@mcoda/mswarm 0.1.133 → 0.1.135-codali.2
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 +44 -0
- package/dist/codali-executor.d.ts +66 -1
- package/dist/codali-executor.d.ts.map +1 -1
- package/dist/codali-executor.js +83 -8
- package/dist/codali-executor.js.map +1 -1
- package/dist/invocation-token.d.ts.map +1 -1
- package/dist/invocation-token.js +1 -0
- package/dist/invocation-token.js.map +1 -1
- package/dist/native-reasoning.d.ts +8 -0
- package/dist/native-reasoning.d.ts.map +1 -0
- package/dist/native-reasoning.js +18 -0
- package/dist/native-reasoning.js.map +1 -0
- package/dist/runtime.d.ts +25 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +220 -20
- package/dist/runtime.js.map +1 -1
- package/dist/server.d.ts +3 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +58 -8
- package/dist/server.js.map +1 -1
- package/dist/vendor/codali/agents/RoleResolution.d.ts.map +1 -1
- package/dist/vendor/codali/agents/RoleResolution.js +4 -4
- package/dist/vendor/codali/api/CodaliApi.d.ts +16 -0
- package/dist/vendor/codali/api/CodaliApi.d.ts.map +1 -1
- package/dist/vendor/codali/api/CodaliApi.js +39 -10
- package/dist/vendor/codali/cli/AskCommand.d.ts +3 -0
- package/dist/vendor/codali/cli/AskCommand.d.ts.map +1 -1
- package/dist/vendor/codali/cli/AskCommand.js +76 -13
- package/dist/vendor/codali/cli/RunCommand.d.ts +4 -0
- package/dist/vendor/codali/cli/RunCommand.d.ts.map +1 -1
- package/dist/vendor/codali/cli/RunCommand.js +110 -24
- package/dist/vendor/codali/cli/TerminalCommand.d.ts +35 -0
- package/dist/vendor/codali/cli/TerminalCommand.d.ts.map +1 -0
- package/dist/vendor/codali/cli/TerminalCommand.js +616 -0
- package/dist/vendor/codali/cli/TerminalCredentials.d.ts +3 -0
- package/dist/vendor/codali/cli/TerminalCredentials.d.ts.map +1 -0
- package/dist/vendor/codali/cli/TerminalCredentials.js +89 -0
- package/dist/vendor/codali/cli/TerminalInput.d.ts +24 -0
- package/dist/vendor/codali/cli/TerminalInput.d.ts.map +1 -0
- package/dist/vendor/codali/cli/TerminalInput.js +98 -0
- package/dist/vendor/codali/cli/TerminalText.d.ts +10 -0
- package/dist/vendor/codali/cli/TerminalText.d.ts.map +1 -0
- package/dist/vendor/codali/cli/TerminalText.js +53 -0
- package/dist/vendor/codali/cli.d.ts.map +1 -1
- package/dist/vendor/codali/cli.js +33 -4
- package/dist/vendor/codali/cognitive/ConfiguredPipeline.d.ts +34 -0
- package/dist/vendor/codali/cognitive/ConfiguredPipeline.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ConfiguredPipeline.js +50 -0
- package/dist/vendor/codali/cognitive/ValidationRunner.d.ts +4 -0
- package/dist/vendor/codali/cognitive/ValidationRunner.d.ts.map +1 -1
- package/dist/vendor/codali/cognitive/ValidationRunner.js +18 -41
- package/dist/vendor/codali/config/NodeOrchestration.d.ts +21 -0
- package/dist/vendor/codali/config/NodeOrchestration.d.ts.map +1 -0
- package/dist/vendor/codali/config/NodeOrchestration.js +54 -0
- package/dist/vendor/codali/config/OrchestrationConfig.d.ts +100 -0
- package/dist/vendor/codali/config/OrchestrationConfig.d.ts.map +1 -0
- package/dist/vendor/codali/config/OrchestrationConfig.js +245 -0
- package/dist/vendor/codali/connectors/mcp/McpClient.d.ts +3 -1
- package/dist/vendor/codali/connectors/mcp/McpClient.d.ts.map +1 -1
- package/dist/vendor/codali/connectors/mcp/McpClient.js +3 -2
- package/dist/vendor/codali/connectors/mcp/McpServerRegistry.d.ts +2 -2
- package/dist/vendor/codali/connectors/mcp/McpServerRegistry.d.ts.map +1 -1
- package/dist/vendor/codali/connectors/mcp/McpServerRegistry.js +39 -16
- package/dist/vendor/codali/connectors/mcp/McpToolAdapter.js +2 -2
- package/dist/vendor/codali/connectors/media/ConfiguredMediaTools.d.ts +6 -0
- package/dist/vendor/codali/connectors/media/ConfiguredMediaTools.d.ts.map +1 -0
- package/dist/vendor/codali/connectors/media/ConfiguredMediaTools.js +41 -0
- package/dist/vendor/codali/connectors/media/ImageGenerationTool.js +3 -3
- package/dist/vendor/codali/connectors/media/MediaArtifactReceipt.d.ts +5 -0
- package/dist/vendor/codali/connectors/media/MediaArtifactReceipt.d.ts.map +1 -0
- package/dist/vendor/codali/connectors/media/MediaArtifactReceipt.js +65 -0
- package/dist/vendor/codali/connectors/media/MediaJobStore.d.ts +68 -0
- package/dist/vendor/codali/connectors/media/MediaJobStore.d.ts.map +1 -0
- package/dist/vendor/codali/connectors/media/MediaJobStore.js +199 -0
- package/dist/vendor/codali/connectors/media/MediaJobWorker.d.ts +2 -0
- package/dist/vendor/codali/connectors/media/MediaJobWorker.d.ts.map +1 -0
- package/dist/vendor/codali/connectors/media/MediaJobWorker.js +65 -0
- package/dist/vendor/codali/connectors/media/RemoteMediaJob.d.ts +6 -0
- package/dist/vendor/codali/connectors/media/RemoteMediaJob.d.ts.map +1 -0
- package/dist/vendor/codali/connectors/media/RemoteMediaJob.js +80 -0
- package/dist/vendor/codali/docdex/DocdexClient.d.ts +18 -1
- package/dist/vendor/codali/docdex/DocdexClient.d.ts.map +1 -1
- package/dist/vendor/codali/docdex/DocdexClient.js +135 -19
- package/dist/vendor/codali/docdex/ManagedDocdex.d.ts +29 -0
- package/dist/vendor/codali/docdex/ManagedDocdex.d.ts.map +1 -0
- package/dist/vendor/codali/docdex/ManagedDocdex.js +215 -0
- package/dist/vendor/codali/docdex/ManagedRuntime.d.ts +28 -0
- package/dist/vendor/codali/docdex/ManagedRuntime.d.ts.map +1 -0
- package/dist/vendor/codali/docdex/ManagedRuntime.js +212 -0
- package/dist/vendor/codali/eval/EvaluationProcess.d.ts +13 -0
- package/dist/vendor/codali/eval/EvaluationProcess.d.ts.map +1 -0
- package/dist/vendor/codali/eval/EvaluationProcess.js +76 -0
- package/dist/vendor/codali/eval/LongWorkflowJourney.d.ts +34 -0
- package/dist/vendor/codali/eval/LongWorkflowJourney.d.ts.map +1 -0
- package/dist/vendor/codali/eval/LongWorkflowJourney.js +243 -0
- package/dist/vendor/codali/eval/PlanningCorpus.d.ts +45 -0
- package/dist/vendor/codali/eval/PlanningCorpus.d.ts.map +1 -0
- package/dist/vendor/codali/eval/PlanningCorpus.js +189 -0
- package/dist/vendor/codali/eval/PlanningCorpusRunner.d.ts +13 -0
- package/dist/vendor/codali/eval/PlanningCorpusRunner.d.ts.map +1 -0
- package/dist/vendor/codali/eval/PlanningCorpusRunner.js +89 -0
- package/dist/vendor/codali/eval/TerminalCorpusRunner.d.ts +36 -0
- package/dist/vendor/codali/eval/TerminalCorpusRunner.d.ts.map +1 -0
- package/dist/vendor/codali/eval/TerminalCorpusRunner.js +222 -0
- package/dist/vendor/codali/eval/TerminalTaskCorpus.d.ts +26 -0
- package/dist/vendor/codali/eval/TerminalTaskCorpus.d.ts.map +1 -0
- package/dist/vendor/codali/eval/TerminalTaskCorpus.js +105 -0
- package/dist/vendor/codali/eval/TerminalWorkflowCorpus.d.ts +11 -0
- package/dist/vendor/codali/eval/TerminalWorkflowCorpus.d.ts.map +1 -0
- package/dist/vendor/codali/eval/TerminalWorkflowCorpus.js +116 -0
- package/dist/vendor/codali/eval/fixtures/TerminalRecoveryJourney.d.ts +4 -0
- package/dist/vendor/codali/eval/fixtures/TerminalRecoveryJourney.d.ts.map +1 -0
- package/dist/vendor/codali/eval/fixtures/TerminalRecoveryJourney.js +132 -0
- package/dist/vendor/codali/gateway/CodaliGateway.d.ts +2 -0
- package/dist/vendor/codali/gateway/CodaliGateway.d.ts.map +1 -1
- package/dist/vendor/codali/gateway/CodaliGateway.js +16 -4
- package/dist/vendor/codali/gateway/ConfiguredGateway.d.ts +23 -0
- package/dist/vendor/codali/gateway/ConfiguredGateway.d.ts.map +1 -0
- package/dist/vendor/codali/gateway/ConfiguredGateway.js +44 -0
- package/dist/vendor/codali/gateway/GatewayTracer.d.ts +1 -1
- package/dist/vendor/codali/gateway/GatewayTracer.d.ts.map +1 -1
- package/dist/vendor/codali/gateway/GatewayTracer.js +2 -27
- package/dist/vendor/codali/gateway/LocalGatewayTaskRunner.d.ts.map +1 -1
- package/dist/vendor/codali/gateway/LocalGatewayTaskRunner.js +13 -1
- package/dist/vendor/codali/index.d.ts +23 -0
- package/dist/vendor/codali/index.d.ts.map +1 -1
- package/dist/vendor/codali/index.js +12 -0
- package/dist/vendor/codali/permissions/PermissionGate.d.ts +44 -0
- package/dist/vendor/codali/permissions/PermissionGate.d.ts.map +1 -0
- package/dist/vendor/codali/permissions/PermissionGate.js +97 -0
- package/dist/vendor/codali/providers/ConfiguredEmbeddings.d.ts +43 -0
- package/dist/vendor/codali/providers/ConfiguredEmbeddings.d.ts.map +1 -0
- package/dist/vendor/codali/providers/ConfiguredEmbeddings.js +87 -0
- package/dist/vendor/codali/providers/ConfiguredModelScope.d.ts +69 -0
- package/dist/vendor/codali/providers/ConfiguredModelScope.d.ts.map +1 -0
- package/dist/vendor/codali/providers/ConfiguredModelScope.js +113 -0
- package/dist/vendor/codali/providers/ConfiguredProvider.d.ts +79 -0
- package/dist/vendor/codali/providers/ConfiguredProvider.d.ts.map +1 -0
- package/dist/vendor/codali/providers/ConfiguredProvider.js +238 -0
- package/dist/vendor/codali/providers/ModelServiceError.d.ts +10 -0
- package/dist/vendor/codali/providers/ModelServiceError.d.ts.map +1 -0
- package/dist/vendor/codali/providers/ModelServiceError.js +45 -0
- package/dist/vendor/codali/providers/MswarmWorkerProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/MswarmWorkerProvider.js +4 -0
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.js +134 -52
- package/dist/vendor/codali/providers/ProviderTypes.d.ts +14 -0
- package/dist/vendor/codali/providers/ProviderTypes.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/CodaliJobRuntime.d.ts +6 -0
- package/dist/vendor/codali/runtime/CodaliJobRuntime.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/CodaliJobRuntime.js +36 -1
- package/dist/vendor/codali/runtime/CodaliRuntime.d.ts +30 -0
- package/dist/vendor/codali/runtime/CodaliRuntime.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/CodaliRuntime.js +71 -1
- package/dist/vendor/codali/runtime/CompletionReport.d.ts +5 -0
- package/dist/vendor/codali/runtime/CompletionReport.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/CompletionReport.js +12 -0
- package/dist/vendor/codali/runtime/ProgressTracker.d.ts +17 -0
- package/dist/vendor/codali/runtime/ProgressTracker.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/ProgressTracker.js +27 -0
- package/dist/vendor/codali/runtime/RequestedTestEvidence.d.ts +12 -0
- package/dist/vendor/codali/runtime/RequestedTestEvidence.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/RequestedTestEvidence.js +16 -0
- package/dist/vendor/codali/runtime/RequiredRetrieval.d.ts +13 -0
- package/dist/vendor/codali/runtime/RequiredRetrieval.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/RequiredRetrieval.js +25 -0
- package/dist/vendor/codali/runtime/ReviewSource.d.ts +6 -0
- package/dist/vendor/codali/runtime/ReviewSource.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/ReviewSource.js +38 -0
- package/dist/vendor/codali/runtime/Runner.d.ts +13 -0
- package/dist/vendor/codali/runtime/Runner.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/Runner.js +220 -158
- package/dist/vendor/codali/runtime/SecretRedaction.d.ts +11 -0
- package/dist/vendor/codali/runtime/SecretRedaction.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/SecretRedaction.js +85 -0
- package/dist/vendor/codali/runtime/SessionController.d.ts +148 -0
- package/dist/vendor/codali/runtime/SessionController.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/SessionController.js +1356 -0
- package/dist/vendor/codali/runtime/StructuralEvidence.d.ts +22 -0
- package/dist/vendor/codali/runtime/StructuralEvidence.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/StructuralEvidence.js +87 -0
- package/dist/vendor/codali/runtime/TaskReviewContext.d.ts +34 -0
- package/dist/vendor/codali/runtime/TaskReviewContext.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/TaskReviewContext.js +34 -0
- package/dist/vendor/codali/runtime/ValidationOutput.d.ts +5 -0
- package/dist/vendor/codali/runtime/ValidationOutput.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/ValidationOutput.js +32 -0
- package/dist/vendor/codali/runtime/VerificationCommand.d.ts +3 -0
- package/dist/vendor/codali/runtime/VerificationCommand.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/VerificationCommand.js +48 -0
- package/dist/vendor/codali/runtime/WorkStatusPage.d.ts +15 -0
- package/dist/vendor/codali/runtime/WorkStatusPage.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/WorkStatusPage.js +58 -0
- package/dist/vendor/codali/runtime/WorkspaceLedger.d.ts +13 -0
- package/dist/vendor/codali/runtime/WorkspaceLedger.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/WorkspaceLedger.js +145 -0
- package/dist/vendor/codali/runtime/WorkspaceLock.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/WorkspaceLock.js +20 -17
- package/dist/vendor/codali/runtime/WorkspaceSnapshot.d.ts +13 -0
- package/dist/vendor/codali/runtime/WorkspaceSnapshot.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/WorkspaceSnapshot.js +88 -0
- package/dist/vendor/codali/session/AtomicState.d.ts +13 -0
- package/dist/vendor/codali/session/AtomicState.d.ts.map +1 -0
- package/dist/vendor/codali/session/AtomicState.js +109 -0
- package/dist/vendor/codali/session/SessionStoragePath.d.ts +15 -0
- package/dist/vendor/codali/session/SessionStoragePath.d.ts.map +1 -0
- package/dist/vendor/codali/session/SessionStoragePath.js +89 -0
- package/dist/vendor/codali/session/SessionStore.d.ts +9 -0
- package/dist/vendor/codali/session/SessionStore.d.ts.map +1 -1
- package/dist/vendor/codali/session/SessionStore.js +181 -47
- package/dist/vendor/codali/session/WorkState.d.ts +23 -0
- package/dist/vendor/codali/session/WorkState.d.ts.map +1 -0
- package/dist/vendor/codali/session/WorkState.js +367 -0
- package/dist/vendor/codali/session/WorkTypes.d.ts +94 -0
- package/dist/vendor/codali/session/WorkTypes.d.ts.map +1 -0
- package/dist/vendor/codali/session/WorkTypes.js +1 -0
- package/dist/vendor/codali/tools/ToolRegistry.d.ts +2 -0
- package/dist/vendor/codali/tools/ToolRegistry.d.ts.map +1 -1
- package/dist/vendor/codali/tools/ToolRegistry.js +12 -2
- package/dist/vendor/codali/tools/ToolTypes.d.ts +16 -0
- package/dist/vendor/codali/tools/ToolTypes.d.ts.map +1 -1
- package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts +2 -0
- package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts.map +1 -1
- package/dist/vendor/codali/tools/docdex/DocdexTools.js +17 -2
- package/dist/vendor/codali/tools/filesystem/FileTools.d.ts.map +1 -1
- package/dist/vendor/codali/tools/filesystem/FileTools.js +30 -10
- package/dist/vendor/codali/tools/shell/AsyncProcess.d.ts +16 -0
- package/dist/vendor/codali/tools/shell/AsyncProcess.d.ts.map +1 -0
- package/dist/vendor/codali/tools/shell/AsyncProcess.js +94 -0
- package/dist/vendor/codali/tools/shell/DarwinRuntimeLibraries.d.ts +13 -0
- package/dist/vendor/codali/tools/shell/DarwinRuntimeLibraries.d.ts.map +1 -0
- package/dist/vendor/codali/tools/shell/DarwinRuntimeLibraries.js +130 -0
- package/dist/vendor/codali/tools/shell/HostToolchain.d.ts +19 -0
- package/dist/vendor/codali/tools/shell/HostToolchain.d.ts.map +1 -0
- package/dist/vendor/codali/tools/shell/HostToolchain.js +264 -0
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.d.ts +15 -0
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.d.ts.map +1 -0
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.js +134 -0
- package/dist/vendor/codali/tools/shell/ShellTool.d.ts.map +1 -1
- package/dist/vendor/codali/tools/shell/ShellTool.js +9 -29
- package/dist/vendor/codali/tools/shell/ShellWorkingDirectory.d.ts +3 -0
- package/dist/vendor/codali/tools/shell/ShellWorkingDirectory.d.ts.map +1 -0
- package/dist/vendor/codali/tools/shell/ShellWorkingDirectory.js +30 -0
- package/package.json +31 -29
- package/scripts/backend-http-drain.mjs +152 -0
- package/scripts/media_gpu_lock.py +238 -0
- package/scripts/stable-audio-3-openai-server.py +45 -14
- package/scripts/stable-diffusion-cpp-openai-server.py +34 -4
- package/scripts/stable-diffusion-cpp-webm-duration.patch +22 -0
- package/scripts/wan22-openai-server.py +97 -18
|
@@ -3,11 +3,19 @@ import { ToolRegistry } from "../tools/ToolRegistry.js";
|
|
|
3
3
|
import type { ToolContext } from "../tools/ToolTypes.js";
|
|
4
4
|
import type { RunLogger } from "./RunLogger.js";
|
|
5
5
|
export interface RunnerOptions {
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
/** A controller may reject a premature final answer within this same bounded loop. */
|
|
8
|
+
continueAfterFinal?: (message: ProviderMessage) => string | undefined | Promise<string | undefined>;
|
|
9
|
+
onMessages?: (messages: ProviderMessage[]) => Promise<void>;
|
|
6
10
|
provider: Provider;
|
|
7
11
|
tools: ToolRegistry;
|
|
8
12
|
context: ToolContext;
|
|
9
13
|
maxSteps: number;
|
|
10
14
|
maxToolCalls: number;
|
|
15
|
+
/** Reserve the last bounded worker step for summarizing gathered evidence. */
|
|
16
|
+
finalStepWithoutTools?: boolean;
|
|
17
|
+
/** Combined tool-result character budget per model turn, when bounded. */
|
|
18
|
+
maxToolResultChars?: number;
|
|
11
19
|
maxTokens?: number;
|
|
12
20
|
temperature?: number;
|
|
13
21
|
responseFormat?: ProviderResponseFormat;
|
|
@@ -45,11 +53,15 @@ export declare class RunnerBudgetError extends Error {
|
|
|
45
53
|
});
|
|
46
54
|
}
|
|
47
55
|
export declare class Runner {
|
|
56
|
+
private continueAfterFinal?;
|
|
57
|
+
private onMessages?;
|
|
48
58
|
private provider;
|
|
49
59
|
private tools;
|
|
50
60
|
private context;
|
|
51
61
|
private maxSteps;
|
|
52
62
|
private maxToolCalls;
|
|
63
|
+
private finalStepWithoutTools;
|
|
64
|
+
private maxToolResultChars?;
|
|
53
65
|
private maxTokens?;
|
|
54
66
|
private temperature?;
|
|
55
67
|
private responseFormat?;
|
|
@@ -60,6 +72,7 @@ export declare class Runner {
|
|
|
60
72
|
private streamFlushMs?;
|
|
61
73
|
private timeoutMs?;
|
|
62
74
|
private logger?;
|
|
75
|
+
private signal?;
|
|
63
76
|
constructor(options: RunnerOptions);
|
|
64
77
|
run(initialMessages: ProviderMessage[]): Promise<RunnerResult>;
|
|
65
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Runner.d.ts","sourceRoot":"","sources":["../../src/runtime/Runner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAEV,QAAQ,EACR,eAAe,EACf,eAAe,EACf,sBAAsB,EAEtB,aAAa,EACd,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Runner.d.ts","sourceRoot":"","sources":["../../src/runtime/Runner.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { truncateToolResult } from "../tools/TruncateResult.js";
|
|
1
2
|
export class RunnerBudgetError extends Error {
|
|
2
3
|
constructor(code, metadata) {
|
|
3
4
|
super(code === "runner_timeout_exceeded"
|
|
@@ -26,6 +27,8 @@ export class Runner {
|
|
|
26
27
|
this.context = options.context;
|
|
27
28
|
this.maxSteps = options.maxSteps;
|
|
28
29
|
this.maxToolCalls = options.maxToolCalls;
|
|
30
|
+
this.finalStepWithoutTools = options.finalStepWithoutTools === true;
|
|
31
|
+
this.maxToolResultChars = options.maxToolResultChars;
|
|
29
32
|
this.maxTokens = options.maxTokens;
|
|
30
33
|
this.temperature = options.temperature;
|
|
31
34
|
this.responseFormat = options.responseFormat;
|
|
@@ -35,181 +38,240 @@ export class Runner {
|
|
|
35
38
|
this.onToken = options.onToken;
|
|
36
39
|
this.streamFlushMs = options.streamFlushMs;
|
|
37
40
|
this.timeoutMs = options.timeoutMs;
|
|
41
|
+
this.continueAfterFinal = options.continueAfterFinal;
|
|
42
|
+
this.onMessages = options.onMessages;
|
|
38
43
|
this.logger = options.logger;
|
|
44
|
+
this.signal = options.signal ?? options.context.signal;
|
|
39
45
|
}
|
|
40
46
|
async run(initialMessages) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
let timeoutId;
|
|
98
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
99
|
-
timeoutId = setTimeout(() => reject(new Error("Runner timeout exceeded")), remaining);
|
|
100
|
-
});
|
|
101
|
-
try {
|
|
102
|
-
return await Promise.race([promise, timeoutPromise]);
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
if (error instanceof Error && /Runner timeout exceeded/i.test(error.message)) {
|
|
106
|
-
await throwBudgetError("runner_timeout_exceeded", -1);
|
|
47
|
+
this.signal?.throwIfAborted();
|
|
48
|
+
const abortController = new AbortController();
|
|
49
|
+
const onAbort = () => abortController.abort(this.signal?.reason);
|
|
50
|
+
this.signal?.addEventListener("abort", onAbort, { once: true });
|
|
51
|
+
const timeout = this.timeoutMs ? setTimeout(() => abortController.abort(new Error("Runner timeout exceeded")), this.timeoutMs) : undefined;
|
|
52
|
+
const signal = abortController.signal;
|
|
53
|
+
try {
|
|
54
|
+
const messages = [...initialMessages];
|
|
55
|
+
let toolCallsExecuted = 0;
|
|
56
|
+
let usageTotals;
|
|
57
|
+
const deadline = this.timeoutMs ? Date.now() + this.timeoutMs : undefined;
|
|
58
|
+
const emitEvent = (event) => {
|
|
59
|
+
if (signal.aborted)
|
|
60
|
+
return;
|
|
61
|
+
if (this.onEvent) {
|
|
62
|
+
this.onEvent(event);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (event.type === "token") {
|
|
66
|
+
this.onToken?.(event.content);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const emitStatus = (phase, message) => {
|
|
70
|
+
this.onEvent?.({ type: "status", phase, message });
|
|
71
|
+
};
|
|
72
|
+
const recordUsage = (usage) => {
|
|
73
|
+
if (!usage)
|
|
74
|
+
return;
|
|
75
|
+
if (!usageTotals)
|
|
76
|
+
usageTotals = {};
|
|
77
|
+
if (usage.inputTokens !== undefined) {
|
|
78
|
+
usageTotals.inputTokens = (usageTotals.inputTokens ?? 0) + usage.inputTokens;
|
|
79
|
+
}
|
|
80
|
+
if (usage.outputTokens !== undefined) {
|
|
81
|
+
usageTotals.outputTokens = (usageTotals.outputTokens ?? 0) + usage.outputTokens;
|
|
82
|
+
}
|
|
83
|
+
if (usage.totalTokens !== undefined) {
|
|
84
|
+
usageTotals.totalTokens = (usageTotals.totalTokens ?? 0) + usage.totalTokens;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const timeRemaining = () => {
|
|
88
|
+
if (!deadline)
|
|
89
|
+
return undefined;
|
|
90
|
+
return deadline - Date.now();
|
|
91
|
+
};
|
|
92
|
+
const throwBudgetError = async (code, step) => {
|
|
93
|
+
const error = new RunnerBudgetError(code, {
|
|
94
|
+
step,
|
|
95
|
+
tool_calls_executed: toolCallsExecuted,
|
|
96
|
+
max_steps: this.maxSteps,
|
|
97
|
+
max_tool_calls: this.maxToolCalls,
|
|
98
|
+
timeout_ms: this.timeoutMs,
|
|
99
|
+
});
|
|
100
|
+
if (this.logger) {
|
|
101
|
+
await this.logger.log("runner_budget_failure", error.metadata);
|
|
107
102
|
}
|
|
108
103
|
throw error;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const toolSpecs = this.tools.describe().map((tool) => ({
|
|
120
|
-
name: tool.name,
|
|
121
|
-
description: tool.description,
|
|
122
|
-
inputSchema: tool.inputSchema,
|
|
123
|
-
}));
|
|
124
|
-
const allowTools = toolSpecs.length > 0 && this.toolChoice !== "none";
|
|
125
|
-
emitStatus("thinking");
|
|
126
|
-
if (this.logger) {
|
|
127
|
-
await this.logger.log("provider_request", {
|
|
128
|
-
provider: this.provider.name,
|
|
129
|
-
messages,
|
|
130
|
-
tools: allowTools ? toolSpecs : [],
|
|
131
|
-
toolChoice: allowTools ? this.toolChoice ?? "auto" : "none",
|
|
132
|
-
responseFormat: this.responseFormat,
|
|
133
|
-
temperature: this.temperature,
|
|
134
|
-
maxTokens: this.maxTokens,
|
|
135
|
-
stream: this.stream ?? false,
|
|
104
|
+
};
|
|
105
|
+
const withTimeout = async (promise, label) => {
|
|
106
|
+
const remaining = timeRemaining();
|
|
107
|
+
if (remaining !== undefined && remaining <= 0) {
|
|
108
|
+
await throwBudgetError("runner_timeout_exceeded", -1);
|
|
109
|
+
}
|
|
110
|
+
let timeoutId;
|
|
111
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
112
|
+
if (remaining !== undefined)
|
|
113
|
+
timeoutId = setTimeout(() => reject(new Error("Runner timeout exceeded")), remaining);
|
|
136
114
|
});
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
onToken: (token) => emitEvent({ type: "token", content: token }),
|
|
148
|
-
streamFlushMs: this.streamFlushMs,
|
|
149
|
-
}), "provider");
|
|
150
|
-
recordUsage(response.usage);
|
|
151
|
-
messages.push(response.message);
|
|
152
|
-
if (this.logger) {
|
|
153
|
-
await this.logger.log("provider_response", {
|
|
154
|
-
message: response.message,
|
|
155
|
-
toolCalls: response.toolCalls,
|
|
156
|
-
usage: response.usage,
|
|
115
|
+
let onCancel;
|
|
116
|
+
const cancelled = new Promise((_, reject) => {
|
|
117
|
+
// Provider streams may not honor AbortSignal; never accept their late reply.
|
|
118
|
+
// Tools are allowed to finish their cancellation cleanup before unlocking.
|
|
119
|
+
if (label === "provider") {
|
|
120
|
+
onCancel = () => reject(signal.reason ?? new Error("Cancelled"));
|
|
121
|
+
signal.addEventListener("abort", onCancel, { once: true });
|
|
122
|
+
if (signal.aborted)
|
|
123
|
+
onCancel();
|
|
124
|
+
}
|
|
157
125
|
});
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
126
|
+
try {
|
|
127
|
+
return await Promise.race([promise, timeoutPromise, cancelled]);
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
if (error instanceof Error && /Runner timeout exceeded/i.test(error.message)) {
|
|
131
|
+
await throwBudgetError("runner_timeout_exceeded", -1);
|
|
132
|
+
}
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
if (timeoutId)
|
|
137
|
+
clearTimeout(timeoutId);
|
|
138
|
+
if (onCancel)
|
|
139
|
+
signal.removeEventListener("abort", onCancel);
|
|
170
140
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
:
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
141
|
+
};
|
|
142
|
+
for (let step = 0; step < this.maxSteps; step += 1) {
|
|
143
|
+
signal.throwIfAborted();
|
|
144
|
+
if (deadline && timeRemaining() <= 0) {
|
|
145
|
+
await throwBudgetError("runner_timeout_exceeded", step);
|
|
146
|
+
}
|
|
147
|
+
const toolSpecs = this.tools.describe().map((tool) => ({
|
|
148
|
+
name: tool.name,
|
|
149
|
+
description: tool.description,
|
|
150
|
+
inputSchema: tool.inputSchema,
|
|
151
|
+
}));
|
|
152
|
+
const finalSummaryStep = this.finalStepWithoutTools && step > 0 && step === this.maxSteps - 1;
|
|
153
|
+
const allowTools = toolSpecs.length > 0 && this.toolChoice !== "none" && !finalSummaryStep;
|
|
154
|
+
emitStatus("thinking");
|
|
155
|
+
if (this.logger) {
|
|
156
|
+
await this.logger.log("provider_request", {
|
|
157
|
+
provider: this.provider.name,
|
|
158
|
+
messages,
|
|
159
|
+
tools: allowTools ? toolSpecs : [],
|
|
160
|
+
toolChoice: allowTools ? this.toolChoice ?? "auto" : "none",
|
|
161
|
+
responseFormat: this.responseFormat,
|
|
162
|
+
temperature: this.temperature,
|
|
163
|
+
maxTokens: this.maxTokens,
|
|
164
|
+
stream: this.stream ?? false,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
const response = await withTimeout(this.provider.generate({
|
|
168
|
+
signal,
|
|
169
|
+
messages,
|
|
170
|
+
tools: allowTools ? toolSpecs : undefined,
|
|
171
|
+
toolChoice: allowTools ? this.toolChoice ?? "auto" : finalSummaryStep ? "none" : undefined,
|
|
172
|
+
maxTokens: this.maxTokens,
|
|
173
|
+
temperature: this.temperature,
|
|
174
|
+
responseFormat: this.responseFormat,
|
|
175
|
+
stream: this.stream,
|
|
176
|
+
onEvent: emitEvent,
|
|
177
|
+
onToken: (token) => emitEvent({ type: "token", content: token }),
|
|
178
|
+
streamFlushMs: this.streamFlushMs,
|
|
179
|
+
}), "provider");
|
|
180
|
+
recordUsage(response.usage);
|
|
181
|
+
signal.throwIfAborted();
|
|
182
|
+
messages.push({
|
|
183
|
+
...response.message,
|
|
184
|
+
...(response.toolCalls?.length ? { toolCalls: response.toolCalls } : {}),
|
|
187
185
|
});
|
|
186
|
+
await this.onMessages?.([...messages]);
|
|
188
187
|
if (this.logger) {
|
|
189
|
-
await this.logger.log("
|
|
188
|
+
await this.logger.log("provider_response", {
|
|
189
|
+
message: response.message,
|
|
190
|
+
toolCalls: response.toolCalls,
|
|
191
|
+
usage: response.usage,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
if (!response.toolCalls || response.toolCalls.length === 0) {
|
|
195
|
+
const continuation = await this.continueAfterFinal?.(response.message);
|
|
196
|
+
if (continuation) {
|
|
197
|
+
messages.push({ role: "user", content: continuation });
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
finalMessage: response.message,
|
|
202
|
+
messages,
|
|
203
|
+
toolCallsExecuted,
|
|
204
|
+
usage: usageTotals,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
for (const call of response.toolCalls) {
|
|
208
|
+
signal.throwIfAborted();
|
|
209
|
+
if (toolCallsExecuted >= this.maxToolCalls) {
|
|
210
|
+
await throwBudgetError("runner_tool_call_limit_exceeded", step);
|
|
211
|
+
}
|
|
212
|
+
toolCallsExecuted += 1;
|
|
213
|
+
emitStatus("executing", call.name);
|
|
214
|
+
this.onEvent?.({ type: "tool_call", name: call.name, args: call.args });
|
|
215
|
+
const result = await withTimeout(this.tools.execute(call.name, call.args, { ...this.context, signal }), "tool");
|
|
216
|
+
const toolError = result.error;
|
|
217
|
+
let content = result.ok
|
|
218
|
+
? result.output
|
|
219
|
+
: `ERROR[${toolError?.code ?? "tool_execution_failed"}]: ${toolError?.message ?? "tool failed"}`;
|
|
220
|
+
if (result.ok && this.maxToolResultChars && this.maxToolResultChars > 0) {
|
|
221
|
+
const limit = Math.max(1, Math.floor(this.maxToolResultChars / response.toolCalls.length));
|
|
222
|
+
let structured = result.data;
|
|
223
|
+
if (structured === undefined) {
|
|
224
|
+
try {
|
|
225
|
+
structured = JSON.parse(content);
|
|
226
|
+
}
|
|
227
|
+
catch { /* Plain-text tool output. */ }
|
|
228
|
+
}
|
|
229
|
+
content = truncateToolResult(structured, content, limit).text;
|
|
230
|
+
}
|
|
231
|
+
if (result.invocationReceipt) {
|
|
232
|
+
content += `\n\n[Tool metadata: invocation receipt ID ${result.invocationReceipt.id}; receiptRef=${result.invocationReceipt.reference}]`;
|
|
233
|
+
}
|
|
234
|
+
messages.push(buildToolMessage(call, content));
|
|
235
|
+
await this.onMessages?.([...messages]);
|
|
236
|
+
this.onEvent?.({
|
|
237
|
+
type: "tool_result",
|
|
190
238
|
name: call.name,
|
|
239
|
+
output: content,
|
|
191
240
|
ok: result.ok,
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
error_category: toolError?.category,
|
|
195
|
-
error_retryable: toolError?.retryable,
|
|
196
|
-
error_details: toolError?.details,
|
|
241
|
+
errorCode: toolError?.code,
|
|
242
|
+
retryable: toolError?.retryable,
|
|
197
243
|
});
|
|
198
|
-
if (
|
|
199
|
-
await this.logger.
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
244
|
+
if (this.logger) {
|
|
245
|
+
await this.logger.log("tool_call", {
|
|
246
|
+
name: call.name,
|
|
247
|
+
ok: result.ok,
|
|
248
|
+
error: toolError?.message,
|
|
249
|
+
error_code: toolError?.code,
|
|
250
|
+
error_category: toolError?.category,
|
|
251
|
+
error_retryable: toolError?.retryable,
|
|
252
|
+
error_details: toolError?.details,
|
|
207
253
|
});
|
|
254
|
+
if (toolError) {
|
|
255
|
+
await this.logger.logSafetyEvent({
|
|
256
|
+
phase: "act",
|
|
257
|
+
category: "tool",
|
|
258
|
+
code: toolError.code,
|
|
259
|
+
disposition: toolError.retryable ? "retryable" : "non_retryable",
|
|
260
|
+
tool: call.name,
|
|
261
|
+
message: toolError.message,
|
|
262
|
+
details: toolError.details,
|
|
263
|
+
});
|
|
264
|
+
}
|
|
208
265
|
}
|
|
209
266
|
}
|
|
210
267
|
}
|
|
268
|
+
await throwBudgetError("runner_step_limit_exceeded", this.maxSteps);
|
|
269
|
+
throw new Error("unreachable_runner_budget_path");
|
|
270
|
+
}
|
|
271
|
+
finally {
|
|
272
|
+
if (timeout)
|
|
273
|
+
clearTimeout(timeout);
|
|
274
|
+
this.signal?.removeEventListener("abort", onAbort);
|
|
211
275
|
}
|
|
212
|
-
await throwBudgetError("runner_step_limit_exceeded", this.maxSteps);
|
|
213
|
-
throw new Error("unreachable_runner_budget_path");
|
|
214
276
|
}
|
|
215
277
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Register credentials when resolved; do not scan or expose unrelated environment values. */
|
|
2
|
+
export declare const registerSecretValue: (value: string) => void;
|
|
3
|
+
export declare const redactSecretValues: (value: string) => string;
|
|
4
|
+
/** Hold incomplete credential-shaped words so split chunks cannot expose a prefix or tail. */
|
|
5
|
+
export declare class StreamingSecretRedactor {
|
|
6
|
+
private pending;
|
|
7
|
+
private droppingWord;
|
|
8
|
+
write(chunk: string): string;
|
|
9
|
+
finish(): string;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=SecretRedaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SecretRedaction.d.ts","sourceRoot":"","sources":["../../src/runtime/SecretRedaction.ts"],"names":[],"mappings":"AAaA,8FAA8F;AAC9F,eAAO,MAAM,mBAAmB,GAAI,OAAO,MAAM,KAAG,IAEnD,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,KAAG,MAKlD,CAAC;AAEF,8FAA8F;AAC9F,qBAAa,uBAAuB;IAClC,OAAO,CAAC,OAAO,CAAM;IACrB,OAAO,CAAC,YAAY,CAAS;IAC7B,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IA4B5B,MAAM,IAAI,MAAM;CAUjB"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const knownSecrets = new Set();
|
|
2
|
+
const patterns = [
|
|
3
|
+
/\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi,
|
|
4
|
+
/\bsk-[A-Za-z0-9_-]{16,}\b/g,
|
|
5
|
+
/\bsk_[A-Za-z0-9]+_[A-Za-z0-9_]{8,}\b/g,
|
|
6
|
+
/\bgh[pousr]_[A-Za-z0-9_]{20,}\b/g,
|
|
7
|
+
/\bglpat-[A-Za-z0-9_-]{16,}\b/g,
|
|
8
|
+
/\bxox[abprs]-[A-Za-z0-9-]{10,}\b/g,
|
|
9
|
+
/\bAKIA[0-9A-Z]{16}\b/g,
|
|
10
|
+
/\bAIza[0-9A-Za-z_-]{30,}\b/g,
|
|
11
|
+
/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g,
|
|
12
|
+
];
|
|
13
|
+
/** Register credentials when resolved; do not scan or expose unrelated environment values. */
|
|
14
|
+
export const registerSecretValue = (value) => {
|
|
15
|
+
if (value.length >= 4) {
|
|
16
|
+
knownSecrets.add(value);
|
|
17
|
+
knownSecrets.add(JSON.stringify(value).slice(1, -1));
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
export const redactSecretValues = (value) => {
|
|
21
|
+
let output = value;
|
|
22
|
+
for (const secret of [...knownSecrets].sort((a, b) => b.length - a.length))
|
|
23
|
+
output = output.split(secret).join("[redacted]");
|
|
24
|
+
for (const pattern of patterns)
|
|
25
|
+
output = output.replace(pattern, "[redacted]");
|
|
26
|
+
return output;
|
|
27
|
+
};
|
|
28
|
+
/** Hold incomplete credential-shaped words so split chunks cannot expose a prefix or tail. */
|
|
29
|
+
export class StreamingSecretRedactor {
|
|
30
|
+
constructor() {
|
|
31
|
+
this.pending = "";
|
|
32
|
+
this.droppingWord = false;
|
|
33
|
+
}
|
|
34
|
+
write(chunk) {
|
|
35
|
+
if (this.droppingWord) {
|
|
36
|
+
const boundary = chunk.search(/[^A-Za-z0-9._~+/=-]/);
|
|
37
|
+
if (boundary < 0)
|
|
38
|
+
return "";
|
|
39
|
+
chunk = chunk.slice(boundary);
|
|
40
|
+
this.droppingWord = false;
|
|
41
|
+
}
|
|
42
|
+
this.pending += chunk;
|
|
43
|
+
let cutoff = this.pending.search(/[A-Za-z0-9._~+/=-]*$/);
|
|
44
|
+
const bearer = /\bBearer\s+[A-Za-z0-9._~+/=-]*$/i.exec(this.pending);
|
|
45
|
+
if (bearer)
|
|
46
|
+
cutoff = Math.min(cutoff, bearer.index);
|
|
47
|
+
for (const secret of knownSecrets) {
|
|
48
|
+
// An exact credential may contain spaces/punctuation, unlike a bearer word.
|
|
49
|
+
for (let at = this.pending.indexOf(secret); at >= 0; at = this.pending.indexOf(secret, at + 1)) {
|
|
50
|
+
if (at < cutoff && at + secret.length > cutoff)
|
|
51
|
+
cutoff = at;
|
|
52
|
+
}
|
|
53
|
+
for (let size = Math.min(secret.length - 1, this.pending.length); size > 0; size--) {
|
|
54
|
+
if (this.pending.endsWith(secret.slice(0, size))) {
|
|
55
|
+
cutoff = Math.min(cutoff, this.pending.length - size);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
let output = redactSecretValues(this.pending.slice(0, cutoff));
|
|
61
|
+
this.pending = this.pending.slice(cutoff);
|
|
62
|
+
// Never release a truncated prefix; discard an oversized unbroken token.
|
|
63
|
+
const longestCredential = Math.max(0, ...[...knownSecrets].map(secret => secret.length));
|
|
64
|
+
if (this.pending.length > Math.max(65536, longestCredential)) {
|
|
65
|
+
output += "[redacted oversized token]";
|
|
66
|
+
this.pending = "";
|
|
67
|
+
this.droppingWord = true;
|
|
68
|
+
}
|
|
69
|
+
return output;
|
|
70
|
+
}
|
|
71
|
+
finish() {
|
|
72
|
+
let output = redactSecretValues(this.pending);
|
|
73
|
+
for (const secret of knownSecrets) {
|
|
74
|
+
for (let size = Math.min(secret.length - 1, output.length); size >= 4; size--) {
|
|
75
|
+
if (output.endsWith(secret.slice(0, size))) {
|
|
76
|
+
output = `${output.slice(0, -size)}[redacted]`;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
this.pending = "";
|
|
82
|
+
this.droppingWord = false;
|
|
83
|
+
return output;
|
|
84
|
+
}
|
|
85
|
+
}
|