@trigger.dev/sdk 4.5.0-rc.3 → 4.5.0-rc.5
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/imports/ai-runtime-cjs.cjs.map +1 -0
- package/dist/commonjs/imports/ai-runtime.d.ts +1 -0
- package/dist/commonjs/imports/ai-runtime.js +27 -0
- package/dist/commonjs/v3/ai-shared.d.ts +16 -1
- package/dist/commonjs/v3/ai-shared.js.map +1 -1
- package/dist/commonjs/v3/ai.d.ts +81 -8
- package/dist/commonjs/v3/ai.js +138 -34
- package/dist/commonjs/v3/ai.js.map +1 -1
- package/dist/commonjs/v3/aiAutoTelemetry.d.ts +2 -0
- package/dist/commonjs/v3/aiAutoTelemetry.js +81 -0
- package/dist/commonjs/v3/aiAutoTelemetry.js.map +1 -0
- package/dist/commonjs/v3/chat-client.js +5 -3
- package/dist/commonjs/v3/chat-client.js.map +1 -1
- package/dist/commonjs/v3/chat-server.d.ts +29 -6
- package/dist/commonjs/v3/chat-server.js +6 -4
- package/dist/commonjs/v3/chat-server.js.map +1 -1
- package/dist/commonjs/v3/chat.d.ts +11 -0
- package/dist/commonjs/v3/chat.js +61 -1
- package/dist/commonjs/v3/chat.js.map +1 -1
- package/dist/commonjs/v3/shared.js +17 -9
- package/dist/commonjs/v3/shared.js.map +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/imports/ai-runtime.d.ts +2 -0
- package/dist/esm/imports/ai-runtime.js +16 -0
- package/dist/esm/imports/ai-runtime.js.map +1 -0
- package/dist/esm/v3/ai-shared.d.ts +16 -1
- package/dist/esm/v3/ai-shared.js.map +1 -1
- package/dist/esm/v3/ai.d.ts +81 -8
- package/dist/esm/v3/ai.js +109 -5
- package/dist/esm/v3/ai.js.map +1 -1
- package/dist/esm/v3/aiAutoTelemetry.d.ts +2 -0
- package/dist/esm/v3/aiAutoTelemetry.js +78 -0
- package/dist/esm/v3/aiAutoTelemetry.js.map +1 -0
- package/dist/esm/v3/chat-client.js +3 -1
- package/dist/esm/v3/chat-client.js.map +1 -1
- package/dist/esm/v3/chat-server.d.ts +29 -6
- package/dist/esm/v3/chat-server.js +3 -1
- package/dist/esm/v3/chat-server.js.map +1 -1
- package/dist/esm/v3/chat.d.ts +11 -0
- package/dist/esm/v3/chat.js +61 -1
- package/dist/esm/v3/chat.js.map +1 -1
- package/dist/esm/v3/shared.js +18 -10
- package/dist/esm/v3/shared.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +11 -6
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-runtime-cjs.cjs","sourceRoot":"","sources":["../../../src/imports/ai-runtime-cjs.cts"],"names":[],"mappings":";AAAA,8EAA8E;AAC9E,iFAAiF;;AAEjF,aAAa;AACb,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzB,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,sBAAsB,GAAG,EAAE,CAAC,sBAAsB,CAAC;AAClE,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,WAAW,GAAG,EAAE,CAAC,WAAW,CAAC;AAC5C,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,UAAU,GAAG,EAAE,CAAC,UAAU,CAAC;AAC1C,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,WAAW,GAAG,EAAE,CAAC,WAAW,CAAC;AAC5C,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,YAAY,GAAG,EAAE,CAAC,YAAY,CAAC;AAC9C,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,UAAU,GAAG,EAAE,CAAC,UAAU,CAAC;AAC1C,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,mBAAmB,GAAG,EAAE,CAAC,mBAAmB,CAAC;AAC5D,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,WAAW,GAAG,EAAE,CAAC,WAAW,CAAC;AAC5C,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC;AAC9B,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,SAAS,GAAG,EAAE,CAAC,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// CJS variant of ./ai-runtime.ts — tshy swaps this in for the CommonJS build.
|
|
3
|
+
// `require("ai")` of an ESM-only package is supported on Node >=20.19 / >=22.12.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
const ai = require("ai");
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
module.exports.convertToModelMessages = ai.convertToModelMessages;
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
module.exports.dynamicTool = ai.dynamicTool;
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
module.exports.generateId = ai.generateId;
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
module.exports.getToolName = ai.getToolName;
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
module.exports.isToolUIPart = ai.isToolUIPart;
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
module.exports.jsonSchema = ai.jsonSchema;
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
module.exports.readUIMessageStream = ai.readUIMessageStream;
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
module.exports.stepCountIs = ai.stepCountIs;
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
module.exports.tool = ai.tool;
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
module.exports.zodSchema = ai.zodSchema;
|
|
27
|
+
//# sourceMappingURL=ai-runtime-cjs.cjs.map
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* import from `ai.ts`.
|
|
16
16
|
*/
|
|
17
17
|
import type { Task, AnyTask } from "@trigger.dev/core/v3";
|
|
18
|
-
import type { ModelMessage, UIMessage } from "ai";
|
|
18
|
+
import type { InferUITools, ModelMessage, ToolSet, UIDataTypes, UIMessage } from "ai";
|
|
19
19
|
/**
|
|
20
20
|
* Message-part `type` value for the pending-message data part the agent
|
|
21
21
|
* injects when a follow-up message arrives mid-turn.
|
|
@@ -171,6 +171,21 @@ export type InferChatClientData<TTask extends AnyTask> = TTask extends Task<stri
|
|
|
171
171
|
* ```
|
|
172
172
|
*/
|
|
173
173
|
export type InferChatUIMessage<TTask extends AnyTask> = TTask extends Task<string, ChatTaskWirePayload<infer TUIM extends UIMessage, any>, any> ? TUIM : UIMessage;
|
|
174
|
+
/**
|
|
175
|
+
* Derive the chat `UIMessage` type for a given tool set. The tool-part types
|
|
176
|
+
* (`tool-${name}` with typed input/output) are inferred from the tools. Use
|
|
177
|
+
* this to declare the message type from your tools (e.g. to pass to
|
|
178
|
+
* `chat.withUIMessage<...>()` or to type the frontend) without hand-writing
|
|
179
|
+
* the `UIMessage<unknown, UIDataTypes, InferUITools<...>>` triple.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* import type { InferChatUIMessageFromTools } from "@trigger.dev/sdk/ai";
|
|
184
|
+
* const tools = { search, readFile };
|
|
185
|
+
* type ChatUiMessage = InferChatUIMessageFromTools<typeof tools>;
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
export type InferChatUIMessageFromTools<TTools extends ToolSet> = UIMessage<unknown, UIDataTypes, InferUITools<TTools>>;
|
|
174
189
|
/**
|
|
175
190
|
* Upsert an incoming wire message into the customer's DB-backed chain
|
|
176
191
|
* inside a `hydrateMessages` hook. Returns `true` iff the chain was
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-shared.js","sourceRoot":"","sources":["../../../src/v3/ai-shared.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;
|
|
1
|
+
{"version":3,"file":"ai-shared.js","sourceRoot":"","sources":["../../../src/v3/ai-shared.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;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,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;YAC5D,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS;gBAAE,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;QAC3D,CAAC;aAAM,IAAI,CAAC,CAAC,KAAK,KAAK,oBAAoB,IAAI,CAAC,CAAC,KAAK,KAAK,eAAe,EAAE,CAAC;YAC3E,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS;gBAAE,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;QAC3D,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IACH,OAAO;QACL,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,KAAK,EAAE,SAAS;KACE,CAAC;AACvB,CAAC"}
|
package/dist/commonjs/v3/ai.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { AnyTask, type MachinePresetName, type RealtimeDefinedInputStream, type RealtimeDefinedStream, Task, type inferSchemaIn, type inferSchemaOut, type TaskIdentifier, type TaskOptions, type TaskSchema, type TaskRunContext, type TaskWithSchema } from "@trigger.dev/core/v3";
|
|
2
|
-
import type { FinishReason, ModelMessage, ToolSet, UIMessage, UIMessageChunk, UIMessageStreamOptions
|
|
3
|
-
|
|
2
|
+
import type { FinishReason, LanguageModelUsage, ModelMessage, Tool, ToolSet, UIMessage, UIMessageChunk, UIMessageStreamOptions } from "ai";
|
|
3
|
+
type ToolCallOptions = {
|
|
4
|
+
toolCallId: string;
|
|
5
|
+
messages?: ModelMessage[];
|
|
6
|
+
abortSignal?: AbortSignal;
|
|
7
|
+
experimental_context?: unknown;
|
|
8
|
+
context?: unknown;
|
|
9
|
+
};
|
|
4
10
|
import { locals } from "./locals.js";
|
|
5
11
|
import type { ResolvedPrompt } from "./prompt.js";
|
|
6
12
|
import type { ResolvedSkill } from "./skill.js";
|
|
@@ -10,6 +16,8 @@ export type { TaskRunContext } from "@trigger.dev/core/v3";
|
|
|
10
16
|
export type ToolCallExecutionOptions = {
|
|
11
17
|
toolCallId: string;
|
|
12
18
|
experimental_context?: unknown;
|
|
19
|
+
/** v7 name for the user context (`experimental_context` on v6). */
|
|
20
|
+
context?: unknown;
|
|
13
21
|
/** Chat context — only present when the tool runs inside a chat.agent turn. */
|
|
14
22
|
chatId?: string;
|
|
15
23
|
turn?: number;
|
|
@@ -225,7 +233,7 @@ export type ChatTaskSignals = {
|
|
|
225
233
|
* The full payload passed to a `chatAgent` run function.
|
|
226
234
|
* Extends `ChatTaskPayload` (the wire payload) with abort signals.
|
|
227
235
|
*/
|
|
228
|
-
export type ChatTaskRunPayload<TClientData = unknown> = ChatTaskPayload<TClientData> & ChatTaskSignals & {
|
|
236
|
+
export type ChatTaskRunPayload<TClientData = unknown, TTools extends ToolSet = ToolSet> = ChatTaskPayload<TClientData> & ChatTaskSignals & {
|
|
229
237
|
/**
|
|
230
238
|
* Task run context — same object as the `ctx` passed to a standard `task({ run })` handler’s second argument.
|
|
231
239
|
* Use for tags, metadata, parent run links, or any API that needs the full run record.
|
|
@@ -235,6 +243,21 @@ export type ChatTaskRunPayload<TClientData = unknown> = ChatTaskPayload<TClientD
|
|
|
235
243
|
previousTurnUsage?: LanguageModelUsage;
|
|
236
244
|
/** Cumulative token usage across all completed turns so far. */
|
|
237
245
|
totalUsage: LanguageModelUsage;
|
|
246
|
+
/**
|
|
247
|
+
* The resolved tool set for this turn, the same `tools` you declared on
|
|
248
|
+
* `chat.agent({ tools })` (or the result of the per-turn `tools` function).
|
|
249
|
+
* Pass straight to `streamText({ tools })` so you don't redeclare them:
|
|
250
|
+
*
|
|
251
|
+
* ```ts
|
|
252
|
+
* run: ({ messages, tools, signal }) =>
|
|
253
|
+
* streamText({ model, messages, tools, abortSignal: signal })
|
|
254
|
+
* ```
|
|
255
|
+
*
|
|
256
|
+
* Declaring `tools` on the config is also what lets the SDK re-run each
|
|
257
|
+
* tool's `toModelOutput` when it re-converts prior-turn history (see the
|
|
258
|
+
* `tools` option on `chat.agent`). Empty object when no `tools` were declared.
|
|
259
|
+
*/
|
|
260
|
+
tools: TTools;
|
|
238
261
|
};
|
|
239
262
|
/** Convenience re-export of the AI SDK's `LanguageModelUsage` type. */
|
|
240
263
|
export type ChatTurnUsage = LanguageModelUsage;
|
|
@@ -462,6 +485,24 @@ export type PrepareMessagesEvent<TClientData = unknown> = {
|
|
|
462
485
|
/** Custom data from the frontend. */
|
|
463
486
|
clientData?: TClientData;
|
|
464
487
|
};
|
|
488
|
+
/**
|
|
489
|
+
* Event passed to the per-turn `tools` function form on `chat.agent`.
|
|
490
|
+
*
|
|
491
|
+
* Use this when the active tool set depends on per-turn context (the user, a
|
|
492
|
+
* feature flag, etc.). Return the `ToolSet` to use for converting this turn's
|
|
493
|
+
* history. Only `inputSchema` and `toModelOutput` are read during conversion,
|
|
494
|
+
* so a lightweight map (no `execute`) is fine.
|
|
495
|
+
*/
|
|
496
|
+
export type ResolveToolsEvent<TClientData = unknown> = {
|
|
497
|
+
/** The chat session ID. */
|
|
498
|
+
chatId: string;
|
|
499
|
+
/** The current turn number (0-indexed). */
|
|
500
|
+
turn: number;
|
|
501
|
+
/** Whether this run is continuing an existing chat. */
|
|
502
|
+
continuation: boolean;
|
|
503
|
+
/** Custom data from the frontend. */
|
|
504
|
+
clientData?: TClientData;
|
|
505
|
+
};
|
|
465
506
|
/**
|
|
466
507
|
* Data shape for `data-compaction` stream chunks emitted during compaction.
|
|
467
508
|
* Use to type the `data` field when rendering compaction parts in the frontend.
|
|
@@ -1330,7 +1371,7 @@ export type ChatResumeEvent<TClientData = unknown, TUIM extends UIMessage = UIMe
|
|
|
1330
1371
|
/** Custom data from the frontend. */
|
|
1331
1372
|
clientData?: TClientData;
|
|
1332
1373
|
};
|
|
1333
|
-
export type ChatAgentOptions<TIdentifier extends string, TClientDataSchema extends TaskSchema | undefined = undefined, TUIMessage extends UIMessage = UIMessage, TActionSchema extends TaskSchema | undefined = undefined> = Omit<TaskOptions<TIdentifier, ChatTaskWirePayload<TUIMessage, inferSchemaIn<TClientDataSchema>>, unknown>, "run" | "retry"> & {
|
|
1374
|
+
export type ChatAgentOptions<TIdentifier extends string, TClientDataSchema extends TaskSchema | undefined = undefined, TUIMessage extends UIMessage = UIMessage, TActionSchema extends TaskSchema | undefined = undefined, TTools extends ToolSet = ToolSet> = Omit<TaskOptions<TIdentifier, ChatTaskWirePayload<TUIMessage, inferSchemaIn<TClientDataSchema>>, unknown>, "run" | "retry"> & {
|
|
1334
1375
|
/**
|
|
1335
1376
|
* Fallback machine preset to use when an attempt fails with an
|
|
1336
1377
|
* out-of-memory (OOM) error. Setting this enables a single OOM retry:
|
|
@@ -1425,6 +1466,38 @@ export type ChatAgentOptions<TIdentifier extends string, TClientDataSchema exten
|
|
|
1425
1466
|
onAction?: (event: ActionEvent<[
|
|
1426
1467
|
TActionSchema
|
|
1427
1468
|
] extends [TaskSchema] ? inferSchemaOut<TActionSchema> : unknown, inferSchemaOut<TClientDataSchema>, TUIMessage>) => Promise<unknown> | unknown;
|
|
1469
|
+
/**
|
|
1470
|
+
* The tools available to this agent.
|
|
1471
|
+
*
|
|
1472
|
+
* `chat.agent` doesn't call the model for you. Your tools still go to
|
|
1473
|
+
* `streamText({ tools })` inside `run()`. Declaring them here additionally
|
|
1474
|
+
* lets the SDK re-run each tool's
|
|
1475
|
+
* [`toModelOutput`](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling#tomodeloutput)
|
|
1476
|
+
* when it re-converts persisted history on later turns. Without this, the
|
|
1477
|
+
* AI SDK has no `tools` to look up `toModelOutput` against, so a tool's
|
|
1478
|
+
* transformed result (e.g. raw image bytes → an image content part, or a
|
|
1479
|
+
* sub-agent summary) silently degrades to its raw JSON output from turn 2
|
|
1480
|
+
* onward.
|
|
1481
|
+
*
|
|
1482
|
+
* Only `inputSchema` and `toModelOutput` are read during conversion (never
|
|
1483
|
+
* `execute`), so you may pass a lightweight map if you keep heavy execute
|
|
1484
|
+
* deps out of this module.
|
|
1485
|
+
*
|
|
1486
|
+
* Pass either a static `ToolSet` or a function of per-turn context (for
|
|
1487
|
+
* tools that depend on the user, a feature flag, etc.). The resolved set is
|
|
1488
|
+
* available on the `run()` payload as `tools`.
|
|
1489
|
+
*
|
|
1490
|
+
* @example
|
|
1491
|
+
* ```ts
|
|
1492
|
+
* const tools = { read_file, search };
|
|
1493
|
+
* chat.agent({
|
|
1494
|
+
* tools,
|
|
1495
|
+
* run: async ({ messages, tools, signal }) =>
|
|
1496
|
+
* streamText({ model, messages, tools, abortSignal: signal }),
|
|
1497
|
+
* });
|
|
1498
|
+
* ```
|
|
1499
|
+
*/
|
|
1500
|
+
tools?: TTools | ((event: ResolveToolsEvent<inferSchemaOut<TClientDataSchema>>) => TTools | Promise<TTools>);
|
|
1428
1501
|
/**
|
|
1429
1502
|
* The run function for the chat task.
|
|
1430
1503
|
*
|
|
@@ -1435,7 +1508,7 @@ export type ChatAgentOptions<TIdentifier extends string, TClientDataSchema exten
|
|
|
1435
1508
|
* **Auto-piping:** If this function returns a value with `.toUIMessageStream()`,
|
|
1436
1509
|
* the stream is automatically piped to the frontend.
|
|
1437
1510
|
*/
|
|
1438
|
-
run: (payload: ChatTaskRunPayload<inferSchemaOut<TClientDataSchema
|
|
1511
|
+
run: (payload: ChatTaskRunPayload<inferSchemaOut<TClientDataSchema>, TTools>) => Promise<unknown>;
|
|
1439
1512
|
/**
|
|
1440
1513
|
* Called once at the start of every run boot — for the initial run, for
|
|
1441
1514
|
* preloaded runs, AND for reactive continuation runs (post-cancel /
|
|
@@ -1899,7 +1972,7 @@ type ChatCustomAgentOptions<TIdentifier extends string, TClientDataSchema extend
|
|
|
1899
1972
|
clientDataSchema?: TClientDataSchema;
|
|
1900
1973
|
};
|
|
1901
1974
|
declare function chatCustomAgent<TIdentifier extends string, TClientDataSchema extends TaskSchema | undefined = undefined, TUIMessage extends UIMessage = UIMessage>(options: ChatCustomAgentOptions<TIdentifier, TClientDataSchema, TUIMessage>): Task<TIdentifier, ChatTaskWirePayload<TUIMessage, inferSchemaIn<TClientDataSchema>>, unknown>;
|
|
1902
|
-
declare function chatAgent<TIdentifier extends string, TClientDataSchema extends TaskSchema | undefined = undefined, TUIMessage extends UIMessage = UIMessage, TActionSchema extends TaskSchema | undefined = undefined>(options: ChatAgentOptions<TIdentifier, TClientDataSchema, TUIMessage, TActionSchema>): Task<TIdentifier, ChatTaskWirePayload<TUIMessage, inferSchemaIn<TClientDataSchema>>, unknown>;
|
|
1975
|
+
declare function chatAgent<TIdentifier extends string, TClientDataSchema extends TaskSchema | undefined = undefined, TUIMessage extends UIMessage = UIMessage, TActionSchema extends TaskSchema | undefined = undefined, TTools extends ToolSet = ToolSet>(options: ChatAgentOptions<TIdentifier, TClientDataSchema, TUIMessage, TActionSchema, TTools>): Task<TIdentifier, ChatTaskWirePayload<TUIMessage, inferSchemaIn<TClientDataSchema>>, unknown>;
|
|
1903
1976
|
/**
|
|
1904
1977
|
* Optional config for {@link chat.withUIMessage}. `streamOptions` become default
|
|
1905
1978
|
* static `toUIMessageStream()` settings; inner `chat.agent({ uiMessageStreamOptions })`
|
|
@@ -1958,7 +2031,7 @@ export interface ChatBuilder<TUIMessage extends UIMessage = UIMessage, TClientDa
|
|
|
1958
2031
|
* and omitted from options. Otherwise, it can still be set directly in options
|
|
1959
2032
|
* (backwards compatible).
|
|
1960
2033
|
*/
|
|
1961
|
-
agent: [TClientDataSchema] extends [undefined] ? <TId extends string, TInfer extends TaskSchema | undefined = undefined, TAction extends TaskSchema | undefined = undefined>(options: ChatAgentOptions<TId, TInfer, TUIMessage, TAction>) => Task<TId, ChatTaskWirePayload<TUIMessage, inferSchemaIn<TInfer>>, unknown> : <TId extends string, TAction extends TaskSchema | undefined = undefined>(options: Omit<ChatAgentOptions<TId, TClientDataSchema, TUIMessage, TAction>, "clientDataSchema">) => Task<TId, ChatTaskWirePayload<TUIMessage, inferSchemaIn<TClientDataSchema>>, unknown>;
|
|
2034
|
+
agent: [TClientDataSchema] extends [undefined] ? <TId extends string, TInfer extends TaskSchema | undefined = undefined, TAction extends TaskSchema | undefined = undefined, TTools extends ToolSet = ToolSet>(options: ChatAgentOptions<TId, TInfer, TUIMessage, TAction, TTools>) => Task<TId, ChatTaskWirePayload<TUIMessage, inferSchemaIn<TInfer>>, unknown> : <TId extends string, TAction extends TaskSchema | undefined = undefined, TTools extends ToolSet = ToolSet>(options: Omit<ChatAgentOptions<TId, TClientDataSchema, TUIMessage, TAction, TTools>, "clientDataSchema">) => Task<TId, ChatTaskWirePayload<TUIMessage, inferSchemaIn<TClientDataSchema>>, unknown>;
|
|
1962
2035
|
/**
|
|
1963
2036
|
* Create a custom agent with manual lifecycle control.
|
|
1964
2037
|
*
|
|
@@ -2560,7 +2633,7 @@ declare function chatLocal<T extends Record<string, unknown>>(options: {
|
|
|
2560
2633
|
* ```
|
|
2561
2634
|
*/
|
|
2562
2635
|
import type { InferChatClientData } from "./ai-shared.js";
|
|
2563
|
-
export type { InferChatClientData, InferChatUIMessage } from "./ai-shared.js";
|
|
2636
|
+
export type { InferChatClientData, InferChatUIMessage, InferChatUIMessageFromTools, } from "./ai-shared.js";
|
|
2564
2637
|
/**
|
|
2565
2638
|
* Options for {@link createChatStartSessionAction}.
|
|
2566
2639
|
*/
|