maka-agent 0.2.0-dev.22.20260905 → 0.2.0-dev.24.20260907
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/acp/maka-acp-agent.js +2 -1
- package/dist/acp/session-configuration.js +143 -0
- package/dist/acp/session-registry.js +90 -4
- package/dist/cli-core.js +2 -0
- package/dist/pi-transcript.js +5 -12
- package/dist/pi-tui-runner.js +74 -4
- package/dist/runtime-host-cli-context.js +167 -78
- package/dist/runtime-host-cli-installation.js +8 -2
- package/dist/runtime-host-cli.js +31 -1
- package/dist/runtime-host-handoff-surface.js +81 -0
- package/dist/runtime-host-installed-update-bootstrap.js +13 -0
- package/dist/runtime-host-installed-update-coordinator.js +33 -0
- package/dist/runtime-host-lifecycle-transaction.js +9 -1
- package/dist/runtime-host-local-handoff.js +37 -4
- package/dist/runtime-host-local-managed-activation.js +84 -0
- package/dist/runtime-host-local-source-retirement.js +18 -2
- package/dist/runtime-host-managed-lifecycle-manager.js +1 -0
- package/dist/runtime-host-operator-retirement.js +50 -0
- package/dist/runtime-host-service-manager.js +3 -0
- package/dist/runtime-host-session-driver.js +4 -25
- package/dist/runtime-host-session-update.js +62 -0
- package/dist/runtime-host-tui-command.js +38 -73
- package/dist/runtime-host-tui-context.js +1 -0
- package/dist/runtime-host-tui-owner.js +226 -0
- package/dist/tui-copy-catalog.js +140 -3
- package/dist/tui-host-owner-copy.js +24 -0
- package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/core/dist/bot-events.js +18 -63
- package/node_modules/@maka/core/dist/canonical-runtime-event.js +3 -1
- package/node_modules/@maka/core/dist/model-call-attempt.js +0 -82
- package/node_modules/@maka/core/dist/model-call-usage-projection.js +0 -186
- package/node_modules/@maka/core/dist/model-failure.js +40 -0
- package/node_modules/@maka/core/dist/model-metadata.generated.js +4 -4
- package/node_modules/@maka/core/dist/model-metadata.js +3 -3
- package/node_modules/@maka/core/dist/model-web-search.js +5 -4
- package/node_modules/@maka/core/dist/provider-registry.js +45 -4
- package/node_modules/@maka/core/dist/record-schema.js +22 -2
- package/node_modules/@maka/core/dist/redaction.js +41 -58
- package/node_modules/@maka/core/dist/runtime-boundary.js +31 -11
- package/node_modules/@maka/core/dist/runtime-event.js +37 -6
- package/node_modules/@maka/core/dist/runtime-handoff.js +98 -0
- package/node_modules/@maka/core/dist/runtime-invocation.js +1 -1
- package/node_modules/@maka/core/dist/runtime-logical-execution.js +112 -0
- package/node_modules/@maka/core/dist/session-trace.js +5 -1
- package/node_modules/@maka/core/dist/session.js +54 -52
- package/node_modules/@maka/core/dist/slash-command-catalog.js +2 -0
- package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +20 -0
- package/node_modules/@maka/core/dist/usage-ledger-merge.js +7 -9
- package/node_modules/@maka/core/dist/usage-record-schema.js +26 -35
- package/node_modules/@maka/core/dist/workhub-creation-intent.js +34 -20
- package/node_modules/@maka/core/package.json +4 -0
- package/node_modules/@maka/eval/harbor/egress-proxy/entrypoint.sh +2 -1
- package/node_modules/@maka/mcp/dist/index.js +131 -1
- package/node_modules/@maka/runtime/dist/agent-run.js +272 -105
- package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +13 -5
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +109 -34
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +155 -134
- package/node_modules/@maka/runtime/dist/bots/base-adapter.js +17 -0
- package/node_modules/@maka/runtime/dist/bots/bot-test.js +38 -22
- package/node_modules/@maka/runtime/dist/bots/dingtalk-bridge.js +7 -5
- package/node_modules/@maka/runtime/dist/bots/discord-bridge.js +4 -4
- package/node_modules/@maka/runtime/dist/bots/feishu-bridge.js +4 -5
- package/node_modules/@maka/runtime/dist/bots/qq-bridge.js +6 -4
- package/node_modules/@maka/runtime/dist/bots/slack-bridge.js +3 -4
- package/node_modules/@maka/runtime/dist/bots/telegram-bridge.js +4 -5
- package/node_modules/@maka/runtime/dist/bots/wechat-bridge.js +17 -19
- package/node_modules/@maka/runtime/dist/bots/wecom-bridge.js +5 -6
- package/node_modules/@maka/runtime/dist/bots/ws-bridge-base.js +2 -3
- package/node_modules/@maka/runtime/dist/context-budget.js +14 -9
- package/node_modules/@maka/runtime/dist/conversation-copy.js +5 -4
- package/node_modules/@maka/runtime/dist/goal-continuation.js +36 -4
- package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +18 -9
- package/node_modules/@maka/runtime/dist/history-compact-summarizer.js +30 -22
- package/node_modules/@maka/runtime/dist/history-compaction.js +29 -4
- package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +106 -0
- package/node_modules/@maka/runtime/dist/message-authority.js +9 -0
- package/node_modules/@maka/runtime/dist/model-adapter.js +19 -98
- package/node_modules/@maka/runtime/dist/model-factory.js +19 -81
- package/node_modules/@maka/runtime/dist/model-fetcher.js +7 -0
- package/node_modules/@maka/runtime/dist/model-runtime.js +85 -111
- package/node_modules/@maka/runtime/dist/native-web-search-tool.js +2 -1
- package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +2 -2
- package/node_modules/@maka/runtime/dist/opencode-session-header.js +4 -2
- package/node_modules/@maka/runtime/dist/provider-error-classification.js +84 -123
- package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +68 -108
- package/node_modules/@maka/runtime/dist/run-handoff-gate.js +97 -0
- package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +82 -54
- package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +117 -159
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +150 -112
- package/node_modules/@maka/runtime/dist/runtime-ledger-repair.js +160 -79
- package/node_modules/@maka/runtime/dist/runtime-read-model.js +30 -89
- package/node_modules/@maka/runtime/dist/runtime-resume.js +80 -4
- package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +5 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +171 -288
- package/node_modules/@maka/runtime/dist/session-projection-helpers.js +0 -27
- package/node_modules/@maka/runtime/dist/session-trace-projection.js +3 -30
- package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +3 -4
- package/node_modules/@maka/runtime/dist/test-connection.js +16 -16
- package/node_modules/@maka/runtime/dist/tool-result-archive-encoding.js +38 -0
- package/node_modules/@maka/runtime/dist/tool-runtime.js +3 -61
- package/node_modules/@maka/runtime/package.json +1 -0
- package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +35 -0
- package/node_modules/@maka/runtime-host/dist/candidate-entry.js +4 -1
- package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +9 -1
- package/node_modules/@maka/runtime-host/dist/client/connection.js +3 -0
- package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +156 -0
- package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +273 -0
- package/node_modules/@maka/runtime-host/dist/client/host-retirement.js +26 -5
- package/node_modules/@maka/runtime-host/dist/client/index.js +3 -1
- package/node_modules/@maka/runtime-host/dist/client/launcher.js +3 -0
- package/node_modules/@maka/runtime-host/dist/client/peer-client.js +13 -0
- package/node_modules/@maka/runtime-host/dist/client/registered-host-termination.js +0 -59
- package/node_modules/@maka/runtime-host/dist/client/remote-compatibility-error.js +2 -0
- package/node_modules/@maka/runtime-host/dist/client/session-subscription.js +27 -5
- package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
- package/node_modules/@maka/runtime-host/dist/operator/retirement-cancellation.js +20 -0
- package/node_modules/@maka/runtime-host/dist/peer-mesh/node.js +28 -16
- package/node_modules/@maka/runtime-host/dist/protocol/external-session.js +4 -0
- package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +29 -12
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +37 -1
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +2 -0
- package/node_modules/@maka/runtime-host/dist/protocol/session-collaboration.js +28 -1
- package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +40 -20
- package/node_modules/@maka/runtime-host/dist/protocol/session-transcript.js +0 -5
- package/node_modules/@maka/runtime-host/dist/protocol/session-turns.js +29 -58
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +11 -1
- package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +33 -0
- package/node_modules/@maka/runtime-host/dist/server/access-authority.js +26 -1
- package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +6 -1
- package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +19 -4
- package/node_modules/@maka/runtime-host/dist/server/canonical-usage-reader.js +24 -11
- package/node_modules/@maka/runtime-host/dist/server/connection-session.js +7 -6
- package/node_modules/@maka/runtime-host/dist/server/daily-review-coordinator.js +7 -4
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +168 -28
- package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +5 -5
- package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +3 -2
- package/node_modules/@maka/runtime-host/dist/server/external-session-coordinator.js +6 -3
- package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +40 -1
- package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +108 -23
- package/node_modules/@maka/runtime-host/dist/server/host-residency-registry.js +13 -7
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-admission-registry.js +3 -1
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +124 -62
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +85 -8
- package/node_modules/@maka/runtime-host/dist/server/root-admission-owner.js +7 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +344 -71
- package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +37 -2
- package/node_modules/@maka/runtime-host/dist/server/serial-outbound-writer.js +45 -3
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +201 -12
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +87 -25
- package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +8 -55
- package/node_modules/@maka/runtime-host/dist/server/session-sidecar-purge.js +1 -16
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +0 -1
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +460 -70
- package/node_modules/@maka/runtime-host/dist/server/shared-session-transcript.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/storage-maintenance.js +109 -0
- package/node_modules/@maka/runtime-host/dist/server/usage-pricing-coordinator.js +4 -11
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +44 -15
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +6 -2
- package/node_modules/@maka/storage/dist/agent-run-store.js +44 -0
- package/node_modules/@maka/storage/dist/artifact-store.js +21 -10
- package/node_modules/@maka/storage/dist/artifact-stores.js +1 -1
- package/node_modules/@maka/storage/dist/claude-code-session-adapter.js +0 -4
- package/node_modules/@maka/storage/dist/codex-session-adapter.js +0 -2
- package/node_modules/@maka/storage/dist/context-offload-snapshot.js +325 -0
- package/node_modules/@maka/storage/dist/conversation-operational-state.js +4 -0
- package/node_modules/@maka/storage/dist/execution-stores.js +11 -7
- package/node_modules/@maka/storage/dist/file-session-repository.js +1012 -0
- package/node_modules/@maka/storage/dist/model-call-ledger.js +199 -32
- package/node_modules/@maka/storage/dist/model-call-usage-sql.js +136 -0
- package/node_modules/@maka/storage/dist/opencode-session-adapter.js +0 -4
- package/node_modules/@maka/storage/dist/operational-state-backup.js +9 -5
- package/node_modules/@maka/storage/dist/operational-state-store-public.js +1 -1
- package/node_modules/@maka/storage/dist/operational-state-store.js +5 -3
- package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
- package/node_modules/@maka/storage/dist/runtime-transcript-query.js +308 -0
- package/node_modules/@maka/storage/dist/session-bundle-policy.js +24 -4
- package/node_modules/@maka/storage/dist/session-message-projection.js +15 -0
- package/node_modules/@maka/storage/dist/session-repository.js +767 -0
- package/node_modules/@maka/storage/dist/session-store.js +25 -99
- package/node_modules/@maka/storage/dist/sqlite-artifact-metadata.js +10 -3
- package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +24 -8
- package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +17 -1
- package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +44 -1
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +129 -25
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +109 -892
- package/node_modules/@maka/storage/dist/sqlite-usage-schema.js +200 -20
- package/node_modules/@maka/storage/dist/tool-result-archive-evidence.js +111 -0
- package/node_modules/@maka/storage/dist/usage-stores.js +6 -2
- package/node_modules/@maka/storage/package.json +2 -0
- package/package.json +1 -1
|
@@ -17,59 +17,54 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
import { PROVIDER_REGISTRY, effectiveBaseUrl, } from '@maka/core/llm-connections';
|
|
20
|
-
import { lookupModelMetadata,
|
|
20
|
+
import { lookupModelMetadata, lookupModelRuntimeOverride, openAiAdapterApiProtocol, } from '@maka/core/model-metadata';
|
|
21
21
|
import { isRetiredProvider } from '@maka/core/provider-registry';
|
|
22
|
+
import { anthropicV1BaseUrl, googleV1BetaBaseUrl, openAiResponsesBaseUrl, } from './provider-urls.js';
|
|
22
23
|
import { resolveApplyPatchProfile } from './apply-patch-profile.js';
|
|
23
24
|
import { resolveRuntimeProviderAdapter, runtimeProviderName, } from './provider-runtime-policy.js';
|
|
24
25
|
export function resolveModelRuntime(connection, modelId) {
|
|
25
|
-
//
|
|
26
|
-
// so consulting it first would let a per-model entry hand a retired provider
|
|
27
|
-
// a working adapter and skip the `unavailable` refusal below entirely. No
|
|
28
|
-
// such entry exists today, but that table is generated from an external
|
|
29
|
-
// source — one row should not be able to undo a retirement.
|
|
26
|
+
// Model metadata cannot reactivate a retired provider.
|
|
30
27
|
if (isRetiredProvider(connection.providerType)) {
|
|
31
28
|
throw new Error(`"${connection.providerType}" is retired and can no longer resolve a model runtime.`);
|
|
32
29
|
}
|
|
33
|
-
const override =
|
|
30
|
+
const override = lookupModelRuntimeOverride(connection.providerType, modelId);
|
|
34
31
|
const defaults = PROVIDER_REGISTRY[connection.providerType];
|
|
35
|
-
// Unknown providerType with no per-model override → can't resolve an adapter.
|
|
36
|
-
// Throw a clear error rather than crashing on `.runtimeAdapter`. Mirrors
|
|
37
|
-
// `isRealConnection` in @maka/core/connection-readiness.ts.
|
|
38
32
|
if (!override && !defaults) {
|
|
39
33
|
throw new Error(`Unknown provider type "${connection.providerType}"; cannot resolve model runtime.`);
|
|
40
34
|
}
|
|
41
35
|
const apiProtocol = connection.models?.find((model) => model.id === modelId)?.apiProtocol;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const adapter = resolveRuntimeProviderAdapter(baseAdapter);
|
|
36
|
+
const baseAdapter = resolveRuntimeProviderAdapter(override?.adapter ?? defaults.runtimeAdapter);
|
|
37
|
+
const calls = adapterCalls(baseAdapter);
|
|
38
|
+
const preferred = openAiAdapterApiProtocol(modelId, connection.providerType);
|
|
39
|
+
const defaultCall = calls.find((call) => call.wire === preferred) ?? calls[0];
|
|
40
|
+
const declared = apiProtocol ? defaults.protocolAdapters?.[apiProtocol] : undefined;
|
|
41
|
+
const call = apiProtocol === undefined
|
|
42
|
+
? defaultCall
|
|
43
|
+
: (calls.find((candidate) => candidate.wire === apiProtocol) ??
|
|
44
|
+
(declared
|
|
45
|
+
? adapterCalls(resolveRuntimeProviderAdapter(declared)).find((candidate) => candidate.wire === apiProtocol)
|
|
46
|
+
: undefined) ??
|
|
47
|
+
adapterCalls(resolveRuntimeProviderAdapter(defaults.runtimeAdapter)).find((candidate) => candidate.wire === apiProtocol));
|
|
48
|
+
if (!call)
|
|
49
|
+
throw new Error(`${defaults.label} does not support ${apiProtocol} for model ${modelId}`);
|
|
50
|
+
const { adapter, wire, reasoningReplay: replay } = call;
|
|
58
51
|
const configuredBaseUrl = connection.baseUrl?.trim();
|
|
59
52
|
const resolvedBaseUrl = configuredBaseUrl
|
|
60
53
|
? effectiveBaseUrl(connection)
|
|
61
|
-
: (override?.
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
: ((calls.includes(call) ? override?.baseUrl : undefined) ?? effectiveBaseUrl(connection));
|
|
55
|
+
const baseUrl = adapter.kind === 'anthropic' && adapter.normalizeBaseUrl
|
|
56
|
+
? anthropicV1BaseUrl(resolvedBaseUrl)
|
|
57
|
+
: adapter.kind === 'google' && adapter.normalizeBaseUrl !== false
|
|
58
|
+
? googleV1BetaBaseUrl(resolvedBaseUrl)
|
|
59
|
+
: adapter.kind === 'openai-compatible' && adapter.normalizeBaseUrl
|
|
60
|
+
? anthropicV1BaseUrl(resolvedBaseUrl)
|
|
61
|
+
: wire === 'openai-responses' && resolvedBaseUrl
|
|
62
|
+
? openAiResponsesBaseUrl(resolvedBaseUrl)
|
|
63
|
+
: resolvedBaseUrl;
|
|
64
|
+
const parallelToolCalls = resolveParallelToolCalls(connection, modelId, baseAdapter);
|
|
65
65
|
return {
|
|
66
|
-
|
|
67
|
-
baseUrl
|
|
68
|
-
? kimiOpenAiBaseUrl(resolvedBaseUrl)
|
|
69
|
-
: resolvedBaseUrl,
|
|
70
|
-
...(apiProtocol ? { apiProtocol } : {}),
|
|
71
|
-
wire,
|
|
72
|
-
reasoningReplay: replay,
|
|
66
|
+
...call,
|
|
67
|
+
baseUrl,
|
|
73
68
|
...(parallelToolCalls === undefined ? {} : { parallelToolCalls }),
|
|
74
69
|
...(replay.kind === 'responses' &&
|
|
75
70
|
replay.contract.adapter === 'open-responses' &&
|
|
@@ -99,88 +94,67 @@ function resolveParallelToolCalls(connection, modelId, adapter) {
|
|
|
99
94
|
// they require an explicit model declaration instead of inheriting this.
|
|
100
95
|
return adapter.kind === 'openai' || adapter.kind === 'openai-codex' ? true : undefined;
|
|
101
96
|
}
|
|
102
|
-
export function modelUsesAnthropicMessages(connection, modelId) {
|
|
103
|
-
return resolveModelRuntime(connection, modelId).wire === 'anthropic-messages';
|
|
104
|
-
}
|
|
105
97
|
/** Native OpenAI lanes keep mutable continuation state inside ModelAdapter. */
|
|
106
98
|
export function modelUsesNativeOpenAiResponses(connection, modelId) {
|
|
107
99
|
return (connection.providerType === 'openai' &&
|
|
108
100
|
resolveModelRuntime(connection, modelId).wire === 'openai-responses');
|
|
109
101
|
}
|
|
110
|
-
function
|
|
102
|
+
function adapterCalls(adapter) {
|
|
111
103
|
switch (adapter.kind) {
|
|
112
104
|
case 'anthropic':
|
|
113
|
-
return
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
// pickers filtering it out; failing here beats sending on a wire we
|
|
117
|
-
// cannot name.
|
|
118
|
-
throw new Error('This provider has no Runtime adapter and cannot resolve a wire.');
|
|
119
|
-
case 'openai-codex':
|
|
120
|
-
return 'openai-responses';
|
|
121
|
-
case 'github-copilot':
|
|
122
|
-
return apiProtocol === 'anthropic-messages'
|
|
123
|
-
? 'anthropic-messages'
|
|
124
|
-
: apiProtocol === 'openai-responses'
|
|
125
|
-
? 'openai-responses'
|
|
126
|
-
: 'openai-chat';
|
|
127
|
-
case 'openai':
|
|
128
|
-
return (adapter.apiProtocol ??
|
|
129
|
-
apiProtocol ??
|
|
130
|
-
openAiAdapterApiProtocol(modelId, providerType)) === 'openai-responses'
|
|
131
|
-
? 'openai-responses'
|
|
132
|
-
: 'openai-chat';
|
|
133
|
-
case 'openai-compatible':
|
|
134
|
-
return adapter.responses !== undefined &&
|
|
135
|
-
(apiProtocol ?? openAiAdapterApiProtocol(modelId, providerType)) === 'openai-responses'
|
|
136
|
-
? 'openai-responses'
|
|
137
|
-
: 'openai-chat';
|
|
105
|
+
return [
|
|
106
|
+
{ adapter, wire: 'anthropic-messages', reasoningReplay: { kind: 'anthropic-signed' } },
|
|
107
|
+
];
|
|
138
108
|
case 'google':
|
|
139
|
-
return 'google-generate';
|
|
109
|
+
return [{ adapter, wire: 'google-generate', reasoningReplay: { kind: 'none' } }];
|
|
140
110
|
case 'cohere':
|
|
141
|
-
return 'cohere-v2';
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
111
|
+
return [{ adapter, wire: 'cohere-v2', reasoningReplay: { kind: 'none' } }];
|
|
112
|
+
case 'openai-codex':
|
|
113
|
+
return [
|
|
114
|
+
{
|
|
115
|
+
adapter,
|
|
116
|
+
wire: 'openai-responses',
|
|
117
|
+
reasoningReplay: {
|
|
118
|
+
kind: 'responses',
|
|
119
|
+
contract: { adapter: 'openai', reasoningReplay: 'encrypted-content' },
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
];
|
|
123
|
+
case 'openai': {
|
|
124
|
+
const calls = [];
|
|
125
|
+
if (adapter.apiProtocol !== 'openai-responses')
|
|
126
|
+
calls.push({ adapter, wire: 'openai-chat', reasoningReplay: { kind: 'none' } });
|
|
127
|
+
if (adapter.apiProtocol !== 'openai-chat')
|
|
128
|
+
calls.push({
|
|
129
|
+
adapter,
|
|
130
|
+
wire: 'openai-responses',
|
|
131
|
+
reasoningReplay: {
|
|
132
|
+
kind: 'responses',
|
|
133
|
+
contract: { adapter: 'openai', reasoningReplay: 'encrypted-content' },
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
return calls;
|
|
137
|
+
}
|
|
138
|
+
case 'openai-compatible': {
|
|
139
|
+
const calls = [
|
|
140
|
+
{
|
|
141
|
+
adapter,
|
|
142
|
+
wire: 'openai-chat',
|
|
143
|
+
reasoningReplay: {
|
|
144
|
+
kind: 'openai-chat-plaintext',
|
|
145
|
+
requestField: adapter.replayAssistantReasoningAs ?? 'observed',
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
];
|
|
149
|
+
if (adapter.responses)
|
|
150
|
+
calls.push({
|
|
151
|
+
adapter,
|
|
152
|
+
wire: 'openai-responses',
|
|
153
|
+
reasoningReplay: { kind: 'responses', contract: adapter.responses },
|
|
154
|
+
});
|
|
155
|
+
return calls;
|
|
156
|
+
}
|
|
157
|
+
case 'unavailable':
|
|
158
|
+
throw new Error('This provider has no Runtime adapter and cannot resolve a wire.');
|
|
185
159
|
}
|
|
186
160
|
}
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import { z } from 'zod';
|
|
20
20
|
import { resolveHostedWebSearchCapability } from '@maka/core/model-web-search';
|
|
21
|
+
import { resolveModelRuntime } from './model-runtime.js';
|
|
21
22
|
export const NATIVE_WEB_SEARCH_TOOL_NAME = 'WebSearch';
|
|
22
23
|
/**
|
|
23
24
|
* Provider-executed search descriptor. AI SDK compiles this into the selected
|
|
@@ -61,7 +62,7 @@ export function routeWebSearchTools(input) {
|
|
|
61
62
|
: undefined;
|
|
62
63
|
}
|
|
63
64
|
else {
|
|
64
|
-
const capability = resolveHostedWebSearchCapability(input.connection.providerType, input.connection.models, input.model);
|
|
65
|
+
const capability = resolveHostedWebSearchCapability(input.connection.providerType, input.connection.models, input.model, resolveModelRuntime(input.connection, input.model).wire);
|
|
65
66
|
if ((firstSearchIndex >= 0 || input.allowAddNative === true) &&
|
|
66
67
|
capability?.implemented === true &&
|
|
67
68
|
capability.adapter === 'openai-responses') {
|
|
@@ -91,7 +91,7 @@ export function buildOpenAiCodexHistoryCompactor(options) {
|
|
|
91
91
|
catch (error) {
|
|
92
92
|
if (error instanceof HistoryCompactSummarizerError)
|
|
93
93
|
throw error;
|
|
94
|
-
if (classifyError(error) === '
|
|
94
|
+
if (classifyError(error) === 'context_overflow') {
|
|
95
95
|
throw new HistoryCompactSummarizerError('input_too_large', { cause: error });
|
|
96
96
|
}
|
|
97
97
|
throw new HistoryCompactSummarizerError('provider_error', { cause: error });
|
|
@@ -126,7 +126,7 @@ export function shouldFallbackFromOpenAiCodexHistoryCompaction(error, abortSigna
|
|
|
126
126
|
if (error.reason !== 'provider_error')
|
|
127
127
|
return false;
|
|
128
128
|
const diagnostic = providerFailureDiagnostic(error);
|
|
129
|
-
return diagnostic.errorClass === '
|
|
129
|
+
return diagnostic.errorClass === 'request_rejected' && !diagnostic.retryable;
|
|
130
130
|
}
|
|
131
131
|
function hasAbortCause(error) {
|
|
132
132
|
const seen = new Set();
|
|
@@ -17,11 +17,13 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
export const OPENCODE_SESSION_HEADER = 'x-opencode-session';
|
|
20
|
-
/** Adds OpenCode Go
|
|
20
|
+
/** Adds OpenCode Go/Free session identity without overriding an explicit header. */
|
|
21
21
|
export function withOpenCodeSessionHeader(providerType, sessionId, headers) {
|
|
22
22
|
const normalizedSessionId = sessionId?.trim();
|
|
23
|
-
if (providerType !== 'opencode-go'
|
|
23
|
+
if ((providerType !== 'opencode-go' && providerType !== 'opencode-free') ||
|
|
24
|
+
!normalizedSessionId) {
|
|
24
25
|
return headers;
|
|
26
|
+
}
|
|
25
27
|
if (Object.keys(headers ?? {}).some((name) => name.toLowerCase() === OPENCODE_SESSION_HEADER)) {
|
|
26
28
|
return headers;
|
|
27
29
|
}
|
|
@@ -17,8 +17,9 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
import { RetryError } from 'ai';
|
|
20
|
+
import { MODEL_FAILURE_MESSAGE_MAX_BYTES } from '@maka/core/model-failure';
|
|
20
21
|
import { truncateUtf8 } from '@maka/core/diagnostic-log';
|
|
21
|
-
import { isAuthenticationErrorText
|
|
22
|
+
import { isAuthenticationErrorText } from '@maka/core/redaction';
|
|
22
23
|
/**
|
|
23
24
|
* Structured provider error identifiers that mean the INPUT exceeded the
|
|
24
25
|
* model's context window. These come from the provider's error JSON and are
|
|
@@ -80,7 +81,6 @@ const USAGE_LIMIT_TEXT_PATTERNS = [
|
|
|
80
81
|
/(?:credit|balance|allowance)[^.]{0,40}(?:exhaust|reached)|exhaust[^.]{0,20}(?:credit|balance)/i,
|
|
81
82
|
/subscription/i,
|
|
82
83
|
];
|
|
83
|
-
const PROVIDER_FAILURE_SUMMARY_MAX_BYTES = 2 * 1024;
|
|
84
84
|
const PROVIDER_FAILURE_FIELD_MAX_BYTES = 256;
|
|
85
85
|
const MAX_SAFE_TIMER_DELAY_MS = 2_147_483_647;
|
|
86
86
|
const OPENAI_RESPONSES_WEBSOCKET_TRANSPORT_ERROR = 'OPENAI_RESPONSES_WEBSOCKET_TRANSPORT_ERROR';
|
|
@@ -153,13 +153,8 @@ function parseRetryAfterMs(headers) {
|
|
|
153
153
|
return null;
|
|
154
154
|
return Math.ceil(delayMs);
|
|
155
155
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
* response headers across the ModelAdapter boundary.
|
|
159
|
-
*/
|
|
160
|
-
export function providerRetryMetadata(error) {
|
|
161
|
-
const facts = normalizeProviderError(error);
|
|
162
|
-
if (!facts)
|
|
156
|
+
function retryMetadataFromFacts(facts, errorClass = classifyProviderFacts(facts)) {
|
|
157
|
+
if (facts.aborted)
|
|
163
158
|
return { retryable: false };
|
|
164
159
|
const { evidence } = facts;
|
|
165
160
|
if (RUNTIME_RETRYABLE_ERROR_CODES.has(evidence.code))
|
|
@@ -169,9 +164,8 @@ export function providerRetryMetadata(error) {
|
|
|
169
164
|
if (isTrustedCodexEdgeRejection(facts))
|
|
170
165
|
return { retryable: false };
|
|
171
166
|
const status = Number(evidence.statusCode || evidence.code);
|
|
172
|
-
const errorClass = classifyProviderFacts(facts);
|
|
173
167
|
const retryAfterMs = parseRetryAfterMs(facts.responseHeaders ?? {});
|
|
174
|
-
if (errorClass === '
|
|
168
|
+
if (errorClass === 'provider_capacity') {
|
|
175
169
|
// Capacity is transient even when the provider sends a malformed delay;
|
|
176
170
|
// fall back to the adapter's bounded local backoff in that case.
|
|
177
171
|
return {
|
|
@@ -179,13 +173,13 @@ export function providerRetryMetadata(error) {
|
|
|
179
173
|
...(retryAfterMs !== undefined && retryAfterMs !== null ? { retryAfterMs } : {}),
|
|
180
174
|
};
|
|
181
175
|
}
|
|
182
|
-
if (errorClass === '
|
|
176
|
+
if (errorClass === 'rate_limit' || status === 429) {
|
|
183
177
|
if (retryAfterMs === undefined || retryAfterMs === null)
|
|
184
178
|
return { retryable: false };
|
|
185
179
|
return { retryable: true, retryAfterMs };
|
|
186
180
|
}
|
|
187
|
-
const retryable = errorClass === '
|
|
188
|
-
errorClass === '
|
|
181
|
+
const retryable = errorClass === 'network' ||
|
|
182
|
+
errorClass === 'provider_unavailable' ||
|
|
189
183
|
status === 408 ||
|
|
190
184
|
status === 409 ||
|
|
191
185
|
(status >= 500 && status <= 599);
|
|
@@ -312,15 +306,7 @@ function normalizeProviderError(error) {
|
|
|
312
306
|
}
|
|
313
307
|
return undefined;
|
|
314
308
|
}
|
|
315
|
-
|
|
316
|
-
* Retains only allowlisted provider failure fields. The provider value may also
|
|
317
|
-
* contain request bodies, headers, or credentials, so it must never be copied
|
|
318
|
-
* or serialized as diagnostic output wholesale.
|
|
319
|
-
*/
|
|
320
|
-
export function providerFailureSummary(error) {
|
|
321
|
-
const facts = normalizeProviderError(error);
|
|
322
|
-
if (!facts)
|
|
323
|
-
return undefined;
|
|
309
|
+
function failureSummaryFromFacts(facts) {
|
|
324
310
|
const sources = facts.summarySources;
|
|
325
311
|
const message = firstProviderMessage(facts);
|
|
326
312
|
const code = firstProviderField(sources, ['code']) ?? firstProviderField(sources, ['type']);
|
|
@@ -335,41 +321,25 @@ export function providerFailureSummary(error) {
|
|
|
335
321
|
if (!message && metadata.length === 0)
|
|
336
322
|
return undefined;
|
|
337
323
|
const suffix = metadata.length > 0 ? ` (${metadata.join(', ')})` : '';
|
|
338
|
-
const messageBudget = Math.max(1,
|
|
339
|
-
const summary = `${truncateUtf8(
|
|
324
|
+
const messageBudget = Math.max(1, MODEL_FAILURE_MESSAGE_MAX_BYTES - Buffer.byteLength(suffix, 'utf8'));
|
|
325
|
+
const summary = `${truncateUtf8(message ?? 'Provider request failed', messageBudget, '…')}${suffix}`;
|
|
340
326
|
return {
|
|
341
|
-
message: truncateUtf8(summary,
|
|
327
|
+
message: truncateUtf8(summary, MODEL_FAILURE_MESSAGE_MAX_BYTES, '…'),
|
|
342
328
|
...(code || statusCode ? { code: code ?? statusCode } : {}),
|
|
343
329
|
};
|
|
344
330
|
}
|
|
345
|
-
const DURABLE_PROVIDER_ERROR_CLASSES = new Set([
|
|
346
|
-
'Abort',
|
|
347
|
-
'Auth',
|
|
348
|
-
'ContextLength',
|
|
349
|
-
'Network',
|
|
350
|
-
'ProviderCapacity',
|
|
351
|
-
'ProviderBilling',
|
|
352
|
-
'ProviderUnavailable',
|
|
353
|
-
'RateLimit',
|
|
354
|
-
'Timeout',
|
|
355
|
-
]);
|
|
356
331
|
/**
|
|
357
332
|
* Projects provider errors into a small durable fingerprint. Unlike the
|
|
358
333
|
* presentation summary, this intentionally excludes provider messages and
|
|
359
|
-
* response bodies:
|
|
334
|
+
* response bodies: free text can echo prompts or credentials.
|
|
360
335
|
*/
|
|
361
336
|
export function providerFailureDiagnostic(error) {
|
|
362
|
-
const facts =
|
|
337
|
+
const facts = extractProviderErrorFacts(error);
|
|
363
338
|
if (!facts)
|
|
364
|
-
return { errorClass: '
|
|
339
|
+
return { errorClass: 'unknown', retryable: false };
|
|
365
340
|
const sources = facts.summarySources;
|
|
366
|
-
const
|
|
367
|
-
const
|
|
368
|
-
const httpStatus = Number.isInteger(numericStatus) && numericStatus >= 100 && numericStatus <= 599
|
|
369
|
-
? numericStatus
|
|
370
|
-
: undefined;
|
|
371
|
-
const classified = classifyProviderFacts(facts);
|
|
372
|
-
const errorClass = durableProviderErrorClass(facts, classified, httpStatus);
|
|
341
|
+
const httpStatus = providerHttpStatus(facts);
|
|
342
|
+
const errorClass = classifyProviderFacts(facts);
|
|
373
343
|
const providerCode = firstProviderField(sources, ['code']) ?? firstProviderField(sources, ['type']);
|
|
374
344
|
const providerRequestId = firstProviderField(sources, ['requestId', 'request_id']) ??
|
|
375
345
|
boundedProviderField(facts.responseHeaders?.['x-request-id']);
|
|
@@ -378,36 +348,14 @@ export function providerFailureDiagnostic(error) {
|
|
|
378
348
|
...(httpStatus !== undefined ? { httpStatus } : {}),
|
|
379
349
|
...(providerCode !== undefined ? { providerCode } : {}),
|
|
380
350
|
...(providerRequestId !== undefined ? { providerRequestId } : {}),
|
|
381
|
-
retryable:
|
|
351
|
+
retryable: retryMetadataFromFacts(facts, errorClass).retryable,
|
|
382
352
|
};
|
|
383
353
|
}
|
|
384
|
-
function
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
classified === 'ProviderCapacity' ||
|
|
389
|
-
(classified === 'ProviderUnavailable' && isTrustedCodexEdgeRejection(facts))) {
|
|
390
|
-
return classified;
|
|
391
|
-
}
|
|
392
|
-
if (httpStatus === 401 || httpStatus === 403)
|
|
393
|
-
return 'Auth';
|
|
394
|
-
if (httpStatus === 402)
|
|
395
|
-
return 'ProviderBilling';
|
|
396
|
-
if (httpStatus === 408)
|
|
397
|
-
return 'Timeout';
|
|
398
|
-
if (httpStatus === 413)
|
|
399
|
-
return 'ContextLength';
|
|
400
|
-
if (httpStatus === 429)
|
|
401
|
-
return 'RateLimit';
|
|
402
|
-
if (httpStatus !== undefined && httpStatus >= 400 && httpStatus <= 499) {
|
|
403
|
-
return 'RequestRejected';
|
|
404
|
-
}
|
|
405
|
-
if (httpStatus !== undefined && httpStatus >= 500 && httpStatus <= 599) {
|
|
406
|
-
return 'ProviderUnavailable';
|
|
354
|
+
function extractProviderErrorFacts(error) {
|
|
355
|
+
if (RetryError.isInstance(error) && error.reason === 'abort') {
|
|
356
|
+
const facts = normalizeProviderError(error);
|
|
357
|
+
return facts ? { ...facts, aborted: true } : undefined;
|
|
407
358
|
}
|
|
408
|
-
return DURABLE_PROVIDER_ERROR_CLASSES.has(classified) ? classified : 'Other';
|
|
409
|
-
}
|
|
410
|
-
function providerFailureDiagnosticFacts(error) {
|
|
411
359
|
let current = providerErrorTarget(error);
|
|
412
360
|
let fallback;
|
|
413
361
|
let codedFallback;
|
|
@@ -503,7 +451,7 @@ function boundedProviderField(value) {
|
|
|
503
451
|
const normalized = String(value).trim();
|
|
504
452
|
if (!normalized)
|
|
505
453
|
return undefined;
|
|
506
|
-
return truncateUtf8(
|
|
454
|
+
return truncateUtf8(normalized, PROVIDER_FAILURE_FIELD_MAX_BYTES, '…');
|
|
507
455
|
}
|
|
508
456
|
function boundedProviderMessage(value, parseJson = true) {
|
|
509
457
|
if (typeof value !== 'string')
|
|
@@ -531,7 +479,7 @@ function boundedProviderMessage(value, parseJson = true) {
|
|
|
531
479
|
}
|
|
532
480
|
if (!normalized)
|
|
533
481
|
return undefined;
|
|
534
|
-
return truncateUtf8(
|
|
482
|
+
return truncateUtf8(normalized, MODEL_FAILURE_MESSAGE_MAX_BYTES, '…');
|
|
535
483
|
}
|
|
536
484
|
/**
|
|
537
485
|
* Provider context-length overflow signatures. A request-level 400/413 whose
|
|
@@ -633,76 +581,111 @@ export function isContextOverflowErrorText(text) {
|
|
|
633
581
|
* wrap a provider failure in a misleading status or message; the weak
|
|
634
582
|
* heuristics rank last so "generate" can never become a rate limit.
|
|
635
583
|
*/
|
|
584
|
+
export function providerModelFailure(error) {
|
|
585
|
+
const facts = extractProviderErrorFacts(error);
|
|
586
|
+
const kind = facts ? classifyProviderFacts(facts) : 'unknown';
|
|
587
|
+
const summary = facts ? failureSummaryFromFacts(facts) : undefined;
|
|
588
|
+
const retry = facts ? retryMetadataFromFacts(facts, kind) : { retryable: false };
|
|
589
|
+
return {
|
|
590
|
+
type: 'model_failure',
|
|
591
|
+
kind,
|
|
592
|
+
...retry,
|
|
593
|
+
...(summary?.code !== undefined ? { code: summary.code } : {}),
|
|
594
|
+
message: summary?.message ?? 'Model request failed',
|
|
595
|
+
};
|
|
596
|
+
}
|
|
636
597
|
export function classifyError(error) {
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
const facts = normalizeProviderError(error);
|
|
640
|
-
return facts ? classifyProviderFacts(facts) : 'Other';
|
|
598
|
+
const facts = extractProviderErrorFacts(error);
|
|
599
|
+
return facts ? classifyProviderFacts(facts) : 'unknown';
|
|
641
600
|
}
|
|
642
601
|
function classifyProviderFacts(facts) {
|
|
643
|
-
|
|
602
|
+
if (facts.aborted)
|
|
603
|
+
return 'abort';
|
|
604
|
+
const { evidence } = facts;
|
|
644
605
|
const { text, statusCode, code, structuredCodes } = evidence;
|
|
645
606
|
const normalizedCode = code.toLowerCase();
|
|
646
607
|
if (code === OPENAI_RESPONSES_WEBSOCKET_TRANSPORT_ERROR)
|
|
647
|
-
return '
|
|
608
|
+
return 'network';
|
|
648
609
|
if (PROVIDER_CAPACITY_CODES.has(normalizedCode) ||
|
|
649
610
|
structuredCodes.some((c) => PROVIDER_CAPACITY_CODES.has(c))) {
|
|
650
|
-
return '
|
|
611
|
+
return 'provider_capacity';
|
|
651
612
|
}
|
|
652
613
|
// Structured provider evidence: the parsed error JSON's code/type is the
|
|
653
614
|
// only unconditional signal for a context overflow.
|
|
654
615
|
if (structuredCodes.some((c) => CONTEXT_OVERFLOW_PROVIDER_CODES.has(c)))
|
|
655
|
-
return '
|
|
616
|
+
return 'context_overflow';
|
|
656
617
|
if (PROVIDER_BILLING_PROVIDER_CODES.has(normalizedCode) ||
|
|
657
618
|
structuredCodes.some((c) => PROVIDER_BILLING_PROVIDER_CODES.has(c))) {
|
|
658
|
-
return '
|
|
619
|
+
return 'provider_billing';
|
|
659
620
|
}
|
|
660
621
|
if (text.includes('abort'))
|
|
661
|
-
return '
|
|
622
|
+
return 'abort';
|
|
662
623
|
if (statusCode === '402' || code === '402')
|
|
663
|
-
return '
|
|
624
|
+
return 'provider_billing';
|
|
664
625
|
if (statusCode === '429' || code === '429')
|
|
665
|
-
return '
|
|
626
|
+
return 'rate_limit';
|
|
666
627
|
if (structuredCodes.includes(OPENAI_CODEX_EDGE_REJECTION_CODE) &&
|
|
667
628
|
isTrustedCodexEdgeRejection(facts)) {
|
|
668
|
-
return '
|
|
629
|
+
return 'provider_unavailable';
|
|
669
630
|
}
|
|
670
631
|
if (statusCode === '401' || statusCode === '403' || code === '401' || code === '403') {
|
|
671
632
|
// Credential-shaped statuses can still carry account-level usage
|
|
672
633
|
// evidence: an exhausted plan/credit window for a validly signed-in
|
|
673
634
|
// user must not tell them to re-authenticate (#2516).
|
|
674
635
|
if (USAGE_LIMIT_TEXT_PATTERNS.some((pattern) => pattern.test(text))) {
|
|
675
|
-
return '
|
|
636
|
+
return 'provider_billing';
|
|
676
637
|
}
|
|
677
|
-
return '
|
|
638
|
+
return 'auth';
|
|
678
639
|
}
|
|
679
640
|
if (statusCode === '413' || code === '413')
|
|
680
|
-
return '
|
|
641
|
+
return 'context_overflow';
|
|
681
642
|
// Free-text overflow relations on the composite text, veto-first inside.
|
|
682
643
|
if (isContextOverflowErrorText(text))
|
|
683
|
-
return '
|
|
644
|
+
return 'context_overflow';
|
|
684
645
|
if (/^5\d\d$/.test(statusCode) || /^5\d\d$/.test(code))
|
|
685
|
-
return '
|
|
646
|
+
return 'provider_unavailable';
|
|
686
647
|
if (structuredCodes.some((c) => PROVIDER_UNAVAILABLE_PROVIDER_CODES.has(c))) {
|
|
687
|
-
return '
|
|
648
|
+
return 'provider_unavailable';
|
|
688
649
|
}
|
|
689
650
|
if (evidence.transportFailure)
|
|
690
|
-
return '
|
|
651
|
+
return 'network';
|
|
652
|
+
if (isTruncatedStreamText(text))
|
|
653
|
+
return 'stream_truncated';
|
|
654
|
+
const httpStatus = providerHttpStatus(facts);
|
|
655
|
+
if (httpStatus === 408)
|
|
656
|
+
return 'timeout';
|
|
657
|
+
if (httpStatus !== undefined && httpStatus >= 500 && httpStatus <= 599) {
|
|
658
|
+
return 'provider_unavailable';
|
|
659
|
+
}
|
|
660
|
+
if (httpStatus !== undefined && httpStatus >= 400 && httpStatus <= 499) {
|
|
661
|
+
return 'request_rejected';
|
|
662
|
+
}
|
|
691
663
|
// Weak word heuristics, last: they only catch errors that carried no
|
|
692
664
|
// stronger evidence for any other class. `rate` must be word-shaped
|
|
693
665
|
// ("generate"/"separate" are not rate limits) while still matching the
|
|
694
666
|
// rate_limit/RateLimitError identifier spellings.
|
|
695
667
|
if (/\brate\b|rate[_-]?limit/.test(text))
|
|
696
|
-
return '
|
|
668
|
+
return 'rate_limit';
|
|
697
669
|
if (isAuthenticationErrorText(text))
|
|
698
|
-
return '
|
|
670
|
+
return 'auth';
|
|
699
671
|
if (text.includes('timeout'))
|
|
700
|
-
return '
|
|
672
|
+
return 'timeout';
|
|
701
673
|
if (text.includes('network') ||
|
|
702
674
|
text.includes('fetch') ||
|
|
703
675
|
/\btypeerror\b.*\bterminated\b/.test(text))
|
|
704
|
-
return '
|
|
705
|
-
return
|
|
676
|
+
return 'network';
|
|
677
|
+
return 'unknown';
|
|
678
|
+
}
|
|
679
|
+
function isTruncatedStreamText(text) {
|
|
680
|
+
return (text.includes('response stream ended without a finish reason') ||
|
|
681
|
+
text.includes('model stream ended without a finish chunk') ||
|
|
682
|
+
(text.includes('stream disconnected before completion') &&
|
|
683
|
+
text.includes('stream closed before response.completed')));
|
|
684
|
+
}
|
|
685
|
+
function providerHttpStatus(facts) {
|
|
686
|
+
const raw = facts.evidence.statusCode || firstProviderField(facts.summarySources, ['statusCode', 'status']);
|
|
687
|
+
const numeric = Number(raw);
|
|
688
|
+
return Number.isInteger(numeric) && numeric >= 100 && numeric <= 599 ? numeric : undefined;
|
|
706
689
|
}
|
|
707
690
|
function isTrustedCodexEdgeRejection(facts) {
|
|
708
691
|
let current = facts.target;
|
|
@@ -718,25 +701,3 @@ function isTrustedCodexEdgeRejection(facts) {
|
|
|
718
701
|
}
|
|
719
702
|
return false;
|
|
720
703
|
}
|
|
721
|
-
export function errorPresentationFromClass(errorClass) {
|
|
722
|
-
switch (errorClass) {
|
|
723
|
-
case 'ContextLength':
|
|
724
|
-
return { reason: 'context_overflow', message: 'Context window exceeded' };
|
|
725
|
-
case 'Timeout':
|
|
726
|
-
return { reason: 'timeout', message: 'Request timed out' };
|
|
727
|
-
case 'Auth':
|
|
728
|
-
return { reason: 'auth', message: 'Authentication failed' };
|
|
729
|
-
case 'ProviderBilling':
|
|
730
|
-
return { reason: 'provider_billing', message: 'Provider billing required' };
|
|
731
|
-
case 'ProviderCapacity':
|
|
732
|
-
return { reason: 'provider_capacity', message: 'Model service is temporarily at capacity' };
|
|
733
|
-
case 'ProviderUnavailable':
|
|
734
|
-
return { reason: 'provider_unavailable', message: 'Provider returned an error' };
|
|
735
|
-
case 'RateLimit':
|
|
736
|
-
return { reason: 'rate_limit', message: 'Rate limit exceeded' };
|
|
737
|
-
case 'Network':
|
|
738
|
-
return { reason: 'network', message: 'Network error' };
|
|
739
|
-
default:
|
|
740
|
-
return {};
|
|
741
|
-
}
|
|
742
|
-
}
|