@trigger.dev/sdk 0.0.0-prerelease-20260908122921 → 0.0.0-prerelease-20260909071038
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/ai-shared.d.ts +15 -0
- package/dist/commonjs/v3/ai-shared.js +35 -1
- package/dist/commonjs/v3/ai-shared.js.map +1 -1
- package/dist/commonjs/v3/ai.d.ts +76 -9
- package/dist/commonjs/v3/ai.js +316 -222
- package/dist/commonjs/v3/ai.js.map +1 -1
- package/dist/commonjs/v3/chat-client.d.ts +8 -0
- package/dist/commonjs/v3/chat-client.js +199 -109
- package/dist/commonjs/v3/chat-client.js.map +1 -1
- package/dist/commonjs/v3/chat-react.d.ts +54 -0
- package/dist/commonjs/v3/chat-react.js +83 -0
- package/dist/commonjs/v3/chat-react.js.map +1 -1
- package/dist/commonjs/v3/chat.d.ts +11 -0
- package/dist/commonjs/v3/chat.js +36 -27
- package/dist/commonjs/v3/chat.js.map +1 -1
- package/dist/commonjs/v3/chatSnapshotIo.d.ts +2 -0
- package/dist/commonjs/v3/chatSnapshotIo.js +174 -0
- package/dist/commonjs/v3/chatSnapshotIo.js.map +1 -0
- package/dist/commonjs/v3/test/index.d.ts +1 -0
- package/dist/commonjs/v3/test/index.js +3 -1
- package/dist/commonjs/v3/test/index.js.map +1 -1
- package/dist/commonjs/v3/test/mock-chat-agent.d.ts +4 -4
- package/dist/commonjs/v3/test/mock-chat-agent.js +25 -4
- package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -1
- package/dist/commonjs/v3/test/transcript-storage-tests.d.ts +40 -0
- package/dist/commonjs/v3/test/transcript-storage-tests.js +258 -0
- package/dist/commonjs/v3/test/transcript-storage-tests.js.map +1 -0
- package/dist/commonjs/v3/transcriptStorage.d.ts +229 -0
- package/dist/commonjs/v3/transcriptStorage.js +321 -0
- package/dist/commonjs/v3/transcriptStorage.js.map +1 -0
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/v3/ai-shared.d.ts +15 -0
- package/dist/esm/v3/ai-shared.js +33 -0
- package/dist/esm/v3/ai-shared.js.map +1 -1
- package/dist/esm/v3/ai.d.ts +76 -9
- package/dist/esm/v3/ai.js +306 -217
- package/dist/esm/v3/ai.js.map +1 -1
- package/dist/esm/v3/chat-client.d.ts +8 -0
- package/dist/esm/v3/chat-client.js +200 -110
- package/dist/esm/v3/chat-client.js.map +1 -1
- package/dist/esm/v3/chat-react.d.ts +54 -0
- package/dist/esm/v3/chat-react.js +81 -0
- package/dist/esm/v3/chat-react.js.map +1 -1
- package/dist/esm/v3/chat.d.ts +11 -0
- package/dist/esm/v3/chat.js +36 -27
- package/dist/esm/v3/chat.js.map +1 -1
- package/dist/esm/v3/chatSnapshotIo.d.ts +2 -0
- package/dist/esm/v3/chatSnapshotIo.js +166 -0
- package/dist/esm/v3/chatSnapshotIo.js.map +1 -0
- package/dist/esm/v3/test/index.d.ts +1 -0
- package/dist/esm/v3/test/index.js +1 -0
- package/dist/esm/v3/test/index.js.map +1 -1
- package/dist/esm/v3/test/mock-chat-agent.d.ts +4 -4
- package/dist/esm/v3/test/mock-chat-agent.js +25 -4
- package/dist/esm/v3/test/mock-chat-agent.js.map +1 -1
- package/dist/esm/v3/test/transcript-storage-tests.d.ts +40 -0
- package/dist/esm/v3/test/transcript-storage-tests.js +255 -0
- package/dist/esm/v3/test/transcript-storage-tests.js.map +1 -0
- package/dist/esm/v3/transcriptStorage.d.ts +229 -0
- package/dist/esm/v3/transcriptStorage.js +309 -0
- package/dist/esm/v3/transcriptStorage.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/docs/ai-chat/actions.mdx +2 -2
- package/docs/ai-chat/background-injection.mdx +2 -0
- package/docs/ai-chat/compaction.mdx +2 -0
- package/docs/ai-chat/frontend.mdx +2 -0
- package/docs/ai-chat/lifecycle-hooks.mdx +6 -2
- package/docs/ai-chat/patterns/database-persistence.mdx +6 -2
- package/docs/ai-chat/patterns/persistence-and-replay.mdx +34 -23
- package/docs/ai-chat/reference.mdx +56 -5
- package/docs/ai-chat/transcript-storage.mdx +233 -0
- package/docs/config/extensions/syncEnvVars.mdx +6 -0
- package/docs/deploy-environment-variables.mdx +23 -2
- package/package.json +2 -2
- package/skills/trigger-authoring-chat-agent/SKILL.md +3 -2
- package/skills/trigger-chat-agent-advanced/SKILL.md +5 -5
|
@@ -139,3 +139,18 @@ export declare function slimSubmitMessageForWire<TMsg extends UIMessage | undefi
|
|
|
139
139
|
* long ID degrades to "not filterable by chat" rather than failing to start.
|
|
140
140
|
*/
|
|
141
141
|
export declare function chatRunTags(chatId: string, userTags?: string[]): string[];
|
|
142
|
+
/**
|
|
143
|
+
* A session body that ends without a turn-complete is only terminal when the
|
|
144
|
+
* server says the session settled — otherwise the turn is still running and
|
|
145
|
+
* the connection was lost (long-poll window closed, proxy restarted). Both
|
|
146
|
+
* transports resubscribe from the last event id, bounded so a permanently
|
|
147
|
+
* empty stream can't spin.
|
|
148
|
+
*/
|
|
149
|
+
export declare const MAX_EOF_RESUBSCRIBES = 5;
|
|
150
|
+
/**
|
|
151
|
+
* Backoff before the nth (1-based) EOF resubscribe, jittered so many clients
|
|
152
|
+
* dropped by the same window don't reconnect in lockstep. Resolves early on
|
|
153
|
+
* abort — otherwise a stop landing mid-backoff leaves the stream open for the
|
|
154
|
+
* rest of it.
|
|
155
|
+
*/
|
|
156
|
+
export declare function waitBeforeEofResubscribe(attempt: number, signal: AbortSignal): Promise<void>;
|
|
@@ -16,10 +16,11 @@
|
|
|
16
16
|
* import from `ai.ts`.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.PENDING_MESSAGE_INJECTED_TYPE = void 0;
|
|
19
|
+
exports.MAX_EOF_RESUBSCRIBES = exports.PENDING_MESSAGE_INJECTED_TYPE = void 0;
|
|
20
20
|
exports.upsertIncomingMessage = upsertIncomingMessage;
|
|
21
21
|
exports.slimSubmitMessageForWire = slimSubmitMessageForWire;
|
|
22
22
|
exports.chatRunTags = chatRunTags;
|
|
23
|
+
exports.waitBeforeEofResubscribe = waitBeforeEofResubscribe;
|
|
23
24
|
/**
|
|
24
25
|
* Message-part `type` value for the pending-message data part the agent
|
|
25
26
|
* injects when a follow-up message arrives mid-turn.
|
|
@@ -178,4 +179,37 @@ function chatRunTags(chatId, userTags = []) {
|
|
|
178
179
|
const tags = chatTag.length <= MAX_RUN_TAG_LENGTH ? [chatTag, ...userTags] : [...userTags];
|
|
179
180
|
return tags.slice(0, MAX_RUN_TAGS);
|
|
180
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* A session body that ends without a turn-complete is only terminal when the
|
|
184
|
+
* server says the session settled — otherwise the turn is still running and
|
|
185
|
+
* the connection was lost (long-poll window closed, proxy restarted). Both
|
|
186
|
+
* transports resubscribe from the last event id, bounded so a permanently
|
|
187
|
+
* empty stream can't spin.
|
|
188
|
+
*/
|
|
189
|
+
exports.MAX_EOF_RESUBSCRIBES = 5;
|
|
190
|
+
/**
|
|
191
|
+
* Backoff before the nth (1-based) EOF resubscribe, jittered so many clients
|
|
192
|
+
* dropped by the same window don't reconnect in lockstep. Resolves early on
|
|
193
|
+
* abort — otherwise a stop landing mid-backoff leaves the stream open for the
|
|
194
|
+
* rest of it.
|
|
195
|
+
*/
|
|
196
|
+
function waitBeforeEofResubscribe(attempt, signal) {
|
|
197
|
+
// An already-aborted signal never fires `abort` again, so a listener added
|
|
198
|
+
// here would wait out the whole backoff.
|
|
199
|
+
if (signal.aborted)
|
|
200
|
+
return Promise.resolve();
|
|
201
|
+
return new Promise((resolve) => {
|
|
202
|
+
let timer;
|
|
203
|
+
const done = () => {
|
|
204
|
+
clearTimeout(timer);
|
|
205
|
+
signal.removeEventListener("abort", done);
|
|
206
|
+
resolve();
|
|
207
|
+
};
|
|
208
|
+
const backoff = Math.min(100 * 2 ** (attempt - 1), 5_000);
|
|
209
|
+
timer = setTimeout(done, backoff * (0.5 + Math.random() * 0.5));
|
|
210
|
+
signal.addEventListener("abort", done);
|
|
211
|
+
if (signal.aborted)
|
|
212
|
+
done();
|
|
213
|
+
});
|
|
214
|
+
}
|
|
181
215
|
//# sourceMappingURL=ai-shared.js.map
|
|
@@ -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;;;;;;;;;;;;;;;GAeG;;;;;;;AAKH;;;GAGG;AACU,QAAA,6BAA6B,GAAG,+BAAwC,CAAC;AA0DtF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,+BACE,MAAc,EACd,KAGC;IAED,IAAI,KAAK,CAAC,OAAO,KAAK,gBAAgB;QAAE,OAAO,KAAK,CAAC;IACrD,IAAI,KAAK,CAAC,gBAAgB,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,MAAM,GAAG,KAAK,CAAC,gBAAgB,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACzE,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC1B,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;QACd,MAAM,WAAW,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,MAAM,CAAC,EAAE,CAAC,CAAC;QAChE,IAAI,WAAW,KAAK,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;IACvC,CAAC;IACD,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpB,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;GAMG;AACH,SAAS,0BAA0B,CACjC,KAAc;IAEd,OAAO,CACL,KAAK,KAAK,kB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AC,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;GAMG;AACU,QAAA,oBAAoB,GAAG,CAAC,CAAC;AAEtC;;;;;GAKG;AACH,kCAAyC,OAAe,EAAE,MAAmB;IAC3E,2EAA2E;IAC3E,yCAAyC;IACzC,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7C,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QACnC,IAAI,KAAoC,CAAC;QACzC,MAAM,IAAI,GAAG,GAAG,EAAE;YAChB,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC1C,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC;QACF,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;QAC1D,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC;QAChE,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACvC,IAAI,MAAM,CAAC,OAAO;YAAE,IAAI,EAAE,CAAC;IAC7B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/commonjs/v3/ai.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type AnyTask, type Task, type ApiClientConfiguration, type inferSchemaIn, type inferSchemaOut, type MachinePresetName, type RealtimeDefinedInputStream, type RealtimeDefinedStream, type TaskIdentifier, type TaskOptions, type TaskRunContext, type TaskSchema, type TaskWithSchema, type AnySessionChannel, type SessionChannelName } from "@trigger.dev/core/v3";
|
|
2
2
|
import type { streamText as aiStreamTextSignature, FinishReason, LanguageModelUsage, ModelMessage, SystemModelMessage, ProviderMetadata, Tool, ToolSet, UIMessage, UIMessageChunk, UIMessageStreamOptions } from "ai";
|
|
3
|
+
import { type TranscriptLoadResult, type TranscriptStorage } from "./transcriptStorage.js";
|
|
3
4
|
import { type ChatInputChunk, type ChatTaskWirePayload, type InferChatClientData, type InferChatUIMessage, type InferChatUIMessageFromTools, PENDING_MESSAGE_INJECTED_TYPE, upsertIncomingMessage } from "./ai-shared.js";
|
|
4
5
|
import { locals } from "./locals.js";
|
|
5
6
|
import type { ResolvedPrompt } from "./prompt.js";
|
|
@@ -33,8 +34,8 @@ type ChatTurnContext<TClientData = unknown> = {
|
|
|
33
34
|
continuation: boolean;
|
|
34
35
|
clientData?: TClientData;
|
|
35
36
|
};
|
|
36
|
-
export
|
|
37
|
-
export
|
|
37
|
+
export { __readChatSnapshotProductionPathForTests, __setReadChatSnapshotImplForTests, __setWriteChatSnapshotImplForTests, __writeChatSnapshotProductionPathForTests, } from "./chatSnapshotIo.js";
|
|
38
|
+
export { defaultStorage, memoryTranscriptStorage, reduceTranscriptChanges, snapshotTranscriptStorage, type LoadContextEvent, type MemoryTranscriptStorage, type TranscriptChange, type TranscriptChangeReason, type TranscriptChangeset, type TranscriptCursors, type TranscriptLoadOptions, type TranscriptLoadResult, type TranscriptScope, type TranscriptState, type TranscriptStorage, type TranscriptStorageContext, } from "./transcriptStorage.js";
|
|
38
39
|
type ReplaySessionOutTailImpl = <TUIMessage extends UIMessage>(sessionId: string, options?: {
|
|
39
40
|
lastEventId?: string;
|
|
40
41
|
}) => Promise<ReplaySessionOutTailResult<TUIMessage>>;
|
|
@@ -1162,8 +1163,9 @@ export type RecoveryPendingToolCall = {
|
|
|
1162
1163
|
* `chat.endRun()` with no buffered user messages, fresh chat, OOM retry
|
|
1163
1164
|
* after a successful turn-complete with no in-flight tail).
|
|
1164
1165
|
*
|
|
1165
|
-
*
|
|
1166
|
-
*
|
|
1166
|
+
* Fires regardless of who owns the model's context. With `hydrateMessages`
|
|
1167
|
+
* or a storage `loadContext`, the recovered tail reaches that hook in
|
|
1168
|
+
* `previousMessages` on the next turn.
|
|
1167
1169
|
*/
|
|
1168
1170
|
export type RecoveryBootEvent<TUIM extends UIMessage = UIMessage> = {
|
|
1169
1171
|
/** Task run context — same as `task({ run })` second-argument `ctx`. */
|
|
@@ -1232,8 +1234,9 @@ export type RecoveryBootResult<TUIM extends UIMessage = UIMessage> = {
|
|
|
1232
1234
|
* context, mutate its tool parts to inject synthesized results,
|
|
1233
1235
|
* collapse history, etc.
|
|
1234
1236
|
*
|
|
1235
|
-
*
|
|
1236
|
-
*
|
|
1237
|
+
* With `hydrateMessages` or a storage `loadContext`, this chain is what
|
|
1238
|
+
* the hook receives as `previousMessages` on the next turn; the hook's
|
|
1239
|
+
* return value is the chain the model sees.
|
|
1237
1240
|
*/
|
|
1238
1241
|
chain?: TUIM[];
|
|
1239
1242
|
/**
|
|
@@ -1768,9 +1771,9 @@ export type ChatAgentOptions<TIdentifier extends string, TClientDataSchema exten
|
|
|
1768
1771
|
* continuation after `chat.endRun()` with no buffered user, a fresh
|
|
1769
1772
|
* chat, or an OOM retry on top of a complete snapshot.
|
|
1770
1773
|
*
|
|
1771
|
-
*
|
|
1772
|
-
*
|
|
1773
|
-
*
|
|
1774
|
+
* Fires regardless of who owns the model's context; a `hydrateMessages`
|
|
1775
|
+
* hook or a storage `loadContext` receives the recovered tail in
|
|
1776
|
+
* `previousMessages` on the next turn.
|
|
1774
1777
|
*
|
|
1775
1778
|
* Defaults (returned when the hook is omitted or returns no field):
|
|
1776
1779
|
* - With two or more in-flight users, the partial and the user it
|
|
@@ -1900,6 +1903,32 @@ export type ChatAgentOptions<TIdentifier extends string, TClientDataSchema exten
|
|
|
1900
1903
|
* ```
|
|
1901
1904
|
*/
|
|
1902
1905
|
hydrateMessages?: (event: HydrateMessagesEvent<inferSchemaOut<TClientDataSchema>, TUIMessage>) => TUIMessage[] | Promise<TUIMessage[]>;
|
|
1906
|
+
/**
|
|
1907
|
+
* Where the conversation is persisted. The runtime calls `save` after
|
|
1908
|
+
* every turn, failed turn and history-changing action with the changes
|
|
1909
|
+
* since the last save, and `load` once when a new run boots to continue
|
|
1910
|
+
* the conversation.
|
|
1911
|
+
*
|
|
1912
|
+
* Defaults to `defaultStorage`, the platform's snapshot in object storage
|
|
1913
|
+
* that the Sessions dashboard renders. Bring your own to write each change
|
|
1914
|
+
* to your database; `memoryTranscriptStorage()` is the reference
|
|
1915
|
+
* implementation and `runTranscriptStorageTests` from
|
|
1916
|
+
* `@trigger.dev/sdk/ai/test` checks yours against the contract.
|
|
1917
|
+
*
|
|
1918
|
+
* A storage with `loadContext` also owns the model's context on every
|
|
1919
|
+
* turn, which is what `hydrateMessages` did. The two cannot be combined.
|
|
1920
|
+
*
|
|
1921
|
+
* @example
|
|
1922
|
+
* ```ts
|
|
1923
|
+
* chat.agent({
|
|
1924
|
+
* id: "my-chat",
|
|
1925
|
+
* storage: myPostgresTranscriptStorage,
|
|
1926
|
+
* run: async ({ messages, signal, streamText }) =>
|
|
1927
|
+
* streamText({ model, messages, abortSignal: signal }),
|
|
1928
|
+
* });
|
|
1929
|
+
* ```
|
|
1930
|
+
*/
|
|
1931
|
+
storage?: TranscriptStorage<inferSchemaOut<TClientDataSchema>>;
|
|
1903
1932
|
/**
|
|
1904
1933
|
* Called at the start of every turn, after message accumulation and `onChatStart` (turn 0),
|
|
1905
1934
|
* but before the `run` function executes.
|
|
@@ -3274,6 +3303,42 @@ export type ChatStartSessionResult = {
|
|
|
3274
3303
|
* ```
|
|
3275
3304
|
*/
|
|
3276
3305
|
declare function createChatStartSessionAction<TChat extends AnyTask = AnyTask>(taskId: string, options?: CreateChatStartSessionActionOptions): (params: ChatStartSessionParams<TChat>) => Promise<ChatStartSessionResult>;
|
|
3306
|
+
export type CreateChatLoadTranscriptActionOptions = {
|
|
3307
|
+
/**
|
|
3308
|
+
* Scope the action to a specific API client configuration (secret key,
|
|
3309
|
+
* base URL) instead of the process-wide one. The default storage reads
|
|
3310
|
+
* through this client.
|
|
3311
|
+
*/
|
|
3312
|
+
apiClient?: ApiClientConfiguration;
|
|
3313
|
+
/** Page size when the caller passes none. */
|
|
3314
|
+
limit?: number;
|
|
3315
|
+
};
|
|
3316
|
+
export type ChatLoadTranscriptParams<TClientData = unknown> = {
|
|
3317
|
+
chatId: string;
|
|
3318
|
+
clientData?: TClientData;
|
|
3319
|
+
limit?: number;
|
|
3320
|
+
before?: string;
|
|
3321
|
+
};
|
|
3322
|
+
/**
|
|
3323
|
+
* Creates a server-side helper that reads a conversation from a transcript
|
|
3324
|
+
* storage, for rendering history before the chat connects. Works the same
|
|
3325
|
+
* for every storage, the platform default included, so the browser never
|
|
3326
|
+
* reads a store directly and the secret key stays on the server.
|
|
3327
|
+
*
|
|
3328
|
+
* Wrap it in a Next.js server action (or any server-side handler), scope it
|
|
3329
|
+
* to the authenticated user through `clientData`, and pass the result to
|
|
3330
|
+
* `useLoadTranscript` in the browser.
|
|
3331
|
+
*
|
|
3332
|
+
* @example
|
|
3333
|
+
* ```ts
|
|
3334
|
+
* // actions.ts
|
|
3335
|
+
* "use server";
|
|
3336
|
+
* import { chat, defaultStorage } from "@trigger.dev/sdk/ai";
|
|
3337
|
+
*
|
|
3338
|
+
* export const loadTranscript = chat.createLoadTranscriptAction(defaultStorage, { limit: 50 });
|
|
3339
|
+
* ```
|
|
3340
|
+
*/
|
|
3341
|
+
declare function createChatLoadTranscriptAction<TClientData = unknown>(storage: TranscriptStorage<TClientData>, options?: CreateChatLoadTranscriptActionOptions): (params: ChatLoadTranscriptParams<TClientData>) => Promise<TranscriptLoadResult>;
|
|
3277
3342
|
export declare const chat: {
|
|
3278
3343
|
/** Create a chat agent. See {@link chatAgent}. */
|
|
3279
3344
|
agent: typeof chatAgent;
|
|
@@ -3285,6 +3350,8 @@ export declare const chat: {
|
|
|
3285
3350
|
withClientData: typeof withClientData;
|
|
3286
3351
|
/** Create a server-side helper for starting (or resuming) a Session for a chatId. See {@link createChatStartSessionAction}. */
|
|
3287
3352
|
createStartSessionAction: typeof createChatStartSessionAction;
|
|
3353
|
+
/** Returns a server-side helper that reads a conversation from a transcript storage. */
|
|
3354
|
+
createLoadTranscriptAction: typeof createChatLoadTranscriptAction;
|
|
3288
3355
|
/** Pipe a stream to the chat transport. See {@link pipeChat}. */
|
|
3289
3356
|
pipe: typeof pipeChat;
|
|
3290
3357
|
/** Return from `onAction` to run a turn on the edited history. See {@link chatTurn}. */
|