@kuralle-agents/core 0.13.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 +4 -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 +1 -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/collectUntilComplete.js +4 -4
- 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 +2 -2
- package/dist/flow/extraction.js +10 -4
- package/dist/flow/reduceTransition.d.ts +2 -2
- package/dist/flow/reduceTransition.js +7 -3
- package/dist/flow/runFlow.js +34 -12
- 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 +9 -14
- package/dist/index.js +5 -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 +6 -6
- package/dist/prompts/index.d.ts +1 -1
- package/dist/prompts/types.d.ts +7 -2
- package/dist/runtime/InMemoryRetrievalCache.d.ts +1 -1
- package/dist/runtime/KnowledgeProvider.d.ts +3 -2
- package/dist/runtime/KnowledgeProvider.js +54 -30
- package/dist/runtime/Runtime.d.ts +3 -1
- package/dist/runtime/Runtime.js +84 -30
- package/dist/runtime/TraceRecorder.d.ts +22 -4
- package/dist/runtime/TraceRecorder.js +65 -29
- package/dist/runtime/buildAgentToolSurface.js +1 -1
- package/dist/runtime/channels/TextDriver.js +12 -9
- package/dist/runtime/channels/executeModelTool.d.ts +6 -0
- package/dist/runtime/channels/executeModelTool.js +70 -10
- 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/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 +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 +39 -5
- package/dist/runtime/durable/RunStore.js +1 -1
- 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/hostLoop.js +26 -6
- package/dist/runtime/index.d.ts +1 -2
- package/dist/runtime/index.js +1 -1
- 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/runHookSafely.d.ts +3 -0
- package/dist/runtime/runHookSafely.js +19 -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/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 +71 -35
- package/dist/tools/effect/defineTool.d.ts +9 -0
- package/dist/tools/effect/defineTool.js +1 -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/types/effectTool.d.ts +2 -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 -16
- package/dist/types/index.js +8 -13
- package/dist/types/knowledge.d.ts +213 -0
- package/dist/types/processors.d.ts +0 -58
- package/dist/types/run-context.d.ts +3 -7
- package/dist/types/runtime.d.ts +3 -74
- package/dist/types/session.d.ts +1 -1
- package/dist/types/skills.d.ts +15 -1
- package/dist/types/stream.d.ts +133 -71
- package/dist/types/stream.js +34 -1
- package/dist/types/trace.d.ts +2 -0
- package/guides/AGENTS.md +3 -3
- 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 +3 -13
- package/dist/foundation/AgentDefinition.d.ts +0 -17
- package/dist/foundation/ConversationEventLog.d.ts +0 -71
- package/dist/foundation/ConversationEventLog.js +0 -1
- 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
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Thrown by `ctx.tool(...)` when a tool declared `needsApproval: true` is denied
|
|
3
|
-
* by a human (the `__approval` signal resolves with `approved: false`). Catch it
|
|
4
|
-
* inside the calling flow `action` node to route gracefully (e.g. escalate or end).
|
|
5
|
-
*/
|
|
1
|
+
/** Thrown when a tool execution exceeds its configured timeout. */
|
|
6
2
|
export class ToolTimeoutError extends Error {
|
|
7
3
|
toolName;
|
|
8
4
|
timeoutMs;
|
|
@@ -13,6 +9,7 @@ export class ToolTimeoutError extends Error {
|
|
|
13
9
|
this.timeoutMs = timeoutMs;
|
|
14
10
|
}
|
|
15
11
|
}
|
|
12
|
+
/** Thrown when a human denies a tool call that requires approval. */
|
|
16
13
|
export class ToolApprovalDeniedError extends Error {
|
|
17
14
|
toolName;
|
|
18
15
|
by;
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -6,5 +6,4 @@ export { isFinalResult } from './final.js';
|
|
|
6
6
|
export type { FinalResult } from './final.js';
|
|
7
7
|
export { createHttpTool } from './http.js';
|
|
8
8
|
export type { HttpToolConfig, HttpToolResult, HttpParam, ParamType, HttpMethod, AuthConfig, } from './http.types.js';
|
|
9
|
-
export { withErrorHandling, executeWithRetry, createCircuitBreaker, withTimeout, isPermanentError, isCircuitOpenError, CircuitOpenError, ToolTimeoutError, type ToolErrorConfig, type ToolResult, } from './errorHandling.js';
|
|
10
9
|
export { DEFAULT_ERROR_MESSAGES, getUserFriendlyError, categorizeError, createErrorResponse, type ErrorCategory, } from './errorMessages.js';
|
package/dist/tools/index.js
CHANGED
|
@@ -2,5 +2,4 @@ export { createTool, createToolWithFiller } from './Tool.js';
|
|
|
2
2
|
export { createHandoffTool, isHandoffResult } from './handoff.js';
|
|
3
3
|
export { isFinalResult } from './final.js';
|
|
4
4
|
export { createHttpTool } from './http.js';
|
|
5
|
-
export { withErrorHandling, executeWithRetry, createCircuitBreaker, withTimeout, isPermanentError, isCircuitOpenError, CircuitOpenError, ToolTimeoutError, } from './errorHandling.js';
|
|
6
5
|
export { DEFAULT_ERROR_MESSAGES, getUserFriendlyError, categorizeError, createErrorResponse, } from './errorMessages.js';
|
|
@@ -17,6 +17,8 @@ export interface Tool<TInput = unknown, TOutput = unknown> {
|
|
|
17
17
|
/** Override the auto-derived effect key (`idempotencyKey(logicalRunId, callsite, {name,args})`). Use when args are not a stable identity (e.g. a nonce). */
|
|
18
18
|
idempotencyKey?: (args: TInput) => string;
|
|
19
19
|
execute: (args: TInput, ctx?: ToolContext) => Promise<TOutput> | AsyncIterable<TOutput>;
|
|
20
|
+
/** Recover from a thrown error by returning a result the model can act on. Not called for timeouts, aborts, schema violations, or control-flow signals. */
|
|
21
|
+
onError?: (error: Error, args: TInput) => Promise<TOutput> | TOutput;
|
|
20
22
|
}
|
|
21
23
|
export type AnyTool = Tool<any, any>;
|
|
22
24
|
export { defineTool } from '../tools/effect/defineTool.js';
|
package/dist/types/flow.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LanguageModel, ModelMessage, ToolSet } from 'ai';
|
|
2
2
|
import type { Instructions } from './agentConfig.js';
|
|
3
|
-
import type { AgentKnowledgeOverrides } from './
|
|
3
|
+
import type { AgentKnowledgeOverrides } from './knowledge.js';
|
|
4
4
|
import type { StandardSchemaV1 } from './standard-schema.js';
|
|
5
5
|
import type { ContextStrategy } from './context.js';
|
|
6
6
|
import type { TurnResult } from './channel.js';
|
|
@@ -11,4 +11,9 @@ export interface Limits {
|
|
|
11
11
|
maxSteps?: number;
|
|
12
12
|
toolMaxSteps?: number;
|
|
13
13
|
maxOscillations?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Ceiling on parallel-safe tools executing at once within one model-emitted batch.
|
|
16
|
+
* Unset means unbounded — the model's batch size decides how many run concurrently.
|
|
17
|
+
*/
|
|
18
|
+
maxToolConcurrency?: number;
|
|
14
19
|
}
|
package/dist/types/hooks.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { ConversationOutcomeRecord } from '../outcomes/types.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { StreamPart } from './stream.js';
|
|
3
3
|
import type { RunContext } from './run-context.js';
|
|
4
4
|
import type { Session } from './session.js';
|
|
5
5
|
import type { TurnUsage } from './telemetry.js';
|
|
6
6
|
export interface Hooks {
|
|
7
7
|
onStart?: (ctx: RunContext) => void | Promise<void>;
|
|
8
|
-
onStreamPart?: (ctx: RunContext, part:
|
|
8
|
+
onStreamPart?: (ctx: RunContext, part: StreamPart) => void | Promise<void>;
|
|
9
9
|
onEnd?: (ctx: RunContext) => void | Promise<void>;
|
|
10
10
|
onConversationEnd?: (args: {
|
|
11
11
|
session: Session;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export type
|
|
15
|
-
export type
|
|
16
|
-
export
|
|
1
|
+
export type { ChoiceOption, ResolvedSelection } from './selection.js';
|
|
2
|
+
export type { TurnUsage, TraceStreamEvent, TracingConfig, Span, SpanEvent, MetricsConfig, ObservabilityMetrics, Metrics, SessionTelemetry, SessionEndMetadata, SessionTrace, } from './telemetry.js';
|
|
3
|
+
export type { ProcessorAction, FlowPromptContext, ProcessorContext, InputProcessorResult, OutputProcessorResult, InputProcessor, OutputProcessor, HandoffInputData, HandoffInputResult, HandoffInputFilter, AgentRoute, RouteCondition, AgentCapabilityDescriptor, } from './processors.js';
|
|
4
|
+
export { defineAgent } from './agentConfig.js';
|
|
5
|
+
export type { AgentWorkspaceConfig, Instructions, AgentConfig } from './agentConfig.js';
|
|
6
|
+
export { fsErrorCode } from './filesystem.js';
|
|
7
|
+
export type { FileSystemEntryType, BufferEncoding, FileContent, FsStat, FileSystemDirent, MkdirOptions, RmOptions, CpOptions, FileSystem, ReadFileOptions, WriteFileOptions, FileEntry, DirectoryEntry, SymlinkEntry, LazyFileEntry, FsEntry, FileInit, LazyFileProvider, InitialFiles, FsError, } from './filesystem.js';
|
|
8
|
+
export type { SkillMeta, SkillLike, SkillStoreLike, SkillSource } from './skills.js';
|
|
9
|
+
export { reply, collect, action, decide, confirmGate, defineFlow } from './flow.js';
|
|
10
|
+
export type { FlowState, Flow, FlowNode, NodeGrounding, Transition, ReplyNode, CollectNode, ActionNode, ConfirmGate, DecideNode, } from './flow.js';
|
|
11
|
+
export type { ChannelId, GoalStatus, TrackedGoal, WorkingMemory, AgentContext, Session, SessionMetadata, AgentState, HandoffRecord, ToolCallRecord, RunContext, } from './session.js';
|
|
12
|
+
export type { ToolSet, ToolPolicy, EnforcementContext, EnforcementResult, EnforcementRule, InjectionPriority, InjectionLevel, Injection, } from './tool.js';
|
|
13
|
+
export { defineTool } from './effectTool.js';
|
|
14
|
+
export type { Tool, AnyTool } from './effectTool.js';
|
|
15
|
+
export type { KnowledgeProviderConfig, AgentKnowledgeOverrides, KnowledgeRetrieverAdapter, KnowledgeEmbedderAdapter, SourceRef, KnowledgeRetrievalResult, KnowledgeChunk, RetrievalCacheAdapter, HttpCallbackConfig, StreamCallbackPayload, StreamCallbackSink, StreamCallbackConfig, } from './knowledge.js';
|
|
16
|
+
export { PART_CHANNEL } from './stream.js';
|
|
17
|
+
export type { StreamChannel, StreamPartBase, TextStartPayload, TextDeltaPayload, TextEndPayload, TextCancelPayload, ToolCallPayload, ToolResultPayload, FlowEnterPayload, FlowEndPayload, NodeEnterPayload, NodeExitPayload, FlowTransitionPayload, HandoffPayload, InterruptedPayload, PausedPayload, ConversationOutcomePayload, InteractivePayload, TurnEndPayload, PipelineValidationBlockPayload, SafetyBlockedPayload, WakePayload, EscalationPayload, ContextCompactedPayload, CompactionSkippedPayload, ContextOverflowRecoveredPayload, ErrorPayload, CustomPayload, DonePayload, KnowledgeCacheHitPayload, KnowledgeCacheMissPayload, KnowledgeSearchPayload, KnowledgeQualityCheckPayload, KnowledgeReformulationPayload, StreamPart, TurnHandle, } from './stream.js';
|
|
18
|
+
export { isAbortSignal } from './runtime.js';
|
|
19
|
+
export type { RefinementStageResult, ValidationStageResult, Hook, StopConditionResult, StopCondition, StreamOptions, AbortOptions, InterruptionEvent, CancellationReason, } from './runtime.js';
|
|
20
|
+
export type { SpanKind, AgentSpan, AgentTrace } from './trace.js';
|
|
21
|
+
export type { AuditEntryBase, AuditEscalationReason, ConversationAuditEntry, ConversationAuditLog, AuditEntryType, AuditListOptions, AuditReplayOptions, AuditConfig, } from '../audit/types.js';
|
|
22
|
+
export { toConversationOutcomeStreamPart, buildMarkOutcomeTool, OUTCOMES_MARK_TOOL_NAME } from '../outcomes/index.js';
|
|
23
|
+
export type { ConversationOutcome, ConversationOutcomeMarkedBy, ConversationOutcomeRecord, CsatRecord, MarkOutcomeToolResult, } from '../outcomes/index.js';
|
|
24
|
+
export { DEFAULT_CHANNEL_POLICIES, getDefaultChannelPolicy, applyChannelPolicy, resolveChannelPolicy } from '../channels/index.js';
|
|
25
|
+
export type { ChannelPolicy, ChannelPolicyChange, ChannelPolicyResult } from '../channels/index.js';
|
package/dist/types/index.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export * from './tool.js';
|
|
10
|
-
export * from './effectTool.js';
|
|
11
|
-
export * from './voice.js';
|
|
12
|
-
export * from './runtime.js';
|
|
13
|
-
export * from './trace.js';
|
|
1
|
+
export { defineAgent } from './agentConfig.js';
|
|
2
|
+
export { fsErrorCode } from './filesystem.js';
|
|
3
|
+
export { reply, collect, action, decide, confirmGate, defineFlow } from './flow.js';
|
|
4
|
+
export { defineTool } from './effectTool.js';
|
|
5
|
+
export { PART_CHANNEL } from './stream.js';
|
|
6
|
+
export { isAbortSignal } from './runtime.js';
|
|
7
|
+
export { toConversationOutcomeStreamPart, buildMarkOutcomeTool, OUTCOMES_MARK_TOOL_NAME } from '../outcomes/index.js';
|
|
8
|
+
export { DEFAULT_CHANNEL_POLICIES, getDefaultChannelPolicy, applyChannelPolicy, resolveChannelPolicy } from '../channels/index.js';
|
|
@@ -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 {
|
|
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 './
|
|
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:
|
|
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;
|
package/dist/types/runtime.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
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:
|
|
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;
|
package/dist/types/session.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ModelMessage } from 'ai';
|
|
2
|
-
import type { RetrievalCacheAdapter } from './
|
|
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';
|
package/dist/types/skills.d.ts
CHANGED
|
@@ -16,4 +16,18 @@ export interface SkillStoreLike {
|
|
|
16
16
|
getAllSkills?(): SkillLike[] | Promise<SkillLike[]>;
|
|
17
17
|
loadAllSkills?(): Promise<SkillLike[]>;
|
|
18
18
|
}
|
|
19
|
-
|
|
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>;
|