@mcoda/mswarm 0.1.133 → 0.1.135-codali.10
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 +79 -1
- package/dist/codali-executor.d.ts.map +1 -1
- package/dist/codali-executor.js +115 -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 +226 -22
- 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 +618 -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 +119 -0
- package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.d.ts +4 -0
- package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.d.ts.map +1 -0
- package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.js +10 -0
- package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.d.ts +6 -0
- package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.d.ts.map +1 -0
- package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.js +145 -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 +136 -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 +24 -0
- package/dist/vendor/codali/index.d.ts.map +1 -1
- package/dist/vendor/codali/index.js +13 -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 +70 -0
- package/dist/vendor/codali/providers/ConfiguredModelScope.d.ts.map +1 -0
- package/dist/vendor/codali/providers/ConfiguredModelScope.js +117 -0
- package/dist/vendor/codali/providers/ConfiguredProvider.d.ts +84 -0
- package/dist/vendor/codali/providers/ConfiguredProvider.d.ts.map +1 -0
- package/dist/vendor/codali/providers/ConfiguredProvider.js +271 -0
- package/dist/vendor/codali/providers/ModelServiceError.d.ts +14 -0
- package/dist/vendor/codali/providers/ModelServiceError.d.ts.map +1 -0
- package/dist/vendor/codali/providers/ModelServiceError.js +67 -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 +140 -52
- package/dist/vendor/codali/providers/ProviderTypes.d.ts +16 -0
- package/dist/vendor/codali/providers/ProviderTypes.d.ts.map +1 -1
- package/dist/vendor/codali/providers/RequestUsage.d.ts +11 -0
- package/dist/vendor/codali/providers/RequestUsage.d.ts.map +1 -0
- package/dist/vendor/codali/providers/RequestUsage.js +33 -0
- 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 +31 -0
- package/dist/vendor/codali/runtime/CodaliRuntime.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/CodaliRuntime.js +72 -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/ReviewContract.d.ts +35 -0
- package/dist/vendor/codali/runtime/ReviewContract.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/ReviewContract.js +131 -0
- package/dist/vendor/codali/runtime/ReviewCoordinator.d.ts +41 -0
- package/dist/vendor/codali/runtime/ReviewCoordinator.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/ReviewCoordinator.js +81 -0
- package/dist/vendor/codali/runtime/ReviewSource.d.ts +9 -0
- package/dist/vendor/codali/runtime/ReviewSource.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/ReviewSource.js +54 -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 +225 -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 +150 -0
- package/dist/vendor/codali/runtime/SessionController.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/SessionController.js +1487 -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/TaskReview.d.ts +25 -0
- package/dist/vendor/codali/runtime/TaskReview.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/TaskReview.js +84 -0
- package/dist/vendor/codali/runtime/TaskReviewContext.d.ts +71 -0
- package/dist/vendor/codali/runtime/TaskReviewContext.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/TaskReviewContext.js +50 -0
- package/dist/vendor/codali/runtime/UsageReconciliation.d.ts +28 -0
- package/dist/vendor/codali/runtime/UsageReconciliation.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/UsageReconciliation.js +68 -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 +5 -0
- package/dist/vendor/codali/runtime/VerificationCommand.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/VerificationCommand.js +76 -0
- package/dist/vendor/codali/runtime/VerificationReceiptSelection.d.ts +15 -0
- package/dist/vendor/codali/runtime/VerificationReceiptSelection.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/VerificationReceiptSelection.js +30 -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 +123 -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 +101 -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 +32 -0
- package/dist/vendor/codali/session/WorkState.d.ts.map +1 -0
- package/dist/vendor/codali/session/WorkState.js +399 -0
- package/dist/vendor/codali/session/WorkTypes.d.ts +102 -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 +19 -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 +266 -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 +138 -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/native_load_guard.py +257 -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
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type OrchestrationProvider, type ResolvedOrchestrationConfig, type ModelOperation, type EffortLevel } from "../config/OrchestrationConfig.js";
|
|
2
|
+
import { type RequestUsageReceipt } from "./RequestUsage.js";
|
|
3
|
+
import type { Provider, ProviderRequest, ProviderResponse } from "./ProviderTypes.js";
|
|
4
|
+
export interface CatalogEntry {
|
|
5
|
+
id: string;
|
|
6
|
+
aliases: string[];
|
|
7
|
+
backend?: string;
|
|
8
|
+
health: string;
|
|
9
|
+
supportsTools: boolean;
|
|
10
|
+
contextWindow?: number;
|
|
11
|
+
operations: string[];
|
|
12
|
+
raw: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
/** Authenticated host context, separate from user/model supplied request bodies. */
|
|
15
|
+
export interface ModelCallerContext {
|
|
16
|
+
clientIdentity?: string;
|
|
17
|
+
clientProduct?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare const normalizeModelCaller: (caller?: ModelCallerContext) => ModelCallerContext;
|
|
20
|
+
/** Discovery failed before inference; a caller may release its local token reservation. */
|
|
21
|
+
export declare class NativeReasoningTransportError extends Error {
|
|
22
|
+
constructor(message: string);
|
|
23
|
+
}
|
|
24
|
+
export declare const providerCredential: (provider: OrchestrationProvider) => Promise<string | undefined>;
|
|
25
|
+
export declare class ModelServiceClient {
|
|
26
|
+
readonly provider: OrchestrationProvider;
|
|
27
|
+
private readonly credentialOverride?;
|
|
28
|
+
private cache?;
|
|
29
|
+
private readonly caller;
|
|
30
|
+
constructor(provider: OrchestrationProvider, credentialOverride?: string | undefined, caller?: ModelCallerContext);
|
|
31
|
+
private credential;
|
|
32
|
+
json(url: string, options?: {
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
method?: string;
|
|
35
|
+
body?: unknown;
|
|
36
|
+
timeoutMs?: number;
|
|
37
|
+
}): Promise<unknown>;
|
|
38
|
+
/** Retry only read-only discovery on explicit temporary service failures.
|
|
39
|
+
* Never reuse this for submission, reconciliation mutations or auth denials. */
|
|
40
|
+
private discoveryJson;
|
|
41
|
+
catalog(signal?: AbortSignal, refresh?: boolean): Promise<CatalogEntry[]>;
|
|
42
|
+
usage(signal?: AbortSignal): Promise<unknown>;
|
|
43
|
+
requestUsage(requestId: string, signal?: AbortSignal): Promise<RequestUsageReceipt>;
|
|
44
|
+
/** The proxy and selected node must both advertise this transport contract.
|
|
45
|
+
* A model's supports_reasoning flag alone says nothing about request forwarding. */
|
|
46
|
+
requireNativeReasoning(modelId: string, parameters: string[], signal?: AbortSignal): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
export interface ModelInvocation {
|
|
49
|
+
id: string;
|
|
50
|
+
binding: string;
|
|
51
|
+
configHash: string;
|
|
52
|
+
modelId: string;
|
|
53
|
+
catalogId: string;
|
|
54
|
+
backend?: string;
|
|
55
|
+
host?: string;
|
|
56
|
+
nativeReasoningRequest?: Record<string, unknown>;
|
|
57
|
+
}
|
|
58
|
+
export declare class ConfiguredProvider implements Provider {
|
|
59
|
+
readonly resolved: ResolvedOrchestrationConfig;
|
|
60
|
+
readonly binding: string;
|
|
61
|
+
private readonly options;
|
|
62
|
+
readonly name = "configured";
|
|
63
|
+
readonly supportsToolCalls = true;
|
|
64
|
+
private clients;
|
|
65
|
+
private readonly caller;
|
|
66
|
+
private readonly credentials;
|
|
67
|
+
constructor(resolved: ResolvedOrchestrationConfig, binding?: string, options?: {
|
|
68
|
+
caller?: ModelCallerContext;
|
|
69
|
+
/** Trusted host credential resolution; never accepted from a request/config document. */
|
|
70
|
+
credentials?: Readonly<Record<string, string>>;
|
|
71
|
+
effort?: EffortLevel;
|
|
72
|
+
beforeRequest?: (invocation: ModelInvocation, request: ProviderRequest) => Promise<void>;
|
|
73
|
+
afterRequest?: (invocation: ModelInvocation, response: ProviderResponse) => Promise<void>;
|
|
74
|
+
});
|
|
75
|
+
client(providerId: string): ModelServiceClient;
|
|
76
|
+
select(operation: ModelOperation, signal?: AbortSignal, requireTools?: boolean): Promise<{
|
|
77
|
+
id: string;
|
|
78
|
+
model: import("../config/OrchestrationConfig.js").OrchestrationModel;
|
|
79
|
+
actual: CatalogEntry;
|
|
80
|
+
provider: OrchestrationProvider;
|
|
81
|
+
}>;
|
|
82
|
+
generate(request: ProviderRequest): Promise<ProviderResponse>;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=ConfiguredProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfiguredProvider.d.ts","sourceRoot":"","sources":["../../src/providers/ConfiguredProvider.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
4
|
+
import { CryptoHelper, PathHelper, mswarmClientProductHeaders } from "@mcoda/shared";
|
|
5
|
+
import { resolveCredential } from "../runcontext/CredentialFile.js";
|
|
6
|
+
import { resolveBinding } from "../config/OrchestrationConfig.js";
|
|
7
|
+
import { OpenAiCompatibleProvider } from "./OpenAiCompatibleProvider.js";
|
|
8
|
+
import { ModelServiceError } from "./ModelServiceError.js";
|
|
9
|
+
import { parseRequestUsage } from "./RequestUsage.js";
|
|
10
|
+
import { registerSecretValue } from "../runtime/SecretRedaction.js";
|
|
11
|
+
export const normalizeModelCaller = (caller = {}) => {
|
|
12
|
+
const clientIdentity = caller.clientIdentity?.trim();
|
|
13
|
+
const clientProduct = caller.clientProduct?.trim().toLowerCase() ?? "codali";
|
|
14
|
+
if (clientIdentity !== undefined && !/^[A-Za-z0-9._:-]{1,128}$/.test(clientIdentity))
|
|
15
|
+
throw new Error("Invalid model client identity");
|
|
16
|
+
if (!/^[a-z0-9](?:[a-z0-9_-]{0,62}[a-z0-9])?$/.test(clientProduct))
|
|
17
|
+
throw new Error("Invalid model client product");
|
|
18
|
+
return { ...(clientIdentity ? { clientIdentity } : {}), clientProduct };
|
|
19
|
+
};
|
|
20
|
+
const modelCallerHeaders = (caller) => ({
|
|
21
|
+
...mswarmClientProductHeaders(caller.clientProduct),
|
|
22
|
+
...(caller.clientIdentity ? { "x-mswarm-client-identity": caller.clientIdentity, "x-mswarm-client": caller.clientIdentity } : {}),
|
|
23
|
+
});
|
|
24
|
+
const record = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
25
|
+
/** Discovery failed before inference; a caller may release its local token reservation. */
|
|
26
|
+
export class NativeReasoningTransportError extends Error {
|
|
27
|
+
constructor(message) { super(message); this.name = "NativeReasoningTransportError"; }
|
|
28
|
+
}
|
|
29
|
+
export const providerCredential = async (provider) => {
|
|
30
|
+
if (!provider.credentialRef)
|
|
31
|
+
return undefined;
|
|
32
|
+
const name = provider.credentialRef.slice(4);
|
|
33
|
+
const direct = resolveCredential(name);
|
|
34
|
+
if (direct) {
|
|
35
|
+
registerSecretValue(direct);
|
|
36
|
+
return direct;
|
|
37
|
+
}
|
|
38
|
+
if (provider.adapter === "mswarm" && resolveCredential("CODALI_MSWARM_LOGGED_OUT") === "1")
|
|
39
|
+
throw new Error("Logged out; use codali login");
|
|
40
|
+
// Migrate by reading the existing user store; never read repository credentials.
|
|
41
|
+
if (provider.adapter === "mswarm" && name === "MCODA_MSWARM_API_KEY") {
|
|
42
|
+
try {
|
|
43
|
+
const config = JSON.parse(await readFile(PathHelper.getGlobalConfigPath(), "utf8"));
|
|
44
|
+
const existing = config.mswarm;
|
|
45
|
+
if (existing?.encryptedApiKey && new URL(existing.baseUrl ?? "https://api.mswarm.org").origin === new URL(provider.baseUrl).origin) {
|
|
46
|
+
const key = await CryptoHelper.decryptSecret(existing.encryptedApiKey);
|
|
47
|
+
registerSecretValue(key);
|
|
48
|
+
return key;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (error.code !== "ENOENT")
|
|
53
|
+
throw new Error("Stored mSwarm credentials could not be loaded; use codali login");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
throw new Error(`Missing credential ${name}; use codali login or set the environment variable`);
|
|
57
|
+
};
|
|
58
|
+
export class ModelServiceClient {
|
|
59
|
+
constructor(provider, credentialOverride, caller) {
|
|
60
|
+
this.provider = provider;
|
|
61
|
+
this.credentialOverride = credentialOverride;
|
|
62
|
+
this.caller = normalizeModelCaller(caller);
|
|
63
|
+
if (credentialOverride)
|
|
64
|
+
registerSecretValue(credentialOverride);
|
|
65
|
+
}
|
|
66
|
+
credential() { return this.credentialOverride === undefined ? providerCredential(this.provider) : Promise.resolve(this.credentialOverride); }
|
|
67
|
+
async json(url, options = {}) {
|
|
68
|
+
if (new URL(url).origin !== new URL(this.provider.baseUrl).origin)
|
|
69
|
+
throw new Error("Refusing credentials to an unconfigured origin");
|
|
70
|
+
const key = await this.credential();
|
|
71
|
+
const controller = new AbortController();
|
|
72
|
+
const abort = () => controller.abort(options.signal?.reason);
|
|
73
|
+
options.signal?.throwIfAborted();
|
|
74
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
75
|
+
const timer = setTimeout(() => controller.abort(new Error("Service request timed out")), options.timeoutMs ?? 30000);
|
|
76
|
+
try {
|
|
77
|
+
const response = await fetch(url, {
|
|
78
|
+
redirect: "error", method: options.method ?? "GET", signal: controller.signal,
|
|
79
|
+
headers: { accept: "application/json", ...(key ? this.provider.adapter === "mswarm" ? { "x-api-key": key } : { authorization: `Bearer ${key}` } : {}), ...(this.provider.adapter === "mswarm" ? modelCallerHeaders(this.caller) : {}), ...(options.body ? { "content-type": "application/json" } : {}) },
|
|
80
|
+
body: options.body === undefined ? undefined : JSON.stringify(options.body),
|
|
81
|
+
});
|
|
82
|
+
if (!response.ok)
|
|
83
|
+
throw await ModelServiceError.fromResponse(response);
|
|
84
|
+
if (!response.body)
|
|
85
|
+
throw new Error("Empty service response");
|
|
86
|
+
const reader = response.body.getReader();
|
|
87
|
+
const chunks = [];
|
|
88
|
+
let size = 0;
|
|
89
|
+
try {
|
|
90
|
+
while (true) {
|
|
91
|
+
const next = await reader.read();
|
|
92
|
+
if (next.done)
|
|
93
|
+
break;
|
|
94
|
+
size += next.value.byteLength;
|
|
95
|
+
if (size > 96 * 1024 * 1024) {
|
|
96
|
+
await reader.cancel();
|
|
97
|
+
throw new Error("Service response exceeds size limit");
|
|
98
|
+
}
|
|
99
|
+
chunks.push(next.value);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
reader.releaseLock();
|
|
104
|
+
}
|
|
105
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
clearTimeout(timer);
|
|
109
|
+
options.signal?.removeEventListener("abort", abort);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** Retry only read-only discovery on explicit temporary service failures.
|
|
113
|
+
* Never reuse this for submission, reconciliation mutations or auth denials. */
|
|
114
|
+
async discoveryJson(url, signal) {
|
|
115
|
+
for (let attempt = 0;; attempt++) {
|
|
116
|
+
signal?.throwIfAborted();
|
|
117
|
+
try {
|
|
118
|
+
return await this.json(url, { signal });
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
signal?.throwIfAborted();
|
|
122
|
+
if (!(error instanceof ModelServiceError) || error.code !== "service_unavailable" || attempt >= 2)
|
|
123
|
+
throw error;
|
|
124
|
+
const retryAfterMs = (error.retryAfterSeconds ?? 0) * 1000;
|
|
125
|
+
if (retryAfterMs > 5000)
|
|
126
|
+
throw error;
|
|
127
|
+
await delay(Math.max(attempt === 0 ? 250 : 750, retryAfterMs), undefined, { signal });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async catalog(signal, refresh = false) {
|
|
132
|
+
const credential = await this.credential();
|
|
133
|
+
const key = createHash("sha256").update(credential ?? "anonymous").digest("hex");
|
|
134
|
+
if (!refresh && this.cache?.key === key && this.cache.expires > Date.now())
|
|
135
|
+
return this.cache.entries;
|
|
136
|
+
const base = new URL(this.provider.baseUrl);
|
|
137
|
+
const url = this.provider.catalogUrl ?? (this.provider.adapter === "mswarm" ? new URL("/v1/swarm/self-hosted/agents", base).toString() : `${this.provider.baseUrl.replace(/\/$/, "")}/models`);
|
|
138
|
+
const payload = record(await this.discoveryJson(url, signal));
|
|
139
|
+
const items = payload.agents ?? payload.data;
|
|
140
|
+
if (!Array.isArray(items))
|
|
141
|
+
throw new Error("Invalid model catalog response");
|
|
142
|
+
const entries = items.map(item => {
|
|
143
|
+
const raw = record(item);
|
|
144
|
+
const aliases = [raw.slug, raw.public_model_id, raw.default_model, raw.id].filter((v) => typeof v === "string" && !!v);
|
|
145
|
+
return { id: aliases[0] ?? "", aliases, backend: raw.adapter === "strata-local" ? "strata" : typeof raw.backend === "string" ? raw.backend : typeof raw.adapter === "string" ? raw.adapter : undefined,
|
|
146
|
+
health: String(raw.health_status ?? "unknown"), supportsTools: raw.supports_tools === true,
|
|
147
|
+
contextWindow: typeof raw.context_window === "number" ? raw.context_window : undefined,
|
|
148
|
+
operations: Array.isArray(raw.operations) ? raw.operations.map(v => typeof v === "string" ? v : String(record(v).type ?? "")) : [], raw };
|
|
149
|
+
}).filter(x => x.id);
|
|
150
|
+
this.cache = { key, expires: Date.now() + 30000, entries };
|
|
151
|
+
return entries;
|
|
152
|
+
}
|
|
153
|
+
async usage(signal) {
|
|
154
|
+
if (this.provider.adapter !== "mswarm" && !this.provider.usageUrl)
|
|
155
|
+
return { available: false };
|
|
156
|
+
return this.json(this.provider.usageUrl ?? new URL("/v1/swarm/runtime/usage-limits", this.provider.baseUrl).toString(), { signal });
|
|
157
|
+
}
|
|
158
|
+
async requestUsage(requestId, signal) {
|
|
159
|
+
if (this.provider.adapter !== "mswarm")
|
|
160
|
+
throw new Error("Provider has no authenticated request receipt contract");
|
|
161
|
+
if (!/^[a-f0-9]{8}-[a-f0-9]{4}-[1-8][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i.test(requestId))
|
|
162
|
+
throw new Error("Invalid request UUID");
|
|
163
|
+
const url = new URL(`/v1/swarm/self-hosted/requests/${encodeURIComponent(requestId)}/receipts`, this.provider.baseUrl);
|
|
164
|
+
return parseRequestUsage(requestId, await this.json(url.href, { signal, timeoutMs: 10000 }));
|
|
165
|
+
}
|
|
166
|
+
/** The proxy and selected node must both advertise this transport contract.
|
|
167
|
+
* A model's supports_reasoning flag alone says nothing about request forwarding. */
|
|
168
|
+
async requireNativeReasoning(modelId, parameters, signal) {
|
|
169
|
+
if (this.provider.adapter !== "mswarm" || parameters.length === 0)
|
|
170
|
+
return;
|
|
171
|
+
const endpoint = new URL(this.provider.baseUrl);
|
|
172
|
+
endpoint.pathname = endpoint.pathname.replace(/\/$/, "");
|
|
173
|
+
endpoint.pathname = ["", "/v1"].includes(endpoint.pathname)
|
|
174
|
+
? "/v1/swarm/self-hosted/openai/models" : `${endpoint.pathname}/models`;
|
|
175
|
+
const payload = record(await this.discoveryJson(endpoint.href, signal).catch(error => {
|
|
176
|
+
throw new NativeReasoningTransportError(`Native reasoning preflight failed before inference: ${error instanceof Error ? error.message : String(error)}`);
|
|
177
|
+
}));
|
|
178
|
+
const models = Array.isArray(payload.data) ? payload.data.map(record) : [];
|
|
179
|
+
const model = models.find(item => [item.id, item.agent_slug, item.remote_slug].includes(modelId));
|
|
180
|
+
const contract = record(model?.native_reasoning);
|
|
181
|
+
const supported = Array.isArray(contract.parameters) ? contract.parameters : [];
|
|
182
|
+
if (contract.transport_version !== 1 || parameters.some(parameter => !supported.includes(parameter))) {
|
|
183
|
+
throw new NativeReasoningTransportError(`Native reasoning transport is unavailable for ${modelId}; upgrade the mSwarm proxy and selected node, or remove unsupported native reasoning settings from the configuration`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
export class ConfiguredProvider {
|
|
188
|
+
constructor(resolved, binding = "lead", options = {}) {
|
|
189
|
+
this.resolved = resolved;
|
|
190
|
+
this.binding = binding;
|
|
191
|
+
this.options = options;
|
|
192
|
+
this.name = "configured";
|
|
193
|
+
this.supportsToolCalls = true;
|
|
194
|
+
this.clients = new Map();
|
|
195
|
+
this.caller = normalizeModelCaller(options.caller);
|
|
196
|
+
this.credentials = Object.freeze(Object.assign(Object.create(null), options.credentials));
|
|
197
|
+
for (const [id, credential] of Object.entries(this.credentials)) {
|
|
198
|
+
if (!Object.prototype.hasOwnProperty.call(resolved.config.providers, id) || typeof credential !== "string" || !credential.trim())
|
|
199
|
+
throw new Error("Invalid host provider credential mapping");
|
|
200
|
+
registerSecretValue(credential);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
client(providerId) {
|
|
204
|
+
const provider = this.resolved.config.providers[providerId];
|
|
205
|
+
if (!provider)
|
|
206
|
+
throw new Error(`Unknown configured provider: ${providerId}`);
|
|
207
|
+
if (!this.clients.has(providerId))
|
|
208
|
+
this.clients.set(providerId, new ModelServiceClient(provider, this.credentials[providerId], this.caller));
|
|
209
|
+
return this.clients.get(providerId);
|
|
210
|
+
}
|
|
211
|
+
async select(operation, signal, requireTools = false) {
|
|
212
|
+
const candidates = resolveBinding(this.resolved.config, this.binding, operation);
|
|
213
|
+
const reasons = [];
|
|
214
|
+
for (const candidate of candidates) {
|
|
215
|
+
const { id, model } = candidate;
|
|
216
|
+
const catalog = await this.client(model.provider).catalog(signal);
|
|
217
|
+
const actual = catalog.find(entry => entry.aliases.includes(model.catalogId));
|
|
218
|
+
if (!actual) {
|
|
219
|
+
reasons.push(`${id}: not entitled/advertised`);
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
if (!["healthy", "unknown", "ready"].includes(actual.health)) {
|
|
223
|
+
reasons.push(`${id}: ${actual.health}`);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (model.backend && actual.backend !== model.backend) {
|
|
227
|
+
reasons.push(`${id}: backend identity not verified`);
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
if (actual.operations.length && !actual.operations.includes(operation)) {
|
|
231
|
+
reasons.push(`${id}: unsupported operation`);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (requireTools && (!model.supportsTools || this.resolved.config.providers[model.provider].adapter === "mswarm" && !actual.supportsTools)) {
|
|
235
|
+
reasons.push(`${id}: tools unavailable`);
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
return { id, model, actual, provider: this.resolved.config.providers[model.provider] };
|
|
239
|
+
}
|
|
240
|
+
throw new Error(`No eligible configured ${this.binding} route: ${reasons.join("; ")}`);
|
|
241
|
+
}
|
|
242
|
+
async generate(request) {
|
|
243
|
+
request.signal?.throwIfAborted();
|
|
244
|
+
const requestId = request.requestId ?? randomUUID();
|
|
245
|
+
if (typeof requestId !== "string" || !/^[a-f0-9]{8}-[a-f0-9]{4}-[1-8][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i.test(requestId)) {
|
|
246
|
+
throw new Error("Model requestId must be a UUID for this inference attempt");
|
|
247
|
+
}
|
|
248
|
+
const { id, model, provider, actual } = await this.select("chat.completions", request.signal, !!request.tools?.length);
|
|
249
|
+
const invocation = { id: requestId, binding: this.binding, configHash: this.resolved.hash, modelId: id, catalogId: model.catalogId, backend: actual.backend, host: model.host };
|
|
250
|
+
const nativeReasoning = this.options.effort ? model.reasoning?.[this.options.effort] : undefined;
|
|
251
|
+
if (nativeReasoning)
|
|
252
|
+
invocation.nativeReasoningRequest = { ...nativeReasoning };
|
|
253
|
+
if (nativeReasoning)
|
|
254
|
+
await this.client(model.provider).requireNativeReasoning(model.catalogId, Object.keys(nativeReasoning), request.signal);
|
|
255
|
+
const maxTokens = Math.min(request.maxTokens ?? model.maxOutputTokens, model.maxOutputTokens);
|
|
256
|
+
const inputEstimate = Math.ceil(JSON.stringify([request.messages, request.tools]).length / 3);
|
|
257
|
+
if (inputEstimate + maxTokens > Math.min(model.contextWindow, actual.contextWindow ?? model.contextWindow))
|
|
258
|
+
throw new Error("Context budget exceeded; checkpoint and compact before continuing");
|
|
259
|
+
const bounded = { ...request, requestId, maxTokens, stream: request.stream === true && model.supportsStreaming === true };
|
|
260
|
+
await this.options.beforeRequest?.(invocation, bounded);
|
|
261
|
+
const adapter = new OpenAiCompatibleProvider({
|
|
262
|
+
model: model.catalogId, baseUrl: provider.baseUrl, apiKey: this.credentials[model.provider] ?? await providerCredential(provider), timeoutMs: 300000,
|
|
263
|
+
supportsStreaming: model.supportsStreaming ?? true, supportsTools: model.supportsTools,
|
|
264
|
+
headers: provider.adapter === "mswarm" ? { ...modelCallerHeaders(this.caller), "x-request-id": requestId } : undefined, retryTransient: false,
|
|
265
|
+
extraBody: nativeReasoning,
|
|
266
|
+
});
|
|
267
|
+
const result = await adapter.generate(bounded);
|
|
268
|
+
await this.options.afterRequest?.(invocation, result);
|
|
269
|
+
return { ...result, route: invocation };
|
|
270
|
+
}
|
|
271
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type ModelServiceErrorCode = "authentication_failed" | "entitlement_missing" | "quota_exhausted" | "rate_limited" | "service_unavailable" | "model_unavailable" | "invalid_request" | "invalid_response" | "context_length_exceeded";
|
|
2
|
+
/** Transport diagnostics contain stable classifications, never an upstream body. */
|
|
3
|
+
export declare class ModelServiceError extends Error {
|
|
4
|
+
readonly code: ModelServiceErrorCode;
|
|
5
|
+
readonly status: number;
|
|
6
|
+
readonly retryAfterSeconds?: number | undefined;
|
|
7
|
+
/** Set by Runner, not inferred from an HTTP status or upstream payload. */
|
|
8
|
+
completedModelCalls?: number;
|
|
9
|
+
constructor(code: ModelServiceErrorCode, status: number, retryAfterSeconds?: number | undefined);
|
|
10
|
+
/** A relay may already have sent HTTP 200 headers when the model fails. */
|
|
11
|
+
static fromRelayError(error: unknown): ModelServiceError | undefined;
|
|
12
|
+
static fromResponse(response: Response): Promise<ModelServiceError>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=ModelServiceError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModelServiceError.d.ts","sourceRoot":"","sources":["../../src/providers/ModelServiceError.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG,uBAAuB,GAAG,qBAAqB,GAAG,iBAAiB,GAAG,cAAc,GAAG,qBAAqB,GAAG,mBAAmB,GAAG,iBAAiB,GAAG,kBAAkB,GAAG,yBAAyB,CAAC;AAU5O,oFAAoF;AACpF,qBAAa,iBAAkB,SAAQ,KAAK;IAG9B,QAAQ,CAAC,IAAI,EAAE,qBAAqB;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM;IAAE,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM;IAF9G,2EAA2E;IAC3E,mBAAmB,CAAC,EAAE,MAAM,CAAC;gBACR,IAAI,EAAE,qBAAqB,EAAW,MAAM,EAAE,MAAM,EAAW,iBAAiB,CAAC,EAAE,MAAM,YAAA;IAK9G,2EAA2E;IAC3E,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,iBAAiB,GAAG,SAAS;WAOvD,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAyB1E"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
function nativeContextRefusal(error) {
|
|
2
|
+
if (error.type !== "invalid_request_error" || typeof error.message !== "string" || error.message.length > 1024)
|
|
3
|
+
return false;
|
|
4
|
+
// Strata currently emits this pre-generation refusal without a machine code.
|
|
5
|
+
// Match only its bounded numeric diagnostics; never retain prompt text.
|
|
6
|
+
return /^request exceeds the context window: prompt \(\d{1,10} tokens\) leaves no room to answer in the context \(\d{1,10}\); requests are never truncated$/.test(error.message)
|
|
7
|
+
|| /^request exceeds the context window: prompt \(\d{1,10} tokens\) \+ max tokens \(\d{1,10}\) exceeds the context \(\d{1,10}\); requests are never truncated\. Send a smaller max_tokens \(at most \d{1,10} here\), or add "fit_max_tokens": true to the model's strata-<model>\.json to shorten it to the room left \(#545\)$/.test(error.message);
|
|
8
|
+
}
|
|
9
|
+
/** Transport diagnostics contain stable classifications, never an upstream body. */
|
|
10
|
+
export class ModelServiceError extends Error {
|
|
11
|
+
constructor(code, status, retryAfterSeconds) {
|
|
12
|
+
super(`Model service HTTP ${status}: ${code}${code === "authentication_failed" ? "; authenticate with codali login" : code === "context_length_exceeded" ? "; checkpoint and reduce context before continuing" : ""}`);
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.status = status;
|
|
15
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
16
|
+
this.name = "ModelServiceError";
|
|
17
|
+
}
|
|
18
|
+
/** A relay may already have sent HTTP 200 headers when the model fails. */
|
|
19
|
+
static fromRelayError(error) {
|
|
20
|
+
if (!error || typeof error !== "object")
|
|
21
|
+
return undefined;
|
|
22
|
+
const code = error.code;
|
|
23
|
+
if (code === "context_length_exceeded" || code === "invalid_response")
|
|
24
|
+
return new ModelServiceError(code, 200);
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
static async fromResponse(response) {
|
|
28
|
+
let serverCode = "";
|
|
29
|
+
let contextRefused = false;
|
|
30
|
+
if (response.body) {
|
|
31
|
+
const reader = response.body.getReader();
|
|
32
|
+
const chunks = [];
|
|
33
|
+
let bytes = 0;
|
|
34
|
+
try {
|
|
35
|
+
while (true) {
|
|
36
|
+
const part = await reader.read();
|
|
37
|
+
if (part.done)
|
|
38
|
+
break;
|
|
39
|
+
bytes += part.value.byteLength;
|
|
40
|
+
if (bytes > 8192)
|
|
41
|
+
break;
|
|
42
|
+
chunks.push(part.value);
|
|
43
|
+
}
|
|
44
|
+
const payload = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
45
|
+
if (typeof (payload.error?.code ?? payload.code) === "string")
|
|
46
|
+
serverCode = String(payload.error?.code ?? payload.code);
|
|
47
|
+
contextRefused = response.status === 400 && (serverCode === "context_length_exceeded"
|
|
48
|
+
|| !!payload.error && nativeContextRefusal(payload.error));
|
|
49
|
+
}
|
|
50
|
+
catch { /* The status still supplies a safe classification. */ }
|
|
51
|
+
finally {
|
|
52
|
+
await reader.cancel().catch(() => undefined);
|
|
53
|
+
reader.releaseLock();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const code = response.status === 401 ? "authentication_failed"
|
|
57
|
+
: response.status === 403 ? "entitlement_missing"
|
|
58
|
+
: ["quota_exceeded", "quota_exhausted", "insufficient_quota", "credits_exhausted", "insufficient_credits"].includes(serverCode) || response.status === 402 ? "quota_exhausted"
|
|
59
|
+
: response.status === 429 ? "rate_limited"
|
|
60
|
+
: response.status === 404 ? "model_unavailable"
|
|
61
|
+
: contextRefused ? "context_length_exceeded"
|
|
62
|
+
: serverCode === "structured_output_failed" ? "invalid_response"
|
|
63
|
+
: response.status >= 500 ? "service_unavailable" : "invalid_request";
|
|
64
|
+
const retry = Number(response.headers.get("retry-after"));
|
|
65
|
+
return new ModelServiceError(code, response.status, response.headers.has("retry-after") && Number.isFinite(retry) && retry >= 0 ? Math.min(retry, 3600) : undefined);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MswarmWorkerProvider.d.ts","sourceRoot":"","sources":["../../src/providers/MswarmWorkerProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EAER,eAAe,EACf,gBAAgB,EAEjB,MAAM,oBAAoB,CAAC;AA8C5B,qBAAa,oBAAqB,YAAW,QAAQ;IAQvC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAPnC,+EAA+E;IAC/E,QAAQ,CAAC,iBAAiB,SAAS;IAEnC,QAAQ,CAAC,IAAI,mBAAmB;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEH,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE;IAWvG,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"MswarmWorkerProvider.d.ts","sourceRoot":"","sources":["../../src/providers/MswarmWorkerProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EAER,eAAe,EACf,gBAAgB,EAEjB,MAAM,oBAAoB,CAAC;AA8C5B,qBAAa,oBAAqB,YAAW,QAAQ;IAQvC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAPnC,+EAA+E;IAC/E,QAAQ,CAAC,iBAAiB,SAAS;IAEnC,QAAQ,CAAC,IAAI,mBAAmB;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEH,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE;IAWvG,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAmEpE"}
|
|
@@ -52,7 +52,10 @@ export class MswarmWorkerProvider {
|
|
|
52
52
|
this.apiKey = config.apiKey;
|
|
53
53
|
}
|
|
54
54
|
async generate(request) {
|
|
55
|
+
request.signal?.throwIfAborted();
|
|
55
56
|
const controller = new AbortController();
|
|
57
|
+
const onAbort = () => controller.abort(request.signal?.reason);
|
|
58
|
+
request.signal?.addEventListener("abort", onAbort, { once: true });
|
|
56
59
|
const timeout = this.config.timeoutMs && this.config.timeoutMs > 0
|
|
57
60
|
? setTimeout(() => controller.abort(), this.config.timeoutMs)
|
|
58
61
|
: undefined;
|
|
@@ -106,6 +109,7 @@ export class MswarmWorkerProvider {
|
|
|
106
109
|
};
|
|
107
110
|
}
|
|
108
111
|
finally {
|
|
112
|
+
request.signal?.removeEventListener("abort", onAbort);
|
|
109
113
|
if (timeout) {
|
|
110
114
|
clearTimeout(timeout);
|
|
111
115
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAiCompatibleProvider.d.ts","sourceRoot":"","sources":["../../src/providers/OpenAiCompatibleProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"OpenAiCompatibleProvider.d.ts","sourceRoot":"","sources":["../../src/providers/OpenAiCompatibleProvider.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EAEd,eAAe,EACf,gBAAgB,EAGjB,MAAM,oBAAoB,CAAC;AAkK5B,eAAO,MAAM,uBAAuB,GAClC,KAAK,MAAM,EACX,MAAM,WAAW,EACjB,aAAa,eAAe,KAC3B,OAAO,CAAC,QAAQ,CAclB,CAAC;AAEF,qBAAa,wBAAyB,YAAW,QAAQ;IAS3C,OAAO,CAAC,MAAM;IAR1B,+EAA+E;IAC/E,QAAQ,CAAC,iBAAiB,QAAQ;IAElC,IAAI,SAAuB;IAC3B,OAAO,CAAC,WAAW,CAAoC;IACvD,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,sBAAsB,CAAoC;gBAE9C,MAAM,EAAE,cAAc;IAWpC,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAwPnE,OAAO,CAAC,WAAW;CA0BpB"}
|