maka-agent 0.2.0-dev.47.20260922 → 0.2.0-dev.49.20260924
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/session-event-mapper.js +1 -4
- package/dist/onboarding-catalog.js +20 -4
- package/dist/pi-transcript.js +0 -8
- package/dist/pi-tui-pickers.js +1 -1
- package/dist/pi-tui-runner.js +6 -4
- package/dist/runtime-host-capability-provider-command.js +25 -6
- package/dist/runtime-host-onboarding.js +5 -3
- package/dist/runtime-host-session-channel.js +9 -3
- package/dist/tui-mcp-control.js +37 -24
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/acp-executor-plugin/dist/acp-errors.js +26 -0
- package/node_modules/@maka/acp-executor-plugin/dist/acp-filesystem.js +103 -0
- package/node_modules/@maka/acp-executor-plugin/dist/acp-process.js +119 -0
- package/node_modules/@maka/acp-executor-plugin/dist/acp-projection.js +146 -0
- package/node_modules/@maka/acp-executor-plugin/dist/index.js +653 -0
- package/node_modules/@maka/acp-executor-plugin/dist/plugin.mjs +24446 -0
- package/node_modules/@maka/acp-executor-plugin/package.json +15 -0
- package/node_modules/@maka/antigravity-acp-plugin/dist/index.js +88 -0
- package/node_modules/@maka/antigravity-acp-plugin/dist/model-presentation.js +53 -0
- package/node_modules/@maka/antigravity-acp-plugin/dist/plugin.mjs +115 -0
- package/node_modules/@maka/antigravity-acp-plugin/package.json +15 -0
- package/node_modules/@maka/core/dist/events.js +13 -0
- package/node_modules/@maka/core/dist/executor-catalog.js +106 -0
- package/node_modules/@maka/core/dist/llm-connections.js +2 -5
- package/node_modules/@maka/core/dist/mcp.js +4 -1
- package/node_modules/@maka/core/dist/model-facts.js +2 -4
- package/node_modules/@maka/core/dist/model-metadata.generated.js +345 -248
- package/node_modules/@maka/core/dist/model-metadata.js +28 -1
- package/node_modules/@maka/core/dist/model-thinking.js +17 -17
- package/node_modules/@maka/core/dist/model-web-search.js +7 -9
- package/node_modules/@maka/core/dist/models-dev-projection.js +1 -1
- package/node_modules/@maka/core/dist/onboarding.js +1 -4
- package/node_modules/@maka/core/dist/provider-registry.js +60 -86
- package/node_modules/@maka/core/dist/runtime-event-store.js +25 -0
- package/node_modules/@maka/core/dist/runtime-event.js +2 -2
- package/node_modules/@maka/core/dist/runtime-invocation.js +5 -0
- package/node_modules/@maka/core/dist/runtime-policy/connection-catalog-codec.js +28 -16
- package/node_modules/@maka/core/dist/runtime-policy/credential-vault-codec.js +6 -0
- package/node_modules/@maka/core/dist/runtime-policy/policy-codec.js +21 -0
- package/node_modules/@maka/core/dist/runtime-policy.js +1 -1
- package/node_modules/@maka/core/dist/session.js +25 -9
- package/node_modules/@maka/core/dist/settings.js +1 -0
- package/node_modules/@maka/core/dist/tool-ledger-scanner.js +365 -104
- package/node_modules/@maka/core/dist/transcript-search.js +1 -0
- package/node_modules/@maka/core/dist/turn-origin.js +14 -0
- package/node_modules/@maka/core/dist/usage-stats/types.js +1 -0
- package/node_modules/@maka/core/package.json +2 -0
- package/node_modules/@maka/eval/dist/harbor-maka-subject.js +3 -0
- package/node_modules/@maka/eval/dist/maka-subject.js +8 -1
- package/node_modules/@maka/mcp/dist/credential-coordinator.js +6 -1
- package/node_modules/@maka/mcp/dist/index.js +31 -5
- package/node_modules/@maka/mcp/dist/oauth.js +54 -6
- package/node_modules/@maka/runtime/dist/agent-run-inspect.js +1 -1
- package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +1 -11
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +2 -12
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +3 -71
- package/node_modules/@maka/runtime/dist/conversation-copy.js +58 -3
- package/node_modules/@maka/runtime/dist/local-web-fetch.js +23 -11
- package/node_modules/@maka/runtime/dist/mcp-tools.js +9 -2
- package/node_modules/@maka/runtime/dist/model-adapter.js +10 -5
- package/node_modules/@maka/runtime/dist/model-factory.js +33 -30
- package/node_modules/@maka/runtime/dist/model-fetcher.js +4 -1
- package/node_modules/@maka/runtime/dist/model-runtime.js +3 -9
- package/node_modules/@maka/runtime/dist/plugin-executor-backend.js +116 -3
- package/node_modules/@maka/runtime/dist/plugin-executor-service.js +212 -16
- package/node_modules/@maka/runtime/dist/read-page.js +11 -8
- package/node_modules/@maka/runtime/dist/recovery-resolver.js +47 -20
- package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +1 -0
- package/node_modules/@maka/runtime/dist/runtime-ledger-repair.js +2 -2
- package/node_modules/@maka/runtime/dist/scheduled-task-tools.js +39 -8
- package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +3 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +182 -127
- package/node_modules/@maka/runtime/dist/shell-run-manager.js +3 -0
- package/node_modules/@maka/runtime/dist/stream-graph-coordinator.js +29 -4
- package/node_modules/@maka/runtime/dist/telemetry/model-pricing.generated.js +141 -134
- package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +3 -3
- package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +7 -6
- package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +28 -62
- package/node_modules/@maka/runtime-host/dist/candidate-entry.js +8 -5
- package/node_modules/@maka/runtime-host/dist/client/hosted-execution-target.js +7 -1
- package/node_modules/@maka/runtime-host/dist/client/index.js +1 -1
- package/node_modules/@maka/runtime-host/dist/client/reconnect-lifecycle.js +8 -1
- package/node_modules/@maka/runtime-host/dist/client/session-catalog-summary.js +6 -1
- package/node_modules/@maka/runtime-host/dist/client/session-subscription.js +3 -0
- package/node_modules/@maka/runtime-host/dist/composition-identity.js +19 -0
- package/node_modules/@maka/runtime-host/dist/protocol/connection-effects.js +6 -3
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +14 -2
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +4 -1
- package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +34 -0
- package/node_modules/@maka/runtime-host/dist/protocol/prompt-suggestions.js +61 -0
- package/node_modules/@maka/runtime-host/dist/protocol/runtime-policy.js +4 -1
- package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +40 -2
- package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +2 -1
- package/node_modules/@maka/runtime-host/dist/server/builtin-external-agent-plugins.js +188 -0
- package/node_modules/@maka/runtime-host/dist/server/candidate.js +12 -7
- package/node_modules/@maka/runtime-host/dist/server/client-capability-recovery.js +44 -46
- package/node_modules/@maka/runtime-host/dist/server/connection-effect-coordinator.js +3 -0
- package/node_modules/@maka/runtime-host/dist/server/context-coordinator.js +2 -0
- package/node_modules/@maka/runtime-host/dist/server/execution-composition-factory.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +212 -24
- package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +41 -2
- package/node_modules/@maka/runtime-host/dist/server/extension-bundle.js +4 -0
- package/node_modules/@maka/runtime-host/dist/server/generated-text.js +39 -0
- package/node_modules/@maka/runtime-host/dist/server/host-composition-source.js +47 -0
- package/node_modules/@maka/runtime-host/dist/server/host-composition.js +1 -29
- package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +2 -9
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +75 -9
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +12 -0
- package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +45 -0
- package/node_modules/@maka/runtime-host/dist/server/jev-routing-model.js +157 -0
- package/node_modules/@maka/runtime-host/dist/server/listener-set.js +2 -2
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +4 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +11 -1
- package/node_modules/@maka/runtime-host/dist/server/process-lifecycle.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/process-termination-error.js +27 -0
- package/node_modules/@maka/runtime-host/dist/server/prompt-suggestion.js +179 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +93 -14
- package/node_modules/@maka/runtime-host/dist/server/runtime-policy-coordinator.js +2 -0
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +99 -12
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +48 -16
- package/node_modules/@maka/runtime-host/dist/server/session-effect-coordinator.js +12 -6
- package/node_modules/@maka/runtime-host/dist/server/session-title.js +3 -16
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +71 -3
- package/node_modules/@maka/runtime-host/dist/server/shared-session-transcript.js +3 -0
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +6 -13
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +39 -11
- package/node_modules/@maka/runtime-host/dist/server/workhub-result-coordinator.js +173 -0
- package/node_modules/@maka/runtime-host/dist/server/workhub-result-runtime.js +293 -0
- package/node_modules/@maka/runtime-host/package.json +2 -0
- package/node_modules/@maka/storage/dist/agent-run-store-contract.js +8 -0
- package/node_modules/@maka/storage/dist/config-transfer.js +14 -8
- package/node_modules/@maka/storage/dist/execution-stores.js +19 -6
- package/node_modules/@maka/storage/dist/interaction-store.js +13 -0
- package/node_modules/@maka/storage/dist/mcp-config-store.js +91 -2
- package/node_modules/@maka/storage/dist/operational-state-store.js +15 -1
- package/node_modules/@maka/storage/dist/plan-authority.js +2 -0
- package/node_modules/@maka/storage/dist/plan-store.js +30 -0
- package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
- package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +28 -17
- package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +9 -3
- package/node_modules/@maka/storage/dist/runtime-policy/credential-vault-document.js +4 -1
- package/node_modules/@maka/storage/dist/runtime-policy/legacy-custom-connection.js +65 -0
- package/node_modules/@maka/storage/dist/runtime-policy/onboarding-transaction.js +10 -5
- package/node_modules/@maka/storage/dist/runtime-policy/policy-document.js +2 -0
- package/node_modules/@maka/storage/dist/session-bundle-policy.js +11 -0
- package/node_modules/@maka/storage/dist/session-store-values.js +16 -4
- package/node_modules/@maka/storage/dist/session-store.js +29 -6
- package/node_modules/@maka/storage/dist/shell-run-authority.js +1 -0
- package/node_modules/@maka/storage/dist/shell-run-store.js +15 -0
- package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +3 -0
- package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +74 -1
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +849 -91
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +21 -3
- package/node_modules/@maka/storage/dist/usage-screen.js +138 -108
- package/package.json +1 -1
|
@@ -52,6 +52,7 @@ export async function openSqliteInteractiveInteractionStoreForRead(lease) {
|
|
|
52
52
|
access: 'read',
|
|
53
53
|
readInteraction: (requestId) => run(() => store.readInteraction(requestId)),
|
|
54
54
|
listSessionPending: (sessionId) => run(() => store.listSessionPending(sessionId)),
|
|
55
|
+
listTurnInteractions: (sessionId, turnId) => run(() => store.listTurnInteractions(sessionId, turnId)),
|
|
55
56
|
listPending: (filter) => run(() => store.listPending(filter)),
|
|
56
57
|
readClientCapabilitySessionGrant: (key) => run(() => store.readClientCapabilitySessionGrant(key)),
|
|
57
58
|
});
|
|
@@ -119,6 +120,7 @@ export async function openSqliteInteractiveInteractionStoreForWrite(lease, store
|
|
|
119
120
|
access: 'write',
|
|
120
121
|
readInteraction: (requestId) => run(() => store.readInteraction(requestId)),
|
|
121
122
|
listSessionPending: (sessionId) => run(() => store.listSessionPending(sessionId)),
|
|
123
|
+
listTurnInteractions: (sessionId, turnId) => run(() => store.listTurnInteractions(sessionId, turnId)),
|
|
122
124
|
listPending: (filter) => run(() => store.listPending(filter)),
|
|
123
125
|
readClientCapabilitySessionGrant: (key) => run(() => store.readClientCapabilitySessionGrant(key)),
|
|
124
126
|
establishRequest: (input) => run(() => store.establishRequest(input)),
|
|
@@ -301,6 +303,17 @@ class SqliteInteractionStore {
|
|
|
301
303
|
assertId(requestId);
|
|
302
304
|
return readSqliteInteraction(this.#lease, requestId);
|
|
303
305
|
}
|
|
306
|
+
async listTurnInteractions(sessionId, turnId) {
|
|
307
|
+
assertId(sessionId);
|
|
308
|
+
assertId(turnId);
|
|
309
|
+
const rows = this.#lease.database
|
|
310
|
+
.prepare(`
|
|
311
|
+
SELECT request_id FROM core_interaction_requests
|
|
312
|
+
WHERE session_id = ? AND turn_id = ? ORDER BY created_at, request_id
|
|
313
|
+
`)
|
|
314
|
+
.all(sessionId, turnId);
|
|
315
|
+
return rows.map(({ request_id }) => readSqliteInteraction(this.#lease, request_id));
|
|
316
|
+
}
|
|
304
317
|
async listSessionPending(sessionId) {
|
|
305
318
|
return this.listPending({ sessionId });
|
|
306
319
|
}
|
|
@@ -16,9 +16,10 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
+
import { watch } from 'node:fs';
|
|
19
20
|
import { readFile } from 'node:fs/promises';
|
|
20
|
-
import { dirname, join } from 'node:path';
|
|
21
|
-
import { MCP_CONFIG_VERSION, createDefaultMcpConfig, isNonLoopbackCleartextHttp, } from '@maka/core/mcp';
|
|
21
|
+
import { basename, dirname, join } from 'node:path';
|
|
22
|
+
import { MCP_CONFIG_VERSION, createDefaultMcpConfig, isNonLoopbackCleartextHttp, mcpConfigChangeRetiresCredentials, } from '@maka/core/mcp';
|
|
22
23
|
import { writeAtomicFile } from './atomic-file-write.js';
|
|
23
24
|
import { withProcessLifetimeFileUpdateLock } from './process-lifetime-file-update-lock.js';
|
|
24
25
|
import { hardenDirectory } from './stable-storage.js';
|
|
@@ -30,6 +31,9 @@ const MAX_ID_LENGTH = 128;
|
|
|
30
31
|
const MAX_STRING_LENGTH = 8_192;
|
|
31
32
|
const MAX_CONFIG_BYTES = 1_048_576;
|
|
32
33
|
const FORBIDDEN_KEYS = new Set(['__proto__', 'prototype', 'constructor']);
|
|
34
|
+
// An atomic replace is a temp write plus a rename; one settle window turns
|
|
35
|
+
// that burst into one notification.
|
|
36
|
+
const CHANGE_SETTLE_MS = 150;
|
|
33
37
|
export class McpConfigSourceError extends Error {
|
|
34
38
|
reason;
|
|
35
39
|
version;
|
|
@@ -54,6 +58,64 @@ export class McpServerExistsError extends Error {
|
|
|
54
58
|
export function createMcpConfigStore(workspaceRoot) {
|
|
55
59
|
return new FileMcpConfigStore(join(workspaceRoot, 'mcp.json'));
|
|
56
60
|
}
|
|
61
|
+
/** Watches the directory, not the file: an atomic replace renames a new
|
|
62
|
+
* inode over the old one, which ends a watch on the file itself. */
|
|
63
|
+
export function subscribeMcpConfigFileChanges(path, listener) {
|
|
64
|
+
const name = basename(path);
|
|
65
|
+
let timer;
|
|
66
|
+
let watcher;
|
|
67
|
+
const settle = () => {
|
|
68
|
+
clearTimeout(timer);
|
|
69
|
+
timer = setTimeout(() => listener(), CHANGE_SETTLE_MS);
|
|
70
|
+
};
|
|
71
|
+
try {
|
|
72
|
+
watcher = watch(dirname(path), { persistent: false }, (_event, filename) => {
|
|
73
|
+
if (filename === null || filename.toString() === name)
|
|
74
|
+
settle();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
queueMicrotask(() => listener(error));
|
|
79
|
+
return () => { };
|
|
80
|
+
}
|
|
81
|
+
settle();
|
|
82
|
+
const stop = () => {
|
|
83
|
+
clearTimeout(timer);
|
|
84
|
+
watcher.close();
|
|
85
|
+
};
|
|
86
|
+
watcher.on('error', (error) => {
|
|
87
|
+
stop();
|
|
88
|
+
listener(error);
|
|
89
|
+
});
|
|
90
|
+
return stop;
|
|
91
|
+
}
|
|
92
|
+
export class McpConfigurationValidationError extends Error {
|
|
93
|
+
constructor(cause) {
|
|
94
|
+
super(cause instanceof Error ? cause.message : 'Invalid MCP configuration', { cause });
|
|
95
|
+
this.name = 'McpConfigurationValidationError';
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** Validate before retiring credentials, and retire before publishing the
|
|
99
|
+
* replacement. Both effects run under the config file's cross-process lock. */
|
|
100
|
+
export function updateMcpConfiguration(store, prepare, retireCredentials) {
|
|
101
|
+
return store.transform(async (current) => {
|
|
102
|
+
const proposed = prepare(current);
|
|
103
|
+
let next;
|
|
104
|
+
try {
|
|
105
|
+
next = normalizeMcpConfig(proposed);
|
|
106
|
+
assertMcpEndpointPolicyOnChanges(current, next);
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
throw new McpConfigurationValidationError(error);
|
|
110
|
+
}
|
|
111
|
+
for (const [serverId, previous] of Object.entries(current.mcpServers)) {
|
|
112
|
+
if (mcpConfigChangeRetiresCredentials(previous, next.mcpServers[serverId])) {
|
|
113
|
+
await retireCredentials(serverId, previous);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return next;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
57
119
|
export function normalizeMcpConfig(value) {
|
|
58
120
|
if (!isRecord(value))
|
|
59
121
|
throw new Error('MCP config must be an object');
|
|
@@ -114,6 +176,21 @@ class FileMcpConfigStore {
|
|
|
114
176
|
return this.withUpdateLock(() => this.readOrCreate());
|
|
115
177
|
}
|
|
116
178
|
}
|
|
179
|
+
subscribeChanges(listener) {
|
|
180
|
+
let stop;
|
|
181
|
+
let stopped = false;
|
|
182
|
+
void this.ensureDirectory().then(() => {
|
|
183
|
+
if (!stopped)
|
|
184
|
+
stop = subscribeMcpConfigFileChanges(this.path, listener);
|
|
185
|
+
}, (error) => {
|
|
186
|
+
if (!stopped)
|
|
187
|
+
listener(error);
|
|
188
|
+
});
|
|
189
|
+
return () => {
|
|
190
|
+
stopped = true;
|
|
191
|
+
stop?.();
|
|
192
|
+
};
|
|
193
|
+
}
|
|
117
194
|
async transform(apply) {
|
|
118
195
|
return this.withUpdateLock(async () => {
|
|
119
196
|
const current = await this.readOrCreate();
|
|
@@ -280,6 +357,18 @@ function normalizeOAuth(value, serverId) {
|
|
|
280
357
|
if (!isRecord(value))
|
|
281
358
|
throw new Error(`${serverId}.oauth must be an object`);
|
|
282
359
|
const result = {};
|
|
360
|
+
if (value.issuer !== undefined) {
|
|
361
|
+
const issuer = nonEmptyString(value.issuer, `${serverId}.oauth.issuer`);
|
|
362
|
+
const parsed = new URL(issuer);
|
|
363
|
+
if (!['https:', 'http:'].includes(parsed.protocol) ||
|
|
364
|
+
parsed.username ||
|
|
365
|
+
parsed.password ||
|
|
366
|
+
parsed.search ||
|
|
367
|
+
parsed.hash) {
|
|
368
|
+
throw new Error(`${serverId}.oauth.issuer must be an HTTP(S) issuer URL without credentials, query or fragment`);
|
|
369
|
+
}
|
|
370
|
+
result.issuer = issuer;
|
|
371
|
+
}
|
|
283
372
|
if (value.clientId !== undefined) {
|
|
284
373
|
result.clientId = nonEmptyString(value.clientId, `${serverId}.oauth.clientId`);
|
|
285
374
|
}
|
|
@@ -138,6 +138,8 @@ class OperationalStateDatabaseOwner {
|
|
|
138
138
|
references = 0;
|
|
139
139
|
closed = false;
|
|
140
140
|
transactionDepth = 0;
|
|
141
|
+
transactionWrote = false;
|
|
142
|
+
writeViewRevisionValue = 0;
|
|
141
143
|
settledCallbacks = [];
|
|
142
144
|
constructor(databasePath, options) {
|
|
143
145
|
this.databasePath = databasePath;
|
|
@@ -173,6 +175,7 @@ class OperationalStateDatabaseOwner {
|
|
|
173
175
|
return {
|
|
174
176
|
database: this.database,
|
|
175
177
|
databasePath: this.databasePath,
|
|
178
|
+
writeViewRevision: () => this.writeViewRevisionValue,
|
|
176
179
|
transaction: (mode, operation) => this.transaction(mode, operation),
|
|
177
180
|
onTransactionSettled: (callback) => {
|
|
178
181
|
if (this.transactionDepth === 0)
|
|
@@ -220,22 +223,33 @@ class OperationalStateDatabaseOwner {
|
|
|
220
223
|
transaction(mode, operation) {
|
|
221
224
|
if (this.closed)
|
|
222
225
|
throw new Error('Operational state database is closed');
|
|
223
|
-
if (this.transactionDepth > 0)
|
|
226
|
+
if (this.transactionDepth > 0) {
|
|
227
|
+
if (mode === 'write')
|
|
228
|
+
this.transactionWrote = true;
|
|
224
229
|
return operation();
|
|
230
|
+
}
|
|
225
231
|
this.database.exec(mode === 'write' ? 'BEGIN IMMEDIATE' : 'BEGIN');
|
|
226
232
|
this.transactionDepth += 1;
|
|
233
|
+
this.transactionWrote = mode === 'write';
|
|
227
234
|
let result;
|
|
228
235
|
try {
|
|
229
236
|
result = operation();
|
|
230
237
|
this.database.exec('COMMIT');
|
|
231
238
|
}
|
|
232
239
|
catch (error) {
|
|
240
|
+
const transactionWrote = this.transactionWrote;
|
|
233
241
|
rollback(this.database);
|
|
234
242
|
this.transactionDepth -= 1;
|
|
243
|
+
this.transactionWrote = false;
|
|
244
|
+
if (transactionWrote)
|
|
245
|
+
this.writeViewRevisionValue += 1;
|
|
235
246
|
this.settle(false);
|
|
236
247
|
throw error;
|
|
237
248
|
}
|
|
238
249
|
this.transactionDepth -= 1;
|
|
250
|
+
if (this.transactionWrote)
|
|
251
|
+
this.writeViewRevisionValue += 1;
|
|
252
|
+
this.transactionWrote = false;
|
|
239
253
|
this.settle(true);
|
|
240
254
|
return result;
|
|
241
255
|
}
|
|
@@ -53,6 +53,7 @@ export function observeInteractivePlanStoreWriter(source, onChanged, onPublicati
|
|
|
53
53
|
access: writer.access,
|
|
54
54
|
[writerBrand]: true,
|
|
55
55
|
readState: (sessionId) => writer.readState(sessionId),
|
|
56
|
+
listPlanRecoverySessionIds: () => writer.listPlanRecoverySessionIds(),
|
|
56
57
|
readOperationReceipt: (sessionId, operationId, operationInput) => writer.readOperationReceipt(sessionId, operationId, operationInput),
|
|
57
58
|
submitProposal: (input) => publish(input.sessionId, () => writer.submitProposal(input)),
|
|
58
59
|
requestRevision: (input) => publish(input.sessionId, () => writer.requestRevision(input)),
|
|
@@ -136,6 +137,7 @@ function createWriterFacade(lease, store) {
|
|
|
136
137
|
access: 'write',
|
|
137
138
|
[writerBrand]: true,
|
|
138
139
|
readState: (sessionId) => run(() => store.readState(sessionId)),
|
|
140
|
+
listPlanRecoverySessionIds: () => run(() => store.listPlanRecoverySessionIds()),
|
|
139
141
|
readOperationReceipt: (sessionId, operationId, operationInput) => run(() => store.readOperationReceipt(sessionId, operationId, structuredClone(operationInput))),
|
|
140
142
|
submitProposal: (input) => run(() => store.submitProposal(cloneSubmit(input))),
|
|
141
143
|
requestRevision: (input) => run(() => store.requestRevision(cloneInput(input))),
|
|
@@ -43,6 +43,36 @@ class SqlitePlanStoreImpl {
|
|
|
43
43
|
async readState(sessionId) {
|
|
44
44
|
return (await this.readLedger(sessionId)).state;
|
|
45
45
|
}
|
|
46
|
+
async listPlanRecoverySessionIds() {
|
|
47
|
+
const rows = this.#lease.database
|
|
48
|
+
.prepare(`
|
|
49
|
+
WITH lifecycle AS (
|
|
50
|
+
SELECT
|
|
51
|
+
session_id,
|
|
52
|
+
json_extract(record_json, '$.type') AS event_type,
|
|
53
|
+
ROW_NUMBER() OVER (PARTITION BY session_id ORDER BY sequence DESC) AS position
|
|
54
|
+
FROM workflow_plan_events
|
|
55
|
+
WHERE json_extract(record_json, '$.type') IN (
|
|
56
|
+
'plan_approved',
|
|
57
|
+
'plan_execution_completed',
|
|
58
|
+
'plan_execution_cancelled',
|
|
59
|
+
'plan_execution_interrupted',
|
|
60
|
+
'plan_execution_resumed'
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
SELECT session_id
|
|
64
|
+
FROM lifecycle
|
|
65
|
+
WHERE position = 1
|
|
66
|
+
AND event_type IN ('plan_approved', 'plan_execution_resumed')
|
|
67
|
+
ORDER BY session_id
|
|
68
|
+
`)
|
|
69
|
+
.all();
|
|
70
|
+
return rows.map((row) => {
|
|
71
|
+
if (typeof row.session_id !== 'string')
|
|
72
|
+
throw new Error('Invalid SQLite Plan row');
|
|
73
|
+
return row.session_id;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
46
76
|
async readOperationReceipt(sessionId, operationId, operationInput) {
|
|
47
77
|
assertSafeId(sessionId);
|
|
48
78
|
assertSafeId(operationId);
|
|
@@ -40,6 +40,7 @@ export async function openRuntimeEventReadPersistence(input) {
|
|
|
40
40
|
kind: 'sqlite',
|
|
41
41
|
runtimeEventStore: Object.freeze({
|
|
42
42
|
listSessionInvocations: (sessionId) => store.listSessionInvocations(sessionId),
|
|
43
|
+
listInvocationRecoveryInventory: (sessionIds) => store.listInvocationRecoveryInventory(sessionIds),
|
|
43
44
|
readRunInvocation: (sessionId, runId) => store.readRunInvocation(sessionId, runId),
|
|
44
45
|
listSessionInvocationsBounded: (sessionId, limit) => store.listSessionInvocationsBounded(sessionId, limit),
|
|
45
46
|
listSessionInvocationsPage: (sessionId, input) => store.listSessionInvocationsPage(sessionId, input),
|
|
@@ -16,21 +16,22 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
-
import { applyConnectionModelOverrides, modelLimitsConflict } from '@maka/core/model-thinking';
|
|
19
|
+
import { applyConnectionModelOverrides, declaredModelApiProtocol, modelLimitsConflict, } from '@maka/core/model-thinking';
|
|
20
20
|
import { resolveConnectionModelCatalog } from '@maka/core/model-catalog';
|
|
21
21
|
import { lookupModelMetadata } from '@maka/core/model-metadata';
|
|
22
22
|
import { LegacyModelFactsReader } from '../model-facts-store.js';
|
|
23
23
|
import { randomUUID } from 'node:crypto';
|
|
24
24
|
import { isDeepStrictEqual } from 'node:util';
|
|
25
|
-
import { CONNECTION_CATALOG_MAX_CONNECTIONS, decodeCanonicalConnectionCatalogEntry, decodeConnectionName, decodeConnectionSlug, decodeConnectionTarget, decodeConnectionTestSummary, decodeProviderType, decodeRuntimePolicyEntityId, normalizeConnectionCatalogEntryUpdateForProvider, normalizeConnectionModelDiscoveryResult, normalizeCreateCatalogConnectionInput, normalizeRemoveCatalogConnectionInput, normalizeSetDefaultConnectionTargetInput, normalizeUpdateCatalogConnectionInput, } from '@maka/core/runtime-policy';
|
|
25
|
+
import { CONNECTION_CATALOG_MAX_CONNECTIONS, decodeCanonicalConnectionCatalogEntry, decodeConnectionName, decodeConnectionSlug, decodeConnectionTarget, decodeConnectionTestSummary, decodeDefaultApiProtocol, decodeProviderType, decodeRuntimePolicyEntityId, normalizeConnectionCatalogEntryUpdateForProvider, normalizeConnectionModelDiscoveryResult, normalizeCreateCatalogConnectionInput, normalizeRemoveCatalogConnectionInput, normalizeSetDefaultConnectionTargetInput, normalizeUpdateCatalogConnectionInput, } from '@maka/core/runtime-policy';
|
|
26
26
|
import { PROVIDER_REGISTRY, reconcileConnectionAfterModelFetch } from '@maka/core/llm-connections';
|
|
27
27
|
import { modelIdAliasesForProvider, providerReportsCompleteModelCatalog, } from '@maka/core/model-metadata';
|
|
28
28
|
import { isRetiredProvider } from '@maka/core/provider-registry';
|
|
29
29
|
import { deepFreeze, nextRevision, record, revision, unique } from './codec.js';
|
|
30
|
+
import { upgradeLegacyCustomProvider } from './legacy-custom-connection.js';
|
|
30
31
|
import { codecError, decodeConnectionInput, decodePersistedDomain, RuntimePolicyStoreError, } from './errors.js';
|
|
31
32
|
import { CATALOG_DOCUMENT_MAX_BYTES, readBoundedJsonDocument, serializeJsonDocument, writeJsonDocument, } from './document-io.js';
|
|
32
33
|
const FILE = 'connection-catalog.json';
|
|
33
|
-
const SCHEMA_VERSION =
|
|
34
|
+
const SCHEMA_VERSION = 3;
|
|
34
35
|
export class ConnectionCatalogDocumentOwner {
|
|
35
36
|
async read(root) {
|
|
36
37
|
const value = await readBoundedJsonDocument(root, FILE, CATALOG_DOCUMENT_MAX_BYTES);
|
|
@@ -43,13 +44,18 @@ export class ConnectionCatalogDocumentOwner {
|
|
|
43
44
|
'defaultTarget',
|
|
44
45
|
'connections',
|
|
45
46
|
]);
|
|
46
|
-
if (raw.schemaVersion !== SCHEMA_VERSION &&
|
|
47
|
+
if (raw.schemaVersion !== SCHEMA_VERSION &&
|
|
48
|
+
raw.schemaVersion !== 2 &&
|
|
49
|
+
raw.schemaVersion !== 1) {
|
|
47
50
|
throw codecError('invalid_document', `${FILE} has an unsupported schema version`);
|
|
48
51
|
}
|
|
49
52
|
if (!Array.isArray(raw.connections) ||
|
|
50
53
|
raw.connections.length > CONNECTION_CATALOG_MAX_CONNECTIONS) {
|
|
51
54
|
throw codecError('invalid_document', `${FILE}.connections must be a bounded array`);
|
|
52
55
|
}
|
|
56
|
+
// v3 folded the three per-protocol custom types into `custom`; the next
|
|
57
|
+
// catalog write persists the upgraded rows.
|
|
58
|
+
const upgrade = raw.schemaVersion === SCHEMA_VERSION ? (item) => item : upgradeLegacyCustomProvider;
|
|
53
59
|
// Releases before #3054 could persist the non-executable Gemini account
|
|
54
60
|
// preview. Keep the raw file recoverable on read, but omit retired entries
|
|
55
61
|
// from the active catalog; the next catalog mutation writes the canonical
|
|
@@ -72,7 +78,7 @@ export class ConnectionCatalogDocumentOwner {
|
|
|
72
78
|
const legacyFacts = legacyRead?.document.overrides;
|
|
73
79
|
const connections = maintainedConnections.map((item) => {
|
|
74
80
|
if (raw.schemaVersion !== 1)
|
|
75
|
-
return decodePersistedDomain(() => decodeCanonicalConnectionCatalogEntry(item));
|
|
81
|
+
return decodePersistedDomain(() => decodeCanonicalConnectionCatalogEntry(upgrade(item)));
|
|
76
82
|
const legacy = item;
|
|
77
83
|
const { relayModelProfiles, lastTestModelFactsFingerprint: _fingerprint, ...base } = legacy;
|
|
78
84
|
const overrides = new Map();
|
|
@@ -117,10 +123,10 @@ export class ConnectionCatalogDocumentOwner {
|
|
|
117
123
|
}),
|
|
118
124
|
});
|
|
119
125
|
}
|
|
120
|
-
return decodePersistedDomain(() => decodeCanonicalConnectionCatalogEntry({
|
|
126
|
+
return decodePersistedDomain(() => decodeCanonicalConnectionCatalogEntry(upgrade({
|
|
121
127
|
...base,
|
|
122
128
|
...(overrides.size ? { modelOverrides: Object.fromEntries(overrides) } : {}),
|
|
123
|
-
}));
|
|
129
|
+
})));
|
|
124
130
|
});
|
|
125
131
|
const catalogIdentities = [...retiredConnections, ...connections];
|
|
126
132
|
unique(catalogIdentities.map((item) => item.slug), `${FILE} connection slugs`, 'invalid_document');
|
|
@@ -227,6 +233,9 @@ export class ConnectionCatalogDocumentOwner {
|
|
|
227
233
|
name: changes.name,
|
|
228
234
|
providerType: previous.providerType,
|
|
229
235
|
...(changes.baseUrl === undefined ? {} : { baseUrl: changes.baseUrl }),
|
|
236
|
+
...(previous.defaultApiProtocol === undefined
|
|
237
|
+
? {}
|
|
238
|
+
: { defaultApiProtocol: previous.defaultApiProtocol }),
|
|
230
239
|
enabled: changes.enabled,
|
|
231
240
|
enabledModelIds: changes.enabledModelIds,
|
|
232
241
|
// Profile-table semantics, in order:
|
|
@@ -359,10 +368,11 @@ export class ConnectionCatalogDocumentOwner {
|
|
|
359
368
|
const { lastTest: _lastTest, ...discoveredWithoutLastTest } = discovered;
|
|
360
369
|
return this.writePatchedResult(root, current, index, testBasisChanged ? discoveredWithoutLastTest : discovered, defaultTarget);
|
|
361
370
|
}
|
|
362
|
-
prepareOnboardingUpsert(current, rawConnectionId, rawSlug, rawProviderType, rawName, rawBaseUrl, rawEnabledModelIds, rawResult, invalidateLastTest) {
|
|
371
|
+
prepareOnboardingUpsert(current, rawConnectionId, rawSlug, rawProviderType, rawDefaultApiProtocol, rawName, rawBaseUrl, rawEnabledModelIds, rawResult, invalidateLastTest) {
|
|
363
372
|
const connectionId = decodeConnectionInput(() => decodeRuntimePolicyEntityId(rawConnectionId));
|
|
364
373
|
const slug = decodeConnectionInput(() => decodeConnectionSlug(rawSlug));
|
|
365
374
|
const providerType = decodeConnectionInput(() => decodeProviderType(rawProviderType));
|
|
375
|
+
const defaultApiProtocol = decodeConnectionInput(() => decodeDefaultApiProtocol(rawDefaultApiProtocol, providerType));
|
|
366
376
|
const requestedName = rawName === null ? null : decodeConnectionInput(() => decodeConnectionName(rawName));
|
|
367
377
|
const definition = PROVIDER_REGISTRY[providerType];
|
|
368
378
|
// Identity first: the intent's connectionId names the connection being
|
|
@@ -371,7 +381,8 @@ export class ConnectionCatalogDocumentOwner {
|
|
|
371
381
|
// slug. Only a genuinely new connection lands at the derived slug.
|
|
372
382
|
const index = current.connections.findIndex((connection) => connection.connectionId === connectionId);
|
|
373
383
|
const previous = current.connections[index];
|
|
374
|
-
if (previous &&
|
|
384
|
+
if (previous &&
|
|
385
|
+
(previous.providerType !== providerType || previous.defaultApiProtocol !== defaultApiProtocol)) {
|
|
375
386
|
return { kind: 'slug_conflict' };
|
|
376
387
|
}
|
|
377
388
|
if (previous && previous.slug !== slug) {
|
|
@@ -422,6 +433,7 @@ export class ConnectionCatalogDocumentOwner {
|
|
|
422
433
|
slug,
|
|
423
434
|
name: definition.label,
|
|
424
435
|
providerType,
|
|
436
|
+
...(defaultApiProtocol === undefined ? {} : { defaultApiProtocol }),
|
|
425
437
|
enabled: false,
|
|
426
438
|
enabledModelIds: [],
|
|
427
439
|
models: [],
|
|
@@ -627,17 +639,16 @@ export function findConnection(document, identity) {
|
|
|
627
639
|
return document.connections.find((item) => sameConnectionIdentity(item, identity));
|
|
628
640
|
}
|
|
629
641
|
export function connectionTestModelBasis(connection) {
|
|
630
|
-
const
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
])
|
|
634
|
-
for (const model of applyConnectionModelOverrides(connection).models) {
|
|
635
|
-
models.set(model.id, { id: model.id, apiProtocol: model.apiProtocol });
|
|
636
|
-
}
|
|
642
|
+
const ids = new Set([
|
|
643
|
+
...connection.enabledModelIds,
|
|
644
|
+
...applyConnectionModelOverrides(connection).models.map((model) => model.id),
|
|
645
|
+
]);
|
|
637
646
|
return {
|
|
638
647
|
enabledModelIds: [...connection.enabledModelIds],
|
|
639
648
|
modelSource: connection.modelSource,
|
|
640
|
-
models: [...
|
|
649
|
+
models: [...ids]
|
|
650
|
+
.sort((a, b) => a.localeCompare(b))
|
|
651
|
+
.map((id) => ({ id, apiProtocol: declaredModelApiProtocol(connection, id) })),
|
|
641
652
|
};
|
|
642
653
|
}
|
|
643
654
|
export function sameConnectionTestModelBasis(actual, expected) {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import { randomUUID } from 'node:crypto';
|
|
20
20
|
import { isDeepStrictEqual } from 'node:util';
|
|
21
|
-
import { CONNECTION_CATALOG_MAX_CONNECTIONS, decodeConnectionModelId, connectionCredentialTarget, decodeConnectionCredentialTarget, decodeConnectionName, decodeConnectionSlug, decodeProviderType, decodeRuntimePolicyEntityId, decodeCredentialLocator, normalizeDeleteCredentialInput, normalizeRemoveCatalogConnectionInput, normalizeRequestHeaderUpdates, normalizeRequestHeaders, normalizeSetCredentialInput, parseRequestHeaders, serializeRequestHeaders, RequestCustomizationValidationError, normalizeCredentialSecret, normalizeCatalogConnectionBaseUrl, normalizeNetworkProxyUpdate, networkProxyCredentialTarget, } from '@maka/core/runtime-policy';
|
|
21
|
+
import { CONNECTION_CATALOG_MAX_CONNECTIONS, decodeConnectionModelId, connectionCredentialTarget, decodeConnectionCredentialTarget, decodeConnectionName, decodeConnectionSlug, decodeDefaultApiProtocol, decodeProviderType, decodeRuntimePolicyEntityId, decodeCredentialLocator, normalizeDeleteCredentialInput, normalizeRemoveCatalogConnectionInput, normalizeRequestHeaderUpdates, normalizeRequestHeaders, normalizeSetCredentialInput, parseRequestHeaders, serializeRequestHeaders, RequestCustomizationValidationError, normalizeCredentialSecret, normalizeCatalogConnectionBaseUrl, normalizeNetworkProxyUpdate, networkProxyCredentialTarget, } from '@maka/core/runtime-policy';
|
|
22
22
|
import { applyConnectionModelOverrides } from '@maka/core/model-thinking';
|
|
23
23
|
import { deriveProviderAuthContract } from '@maka/core/provider-auth';
|
|
24
24
|
import { isRetiredProvider } from '@maka/core/provider-registry';
|
|
@@ -806,6 +806,7 @@ export class RuntimePolicyCoordinator {
|
|
|
806
806
|
const requestedSlug = requestedTarget.slug === undefined
|
|
807
807
|
? null
|
|
808
808
|
: decodeConnectionInput(() => decodeConnectionSlug(requestedTarget.slug));
|
|
809
|
+
const defaultApiProtocol = decodeConnectionInput(() => decodeDefaultApiProtocol(requestedTarget.defaultApiProtocol, providerType));
|
|
809
810
|
target = {
|
|
810
811
|
kind: 'create',
|
|
811
812
|
candidate: {
|
|
@@ -813,6 +814,7 @@ export class RuntimePolicyCoordinator {
|
|
|
813
814
|
slug: requestedSlug ??
|
|
814
815
|
deriveConnectionSlug(providerType, catalog.connections.map((connection) => connection.slug)),
|
|
815
816
|
providerType,
|
|
817
|
+
...(defaultApiProtocol === undefined ? {} : { defaultApiProtocol }),
|
|
816
818
|
},
|
|
817
819
|
slugRequested: requestedSlug !== null,
|
|
818
820
|
name: requestedTarget.name === undefined
|
|
@@ -831,6 +833,9 @@ export class RuntimePolicyCoordinator {
|
|
|
831
833
|
connectionId: existing.connectionId,
|
|
832
834
|
slug: existing.slug,
|
|
833
835
|
providerType: existing.providerType,
|
|
836
|
+
...(existing.defaultApiProtocol === undefined
|
|
837
|
+
? {}
|
|
838
|
+
: { defaultApiProtocol: existing.defaultApiProtocol }),
|
|
834
839
|
},
|
|
835
840
|
revision: existing.revision,
|
|
836
841
|
};
|
|
@@ -1034,11 +1039,12 @@ export class RuntimePolicyCoordinator {
|
|
|
1034
1039
|
connectionId,
|
|
1035
1040
|
slug: candidate.slug,
|
|
1036
1041
|
providerType: candidate.providerType,
|
|
1042
|
+
defaultApiProtocol: candidate.defaultApiProtocol,
|
|
1037
1043
|
name: basis.target.kind === 'create' ? basis.target.name : null,
|
|
1038
1044
|
baseUrl: basis.baseUrl,
|
|
1039
1045
|
invalidateLastTest,
|
|
1040
1046
|
});
|
|
1041
|
-
const catalogPreflight = this.catalog.prepareOnboardingUpsert(catalog, intent.connectionId, intent.slug, intent.providerType, intent.name, intent.baseUrl, intent.enabledModelIds, intent.discovery, intent.invalidateLastTest);
|
|
1047
|
+
const catalogPreflight = this.catalog.prepareOnboardingUpsert(catalog, intent.connectionId, intent.slug, intent.providerType, intent.defaultApiProtocol, intent.name, intent.baseUrl, intent.enabledModelIds, intent.discovery, intent.invalidateLastTest);
|
|
1042
1048
|
if (catalogPreflight.kind === 'slug_conflict') {
|
|
1043
1049
|
if (basis.target.kind === 'create' && basis.target.slugRequested) {
|
|
1044
1050
|
return deepFreeze({ kind: 'slug_taken' });
|
|
@@ -1468,7 +1474,7 @@ export class RuntimePolicyCoordinator {
|
|
|
1468
1474
|
// Validate the durable identity and final catalog shape before touching
|
|
1469
1475
|
// the vault. A damaged v2 intent must not rotate a real connection's
|
|
1470
1476
|
// credential before discovering that its ID/slug pair cannot commit.
|
|
1471
|
-
const prepared = this.catalog.prepareOnboardingUpsert(catalog, intent.connectionId, slug, intent.providerType, intent.name, intent.baseUrl, intent.enabledModelIds, intent.discovery, intent.invalidateLastTest);
|
|
1477
|
+
const prepared = this.catalog.prepareOnboardingUpsert(catalog, intent.connectionId, slug, intent.providerType, intent.defaultApiProtocol, intent.name, intent.baseUrl, intent.enabledModelIds, intent.discovery, intent.invalidateLastTest);
|
|
1472
1478
|
if (prepared.kind === 'slug_conflict') {
|
|
1473
1479
|
throw codecError('invalid_document', intent.schemaVersion === 1
|
|
1474
1480
|
? 'Legacy onboarding intent conflicts with the connection id'
|
|
@@ -237,7 +237,8 @@ function sameLocator(left, right) {
|
|
|
237
237
|
if (left.scope === 'web_search' && right.scope === 'web_search') {
|
|
238
238
|
return left.provider === right.provider;
|
|
239
239
|
}
|
|
240
|
-
return left.scope === 'network_proxy' && right.scope === 'network_proxy'
|
|
240
|
+
return ((left.scope === 'network_proxy' && right.scope === 'network_proxy') ||
|
|
241
|
+
(left.scope === 'jev' && right.scope === 'jev'));
|
|
241
242
|
}
|
|
242
243
|
function locatorKey(locator) {
|
|
243
244
|
switch (locator.scope) {
|
|
@@ -245,6 +246,8 @@ function locatorKey(locator) {
|
|
|
245
246
|
return `connection:${locator.connectionId}:${locator.kind}`;
|
|
246
247
|
case 'web_search':
|
|
247
248
|
return `web_search:${locator.provider}:api_key`;
|
|
249
|
+
case 'jev':
|
|
250
|
+
return 'jev:api_key';
|
|
248
251
|
case 'network_proxy':
|
|
249
252
|
return 'network_proxy:password';
|
|
250
253
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
const LEGACY_CUSTOM_PROVIDER_PROTOCOLS = {
|
|
20
|
+
'openai-compatible': 'openai-chat',
|
|
21
|
+
'openai-responses-compatible': 'openai-responses',
|
|
22
|
+
'anthropic-compatible': 'anthropic-messages',
|
|
23
|
+
};
|
|
24
|
+
/** Rewrites a raw record naming one of the per-protocol custom types that `custom` replaced. */
|
|
25
|
+
export function upgradeLegacyCustomProvider(item) {
|
|
26
|
+
if (typeof item !== 'object' || item === null)
|
|
27
|
+
return item;
|
|
28
|
+
const providerType = Reflect.get(item, 'providerType');
|
|
29
|
+
if (typeof providerType !== 'string' ||
|
|
30
|
+
!Object.hasOwn(LEGACY_CUSTOM_PROVIDER_PROTOCOLS, providerType)) {
|
|
31
|
+
return item;
|
|
32
|
+
}
|
|
33
|
+
const upgraded = {
|
|
34
|
+
...item,
|
|
35
|
+
providerType: 'custom',
|
|
36
|
+
defaultApiProtocol: LEGACY_CUSTOM_PROVIDER_PROTOCOLS[providerType],
|
|
37
|
+
};
|
|
38
|
+
return providerType === 'anthropic-compatible' ? keepInferredHostedSearch(upgraded) : upgraded;
|
|
39
|
+
}
|
|
40
|
+
// `anthropic-compatible` inferred hosted web search for this one model; `custom`
|
|
41
|
+
// only honors a declaration, so a migrated catalog row gets one written for it.
|
|
42
|
+
const HOSTED_SEARCH_MODEL = 'deepseek-v4-flash';
|
|
43
|
+
function keepInferredHostedSearch(row) {
|
|
44
|
+
const models = Reflect.get(row, 'models');
|
|
45
|
+
const enabled = Reflect.get(row, 'enabledModelIds');
|
|
46
|
+
if (!Array.isArray(models) ||
|
|
47
|
+
!(models.some((model) => model?.id === HOSTED_SEARCH_MODEL) ||
|
|
48
|
+
(Array.isArray(enabled) && enabled.includes(HOSTED_SEARCH_MODEL)))) {
|
|
49
|
+
return row;
|
|
50
|
+
}
|
|
51
|
+
const overrides = Reflect.get(row, 'modelOverrides') ?? {};
|
|
52
|
+
const current = overrides[HOSTED_SEARCH_MODEL] ?? {};
|
|
53
|
+
if (current.capabilities?.webSearch !== undefined)
|
|
54
|
+
return row;
|
|
55
|
+
return {
|
|
56
|
+
...row,
|
|
57
|
+
modelOverrides: {
|
|
58
|
+
...overrides,
|
|
59
|
+
[HOSTED_SEARCH_MODEL]: {
|
|
60
|
+
...current,
|
|
61
|
+
capabilities: { ...current.capabilities, webSearch: true },
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -18,10 +18,11 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import { unlink } from 'node:fs/promises';
|
|
20
20
|
import { join } from 'node:path';
|
|
21
|
-
import { decodeProviderType, decodeCanonicalConnectionCatalogEntry, decodeCredentialVersionBasis, decodeConnectionName, decodeConnectionSlug, decodeRuntimePolicyEntityId, normalizeCatalogConnectionBaseUrl,
|
|
21
|
+
import { decodeDefaultApiProtocol, decodeProviderType, decodeCanonicalConnectionCatalogEntry, decodeCredentialVersionBasis, decodeConnectionName, decodeConnectionSlug, decodeRuntimePolicyEntityId, normalizeCatalogConnectionBaseUrl, normalizeConnectionCatalogEntryUpdate, normalizeConnectionModelDiscoveryResult, normalizeCredentialSecret, } from '@maka/core/runtime-policy';
|
|
22
22
|
import { deriveConnectionSlug, PROVIDER_REGISTRY, providerAuthSupportsApiKey, } from '@maka/core/llm-connections';
|
|
23
23
|
import { syncDirectory } from '../stable-storage.js';
|
|
24
24
|
import { record } from './codec.js';
|
|
25
|
+
import { upgradeLegacyCustomProvider } from './legacy-custom-connection.js';
|
|
25
26
|
import { codecError, commitOutcomeUnknown, decodeConnectionInput, decodeCredentialInput, decodePersistedDomain, ioFailed, } from './errors.js';
|
|
26
27
|
import { readBoundedJsonDocument, writeJsonDocument } from './document-io.js';
|
|
27
28
|
const FILE = 'runtime-policy-onboarding.json';
|
|
@@ -31,6 +32,7 @@ const MAX_BYTES = 5 * 1024 * 1024;
|
|
|
31
32
|
export function prepareConnectionOnboardingIntent(input, source = 'input') {
|
|
32
33
|
const decode = source === 'persisted' ? decodePersistedDomain : decodeConnectionInput;
|
|
33
34
|
const providerType = decode(() => decodeProviderType(input.providerType));
|
|
35
|
+
const defaultApiProtocol = decode(() => decodeDefaultApiProtocol(input.defaultApiProtocol, providerType));
|
|
34
36
|
const definition = PROVIDER_REGISTRY[providerType];
|
|
35
37
|
if (!providerAuthSupportsApiKey(providerType) && definition.authKind !== 'oauth_token') {
|
|
36
38
|
throw codecError(source === 'persisted' ? 'invalid_document' : 'invalid_connection_input', 'Onboarding requires a provider with a connection credential');
|
|
@@ -48,12 +50,11 @@ export function prepareConnectionOnboardingIntent(input, source = 'input') {
|
|
|
48
50
|
const baseUrl = input.baseUrl === null || input.baseUrl === undefined
|
|
49
51
|
? null
|
|
50
52
|
: (decode(() => normalizeCatalogConnectionBaseUrl(input.baseUrl, providerType)) ?? null);
|
|
51
|
-
const normalized = decode(() =>
|
|
53
|
+
const normalized = decode(() => normalizeConnectionCatalogEntryUpdate({
|
|
52
54
|
name: definition.label,
|
|
53
|
-
...((baseUrl ?? definition.baseUrl) ? { baseUrl: baseUrl ?? definition.baseUrl } : {}),
|
|
54
55
|
enabled: true,
|
|
55
56
|
enabledModelIds: input.enabledModelIds,
|
|
56
|
-
}
|
|
57
|
+
}));
|
|
57
58
|
const available = new Set(discovery.models.map(({ id }) => id));
|
|
58
59
|
if (normalized.enabledModelIds.length === 0 ||
|
|
59
60
|
normalized.enabledModelIds.some((modelId) => !available.has(modelId))) {
|
|
@@ -72,6 +73,7 @@ export function prepareConnectionOnboardingIntent(input, source = 'input') {
|
|
|
72
73
|
connectionId: decode(() => decodeRuntimePolicyEntityId(input.connectionId)),
|
|
73
74
|
slug: decode(() => decodeConnectionSlug(input.slug)),
|
|
74
75
|
providerType,
|
|
76
|
+
...(defaultApiProtocol === undefined ? {} : { defaultApiProtocol }),
|
|
75
77
|
name: input.name === undefined || input.name === null
|
|
76
78
|
? null
|
|
77
79
|
: decode(() => decodeConnectionName(input.name)),
|
|
@@ -98,6 +100,7 @@ export async function readConnectionOnboardingIntent(root) {
|
|
|
98
100
|
'connectionId',
|
|
99
101
|
'slug',
|
|
100
102
|
'providerType',
|
|
103
|
+
'defaultApiProtocol',
|
|
101
104
|
'name',
|
|
102
105
|
'suppliedSecret',
|
|
103
106
|
'baseUrl',
|
|
@@ -109,11 +112,12 @@ export async function readConnectionOnboardingIntent(root) {
|
|
|
109
112
|
return decodeInteractiveOAuthEnrollmentIntent(value);
|
|
110
113
|
}
|
|
111
114
|
// `baseUrl` is allowed but not required for the oldest v1 journal shape.
|
|
112
|
-
const raw = record(value, FILE, 'invalid_document', [
|
|
115
|
+
const raw = record(upgradeLegacyCustomProvider(value), FILE, 'invalid_document', [
|
|
113
116
|
'schemaVersion',
|
|
114
117
|
'connectionId',
|
|
115
118
|
'slug',
|
|
116
119
|
'providerType',
|
|
120
|
+
'defaultApiProtocol',
|
|
117
121
|
'name',
|
|
118
122
|
'suppliedSecret',
|
|
119
123
|
'baseUrl',
|
|
@@ -134,6 +138,7 @@ export async function readConnectionOnboardingIntent(root) {
|
|
|
134
138
|
}
|
|
135
139
|
const prepared = prepareConnectionOnboardingIntent({
|
|
136
140
|
providerType: raw.providerType,
|
|
141
|
+
defaultApiProtocol: raw.defaultApiProtocol,
|
|
137
142
|
connectionId: raw.connectionId,
|
|
138
143
|
slug: raw.schemaVersion === 1 ? deriveLegacyIntentPlaceholderSlug(raw.providerType) : raw.slug,
|
|
139
144
|
name: raw.name,
|
|
@@ -84,6 +84,8 @@ export function policySnapshot(document) {
|
|
|
84
84
|
}
|
|
85
85
|
function applyMutation(policy, operation) {
|
|
86
86
|
switch (operation.kind) {
|
|
87
|
+
case 'set_jev':
|
|
88
|
+
return { ...policy, jev: operation.value };
|
|
87
89
|
case 'set_network_proxy':
|
|
88
90
|
return { ...policy, networkProxy: operation.value };
|
|
89
91
|
case 'set_personalization':
|