@kortyx/agent 0.28.0 → 0.30.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/index.d.ts CHANGED
@@ -1,208 +1,17 @@
1
- import { KortyxError, FailureDescriptor } from '@kortyx/core/errors';
2
- import { FinalizedChatMessage, StreamChunk } from '@kortyx/stream';
3
- import { WorkflowDefinition, ExecutionLimits, TokenUsage, ExecutionLimitReached, ExecutionBudget, GraphState } from '@kortyx/core';
1
+ import { a3 as ChatLifecyclePhase, a4 as ChatLifecycleHookError, a5 as Agent, a6 as ChatResponseFinalized, p as EvalJson, C as CreateEvalsOptions, S as EvalSuite, K as EvalRunOptions, L as EvalRunResult, t as EvalJudgeOptions, q as EvalJudge, r as EvalJudgeIdentity } from './studio-judge-BFF0TsT2.js';
2
+ export { a7 as AgentProcessOptions, a8 as AgentProjectTopologyOptions, a9 as ChatResponseStatus, aa as CreateAgentArgs, E as EvalCase, a as EvalCaseResult, c as EvalCommand, d as EvalConfigurationError, e as EvalContext, f as EvalCriterion, g as EvalCriterionResult, h as EvalDefaults, i as EvalExecution, j as EvalExecutionStatus, k as EvalExpectation, l as EvalGradeInput, m as EvalHandlerRef, n as EvalInterrupt, o as EvalIssue, s as EvalJudgeIdentitySchema, u as EvalJudgeUsage, v as EvalJudgeUsageSchema, w as EvalManifest, x as EvalManifestSchema, y as EvalObservation, A as EvalOutputExpectation, B as EvalPhase, D as EvalProgress, F as EvalProgressSchema, G as EvalRemoteRunRequest, H as EvalRemoteRunRequestSchema, I as EvalResponder, M as EvalRunResultSchema, N as EvalSetupContext, O as EvalStatus, P as EvalStep, Q as EvalStepResult, T as EvalSuiteSchema, U as EvalVerdict, W as EvalWireEvent, X as EvalWireEventSchema, ab as ExecutableWorkflow, ac as ExecuteOptions, ad as ExecutionInfo, ae as ExecutionInterrupt, af as ExecutionRequestError, ag as ExecutionResult, ah as InterruptScope, ai as ListInterruptsOptions, aj as PendingInterrupt, ak as ResumableInterrupt, al as ResumeHandle, am as ResumeOptions, an as ResumeResponse, Y as StudioEvalJudgeOptions, Z as StudioEvalJudgeRequestSchema, _ as StudioEvalJudgeResponseSchema, $ as StudioEvalStartRequestSchema, ao as createAgent, a0 as createStudioEvalJudge, a1 as defineSuite, a2 as parseEvalSuite, ap as projectWorkflowTopology } from './studio-judge-BFF0TsT2.js';
3
+ import { C as ChatMessage } from './chat-message-D4EsFcr1.js';
4
+ export { StreamChatFromRouteArgs, streamChatFromRoute } from './browser.js';
4
5
  import { GetProviderFn } from '@kortyx/providers';
5
- import { PendingRequestRecord, PendingRequestStore, CheckpointSummary, CheckpointId, SessionCheckpointRecord, RollbackSessionCheckpointResult, ForkSessionCheckpointResult, WorkflowRegistry, FrameworkAdapter, ExecutionRuntimeConfig } from '@kortyx/runtime';
6
- import { z } from 'zod';
6
+ import { PendingRequestRecord, FrameworkAdapter, WorkflowRegistry } from '@kortyx/runtime';
7
+ import { StreamChunk } from '@kortyx/stream';
8
+ import { ExecutionBudget, GraphState, WorkflowDefinition, ExecutionLimits } from '@kortyx/core';
7
9
  import * as _kortyx_hooks from '@kortyx/hooks';
8
- import { KortyxTelemetryConfig, EnsureWorkflowTopologyRequest } from '@kortyx/hooks';
9
- import { C as ChatMessage } from './browser-EVWVR9BO.js';
10
- export { S as StreamChatFromRouteArgs, s as streamChatFromRoute } from './browser-EVWVR9BO.js';
10
+ import { z } from 'zod';
11
11
  import { StreamEvent } from '@langchain/core/tracers/log_stream';
12
+ import '@kortyx/core/errors';
12
13
  import '@kortyx/stream/browser';
13
14
 
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
-
29
- type ExecutableWorkflow = WorkflowDefinition & {
30
- inputSchema: z.ZodType;
31
- outputSchema: z.ZodType<Record<string, unknown>>;
32
- };
33
- /** Serializable identity of a waiting request. Treat tokens as private credentials. */
34
- type ResumeHandle = {
35
- token: string;
36
- requestId: string;
37
- sessionId: string;
38
- runId: string;
39
- };
40
- type ResumeResponse = {
41
- type: "text";
42
- text: string;
43
- } | {
44
- type: "select";
45
- ids: string[];
46
- } | {
47
- type: "value";
48
- value: unknown;
49
- } | {
50
- type: "cancel";
51
- };
52
- type ExecutionInterrupt = {
53
- workflow: string;
54
- node: string;
55
- input: PendingRequestRecord["schema"] & {
56
- options: Array<{
57
- id: string;
58
- label: string;
59
- description?: string | undefined;
60
- }>;
61
- };
62
- };
63
- type ExecutionInfo = {
64
- runId: string;
65
- sessionId: string;
66
- checkpointId?: string;
67
- usage?: TokenUsage;
68
- };
69
- type ExecutionResult<T = Record<string, unknown>> = ExecutionInfo & ({
70
- status: "completed";
71
- data: T;
72
- } | {
73
- status: "suspended";
74
- reason?: "limit_reached";
75
- limit?: ExecutionLimitReached;
76
- interrupt: ExecutionInterrupt;
77
- resume: ResumeHandle;
78
- } | {
79
- status: "cancelled";
80
- reason: string;
81
- } | {
82
- status: "failed";
83
- error: Pick<FailureDescriptor, "code" | "message"> & Partial<FailureDescriptor>;
84
- });
85
- type ExecuteOptions<W extends ExecutableWorkflow> = {
86
- limits?: ExecutionLimits;
87
- abortSignal?: AbortSignal;
88
- workflow: W;
89
- input: z.input<W["inputSchema"]>;
90
- sessionId?: string;
91
- context?: Record<string, unknown>;
92
- };
93
- type ResumeOptions<W extends ExecutableWorkflow> = {
94
- limits?: ExecutionLimits;
95
- abortSignal?: AbortSignal;
96
- workflow: W;
97
- resume: ResumeHandle;
98
- response: ResumeResponse;
99
- };
100
- /** The command was rejected before starting work or claiming an interrupt. */
101
- declare class ExecutionRequestError extends KortyxError {
102
- name: string;
103
- constructor(code: string, message: string, cause?: unknown);
104
- }
105
-
106
- declare const scopeSchema: z.ZodObject<{
107
- sessionId: z.ZodOptional<z.ZodString>;
108
- runId: z.ZodOptional<z.ZodString>;
109
- context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
110
- }, z.core.$strict>;
111
- type InterruptScope = z.input<typeof scopeSchema>;
112
- type ListInterruptsOptions = InterruptScope & {
113
- status?: "pending";
114
- afterResponseCompleted?: boolean;
115
- };
116
- type PendingInterrupt = {
117
- id: string;
118
- status: "pending";
119
- runId: string;
120
- sessionId: string;
121
- workflow: string;
122
- node: string;
123
- createdAt: string;
124
- expiresAt: string;
125
- afterResponseCompleted: boolean;
126
- input: Omit<PendingRequestRecord["schema"], "meta"> & {
127
- options: Array<{
128
- id: string;
129
- label: string;
130
- description?: string;
131
- }>;
132
- };
133
- };
134
- type ResumableInterrupt = PendingInterrupt & {
135
- resume: ResumeHandle;
136
- };
137
- declare function createInterruptDiscovery(store: PendingRequestStore): {
138
- listInterrupts(options: ListInterruptsOptions): Promise<PendingInterrupt[]>;
139
- getInterrupt(id: string, scope: InterruptScope): Promise<ResumableInterrupt | null>;
140
- };
141
-
142
- /** Produces the topology-only, deterministic Contract A snapshot. */
143
- declare const projectWorkflowTopology: (args: {
144
- workflow: WorkflowDefinition;
145
- environment: string;
146
- service: NonNullable<KortyxTelemetryConfig["service"]>;
147
- knownWorkflowIds?: readonly string[] | undefined;
148
- }) => EnsureWorkflowTopologyRequest;
149
-
150
- interface AgentProcessOptions {
151
- executionSignal?: AbortSignal | undefined;
152
- onExecution?: ((completion: Promise<void>) => void) | undefined;
153
- clientTurnId?: string | undefined;
154
- continueOnDisconnect?: boolean | undefined;
155
- onResponseFinalized?: ((event: ChatResponseFinalized) => void | Promise<void>) | undefined;
156
- limits?: ExecutionLimits | undefined;
157
- abortSignal?: AbortSignal | undefined;
158
- sessionId?: string | undefined;
159
- workflowId?: string | undefined;
160
- context?: Record<string, unknown> | undefined;
161
- }
162
- type AgentTopologySnapshot = ReturnType<typeof projectWorkflowTopology>;
163
- interface AgentProjectTopologyOptions {
164
- environment: string;
165
- service: AgentTopologySnapshot["service"];
166
- }
167
- interface CreateAgentArgs {
168
- limits?: ExecutionLimits | undefined;
169
- getProvider?: GetProviderFn | undefined;
170
- workflows?: WorkflowDefinition[];
171
- workflowsDir?: string;
172
- workflowRegistry?: WorkflowRegistry;
173
- defaultWorkflowId?: string;
174
- frameworkAdapter?: FrameworkAdapter;
175
- telemetry?: ExecutionRuntimeConfig["telemetry"];
176
- }
177
- interface Agent extends ReturnType<typeof createInterruptDiscovery> {
178
- execute<W extends ExecutableWorkflow>(args: ExecuteOptions<W>): Promise<ExecutionResult<z.output<W["outputSchema"]>>>;
179
- execute(args: {
180
- limits?: ExecutionLimits;
181
- abortSignal?: AbortSignal;
182
- workflow: string;
183
- input: unknown;
184
- sessionId?: string;
185
- context?: Record<string, unknown>;
186
- }): Promise<ExecutionResult>;
187
- resume<W extends ExecutableWorkflow>(args: ResumeOptions<W>): Promise<ExecutionResult<z.output<W["outputSchema"]>>>;
188
- resume(args: {
189
- limits?: ExecutionLimits;
190
- abortSignal?: AbortSignal;
191
- workflow: string;
192
- resume: ResumeHandle;
193
- response: ResumeResponse;
194
- }): Promise<ExecutionResult>;
195
- projectTopology?: (options: AgentProjectTopologyOptions) => Promise<AgentTopologySnapshot[]>;
196
- streamChat: (messages: ChatMessage[], options?: AgentProcessOptions) => Promise<AsyncIterable<StreamChunk>>;
197
- listCheckpoints: (sessionId: string) => Promise<CheckpointSummary[]>;
198
- getCheckpoint: (id: CheckpointId) => Promise<SessionCheckpointRecord | null>;
199
- rollbackTo: (id: CheckpointId) => Promise<RollbackSessionCheckpointResult>;
200
- fork: (id: CheckpointId, options?: {
201
- newSessionId?: string;
202
- }) => Promise<ForkSessionCheckpointResult>;
203
- }
204
- declare function createAgent(args: CreateAgentArgs): Agent;
205
-
206
15
  type ChatRequestBody = {
207
16
  sessionId?: string | undefined;
208
17
  workflowId?: string | undefined;
@@ -406,6 +215,51 @@ interface StreamChatArgs<Options> {
406
215
  }
407
216
  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>>;
408
217
 
218
+ /** Run serializable conversations against the same agent used by the application. */
219
+ declare function createEvals<Params = EvalJson | undefined, Prepared = undefined>(options: CreateEvalsOptions<Params, Prepared>): {
220
+ listSuites(): EvalSuite[];
221
+ describe(): {
222
+ judge?: {
223
+ location?: "app" | "studio";
224
+ id: string;
225
+ version: string;
226
+ };
227
+ paramsSchema?: z.core.ZodStandardJSONSchemaPayload<z.ZodType<Params, unknown, z.core.$ZodTypeInternals<Params, unknown>>>;
228
+ schemaVersion: 1;
229
+ studioJudging: true;
230
+ suites: EvalSuite[];
231
+ responders: {
232
+ schemaVersion?: string;
233
+ schemaId?: string;
234
+ name: string;
235
+ }[];
236
+ references: string[];
237
+ };
238
+ run(args: EvalRunOptions): Promise<EvalRunResult>;
239
+ };
240
+
241
+ /** A separate model call: the evaluated agent never grades itself inside its workflow. */
242
+ declare function createEvalJudge({ model, id, version, }: EvalJudgeOptions): EvalJudge;
243
+
244
+ declare const getEvalSuiteRevision: (suite: EvalSuite) => string;
245
+
246
+ type EvalRunner = {
247
+ describe: () => {
248
+ schemaVersion: 1;
249
+ suites: readonly EvalSuite[];
250
+ studioJudging?: true;
251
+ judge?: EvalJudgeIdentity;
252
+ };
253
+ run: (args: EvalRunOptions) => Promise<EvalRunResult>;
254
+ };
255
+ /** Mount this Web Request handler in the consumer app. Keys never enter cases. */
256
+ declare function createEvalRouteHandler({ evals, serviceKey, maxCases, maxActiveRuns, }: {
257
+ evals: EvalRunner;
258
+ serviceKey: string;
259
+ maxCases?: number;
260
+ maxActiveRuns?: number;
261
+ }): (request: Request) => Promise<Response>;
262
+
409
263
  interface TransformOptions {
410
264
  debug?: boolean;
411
265
  emitStatus?: boolean;
@@ -420,4 +274,4 @@ declare function transformGraphStreamForUI(stream: AsyncIterable<StreamEvent>, o
420
274
 
421
275
  declare function extractLatestUserMessage(messages: ChatMessage[]): string;
422
276
 
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 };
277
+ export { Agent, type ApplyResumeSelection, type ChatLifecycleErrorEvent, ChatLifecycleHookError, ChatLifecyclePhase, ChatMessage, type ChatRequestBody, ChatResponseFinalized, type ChatRouteHandlerOptions, type CheckpointRequestBody, type CheckpointRouteHandlerOptions, type CompiledGraphLike, CreateEvalsOptions, EvalJson, EvalJudge, EvalJudgeIdentity, EvalJudgeOptions, EvalRunOptions, EvalRunResult, type EvalRunner, EvalSuite, type OrchestrateArgs, type ResumeMeta, type SaveMemoryFn, type SelectWorkflowFn, type StreamChatArgs, createChatRouteHandler, createCheckpointRouteHandler, createEvalJudge, createEvalRouteHandler, createEvals, createFailureResponse, extractLatestUserMessage, getEvalSuiteRevision, handleChatRequestBody, handleCheckpointRequestBody, orchestrateGraphStream, parseChatRequestBody, parseCheckpointRequestBody, parseResumeMeta, readRequestJson, streamChat, transformGraphStreamForUI, tryPrepareResumeStream };