@revealui/ai 0.8.0 → 0.8.1
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 +25 -12
- package/dist/client/hooks/useAgentStream.d.ts.map +1 -1
- package/dist/client/hooks/useAgentStream.js +1 -29
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/inference/context-assembly.d.ts.map +1 -1
- package/dist/inference/context-assembly.js +1 -3
- package/dist/inference/overflow-compressor.d.ts.map +1 -1
- package/dist/inference/overflow-compressor.js +1 -3
- package/dist/ingestion/pipeline.d.ts.map +1 -1
- package/dist/ingestion/pipeline.js +1 -3
- package/dist/ingestion/text-splitter.d.ts.map +1 -1
- package/dist/ingestion/text-splitter.js +1 -3
- package/dist/internal/token-estimate.d.ts +6 -0
- package/dist/internal/token-estimate.d.ts.map +1 -0
- package/dist/internal/token-estimate.js +7 -0
- package/dist/llm/client.d.ts +4 -3
- package/dist/llm/client.d.ts.map +1 -1
- package/dist/llm/client.js +11 -4
- package/dist/llm/local-ai-profile.d.ts +39 -0
- package/dist/llm/local-ai-profile.d.ts.map +1 -0
- package/dist/llm/local-ai-profile.js +165 -0
- package/dist/llm/providers/inference-snaps.d.ts +24 -13
- package/dist/llm/providers/inference-snaps.d.ts.map +1 -1
- package/dist/llm/providers/inference-snaps.js +21 -17
- package/dist/llm/providers/us-origin-snaps.d.ts +79 -0
- package/dist/llm/providers/us-origin-snaps.d.ts.map +1 -0
- package/dist/llm/providers/us-origin-snaps.js +108 -0
- package/dist/observability/export.d.ts +78 -0
- package/dist/observability/export.d.ts.map +1 -0
- package/dist/observability/export.js +229 -0
- package/dist/observability/index.d.ts +19 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +16 -0
- package/dist/observability/instrumentation.d.ts +68 -0
- package/dist/observability/instrumentation.d.ts.map +1 -0
- package/dist/observability/instrumentation.js +219 -0
- package/dist/observability/storage.d.ts +39 -0
- package/dist/observability/storage.d.ts.map +1 -0
- package/dist/observability/storage.js +184 -0
- package/dist/orchestration/runtime.d.ts +7 -0
- package/dist/orchestration/runtime.d.ts.map +1 -1
- package/dist/orchestration/runtime.js +9 -2
- package/dist/orchestration/ticket-agent.d.ts +10 -0
- package/dist/orchestration/ticket-agent.d.ts.map +1 -1
- package/dist/orchestration/ticket-agent.js +7 -1
- package/dist/skills/index.d.ts +4 -0
- package/dist/skills/index.d.ts.map +1 -1
- package/dist/skills/index.js +4 -0
- package/dist/skills/integration/agent-skill-provider.d.ts +0 -5
- package/dist/skills/integration/agent-skill-provider.d.ts.map +1 -1
- package/dist/skills/integration/agent-skill-provider.js +3 -9
- package/dist/tools/admin/factory.d.ts +6 -0
- package/dist/tools/admin/factory.d.ts.map +1 -1
- package/dist/tools/admin/factory.js +3 -2
- package/dist/tools/coding/index.d.ts +6 -0
- package/dist/tools/coding/index.d.ts.map +1 -1
- package/dist/tools/coding/index.js +7 -2
- package/dist/tools/governance.d.ts +37 -0
- package/dist/tools/governance.d.ts.map +1 -0
- package/dist/tools/governance.js +42 -0
- package/dist/tools/integrity-audit.d.ts +27 -0
- package/dist/tools/integrity-audit.d.ts.map +1 -0
- package/dist/tools/integrity-audit.js +64 -0
- package/dist/tools/mcp-adapter.d.ts +23 -3
- package/dist/tools/mcp-adapter.d.ts.map +1 -1
- package/dist/tools/mcp-adapter.js +189 -132
- package/dist/tools/mcp-sampling.d.ts +3 -3
- package/dist/tools/mcp-sampling.js +3 -3
- package/dist/tools/web/duck-duck-go.d.ts.map +1 -1
- package/dist/tools/web/duck-duck-go.js +1 -4
- package/dist/tools/web/exa.d.ts.map +1 -1
- package/dist/tools/web/exa.js +1 -4
- package/dist/tools/web/tavily.d.ts.map +1 -1
- package/dist/tools/web/tavily.js +1 -4
- package/package.json +68 -33
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @revealui/ai - Observability
|
|
3
|
+
*
|
|
4
|
+
* **INCUBATING (fleet-redundancy C11 / ADR-007).** Agent event/metrics helpers
|
|
5
|
+
* are available as a library. No RevealUI app currently mounts this surface as
|
|
6
|
+
* the product observability path; prefer explicit wiring under a WIRE ticket.
|
|
7
|
+
*
|
|
8
|
+
* Agent operation tracking, logging, and metrics collection.
|
|
9
|
+
*/
|
|
10
|
+
export { createDownloadableBlob, downloadEvents, EventExporter, exportToCSV, exportToFile, exportToJSON, exportToNDJSON, } from './export.js';
|
|
11
|
+
export type { LLMCallOptions, LLMResponse } from './instrumentation.js';
|
|
12
|
+
export { instrumentAgent, instrumentLLMCall, instrumentTaskExecution, instrumentTool, LLMCostCalculators, logTaskDelegation, } from './instrumentation.js';
|
|
13
|
+
export { AgentEventLogger } from './logger.js';
|
|
14
|
+
export { AgentMetricsCollector } from './metrics.js';
|
|
15
|
+
export { AgentEventQuery } from './query.js';
|
|
16
|
+
export { FileSystemEventStorage, LocalStorageEventStorage, MemoryEventStorage, } from './storage.js';
|
|
17
|
+
export type { AgentEvent, AgentMetrics, DecisionEvent, ErrorEvent, EventFilter, EventStorage, LLMCallEvent, MetricsSummary, ToolCallEvent, } from './types.js';
|
|
18
|
+
export * from './types.js';
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/observability/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,aAAa,EACb,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,uBAAuB,EACvB,cAAc,EACd,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,UAAU,EACV,YAAY,EACZ,aAAa,EACb,UAAU,EACV,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @revealui/ai - Observability
|
|
3
|
+
*
|
|
4
|
+
* **INCUBATING (fleet-redundancy C11 / ADR-007).** Agent event/metrics helpers
|
|
5
|
+
* are available as a library. No RevealUI app currently mounts this surface as
|
|
6
|
+
* the product observability path; prefer explicit wiring under a WIRE ticket.
|
|
7
|
+
*
|
|
8
|
+
* Agent operation tracking, logging, and metrics collection.
|
|
9
|
+
*/
|
|
10
|
+
export { createDownloadableBlob, downloadEvents, EventExporter, exportToCSV, exportToFile, exportToJSON, exportToNDJSON, } from './export.js';
|
|
11
|
+
export { instrumentAgent, instrumentLLMCall, instrumentTaskExecution, instrumentTool, LLMCostCalculators, logTaskDelegation, } from './instrumentation.js';
|
|
12
|
+
export { AgentEventLogger } from './logger.js';
|
|
13
|
+
export { AgentMetricsCollector } from './metrics.js';
|
|
14
|
+
export { AgentEventQuery } from './query.js';
|
|
15
|
+
export { FileSystemEventStorage, LocalStorageEventStorage, MemoryEventStorage, } from './storage.js';
|
|
16
|
+
export * from './types.js';
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @revealui/ai - Instrumentation Utilities
|
|
3
|
+
*
|
|
4
|
+
* Helper functions and wrappers for instrumenting agent operations with observability.
|
|
5
|
+
*/
|
|
6
|
+
import type { Agent, AgentResult, Task } from '../orchestration/agent.js';
|
|
7
|
+
import type { Tool } from '../tools/base.js';
|
|
8
|
+
import type { AgentEventLogger } from './logger.js';
|
|
9
|
+
/**
|
|
10
|
+
* Wrap a tool execution with observability logging
|
|
11
|
+
*/
|
|
12
|
+
export declare function instrumentTool(tool: Tool, logger: AgentEventLogger, agentId: string, sessionId: string): Tool;
|
|
13
|
+
/**
|
|
14
|
+
* Wrap an agent with observability logging
|
|
15
|
+
*/
|
|
16
|
+
export declare function instrumentAgent(agent: Agent, logger: AgentEventLogger): Agent & {
|
|
17
|
+
logger: AgentEventLogger;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Instrument a task delegation decision
|
|
21
|
+
*/
|
|
22
|
+
export declare function logTaskDelegation(logger: AgentEventLogger, task: Task, selectedAgent: Agent, reasoning: string, confidence?: number): void;
|
|
23
|
+
/**
|
|
24
|
+
* Instrument task execution
|
|
25
|
+
*/
|
|
26
|
+
export declare function instrumentTaskExecution<T extends AgentResult>(logger: AgentEventLogger, task: Task, agentId: string, executor: () => Promise<T>): Promise<T>;
|
|
27
|
+
/**
|
|
28
|
+
* Instrument LLM call with token counting
|
|
29
|
+
*/
|
|
30
|
+
export interface LLMCallOptions {
|
|
31
|
+
provider: string;
|
|
32
|
+
model: string;
|
|
33
|
+
agentId: string;
|
|
34
|
+
sessionId: string;
|
|
35
|
+
taskId?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface LLMResponse {
|
|
38
|
+
content: string;
|
|
39
|
+
usage: {
|
|
40
|
+
promptTokens: number;
|
|
41
|
+
completionTokens: number;
|
|
42
|
+
totalTokens: number;
|
|
43
|
+
};
|
|
44
|
+
cacheHit?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export declare function instrumentLLMCall<T extends LLMResponse>(logger: AgentEventLogger, options: LLMCallOptions, executor: () => Promise<T>, costCalculator?: (usage: T['usage']) => number): Promise<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Cost calculators for popular LLM providers
|
|
49
|
+
*/
|
|
50
|
+
export declare const LLMCostCalculators: {
|
|
51
|
+
/**
|
|
52
|
+
* OpenAI cost calculator
|
|
53
|
+
* Prices as of 2024 (per 1M tokens)
|
|
54
|
+
*/
|
|
55
|
+
openai: (model: string, usage: {
|
|
56
|
+
promptTokens: number;
|
|
57
|
+
completionTokens: number;
|
|
58
|
+
}) => number;
|
|
59
|
+
/**
|
|
60
|
+
* Anthropic cost calculator
|
|
61
|
+
* Prices as of 2024 (per 1M tokens)
|
|
62
|
+
*/
|
|
63
|
+
anthropic: (model: string, usage: {
|
|
64
|
+
promptTokens: number;
|
|
65
|
+
completionTokens: number;
|
|
66
|
+
}) => number;
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=instrumentation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../src/observability/instrumentation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;GAEG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAChB,IAAI,CAuDN;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,gBAAgB,GACvB,KAAK,GAAG;IAAE,MAAM,EAAE,gBAAgB,CAAA;CAAE,CAOtC;AA4BD;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,gBAAgB,EACxB,IAAI,EAAE,IAAI,EACV,aAAa,EAAE,KAAK,EACpB,SAAS,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,MAAM,GAClB,IAAI,CAcN;AAED;;GAEG;AACH,wBAAsB,uBAAuB,CAAC,CAAC,SAAS,WAAW,EACjE,MAAM,EAAE,gBAAgB,EACxB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACzB,OAAO,CAAC,CAAC,CAAC,CA2CZ;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE;QACL,YAAY,EAAE,MAAM,CAAC;QACrB,gBAAgB,EAAE,MAAM,CAAC;QACzB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAsB,iBAAiB,CAAC,CAAC,SAAS,WAAW,EAC3D,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,cAAc,EACvB,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC1B,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,MAAM,GAC7C,OAAO,CAAC,CAAC,CAAC,CA4CZ;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB;IAC7B;;;OAGG;oBACa,MAAM,SAAS;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAA;KAAE;IAcjF;;;OAGG;uBACgB,MAAM,SAAS;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAA;KAAE;CAarF,CAAC"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @revealui/ai - Instrumentation Utilities
|
|
3
|
+
*
|
|
4
|
+
* Helper functions and wrappers for instrumenting agent operations with observability.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Wrap a tool execution with observability logging
|
|
8
|
+
*/
|
|
9
|
+
export function instrumentTool(tool, logger, agentId, sessionId) {
|
|
10
|
+
return {
|
|
11
|
+
...tool,
|
|
12
|
+
execute: async (params) => {
|
|
13
|
+
const startTime = Date.now();
|
|
14
|
+
try {
|
|
15
|
+
const result = await tool.execute(params);
|
|
16
|
+
const durationMs = Date.now() - startTime;
|
|
17
|
+
// Log tool call
|
|
18
|
+
logger.logToolCall({
|
|
19
|
+
timestamp: Date.now(),
|
|
20
|
+
agentId,
|
|
21
|
+
sessionId,
|
|
22
|
+
toolName: tool.name,
|
|
23
|
+
params: params,
|
|
24
|
+
result: result.data,
|
|
25
|
+
durationMs,
|
|
26
|
+
success: result.success,
|
|
27
|
+
errorMessage: result.error,
|
|
28
|
+
});
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
const durationMs = Date.now() - startTime;
|
|
33
|
+
// Log failed tool call
|
|
34
|
+
logger.logToolCall({
|
|
35
|
+
timestamp: Date.now(),
|
|
36
|
+
agentId,
|
|
37
|
+
sessionId,
|
|
38
|
+
toolName: tool.name,
|
|
39
|
+
params: params,
|
|
40
|
+
durationMs,
|
|
41
|
+
success: false,
|
|
42
|
+
errorMessage: error instanceof Error ? error.message : String(error),
|
|
43
|
+
});
|
|
44
|
+
// Log error event
|
|
45
|
+
logger.logError({
|
|
46
|
+
timestamp: Date.now(),
|
|
47
|
+
agentId,
|
|
48
|
+
sessionId,
|
|
49
|
+
message: `Tool execution failed: ${tool.name}`,
|
|
50
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
51
|
+
recoverable: true,
|
|
52
|
+
errorCode: 'TOOL_EXECUTION_ERROR',
|
|
53
|
+
context: { toolName: tool.name, params },
|
|
54
|
+
});
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Wrap an agent with observability logging
|
|
62
|
+
*/
|
|
63
|
+
export function instrumentAgent(agent, logger) {
|
|
64
|
+
return {
|
|
65
|
+
...agent,
|
|
66
|
+
logger,
|
|
67
|
+
// Agent interface methods would be instrumented here
|
|
68
|
+
// This is a placeholder as the Agent interface may vary
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function taskSessionId(task) {
|
|
72
|
+
const sessionId = task.sessionId;
|
|
73
|
+
return typeof sessionId === 'string' && sessionId.length > 0 ? sessionId : 'session';
|
|
74
|
+
}
|
|
75
|
+
function taskInputParams(task) {
|
|
76
|
+
const extended = task;
|
|
77
|
+
if (extended.input !== undefined &&
|
|
78
|
+
extended.input !== null &&
|
|
79
|
+
typeof extended.input === 'object' &&
|
|
80
|
+
!Array.isArray(extended.input)) {
|
|
81
|
+
return extended.input;
|
|
82
|
+
}
|
|
83
|
+
return (task.parameters ?? {});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Instrument a task delegation decision
|
|
87
|
+
*/
|
|
88
|
+
export function logTaskDelegation(logger, task, selectedAgent, reasoning, confidence) {
|
|
89
|
+
logger.logDecision({
|
|
90
|
+
timestamp: Date.now(),
|
|
91
|
+
agentId: selectedAgent.id,
|
|
92
|
+
sessionId: taskSessionId(task),
|
|
93
|
+
taskId: task.id,
|
|
94
|
+
reasoning,
|
|
95
|
+
chosenTool: selectedAgent.name,
|
|
96
|
+
confidence,
|
|
97
|
+
context: {
|
|
98
|
+
taskType: task.type,
|
|
99
|
+
taskDescription: task.description,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Instrument task execution
|
|
105
|
+
*/
|
|
106
|
+
export async function instrumentTaskExecution(logger, task, agentId, executor) {
|
|
107
|
+
const startTime = Date.now();
|
|
108
|
+
const sessionId = taskSessionId(task);
|
|
109
|
+
try {
|
|
110
|
+
const result = await executor();
|
|
111
|
+
const durationMs = Date.now() - startTime;
|
|
112
|
+
// Log as a tool call (task execution is essentially a tool)
|
|
113
|
+
logger.logToolCall({
|
|
114
|
+
timestamp: Date.now(),
|
|
115
|
+
agentId,
|
|
116
|
+
sessionId,
|
|
117
|
+
taskId: task.id,
|
|
118
|
+
toolName: `task:${task.type}`,
|
|
119
|
+
params: taskInputParams(task),
|
|
120
|
+
result: result.output,
|
|
121
|
+
durationMs,
|
|
122
|
+
success: result.success,
|
|
123
|
+
errorMessage: result.error,
|
|
124
|
+
});
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
const durationMs = Date.now() - startTime;
|
|
129
|
+
logger.logError({
|
|
130
|
+
timestamp: Date.now(),
|
|
131
|
+
agentId,
|
|
132
|
+
sessionId,
|
|
133
|
+
taskId: task.id,
|
|
134
|
+
message: `Task execution failed: ${task.type}`,
|
|
135
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
136
|
+
recoverable: false,
|
|
137
|
+
errorCode: 'TASK_EXECUTION_ERROR',
|
|
138
|
+
context: {
|
|
139
|
+
taskType: task.type,
|
|
140
|
+
durationMs,
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
export async function instrumentLLMCall(logger, options, executor, costCalculator) {
|
|
147
|
+
const startTime = Date.now();
|
|
148
|
+
try {
|
|
149
|
+
const response = await executor();
|
|
150
|
+
const durationMs = Date.now() - startTime;
|
|
151
|
+
const cost = costCalculator ? costCalculator(response.usage) : undefined;
|
|
152
|
+
logger.logLLMCall({
|
|
153
|
+
timestamp: Date.now(),
|
|
154
|
+
agentId: options.agentId,
|
|
155
|
+
sessionId: options.sessionId,
|
|
156
|
+
taskId: options.taskId,
|
|
157
|
+
provider: options.provider,
|
|
158
|
+
model: options.model,
|
|
159
|
+
promptTokens: response.usage.promptTokens,
|
|
160
|
+
completionTokens: response.usage.completionTokens,
|
|
161
|
+
durationMs,
|
|
162
|
+
cost,
|
|
163
|
+
cacheHit: response.cacheHit,
|
|
164
|
+
});
|
|
165
|
+
return response;
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
const durationMs = Date.now() - startTime;
|
|
169
|
+
logger.logError({
|
|
170
|
+
timestamp: Date.now(),
|
|
171
|
+
agentId: options.agentId,
|
|
172
|
+
sessionId: options.sessionId,
|
|
173
|
+
taskId: options.taskId,
|
|
174
|
+
message: `LLM call failed: ${options.provider}/${options.model}`,
|
|
175
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
176
|
+
recoverable: true,
|
|
177
|
+
errorCode: 'LLM_CALL_ERROR',
|
|
178
|
+
context: {
|
|
179
|
+
provider: options.provider,
|
|
180
|
+
model: options.model,
|
|
181
|
+
durationMs,
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Cost calculators for popular LLM providers
|
|
189
|
+
*/
|
|
190
|
+
export const LLMCostCalculators = {
|
|
191
|
+
/**
|
|
192
|
+
* OpenAI cost calculator
|
|
193
|
+
* Prices as of 2024 (per 1M tokens)
|
|
194
|
+
*/
|
|
195
|
+
openai: (model, usage) => {
|
|
196
|
+
const prices = {
|
|
197
|
+
'gpt-4-turbo': { input: 10, output: 30 },
|
|
198
|
+
'gpt-4': { input: 30, output: 60 },
|
|
199
|
+
'gpt-3.5-turbo': { input: 0.5, output: 1.5 },
|
|
200
|
+
};
|
|
201
|
+
const price = prices[model] ?? prices['gpt-3.5-turbo'] ?? { input: 0.5, output: 1.5 };
|
|
202
|
+
return ((usage.promptTokens / 1_000_000) * price.input +
|
|
203
|
+
(usage.completionTokens / 1_000_000) * price.output);
|
|
204
|
+
},
|
|
205
|
+
/**
|
|
206
|
+
* Anthropic cost calculator
|
|
207
|
+
* Prices as of 2024 (per 1M tokens)
|
|
208
|
+
*/
|
|
209
|
+
anthropic: (model, usage) => {
|
|
210
|
+
const prices = {
|
|
211
|
+
'claude-3-opus': { input: 15, output: 75 },
|
|
212
|
+
'claude-3-sonnet': { input: 3, output: 15 },
|
|
213
|
+
'claude-3-haiku': { input: 0.25, output: 1.25 },
|
|
214
|
+
};
|
|
215
|
+
const price = prices[model] ?? prices['claude-3-sonnet'] ?? { input: 3, output: 15 };
|
|
216
|
+
return ((usage.promptTokens / 1_000_000) * price.input +
|
|
217
|
+
(usage.completionTokens / 1_000_000) * price.output);
|
|
218
|
+
},
|
|
219
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @revealui/ai - Event Storage Implementations
|
|
3
|
+
*
|
|
4
|
+
* Storage backends for persisting agent events.
|
|
5
|
+
*/
|
|
6
|
+
import type { AnyAgentEvent, EventFilter, EventStorage } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* In-memory storage (no persistence)
|
|
9
|
+
*/
|
|
10
|
+
export declare class MemoryEventStorage implements EventStorage {
|
|
11
|
+
private events;
|
|
12
|
+
save(events: AnyAgentEvent[]): Promise<void>;
|
|
13
|
+
load(filter?: EventFilter): Promise<AnyAgentEvent[]>;
|
|
14
|
+
clear(): Promise<void>;
|
|
15
|
+
count(filter?: EventFilter): Promise<number>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Local storage (browser)
|
|
19
|
+
*/
|
|
20
|
+
export declare class LocalStorageEventStorage implements EventStorage {
|
|
21
|
+
private key;
|
|
22
|
+
constructor(key?: string);
|
|
23
|
+
save(events: AnyAgentEvent[]): Promise<void>;
|
|
24
|
+
load(filter?: EventFilter): Promise<AnyAgentEvent[]>;
|
|
25
|
+
clear(): Promise<void>;
|
|
26
|
+
count(filter?: EventFilter): Promise<number>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* File system storage (Node.js)
|
|
30
|
+
*/
|
|
31
|
+
export declare class FileSystemEventStorage implements EventStorage {
|
|
32
|
+
private filePath;
|
|
33
|
+
constructor(filePath: string);
|
|
34
|
+
save(events: AnyAgentEvent[]): Promise<void>;
|
|
35
|
+
load(filter?: EventFilter): Promise<AnyAgentEvent[]>;
|
|
36
|
+
clear(): Promise<void>;
|
|
37
|
+
count(filter?: EventFilter): Promise<number>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/observability/storage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE3E;;GAEG;AACH,qBAAa,kBAAmB,YAAW,YAAY;IACrD,OAAO,CAAC,MAAM,CAAuB;IAE/B,IAAI,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5C,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAoCpD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,KAAK,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;CAInD;AAED;;GAEG;AACH,qBAAa,wBAAyB,YAAW,YAAY;IAC3D,OAAO,CAAC,GAAG,CAAS;gBAER,GAAG,SAA0B;IAInC,IAAI,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAO5C,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAqDpD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQtB,KAAK,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;CAInD;AAED;;GAEG;AACH,qBAAa,sBAAuB,YAAW,YAAY;IACzD,OAAO,CAAC,QAAQ,CAAS;gBAEb,QAAQ,EAAE,MAAM;IAItB,IAAI,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAU5C,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAgDpD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAYtB,KAAK,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;CAInD"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @revealui/ai - Event Storage Implementations
|
|
3
|
+
*
|
|
4
|
+
* Storage backends for persisting agent events.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* In-memory storage (no persistence)
|
|
8
|
+
*/
|
|
9
|
+
export class MemoryEventStorage {
|
|
10
|
+
events = [];
|
|
11
|
+
async save(events) {
|
|
12
|
+
this.events = [...events];
|
|
13
|
+
}
|
|
14
|
+
async load(filter) {
|
|
15
|
+
if (!filter) {
|
|
16
|
+
return [...this.events];
|
|
17
|
+
}
|
|
18
|
+
let filtered = [...this.events];
|
|
19
|
+
if (filter.agentId) {
|
|
20
|
+
filtered = filtered.filter((e) => e.agentId === filter.agentId);
|
|
21
|
+
}
|
|
22
|
+
if (filter.sessionId) {
|
|
23
|
+
filtered = filtered.filter((e) => e.sessionId === filter.sessionId);
|
|
24
|
+
}
|
|
25
|
+
if (filter.taskId) {
|
|
26
|
+
filtered = filtered.filter((e) => e.taskId === filter.taskId);
|
|
27
|
+
}
|
|
28
|
+
if (filter.eventType) {
|
|
29
|
+
filtered = filtered.filter((e) => e.eventType === filter.eventType);
|
|
30
|
+
}
|
|
31
|
+
if (filter.startTime) {
|
|
32
|
+
const startTime = filter.startTime;
|
|
33
|
+
filtered = filtered.filter((e) => e.timestamp >= startTime);
|
|
34
|
+
}
|
|
35
|
+
if (filter.endTime) {
|
|
36
|
+
const endTime = filter.endTime;
|
|
37
|
+
filtered = filtered.filter((e) => e.timestamp <= endTime);
|
|
38
|
+
}
|
|
39
|
+
return filtered;
|
|
40
|
+
}
|
|
41
|
+
async clear() {
|
|
42
|
+
this.events = [];
|
|
43
|
+
}
|
|
44
|
+
async count(filter) {
|
|
45
|
+
const events = await this.load(filter);
|
|
46
|
+
return events.length;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Local storage (browser)
|
|
51
|
+
*/
|
|
52
|
+
export class LocalStorageEventStorage {
|
|
53
|
+
key;
|
|
54
|
+
constructor(key = 'revealui:agent:events') {
|
|
55
|
+
this.key = key;
|
|
56
|
+
}
|
|
57
|
+
async save(events) {
|
|
58
|
+
if (typeof window === 'undefined' || !window.localStorage) {
|
|
59
|
+
throw new Error('LocalStorage not available');
|
|
60
|
+
}
|
|
61
|
+
window.localStorage.setItem(this.key, JSON.stringify(events));
|
|
62
|
+
}
|
|
63
|
+
async load(filter) {
|
|
64
|
+
if (typeof window === 'undefined' || !window.localStorage) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
const data = window.localStorage.getItem(this.key);
|
|
69
|
+
if (!data) {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
const events = JSON.parse(data);
|
|
73
|
+
if (!filter) {
|
|
74
|
+
return events;
|
|
75
|
+
}
|
|
76
|
+
let filtered = events;
|
|
77
|
+
if (filter.agentId) {
|
|
78
|
+
filtered = filtered.filter((e) => e.agentId === filter.agentId);
|
|
79
|
+
}
|
|
80
|
+
if (filter.sessionId) {
|
|
81
|
+
filtered = filtered.filter((e) => e.sessionId === filter.sessionId);
|
|
82
|
+
}
|
|
83
|
+
if (filter.taskId) {
|
|
84
|
+
filtered = filtered.filter((e) => e.taskId === filter.taskId);
|
|
85
|
+
}
|
|
86
|
+
if (filter.eventType) {
|
|
87
|
+
filtered = filtered.filter((e) => e.eventType === filter.eventType);
|
|
88
|
+
}
|
|
89
|
+
if (filter.startTime) {
|
|
90
|
+
const startTime = filter.startTime;
|
|
91
|
+
filtered = filtered.filter((e) => e.timestamp >= startTime);
|
|
92
|
+
}
|
|
93
|
+
if (filter.endTime) {
|
|
94
|
+
const endTime = filter.endTime;
|
|
95
|
+
filtered = filtered.filter((e) => e.timestamp <= endTime);
|
|
96
|
+
}
|
|
97
|
+
return filtered;
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
// Return empty array on error - graceful degradation
|
|
101
|
+
void (error instanceof Error ? error.message : String(error)); // Query failed - graceful degradation
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async clear() {
|
|
106
|
+
if (typeof window === 'undefined' || !window.localStorage) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
window.localStorage.removeItem(this.key);
|
|
110
|
+
}
|
|
111
|
+
async count(filter) {
|
|
112
|
+
const events = await this.load(filter);
|
|
113
|
+
return events.length;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* File system storage (Node.js)
|
|
118
|
+
*/
|
|
119
|
+
export class FileSystemEventStorage {
|
|
120
|
+
filePath;
|
|
121
|
+
constructor(filePath) {
|
|
122
|
+
this.filePath = filePath;
|
|
123
|
+
}
|
|
124
|
+
async save(events) {
|
|
125
|
+
const fs = await import('node:fs/promises');
|
|
126
|
+
const path = await import('node:path');
|
|
127
|
+
const dir = path.dirname(this.filePath);
|
|
128
|
+
await fs.mkdir(dir, { recursive: true });
|
|
129
|
+
await fs.writeFile(this.filePath, JSON.stringify(events, null, 2), 'utf-8');
|
|
130
|
+
}
|
|
131
|
+
async load(filter) {
|
|
132
|
+
const fs = await import('node:fs/promises');
|
|
133
|
+
try {
|
|
134
|
+
const data = await fs.readFile(this.filePath, 'utf-8');
|
|
135
|
+
const events = JSON.parse(data);
|
|
136
|
+
if (!filter) {
|
|
137
|
+
return events;
|
|
138
|
+
}
|
|
139
|
+
let filtered = events;
|
|
140
|
+
if (filter.agentId) {
|
|
141
|
+
filtered = filtered.filter((e) => e.agentId === filter.agentId);
|
|
142
|
+
}
|
|
143
|
+
if (filter.sessionId) {
|
|
144
|
+
filtered = filtered.filter((e) => e.sessionId === filter.sessionId);
|
|
145
|
+
}
|
|
146
|
+
if (filter.taskId) {
|
|
147
|
+
filtered = filtered.filter((e) => e.taskId === filter.taskId);
|
|
148
|
+
}
|
|
149
|
+
if (filter.eventType) {
|
|
150
|
+
filtered = filtered.filter((e) => e.eventType === filter.eventType);
|
|
151
|
+
}
|
|
152
|
+
if (filter.startTime) {
|
|
153
|
+
const startTime = filter.startTime;
|
|
154
|
+
filtered = filtered.filter((e) => e.timestamp >= startTime);
|
|
155
|
+
}
|
|
156
|
+
if (filter.endTime) {
|
|
157
|
+
const endTime = filter.endTime;
|
|
158
|
+
filtered = filtered.filter((e) => e.timestamp <= endTime);
|
|
159
|
+
}
|
|
160
|
+
return filtered;
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
if (error.code === 'ENOENT') {
|
|
164
|
+
return [];
|
|
165
|
+
}
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async clear() {
|
|
170
|
+
const fs = await import('node:fs/promises');
|
|
171
|
+
try {
|
|
172
|
+
await fs.unlink(this.filePath);
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
if (error.code !== 'ENOENT') {
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async count(filter) {
|
|
181
|
+
const events = await this.load(filter);
|
|
182
|
+
return events.length;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -8,6 +8,7 @@ import type { ReasoningEffort } from '../llm/providers/base.js';
|
|
|
8
8
|
import type { AgentSkillProvider } from '../skills/integration/agent-skill-provider.js';
|
|
9
9
|
import type { ApprovalCallback } from '../tools/base.js';
|
|
10
10
|
import type { MCPToolSource, McpClientLike } from '../tools/mcp-adapter.js';
|
|
11
|
+
import type { McpToolCallEvent } from '../tools/mcp-events.js';
|
|
11
12
|
import type { Agent, AgentResult, Task } from './agent.js';
|
|
12
13
|
/**
|
|
13
14
|
* Reasoning-depth hint for a task. Alias of the neutral `ReasoningEffort` — the agnostic
|
|
@@ -64,6 +65,12 @@ export interface RuntimeConfig {
|
|
|
64
65
|
name: string;
|
|
65
66
|
client: McpClientLike;
|
|
66
67
|
}>;
|
|
68
|
+
/**
|
|
69
|
+
* GAP-355 integrity audit for MCP tools discovered at run time.
|
|
70
|
+
* Passed into `createToolsFromMcpClient` and `discoverMCPTools` so library
|
|
71
|
+
* consumers (not only agent-stream) fail closed when a receipt cannot land.
|
|
72
|
+
*/
|
|
73
|
+
onToolAudit?: (event: McpToolCallEvent) => void | Promise<void>;
|
|
67
74
|
/**
|
|
68
75
|
* Optional skill provider. When set, activated skills are injected into the
|
|
69
76
|
* system prompt before the first LLM call, giving the agent contextual
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/orchestration/runtime.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAW,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAEzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAC;AACxF,OAAO,KAAK,EAAE,gBAAgB,EAAoB,MAAM,kBAAkB,CAAC;AAE3E,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/orchestration/runtime.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAW,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAEzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAC;AACxF,OAAO,KAAK,EAAE,gBAAgB,EAAoB,MAAM,kBAAkB,CAAC;AAE3E,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,eAAe,CAAC;AAE5C,MAAM,WAAW,aAAa;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;OAIG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B;;;;;;;;;OASG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,UAAU,CAAC,EAAE,aAAa,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,aAAa,CAAA;KAAE,CAAC,CAAC;IACpE;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE;;;;OAIG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC;IACnC;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,gCAAgC,EAAE,SAAS,CAAC;IAC/D;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC;AAED,qBAAa,YAAY;IACvB,SAAS,CAAC,MAAM,EAAE,aAAa,CAAC;IAChC,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,cAAc,CAAgD;IACtE,OAAO,CAAC,cAAc,CAAS;gBAEnB,MAAM,GAAE,aAAkB;IA2BtC;;OAEG;IACG,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC;YAqBzE,OAAO;IAsPrB;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAI7B;;OAEG;IACG,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAc9E;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA+B9B;;OAEG;IACH,SAAS,IAAI;QACX,cAAc,EAAE,OAAO,CAAC;QACxB,WAAW,EAAE,MAAM,CAAC;QACpB,cAAc,EAAE,MAAM,CAAC;KACxB;CAOF"}
|
|
@@ -23,6 +23,7 @@ export class AgentRuntime {
|
|
|
23
23
|
enableCache: config.enableCache ?? true, // Enable by default for cost savings
|
|
24
24
|
mcpToolSource: config.mcpToolSource,
|
|
25
25
|
mcpClients: config.mcpClients,
|
|
26
|
+
onToolAudit: config.onToolAudit,
|
|
26
27
|
skillProvider: config.skillProvider,
|
|
27
28
|
thinkingLevel: config.thinkingLevel,
|
|
28
29
|
modelTier: config.modelTier,
|
|
@@ -64,13 +65,19 @@ export class AgentRuntime {
|
|
|
64
65
|
// - Standard `McpClient` instances (Stage 5.1a, preferred)
|
|
65
66
|
// - `MCPToolSource` / hypervisor (legacy, deprecated but supported)
|
|
66
67
|
const mcpTools = [];
|
|
68
|
+
const onToolAudit = this.config.onToolAudit;
|
|
67
69
|
if (this.config.mcpToolSource) {
|
|
68
|
-
mcpTools.push(...discoverMCPTools(this.config.mcpToolSource
|
|
70
|
+
mcpTools.push(...discoverMCPTools(this.config.mcpToolSource, {
|
|
71
|
+
...(onToolAudit !== undefined ? { onToolAudit } : {}),
|
|
72
|
+
}));
|
|
69
73
|
}
|
|
70
74
|
if (this.config.mcpClients && this.config.mcpClients.length > 0) {
|
|
71
75
|
for (const { name, client } of this.config.mcpClients) {
|
|
72
76
|
try {
|
|
73
|
-
const fromClient = await createToolsFromMcpClient(client, {
|
|
77
|
+
const fromClient = await createToolsFromMcpClient(client, {
|
|
78
|
+
namespace: name,
|
|
79
|
+
...(onToolAudit !== undefined ? { onToolAudit } : {}),
|
|
80
|
+
});
|
|
74
81
|
mcpTools.push(...fromClient);
|
|
75
82
|
}
|
|
76
83
|
catch {
|
|
@@ -15,6 +15,7 @@ import type { Database } from '@revealui/db/client';
|
|
|
15
15
|
import type { LLMClient } from '../llm/client.js';
|
|
16
16
|
import type { EpisodicMemory } from '../memory/stores/episodic-memory.js';
|
|
17
17
|
import type { AdminAPIClient, CollectionMetadata, GlobalMetadata } from '../tools/admin/factory.js';
|
|
18
|
+
import type { Tool } from '../tools/base.js';
|
|
18
19
|
import type { TicketMutationClient } from '../tools/ticket-tools.js';
|
|
19
20
|
import type { AgentResult } from './agent.js';
|
|
20
21
|
export interface TicketInput {
|
|
@@ -51,6 +52,15 @@ export interface TicketAgentConfig {
|
|
|
51
52
|
maxIterations?: number;
|
|
52
53
|
/** Timeout in ms (default: 120_000) */
|
|
53
54
|
timeout?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Optional tool transform after the tool set is assembled (GAP-355 S6-4).
|
|
57
|
+
* Server injects pre-authorize wraps without `@revealui/ai` importing server.
|
|
58
|
+
* Called once per dispatch with the ticket id and optional dispatchId.
|
|
59
|
+
*/
|
|
60
|
+
wrapTools?: (tools: Tool[], ctx: {
|
|
61
|
+
ticketId: string;
|
|
62
|
+
dispatchId?: string;
|
|
63
|
+
}) => Tool[];
|
|
54
64
|
}
|
|
55
65
|
export declare class TicketAgentDispatcher {
|
|
56
66
|
private config;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ticket-agent.d.ts","sourceRoot":"","sources":["../../src/orchestration/ticket-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,KAAK,EACV,cAAc,EAEd,kBAAkB,EAClB,cAAc,EACf,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"ticket-agent.d.ts","sourceRoot":"","sources":["../../src/orchestration/ticket-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,KAAK,EACV,cAAc,EAEd,kBAAkB,EAClB,cAAc,EACf,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAGrE,OAAO,KAAK,EAAS,WAAW,EAAQ,MAAM,YAAY,CAAC;AAG3D,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,0GAA0G;IAC1G,WAAW,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,2CAA2C;IAC3C,SAAS,EAAE,SAAS,CAAC;IAErB,2DAA2D;IAC3D,SAAS,EAAE,cAAc,CAAC;IAE1B,wEAAwE;IACxE,YAAY,EAAE,oBAAoB,CAAC;IAEnC,yEAAyE;IACzE,WAAW,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAEnC,yCAAyC;IACzC,OAAO,CAAC,EAAE,cAAc,EAAE,CAAC;IAE3B;;;;OAIG;IACH,MAAM,CAAC,EAAE,cAAc,CAAC;IAExB;;;OAGG;IACH,EAAE,CAAC,EAAE,QAAQ,CAAC;IAEd,wDAAwD;IACxD,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,EAAE,CAAC;CACvF;AAwDD,qBAAa,qBAAqB;IAChC,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,YAAY,CAAoB;gBAE5B,MAAM,EAAE,iBAAiB;IAUrC;;;;;;;;;;;;;;;OAeG;IACG,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,GAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,OAAO,CAAC,WAAW,CAAC;CAgEjG"}
|
|
@@ -113,7 +113,13 @@ export class TicketAgentDispatcher {
|
|
|
113
113
|
const extraTools = db
|
|
114
114
|
? [webScraperTool, createDocumentSummarizerTool(db, this.config.llmClient)]
|
|
115
115
|
: [webScraperTool];
|
|
116
|
-
|
|
116
|
+
let tools = [...cmsTools, ...ticketTools, ...extraTools];
|
|
117
|
+
if (this.config.wrapTools) {
|
|
118
|
+
tools = this.config.wrapTools(tools, {
|
|
119
|
+
ticketId: ticket.id,
|
|
120
|
+
...(options.dispatchId !== undefined ? { dispatchId: options.dispatchId } : {}),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
117
123
|
// The runtime does not call agent.memory - satisfy the interface with a stub when no
|
|
118
124
|
// shared memory instance is provided. Cast is safe: only runtime touches this field.
|
|
119
125
|
const memory = (sharedMemory ?? {});
|