maka-agent 0.2.0-dev.48.20260923 → 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-onboarding.js +5 -3
- package/dist/runtime-host-session-channel.js +9 -3
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/core/dist/events.js +13 -0
- package/node_modules/@maka/core/dist/llm-connections.js +2 -5
- 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-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.js +2 -2
- package/node_modules/@maka/core/dist/runtime-policy/connection-catalog-codec.js +28 -16
- package/node_modules/@maka/core/dist/runtime-policy.js +1 -1
- package/node_modules/@maka/core/dist/session.js +23 -9
- package/node_modules/@maka/core/dist/transcript-search.js +1 -0
- package/node_modules/@maka/core/dist/usage-stats/types.js +1 -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/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 +2 -2
- package/node_modules/@maka/runtime/dist/local-web-fetch.js +23 -11
- 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/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/scheduled-task-tools.js +39 -8
- package/node_modules/@maka/runtime/dist/session-manager.js +12 -2
- 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/client/hosted-execution-target.js +7 -1
- package/node_modules/@maka/runtime-host/dist/client/session-subscription.js +3 -0
- package/node_modules/@maka/runtime-host/dist/protocol/connection-effects.js +6 -3
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +5 -1
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +4 -1
- 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-continuity.js +2 -1
- package/node_modules/@maka/runtime-host/dist/server/connection-effect-coordinator.js +3 -0
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +54 -6
- package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +38 -2
- package/node_modules/@maka/runtime-host/dist/server/generated-text.js +39 -0
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +8 -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 +2 -2
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +48 -16
- 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 +38 -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 +35 -11
- package/node_modules/@maka/storage/dist/config-transfer.js +14 -8
- package/node_modules/@maka/storage/dist/execution-stores.js +4 -3
- package/node_modules/@maka/storage/dist/interaction-store.js +13 -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/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/session-bundle-policy.js +11 -0
- package/node_modules/@maka/storage/dist/session-store.js +29 -6
- package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +3 -0
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +125 -7
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +5 -3
- package/node_modules/@maka/storage/dist/usage-screen.js +138 -108
- package/package.json +1 -1
|
@@ -112,17 +112,8 @@ export class WorkHubCoordinationActionGate {
|
|
|
112
112
|
const source = await this.#stopSource(input.actionId, proposal.expects.targetSessionId);
|
|
113
113
|
const stopFingerprint = stopActionFingerprint(input, source);
|
|
114
114
|
await this.#claimAction(input.actionId, 'stop', stopFingerprint, source.delegationId);
|
|
115
|
-
const existing = await this.#effects.readStopRequest(source.delegationId);
|
|
115
|
+
const existing = await this.#effects.readStopRequest(source.delegationId, input.actionId);
|
|
116
116
|
if (existing) {
|
|
117
|
-
if (existing.actionId !== input.actionId) {
|
|
118
|
-
// `not_owned` deliberately leaves the delegation active, so the user
|
|
119
|
-
// can and will try again with a fresh request. That later attempt has
|
|
120
|
-
// its own identity and must converge on the immutable non-destructive
|
|
121
|
-
// outcome instead of colliding with the first attempt's stop claim.
|
|
122
|
-
const resolved = await this.#effects.readStopResolution(source.delegationId);
|
|
123
|
-
if (resolved?.outcome === 'not_owned')
|
|
124
|
-
return stopResult(resolved);
|
|
125
|
-
}
|
|
126
117
|
assertStopReplay(existing, input, source, stopFingerprint);
|
|
127
118
|
return this.#stop(existing, source);
|
|
128
119
|
}
|
|
@@ -280,7 +271,7 @@ export class WorkHubCoordinationActionGate {
|
|
|
280
271
|
// nothing to converge on — and nothing destructive happened either, so
|
|
281
272
|
// that case resolves from the active links below, subject to the claim
|
|
282
273
|
// still naming what they resolve to.
|
|
283
|
-
const requested = await this.#effects.readStopRequest(claim.subject);
|
|
274
|
+
const requested = await this.#effects.readStopRequest(claim.subject, actionId);
|
|
284
275
|
if (requested) {
|
|
285
276
|
const claimed = await this.#effects.readAssignment(requested.stopsActionId);
|
|
286
277
|
if (!claimed || claimed.targetSessionId !== targetSessionId) {
|
|
@@ -302,7 +293,7 @@ export class WorkHubCoordinationActionGate {
|
|
|
302
293
|
return resolved;
|
|
303
294
|
}
|
|
304
295
|
async #soleWorkingDelegation(targetSessionId, operation) {
|
|
305
|
-
const onTarget = await this.#effects.listActiveAssignments(targetSessionId);
|
|
296
|
+
const onTarget = await this.#effects.listActiveAssignments(targetSessionId, true);
|
|
306
297
|
if (onTarget.length === 0) {
|
|
307
298
|
throw new WorkHubActionGateFailure('action_conflict', `WorkHub has no active durable delegation to ${operation} on that Session`);
|
|
308
299
|
}
|
|
@@ -323,6 +314,8 @@ export class WorkHubCoordinationActionGate {
|
|
|
323
314
|
holdingWork.push(assignment);
|
|
324
315
|
}
|
|
325
316
|
}
|
|
317
|
+
if (holdingWork.length === 0 && operation === 'resume')
|
|
318
|
+
return resolved;
|
|
326
319
|
if (holdingWork.length !== 1) {
|
|
327
320
|
throw new WorkHubActionGateFailure('action_conflict', `WorkHub ${operation} target does not identify one active durable delegation`);
|
|
328
321
|
}
|
|
@@ -331,7 +324,7 @@ export class WorkHubCoordinationActionGate {
|
|
|
331
324
|
return resolved;
|
|
332
325
|
}
|
|
333
326
|
async #stop(request, source) {
|
|
334
|
-
const resolved = await this.#effects.readStopResolution(source.delegationId);
|
|
327
|
+
const resolved = await this.#effects.readStopResolution(source.delegationId, request.actionId);
|
|
335
328
|
if (resolved)
|
|
336
329
|
return stopResultFromRecord(resolved, request);
|
|
337
330
|
const retirement = await this.#effects.retireDelegation(source, {
|
|
@@ -95,12 +95,12 @@ export class HostWorkHubCoordinationCoordinator {
|
|
|
95
95
|
readAssignment: (actionId) => this.#stores.readWorkHubAssignment(actionId),
|
|
96
96
|
// This lookup is advisory. Stop and replacement both repeat their exact
|
|
97
97
|
// proof under the Coordination and target admissions before writing.
|
|
98
|
-
listActiveAssignments: (targetSessionId) => this.#stores.readActiveWorkHubAssignmentsByTarget([targetSessionId]),
|
|
98
|
+
listActiveAssignments: (targetSessionId, includeStopped) => this.#stores.readActiveWorkHubAssignmentsByTarget([targetSessionId], undefined, includeStopped),
|
|
99
99
|
readReplacement: (delegationId) => this.#stores.readWorkHubReplacement(delegationId),
|
|
100
100
|
readReplacementAbort: (delegationId) => this.#stores.readWorkHubReplacementAbort(delegationId),
|
|
101
101
|
readSupersession: (delegationId) => this.#stores.readWorkHubSupersession(delegationId),
|
|
102
|
-
readStopRequest: (delegationId) => this.#stores.readWorkHubStopRequest(delegationId),
|
|
103
|
-
readStopResolution: (delegationId) => this.#stores.readWorkHubStopResolution(delegationId),
|
|
102
|
+
readStopRequest: (delegationId, actionId) => this.#stores.readWorkHubStopRequest(delegationId, actionId),
|
|
103
|
+
readStopResolution: (delegationId, actionId) => this.#stores.readWorkHubStopResolution(delegationId, actionId),
|
|
104
104
|
assign: options.sessionActions.assign,
|
|
105
105
|
prepareReplacement: (input) => this.#prepareReplacement(input),
|
|
106
106
|
abortReplacement: (input) => this.#abortReplacement(input),
|
|
@@ -165,7 +165,7 @@ export class HostWorkHubCoordinationCoordinator {
|
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
167
|
async #prepareStop(input) {
|
|
168
|
-
|
|
168
|
+
let suffix;
|
|
169
169
|
return this.#commitCoordinationFact({
|
|
170
170
|
// Only the two Sessions this stop can change: the one whose delegation
|
|
171
171
|
// ends, and the Coordination Session that records it. Holding a lane for
|
|
@@ -173,7 +173,14 @@ export class HostWorkHubCoordinationCoordinator {
|
|
|
173
173
|
// delegation traffic behind one stop, and the proof below needs no lane
|
|
174
174
|
// it does not already hold.
|
|
175
175
|
admissionSessionIds: [WORKHUB_COORDINATION_SESSION_ID, input.targetSessionId],
|
|
176
|
-
read: () =>
|
|
176
|
+
read: async () => {
|
|
177
|
+
// Choose the slot from the same admitted snapshot as the write.
|
|
178
|
+
const first = await this.#stores.readWorkHubStopRequest(input.stopsDelegationId);
|
|
179
|
+
suffix = workHubDestructiveClaimIdentitySuffix(first && first.actionId !== input.actionId
|
|
180
|
+
? JSON.stringify([input.stopsDelegationId, input.actionId])
|
|
181
|
+
: input.stopsDelegationId);
|
|
182
|
+
return this.#stores.readWorkHubStopRequest(input.stopsDelegationId, input.actionId);
|
|
183
|
+
},
|
|
177
184
|
build: (existing) => ({
|
|
178
185
|
type: 'workhub_coordination',
|
|
179
186
|
id: `whq_${suffix}`,
|
|
@@ -196,7 +203,7 @@ export class HostWorkHubCoordinationCoordinator {
|
|
|
196
203
|
const [replacement, supersession, activeAssignments] = await Promise.all([
|
|
197
204
|
this.#stores.readWorkHubReplacement(input.stopsDelegationId),
|
|
198
205
|
this.#stores.readWorkHubSupersession(input.stopsDelegationId),
|
|
199
|
-
this.#stores.readActiveWorkHubAssignmentsByTarget([input.targetSessionId]),
|
|
206
|
+
this.#stores.readActiveWorkHubAssignmentsByTarget([input.targetSessionId], undefined, true),
|
|
200
207
|
]);
|
|
201
208
|
if (replacement || supersession) {
|
|
202
209
|
throw new WorkHubActionGateFailure('action_conflict', 'WorkHub delegation is already being replaced');
|
|
@@ -225,9 +232,9 @@ export class HostWorkHubCoordinationCoordinator {
|
|
|
225
232
|
}
|
|
226
233
|
#resolveStop(input) {
|
|
227
234
|
const request = input.request;
|
|
228
|
-
const suffix = workHubDestructiveClaimIdentitySuffix(request.stopsDelegationId);
|
|
235
|
+
const suffix = workHubDestructiveClaimIdentitySuffix(JSON.stringify([request.stopsDelegationId, request.actionId]));
|
|
229
236
|
return this.#commitCoordinationFact({
|
|
230
|
-
read: () => this.#stores.readWorkHubStopResolution(request.stopsDelegationId),
|
|
237
|
+
read: () => this.#stores.readWorkHubStopResolution(request.stopsDelegationId, request.actionId),
|
|
231
238
|
build: (existing) => ({
|
|
232
239
|
type: 'workhub_coordination',
|
|
233
240
|
id: `whz_${suffix}`,
|
|
@@ -244,9 +251,23 @@ export class HostWorkHubCoordinationCoordinator {
|
|
|
244
251
|
outcome: input.outcome,
|
|
245
252
|
...(input.targetTurnId ? { targetTurnId: input.targetTurnId } : {}),
|
|
246
253
|
}),
|
|
254
|
+
additionalMessages: async (resolved) => {
|
|
255
|
+
const primary = await this.#stores.readWorkHubStopResolution(request.stopsDelegationId);
|
|
256
|
+
// Keep immutable per-action receipts; the delegation slot aggregates only
|
|
257
|
+
// terminal knowledge. Upgrade not_owned at a distinct immutable identity;
|
|
258
|
+
// appendMessages never replaces an existing identity.
|
|
259
|
+
if (primary && (primary.outcome !== 'not_owned' || resolved.outcome === 'not_owned'))
|
|
260
|
+
return [];
|
|
261
|
+
return [
|
|
262
|
+
{
|
|
263
|
+
...resolved,
|
|
264
|
+
id: `${primary ? 'whzt_' : 'whz_'}${workHubDestructiveClaimIdentitySuffix(request.stopsDelegationId)}`,
|
|
265
|
+
},
|
|
266
|
+
];
|
|
267
|
+
},
|
|
247
268
|
conflictMessage: 'WorkHub stop already has a different resolution',
|
|
248
269
|
beforeAppend: async () => {
|
|
249
|
-
const durable = await this.#stores.readWorkHubStopRequest(request.stopsDelegationId);
|
|
270
|
+
const durable = await this.#stores.readWorkHubStopRequest(request.stopsDelegationId, request.actionId);
|
|
250
271
|
if (!durable || !isDeepStrictEqual(durable, request)) {
|
|
251
272
|
throw new WorkHubActionGateFailure('action_conflict', 'WorkHub stop request identity changed');
|
|
252
273
|
}
|
|
@@ -296,7 +317,10 @@ export class HostWorkHubCoordinationCoordinator {
|
|
|
296
317
|
}
|
|
297
318
|
await options.beforeAppend(lease);
|
|
298
319
|
try {
|
|
299
|
-
await this.#stores.appendMessages(WORKHUB_COORDINATION_SESSION_ID, [
|
|
320
|
+
await this.#stores.appendMessages(WORKHUB_COORDINATION_SESSION_ID, [
|
|
321
|
+
requested,
|
|
322
|
+
...((await options.additionalMessages?.(requested)) ?? []),
|
|
323
|
+
]);
|
|
300
324
|
await this.#continuity.refreshCanonical(WORKHUB_COORDINATION_SESSION_ID, lease);
|
|
301
325
|
return requested;
|
|
302
326
|
}
|
|
@@ -314,7 +338,7 @@ export class HostWorkHubCoordinationCoordinator {
|
|
|
314
338
|
const result = await this.#actionGate.candidates();
|
|
315
339
|
// One bounded read for the whole page. The candidate set is already
|
|
316
340
|
// capped, and a per-candidate lookup would rescan each target's history.
|
|
317
|
-
const latestByTarget = new Map((await this.#stores.readActiveWorkHubAssignmentsByTarget(result.candidates.map(({ sessionId }) => sessionId), 1)).map((assignment) => [assignment.targetSessionId, assignment.actionId]));
|
|
341
|
+
const latestByTarget = new Map((await this.#stores.readActiveWorkHubAssignmentsByTarget(result.candidates.map(({ sessionId }) => sessionId), 1, true)).map((assignment) => [assignment.targetSessionId, assignment.actionId]));
|
|
318
342
|
return {
|
|
319
343
|
ok: true,
|
|
320
344
|
result: {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
-
import {
|
|
19
|
+
import { providerDefaultsOf } from '@maka/core/provider-registry';
|
|
20
20
|
/**
|
|
21
21
|
* Config import / export — Alma-style selective bundle.
|
|
22
22
|
*
|
|
@@ -113,25 +113,31 @@ export function parseConfigBundle(raw) {
|
|
|
113
113
|
return { ok: true, bundle };
|
|
114
114
|
}
|
|
115
115
|
export function planConnectionMerge(existing, incoming, strategy) {
|
|
116
|
-
const
|
|
116
|
+
const existingBySlug = new Map(existing.map((c) => [c.slug, c]));
|
|
117
117
|
const plan = { create: [], overwrite: [], skipped: [] };
|
|
118
118
|
const seen = new Set();
|
|
119
119
|
for (const conn of incoming) {
|
|
120
120
|
if (seen.has(conn.slug))
|
|
121
121
|
continue; // de-dupe within the imported set
|
|
122
122
|
seen.add(conn.slug);
|
|
123
|
-
// A backup taken before a provider was retired still carries
|
|
124
|
-
// connection, and the catalog refuses to create one — rightly, since
|
|
125
|
-
// could never execute. Planning it as skipped is what keeps that refusal
|
|
123
|
+
// A backup taken before a provider was retired or removed still carries
|
|
124
|
+
// its connection, and the catalog refuses to create one — rightly, since
|
|
125
|
+
// it could never execute. Planning it as skipped is what keeps that refusal
|
|
126
126
|
// from aborting the restore partway and leaving the rest of the bundle
|
|
127
127
|
// (settings, credentials, memory) unapplied. Its credential is skipped
|
|
128
128
|
// with it: only a created or overwritten slug gets its secret written.
|
|
129
|
-
|
|
129
|
+
const provider = providerDefaultsOf(conn.providerType);
|
|
130
|
+
if (!provider || provider.retired === true) {
|
|
130
131
|
plan.skipped.push({ slug: conn.slug, reason: 'provider_retired' });
|
|
131
132
|
continue;
|
|
132
133
|
}
|
|
133
|
-
|
|
134
|
-
|
|
134
|
+
const current = existingBySlug.get(conn.slug);
|
|
135
|
+
if (current) {
|
|
136
|
+
// A custom connection's protocol is fixed at creation, so an overwrite
|
|
137
|
+
// could not apply the snapshot's protocol and would leave a hybrid.
|
|
138
|
+
const protocolFixed = current.providerType === conn.providerType &&
|
|
139
|
+
current.defaultApiProtocol !== conn.defaultApiProtocol;
|
|
140
|
+
if (strategy === 'overwrite' && !protocolFixed)
|
|
135
141
|
plan.overwrite.push(cloneJson(conn));
|
|
136
142
|
else
|
|
137
143
|
plan.skipped.push({ slug: conn.slug, reason: 'exists' });
|
|
@@ -248,12 +248,12 @@ async function createExecutionStoresForWrite(lease, provider) {
|
|
|
248
248
|
createStableSession: (request, initialBoundary) => run(() => sessionStore.createStableSession(request, initialBoundary)),
|
|
249
249
|
assignWorkHubMessage: (request) => run(() => sessionStore.assignWorkHubMessage(request)),
|
|
250
250
|
readWorkHubAssignment: (actionId) => run(() => sessionStore.readWorkHubAssignment(actionId)),
|
|
251
|
-
readActiveWorkHubAssignmentsByTarget: (targetSessionIds, maxAssignmentsPerTarget) => run(() => sessionStore.readActiveWorkHubAssignmentsByTarget(targetSessionIds, maxAssignmentsPerTarget)),
|
|
251
|
+
readActiveWorkHubAssignmentsByTarget: (targetSessionIds, maxAssignmentsPerTarget, includeStopped) => run(() => sessionStore.readActiveWorkHubAssignmentsByTarget(targetSessionIds, maxAssignmentsPerTarget, includeStopped)),
|
|
252
252
|
readWorkHubReplacement: (delegationId) => run(() => sessionStore.readWorkHubReplacement(delegationId)),
|
|
253
253
|
readWorkHubReplacementAbort: (delegationId) => run(() => sessionStore.readWorkHubReplacementAbort(delegationId)),
|
|
254
254
|
readWorkHubSupersession: (delegationId) => run(() => sessionStore.readWorkHubSupersession(delegationId)),
|
|
255
|
-
readWorkHubStopRequest: (delegationId) => run(() => sessionStore.readWorkHubStopRequest(delegationId)),
|
|
256
|
-
readWorkHubStopResolution: (delegationId) => run(() => sessionStore.readWorkHubStopResolution(delegationId)),
|
|
255
|
+
readWorkHubStopRequest: (delegationId, actionId) => run(() => sessionStore.readWorkHubStopRequest(delegationId, actionId)),
|
|
256
|
+
readWorkHubStopResolution: (delegationId, actionId) => run(() => sessionStore.readWorkHubStopResolution(delegationId, actionId)),
|
|
257
257
|
claimWorkHubAction: (claim) => run(() => sessionStore.claimWorkHubAction(claim)),
|
|
258
258
|
readWorkHubActionClaim: (actionId) => run(() => sessionStore.readWorkHubActionClaim(actionId)),
|
|
259
259
|
discardStableConversationCopy: (sessionId, requestFingerprint) => run(() => sessionStore.discardStableConversationCopy(sessionId, requestFingerprint)),
|
|
@@ -403,6 +403,7 @@ async function createExecutionStoresForWrite(lease, provider) {
|
|
|
403
403
|
commitToolPrepared: (input) => run(() => runtimePersistence.runtimeCommitStore.commitToolPrepared(input)),
|
|
404
404
|
commitToolOutcome: (input) => run(() => runtimePersistence.runtimeCommitStore.commitToolOutcome(input)),
|
|
405
405
|
listUnsettledToolOperations: (sessionIds) => run(() => runtimePersistence.runtimeCommitStore.listUnsettledToolOperations(sessionIds)),
|
|
406
|
+
rebuildTerminalToolProjectionsForSessions: (sessionIds) => run(() => runtimePersistence.runtimeCommitStore.rebuildTerminalToolProjectionsForSessions(sessionIds)),
|
|
406
407
|
},
|
|
407
408
|
};
|
|
408
409
|
freezeExecutionStoresFacade(stores);
|
|
@@ -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,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'
|
|
@@ -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,
|
|
@@ -47,6 +47,7 @@ import { CONTEXT_OFFLOAD_DATABASE_NAME, CONTEXT_OFFLOAD_VALUES_DIRECTORY_NAME, }
|
|
|
47
47
|
import { acquireOperationalStateDatabase, inspectOperationalStateSchema, OPERATIONAL_STATE_DATABASE_NAME, OperationalStateMigrationBlockedError, } from './operational-state-store.js';
|
|
48
48
|
import { TERMINAL_RUNTIME_EVENT_SQL } from './runtime-transcript-query.js';
|
|
49
49
|
import { isSafeStorageId } from './storage-id.js';
|
|
50
|
+
import { createSqliteRuntimeStore } from './sqlite-runtime-store.js';
|
|
50
51
|
export const SESSION_BUNDLE_STATE_ENTRIES = [
|
|
51
52
|
'artifacts',
|
|
52
53
|
OPERATIONAL_STATE_DATABASE_NAME,
|
|
@@ -288,6 +289,16 @@ async function backupOperationalState(stateRoot, destinationPath) {
|
|
|
288
289
|
}
|
|
289
290
|
}
|
|
290
291
|
async function filterBackedUpDatabase(destinationPath, sessionIds, options) {
|
|
292
|
+
const runtimeStore = createSqliteRuntimeStore(destinationPath);
|
|
293
|
+
try {
|
|
294
|
+
// Repair only terminal facts for currently unsettled tools. A full
|
|
295
|
+
// projection rebuild decodes every RuntimeEvent in the Session, including
|
|
296
|
+
// legacy payloads that this build must preserve opaquely in the bundle.
|
|
297
|
+
await runtimeStore.rebuildTerminalToolProjectionsForSessions(sessionIds);
|
|
298
|
+
}
|
|
299
|
+
finally {
|
|
300
|
+
runtimeStore.close();
|
|
301
|
+
}
|
|
291
302
|
const database = new DatabaseSync(destinationPath);
|
|
292
303
|
try {
|
|
293
304
|
// Quiescence is asserted here, on the copy, not on the live database.
|