@kuralle-agents/core 0.12.0 → 0.14.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/README.md +89 -4
- package/dist/ai-sdk/uiMessageStream.d.ts +2 -2
- package/dist/ai-sdk/uiMessageStream.js +42 -29
- package/dist/capabilities/LivePromptAssembler.d.ts +1 -1
- package/dist/capabilities/LivePromptAssembler.js +2 -1
- package/dist/capabilities/index.d.ts +1 -1
- package/dist/eval/EvalRunner.js +4 -4
- package/dist/eval/simulation.js +4 -3
- package/dist/events/TurnHandle.d.ts +3 -3
- package/dist/flow/collectDigression.d.ts +5 -2
- package/dist/flow/collectDigression.js +48 -10
- package/dist/flow/collectUntilComplete.js +13 -5
- package/dist/flow/degrade.js +8 -4
- package/dist/flow/emitInteractive.d.ts +2 -2
- package/dist/flow/emitInteractive.js +6 -3
- package/dist/flow/extraction.d.ts +3 -2
- package/dist/flow/extraction.js +14 -4
- package/dist/flow/reduceTransition.d.ts +2 -2
- package/dist/flow/reduceTransition.js +7 -3
- package/dist/flow/runFlow.js +97 -17
- package/dist/foundation/AgentStateController.d.ts +1 -1
- package/dist/foundation/ToolExecutor.d.ts +2 -2
- package/dist/foundation/index.d.ts +0 -11
- package/dist/foundation/index.js +0 -5
- package/dist/index.d.ts +15 -15
- package/dist/index.js +9 -6
- package/dist/outcomes/streamPart.d.ts +2 -2
- package/dist/outcomes/streamPart.js +2 -3
- package/dist/prompts/PromptBuilder.d.ts +3 -3
- package/dist/prompts/PromptBuilder.js +13 -6
- package/dist/prompts/index.d.ts +1 -1
- package/dist/prompts/types.d.ts +9 -2
- package/dist/runtime/InMemoryRetrievalCache.d.ts +25 -0
- package/dist/runtime/InMemoryRetrievalCache.js +59 -0
- package/dist/runtime/KnowledgeProvider.d.ts +3 -2
- package/dist/runtime/KnowledgeProvider.js +60 -31
- package/dist/runtime/Runtime.d.ts +47 -1
- package/dist/runtime/Runtime.js +273 -36
- package/dist/runtime/TokenAccumulator.d.ts +7 -0
- package/dist/runtime/TokenAccumulator.js +7 -0
- package/dist/runtime/TraceRecorder.d.ts +51 -0
- package/dist/runtime/TraceRecorder.js +326 -0
- package/dist/runtime/buildAgentToolSurface.js +1 -1
- package/dist/runtime/channels/TextDriver.js +57 -31
- package/dist/runtime/channels/executeModelTool.d.ts +14 -1
- package/dist/runtime/channels/executeModelTool.js +132 -3
- package/dist/runtime/channels/extractionTurn.js +1 -1
- package/dist/runtime/channels/index.d.ts +0 -3
- package/dist/runtime/channels/index.js +0 -6
- package/dist/runtime/channels/inputBuffer.d.ts +1 -0
- package/dist/runtime/channels/inputBuffer.js +9 -0
- package/dist/runtime/channels/streaming/hostControlSpeak.js +5 -1
- package/dist/runtime/channels/streaming/speakGated.js +24 -12
- package/dist/runtime/citations/index.d.ts +3 -3
- package/dist/runtime/closeRun.js +14 -10
- package/dist/runtime/compaction.d.ts +2 -0
- package/dist/runtime/compaction.js +3 -2
- package/dist/runtime/controlFlowSignal.d.ts +24 -0
- package/dist/runtime/controlFlowSignal.js +29 -0
- package/dist/runtime/ctx.d.ts +3 -4
- package/dist/runtime/ctx.js +147 -60
- package/dist/runtime/durable/RunStore.d.ts +16 -0
- package/dist/runtime/durable/RunStore.js +7 -1
- package/dist/runtime/durable/SessionRunStore.d.ts +7 -2
- package/dist/runtime/durable/SessionRunStore.js +136 -34
- package/dist/runtime/durable/idempotency.d.ts +1 -0
- package/dist/runtime/durable/idempotency.js +3 -0
- package/dist/runtime/durable/replay.js +7 -2
- package/dist/runtime/durable/types.d.ts +11 -0
- package/dist/runtime/goals.d.ts +18 -0
- package/dist/runtime/goals.js +158 -0
- package/dist/runtime/grounding/gather.d.ts +1 -1
- package/dist/runtime/grounding/inMemoryKnowledge.d.ts +1 -1
- package/dist/runtime/grounding/knowledge.d.ts +1 -1
- package/dist/runtime/grounding/knowledge.js +1 -1
- package/dist/runtime/handoffContinuation.d.ts +20 -0
- package/dist/runtime/handoffContinuation.js +30 -0
- package/dist/runtime/handoffOscillation.d.ts +6 -0
- package/dist/runtime/handoffOscillation.js +17 -0
- package/dist/runtime/hostLoop.js +37 -6
- package/dist/runtime/index.d.ts +4 -3
- package/dist/runtime/index.js +2 -1
- package/dist/runtime/openRun.d.ts +2 -0
- package/dist/runtime/openRun.js +46 -17
- package/dist/runtime/outcomeMarking.d.ts +2 -2
- package/dist/runtime/outcomeMarking.js +2 -1
- package/dist/runtime/policies/agentTurn.d.ts +1 -1
- package/dist/runtime/policies/limits.d.ts +1 -0
- package/dist/runtime/policies/limits.js +3 -0
- package/dist/runtime/runHookSafely.d.ts +3 -0
- package/dist/runtime/runHookSafely.js +19 -0
- package/dist/runtime/select.d.ts +5 -1
- package/dist/runtime/select.js +30 -1
- package/dist/runtime/turnTokenUsage.d.ts +28 -0
- package/dist/runtime/turnTokenUsage.js +70 -0
- package/dist/scheduler/index.d.ts +2 -2
- package/dist/scheduler/index.js +1 -1
- package/dist/services/TracingService.js +2 -3
- package/dist/session/SessionStore.d.ts +6 -0
- package/dist/session/SessionStore.js +12 -1
- package/dist/session/stores/MemoryStore.d.ts +1 -1
- package/dist/session/stores/MemoryStore.js +16 -2
- package/dist/session/testing.d.ts +6 -1
- package/dist/session/testing.js +34 -0
- package/dist/session/utils.d.ts +3 -0
- package/dist/session/utils.js +23 -0
- package/dist/skills/collectSkills.d.ts +11 -3
- package/dist/skills/collectSkills.js +51 -8
- package/dist/skills/compositeSkillStore.d.ts +26 -0
- package/dist/skills/compositeSkillStore.js +54 -0
- package/dist/skills/defineSkill.d.ts +21 -0
- package/dist/skills/defineSkill.js +26 -0
- package/dist/skills/fsSkillStore.d.ts +3 -0
- package/dist/skills/fsSkillStore.js +79 -0
- package/dist/skills/index.d.ts +4 -0
- package/dist/skills/index.js +4 -0
- package/dist/skills/parseSkillFrontmatter.d.ts +14 -0
- package/dist/skills/parseSkillFrontmatter.js +183 -0
- package/dist/skills/wireAgentSkills.d.ts +2 -1
- package/dist/skills/wireAgentSkills.js +2 -2
- package/dist/testing/mocks.d.ts +3 -3
- package/dist/testing/mocks.js +7 -3
- package/dist/tools/controlResults.d.ts +14 -0
- package/dist/tools/controlResults.js +15 -0
- package/dist/tools/effect/ToolExecutor.d.ts +6 -0
- package/dist/tools/effect/ToolExecutor.js +75 -36
- package/dist/tools/effect/defineTool.d.ts +11 -0
- package/dist/tools/effect/defineTool.js +3 -0
- package/dist/tools/effect/errors.d.ts +2 -5
- package/dist/tools/effect/errors.js +2 -5
- package/dist/tools/index.d.ts +0 -1
- package/dist/tools/index.js +0 -1
- package/dist/tracing/MemoryTraceStore.d.ts +16 -0
- package/dist/tracing/MemoryTraceStore.js +56 -0
- package/dist/tracing/OtelTraceSink.d.ts +127 -0
- package/dist/tracing/OtelTraceSink.js +101 -0
- package/dist/tracing/TraceStore.d.ts +19 -0
- package/dist/tracing/TraceStore.js +32 -0
- package/dist/tracing/index.d.ts +3 -0
- package/dist/tracing/index.js +3 -0
- package/dist/tracing/testing.d.ts +3 -0
- package/dist/tracing/testing.js +45 -0
- package/dist/types/agentConfig.d.ts +2 -1
- package/dist/types/channel.d.ts +14 -1
- package/dist/types/effectTool.d.ts +6 -0
- package/dist/types/flow.d.ts +1 -1
- package/dist/types/guardrails.d.ts +5 -0
- package/dist/types/hooks.d.ts +2 -2
- package/dist/types/index.d.ts +25 -15
- package/dist/types/index.js +8 -12
- package/dist/types/knowledge.d.ts +213 -0
- package/dist/types/processors.d.ts +0 -58
- package/dist/types/run-context.d.ts +16 -7
- package/dist/types/runtime.d.ts +3 -74
- package/dist/types/session.d.ts +11 -1
- package/dist/types/skills.d.ts +15 -1
- package/dist/types/stream.d.ts +138 -68
- package/dist/types/stream.js +34 -1
- package/dist/types/trace.d.ts +52 -0
- package/guides/AGENTS.md +3 -3
- package/guides/EXAMPLE_VERIFICATION.md +4 -4
- package/guides/FLOWS.md +1 -1
- package/guides/GETTING_STARTED.md +1 -1
- package/guides/RUNTIME.md +20 -15
- package/guides/TOOLS.md +1 -1
- package/package.json +13 -14
- package/dist/foundation/AgentDefinition.d.ts +0 -17
- package/dist/foundation/ConversationEventLog.d.ts +0 -71
- package/dist/foundation/ConversationState.d.ts +0 -33
- package/dist/foundation/ConversationState.js +0 -1
- package/dist/foundation/DefaultConversationEventLog.d.ts +0 -27
- package/dist/foundation/DefaultConversationEventLog.js +0 -205
- package/dist/foundation/DefaultConversationState.d.ts +0 -36
- package/dist/foundation/DefaultConversationState.js +0 -103
- package/dist/foundation/DefaultToolExecutor.d.ts +0 -57
- package/dist/foundation/DefaultToolExecutor.js +0 -132
- package/dist/foundation/createFoundation.d.ts +0 -32
- package/dist/foundation/createFoundation.js +0 -33
- package/dist/hooks/HookRunner.d.ts +0 -37
- package/dist/hooks/HookRunner.js +0 -111
- package/dist/hooks/builtin/logging.d.ts +0 -5
- package/dist/hooks/builtin/logging.js +0 -98
- package/dist/hooks/builtin/metrics.d.ts +0 -7
- package/dist/hooks/builtin/metrics.js +0 -60
- package/dist/hooks/builtin/observability.d.ts +0 -20
- package/dist/hooks/builtin/observability.js +0 -572
- package/dist/hooks/helpers.d.ts +0 -22
- package/dist/hooks/helpers.js +0 -183
- package/dist/hooks/index.d.ts +0 -8
- package/dist/hooks/index.js +0 -6
- package/dist/realtime/RealtimeAudioClient.d.ts +0 -166
- package/dist/realtime/RealtimeAudioClient.js +0 -14
- package/dist/realtime/RealtimeSessionHandle.d.ts +0 -6
- package/dist/realtime/RealtimeSessionHandle.js +0 -1
- package/dist/realtime/index.d.ts +0 -2
- package/dist/realtime/index.js +0 -1
- package/dist/runtime/channels/VoiceDriver.d.ts +0 -31
- package/dist/runtime/channels/VoiceDriver.js +0 -321
- package/dist/runtime/channels/voiceTools.d.ts +0 -9
- package/dist/runtime/channels/voiceTools.js +0 -51
- package/dist/tools/errorHandling.d.ts +0 -35
- package/dist/tools/errorHandling.js +0 -145
- package/dist/types/voice.d.ts +0 -517
- package/dist/types/voice.js +0 -14
- package/dist/utils/isRecord.d.ts +0 -1
- package/dist/utils/isRecord.js +0 -3
- package/dist/utils/messageNormalization.d.ts +0 -2
- package/dist/utils/messageNormalization.js +0 -137
- /package/dist/{foundation/AgentDefinition.js → types/knowledge.js} +0 -0
- /package/dist/{foundation/ConversationEventLog.js → types/trace.js} +0 -0
package/dist/types/voice.d.ts
DELETED
|
@@ -1,517 +0,0 @@
|
|
|
1
|
-
import type { ConversationOutcome, ConversationOutcomeMarkedBy } from '../outcomes/types.js';
|
|
2
|
-
import type { ChannelId } from './session.js';
|
|
3
|
-
/**
|
|
4
|
-
* Runtime-level knowledge configuration. Configured once on the Runtime,
|
|
5
|
-
* inherited by all agents. Per-agent overrides via `AgentKnowledgeOverrides`
|
|
6
|
-
* can only reduce capabilities (e.g., disable compiled knowledge, restrict
|
|
7
|
-
* topK, filter by metadata).
|
|
8
|
-
*/
|
|
9
|
-
export interface KnowledgeProviderConfig {
|
|
10
|
-
/**
|
|
11
|
-
* Retriever for hybrid search (Layer 3). Any object implementing the
|
|
12
|
-
* Retriever interface from `@kuralle-agents/rag`. When not provided,
|
|
13
|
-
* only compiled knowledge and cache are available.
|
|
14
|
-
*/
|
|
15
|
-
retriever?: KnowledgeRetrieverAdapter;
|
|
16
|
-
/**
|
|
17
|
-
* Embedder for cache similarity lookup. Required when `retriever` is
|
|
18
|
-
* provided (needed for cache population and query embedding).
|
|
19
|
-
*/
|
|
20
|
-
embedder?: KnowledgeEmbedderAdapter;
|
|
21
|
-
/**
|
|
22
|
-
* Pre-compiled knowledge content (Layer 1). Injected into the system
|
|
23
|
-
* prompt every turn with zero search latency. Produced offline by
|
|
24
|
-
* KnowledgeCompiler.
|
|
25
|
-
*/
|
|
26
|
-
compiled?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Retrieval cache configuration. When omitted, a default configuration
|
|
29
|
-
* is used (maxEntries: 256, ttlMs: 300000, similarityThreshold: 0.85).
|
|
30
|
-
*/
|
|
31
|
-
cache?: {
|
|
32
|
-
/** Maximum entries in the LRU cache. Default: 256. */
|
|
33
|
-
maxEntries?: number;
|
|
34
|
-
/** Cache entry TTL in milliseconds. Default: 300000 (5 minutes). */
|
|
35
|
-
ttlMs?: number;
|
|
36
|
-
/** Minimum cosine similarity for a cache hit. Default: 0.85. */
|
|
37
|
-
similarityThreshold?: number;
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Predictive pre-fetch configuration. When enabled, the system
|
|
41
|
-
* predicts follow-up topics from the conversation window and
|
|
42
|
-
* pre-fetches relevant content into the session cache.
|
|
43
|
-
*/
|
|
44
|
-
prefetch?: {
|
|
45
|
-
/** Enable predictive pre-fetching. Default: false. */
|
|
46
|
-
enabled?: boolean;
|
|
47
|
-
/** Number of keywords to extract per prediction. Default: 3. */
|
|
48
|
-
maxKeywords?: number;
|
|
49
|
-
/** Number of recent messages to analyze. Default: 5. */
|
|
50
|
-
conversationWindow?: number;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Default retrieval options applied to all agents unless overridden.
|
|
54
|
-
*/
|
|
55
|
-
defaults?: {
|
|
56
|
-
/** Maximum results from Layer 3 search. Default: 5. */
|
|
57
|
-
topK?: number;
|
|
58
|
-
/** Maximum tokens for retrieval context in the system prompt. Default: 2000. */
|
|
59
|
-
maxOutputTokens?: number;
|
|
60
|
-
/** Whether to include embedding vectors in results (for cache writeback). Default: true. */
|
|
61
|
-
includeEmbeddings?: boolean;
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* Retrieval quality checking configuration. When configured, retrieval
|
|
65
|
-
* results are evaluated using score distribution (sub-millisecond).
|
|
66
|
-
* For text agents, low-quality results trigger inline reformulation.
|
|
67
|
-
* For voice agents, low-quality results trigger background reformulation
|
|
68
|
-
* via the pre-fetcher.
|
|
69
|
-
*/
|
|
70
|
-
qualityCheck?: {
|
|
71
|
-
/** Minimum top-result score to consider quality "high". Default: 0.5. */
|
|
72
|
-
highThreshold?: number;
|
|
73
|
-
/** Minimum top-result score to consider quality "medium". Default: 0.3. */
|
|
74
|
-
mediumThreshold?: number;
|
|
75
|
-
/**
|
|
76
|
-
* Query reformulator callback. When provided and quality is "low",
|
|
77
|
-
* the system rewrites the query and re-retrieves.
|
|
78
|
-
*/
|
|
79
|
-
reformulate?: (query: string, results: KnowledgeRetrievalResult[]) => Promise<string>;
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* How retrieved source references should be rendered into the model prompt.
|
|
83
|
-
* Defaults to 'footnotes'.
|
|
84
|
-
*/
|
|
85
|
-
renderCitations?: 'inline' | 'footnotes' | 'off';
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Per-agent knowledge overrides. Can only reduce capabilities — cannot
|
|
89
|
-
* add a retriever that doesn't exist at the Runtime level.
|
|
90
|
-
*/
|
|
91
|
-
export interface AgentKnowledgeOverrides {
|
|
92
|
-
/** Disable compiled knowledge injection for this agent. */
|
|
93
|
-
compiledEnabled?: boolean;
|
|
94
|
-
/** Disable retrieval tool for this agent. */
|
|
95
|
-
toolEnabled?: boolean;
|
|
96
|
-
/** Override topK (must be <= Runtime default). */
|
|
97
|
-
topK?: number;
|
|
98
|
-
/** Override max output tokens (must be <= Runtime default). */
|
|
99
|
-
maxOutputTokens?: number;
|
|
100
|
-
/** Metadata filter restricting which documents this agent can access. */
|
|
101
|
-
filter?: Record<string, unknown>;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Adapter interface for retrievers used by KnowledgeProvider.
|
|
105
|
-
* Mirrors the Retriever interface from `@kuralle-agents/rag` without
|
|
106
|
-
* creating a dependency from core → rag.
|
|
107
|
-
*/
|
|
108
|
-
export interface KnowledgeRetrieverAdapter {
|
|
109
|
-
retrieve(query: string, options?: {
|
|
110
|
-
topK?: number;
|
|
111
|
-
filter?: Record<string, unknown>;
|
|
112
|
-
queryEmbedding?: readonly number[];
|
|
113
|
-
includeEmbeddings?: boolean;
|
|
114
|
-
}): Promise<KnowledgeRetrievalResult[]>;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Adapter interface for embedders used by KnowledgeProvider.
|
|
118
|
-
* Mirrors the Embedder interface from `@kuralle-agents/rag`.
|
|
119
|
-
*/
|
|
120
|
-
export interface KnowledgeEmbedderAdapter {
|
|
121
|
-
embed(text: string): Promise<readonly number[]>;
|
|
122
|
-
}
|
|
123
|
-
export interface SourceRef {
|
|
124
|
-
readonly id: string;
|
|
125
|
-
readonly title?: string;
|
|
126
|
-
readonly url?: string;
|
|
127
|
-
readonly lastModified?: string;
|
|
128
|
-
readonly score?: number;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* A single result from knowledge retrieval, used across the pipeline.
|
|
132
|
-
*/
|
|
133
|
-
export interface KnowledgeRetrievalResult {
|
|
134
|
-
id: string;
|
|
135
|
-
text: string;
|
|
136
|
-
sourceId: string;
|
|
137
|
-
score?: number;
|
|
138
|
-
relevanceScore?: number;
|
|
139
|
-
snippet?: string;
|
|
140
|
-
metadata?: Record<string, unknown>;
|
|
141
|
-
embedding?: readonly number[];
|
|
142
|
-
}
|
|
143
|
-
export type KnowledgeChunk = KnowledgeRetrievalResult;
|
|
144
|
-
/**
|
|
145
|
-
* Interface for the session-level retrieval cache. Implemented by
|
|
146
|
-
* `RetrievalCache` from `@kuralle-agents/rag`. Defined here so
|
|
147
|
-
* `RunContext.retrievalCache` can be properly typed without core
|
|
148
|
-
* depending on rag.
|
|
149
|
-
*/
|
|
150
|
-
export interface RetrievalCacheAdapter {
|
|
151
|
-
lookup(queryEmbedding: readonly number[], topK?: number): KnowledgeRetrievalResult[];
|
|
152
|
-
populate(results: KnowledgeRetrievalResult[], queryEmbedding?: readonly number[]): void;
|
|
153
|
-
readonly size: number;
|
|
154
|
-
}
|
|
155
|
-
export interface HttpCallbackConfig {
|
|
156
|
-
url: string;
|
|
157
|
-
method?: 'POST' | 'PUT';
|
|
158
|
-
headers?: Record<string, string>;
|
|
159
|
-
allowList?: string[];
|
|
160
|
-
denyList?: string[];
|
|
161
|
-
includeFullText?: boolean;
|
|
162
|
-
timeoutMs?: number;
|
|
163
|
-
}
|
|
164
|
-
export interface StreamCallbackPayload {
|
|
165
|
-
sessionId: string;
|
|
166
|
-
agentId: string;
|
|
167
|
-
timestamp: string;
|
|
168
|
-
part: HarnessStreamPart;
|
|
169
|
-
fullText?: string;
|
|
170
|
-
}
|
|
171
|
-
export interface StreamCallbackSink {
|
|
172
|
-
name?: string;
|
|
173
|
-
write: (payload: StreamCallbackPayload) => Promise<void>;
|
|
174
|
-
close?: () => Promise<void>;
|
|
175
|
-
}
|
|
176
|
-
export interface StreamCallbackConfig {
|
|
177
|
-
sinks?: StreamCallbackSink[];
|
|
178
|
-
/**
|
|
179
|
-
* Events to emit when no explicit allowList is provided.
|
|
180
|
-
* - message: emit message-oriented events (input, done, error, tripwire, plus tool/transition events per toggles)
|
|
181
|
-
* - all: emit every runtime event (legacy/high-volume behavior)
|
|
182
|
-
* Default: message
|
|
183
|
-
*/
|
|
184
|
-
eventMode?: 'message' | 'all';
|
|
185
|
-
/**
|
|
186
|
-
* Emit streaming text-delta events.
|
|
187
|
-
* Default: false (final text is emitted on terminal events via fullText)
|
|
188
|
-
*/
|
|
189
|
-
emitTextDeltas?: boolean;
|
|
190
|
-
/**
|
|
191
|
-
* Emit tool lifecycle events (tool-call/tool-result/tool-error) in message mode.
|
|
192
|
-
* Default: true
|
|
193
|
-
*/
|
|
194
|
-
emitToolEvents?: boolean;
|
|
195
|
-
/**
|
|
196
|
-
* Emit transition lifecycle events (flow-transition/handoff) in message mode.
|
|
197
|
-
* Default: true
|
|
198
|
-
*/
|
|
199
|
-
emitTransitionEvents?: boolean;
|
|
200
|
-
/**
|
|
201
|
-
* Attach accumulated assistant text as fullText on terminal events.
|
|
202
|
-
* Default: true
|
|
203
|
-
*/
|
|
204
|
-
emitFinalText?: boolean;
|
|
205
|
-
allowList?: string[];
|
|
206
|
-
denyList?: string[];
|
|
207
|
-
includeFullText?: boolean;
|
|
208
|
-
maxQueueSize?: number;
|
|
209
|
-
dropPolicy?: 'drop_oldest' | 'drop_newest';
|
|
210
|
-
logDroppedEvents?: boolean;
|
|
211
|
-
/** If true, wait for sink queue drain when a stream call ends. Default: false. */
|
|
212
|
-
flushOnEnd?: boolean;
|
|
213
|
-
flushTimeoutMs?: number;
|
|
214
|
-
}
|
|
215
|
-
export type HarnessStreamPart = {
|
|
216
|
-
type: 'input';
|
|
217
|
-
text: string;
|
|
218
|
-
userId?: string;
|
|
219
|
-
} | {
|
|
220
|
-
type: 'text-start';
|
|
221
|
-
id: string;
|
|
222
|
-
} | {
|
|
223
|
-
type: 'text-delta';
|
|
224
|
-
id: string;
|
|
225
|
-
delta: string;
|
|
226
|
-
} | {
|
|
227
|
-
type: 'text-end';
|
|
228
|
-
id: string;
|
|
229
|
-
} | {
|
|
230
|
-
type: 'text-cancel';
|
|
231
|
-
id: string;
|
|
232
|
-
reason: string;
|
|
233
|
-
} | {
|
|
234
|
-
type: 'channel-switched';
|
|
235
|
-
from: ChannelId;
|
|
236
|
-
to: ChannelId;
|
|
237
|
-
conversationId: string;
|
|
238
|
-
} | {
|
|
239
|
-
type: 'channel-policy-applied';
|
|
240
|
-
channelId: ChannelId;
|
|
241
|
-
changes: Array<'strip-markdown' | 'strip-emojis' | 'truncate' | 'custom'>;
|
|
242
|
-
beforeLen: number;
|
|
243
|
-
afterLen: number;
|
|
244
|
-
} | {
|
|
245
|
-
type: 'conversation-outcome';
|
|
246
|
-
outcome: ConversationOutcome;
|
|
247
|
-
reason?: string;
|
|
248
|
-
markedBy: ConversationOutcomeMarkedBy;
|
|
249
|
-
} | {
|
|
250
|
-
type: 'tripwire';
|
|
251
|
-
phase: 'input' | 'output';
|
|
252
|
-
processorId: string;
|
|
253
|
-
reason: string;
|
|
254
|
-
message?: string;
|
|
255
|
-
} | {
|
|
256
|
-
type: 'pipeline-refinement-start';
|
|
257
|
-
capabilities: string[];
|
|
258
|
-
} | {
|
|
259
|
-
type: 'pipeline-refinement-end';
|
|
260
|
-
aggregate: 'continue' | 'rewrite' | 'escalate' | 'block';
|
|
261
|
-
confidence: number;
|
|
262
|
-
latencyMs: number;
|
|
263
|
-
} | {
|
|
264
|
-
type: 'pipeline-refinement-rewrite';
|
|
265
|
-
before: string;
|
|
266
|
-
after: string;
|
|
267
|
-
rationale: string;
|
|
268
|
-
} | {
|
|
269
|
-
type: 'pipeline-validation-start';
|
|
270
|
-
capabilities: string[];
|
|
271
|
-
} | {
|
|
272
|
-
type: 'pipeline-validation-end';
|
|
273
|
-
aggregate: 'continue' | 'rewrite' | 'block';
|
|
274
|
-
confidence: number;
|
|
275
|
-
latencyMs: number;
|
|
276
|
-
} | {
|
|
277
|
-
type: 'pipeline-validation-block';
|
|
278
|
-
rationale: string;
|
|
279
|
-
userFacingMessage?: string;
|
|
280
|
-
} | {
|
|
281
|
-
type: 'safety-blocked';
|
|
282
|
-
moderator: string;
|
|
283
|
-
rationale: string;
|
|
284
|
-
userFacingMessage: string;
|
|
285
|
-
handlerOutcome?: 'queued' | 'connected' | 'failed';
|
|
286
|
-
} | {
|
|
287
|
-
type: 'safety-rewritten';
|
|
288
|
-
moderator: string;
|
|
289
|
-
beforeLen: number;
|
|
290
|
-
afterLen: number;
|
|
291
|
-
before?: string;
|
|
292
|
-
after?: string;
|
|
293
|
-
} | {
|
|
294
|
-
type: 'safety-slow';
|
|
295
|
-
moderator: string;
|
|
296
|
-
latencyMs: number;
|
|
297
|
-
deadlineMs: number;
|
|
298
|
-
} | {
|
|
299
|
-
type: 'escalation-triggered';
|
|
300
|
-
reason: 'low-confidence' | 'user-request' | 'frustration' | 'tool-call' | 'safety-block';
|
|
301
|
-
confidence?: number;
|
|
302
|
-
handlerOutcome?: 'queued' | 'connected' | 'failed';
|
|
303
|
-
handoverMessage: string;
|
|
304
|
-
} | {
|
|
305
|
-
type: 'tool-call';
|
|
306
|
-
toolCallId: string;
|
|
307
|
-
toolName: string;
|
|
308
|
-
args: unknown;
|
|
309
|
-
} | {
|
|
310
|
-
type: 'tool-result';
|
|
311
|
-
toolCallId: string;
|
|
312
|
-
toolName: string;
|
|
313
|
-
result: unknown;
|
|
314
|
-
} | {
|
|
315
|
-
type: 'tool-error';
|
|
316
|
-
toolCallId: string;
|
|
317
|
-
toolName: string;
|
|
318
|
-
error: string;
|
|
319
|
-
} | {
|
|
320
|
-
type: 'handoff';
|
|
321
|
-
from: string;
|
|
322
|
-
to: string;
|
|
323
|
-
reason: string;
|
|
324
|
-
} | {
|
|
325
|
-
type: 'node-enter';
|
|
326
|
-
nodeName: string;
|
|
327
|
-
} | {
|
|
328
|
-
type: 'node-exit';
|
|
329
|
-
nodeName: string;
|
|
330
|
-
} | {
|
|
331
|
-
type: 'flow-transition';
|
|
332
|
-
from: string;
|
|
333
|
-
to: string;
|
|
334
|
-
} | {
|
|
335
|
-
type: 'flow-end';
|
|
336
|
-
reason: string;
|
|
337
|
-
} | {
|
|
338
|
-
type: 'turn-end';
|
|
339
|
-
} | {
|
|
340
|
-
type: 'step-start';
|
|
341
|
-
step: number;
|
|
342
|
-
agentId: string;
|
|
343
|
-
} | {
|
|
344
|
-
type: 'step-end';
|
|
345
|
-
step: number;
|
|
346
|
-
agentId: string;
|
|
347
|
-
latencyMs?: number;
|
|
348
|
-
ttftMs?: number;
|
|
349
|
-
} | {
|
|
350
|
-
type: 'persona-applied';
|
|
351
|
-
personaName: string;
|
|
352
|
-
experiment?: {
|
|
353
|
-
cohort: 'control' | 'variant';
|
|
354
|
-
allocationPct: number;
|
|
355
|
-
};
|
|
356
|
-
} | {
|
|
357
|
-
type: 'agent-start';
|
|
358
|
-
agentId: string;
|
|
359
|
-
personaName?: string;
|
|
360
|
-
experiment?: {
|
|
361
|
-
cohort: 'control' | 'variant';
|
|
362
|
-
allocationPct: number;
|
|
363
|
-
};
|
|
364
|
-
} | {
|
|
365
|
-
type: 'agent-end';
|
|
366
|
-
agentId: string;
|
|
367
|
-
} | {
|
|
368
|
-
type: 'context-compacted';
|
|
369
|
-
messagesBefore: number;
|
|
370
|
-
messagesAfter: number;
|
|
371
|
-
/** Estimated input tokens before compaction. */
|
|
372
|
-
tokensBefore?: number;
|
|
373
|
-
/** Estimated input tokens after compaction. */
|
|
374
|
-
tokensAfter?: number;
|
|
375
|
-
/** 0–100. */
|
|
376
|
-
savingsPct?: number;
|
|
377
|
-
/** Strategy actually used (may differ from configured if cooldown fired). */
|
|
378
|
-
strategy?: 'truncate' | 'summarize';
|
|
379
|
-
/** Wall-clock ms inside autoCompactMessages. */
|
|
380
|
-
latencyMs?: number;
|
|
381
|
-
/** Summarizer model id, when summarize path ran. */
|
|
382
|
-
summaryModel?: string;
|
|
383
|
-
} | {
|
|
384
|
-
type: 'compaction-skipped';
|
|
385
|
-
/** Why compaction was triggered but bailed out without changing messages. */
|
|
386
|
-
reason: 'thrashing' | 'cooldown';
|
|
387
|
-
/** Message count at the time of the skip — for caller diagnostics. */
|
|
388
|
-
messagesCount: number;
|
|
389
|
-
} | {
|
|
390
|
-
type: 'compaction-scheduled';
|
|
391
|
-
/**
|
|
392
|
-
* Where the work will run:
|
|
393
|
-
* - 'background' = off-thread (voice mode default; PR-18)
|
|
394
|
-
* - 'foreground' = blocking the current turn (text default)
|
|
395
|
-
*/
|
|
396
|
-
when: 'background' | 'foreground';
|
|
397
|
-
/** Message count at the time of scheduling. */
|
|
398
|
-
messagesCount: number;
|
|
399
|
-
} | {
|
|
400
|
-
type: 'facts-evicted';
|
|
401
|
-
/** Keys removed from session.workingMemory.__keyFacts because they exceeded factTtlSeconds. */
|
|
402
|
-
evictedKeys: string[];
|
|
403
|
-
/** TTL configured in seconds (for caller diagnostics). */
|
|
404
|
-
ttlSeconds: number;
|
|
405
|
-
} | {
|
|
406
|
-
type: 'context-overflow-recovered';
|
|
407
|
-
/** Provider error message that triggered recovery (truncated to 200 chars). */
|
|
408
|
-
errorMessage: string;
|
|
409
|
-
/** Messages stripped from the failed turn before re-compacting. */
|
|
410
|
-
messagesStripped: number;
|
|
411
|
-
/** Whether the post-recovery autoCompactMessages call actually compacted. */
|
|
412
|
-
compacted: boolean;
|
|
413
|
-
/** How many recovery attempts have occurred this step (1 = first attempt). */
|
|
414
|
-
attempt: number;
|
|
415
|
-
} | {
|
|
416
|
-
type: 'turn-timeout';
|
|
417
|
-
/** Which deadline tripped: 'overall' (turnTimeoutMs) or 'zero-token' (zeroTokenTimeoutMs). */
|
|
418
|
-
kind: 'overall' | 'zero-token';
|
|
419
|
-
/** Configured deadline in ms. */
|
|
420
|
-
deadlineMs: number;
|
|
421
|
-
/** ms from LLM call start to abort. */
|
|
422
|
-
elapsedMs: number;
|
|
423
|
-
/** True if the model produced ANY content before the deadline. */
|
|
424
|
-
anyOutput: boolean;
|
|
425
|
-
/** Agent id whose turn was aborted. */
|
|
426
|
-
agentId: string;
|
|
427
|
-
} | {
|
|
428
|
-
type: 'result-evicted';
|
|
429
|
-
toolCallId: string;
|
|
430
|
-
filepath: string;
|
|
431
|
-
} | {
|
|
432
|
-
type: 'interrupted';
|
|
433
|
-
sessionId: string;
|
|
434
|
-
reason: string;
|
|
435
|
-
timestamp: Date;
|
|
436
|
-
lastAgentId?: string;
|
|
437
|
-
lastStep?: number;
|
|
438
|
-
} | {
|
|
439
|
-
type: 'custom';
|
|
440
|
-
name: string;
|
|
441
|
-
data: unknown;
|
|
442
|
-
timestamp?: Date;
|
|
443
|
-
} | {
|
|
444
|
-
type: 'tool-start';
|
|
445
|
-
toolCallId: string;
|
|
446
|
-
toolName: string;
|
|
447
|
-
message?: string;
|
|
448
|
-
} | {
|
|
449
|
-
type: 'tool-done';
|
|
450
|
-
toolCallId: string;
|
|
451
|
-
toolName: string;
|
|
452
|
-
durationMs: number;
|
|
453
|
-
} | {
|
|
454
|
-
type: 'error';
|
|
455
|
-
error: string;
|
|
456
|
-
} | {
|
|
457
|
-
type: 'suggested-questions';
|
|
458
|
-
suggestions: string[];
|
|
459
|
-
isPartial?: boolean;
|
|
460
|
-
} | {
|
|
461
|
-
type: 'text-clear';
|
|
462
|
-
agentId: string;
|
|
463
|
-
} | {
|
|
464
|
-
type: 'knowledge-retrieval-start';
|
|
465
|
-
query: string;
|
|
466
|
-
message?: string;
|
|
467
|
-
} | {
|
|
468
|
-
type: 'knowledge-cache-hit';
|
|
469
|
-
query: string;
|
|
470
|
-
resultCount: number;
|
|
471
|
-
latencyMs: number;
|
|
472
|
-
} | {
|
|
473
|
-
type: 'knowledge-cache-miss';
|
|
474
|
-
query: string;
|
|
475
|
-
latencyMs: number;
|
|
476
|
-
} | {
|
|
477
|
-
type: 'knowledge-search';
|
|
478
|
-
query: string;
|
|
479
|
-
resultCount: number;
|
|
480
|
-
latencyMs: number;
|
|
481
|
-
layer: 'cache' | 'hybrid';
|
|
482
|
-
} | {
|
|
483
|
-
type: 'knowledge-citation';
|
|
484
|
-
sourceId: string;
|
|
485
|
-
title?: string;
|
|
486
|
-
url?: string;
|
|
487
|
-
lastModified?: string;
|
|
488
|
-
score?: number;
|
|
489
|
-
} | {
|
|
490
|
-
type: 'knowledge-no-results';
|
|
491
|
-
query: string;
|
|
492
|
-
reason: 'empty-corpus' | 'no-match' | 'retriever-error';
|
|
493
|
-
} | {
|
|
494
|
-
type: 'knowledge-prefetch';
|
|
495
|
-
keywords: string[];
|
|
496
|
-
resultCount: number;
|
|
497
|
-
} | {
|
|
498
|
-
type: 'knowledge-compiled';
|
|
499
|
-
tokenCount: number;
|
|
500
|
-
} | {
|
|
501
|
-
type: 'knowledge-quality-check';
|
|
502
|
-
query: string;
|
|
503
|
-
quality: 'high' | 'medium' | 'low';
|
|
504
|
-
topScore: number;
|
|
505
|
-
avgScore: number;
|
|
506
|
-
coverageEstimate: number;
|
|
507
|
-
} | {
|
|
508
|
-
type: 'knowledge-reformulation';
|
|
509
|
-
originalQuery: string;
|
|
510
|
-
reformulatedQuery: string;
|
|
511
|
-
trigger: 'inline' | 'background';
|
|
512
|
-
latencyMs: number;
|
|
513
|
-
} | {
|
|
514
|
-
type: 'done';
|
|
515
|
-
sessionId: string;
|
|
516
|
-
userId?: string;
|
|
517
|
-
};
|
package/dist/types/voice.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// ============================================
|
|
2
|
-
// VOICE-CRITICAL INFRASTRUCTURE
|
|
3
|
-
//
|
|
4
|
-
// Voice sessions are the highest-throughput consumer of two cross-cutting
|
|
5
|
-
// subsystems, so their types live here even though text sessions also use
|
|
6
|
-
// them:
|
|
7
|
-
// 1. Knowledge retrieval — voice latency budget demands sub-millisecond
|
|
8
|
-
// lookup; the three-layer architecture (compiled, cache, hybrid) is
|
|
9
|
-
// motivated by voice.
|
|
10
|
-
// 2. Stream/callback plumbing — voice produces many more stream parts
|
|
11
|
-
// per session than text; HarnessStreamPart, StreamCallback, and
|
|
12
|
-
// HttpCallbackConfig describe the hot-path event flow.
|
|
13
|
-
// ============================================
|
|
14
|
-
export {};
|
package/dist/utils/isRecord.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
package/dist/utils/isRecord.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
function isRecord(value) {
|
|
2
|
-
return value !== null && typeof value === 'object';
|
|
3
|
-
}
|
|
4
|
-
function getTextFromParts(parts) {
|
|
5
|
-
return parts
|
|
6
|
-
.map(part => {
|
|
7
|
-
if (!isRecord(part) || part.type !== 'text') {
|
|
8
|
-
return '';
|
|
9
|
-
}
|
|
10
|
-
return typeof part.text === 'string' ? part.text : '';
|
|
11
|
-
})
|
|
12
|
-
.join('')
|
|
13
|
-
.trim();
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Extract provider metadata fields from a part if present.
|
|
17
|
-
* Gemini thinking models require `providerMetadata.google.thoughtSignature`
|
|
18
|
-
* to be preserved on tool-call and reasoning parts. Stripping it causes
|
|
19
|
-
* "Function call is missing a thought_signature" errors on subsequent turns.
|
|
20
|
-
*/
|
|
21
|
-
function extractProviderFields(part) {
|
|
22
|
-
const extra = {};
|
|
23
|
-
if (isRecord(part.providerMetadata))
|
|
24
|
-
extra.providerMetadata = part.providerMetadata;
|
|
25
|
-
if (isRecord(part.providerOptions))
|
|
26
|
-
extra.providerOptions = part.providerOptions;
|
|
27
|
-
return extra;
|
|
28
|
-
}
|
|
29
|
-
function normalizeToolParts(parts) {
|
|
30
|
-
const normalized = [];
|
|
31
|
-
for (const part of parts) {
|
|
32
|
-
if (!isRecord(part) || typeof part.type !== 'string') {
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
if (part.type === 'tool-result') {
|
|
36
|
-
if (typeof part.toolCallId === 'string' &&
|
|
37
|
-
typeof part.toolName === 'string' &&
|
|
38
|
-
'output' in part) {
|
|
39
|
-
normalized.push({
|
|
40
|
-
type: 'tool-result',
|
|
41
|
-
toolCallId: part.toolCallId,
|
|
42
|
-
toolName: part.toolName,
|
|
43
|
-
output: part.output,
|
|
44
|
-
...extractProviderFields(part),
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
if (part.type === 'tool-approval-response') {
|
|
50
|
-
if (typeof part.approvalId === 'string' && typeof part.approved === 'boolean') {
|
|
51
|
-
normalized.push({
|
|
52
|
-
type: 'tool-approval-response',
|
|
53
|
-
approvalId: part.approvalId,
|
|
54
|
-
approved: part.approved,
|
|
55
|
-
...(typeof part.reason === 'string' ? { reason: part.reason } : {}),
|
|
56
|
-
...(typeof part.providerExecuted === 'boolean'
|
|
57
|
-
? { providerExecuted: part.providerExecuted }
|
|
58
|
-
: {}),
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return normalized;
|
|
64
|
-
}
|
|
65
|
-
function normalizeAssistantParts(parts) {
|
|
66
|
-
const normalized = [];
|
|
67
|
-
for (const part of parts) {
|
|
68
|
-
if (!isRecord(part) || typeof part.type !== 'string') {
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
if (part.type === 'text') {
|
|
72
|
-
if (typeof part.text === 'string') {
|
|
73
|
-
normalized.push({ type: 'text', text: part.text, ...extractProviderFields(part) });
|
|
74
|
-
}
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
if (part.type === 'tool-call') {
|
|
78
|
-
if (typeof part.toolCallId === 'string' &&
|
|
79
|
-
typeof part.toolName === 'string' &&
|
|
80
|
-
'input' in part) {
|
|
81
|
-
normalized.push({
|
|
82
|
-
type: 'tool-call',
|
|
83
|
-
toolCallId: part.toolCallId,
|
|
84
|
-
toolName: part.toolName,
|
|
85
|
-
input: part.input,
|
|
86
|
-
...extractProviderFields(part),
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
if (part.type === 'tool-result') {
|
|
92
|
-
if (typeof part.toolCallId === 'string' &&
|
|
93
|
-
typeof part.toolName === 'string' &&
|
|
94
|
-
'output' in part) {
|
|
95
|
-
normalized.push({
|
|
96
|
-
type: 'tool-result',
|
|
97
|
-
toolCallId: part.toolCallId,
|
|
98
|
-
toolName: part.toolName,
|
|
99
|
-
output: part.output,
|
|
100
|
-
...extractProviderFields(part),
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
if (part.type === 'reasoning' && typeof part.text === 'string') {
|
|
106
|
-
normalized.push({ type: 'reasoning', text: part.text, ...extractProviderFields(part) });
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return normalized;
|
|
110
|
-
}
|
|
111
|
-
export function normalizeModelMessage(message) {
|
|
112
|
-
const role = message.role;
|
|
113
|
-
const content = message.content;
|
|
114
|
-
if (typeof content === 'string') {
|
|
115
|
-
return message;
|
|
116
|
-
}
|
|
117
|
-
if (!Array.isArray(content)) {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
if (role === 'tool') {
|
|
121
|
-
const toolParts = normalizeToolParts(content);
|
|
122
|
-
if (toolParts.length === 0) {
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
return { role: 'tool', content: toolParts };
|
|
126
|
-
}
|
|
127
|
-
if (role === 'assistant') {
|
|
128
|
-
const assistantParts = normalizeAssistantParts(content);
|
|
129
|
-
if (assistantParts.length > 0) {
|
|
130
|
-
return { role: 'assistant', content: assistantParts };
|
|
131
|
-
}
|
|
132
|
-
const text = getTextFromParts(content);
|
|
133
|
-
return text.length > 0 ? { role, content: text } : null;
|
|
134
|
-
}
|
|
135
|
-
const text = getTextFromParts(content);
|
|
136
|
-
return text.length > 0 ? { role, content: text } : null;
|
|
137
|
-
}
|
|
File without changes
|
|
File without changes
|