@cognidesk/core 0.0.1

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.
@@ -0,0 +1,1688 @@
1
+ import * as zod from 'zod';
2
+ import { z } from 'zod';
3
+ import { Attributes, Span } from '@opentelemetry/api';
4
+ import pino, { Logger } from 'pino';
5
+ import * as zod_v4_core from 'zod/v4/core';
6
+
7
+ interface UsageRecord {
8
+ inputTokens?: number;
9
+ outputTokens?: number;
10
+ cachedInputTokens?: number;
11
+ reasoningTokens?: number;
12
+ totalTokens?: number;
13
+ providerMetadata?: Record<string, unknown>;
14
+ }
15
+ interface ModelMessage {
16
+ role: "system" | "user" | "assistant" | "tool";
17
+ content: string;
18
+ name?: string;
19
+ toolCallId?: string;
20
+ toolCalls?: ModelToolCall[];
21
+ }
22
+ interface ModelToolDefinition {
23
+ name: string;
24
+ description?: string;
25
+ input: z.ZodType;
26
+ }
27
+ interface ModelToolCall {
28
+ id: string;
29
+ name: string;
30
+ input: unknown;
31
+ providerMetadata?: Record<string, unknown>;
32
+ }
33
+ interface TextGenerationInput {
34
+ role: ModelRole;
35
+ promptTask?: PromptTask;
36
+ promptPayload?: ModelVisiblePromptPayload;
37
+ messages: ModelMessage[];
38
+ responseFormat?: z.ZodType;
39
+ tools?: ModelToolDefinition[];
40
+ toolChoice?: "auto" | "none" | "required";
41
+ onTextDelta?(delta: string): void | Promise<void>;
42
+ signal?: AbortSignal;
43
+ }
44
+ interface TextGenerationOutput<T = unknown> {
45
+ text: string;
46
+ structured?: T;
47
+ toolCalls?: ModelToolCall[];
48
+ usage?: UsageRecord;
49
+ providerMetadata?: Record<string, unknown>;
50
+ }
51
+ interface EmbeddingInput {
52
+ role: "journeyEmbedding";
53
+ text: string;
54
+ signal?: AbortSignal;
55
+ }
56
+ interface EmbeddingOutput {
57
+ embedding: number[];
58
+ model: string;
59
+ dimensions: number;
60
+ usage?: UsageRecord;
61
+ providerMetadata?: Record<string, unknown>;
62
+ }
63
+ type ModelRole = "response" | "matcher" | "extraction" | "citationPostProcessing" | "journeyEmbedding" | "compaction";
64
+ type PromptProfileRole = Exclude<ModelRole, "journeyEmbedding">;
65
+ type PromptTask = "response" | "journey-matcher" | "transition-matcher" | "delegation-completion" | "extraction" | "citation-post-processing" | "compaction" | "generated-preamble";
66
+ type ModelVisiblePromptPayload = Record<string, unknown>;
67
+ interface StructuredOutputPromptMetadata {
68
+ required: boolean;
69
+ name: string;
70
+ schema?: unknown;
71
+ }
72
+ interface ModelPromptProfileRenderInput {
73
+ role: PromptProfileRole;
74
+ promptTask: PromptTask;
75
+ model: {
76
+ provider: string;
77
+ model: string;
78
+ logicalModelSlug?: string;
79
+ };
80
+ payload: ModelVisiblePromptPayload;
81
+ structuredOutput?: StructuredOutputPromptMetadata;
82
+ }
83
+ type ModelPromptProfileRender = (input: ModelPromptProfileRenderInput) => string | Promise<string>;
84
+ interface ModelPromptProfile {
85
+ readonly id: string;
86
+ readonly description?: string;
87
+ readonly logicalModelSlug?: string;
88
+ renderInstruction(input: ModelPromptProfileRenderInput): string | Promise<string>;
89
+ }
90
+ interface ModelAdapter {
91
+ readonly provider: string;
92
+ readonly model: string;
93
+ readonly promptProfile?: ModelPromptProfile;
94
+ generateText(input: TextGenerationInput): Promise<TextGenerationOutput>;
95
+ embed?(input: EmbeddingInput): Promise<EmbeddingOutput>;
96
+ }
97
+ type AgentModelAdapters = {
98
+ [Role in ModelRole]: ModelAdapter;
99
+ };
100
+ type AgentModelSet = AgentModelAdapters;
101
+
102
+ type MaybePromise$2<T> = Promise<T> | T;
103
+ type TelemetryContentMode = "redacted" | "full";
104
+ interface RuntimeTelemetryOptions {
105
+ enabled?: boolean;
106
+ content?: TelemetryContentMode;
107
+ }
108
+ interface RuntimeEventTelemetry {
109
+ traceId: string;
110
+ spanId?: string;
111
+ }
112
+ interface TelemetryContextSpanOptions {
113
+ attributes?: Attributes;
114
+ }
115
+ type TelemetrySpanRunner<T> = (span: Span) => MaybePromise$2<T>;
116
+ interface TelemetryContext {
117
+ startSpan(name: string, options?: TelemetryContextSpanOptions): Span;
118
+ withSpan<T>(name: string, run: TelemetrySpanRunner<T>): Promise<T>;
119
+ withSpan<T>(name: string, options: TelemetryContextSpanOptions, run: TelemetrySpanRunner<T>): Promise<T>;
120
+ setAttribute(name: string, value: string | number | boolean): void;
121
+ addEvent(name: string, attributes?: Attributes): void;
122
+ recordException(error: unknown): void;
123
+ }
124
+ declare const telemetrySpanNames: {
125
+ readonly runtimeInitialize: "cognidesk.runtime.initialize";
126
+ readonly runtimeCreateConversation: "cognidesk.runtime.create_conversation";
127
+ readonly runtimeEmitEvent: "cognidesk.runtime.emit_event";
128
+ readonly runtimeEmitIntermediateMessage: "cognidesk.runtime.emit_intermediate_message";
129
+ readonly runtimeEmitGeneratedPreamble: "cognidesk.runtime.emit_generated_preamble";
130
+ readonly runtimeEmitCustomEvent: "cognidesk.runtime.emit_custom_event";
131
+ readonly runtimeEmitJourneyEvent: "cognidesk.runtime.emit_journey_event";
132
+ readonly runtimeListEvents: "cognidesk.runtime.list_events";
133
+ readonly runtimeReplayConversation: "cognidesk.runtime.replay_conversation";
134
+ readonly runtimeSubmitWidget: "cognidesk.runtime.submit_widget";
135
+ readonly runtimeGetSnapshot: "cognidesk.runtime.get_snapshot";
136
+ readonly runtimeHandleUserMessage: "cognidesk.runtime.handle_user_message";
137
+ readonly runtimeCloseConversation: "cognidesk.runtime.close_conversation";
138
+ readonly runtimeRequestHandoff: "cognidesk.runtime.request_handoff";
139
+ readonly runtimeResumeConversation: "cognidesk.runtime.resume_conversation";
140
+ readonly runtimeCompactConversation: "cognidesk.runtime.compact_conversation";
141
+ readonly journeySelect: "cognidesk.journey.select";
142
+ readonly modelGenerate: "cognidesk.model.generate";
143
+ readonly toolExecute: "cognidesk.tool.execute";
144
+ readonly actionExecute: "cognidesk.action.execute";
145
+ readonly knowledgeRetrieve: "cognidesk.knowledge.retrieve";
146
+ };
147
+ declare const telemetryAttributes: {
148
+ readonly agentId: "cognidesk.agent.id";
149
+ readonly conversationId: "cognidesk.conversation.id";
150
+ readonly journeyId: "cognidesk.journey.id";
151
+ readonly stateId: "cognidesk.state.id";
152
+ readonly operation: "cognidesk.operation";
153
+ readonly modelRole: "cognidesk.model.role";
154
+ readonly modelProvider: "cognidesk.model.provider";
155
+ readonly modelName: "cognidesk.model.name";
156
+ readonly promptTask: "cognidesk.prompt.task";
157
+ readonly toolName: "cognidesk.tool.name";
158
+ readonly actionName: "cognidesk.action.name";
159
+ readonly knowledgeSourceName: "cognidesk.knowledge.source.name";
160
+ readonly success: "cognidesk.success";
161
+ readonly errorType: "cognidesk.error.type";
162
+ };
163
+ declare const telemetryEventNames: {
164
+ readonly runtimeEvent: "cognidesk.runtime.event";
165
+ readonly userMessage: "cognidesk.user.message";
166
+ readonly modelInput: "cognidesk.model.input";
167
+ readonly modelOutput: "cognidesk.model.output";
168
+ readonly toolInput: "cognidesk.tool.input";
169
+ readonly toolOutput: "cognidesk.tool.output";
170
+ readonly knowledgeItems: "cognidesk.knowledge.items";
171
+ };
172
+ type TelemetryOptionsCarrier = {
173
+ telemetry?: RuntimeTelemetryOptions;
174
+ };
175
+ type MetricKind = "runtime" | "model" | "tool" | "action" | "knowledge";
176
+ type TelemetryMetricOptions = {
177
+ kind: MetricKind;
178
+ attributes?: Attributes;
179
+ tokenUsage?: {
180
+ inputTokens?: number;
181
+ outputTokens?: number;
182
+ totalTokens?: number;
183
+ };
184
+ };
185
+ interface TelemetrySpanOptions {
186
+ name: string;
187
+ attributes?: Attributes;
188
+ metric?: TelemetryMetricOptions;
189
+ }
190
+ declare function telemetryEnabled(options: TelemetryOptionsCarrier): boolean;
191
+ declare function telemetryContentMode(options: TelemetryOptionsCarrier): TelemetryContentMode;
192
+ declare function withTelemetrySpan<T>(options: TelemetryOptionsCarrier, spanOptions: TelemetrySpanOptions, run: (span: Span) => MaybePromise$2<T>): Promise<T>;
193
+ declare function recordRuntimeEventMetric(options: TelemetryOptionsCarrier, attributes?: Attributes): void;
194
+ declare function addTelemetryContentEvent(options: TelemetryOptionsCarrier, name: string, attributes: Record<string, unknown>): void;
195
+ declare function activeRuntimeEventTelemetry(options: TelemetryOptionsCarrier): RuntimeEventTelemetry | undefined;
196
+ declare function createTelemetryContext(options: TelemetryOptionsCarrier): TelemetryContext;
197
+
198
+ type Primitive = string | number | boolean | bigint | symbol | null | undefined | Date;
199
+ type StringKey<T> = Extract<keyof T, string>;
200
+ type ContextPath<T> = T extends Primitive ? never : T extends readonly unknown[] ? never : {
201
+ [K in StringKey<T>]: T[K] extends Primitive | readonly unknown[] ? K : K | `${K}.${ContextPath<T[K]>}`;
202
+ }[StringKey<T>];
203
+ type ObjectSchema = z.ZodObject<Record<string, z.ZodType>>;
204
+ type InferSchema<TSchema extends z.ZodType> = z.infer<TSchema>;
205
+ interface ApplicationContextParts<TConversation, TTurn> {
206
+ conversation: TConversation;
207
+ turn: TTurn;
208
+ }
209
+ type GuardResult = boolean | {
210
+ allow: true;
211
+ } | {
212
+ allow: false;
213
+ code: string;
214
+ message?: string;
215
+ prompt?: WidgetPromptDefinition<WidgetDefinition>;
216
+ metadata?: Record<string, unknown>;
217
+ };
218
+ type GuardContext<TApp, TJourneyContext> = {
219
+ app: TApp;
220
+ context: TJourneyContext;
221
+ };
222
+ interface ToolExecutionContext<TInput, TApp = unknown> {
223
+ input: TInput;
224
+ app: TApp;
225
+ conversationId: string;
226
+ telemetry: TelemetryContext;
227
+ idempotencyKey?: string;
228
+ signal?: AbortSignal;
229
+ }
230
+ interface ToolDefinition<TName extends string = string, TInputSchema extends z.ZodType = z.ZodType, TOutputSchema extends z.ZodType = z.ZodType, TSideEffect extends boolean = boolean> {
231
+ kind: "tool";
232
+ name: TName;
233
+ description?: string;
234
+ input: TInputSchema;
235
+ output: TOutputSchema;
236
+ sideEffect: TSideEffect;
237
+ idempotencyKey?: (args: {
238
+ input: z.infer<TInputSchema>;
239
+ conversationId: string;
240
+ }) => string;
241
+ execute: (context: ToolExecutionContext<z.infer<TInputSchema>>) => Promise<z.infer<TOutputSchema>>;
242
+ }
243
+ type AnyTool = ToolDefinition<string, z.ZodType, z.ZodType, boolean>;
244
+ type SideEffectTool = ToolDefinition<string, z.ZodType, z.ZodType, true>;
245
+ interface WidgetDefinition<TKind extends string = string, TInputSchema extends z.ZodType = z.ZodType, TOutputSchema extends z.ZodType = z.ZodType> {
246
+ kind: TKind;
247
+ input: TInputSchema;
248
+ output: TOutputSchema;
249
+ }
250
+ interface WidgetPromptDefinition<TWidget extends WidgetDefinition = WidgetDefinition> {
251
+ widget: TWidget;
252
+ input: z.infer<TWidget["input"]>;
253
+ }
254
+ interface KnowledgeItem<TMetadata = unknown> {
255
+ id: string;
256
+ title?: string;
257
+ content: string;
258
+ score?: number;
259
+ metadata: TMetadata;
260
+ }
261
+ interface KnowledgeSource<TName extends string = string, TQuerySchema extends z.ZodType = z.ZodType, TMetadataSchema extends z.ZodType = z.ZodType> {
262
+ kind: "knowledgeSource";
263
+ name: TName;
264
+ query: TQuerySchema;
265
+ metadata: TMetadataSchema;
266
+ retrieve(input: {
267
+ query: z.infer<TQuerySchema>;
268
+ signal?: AbortSignal;
269
+ }): Promise<{
270
+ items: Array<KnowledgeItem<z.infer<TMetadataSchema>>>;
271
+ }>;
272
+ }
273
+ interface CustomRuntimeEventDefinition<TName extends string = string, TPayloadSchema extends z.ZodType = z.ZodType> {
274
+ kind: "customRuntimeEvent";
275
+ name: TName;
276
+ payload: TPayloadSchema;
277
+ visibleToModel?: boolean;
278
+ }
279
+ type AnyCustomRuntimeEvent = CustomRuntimeEventDefinition<string, z.ZodType>;
280
+
281
+ interface RuntimeEventBase<TType extends string, TData> {
282
+ id: string;
283
+ conversationId: string;
284
+ offset: number;
285
+ type: TType;
286
+ createdAt: string;
287
+ telemetry?: RuntimeEventTelemetry;
288
+ data: TData;
289
+ }
290
+ type ConversationLifecycle = "active" | "handoff" | "closed";
291
+ interface MessageSegment {
292
+ id: string;
293
+ text: string;
294
+ references?: SupportReference[];
295
+ }
296
+ type SupportReference = {
297
+ type: "knowledge";
298
+ id: string;
299
+ sourceName?: string;
300
+ title?: string;
301
+ metadata?: unknown;
302
+ } | {
303
+ type: "toolResult";
304
+ id: string;
305
+ };
306
+ type RuntimeEvent = RuntimeEventBase<"message.started", {
307
+ role: "assistant" | "user";
308
+ }> | RuntimeEventBase<"message.delta", {
309
+ textDelta: string;
310
+ }> | RuntimeEventBase<"message.completed", {
311
+ text: string;
312
+ segments?: MessageSegment[];
313
+ usage?: UsageRecord;
314
+ intermediate?: boolean;
315
+ visibleToModel?: boolean;
316
+ }> | RuntimeEventBase<"message.aborted", {
317
+ reason: string;
318
+ partialText?: string;
319
+ }> | RuntimeEventBase<"voice.segment.started", {
320
+ channelSegmentId: string;
321
+ connectionId: string;
322
+ adapter: string;
323
+ provider?: string;
324
+ }> | RuntimeEventBase<"voice.segment.ended", {
325
+ channelSegmentId: string;
326
+ connectionId?: string;
327
+ reason?: string;
328
+ }> | RuntimeEventBase<"voice.connection.failed", {
329
+ channelSegmentId: string;
330
+ connectionId?: string;
331
+ code: string;
332
+ message: string;
333
+ retryable?: boolean;
334
+ }> | RuntimeEventBase<"voice.interrupted", {
335
+ channelSegmentId: string;
336
+ connectionId?: string;
337
+ interruptedMessageId?: string;
338
+ source?: "userSpeech" | "adapter" | "provider";
339
+ reason?: string;
340
+ recordingReferenceId?: string;
341
+ offsetMs?: number;
342
+ }> | RuntimeEventBase<"voice.recording.started", {
343
+ channelSegmentId: string;
344
+ recordingReferenceId: string;
345
+ policy?: unknown;
346
+ }> | RuntimeEventBase<"voice.recording.completed", {
347
+ channelSegmentId: string;
348
+ recordingReferenceId: string;
349
+ uri?: string;
350
+ startedAt?: string;
351
+ endedAt?: string;
352
+ metadata?: unknown;
353
+ }> | RuntimeEventBase<"voice.transcript.committed", {
354
+ channelSegmentId: string;
355
+ speaker: "user" | "assistant";
356
+ messageEventId: string;
357
+ recordingReferenceId?: string;
358
+ startedAtMs?: number;
359
+ endedAtMs?: number;
360
+ transcriptionSource?: string;
361
+ metadata?: unknown;
362
+ }> | RuntimeEventBase<"journey.candidates.retrieved", {
363
+ journeyIds: string[];
364
+ }> | RuntimeEventBase<"journey.matched", {
365
+ candidates: Array<{
366
+ journeyId: string;
367
+ confidence: number;
368
+ reason?: string;
369
+ }>;
370
+ }> | RuntimeEventBase<"journey.activated", {
371
+ journeyId: string;
372
+ previousJourneyId?: string;
373
+ }> | RuntimeEventBase<"journey.completed", {
374
+ journeyId: string;
375
+ stateId?: string;
376
+ reason?: string;
377
+ }> | RuntimeEventBase<"journey.guard.denied", {
378
+ journeyId: string;
379
+ stateId?: string;
380
+ code: string;
381
+ message?: string;
382
+ metadata?: Record<string, unknown>;
383
+ }> | RuntimeEventBase<"journey.event.emitted", {
384
+ name: string;
385
+ payload: unknown;
386
+ routing: "none" | "activeJourneyOnly" | "full" | "targeted";
387
+ target?: {
388
+ journeyId?: string;
389
+ stateId?: string;
390
+ };
391
+ }> | RuntimeEventBase<"journey.state.entered", {
392
+ journeyId: string;
393
+ stateId: string;
394
+ }> | RuntimeEventBase<"journey.extraction.proposed", {
395
+ journeyId: string;
396
+ stateId: string;
397
+ fields: string[];
398
+ }> | RuntimeEventBase<"journey.extraction.accepted", {
399
+ journeyId: string;
400
+ stateId: string;
401
+ fields: string[];
402
+ }> | RuntimeEventBase<"action.started", {
403
+ actionName: string;
404
+ journeyId?: string;
405
+ stateId?: string;
406
+ }> | RuntimeEventBase<"action.completed", {
407
+ actionName: string;
408
+ success: boolean;
409
+ journeyId?: string;
410
+ stateId?: string;
411
+ error?: string;
412
+ }> | RuntimeEventBase<"tool.started", {
413
+ toolName: string;
414
+ journeyId?: string;
415
+ stateId?: string;
416
+ }> | RuntimeEventBase<"tool.completed", {
417
+ toolName: string;
418
+ success: boolean;
419
+ journeyId?: string;
420
+ stateId?: string;
421
+ result?: unknown;
422
+ error?: string;
423
+ }> | RuntimeEventBase<"knowledge.retrieved", {
424
+ sourceName: string;
425
+ itemIds: string[];
426
+ }> | RuntimeEventBase<"ui.prompted", {
427
+ promptId: string;
428
+ widgetKind: string;
429
+ input: unknown;
430
+ }> | RuntimeEventBase<"ui.submitted", {
431
+ promptId: string;
432
+ widgetKind: string;
433
+ output: unknown;
434
+ }> | RuntimeEventBase<"conversation.compaction.started", {
435
+ fromOffset: number;
436
+ toOffset: number;
437
+ }> | RuntimeEventBase<"conversation.compaction.completed", {
438
+ fromOffset: number;
439
+ toOffset: number;
440
+ schemaVersion: string;
441
+ }> | RuntimeEventBase<"handoff.requested", {
442
+ reason: string;
443
+ summary?: string;
444
+ payload?: unknown;
445
+ }> | RuntimeEventBase<"handoff.resumed", {
446
+ reason?: string;
447
+ payload?: unknown;
448
+ }> | RuntimeEventBase<"conversation.closed", {
449
+ reason?: string;
450
+ }> | RuntimeEventBase<"error", {
451
+ code: string;
452
+ message: string;
453
+ details?: unknown;
454
+ }> | RuntimeEventBase<`custom.${string}`, unknown>;
455
+
456
+ interface ConversationRecord<TConversationContext = unknown> {
457
+ id: string;
458
+ agentId: string;
459
+ lifecycle: ConversationLifecycle;
460
+ context: TConversationContext;
461
+ createdAt: string;
462
+ updatedAt: string;
463
+ }
464
+ type RuntimeEventInput<TType extends RuntimeEvent["type"] = RuntimeEvent["type"]> = Omit<Extract<RuntimeEvent, {
465
+ type: TType;
466
+ }>, "id" | "offset" | "createdAt" | "telemetry"> & {
467
+ id?: string;
468
+ createdAt?: string;
469
+ telemetry?: RuntimeEvent["telemetry"];
470
+ };
471
+ interface ListEventsOptions {
472
+ conversationId: string;
473
+ afterOffset?: number;
474
+ limit?: number;
475
+ }
476
+ interface CreateConversationInput<TConversationContext = unknown> {
477
+ id?: string;
478
+ agentId: string;
479
+ context: TConversationContext;
480
+ }
481
+ interface StorageAdapter {
482
+ initialize?(): Promise<void> | void;
483
+ createConversation<TConversationContext = unknown>(input: CreateConversationInput<TConversationContext>): Promise<ConversationRecord<TConversationContext>>;
484
+ getConversation<TConversationContext = unknown>(conversationId: string): Promise<ConversationRecord<TConversationContext> | null>;
485
+ updateConversationLifecycle(conversationId: string, lifecycle: ConversationLifecycle): Promise<ConversationRecord | null>;
486
+ appendEvent<TEvent extends RuntimeEventInput>(event: TEvent): Promise<RuntimeEvent>;
487
+ listEvents(options: ListEventsOptions): Promise<RuntimeEvent[]>;
488
+ saveSnapshot(snapshot: RuntimeSnapshot): Promise<void>;
489
+ getSnapshot(conversationId: string): Promise<RuntimeSnapshot | null>;
490
+ }
491
+
492
+ type ConversationChannel = "chat" | "voice";
493
+ type VoiceConnectionStatus = "starting" | "connected" | "ended" | "failed";
494
+ type VoiceSpeaker = "user" | "assistant";
495
+ interface VoiceIceServer {
496
+ urls: string | string[];
497
+ username?: string;
498
+ credential?: string;
499
+ }
500
+ interface VoiceRecordingPolicy {
501
+ enabled?: boolean;
502
+ requireConsent?: boolean;
503
+ mode?: "input" | "both";
504
+ metadata?: Record<string, unknown>;
505
+ }
506
+ interface VoiceSelection {
507
+ provider: string;
508
+ voice: string;
509
+ }
510
+ interface VoiceModelSet {
511
+ provider: string;
512
+ model: string;
513
+ voice?: string;
514
+ settings?: Record<string, unknown>;
515
+ }
516
+ interface VoiceProfile {
517
+ instructions?: string;
518
+ modelSet?: VoiceModelSet;
519
+ recording?: VoiceRecordingPolicy;
520
+ metadata?: Record<string, unknown>;
521
+ }
522
+ interface VoiceChannelSegment {
523
+ id: string;
524
+ conversationId: string;
525
+ channel: "voice";
526
+ startedAt: string;
527
+ endedAt?: string;
528
+ }
529
+ interface VoiceConnection {
530
+ id: string;
531
+ channelSegmentId: string;
532
+ status: VoiceConnectionStatus;
533
+ adapter: string;
534
+ provider?: string;
535
+ providerSessionId?: string;
536
+ expiresAt?: string;
537
+ }
538
+ interface VoiceSocketMetadata {
539
+ url: string;
540
+ token: string;
541
+ expiresAt: string;
542
+ protocol: "cognidesk.voice.v1";
543
+ }
544
+ interface VoiceStartClientHints {
545
+ userAgent?: string;
546
+ locale?: string;
547
+ metadata?: Record<string, unknown>;
548
+ }
549
+ interface StartVoiceConversationInput<TConversationContext = unknown> {
550
+ id?: string;
551
+ agentId: string;
552
+ context: TConversationContext;
553
+ client?: VoiceStartClientHints;
554
+ app?: unknown;
555
+ }
556
+ interface StartVoiceSegmentInput {
557
+ conversationId: string;
558
+ client?: VoiceStartClientHints;
559
+ app?: unknown;
560
+ }
561
+ interface StartVoiceResult {
562
+ conversation: ConversationRecord;
563
+ channelSegment: VoiceChannelSegment;
564
+ connection: VoiceConnection;
565
+ socket?: VoiceSocketMetadata;
566
+ events: RuntimeEvent[];
567
+ }
568
+ interface CommitVoiceTranscriptInput {
569
+ conversationId: string;
570
+ channelSegmentId: string;
571
+ speaker: VoiceSpeaker;
572
+ text: string;
573
+ recordingReferenceId?: string;
574
+ startedAtMs?: number;
575
+ endedAtMs?: number;
576
+ transcriptionSource?: string;
577
+ metadata?: Record<string, unknown>;
578
+ }
579
+ interface CommitVoiceTranscriptReferenceInput extends CommitVoiceTranscriptInput {
580
+ messageEventId: string;
581
+ }
582
+ interface CommitVoiceTranscriptResult {
583
+ message: RuntimeEvent;
584
+ event: RuntimeEvent;
585
+ events: RuntimeEvent[];
586
+ }
587
+ interface RecordVoiceInterruptionInput {
588
+ conversationId: string;
589
+ channelSegmentId: string;
590
+ connectionId?: string;
591
+ interruptedMessageId?: string;
592
+ source?: "userSpeech" | "adapter" | "provider";
593
+ reason?: string;
594
+ recordingReferenceId?: string;
595
+ offsetMs?: number;
596
+ }
597
+ type VoiceRuntimeEventInput = Extract<RuntimeEventInput, {
598
+ type: `voice.${string}`;
599
+ }>;
600
+
601
+ interface RuntimeSnapshot {
602
+ conversationId: string;
603
+ lifecycle: ConversationLifecycle;
604
+ activeJourneyId?: string;
605
+ activeStateIds: string[];
606
+ journeyContext?: unknown;
607
+ journeyContexts?: JourneyContextRecord[];
608
+ journeySummaries?: JourneySummary[];
609
+ compactionSummary?: unknown;
610
+ definitionHash?: string;
611
+ updatedAt: string;
612
+ }
613
+ interface JourneySummary {
614
+ journeyId: string;
615
+ kind: "stateMachine" | "delegation";
616
+ summary: string;
617
+ completedAt: string;
618
+ stateId?: string;
619
+ reason?: string;
620
+ }
621
+ interface JourneyContextRecord {
622
+ journeyId: string;
623
+ context: unknown;
624
+ updatedAt: string;
625
+ stateId?: string;
626
+ }
627
+
628
+ declare class DefinitionError extends Error {
629
+ constructor(message: string);
630
+ }
631
+
632
+ declare const conversationCompactionSummarySchema: z.ZodObject<{
633
+ summary: z.ZodString;
634
+ stableFacts: z.ZodArray<z.ZodString>;
635
+ openQuestions: z.ZodArray<z.ZodString>;
636
+ activeCommitments: z.ZodArray<z.ZodString>;
637
+ }, z.core.$strip>;
638
+ type ConversationCompactionSummary = z.infer<typeof conversationCompactionSummarySchema>;
639
+
640
+ declare class CapabilityScope<TItem> {
641
+ private readonly items;
642
+ private onlyItems;
643
+ private readonly excludedItems;
644
+ add(...items: TItem[]): this;
645
+ only(...items: TItem[]): this;
646
+ exclude(...items: TItem[]): this;
647
+ list(inherited?: TItem[]): TItem[];
648
+ }
649
+
650
+ type MaybePromise$1<T> = T | Promise<T>;
651
+ type FieldWidgetOption = WidgetDefinition | WidgetPromptDefinition;
652
+ interface ConfirmationPolicy {
653
+ message?: string;
654
+ widget?: WidgetDefinition;
655
+ reason?: string;
656
+ }
657
+ interface FieldCollectionOptions<TContext> {
658
+ prompt?: string;
659
+ required?: boolean;
660
+ requiredWhen?: (args: {
661
+ context: TContext;
662
+ }) => boolean;
663
+ extract?: boolean;
664
+ confirm?: boolean | "beforeAction" | ConfirmationPolicy;
665
+ widget?: FieldWidgetOption;
666
+ widgetInput?: (args: {
667
+ context: TContext;
668
+ }) => unknown;
669
+ }
670
+ interface ListCollectionOptions<TContext, TItemSchema extends z.ZodType> {
671
+ item: TItemSchema;
672
+ countFrom?: ContextPath<TContext>;
673
+ prompt?: string;
674
+ widget?: FieldWidgetOption;
675
+ }
676
+ interface TransitionOptions<TContext> {
677
+ priority?: number;
678
+ guard?: (context: GuardContext<unknown, TContext>) => MaybePromise$1<GuardResult>;
679
+ description?: string;
680
+ }
681
+ interface ToolRunOptions<TTool extends AnyTool, TContext> {
682
+ input?: (args: {
683
+ context: TContext;
684
+ }) => z.infer<TTool["input"]>;
685
+ assign?: Partial<Record<ContextPath<TContext>, (args: {
686
+ output: z.infer<TTool["output"]>;
687
+ context: TContext;
688
+ }) => unknown>>;
689
+ onSuccess?: StateBuilder<string, ObjectSchema>;
690
+ onFailure?: StateBuilder<string, ObjectSchema>;
691
+ onValidationError?: StateBuilder<string, ObjectSchema>;
692
+ }
693
+ type ToolRunOptionsFor<TTool extends AnyTool, TContext> = TTool extends SideEffectTool ? ToolRunOptions<TTool, TContext> & {
694
+ confirm: ConfirmationPolicy;
695
+ } : ToolRunOptions<TTool, TContext> & {
696
+ confirm?: ConfirmationPolicy;
697
+ };
698
+ interface StateActionUseOptions<TAction extends ActionDefinition, TContext> {
699
+ type?: "entry" | "exit" | "transition";
700
+ input?: (args: {
701
+ context: TContext;
702
+ }) => z.infer<TAction["input"]>;
703
+ }
704
+ interface ActionDefinition<TName extends string = string, TInputSchema extends z.ZodType = z.ZodType> {
705
+ kind: "action";
706
+ name: TName;
707
+ input: TInputSchema;
708
+ run: (args: {
709
+ input: z.infer<TInputSchema>;
710
+ }) => MaybePromise$1<void>;
711
+ requiresVisit?: boolean;
712
+ retry?: false | {
713
+ maxAttempts?: number;
714
+ notice?: string;
715
+ };
716
+ }
717
+ interface JourneyEventDefinition<TName extends string = string, TPayloadSchema extends z.ZodType = z.ZodType> {
718
+ kind: "journeyEvent";
719
+ name: TName;
720
+ payload: TPayloadSchema;
721
+ routing?: EventRoutingMode;
722
+ }
723
+ type EventRoutingMode = "none" | "activeJourneyOnly" | "full" | "targeted";
724
+ declare function tool<const TName extends string, TInputSchema extends z.ZodType, TOutputSchema extends z.ZodType, const TSideEffect extends boolean = false>(name: TName, config: {
725
+ description?: string;
726
+ input: TInputSchema;
727
+ output: TOutputSchema;
728
+ sideEffect?: TSideEffect;
729
+ idempotencyKey?: (args: {
730
+ input: z.infer<TInputSchema>;
731
+ conversationId: string;
732
+ }) => string;
733
+ execute: (context: ToolExecutionContext<z.infer<TInputSchema>>) => Promise<z.infer<TOutputSchema>>;
734
+ }): ToolDefinition<TName, TInputSchema, TOutputSchema, TSideEffect>;
735
+ declare function widget<const TKind extends string, TInputSchema extends z.ZodType, TOutputSchema extends z.ZodType>(kind: TKind, config: {
736
+ input: TInputSchema;
737
+ output: TOutputSchema;
738
+ }): WidgetDefinition<TKind, TInputSchema, TOutputSchema>;
739
+ declare function widgetPrompt<TWidget extends WidgetDefinition>(widgetDefinition: TWidget, input: z.infer<TWidget["input"]>): WidgetPromptDefinition<TWidget>;
740
+ declare function knowledgeSource<const TName extends string, TQuerySchema extends z.ZodType, TMetadataSchema extends z.ZodType>(name: TName, config: Omit<KnowledgeSource<TName, TQuerySchema, TMetadataSchema>, "kind" | "name">): {
741
+ query: TQuerySchema;
742
+ metadata: TMetadataSchema;
743
+ retrieve: (input: {
744
+ query: z.core.output<TQuerySchema>;
745
+ signal?: AbortSignal;
746
+ }) => Promise<{
747
+ items: KnowledgeItem<z.core.output<TMetadataSchema>>[];
748
+ }>;
749
+ kind: "knowledgeSource";
750
+ name: TName;
751
+ };
752
+ declare function action<const TName extends string, TInputSchema extends z.ZodType>(name: TName, config: {
753
+ input: TInputSchema;
754
+ run: (args: {
755
+ input: z.infer<TInputSchema>;
756
+ }) => MaybePromise$1<void>;
757
+ requiresVisit?: boolean;
758
+ retry?: false | {
759
+ maxAttempts?: number;
760
+ notice?: string;
761
+ };
762
+ }): ActionDefinition<TName, TInputSchema>;
763
+ declare function journeyEvent<const TName extends string, TPayloadSchema extends z.ZodType>(name: TName, config: {
764
+ payload: TPayloadSchema;
765
+ routing?: EventRoutingMode;
766
+ }): JourneyEventDefinition<TName, TPayloadSchema>;
767
+ declare function customRuntimeEvent<const TName extends string, TPayloadSchema extends z.ZodType>(name: TName, config: {
768
+ payload: TPayloadSchema;
769
+ visibleToModel?: boolean;
770
+ }): CustomRuntimeEventDefinition<TName, TPayloadSchema>;
771
+
772
+ type InferObject$2<TSchema extends ObjectSchema> = z.infer<TSchema>;
773
+ interface StateReference<TId extends string = string> {
774
+ readonly id: TId;
775
+ }
776
+ interface CompiledAgent {
777
+ id: string;
778
+ instructions: string;
779
+ logLevel?: AgentLogLevel;
780
+ behavior: AgentBehaviorOptions;
781
+ postProcessing: AgentPostProcessingOptions;
782
+ voice?: VoiceProfile;
783
+ journeys: CompiledJourney[];
784
+ tools: AnyTool[];
785
+ knowledge: KnowledgeSource[];
786
+ widgets: WidgetDefinition[];
787
+ customEvents: AnyCustomRuntimeEvent[];
788
+ }
789
+ interface CompiledJourney {
790
+ id: string;
791
+ kind: "stateMachine" | "delegation";
792
+ condition: string;
793
+ examples: string[];
794
+ tags: string[];
795
+ priority: number;
796
+ stickiness: "low" | "medium" | "high";
797
+ alwaysInclude: boolean;
798
+ always?: JourneyActivationPredicate;
799
+ includeWhen?: CandidateFilterPredicate;
800
+ matcher?: JourneyActivationPredicate;
801
+ guard?: JourneyGuardPredicate;
802
+ contextReuse?: CompiledContextReusePolicy;
803
+ knowledge: KnowledgeSource[];
804
+ tools: AnyTool[];
805
+ context?: ObjectSchema;
806
+ delegation?: CompiledDelegation;
807
+ states: CompiledState[];
808
+ initialStateId?: string;
809
+ alternateEntries: CompiledJourneyEntry[];
810
+ toGraph(): JourneyGraph;
811
+ toJSON(): JourneyGraph;
812
+ toMermaid(): string;
813
+ }
814
+ interface CompiledState {
815
+ id: string;
816
+ parentId?: string;
817
+ initialStateId?: string;
818
+ type: "state" | "parallel" | "final";
819
+ instructions?: string;
820
+ summary?: string;
821
+ tools: AnyTool[];
822
+ knowledge: KnowledgeSource[];
823
+ collected: Array<{
824
+ path: string;
825
+ required: boolean;
826
+ extract: boolean;
827
+ confirm?: true | "beforeAction" | ConfirmationPolicy;
828
+ prompt?: string;
829
+ widget?: WidgetDefinition;
830
+ widgetInput?: unknown | ((args: {
831
+ context: unknown;
832
+ }) => unknown);
833
+ requiredWhen?: (args: {
834
+ context: unknown;
835
+ }) => boolean;
836
+ }>;
837
+ transitions: CompiledTransition[];
838
+ actions: Array<{
839
+ type: "entry" | "exit" | "transition";
840
+ name: string;
841
+ }>;
842
+ actionRuns: CompiledActionRun[];
843
+ toolRuns: CompiledToolRun[];
844
+ requiresVisit: boolean;
845
+ }
846
+ interface CompiledTransition<TContext = unknown> {
847
+ kind: "event" | "conversational";
848
+ targetId: string;
849
+ eventName?: string;
850
+ description?: string;
851
+ priority?: number;
852
+ guard?: (context: GuardContext<unknown, TContext>) => MaybePromise$1<GuardResult>;
853
+ }
854
+ interface CompiledToolRun<TContext = unknown> {
855
+ tool: AnyTool;
856
+ confirm?: ConfirmationPolicy;
857
+ actionType: "entry" | "exit" | "transition";
858
+ input?: (args: {
859
+ context: TContext;
860
+ }) => unknown;
861
+ assign: Array<{
862
+ path: string;
863
+ value: (args: {
864
+ output: unknown;
865
+ context: TContext;
866
+ }) => unknown;
867
+ }>;
868
+ onSuccessId?: string;
869
+ onFailureId?: string;
870
+ onValidationErrorId?: string;
871
+ }
872
+ interface CompiledActionRun<TContext = unknown> {
873
+ action: ActionDefinition;
874
+ actionType: "entry" | "exit" | "transition";
875
+ input?: (args: {
876
+ context: TContext;
877
+ }) => unknown;
878
+ }
879
+ interface CompiledDelegation {
880
+ goal: string;
881
+ instructions?: string;
882
+ tools: AnyTool[];
883
+ completeWhen: string[];
884
+ }
885
+ interface CompiledJourneyEntry<TContext = unknown> {
886
+ stateId: string;
887
+ description?: string;
888
+ priority?: number;
889
+ when: JourneyEntryPredicate<unknown, unknown, unknown, TContext>;
890
+ }
891
+ interface JourneyGraphState {
892
+ id: string;
893
+ parentId?: string;
894
+ initialStateId?: string;
895
+ type: "state" | "parallel" | "final";
896
+ instructions?: string;
897
+ summary?: string;
898
+ collected: Array<{
899
+ path: string;
900
+ required: boolean;
901
+ extract: boolean;
902
+ }>;
903
+ transitions: Array<{
904
+ kind: "event" | "conversational";
905
+ targetId: string;
906
+ eventName?: string;
907
+ description?: string;
908
+ priority?: number;
909
+ }>;
910
+ actions: Array<{
911
+ type: "entry" | "exit" | "transition";
912
+ name: string;
913
+ }>;
914
+ requiresVisit: boolean;
915
+ }
916
+ interface JourneyGraph {
917
+ id: string;
918
+ kind: "stateMachine" | "delegation";
919
+ initialStateId?: string;
920
+ alternateEntries?: Array<{
921
+ stateId: string;
922
+ description?: string;
923
+ priority?: number;
924
+ }>;
925
+ states: JourneyGraphState[];
926
+ }
927
+ type JourneyActivationPredicate<TApp = unknown, TConversation = unknown, TTurn = unknown> = (args: ApplicationContextParts<TConversation, TTurn> & {
928
+ app: TApp;
929
+ activeJourneyId?: string;
930
+ }) => MaybePromise$1<boolean>;
931
+ type CandidateFilterPredicate<TApp = unknown, TConversation = unknown, TTurn = unknown> = (args: ApplicationContextParts<TConversation, TTurn> & {
932
+ app: TApp;
933
+ activeJourneyId?: string;
934
+ }) => boolean;
935
+ type JourneyGuardPredicate<TApp = unknown, TConversation = unknown, TTurn = unknown> = (args: ApplicationContextParts<TConversation, TTurn> & {
936
+ app: TApp;
937
+ activeJourneyId?: string;
938
+ journeyId: string;
939
+ }) => MaybePromise$1<GuardResult>;
940
+ type ContextReusePredicate<TApp = unknown, TConversation = unknown, TTurn = unknown, TContext = unknown> = (args: ApplicationContextParts<TConversation, TTurn> & {
941
+ app: TApp;
942
+ activeJourneyId?: string;
943
+ journeyId: string;
944
+ previousContext: TContext;
945
+ }) => MaybePromise$1<boolean>;
946
+ type JourneyEntryPredicate<TApp = unknown, TConversation = unknown, TTurn = unknown, TContext = unknown> = (args: ApplicationContextParts<TConversation, TTurn> & {
947
+ app: TApp;
948
+ context: TContext;
949
+ journeyId: string;
950
+ activeJourneyId?: string;
951
+ }) => MaybePromise$1<boolean>;
952
+ interface JourneyEntryOptions<TContext> {
953
+ description?: string;
954
+ priority?: number;
955
+ when: JourneyEntryPredicate<unknown, unknown, unknown, TContext>;
956
+ }
957
+ interface ContextReusePolicy<TContext> {
958
+ fields?: Array<ContextPath<TContext>>;
959
+ when: ContextReusePredicate<unknown, unknown, unknown, TContext>;
960
+ }
961
+ interface CompiledContextReusePolicy {
962
+ fields?: string[];
963
+ when: ContextReusePredicate;
964
+ }
965
+ interface ActivationMetadata {
966
+ condition: string;
967
+ examples?: string[];
968
+ tags?: string[];
969
+ priority?: number;
970
+ stickiness?: "low" | "medium" | "high";
971
+ always?: boolean | JourneyActivationPredicate;
972
+ alwaysInclude?: boolean;
973
+ includeWhen?: CandidateFilterPredicate;
974
+ matcher?: JourneyActivationPredicate;
975
+ guard?: JourneyGuardPredicate;
976
+ }
977
+ interface StateMachineJourneyOptions<TContextSchema extends ObjectSchema> extends ActivationMetadata {
978
+ context: TContextSchema;
979
+ description?: string;
980
+ contextReuse?: ContextReusePolicy<InferObject$2<TContextSchema>>;
981
+ }
982
+ interface DelegationJourneyOptions extends ActivationMetadata {
983
+ specialist: {
984
+ goal: string;
985
+ instructions?: string;
986
+ tools?: AnyTool[];
987
+ knowledge?: KnowledgeSource[];
988
+ };
989
+ completeWhen?: string[];
990
+ }
991
+ interface AgentBehaviorOptions {
992
+ interruptOnNewMessage?: boolean;
993
+ }
994
+ interface AgentPostProcessingOptions {
995
+ citations?: boolean;
996
+ }
997
+ type AgentLogLevel = "trace" | "debug" | "info" | "error";
998
+ interface AgentOptions {
999
+ instructions: string;
1000
+ logLevel?: AgentLogLevel;
1001
+ behavior?: AgentBehaviorOptions;
1002
+ postProcessing?: AgentPostProcessingOptions;
1003
+ }
1004
+ type VoiceProfileOptions = VoiceProfile;
1005
+
1006
+ type InferObject$1<TSchema extends ObjectSchema> = z.infer<TSchema>;
1007
+ interface InternalTransition {
1008
+ kind: "event" | "conversational";
1009
+ target: StateBuilder<string, ObjectSchema>;
1010
+ eventName?: string;
1011
+ description?: string;
1012
+ priority?: number;
1013
+ guard?: (context: GuardContext<unknown, unknown>) => MaybePromise$1<GuardResult>;
1014
+ }
1015
+ interface InternalToolRun {
1016
+ tool: AnyTool;
1017
+ confirm?: ConfirmationPolicy;
1018
+ actionType: "entry" | "exit" | "transition";
1019
+ input?: (args: {
1020
+ context: unknown;
1021
+ }) => unknown;
1022
+ assign: Array<{
1023
+ path: string;
1024
+ value: (args: {
1025
+ output: unknown;
1026
+ context: unknown;
1027
+ }) => unknown;
1028
+ }>;
1029
+ onSuccess?: StateBuilder<string, ObjectSchema>;
1030
+ onFailure?: StateBuilder<string, ObjectSchema>;
1031
+ onValidationError?: StateBuilder<string, ObjectSchema>;
1032
+ }
1033
+ interface InternalActionRun {
1034
+ action: ActionDefinition;
1035
+ actionType: "entry" | "exit" | "transition";
1036
+ input?: (args: {
1037
+ context: unknown;
1038
+ }) => unknown;
1039
+ }
1040
+ interface CollectedField {
1041
+ path: string;
1042
+ required: boolean;
1043
+ extract: boolean;
1044
+ confirm?: true | "beforeAction" | ConfirmationPolicy;
1045
+ prompt?: string;
1046
+ widget?: WidgetDefinition;
1047
+ widgetInput?: unknown | ((args: {
1048
+ context: unknown;
1049
+ }) => unknown);
1050
+ requiredWhen?: (args: {
1051
+ context: unknown;
1052
+ }) => boolean;
1053
+ }
1054
+ interface StateActionRecord {
1055
+ type: "entry" | "exit" | "transition";
1056
+ name: string;
1057
+ requiresVisit?: boolean;
1058
+ }
1059
+ interface TransitionTargetBuilder<TContextSchema extends ObjectSchema, TReturn> {
1060
+ target(state: StateBuilder<string, TContextSchema>): TReturn;
1061
+ }
1062
+
1063
+ declare class StateBuilder<const TId extends string, TContextSchema extends ObjectSchema> implements StateReference<TId> {
1064
+ readonly id: TId;
1065
+ readonly contextSchema: TContextSchema;
1066
+ readonly parent?: StateBuilder<string, TContextSchema> | undefined;
1067
+ readonly tools: CapabilityScope<AnyTool>;
1068
+ readonly knowledge: CapabilityScope<KnowledgeSource<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
1069
+ readonly children: StateBuilder<string, TContextSchema>[];
1070
+ readonly transitions: InternalTransition[];
1071
+ readonly toolRuns: InternalToolRun[];
1072
+ readonly actionRuns: InternalActionRun[];
1073
+ readonly collectedFields: CollectedField[];
1074
+ readonly stateActions: StateActionRecord[];
1075
+ private visitRequirement;
1076
+ private stateInstructions?;
1077
+ private stateSummary?;
1078
+ private stateType;
1079
+ private initialChildState?;
1080
+ constructor(id: TId, contextSchema: TContextSchema, parent?: StateBuilder<string, TContextSchema> | undefined);
1081
+ instructions(value: string): this;
1082
+ summary(value: string): this;
1083
+ collect(path: ContextPath<InferObject$1<TContextSchema>>, options?: FieldCollectionOptions<InferObject$1<TContextSchema>>): this;
1084
+ collectList<TItemSchema extends z.ZodType>(path: ContextPath<InferObject$1<TContextSchema>>, options: ListCollectionOptions<InferObject$1<TContextSchema>, TItemSchema>): this;
1085
+ state<const TChildId extends string>(id: TChildId): StateBuilder<TChildId, TContextSchema>;
1086
+ parallel<const TChildId extends string>(id: TChildId): StateBuilder<TChildId, TContextSchema>;
1087
+ final<const TChildId extends string>(id: TChildId): StateBuilder<TChildId, TContextSchema>;
1088
+ initial(state: StateBuilder<string, TContextSchema>): this;
1089
+ markFinal(): this;
1090
+ markParallel(): this;
1091
+ when(description: string, options?: TransitionOptions<InferObject$1<TContextSchema>>): TransitionTargetBuilder<TContextSchema, this>;
1092
+ on(event: JourneyEventDefinition, options?: TransitionOptions<InferObject$1<TContextSchema>>): TransitionTargetBuilder<TContextSchema, this>;
1093
+ transitionTo(state: StateBuilder<string, TContextSchema>, options?: TransitionOptions<InferObject$1<TContextSchema>>): this;
1094
+ entry<TTool extends AnyTool>(toolDefinition: TTool, options: ToolRunOptionsFor<TTool, InferObject$1<TContextSchema>>): this;
1095
+ exit<TTool extends AnyTool>(toolDefinition: TTool, options: ToolRunOptionsFor<TTool, InferObject$1<TContextSchema>>): this;
1096
+ runTool<TTool extends AnyTool>(toolDefinition: TTool, options: ToolRunOptionsFor<TTool, InferObject$1<TContextSchema>>): this;
1097
+ private registerToolRun;
1098
+ useAction<TAction extends ActionDefinition>(actionDefinition: TAction, options?: StateActionUseOptions<TAction, InferObject$1<TContextSchema>> | "entry" | "exit" | "transition"): this;
1099
+ requiresVisit(reason?: string): this;
1100
+ allowSkip(): this;
1101
+ compile(parentId?: string, inheritedTools?: AnyTool[], inheritedKnowledge?: KnowledgeSource[], inheritedCollectedFields?: StateBuilder<string, TContextSchema>["collectedFields"]): CompiledState[];
1102
+ }
1103
+
1104
+ type InferObject<TSchema extends ObjectSchema> = z.infer<TSchema>;
1105
+ interface JourneyFragment<TName extends string = string, TContextSchema extends ObjectSchema = ObjectSchema> {
1106
+ kind: "journeyFragment";
1107
+ name: TName;
1108
+ context: TContextSchema;
1109
+ apply(journey: StateMachineJourneyBuilder<string, TContextSchema>): void;
1110
+ }
1111
+ interface JourneyFragmentOptions<TContextSchema extends ObjectSchema> {
1112
+ context: TContextSchema;
1113
+ tools?: AnyTool[];
1114
+ knowledge?: KnowledgeSource[];
1115
+ define: (journey: StateMachineJourneyBuilder<string, TContextSchema>) => void;
1116
+ }
1117
+ declare class StateCollection<TContextSchema extends ObjectSchema> {
1118
+ private readonly contextSchema;
1119
+ private readonly states;
1120
+ constructor(contextSchema: TContextSchema);
1121
+ add<const TId extends string>(id: TId): StateBuilder<TId, TContextSchema>;
1122
+ get<TId extends string>(id: TId): StateBuilder<TId, TContextSchema>;
1123
+ list(): StateBuilder<string, TContextSchema>[];
1124
+ }
1125
+ declare class TypedStateRegistry<TStateIds extends string, TContextSchema extends ObjectSchema> {
1126
+ private readonly collection;
1127
+ constructor(collection: StateCollection<TContextSchema>);
1128
+ get<TId extends TStateIds>(id: TId): StateBuilder<TId, TContextSchema>;
1129
+ }
1130
+ declare class StateMachineJourneyBuilder<const TId extends string, TContextSchema extends ObjectSchema> {
1131
+ readonly id: TId;
1132
+ readonly options: StateMachineJourneyOptions<TContextSchema>;
1133
+ readonly kind: "stateMachine";
1134
+ readonly states: StateCollection<TContextSchema>;
1135
+ readonly tools: CapabilityScope<AnyTool>;
1136
+ readonly knowledge: CapabilityScope<KnowledgeSource<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
1137
+ private readonly alternateEntryStates;
1138
+ private initialState?;
1139
+ constructor(id: TId, options: StateMachineJourneyOptions<TContextSchema>);
1140
+ state<const TStateId extends string>(id: TStateId): StateBuilder<TStateId, TContextSchema>;
1141
+ parallel<const TStateId extends string>(id: TStateId): StateBuilder<TStateId, TContextSchema>;
1142
+ defineStates<const TStateIds extends readonly [string, ...string[]]>(...ids: TStateIds): TypedStateRegistry<TStateIds[number], TContextSchema>;
1143
+ final<const TStateId extends string>(id: TStateId): StateBuilder<TStateId, TContextSchema>;
1144
+ event<const TName extends string, TPayloadSchema extends z.ZodType>(name: TName, config: {
1145
+ payload: TPayloadSchema;
1146
+ routing?: EventRoutingMode;
1147
+ }): JourneyEventDefinition<TName, TPayloadSchema>;
1148
+ use(fragment: JourneyFragment<string, TContextSchema>): this;
1149
+ alternateEntry(state: StateBuilder<string, TContextSchema>, options: JourneyEntryOptions<InferObject<TContextSchema>>): this;
1150
+ initial(state: StateBuilder<string, TContextSchema>): this;
1151
+ compile(): CompiledJourney;
1152
+ }
1153
+ declare class DelegationJourneyBuilder<const TId extends string> {
1154
+ readonly id: TId;
1155
+ readonly options: DelegationJourneyOptions;
1156
+ readonly kind: "delegation";
1157
+ constructor(id: TId, options: DelegationJourneyOptions);
1158
+ compile(): CompiledJourney;
1159
+ }
1160
+ declare function journeyFragment<const TName extends string, TContextSchema extends ObjectSchema>(name: TName, options: JourneyFragmentOptions<TContextSchema>): JourneyFragment<TName, TContextSchema>;
1161
+
1162
+ declare class AgentBuilder<const TId extends string> {
1163
+ readonly id: TId;
1164
+ readonly options: AgentOptions;
1165
+ readonly tools: CapabilityScope<AnyTool>;
1166
+ readonly knowledge: CapabilityScope<KnowledgeSource<string, zod.ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>, zod.ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>>;
1167
+ readonly customEvents: CapabilityScope<AnyCustomRuntimeEvent>;
1168
+ readonly widgets: WidgetDefinition[];
1169
+ private voiceProfile?;
1170
+ private readonly journeys;
1171
+ constructor(id: TId, options: AgentOptions);
1172
+ stateMachineJourney<const TJourneyId extends string, TContextSchema extends ObjectSchema>(id: TJourneyId, options: StateMachineJourneyOptions<TContextSchema>): StateMachineJourneyBuilder<TJourneyId, TContextSchema>;
1173
+ delegationJourney<const TJourneyId extends string>(id: TJourneyId, options: DelegationJourneyOptions): DelegationJourneyBuilder<TJourneyId>;
1174
+ registerWidget(widgetDefinition: WidgetDefinition): this;
1175
+ voice(options: VoiceProfileOptions): this;
1176
+ compile(): CompiledAgent;
1177
+ }
1178
+ declare function createAgent<const TId extends string>(id: TId, options: AgentOptions): AgentBuilder<TId>;
1179
+
1180
+ declare const JOURNEY_INDEX_PROJECTION_VERSION = "cognidesk.journey-index.v1";
1181
+ declare const journeyIndexEmbeddingSchema: z.ZodObject<{
1182
+ model: z.ZodString;
1183
+ dimensions: z.ZodNumber;
1184
+ vector: z.ZodArray<z.ZodNumber>;
1185
+ }, z.core.$strip>;
1186
+ declare const journeyIndexEntrySchema: z.ZodObject<{
1187
+ journeyId: z.ZodString;
1188
+ kind: z.ZodEnum<{
1189
+ stateMachine: "stateMachine";
1190
+ delegation: "delegation";
1191
+ }>;
1192
+ condition: z.ZodString;
1193
+ examples: z.ZodArray<z.ZodString>;
1194
+ tags: z.ZodArray<z.ZodString>;
1195
+ priority: z.ZodNumber;
1196
+ stickiness: z.ZodEnum<{
1197
+ low: "low";
1198
+ medium: "medium";
1199
+ high: "high";
1200
+ }>;
1201
+ alwaysInclude: z.ZodBoolean;
1202
+ definitionHash: z.ZodString;
1203
+ routingText: z.ZodString;
1204
+ embedding: z.ZodObject<{
1205
+ model: z.ZodString;
1206
+ dimensions: z.ZodNumber;
1207
+ vector: z.ZodArray<z.ZodNumber>;
1208
+ }, z.core.$strip>;
1209
+ }, z.core.$strip>;
1210
+ declare const journeyIndexSchema: z.ZodObject<{
1211
+ agentId: z.ZodString;
1212
+ projectionVersion: z.ZodLiteral<"cognidesk.journey-index.v1">;
1213
+ definitionHash: z.ZodString;
1214
+ embeddingProvider: z.ZodString;
1215
+ embeddingModel: z.ZodString;
1216
+ generatedAt: z.ZodString;
1217
+ entries: z.ZodArray<z.ZodObject<{
1218
+ journeyId: z.ZodString;
1219
+ kind: z.ZodEnum<{
1220
+ stateMachine: "stateMachine";
1221
+ delegation: "delegation";
1222
+ }>;
1223
+ condition: z.ZodString;
1224
+ examples: z.ZodArray<z.ZodString>;
1225
+ tags: z.ZodArray<z.ZodString>;
1226
+ priority: z.ZodNumber;
1227
+ stickiness: z.ZodEnum<{
1228
+ low: "low";
1229
+ medium: "medium";
1230
+ high: "high";
1231
+ }>;
1232
+ alwaysInclude: z.ZodBoolean;
1233
+ definitionHash: z.ZodString;
1234
+ routingText: z.ZodString;
1235
+ embedding: z.ZodObject<{
1236
+ model: z.ZodString;
1237
+ dimensions: z.ZodNumber;
1238
+ vector: z.ZodArray<z.ZodNumber>;
1239
+ }, z.core.$strip>;
1240
+ }, z.core.$strip>>;
1241
+ }, z.core.$strip>;
1242
+ type JourneyIndexEmbedding = z.infer<typeof journeyIndexEmbeddingSchema>;
1243
+ type JourneyIndexEntry = z.infer<typeof journeyIndexEntrySchema>;
1244
+ type JourneyIndex = z.infer<typeof journeyIndexSchema>;
1245
+ interface BuildJourneyIndexOptions {
1246
+ embeddingModel: ModelAdapter;
1247
+ generatedAt?: string;
1248
+ signal?: AbortSignal;
1249
+ }
1250
+ interface JourneyIndexValidationResult {
1251
+ ok: boolean;
1252
+ errors: string[];
1253
+ }
1254
+ interface ValidateJourneyIndexOptions {
1255
+ embeddingModel?: Pick<ModelAdapter, "provider" | "model">;
1256
+ }
1257
+ interface SelectJourneyCandidatesOptions<TApp = unknown, TConversation = unknown, TTurn = unknown> {
1258
+ agent: CompiledAgent;
1259
+ index: JourneyIndex;
1260
+ embeddingModel: ModelAdapter;
1261
+ message: string;
1262
+ app: TApp;
1263
+ conversation: TConversation;
1264
+ turn: TTurn;
1265
+ activeJourneyId?: string;
1266
+ topK?: number;
1267
+ allowStaleIndex?: boolean;
1268
+ signal?: AbortSignal;
1269
+ }
1270
+ interface JourneyCandidate {
1271
+ journeyId: string;
1272
+ journey: CompiledJourney;
1273
+ score: number;
1274
+ similarity: number;
1275
+ reason: "always" | "matcher" | "embedding";
1276
+ definitionHash: string;
1277
+ }
1278
+
1279
+ declare function buildJourneyIndex(agent: CompiledAgent, options: BuildJourneyIndexOptions): Promise<JourneyIndex>;
1280
+
1281
+ declare function createJourneyRoutingText(journey: CompiledJourney): string;
1282
+ declare function hashAgentRoutingDefinition(agent: CompiledAgent): string;
1283
+ declare function hashJourneyDefinition(journey: CompiledJourney): string;
1284
+
1285
+ declare function selectJourneyCandidates<TApp, TConversation, TTurn>(options: SelectJourneyCandidatesOptions<TApp, TConversation, TTurn>): Promise<JourneyCandidate[]>;
1286
+
1287
+ declare function validateJourneyIndex(agent: CompiledAgent, index: JourneyIndex, options?: ValidateJourneyIndexOptions): JourneyIndexValidationResult;
1288
+
1289
+ interface ReplayedMessage {
1290
+ id: string;
1291
+ offset: number;
1292
+ role: "user" | "assistant";
1293
+ text: string;
1294
+ intermediate: boolean;
1295
+ aborted: boolean;
1296
+ reason?: string;
1297
+ segments?: MessageSegment[];
1298
+ }
1299
+ interface ReplayedPrompt {
1300
+ promptId: string;
1301
+ offset: number;
1302
+ widgetKind: string;
1303
+ input: unknown;
1304
+ }
1305
+
1306
+ type MaybePromise<T> = Promise<T> | T;
1307
+ interface PrivacyHookContext {
1308
+ conversationId: string;
1309
+ agentId: string;
1310
+ }
1311
+ interface PrivacyHooks {
1312
+ redactUserMessage?(input: PrivacyHookContext & {
1313
+ text: string;
1314
+ }): MaybePromise<string>;
1315
+ redactModelMessages?(input: PrivacyHookContext & {
1316
+ messages: ModelMessage[];
1317
+ }): MaybePromise<ModelMessage[]>;
1318
+ redactAssistantMessage?(input: PrivacyHookContext & {
1319
+ text: string;
1320
+ }): MaybePromise<string>;
1321
+ redactConversationContext?(input: PrivacyHookContext & {
1322
+ context: unknown;
1323
+ }): MaybePromise<unknown>;
1324
+ redactRuntimeEvent?(input: PrivacyHookContext & {
1325
+ event: RuntimeEventInput;
1326
+ }): MaybePromise<RuntimeEventInput>;
1327
+ redactRuntimeSnapshot?(input: PrivacyHookContext & {
1328
+ snapshot: RuntimeSnapshot;
1329
+ }): MaybePromise<RuntimeSnapshot>;
1330
+ redactModelInput?(input: PrivacyHookContext & {
1331
+ input: TextGenerationInput;
1332
+ }): MaybePromise<TextGenerationInput>;
1333
+ }
1334
+
1335
+ interface RuntimeOptions {
1336
+ storage: StorageAdapter;
1337
+ agent?: CompiledAgent;
1338
+ models?: AgentModelSet;
1339
+ journeyIndex?: JourneyIndex;
1340
+ topKJourneys?: number;
1341
+ app?: unknown;
1342
+ knowledgeLimit?: number;
1343
+ privacy?: PrivacyHooks;
1344
+ telemetry?: RuntimeTelemetryOptions;
1345
+ logLevel?: AgentLogLevel;
1346
+ logger?: Pick<Logger, "trace" | "debug" | "info" | "warn" | "error" | "child">;
1347
+ compaction?: {
1348
+ beforeTurn?: boolean;
1349
+ afterTurn?: boolean;
1350
+ minEvents?: number;
1351
+ schemaVersion?: string;
1352
+ instructions?: string;
1353
+ summarySchema?: z.ZodType;
1354
+ };
1355
+ postProcessing?: {
1356
+ citations?: boolean;
1357
+ };
1358
+ streaming?: {
1359
+ syntheticDeltas?: boolean;
1360
+ };
1361
+ toolRetry?: {
1362
+ maxAttempts?: number;
1363
+ notice?: string;
1364
+ };
1365
+ }
1366
+ interface CreateRuntimeConversationInput<TConversationContext = unknown> extends CreateConversationInput<TConversationContext> {
1367
+ }
1368
+ interface HandleUserMessageInput<TTurn = unknown> {
1369
+ conversationId: string;
1370
+ text: string;
1371
+ channel?: ConversationChannel;
1372
+ turn?: TTurn;
1373
+ app?: unknown;
1374
+ signal?: AbortSignal;
1375
+ recordUserMessage?: boolean;
1376
+ assistantMessageMode?: "canonical" | "intermediate" | "none";
1377
+ onAssistantTextDelta?(textDelta: string): Promise<void> | void;
1378
+ }
1379
+ interface HandleUserMessageResult {
1380
+ conversation: ConversationRecord;
1381
+ snapshot: RuntimeSnapshot;
1382
+ events: RuntimeEvent[];
1383
+ text: string;
1384
+ activeJourneyId?: string;
1385
+ }
1386
+ interface HandleVoiceUserMessageInput<TTurn = unknown> extends HandleUserMessageInput<TTurn> {
1387
+ channelSegmentId: string;
1388
+ connectionId?: string;
1389
+ recordingReferenceId?: string;
1390
+ startedAtMs?: number;
1391
+ endedAtMs?: number;
1392
+ transcriptionSource?: string;
1393
+ metadata?: Record<string, unknown>;
1394
+ }
1395
+ interface HandleVoiceUserMessageResult extends HandleUserMessageResult {
1396
+ voiceEvents: RuntimeEvent[];
1397
+ }
1398
+ interface CompactConversationInput {
1399
+ conversationId: string;
1400
+ fromOffset?: number;
1401
+ toOffset?: number;
1402
+ schemaVersion?: string;
1403
+ signal?: AbortSignal;
1404
+ }
1405
+ interface ReplayConversationInput {
1406
+ conversationId: string;
1407
+ afterOffset?: number;
1408
+ }
1409
+ interface ReplayConversationResult {
1410
+ conversation: ConversationRecord;
1411
+ snapshot: RuntimeSnapshot | null;
1412
+ events: RuntimeEvent[];
1413
+ messages: ReplayedMessage[];
1414
+ openPrompts: ReplayedPrompt[];
1415
+ }
1416
+ interface SubmitWidgetInput {
1417
+ conversationId: string;
1418
+ promptId: string;
1419
+ widgetKind: string;
1420
+ output: unknown;
1421
+ }
1422
+ interface EmitIntermediateMessageInput {
1423
+ conversationId: string;
1424
+ text: string;
1425
+ visibleToModel?: boolean;
1426
+ }
1427
+ interface EmitGeneratedPreambleInput {
1428
+ conversationId: string;
1429
+ purpose?: string;
1430
+ maxWords?: number;
1431
+ signal?: AbortSignal;
1432
+ }
1433
+ interface EmitGeneratedPreambleResult {
1434
+ text: string;
1435
+ events: RuntimeEvent[];
1436
+ }
1437
+ interface EmitCustomEventInput<TEvent extends CustomRuntimeEventDefinition = CustomRuntimeEventDefinition> {
1438
+ conversationId: string;
1439
+ event: TEvent;
1440
+ payload: z.infer<TEvent["payload"]>;
1441
+ }
1442
+ interface EmitJourneyEventInput<TEvent extends JourneyEventDefinition = JourneyEventDefinition> {
1443
+ conversationId: string;
1444
+ event: TEvent;
1445
+ payload: z.infer<TEvent["payload"]>;
1446
+ routing?: EventRoutingMode;
1447
+ target?: {
1448
+ journeyId?: string;
1449
+ stateId?: string;
1450
+ };
1451
+ app?: unknown;
1452
+ signal?: AbortSignal;
1453
+ }
1454
+ interface EmitJourneyEventResult {
1455
+ event: RuntimeEvent;
1456
+ snapshot: RuntimeSnapshot | null;
1457
+ events: RuntimeEvent[];
1458
+ }
1459
+ interface RequestHandoffInput {
1460
+ conversationId: string;
1461
+ reason: string;
1462
+ summary?: string;
1463
+ payload?: unknown;
1464
+ }
1465
+ interface ResumeConversationInput {
1466
+ conversationId: string;
1467
+ reason?: string;
1468
+ payload?: unknown;
1469
+ }
1470
+ interface CompactConversationResult<TSummary = ConversationCompactionSummary> {
1471
+ summary: TSummary;
1472
+ snapshot: RuntimeSnapshot;
1473
+ events: RuntimeEvent[];
1474
+ }
1475
+
1476
+ declare class CognideskRuntime {
1477
+ private readonly activeTurns;
1478
+ private readonly kernel;
1479
+ private readonly options;
1480
+ constructor(options: RuntimeOptions);
1481
+ initialize(): Promise<void>;
1482
+ createConversation<TConversationContext = unknown>(input: CreateRuntimeConversationInput<TConversationContext>): Promise<ConversationRecord<TConversationContext>>;
1483
+ emit<TEvent extends RuntimeEventInput>(event: TEvent): Promise<RuntimeEvent>;
1484
+ emitIntermediateMessage(input: EmitIntermediateMessageInput): Promise<{
1485
+ events: RuntimeEvent[];
1486
+ }>;
1487
+ emitGeneratedPreamble(input: EmitGeneratedPreambleInput): Promise<EmitGeneratedPreambleResult>;
1488
+ emitCustomEvent<TEvent extends CustomRuntimeEventDefinition>(input: EmitCustomEventInput<TEvent>): Promise<RuntimeEvent>;
1489
+ emitJourneyEvent<TEvent extends JourneyEventDefinition>(input: EmitJourneyEventInput<TEvent>): Promise<EmitJourneyEventResult>;
1490
+ listEvents(conversationId: string, afterOffset?: number): Promise<RuntimeEvent[]>;
1491
+ replayConversation(input: ReplayConversationInput): Promise<ReplayConversationResult>;
1492
+ submitWidget(input: SubmitWidgetInput): Promise<RuntimeEvent>;
1493
+ getSnapshot(conversationId: string): Promise<RuntimeSnapshot | null>;
1494
+ handleUserMessage<TTurn = unknown>(input: HandleUserMessageInput<TTurn>): Promise<HandleUserMessageResult>;
1495
+ handleVoiceUserMessage<TTurn = unknown>(input: HandleVoiceUserMessageInput<TTurn>): Promise<HandleVoiceUserMessageResult>;
1496
+ startVoiceConversation<TConversationContext = unknown>(input: StartVoiceConversationInput<TConversationContext>): Promise<StartVoiceResult>;
1497
+ startVoiceSegment(input: StartVoiceSegmentInput): Promise<StartVoiceResult>;
1498
+ endVoiceSegment(input: {
1499
+ conversationId: string;
1500
+ channelSegmentId: string;
1501
+ connectionId?: string;
1502
+ reason?: string;
1503
+ }): Promise<RuntimeEvent>;
1504
+ commitVoiceTranscript(input: CommitVoiceTranscriptInput): Promise<CommitVoiceTranscriptResult>;
1505
+ recordVoiceInterruption(input: RecordVoiceInterruptionInput): Promise<RuntimeEvent>;
1506
+ closeConversation(conversationId: string, reason?: string): Promise<ConversationRecord<unknown>>;
1507
+ requestHandoff(input: RequestHandoffInput): Promise<{
1508
+ conversation: ConversationRecord<unknown>;
1509
+ event: RuntimeEvent;
1510
+ }>;
1511
+ resumeConversation(input: ResumeConversationInput): Promise<{
1512
+ conversation: ConversationRecord<unknown>;
1513
+ event: RuntimeEvent;
1514
+ }>;
1515
+ compactConversation<TSummary = ConversationCompactionSummary>(input: CompactConversationInput): Promise<CompactConversationResult<TSummary>>;
1516
+ private runtimeOperation;
1517
+ }
1518
+ declare function createRuntime(options: RuntimeOptions): CognideskRuntime;
1519
+
1520
+ type SdkLogLevel = AgentLogLevel;
1521
+ type SdkLogger = Pick<Logger, "trace" | "debug" | "info" | "warn" | "error" | "child">;
1522
+ interface RuntimeLogContext {
1523
+ agentId?: string;
1524
+ conversationId?: string;
1525
+ journeyId?: string;
1526
+ stateId?: string;
1527
+ }
1528
+ declare function createRuntimeLogger(options: RuntimeOptions): SdkLogger;
1529
+ declare function runtimeLogger(options: RuntimeOptions, context?: RuntimeLogContext): Pick<pino.Logger, "error" | "trace" | "debug" | "info" | "warn" | "child">;
1530
+
1531
+ declare const textInputWidget: WidgetDefinition<"text-input", z.ZodObject<{
1532
+ label: z.ZodString;
1533
+ description: z.ZodOptional<z.ZodString>;
1534
+ placeholder: z.ZodOptional<z.ZodString>;
1535
+ }, z.core.$strip>, z.ZodObject<{
1536
+ value: z.ZodString;
1537
+ }, z.core.$strip>>;
1538
+ declare const choiceWidget: WidgetDefinition<"choice", z.ZodObject<{
1539
+ label: z.ZodString;
1540
+ options: z.ZodArray<z.ZodObject<{
1541
+ id: z.ZodString;
1542
+ label: z.ZodString;
1543
+ description: z.ZodOptional<z.ZodString>;
1544
+ }, z.core.$strip>>;
1545
+ }, z.core.$strip>, z.ZodObject<{
1546
+ selectedId: z.ZodString;
1547
+ }, z.core.$strip>>;
1548
+ declare const confirmationWidget: WidgetDefinition<"confirmation", z.ZodObject<{
1549
+ title: z.ZodString;
1550
+ message: z.ZodString;
1551
+ confirmLabel: z.ZodOptional<z.ZodString>;
1552
+ cancelLabel: z.ZodOptional<z.ZodString>;
1553
+ }, z.core.$strip>, z.ZodObject<{
1554
+ confirmed: z.ZodBoolean;
1555
+ }, z.core.$strip>>;
1556
+ declare const datePickerWidget: WidgetDefinition<"date-picker", z.ZodObject<{
1557
+ label: z.ZodString;
1558
+ min: z.ZodOptional<z.ZodString>;
1559
+ max: z.ZodOptional<z.ZodString>;
1560
+ }, z.core.$strip>, z.ZodObject<{
1561
+ value: z.ZodString;
1562
+ }, z.core.$strip>>;
1563
+ declare const formWidget: WidgetDefinition<"form", z.ZodObject<{
1564
+ title: z.ZodString;
1565
+ fields: z.ZodArray<z.ZodObject<{
1566
+ path: z.ZodString;
1567
+ label: z.ZodString;
1568
+ description: z.ZodOptional<z.ZodString>;
1569
+ type: z.ZodEnum<{
1570
+ number: "number";
1571
+ date: "date";
1572
+ text: "text";
1573
+ choice: "choice";
1574
+ email: "email";
1575
+ }>;
1576
+ required: z.ZodDefault<z.ZodBoolean>;
1577
+ placeholder: z.ZodOptional<z.ZodString>;
1578
+ min: z.ZodOptional<z.ZodString>;
1579
+ max: z.ZodOptional<z.ZodString>;
1580
+ options: z.ZodOptional<z.ZodArray<z.ZodObject<{
1581
+ id: z.ZodString;
1582
+ label: z.ZodString;
1583
+ }, z.core.$strip>>>;
1584
+ }, z.core.$strip>>;
1585
+ }, z.core.$strip>, z.ZodObject<{
1586
+ values: z.ZodRecord<z.ZodString, z.ZodUnknown>;
1587
+ }, z.core.$strip>>;
1588
+ declare const endConversationTool: ToolDefinition<"cognidesk.endConversation", z.ZodObject<{
1589
+ reason: z.ZodOptional<z.ZodString>;
1590
+ }, z.core.$strip>, z.ZodObject<{
1591
+ closed: z.ZodLiteral<true>;
1592
+ }, z.core.$strip>, true>;
1593
+ declare const handoffTool: ToolDefinition<"cognidesk.handoff", z.ZodObject<{
1594
+ reason: z.ZodString;
1595
+ summary: z.ZodOptional<z.ZodString>;
1596
+ payload: z.ZodOptional<z.ZodUnknown>;
1597
+ }, z.core.$strip>, z.ZodObject<{
1598
+ handoffRequested: z.ZodLiteral<true>;
1599
+ }, z.core.$strip>, true>;
1600
+ declare const journeyContextViewerTool: ToolDefinition<"cognidesk.viewJourneyContext", z.ZodObject<{
1601
+ journeyId: z.ZodString;
1602
+ fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
1603
+ }, z.core.$strip>, z.ZodObject<{
1604
+ journeyId: z.ZodString;
1605
+ context: z.ZodUnknown;
1606
+ }, z.core.$strip>, false>;
1607
+ declare const builtInWidgets: {
1608
+ textInputWidget: WidgetDefinition<"text-input", z.ZodObject<{
1609
+ label: z.ZodString;
1610
+ description: z.ZodOptional<z.ZodString>;
1611
+ placeholder: z.ZodOptional<z.ZodString>;
1612
+ }, z.core.$strip>, z.ZodObject<{
1613
+ value: z.ZodString;
1614
+ }, z.core.$strip>>;
1615
+ choiceWidget: WidgetDefinition<"choice", z.ZodObject<{
1616
+ label: z.ZodString;
1617
+ options: z.ZodArray<z.ZodObject<{
1618
+ id: z.ZodString;
1619
+ label: z.ZodString;
1620
+ description: z.ZodOptional<z.ZodString>;
1621
+ }, z.core.$strip>>;
1622
+ }, z.core.$strip>, z.ZodObject<{
1623
+ selectedId: z.ZodString;
1624
+ }, z.core.$strip>>;
1625
+ confirmationWidget: WidgetDefinition<"confirmation", z.ZodObject<{
1626
+ title: z.ZodString;
1627
+ message: z.ZodString;
1628
+ confirmLabel: z.ZodOptional<z.ZodString>;
1629
+ cancelLabel: z.ZodOptional<z.ZodString>;
1630
+ }, z.core.$strip>, z.ZodObject<{
1631
+ confirmed: z.ZodBoolean;
1632
+ }, z.core.$strip>>;
1633
+ datePickerWidget: WidgetDefinition<"date-picker", z.ZodObject<{
1634
+ label: z.ZodString;
1635
+ min: z.ZodOptional<z.ZodString>;
1636
+ max: z.ZodOptional<z.ZodString>;
1637
+ }, z.core.$strip>, z.ZodObject<{
1638
+ value: z.ZodString;
1639
+ }, z.core.$strip>>;
1640
+ formWidget: WidgetDefinition<"form", z.ZodObject<{
1641
+ title: z.ZodString;
1642
+ fields: z.ZodArray<z.ZodObject<{
1643
+ path: z.ZodString;
1644
+ label: z.ZodString;
1645
+ description: z.ZodOptional<z.ZodString>;
1646
+ type: z.ZodEnum<{
1647
+ number: "number";
1648
+ date: "date";
1649
+ text: "text";
1650
+ choice: "choice";
1651
+ email: "email";
1652
+ }>;
1653
+ required: z.ZodDefault<z.ZodBoolean>;
1654
+ placeholder: z.ZodOptional<z.ZodString>;
1655
+ min: z.ZodOptional<z.ZodString>;
1656
+ max: z.ZodOptional<z.ZodString>;
1657
+ options: z.ZodOptional<z.ZodArray<z.ZodObject<{
1658
+ id: z.ZodString;
1659
+ label: z.ZodString;
1660
+ }, z.core.$strip>>>;
1661
+ }, z.core.$strip>>;
1662
+ }, z.core.$strip>, z.ZodObject<{
1663
+ values: z.ZodRecord<z.ZodString, z.ZodUnknown>;
1664
+ }, z.core.$strip>>;
1665
+ };
1666
+ declare const builtInTools: {
1667
+ endConversationTool: ToolDefinition<"cognidesk.endConversation", z.ZodObject<{
1668
+ reason: z.ZodOptional<z.ZodString>;
1669
+ }, z.core.$strip>, z.ZodObject<{
1670
+ closed: z.ZodLiteral<true>;
1671
+ }, z.core.$strip>, true>;
1672
+ handoffTool: ToolDefinition<"cognidesk.handoff", z.ZodObject<{
1673
+ reason: z.ZodString;
1674
+ summary: z.ZodOptional<z.ZodString>;
1675
+ payload: z.ZodOptional<z.ZodUnknown>;
1676
+ }, z.core.$strip>, z.ZodObject<{
1677
+ handoffRequested: z.ZodLiteral<true>;
1678
+ }, z.core.$strip>, true>;
1679
+ journeyContextViewerTool: ToolDefinition<"cognidesk.viewJourneyContext", z.ZodObject<{
1680
+ journeyId: z.ZodString;
1681
+ fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
1682
+ }, z.core.$strip>, z.ZodObject<{
1683
+ journeyId: z.ZodString;
1684
+ context: z.ZodUnknown;
1685
+ }, z.core.$strip>, false>;
1686
+ };
1687
+
1688
+ export { type ActionDefinition, type ActivationMetadata, type AgentBehaviorOptions, AgentBuilder, type AgentLogLevel, type AgentModelAdapters, type AgentModelSet, type AgentOptions, type AgentPostProcessingOptions, type AnyCustomRuntimeEvent, type AnyTool, type ApplicationContextParts, type BuildJourneyIndexOptions, type CandidateFilterPredicate, CapabilityScope, CognideskRuntime, type CommitVoiceTranscriptInput, type CommitVoiceTranscriptReferenceInput, type CommitVoiceTranscriptResult, type CompactConversationInput, type CompactConversationResult, type CompiledActionRun, type CompiledAgent, type CompiledContextReusePolicy, type CompiledDelegation, type CompiledJourney, type CompiledJourneyEntry, type CompiledState, type CompiledToolRun, type CompiledTransition, type ConfirmationPolicy, type ContextPath, type ContextReusePolicy, type ContextReusePredicate, type ConversationChannel, type ConversationCompactionSummary, type ConversationLifecycle, type ConversationRecord, type CreateConversationInput, type CreateRuntimeConversationInput, type CustomRuntimeEventDefinition, DefinitionError, DelegationJourneyBuilder, type DelegationJourneyOptions, type EmbeddingInput, type EmbeddingOutput, type EmitCustomEventInput, type EmitGeneratedPreambleInput, type EmitGeneratedPreambleResult, type EmitIntermediateMessageInput, type EmitJourneyEventInput, type EmitJourneyEventResult, type EventRoutingMode, type FieldCollectionOptions, type GuardContext, type GuardResult, type HandleUserMessageInput, type HandleUserMessageResult, type HandleVoiceUserMessageInput, type HandleVoiceUserMessageResult, type InferSchema, JOURNEY_INDEX_PROJECTION_VERSION, type JourneyActivationPredicate, type JourneyCandidate, type JourneyContextRecord, type JourneyEntryOptions, type JourneyEntryPredicate, type JourneyEventDefinition, type JourneyFragment, type JourneyFragmentOptions, type JourneyGraph, type JourneyGraphState, type JourneyGuardPredicate, type JourneyIndex, type JourneyIndexEmbedding, type JourneyIndexEntry, type JourneyIndexValidationResult, type JourneySummary, type KnowledgeItem, type KnowledgeSource, type ListCollectionOptions, type ListEventsOptions, type MessageSegment, type ModelAdapter, type ModelMessage, type ModelPromptProfile, type ModelPromptProfileRender, type ModelPromptProfileRenderInput, type ModelRole, type ModelToolCall, type ModelToolDefinition, type ModelVisiblePromptPayload, type ObjectSchema, type PrivacyHookContext, type PrivacyHooks, type PromptProfileRole, type PromptTask, type RecordVoiceInterruptionInput, type ReplayConversationInput, type ReplayConversationResult, type ReplayedMessage, type ReplayedPrompt, type RequestHandoffInput, type ResumeConversationInput, type RuntimeEvent, type RuntimeEventBase, type RuntimeEventInput, type RuntimeEventTelemetry, type RuntimeLogContext, type RuntimeOptions, type RuntimeSnapshot, type RuntimeTelemetryOptions, type SdkLogLevel, type SdkLogger, type SelectJourneyCandidatesOptions, type SideEffectTool, type StartVoiceConversationInput, type StartVoiceResult, type StartVoiceSegmentInput, type StateActionUseOptions, StateBuilder, StateCollection, StateMachineJourneyBuilder, type StateMachineJourneyOptions, type StateReference, type StorageAdapter, type StructuredOutputPromptMetadata, type SubmitWidgetInput, type SupportReference, type TelemetryContentMode, type TelemetryContext, type TelemetryContextSpanOptions, type TelemetrySpanOptions, type TelemetrySpanRunner, type TextGenerationInput, type TextGenerationOutput, type ToolDefinition, type ToolExecutionContext, type ToolRunOptions, type ToolRunOptionsFor, type TransitionOptions, TypedStateRegistry, type UsageRecord, type ValidateJourneyIndexOptions, type VoiceChannelSegment, type VoiceConnection, type VoiceConnectionStatus, type VoiceIceServer, type VoiceModelSet, type VoiceProfile, type VoiceProfileOptions, type VoiceRecordingPolicy, type VoiceRuntimeEventInput, type VoiceSelection, type VoiceSocketMetadata, type VoiceSpeaker, type VoiceStartClientHints, type WidgetDefinition, type WidgetPromptDefinition, action, activeRuntimeEventTelemetry, addTelemetryContentEvent, buildJourneyIndex, builtInTools, builtInWidgets, choiceWidget, confirmationWidget, conversationCompactionSummarySchema, createAgent, createJourneyRoutingText, createRuntime, createRuntimeLogger, createTelemetryContext, customRuntimeEvent, datePickerWidget, endConversationTool, formWidget, handoffTool, hashAgentRoutingDefinition, hashJourneyDefinition, journeyContextViewerTool, journeyEvent, journeyFragment, journeyIndexEmbeddingSchema, journeyIndexEntrySchema, journeyIndexSchema, knowledgeSource, recordRuntimeEventMetric, runtimeLogger, selectJourneyCandidates, telemetryAttributes, telemetryContentMode, telemetryEnabled, telemetryEventNames, telemetrySpanNames, textInputWidget, tool, validateJourneyIndex, widget, widgetPrompt, withTelemetrySpan };