chore: import upstream snapshot with attribution
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,156 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import {
|
||||
DEFAULT_PERSON_FIELDS,
|
||||
type GoogleContactsCreateParams,
|
||||
type GoogleContactsCreateResponse,
|
||||
PEOPLE_API_BASE,
|
||||
transformPerson,
|
||||
} from '@/tools/google_contacts/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
const logger = createLogger('GoogleContactsCreate')
|
||||
|
||||
export const createTool: ToolConfig<GoogleContactsCreateParams, GoogleContactsCreateResponse> = {
|
||||
id: 'google_contacts_create',
|
||||
name: 'Google Contacts Create',
|
||||
description: 'Create a new contact in Google Contacts',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'google-contacts',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'Access token for Google People API',
|
||||
},
|
||||
givenName: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'First name of the contact',
|
||||
},
|
||||
familyName: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Last name of the contact',
|
||||
},
|
||||
email: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Email address of the contact',
|
||||
},
|
||||
emailType: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Email type: home, work, or other',
|
||||
},
|
||||
phone: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Phone number of the contact',
|
||||
},
|
||||
phoneType: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Phone type: mobile, home, work, or other',
|
||||
},
|
||||
organization: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Organization/company name',
|
||||
},
|
||||
jobTitle: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Job title at the organization',
|
||||
},
|
||||
notes: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Notes or biography for the contact',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: () => `${PEOPLE_API_BASE}/people:createContact?personFields=${DEFAULT_PERSON_FIELDS}`,
|
||||
method: 'POST',
|
||||
headers: (params: GoogleContactsCreateParams) => ({
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params: GoogleContactsCreateParams) => {
|
||||
const person: Record<string, any> = {
|
||||
names: [
|
||||
{
|
||||
givenName: params.givenName,
|
||||
...(params.familyName ? { familyName: params.familyName } : {}),
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
if (params.email) {
|
||||
person.emailAddresses = [{ value: params.email, type: params.emailType || 'other' }]
|
||||
}
|
||||
|
||||
if (params.phone) {
|
||||
person.phoneNumbers = [{ value: params.phone, type: params.phoneType || 'mobile' }]
|
||||
}
|
||||
|
||||
if (params.organization || params.jobTitle) {
|
||||
person.organizations = [
|
||||
{
|
||||
...(params.organization ? { name: params.organization } : {}),
|
||||
...(params.jobTitle ? { title: params.jobTitle } : {}),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
if (params.notes) {
|
||||
person.biographies = [{ value: params.notes, contentType: 'TEXT_PLAIN' }]
|
||||
}
|
||||
|
||||
return person
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
const errorMessage = data.error?.message || 'Failed to create contact'
|
||||
logger.error('Failed to create contact', { status: response.status, error: errorMessage })
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
const contact = transformPerson(data)
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
content: `Contact "${contact.displayName || contact.givenName}" created successfully`,
|
||||
metadata: contact,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
content: { type: 'string', description: 'Contact creation confirmation message' },
|
||||
metadata: {
|
||||
type: 'json',
|
||||
description: 'Created contact metadata including resource name and details',
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import {
|
||||
type GoogleContactsDeleteParams,
|
||||
type GoogleContactsDeleteResponse,
|
||||
PEOPLE_API_BASE,
|
||||
} from '@/tools/google_contacts/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
const logger = createLogger('GoogleContactsDelete')
|
||||
|
||||
export const deleteTool: ToolConfig<GoogleContactsDeleteParams, GoogleContactsDeleteResponse> = {
|
||||
id: 'google_contacts_delete',
|
||||
name: 'Google Contacts Delete',
|
||||
description: 'Delete a contact from Google Contacts',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'google-contacts',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'Access token for Google People API',
|
||||
},
|
||||
resourceName: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Resource name of the contact to delete (e.g., people/c1234567890)',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: GoogleContactsDeleteParams) =>
|
||||
`${PEOPLE_API_BASE}/${params.resourceName.trim()}:deleteContact`,
|
||||
method: 'DELETE',
|
||||
headers: (params: GoogleContactsDeleteParams) => ({
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response, params) => {
|
||||
if (response.status === 200 || response.status === 204 || response.ok) {
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
content: 'Contact successfully deleted',
|
||||
metadata: {
|
||||
resourceName: params?.resourceName || '',
|
||||
deleted: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const errorData = await response.json()
|
||||
const errorMessage = errorData.error?.message || 'Failed to delete contact'
|
||||
logger.error('Failed to delete contact', { status: response.status, error: errorMessage })
|
||||
throw new Error(errorMessage)
|
||||
},
|
||||
|
||||
outputs: {
|
||||
content: { type: 'string', description: 'Contact deletion confirmation message' },
|
||||
metadata: {
|
||||
type: 'json',
|
||||
description: 'Deletion details including resource name',
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import {
|
||||
DEFAULT_PERSON_FIELDS,
|
||||
type GoogleContactsGetParams,
|
||||
type GoogleContactsGetResponse,
|
||||
PEOPLE_API_BASE,
|
||||
transformPerson,
|
||||
} from '@/tools/google_contacts/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
const logger = createLogger('GoogleContactsGet')
|
||||
|
||||
export const getTool: ToolConfig<GoogleContactsGetParams, GoogleContactsGetResponse> = {
|
||||
id: 'google_contacts_get',
|
||||
name: 'Google Contacts Get',
|
||||
description: 'Get a specific contact from Google Contacts',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'google-contacts',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'Access token for Google People API',
|
||||
},
|
||||
resourceName: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Resource name of the contact (e.g., people/c1234567890)',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: GoogleContactsGetParams) =>
|
||||
`${PEOPLE_API_BASE}/${params.resourceName.trim()}?personFields=${DEFAULT_PERSON_FIELDS}`,
|
||||
method: 'GET',
|
||||
headers: (params: GoogleContactsGetParams) => ({
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
const errorMessage = data.error?.message || 'Failed to get contact'
|
||||
logger.error('Failed to get contact', { status: response.status, error: errorMessage })
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
const contact = transformPerson(data)
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
content: `Retrieved contact "${contact.displayName || contact.resourceName}"`,
|
||||
metadata: contact,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
content: { type: 'string', description: 'Contact retrieval confirmation message' },
|
||||
metadata: {
|
||||
type: 'json',
|
||||
description: 'Contact details including name, email, phone, and organization',
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { createTool } from '@/tools/google_contacts/create'
|
||||
import { deleteTool } from '@/tools/google_contacts/delete'
|
||||
import { getTool } from '@/tools/google_contacts/get'
|
||||
import { listTool } from '@/tools/google_contacts/list'
|
||||
import { searchTool } from '@/tools/google_contacts/search'
|
||||
import { updateTool } from '@/tools/google_contacts/update'
|
||||
|
||||
export const googleContactsCreateTool = createTool
|
||||
export const googleContactsDeleteTool = deleteTool
|
||||
export const googleContactsGetTool = getTool
|
||||
export const googleContactsListTool = listTool
|
||||
export const googleContactsSearchTool = searchTool
|
||||
export const googleContactsUpdateTool = updateTool
|
||||
@@ -0,0 +1,101 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import {
|
||||
DEFAULT_PERSON_FIELDS,
|
||||
type GoogleContactsListParams,
|
||||
type GoogleContactsListResponse,
|
||||
PEOPLE_API_BASE,
|
||||
transformPerson,
|
||||
} from '@/tools/google_contacts/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
const logger = createLogger('GoogleContactsList')
|
||||
|
||||
export const listTool: ToolConfig<GoogleContactsListParams, GoogleContactsListResponse> = {
|
||||
id: 'google_contacts_list',
|
||||
name: 'Google Contacts List',
|
||||
description: 'List contacts from Google Contacts',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'google-contacts',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'Access token for Google People API',
|
||||
},
|
||||
pageSize: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Number of contacts to return (1-1000, default 100)',
|
||||
},
|
||||
pageToken: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Page token from a previous list request for pagination',
|
||||
},
|
||||
sortOrder: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Sort order for contacts',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: GoogleContactsListParams) => {
|
||||
const queryParams = new URLSearchParams()
|
||||
queryParams.append('personFields', DEFAULT_PERSON_FIELDS)
|
||||
|
||||
if (params.pageSize) queryParams.append('pageSize', params.pageSize.toString())
|
||||
if (params.pageToken) queryParams.append('pageToken', params.pageToken)
|
||||
if (params.sortOrder) queryParams.append('sortOrder', params.sortOrder)
|
||||
|
||||
return `${PEOPLE_API_BASE}/people/me/connections?${queryParams.toString()}`
|
||||
},
|
||||
method: 'GET',
|
||||
headers: (params: GoogleContactsListParams) => ({
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
const errorMessage = data.error?.message || 'Failed to list contacts'
|
||||
logger.error('Failed to list contacts', { status: response.status, error: errorMessage })
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
const connections = data.connections || []
|
||||
const contacts = connections.map((person: Record<string, any>) => transformPerson(person))
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
content: `Found ${contacts.length} contact${contacts.length !== 1 ? 's' : ''}`,
|
||||
metadata: {
|
||||
totalItems: data.totalItems ?? null,
|
||||
nextPageToken: data.nextPageToken ?? null,
|
||||
contacts,
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
content: { type: 'string', description: 'Summary of found contacts count' },
|
||||
metadata: {
|
||||
type: 'json',
|
||||
description: 'List of contacts with pagination tokens',
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import {
|
||||
DEFAULT_PERSON_FIELDS,
|
||||
type GoogleContactsSearchParams,
|
||||
type GoogleContactsSearchResponse,
|
||||
PEOPLE_API_BASE,
|
||||
transformPerson,
|
||||
} from '@/tools/google_contacts/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
const logger = createLogger('GoogleContactsSearch')
|
||||
|
||||
export const searchTool: ToolConfig<GoogleContactsSearchParams, GoogleContactsSearchResponse> = {
|
||||
id: 'google_contacts_search',
|
||||
name: 'Google Contacts Search',
|
||||
description: 'Search contacts in Google Contacts by name, email, phone, or organization',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'google-contacts',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'Access token for Google People API',
|
||||
},
|
||||
query: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Search query to match against contact names, emails, phones, and organizations',
|
||||
},
|
||||
pageSize: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Number of results to return (default 10, max 30)',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: GoogleContactsSearchParams) => {
|
||||
const queryParams = new URLSearchParams()
|
||||
queryParams.append('query', params.query)
|
||||
queryParams.append('readMask', DEFAULT_PERSON_FIELDS)
|
||||
|
||||
if (params.pageSize) queryParams.append('pageSize', params.pageSize.toString())
|
||||
|
||||
return `${PEOPLE_API_BASE}/people:searchContacts?${queryParams.toString()}`
|
||||
},
|
||||
method: 'GET',
|
||||
headers: (params: GoogleContactsSearchParams) => ({
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
const errorMessage = data.error?.message || 'Failed to search contacts'
|
||||
logger.error('Failed to search contacts', { status: response.status, error: errorMessage })
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
const results = data.results || []
|
||||
const contacts = results.map((result: Record<string, any>) =>
|
||||
transformPerson(result.person || result)
|
||||
)
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
content: `Found ${contacts.length} contact${contacts.length !== 1 ? 's' : ''} matching query`,
|
||||
metadata: {
|
||||
contacts,
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
content: { type: 'string', description: 'Summary of search results count' },
|
||||
metadata: {
|
||||
type: 'json',
|
||||
description: 'Search results with matching contacts',
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
import type { ToolResponse } from '@/tools/types'
|
||||
|
||||
export const PEOPLE_API_BASE = 'https://people.googleapis.com/v1'
|
||||
|
||||
export const DEFAULT_PERSON_FIELDS =
|
||||
'names,emailAddresses,phoneNumbers,organizations,addresses,biographies,urls,photos,metadata'
|
||||
|
||||
interface BaseGoogleContactsParams {
|
||||
accessToken: string
|
||||
}
|
||||
|
||||
export interface GoogleContactsCreateParams extends BaseGoogleContactsParams {
|
||||
givenName: string
|
||||
familyName?: string
|
||||
email?: string
|
||||
emailType?: 'home' | 'work' | 'other'
|
||||
phone?: string
|
||||
phoneType?: 'mobile' | 'home' | 'work' | 'other'
|
||||
organization?: string
|
||||
jobTitle?: string
|
||||
notes?: string
|
||||
}
|
||||
|
||||
export interface GoogleContactsGetParams extends BaseGoogleContactsParams {
|
||||
resourceName: string
|
||||
}
|
||||
|
||||
export interface GoogleContactsListParams extends BaseGoogleContactsParams {
|
||||
pageSize?: number
|
||||
pageToken?: string
|
||||
sortOrder?:
|
||||
| 'LAST_MODIFIED_ASCENDING'
|
||||
| 'LAST_MODIFIED_DESCENDING'
|
||||
| 'FIRST_NAME_ASCENDING'
|
||||
| 'LAST_NAME_ASCENDING'
|
||||
}
|
||||
|
||||
export interface GoogleContactsUpdateParams extends BaseGoogleContactsParams {
|
||||
resourceName: string
|
||||
etag: string
|
||||
givenName?: string
|
||||
familyName?: string
|
||||
email?: string
|
||||
emailType?: 'home' | 'work' | 'other'
|
||||
phone?: string
|
||||
phoneType?: 'mobile' | 'home' | 'work' | 'other'
|
||||
organization?: string
|
||||
jobTitle?: string
|
||||
notes?: string
|
||||
}
|
||||
|
||||
export interface GoogleContactsDeleteParams extends BaseGoogleContactsParams {
|
||||
resourceName: string
|
||||
}
|
||||
|
||||
export interface GoogleContactsSearchParams extends BaseGoogleContactsParams {
|
||||
query: string
|
||||
pageSize?: number
|
||||
}
|
||||
|
||||
export type GoogleContactsToolParams =
|
||||
| GoogleContactsCreateParams
|
||||
| GoogleContactsGetParams
|
||||
| GoogleContactsListParams
|
||||
| GoogleContactsUpdateParams
|
||||
| GoogleContactsDeleteParams
|
||||
| GoogleContactsSearchParams
|
||||
|
||||
interface ContactMetadata {
|
||||
resourceName: string
|
||||
etag: string
|
||||
displayName: string | null
|
||||
givenName: string | null
|
||||
familyName: string | null
|
||||
emails: Array<{ value: string; type: string }> | null
|
||||
phones: Array<{ value: string; type: string }> | null
|
||||
organizations: Array<{ name: string; title: string }> | null
|
||||
addresses: Array<{ formattedValue: string; type: string }> | null
|
||||
biographies: Array<{ value: string }> | null
|
||||
urls: Array<{ value: string; type: string }> | null
|
||||
photos: Array<{ url: string }> | null
|
||||
}
|
||||
|
||||
export interface GoogleContactsCreateResponse extends ToolResponse {
|
||||
output: {
|
||||
content: string
|
||||
metadata: ContactMetadata
|
||||
}
|
||||
}
|
||||
|
||||
export interface GoogleContactsGetResponse extends ToolResponse {
|
||||
output: {
|
||||
content: string
|
||||
metadata: ContactMetadata
|
||||
}
|
||||
}
|
||||
|
||||
export interface GoogleContactsListResponse extends ToolResponse {
|
||||
output: {
|
||||
content: string
|
||||
metadata: {
|
||||
totalItems: number | null
|
||||
nextPageToken: string | null
|
||||
contacts: ContactMetadata[]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface GoogleContactsUpdateResponse extends ToolResponse {
|
||||
output: {
|
||||
content: string
|
||||
metadata: ContactMetadata
|
||||
}
|
||||
}
|
||||
|
||||
export interface GoogleContactsDeleteResponse extends ToolResponse {
|
||||
output: {
|
||||
content: string
|
||||
metadata: {
|
||||
resourceName: string
|
||||
deleted: boolean
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface GoogleContactsSearchResponse extends ToolResponse {
|
||||
output: {
|
||||
content: string
|
||||
metadata: {
|
||||
contacts: ContactMetadata[]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type GoogleContactsResponse =
|
||||
| GoogleContactsCreateResponse
|
||||
| GoogleContactsGetResponse
|
||||
| GoogleContactsListResponse
|
||||
| GoogleContactsUpdateResponse
|
||||
| GoogleContactsDeleteResponse
|
||||
| GoogleContactsSearchResponse
|
||||
|
||||
/** Transforms a raw Google People API person object into a ContactMetadata */
|
||||
export function transformPerson(person: Record<string, any>): ContactMetadata {
|
||||
return {
|
||||
resourceName: person.resourceName ?? '',
|
||||
etag: person.etag ?? '',
|
||||
displayName: person.names?.[0]?.displayName ?? null,
|
||||
givenName: person.names?.[0]?.givenName ?? null,
|
||||
familyName: person.names?.[0]?.familyName ?? null,
|
||||
emails:
|
||||
person.emailAddresses?.map((e: Record<string, any>) => ({
|
||||
value: e.value ?? '',
|
||||
type: e.type ?? 'other',
|
||||
})) ?? null,
|
||||
phones:
|
||||
person.phoneNumbers?.map((p: Record<string, any>) => ({
|
||||
value: p.value ?? '',
|
||||
type: p.type ?? 'other',
|
||||
})) ?? null,
|
||||
organizations:
|
||||
person.organizations?.map((o: Record<string, any>) => ({
|
||||
name: o.name ?? '',
|
||||
title: o.title ?? '',
|
||||
})) ?? null,
|
||||
addresses:
|
||||
person.addresses?.map((a: Record<string, any>) => ({
|
||||
formattedValue: a.formattedValue ?? '',
|
||||
type: a.type ?? 'other',
|
||||
})) ?? null,
|
||||
biographies:
|
||||
person.biographies?.map((b: Record<string, any>) => ({
|
||||
value: b.value ?? '',
|
||||
})) ?? null,
|
||||
urls:
|
||||
person.urls?.map((u: Record<string, any>) => ({
|
||||
value: u.value ?? '',
|
||||
type: u.type ?? 'other',
|
||||
})) ?? null,
|
||||
photos:
|
||||
person.photos?.map((p: Record<string, any>) => ({
|
||||
url: p.url ?? '',
|
||||
})) ?? null,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import {
|
||||
DEFAULT_PERSON_FIELDS,
|
||||
type GoogleContactsUpdateParams,
|
||||
type GoogleContactsUpdateResponse,
|
||||
PEOPLE_API_BASE,
|
||||
transformPerson,
|
||||
} from '@/tools/google_contacts/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
const logger = createLogger('GoogleContactsUpdate')
|
||||
|
||||
export const updateTool: ToolConfig<GoogleContactsUpdateParams, GoogleContactsUpdateResponse> = {
|
||||
id: 'google_contacts_update',
|
||||
name: 'Google Contacts Update',
|
||||
description: 'Update an existing contact in Google Contacts',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'google-contacts',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'Access token for Google People API',
|
||||
},
|
||||
resourceName: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Resource name of the contact (e.g., people/c1234567890)',
|
||||
},
|
||||
etag: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'ETag from a previous get request (required for concurrency control)',
|
||||
},
|
||||
givenName: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Updated first name',
|
||||
},
|
||||
familyName: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Updated last name',
|
||||
},
|
||||
email: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Updated email address',
|
||||
},
|
||||
emailType: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Email type: home, work, or other',
|
||||
},
|
||||
phone: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Updated phone number',
|
||||
},
|
||||
phoneType: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Phone type: mobile, home, work, or other',
|
||||
},
|
||||
organization: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Updated organization/company name',
|
||||
},
|
||||
jobTitle: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Updated job title',
|
||||
},
|
||||
notes: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Updated notes or biography',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: GoogleContactsUpdateParams) => {
|
||||
const updateFields: string[] = []
|
||||
if (params.givenName || params.familyName) updateFields.push('names')
|
||||
if (params.email) updateFields.push('emailAddresses')
|
||||
if (params.phone) updateFields.push('phoneNumbers')
|
||||
if (params.organization || params.jobTitle) updateFields.push('organizations')
|
||||
if (params.notes) updateFields.push('biographies')
|
||||
|
||||
if (updateFields.length === 0) {
|
||||
throw new Error('At least one field to update must be provided')
|
||||
}
|
||||
|
||||
const updatePersonFields = updateFields.join(',')
|
||||
|
||||
return `${PEOPLE_API_BASE}/${params.resourceName.trim()}:updateContact?updatePersonFields=${updatePersonFields}&personFields=${DEFAULT_PERSON_FIELDS}`
|
||||
},
|
||||
method: 'PATCH',
|
||||
headers: (params: GoogleContactsUpdateParams) => ({
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params: GoogleContactsUpdateParams) => {
|
||||
const person: Record<string, any> = {
|
||||
etag: params.etag,
|
||||
metadata: { sources: [{ type: 'CONTACT', etag: params.etag }] },
|
||||
}
|
||||
|
||||
if (params.givenName || params.familyName) {
|
||||
person.names = [
|
||||
{
|
||||
...(params.givenName ? { givenName: params.givenName } : {}),
|
||||
...(params.familyName ? { familyName: params.familyName } : {}),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
if (params.email) {
|
||||
person.emailAddresses = [{ value: params.email, type: params.emailType || 'other' }]
|
||||
}
|
||||
|
||||
if (params.phone) {
|
||||
person.phoneNumbers = [{ value: params.phone, type: params.phoneType || 'mobile' }]
|
||||
}
|
||||
|
||||
if (params.organization || params.jobTitle) {
|
||||
person.organizations = [
|
||||
{
|
||||
...(params.organization ? { name: params.organization } : {}),
|
||||
...(params.jobTitle ? { title: params.jobTitle } : {}),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
if (params.notes) {
|
||||
person.biographies = [{ value: params.notes, contentType: 'TEXT_PLAIN' }]
|
||||
}
|
||||
|
||||
return person
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
const errorMessage = data.error?.message || 'Failed to update contact'
|
||||
logger.error('Failed to update contact', { status: response.status, error: errorMessage })
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
const contact = transformPerson(data)
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
content: `Contact "${contact.displayName || contact.resourceName}" updated successfully`,
|
||||
metadata: contact,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
content: { type: 'string', description: 'Contact update confirmation message' },
|
||||
metadata: {
|
||||
type: 'json',
|
||||
description: 'Updated contact metadata',
|
||||
},
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user