@mcoda/codali 0.1.108 → 0.1.110
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/agents/AgentInventory.d.ts +56 -0
- package/dist/agents/AgentInventory.d.ts.map +1 -0
- package/dist/agents/AgentInventory.js +131 -0
- package/dist/agents/RoleResolution.d.ts +49 -0
- package/dist/agents/RoleResolution.d.ts.map +1 -0
- package/dist/agents/RoleResolution.js +166 -0
- package/dist/api/ChatCompletionsAdapter.d.ts +76 -0
- package/dist/api/ChatCompletionsAdapter.d.ts.map +1 -0
- package/dist/api/ChatCompletionsAdapter.js +54 -0
- package/dist/api/CodaliApi.d.ts +78 -0
- package/dist/api/CodaliApi.d.ts.map +1 -0
- package/dist/api/CodaliApi.js +273 -0
- package/dist/api/CodaliServer.d.ts +42 -0
- package/dist/api/CodaliServer.d.ts.map +1 -0
- package/dist/api/CodaliServer.js +118 -0
- package/dist/cli/AskCommand.d.ts +66 -0
- package/dist/cli/AskCommand.d.ts.map +1 -0
- package/dist/cli/AskCommand.js +536 -0
- package/dist/cli/AuthCommand.d.ts +19 -0
- package/dist/cli/AuthCommand.d.ts.map +1 -0
- package/dist/cli/AuthCommand.js +161 -0
- package/dist/cli/ServeCommand.d.ts +5 -0
- package/dist/cli/ServeCommand.d.ts.map +1 -0
- package/dist/cli/ServeCommand.js +87 -0
- package/dist/cli/ToolsCommand.d.ts +22 -0
- package/dist/cli/ToolsCommand.d.ts.map +1 -0
- package/dist/cli/ToolsCommand.js +208 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +29 -1
- package/dist/connectors/http/HttpToolDefinition.d.ts +74 -0
- package/dist/connectors/http/HttpToolDefinition.d.ts.map +1 -0
- package/dist/connectors/http/HttpToolDefinition.js +190 -0
- package/dist/connectors/http/HttpToolSource.d.ts +18 -0
- package/dist/connectors/http/HttpToolSource.d.ts.map +1 -0
- package/dist/connectors/http/HttpToolSource.js +29 -0
- package/dist/connectors/mcp/McpClient.d.ts +132 -0
- package/dist/connectors/mcp/McpClient.d.ts.map +1 -0
- package/dist/connectors/mcp/McpClient.js +215 -0
- package/dist/connectors/mcp/McpServerRegistry.d.ts +75 -0
- package/dist/connectors/mcp/McpServerRegistry.d.ts.map +1 -0
- package/dist/connectors/mcp/McpServerRegistry.js +180 -0
- package/dist/connectors/mcp/McpToolAdapter.d.ts +48 -0
- package/dist/connectors/mcp/McpToolAdapter.d.ts.map +1 -0
- package/dist/connectors/mcp/McpToolAdapter.js +101 -0
- package/dist/connectors/mcp/McpToolSource.d.ts +27 -0
- package/dist/connectors/mcp/McpToolSource.d.ts.map +1 -0
- package/dist/connectors/mcp/McpToolSource.js +33 -0
- package/dist/connectors/media/ImageGenerationTool.d.ts +43 -0
- package/dist/connectors/media/ImageGenerationTool.d.ts.map +1 -0
- package/dist/connectors/media/ImageGenerationTool.js +122 -0
- package/dist/connectors/oauth/DeviceCodeAuth.d.ts +74 -0
- package/dist/connectors/oauth/DeviceCodeAuth.d.ts.map +1 -0
- package/dist/connectors/oauth/DeviceCodeAuth.js +153 -0
- package/dist/docdex/DocdexClient.d.ts +2 -0
- package/dist/docdex/DocdexClient.d.ts.map +1 -1
- package/dist/docdex/DocdexClient.js +4 -0
- package/dist/gateway/CodaliGateway.d.ts +51 -3
- package/dist/gateway/CodaliGateway.d.ts.map +1 -1
- package/dist/gateway/CodaliGateway.js +241 -3
- package/dist/gateway/CodaliGatewayTypes.d.ts +34 -0
- package/dist/gateway/CodaliGatewayTypes.d.ts.map +1 -1
- package/dist/gateway/EvidenceNormalizer.d.ts.map +1 -1
- package/dist/gateway/EvidenceNormalizer.js +98 -1
- package/dist/gateway/Finalizer.d.ts +50 -0
- package/dist/gateway/Finalizer.d.ts.map +1 -0
- package/dist/gateway/Finalizer.js +79 -0
- package/dist/gateway/GatewayPlanner.d.ts +13 -0
- package/dist/gateway/GatewayPlanner.d.ts.map +1 -1
- package/dist/gateway/GatewayPlanner.js +81 -16
- package/dist/gateway/GatewayStateMachine.d.ts.map +1 -1
- package/dist/gateway/GatewayStateMachine.js +6 -0
- package/dist/gateway/GatewayTracer.d.ts +93 -0
- package/dist/gateway/GatewayTracer.d.ts.map +1 -0
- package/dist/gateway/GatewayTracer.js +214 -0
- package/dist/gateway/LocalGatewayProvider.d.ts +59 -0
- package/dist/gateway/LocalGatewayProvider.d.ts.map +1 -0
- package/dist/gateway/LocalGatewayProvider.js +195 -0
- package/dist/gateway/LocalGatewayTaskRunner.d.ts +79 -0
- package/dist/gateway/LocalGatewayTaskRunner.d.ts.map +1 -0
- package/dist/gateway/LocalGatewayTaskRunner.js +361 -0
- package/dist/gateway/RelevanceJudge.d.ts +25 -0
- package/dist/gateway/RelevanceJudge.d.ts.map +1 -0
- package/dist/gateway/RelevanceJudge.js +124 -0
- package/dist/gateway/ResponseSchema.d.ts +32 -0
- package/dist/gateway/ResponseSchema.d.ts.map +1 -0
- package/dist/gateway/ResponseSchema.js +120 -0
- package/dist/gateway/TemporalContext.d.ts +36 -0
- package/dist/gateway/TemporalContext.d.ts.map +1 -0
- package/dist/gateway/TemporalContext.js +115 -0
- package/dist/gateway/ToolCapabilityCompiler.d.ts +5 -0
- package/dist/gateway/ToolCapabilityCompiler.d.ts.map +1 -1
- package/dist/gateway/ToolCapabilityCompiler.js +27 -2
- package/dist/gateway/ToolDescriptorSource.d.ts +6 -0
- package/dist/gateway/ToolDescriptorSource.d.ts.map +1 -0
- package/dist/gateway/ToolDescriptorSource.js +30 -0
- package/dist/gateway/ToolExposure.d.ts +36 -0
- package/dist/gateway/ToolExposure.d.ts.map +1 -0
- package/dist/gateway/ToolExposure.js +154 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +45 -0
- package/dist/providers/ClaudeCliProvider.d.ts +2 -0
- package/dist/providers/ClaudeCliProvider.d.ts.map +1 -1
- package/dist/providers/ClaudeCliProvider.js +2 -0
- package/dist/providers/CodexCliProvider.d.ts +2 -0
- package/dist/providers/CodexCliProvider.d.ts.map +1 -1
- package/dist/providers/CodexCliProvider.js +2 -0
- package/dist/providers/MswarmWorkerProvider.d.ts +2 -0
- package/dist/providers/MswarmWorkerProvider.d.ts.map +1 -1
- package/dist/providers/MswarmWorkerProvider.js +2 -0
- package/dist/providers/OllamaRemoteProvider.d.ts +2 -0
- package/dist/providers/OllamaRemoteProvider.d.ts.map +1 -1
- package/dist/providers/OllamaRemoteProvider.js +2 -0
- package/dist/providers/OpenAiCompatibleProvider.d.ts +2 -0
- package/dist/providers/OpenAiCompatibleProvider.d.ts.map +1 -1
- package/dist/providers/OpenAiCompatibleProvider.js +2 -0
- package/dist/providers/ProviderTypes.d.ts +13 -0
- package/dist/providers/ProviderTypes.d.ts.map +1 -1
- package/dist/providers/ProviderTypes.js +1 -1
- package/dist/runcontext/CredentialFile.d.ts +12 -0
- package/dist/runcontext/CredentialFile.d.ts.map +1 -0
- package/dist/runcontext/CredentialFile.js +81 -0
- package/dist/runcontext/RunContextResolver.d.ts +126 -0
- package/dist/runcontext/RunContextResolver.d.ts.map +1 -0
- package/dist/runcontext/RunContextResolver.js +389 -0
- package/dist/storage/CodaliDatasetPrivacyEngine.d.ts +1 -1
- package/dist/storage/CodaliDatasetPrivacyEngine.d.ts.map +1 -1
- package/dist/storage/CodaliDatasetPrivacyEngine.js +12 -0
- package/dist/tools/ToolRegistry.d.ts +14 -1
- package/dist/tools/ToolRegistry.d.ts.map +1 -1
- package/dist/tools/ToolRegistry.js +38 -1
- package/dist/tools/ToolTypes.d.ts +35 -0
- package/dist/tools/ToolTypes.d.ts.map +1 -1
- package/dist/tools/ToolTypes.js +21 -0
- package/dist/tools/TruncateResult.d.ts +29 -0
- package/dist/tools/TruncateResult.d.ts.map +1 -0
- package/dist/tools/TruncateResult.js +91 -0
- package/dist/tools/diff/DiffTool.d.ts.map +1 -1
- package/dist/tools/diff/DiffTool.js +2 -0
- package/dist/tools/docdex/DocdexTools.d.ts +21 -1
- package/dist/tools/docdex/DocdexTools.d.ts.map +1 -1
- package/dist/tools/docdex/DocdexTools.js +151 -17
- package/dist/tools/filesystem/FileTools.d.ts.map +1 -1
- package/dist/tools/filesystem/FileTools.js +8 -0
- package/dist/tools/search/SearchTool.d.ts.map +1 -1
- package/dist/tools/search/SearchTool.js +3 -1
- package/dist/tools/shell/ShellTool.d.ts.map +1 -1
- package/dist/tools/shell/ShellTool.js +2 -0
- package/package.json +4 -3
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { CodaliContextPack, CodaliGatewayRequest } from "./CodaliGatewayTypes.js";
|
|
2
|
+
import type { CodaliGatewayStoredArtifact } from "./CodaliGatewayStore.js";
|
|
3
|
+
import type { CodaliArtifactRef } from "./CodaliGatewayTypes.js";
|
|
4
|
+
/**
|
|
5
|
+
* The finishing step every run passes through.
|
|
6
|
+
*
|
|
7
|
+
* Skipping the large synthesizer for a simple factual lookup is sensible;
|
|
8
|
+
* skipping *normalization* is not. Without one consistent finisher each tool
|
|
9
|
+
* shapes its own output, citations quietly disappear, units go unlabelled, and
|
|
10
|
+
* raw tool error strings leak to end users. So there is no path from a tool
|
|
11
|
+
* result to a caller that does not come through here.
|
|
12
|
+
*
|
|
13
|
+
* Three modes:
|
|
14
|
+
*
|
|
15
|
+
* - `deterministic` — one clean, well-attributed result. Formatted in code,
|
|
16
|
+
* no model call. This is what makes a simple lookup cheap.
|
|
17
|
+
* - `synthesizer` — multiple, conflicting, or unstructured sources. Needs
|
|
18
|
+
* the large model to reconcile them.
|
|
19
|
+
* - `artifact` — media. The artifact is the answer; prose only frames it.
|
|
20
|
+
*/
|
|
21
|
+
export type FinalizerMode = "deterministic" | "synthesizer" | "artifact";
|
|
22
|
+
export interface FinalizerDecision {
|
|
23
|
+
mode: FinalizerMode;
|
|
24
|
+
reason: string;
|
|
25
|
+
}
|
|
26
|
+
export interface FinalizerDecisionInput {
|
|
27
|
+
request: CodaliGatewayRequest;
|
|
28
|
+
contextPack: CodaliContextPack;
|
|
29
|
+
artifacts: readonly CodaliArtifactRef[];
|
|
30
|
+
/**
|
|
31
|
+
* Set when the router judged this a direct lookup — a question whose answer
|
|
32
|
+
* *is* the retrieved fact, rather than something that must be reasoned from
|
|
33
|
+
* it. Required for the deterministic path.
|
|
34
|
+
*/
|
|
35
|
+
directLookup?: boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare const decideFinalizerMode: (input: FinalizerDecisionInput) => FinalizerDecision;
|
|
38
|
+
/**
|
|
39
|
+
* Formats a single fact without a model call. Deliberately conservative: it
|
|
40
|
+
* restates the claim and attributes it. It never paraphrases, because
|
|
41
|
+
* paraphrasing without a model is how meaning gets lost.
|
|
42
|
+
*/
|
|
43
|
+
export declare const formatDeterministicAnswer: (contextPack: CodaliContextPack) => string;
|
|
44
|
+
/**
|
|
45
|
+
* Frames artifacts as the answer. The artifact reference carries the payload;
|
|
46
|
+
* this is only the surrounding text.
|
|
47
|
+
*/
|
|
48
|
+
export declare const formatArtifactAnswer: (artifacts: readonly CodaliArtifactRef[], existingAnswer?: string) => string;
|
|
49
|
+
export declare const artifactRefsFromStored: (artifacts: readonly CodaliGatewayStoredArtifact[]) => CodaliArtifactRef[];
|
|
50
|
+
//# sourceMappingURL=Finalizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Finalizer.d.ts","sourceRoot":"","sources":["../../src/gateway/Finalizer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACvF,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,MAAM,aAAa,GAAG,eAAe,GAAG,aAAa,GAAG,UAAU,CAAC;AAEzE,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,oBAAoB,CAAC;IAC9B,WAAW,EAAE,iBAAiB,CAAC;IAC/B,SAAS,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACxC;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAQD,eAAO,MAAM,mBAAmB,GAC9B,OAAO,sBAAsB,KAC5B,iBAqCF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GAAI,aAAa,iBAAiB,KAAG,MAM1E,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAC/B,WAAW,SAAS,iBAAiB,EAAE,EACvC,iBAAiB,MAAM,KACtB,MAUF,CAAC;AAEF,eAAO,MAAM,sBAAsB,GACjC,WAAW,SAAS,2BAA2B,EAAE,KAChD,iBAAiB,EAaf,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single high-confidence fact from one source, with nothing contradicting it
|
|
3
|
+
* and nothing known to be missing, does not need a large model to restate it.
|
|
4
|
+
*/
|
|
5
|
+
const DETERMINISTIC_MIN_CONFIDENCE = 0.85;
|
|
6
|
+
export const decideFinalizerMode = (input) => {
|
|
7
|
+
if (input.artifacts.length > 0) {
|
|
8
|
+
return { mode: "artifact", reason: "run produced artifacts" };
|
|
9
|
+
}
|
|
10
|
+
// An explicit response schema means the caller wants structured output that
|
|
11
|
+
// a deterministic formatter cannot invent. Always synthesize.
|
|
12
|
+
if (input.request.response?.schema) {
|
|
13
|
+
return { mode: "synthesizer", reason: "caller supplied a response schema" };
|
|
14
|
+
}
|
|
15
|
+
// The deterministic formatter restates a retrieved claim; it cannot reason.
|
|
16
|
+
// "One high-confidence fact exists" is not sufficient grounds to use it —
|
|
17
|
+
// the question "why is X failing?" may rest on a single solid fact and still
|
|
18
|
+
// need real synthesis. So the router must have judged this a direct lookup.
|
|
19
|
+
if (!input.directLookup) {
|
|
20
|
+
return { mode: "synthesizer", reason: "not a direct lookup" };
|
|
21
|
+
}
|
|
22
|
+
const facts = input.contextPack.decisionFacts;
|
|
23
|
+
if (facts.length !== 1) {
|
|
24
|
+
return {
|
|
25
|
+
mode: "synthesizer",
|
|
26
|
+
reason: facts.length === 0 ? "no decision facts" : "multiple decision facts",
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (input.contextPack.contradictions.length > 0) {
|
|
30
|
+
return { mode: "synthesizer", reason: "contradictory evidence" };
|
|
31
|
+
}
|
|
32
|
+
if (input.contextPack.missingInformation.length > 0) {
|
|
33
|
+
return { mode: "synthesizer", reason: "known missing information" };
|
|
34
|
+
}
|
|
35
|
+
if ((facts[0]?.confidence ?? 0) < DETERMINISTIC_MIN_CONFIDENCE) {
|
|
36
|
+
return { mode: "synthesizer", reason: "single fact below confidence threshold" };
|
|
37
|
+
}
|
|
38
|
+
return { mode: "deterministic", reason: "single high-confidence fact" };
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Formats a single fact without a model call. Deliberately conservative: it
|
|
42
|
+
* restates the claim and attributes it. It never paraphrases, because
|
|
43
|
+
* paraphrasing without a model is how meaning gets lost.
|
|
44
|
+
*/
|
|
45
|
+
export const formatDeterministicAnswer = (contextPack) => {
|
|
46
|
+
const fact = contextPack.decisionFacts[0];
|
|
47
|
+
if (!fact)
|
|
48
|
+
return "";
|
|
49
|
+
const attribution = fact.sourceTitle ?? fact.sourceUri ?? fact.sourceId;
|
|
50
|
+
const claim = fact.summary?.trim() || fact.claim.trim();
|
|
51
|
+
return attribution ? `${claim}\n\nSource: ${attribution} [${fact.id}]` : claim;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Frames artifacts as the answer. The artifact reference carries the payload;
|
|
55
|
+
* this is only the surrounding text.
|
|
56
|
+
*/
|
|
57
|
+
export const formatArtifactAnswer = (artifacts, existingAnswer) => {
|
|
58
|
+
const framed = existingAnswer?.trim();
|
|
59
|
+
const lines = artifacts.map((artifact) => {
|
|
60
|
+
const location = artifact.path ?? artifact.uri ?? artifact.id;
|
|
61
|
+
return `- ${artifact.type}: ${location}`;
|
|
62
|
+
});
|
|
63
|
+
const header = artifacts.length === 1 ? "Generated artifact:" : "Generated artifacts:";
|
|
64
|
+
return [framed, framed ? "" : undefined, header, ...lines]
|
|
65
|
+
.filter((line) => line !== undefined)
|
|
66
|
+
.join("\n");
|
|
67
|
+
};
|
|
68
|
+
export const artifactRefsFromStored = (artifacts) => artifacts.map((artifact) => ({
|
|
69
|
+
id: artifact.id,
|
|
70
|
+
type: artifact.type,
|
|
71
|
+
uri: artifact.uri,
|
|
72
|
+
path: artifact.path,
|
|
73
|
+
model: artifact.model,
|
|
74
|
+
taskId: artifact.taskId,
|
|
75
|
+
mimeType: typeof artifact.metadata?.mimeType === "string"
|
|
76
|
+
? artifact.metadata.mimeType
|
|
77
|
+
: undefined,
|
|
78
|
+
metadata: artifact.metadata,
|
|
79
|
+
}));
|
|
@@ -5,6 +5,10 @@ export interface CodaliGatewayPlannerToolDescriptor {
|
|
|
5
5
|
name: string;
|
|
6
6
|
description?: string;
|
|
7
7
|
inputSchema?: Record<string, unknown>;
|
|
8
|
+
outputSchema?: Record<string, unknown>;
|
|
9
|
+
/** Capability group used for two-level tool exposure. See ToolExposure.ts. */
|
|
10
|
+
capability?: string;
|
|
11
|
+
readOnly?: boolean;
|
|
8
12
|
}
|
|
9
13
|
export interface GatewayPlannerInput {
|
|
10
14
|
request: CodaliGatewayRequest;
|
|
@@ -58,6 +62,15 @@ export declare const CODALI_GATEWAY_CLASSIFIER_SCHEMA: {
|
|
|
58
62
|
readonly directAnswerCandidate: {
|
|
59
63
|
readonly type: "string";
|
|
60
64
|
};
|
|
65
|
+
readonly capabilities: {
|
|
66
|
+
readonly type: "array";
|
|
67
|
+
readonly items: {
|
|
68
|
+
readonly type: "string";
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
readonly needsClarification: {
|
|
72
|
+
readonly type: "string";
|
|
73
|
+
};
|
|
61
74
|
readonly rationale: {
|
|
62
75
|
readonly type: "string";
|
|
63
76
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GatewayPlanner.d.ts","sourceRoot":"","sources":["../../src/gateway/GatewayPlanner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,eAAe,EAEhB,MAAM,+BAA+B,CAAC;AAIvC,OAAO,KAAK,EACV,6BAA6B,EAC7B,0BAA0B,EAC1B,oBAAoB,EAEpB,4BAA4B,EAE7B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"GatewayPlanner.d.ts","sourceRoot":"","sources":["../../src/gateway/GatewayPlanner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,eAAe,EAEhB,MAAM,+BAA+B,CAAC;AAIvC,OAAO,KAAK,EACV,6BAA6B,EAC7B,0BAA0B,EAC1B,oBAAoB,EAEpB,4BAA4B,EAE7B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,4BAA4B,CAAC;AAKpC,MAAM,WAAW,kCAAkC;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,8EAA8E;IAC9E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,oBAAoB,CAAC;IAC9B,iBAAiB,CAAC,EAAE,wBAAwB,CAAC;IAC7C,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,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AAC,QAAQ,CAAC,OAAO;IAJ1B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;gBAGxB,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE,2BAAgC;IAKtD,QAAQ,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC;QAClD,UAAU,EAAE,6BAA6B,CAAC;QAC1C,cAAc,EAAE,MAAM,CAAC;QACvB,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,EAAE,CAAC;KACpB,CAAC;IAiBI,IAAI,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,2BAA2B,CAAC;YAuE9D,iBAAiB;CAgDhC;AAED,eAAO,MAAM,0BAA0B,GACrC,UAAU,QAAQ,EAClB,UAAU,2BAA2B,KACpC,oBAAmE,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { validateCodaliGatewayPlannerOutput, } from "./CodaliGatewaySchemas.js";
|
|
2
2
|
import { compileCodaliGatewayPolicy, } from "./GatewayPolicyCompiler.js";
|
|
3
3
|
import { CODALI_GATEWAY_SECURITY_PROMPT_HARDENING } from "./GatewaySecurityPolicy.js";
|
|
4
|
+
import { renderCapabilityLines, renderToolLines } from "./ToolExposure.js";
|
|
5
|
+
import { buildTemporalContext, renderTemporalContext } from "./TemporalContext.js";
|
|
4
6
|
export class CodaliGatewayPlannerError extends Error {
|
|
5
7
|
constructor(code, message, issues) {
|
|
6
8
|
super(`${code}: ${message}`);
|
|
@@ -28,6 +30,8 @@ export const CODALI_GATEWAY_CLASSIFIER_SCHEMA = {
|
|
|
28
30
|
needsAppTools: { type: "boolean" },
|
|
29
31
|
needsImageWorker: { type: "boolean" },
|
|
30
32
|
directAnswerCandidate: { type: "string" },
|
|
33
|
+
capabilities: { type: "array", items: { type: "string" } },
|
|
34
|
+
needsClarification: { type: "string" },
|
|
31
35
|
rationale: { type: "string" },
|
|
32
36
|
confidence: { enum: ["high", "medium", "low"] },
|
|
33
37
|
metadata: { type: "object" },
|
|
@@ -360,23 +364,56 @@ const validateClassifierOutput = (value, input, policyCompilation) => {
|
|
|
360
364
|
needsImageWorker: booleans.needsImageWorker ?? false,
|
|
361
365
|
directAnswerCandidate: readString(record, "directAnswerCandidate") ??
|
|
362
366
|
readString(record, "direct_answer_candidate"),
|
|
367
|
+
capabilities: readCapabilities(record),
|
|
368
|
+
needsClarification: (() => {
|
|
369
|
+
const asked = readString(record, "needsClarification") ??
|
|
370
|
+
readString(record, "needs_clarification");
|
|
371
|
+
const originalQuery = input?.request.query ?? "";
|
|
372
|
+
return asked && isRealClarification(asked, originalQuery) ? asked : undefined;
|
|
373
|
+
})(),
|
|
363
374
|
rationale: readString(record, "rationale"),
|
|
364
375
|
confidence,
|
|
365
376
|
metadata: isRecord(record.metadata) ? record.metadata : undefined,
|
|
366
377
|
},
|
|
367
378
|
};
|
|
368
379
|
};
|
|
369
|
-
const describeTool = (name, descriptors) => {
|
|
370
|
-
const descriptor = descriptors?.[name];
|
|
371
|
-
if (!descriptor) {
|
|
372
|
-
return `${name}: read-only allowed tool`;
|
|
373
|
-
}
|
|
374
|
-
if (typeof descriptor === "string") {
|
|
375
|
-
return `${name}: ${descriptor}`;
|
|
376
|
-
}
|
|
377
|
-
return `${name}: ${descriptor.description ?? "read-only allowed tool"}`;
|
|
378
|
-
};
|
|
379
380
|
const allowedToolNames = (compilation) => [...compilation.effectiveAllowedTools].sort();
|
|
381
|
+
/**
|
|
382
|
+
* Capability names the classifier selected for stage-2 tool expansion. Absent
|
|
383
|
+
* or unparseable means "no narrowing", which expands everything - a wrong
|
|
384
|
+
* selection must degrade to a bigger prompt, never to a blind planner.
|
|
385
|
+
*/
|
|
386
|
+
/**
|
|
387
|
+
* A clarifying question must add something. A small model asked "set
|
|
388
|
+
* needsClarification if the request is ambiguous" will sometimes echo the
|
|
389
|
+
* question back, which stops the run and tells the user nothing — worse than
|
|
390
|
+
* attempting an answer. Restatements are therefore discarded.
|
|
391
|
+
*/
|
|
392
|
+
const normalizeForCompare = (value) => value.toLowerCase().replace(/[^a-z0-9 ]+/g, " ").replace(/\s+/g, " ").trim();
|
|
393
|
+
const isRealClarification = (question, query) => {
|
|
394
|
+
const asked = normalizeForCompare(question);
|
|
395
|
+
const original = normalizeForCompare(query);
|
|
396
|
+
if (!asked)
|
|
397
|
+
return false;
|
|
398
|
+
if (asked === original)
|
|
399
|
+
return false;
|
|
400
|
+
// A near-restatement: nothing in it that was not already in the question.
|
|
401
|
+
if (original.includes(asked) || asked.includes(original))
|
|
402
|
+
return false;
|
|
403
|
+
const originalWords = new Set(original.split(" "));
|
|
404
|
+
const novel = asked.split(" ").filter((word) => word.length > 2 && !originalWords.has(word));
|
|
405
|
+
return novel.length > 0;
|
|
406
|
+
};
|
|
407
|
+
const readCapabilities = (record) => {
|
|
408
|
+
const raw = record.capabilities ?? record.capability_groups ?? record.capabilityGroups;
|
|
409
|
+
if (!Array.isArray(raw))
|
|
410
|
+
return undefined;
|
|
411
|
+
const values = raw
|
|
412
|
+
.filter((entry) => typeof entry === "string")
|
|
413
|
+
.map((entry) => entry.trim())
|
|
414
|
+
.filter((entry) => entry.length > 0);
|
|
415
|
+
return values.length > 0 ? values : undefined;
|
|
416
|
+
};
|
|
380
417
|
export const buildCodaliGatewayClassifierMessages = (input) => {
|
|
381
418
|
const policy = input.policyCompilation ?? compileCodaliGatewayPolicy({ request: input.request });
|
|
382
419
|
const tools = allowedToolNames(policy);
|
|
@@ -394,8 +431,12 @@ export const buildCodaliGatewayClassifierMessages = (input) => {
|
|
|
394
431
|
`Product: ${input.request.product?.name ?? "generic"}`,
|
|
395
432
|
`Tenant scoped: ${input.request.tenant?.id || input.request.tenant?.slug ? "yes" : "unknown"}`,
|
|
396
433
|
`Image worker allowed: ${input.request.policy.allowImageWorker === true ? "yes" : "no"}`,
|
|
397
|
-
|
|
434
|
+
...renderTemporalContext(buildTemporalContext(input.request.query)),
|
|
435
|
+
"Available capabilities:",
|
|
436
|
+
renderCapabilityLines(tools, input.toolDescriptions),
|
|
398
437
|
"Decide these booleans: needsPrivateData, needsFreshData, needsDocdex, needsAppTools, needsImageWorker.",
|
|
438
|
+
"If the request is genuinely ambiguous — an unidentifiable person, project, or scope — set needsClarification to the single question that would resolve it. Never guess an identity.",
|
|
439
|
+
"List in `capabilities` only the capability names above that this query actually needs; the planner will then see the full tool schemas for just those.",
|
|
399
440
|
"If a direct answer is possible without private/runtime tools, include directAnswerCandidate.",
|
|
400
441
|
].join("\n");
|
|
401
442
|
return [
|
|
@@ -406,9 +447,10 @@ export const buildCodaliGatewayClassifierMessages = (input) => {
|
|
|
406
447
|
export const buildCodaliGatewayPlannerMessages = (input, classifier) => {
|
|
407
448
|
const policy = input.policyCompilation ?? compileCodaliGatewayPolicy({ request: input.request });
|
|
408
449
|
const tools = allowedToolNames(policy);
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
450
|
+
// Stage 2 of two-level exposure: expand full schemas, but only for the
|
|
451
|
+
// capabilities the classifier selected.
|
|
452
|
+
const exposure = renderToolLines(tools, input.toolDescriptions, classifier.capabilities);
|
|
453
|
+
const toolLines = exposure.text;
|
|
412
454
|
const workerRoles = [
|
|
413
455
|
"direct_answer",
|
|
414
456
|
"rag_worker",
|
|
@@ -431,11 +473,15 @@ export const buildCodaliGatewayPlannerMessages = (input, classifier) => {
|
|
|
431
473
|
`Query: ${input.request.query}`,
|
|
432
474
|
`Classifier: ${JSON.stringify(classifier)}`,
|
|
433
475
|
`Policy limits: maxIterations=${input.request.policy.maxIterations}, maxToolCalls=${policy.security.limits.maxToolCalls}, maxModelCalls=${policy.security.limits.maxModelCalls}, maxEvidenceItems=${policy.security.limits.maxEvidenceItems}, maxImageArtifacts=${policy.security.limits.maxImageArtifacts}`,
|
|
476
|
+
...renderTemporalContext(buildTemporalContext(input.request.query)),
|
|
434
477
|
`Worker roles available: ${workerRoles}`,
|
|
435
|
-
"Allowed tools:",
|
|
478
|
+
"Allowed tools (name, purpose, and argument shape). Use these names exactly:",
|
|
436
479
|
toolLines,
|
|
480
|
+
exposure.truncated
|
|
481
|
+
? `(Tool list truncated to ${exposure.expandedTools.length}; narrow the capabilities if the needed tool is absent.)`
|
|
482
|
+
: "",
|
|
437
483
|
"Output planner JSON with queryType, subquestions, workerTasks, expectedEvidenceCount, maxIterations, requiresFinalLargeModel, and metadata.",
|
|
438
|
-
].join("\n");
|
|
484
|
+
].filter(Boolean).join("\n");
|
|
439
485
|
return [
|
|
440
486
|
{ role: "system", content: system },
|
|
441
487
|
{ role: "user", content: user },
|
|
@@ -742,6 +788,25 @@ export class CodaliGatewayPlanner {
|
|
|
742
788
|
throw new CodaliGatewayPlannerError("GATEWAY_POLICY_COMPILE_FAILED", "Cannot plan with invalid gateway policy.");
|
|
743
789
|
}
|
|
744
790
|
const classifierResult = await this.classify({ ...input, policyCompilation });
|
|
791
|
+
// A request the classifier could not disambiguate has nothing to plan.
|
|
792
|
+
// Skipping the planner stage saves a model call and, more importantly,
|
|
793
|
+
// avoids producing a plan built on a guessed identity.
|
|
794
|
+
if (classifierResult.classifier.needsClarification?.trim()) {
|
|
795
|
+
return {
|
|
796
|
+
policyCompilation,
|
|
797
|
+
classifier: classifierResult.classifier,
|
|
798
|
+
planner: {
|
|
799
|
+
queryType: classifierResult.classifier.queryType,
|
|
800
|
+
subquestions: [],
|
|
801
|
+
workerTasks: [],
|
|
802
|
+
},
|
|
803
|
+
warnings: [...classifierResult.warnings, "planner_skipped:needs_clarification"],
|
|
804
|
+
classifierRepairAttempts: classifierResult.repairAttempts,
|
|
805
|
+
plannerRepairAttempts: 0,
|
|
806
|
+
classifierRawContent: classifierResult.rawContent,
|
|
807
|
+
plannerRawContent: "",
|
|
808
|
+
};
|
|
809
|
+
}
|
|
745
810
|
const plannerMessages = buildCodaliGatewayPlannerMessages({ ...input, policyCompilation }, classifierResult.classifier);
|
|
746
811
|
const plannerResult = await this.generateValidated("planner", plannerMessages, PLANNER_RESPONSE_FORMAT, (value) => {
|
|
747
812
|
const validation = validateCodaliGatewayPlannerOutput(normalizePlannerOutput(value, { ...input, policyCompilation }, classifierResult.classifier, policyCompilation));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GatewayStateMachine.d.ts","sourceRoot":"","sources":["../../src/gateway/GatewayStateMachine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,8BAA8B,EAC9B,0BAA0B,EAC1B,oBAAoB,EACpB,0BAA0B,EAC1B,2BAA2B,EAC3B,uBAAuB,EACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAChC,KAAK,8BAA8B,EACnC,KAAK,6BAA6B,EACnC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"GatewayStateMachine.d.ts","sourceRoot":"","sources":["../../src/gateway/GatewayStateMachine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,8BAA8B,EAC9B,0BAA0B,EAC1B,oBAAoB,EACpB,0BAA0B,EAC1B,2BAA2B,EAC3B,uBAAuB,EACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAChC,KAAK,8BAA8B,EACnC,KAAK,6BAA6B,EACnC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,4BAA4B,CAAC;AAUpC,MAAM,MAAM,6BAA6B,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE/E,MAAM,MAAM,kCAAkC,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEpF,MAAM,WAAW,iCAAiC;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,6BAA6B,CAAC;IACt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AA2B;IA2DnC,OAAO,CAAC,6BAA6B;IAYrC,OAAO,CAAC,2BAA2B;YAuBrB,YAAY;YAuCZ,+BAA+B;YAmI/B,OAAO;YAoHP,mBAAmB;YAoNnB,QAAQ;IA+BtB,OAAO,CAAC,aAAa;CAetB;AAED,eAAO,MAAM,+BAA+B,GAC1C,SAAS,gCAAgC,KACxC,yBAAmE,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createInMemoryCodaliGatewayStore, } from "./CodaliGatewayStore.js";
|
|
2
2
|
import { compileCodaliGatewayPolicy, } from "./GatewayPolicyCompiler.js";
|
|
3
3
|
import { normalizeCodaliEvidence } from "./EvidenceNormalizer.js";
|
|
4
|
+
import { buildTemporalContext, renderTemporalContext } from "./TemporalContext.js";
|
|
4
5
|
import { validateCodaliGatewayVerifierOutput } from "./CodaliGatewaySchemas.js";
|
|
5
6
|
import { CODALI_GATEWAY_SECURITY_PROMPT_HARDENING } from "./GatewaySecurityPolicy.js";
|
|
6
7
|
import { dispatchAppToolGateway, AppToolGatewayDispatchError, } from "./AppToolGatewayDispatcher.js";
|
|
@@ -122,6 +123,11 @@ export const buildCodaliGatewayWorkerPrompt = (input) => [
|
|
|
122
123
|
CODALI_GATEWAY_SECURITY_PROMPT_HARDENING.tenantScope,
|
|
123
124
|
"Return structured evidence, source references, tool telemetry, and any errors.",
|
|
124
125
|
`User query: ${input.request.query}`,
|
|
126
|
+
// The worker is what actually forms tool arguments, so it needs the resolved
|
|
127
|
+
// window. Without it a model invents dates — observed producing 2023 and
|
|
128
|
+
// 2024 ranges for "the last two weeks" in 2026 — and the tool call is
|
|
129
|
+
// syntactically fine but silently answers a different question.
|
|
130
|
+
...renderTemporalContext(buildTemporalContext(input.request.query)),
|
|
125
131
|
`Task id: ${input.task.id}`,
|
|
126
132
|
`Worker role: ${input.task.workerRole}`,
|
|
127
133
|
`Objective: ${input.task.objective}`,
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal run tracing.
|
|
3
|
+
*
|
|
4
|
+
* This ships with the first executable version rather than being deferred to a
|
|
5
|
+
* later observability phase. Tool-selection and iteration failures are the two
|
|
6
|
+
* things most likely to go wrong in an orchestrator, and both are close to
|
|
7
|
+
* undiagnosable without a record of what was chosen and why. Full trace replay
|
|
8
|
+
* can wait; knowing which model ran, which tools it picked, and why the run
|
|
9
|
+
* stopped cannot.
|
|
10
|
+
*
|
|
11
|
+
* Arguments are sanitized before they are recorded, because tool arguments
|
|
12
|
+
* routinely carry tokens and paths that must not reach a log.
|
|
13
|
+
*/
|
|
14
|
+
export interface GatewayTraceRecord {
|
|
15
|
+
runId?: string;
|
|
16
|
+
query: string;
|
|
17
|
+
startedAt: string;
|
|
18
|
+
roleBindings: Record<string, string>;
|
|
19
|
+
capabilities?: string[];
|
|
20
|
+
plannedTasks: Array<{
|
|
21
|
+
id: string;
|
|
22
|
+
role: string;
|
|
23
|
+
objective: string;
|
|
24
|
+
tools: string[];
|
|
25
|
+
}>;
|
|
26
|
+
toolCalls: Array<{
|
|
27
|
+
taskId: string;
|
|
28
|
+
tool: string;
|
|
29
|
+
args: unknown;
|
|
30
|
+
ok?: boolean;
|
|
31
|
+
latencyMs?: number;
|
|
32
|
+
errorCode?: string;
|
|
33
|
+
}>;
|
|
34
|
+
rounds: number;
|
|
35
|
+
finalizerMode?: string;
|
|
36
|
+
completionReason?: string;
|
|
37
|
+
status?: string;
|
|
38
|
+
durationMs?: number;
|
|
39
|
+
warnings: string[];
|
|
40
|
+
}
|
|
41
|
+
export declare const redactSecretValues: (value: string) => string;
|
|
42
|
+
/**
|
|
43
|
+
* Redacts sensitive-looking values and truncates long ones. Applied to every
|
|
44
|
+
* argument before it is recorded or printed.
|
|
45
|
+
*/
|
|
46
|
+
export declare const sanitizeArgs: (value: unknown, depth?: number) => unknown;
|
|
47
|
+
export interface GatewayTracerOptions {
|
|
48
|
+
/** Print progress to stderr as the run proceeds. */
|
|
49
|
+
verbose?: boolean;
|
|
50
|
+
write?: (line: string) => void;
|
|
51
|
+
}
|
|
52
|
+
export declare class GatewayTracer {
|
|
53
|
+
private readonly options;
|
|
54
|
+
private readonly record;
|
|
55
|
+
private readonly startedMs;
|
|
56
|
+
constructor(query: string, options?: GatewayTracerOptions);
|
|
57
|
+
private emit;
|
|
58
|
+
setRunId(runId: string): void;
|
|
59
|
+
setRoleBindings(bindings: Record<string, string | undefined>): void;
|
|
60
|
+
recordPlan(input: {
|
|
61
|
+
capabilities?: string[];
|
|
62
|
+
tasks: Array<{
|
|
63
|
+
id: string;
|
|
64
|
+
workerRole: string;
|
|
65
|
+
objective: string;
|
|
66
|
+
toolsAllowed?: string[];
|
|
67
|
+
}>;
|
|
68
|
+
}): void;
|
|
69
|
+
recordToolCall(input: {
|
|
70
|
+
taskId: string;
|
|
71
|
+
tool: string;
|
|
72
|
+
args: unknown;
|
|
73
|
+
}): void;
|
|
74
|
+
recordToolResult(input: {
|
|
75
|
+
taskId: string;
|
|
76
|
+
tool: string;
|
|
77
|
+
ok: boolean;
|
|
78
|
+
latencyMs: number;
|
|
79
|
+
errorCode?: string;
|
|
80
|
+
}): void;
|
|
81
|
+
recordRound(round: number): void;
|
|
82
|
+
addWarning(warning: string): void;
|
|
83
|
+
finish(input: {
|
|
84
|
+
status: string;
|
|
85
|
+
finalizerMode?: string;
|
|
86
|
+
completionReason?: string;
|
|
87
|
+
warnings?: string[];
|
|
88
|
+
}): GatewayTraceRecord;
|
|
89
|
+
snapshot(): GatewayTraceRecord;
|
|
90
|
+
/** Human-readable summary printed by `codali ask --trace`. */
|
|
91
|
+
render(): string;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=GatewayTracer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GatewayTracer.d.ts","sourceRoot":"","sources":["../../src/gateway/GatewayTracer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,kBAAkB;IACjC,KAAK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