d25d482dc2
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
144 lines
4.7 KiB
TypeScript
144 lines
4.7 KiB
TypeScript
import type {
|
|
AgentPhoneConversationMessage,
|
|
AgentPhoneGetConversationParams,
|
|
AgentPhoneGetConversationResult,
|
|
} from '@/tools/agentphone/types'
|
|
import type { ToolConfig } from '@/tools/types'
|
|
|
|
export const agentphoneGetConversationTool: ToolConfig<
|
|
AgentPhoneGetConversationParams,
|
|
AgentPhoneGetConversationResult
|
|
> = {
|
|
id: 'agentphone_get_conversation',
|
|
name: 'Get Conversation',
|
|
description: 'Get a conversation along with its recent messages',
|
|
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',
|
|
},
|
|
messageLimit: {
|
|
type: 'number',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Number of recent messages to include (default 50, max 100)',
|
|
},
|
|
},
|
|
|
|
request: {
|
|
url: (params) => {
|
|
const query = new URLSearchParams()
|
|
if (typeof params.messageLimit === 'number') {
|
|
query.set('message_limit', String(params.messageLimit))
|
|
}
|
|
const qs = query.toString()
|
|
return `https://api.agentphone.to/v1/conversations/${params.conversationId.trim()}${qs ? `?${qs}` : ''}`
|
|
},
|
|
method: 'GET',
|
|
headers: (params) => ({
|
|
Authorization: `Bearer ${params.apiKey}`,
|
|
}),
|
|
},
|
|
|
|
transformResponse: async (response): Promise<AgentPhoneGetConversationResult> => {
|
|
const data = await response.json()
|
|
|
|
if (!response.ok) {
|
|
return {
|
|
success: false,
|
|
error: data?.detail?.[0]?.msg ?? data?.message ?? 'Failed to fetch conversation',
|
|
output: {
|
|
id: '',
|
|
agentId: null,
|
|
phoneNumberId: '',
|
|
phoneNumber: '',
|
|
participant: '',
|
|
lastMessageAt: '',
|
|
messageCount: 0,
|
|
metadata: null,
|
|
createdAt: '',
|
|
messages: [],
|
|
},
|
|
}
|
|
}
|
|
|
|
const messages: AgentPhoneConversationMessage[] = (data.messages ?? []).map(
|
|
(msg: Record<string, unknown>) => ({
|
|
id: (msg.id as string) ?? '',
|
|
body: (msg.body as string) ?? '',
|
|
fromNumber: (msg.fromNumber as string) ?? '',
|
|
toNumber: (msg.toNumber as string) ?? '',
|
|
direction: (msg.direction as string) ?? '',
|
|
channel: (msg.channel as string | null) ?? null,
|
|
mediaUrl: (msg.mediaUrl as string | null) ?? null,
|
|
mediaUrls: Array.isArray(msg.mediaUrls) ? (msg.mediaUrls as string[]) : [],
|
|
receivedAt: (msg.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 in the conversation' },
|
|
metadata: {
|
|
type: 'json',
|
|
description: 'Custom metadata stored on the conversation',
|
|
optional: true,
|
|
},
|
|
createdAt: { type: 'string', description: 'ISO 8601 timestamp' },
|
|
messages: {
|
|
type: 'array',
|
|
description: 'Recent messages in the conversation',
|
|
items: {
|
|
type: 'object',
|
|
properties: {
|
|
id: { type: 'string', description: 'Message ID' },
|
|
body: { type: 'string', description: 'Message text' },
|
|
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: 'sms, mms, or imessage', optional: true },
|
|
mediaUrl: { type: 'string', description: 'Attached media URL', optional: true },
|
|
mediaUrls: {
|
|
type: 'array',
|
|
description: 'All attached media URLs',
|
|
items: { type: 'string' },
|
|
},
|
|
receivedAt: { type: 'string', description: 'ISO 8601 timestamp' },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|