@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.
Files changed (158) 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 +4 -4
  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 +2 -2
  15. package/dist/flow/extraction.js +10 -4
  16. package/dist/flow/reduceTransition.d.ts +2 -2
  17. package/dist/flow/reduceTransition.js +7 -3
  18. package/dist/flow/runFlow.js +34 -12
  19. package/dist/foundation/AgentStateController.d.ts +1 -1
  20. package/dist/foundation/ToolExecutor.d.ts +2 -2
  21. package/dist/foundation/index.d.ts +0 -11
  22. package/dist/foundation/index.js +0 -5
  23. package/dist/index.d.ts +9 -14
  24. package/dist/index.js +5 -6
  25. package/dist/outcomes/streamPart.d.ts +2 -2
  26. package/dist/outcomes/streamPart.js +2 -3
  27. package/dist/prompts/PromptBuilder.d.ts +3 -3
  28. package/dist/prompts/PromptBuilder.js +6 -6
  29. package/dist/prompts/index.d.ts +1 -1
  30. package/dist/prompts/types.d.ts +7 -2
  31. package/dist/runtime/InMemoryRetrievalCache.d.ts +1 -1
  32. package/dist/runtime/KnowledgeProvider.d.ts +3 -2
  33. package/dist/runtime/KnowledgeProvider.js +54 -30
  34. package/dist/runtime/Runtime.d.ts +3 -1
  35. package/dist/runtime/Runtime.js +84 -30
  36. package/dist/runtime/TraceRecorder.d.ts +22 -4
  37. package/dist/runtime/TraceRecorder.js +65 -29
  38. package/dist/runtime/buildAgentToolSurface.js +1 -1
  39. package/dist/runtime/channels/TextDriver.js +12 -9
  40. package/dist/runtime/channels/executeModelTool.d.ts +6 -0
  41. package/dist/runtime/channels/executeModelTool.js +70 -10
  42. package/dist/runtime/channels/extractionTurn.js +1 -1
  43. package/dist/runtime/channels/index.d.ts +0 -3
  44. package/dist/runtime/channels/index.js +0 -6
  45. package/dist/runtime/channels/streaming/hostControlSpeak.js +5 -1
  46. package/dist/runtime/channels/streaming/speakGated.js +24 -12
  47. package/dist/runtime/citations/index.d.ts +3 -3
  48. package/dist/runtime/closeRun.js +3 -2
  49. package/dist/runtime/controlFlowSignal.d.ts +24 -0
  50. package/dist/runtime/controlFlowSignal.js +29 -0
  51. package/dist/runtime/ctx.d.ts +3 -4
  52. package/dist/runtime/ctx.js +39 -5
  53. package/dist/runtime/durable/RunStore.js +1 -1
  54. package/dist/runtime/grounding/gather.d.ts +1 -1
  55. package/dist/runtime/grounding/inMemoryKnowledge.d.ts +1 -1
  56. package/dist/runtime/grounding/knowledge.d.ts +1 -1
  57. package/dist/runtime/hostLoop.js +26 -6
  58. package/dist/runtime/index.d.ts +1 -2
  59. package/dist/runtime/index.js +1 -1
  60. package/dist/runtime/outcomeMarking.d.ts +2 -2
  61. package/dist/runtime/outcomeMarking.js +2 -1
  62. package/dist/runtime/policies/agentTurn.d.ts +1 -1
  63. package/dist/runtime/runHookSafely.d.ts +3 -0
  64. package/dist/runtime/runHookSafely.js +19 -0
  65. package/dist/scheduler/index.d.ts +2 -2
  66. package/dist/scheduler/index.js +1 -1
  67. package/dist/services/TracingService.js +2 -3
  68. package/dist/skills/collectSkills.d.ts +11 -3
  69. package/dist/skills/collectSkills.js +51 -8
  70. package/dist/skills/compositeSkillStore.d.ts +26 -0
  71. package/dist/skills/compositeSkillStore.js +54 -0
  72. package/dist/skills/defineSkill.d.ts +21 -0
  73. package/dist/skills/defineSkill.js +26 -0
  74. package/dist/skills/fsSkillStore.d.ts +3 -0
  75. package/dist/skills/fsSkillStore.js +79 -0
  76. package/dist/skills/index.d.ts +4 -0
  77. package/dist/skills/index.js +4 -0
  78. package/dist/skills/parseSkillFrontmatter.d.ts +14 -0
  79. package/dist/skills/parseSkillFrontmatter.js +183 -0
  80. package/dist/skills/wireAgentSkills.d.ts +2 -1
  81. package/dist/skills/wireAgentSkills.js +2 -2
  82. package/dist/testing/mocks.d.ts +3 -3
  83. package/dist/testing/mocks.js +7 -3
  84. package/dist/tools/controlResults.d.ts +14 -0
  85. package/dist/tools/controlResults.js +15 -0
  86. package/dist/tools/effect/ToolExecutor.d.ts +6 -0
  87. package/dist/tools/effect/ToolExecutor.js +71 -35
  88. package/dist/tools/effect/defineTool.d.ts +9 -0
  89. package/dist/tools/effect/defineTool.js +1 -0
  90. package/dist/tools/effect/errors.d.ts +2 -5
  91. package/dist/tools/effect/errors.js +2 -5
  92. package/dist/tools/index.d.ts +0 -1
  93. package/dist/tools/index.js +0 -1
  94. package/dist/types/effectTool.d.ts +2 -0
  95. package/dist/types/flow.d.ts +1 -1
  96. package/dist/types/guardrails.d.ts +5 -0
  97. package/dist/types/hooks.d.ts +2 -2
  98. package/dist/types/index.d.ts +25 -16
  99. package/dist/types/index.js +8 -13
  100. package/dist/types/knowledge.d.ts +213 -0
  101. package/dist/types/processors.d.ts +0 -58
  102. package/dist/types/run-context.d.ts +3 -7
  103. package/dist/types/runtime.d.ts +3 -74
  104. package/dist/types/session.d.ts +1 -1
  105. package/dist/types/skills.d.ts +15 -1
  106. package/dist/types/stream.d.ts +133 -71
  107. package/dist/types/stream.js +34 -1
  108. package/dist/types/trace.d.ts +2 -0
  109. package/guides/AGENTS.md +3 -3
  110. package/guides/FLOWS.md +1 -1
  111. package/guides/GETTING_STARTED.md +1 -1
  112. package/guides/RUNTIME.md +20 -15
  113. package/guides/TOOLS.md +1 -1
  114. package/package.json +3 -13
  115. package/dist/foundation/AgentDefinition.d.ts +0 -17
  116. package/dist/foundation/ConversationEventLog.d.ts +0 -71
  117. package/dist/foundation/ConversationEventLog.js +0 -1
  118. package/dist/foundation/ConversationState.d.ts +0 -33
  119. package/dist/foundation/ConversationState.js +0 -1
  120. package/dist/foundation/DefaultConversationEventLog.d.ts +0 -27
  121. package/dist/foundation/DefaultConversationEventLog.js +0 -205
  122. package/dist/foundation/DefaultConversationState.d.ts +0 -36
  123. package/dist/foundation/DefaultConversationState.js +0 -103
  124. package/dist/foundation/DefaultToolExecutor.d.ts +0 -57
  125. package/dist/foundation/DefaultToolExecutor.js +0 -132
  126. package/dist/foundation/createFoundation.d.ts +0 -32
  127. package/dist/foundation/createFoundation.js +0 -33
  128. package/dist/hooks/HookRunner.d.ts +0 -37
  129. package/dist/hooks/HookRunner.js +0 -111
  130. package/dist/hooks/builtin/logging.d.ts +0 -5
  131. package/dist/hooks/builtin/logging.js +0 -98
  132. package/dist/hooks/builtin/metrics.d.ts +0 -7
  133. package/dist/hooks/builtin/metrics.js +0 -60
  134. package/dist/hooks/builtin/observability.d.ts +0 -20
  135. package/dist/hooks/builtin/observability.js +0 -572
  136. package/dist/hooks/helpers.d.ts +0 -22
  137. package/dist/hooks/helpers.js +0 -183
  138. package/dist/hooks/index.d.ts +0 -8
  139. package/dist/hooks/index.js +0 -6
  140. package/dist/realtime/RealtimeAudioClient.d.ts +0 -166
  141. package/dist/realtime/RealtimeAudioClient.js +0 -14
  142. package/dist/realtime/RealtimeSessionHandle.d.ts +0 -6
  143. package/dist/realtime/RealtimeSessionHandle.js +0 -1
  144. package/dist/realtime/index.d.ts +0 -2
  145. package/dist/realtime/index.js +0 -1
  146. package/dist/runtime/channels/VoiceDriver.d.ts +0 -31
  147. package/dist/runtime/channels/VoiceDriver.js +0 -321
  148. package/dist/runtime/channels/voiceTools.d.ts +0 -9
  149. package/dist/runtime/channels/voiceTools.js +0 -51
  150. package/dist/tools/errorHandling.d.ts +0 -35
  151. package/dist/tools/errorHandling.js +0 -145
  152. package/dist/types/voice.d.ts +0 -517
  153. package/dist/types/voice.js +0 -14
  154. package/dist/utils/isRecord.d.ts +0 -1
  155. package/dist/utils/isRecord.js +0 -3
  156. package/dist/utils/messageNormalization.d.ts +0 -2
  157. package/dist/utils/messageNormalization.js +0 -137
  158. /package/dist/{foundation/AgentDefinition.js → types/knowledge.js} +0 -0
@@ -1,111 +0,0 @@
1
- const defaultErrorHandler = (hookName, error) => {
2
- console.error(`[HookRunner] Hook "${hookName}" failed:`, error.message);
3
- };
4
- export class HookRunner {
5
- hooks;
6
- errorHandler;
7
- constructor(hooks = {}, errorHandler) {
8
- this.hooks = hooks;
9
- this.errorHandler = errorHandler ?? defaultErrorHandler;
10
- }
11
- /** Check if a specific hook is configured. */
12
- has(hookName) {
13
- return Boolean(this.hooks[hookName]);
14
- }
15
- async run(hookName, ...args) {
16
- const hook = this.hooks[hookName];
17
- if (!hook)
18
- return;
19
- try {
20
- await hook(...args);
21
- }
22
- catch (error) {
23
- this.errorHandler(String(hookName), error);
24
- }
25
- }
26
- async onStart(context) {
27
- await this.run('onStart', context);
28
- }
29
- async onEnd(context, result) {
30
- await this.run('onEnd', context, result);
31
- }
32
- async onStepStart(context, step) {
33
- await this.run('onStepStart', context, step);
34
- }
35
- async onStepEnd(context, step, result) {
36
- await this.run('onStepEnd', context, step, result);
37
- }
38
- async onTokensUpdate(context, turn) {
39
- await this.run('onTokensUpdate', context, turn);
40
- }
41
- async onToolCall(context, call) {
42
- await this.run('onToolCall', context, call);
43
- }
44
- async onToolResult(context, call) {
45
- await this.run('onToolResult', context, call);
46
- }
47
- async onToolError(context, call, error) {
48
- await this.run('onToolError', context, call, error);
49
- }
50
- async onTurnEnd(context, summary) {
51
- const hook = this.hooks.onTurnEnd;
52
- if (!hook)
53
- return;
54
- try {
55
- return await hook(context, summary);
56
- }
57
- catch (error) {
58
- this.errorHandler('onTurnEnd', error);
59
- }
60
- }
61
- async onAgentStart(context, agentId) {
62
- await this.run('onAgentStart', context, agentId);
63
- }
64
- async onAgentEnd(context, agentId) {
65
- await this.run('onAgentEnd', context, agentId);
66
- }
67
- async onHandoff(context, from, to, reason) {
68
- await this.run('onHandoff', context, from, to, reason);
69
- }
70
- async onError(context, error) {
71
- await this.run('onError', context, error);
72
- }
73
- async onMessage(context, message) {
74
- await this.run('onMessage', context, message);
75
- }
76
- async onStreamPart(context, part) {
77
- await this.run('onStreamPart', context, part);
78
- }
79
- async onSessionEnd(session, metadata) {
80
- await this.run('onSessionEnd', session, metadata);
81
- }
82
- async onConversationEnd(session, outcome) {
83
- await this.run('onConversationEnd', session, outcome);
84
- }
85
- merge(additionalHooks) {
86
- const hooks = this.hooks;
87
- for (const [key, hook] of Object.entries(additionalHooks)) {
88
- const existing = hooks[key];
89
- if (!hook)
90
- continue;
91
- if (existing) {
92
- hooks[key] = (async (...args) => {
93
- await existing(...args);
94
- await hook(...args);
95
- });
96
- }
97
- else {
98
- hooks[key] = hook;
99
- }
100
- }
101
- }
102
- setHooks(hooks) {
103
- this.hooks = hooks;
104
- }
105
- getHooks() {
106
- return { ...this.hooks };
107
- }
108
- }
109
- export function createHookRunner(hooks, errorHandler) {
110
- return new HookRunner(hooks, errorHandler);
111
- }
@@ -1,5 +0,0 @@
1
- import type { HarnessHooks } from '../../types/index.js';
2
- type LogLevel = 'debug' | 'info' | 'warn' | 'error';
3
- export declare const loggingHooks: HarnessHooks;
4
- export declare function createLoggingHooks(logFn: (level: LogLevel, message: string, data?: Record<string, unknown>) => void): HarnessHooks;
5
- export {};
@@ -1,98 +0,0 @@
1
- function log(level, message, context, data) {
2
- const entry = {
3
- timestamp: new Date().toISOString(),
4
- level,
5
- component: 'kuralle',
6
- message,
7
- traceId: context?.session.id,
8
- data,
9
- };
10
- console.log(JSON.stringify(entry));
11
- }
12
- export const loggingHooks = {
13
- onStart: async (context) => {
14
- log('info', 'Agent run started', context, {
15
- sessionId: context.session.id,
16
- agentId: context.agentId,
17
- userId: context.session.userId,
18
- });
19
- },
20
- onEnd: async (context, result) => {
21
- const duration = Date.now() - context.startTime;
22
- log('info', 'Agent run completed', context, {
23
- success: result.success,
24
- error: result.error?.message,
25
- duration,
26
- steps: context.stepCount,
27
- tokens: context.totalTokens,
28
- handoffs: context.handoffStack.length,
29
- });
30
- },
31
- onStepStart: async (context, step) => {
32
- log('debug', `Step ${step} started`, context, { step, agentId: context.agentId });
33
- },
34
- onStepEnd: async (context, step, result) => {
35
- log('debug', `Step ${step} completed`, context, {
36
- step,
37
- finishReason: result.finishReason,
38
- toolCalls: result.toolCalls.length,
39
- tokens: result.tokensUsed,
40
- });
41
- },
42
- onToolCall: async (context, call) => {
43
- log('info', `Tool called: ${call.toolName}`, context, {
44
- toolCallId: call.toolCallId,
45
- toolName: call.toolName,
46
- args: call.args,
47
- });
48
- },
49
- onToolResult: async (context, call) => {
50
- log('debug', `Tool completed: ${call.toolName}`, context, {
51
- toolCallId: call.toolCallId,
52
- toolName: call.toolName,
53
- success: call.success,
54
- durationMs: call.durationMs,
55
- resultPreview: JSON.stringify(call.result)?.slice(0, 200),
56
- });
57
- },
58
- onToolError: async (context, call, error) => {
59
- log('error', `Tool failed: ${call.toolName}`, context, {
60
- toolCallId: call.toolCallId,
61
- toolName: call.toolName,
62
- error: error.message,
63
- stack: error.stack,
64
- });
65
- },
66
- onHandoff: async (context, from, to, reason) => {
67
- log('info', `Agent handoff: ${from} -> ${to}`, context, { from, to, reason });
68
- },
69
- onError: async (context, error) => {
70
- log('error', 'Agent error', context, {
71
- error: error.message,
72
- stack: error.stack,
73
- step: context.stepCount,
74
- });
75
- },
76
- onAgentStart: async (context, agentId) => {
77
- log('info', `Agent started: ${agentId}`, context, { agentId });
78
- },
79
- onAgentEnd: async (context, agentId) => {
80
- log('info', `Agent ended: ${agentId}`, context, { agentId });
81
- },
82
- };
83
- export function createLoggingHooks(logFn) {
84
- const customLog = (level, message, context, data) => {
85
- logFn(level, message, {
86
- ...data,
87
- traceId: context?.session.id,
88
- timestamp: new Date().toISOString(),
89
- });
90
- };
91
- return {
92
- onStart: async (ctx) => customLog('info', 'Agent started', ctx, { agentId: ctx.agentId }),
93
- onEnd: async (ctx, r) => customLog('info', 'Agent ended', ctx, { success: r.success }),
94
- onToolCall: async (ctx, c) => customLog('info', `Tool: ${c.toolName}`, ctx, { args: c.args }),
95
- onHandoff: async (ctx, f, t, r) => customLog('info', `Handoff: ${f}->${t}`, ctx, { reason: r }),
96
- onError: async (ctx, e) => customLog('error', 'Error', ctx, { error: e.message }),
97
- };
98
- }
@@ -1,7 +0,0 @@
1
- import type { HarnessHooks } from '../../types/index.js';
2
- import type { Metrics } from '../../types/index.js';
3
- import { InMemoryMetricsService } from '../../services/MetricsService.js';
4
- export { Metrics };
5
- export declare class InMemoryMetrics extends InMemoryMetricsService implements Metrics {
6
- }
7
- export declare function createMetricsHooks(metrics: Metrics): HarnessHooks;
@@ -1,60 +0,0 @@
1
- import { InMemoryMetricsService } from '../../services/MetricsService.js';
2
- // Re-export as alias for compatibility
3
- export class InMemoryMetrics extends InMemoryMetricsService {
4
- }
5
- export function createMetricsHooks(metrics) {
6
- const toolStartTimes = new Map();
7
- return {
8
- onStart: async (context) => {
9
- metrics.increment('agent.starts', 1, { agent: context.agentId });
10
- metrics.gauge('agent.active', 1);
11
- },
12
- onEnd: async (context, result) => {
13
- const duration = Date.now() - context.startTime;
14
- metrics.increment(result.success ? 'agent.success' : 'agent.failure');
15
- metrics.gauge('agent.active', -1);
16
- metrics.timing('agent.duration', duration);
17
- metrics.histogram('agent.steps', context.stepCount);
18
- metrics.histogram('agent.tokens', context.totalTokens);
19
- metrics.histogram('agent.handoffs', context.handoffStack.length);
20
- },
21
- onToolCall: async (_context, call) => {
22
- metrics.increment('tool.calls', 1, { tool: call.toolName });
23
- toolStartTimes.set(call.toolCallId, Date.now());
24
- },
25
- onToolResult: async (_context, call) => {
26
- const startTime = toolStartTimes.get(call.toolCallId);
27
- if (startTime) {
28
- metrics.timing('tool.duration', Date.now() - startTime, { tool: call.toolName });
29
- toolStartTimes.delete(call.toolCallId);
30
- }
31
- metrics.increment('tool.success', 1, { tool: call.toolName });
32
- },
33
- onToolError: async (_context, call) => {
34
- const startTime = toolStartTimes.get(call.toolCallId);
35
- if (startTime) {
36
- metrics.timing('tool.duration', Date.now() - startTime, { tool: call.toolName });
37
- toolStartTimes.delete(call.toolCallId);
38
- }
39
- metrics.increment('tool.errors', 1, { tool: call.toolName });
40
- },
41
- onHandoff: async (_context, from, to) => {
42
- metrics.increment('agent.handoffs', 1, { from, to });
43
- },
44
- onError: async () => {
45
- metrics.increment('agent.errors');
46
- },
47
- onStreamPart: async (_context, part) => {
48
- // Capture flow-level metrics emitted as custom stream events
49
- if (part.type === 'custom' && typeof part.name === 'string' && part.name.startsWith('flow.')) {
50
- const data = part.data;
51
- if (data && typeof data.durationMs === 'number') {
52
- metrics.timing(part.name, data.durationMs);
53
- }
54
- else {
55
- metrics.increment(part.name);
56
- }
57
- }
58
- },
59
- };
60
- }
@@ -1,20 +0,0 @@
1
- import type { HarnessHooks } from '../../types/index.js';
2
- import type { Metrics, SessionTrace, TraceStreamEvent } from '../../types/telemetry.js';
3
- export interface ObservabilityConfig {
4
- /** Where to send the final SessionTrace. Default: console. */
5
- exporter?: 'console' | 'json' | ((trace: SessionTrace) => Promise<void>);
6
- /** Output file for `json` exporter. Default: `./.kuralle-traces/session-<id>.json` */
7
- outputPath?: string;
8
- /** Include message text in span events (PII risk). Default: false. */
9
- includeContent?: boolean;
10
- /** Optional metrics service for timings alongside spans. */
11
- metrics?: Metrics;
12
- /** Service name stored on spans. */
13
- serviceName?: string;
14
- /**
15
- * Optional live trace stream (e.g. Kuralle Studio WebSocket). Fire-and-forget;
16
- * keep handlers synchronous or schedule async work without blocking the harness.
17
- */
18
- traceStream?: (event: TraceStreamEvent) => void;
19
- }
20
- export declare function createObservabilityHooks(config?: ObservabilityConfig): HarnessHooks;