@trigger.dev/sdk 4.4.6 → 4.5.0-rc.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/commonjs/v3/agentSkillsRuntime.d.ts +28 -0
- package/dist/commonjs/v3/agentSkillsRuntime.js +163 -0
- package/dist/commonjs/v3/agentSkillsRuntime.js.map +1 -0
- package/dist/commonjs/v3/ai-shared.d.ts +173 -0
- package/dist/commonjs/v3/ai-shared.js +25 -0
- package/dist/commonjs/v3/ai-shared.js.map +1 -0
- package/dist/commonjs/v3/ai.d.ts +2823 -5
- package/dist/commonjs/v3/ai.js +6197 -13
- package/dist/commonjs/v3/ai.js.map +1 -1
- package/dist/commonjs/v3/auth.d.ts +9 -0
- package/dist/commonjs/v3/auth.js.map +1 -1
- package/dist/commonjs/v3/chat-client.d.ts +301 -0
- package/dist/commonjs/v3/chat-client.js +624 -0
- package/dist/commonjs/v3/chat-client.js.map +1 -0
- package/dist/commonjs/v3/chat-react.d.ts +155 -0
- package/dist/commonjs/v3/chat-react.js +330 -0
- package/dist/commonjs/v3/chat-react.js.map +1 -0
- package/dist/commonjs/v3/chat-server.d.ts +206 -0
- package/dist/commonjs/v3/chat-server.js +737 -0
- package/dist/commonjs/v3/chat-server.js.map +1 -0
- package/dist/commonjs/v3/chat-server.test.d.ts +1 -0
- package/dist/commonjs/v3/chat-server.test.js +518 -0
- package/dist/commonjs/v3/chat-server.test.js.map +1 -0
- package/dist/commonjs/v3/chat-tab-coordinator.d.ts +65 -0
- package/dist/commonjs/v3/chat-tab-coordinator.js +235 -0
- package/dist/commonjs/v3/chat-tab-coordinator.js.map +1 -0
- package/dist/commonjs/v3/chat-tab-coordinator.test.d.ts +1 -0
- package/dist/commonjs/v3/chat-tab-coordinator.test.js +140 -0
- package/dist/commonjs/v3/chat-tab-coordinator.test.js.map +1 -0
- package/dist/commonjs/v3/chat.d.ts +437 -0
- package/dist/commonjs/v3/chat.js +968 -0
- package/dist/commonjs/v3/chat.js.map +1 -0
- package/dist/commonjs/v3/chat.test.d.ts +1 -0
- package/dist/commonjs/v3/chat.test.js +1180 -0
- package/dist/commonjs/v3/chat.test.js.map +1 -0
- package/dist/commonjs/v3/createStartSessionAction.test.d.ts +1 -0
- package/dist/commonjs/v3/createStartSessionAction.test.js +113 -0
- package/dist/commonjs/v3/createStartSessionAction.test.js.map +1 -0
- package/dist/commonjs/v3/deployments.d.ts +26 -0
- package/dist/commonjs/v3/deployments.js +37 -0
- package/dist/commonjs/v3/deployments.js.map +1 -0
- package/dist/commonjs/v3/index.d.ts +6 -3
- package/dist/commonjs/v3/index.js +7 -1
- package/dist/commonjs/v3/index.js.map +1 -1
- package/dist/commonjs/v3/runs.d.ts +22 -7
- package/dist/commonjs/v3/runs.js +1 -0
- package/dist/commonjs/v3/runs.js.map +1 -1
- package/dist/commonjs/v3/sessions.d.ts +228 -0
- package/dist/commonjs/v3/sessions.js +664 -0
- package/dist/commonjs/v3/sessions.js.map +1 -0
- package/dist/commonjs/v3/sessions.test.d.ts +1 -0
- package/dist/commonjs/v3/sessions.test.js +154 -0
- package/dist/commonjs/v3/sessions.test.js.map +1 -0
- package/dist/commonjs/v3/shared.d.ts +24 -2
- package/dist/commonjs/v3/shared.js +189 -1
- package/dist/commonjs/v3/shared.js.map +1 -1
- package/dist/commonjs/v3/skill.d.ts +99 -0
- package/dist/commonjs/v3/skill.js +155 -0
- package/dist/commonjs/v3/skill.js.map +1 -0
- package/dist/commonjs/v3/skills.d.ts +2 -0
- package/dist/commonjs/v3/skills.js +6 -0
- package/dist/commonjs/v3/skills.js.map +1 -0
- package/dist/commonjs/v3/streams.js +127 -19
- package/dist/commonjs/v3/streams.js.map +1 -1
- package/dist/commonjs/v3/tasks.d.ts +2 -1
- package/dist/commonjs/v3/tasks.js +1 -0
- package/dist/commonjs/v3/tasks.js.map +1 -1
- package/dist/commonjs/v3/test/index.d.ts +3 -0
- package/dist/commonjs/v3/test/index.js +18 -0
- package/dist/commonjs/v3/test/index.js.map +1 -0
- package/dist/commonjs/v3/test/mock-chat-agent.d.ts +259 -0
- package/dist/commonjs/v3/test/mock-chat-agent.js +468 -0
- package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -0
- package/dist/commonjs/v3/test/setup-catalog.d.ts +1 -0
- package/dist/commonjs/v3/test/setup-catalog.js +18 -0
- package/dist/commonjs/v3/test/setup-catalog.js.map +1 -0
- package/dist/commonjs/v3/test/test-session-handle.d.ts +53 -0
- package/dist/commonjs/v3/test/test-session-handle.js +256 -0
- package/dist/commonjs/v3/test/test-session-handle.js.map +1 -0
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/v3/agentSkillsRuntime.d.ts +28 -0
- package/dist/esm/v3/agentSkillsRuntime.js +136 -0
- package/dist/esm/v3/agentSkillsRuntime.js.map +1 -0
- package/dist/esm/v3/ai-shared.d.ts +173 -0
- package/dist/esm/v3/ai-shared.js +22 -0
- package/dist/esm/v3/ai-shared.js.map +1 -0
- package/dist/esm/v3/ai.d.ts +2823 -5
- package/dist/esm/v3/ai.js +6187 -14
- package/dist/esm/v3/ai.js.map +1 -1
- package/dist/esm/v3/auth.d.ts +9 -0
- package/dist/esm/v3/auth.js.map +1 -1
- package/dist/esm/v3/chat-client.d.ts +301 -0
- package/dist/esm/v3/chat-client.js +619 -0
- package/dist/esm/v3/chat-client.js.map +1 -0
- package/dist/esm/v3/chat-react.d.ts +155 -0
- package/dist/esm/v3/chat-react.js +325 -0
- package/dist/esm/v3/chat-react.js.map +1 -0
- package/dist/esm/v3/chat-server.d.ts +206 -0
- package/dist/esm/v3/chat-server.js +734 -0
- package/dist/esm/v3/chat-server.js.map +1 -0
- package/dist/esm/v3/chat-server.test.d.ts +1 -0
- package/dist/esm/v3/chat-server.test.js +516 -0
- package/dist/esm/v3/chat-server.test.js.map +1 -0
- package/dist/esm/v3/chat-tab-coordinator.d.ts +65 -0
- package/dist/esm/v3/chat-tab-coordinator.js +231 -0
- package/dist/esm/v3/chat-tab-coordinator.js.map +1 -0
- package/dist/esm/v3/chat-tab-coordinator.test.d.ts +1 -0
- package/dist/esm/v3/chat-tab-coordinator.test.js +138 -0
- package/dist/esm/v3/chat-tab-coordinator.test.js.map +1 -0
- package/dist/esm/v3/chat.d.ts +437 -0
- package/dist/esm/v3/chat.js +961 -0
- package/dist/esm/v3/chat.js.map +1 -0
- package/dist/esm/v3/chat.test.d.ts +1 -0
- package/dist/esm/v3/chat.test.js +1178 -0
- package/dist/esm/v3/chat.test.js.map +1 -0
- package/dist/esm/v3/createStartSessionAction.test.d.ts +1 -0
- package/dist/esm/v3/createStartSessionAction.test.js +111 -0
- package/dist/esm/v3/createStartSessionAction.test.js.map +1 -0
- package/dist/esm/v3/deployments.d.ts +26 -0
- package/dist/esm/v3/deployments.js +34 -0
- package/dist/esm/v3/deployments.js.map +1 -0
- package/dist/esm/v3/index.d.ts +6 -3
- package/dist/esm/v3/index.js +4 -1
- package/dist/esm/v3/index.js.map +1 -1
- package/dist/esm/v3/runs.d.ts +15 -0
- package/dist/esm/v3/runs.js +1 -0
- package/dist/esm/v3/runs.js.map +1 -1
- package/dist/esm/v3/sessions.d.ts +228 -0
- package/dist/esm/v3/sessions.js +656 -0
- package/dist/esm/v3/sessions.js.map +1 -0
- package/dist/esm/v3/sessions.test.d.ts +1 -0
- package/dist/esm/v3/sessions.test.js +152 -0
- package/dist/esm/v3/sessions.test.js.map +1 -0
- package/dist/esm/v3/shared.d.ts +24 -2
- package/dist/esm/v3/shared.js +188 -1
- package/dist/esm/v3/shared.js.map +1 -1
- package/dist/esm/v3/skill.d.ts +99 -0
- package/dist/esm/v3/skill.js +128 -0
- package/dist/esm/v3/skill.js.map +1 -0
- package/dist/esm/v3/skills.d.ts +2 -0
- package/dist/esm/v3/skills.js +2 -0
- package/dist/esm/v3/skills.js.map +1 -0
- package/dist/esm/v3/streams.js +127 -20
- package/dist/esm/v3/streams.js.map +1 -1
- package/dist/esm/v3/tasks.d.ts +2 -1
- package/dist/esm/v3/tasks.js +2 -1
- package/dist/esm/v3/tasks.js.map +1 -1
- package/dist/esm/v3/test/index.d.ts +3 -0
- package/dist/esm/v3/test/index.js +13 -0
- package/dist/esm/v3/test/index.js.map +1 -0
- package/dist/esm/v3/test/mock-chat-agent.d.ts +259 -0
- package/dist/esm/v3/test/mock-chat-agent.js +465 -0
- package/dist/esm/v3/test/mock-chat-agent.js.map +1 -0
- package/dist/esm/v3/test/setup-catalog.d.ts +1 -0
- package/dist/esm/v3/test/setup-catalog.js +16 -0
- package/dist/esm/v3/test/setup-catalog.js.map +1 -0
- package/dist/esm/v3/test/test-session-handle.d.ts +53 -0
- package/dist/esm/v3/test/test-session-handle.js +251 -0
- package/dist/esm/v3/test/test-session-handle.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/package.json +87 -6
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side API for chatting with Trigger.dev agents.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { AgentChat } from "@trigger.dev/sdk/chat";
|
|
7
|
+
*
|
|
8
|
+
* const chat = new AgentChat<typeof myAgent>({
|
|
9
|
+
* agent: "my-agent",
|
|
10
|
+
* clientData: { userId: "user_123" },
|
|
11
|
+
* });
|
|
12
|
+
*
|
|
13
|
+
* const stream = await chat.sendMessage("Review PR #1");
|
|
14
|
+
* const text = await stream.text();
|
|
15
|
+
* await chat.close();
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
import type { SessionTriggerConfig, Task } from "@trigger.dev/core/v3";
|
|
19
|
+
import type { ModelMessage, UIMessage, UIMessageChunk } from "ai";
|
|
20
|
+
import type { ChatTaskWirePayload } from "./ai-shared.js";
|
|
21
|
+
/** Extract the client data (metadata) type from a chat agent task. */
|
|
22
|
+
export type InferChatClientData<T> = T extends Task<any, ChatTaskWirePayload<any, infer TMetadata>, any> ? unknown extends TMetadata ? Record<string, unknown> : TMetadata : Record<string, unknown>;
|
|
23
|
+
/** Extract the UIMessage type from a chat agent task. */
|
|
24
|
+
export type InferChatUIMessage<T> = T extends Task<any, ChatTaskWirePayload<infer TUIMessage, any>, any> ? TUIMessage : UIMessage;
|
|
25
|
+
/** Persistable session state — store this to resume across requests. */
|
|
26
|
+
export type ChatSession = {
|
|
27
|
+
/** Last SSE event ID seen on `session.out` — used to resume without replay. */
|
|
28
|
+
lastEventId?: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Discriminator passed to per-endpoint `baseURL` and `fetch` callbacks on
|
|
32
|
+
* `AgentChat`. Same shape as the type on `TriggerChatTransport` — these
|
|
33
|
+
* mirror so customers can share a single resolver between the two clients.
|
|
34
|
+
*/
|
|
35
|
+
export type AgentChatEndpoint = "in" | "out";
|
|
36
|
+
export type AgentChatEndpointContext = {
|
|
37
|
+
endpoint: AgentChatEndpoint;
|
|
38
|
+
chatId: string;
|
|
39
|
+
};
|
|
40
|
+
export type AgentChatBaseURLResolver = (ctx: AgentChatEndpointContext) => string;
|
|
41
|
+
export type AgentChatFetchOverride = (url: string, init: RequestInit, ctx: AgentChatEndpointContext) => Promise<Response>;
|
|
42
|
+
export type AgentChatOptions<TAgent = unknown> = {
|
|
43
|
+
/** The agent task ID to trigger. */
|
|
44
|
+
agent: string;
|
|
45
|
+
/**
|
|
46
|
+
* Conversation ID. Used for tagging runs and correlating messages.
|
|
47
|
+
* @default crypto.randomUUID()
|
|
48
|
+
*/
|
|
49
|
+
id?: string;
|
|
50
|
+
/** Client data included in every request. Typed from the agent's clientDataSchema. */
|
|
51
|
+
clientData?: InferChatClientData<TAgent>;
|
|
52
|
+
/**
|
|
53
|
+
* Restore a previous session. Pass `lastEventId` from a previous
|
|
54
|
+
* request to resume the SSE stream without replaying old chunks.
|
|
55
|
+
*/
|
|
56
|
+
session?: ChatSession;
|
|
57
|
+
/**
|
|
58
|
+
* Called when a new run is triggered for this session (initial start).
|
|
59
|
+
* Useful for telemetry / dashboard linking. The runId is the
|
|
60
|
+
* friendlyId.
|
|
61
|
+
*/
|
|
62
|
+
onTriggered?: (event: {
|
|
63
|
+
runId: string;
|
|
64
|
+
chatId: string;
|
|
65
|
+
}) => void | Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Called when a turn completes. Persist `lastEventId` for stream
|
|
68
|
+
* resumption across requests.
|
|
69
|
+
*/
|
|
70
|
+
onTurnComplete?: (event: {
|
|
71
|
+
chatId: string;
|
|
72
|
+
lastEventId?: string;
|
|
73
|
+
}) => void | Promise<void>;
|
|
74
|
+
/** SSE timeout in seconds. @default 120 */
|
|
75
|
+
streamTimeoutSeconds?: number;
|
|
76
|
+
/**
|
|
77
|
+
* Default trigger config used when starting a new session for this
|
|
78
|
+
* chat. Folded into `sessions.start({...triggerConfig})` body.
|
|
79
|
+
*/
|
|
80
|
+
triggerConfig?: SessionTriggerConfig;
|
|
81
|
+
/**
|
|
82
|
+
* Override the Trigger.dev API base URL for the chat's `.in/append` and
|
|
83
|
+
* `.out` SSE endpoints. String form applies to both; pass a function to
|
|
84
|
+
* pick per endpoint. Defaults to `apiClientManager.baseURL` (whatever
|
|
85
|
+
* `@trigger.dev/sdk` was configured with — typically `TRIGGER_API_URL`
|
|
86
|
+
* env var).
|
|
87
|
+
*
|
|
88
|
+
* Session creation (`POST /api/v1/sessions`) and token mint
|
|
89
|
+
* (`POST /api/v1/auth/jwt/claims`) still flow through
|
|
90
|
+
* `apiClientManager` — pass equivalent options to
|
|
91
|
+
* `chat.createStartSessionAction` if you need those routed too.
|
|
92
|
+
*/
|
|
93
|
+
baseURL?: string | AgentChatBaseURLResolver;
|
|
94
|
+
/**
|
|
95
|
+
* Optional per-request fetch override. Receives the resolved URL, the
|
|
96
|
+
* RequestInit, and endpoint context. Use this for header injection
|
|
97
|
+
* (tracing), proxy routing, or custom retries. Applies to both the
|
|
98
|
+
* `.in/append` POSTs and the `.out` SSE GET.
|
|
99
|
+
*/
|
|
100
|
+
fetch?: AgentChatFetchOverride;
|
|
101
|
+
};
|
|
102
|
+
/** Parsed tool call from the stream. */
|
|
103
|
+
export type ChatToolCall = {
|
|
104
|
+
toolName: string;
|
|
105
|
+
toolCallId: string;
|
|
106
|
+
input: unknown;
|
|
107
|
+
};
|
|
108
|
+
/** Parsed tool result from the stream. */
|
|
109
|
+
export type ChatToolResult = {
|
|
110
|
+
toolCallId: string;
|
|
111
|
+
output: unknown;
|
|
112
|
+
};
|
|
113
|
+
/** Accumulated result after a stream completes. */
|
|
114
|
+
export type ChatStreamResult = {
|
|
115
|
+
text: string;
|
|
116
|
+
toolCalls: ChatToolCall[];
|
|
117
|
+
toolResults: ChatToolResult[];
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* A single turn's response stream from an agent.
|
|
121
|
+
*
|
|
122
|
+
* Pick one consumption mode:
|
|
123
|
+
* - `for await (const chunk of stream)` — typed UIMessageChunk iteration
|
|
124
|
+
* - `await stream.result()` — accumulated `{ text, toolCalls, toolResults }`
|
|
125
|
+
* - `await stream.text()` — just the text
|
|
126
|
+
* - `yield* stream.messages()` — sub-agent pattern (yields UIMessage snapshots)
|
|
127
|
+
*/
|
|
128
|
+
export declare class ChatStream {
|
|
129
|
+
private readonly _consumerStream;
|
|
130
|
+
private readonly _messageCollector?;
|
|
131
|
+
private resultPromise;
|
|
132
|
+
constructor(stream: ReadableStream<UIMessageChunk>, onAssistantMessage?: (message: UIMessage) => void);
|
|
133
|
+
/** The raw ReadableStream for direct use with AI SDK utilities. */
|
|
134
|
+
get stream(): ReadableStream<UIMessageChunk>;
|
|
135
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<UIMessageChunk>;
|
|
136
|
+
/**
|
|
137
|
+
* Yields accumulated UIMessage snapshots for the sub-agent tool pattern.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* const stream = await chat.sendMessage("Research this topic");
|
|
142
|
+
* yield* stream.messages();
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
messages(): AsyncGenerator<UIMessage, void, unknown>;
|
|
146
|
+
/** Consume the stream and return the accumulated result. */
|
|
147
|
+
result(): Promise<ChatStreamResult>;
|
|
148
|
+
/** Consume the stream and return just the text. */
|
|
149
|
+
text(): Promise<string>;
|
|
150
|
+
private consumeStream;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* A chat conversation with a Trigger.dev agent.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```ts
|
|
157
|
+
* // Simple usage
|
|
158
|
+
* const chat = new AgentChat<typeof myAgent>({ agent: "my-agent" });
|
|
159
|
+
* const text = await (await chat.sendMessage("Hello")).text();
|
|
160
|
+
* await chat.close();
|
|
161
|
+
*
|
|
162
|
+
* // Stateless request handler — persist and restore session
|
|
163
|
+
* const chat = new AgentChat<typeof myAgent>({
|
|
164
|
+
* agent: "my-agent",
|
|
165
|
+
* id: chatId,
|
|
166
|
+
* session: { lastEventId: savedLastEventId },
|
|
167
|
+
* onTriggered: ({ runId }) => db.save(chatId, { runId }),
|
|
168
|
+
* onTurnComplete: ({ lastEventId }) => db.update(chatId, { lastEventId }),
|
|
169
|
+
* });
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export declare class AgentChat<TAgent = unknown> {
|
|
173
|
+
private readonly taskId;
|
|
174
|
+
private readonly chatId;
|
|
175
|
+
private readonly streamTimeoutSeconds;
|
|
176
|
+
private readonly clientData;
|
|
177
|
+
private readonly triggerConfigDefault;
|
|
178
|
+
private readonly onTriggered;
|
|
179
|
+
private readonly onTurnComplete;
|
|
180
|
+
private readonly baseURLResolver;
|
|
181
|
+
private readonly fetchOverride;
|
|
182
|
+
private state;
|
|
183
|
+
constructor(options: AgentChatOptions<TAgent>);
|
|
184
|
+
/** The conversation ID. */
|
|
185
|
+
get id(): string;
|
|
186
|
+
/** Persistable session state — pass back via `options.session` to resume. */
|
|
187
|
+
get session(): ChatSession;
|
|
188
|
+
/**
|
|
189
|
+
* Eagerly start the session — creates the row and triggers the first
|
|
190
|
+
* run. The agent's `onPreload` hook fires immediately. Idempotent: a
|
|
191
|
+
* second call is a no-op.
|
|
192
|
+
*/
|
|
193
|
+
preload(options?: {
|
|
194
|
+
idleTimeoutInSeconds?: number;
|
|
195
|
+
}): Promise<ChatSession>;
|
|
196
|
+
/**
|
|
197
|
+
* Send a text message and get the response stream.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* const stream = await chat.sendMessage("Review PR #1");
|
|
202
|
+
* const text = await stream.text();
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
sendMessage(text: string, options?: {
|
|
206
|
+
abortSignal?: AbortSignal;
|
|
207
|
+
}): Promise<ChatStream>;
|
|
208
|
+
/** Send raw UIMessage-like objects. Use `sendMessage()` for simple text. */
|
|
209
|
+
sendRaw(messages: UIMessage[] | Array<{
|
|
210
|
+
id: string;
|
|
211
|
+
role: string;
|
|
212
|
+
parts?: unknown[];
|
|
213
|
+
[key: string]: unknown;
|
|
214
|
+
}>, options?: {
|
|
215
|
+
trigger?: "submit-message" | "regenerate-message";
|
|
216
|
+
abortSignal?: AbortSignal;
|
|
217
|
+
}): Promise<ReadableStream<UIMessageChunk>>;
|
|
218
|
+
/** Send a steering message during an active stream. */
|
|
219
|
+
steer(text: string): Promise<boolean>;
|
|
220
|
+
/** Stop the current generation (agent stays alive for next turn). */
|
|
221
|
+
stop(): Promise<void>;
|
|
222
|
+
/**
|
|
223
|
+
* Hand over from a `chat.handover` route handler to a parked
|
|
224
|
+
* `handover-prepare` agent run. Wakes the run, which seeds its
|
|
225
|
+
* accumulators with `partialAssistantMessage` and continues from
|
|
226
|
+
* tool execution onward — the model call for step 1 is skipped.
|
|
227
|
+
*
|
|
228
|
+
* Used internally by `chat.handover`; not part of the customer
|
|
229
|
+
* surface.
|
|
230
|
+
*/
|
|
231
|
+
sendHandover(args: {
|
|
232
|
+
partialAssistantMessage: ModelMessage[];
|
|
233
|
+
/**
|
|
234
|
+
* UI messageId from the customer's step-1 stream — propagated to
|
|
235
|
+
* the agent so its post-handover chunks merge into the same
|
|
236
|
+
* assistant message on the browser.
|
|
237
|
+
*/
|
|
238
|
+
messageId?: string;
|
|
239
|
+
/**
|
|
240
|
+
* Whether the customer's step 1 is the final response (pure-text
|
|
241
|
+
* finish). When true, the agent runs hooks but skips the LLM
|
|
242
|
+
* call. When false, the agent runs `streamText` which executes
|
|
243
|
+
* pending tool-calls and continues from step 2.
|
|
244
|
+
*/
|
|
245
|
+
isFinal: boolean;
|
|
246
|
+
}): Promise<void>;
|
|
247
|
+
/**
|
|
248
|
+
* Tell a parked `handover-prepare` agent run that the customer's
|
|
249
|
+
* first turn finished pure-text (no tool calls) — the run exits
|
|
250
|
+
* cleanly without making an LLM call.
|
|
251
|
+
*
|
|
252
|
+
* Used internally by `chat.handover`; not part of the customer
|
|
253
|
+
* surface.
|
|
254
|
+
*/
|
|
255
|
+
sendHandoverSkip(): Promise<void>;
|
|
256
|
+
/**
|
|
257
|
+
* Send a custom action to the agent.
|
|
258
|
+
*
|
|
259
|
+
* Actions are not turns. They wake the agent, fire `hydrateMessages`
|
|
260
|
+
* (if configured) and `onAction` only — no `onTurnStart` /
|
|
261
|
+
* `prepareMessages` / `onBeforeTurnComplete` / `onTurnComplete`, no
|
|
262
|
+
* `run()` invocation.
|
|
263
|
+
*
|
|
264
|
+
* The action payload is validated against the agent's `actionSchema`
|
|
265
|
+
* on the backend. Use `chat.history.*` inside `onAction` to mutate
|
|
266
|
+
* state. To produce a model response from the action, return a
|
|
267
|
+
* `StreamTextResult` (or `string` / `UIMessage`) from `onAction` —
|
|
268
|
+
* the returned stream is auto-piped over this stream. When `onAction`
|
|
269
|
+
* returns `void`, the action is side-effect-only and the returned
|
|
270
|
+
* stream completes immediately with `trigger:turn-complete`.
|
|
271
|
+
*
|
|
272
|
+
* @returns A `ChatStream`. For void actions the stream completes
|
|
273
|
+
* immediately. For actions that return a model response, the stream
|
|
274
|
+
* carries the assistant chunks.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* const stream = await agentChat.sendAction({ type: "undo" });
|
|
279
|
+
* for await (const chunk of stream) {
|
|
280
|
+
* if (chunk.type === "text-delta") process.stdout.write(chunk.delta);
|
|
281
|
+
* }
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
sendAction(action: unknown, options?: {
|
|
285
|
+
abortSignal?: AbortSignal;
|
|
286
|
+
}): Promise<ChatStream>;
|
|
287
|
+
/** Close the conversation — agent exits its loop gracefully. */
|
|
288
|
+
close(): Promise<boolean>;
|
|
289
|
+
/** Reconnect to the response stream (e.g. after a disconnect). */
|
|
290
|
+
reconnect(abortSignal?: AbortSignal): Promise<ReadableStream<UIMessageChunk> | null>;
|
|
291
|
+
private resolveBaseURL;
|
|
292
|
+
private doFetch;
|
|
293
|
+
private appendInputChunk;
|
|
294
|
+
/**
|
|
295
|
+
* Idempotent: `sessions.start` upserts on `(env, externalId)`. Two
|
|
296
|
+
* concurrent AgentChat instances on the same chatId converge to the
|
|
297
|
+
* same session.
|
|
298
|
+
*/
|
|
299
|
+
private ensureStarted;
|
|
300
|
+
private subscribeToSessionStream;
|
|
301
|
+
}
|