@telnyx/ai-agent-lib 0.4.5 → 0.5.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/message.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { FunctionCallItem, IAIConversationMessageEvent } from "@telnyx/webrtc";
1
2
  export type TranscriptMessage = {
2
3
  id: string;
3
4
  jsonrpc: "2.0";
@@ -48,6 +49,22 @@ export type ConversationItemCreatedMessage = {
48
49
  voice_sdk_id: string;
49
50
  };
50
51
  export declare function isConversationItemCreatedMessage(message: unknown): message is ConversationItemCreatedMessage;
52
+ /**
53
+ * PR-531 `function_call` payload delivered by `@telnyx/webrtc` over the
54
+ * `SwEvent.AIConversationMessage` (`telnyx.ai.conversation`) event.
55
+ *
56
+ * These items intentionally have NO `params.item.content`, so they are never
57
+ * mistaken for transcript items by {@link isConversationItemCreatedMessage}
58
+ * (which requires `params.item.content`). Tool-call handling stays fully
59
+ * separate from transcript parsing.
60
+ */
61
+ export declare function isAIConversationMessageEvent(event: unknown): event is IAIConversationMessageEvent;
62
+ /**
63
+ * Extracts a PR-531 `function_call` item from an inbound
64
+ * `telnyx.ai.conversation` event, or returns `null` when the event is not an
65
+ * inbound function call (e.g. transcript / state / output messages).
66
+ */
67
+ export declare function getFunctionCallItem(event: unknown): FunctionCallItem | null;
51
68
  export type ConversationItemDeletedMessage = {
52
69
  id: string;
53
70
  jsonrpc: "2.0";
package/dist/types.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import type { INotification, Call, ICallOptions } from "@telnyx/webrtc";
2
2
  import { SwEvent } from "@telnyx/webrtc";
3
+ import { isFunctionCallParams, isFunctionCallOutputParams } from "@telnyx/webrtc";
4
+ import type { FunctionCallItem, FunctionCallOutputItem, AIConversationParams, IAIConversationMessageEvent } from "@telnyx/webrtc";
3
5
  export type Attachment = {
4
6
  type: "image";
5
7
  url: string;
@@ -11,6 +13,51 @@ export type TranscriptItem = {
11
13
  timestamp: Date;
12
14
  attachments?: Array<Attachment>;
13
15
  };
16
+ /**
17
+ * Context passed to a client-side tool handler when ACA invokes a
18
+ * PR-531 `function_call`. Lets handlers correlate the invocation and read
19
+ * metadata without reaching into SDK internals.
20
+ */
21
+ export type ClientSideToolContext = {
22
+ /** The PR-531 `call_id`. Must round-trip into the `function_call_output`. */
23
+ callId: string;
24
+ /** The registered tool name ACA asked to invoke. */
25
+ toolName: string;
26
+ /** Raw JSON `arguments` string exactly as received from ACA. */
27
+ rawArguments: string;
28
+ };
29
+ /**
30
+ * A client-side tool implementation. Receives the parsed `arguments` object
31
+ * (or `undefined` when ACA sends empty arguments) plus invocation context.
32
+ *
33
+ * The return value is serialized and sent back to ACA as the
34
+ * `function_call_output.output`. Strings are sent verbatim; anything else is
35
+ * JSON-stringified. Throwing (or rejecting) is caught and reported back to ACA
36
+ * as a safe error output so the conversation can continue.
37
+ */
38
+ export type ClientSideToolHandler = (args: unknown, context: ClientSideToolContext) => unknown | Promise<unknown>;
39
+ /** Map of tool name -> handler, accepted by the constructor. */
40
+ export type ClientSideToolMap = Record<string, ClientSideToolHandler>;
41
+ /** Reason a tool invocation produced an error output. */
42
+ export type ClientSideToolErrorReason = "unknown_tool" | "invalid_arguments" | "handler_error" | "timeout" | "shutdown";
43
+ /** Emitted when a client-side tool invocation begins. */
44
+ export type ClientSideToolInvokedInfo = {
45
+ callId: string;
46
+ toolName: string;
47
+ };
48
+ /** Emitted when a client-side tool invocation produced an output for ACA. */
49
+ export type ClientSideToolCompletedInfo = {
50
+ callId: string;
51
+ toolName: string;
52
+ /** True when the output represents a handled error rather than a result. */
53
+ isError: boolean;
54
+ };
55
+ /** Emitted when a client-side tool invocation failed and reported a safe error. */
56
+ export type ClientSideToolErrorInfo = {
57
+ callId: string;
58
+ toolName: string;
59
+ reason: ClientSideToolErrorReason;
60
+ };
14
61
  export type AgentStateData = {
15
62
  state: AgentState;
16
63
  /** Latency in milliseconds from when user stopped speaking until agent response began. Only present when state is "speaking". */
@@ -71,6 +118,9 @@ export type AIAgentEvents = {
71
118
  "conversation.update": (call: INotification) => void;
72
119
  "conversation.agent.state": (data: AgentStateData) => void;
73
120
  "agent.audio.mute": (muted: boolean) => void;
121
+ "client.tool.invoked": (info: ClientSideToolInvokedInfo) => void;
122
+ "client.tool.completed": (info: ClientSideToolCompletedInfo) => void;
123
+ "client.tool.error": (info: ClientSideToolErrorInfo) => void;
74
124
  };
75
125
  export type AgentState = "speaking" | "listening" | "thinking";
76
126
  export type TranscriptEvents = Pick<AIAgentEvents, "transcript.item">;
@@ -108,3 +158,5 @@ export type VADOptions = {
108
158
  };
109
159
  export type { INotification, Call, ICallOptions };
110
160
  export { SwEvent };
161
+ export type { FunctionCallItem, FunctionCallOutputItem, AIConversationParams, IAIConversationMessageEvent, };
162
+ export { isFunctionCallParams, isFunctionCallOutputParams };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@telnyx/ai-agent-lib",
3
3
  "private": false,
4
- "version": "0.4.5",
4
+ "version": "0.5.0-beta.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -21,6 +21,8 @@
21
21
  "dev": "vite",
22
22
  "build": "tsc -p tsconfig.build.json && vite build",
23
23
  "lint": "eslint .",
24
+ "test": "vitest run",
25
+ "test:watch": "vitest",
24
26
  "format": "prettier --write .",
25
27
  "preview": "vite preview",
26
28
  "release": "release-it"
@@ -30,7 +32,7 @@
30
32
  "react-dom": "^19.1.0"
31
33
  },
32
34
  "dependencies": {
33
- "@telnyx/webrtc": "2.27.1",
35
+ "@telnyx/webrtc": "2.27.2-beta.0",
34
36
  "eventemitter3": "^5.0.1",
35
37
  "jotai": "^2.12.5",
36
38
  "loglevel": "^1.9.2"
@@ -54,7 +56,8 @@
54
56
  "release-it": "^19.0.4",
55
57
  "typescript": "~5.8.3",
56
58
  "typescript-eslint": "^8.52.0",
57
- "vite": "^7.0.4"
59
+ "vite": "^7.0.4",
60
+ "vitest": "^3.2.4"
58
61
  },
59
62
  "lint-staged": {
60
63
  "**/*.{ts,tsx,js,jsx}": [