@kortyx/agent 0.26.2 → 0.27.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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.27.0](https://github.com/kortyx-io/kortyx/compare/agent-v0.26.2...agent-v0.27.0) (2026-09-23)
4
+
5
+
6
+ ### Features
7
+
8
+ * **chat:** add server-side transcript lifecycle hooks ([#240](https://github.com/kortyx-io/kortyx/issues/240)) ([f84a674](https://github.com/kortyx-io/kortyx/commit/f84a6749819ee7bab343efb03f38eae743de0655))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @kortyx/runtime bumped to 0.21.3
16
+ * @kortyx/stream bumped to 0.14.0
17
+
3
18
  ## [0.26.2](https://github.com/kortyx-io/kortyx/compare/agent-v0.26.1...agent-v0.26.2) (2026-09-22)
4
19
 
5
20
 
@@ -11,6 +11,7 @@ type ChatMessage = {
11
11
  interface StreamChatFromRouteArgs {
12
12
  endpoint: string;
13
13
  sessionId?: string | undefined;
14
+ clientTurnId?: string | undefined;
14
15
  workflowId?: string | undefined;
15
16
  messages: ChatMessage[];
16
17
  fetchImpl?: typeof fetch;
package/dist/browser.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { S as StreamChatFromRouteArgs, s as streamChatFromRoute } from './browser-wjeg_MwV.js';
1
+ export { S as StreamChatFromRouteArgs, s as streamChatFromRoute } from './browser-EVWVR9BO.js';
2
2
  import '@kortyx/stream/browser';
package/dist/browser.js CHANGED
@@ -32,6 +32,7 @@ async function* streamChatFromRoute(args) {
32
32
  ...args.headers ? { headers: args.headers } : {},
33
33
  body: {
34
34
  sessionId: args.sessionId,
35
+ clientTurnId: args.clientTurnId,
35
36
  workflowId: args.workflowId,
36
37
  messages: args.messages
37
38
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/browser.ts","../src/adapters/http-client.ts"],"sourcesContent":["// Browser-safe exports for client bundles.\n// Keep this file free of Node-only imports (fs, path, etc).\n\nexport type { StreamChatFromRouteArgs } from \"./adapters/http-client\";\nexport { streamChatFromRoute } from \"./adapters/http-client\";\n","import { type StreamChunk, streamFromRoute } from \"@kortyx/stream/browser\";\nimport type { ChatMessage } from \"../types/chat-message\";\n\nexport interface StreamChatFromRouteArgs {\n endpoint: string;\n sessionId?: string | undefined;\n workflowId?: string | undefined;\n messages: ChatMessage[];\n fetchImpl?: typeof fetch;\n headers?: Record<string, string> | undefined;\n}\n\nexport async function* streamChatFromRoute(\n args: StreamChatFromRouteArgs,\n): AsyncGenerator<StreamChunk, void, void> {\n yield* streamFromRoute({\n endpoint: args.endpoint,\n ...(args.fetchImpl ? { fetchImpl: args.fetchImpl } : {}),\n ...(args.headers ? { headers: args.headers } : {}),\n body: {\n sessionId: args.sessionId,\n workflowId: args.workflowId,\n messages: args.messages,\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAAkD;AAYlD,gBAAuB,oBACrB,MACyC;AACzC,aAAO,gCAAgB;AAAA,IACrB,UAAU,KAAK;AAAA,IACf,GAAI,KAAK,YAAY,EAAE,WAAW,KAAK,UAAU,IAAI,CAAC;AAAA,IACtD,GAAI,KAAK,UAAU,EAAE,SAAS,KAAK,QAAQ,IAAI,CAAC;AAAA,IAChD,MAAM;AAAA,MACJ,WAAW,KAAK;AAAA,MAChB,YAAY,KAAK;AAAA,MACjB,UAAU,KAAK;AAAA,IACjB;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../src/browser.ts","../src/adapters/http-client.ts"],"sourcesContent":["// Browser-safe exports for client bundles.\n// Keep this file free of Node-only imports (fs, path, etc).\n\nexport type { StreamChatFromRouteArgs } from \"./adapters/http-client\";\nexport { streamChatFromRoute } from \"./adapters/http-client\";\n","import { type StreamChunk, streamFromRoute } from \"@kortyx/stream/browser\";\nimport type { ChatMessage } from \"../types/chat-message\";\n\nexport interface StreamChatFromRouteArgs {\n endpoint: string;\n sessionId?: string | undefined;\n clientTurnId?: string | undefined;\n workflowId?: string | undefined;\n messages: ChatMessage[];\n fetchImpl?: typeof fetch;\n headers?: Record<string, string> | undefined;\n}\n\nexport async function* streamChatFromRoute(\n args: StreamChatFromRouteArgs,\n): AsyncGenerator<StreamChunk, void, void> {\n yield* streamFromRoute({\n endpoint: args.endpoint,\n ...(args.fetchImpl ? { fetchImpl: args.fetchImpl } : {}),\n ...(args.headers ? { headers: args.headers } : {}),\n body: {\n sessionId: args.sessionId,\n clientTurnId: args.clientTurnId,\n workflowId: args.workflowId,\n messages: args.messages,\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAAkD;AAalD,gBAAuB,oBACrB,MACyC;AACzC,aAAO,gCAAgB;AAAA,IACrB,UAAU,KAAK;AAAA,IACf,GAAI,KAAK,YAAY,EAAE,WAAW,KAAK,UAAU,IAAI,CAAC;AAAA,IACtD,GAAI,KAAK,UAAU,EAAE,SAAS,KAAK,QAAQ,IAAI,CAAC;AAAA,IAChD,MAAM;AAAA,MACJ,WAAW,KAAK;AAAA,MAChB,cAAc,KAAK;AAAA,MACnB,YAAY,KAAK;AAAA,MACjB,UAAU,KAAK;AAAA,IACjB;AAAA,EACF,CAAC;AACH;","names":[]}
package/dist/index.d.ts CHANGED
@@ -1,16 +1,31 @@
1
+ import { KortyxError, FailureDescriptor } from '@kortyx/core/errors';
2
+ import { FinalizedChatMessage, StreamChunk } from '@kortyx/stream';
1
3
  import { WorkflowDefinition, ExecutionLimits, TokenUsage, ExecutionLimitReached, ExecutionBudget, GraphState } from '@kortyx/core';
2
4
  import { GetProviderFn } from '@kortyx/providers';
3
5
  import { PendingRequestRecord, PendingRequestStore, CheckpointSummary, CheckpointId, SessionCheckpointRecord, RollbackSessionCheckpointResult, ForkSessionCheckpointResult, WorkflowRegistry, FrameworkAdapter, ExecutionRuntimeConfig } from '@kortyx/runtime';
4
- import { StreamChunk } from '@kortyx/stream';
5
6
  import { z } from 'zod';
6
- import { FailureDescriptor, KortyxError } from '@kortyx/core/errors';
7
7
  import * as _kortyx_hooks from '@kortyx/hooks';
8
8
  import { KortyxTelemetryConfig, EnsureWorkflowTopologyRequest } from '@kortyx/hooks';
9
- import { C as ChatMessage } from './browser-wjeg_MwV.js';
10
- export { S as StreamChatFromRouteArgs, s as streamChatFromRoute } from './browser-wjeg_MwV.js';
9
+ import { C as ChatMessage } from './browser-EVWVR9BO.js';
10
+ export { S as StreamChatFromRouteArgs, s as streamChatFromRoute } from './browser-EVWVR9BO.js';
11
11
  import { StreamEvent } from '@langchain/core/tracers/log_stream';
12
12
  import '@kortyx/stream/browser';
13
13
 
14
+ type ChatResponseStatus = "completed" | "failed" | "cancelled" | "interrupted";
15
+ type ChatResponseFinalized = {
16
+ sessionId: string;
17
+ runId: string;
18
+ clientTurnId: string;
19
+ status: ChatResponseStatus;
20
+ message: FinalizedChatMessage;
21
+ checkpointId?: string;
22
+ };
23
+ type ChatLifecyclePhase = "turn-accepted" | "response-finalized" | "forked" | "rolled-back";
24
+ declare class ChatLifecycleHookError extends KortyxError {
25
+ readonly phase: ChatLifecyclePhase;
26
+ constructor(phase: ChatLifecyclePhase, cause: unknown);
27
+ }
28
+
14
29
  type ExecutableWorkflow = WorkflowDefinition & {
15
30
  inputSchema: z.ZodType;
16
31
  outputSchema: z.ZodType<Record<string, unknown>>;
@@ -135,6 +150,9 @@ declare const projectWorkflowTopology: (args: {
135
150
  interface AgentProcessOptions {
136
151
  executionSignal?: AbortSignal | undefined;
137
152
  onExecution?: ((completion: Promise<void>) => void) | undefined;
153
+ clientTurnId?: string | undefined;
154
+ continueOnDisconnect?: boolean | undefined;
155
+ onResponseFinalized?: ((event: ChatResponseFinalized) => void | Promise<void>) | undefined;
138
156
  limits?: ExecutionLimits | undefined;
139
157
  abortSignal?: AbortSignal | undefined;
140
158
  sessionId?: string | undefined;
@@ -190,8 +208,52 @@ type ChatRequestBody = {
190
208
  workflowId?: string | undefined;
191
209
  stream?: boolean | undefined;
192
210
  context?: Record<string, unknown> | undefined;
211
+ clientTurnId?: string | undefined;
193
212
  messages: ChatMessage[];
194
213
  };
214
+ type ChatLifecycleErrorEvent = {
215
+ phase: ChatLifecyclePhase;
216
+ clientTurnId?: string;
217
+ error: ChatLifecycleHookError;
218
+ };
219
+ type ChatRouteHandlerOptions = {
220
+ agent: Agent;
221
+ errorStatus?: number | undefined;
222
+ onExecution?: ((completion: Promise<void>) => void) | undefined;
223
+ /** Defaults to cancel. Continue requires onExecution to retain host lifetime. */
224
+ disconnect?: "cancel" | "continue" | undefined;
225
+ onTurnAccepted?: ((event: {
226
+ request: Request;
227
+ sessionId: string;
228
+ clientTurnId: string;
229
+ userMessage: ChatMessage & {
230
+ role: "user";
231
+ };
232
+ kind: "prompt" | "interrupt-response";
233
+ }) => void | Promise<void>) | undefined;
234
+ onResponseFinalized?: ((event: ChatResponseFinalized & {
235
+ request: Request;
236
+ }) => void | Promise<void>) | undefined;
237
+ onLifecycleError?: ((event: ChatLifecycleErrorEvent) => void | Promise<void>) | undefined;
238
+ };
239
+ type CheckpointRouteHandlerOptions = {
240
+ agent: Agent;
241
+ errorStatus?: number | undefined;
242
+ onForked?: ((event: {
243
+ request: Request;
244
+ sourceSessionId: string;
245
+ newSessionId: string;
246
+ sourceCheckpointId: string;
247
+ newCheckpointId: string;
248
+ }) => void | Promise<void>) | undefined;
249
+ onRolledBack?: ((event: {
250
+ request: Request;
251
+ sessionId: string;
252
+ headCheckpointId: string;
253
+ invalidatedStructuredStreamIds: string[];
254
+ }) => void | Promise<void>) | undefined;
255
+ onLifecycleError?: ((event: ChatLifecycleErrorEvent) => void | Promise<void>) | undefined;
256
+ };
195
257
  type CheckpointRequestBody = {
196
258
  action: "list";
197
259
  sessionId: string;
@@ -215,22 +277,21 @@ declare function parseCheckpointRequestBody(value: unknown): CheckpointRequestBo
215
277
  declare function handleChatRequestBody(args: {
216
278
  abortSignal?: AbortSignal | undefined;
217
279
  onExecution?: ((completion: Promise<void>) => void) | undefined;
280
+ continueOnDisconnect?: boolean | undefined;
281
+ onResponseFinalized?: ((event: ChatResponseFinalized) => void | Promise<void>) | undefined;
218
282
  agent: Agent;
219
283
  body: ChatRequestBody;
220
284
  }): Promise<Response>;
221
- declare function createChatRouteHandler(args: {
222
- onExecution?: ((completion: Promise<void>) => void) | undefined;
223
- agent: Agent;
224
- errorStatus?: number | undefined;
225
- }): (request: Request) => Promise<Response>;
285
+ declare function createChatRouteHandler(args: ChatRouteHandlerOptions): (request: Request) => Promise<Response>;
226
286
  declare function handleCheckpointRequestBody(args: {
227
287
  agent: Agent;
228
288
  body: CheckpointRequestBody;
289
+ request?: Request | undefined;
290
+ onForked?: CheckpointRouteHandlerOptions["onForked"];
291
+ onRolledBack?: CheckpointRouteHandlerOptions["onRolledBack"];
292
+ onLifecycleError?: CheckpointRouteHandlerOptions["onLifecycleError"];
229
293
  }): Promise<Response>;
230
- declare function createCheckpointRouteHandler(args: {
231
- agent: Agent;
232
- errorStatus?: number | undefined;
233
- }): (request: Request) => Promise<Response>;
294
+ declare function createCheckpointRouteHandler(args: CheckpointRouteHandlerOptions): (request: Request) => Promise<Response>;
234
295
 
235
296
  type SelectWorkflowFn = (workflowId: string) => Promise<WorkflowDefinition>;
236
297
  type SaveMemoryFn = (sessionId: string, state: GraphState) => Promise<void>;
@@ -261,6 +322,9 @@ interface OrchestrateArgs {
261
322
  executionLeaseRelease?: (() => Promise<void>) | undefined;
262
323
  executionSignal?: AbortSignal | undefined;
263
324
  onExecution?: ((completion: Promise<void>) => void) | undefined;
325
+ clientTurnId?: string | undefined;
326
+ continueOnDisconnect?: boolean | undefined;
327
+ onResponseFinalized?: ((event: ChatResponseFinalized) => void | Promise<void>) | undefined;
264
328
  abortSignal?: AbortSignal | undefined;
265
329
  emitOutput?: boolean | undefined;
266
330
  onOutcome?: ((outcome: OrchestrationOutcome) => void) | undefined;
@@ -277,7 +341,7 @@ interface OrchestrateArgs {
277
341
  * Orchestrates runtime execution with mid-stream transitions emitted by
278
342
  * runtime events.
279
343
  */
280
- declare function orchestrateGraphStream({ sessionId, runId, graph, state, config: initialConfig, abortSignal: requestSignal, executionSignal, onExecution, emitOutput, onOutcome, selectWorkflow, knownWorkflowIds, frameworkAdapter, executionLeaseRelease, }: OrchestrateArgs): Promise<NodeJS.ReadableStream>;
344
+ declare function orchestrateGraphStream({ sessionId, runId, graph, state, config: initialConfig, abortSignal: requestSignal, executionSignal, onExecution, clientTurnId, continueOnDisconnect, onResponseFinalized, emitOutput, onOutcome, selectWorkflow, knownWorkflowIds, frameworkAdapter, executionLeaseRelease, }: OrchestrateArgs): Promise<NodeJS.ReadableStream>;
281
345
 
282
346
  interface ResumeMeta {
283
347
  token: string;
@@ -297,6 +361,9 @@ interface TryResumeArgs {
297
361
  abortSignal?: AbortSignal | undefined;
298
362
  executionSignal?: AbortSignal | undefined;
299
363
  onExecution?: ((completion: Promise<void>) => void) | undefined;
364
+ clientTurnId?: string | undefined;
365
+ continueOnDisconnect?: boolean | undefined;
366
+ onResponseFinalized?: OrchestrateArgs["onResponseFinalized"];
300
367
  lastMessage?: ChatMessage | undefined;
301
368
  meta?: ResumeMeta | undefined;
302
369
  emitOutput?: boolean | undefined;
@@ -310,7 +377,7 @@ interface TryResumeArgs {
310
377
  applyResumeSelection?: ApplyResumeSelection;
311
378
  frameworkAdapter?: FrameworkAdapter;
312
379
  }
313
- declare function tryPrepareResumeStream({ limits, abortSignal, executionSignal, onExecution, lastMessage, meta: suppliedMeta, emitOutput, onOutcome, validatePending, sessionId, config, selectWorkflow, knownWorkflowIds, defaultWorkflowId, applyResumeSelection, frameworkAdapter, }: TryResumeArgs): Promise<AsyncIterable<StreamChunk> | null>;
380
+ declare function tryPrepareResumeStream({ limits, abortSignal, executionSignal, onExecution, clientTurnId, continueOnDisconnect, onResponseFinalized, lastMessage, meta: suppliedMeta, emitOutput, onOutcome, validatePending, sessionId, config, selectWorkflow, knownWorkflowIds, defaultWorkflowId, applyResumeSelection, frameworkAdapter, }: TryResumeArgs): Promise<AsyncIterable<StreamChunk> | null>;
314
381
 
315
382
  interface RuntimeConfig {
316
383
  session?: {
@@ -322,6 +389,9 @@ interface StreamChatArgs<Options> {
322
389
  abortSignal?: AbortSignal | undefined;
323
390
  executionSignal?: AbortSignal | undefined;
324
391
  onExecution?: ((completion: Promise<void>) => void) | undefined;
392
+ clientTurnId?: string | undefined;
393
+ continueOnDisconnect?: boolean | undefined;
394
+ onResponseFinalized?: ((event: ChatResponseFinalized) => void | Promise<void>) | undefined;
325
395
  messages: ChatMessage[];
326
396
  options?: Options | undefined;
327
397
  sessionId?: string;
@@ -334,7 +404,7 @@ interface StreamChatArgs<Options> {
334
404
  getProvider: GetProviderFn;
335
405
  applyResumeSelection?: ApplyResumeSelection;
336
406
  }
337
- declare function streamChat<Options = unknown>({ messages, abortSignal, executionSignal, onExecution, options, sessionId, defaultWorkflowId, loadRuntimeConfig, selectWorkflow, workflowRegistry, knownWorkflowIds, frameworkAdapter, getProvider, applyResumeSelection, }: StreamChatArgs<Options>): Promise<AsyncIterable<StreamChunk>>;
407
+ declare function streamChat<Options = unknown>({ messages, abortSignal, executionSignal, onExecution, clientTurnId, continueOnDisconnect, onResponseFinalized, options, sessionId, defaultWorkflowId, loadRuntimeConfig, selectWorkflow, workflowRegistry, knownWorkflowIds, frameworkAdapter, getProvider, applyResumeSelection, }: StreamChatArgs<Options>): Promise<AsyncIterable<StreamChunk>>;
338
408
 
339
409
  interface TransformOptions {
340
410
  debug?: boolean;
@@ -350,4 +420,4 @@ declare function transformGraphStreamForUI(stream: AsyncIterable<StreamEvent>, o
350
420
 
351
421
  declare function extractLatestUserMessage(messages: ChatMessage[]): string;
352
422
 
353
- export { type Agent, type AgentProcessOptions, type AgentProjectTopologyOptions, type ApplyResumeSelection, ChatMessage, type ChatRequestBody, type CheckpointRequestBody, type CompiledGraphLike, type CreateAgentArgs, type ExecutableWorkflow, type ExecuteOptions, type ExecutionInfo, type ExecutionInterrupt, ExecutionRequestError, type ExecutionResult, type InterruptScope, type ListInterruptsOptions, type OrchestrateArgs, type PendingInterrupt, type ResumableInterrupt, type ResumeHandle, type ResumeMeta, type ResumeOptions, type ResumeResponse, type SaveMemoryFn, type SelectWorkflowFn, type StreamChatArgs, createAgent, createChatRouteHandler, createCheckpointRouteHandler, createFailureResponse, extractLatestUserMessage, handleChatRequestBody, handleCheckpointRequestBody, orchestrateGraphStream, parseChatRequestBody, parseCheckpointRequestBody, parseResumeMeta, projectWorkflowTopology, readRequestJson, streamChat, transformGraphStreamForUI, tryPrepareResumeStream };
423
+ export { type Agent, type AgentProcessOptions, type AgentProjectTopologyOptions, type ApplyResumeSelection, type ChatLifecycleErrorEvent, ChatLifecycleHookError, type ChatLifecyclePhase, ChatMessage, type ChatRequestBody, type ChatResponseFinalized, type ChatResponseStatus, type ChatRouteHandlerOptions, type CheckpointRequestBody, type CheckpointRouteHandlerOptions, type CompiledGraphLike, type CreateAgentArgs, type ExecutableWorkflow, type ExecuteOptions, type ExecutionInfo, type ExecutionInterrupt, ExecutionRequestError, type ExecutionResult, type InterruptScope, type ListInterruptsOptions, type OrchestrateArgs, type PendingInterrupt, type ResumableInterrupt, type ResumeHandle, type ResumeMeta, type ResumeOptions, type ResumeResponse, type SaveMemoryFn, type SelectWorkflowFn, type StreamChatArgs, createAgent, createChatRouteHandler, createCheckpointRouteHandler, createFailureResponse, extractLatestUserMessage, handleChatRequestBody, handleCheckpointRequestBody, orchestrateGraphStream, parseChatRequestBody, parseCheckpointRequestBody, parseResumeMeta, projectWorkflowTopology, readRequestJson, streamChat, transformGraphStreamForUI, tryPrepareResumeStream };