Files
simstudioai--sim/apps/sim/tools/agentphone/update_conversation.ts
T
wehub-resource-sync d25d482dc2
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) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

153 lines
4.9 KiB
TypeScript

import type {
AgentPhoneConversationMessage,
AgentPhoneUpdateConversationParams,
AgentPhoneUpdateConversationResult,
} from '@/tools/agentphone/types'
import type { ToolConfig } from '@/tools/types'
export const agentphoneUpdateConversationTool: ToolConfig<
AgentPhoneUpdateConversationParams,
AgentPhoneUpdateConversationResult
> = {
id: 'agentphone_update_conversation',
name: 'Update Conversation',
description: 'Update conversation metadata (stored state). Pass null to clear existing metadata.',
version: '1.0.0',
params: {
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'AgentPhone API key',
},
conversationId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Conversation ID',
},
metadata: {
type: 'json',
required: false,
visibility: 'user-or-llm',
description:
'Custom key-value metadata to store on the conversation. Pass null to clear existing metadata.',
},
},
request: {
url: (params) => `https://api.agentphone.to/v1/conversations/${params.conversationId.trim()}`,
method: 'PATCH',
headers: (params) => ({
Authorization: `Bearer ${params.apiKey}`,
'Content-Type': 'application/json',
}),
body: (params) => {
const body: Record<string, unknown> = {}
if (params.metadata !== undefined) body.metadata = params.metadata
return body
},
},
transformResponse: async (response): Promise<AgentPhoneUpdateConversationResult> => {
const data = await response.json()
if (!response.ok) {
return {
success: false,
error: data?.detail?.[0]?.msg ?? data?.message ?? 'Failed to update conversation',
output: {
id: '',
agentId: null,
phoneNumberId: '',
phoneNumber: '',
participant: '',
lastMessageAt: '',
messageCount: 0,
metadata: null,
createdAt: '',
messages: [],
},
}
}
const rawMessages = Array.isArray(data?.messages) ? data.messages : []
const messages: AgentPhoneConversationMessage[] = rawMessages.map(
(message: Record<string, unknown>) => ({
id: (message.id as string) ?? '',
body: (message.body as string) ?? '',
fromNumber: (message.fromNumber as string) ?? '',
toNumber: (message.toNumber as string) ?? '',
direction: (message.direction as string) ?? '',
channel: (message.channel as string | null) ?? null,
mediaUrl: (message.mediaUrl as string | null) ?? null,
mediaUrls: Array.isArray(message.mediaUrls) ? (message.mediaUrls as string[]) : [],
receivedAt: (message.receivedAt as string) ?? '',
})
)
return {
success: true,
output: {
id: data.id ?? '',
agentId: data.agentId ?? null,
phoneNumberId: data.phoneNumberId ?? '',
phoneNumber: data.phoneNumber ?? '',
participant: data.participant ?? '',
lastMessageAt: data.lastMessageAt ?? '',
messageCount: data.messageCount ?? 0,
metadata: data.metadata ?? null,
createdAt: data.createdAt ?? '',
messages,
},
}
},
outputs: {
id: { type: 'string', description: 'Conversation ID' },
agentId: { type: 'string', description: 'Agent ID', optional: true },
phoneNumberId: { type: 'string', description: 'Phone number ID' },
phoneNumber: { type: 'string', description: 'Phone number' },
participant: { type: 'string', description: 'External participant phone number' },
lastMessageAt: { type: 'string', description: 'ISO 8601 timestamp' },
messageCount: { type: 'number', description: 'Number of messages' },
metadata: {
type: 'json',
description: 'Custom metadata stored on the conversation',
optional: true,
},
createdAt: { type: 'string', description: 'ISO 8601 timestamp' },
messages: {
type: 'array',
description: 'Messages in the conversation',
items: {
type: 'object',
properties: {
id: { type: 'string', description: 'Message ID' },
body: { type: 'string', description: 'Message body' },
fromNumber: { type: 'string', description: 'Sender phone number' },
toNumber: { type: 'string', description: 'Recipient phone number' },
direction: { type: 'string', description: 'inbound or outbound' },
channel: {
type: 'string',
description: 'Channel (sms, mms, etc.)',
optional: true,
},
mediaUrl: {
type: 'string',
description: 'Media URL if any',
optional: true,
},
mediaUrls: {
type: 'array',
description: 'All attached media URLs',
items: { type: 'string' },
},
receivedAt: { type: 'string', description: 'ISO 8601 timestamp' },
},
},
},
},
}