@kortyx/agent 0.16.0 → 0.19.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,58 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.19.0](https://github.com/kortyx-io/kortyx/compare/agent-v0.18.0...agent-v0.19.0) (2026-09-11)
4
+
5
+
6
+ ### Features
7
+
8
+ * complete client responses while workflows continue in background ([#165](https://github.com/kortyx-io/kortyx/issues/165)) ([a8a08cd](https://github.com/kortyx-io/kortyx/commit/a8a08cd1e9533e4b44efa4af54a2d2cec54431ae))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @kortyx/runtime bumped to 0.15.0
16
+ * devDependencies
17
+ * @kortyx/hooks bumped to 0.22.0
18
+
19
+ ## [0.18.0](https://github.com/kortyx-io/kortyx/compare/agent-v0.17.0...agent-v0.18.0) (2026-09-10)
20
+
21
+
22
+ ### Features
23
+
24
+ * **runtime:** add shared execution limits and checkpoint continuation ([#163](https://github.com/kortyx-io/kortyx/issues/163)) ([e22232c](https://github.com/kortyx-io/kortyx/commit/e22232c059fae4f7df1bd36423902bd365887942))
25
+
26
+
27
+ ### Dependencies
28
+
29
+ * The following workspace dependencies were updated
30
+ * dependencies
31
+ * @kortyx/core bumped to 0.8.0
32
+ * @kortyx/runtime bumped to 0.14.0
33
+ * @kortyx/stream bumped to 0.11.0
34
+ * devDependencies
35
+ * @kortyx/hooks bumped to 0.21.0
36
+
37
+ ## [0.17.0](https://github.com/kortyx-io/kortyx/compare/agent-v0.16.0...agent-v0.17.0) (2026-09-10)
38
+
39
+
40
+ ### Features
41
+
42
+ * cancel workflow trees and reflect cancellation in Studio ([#161](https://github.com/kortyx-io/kortyx/issues/161)) ([699ad18](https://github.com/kortyx-io/kortyx/commit/699ad18905955c6340c3d85b9fae7f0bffd00a0d))
43
+ * execute and resume workflows without chat transport ([#159](https://github.com/kortyx-io/kortyx/issues/159)) ([6decb17](https://github.com/kortyx-io/kortyx/commit/6decb1714fedc021ac9e125b6ed9f75475ed928a))
44
+
45
+
46
+ ### Dependencies
47
+
48
+ * The following workspace dependencies were updated
49
+ * dependencies
50
+ * @kortyx/core bumped to 0.7.0
51
+ * @kortyx/runtime bumped to 0.13.0
52
+ * @kortyx/stream bumped to 0.10.0
53
+ * devDependencies
54
+ * @kortyx/hooks bumped to 0.20.0
55
+
3
56
  ## [0.16.0](https://github.com/kortyx-io/kortyx/compare/agent-v0.15.0...agent-v0.16.0) (2026-09-09)
4
57
 
5
58
 
package/dist/index.d.ts CHANGED
@@ -1,13 +1,129 @@
1
- import { WorkflowDefinition, GraphState } from '@kortyx/core';
1
+ import { WorkflowDefinition, ExecutionLimits, TokenUsage, ExecutionLimitReached, ExecutionBudget, GraphState } from '@kortyx/core';
2
2
  import { GetProviderFn } from '@kortyx/providers';
3
- import { CheckpointSummary, CheckpointId, SessionCheckpointRecord, RollbackSessionCheckpointResult, ForkSessionCheckpointResult, WorkflowRegistry, FrameworkAdapter, ExecutionRuntimeConfig, PendingRequestRecord } from '@kortyx/runtime';
3
+ import { PendingRequestRecord, PendingRequestStore, CheckpointSummary, CheckpointId, SessionCheckpointRecord, RollbackSessionCheckpointResult, ForkSessionCheckpointResult, WorkflowRegistry, FrameworkAdapter, ExecutionRuntimeConfig } from '@kortyx/runtime';
4
4
  import { StreamChunk } from '@kortyx/stream';
5
+ import { z } from 'zod';
6
+ import * as _kortyx_hooks from '@kortyx/hooks';
5
7
  import { KortyxTelemetryConfig, EnsureWorkflowTopologyRequest } from '@kortyx/hooks';
6
8
  import { C as ChatMessage } from './browser-wjeg_MwV.js';
7
9
  export { S as StreamChatFromRouteArgs, s as streamChatFromRoute } from './browser-wjeg_MwV.js';
8
10
  import { StreamEvent } from '@langchain/core/tracers/log_stream';
9
11
  import '@kortyx/stream/browser';
10
12
 
13
+ type ExecutableWorkflow = WorkflowDefinition & {
14
+ inputSchema: z.ZodType;
15
+ outputSchema: z.ZodType<Record<string, unknown>>;
16
+ };
17
+ /** Serializable identity of a waiting request. Treat tokens as private credentials. */
18
+ type ResumeHandle = {
19
+ token: string;
20
+ requestId: string;
21
+ sessionId: string;
22
+ runId: string;
23
+ };
24
+ type ResumeResponse = {
25
+ type: "text";
26
+ text: string;
27
+ } | {
28
+ type: "select";
29
+ ids: string[];
30
+ } | {
31
+ type: "cancel";
32
+ };
33
+ type ExecutionInterrupt = {
34
+ workflow: string;
35
+ node: string;
36
+ input: PendingRequestRecord["schema"] & {
37
+ options: Array<{
38
+ id: string;
39
+ label: string;
40
+ description?: string | undefined;
41
+ }>;
42
+ };
43
+ };
44
+ type ExecutionInfo = {
45
+ runId: string;
46
+ sessionId: string;
47
+ checkpointId?: string;
48
+ usage?: TokenUsage;
49
+ };
50
+ type ExecutionResult<T = Record<string, unknown>> = ExecutionInfo & ({
51
+ status: "completed";
52
+ data: T;
53
+ } | {
54
+ status: "suspended";
55
+ reason?: "limit_reached";
56
+ limit?: ExecutionLimitReached;
57
+ interrupt: ExecutionInterrupt;
58
+ resume: ResumeHandle;
59
+ } | {
60
+ status: "cancelled";
61
+ reason: string;
62
+ } | {
63
+ status: "failed";
64
+ error: {
65
+ code: string;
66
+ message: string;
67
+ };
68
+ });
69
+ type ExecuteOptions<W extends ExecutableWorkflow> = {
70
+ limits?: ExecutionLimits;
71
+ abortSignal?: AbortSignal;
72
+ workflow: W;
73
+ input: z.input<W["inputSchema"]>;
74
+ sessionId?: string;
75
+ context?: Record<string, unknown>;
76
+ };
77
+ type ResumeOptions<W extends ExecutableWorkflow> = {
78
+ limits?: ExecutionLimits;
79
+ abortSignal?: AbortSignal;
80
+ workflow: W;
81
+ resume: ResumeHandle;
82
+ response: ResumeResponse;
83
+ };
84
+ /** The command was rejected before starting work or claiming an interrupt. */
85
+ declare class ExecutionRequestError extends Error {
86
+ readonly code: string;
87
+ name: string;
88
+ constructor(code: string, message: string);
89
+ }
90
+
91
+ declare const scopeSchema: z.ZodObject<{
92
+ sessionId: z.ZodOptional<z.ZodString>;
93
+ runId: z.ZodOptional<z.ZodString>;
94
+ context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
95
+ }, z.core.$strict>;
96
+ type InterruptScope = z.input<typeof scopeSchema>;
97
+ type ListInterruptsOptions = InterruptScope & {
98
+ status?: "pending";
99
+ afterResponseCompleted?: boolean;
100
+ };
101
+ type PendingInterrupt = {
102
+ id: string;
103
+ status: "pending";
104
+ runId: string;
105
+ sessionId: string;
106
+ workflow: string;
107
+ node: string;
108
+ createdAt: string;
109
+ expiresAt: string;
110
+ afterResponseCompleted: boolean;
111
+ input: Omit<PendingRequestRecord["schema"], "meta"> & {
112
+ options: Array<{
113
+ id: string;
114
+ label: string;
115
+ description?: string;
116
+ }>;
117
+ };
118
+ };
119
+ type ResumableInterrupt = PendingInterrupt & {
120
+ resume: ResumeHandle;
121
+ };
122
+ declare function createInterruptDiscovery(store: PendingRequestStore): {
123
+ listInterrupts(options: ListInterruptsOptions): Promise<PendingInterrupt[]>;
124
+ getInterrupt(id: string, scope: InterruptScope): Promise<ResumableInterrupt | null>;
125
+ };
126
+
11
127
  /** Produces the topology-only, deterministic Contract A snapshot. */
12
128
  declare const projectWorkflowTopology: (args: {
13
129
  workflow: WorkflowDefinition;
@@ -17,6 +133,10 @@ declare const projectWorkflowTopology: (args: {
17
133
  }) => EnsureWorkflowTopologyRequest;
18
134
 
19
135
  interface AgentProcessOptions {
136
+ executionSignal?: AbortSignal | undefined;
137
+ onExecution?: ((completion: Promise<void>) => void) | undefined;
138
+ limits?: ExecutionLimits | undefined;
139
+ abortSignal?: AbortSignal | undefined;
20
140
  sessionId?: string | undefined;
21
141
  workflowId?: string | undefined;
22
142
  context?: Record<string, unknown> | undefined;
@@ -27,6 +147,7 @@ interface AgentProjectTopologyOptions {
27
147
  service: AgentTopologySnapshot["service"];
28
148
  }
29
149
  interface CreateAgentArgs {
150
+ limits?: ExecutionLimits | undefined;
30
151
  getProvider?: GetProviderFn | undefined;
31
152
  workflows?: WorkflowDefinition[];
32
153
  workflowsDir?: string;
@@ -35,7 +156,24 @@ interface CreateAgentArgs {
35
156
  frameworkAdapter?: FrameworkAdapter;
36
157
  telemetry?: ExecutionRuntimeConfig["telemetry"];
37
158
  }
38
- interface Agent {
159
+ interface Agent extends ReturnType<typeof createInterruptDiscovery> {
160
+ execute<W extends ExecutableWorkflow>(args: ExecuteOptions<W>): Promise<ExecutionResult<z.output<W["outputSchema"]>>>;
161
+ execute(args: {
162
+ limits?: ExecutionLimits;
163
+ abortSignal?: AbortSignal;
164
+ workflow: string;
165
+ input: unknown;
166
+ sessionId?: string;
167
+ context?: Record<string, unknown>;
168
+ }): Promise<ExecutionResult>;
169
+ resume<W extends ExecutableWorkflow>(args: ResumeOptions<W>): Promise<ExecutionResult<z.output<W["outputSchema"]>>>;
170
+ resume(args: {
171
+ limits?: ExecutionLimits;
172
+ abortSignal?: AbortSignal;
173
+ workflow: string;
174
+ resume: ResumeHandle;
175
+ response: ResumeResponse;
176
+ }): Promise<ExecutionResult>;
39
177
  projectTopology?: (options: AgentProjectTopologyOptions) => Promise<AgentTopologySnapshot[]>;
40
178
  streamChat: (messages: ChatMessage[], options?: AgentProcessOptions) => Promise<AsyncIterable<StreamChunk>>;
41
179
  listCheckpoints: (sessionId: string) => Promise<CheckpointSummary[]>;
@@ -71,10 +209,13 @@ type CheckpointRequestBody = {
71
209
  declare function parseChatRequestBody(value: unknown): ChatRequestBody;
72
210
  declare function parseCheckpointRequestBody(value: unknown): CheckpointRequestBody;
73
211
  declare function handleChatRequestBody(args: {
212
+ abortSignal?: AbortSignal | undefined;
213
+ onExecution?: ((completion: Promise<void>) => void) | undefined;
74
214
  agent: Agent;
75
215
  body: ChatRequestBody;
76
216
  }): Promise<Response>;
77
217
  declare function createChatRouteHandler(args: {
218
+ onExecution?: ((completion: Promise<void>) => void) | undefined;
78
219
  agent: Agent;
79
220
  errorStatus?: number | undefined;
80
221
  }): (request: Request) => Promise<Response>;
@@ -90,6 +231,11 @@ declare function createCheckpointRouteHandler(args: {
90
231
  type SelectWorkflowFn = (workflowId: string) => Promise<WorkflowDefinition>;
91
232
  type SaveMemoryFn = (sessionId: string, state: GraphState) => Promise<void>;
92
233
  interface CompiledGraphLike {
234
+ execution?: {
235
+ abortSignal?: AbortSignal | undefined;
236
+ budget?: ExecutionBudget | undefined;
237
+ completeResponse?: ((options: _kortyx_hooks.CompleteResponseOptions, state: GraphState) => Promise<void>) | undefined;
238
+ };
93
239
  config?: Record<string, unknown>;
94
240
  streamEvents: (state: GraphState, options?: {
95
241
  version?: string;
@@ -99,7 +245,19 @@ interface CompiledGraphLike {
99
245
  configurable?: Record<string, unknown>;
100
246
  }) => Promise<unknown>;
101
247
  }
248
+ type OrchestrationOutcome = {
249
+ cancelled?: boolean;
250
+ state: GraphState;
251
+ pending?: PendingRequestRecord | undefined;
252
+ checkpointId?: string | undefined;
253
+ error?: unknown;
254
+ };
102
255
  interface OrchestrateArgs {
256
+ executionSignal?: AbortSignal | undefined;
257
+ onExecution?: ((completion: Promise<void>) => void) | undefined;
258
+ abortSignal?: AbortSignal | undefined;
259
+ emitOutput?: boolean | undefined;
260
+ onOutcome?: ((outcome: OrchestrationOutcome) => void) | undefined;
103
261
  sessionId?: string;
104
262
  runId: string;
105
263
  graph: CompiledGraphLike;
@@ -113,7 +271,7 @@ interface OrchestrateArgs {
113
271
  * Orchestrates runtime execution with mid-stream transitions emitted by
114
272
  * runtime events.
115
273
  */
116
- declare function orchestrateGraphStream({ sessionId, runId, graph, state, config: initialConfig, selectWorkflow, knownWorkflowIds, frameworkAdapter, }: OrchestrateArgs): Promise<NodeJS.ReadableStream>;
274
+ declare function orchestrateGraphStream({ sessionId, runId, graph, state, config: initialConfig, abortSignal: requestSignal, executionSignal, onExecution, emitOutput, onOutcome, selectWorkflow, knownWorkflowIds, frameworkAdapter, }: OrchestrateArgs): Promise<NodeJS.ReadableStream>;
117
275
 
118
276
  interface ResumeMeta {
119
277
  token: string;
@@ -127,7 +285,15 @@ type ApplyResumeSelection = (args: {
127
285
  }) => Record<string, unknown> | null | undefined;
128
286
  declare function parseResumeMeta(msg: ChatMessage | undefined): ResumeMeta | null;
129
287
  interface TryResumeArgs {
130
- lastMessage: ChatMessage | undefined;
288
+ limits?: ExecutionLimits | undefined;
289
+ abortSignal?: AbortSignal | undefined;
290
+ executionSignal?: AbortSignal | undefined;
291
+ onExecution?: ((completion: Promise<void>) => void) | undefined;
292
+ lastMessage?: ChatMessage | undefined;
293
+ meta?: ResumeMeta | undefined;
294
+ emitOutput?: boolean | undefined;
295
+ onOutcome?: OrchestrateArgs["onOutcome"];
296
+ validatePending?: ((pending: PendingRequestRecord) => void | Promise<void>) | undefined;
131
297
  sessionId: string;
132
298
  config: Record<string, unknown>;
133
299
  selectWorkflow: SelectWorkflowFn;
@@ -136,7 +302,7 @@ interface TryResumeArgs {
136
302
  applyResumeSelection?: ApplyResumeSelection;
137
303
  frameworkAdapter?: FrameworkAdapter;
138
304
  }
139
- declare function tryPrepareResumeStream({ lastMessage, sessionId, config, selectWorkflow, knownWorkflowIds, defaultWorkflowId, applyResumeSelection, frameworkAdapter, }: TryResumeArgs): Promise<AsyncIterable<StreamChunk> | null>;
305
+ 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>;
140
306
 
141
307
  interface RuntimeConfig {
142
308
  session?: {
@@ -145,6 +311,9 @@ interface RuntimeConfig {
145
311
  [key: string]: unknown;
146
312
  }
147
313
  interface StreamChatArgs<Options> {
314
+ abortSignal?: AbortSignal | undefined;
315
+ executionSignal?: AbortSignal | undefined;
316
+ onExecution?: ((completion: Promise<void>) => void) | undefined;
148
317
  messages: ChatMessage[];
149
318
  options?: Options | undefined;
150
319
  sessionId?: string;
@@ -157,7 +326,7 @@ interface StreamChatArgs<Options> {
157
326
  getProvider: GetProviderFn;
158
327
  applyResumeSelection?: ApplyResumeSelection;
159
328
  }
160
- declare function streamChat<Options = unknown>({ messages, options, sessionId, defaultWorkflowId, loadRuntimeConfig, selectWorkflow, workflowRegistry, knownWorkflowIds, frameworkAdapter, getProvider, applyResumeSelection, }: StreamChatArgs<Options>): Promise<AsyncIterable<StreamChunk>>;
329
+ declare function streamChat<Options = unknown>({ messages, abortSignal, executionSignal, onExecution, options, sessionId, defaultWorkflowId, loadRuntimeConfig, selectWorkflow, workflowRegistry, knownWorkflowIds, frameworkAdapter, getProvider, applyResumeSelection, }: StreamChatArgs<Options>): Promise<AsyncIterable<StreamChunk>>;
161
330
 
162
331
  interface TransformOptions {
163
332
  debug?: boolean;
@@ -173,4 +342,4 @@ declare function transformGraphStreamForUI(stream: AsyncIterable<StreamEvent>, o
173
342
 
174
343
  declare function extractLatestUserMessage(messages: ChatMessage[]): string;
175
344
 
176
- export { type Agent, type AgentProcessOptions, type AgentProjectTopologyOptions, type ApplyResumeSelection, ChatMessage, type ChatRequestBody, type CheckpointRequestBody, type CompiledGraphLike, type CreateAgentArgs, type OrchestrateArgs, type ResumeMeta, type SaveMemoryFn, type SelectWorkflowFn, type StreamChatArgs, createAgent, createChatRouteHandler, createCheckpointRouteHandler, extractLatestUserMessage, handleChatRequestBody, handleCheckpointRequestBody, orchestrateGraphStream, parseChatRequestBody, parseCheckpointRequestBody, parseResumeMeta, projectWorkflowTopology, streamChat, transformGraphStreamForUI, tryPrepareResumeStream };
345
+ 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, extractLatestUserMessage, handleChatRequestBody, handleCheckpointRequestBody, orchestrateGraphStream, parseChatRequestBody, parseCheckpointRequestBody, parseResumeMeta, projectWorkflowTopology, streamChat, transformGraphStreamForUI, tryPrepareResumeStream };