@kat-ai/sdk 0.1.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/client.d.mts +45 -0
- package/dist/client.d.ts +45 -0
- package/dist/client.js +26 -0
- package/dist/client.js.map +1 -0
- package/dist/client.mjs +24 -0
- package/dist/client.mjs.map +1 -0
- package/dist/core-pLiFHTBe.d.mts +406 -0
- package/dist/core-pLiFHTBe.d.ts +406 -0
- package/dist/index.d.mts +2829 -0
- package/dist/index.d.ts +2829 -0
- package/dist/index.js +8028 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +7918 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export { E as ExecutionTrace, a as LogEntry, L as LogLevel, T as TraceStep } from './core-pLiFHTBe.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Client-safe exports for browser/client-side usage
|
|
5
|
+
*
|
|
6
|
+
* This module provides types and minimal runtime utilities without any
|
|
7
|
+
* Node.js dependencies, making it safe to import in client components
|
|
8
|
+
* (e.g., Next.js 'use client', React components, browser scripts).
|
|
9
|
+
*
|
|
10
|
+
* For server-side code, import from '@kat/core' instead.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
type StreamAnnotation = {
|
|
14
|
+
type: 'trace_step';
|
|
15
|
+
step: any;
|
|
16
|
+
} | {
|
|
17
|
+
type: 'trace_complete';
|
|
18
|
+
trace: any;
|
|
19
|
+
} | {
|
|
20
|
+
type: 'session_id';
|
|
21
|
+
sessionId: string;
|
|
22
|
+
} | {
|
|
23
|
+
type: 'follow_up';
|
|
24
|
+
questions: string[];
|
|
25
|
+
};
|
|
26
|
+
type TraceEvent = {
|
|
27
|
+
type: 'step';
|
|
28
|
+
step: any;
|
|
29
|
+
} | {
|
|
30
|
+
type: 'trace_complete';
|
|
31
|
+
trace: any;
|
|
32
|
+
} | {
|
|
33
|
+
type: 'session_id';
|
|
34
|
+
sessionId: string;
|
|
35
|
+
} | {
|
|
36
|
+
type: 'follow_up';
|
|
37
|
+
questions: string[];
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Parse stream data annotation from the stream
|
|
41
|
+
* This is a pure function with no external dependencies
|
|
42
|
+
*/
|
|
43
|
+
declare function parseStreamAnnotation(data: unknown): StreamAnnotation | null;
|
|
44
|
+
|
|
45
|
+
export { type StreamAnnotation, type TraceEvent, parseStreamAnnotation };
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export { E as ExecutionTrace, a as LogEntry, L as LogLevel, T as TraceStep } from './core-pLiFHTBe.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Client-safe exports for browser/client-side usage
|
|
5
|
+
*
|
|
6
|
+
* This module provides types and minimal runtime utilities without any
|
|
7
|
+
* Node.js dependencies, making it safe to import in client components
|
|
8
|
+
* (e.g., Next.js 'use client', React components, browser scripts).
|
|
9
|
+
*
|
|
10
|
+
* For server-side code, import from '@kat/core' instead.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
type StreamAnnotation = {
|
|
14
|
+
type: 'trace_step';
|
|
15
|
+
step: any;
|
|
16
|
+
} | {
|
|
17
|
+
type: 'trace_complete';
|
|
18
|
+
trace: any;
|
|
19
|
+
} | {
|
|
20
|
+
type: 'session_id';
|
|
21
|
+
sessionId: string;
|
|
22
|
+
} | {
|
|
23
|
+
type: 'follow_up';
|
|
24
|
+
questions: string[];
|
|
25
|
+
};
|
|
26
|
+
type TraceEvent = {
|
|
27
|
+
type: 'step';
|
|
28
|
+
step: any;
|
|
29
|
+
} | {
|
|
30
|
+
type: 'trace_complete';
|
|
31
|
+
trace: any;
|
|
32
|
+
} | {
|
|
33
|
+
type: 'session_id';
|
|
34
|
+
sessionId: string;
|
|
35
|
+
} | {
|
|
36
|
+
type: 'follow_up';
|
|
37
|
+
questions: string[];
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Parse stream data annotation from the stream
|
|
41
|
+
* This is a pure function with no external dependencies
|
|
42
|
+
*/
|
|
43
|
+
declare function parseStreamAnnotation(data: unknown): StreamAnnotation | null;
|
|
44
|
+
|
|
45
|
+
export { type StreamAnnotation, type TraceEvent, parseStreamAnnotation };
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/client.ts
|
|
4
|
+
function parseStreamAnnotation(data) {
|
|
5
|
+
if (!data || typeof data !== "object") {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
const obj = data;
|
|
9
|
+
if (obj.type === "trace_step" && obj.step) {
|
|
10
|
+
return { type: "trace_step", step: obj.step };
|
|
11
|
+
}
|
|
12
|
+
if (obj.type === "trace_complete" && obj.trace) {
|
|
13
|
+
return { type: "trace_complete", trace: obj.trace };
|
|
14
|
+
}
|
|
15
|
+
if (obj.type === "session_id" && typeof obj.sessionId === "string") {
|
|
16
|
+
return { type: "session_id", sessionId: obj.sessionId };
|
|
17
|
+
}
|
|
18
|
+
if (obj.type === "follow_up" && Array.isArray(obj.questions)) {
|
|
19
|
+
return { type: "follow_up", questions: obj.questions };
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
exports.parseStreamAnnotation = parseStreamAnnotation;
|
|
25
|
+
//# sourceMappingURL=client.js.map
|
|
26
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"names":[],"mappings":";;;AAgCO,SAAS,sBAAsB,IAAA,EAAwC;AAC1E,EAAA,IAAI,CAAC,IAAA,IAAQ,OAAO,IAAA,KAAS,QAAA,EAAU;AACnC,IAAA,OAAO,IAAA;AAAA,EACX;AAEA,EAAA,MAAM,GAAA,GAAM,IAAA;AAEZ,EAAA,IAAI,GAAA,CAAI,IAAA,KAAS,YAAA,IAAgB,GAAA,CAAI,IAAA,EAAM;AACvC,IAAA,OAAO,EAAE,IAAA,EAAM,YAAA,EAAc,IAAA,EAAM,IAAI,IAAA,EAAK;AAAA,EAChD;AAEA,EAAA,IAAI,GAAA,CAAI,IAAA,KAAS,gBAAA,IAAoB,GAAA,CAAI,KAAA,EAAO;AAC5C,IAAA,OAAO,EAAE,IAAA,EAAM,gBAAA,EAAkB,KAAA,EAAO,IAAI,KAAA,EAAM;AAAA,EACtD;AAEA,EAAA,IAAI,IAAI,IAAA,KAAS,YAAA,IAAgB,OAAO,GAAA,CAAI,cAAc,QAAA,EAAU;AAChE,IAAA,OAAO,EAAE,IAAA,EAAM,YAAA,EAAc,SAAA,EAAW,IAAI,SAAA,EAAU;AAAA,EAC1D;AAEA,EAAA,IAAI,IAAI,IAAA,KAAS,WAAA,IAAe,MAAM,OAAA,CAAQ,GAAA,CAAI,SAAS,CAAA,EAAG;AAC1D,IAAA,OAAO,EAAE,IAAA,EAAM,WAAA,EAAa,SAAA,EAAW,IAAI,SAAA,EAAsB;AAAA,EACrE;AAEA,EAAA,OAAO,IAAA;AACX","file":"client.js","sourcesContent":["/**\n * Client-safe exports for browser/client-side usage\n * \n * This module provides types and minimal runtime utilities without any\n * Node.js dependencies, making it safe to import in client components\n * (e.g., Next.js 'use client', React components, browser scripts).\n * \n * For server-side code, import from '@kat/core' instead.\n */\n\n// Re-export types only - these are pure types with no runtime code\nexport type { LogLevel, LogEntry } from './logger';\nexport type { TraceStep, ExecutionTrace } from './types/core';\n\n// StreamAnnotation type - wire format for Vercel AI SDK\nexport type StreamAnnotation =\n | { type: 'trace_step'; step: any }\n | { type: 'trace_complete'; trace: any }\n | { type: 'session_id'; sessionId: string }\n | { type: 'follow_up'; questions: string[] };\n\n// TraceEvent type - internal event format\nexport type TraceEvent =\n | { type: 'step'; step: any }\n | { type: 'trace_complete'; trace: any }\n | { type: 'session_id'; sessionId: string }\n | { type: 'follow_up'; questions: string[] };\n\n/**\n * Parse stream data annotation from the stream\n * This is a pure function with no external dependencies\n */\nexport function parseStreamAnnotation(data: unknown): StreamAnnotation | null {\n if (!data || typeof data !== 'object') {\n return null;\n }\n\n const obj = data as Record<string, unknown>;\n\n if (obj.type === 'trace_step' && obj.step) {\n return { type: 'trace_step', step: obj.step };\n }\n\n if (obj.type === 'trace_complete' && obj.trace) {\n return { type: 'trace_complete', trace: obj.trace };\n }\n\n if (obj.type === 'session_id' && typeof obj.sessionId === 'string') {\n return { type: 'session_id', sessionId: obj.sessionId };\n }\n\n if (obj.type === 'follow_up' && Array.isArray(obj.questions)) {\n return { type: 'follow_up', questions: obj.questions as string[] };\n }\n\n return null;\n}\n"]}
|
package/dist/client.mjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
function parseStreamAnnotation(data) {
|
|
3
|
+
if (!data || typeof data !== "object") {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
const obj = data;
|
|
7
|
+
if (obj.type === "trace_step" && obj.step) {
|
|
8
|
+
return { type: "trace_step", step: obj.step };
|
|
9
|
+
}
|
|
10
|
+
if (obj.type === "trace_complete" && obj.trace) {
|
|
11
|
+
return { type: "trace_complete", trace: obj.trace };
|
|
12
|
+
}
|
|
13
|
+
if (obj.type === "session_id" && typeof obj.sessionId === "string") {
|
|
14
|
+
return { type: "session_id", sessionId: obj.sessionId };
|
|
15
|
+
}
|
|
16
|
+
if (obj.type === "follow_up" && Array.isArray(obj.questions)) {
|
|
17
|
+
return { type: "follow_up", questions: obj.questions };
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { parseStreamAnnotation };
|
|
23
|
+
//# sourceMappingURL=client.mjs.map
|
|
24
|
+
//# sourceMappingURL=client.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"names":[],"mappings":";AAgCO,SAAS,sBAAsB,IAAA,EAAwC;AAC1E,EAAA,IAAI,CAAC,IAAA,IAAQ,OAAO,IAAA,KAAS,QAAA,EAAU;AACnC,IAAA,OAAO,IAAA;AAAA,EACX;AAEA,EAAA,MAAM,GAAA,GAAM,IAAA;AAEZ,EAAA,IAAI,GAAA,CAAI,IAAA,KAAS,YAAA,IAAgB,GAAA,CAAI,IAAA,EAAM;AACvC,IAAA,OAAO,EAAE,IAAA,EAAM,YAAA,EAAc,IAAA,EAAM,IAAI,IAAA,EAAK;AAAA,EAChD;AAEA,EAAA,IAAI,GAAA,CAAI,IAAA,KAAS,gBAAA,IAAoB,GAAA,CAAI,KAAA,EAAO;AAC5C,IAAA,OAAO,EAAE,IAAA,EAAM,gBAAA,EAAkB,KAAA,EAAO,IAAI,KAAA,EAAM;AAAA,EACtD;AAEA,EAAA,IAAI,IAAI,IAAA,KAAS,YAAA,IAAgB,OAAO,GAAA,CAAI,cAAc,QAAA,EAAU;AAChE,IAAA,OAAO,EAAE,IAAA,EAAM,YAAA,EAAc,SAAA,EAAW,IAAI,SAAA,EAAU;AAAA,EAC1D;AAEA,EAAA,IAAI,IAAI,IAAA,KAAS,WAAA,IAAe,MAAM,OAAA,CAAQ,GAAA,CAAI,SAAS,CAAA,EAAG;AAC1D,IAAA,OAAO,EAAE,IAAA,EAAM,WAAA,EAAa,SAAA,EAAW,IAAI,SAAA,EAAsB;AAAA,EACrE;AAEA,EAAA,OAAO,IAAA;AACX","file":"client.mjs","sourcesContent":["/**\n * Client-safe exports for browser/client-side usage\n * \n * This module provides types and minimal runtime utilities without any\n * Node.js dependencies, making it safe to import in client components\n * (e.g., Next.js 'use client', React components, browser scripts).\n * \n * For server-side code, import from '@kat/core' instead.\n */\n\n// Re-export types only - these are pure types with no runtime code\nexport type { LogLevel, LogEntry } from './logger';\nexport type { TraceStep, ExecutionTrace } from './types/core';\n\n// StreamAnnotation type - wire format for Vercel AI SDK\nexport type StreamAnnotation =\n | { type: 'trace_step'; step: any }\n | { type: 'trace_complete'; trace: any }\n | { type: 'session_id'; sessionId: string }\n | { type: 'follow_up'; questions: string[] };\n\n// TraceEvent type - internal event format\nexport type TraceEvent =\n | { type: 'step'; step: any }\n | { type: 'trace_complete'; trace: any }\n | { type: 'session_id'; sessionId: string }\n | { type: 'follow_up'; questions: string[] };\n\n/**\n * Parse stream data annotation from the stream\n * This is a pure function with no external dependencies\n */\nexport function parseStreamAnnotation(data: unknown): StreamAnnotation | null {\n if (!data || typeof data !== 'object') {\n return null;\n }\n\n const obj = data as Record<string, unknown>;\n\n if (obj.type === 'trace_step' && obj.step) {\n return { type: 'trace_step', step: obj.step };\n }\n\n if (obj.type === 'trace_complete' && obj.trace) {\n return { type: 'trace_complete', trace: obj.trace };\n }\n\n if (obj.type === 'session_id' && typeof obj.sessionId === 'string') {\n return { type: 'session_id', sessionId: obj.sessionId };\n }\n\n if (obj.type === 'follow_up' && Array.isArray(obj.questions)) {\n return { type: 'follow_up', questions: obj.questions as string[] };\n }\n\n return null;\n}\n"]}
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger Module
|
|
3
|
+
*
|
|
4
|
+
* Utility for capturing and streaming logs via SSE (Server-Sent Events).
|
|
5
|
+
* Provides session-scoped logging and trace step streaming.
|
|
6
|
+
*/
|
|
7
|
+
type LogLevel = 'log' | 'info' | 'warn' | 'error' | 'debug';
|
|
8
|
+
interface LogEntry {
|
|
9
|
+
id: string;
|
|
10
|
+
sessionId: string;
|
|
11
|
+
level: LogLevel;
|
|
12
|
+
message: string;
|
|
13
|
+
timestamp: string;
|
|
14
|
+
data?: any;
|
|
15
|
+
stack?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Subscribe to log entries for a specific session
|
|
19
|
+
*
|
|
20
|
+
* @param sessionId - The session identifier to subscribe to
|
|
21
|
+
* @param callback - Function called when a log entry is emitted
|
|
22
|
+
* @returns Unsubscribe function to stop receiving logs
|
|
23
|
+
*/
|
|
24
|
+
declare function subscribeToLogs(sessionId: string, callback: (log: LogEntry) => void): () => void;
|
|
25
|
+
/**
|
|
26
|
+
* Get all stored logs for a session
|
|
27
|
+
*
|
|
28
|
+
* @param sessionId - The session identifier
|
|
29
|
+
* @returns Array of log entries for the session
|
|
30
|
+
*/
|
|
31
|
+
declare function getSessionLogs(sessionId: string): LogEntry[];
|
|
32
|
+
/**
|
|
33
|
+
* Clear all logs and trace steps for a session
|
|
34
|
+
*
|
|
35
|
+
* @param sessionId - The session identifier
|
|
36
|
+
*/
|
|
37
|
+
declare function clearSessionLogs(sessionId: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Subscribe to trace steps for a session
|
|
40
|
+
*
|
|
41
|
+
* @param sessionId - The session identifier to subscribe to
|
|
42
|
+
* @param callback - Function called when a trace step is emitted
|
|
43
|
+
* @returns Unsubscribe function to stop receiving trace steps
|
|
44
|
+
*/
|
|
45
|
+
declare function subscribeToTraceSteps(sessionId: string, callback: (traceStep: any) => void): () => void;
|
|
46
|
+
/**
|
|
47
|
+
* Emit a trace step for a session
|
|
48
|
+
*
|
|
49
|
+
* @param sessionId - The session identifier
|
|
50
|
+
* @param traceStep - The trace step object to emit
|
|
51
|
+
*/
|
|
52
|
+
declare function emitTraceStep(sessionId: string, traceStep: any): void;
|
|
53
|
+
/**
|
|
54
|
+
* Create a logger instance for a specific session
|
|
55
|
+
*
|
|
56
|
+
* @param sessionId - The session identifier
|
|
57
|
+
* @returns Logger object with log, info, warn, error, and debug methods
|
|
58
|
+
*/
|
|
59
|
+
declare function createSessionLogger(sessionId: string): {
|
|
60
|
+
log: (message: string, data?: any) => void;
|
|
61
|
+
info: (message: string, data?: any) => void;
|
|
62
|
+
warn: (message: string, data?: any) => void;
|
|
63
|
+
error: (message: string, error?: Error, data?: any) => void;
|
|
64
|
+
debug: (message: string, data?: any) => void;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Core Types
|
|
69
|
+
*
|
|
70
|
+
* Core type definitions for the multi-KB orchestration framework.
|
|
71
|
+
*/
|
|
72
|
+
/**
|
|
73
|
+
* Dynamic slots interface - actual slot names come from agent.config.json
|
|
74
|
+
* This is a generic interface that accepts any slot name defined in config
|
|
75
|
+
*/
|
|
76
|
+
interface Slots {
|
|
77
|
+
[slotName: string]: string | boolean | undefined;
|
|
78
|
+
}
|
|
79
|
+
interface Intent {
|
|
80
|
+
intentId: string;
|
|
81
|
+
userUtterance: string;
|
|
82
|
+
slots: Slots;
|
|
83
|
+
goals: string[];
|
|
84
|
+
missingSlots?: string[];
|
|
85
|
+
clarificationNeeded?: boolean;
|
|
86
|
+
clarificationQuestion?: string;
|
|
87
|
+
}
|
|
88
|
+
type PlanStepType = 'kb_call' | 'llm_synthesis';
|
|
89
|
+
interface PlanStepKBCall {
|
|
90
|
+
id: string;
|
|
91
|
+
type: 'kb_call';
|
|
92
|
+
kbId: string;
|
|
93
|
+
inputs: Partial<Slots>;
|
|
94
|
+
expectedOutputs: string[];
|
|
95
|
+
}
|
|
96
|
+
interface PlanStepSynthesis {
|
|
97
|
+
id: string;
|
|
98
|
+
type: 'llm_synthesis';
|
|
99
|
+
fromSteps: string[];
|
|
100
|
+
}
|
|
101
|
+
type PlanStep = PlanStepKBCall | PlanStepSynthesis;
|
|
102
|
+
interface Plan {
|
|
103
|
+
planId: string;
|
|
104
|
+
steps: PlanStep[];
|
|
105
|
+
reasoning?: string;
|
|
106
|
+
confidence?: number;
|
|
107
|
+
}
|
|
108
|
+
type TraceStepType = 'disambiguation' | 'slot_filling' | 'planning' | 'kb_call' | 'synthesis';
|
|
109
|
+
interface TraceStep {
|
|
110
|
+
stepId: string;
|
|
111
|
+
stepType: TraceStepType;
|
|
112
|
+
timestamp: string;
|
|
113
|
+
description: string;
|
|
114
|
+
thought?: string;
|
|
115
|
+
understanding?: string;
|
|
116
|
+
learned?: string;
|
|
117
|
+
conclusion?: string;
|
|
118
|
+
details?: {
|
|
119
|
+
extractedIntent?: Intent;
|
|
120
|
+
relevantKBs?: string[];
|
|
121
|
+
missingSlots?: string[];
|
|
122
|
+
followUpQuestions?: string[];
|
|
123
|
+
selectedKBs?: Array<{
|
|
124
|
+
kbId: string;
|
|
125
|
+
reason: string;
|
|
126
|
+
}>;
|
|
127
|
+
kbId?: string;
|
|
128
|
+
kbName?: string;
|
|
129
|
+
query?: string;
|
|
130
|
+
inputs?: Partial<Slots>;
|
|
131
|
+
sourceSteps?: string[];
|
|
132
|
+
error?: string;
|
|
133
|
+
[key: string]: any;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
interface StepResult {
|
|
137
|
+
stepId: string;
|
|
138
|
+
kbId?: string;
|
|
139
|
+
requestPayload?: any;
|
|
140
|
+
responsePayload?: any;
|
|
141
|
+
contextSnippets?: any[];
|
|
142
|
+
inputs?: Partial<Slots>;
|
|
143
|
+
error?: string;
|
|
144
|
+
}
|
|
145
|
+
interface KBRetrieval {
|
|
146
|
+
kbId: string;
|
|
147
|
+
kbName: string;
|
|
148
|
+
stepId: string;
|
|
149
|
+
query: string;
|
|
150
|
+
inputs: Partial<Slots>;
|
|
151
|
+
retrievedInformation: {
|
|
152
|
+
answer: string;
|
|
153
|
+
contextSnippets?: Array<{
|
|
154
|
+
label: string;
|
|
155
|
+
content: string;
|
|
156
|
+
referenceSummary: string;
|
|
157
|
+
}>;
|
|
158
|
+
};
|
|
159
|
+
timestamp: string;
|
|
160
|
+
}
|
|
161
|
+
interface AgentContext {
|
|
162
|
+
userObjective: string;
|
|
163
|
+
pendingQuestion?: PendingQuestion;
|
|
164
|
+
missingInformation: {
|
|
165
|
+
slots: string[];
|
|
166
|
+
unobtainableSlots: string[];
|
|
167
|
+
descriptions: Record<string, string>;
|
|
168
|
+
questionHistory?: Array<{
|
|
169
|
+
slot: string;
|
|
170
|
+
question: string;
|
|
171
|
+
timestamp: string;
|
|
172
|
+
answered: boolean;
|
|
173
|
+
}>;
|
|
174
|
+
};
|
|
175
|
+
collectedInformation: {
|
|
176
|
+
slots: Partial<Slots>;
|
|
177
|
+
collectionHistory: Array<{
|
|
178
|
+
timestamp: string;
|
|
179
|
+
slot: string;
|
|
180
|
+
value: any;
|
|
181
|
+
source: 'initial_extraction' | 'user_response' | 'merged';
|
|
182
|
+
}>;
|
|
183
|
+
};
|
|
184
|
+
kbRetrievals: KBRetrieval[];
|
|
185
|
+
agentThinking: Array<{
|
|
186
|
+
phase: 'disambiguation' | 'planning' | 'execution' | 'synthesis';
|
|
187
|
+
timestamp: string;
|
|
188
|
+
reasoning: string;
|
|
189
|
+
details?: any;
|
|
190
|
+
}>;
|
|
191
|
+
stepCounts?: Record<string, number>;
|
|
192
|
+
}
|
|
193
|
+
interface ExecutionTrace {
|
|
194
|
+
sessionId: string;
|
|
195
|
+
intent: Intent;
|
|
196
|
+
plan: Plan;
|
|
197
|
+
stepResults: StepResult[];
|
|
198
|
+
traceSteps: TraceStep[];
|
|
199
|
+
context: AgentContext;
|
|
200
|
+
}
|
|
201
|
+
/** Pending question for form-filling flow */
|
|
202
|
+
interface PendingQuestion {
|
|
203
|
+
slot: string;
|
|
204
|
+
question: string;
|
|
205
|
+
askedAt: string;
|
|
206
|
+
attempts: number;
|
|
207
|
+
options?: MultiChoiceOption[];
|
|
208
|
+
}
|
|
209
|
+
/** Multi-choice option for disambiguation questions */
|
|
210
|
+
interface MultiChoiceOption {
|
|
211
|
+
/** Unique identifier for the option */
|
|
212
|
+
id: string;
|
|
213
|
+
/** Display label for the option */
|
|
214
|
+
label: string;
|
|
215
|
+
/** Optional description providing more context */
|
|
216
|
+
description?: string;
|
|
217
|
+
}
|
|
218
|
+
/** Disambiguation actions - explicit decisions from the policy engine */
|
|
219
|
+
type DisambiguationAction = {
|
|
220
|
+
type: 'ASK_SLOT';
|
|
221
|
+
slot: string;
|
|
222
|
+
question: string;
|
|
223
|
+
options?: MultiChoiceOption[];
|
|
224
|
+
} | {
|
|
225
|
+
type: 'CALL_KB';
|
|
226
|
+
kbIds: string[];
|
|
227
|
+
slots: Partial<Slots>;
|
|
228
|
+
} | {
|
|
229
|
+
type: 'PARTIAL_PROCEED';
|
|
230
|
+
kbIds: string[];
|
|
231
|
+
slots: Partial<Slots>;
|
|
232
|
+
missingSlots: string[];
|
|
233
|
+
} | {
|
|
234
|
+
type: 'BLOCKED';
|
|
235
|
+
reason: string;
|
|
236
|
+
} | {
|
|
237
|
+
type: 'OUT_OF_SCOPE';
|
|
238
|
+
redirectMessage: string;
|
|
239
|
+
availableCapabilities: string[];
|
|
240
|
+
};
|
|
241
|
+
/** Details about why a KB was selected during routing */
|
|
242
|
+
interface KBRoutingReason {
|
|
243
|
+
kbId: string;
|
|
244
|
+
selectedBy: 'llm_hint' | 'slot_trigger' | 'input_match' | 'fallback';
|
|
245
|
+
trigger?: string;
|
|
246
|
+
}
|
|
247
|
+
/** Detailed routing decision for tracing */
|
|
248
|
+
interface RoutingDecision {
|
|
249
|
+
kbHintsReceived: string[];
|
|
250
|
+
kbsFromHints: string[];
|
|
251
|
+
slotTriggersMatched: Array<{
|
|
252
|
+
kbId: string;
|
|
253
|
+
trigger: string;
|
|
254
|
+
}>;
|
|
255
|
+
kbsFromSlotTriggers: string[];
|
|
256
|
+
kbsFromFallback: string[];
|
|
257
|
+
finalKBs: string[];
|
|
258
|
+
routingReasons: KBRoutingReason[];
|
|
259
|
+
}
|
|
260
|
+
/** Details from the disambiguation process for tracing */
|
|
261
|
+
interface DisambiguationDetails {
|
|
262
|
+
llmExtraction: {
|
|
263
|
+
kbHints: string[];
|
|
264
|
+
goals: string[];
|
|
265
|
+
reasoning?: string;
|
|
266
|
+
isOutOfScope?: boolean;
|
|
267
|
+
};
|
|
268
|
+
routingDecision: RoutingDecision;
|
|
269
|
+
}
|
|
270
|
+
/** Result from disambiguation with explicit action */
|
|
271
|
+
interface DisambiguationResult {
|
|
272
|
+
intent: Intent;
|
|
273
|
+
updatedContext: AgentContext;
|
|
274
|
+
action: DisambiguationAction;
|
|
275
|
+
disambiguationDetails?: DisambiguationDetails;
|
|
276
|
+
}
|
|
277
|
+
/** Facts extracted from LLM (no decisions, just observations) */
|
|
278
|
+
interface LLMExtractionFacts {
|
|
279
|
+
slots: Partial<Slots>;
|
|
280
|
+
goals: string[];
|
|
281
|
+
kbHints: string[];
|
|
282
|
+
intentSummary: string;
|
|
283
|
+
nonAnswer?: boolean;
|
|
284
|
+
topicShift?: boolean;
|
|
285
|
+
isOutOfScope?: boolean;
|
|
286
|
+
reasoning?: string;
|
|
287
|
+
}
|
|
288
|
+
/** Types for enhanced planning */
|
|
289
|
+
interface KBRelevanceInfo {
|
|
290
|
+
kbId: string;
|
|
291
|
+
reason: string;
|
|
292
|
+
priority: number;
|
|
293
|
+
requiredSlots: string[];
|
|
294
|
+
confidence: number;
|
|
295
|
+
}
|
|
296
|
+
interface PlanningReasoning {
|
|
297
|
+
goalAnalysis: string;
|
|
298
|
+
kbSelection: KBRelevanceInfo[];
|
|
299
|
+
dependencyAnalysis: string;
|
|
300
|
+
riskAssessment: string;
|
|
301
|
+
alternatives?: string[];
|
|
302
|
+
}
|
|
303
|
+
interface PlanModification {
|
|
304
|
+
originalPlanId: string;
|
|
305
|
+
modifiedPlanId: string;
|
|
306
|
+
changes: Array<{
|
|
307
|
+
type: 'add_step' | 'remove_step' | 'modify_step' | 'reorder_steps';
|
|
308
|
+
stepId?: string;
|
|
309
|
+
newStep?: PlanStep;
|
|
310
|
+
reason: string;
|
|
311
|
+
}>;
|
|
312
|
+
reasoning: string;
|
|
313
|
+
confidence: number;
|
|
314
|
+
}
|
|
315
|
+
interface ConversationMessage {
|
|
316
|
+
role: 'user' | 'assistant';
|
|
317
|
+
content: string;
|
|
318
|
+
timestamp?: string;
|
|
319
|
+
}
|
|
320
|
+
interface ChatRequest {
|
|
321
|
+
/** Session ID for conversation tracking */
|
|
322
|
+
sessionId?: string;
|
|
323
|
+
/** The user's message */
|
|
324
|
+
message: string;
|
|
325
|
+
/** Whether to include execution trace in response */
|
|
326
|
+
returnTrace?: boolean;
|
|
327
|
+
/** Previous intent for multi-turn conversations */
|
|
328
|
+
previousIntent?: Intent;
|
|
329
|
+
/** Previous agent context for multi-turn conversations */
|
|
330
|
+
previousContext?: AgentContext;
|
|
331
|
+
/** Full conversation history with timestamps */
|
|
332
|
+
conversationHistory?: ConversationMessage[];
|
|
333
|
+
}
|
|
334
|
+
/** Outcome type for chat responses */
|
|
335
|
+
type ChatOutcome = 'answer' | 'follow_up' | 'blocked' | 'out_of_scope';
|
|
336
|
+
interface ChatResponse {
|
|
337
|
+
/** Session ID for conversation tracking */
|
|
338
|
+
sessionId: string;
|
|
339
|
+
/** The type of outcome */
|
|
340
|
+
outcome: ChatOutcome;
|
|
341
|
+
/** The answer text (for 'answer' outcome) */
|
|
342
|
+
answer: string | null;
|
|
343
|
+
/** Follow-up question (for 'follow_up' outcome) */
|
|
344
|
+
followUpQuestion: string | null;
|
|
345
|
+
/** Multi-choice options for follow-up questions */
|
|
346
|
+
options?: MultiChoiceOption[];
|
|
347
|
+
/** Citations referenced in the answer */
|
|
348
|
+
citations: ChatCitation[];
|
|
349
|
+
/** Agent context for multi-turn conversations */
|
|
350
|
+
context: AgentContext;
|
|
351
|
+
/** Extracted intent */
|
|
352
|
+
intent: Intent;
|
|
353
|
+
/** Execution trace (if requested) */
|
|
354
|
+
trace?: ExecutionTrace;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Citation in chat response.
|
|
358
|
+
* This is a subset of the full Citation type from agent/types.ts,
|
|
359
|
+
* optimized for API responses.
|
|
360
|
+
*/
|
|
361
|
+
interface ChatCitation {
|
|
362
|
+
/** Citation label (e.g., 'S1', 'S2') */
|
|
363
|
+
label: string;
|
|
364
|
+
/** KB that provided this citation */
|
|
365
|
+
kbId: string;
|
|
366
|
+
/** Human-readable summary of the reference */
|
|
367
|
+
referenceSummary: string;
|
|
368
|
+
/** Preview of the content */
|
|
369
|
+
preview?: string;
|
|
370
|
+
/** Full content */
|
|
371
|
+
content?: string;
|
|
372
|
+
/** MIME type of the source content */
|
|
373
|
+
contentType?: string;
|
|
374
|
+
/** Name of the source file */
|
|
375
|
+
fileName?: string;
|
|
376
|
+
/** Reference metadata including signed URLs */
|
|
377
|
+
reference?: {
|
|
378
|
+
id?: string;
|
|
379
|
+
file?: {
|
|
380
|
+
name?: string;
|
|
381
|
+
signedUrl?: string;
|
|
382
|
+
metadata?: Record<string, unknown>;
|
|
383
|
+
};
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Unified trace event type for all trace adapter communications.
|
|
388
|
+
*
|
|
389
|
+
* This discriminated union consolidates all trace-related events into a single type,
|
|
390
|
+
* simplifying the TraceAdapter interface and eliminating duplicate type definitions.
|
|
391
|
+
*/
|
|
392
|
+
type TraceEvent = {
|
|
393
|
+
type: 'step';
|
|
394
|
+
step: TraceStep;
|
|
395
|
+
} | {
|
|
396
|
+
type: 'trace_complete';
|
|
397
|
+
trace: ExecutionTrace;
|
|
398
|
+
} | {
|
|
399
|
+
type: 'session_id';
|
|
400
|
+
sessionId: string;
|
|
401
|
+
} | {
|
|
402
|
+
type: 'follow_up';
|
|
403
|
+
questions: string[];
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
export { type AgentContext as A, type ConversationMessage as C, type DisambiguationResult as D, type ExecutionTrace as E, type Intent as I, type KBRetrieval as K, type LogLevel as L, type MultiChoiceOption as M, type Plan as P, type Slots as S, type TraceStep as T, type LogEntry as a, type TraceEvent as b, type ChatResponse as c, type ChatCitation as d, type StepResult as e, type PlanStepKBCall as f, type PlanStepSynthesis as g, createSessionLogger as h, subscribeToTraceSteps as i, emitTraceStep as j, getSessionLogs as k, clearSessionLogs as l, type PlanStepType as m, type PlanStep as n, type TraceStepType as o, type PendingQuestion as p, type DisambiguationAction as q, type DisambiguationDetails as r, subscribeToLogs as s, type LLMExtractionFacts as t, type KBRelevanceInfo as u, type PlanningReasoning as v, type PlanModification as w, type ChatRequest as x, type ChatOutcome as y };
|