maka-agent 0.2.0-dev.43.20260919 → 0.2.0-dev.44.20260920
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/LICENSE +12 -6
- package/dist/mcp-capability-provider.js +7 -0
- package/dist/runtime-host-tui-command.js +1 -1
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/core/dist/chat-model-choice.js +3 -0
- package/node_modules/@maka/core/dist/llm-connections.js +3 -21
- package/node_modules/@maka/core/dist/model-catalog.js +8 -20
- package/node_modules/@maka/core/dist/model-metadata.generated.js +304 -304
- package/node_modules/@maka/core/dist/model-thinking.js +16 -1
- package/node_modules/@maka/core/dist/models-dev-projection.js +0 -1
- package/node_modules/@maka/core/dist/provider-registry.js +7 -51
- package/node_modules/@maka/core/dist/runtime-policy/connection-catalog-codec.js +7 -0
- package/node_modules/@maka/core/dist/runtime-policy/model-catalog-entry-codec.js +14 -1
- package/node_modules/@maka/core/dist/settings.js +2 -3
- package/node_modules/@maka/mcp/dist/index.js +22 -0
- package/node_modules/@maka/mcp/dist/oauth.js +4 -2
- package/node_modules/@maka/mcp/dist/tool-progress.js +45 -0
- package/node_modules/@maka/runtime/dist/opencode-session-header.js +2 -3
- package/node_modules/@maka/runtime/dist/session-manager.js +1 -44
- package/node_modules/@maka/runtime/dist/test-connection.js +3 -66
- package/node_modules/@maka/runtime-host/dist/client/client-capability-channel.js +44 -9
- package/node_modules/@maka/runtime-host/dist/client/index.js +1 -1
- package/node_modules/@maka/runtime-host/dist/client/session-subscription.js +33 -3
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +7 -1
- package/node_modules/@maka/runtime-host/dist/protocol/message.js +10 -0
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +0 -1
- package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +1 -1
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +0 -33
- package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +2 -0
- package/node_modules/@maka/runtime-host/dist/server/bootstrap-runtime-policy.js +31 -104
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +0 -2
- package/node_modules/@maka/runtime-host/dist/server/interactive-turn-coordinator.js +1 -16
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +46 -28
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +5 -16
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +21 -12
- package/node_modules/@maka/runtime-host/dist/server/session-turn-access-request-coordinator.js +7 -17
- package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +0 -62
- package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +0 -3
- package/node_modules/@maka/storage/dist/runtime-policy-stores.js +0 -1
- package/package.json +1 -1
|
@@ -85,6 +85,9 @@ function normalizeModelOverride(entry) {
|
|
|
85
85
|
declared.thinkingLevels = DECLARABLE_RELAY_THINKING_LEVELS.filter((level) => declaredSet.has(level));
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
+
if (isThinkingLevel(entry.defaultThinkingLevel)) {
|
|
89
|
+
declared.defaultThinkingLevel = entry.defaultThinkingLevel;
|
|
90
|
+
}
|
|
88
91
|
if (typeof entry.vision === 'boolean')
|
|
89
92
|
declared.vision = entry.vision;
|
|
90
93
|
for (const field of [
|
|
@@ -188,6 +191,18 @@ export function thinkingVariantsForConnection(connection, modelId) {
|
|
|
188
191
|
return declared;
|
|
189
192
|
return thinkingVariantsForModel(connection.providerType, modelId);
|
|
190
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Resolve the configured new-Session default against the model's effective
|
|
196
|
+
* capability ladder. A stale declaration falls back to the provider default
|
|
197
|
+
* instead of reaching Session creation as an unsupported level.
|
|
198
|
+
*/
|
|
199
|
+
export function defaultThinkingLevelForConnection(connection, modelId) {
|
|
200
|
+
const configured = modelOverride(connection, modelId)?.defaultThinkingLevel;
|
|
201
|
+
return configured !== undefined &&
|
|
202
|
+
thinkingVariantsForConnection(connection, modelId).includes(configured)
|
|
203
|
+
? configured
|
|
204
|
+
: undefined;
|
|
205
|
+
}
|
|
191
206
|
/**
|
|
192
207
|
* Discard-semantics gate: returns the level when the model offers it,
|
|
193
208
|
* `undefined` otherwise. Callers that must *reject* a bad level (IPC/session
|
|
@@ -225,7 +240,7 @@ export function thinkingVariantsForModel(providerType, modelId) {
|
|
|
225
240
|
export function applyModelOverride(model, override) {
|
|
226
241
|
if (!override)
|
|
227
242
|
return model;
|
|
228
|
-
const { thinkingLevels: _thinking, serviceTier: _tier, compactionThreshold: _threshold, maxOutputTokens: _outputBudget, vision, capabilities, ...facts } = override;
|
|
243
|
+
const { thinkingLevels: _thinking, defaultThinkingLevel: _defaultThinking, serviceTier: _tier, compactionThreshold: _threshold, maxOutputTokens: _outputBudget, vision, capabilities, ...facts } = override;
|
|
229
244
|
return {
|
|
230
245
|
...model,
|
|
231
246
|
...facts,
|
|
@@ -203,7 +203,6 @@ export function projectModelsDevModel(providerId, modelId, provider, model) {
|
|
|
203
203
|
...(model.knowledge !== undefined ? { knowledgeCutoff: model.knowledge } : {}),
|
|
204
204
|
...(model.structured_output !== undefined ? { structuredOutput: model.structured_output } : {}),
|
|
205
205
|
...(model.last_updated !== undefined ? { lastUpdated: model.last_updated } : {}),
|
|
206
|
-
...(model.cost?.input === 0 ? { isFree: true } : {}),
|
|
207
206
|
capabilities: {
|
|
208
207
|
...(modalities ? { vision: modalities.input.includes('image') } : {}),
|
|
209
208
|
reasoning: model.reasoning === true,
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
import { GENERATED_MODELS_DEV_METADATA, GENERATED_MODELS_DEV_MODEL_PROVIDER_OVERRIDES, GENERATED_MODELS_DEV_PROVIDER_FACTS, } from './model-metadata.generated.js';
|
|
20
|
-
export const OPENCODE_FREE_DEFAULT_MODEL = 'nemotron-3-ultra-free';
|
|
21
20
|
const siliconflow = GENERATED_MODELS_DEV_PROVIDER_FACTS.siliconflow;
|
|
22
21
|
if (!siliconflow.api)
|
|
23
22
|
throw new Error('models.dev SiliconFlow provider facts are missing api');
|
|
@@ -423,37 +422,6 @@ if (opencodeGo.id !== 'opencode-go' || opencodeGo.api !== 'https://opencode.ai/z
|
|
|
423
422
|
throw new Error('models.dev OpenCode Go provider facts are missing the stable id or API');
|
|
424
423
|
}
|
|
425
424
|
const opencodeGoModelIds = toolCallingModelIds('OpenCode Go', GENERATED_MODELS_DEV_METADATA['opencode-go'], ['minimax-m3']).filter((id) => GENERATED_MODELS_DEV_METADATA['opencode-go'][id]?.lifecycle !== 'deprecated');
|
|
426
|
-
// opencode-free is Maka's first-class free anonymous default. It shares the
|
|
427
|
-
// OpenCode Zen endpoint and model ids, exposing the active tool-capable
|
|
428
|
-
// models the models.dev snapshot marks `isFree` (zero input cost). Deriving
|
|
429
|
-
// the set from the snapshot lets routine metadata refreshes rotate free
|
|
430
|
-
// models in and out instead of letting a hardcoded pin rot (#3409).
|
|
431
|
-
//
|
|
432
|
-
// Persistently broken free models, excluded with dated evidence. Deny-only:
|
|
433
|
-
// a stale entry hides at most one healthy model, the opposite failure mode of
|
|
434
|
-
// the allow-list pin this replaced. Entries should be re-probed on snapshot
|
|
435
|
-
// refreshes and removed once the model produces content again.
|
|
436
|
-
// 2026-08-21 muse-spark-1.2-contributor-free: anonymous completions return
|
|
437
|
-
// 200 with an empty message and bill the full token budget (4 consecutive
|
|
438
|
-
// probes, max_tokens 8–200) — a failure shape that even "the send settles it"
|
|
439
|
-
// cannot surface, which is why these ids are also vetoed in
|
|
440
|
-
// `authorizeConnectionModel` rather than merely dropped from this derivation.
|
|
441
|
-
// 2026-08-30 x-preview-f-free (Ox Alpha Free): retired upstream — dropped from
|
|
442
|
-
// the anonymous /models listing and every completion returns HTTP 401
|
|
443
|
-
// {"type":"ModelError","message":"Model x-preview-f-free is not supported"}.
|
|
444
|
-
// models.dev still snapshots it as free+active, so the derivation kept offering
|
|
445
|
-
// it as a default-enabled, picker-visible row until this quarantine. Remove
|
|
446
|
-
// once the snapshot marks it deprecated (or upstream serves it again).
|
|
447
|
-
const OPENCODE_FREE_BROKEN_MODEL_IDS = new Set([
|
|
448
|
-
'muse-spark-1.2-contributor-free',
|
|
449
|
-
'x-preview-f-free',
|
|
450
|
-
]);
|
|
451
|
-
const opencodeFreeModelIds = toolCallingModelIds('OpenCode Free', Object.fromEntries(Object.entries(GENERATED_MODELS_DEV_METADATA.opencode).filter(([id, model]) => model.isFree === true &&
|
|
452
|
-
model.lifecycle !== 'deprecated' &&
|
|
453
|
-
!OPENCODE_FREE_BROKEN_MODEL_IDS.has(id))), [OPENCODE_FREE_DEFAULT_MODEL]);
|
|
454
|
-
if (opencodeFreeModelIds[0] !== OPENCODE_FREE_DEFAULT_MODEL) {
|
|
455
|
-
throw new Error(`models.dev opencode snapshot no longer serves ${OPENCODE_FREE_DEFAULT_MODEL} as an active tool-capable free model; pick a new OPENCODE_FREE_DEFAULT_MODEL`);
|
|
456
|
-
}
|
|
457
425
|
const githubCopilot = GENERATED_MODELS_DEV_PROVIDER_FACTS['github-copilot'];
|
|
458
426
|
if (githubCopilot.id !== 'github-copilot') {
|
|
459
427
|
throw new Error('models.dev GitHub Copilot provider facts are missing stable id github-copilot');
|
|
@@ -968,22 +936,15 @@ const providerRegistry = {
|
|
|
968
936
|
label: 'OpenCode Free',
|
|
969
937
|
baseUrl: opencode.api,
|
|
970
938
|
authKind: 'none',
|
|
971
|
-
fallbackModels: [
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
brokenModelIds: [...OPENCODE_FREE_BROKEN_MODEL_IDS],
|
|
976
|
-
status: 'ready',
|
|
977
|
-
runtimeAdapter: { kind: 'openai-compatible', name: 'provider' },
|
|
939
|
+
fallbackModels: [],
|
|
940
|
+
status: 'phase3-experimental',
|
|
941
|
+
runtimeAdapter: { kind: 'unavailable' },
|
|
942
|
+
retired: true,
|
|
978
943
|
modelDiscovery: {
|
|
979
944
|
kind: 'fallback',
|
|
980
|
-
reason: '
|
|
945
|
+
reason: 'OpenCode restricts its free tier to the OpenCode client.',
|
|
981
946
|
},
|
|
982
947
|
category: 'overseas',
|
|
983
|
-
catalogGroup: 'plans',
|
|
984
|
-
signupUrl: 'https://opencode.ai/zen',
|
|
985
|
-
catalogOrder: 0,
|
|
986
|
-
recommendedOrder: 0,
|
|
987
948
|
},
|
|
988
949
|
togetherai: {
|
|
989
950
|
label: together.name,
|
|
@@ -1471,16 +1432,11 @@ export function providerDefaultsOf(providerType) {
|
|
|
1471
1432
|
}
|
|
1472
1433
|
/**
|
|
1473
1434
|
* The models a provider offers with no live list to go on: the baseline it
|
|
1474
|
-
* ships
|
|
1435
|
+
* ships. This is the only reader of
|
|
1475
1436
|
* `fallbackModels` — a provider's offline offer has exactly one authority.
|
|
1476
|
-
*
|
|
1477
|
-
* `brokenModelIds` subtracts here rather than being pruned from the baseline at
|
|
1478
|
-
* the source because the ids it names are ones a stored connection may still
|
|
1479
|
-
* carry from an older shipped list.
|
|
1480
1437
|
*/
|
|
1481
1438
|
export function providerFallbackModelIds(defaults) {
|
|
1482
|
-
|
|
1483
|
-
return defaults.fallbackModels.filter((id) => !broken.has(id));
|
|
1439
|
+
return [...defaults.fallbackModels];
|
|
1484
1440
|
}
|
|
1485
1441
|
/**
|
|
1486
1442
|
* The provider's name as a model row shows it, or `undefined` when this build
|
|
@@ -168,6 +168,7 @@ export function decodeModelOverridesTable(value) {
|
|
|
168
168
|
decodeConnectionModelId(modelId);
|
|
169
169
|
const entry = exactRecord(rawEntry, `relay model profile for ${modelId}`, [
|
|
170
170
|
'thinkingLevels',
|
|
171
|
+
'defaultThinkingLevel',
|
|
171
172
|
'vision',
|
|
172
173
|
'contextWindow',
|
|
173
174
|
'serviceTier',
|
|
@@ -200,6 +201,12 @@ export function decodeModelOverridesTable(value) {
|
|
|
200
201
|
}
|
|
201
202
|
declared.thinkingLevels = [...entry.thinkingLevels];
|
|
202
203
|
}
|
|
204
|
+
if (entry.defaultThinkingLevel !== undefined) {
|
|
205
|
+
if (!isThinkingLevel(entry.defaultThinkingLevel)) {
|
|
206
|
+
throw domainError(`default thinking level for ${modelId} is invalid`);
|
|
207
|
+
}
|
|
208
|
+
declared.defaultThinkingLevel = entry.defaultThinkingLevel;
|
|
209
|
+
}
|
|
203
210
|
if (entry.vision !== undefined) {
|
|
204
211
|
declared.vision = booleanValue(entry.vision, `declared vision for ${modelId}`);
|
|
205
212
|
}
|
|
@@ -36,6 +36,7 @@ export function decodeModelCatalogEntry(value) {
|
|
|
36
36
|
'defaultSupportsVision',
|
|
37
37
|
'compactionThreshold',
|
|
38
38
|
'thinkingLevels',
|
|
39
|
+
'defaultThinkingLevel',
|
|
39
40
|
'contextWindow',
|
|
40
41
|
'inputLimit',
|
|
41
42
|
'defaultContextWindow',
|
|
@@ -49,6 +50,7 @@ export function decodeModelCatalogEntry(value) {
|
|
|
49
50
|
id: item.id,
|
|
50
51
|
...pick(item, ['displayName', 'description', 'contextWindow', 'inputLimit', 'knowledgeCutoff']),
|
|
51
52
|
});
|
|
53
|
+
const thinkingLevels = decodeThinkingLevels(item.thinkingLevels);
|
|
52
54
|
return {
|
|
53
55
|
...shared,
|
|
54
56
|
...Object.fromEntries(['defaultContextWindow', 'defaultInputLimit'].flatMap((field) => item[field] === undefined
|
|
@@ -67,9 +69,20 @@ export function decodeModelCatalogEntry(value) {
|
|
|
67
69
|
defaultSupportsVision: booleanValue(item.defaultSupportsVision, 'entry default vision support'),
|
|
68
70
|
}
|
|
69
71
|
: {}),
|
|
70
|
-
thinkingLevels
|
|
72
|
+
thinkingLevels,
|
|
73
|
+
...(item.defaultThinkingLevel === undefined
|
|
74
|
+
? {}
|
|
75
|
+
: {
|
|
76
|
+
defaultThinkingLevel: decodeDefaultThinkingLevel(item.defaultThinkingLevel, thinkingLevels),
|
|
77
|
+
}),
|
|
71
78
|
};
|
|
72
79
|
}
|
|
80
|
+
function decodeDefaultThinkingLevel(value, available) {
|
|
81
|
+
if (!isThinkingLevel(value) || !available.includes(value)) {
|
|
82
|
+
throw domainError('entry default thinking level is invalid');
|
|
83
|
+
}
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
73
86
|
function decodeThinkingLevels(value) {
|
|
74
87
|
if (!Array.isArray(value))
|
|
75
88
|
throw domainError('entry thinking levels must be an array');
|
|
@@ -608,9 +608,8 @@ function defaultChatDefaultsSettings() {
|
|
|
608
608
|
function normalizeChatDefaultsSettings(settings) {
|
|
609
609
|
return {
|
|
610
610
|
...(settings.codeModeEnabled === true ? { codeModeEnabled: true } : {}),
|
|
611
|
-
//
|
|
612
|
-
//
|
|
613
|
-
// session creation as a rung no picker recognizes.
|
|
611
|
+
// Preserve the retired field while older settings documents still carry it.
|
|
612
|
+
// No task creation path consumes it; defaults now live on model overrides.
|
|
614
613
|
thinkingLevel: isThinkingLevel(settings.thinkingLevel) ? settings.thinkingLevel : undefined,
|
|
615
614
|
// A retired mode is decoded (not rejected) so an existing settings file
|
|
616
615
|
// keeps working; knowing which modes are retired lives in one place.
|
|
@@ -31,6 +31,7 @@ import { createMcpToolBinding, parseMcpToolBinding } from './tool-binding.js';
|
|
|
31
31
|
import { McpToolCallError, normalizeToolCallError } from './tool-call-error.js';
|
|
32
32
|
import { discoverMcpTools } from './tool-discovery.js';
|
|
33
33
|
import { McpToolCallPreparer } from './tool-output-validation.js';
|
|
34
|
+
import { mapMcpToolProgress } from './tool-progress.js';
|
|
34
35
|
import { McpCredentialCoordinator } from './credential-coordinator.js';
|
|
35
36
|
import { assertTransportSecurity, urlProvenance, } from './transport-security.js';
|
|
36
37
|
import { McpAuthRequiredError, McpOAuthProvider, } from './oauth.js';
|
|
@@ -597,6 +598,26 @@ export class McpClientManager {
|
|
|
597
598
|
entry.toolSnapshot.get(toolName)?.binding !== binding)
|
|
598
599
|
throw new McpToolCallError(serverId, toolName, 'tool binding is stale');
|
|
599
600
|
};
|
|
601
|
+
const progressListener = options.onProgress ?? options.emitProgress;
|
|
602
|
+
let forwardedProgressTotal;
|
|
603
|
+
let forwardedProgressCurrent = -1;
|
|
604
|
+
const forwardProgress = (progress) => {
|
|
605
|
+
const mapped = mapMcpToolProgress(progress);
|
|
606
|
+
if (!mapped)
|
|
607
|
+
return;
|
|
608
|
+
if ((forwardedProgressTotal !== undefined && mapped.total !== forwardedProgressTotal) ||
|
|
609
|
+
mapped.current <= forwardedProgressCurrent) {
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
forwardedProgressTotal ??= mapped.total;
|
|
613
|
+
forwardedProgressCurrent = mapped.current;
|
|
614
|
+
try {
|
|
615
|
+
progressListener?.(mapped.current, mapped.total);
|
|
616
|
+
}
|
|
617
|
+
catch {
|
|
618
|
+
// Progress is advisory: a listener failure must not fail the tool.
|
|
619
|
+
}
|
|
620
|
+
};
|
|
600
621
|
try {
|
|
601
622
|
const originalArguments = requestInteraction ? structuredClone(args) : args;
|
|
602
623
|
let continuation = {};
|
|
@@ -618,6 +639,7 @@ export class McpClientManager {
|
|
|
618
639
|
signal,
|
|
619
640
|
timeout: options.timeoutMs ?? this.timeouts.callToolMs,
|
|
620
641
|
toolDefinition: structuredClone(preparation.value.definitionForSdk),
|
|
642
|
+
...(progressListener ? { onprogress: forwardProgress } : {}),
|
|
621
643
|
...(requestInteraction ? { allowInputRequired: true } : {}),
|
|
622
644
|
});
|
|
623
645
|
refreshInventory();
|
|
@@ -51,6 +51,8 @@ export class McpAuthRequiredError extends Error {
|
|
|
51
51
|
* redirectToAuthorization. The URL itself is never opened or sent in a
|
|
52
52
|
* token request. */
|
|
53
53
|
const BACKGROUND_REDIRECT_URL = 'http://127.0.0.1/maka-mcp-oauth-noninteractive';
|
|
54
|
+
/** Product homepage sent in OAuth dynamic client registration. */
|
|
55
|
+
const MCP_OAUTH_CLIENT_URI = 'https://maka.apache.org/en/';
|
|
54
56
|
export class McpOAuthProvider {
|
|
55
57
|
options;
|
|
56
58
|
/** Present only when an interactive state was supplied — the SDK treats
|
|
@@ -68,8 +70,8 @@ export class McpOAuthProvider {
|
|
|
68
70
|
get clientMetadata() {
|
|
69
71
|
return {
|
|
70
72
|
client_name: this.options.clientName,
|
|
71
|
-
client_uri:
|
|
72
|
-
software_id:
|
|
73
|
+
client_uri: MCP_OAUTH_CLIENT_URI,
|
|
74
|
+
software_id: this.options.clientName,
|
|
73
75
|
software_version: this.options.clientVersion,
|
|
74
76
|
redirect_uris: this.options.interactive ? [this.options.interactive.redirectUrl] : [],
|
|
75
77
|
grant_types: ['authorization_code', 'refresh_token'],
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
export const MCP_TOOL_PROGRESS_MAX_TOTAL = 1_024;
|
|
20
|
+
/**
|
|
21
|
+
* Map an SDK `notifications/progress` payload onto the Host progress pair.
|
|
22
|
+
* First slice: only finite step counts that the shared tool-progress codec
|
|
23
|
+
* already accepts. Missing `total`, fractions, and inverted ranges are
|
|
24
|
+
* dropped so a noisy server cannot fail the tool call.
|
|
25
|
+
*/
|
|
26
|
+
export function mapMcpToolProgress(value) {
|
|
27
|
+
if (!isRecord(value))
|
|
28
|
+
return undefined;
|
|
29
|
+
const current = value.progress;
|
|
30
|
+
const total = value.total;
|
|
31
|
+
if (typeof current !== 'number' || typeof total !== 'number')
|
|
32
|
+
return undefined;
|
|
33
|
+
if (!Number.isSafeInteger(current) ||
|
|
34
|
+
!Number.isSafeInteger(total) ||
|
|
35
|
+
current < 0 ||
|
|
36
|
+
total < 1 ||
|
|
37
|
+
total > MCP_TOOL_PROGRESS_MAX_TOTAL ||
|
|
38
|
+
current > total) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
return { current, total };
|
|
42
|
+
}
|
|
43
|
+
function isRecord(value) {
|
|
44
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
45
|
+
}
|
|
@@ -17,11 +17,10 @@
|
|
|
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 session identity without overriding an explicit header. */
|
|
21
21
|
export function withOpenCodeSessionHeader(providerType, sessionId, headers) {
|
|
22
22
|
const normalizedSessionId = sessionId?.trim();
|
|
23
|
-
if (
|
|
24
|
-
!normalizedSessionId) {
|
|
23
|
+
if (providerType !== 'opencode-go' || !normalizedSessionId) {
|
|
25
24
|
return headers;
|
|
26
25
|
}
|
|
27
26
|
if (Object.keys(headers ?? {}).some((name) => name.toLowerCase() === OPENCODE_SESSION_HEADER)) {
|
|
@@ -20,7 +20,7 @@ import { countRecallSearchableMessages, listRecallCandidateSessions, } from './r
|
|
|
20
20
|
import { createHash } from 'node:crypto';
|
|
21
21
|
import { isDeepStrictEqual } from 'node:util';
|
|
22
22
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
23
|
-
import { messageContentsEqual
|
|
23
|
+
import { messageContentsEqual } from '@maka/core/events';
|
|
24
24
|
import { isCanonicalReadOnlyPermissionProfile } from '@maka/core/permission-profile';
|
|
25
25
|
import { DEFAULT_TOOL_MODE } from '@maka/core/tool-mode';
|
|
26
26
|
import { PLAN_USER_ABANDON_REASON, PLAN_USER_CANCEL_REASON, PlanConflictError, activePlanExecution, } from '@maka/core/plan';
|
|
@@ -97,14 +97,6 @@ export class SessionConfigurationRevisionConflictError extends Error {
|
|
|
97
97
|
this.actualRevision = actualRevision;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
export class RuntimeRegenerateTurnError extends Error {
|
|
101
|
-
code;
|
|
102
|
-
name = 'RuntimeRegenerateTurnError';
|
|
103
|
-
constructor(code, message) {
|
|
104
|
-
super(message);
|
|
105
|
-
this.code = code;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
100
|
export class BackendRegistry {
|
|
109
101
|
registrations = new Map();
|
|
110
102
|
register(kind, registration) {
|
|
@@ -2752,41 +2744,6 @@ export class SessionManager {
|
|
|
2752
2744
|
? authority.stopRoot(identity, input)
|
|
2753
2745
|
: this.runtimeKernel.stopSession(identity.sessionId, input);
|
|
2754
2746
|
}
|
|
2755
|
-
async *regenerateTurn(sessionId, input) {
|
|
2756
|
-
const execution = this.runtimeKernel.claimExecution(sessionId);
|
|
2757
|
-
try {
|
|
2758
|
-
const source = await this.prepareRegenerateTurn(sessionId, input.sourceTurnId);
|
|
2759
|
-
yield* this.sendMessage(sessionId, {
|
|
2760
|
-
turnId: input.turnId ?? this.deps.newId(),
|
|
2761
|
-
...source.content,
|
|
2762
|
-
parentTurnId: source.sourceTurnId,
|
|
2763
|
-
regeneratedFromTurnId: source.sourceTurnId,
|
|
2764
|
-
}, { execution });
|
|
2765
|
-
}
|
|
2766
|
-
finally {
|
|
2767
|
-
execution.release();
|
|
2768
|
-
}
|
|
2769
|
-
}
|
|
2770
|
-
async prepareRegenerateTurn(sessionId, sourceTurnId) {
|
|
2771
|
-
const view = await this.getSessionView(sessionId);
|
|
2772
|
-
const source = view.turns.find((candidate) => candidate.turnId === sourceTurnId);
|
|
2773
|
-
if (!source) {
|
|
2774
|
-
throw new RuntimeRegenerateTurnError('not_found', `Cannot regenerate unknown Turn ${sourceTurnId}`);
|
|
2775
|
-
}
|
|
2776
|
-
if (source.status !== 'failed' &&
|
|
2777
|
-
source.status !== 'aborted' &&
|
|
2778
|
-
source.status !== 'completed') {
|
|
2779
|
-
throw new RuntimeRegenerateTurnError('operation_conflict', `Cannot regenerate Turn ${sourceTurnId} while it is ${source.status}`);
|
|
2780
|
-
}
|
|
2781
|
-
const user = view.messages.find((message) => message.type === 'user' && message.turnId === sourceTurnId);
|
|
2782
|
-
if (!user) {
|
|
2783
|
-
throw new RuntimeRegenerateTurnError('operation_conflict', `Turn ${sourceTurnId} has no UserMessage`);
|
|
2784
|
-
}
|
|
2785
|
-
return {
|
|
2786
|
-
sourceTurnId,
|
|
2787
|
-
content: normalizeMessageContent(user),
|
|
2788
|
-
};
|
|
2789
|
-
}
|
|
2790
2747
|
/** Canonical, repaired source view for a Host-owned cross-Session copy. */
|
|
2791
2748
|
async readConversationCopySnapshot(sessionId) {
|
|
2792
2749
|
return this.getSessionView(sessionId);
|
|
@@ -106,47 +106,15 @@ async function testConnectionStrict(connection, apiKey, model, fetchFn, t0, time
|
|
|
106
106
|
if (!defaults) {
|
|
107
107
|
return { ok: false, errorMessage: `Unknown provider type "${connection.providerType}"` };
|
|
108
108
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
if (defaults.retired)
|
|
110
|
+
return retiredProviderTestResult(connection.providerType);
|
|
111
|
+
const sessionId = connection.providerType === 'opencode-go' ? randomUUID() : undefined;
|
|
112
112
|
const auth = defaults.authKind;
|
|
113
113
|
const secret = auth === 'none' ? '' : apiKey;
|
|
114
114
|
const testModel = resolveConnectionTestModel(connection, model, providerFallbackModelIds(defaults));
|
|
115
115
|
if (!testModel) {
|
|
116
116
|
return { ok: false, errorMessage: 'No model to test' };
|
|
117
117
|
}
|
|
118
|
-
if (connection.providerType === 'opencode-free' && !model?.trim()) {
|
|
119
|
-
const brokenModelIds = new Set(defaults.brokenModelIds ?? []);
|
|
120
|
-
const candidates = [
|
|
121
|
-
...new Set([
|
|
122
|
-
...connectionEnabledModelIds(connection).filter((id) => !brokenModelIds.has(id)),
|
|
123
|
-
...providerFallbackModelIds(defaults),
|
|
124
|
-
]),
|
|
125
|
-
];
|
|
126
|
-
if (candidates.length === 0) {
|
|
127
|
-
return { ok: false, errorMessage: 'No model to test' };
|
|
128
|
-
}
|
|
129
|
-
let lastFailure;
|
|
130
|
-
for (let index = 0; index < candidates.length; index += 1) {
|
|
131
|
-
const candidate = candidates[index];
|
|
132
|
-
const remainingMs = timeoutMs - (Date.now() - t0);
|
|
133
|
-
if (remainingMs <= 0) {
|
|
134
|
-
return connectionTestFailure(new ConnectionEffectFetchError('timeout'), t0);
|
|
135
|
-
}
|
|
136
|
-
const remainingCandidates = candidates.length - index;
|
|
137
|
-
const attemptTimeoutMs = Math.max(1, Math.floor(remainingMs / remainingCandidates));
|
|
138
|
-
try {
|
|
139
|
-
const result = await testConnectionModel(connection, secret, candidate, fetchFn, t0, attemptTimeoutMs, sessionId);
|
|
140
|
-
if (result.ok)
|
|
141
|
-
return result;
|
|
142
|
-
lastFailure = result;
|
|
143
|
-
}
|
|
144
|
-
catch (error) {
|
|
145
|
-
lastFailure = connectionTestFailure(error, t0, true);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return lastFailure ?? connectionTestFailure(new ConnectionEffectFetchError('timeout'), t0);
|
|
149
|
-
}
|
|
150
118
|
return await testConnectionModel(connection, secret, testModel, fetchFn, t0, timeoutMs, sessionId);
|
|
151
119
|
}
|
|
152
120
|
async function testConnectionModel(connection, secret, testModel, fetchFn, t0, timeoutMs = CONNECTION_TEST_TIMEOUT_MS, sessionId) {
|
|
@@ -332,40 +300,9 @@ async function probeOpenAI(connection, baseUrl, apiKey, model, t0, fetchFn, time
|
|
|
332
300
|
});
|
|
333
301
|
if (!r.ok)
|
|
334
302
|
return httpFailure(r, t0);
|
|
335
|
-
if (connection.providerType === 'opencode-free') {
|
|
336
|
-
const body = await r.readJson();
|
|
337
|
-
if (!isOpenAIChatCompletion(body)) {
|
|
338
|
-
return {
|
|
339
|
-
ok: false,
|
|
340
|
-
errorMessage: 'OpenCode Free returned no valid chat completion',
|
|
341
|
-
errorClass: 'provider_unavailable',
|
|
342
|
-
latencyMs: Date.now() - t0,
|
|
343
|
-
modelTested: model,
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
return { ok: true, latencyMs: Date.now() - t0, modelTested: model };
|
|
347
|
-
}
|
|
348
303
|
await r.cancel();
|
|
349
304
|
return { ok: true, latencyMs: Date.now() - t0, modelTested: model };
|
|
350
305
|
}
|
|
351
|
-
function isOpenAIChatCompletion(value) {
|
|
352
|
-
if (!value || typeof value !== 'object')
|
|
353
|
-
return false;
|
|
354
|
-
const choices = value.choices;
|
|
355
|
-
return (Array.isArray(choices) &&
|
|
356
|
-
choices.some((choice) => {
|
|
357
|
-
if (!choice || typeof choice !== 'object')
|
|
358
|
-
return false;
|
|
359
|
-
const message = choice.message;
|
|
360
|
-
if (!message || typeof message !== 'object')
|
|
361
|
-
return false;
|
|
362
|
-
const completion = message;
|
|
363
|
-
return (typeof completion.content === 'string' ||
|
|
364
|
-
typeof completion.reasoning === 'string' ||
|
|
365
|
-
typeof completion.reasoning_content === 'string' ||
|
|
366
|
-
(Array.isArray(completion.tool_calls) && completion.tool_calls.length > 0));
|
|
367
|
-
}));
|
|
368
|
-
}
|
|
369
306
|
async function probeGoogle(baseUrl, apiKey, model, t0, normalizeBaseUrl, fetchFn) {
|
|
370
307
|
const url = `${stripTrailing(baseUrl)}/models/${encodeURIComponent(model)}:generateContent${normalizeBaseUrl ? `?key=${encodeURIComponent(apiKey)}` : ''}`;
|
|
371
308
|
const r = await fetchForConnectionEffect(fetchFn, url, {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
import { randomUUID } from 'node:crypto';
|
|
20
|
-
import { CLIENT_CAPABILITY_MAX_RESULT_BYTES, CLIENT_CAPABILITY_RESULT_CHUNK_MAX_BYTES, decodeClientCapabilityClientFrame, decodeClientCapabilityReplaceInput, decodeClientCapabilityResult, } from '../protocol/index.js';
|
|
20
|
+
import { CLIENT_CAPABILITY_MAX_PROGRESS_TOTAL, CLIENT_CAPABILITY_MAX_RESULT_BYTES, CLIENT_CAPABILITY_RESULT_CHUNK_MAX_BYTES, decodeClientCapabilityClientFrame, decodeClientCapabilityReplaceInput, decodeClientCapabilityResult, } from '../protocol/index.js';
|
|
21
21
|
/** Client-owned registration, reverse invocation, and teardown lifecycle. */
|
|
22
22
|
export class ClientCapabilityChannel {
|
|
23
23
|
#options;
|
|
@@ -247,6 +247,40 @@ export class ClientCapabilityChannel {
|
|
|
247
247
|
});
|
|
248
248
|
return accepting;
|
|
249
249
|
};
|
|
250
|
+
let pendingProgress;
|
|
251
|
+
let progressWriting = false;
|
|
252
|
+
let progressWrite = Promise.resolve();
|
|
253
|
+
const scheduleProgressWrite = () => {
|
|
254
|
+
if (progressWriting)
|
|
255
|
+
return;
|
|
256
|
+
progressWriting = true;
|
|
257
|
+
progressWrite = (async () => {
|
|
258
|
+
while (pendingProgress) {
|
|
259
|
+
const next = pendingProgress;
|
|
260
|
+
pendingProgress = undefined;
|
|
261
|
+
try {
|
|
262
|
+
await this.#options.write({
|
|
263
|
+
kind: 'client.capability.progress',
|
|
264
|
+
invocationId,
|
|
265
|
+
current: next.current,
|
|
266
|
+
total: next.total,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
// Progress is advisory: a failed write must not fail the invocation.
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
})().finally(() => {
|
|
275
|
+
progressWriting = false;
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
const flushProgress = async () => {
|
|
279
|
+
do {
|
|
280
|
+
scheduleProgressWrite();
|
|
281
|
+
await progressWrite;
|
|
282
|
+
} while (pendingProgress);
|
|
283
|
+
};
|
|
250
284
|
try {
|
|
251
285
|
const progress = (current, total) => {
|
|
252
286
|
if (!accepted ||
|
|
@@ -255,17 +289,17 @@ export class ClientCapabilityChannel {
|
|
|
255
289
|
!Number.isInteger(total) ||
|
|
256
290
|
current < 0 ||
|
|
257
291
|
total < 1 ||
|
|
292
|
+
total > CLIENT_CAPABILITY_MAX_PROGRESS_TOTAL ||
|
|
258
293
|
current > total) {
|
|
259
294
|
return;
|
|
260
295
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
.catch((error) => this.#options.onFailure(asError(error)));
|
|
296
|
+
const previous = invocation.progress;
|
|
297
|
+
if (previous && (previous.total !== total || current <= previous.current)) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
invocation.progress = { current, total };
|
|
301
|
+
pendingProgress = { current, total };
|
|
302
|
+
scheduleProgressWrite();
|
|
269
303
|
};
|
|
270
304
|
const requestInteraction = async (request) => {
|
|
271
305
|
if (!accepted) {
|
|
@@ -315,6 +349,7 @@ export class ClientCapabilityChannel {
|
|
|
315
349
|
throw new Error('Client Capability provider returned with a pending interaction');
|
|
316
350
|
}
|
|
317
351
|
await accept({ kind: 'none' });
|
|
352
|
+
await flushProgress();
|
|
318
353
|
await this.#sendResult(invocationId, result, invocation);
|
|
319
354
|
}
|
|
320
355
|
catch (error) {
|
|
@@ -30,7 +30,7 @@ export { RuntimeHostSshOperatorActivationError, activateRuntimeHostSshOperator,
|
|
|
30
30
|
export { normalizeRuntimeHostSshDestination, openRuntimeHostSshTunnel, } from './ssh-tunnel.js';
|
|
31
31
|
export { RuntimeHostPermanentReconnectError, startRuntimeHostReconnectLifecycle, } from './reconnect-lifecycle.js';
|
|
32
32
|
export { RUNTIME_HOST_REMOTE_INCOMPATIBLE_CODE, RuntimeHostRemoteCompatibilityError, } from './remote-compatibility-error.js';
|
|
33
|
-
export { RuntimeHostSubscriptionError, } from './session-subscription.js';
|
|
33
|
+
export { RuntimeHostSubscriptionError, SessionRemovedSubscriptionError, subscriptionClosedError, } from './session-subscription.js';
|
|
34
34
|
export { RuntimeHostStartupError, runtimeHostStartupError, } from './startup-error.js';
|
|
35
35
|
export { connectRuntimeHostWslEnvironment, listRuntimeHostWslDistributions, normalizeRuntimeHostWslDistribution, resolveSystemRuntimeHostWslExecutable, } from './wsl-environment.js';
|
|
36
36
|
export { RuntimeHostCatalogReadError, RuntimeHostSessionCatalogRevisionChangedError, readRuntimeHostConnectionCatalog, readRuntimeHostInvocableSkills, readRuntimeHostProjectDetails, readRuntimeHostResources, readRuntimeHostProjects, readRuntimeHostSessionCatalogPage, readRuntimeHostSessions, readRuntimeHostSkillCatalog, } from './catalog-reader.js';
|