@kuralle-agents/core 0.13.0 → 0.15.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.
Files changed (160) hide show
  1. package/README.md +4 -4
  2. package/dist/ai-sdk/uiMessageStream.d.ts +2 -2
  3. package/dist/ai-sdk/uiMessageStream.js +42 -29
  4. package/dist/capabilities/LivePromptAssembler.d.ts +1 -1
  5. package/dist/capabilities/LivePromptAssembler.js +1 -1
  6. package/dist/capabilities/index.d.ts +1 -1
  7. package/dist/eval/EvalRunner.js +4 -4
  8. package/dist/eval/simulation.js +4 -3
  9. package/dist/events/TurnHandle.d.ts +3 -3
  10. package/dist/flow/collectUntilComplete.js +30 -7
  11. package/dist/flow/degrade.js +8 -4
  12. package/dist/flow/emitInteractive.d.ts +2 -2
  13. package/dist/flow/emitInteractive.js +6 -3
  14. package/dist/flow/extraction.d.ts +21 -2
  15. package/dist/flow/extraction.js +62 -7
  16. package/dist/flow/reduceTransition.d.ts +2 -2
  17. package/dist/flow/reduceTransition.js +7 -3
  18. package/dist/flow/runFlow.d.ts +11 -0
  19. package/dist/flow/runFlow.js +68 -12
  20. package/dist/foundation/AgentStateController.d.ts +1 -1
  21. package/dist/foundation/ToolExecutor.d.ts +2 -2
  22. package/dist/foundation/index.d.ts +0 -11
  23. package/dist/foundation/index.js +0 -5
  24. package/dist/index.d.ts +9 -14
  25. package/dist/index.js +5 -6
  26. package/dist/outcomes/streamPart.d.ts +2 -2
  27. package/dist/outcomes/streamPart.js +2 -3
  28. package/dist/prompts/PromptBuilder.d.ts +3 -3
  29. package/dist/prompts/PromptBuilder.js +6 -6
  30. package/dist/prompts/index.d.ts +1 -1
  31. package/dist/prompts/types.d.ts +7 -2
  32. package/dist/runtime/InMemoryRetrievalCache.d.ts +1 -1
  33. package/dist/runtime/KnowledgeProvider.d.ts +3 -2
  34. package/dist/runtime/KnowledgeProvider.js +54 -30
  35. package/dist/runtime/Runtime.d.ts +9 -1
  36. package/dist/runtime/Runtime.js +123 -30
  37. package/dist/runtime/TraceRecorder.d.ts +22 -4
  38. package/dist/runtime/TraceRecorder.js +65 -29
  39. package/dist/runtime/buildAgentToolSurface.js +1 -1
  40. package/dist/runtime/channels/TextDriver.js +12 -9
  41. package/dist/runtime/channels/executeModelTool.d.ts +6 -0
  42. package/dist/runtime/channels/executeModelTool.js +70 -10
  43. package/dist/runtime/channels/extractionTurn.js +1 -1
  44. package/dist/runtime/channels/index.d.ts +0 -3
  45. package/dist/runtime/channels/index.js +0 -6
  46. package/dist/runtime/channels/streaming/hostControlSpeak.js +5 -1
  47. package/dist/runtime/channels/streaming/speakGated.js +33 -12
  48. package/dist/runtime/citations/index.d.ts +3 -3
  49. package/dist/runtime/closeRun.js +3 -2
  50. package/dist/runtime/controlFlowSignal.d.ts +24 -0
  51. package/dist/runtime/controlFlowSignal.js +29 -0
  52. package/dist/runtime/ctx.d.ts +3 -4
  53. package/dist/runtime/ctx.js +39 -5
  54. package/dist/runtime/durable/RunStore.js +1 -1
  55. package/dist/runtime/grounding/gather.d.ts +1 -1
  56. package/dist/runtime/grounding/inMemoryKnowledge.d.ts +1 -1
  57. package/dist/runtime/grounding/knowledge.d.ts +1 -1
  58. package/dist/runtime/hostLoop.js +39 -10
  59. package/dist/runtime/index.d.ts +1 -2
  60. package/dist/runtime/index.js +1 -1
  61. package/dist/runtime/outcomeMarking.d.ts +2 -2
  62. package/dist/runtime/outcomeMarking.js +2 -1
  63. package/dist/runtime/policies/agentTurn.d.ts +1 -1
  64. package/dist/runtime/runHookSafely.d.ts +3 -0
  65. package/dist/runtime/runHookSafely.js +19 -0
  66. package/dist/scheduler/index.d.ts +2 -2
  67. package/dist/scheduler/index.js +1 -1
  68. package/dist/services/TracingService.js +2 -3
  69. package/dist/skills/collectSkills.d.ts +11 -3
  70. package/dist/skills/collectSkills.js +51 -8
  71. package/dist/skills/compositeSkillStore.d.ts +26 -0
  72. package/dist/skills/compositeSkillStore.js +54 -0
  73. package/dist/skills/defineSkill.d.ts +21 -0
  74. package/dist/skills/defineSkill.js +26 -0
  75. package/dist/skills/fsSkillStore.d.ts +3 -0
  76. package/dist/skills/fsSkillStore.js +79 -0
  77. package/dist/skills/index.d.ts +4 -0
  78. package/dist/skills/index.js +4 -0
  79. package/dist/skills/parseSkillFrontmatter.d.ts +14 -0
  80. package/dist/skills/parseSkillFrontmatter.js +183 -0
  81. package/dist/skills/wireAgentSkills.d.ts +2 -1
  82. package/dist/skills/wireAgentSkills.js +2 -2
  83. package/dist/testing/mocks.d.ts +3 -3
  84. package/dist/testing/mocks.js +7 -3
  85. package/dist/tools/controlResults.d.ts +14 -0
  86. package/dist/tools/controlResults.js +15 -0
  87. package/dist/tools/effect/ToolExecutor.d.ts +6 -0
  88. package/dist/tools/effect/ToolExecutor.js +71 -35
  89. package/dist/tools/effect/defineTool.d.ts +9 -0
  90. package/dist/tools/effect/defineTool.js +1 -0
  91. package/dist/tools/effect/errors.d.ts +2 -5
  92. package/dist/tools/effect/errors.js +2 -5
  93. package/dist/tools/fs/createFsTool.js +2 -1
  94. package/dist/tools/index.d.ts +0 -1
  95. package/dist/tools/index.js +0 -1
  96. package/dist/types/effectTool.d.ts +2 -0
  97. package/dist/types/flow.d.ts +1 -1
  98. package/dist/types/guardrails.d.ts +5 -0
  99. package/dist/types/hooks.d.ts +2 -2
  100. package/dist/types/index.d.ts +25 -16
  101. package/dist/types/index.js +8 -13
  102. package/dist/types/knowledge.d.ts +213 -0
  103. package/dist/types/processors.d.ts +0 -58
  104. package/dist/types/run-context.d.ts +3 -7
  105. package/dist/types/runtime.d.ts +3 -74
  106. package/dist/types/session.d.ts +1 -1
  107. package/dist/types/skills.d.ts +15 -1
  108. package/dist/types/stream.d.ts +133 -71
  109. package/dist/types/stream.js +34 -1
  110. package/dist/types/trace.d.ts +2 -0
  111. package/guides/AGENTS.md +3 -3
  112. package/guides/FLOWS.md +1 -1
  113. package/guides/GETTING_STARTED.md +1 -1
  114. package/guides/RUNTIME.md +20 -15
  115. package/guides/TOOLS.md +1 -1
  116. package/package.json +3 -13
  117. package/dist/foundation/AgentDefinition.d.ts +0 -17
  118. package/dist/foundation/ConversationEventLog.d.ts +0 -71
  119. package/dist/foundation/ConversationEventLog.js +0 -1
  120. package/dist/foundation/ConversationState.d.ts +0 -33
  121. package/dist/foundation/ConversationState.js +0 -1
  122. package/dist/foundation/DefaultConversationEventLog.d.ts +0 -27
  123. package/dist/foundation/DefaultConversationEventLog.js +0 -205
  124. package/dist/foundation/DefaultConversationState.d.ts +0 -36
  125. package/dist/foundation/DefaultConversationState.js +0 -103
  126. package/dist/foundation/DefaultToolExecutor.d.ts +0 -57
  127. package/dist/foundation/DefaultToolExecutor.js +0 -132
  128. package/dist/foundation/createFoundation.d.ts +0 -32
  129. package/dist/foundation/createFoundation.js +0 -33
  130. package/dist/hooks/HookRunner.d.ts +0 -37
  131. package/dist/hooks/HookRunner.js +0 -111
  132. package/dist/hooks/builtin/logging.d.ts +0 -5
  133. package/dist/hooks/builtin/logging.js +0 -98
  134. package/dist/hooks/builtin/metrics.d.ts +0 -7
  135. package/dist/hooks/builtin/metrics.js +0 -60
  136. package/dist/hooks/builtin/observability.d.ts +0 -20
  137. package/dist/hooks/builtin/observability.js +0 -572
  138. package/dist/hooks/helpers.d.ts +0 -22
  139. package/dist/hooks/helpers.js +0 -183
  140. package/dist/hooks/index.d.ts +0 -8
  141. package/dist/hooks/index.js +0 -6
  142. package/dist/realtime/RealtimeAudioClient.d.ts +0 -166
  143. package/dist/realtime/RealtimeAudioClient.js +0 -14
  144. package/dist/realtime/RealtimeSessionHandle.d.ts +0 -6
  145. package/dist/realtime/RealtimeSessionHandle.js +0 -1
  146. package/dist/realtime/index.d.ts +0 -2
  147. package/dist/realtime/index.js +0 -1
  148. package/dist/runtime/channels/VoiceDriver.d.ts +0 -31
  149. package/dist/runtime/channels/VoiceDriver.js +0 -321
  150. package/dist/runtime/channels/voiceTools.d.ts +0 -9
  151. package/dist/runtime/channels/voiceTools.js +0 -51
  152. package/dist/tools/errorHandling.d.ts +0 -35
  153. package/dist/tools/errorHandling.js +0 -145
  154. package/dist/types/voice.d.ts +0 -517
  155. package/dist/types/voice.js +0 -14
  156. package/dist/utils/isRecord.d.ts +0 -1
  157. package/dist/utils/isRecord.js +0 -3
  158. package/dist/utils/messageNormalization.d.ts +0 -2
  159. package/dist/utils/messageNormalization.js +0 -137
  160. /package/dist/{foundation/AgentDefinition.js → types/knowledge.js} +0 -0
@@ -0,0 +1,213 @@
1
+ import type { StreamPart } from './stream.js';
2
+ /**
3
+ * Runtime-level knowledge configuration. Configured once on the Runtime,
4
+ * inherited by all agents. Per-agent overrides via `AgentKnowledgeOverrides`
5
+ * can only reduce capabilities (e.g., disable compiled knowledge, restrict
6
+ * topK, filter by metadata).
7
+ */
8
+ export interface KnowledgeProviderConfig {
9
+ /**
10
+ * Retriever for hybrid search (Layer 3). Any object implementing the
11
+ * Retriever interface from `@kuralle-agents/rag`. When not provided,
12
+ * only compiled knowledge and cache are available.
13
+ */
14
+ retriever?: KnowledgeRetrieverAdapter;
15
+ /**
16
+ * Embedder for cache similarity lookup. Required when `retriever` is
17
+ * provided (needed for cache population and query embedding).
18
+ */
19
+ embedder?: KnowledgeEmbedderAdapter;
20
+ /**
21
+ * Pre-compiled knowledge content (Layer 1). Injected into the system
22
+ * prompt every turn with zero search latency. Produced offline by
23
+ * KnowledgeCompiler.
24
+ */
25
+ compiled?: string;
26
+ /**
27
+ * Retrieval cache configuration. When omitted, a default configuration
28
+ * is used (maxEntries: 256, ttlMs: 300000, similarityThreshold: 0.85).
29
+ */
30
+ cache?: {
31
+ /** Maximum entries in the LRU cache. Default: 256. */
32
+ maxEntries?: number;
33
+ /** Cache entry TTL in milliseconds. Default: 300000 (5 minutes). */
34
+ ttlMs?: number;
35
+ /** Minimum cosine similarity for a cache hit. Default: 0.85. */
36
+ similarityThreshold?: number;
37
+ };
38
+ /**
39
+ * Predictive pre-fetch configuration. When enabled, the system
40
+ * predicts follow-up topics from the conversation window and
41
+ * pre-fetches relevant content into the session cache.
42
+ */
43
+ prefetch?: {
44
+ /** Enable predictive pre-fetching. Default: false. */
45
+ enabled?: boolean;
46
+ /** Number of keywords to extract per prediction. Default: 3. */
47
+ maxKeywords?: number;
48
+ /** Number of recent messages to analyze. Default: 5. */
49
+ conversationWindow?: number;
50
+ };
51
+ /**
52
+ * Default retrieval options applied to all agents unless overridden.
53
+ */
54
+ defaults?: {
55
+ /** Maximum results from Layer 3 search. Default: 5. */
56
+ topK?: number;
57
+ /** Maximum tokens for retrieval context in the system prompt. Default: 2000. */
58
+ maxOutputTokens?: number;
59
+ /** Whether to include embedding vectors in results (for cache writeback). Default: true. */
60
+ includeEmbeddings?: boolean;
61
+ };
62
+ /**
63
+ * Retrieval quality checking configuration. When configured, retrieval
64
+ * results are evaluated using score distribution (sub-millisecond).
65
+ * For text agents, low-quality results trigger inline reformulation.
66
+ * For voice agents, low-quality results trigger background reformulation
67
+ * via the pre-fetcher.
68
+ */
69
+ qualityCheck?: {
70
+ /** Minimum top-result score to consider quality "high". Default: 0.5. */
71
+ highThreshold?: number;
72
+ /** Minimum top-result score to consider quality "medium". Default: 0.3. */
73
+ mediumThreshold?: number;
74
+ /**
75
+ * Query reformulator callback. When provided and quality is "low",
76
+ * the system rewrites the query and re-retrieves.
77
+ */
78
+ reformulate?: (query: string, results: KnowledgeRetrievalResult[]) => Promise<string>;
79
+ };
80
+ /**
81
+ * How retrieved source references should be rendered into the model prompt.
82
+ * Defaults to 'footnotes'.
83
+ */
84
+ renderCitations?: 'inline' | 'footnotes' | 'off';
85
+ }
86
+ /**
87
+ * Per-agent knowledge overrides. Can only reduce capabilities — cannot
88
+ * add a retriever that doesn't exist at the Runtime level.
89
+ */
90
+ export interface AgentKnowledgeOverrides {
91
+ /** Disable compiled knowledge injection for this agent. */
92
+ compiledEnabled?: boolean;
93
+ /** Disable retrieval tool for this agent. */
94
+ toolEnabled?: boolean;
95
+ /** Override topK (must be <= Runtime default). */
96
+ topK?: number;
97
+ /** Override max output tokens (must be <= Runtime default). */
98
+ maxOutputTokens?: number;
99
+ /** Metadata filter restricting which documents this agent can access. */
100
+ filter?: Record<string, unknown>;
101
+ }
102
+ /**
103
+ * Adapter interface for retrievers used by KnowledgeProvider.
104
+ * Mirrors the Retriever interface from `@kuralle-agents/rag` without
105
+ * creating a dependency from core → rag.
106
+ */
107
+ export interface KnowledgeRetrieverAdapter {
108
+ retrieve(query: string, options?: {
109
+ topK?: number;
110
+ filter?: Record<string, unknown>;
111
+ queryEmbedding?: readonly number[];
112
+ includeEmbeddings?: boolean;
113
+ }): Promise<KnowledgeRetrievalResult[]>;
114
+ }
115
+ /**
116
+ * Adapter interface for embedders used by KnowledgeProvider.
117
+ * Mirrors the Embedder interface from `@kuralle-agents/rag`.
118
+ */
119
+ export interface KnowledgeEmbedderAdapter {
120
+ embed(text: string): Promise<readonly number[]>;
121
+ }
122
+ export interface SourceRef {
123
+ readonly id: string;
124
+ readonly title?: string;
125
+ readonly url?: string;
126
+ readonly lastModified?: string;
127
+ readonly score?: number;
128
+ }
129
+ /**
130
+ * A single result from knowledge retrieval, used across the pipeline.
131
+ */
132
+ export interface KnowledgeRetrievalResult {
133
+ id: string;
134
+ text: string;
135
+ sourceId: string;
136
+ score?: number;
137
+ relevanceScore?: number;
138
+ snippet?: string;
139
+ metadata?: Record<string, unknown>;
140
+ embedding?: readonly number[];
141
+ }
142
+ export type KnowledgeChunk = KnowledgeRetrievalResult;
143
+ /**
144
+ * Interface for the session-level retrieval cache. Implemented by
145
+ * `RetrievalCache` from `@kuralle-agents/rag`. Defined here so
146
+ * `RunContext.retrievalCache` can be properly typed without core
147
+ * depending on rag.
148
+ */
149
+ export interface RetrievalCacheAdapter {
150
+ lookup(queryEmbedding: readonly number[], topK?: number): KnowledgeRetrievalResult[];
151
+ populate(results: KnowledgeRetrievalResult[], queryEmbedding?: readonly number[]): void;
152
+ readonly size: number;
153
+ }
154
+ export interface HttpCallbackConfig {
155
+ url: string;
156
+ method?: 'POST' | 'PUT';
157
+ headers?: Record<string, string>;
158
+ allowList?: string[];
159
+ denyList?: string[];
160
+ includeFullText?: boolean;
161
+ timeoutMs?: number;
162
+ }
163
+ export interface StreamCallbackPayload {
164
+ sessionId: string;
165
+ agentId: string;
166
+ timestamp: string;
167
+ part: StreamPart;
168
+ fullText?: string;
169
+ }
170
+ export interface StreamCallbackSink {
171
+ name?: string;
172
+ write: (payload: StreamCallbackPayload) => Promise<void>;
173
+ close?: () => Promise<void>;
174
+ }
175
+ export interface StreamCallbackConfig {
176
+ sinks?: StreamCallbackSink[];
177
+ /**
178
+ * Events to emit when no explicit allowList is provided.
179
+ * - message: emit terminal events plus tool/transition events per toggles
180
+ * - all: emit every runtime event
181
+ * Default: message
182
+ */
183
+ eventMode?: 'message' | 'all';
184
+ /**
185
+ * Emit streaming text-delta events.
186
+ * Default: false (final text is emitted on terminal events via fullText)
187
+ */
188
+ emitTextDeltas?: boolean;
189
+ /**
190
+ * Emit tool lifecycle events (tool-call/tool-result) in message mode.
191
+ * Default: true
192
+ */
193
+ emitToolEvents?: boolean;
194
+ /**
195
+ * Emit transition lifecycle events (flow-transition/handoff) in message mode.
196
+ * Default: true
197
+ */
198
+ emitTransitionEvents?: boolean;
199
+ /**
200
+ * Attach accumulated assistant text as fullText on terminal events.
201
+ * Default: true
202
+ */
203
+ emitFinalText?: boolean;
204
+ allowList?: string[];
205
+ denyList?: string[];
206
+ includeFullText?: boolean;
207
+ maxQueueSize?: number;
208
+ dropPolicy?: 'drop_oldest' | 'drop_newest';
209
+ logDroppedEvents?: boolean;
210
+ /** If true, wait for sink queue drain when a stream call ends. Default: false. */
211
+ flushOnEnd?: boolean;
212
+ flushTimeoutMs?: number;
213
+ }
@@ -70,61 +70,3 @@ export interface AgentCapabilityDescriptor {
70
70
  handlesIntents?: string[];
71
71
  doesNotHandle?: string[];
72
72
  }
73
- export type AgentStreamPart = {
74
- type: 'text-start';
75
- id: string;
76
- } | {
77
- type: 'text-delta';
78
- id: string;
79
- delta: string;
80
- } | {
81
- type: 'text-end';
82
- id: string;
83
- } | {
84
- type: 'text-cancel';
85
- id: string;
86
- reason: string;
87
- } | {
88
- type: 'tool-call';
89
- toolName: string;
90
- args: unknown;
91
- toolCallId?: string;
92
- } | {
93
- type: 'tool-result';
94
- toolName: string;
95
- result: unknown;
96
- toolCallId?: string;
97
- } | {
98
- type: 'tool-error';
99
- toolName: string;
100
- error: string;
101
- toolCallId?: string;
102
- } | {
103
- type: 'handoff';
104
- targetAgent: string;
105
- reason?: string;
106
- } | {
107
- type: 'node-enter';
108
- nodeName: string;
109
- } | {
110
- type: 'node-exit';
111
- nodeName: string;
112
- } | {
113
- type: 'flow-transition';
114
- from: string;
115
- to: string;
116
- } | {
117
- type: 'flow-end';
118
- reason: string;
119
- } | {
120
- type: 'custom';
121
- name: string;
122
- data: unknown;
123
- timestamp?: Date;
124
- } | {
125
- type: 'turn-end';
126
- metadata?: Record<string, unknown>;
127
- } | {
128
- type: 'error';
129
- error: string;
130
- };
@@ -3,14 +3,14 @@ import type { Session } from './session.js';
3
3
  import type { InputProcessor, OutputProcessor } from './processors.js';
4
4
  import type { RunState } from '../runtime/durable/types.js';
5
5
  import type { RunStore } from '../runtime/durable/RunStore.js';
6
- import type { HarnessStreamPart } from './stream.js';
6
+ import type { StreamPart } from './stream.js';
7
7
  import type { RefinementCapability } from '../capabilities/RefinementCapability.js';
8
8
  import type { ValidationCapability } from '../capabilities/ValidationCapability.js';
9
9
  import type { Limits } from './guardrails.js';
10
10
  import type { AnyTool } from './effectTool.js';
11
11
  import type { FileSystem } from './filesystem.js';
12
12
  import type { Instructions } from './agentConfig.js';
13
- import type { AgentKnowledgeOverrides, SourceRef, RetrievalCacheAdapter } from './voice.js';
13
+ import type { AgentKnowledgeOverrides, SourceRef, RetrievalCacheAdapter } from './knowledge.js';
14
14
  export interface GatherScope {
15
15
  query?: string;
16
16
  knowledge?: AgentKnowledgeOverrides & {
@@ -45,16 +45,12 @@ export interface MemoryService {
45
45
  preload?(ctx: RunContext, scope?: GatherScope): Promise<string | undefined>;
46
46
  ingest?(ctx: RunContext): Promise<void>;
47
47
  }
48
- export interface HookRunner {
49
- onStreamPart?(ctx: RunContext, part: HarnessStreamPart): void | Promise<void>;
50
- }
51
48
  export interface RunContext {
52
49
  session: Session;
53
50
  runState: RunState;
54
51
  runStore: RunStore;
55
- emit: (part: HarnessStreamPart) => void;
52
+ emit: (part: StreamPart) => void;
56
53
  toolExecutor: EffectToolExecutor;
57
- hookRunner: HookRunner;
58
54
  model: LanguageModel;
59
55
  /** Control-path model (routing, decide, extraction) at temperature 0. */
60
56
  controlModel: LanguageModel;
@@ -1,10 +1,6 @@
1
- import type { ModelMessage } from 'ai';
2
- import type { SessionEndMetadata, TurnUsage } from './telemetry.js';
3
- import type { AgentStreamPart } from './processors.js';
4
- import type { AgentContext, RunContext, Session, ToolCallRecord } from './session.js';
5
- import type { HarnessStreamPart } from './voice.js';
1
+ import type { AgentContext, RunContext } from './session.js';
2
+ import type { StreamPart } from './stream.js';
6
3
  import type { RefineDecision, ValidateDecision } from '../capabilities/index.js';
7
- import type { ConversationOutcome, ConversationOutcomeRecord } from '../outcomes/types.js';
8
4
  import type { ChannelId } from './session.js';
9
5
  export interface RefinementStageResult {
10
6
  proceed: boolean;
@@ -24,7 +20,7 @@ export interface Hook {
24
20
  name: string;
25
21
  onTurnStart?: (ctx: AgentContext, input: string) => Promise<void>;
26
22
  onTurnEnd?: (ctx: AgentContext) => Promise<void>;
27
- onStreamPart?: (ctx: AgentContext, part: AgentStreamPart) => Promise<void>;
23
+ onStreamPart?: (ctx: AgentContext, part: StreamPart) => Promise<void>;
28
24
  onAgentSwitch?: (ctx: AgentContext, from: string, to: string) => Promise<void>;
29
25
  onError?: (ctx: AgentContext, error: Error) => Promise<void>;
30
26
  }
@@ -36,73 +32,6 @@ export interface StopCondition {
36
32
  name: string;
37
33
  check: (context: RunContext) => StopConditionResult;
38
34
  }
39
- export interface StepResult {
40
- text?: string;
41
- toolCalls: ToolCallRecord[];
42
- finishReason: string;
43
- tokensUsed: number;
44
- handoffTo?: string;
45
- }
46
- export interface TurnSummary {
47
- sessionId: string;
48
- userId?: string;
49
- agentId: string;
50
- messageCount: number;
51
- toolCallCount: number;
52
- totalTokens: number;
53
- }
54
- export interface TurnEndHookResult {
55
- outcome?: ConversationOutcome;
56
- reason?: string;
57
- }
58
- export interface HarnessHooks {
59
- onStart?: (context: RunContext) => Promise<void>;
60
- onEnd?: (context: RunContext, result: {
61
- success: boolean;
62
- error?: Error;
63
- }) => Promise<void>;
64
- onStepStart?: (context: RunContext, step: number) => Promise<void>;
65
- onStepEnd?: (context: RunContext, step: number, result: StepResult) => Promise<void>;
66
- onToolCall?: (context: RunContext, call: ToolCallRecord) => Promise<void>;
67
- onToolResult?: (context: RunContext, call: ToolCallRecord) => Promise<void>;
68
- onToolError?: (context: RunContext, call: ToolCallRecord, error: Error) => Promise<void>;
69
- onTurnEnd?: (context: RunContext, summary: TurnSummary) => Promise<TurnEndHookResult | void>;
70
- onAgentStart?: (context: RunContext, agentId: string) => Promise<void>;
71
- onAgentEnd?: (context: RunContext, agentId: string) => Promise<void>;
72
- onHandoff?: (context: RunContext, from: string, to: string, reason: string) => Promise<void>;
73
- onError?: (context: RunContext, error: Error) => Promise<void>;
74
- onMessage?: (context: RunContext, message: ModelMessage) => Promise<void>;
75
- onStreamPart?: (context: RunContext, part: HarnessStreamPart) => Promise<void>;
76
- onPersistenceError?: (session: Session, error: Error) => Promise<void>;
77
- onMemoryIngest?: (context: RunContext, session: Session) => Promise<boolean | void>;
78
- onMemoryIngested?: (context: RunContext, session: Session) => Promise<void>;
79
- onBeforeModelCall?: (context: RunContext, data: BeforeModelCallData) => Promise<BeforeModelCallResult | void>;
80
- onSessionEnd?: (session: Session, metadata: SessionEndMetadata) => Promise<void>;
81
- onConversationEnd?: (session: Session, outcome: ConversationOutcomeRecord) => Promise<{
82
- csatInvited: boolean;
83
- csatChannel?: 'email' | 'in-app' | 'sms';
84
- } | void>;
85
- onTokensUpdate?: (context: RunContext, turn: TurnUsage) => Promise<void> | void;
86
- }
87
- export interface BeforeModelCallData {
88
- systemPrompt: string;
89
- messages: ModelMessage[];
90
- estimatedTokens: number;
91
- agentId: string;
92
- tokenBreakdown: {
93
- basePrompt: number;
94
- autoRetrieve: number;
95
- workingMemory: number;
96
- extraction: number;
97
- longTermMemory: number;
98
- policyInjections: number;
99
- messageHistory: number;
100
- };
101
- }
102
- export interface BeforeModelCallResult {
103
- systemPrompt?: string;
104
- messages?: ModelMessage[];
105
- }
106
35
  export interface StreamOptions {
107
36
  input: string;
108
37
  sessionId?: string;
@@ -1,5 +1,5 @@
1
1
  import type { ModelMessage } from 'ai';
2
- import type { RetrievalCacheAdapter } from './voice.js';
2
+ import type { RetrievalCacheAdapter } from './knowledge.js';
3
3
  import type { RefinementStageResult } from './runtime.js';
4
4
  import type { EscalationReason, EscalationOutcome } from '../escalation/types.js';
5
5
  import type { ConversationOutcomeRecord, CsatRecord } from '../outcomes/types.js';
@@ -16,4 +16,18 @@ export interface SkillStoreLike {
16
16
  getAllSkills?(): SkillLike[] | Promise<SkillLike[]>;
17
17
  loadAllSkills?(): Promise<SkillLike[]>;
18
18
  }
19
- export type SkillSource = SkillLike | SkillLike[] | SkillStoreLike;
19
+ /**
20
+ * One way to supply skills. A `string` is a filesystem root scanned for
21
+ * `<dir>/SKILL.md`, resolved against the agent's `workspace` filesystem.
22
+ */
23
+ export type SkillEntry = SkillLike | SkillStoreLike | string;
24
+ /**
25
+ * Skills for an agent: one entry, or an ordered array mixing inline skills, stores, and
26
+ * workspace paths. **Later entries win** on a name collision, so layering reads in the
27
+ * order you write it:
28
+ *
29
+ * ```ts
30
+ * skills: ['/skills/org', '/skills/team', defineSkill({ name: 'override', … })]
31
+ * ```
32
+ */
33
+ export type SkillSource = SkillEntry | ReadonlyArray<SkillEntry>;