@mcoda/codali 0.1.88 → 0.1.89
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/dist/cli/EvalCommand.d.ts +8 -0
- package/dist/cli/EvalCommand.d.ts.map +1 -1
- package/dist/cli/EvalCommand.js +93 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1 -0
- package/dist/docdex/DocdexClient.d.ts +8 -1
- package/dist/docdex/DocdexClient.d.ts.map +1 -1
- package/dist/docdex/DocdexClient.js +126 -33
- package/dist/eval/CodaliGatewayLiveHarness.d.ts +169 -0
- package/dist/eval/CodaliGatewayLiveHarness.d.ts.map +1 -0
- package/dist/eval/CodaliGatewayLiveHarness.js +824 -0
- package/dist/eval/GatewayEvalSuite.d.ts +202 -0
- package/dist/eval/GatewayEvalSuite.d.ts.map +1 -0
- package/dist/eval/GatewayEvalSuite.js +673 -0
- package/dist/gateway/AgentTierResolver.d.ts +74 -0
- package/dist/gateway/AgentTierResolver.d.ts.map +1 -0
- package/dist/gateway/AgentTierResolver.js +576 -0
- package/dist/gateway/AppToolGatewayDispatcher.d.ts +88 -0
- package/dist/gateway/AppToolGatewayDispatcher.d.ts.map +1 -0
- package/dist/gateway/AppToolGatewayDispatcher.js +381 -0
- package/dist/gateway/CodaliGateway.d.ts +73 -0
- package/dist/gateway/CodaliGateway.d.ts.map +1 -0
- package/dist/gateway/CodaliGateway.js +824 -0
- package/dist/gateway/CodaliGatewaySchemas.d.ts +21 -0
- package/dist/gateway/CodaliGatewaySchemas.d.ts.map +1 -0
- package/dist/gateway/CodaliGatewaySchemas.js +874 -0
- package/dist/gateway/CodaliGatewayStore.d.ts +157 -0
- package/dist/gateway/CodaliGatewayStore.d.ts.map +1 -0
- package/dist/gateway/CodaliGatewayStore.js +206 -0
- package/dist/gateway/CodaliGatewayTypes.d.ts +336 -0
- package/dist/gateway/CodaliGatewayTypes.d.ts.map +1 -0
- package/dist/gateway/CodaliGatewayTypes.js +1 -0
- package/dist/gateway/ContextPackBuilder.d.ts +43 -0
- package/dist/gateway/ContextPackBuilder.d.ts.map +1 -0
- package/dist/gateway/ContextPackBuilder.js +317 -0
- package/dist/gateway/EvidenceNormalizer.d.ts +42 -0
- package/dist/gateway/EvidenceNormalizer.d.ts.map +1 -0
- package/dist/gateway/EvidenceNormalizer.js +488 -0
- package/dist/gateway/GatewayPlanner.d.ts +195 -0
- package/dist/gateway/GatewayPlanner.d.ts.map +1 -0
- package/dist/gateway/GatewayPlanner.js +379 -0
- package/dist/gateway/GatewayPolicyCompiler.d.ts +30 -0
- package/dist/gateway/GatewayPolicyCompiler.d.ts.map +1 -0
- package/dist/gateway/GatewayPolicyCompiler.js +114 -0
- package/dist/gateway/GatewaySecurityPolicy.d.ts +14 -0
- package/dist/gateway/GatewaySecurityPolicy.d.ts.map +1 -0
- package/dist/gateway/GatewaySecurityPolicy.js +350 -0
- package/dist/gateway/GatewayStateMachine.d.ts +165 -0
- package/dist/gateway/GatewayStateMachine.d.ts.map +1 -0
- package/dist/gateway/GatewayStateMachine.js +790 -0
- package/dist/gateway/GatewayTraceReplay.d.ts +120 -0
- package/dist/gateway/GatewayTraceReplay.d.ts.map +1 -0
- package/dist/gateway/GatewayTraceReplay.js +273 -0
- package/dist/gateway/ToolCapabilityCompiler.d.ts +50 -0
- package/dist/gateway/ToolCapabilityCompiler.d.ts.map +1 -0
- package/dist/gateway/ToolCapabilityCompiler.js +442 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -0
- package/dist/runtime/CodaliRuntime.d.ts +7 -0
- package/dist/runtime/CodaliRuntime.d.ts.map +1 -1
- package/dist/runtime/CodaliRuntime.js +98 -54
- package/dist/tools/ToolRegistry.d.ts.map +1 -1
- package/dist/tools/ToolRegistry.js +4 -0
- package/dist/tools/ToolTypes.d.ts +1 -1
- package/dist/tools/ToolTypes.d.ts.map +1 -1
- package/dist/tools/ToolTypes.js +5 -1
- package/package.json +3 -3
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { CodaliContextPack, CodaliEvidenceItem, CodaliGatewayRequest, CodaliGatewayTraceEvent } from "./CodaliGatewayTypes.js";
|
|
2
|
+
import { type CodaliGatewayRunTrace, type CodaliGatewayStore, type CodaliGatewayStoredArtifact, type CodaliGatewayStoredModelCall, type CodaliGatewayStoredTask, type CodaliGatewayStoredToolCall } from "./CodaliGatewayStore.js";
|
|
3
|
+
export declare const CODALI_GATEWAY_TRACE_SCHEMA_VERSION: 1;
|
|
4
|
+
export declare const CODALI_GATEWAY_REPLAY_FIXTURE_SCHEMA_VERSION: 1;
|
|
5
|
+
export declare const CODALI_GATEWAY_TRACE_EVENT_NAMES: {
|
|
6
|
+
readonly RUN_CREATED: "codali.gateway.run.created";
|
|
7
|
+
readonly RUN_STATUS: "codali.gateway.run.status";
|
|
8
|
+
readonly TASK_STATUS: "codali.gateway.task.status";
|
|
9
|
+
readonly TOOL_CALL: "codali.gateway.tool.call";
|
|
10
|
+
readonly MODEL_CALL: "codali.gateway.model.call";
|
|
11
|
+
readonly EVIDENCE_RECORDED: "codali.gateway.evidence.recorded";
|
|
12
|
+
readonly CONTEXT_PACK_BUILT: "codali.gateway.context_pack.built";
|
|
13
|
+
readonly ARTIFACT_CREATED: "codali.gateway.artifact.created";
|
|
14
|
+
readonly FINAL_SYNTHESIS: "codali.gateway.final_synthesis";
|
|
15
|
+
};
|
|
16
|
+
export interface CodaliGatewayDebugSummary {
|
|
17
|
+
runId: string;
|
|
18
|
+
status: string;
|
|
19
|
+
mode?: string;
|
|
20
|
+
product?: string;
|
|
21
|
+
tenantId?: string;
|
|
22
|
+
tenantSlug?: string;
|
|
23
|
+
conversationId?: string;
|
|
24
|
+
taskCount: number;
|
|
25
|
+
evidenceCount: number;
|
|
26
|
+
toolCallCount: number;
|
|
27
|
+
modelCallCount: number;
|
|
28
|
+
artifactCount: number;
|
|
29
|
+
sourceCount: number;
|
|
30
|
+
calledTools: string[];
|
|
31
|
+
failedTools: string[];
|
|
32
|
+
modelRoles: string[];
|
|
33
|
+
finalModel?: {
|
|
34
|
+
role: string;
|
|
35
|
+
agentSlug?: string;
|
|
36
|
+
model?: string;
|
|
37
|
+
provider?: string;
|
|
38
|
+
status: string;
|
|
39
|
+
};
|
|
40
|
+
warnings: string[];
|
|
41
|
+
errors: string[];
|
|
42
|
+
}
|
|
43
|
+
export interface CodaliGatewayTraceReadResult {
|
|
44
|
+
schemaVersion: typeof CODALI_GATEWAY_TRACE_SCHEMA_VERSION;
|
|
45
|
+
runId: string;
|
|
46
|
+
status: string;
|
|
47
|
+
run: CodaliGatewayRunTrace["run"];
|
|
48
|
+
tasks: CodaliGatewayStoredTask[];
|
|
49
|
+
evidence: CodaliEvidenceItem[];
|
|
50
|
+
toolCalls: CodaliGatewayStoredToolCall[];
|
|
51
|
+
modelCalls: CodaliGatewayStoredModelCall[];
|
|
52
|
+
contextPack?: CodaliContextPack;
|
|
53
|
+
artifacts: CodaliGatewayStoredArtifact[];
|
|
54
|
+
finalAnswer?: string;
|
|
55
|
+
debugSummary: CodaliGatewayDebugSummary;
|
|
56
|
+
events: CodaliGatewayTraceEvent[];
|
|
57
|
+
}
|
|
58
|
+
export interface CodaliGatewayTraceReadInput {
|
|
59
|
+
store: CodaliGatewayStore;
|
|
60
|
+
runId: string;
|
|
61
|
+
}
|
|
62
|
+
export interface CodaliGatewayReplayFixtureToolCall {
|
|
63
|
+
id: string;
|
|
64
|
+
taskId?: string;
|
|
65
|
+
tool: string;
|
|
66
|
+
status: string;
|
|
67
|
+
args?: unknown;
|
|
68
|
+
result?: unknown;
|
|
69
|
+
errorCode?: string;
|
|
70
|
+
errorMessage?: string;
|
|
71
|
+
latencyMs?: number;
|
|
72
|
+
}
|
|
73
|
+
export interface CodaliGatewayReplayFixtureModelCall {
|
|
74
|
+
id: string;
|
|
75
|
+
taskId?: string;
|
|
76
|
+
role: string;
|
|
77
|
+
status: string;
|
|
78
|
+
agentSlug?: string;
|
|
79
|
+
model?: string;
|
|
80
|
+
provider?: string;
|
|
81
|
+
input?: unknown;
|
|
82
|
+
output?: unknown;
|
|
83
|
+
errorCode?: string;
|
|
84
|
+
errorMessage?: string;
|
|
85
|
+
latencyMs?: number;
|
|
86
|
+
}
|
|
87
|
+
export interface CodaliGatewayReplayFixture {
|
|
88
|
+
schemaVersion: typeof CODALI_GATEWAY_REPLAY_FIXTURE_SCHEMA_VERSION;
|
|
89
|
+
fixtureId: string;
|
|
90
|
+
runId: string;
|
|
91
|
+
exportedAt: string;
|
|
92
|
+
request?: CodaliGatewayRequest | Record<string, unknown>;
|
|
93
|
+
planner: {
|
|
94
|
+
classifierOutput?: unknown;
|
|
95
|
+
plannerOutput?: unknown;
|
|
96
|
+
};
|
|
97
|
+
contextPack?: CodaliContextPack;
|
|
98
|
+
evidence: CodaliEvidenceItem[];
|
|
99
|
+
toolFixtures: CodaliGatewayReplayFixtureToolCall[];
|
|
100
|
+
modelFixtures: CodaliGatewayReplayFixtureModelCall[];
|
|
101
|
+
finalAnswer?: string;
|
|
102
|
+
debugSummary: CodaliGatewayDebugSummary;
|
|
103
|
+
events: CodaliGatewayTraceEvent[];
|
|
104
|
+
}
|
|
105
|
+
export interface CodaliGatewayReplayFixtureOptions {
|
|
106
|
+
fixtureId?: string;
|
|
107
|
+
includeModelInputs?: boolean;
|
|
108
|
+
includeModelOutputs?: boolean;
|
|
109
|
+
includeToolResults?: boolean;
|
|
110
|
+
}
|
|
111
|
+
export interface CodaliGatewayReplayFixtureInput {
|
|
112
|
+
store: CodaliGatewayStore;
|
|
113
|
+
runId: string;
|
|
114
|
+
options?: CodaliGatewayReplayFixtureOptions;
|
|
115
|
+
}
|
|
116
|
+
export declare const summarizeCodaliGatewayTrace: (trace: CodaliGatewayRunTrace) => CodaliGatewayDebugSummary;
|
|
117
|
+
export declare const buildCodaliGatewayTraceEvents: (trace: CodaliGatewayRunTrace | undefined) => CodaliGatewayTraceEvent[];
|
|
118
|
+
export declare const readCodaliGatewayTrace: ({ store, runId, }: CodaliGatewayTraceReadInput) => Promise<CodaliGatewayTraceReadResult | undefined>;
|
|
119
|
+
export declare const exportCodaliGatewayReplayFixture: ({ store, runId, options, }: CodaliGatewayReplayFixtureInput) => Promise<CodaliGatewayReplayFixture | undefined>;
|
|
120
|
+
//# sourceMappingURL=GatewayTraceReplay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GatewayTraceReplay.d.ts","sourceRoot":"","sources":["../../src/gateway/GatewayTraceReplay.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAChC,KAAK,4BAA4B,EACjC,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,EACjC,MAAM,yBAAyB,CAAC;AAEjC,eAAO,MAAM,mCAAmC,EAAG,CAAU,CAAC;AAC9D,eAAO,MAAM,4CAA4C,EAAG,CAAU,CAAC;AAEvE,eAAO,MAAM,gCAAgC;;;;;;;;;;CAUnC,CAAC;AAEX,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,EAAE,CAAC;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mB,CAAC,EAAE,OAAO,CAAC;IAC9B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,+BAA+B;IAC9C,KAAK,EAAE,kBAAkB,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,iCAAiC,CAAC;CAC7C;AA+GD,eAAO,MAAM,2BAA2B,GACtC,OAAO,qBAAqB,KAC3B,yBAoCF,CAAC;AAEF,eAAO,MAAM,6BAA6B,GACxC,OAAO,qBAAqB,GAAG,SAAS,KACvC,uBAAuB,EAmIzB,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAU,mBAG1C,2BAA2B,KAAG,OAAO,CAAC,4BAA4B,GAAG,SAAS,CAuBhF,CAAC;AAEF,eAAO,MAAM,gCAAgC,GAAU,4BAIpD,+BAA+B,KAAG,OAAO,CAAC,0BAA0B,GAAG,SAAS,CAmDlF,CAAC"}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { redactCodaliGatewaySecrets, } from "./CodaliGatewayStore.js";
|
|
3
|
+
export const CODALI_GATEWAY_TRACE_SCHEMA_VERSION = 1;
|
|
4
|
+
export const CODALI_GATEWAY_REPLAY_FIXTURE_SCHEMA_VERSION = 1;
|
|
5
|
+
export const CODALI_GATEWAY_TRACE_EVENT_NAMES = {
|
|
6
|
+
RUN_CREATED: "codali.gateway.run.created",
|
|
7
|
+
RUN_STATUS: "codali.gateway.run.status",
|
|
8
|
+
TASK_STATUS: "codali.gateway.task.status",
|
|
9
|
+
TOOL_CALL: "codali.gateway.tool.call",
|
|
10
|
+
MODEL_CALL: "codali.gateway.model.call",
|
|
11
|
+
EVIDENCE_RECORDED: "codali.gateway.evidence.recorded",
|
|
12
|
+
CONTEXT_PACK_BUILT: "codali.gateway.context_pack.built",
|
|
13
|
+
ARTIFACT_CREATED: "codali.gateway.artifact.created",
|
|
14
|
+
FINAL_SYNTHESIS: "codali.gateway.final_synthesis",
|
|
15
|
+
};
|
|
16
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17
|
+
const cloneRedacted = (value) => redactCodaliGatewaySecrets(value);
|
|
18
|
+
const uniqueInOrder = (values) => {
|
|
19
|
+
const seen = new Set();
|
|
20
|
+
const output = [];
|
|
21
|
+
for (const value of values) {
|
|
22
|
+
if (!value || seen.has(value)) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
seen.add(value);
|
|
26
|
+
output.push(value);
|
|
27
|
+
}
|
|
28
|
+
return output;
|
|
29
|
+
};
|
|
30
|
+
const metadataString = (metadata, key) => {
|
|
31
|
+
const value = metadata?.[key];
|
|
32
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
33
|
+
};
|
|
34
|
+
const requestMode = (request, metadata) => {
|
|
35
|
+
if (isRecord(request) && typeof request.mode === "string") {
|
|
36
|
+
return request.mode;
|
|
37
|
+
}
|
|
38
|
+
return metadataString(metadata, "mode");
|
|
39
|
+
};
|
|
40
|
+
const requestProduct = (request, metadata) => {
|
|
41
|
+
if (isRecord(request) && isRecord(request.product)) {
|
|
42
|
+
const productName = request.product.name;
|
|
43
|
+
if (typeof productName === "string" && productName.length > 0) {
|
|
44
|
+
return productName;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return metadataString(metadata, "product");
|
|
48
|
+
};
|
|
49
|
+
const requestTenantValue = (request, key) => {
|
|
50
|
+
if (!isRecord(request) || !isRecord(request.tenant)) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
const value = request.tenant[key];
|
|
54
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
55
|
+
};
|
|
56
|
+
const requestConversationId = (request) => {
|
|
57
|
+
if (!isRecord(request) || !isRecord(request.conversation)) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
const value = request.conversation.id;
|
|
61
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
62
|
+
};
|
|
63
|
+
const collectSourceIds = (contextPack) => {
|
|
64
|
+
if (!contextPack) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
return uniqueInOrder([
|
|
68
|
+
...contextPack.decisionFacts.map((fact) => fact.sourceId),
|
|
69
|
+
...contextPack.decisionFacts.map((fact) => fact.sourceUri),
|
|
70
|
+
...contextPack.selectedExcerpts.map((excerpt) => excerpt.evidenceId),
|
|
71
|
+
]);
|
|
72
|
+
};
|
|
73
|
+
const finalModelCall = (modelCalls) => [...modelCalls]
|
|
74
|
+
.reverse()
|
|
75
|
+
.find((call) => call.role === "final_synthesizer")
|
|
76
|
+
?? [...modelCalls].reverse().find((call) => call.role === "final");
|
|
77
|
+
const finalAnswerFromTrace = (modelCalls) => {
|
|
78
|
+
const call = finalModelCall(modelCalls);
|
|
79
|
+
return typeof call?.output === "string" ? call.output : undefined;
|
|
80
|
+
};
|
|
81
|
+
const event = (kind, message, metadata, timestamp) => ({
|
|
82
|
+
kind,
|
|
83
|
+
timestamp: timestamp ?? new Date(0).toISOString(),
|
|
84
|
+
message,
|
|
85
|
+
metadata: cloneRedacted(metadata),
|
|
86
|
+
});
|
|
87
|
+
export const summarizeCodaliGatewayTrace = (trace) => {
|
|
88
|
+
const metadata = trace.run.metadata;
|
|
89
|
+
const finalCall = finalModelCall(trace.modelCalls);
|
|
90
|
+
return {
|
|
91
|
+
runId: trace.run.runId,
|
|
92
|
+
status: trace.run.status,
|
|
93
|
+
mode: requestMode(trace.run.request, metadata),
|
|
94
|
+
product: requestProduct(trace.run.request, metadata),
|
|
95
|
+
tenantId: requestTenantValue(trace.run.request, "id"),
|
|
96
|
+
tenantSlug: requestTenantValue(trace.run.request, "slug"),
|
|
97
|
+
conversationId: requestConversationId(trace.run.request),
|
|
98
|
+
taskCount: trace.tasks.length,
|
|
99
|
+
evidenceCount: trace.evidence.length,
|
|
100
|
+
toolCallCount: trace.toolCalls.length,
|
|
101
|
+
modelCallCount: trace.modelCalls.length,
|
|
102
|
+
artifactCount: trace.artifacts.length,
|
|
103
|
+
sourceCount: collectSourceIds(trace.contextPack).length,
|
|
104
|
+
calledTools: uniqueInOrder(trace.toolCalls.map((call) => call.tool)),
|
|
105
|
+
failedTools: uniqueInOrder(trace.toolCalls
|
|
106
|
+
.filter((call) => call.status !== "success")
|
|
107
|
+
.map((call) => call.tool)),
|
|
108
|
+
modelRoles: uniqueInOrder(trace.modelCalls.map((call) => call.role)),
|
|
109
|
+
finalModel: finalCall
|
|
110
|
+
? {
|
|
111
|
+
role: finalCall.role,
|
|
112
|
+
agentSlug: finalCall.agentSlug,
|
|
113
|
+
model: finalCall.model,
|
|
114
|
+
provider: finalCall.provider,
|
|
115
|
+
status: finalCall.status,
|
|
116
|
+
}
|
|
117
|
+
: undefined,
|
|
118
|
+
warnings: [...trace.run.warnings],
|
|
119
|
+
errors: [...trace.run.errors],
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
export const buildCodaliGatewayTraceEvents = (trace) => {
|
|
123
|
+
if (!trace) {
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
const events = [
|
|
127
|
+
event(CODALI_GATEWAY_TRACE_EVENT_NAMES.RUN_CREATED, "Gateway run created", { runId: trace.run.runId, status: trace.run.status }, trace.run.createdAt),
|
|
128
|
+
event(CODALI_GATEWAY_TRACE_EVENT_NAMES.RUN_STATUS, "Gateway run status updated", { runId: trace.run.runId, status: trace.run.status }, trace.run.updatedAt),
|
|
129
|
+
];
|
|
130
|
+
for (const task of trace.tasks) {
|
|
131
|
+
events.push(event(CODALI_GATEWAY_TRACE_EVENT_NAMES.TASK_STATUS, "Gateway task status updated", {
|
|
132
|
+
runId: trace.run.runId,
|
|
133
|
+
taskId: task.id,
|
|
134
|
+
status: task.status,
|
|
135
|
+
workerRole: task.workerRole,
|
|
136
|
+
}, task.updatedAt));
|
|
137
|
+
}
|
|
138
|
+
if (trace.evidence.length > 0) {
|
|
139
|
+
events.push(event(CODALI_GATEWAY_TRACE_EVENT_NAMES.EVIDENCE_RECORDED, "Gateway evidence recorded", {
|
|
140
|
+
runId: trace.run.runId,
|
|
141
|
+
evidenceCount: trace.evidence.length,
|
|
142
|
+
evidenceIds: trace.evidence.map((item) => item.id),
|
|
143
|
+
}, trace.run.updatedAt));
|
|
144
|
+
}
|
|
145
|
+
for (const call of trace.toolCalls) {
|
|
146
|
+
events.push(event(CODALI_GATEWAY_TRACE_EVENT_NAMES.TOOL_CALL, "Gateway tool call recorded", {
|
|
147
|
+
runId: trace.run.runId,
|
|
148
|
+
toolCallId: call.id,
|
|
149
|
+
taskId: call.taskId,
|
|
150
|
+
tool: call.tool,
|
|
151
|
+
status: call.status,
|
|
152
|
+
latencyMs: call.latencyMs,
|
|
153
|
+
errorCode: call.errorCode,
|
|
154
|
+
}, call.endedAt ?? call.startedAt));
|
|
155
|
+
}
|
|
156
|
+
for (const call of trace.modelCalls) {
|
|
157
|
+
events.push(event(CODALI_GATEWAY_TRACE_EVENT_NAMES.MODEL_CALL, "Gateway model call recorded", {
|
|
158
|
+
runId: trace.run.runId,
|
|
159
|
+
modelCallId: call.id,
|
|
160
|
+
taskId: call.taskId,
|
|
161
|
+
role: call.role,
|
|
162
|
+
status: call.status,
|
|
163
|
+
agentSlug: call.agentSlug,
|
|
164
|
+
model: call.model,
|
|
165
|
+
provider: call.provider,
|
|
166
|
+
latencyMs: call.latencyMs,
|
|
167
|
+
errorCode: call.errorCode,
|
|
168
|
+
}, call.endedAt ?? call.startedAt));
|
|
169
|
+
}
|
|
170
|
+
if (trace.contextPack) {
|
|
171
|
+
events.push(event(CODALI_GATEWAY_TRACE_EVENT_NAMES.CONTEXT_PACK_BUILT, "Gateway context pack built", {
|
|
172
|
+
runId: trace.run.runId,
|
|
173
|
+
contextPackId: trace.contextPack.id,
|
|
174
|
+
evidenceCount: trace.contextPack.decisionFacts.length,
|
|
175
|
+
tokenEstimate: trace.contextPack.tokenEstimate,
|
|
176
|
+
sourceCount: collectSourceIds(trace.contextPack).length,
|
|
177
|
+
}, trace.run.updatedAt));
|
|
178
|
+
}
|
|
179
|
+
for (const artifact of trace.artifacts) {
|
|
180
|
+
events.push(event(CODALI_GATEWAY_TRACE_EVENT_NAMES.ARTIFACT_CREATED, "Gateway artifact created", {
|
|
181
|
+
runId: trace.run.runId,
|
|
182
|
+
artifactId: artifact.id,
|
|
183
|
+
taskId: artifact.taskId,
|
|
184
|
+
type: artifact.type,
|
|
185
|
+
uri: artifact.uri,
|
|
186
|
+
path: artifact.path,
|
|
187
|
+
model: artifact.model,
|
|
188
|
+
}, artifact.createdAt));
|
|
189
|
+
}
|
|
190
|
+
const finalCall = finalModelCall(trace.modelCalls);
|
|
191
|
+
if (finalCall || isRecord(trace.run.metadata?.finalSynthesis)) {
|
|
192
|
+
events.push(event(CODALI_GATEWAY_TRACE_EVENT_NAMES.FINAL_SYNTHESIS, "Gateway final synthesis recorded", {
|
|
193
|
+
runId: trace.run.runId,
|
|
194
|
+
modelCallId: finalCall?.id,
|
|
195
|
+
status: finalCall?.status ?? trace.run.status,
|
|
196
|
+
finalSynthesis: trace.run.metadata?.finalSynthesis,
|
|
197
|
+
}, finalCall?.endedAt ?? trace.run.updatedAt));
|
|
198
|
+
}
|
|
199
|
+
return events;
|
|
200
|
+
};
|
|
201
|
+
export const readCodaliGatewayTrace = async ({ store, runId, }) => {
|
|
202
|
+
const trace = await store.readRunTrace(runId);
|
|
203
|
+
if (!trace) {
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
const redacted = cloneRedacted(trace);
|
|
207
|
+
const debugSummary = summarizeCodaliGatewayTrace(redacted);
|
|
208
|
+
return {
|
|
209
|
+
schemaVersion: CODALI_GATEWAY_TRACE_SCHEMA_VERSION,
|
|
210
|
+
runId,
|
|
211
|
+
status: redacted.run.status,
|
|
212
|
+
run: redacted.run,
|
|
213
|
+
tasks: redacted.tasks,
|
|
214
|
+
evidence: redacted.evidence,
|
|
215
|
+
toolCalls: redacted.toolCalls,
|
|
216
|
+
modelCalls: redacted.modelCalls,
|
|
217
|
+
contextPack: redacted.contextPack,
|
|
218
|
+
artifacts: redacted.artifacts,
|
|
219
|
+
finalAnswer: finalAnswerFromTrace(redacted.modelCalls),
|
|
220
|
+
debugSummary,
|
|
221
|
+
events: buildCodaliGatewayTraceEvents(redacted),
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
export const exportCodaliGatewayReplayFixture = async ({ store, runId, options = {}, }) => {
|
|
225
|
+
const trace = await readCodaliGatewayTrace({ store, runId });
|
|
226
|
+
if (!trace) {
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
const classifierCall = trace.modelCalls.find((call) => call.role === "classifier");
|
|
230
|
+
const plannerCall = trace.modelCalls.find((call) => call.role === "planner");
|
|
231
|
+
const includeModelOutputs = options.includeModelOutputs === true;
|
|
232
|
+
return cloneRedacted({
|
|
233
|
+
schemaVersion: CODALI_GATEWAY_REPLAY_FIXTURE_SCHEMA_VERSION,
|
|
234
|
+
fixtureId: options.fixtureId ?? `gateway-replay-${randomUUID()}`,
|
|
235
|
+
runId: trace.runId,
|
|
236
|
+
exportedAt: new Date().toISOString(),
|
|
237
|
+
request: trace.run.request,
|
|
238
|
+
planner: {
|
|
239
|
+
classifierOutput: includeModelOutputs ? classifierCall?.output : undefined,
|
|
240
|
+
plannerOutput: includeModelOutputs ? plannerCall?.output : undefined,
|
|
241
|
+
},
|
|
242
|
+
contextPack: trace.contextPack,
|
|
243
|
+
evidence: trace.evidence,
|
|
244
|
+
toolFixtures: trace.toolCalls.map((call) => ({
|
|
245
|
+
id: call.id,
|
|
246
|
+
taskId: call.taskId,
|
|
247
|
+
tool: call.tool,
|
|
248
|
+
status: call.status,
|
|
249
|
+
args: call.args,
|
|
250
|
+
result: options.includeToolResults === false ? undefined : call.result,
|
|
251
|
+
errorCode: call.errorCode,
|
|
252
|
+
errorMessage: call.errorMessage,
|
|
253
|
+
latencyMs: call.latencyMs,
|
|
254
|
+
})),
|
|
255
|
+
modelFixtures: trace.modelCalls.map((call) => ({
|
|
256
|
+
id: call.id,
|
|
257
|
+
taskId: call.taskId,
|
|
258
|
+
role: call.role,
|
|
259
|
+
status: call.status,
|
|
260
|
+
agentSlug: call.agentSlug,
|
|
261
|
+
model: call.model,
|
|
262
|
+
provider: call.provider,
|
|
263
|
+
input: options.includeModelInputs === true ? call.input : undefined,
|
|
264
|
+
output: includeModelOutputs ? call.output : undefined,
|
|
265
|
+
errorCode: call.errorCode,
|
|
266
|
+
errorMessage: call.errorMessage,
|
|
267
|
+
latencyMs: call.latencyMs,
|
|
268
|
+
})),
|
|
269
|
+
finalAnswer: includeModelOutputs ? trace.finalAnswer : undefined,
|
|
270
|
+
debugSummary: trace.debugSummary,
|
|
271
|
+
events: trace.events,
|
|
272
|
+
});
|
|
273
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { CodaliRuntimeAppToolContract, CodaliRuntimeAppToolGatewayContract, CodaliRuntimeDocdexInput, CodaliRuntimeToolManifest } from "../runtime/CodaliRuntime.js";
|
|
2
|
+
import type { CodaliGatewayPolicy, CodaliGatewayToolRiskCategory } from "./CodaliGatewayTypes.js";
|
|
3
|
+
export type CodaliGatewayToolCapabilityKind = "actual" | "virtual" | "app_contract" | "app_gateway" | "builtin";
|
|
4
|
+
export type CodaliGatewayToolCapabilityStatus = "allowed" | "denied" | "skipped";
|
|
5
|
+
export interface CodaliGatewayCompilerIssue {
|
|
6
|
+
code: string;
|
|
7
|
+
message: string;
|
|
8
|
+
tool?: string;
|
|
9
|
+
severity: "warning" | "error";
|
|
10
|
+
details?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
export interface CodaliGatewaySkippedTool {
|
|
13
|
+
name: string;
|
|
14
|
+
reason: string;
|
|
15
|
+
details?: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
export interface CodaliGatewayCompiledToolCapability {
|
|
18
|
+
name: string;
|
|
19
|
+
kind: CodaliGatewayToolCapabilityKind;
|
|
20
|
+
status: CodaliGatewayToolCapabilityStatus;
|
|
21
|
+
readOnly: boolean;
|
|
22
|
+
riskCategory: CodaliGatewayToolRiskCategory;
|
|
23
|
+
approvalRequired: boolean;
|
|
24
|
+
backingTools: string[];
|
|
25
|
+
reasons: string[];
|
|
26
|
+
}
|
|
27
|
+
export interface ToolCapabilityCompilerInput {
|
|
28
|
+
policy: CodaliGatewayPolicy;
|
|
29
|
+
docdex?: CodaliRuntimeDocdexInput;
|
|
30
|
+
tools?: CodaliRuntimeToolManifest;
|
|
31
|
+
requiredDocdexOperations?: string[];
|
|
32
|
+
allowedBackingTools?: string[];
|
|
33
|
+
}
|
|
34
|
+
export interface ToolCapabilityCompilation {
|
|
35
|
+
allowedTools: string[];
|
|
36
|
+
deniedTools: string[];
|
|
37
|
+
visibleTools: string[];
|
|
38
|
+
appVirtualTools: string[];
|
|
39
|
+
appToolContracts: Record<string, CodaliRuntimeAppToolContract>;
|
|
40
|
+
appToolGateway?: CodaliRuntimeAppToolGatewayContract;
|
|
41
|
+
capabilities: CodaliGatewayCompiledToolCapability[];
|
|
42
|
+
skippedTools: CodaliGatewaySkippedTool[];
|
|
43
|
+
warnings: CodaliGatewayCompilerIssue[];
|
|
44
|
+
errors: CodaliGatewayCompilerIssue[];
|
|
45
|
+
requiredDocdexOperations: string[];
|
|
46
|
+
}
|
|
47
|
+
export declare const CODALI_GATEWAY_READ_ONLY_BACKING_TOOLS: readonly ["docdex_search", "docdex_batch_search", "docdex_open", "docdex_files", "docdex_tree", "docdex_stats"];
|
|
48
|
+
export declare const CODALI_GATEWAY_RESERVED_TOOL_ARG_KEYS: readonly ["apiKey", "api_key", "baseUrl", "base_url", "credentialSource", "credential_source", "docdex", "repo", "repoId", "repo_id", "repoRoot", "repo_root", "tenant", "tenantId", "tenant_id"];
|
|
49
|
+
export declare const compileToolCapabilities: (input: ToolCapabilityCompilerInput) => ToolCapabilityCompilation;
|
|
50
|
+
//# sourceMappingURL=ToolCapabilityCompi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