@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.
Files changed (68) hide show
  1. package/dist/cli/EvalCommand.d.ts +8 -0
  2. package/dist/cli/EvalCommand.d.ts.map +1 -1
  3. package/dist/cli/EvalCommand.js +93 -1
  4. package/dist/cli.d.ts.map +1 -1
  5. package/dist/cli.js +1 -0
  6. package/dist/docdex/DocdexClient.d.ts +8 -1
  7. package/dist/docdex/DocdexClient.d.ts.map +1 -1
  8. package/dist/docdex/DocdexClient.js +126 -33
  9. package/dist/eval/CodaliGatewayLiveHarness.d.ts +169 -0
  10. package/dist/eval/CodaliGatewayLiveHarness.d.ts.map +1 -0
  11. package/dist/eval/CodaliGatewayLiveHarness.js +824 -0
  12. package/dist/eval/GatewayEvalSuite.d.ts +202 -0
  13. package/dist/eval/GatewayEvalSuite.d.ts.map +1 -0
  14. package/dist/eval/GatewayEvalSuite.js +673 -0
  15. package/dist/gateway/AgentTierResolver.d.ts +74 -0
  16. package/dist/gateway/AgentTierResolver.d.ts.map +1 -0
  17. package/dist/gateway/AgentTierResolver.js +576 -0
  18. package/dist/gateway/AppToolGatewayDispatcher.d.ts +88 -0
  19. package/dist/gateway/AppToolGatewayDispatcher.d.ts.map +1 -0
  20. package/dist/gateway/AppToolGatewayDispatcher.js +381 -0
  21. package/dist/gateway/CodaliGateway.d.ts +73 -0
  22. package/dist/gateway/CodaliGateway.d.ts.map +1 -0
  23. package/dist/gateway/CodaliGateway.js +824 -0
  24. package/dist/gateway/CodaliGatewaySchemas.d.ts +21 -0
  25. package/dist/gateway/CodaliGatewaySchemas.d.ts.map +1 -0
  26. package/dist/gateway/CodaliGatewaySchemas.js +874 -0
  27. package/dist/gateway/CodaliGatewayStore.d.ts +157 -0
  28. package/dist/gateway/CodaliGatewayStore.d.ts.map +1 -0
  29. package/dist/gateway/CodaliGatewayStore.js +206 -0
  30. package/dist/gateway/CodaliGatewayTypes.d.ts +336 -0
  31. package/dist/gateway/CodaliGatewayTypes.d.ts.map +1 -0
  32. package/dist/gateway/CodaliGatewayTypes.js +1 -0
  33. package/dist/gateway/ContextPackBuilder.d.ts +43 -0
  34. package/dist/gateway/ContextPackBuilder.d.ts.map +1 -0
  35. package/dist/gateway/ContextPackBuilder.js +317 -0
  36. package/dist/gateway/EvidenceNormalizer.d.ts +42 -0
  37. package/dist/gateway/EvidenceNormalizer.d.ts.map +1 -0
  38. package/dist/gateway/EvidenceNormalizer.js +488 -0
  39. package/dist/gateway/GatewayPlanner.d.ts +195 -0
  40. package/dist/gateway/GatewayPlanner.d.ts.map +1 -0
  41. package/dist/gateway/GatewayPlanner.js +379 -0
  42. package/dist/gateway/GatewayPolicyCompiler.d.ts +30 -0
  43. package/dist/gateway/GatewayPolicyCompiler.d.ts.map +1 -0
  44. package/dist/gateway/GatewayPolicyCompiler.js +114 -0
  45. package/dist/gateway/GatewaySecurityPolicy.d.ts +14 -0
  46. package/dist/gateway/GatewaySecurityPolicy.d.ts.map +1 -0
  47. package/dist/gateway/GatewaySecurityPolicy.js +350 -0
  48. package/dist/gateway/GatewayStateMachine.d.ts +165 -0
  49. package/dist/gateway/GatewayStateMachine.d.ts.map +1 -0
  50. package/dist/gateway/GatewayStateMachine.js +790 -0
  51. package/dist/gateway/GatewayTraceReplay.d.ts +120 -0
  52. package/dist/gateway/GatewayTraceReplay.d.ts.map +1 -0
  53. package/dist/gateway/GatewayTraceReplay.js +273 -0
  54. package/dist/gateway/ToolCapabilityCompiler.d.ts +50 -0
  55. package/dist/gateway/ToolCapabilityCompiler.d.ts.map +1 -0
  56. package/dist/gateway/ToolCapabilityCompiler.js +442 -0
  57. package/dist/index.d.ts +30 -0
  58. package/dist/index.d.ts.map +1 -1
  59. package/dist/index.js +15 -0
  60. package/dist/runtime/CodaliRuntime.d.ts +7 -0
  61. package/dist/runtime/CodaliRuntime.d.ts.map +1 -1
  62. package/dist/runtime/CodaliRuntime.js +98 -54
  63. package/dist/tools/ToolRegistry.d.ts.map +1 -1
  64. package/dist/tools/ToolRegistry.js +4 -0
  65. package/dist/tools/ToolTypes.d.ts +1 -1
  66. package/dist/tools/ToolTypes.d.ts.map +1 -1
  67. package/dist/tools/ToolTypes.js +5 -1
  68. package/package.json +3 -3
@@ -0,0 +1,157 @@
1
+ import type { CodaliContextPack, CodaliEvidenceItem, CodaliGatewayRequest, CodaliGatewayStatus } from "./CodaliGatewayTypes.js";
2
+ export type CodaliGatewayStoreRunStatus = "pending" | "running" | CodaliGatewayStatus | "cancelled";
3
+ export type CodaliGatewayStoreTaskStatus = "pending" | "running" | "succeeded" | "failed" | "skipped";
4
+ export type CodaliGatewayStoredToolStatus = "success" | "failed" | "blocked";
5
+ export type CodaliGatewayStoredModelStatus = "success" | "failed" | "repaired";
6
+ export interface CodaliGatewayStoredRun {
7
+ runId: string;
8
+ status: CodaliGatewayStoreRunStatus;
9
+ createdAt: string;
10
+ updatedAt: string;
11
+ request?: CodaliGatewayRequest | Record<string, unknown>;
12
+ warnings: string[];
13
+ errors: string[];
14
+ metadata?: Record<string, unknown>;
15
+ }
16
+ export interface CodaliGatewayStoredTask {
17
+ id: string;
18
+ runId: string;
19
+ status: CodaliGatewayStoreTaskStatus;
20
+ workerRole?: string;
21
+ objective?: string;
22
+ createdAt: string;
23
+ updatedAt: string;
24
+ metadata?: Record<string, unknown>;
25
+ }
26
+ export interface CodaliGatewayStoredToolCall {
27
+ id: string;
28
+ runId: string;
29
+ taskId?: string;
30
+ tool: string;
31
+ status: CodaliGatewayStoredToolStatus;
32
+ startedAt: string;
33
+ endedAt?: string;
34
+ latencyMs?: number;
35
+ args?: unknown;
36
+ result?: unknown;
37
+ errorCode?: string;
38
+ errorMessage?: string;
39
+ metadata?: Record<string, unknown>;
40
+ }
41
+ export interface CodaliGatewayStoredModelCall {
42
+ id: string;
43
+ runId: string;
44
+ taskId?: string;
45
+ role: string;
46
+ status: CodaliGatewayStoredModelStatus;
47
+ startedAt: string;
48
+ endedAt?: string;
49
+ latencyMs?: number;
50
+ agentSlug?: string;
51
+ model?: string;
52
+ provider?: string;
53
+ input?: unknown;
54
+ output?: unknown;
55
+ errorCode?: string;
56
+ errorMessage?: string;
57
+ metadata?: Record<string, unknown>;
58
+ }
59
+ export interface CodaliGatewayStoredArtifact {
60
+ id: string;
61
+ runId: string;
62
+ taskId?: string;
63
+ type: string;
64
+ uri?: string;
65
+ path?: string;
66
+ model?: string;
67
+ prompt?: string;
68
+ metadata?: Record<string, unknown>;
69
+ createdAt: string;
70
+ }
71
+ export interface CodaliGatewayRunTrace {
72
+ run: CodaliGatewayStoredRun;
73
+ tasks: CodaliGatewayStoredTask[];
74
+ evidence: CodaliEvidenceItem[];
75
+ toolCalls: CodaliGatewayStoredToolCall[];
76
+ modelCalls: CodaliGatewayStoredModelCall[];
77
+ contextPack?: CodaliContextPack;
78
+ artifacts: CodaliGatewayStoredArtifact[];
79
+ }
80
+ export interface CodaliGatewayCreateRunInput {
81
+ runId?: string;
82
+ request?: CodaliGatewayRequest | Record<string, unknown>;
83
+ status?: CodaliGatewayStoreRunStatus;
84
+ metadata?: Record<string, unknown>;
85
+ }
86
+ export interface CodaliGatewayUpdateRunInput {
87
+ status?: CodaliGatewayStoreRunStatus;
88
+ warnings?: string[];
89
+ errors?: string[];
90
+ metadata?: Record<string, unknown>;
91
+ }
92
+ export interface CodaliGatewayCreateTaskInput {
93
+ id?: string;
94
+ runId: string;
95
+ status?: CodaliGatewayStoreTaskStatus;
96
+ workerRole?: string;
97
+ objective?: string;
98
+ metadata?: Record<string, unknown>;
99
+ }
100
+ export interface CodaliGatewayUpdateTaskInput {
101
+ status?: CodaliGatewayStoreTaskStatus;
102
+ workerRole?: string;
103
+ objective?: string;
104
+ metadata?: Record<string, unknown>;
105
+ }
106
+ export interface CodaliGatewayStore {
107
+ createRun(input: CodaliGatewayCreateRunInput): Promise<CodaliGatewayStoredRun>;
108
+ updateRun(runId: string, input: CodaliGatewayUpdateRunInput): Promise<CodaliGatewayStoredRun>;
109
+ createTask(input: CodaliGatewayCreateTaskInput): Promise<CodaliGatewayStoredTask>;
110
+ updateTask(runId: string, taskId: string, input: CodaliGatewayUpdateTaskInput): Promise<CodaliGatewayStoredTask>;
111
+ appendEvidence(runId: string, evidence: CodaliEvidenceItem[]): Promise<CodaliEvidenceItem[]>;
112
+ appendToolCall(call: Omit<CodaliGatewayStoredToolCall, "id" | "startedAt"> & {
113
+ id?: string;
114
+ startedAt?: string;
115
+ }): Promise<CodaliGatewayStoredToolCall>;
116
+ appendModelCall(call: Omit<CodaliGatewayStoredModelCall, "id" | "startedAt"> & {
117
+ id?: string;
118
+ startedAt?: string;
119
+ }): Promise<CodaliGatewayStoredModelCall>;
120
+ saveContextPack(runId: string, contextPack: CodaliContextPack): Promise<CodaliContextPack>;
121
+ saveArtifact(artifact: Omit<CodaliGatewayStoredArtifact, "id" | "createdAt"> & {
122
+ id?: string;
123
+ createdAt?: string;
124
+ }): Promise<CodaliGatewayStoredArtifact>;
125
+ readRunTrace(runId: string): Promise<CodaliGatewayRunTrace | undefined>;
126
+ }
127
+ export declare const redactCodaliGatewaySecrets: <T>(value: T) => T;
128
+ export declare class InMemoryCodaliGatewayStore implements CodaliGatewayStore {
129
+ private runs;
130
+ private tasks;
131
+ private evidence;
132
+ private toolCalls;
133
+ private modelCalls;
134
+ private contextPacks;
135
+ private artifacts;
136
+ createRun(input: CodaliGatewayCreateRunInput): Promise<CodaliGatewayStoredRun>;
137
+ updateRun(runId: string, input: CodaliGatewayUpdateRunInput): Promise<CodaliGatewayStoredRun>;
138
+ createTask(input: CodaliGatewayCreateTaskInput): Promise<CodaliGatewayStoredTask>;
139
+ updateTask(runId: string, taskId: string, input: CodaliGatewayUpdateTaskInput): Promise<CodaliGatewayStoredTask>;
140
+ appendEvidence(runId: string, evidence: CodaliEvidenceItem[]): Promise<CodaliEvidenceItem[]>;
141
+ appendToolCall(call: Omit<CodaliGatewayStoredToolCall, "id" | "startedAt"> & {
142
+ id?: string;
143
+ startedAt?: string;
144
+ }): Promise<CodaliGatewayStoredToolCall>;
145
+ appendModelCall(call: Omit<CodaliGatewayStoredModelCall, "id" | "startedAt"> & {
146
+ id?: string;
147
+ startedAt?: string;
148
+ }): Promise<CodaliGatewayStoredModelCall>;
149
+ saveContextPack(runId: string, contextPack: CodaliContextPack): Promise<CodaliContextPack>;
150
+ saveArtifact(artifact: Omit<CodaliGatewayStoredArtifact, "id" | "createdAt"> & {
151
+ id?: string;
152
+ createdAt?: string;
153
+ }): Promise<CodaliGatewayStoredArtifact>;
154
+ readRunTrace(runId: string): Promise<CodaliGatewayRunTrace | undefined>;
155
+ }
156
+ export declare const createInMemoryCodaliGatewayStore: () => InMemoryCodaliGatewayStore;
157
+ //# sourceMappingURL=CodaliGatewayStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CodaliGatewayStore.d.ts","sourceRoot":"","sources":["../../src/gateway/CodaliGatewayStore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,2BAA2B,GACnC,SAAS,GACT,SAAS,GACT,mBAAmB,GACnB,WAAW,CAAC;AAEhB,MAAM,MAAM,4BAA4B,GACpC,SAAS,GACT,SAAS,GACT,WAAW,GACX,QAAQ,GACR,SAAS,CAAC;AAEd,MAAM,MAAM,6BAA6B,GACrC,SAAS,GACT,QAAQ,GACR,SAAS,CAAC;AAEd,MAAM,MAAM,8BAA8B,GACtC,SAAS,GACT,QAAQ,GACR,UAAU,CAAC;AAEf,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,2BAA2B,CAAC;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC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AAM,gCAAgC,QAAO,0BAClB,CAAC"}
@@ -0,0 +1,206 @@
1
+ import { randomUUID } from "node:crypto";
2
+ const REDACTED = "[redacted]";
3
+ const SENSITIVE_KEY_PATTERNS = [
4
+ /api[-_]?key/i,
5
+ /authorization/i,
6
+ /bearer/i,
7
+ /credential/i,
8
+ /password/i,
9
+ /secret/i,
10
+ /token/i,
11
+ /^x[-_]?api[-_]?key$/i,
12
+ ];
13
+ const NON_SECRET_TOKEN_KEY_PATTERNS = [
14
+ /^input[-_]?tokens?$/i,
15
+ /^max[-_]?context[-_]?pack[-_]?tokens?$/i,
16
+ /^max[-_]?tokens?$/i,
17
+ /^output[-_]?tokens?$/i,
18
+ /^token[-_]?estimate$/i,
19
+ /^total[-_]?tokens?$/i,
20
+ ];
21
+ const SECRET_VALUE_PATTERNS = [
22
+ /Bearer\s+[A-Za-z0-9._~+/=-]{12,}/g,
23
+ /\bsk-[A-Za-z0-9]{16,}\b/g,
24
+ /\b[A-Za-z0-9_-]{24,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g,
25
+ ];
26
+ const isRecord = (value) => Boolean(value && typeof value === "object" && !Array.isArray(value));
27
+ const isSensitiveKey = (key) => !NON_SECRET_TOKEN_KEY_PATTERNS.some((pattern) => pattern.test(key)) &&
28
+ SENSITIVE_KEY_PATTERNS.some((pattern) => pattern.test(key));
29
+ const redactString = (value) => {
30
+ let redacted = value;
31
+ for (const pattern of SECRET_VALUE_PATTERNS) {
32
+ redacted = redacted.replace(pattern, REDACTED);
33
+ }
34
+ return redacted;
35
+ };
36
+ export const redactCodaliGatewaySecrets = (value) => {
37
+ if (Array.isArray(value)) {
38
+ return value.map((item) => redactCodaliGatewaySecrets(item));
39
+ }
40
+ if (typeof value === "string") {
41
+ return redactString(value);
42
+ }
43
+ if (!isRecord(value)) {
44
+ return value;
45
+ }
46
+ const output = {};
47
+ for (const [key, child] of Object.entries(value)) {
48
+ output[key] = isSensitiveKey(key) ? REDACTED : redactCodaliGatewaySecrets(child);
49
+ }
50
+ return output;
51
+ };
52
+ const clone = (value) => value === undefined ? value : JSON.parse(JSON.stringify(value));
53
+ const cloneRedacted = (value) => redactCodaliGatewaySecrets(clone(value));
54
+ const nowIso = () => new Date().toISOString();
55
+ const requireRun = (runs, runId) => {
56
+ const run = runs.get(runId);
57
+ if (!run) {
58
+ throw new Error(`GATEWAY_RUN_NOT_FOUND: ${runId}`);
59
+ }
60
+ return run;
61
+ };
62
+ const requireTask = (tasks, runId, taskId) => {
63
+ const task = tasks.find((item) => item.runId === runId && item.id === taskId);
64
+ if (!task) {
65
+ throw new Error(`GATEWAY_TASK_NOT_FOUND: ${taskId}`);
66
+ }
67
+ return task;
68
+ };
69
+ export class InMemoryCodaliGatewayStore {
70
+ constructor() {
71
+ this.runs = new Map();
72
+ this.tasks = [];
73
+ this.evidence = new Map();
74
+ this.toolCalls = [];
75
+ this.modelCalls = [];
76
+ this.contextPacks = new Map();
77
+ this.artifacts = [];
78
+ }
79
+ async createRun(input) {
80
+ const runId = input.runId ?? randomUUID();
81
+ if (this.runs.has(runId)) {
82
+ throw new Error(`GATEWAY_RUN_ALREADY_EXISTS: ${runId}`);
83
+ }
84
+ const createdAt = nowIso();
85
+ const run = {
86
+ runId,
87
+ status: input.status ?? "pending",
88
+ createdAt,
89
+ updatedAt: createdAt,
90
+ request: input.request ? cloneRedacted(input.request) : undefined,
91
+ warnings: [],
92
+ errors: [],
93
+ metadata: input.metadata ? cloneRedacted(input.metadata) : undefined,
94
+ };
95
+ this.runs.set(runId, run);
96
+ return clone(run);
97
+ }
98
+ async updateRun(runId, input) {
99
+ const run = requireRun(this.runs, runId);
100
+ const updated = {
101
+ ...run,
102
+ status: input.status ?? run.status,
103
+ warnings: input.warnings ? [...input.warnings] : run.warnings,
104
+ errors: input.errors ? [...input.errors] : run.errors,
105
+ metadata: input.metadata ? cloneRedacted(input.metadata) : run.metadata,
106
+ updatedAt: nowIso(),
107
+ };
108
+ this.runs.set(runId, updated);
109
+ return clone(updated);
110
+ }
111
+ async createTask(input) {
112
+ requireRun(this.runs, input.runId);
113
+ const id = input.id ?? randomUUID();
114
+ if (this.tasks.some((task) => task.runId === input.runId && task.id === id)) {
115
+ throw new Error(`GATEWAY_TASK_ALREADY_EXISTS: ${id}`);
116
+ }
117
+ const createdAt = nowIso();
118
+ const task = {
119
+ id,
120
+ runId: input.runId,
121
+ status: input.status ?? "pending",
122
+ workerRole: input.workerRole,
123
+ objective: input.objective,
124
+ createdAt,
125
+ updatedAt: createdAt,
126
+ metadata: input.metadata ? cloneRedacted(input.metadata) : undefined,
127
+ };
128
+ this.tasks.push(task);
129
+ return clone(task);
130
+ }
131
+ async updateTask(runId, taskId, input) {
132
+ requireRun(this.runs, runId);
133
+ const task = requireTask(this.tasks, runId, taskId);
134
+ const updated = {
135
+ ...task,
136
+ status: input.status ?? task.status,
137
+ workerRole: input.workerRole ?? task.workerRole,
138
+ objective: input.objective ?? task.objective,
139
+ metadata: input.metadata ? cloneRedacted(input.metadata) : task.metadata,
140
+ updatedAt: nowIso(),
141
+ };
142
+ const index = this.tasks.indexOf(task);
143
+ this.tasks[index] = updated;
144
+ return clone(updated);
145
+ }
146
+ async appendEvidence(runId, evidence) {
147
+ requireRun(this.runs, runId);
148
+ const existing = this.evidence.get(runId) ?? [];
149
+ const redacted = cloneRedacted(evidence);
150
+ existing.push(...redacted);
151
+ this.evidence.set(runId, existing);
152
+ return clone(redacted);
153
+ }
154
+ async appendToolCall(call) {
155
+ requireRun(this.runs, call.runId);
156
+ const record = cloneRedacted({
157
+ ...call,
158
+ id: call.id ?? randomUUID(),
159
+ startedAt: call.startedAt ?? nowIso(),
160
+ });
161
+ this.toolCalls.push(record);
162
+ return clone(record);
163
+ }
164
+ async appendModelCall(call) {
165
+ requireRun(this.runs, call.runId);
166
+ const record = cloneRedacted({
167
+ ...call,
168
+ id: call.id ?? randomUUID(),
169
+ startedAt: call.startedAt ?? nowIso(),
170
+ });
171
+ this.modelCalls.push(record);
172
+ return clone(record);
173
+ }
174
+ async saveContextPack(runId, contextPack) {
175
+ requireRun(this.runs, runId);
176
+ const redacted = cloneRedacted(contextPack);
177
+ this.contextPacks.set(runId, redacted);
178
+ return clone(redacted);
179
+ }
180
+ async saveArtifact(artifact) {
181
+ requireRun(this.runs, artifact.runId);
182
+ const record = cloneRedacted({
183
+ ...artifact,
184
+ id: artifact.id ?? randomUUID(),
185
+ createdAt: artifact.createdAt ?? nowIso(),
186
+ });
187
+ this.artifacts.push(record);
188
+ return clone(record);
189
+ }
190
+ async readRunTrace(runId) {
191
+ const run = this.runs.get(runId);
192
+ if (!run) {
193
+ return undefined;
194
+ }
195
+ return clone({
196
+ run,
197
+ tasks: this.tasks.filter((task) => task.runId === runId),
198
+ evidence: this.evidence.get(runId) ?? [],
199
+ toolCalls: this.toolCalls.filter((call) => call.runId === runId),
200
+ modelCalls: this.modelCalls.filter((call) => call.runId === runId),
201
+ contextPack: this.contextPacks.get(runId),
202
+ artifacts: this.artifacts.filter((artifact) => artifact.runId === runId),
203
+ });
204
+ }
205
+ }
206
+ export const createInMemoryCodaliGatewayStore = () => new InMemoryCodaliGatewayStore();