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
|
@@ -20,11 +20,11 @@ import { openai } from '@ai-sdk/openai';
|
|
|
20
20
|
import { anthropic } from '@ai-sdk/anthropic';
|
|
21
21
|
import { providerAuthRequiresSecret, } from '@maka/core/llm-connections';
|
|
22
22
|
import { lookupModelMetadata } from '@maka/core/model-metadata';
|
|
23
|
-
import { generalizedErrorMessage } from '@maka/core/redaction';
|
|
24
23
|
import { rawFinishReasonString } from './model-protocol.js';
|
|
25
24
|
import { resolveModelRuntime } from './model-runtime.js';
|
|
26
25
|
import { plaintextResponsesReasoningProviderOptions, safePlaintextResponsesReasoningItemId, } from './responses-reasoning-state.js';
|
|
27
|
-
import { classifyError,
|
|
26
|
+
import { classifyError, providerModelFailure } from './provider-error-classification.js';
|
|
27
|
+
import { withProviderStreamTracking, } from './provider-request-telemetry.js';
|
|
28
28
|
import { createOpenAiChatReasoningTransportState, openAiChatReasoningFieldProviderOptions, restoreOpenAiChatEmptyReasoning, } from './openai-chat-reasoning-transport.js';
|
|
29
29
|
import { mergeOpenAiResponsesProviderOptions, planOpenAiResponsesContinuation, } from './openai-responses-continuation.js';
|
|
30
30
|
import { createOpenAiResponsesTransportState, OPENAI_RESPONSES_LANE_HEADER, } from './openai-responses-websocket.js';
|
|
@@ -37,7 +37,7 @@ export class ModelAdapter {
|
|
|
37
37
|
openAiResponsesTransportState;
|
|
38
38
|
constructor(input) {
|
|
39
39
|
this.input = input;
|
|
40
|
-
this.runtime = resolveModelRuntime(input.connection, input.modelId);
|
|
40
|
+
this.runtime = input.resolvedRuntime ?? resolveModelRuntime(input.connection, input.modelId);
|
|
41
41
|
this.openAiChatReasoningTransportState = createOpenAiChatReasoningTransportState(this.runtime.reasoningReplay.kind === 'openai-chat-plaintext'
|
|
42
42
|
? this.runtime.reasoningReplay.requestField
|
|
43
43
|
: 'observed');
|
|
@@ -102,20 +102,14 @@ export class ModelAdapter {
|
|
|
102
102
|
const { streamText, wrapLanguageModel } = ai;
|
|
103
103
|
const maxOutputTokens = selectedModelMaxOutputTokens(this.input.connection, this.input.modelId, this.input.providerOptions, this.runtime);
|
|
104
104
|
const trackedModel = input.providerRequestTracker
|
|
105
|
-
?
|
|
105
|
+
? withProviderStreamTracking({
|
|
106
106
|
model: input.model,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
doStream,
|
|
114
|
-
...(input.historyCompactBoundary
|
|
115
|
-
? { historyCompactBoundary: input.historyCompactBoundary }
|
|
116
|
-
: {}),
|
|
117
|
-
}),
|
|
118
|
-
},
|
|
107
|
+
wrapLanguageModel,
|
|
108
|
+
tracker: input.providerRequestTracker,
|
|
109
|
+
abortSignal: input.abortSignal,
|
|
110
|
+
...(input.historyCompactBoundary
|
|
111
|
+
? { historyCompactBoundary: input.historyCompactBoundary }
|
|
112
|
+
: {}),
|
|
119
113
|
})
|
|
120
114
|
: input.model;
|
|
121
115
|
const usesOpenAiResponsesAdapter = hasOpenAiResponsesAdapter(this.runtime);
|
|
@@ -345,7 +339,7 @@ export class ModelAdapter {
|
|
|
345
339
|
: undefined, this.runtime);
|
|
346
340
|
}
|
|
347
341
|
makeErrorEvent(turnId, err, reasonOverride) {
|
|
348
|
-
const failure =
|
|
342
|
+
const failure = normalizeProviderFailure(err);
|
|
349
343
|
return {
|
|
350
344
|
type: 'error',
|
|
351
345
|
id: this.input.newId(),
|
|
@@ -355,7 +349,7 @@ export class ModelAdapter {
|
|
|
355
349
|
...(failure.code !== undefined ? { code: failure.code } : {}),
|
|
356
350
|
...(reasonOverride !== undefined
|
|
357
351
|
? { reason: reasonOverride }
|
|
358
|
-
: failure.kind !== 'abort'
|
|
352
|
+
: failure.kind !== 'abort'
|
|
359
353
|
? { reason: failure.kind }
|
|
360
354
|
: {}),
|
|
361
355
|
message: failure.message,
|
|
@@ -366,7 +360,7 @@ export class ModelAdapter {
|
|
|
366
360
|
}
|
|
367
361
|
classifyError(error) {
|
|
368
362
|
if (isModelFailure(error))
|
|
369
|
-
return
|
|
363
|
+
return error.kind;
|
|
370
364
|
return classifyError(error);
|
|
371
365
|
}
|
|
372
366
|
/** Map a successfully settled provider step to its runtime stop reason. */
|
|
@@ -386,19 +380,20 @@ export class ModelAdapter {
|
|
|
386
380
|
export function settleModelStepOutcome(evidence) {
|
|
387
381
|
const { aborted, failure, sawFinish, finishReason, rawFinishReason, usage, request } = evidence;
|
|
388
382
|
if (aborted || failure?.kind === 'abort') {
|
|
389
|
-
return failedStepOutcome('aborted', failure ??
|
|
383
|
+
return failedStepOutcome('aborted', failure ??
|
|
384
|
+
normalizeProviderFailure(Object.assign(new Error('aborted'), { name: 'AbortError' })), request, usage);
|
|
390
385
|
}
|
|
391
386
|
if (failure) {
|
|
392
|
-
return failedStepOutcome(
|
|
387
|
+
return failedStepOutcome('failed', failure, request, usage);
|
|
393
388
|
}
|
|
394
389
|
if (!sawFinish || finishReason === 'other' || finishReason === 'unknown') {
|
|
395
|
-
return failedStepOutcome('truncated', modelStepFailure('
|
|
390
|
+
return failedStepOutcome('truncated', modelStepFailure('stream_truncated', `Provider stream ended without finishing (${finishReason})`), request, usage);
|
|
396
391
|
}
|
|
397
392
|
if (finishReason === 'content-filter' || finishReason === 'error') {
|
|
398
393
|
const terminalFailure = finishReason === 'error'
|
|
399
394
|
? providerFinishFailure(rawFinishReason)
|
|
400
395
|
: modelStepFailure('unknown', 'Provider stopped the stream on a content filter');
|
|
401
|
-
return failedStepOutcome(
|
|
396
|
+
return failedStepOutcome('failed', terminalFailure, request, usage);
|
|
402
397
|
}
|
|
403
398
|
return {
|
|
404
399
|
kind: 'completed',
|
|
@@ -888,34 +883,8 @@ function compileProviderTool(tool) {
|
|
|
888
883
|
});
|
|
889
884
|
}
|
|
890
885
|
}
|
|
891
|
-
function normalizeModelFailure(error) {
|
|
892
|
-
if (isModelFailure(error))
|
|
893
|
-
return error;
|
|
894
|
-
const errorClass = classifyError(error);
|
|
895
|
-
const presentation = errorPresentationFromClass(errorClass);
|
|
896
|
-
const retry = providerRetryMetadata(error);
|
|
897
|
-
const code = error instanceof Error && 'code' in error
|
|
898
|
-
? String(error.code)
|
|
899
|
-
: undefined;
|
|
900
|
-
return {
|
|
901
|
-
type: 'model_failure',
|
|
902
|
-
kind: modelFailureKind(errorClass),
|
|
903
|
-
retryable: retry.retryable,
|
|
904
|
-
...(retry.retryAfterMs !== undefined ? { retryAfterMs: retry.retryAfterMs } : {}),
|
|
905
|
-
...(code !== undefined ? { code } : {}),
|
|
906
|
-
message: presentation.message ?? generalizedErrorMessage(error),
|
|
907
|
-
};
|
|
908
|
-
}
|
|
909
886
|
function normalizeProviderFailure(error) {
|
|
910
|
-
|
|
911
|
-
return error;
|
|
912
|
-
const summary = providerFailureSummary(error);
|
|
913
|
-
const failure = normalizeModelFailure(error);
|
|
914
|
-
return {
|
|
915
|
-
...failure,
|
|
916
|
-
...(summary?.code !== undefined ? { code: summary.code } : {}),
|
|
917
|
-
...(failure.kind === 'unknown' && summary !== undefined ? { message: summary.message } : {}),
|
|
918
|
-
};
|
|
887
|
+
return isModelFailure(error) ? error : providerModelFailure(error);
|
|
919
888
|
}
|
|
920
889
|
function isModelFailure(value) {
|
|
921
890
|
return (typeof value === 'object' &&
|
|
@@ -924,54 +893,6 @@ function isModelFailure(value) {
|
|
|
924
893
|
typeof value.kind === 'string' &&
|
|
925
894
|
typeof value.message === 'string');
|
|
926
895
|
}
|
|
927
|
-
function modelFailureKind(errorClass) {
|
|
928
|
-
switch (errorClass) {
|
|
929
|
-
case 'Abort':
|
|
930
|
-
return 'abort';
|
|
931
|
-
case 'Auth':
|
|
932
|
-
return 'auth';
|
|
933
|
-
case 'ContextLength':
|
|
934
|
-
return 'context_overflow';
|
|
935
|
-
case 'Network':
|
|
936
|
-
return 'network';
|
|
937
|
-
case 'ProviderBilling':
|
|
938
|
-
return 'provider_billing';
|
|
939
|
-
case 'ProviderCapacity':
|
|
940
|
-
return 'provider_capacity';
|
|
941
|
-
case 'ProviderUnavailable':
|
|
942
|
-
return 'provider_unavailable';
|
|
943
|
-
case 'RateLimit':
|
|
944
|
-
return 'rate_limit';
|
|
945
|
-
case 'Timeout':
|
|
946
|
-
return 'timeout';
|
|
947
|
-
default:
|
|
948
|
-
return 'unknown';
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
function errorClassFromFailureKind(kind) {
|
|
952
|
-
switch (kind) {
|
|
953
|
-
case 'abort':
|
|
954
|
-
return 'Abort';
|
|
955
|
-
case 'auth':
|
|
956
|
-
return 'Auth';
|
|
957
|
-
case 'context_overflow':
|
|
958
|
-
return 'ContextLength';
|
|
959
|
-
case 'network':
|
|
960
|
-
return 'Network';
|
|
961
|
-
case 'provider_billing':
|
|
962
|
-
return 'ProviderBilling';
|
|
963
|
-
case 'provider_capacity':
|
|
964
|
-
return 'ProviderCapacity';
|
|
965
|
-
case 'provider_unavailable':
|
|
966
|
-
return 'ProviderUnavailable';
|
|
967
|
-
case 'rate_limit':
|
|
968
|
-
return 'RateLimit';
|
|
969
|
-
case 'timeout':
|
|
970
|
-
return 'Timeout';
|
|
971
|
-
case 'unknown':
|
|
972
|
-
return 'Other';
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
896
|
export function normalizeAiSdkUsage(usage, options = {}) {
|
|
976
897
|
if (!usage)
|
|
977
898
|
return undefined;
|
|
@@ -29,7 +29,7 @@ import { isJSONArray, } from '@ai-sdk/provider';
|
|
|
29
29
|
import { lookupModelMetadata } from '@maka/core/model-metadata';
|
|
30
30
|
import { resolveThinkingLevel, supportsRelayFastServiceTier, thinkingOptionsForModel, thinkingVariantsForConnection, } from '@maka/core/model-thinking';
|
|
31
31
|
import { createOpenAiChatReasoningTransport, createOpenAiChatReasoningTransportState, } from './openai-chat-reasoning-transport.js';
|
|
32
|
-
import {
|
|
32
|
+
import { openResponsesUrl } from './provider-urls.js';
|
|
33
33
|
import { createOpenResponsesCompatibilityFinalizer } from './open-responses-compatibility.js';
|
|
34
34
|
import { resolveModelRuntime } from './model-runtime.js';
|
|
35
35
|
import { runtimeProviderName } from './provider-runtime-policy.js';
|
|
@@ -51,22 +51,14 @@ export function getAIModel(input) {
|
|
|
51
51
|
bodyOverlay: connection.requestBodyOverlay,
|
|
52
52
|
};
|
|
53
53
|
const requestFetch = createRequestCustomizationFetch(baseFetch, requestCustomization);
|
|
54
|
-
if (adapter.kind === 'google' && adapter.normalizeBaseUrl === false) {
|
|
55
|
-
return createGoogle({ apiKey, baseURL, fetch: requestFetch }).chat(modelId);
|
|
56
|
-
}
|
|
57
54
|
switch (adapter.kind) {
|
|
58
55
|
case 'anthropic':
|
|
59
56
|
return createAnthropic({
|
|
60
57
|
...(adapter.auth === 'bearer' ? { authToken: apiKey } : { apiKey }),
|
|
61
|
-
baseURL
|
|
58
|
+
baseURL,
|
|
62
59
|
fetch: requestFetch,
|
|
63
|
-
headers: { 'anthropic-beta': ANTHROPIC_BETA },
|
|
60
|
+
headers: adapter.includeBetaHeaders === false ? undefined : { 'anthropic-beta': ANTHROPIC_BETA },
|
|
64
61
|
}).chat(modelId);
|
|
65
|
-
case 'unavailable':
|
|
66
|
-
// A retired provider must never reach model construction. The pickers
|
|
67
|
-
// filter it out and `resolveModelRuntime` refuses earlier; this is the
|
|
68
|
-
// backstop that keeps a stored connection from silently sending.
|
|
69
|
-
throw new Error('This provider is retired and can no longer be used to send.');
|
|
70
62
|
case 'openai-codex':
|
|
71
63
|
return createOpenAI({
|
|
72
64
|
apiKey,
|
|
@@ -76,36 +68,10 @@ export function getAIModel(input) {
|
|
|
76
68
|
: requestFetch,
|
|
77
69
|
headers: openAiCodexHeaders(apiKey),
|
|
78
70
|
}).responses(modelId);
|
|
79
|
-
case 'github-copilot': {
|
|
80
|
-
if (wire === 'openai-responses') {
|
|
81
|
-
return createOpenAI({ apiKey, baseURL, fetch: requestFetch }).responses(modelId);
|
|
82
|
-
}
|
|
83
|
-
if (wire === 'anthropic-messages') {
|
|
84
|
-
return createAnthropic({
|
|
85
|
-
authToken: apiKey,
|
|
86
|
-
baseURL: anthropicV1BaseUrl(baseURL),
|
|
87
|
-
fetch: requestFetch,
|
|
88
|
-
}).chat(modelId);
|
|
89
|
-
}
|
|
90
|
-
if (reasoningReplay.kind !== 'openai-chat-plaintext') {
|
|
91
|
-
throw new Error('Copilot OpenAI Chat wire requires plaintext reasoning replay');
|
|
92
|
-
}
|
|
93
|
-
const reasoningTransport = createOpenAiChatReasoningTransport(requestFetch, openAiChatReasoningTransportState ??
|
|
94
|
-
createOpenAiChatReasoningTransportState(reasoningReplay.requestField));
|
|
95
|
-
return createOpenAICompatible({
|
|
96
|
-
name: 'github-copilot',
|
|
97
|
-
apiKey,
|
|
98
|
-
baseURL,
|
|
99
|
-
fetch: reasoningTransport.fetch,
|
|
100
|
-
transformRequestBody: reasoningTransport.transformRequestBody,
|
|
101
|
-
}).chatModel(modelId);
|
|
102
|
-
}
|
|
103
71
|
case 'openai': {
|
|
104
72
|
const openai = createOpenAI({
|
|
105
73
|
apiKey,
|
|
106
|
-
|
|
107
|
-
// overrides back to their base so probe-approved relay URLs work.
|
|
108
|
-
baseURL: wire === 'openai-responses' && baseURL ? openAiResponsesBaseUrl(baseURL) : baseURL,
|
|
74
|
+
baseURL,
|
|
109
75
|
fetch: !hasRequestCustomization && openAiResponsesTransportState
|
|
110
76
|
? openAiResponsesTransportState.wrapFetch(requestFetch)
|
|
111
77
|
: requestFetch,
|
|
@@ -115,7 +81,7 @@ export function getAIModel(input) {
|
|
|
115
81
|
case 'google':
|
|
116
82
|
return createGoogle({
|
|
117
83
|
apiKey,
|
|
118
|
-
baseURL
|
|
84
|
+
baseURL,
|
|
119
85
|
fetch: requestFetch,
|
|
120
86
|
}).chat(modelId);
|
|
121
87
|
case 'cohere':
|
|
@@ -125,9 +91,6 @@ export function getAIModel(input) {
|
|
|
125
91
|
throw new Error(`${connection.providerType} connection ${connection.slug} requires a base URL`);
|
|
126
92
|
}
|
|
127
93
|
if (wire === 'openai-responses') {
|
|
128
|
-
if (reasoningReplay.kind !== 'responses') {
|
|
129
|
-
throw new Error('Responses wire requires a Responses continuation contract');
|
|
130
|
-
}
|
|
131
94
|
if (reasoningReplay.contract.adapter === 'open-responses') {
|
|
132
95
|
const finalizeBody = createOpenResponsesCompatibilityFinalizer(reasoningReplay.contract.compatibility);
|
|
133
96
|
// Request customization is applied first; provider compatibility is
|
|
@@ -148,9 +111,7 @@ export function getAIModel(input) {
|
|
|
148
111
|
}
|
|
149
112
|
return createOpenAI({
|
|
150
113
|
apiKey,
|
|
151
|
-
|
|
152
|
-
// native adapter appends `/responses` itself, so pass the base.
|
|
153
|
-
baseURL: baseURL ? openAiResponsesBaseUrl(baseURL) : baseURL,
|
|
114
|
+
baseURL,
|
|
154
115
|
fetch: requestFetch,
|
|
155
116
|
}).responses(modelId);
|
|
156
117
|
}
|
|
@@ -158,7 +119,7 @@ export function getAIModel(input) {
|
|
|
158
119
|
throw new Error('OpenAI-compatible Chat wire requires plaintext reasoning replay');
|
|
159
120
|
}
|
|
160
121
|
const reasoningTransport = createOpenAiChatReasoningTransport(requestFetch, openAiChatReasoningTransportState ??
|
|
161
|
-
createOpenAiChatReasoningTransportState(reasoningReplay.requestField),
|
|
122
|
+
createOpenAiChatReasoningTransportState(reasoningReplay.requestField), adapter.normalizeUsage);
|
|
162
123
|
const transformRequestBody = adapter.replayAssistantReasoningDetails
|
|
163
124
|
? composeRequestTransforms(reasoningTransport.transformRequestBody, replayAssistantReasoning('reasoning', true))
|
|
164
125
|
: reasoningTransport.transformRequestBody;
|
|
@@ -378,10 +339,10 @@ function claudeThinkingMode(providerType, modelId, thinkingOptions) {
|
|
|
378
339
|
? 'adaptive'
|
|
379
340
|
: 'legacy';
|
|
380
341
|
}
|
|
381
|
-
export function buildProviderOptions(connection, modelId, thinkingLevel) {
|
|
382
|
-
return withParallelToolCallOptions(connection, modelId, buildThinkingProviderOptions(connection, modelId, thinkingLevel));
|
|
342
|
+
export function buildProviderOptions(connection, modelId, thinkingLevel, runtime = resolveModelRuntime(connection, modelId)) {
|
|
343
|
+
return withParallelToolCallOptions(connection, modelId, buildThinkingProviderOptions(connection, modelId, thinkingLevel, runtime), runtime);
|
|
383
344
|
}
|
|
384
|
-
function buildThinkingProviderOptions(connection, modelId, thinkingLevel) {
|
|
345
|
+
function buildThinkingProviderOptions(connection, modelId, thinkingLevel, runtime = resolveModelRuntime(connection, modelId)) {
|
|
385
346
|
const thinkingOptions = thinkingOptionsForModel(connection.providerType, modelId);
|
|
386
347
|
const level = resolveThinkingLevel(connection, modelId, thinkingLevel);
|
|
387
348
|
switch (connection.providerType) {
|
|
@@ -396,7 +357,7 @@ function buildThinkingProviderOptions(connection, modelId, thinkingLevel) {
|
|
|
396
357
|
if (thinkingLevel === 'off')
|
|
397
358
|
return {};
|
|
398
359
|
const effort = level ?? 'max';
|
|
399
|
-
if (
|
|
360
|
+
if (runtime.wire === 'openai-chat') {
|
|
400
361
|
// The kimiCodingPlan provider-options namespace is the
|
|
401
362
|
// openai-compatible adapter name; ai-sdk resolves its camelCase
|
|
402
363
|
// alias to the kimi-coding-plan schema key (reasoning_effort).
|
|
@@ -471,7 +432,7 @@ function buildThinkingProviderOptions(connection, modelId, thinkingLevel) {
|
|
|
471
432
|
};
|
|
472
433
|
}
|
|
473
434
|
case 'openai': {
|
|
474
|
-
const usesResponses =
|
|
435
|
+
const usesResponses = runtime.wire === 'openai-responses';
|
|
475
436
|
const reasoningEffort = level === 'off'
|
|
476
437
|
? 'none'
|
|
477
438
|
: (level ??
|
|
@@ -493,9 +454,7 @@ function buildThinkingProviderOptions(connection, modelId, thinkingLevel) {
|
|
|
493
454
|
};
|
|
494
455
|
case 'xai':
|
|
495
456
|
case 'xai-oauth':
|
|
496
|
-
|
|
497
|
-
// model serves the plain OpenAI-compatible chat wire handled below.
|
|
498
|
-
if (modelId === 'grok-4.5') {
|
|
457
|
+
if (runtime.wire === 'openai-responses') {
|
|
499
458
|
return {
|
|
500
459
|
openai: {
|
|
501
460
|
store: false,
|
|
@@ -506,7 +465,7 @@ function buildThinkingProviderOptions(connection, modelId, thinkingLevel) {
|
|
|
506
465
|
},
|
|
507
466
|
};
|
|
508
467
|
}
|
|
509
|
-
return buildFamilyWire(connection, modelId, level, thinkingOptions, thinkingLevel);
|
|
468
|
+
return buildFamilyWire(connection, modelId, level, thinkingOptions, thinkingLevel, runtime);
|
|
510
469
|
case 'volcengine-ark':
|
|
511
470
|
return {
|
|
512
471
|
[toCamelCase(connection.providerType)]: {
|
|
@@ -550,11 +509,10 @@ function buildThinkingProviderOptions(connection, modelId, thinkingLevel) {
|
|
|
550
509
|
// above (level is defined only when metadata declares it) is what makes
|
|
551
510
|
// this safe to generalize: undeclared models never reach the wire.
|
|
552
511
|
default:
|
|
553
|
-
return buildFamilyWire(connection, modelId, level, thinkingOptions, thinkingLevel);
|
|
512
|
+
return buildFamilyWire(connection, modelId, level, thinkingOptions, thinkingLevel, runtime);
|
|
554
513
|
}
|
|
555
514
|
}
|
|
556
|
-
function withParallelToolCallOptions(connection, modelId, options) {
|
|
557
|
-
const runtime = resolveModelRuntime(connection, modelId);
|
|
515
|
+
function withParallelToolCallOptions(connection, modelId, options, runtime) {
|
|
558
516
|
if (runtime.parallelToolCalls === undefined)
|
|
559
517
|
return options;
|
|
560
518
|
let providerKey;
|
|
@@ -563,16 +521,9 @@ function withParallelToolCallOptions(connection, modelId, options) {
|
|
|
563
521
|
providerKey = 'openai';
|
|
564
522
|
optionKey = 'parallelToolCalls';
|
|
565
523
|
}
|
|
566
|
-
else if (runtime.adapter.kind === 'github-copilot') {
|
|
567
|
-
if (runtime.wire === 'anthropic-messages')
|
|
568
|
-
return options;
|
|
569
|
-
providerKey = runtime.wire === 'openai-responses' ? 'openai' : 'githubCopilot';
|
|
570
|
-
optionKey = runtime.wire === 'openai-responses' ? 'parallelToolCalls' : 'parallel_tool_calls';
|
|
571
|
-
}
|
|
572
524
|
else if (runtime.adapter.kind === 'openai-compatible') {
|
|
573
525
|
if (runtime.wire === 'openai-responses') {
|
|
574
|
-
if (runtime.reasoningReplay.
|
|
575
|
-
runtime.reasoningReplay.contract.adapter !== 'openai') {
|
|
526
|
+
if (runtime.reasoningReplay.contract.adapter !== 'openai') {
|
|
576
527
|
return options;
|
|
577
528
|
}
|
|
578
529
|
providerKey = 'openai';
|
|
@@ -595,8 +546,8 @@ function withParallelToolCallOptions(connection, modelId, options) {
|
|
|
595
546
|
},
|
|
596
547
|
};
|
|
597
548
|
}
|
|
598
|
-
function buildFamilyWire(connection, modelId, level, thinkingOptions, requestedLevel) {
|
|
599
|
-
const { adapter, wire, reasoningReplay } =
|
|
549
|
+
function buildFamilyWire(connection, modelId, level, thinkingOptions, requestedLevel, runtime) {
|
|
550
|
+
const { adapter, wire, reasoningReplay } = runtime;
|
|
600
551
|
const explicitReasoningEffort = level ? (level === 'off' ? 'none' : level) : undefined;
|
|
601
552
|
const serviceTier = wire === 'openai-responses' &&
|
|
602
553
|
reasoningReplay.kind === 'responses' &&
|
|
@@ -609,9 +560,6 @@ function buildFamilyWire(connection, modelId, level, thinkingOptions, requestedL
|
|
|
609
560
|
// consumes a provider-native reasoningEffort through the same namespace,
|
|
610
561
|
// keyed by the provider name getAIModel passes to createOpenResponses.
|
|
611
562
|
if (wire === 'openai-responses') {
|
|
612
|
-
if (reasoningReplay.kind !== 'responses') {
|
|
613
|
-
throw new Error('Responses wire requires a Responses continuation contract');
|
|
614
|
-
}
|
|
615
563
|
// Connection-aware: a relay model's declared variants count too.
|
|
616
564
|
const reasons = thinkingVariantsForConnection(connection, modelId).length > 0;
|
|
617
565
|
if (reasoningReplay.contract.adapter === 'open-responses') {
|
|
@@ -687,16 +635,6 @@ function buildFamilyWire(connection, modelId, level, thinkingOptions, requestedL
|
|
|
687
635
|
? { thinking: { type: 'disabled' } }
|
|
688
636
|
: {},
|
|
689
637
|
};
|
|
690
|
-
case 'github-copilot': {
|
|
691
|
-
// Copilot routes per account-declared model protocol (mirrors the
|
|
692
|
-
// getAIModel case), defaulting to its OpenAI-compatible chat wire. Its
|
|
693
|
-
// Responses protocol is answered by the wire branch above.
|
|
694
|
-
const copilotProtocol = connection.models?.find((model) => model.id === modelId)?.apiProtocol;
|
|
695
|
-
if (copilotProtocol === 'anthropic-messages') {
|
|
696
|
-
return level !== 'off' ? { anthropic: { effort: level } } : {};
|
|
697
|
-
}
|
|
698
|
-
return { githubCopilot: { reasoningEffort: explicitReasoningEffort } };
|
|
699
|
-
}
|
|
700
638
|
default:
|
|
701
639
|
return {};
|
|
702
640
|
}
|
|
@@ -149,6 +149,13 @@ async function fetchProviderModelsStrict(connection, apiKey, fetchFn) {
|
|
|
149
149
|
.filter((model) => discovery.filter !== 'language-models' || model.type === 'language')
|
|
150
150
|
.map(toModelInfo)
|
|
151
151
|
.filter((model) => model !== null);
|
|
152
|
+
if (discovery.modelProtocols === 'commandcode') {
|
|
153
|
+
for (const model of models) {
|
|
154
|
+
if (/^(?:anthropic\/)?claude-/i.test(model.id)) {
|
|
155
|
+
model.apiProtocol = 'anthropic-messages';
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
152
159
|
return filterDiscoveredModels(models, discovery.filter);
|
|
153
160
|
}
|
|
154
161
|
case 'google': {
|