maka-agent 0.2.0-dev.49.20260924 → 0.2.0-dev.50.20260925
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +35 -0
- package/dist/acp/maka-acp-agent.js +71 -11
- package/dist/acp/session-event-mapper.js +59 -3
- package/dist/acp/session-interactions.js +33 -3
- package/dist/acp/session-mcp.js +160 -11
- package/dist/acp/session-registry.js +1014 -242
- package/dist/acp/turn-observation.js +260 -0
- package/dist/mcp-capability-publication.js +17 -1
- package/dist/pi-transcript-tools.js +8 -3
- package/dist/runtime-host-session-channel.js +71 -47
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/core/dist/relative-time.js +9 -1
- package/node_modules/@maka/core/dist/session.js +0 -15
- package/node_modules/@maka/core/dist/tool-quiet-preview.js +31 -0
- package/node_modules/@maka/core/dist/transcript-search.js +0 -1
- package/node_modules/@maka/runtime/dist/conversation-copy.js +7 -1
- package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +0 -1
- package/node_modules/@maka/runtime-host/dist/client/client-capability-channel.js +3 -1
- package/node_modules/@maka/runtime-host/dist/client/connection.js +2 -2
- package/node_modules/@maka/runtime-host/dist/client/session-subscription.js +0 -3
- package/node_modules/@maka/runtime-host/dist/protocol/client-capability.js +19 -1
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +4 -1
- package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +1 -2
- package/node_modules/@maka/runtime-host/dist/server/client-capability-coordinator.js +122 -9
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +11 -6
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +5 -0
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +0 -16
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +3 -38
- package/node_modules/@maka/runtime-host/dist/server/shared-session-transcript.js +0 -3
- package/node_modules/@maka/storage/dist/interaction-store.js +0 -13
- package/node_modules/@maka/storage/dist/runtime-partial-values.js +5 -1
- package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +1 -3
- package/node_modules/@maka/storage/dist/usage-screen.js +101 -35
- package/package.json +1 -1
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
+
import { isPartialRuntimeEvent, } from '@maka/core/runtime-event';
|
|
19
20
|
import { buildInvocationOpenedEvent, isSessionInlineInvocation, } from '@maka/core/runtime-invocation';
|
|
20
21
|
import { parseAttachmentResourceRef } from '@maka/core/attachments';
|
|
21
22
|
import { markPersisted } from '@maka/core/persisted-value';
|
|
@@ -182,6 +183,8 @@ export async function prepareConversationRuntimeLedgerCopy(input) {
|
|
|
182
183
|
// before the first event of its run in the Session's order.
|
|
183
184
|
const restoredOpenings = new Map(selectedRunEvents.flatMap(({ run, restoredOpening }) => restoredOpening ? [[run.runId, restoredOpening]] : []));
|
|
184
185
|
const inlineRuntimeEvents = input.sourceEvents.flatMap((event) => {
|
|
186
|
+
if (isPartialRuntimeEvent(event))
|
|
187
|
+
return [];
|
|
185
188
|
const opening = restoredOpenings.get(event.runId);
|
|
186
189
|
if (!opening)
|
|
187
190
|
return [event];
|
|
@@ -652,7 +655,10 @@ async function loadConversationCopyRunEvents(sourceRuns, sourceEvents, copyTurnI
|
|
|
652
655
|
return [
|
|
653
656
|
Promise.resolve(projectedEvents.length > 0
|
|
654
657
|
? projectedEvents
|
|
655
|
-
: runtimeEventStore.readRuntimeEvents(run.sessionId, run.runId)).then((
|
|
658
|
+
: runtimeEventStore.readRuntimeEvents(run.sessionId, run.runId)).then((sourceRunEvents) => {
|
|
659
|
+
// Copy settled facts only, including for older ledgers that persisted
|
|
660
|
+
// nested Code Mode heartbeats instead of keeping partial snapshots.
|
|
661
|
+
const events = sourceRunEvents.filter((event) => !isPartialRuntimeEvent(event));
|
|
656
662
|
if (events.some((event) => event.content?.kind === 'invocation_opened')) {
|
|
657
663
|
return { run, events };
|
|
658
664
|
}
|
|
@@ -280,7 +280,6 @@ export function backfillRuntimeEventsFromStoredMessages(input) {
|
|
|
280
280
|
// Both are already accounted for elsewhere: the turn's ending becomes the
|
|
281
281
|
// terminal RuntimeEvent below, and a coordination record is the WorkHub's
|
|
282
282
|
// own durable proof, which no run ledger owns a copy of.
|
|
283
|
-
case 'form_interaction': // InteractionStore owns this read projection.
|
|
284
283
|
case 'turn_state':
|
|
285
284
|
case 'workhub_coordination':
|
|
286
285
|
break;
|
|
@@ -30,7 +30,7 @@ export class ClientCapabilityChannel {
|
|
|
30
30
|
constructor(options) {
|
|
31
31
|
this.#options = options;
|
|
32
32
|
}
|
|
33
|
-
async replace(provider, timeoutMs, sessionId) {
|
|
33
|
+
async replace(provider, timeoutMs, sessionId, requireIdleSession = false, sessionConfigurationId) {
|
|
34
34
|
this.#assertOpen();
|
|
35
35
|
if (this.#pendingMutations.has(sessionId)) {
|
|
36
36
|
throw new Error('A Client Capability registration mutation is already pending');
|
|
@@ -43,6 +43,8 @@ export class ClientCapabilityChannel {
|
|
|
43
43
|
const canonical = decodeClientCapabilityReplaceInput({
|
|
44
44
|
registrationId,
|
|
45
45
|
...(sessionId === undefined ? {} : { sessionId }),
|
|
46
|
+
...(requireIdleSession ? { requireIdleSession: true } : {}),
|
|
47
|
+
...(sessionConfigurationId === undefined ? {} : { sessionConfigurationId }),
|
|
46
48
|
offers: provider.offers(),
|
|
47
49
|
...(services.length === 0 ? {} : { services }),
|
|
48
50
|
});
|
|
@@ -300,8 +300,8 @@ class RuntimeHostConnectionImpl {
|
|
|
300
300
|
await this.closed;
|
|
301
301
|
}
|
|
302
302
|
async replaceClientCapabilities(provider, options) {
|
|
303
|
-
const { timeoutMs = DEFAULT_HANDSHAKE_TIMEOUT_MS, sessionId } = typeof options === 'number' ? { timeoutMs: options } : (options ?? {});
|
|
304
|
-
return this.#clientCapabilities.replace(provider, timeoutMs, sessionId);
|
|
303
|
+
const { timeoutMs = DEFAULT_HANDSHAKE_TIMEOUT_MS, sessionId, requireIdleSession, sessionConfigurationId, } = typeof options === 'number' ? { timeoutMs: options } : (options ?? {});
|
|
304
|
+
return this.#clientCapabilities.replace(provider, timeoutMs, sessionId, requireIdleSession, sessionConfigurationId);
|
|
305
305
|
}
|
|
306
306
|
async unregisterClientCapabilities(options) {
|
|
307
307
|
const { timeoutMs = DEFAULT_HANDSHAKE_TIMEOUT_MS, sessionId } = typeof options === 'number' ? { timeoutMs: options } : (options ?? {});
|
|
@@ -32,9 +32,6 @@ export class SessionRemovedSubscriptionError extends Error {
|
|
|
32
32
|
name = 'SessionRemovedSubscriptionError';
|
|
33
33
|
}
|
|
34
34
|
export function subscriptionClosedError(reason) {
|
|
35
|
-
if (reason === 'transcript_changed') {
|
|
36
|
-
return new RuntimeHostSubscriptionError('transcript_changed', 'Settled choice history requires a fresh transcript');
|
|
37
|
-
}
|
|
38
35
|
if (reason === 'session_removed') {
|
|
39
36
|
return new SessionRemovedSubscriptionError('Runtime Host Session was removed while it was observed');
|
|
40
37
|
}
|
|
@@ -39,6 +39,8 @@ const CLIENT_CAPABILITY_ERRORS = [
|
|
|
39
39
|
'host_draining',
|
|
40
40
|
'operation_unavailable',
|
|
41
41
|
'invalid_request',
|
|
42
|
+
'session_busy',
|
|
43
|
+
'session_binding_conflict',
|
|
42
44
|
'internal_failure',
|
|
43
45
|
];
|
|
44
46
|
export const CLIENT_CAPABILITY_OPERATION_SPECS = {
|
|
@@ -59,7 +61,7 @@ export const CLIENT_CAPABILITY_OPERATION_SPECS = {
|
|
|
59
61
|
};
|
|
60
62
|
export function decodeClientCapabilityReplaceInput(value) {
|
|
61
63
|
const record = requireRecord(value, 'Client Capability replacement');
|
|
62
|
-
assertOptionalExactKeys(record, 'Client Capability replacement', ['registrationId', 'offers'], ['services', 'sessionId']);
|
|
64
|
+
assertOptionalExactKeys(record, 'Client Capability replacement', ['registrationId', 'offers'], ['services', 'sessionId', 'requireIdleSession', 'sessionConfigurationId']);
|
|
63
65
|
if (!Array.isArray(record.offers) || record.offers.length > CLIENT_CAPABILITY_MAX_OFFERS) {
|
|
64
66
|
throw invalidProtocolFrame('Invalid Client Capability offers');
|
|
65
67
|
}
|
|
@@ -76,6 +78,18 @@ export function decodeClientCapabilityReplaceInput(value) {
|
|
|
76
78
|
const offers = record.offers.map((offer) => decodeClientCapabilityOffer(offer));
|
|
77
79
|
const services = serviceValues.map((service) => decodeClientCapabilityServiceOffer(service));
|
|
78
80
|
const sessionId = record.sessionId === undefined ? undefined : requireEntityId(record.sessionId, 'sessionId');
|
|
81
|
+
if (record.requireIdleSession !== undefined && typeof record.requireIdleSession !== 'boolean') {
|
|
82
|
+
throw invalidProtocolFrame('Invalid Client Capability idle requirement');
|
|
83
|
+
}
|
|
84
|
+
if (record.requireIdleSession === true && sessionId === undefined) {
|
|
85
|
+
throw invalidProtocolFrame('Client Capability idle requirement needs a target Session');
|
|
86
|
+
}
|
|
87
|
+
if (record.sessionConfigurationId !== undefined &&
|
|
88
|
+
(sessionId === undefined ||
|
|
89
|
+
typeof record.sessionConfigurationId !== 'string' ||
|
|
90
|
+
!/^sha256:[a-f0-9]{64}$/.test(record.sessionConfigurationId))) {
|
|
91
|
+
throw invalidProtocolFrame('Invalid Client Capability Session configuration identity');
|
|
92
|
+
}
|
|
79
93
|
if (sessionId !== undefined &&
|
|
80
94
|
(services.length > 0 ||
|
|
81
95
|
offers.some((offer) => offer.affinity !== 'session' || offer.hostPathAccess !== 'none'))) {
|
|
@@ -115,6 +129,10 @@ export function decodeClientCapabilityReplaceInput(value) {
|
|
|
115
129
|
const decoded = {
|
|
116
130
|
registrationId: requireEntityId(record.registrationId, 'registrationId'),
|
|
117
131
|
...(sessionId === undefined ? {} : { sessionId }),
|
|
132
|
+
...(record.requireIdleSession === true ? { requireIdleSession: true } : {}),
|
|
133
|
+
...(record.sessionConfigurationId === undefined
|
|
134
|
+
? {}
|
|
135
|
+
: { sessionConfigurationId: record.sessionConfigurationId }),
|
|
118
136
|
offers,
|
|
119
137
|
...(record.services === undefined ? {} : { services }),
|
|
120
138
|
};
|
|
@@ -64,7 +64,10 @@ export const RUNTIME_HOST_REGISTRATION_SCHEMA_VERSION = 1;
|
|
|
64
64
|
export const RUNTIME_HOST_PROTOCOL_VERSION = 0;
|
|
65
65
|
// Increment when the same protocol version no longer guarantees safe Client-Host
|
|
66
66
|
// interoperability. Mismatches are rejected before domain commands are admitted.
|
|
67
|
-
export const RUNTIME_HOST_COMPATIBILITY_EPOCH =
|
|
67
|
+
export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 189;
|
|
68
|
+
// 189: Remove form_interaction transcript messages and the transcript_changed close reason.
|
|
69
|
+
// 188: Session capability replacement can require an atomic idle root check;
|
|
70
|
+
// complete MCP configuration identities fence conflicting providers across ACP clients.
|
|
68
71
|
// 187: transcript_changed closes a subscription for automatic bounded-tail reseeding.
|
|
69
72
|
// 186: Settled form/question history adds form_interaction transcript messages.
|
|
70
73
|
// 185: Add the bounded next-prompt suggestion operation.
|
|
@@ -268,8 +268,7 @@ export function decodeSubscriptionFrame(value) {
|
|
|
268
268
|
]);
|
|
269
269
|
if (record.reason !== 'slow_consumer' &&
|
|
270
270
|
record.reason !== 'session_removed' &&
|
|
271
|
-
record.reason !== 'access_revoked'
|
|
272
|
-
record.reason !== 'transcript_changed') {
|
|
271
|
+
record.reason !== 'access_revoked') {
|
|
273
272
|
throw invalidProtocolFrame('Invalid subscription close reason');
|
|
274
273
|
}
|
|
275
274
|
frame = { kind: record.kind, ...envelope, reason: record.reason };
|
|
@@ -52,6 +52,7 @@ export class HostClientCapabilityCoordinator {
|
|
|
52
52
|
};
|
|
53
53
|
#activation;
|
|
54
54
|
#isSessionRetired;
|
|
55
|
+
#isSessionTurnBusy;
|
|
55
56
|
#onModelToolsChanged;
|
|
56
57
|
#interactions;
|
|
57
58
|
#grants;
|
|
@@ -67,6 +68,7 @@ export class HostClientCapabilityCoordinator {
|
|
|
67
68
|
constructor(options) {
|
|
68
69
|
this.#activation = options.activation;
|
|
69
70
|
this.#isSessionRetired = options.isSessionRetired;
|
|
71
|
+
this.#isSessionTurnBusy = options.isSessionTurnBusy ?? (() => false);
|
|
70
72
|
this.#onModelToolsChanged = options.onModelToolsChanged;
|
|
71
73
|
this.#interactions = options.interactions;
|
|
72
74
|
this.#grants = options.grants;
|
|
@@ -87,6 +89,7 @@ export class HostClientCapabilityCoordinator {
|
|
|
87
89
|
provider,
|
|
88
90
|
sender,
|
|
89
91
|
superseded: false,
|
|
92
|
+
supersededSessionIds: new Set(),
|
|
90
93
|
});
|
|
91
94
|
let closeTask;
|
|
92
95
|
return {
|
|
@@ -326,7 +329,10 @@ export class HostClientCapabilityCoordinator {
|
|
|
326
329
|
providerId: candidate.registration.providerId,
|
|
327
330
|
...(candidate.registration.sessionId === undefined
|
|
328
331
|
? {}
|
|
329
|
-
: {
|
|
332
|
+
: {
|
|
333
|
+
sessionId: candidate.registration.sessionId,
|
|
334
|
+
sessionConfigurationId: candidate.registration.sessionConfigurationId,
|
|
335
|
+
}),
|
|
330
336
|
});
|
|
331
337
|
selected.push(candidate);
|
|
332
338
|
}
|
|
@@ -340,7 +346,10 @@ export class HostClientCapabilityCoordinator {
|
|
|
340
346
|
providerId: candidate.registration.providerId,
|
|
341
347
|
...(candidate.registration.sessionId === undefined
|
|
342
348
|
? {}
|
|
343
|
-
: {
|
|
349
|
+
: {
|
|
350
|
+
sessionId: candidate.registration.sessionId,
|
|
351
|
+
sessionConfigurationId: candidate.registration.sessionConfigurationId,
|
|
352
|
+
}),
|
|
344
353
|
});
|
|
345
354
|
}
|
|
346
355
|
else {
|
|
@@ -676,6 +685,17 @@ export class HostClientCapabilityCoordinator {
|
|
|
676
685
|
},
|
|
677
686
|
};
|
|
678
687
|
}
|
|
688
|
+
// This check and the registration commit below run in one synchronous
|
|
689
|
+
// activation continuation. A new root reservation cannot interleave them.
|
|
690
|
+
if (input.requireIdleSession && input.sessionId && this.#isSessionTurnBusy(input.sessionId)) {
|
|
691
|
+
return {
|
|
692
|
+
ok: false,
|
|
693
|
+
error: {
|
|
694
|
+
code: 'session_busy',
|
|
695
|
+
message: 'Session has an active or admitting root Turn',
|
|
696
|
+
},
|
|
697
|
+
};
|
|
698
|
+
}
|
|
679
699
|
const connection = this.#connections.get(context.connectionId);
|
|
680
700
|
if (!connection) {
|
|
681
701
|
return {
|
|
@@ -687,23 +707,71 @@ export class HostClientCapabilityCoordinator {
|
|
|
687
707
|
};
|
|
688
708
|
}
|
|
689
709
|
const { provider } = connection;
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
710
|
+
const sessionId = input.sessionId;
|
|
711
|
+
if ((sessionId === undefined && connection.superseded) ||
|
|
712
|
+
(sessionId !== undefined && connection.supersededSessionIds.has(sessionId))) {
|
|
693
713
|
return {
|
|
694
714
|
ok: false,
|
|
695
715
|
error: {
|
|
696
716
|
code: 'invalid_request',
|
|
697
|
-
message: 'Client Capability
|
|
717
|
+
message: 'Client Capability connection has been superseded',
|
|
698
718
|
},
|
|
699
719
|
};
|
|
700
720
|
}
|
|
701
|
-
if (
|
|
721
|
+
if (sessionId !== undefined) {
|
|
722
|
+
const current = provider.sessionRegistrations.get(sessionId);
|
|
723
|
+
// Connections with the same provider identity may overlap during
|
|
724
|
+
// reconnect. Only the owning connection can deliberately reconfigure
|
|
725
|
+
// a Session; another connection must prove the same complete config.
|
|
726
|
+
const crossConnectionConflict = current !== undefined &&
|
|
727
|
+
current.connectionId !== context.connectionId &&
|
|
728
|
+
input.sessionConfigurationId !== current.sessionConfigurationId;
|
|
729
|
+
const conflicts = [...this.#providers.values()].some((other) => {
|
|
730
|
+
if (other.providerId === provider.providerId)
|
|
731
|
+
return false;
|
|
732
|
+
const current = other.sessionRegistrations.get(sessionId);
|
|
733
|
+
return (current &&
|
|
734
|
+
(input.sessionConfigurationId !== undefined ||
|
|
735
|
+
current.sessionConfigurationId !== undefined) &&
|
|
736
|
+
input.sessionConfigurationId !== current.sessionConfigurationId);
|
|
737
|
+
});
|
|
738
|
+
// A disconnected frozen provider cannot silently be replaced either.
|
|
739
|
+
const lostBinding = [...(this.#sessions.get(sessionId)?.sessionBindings ?? [])].some(([contractId, binding]) => {
|
|
740
|
+
if (binding.sessionId !== sessionId)
|
|
741
|
+
return false;
|
|
742
|
+
if (binding.providerId === provider.providerId) {
|
|
743
|
+
// A remote profile retains its provider ID across connections.
|
|
744
|
+
// Keep its frozen configuration fenced after the old channel exits.
|
|
745
|
+
return (binding.kind === 'lost' &&
|
|
746
|
+
input.sessionConfigurationId !== binding.sessionConfigurationId);
|
|
747
|
+
}
|
|
748
|
+
return (!this.#providers.get(binding.providerId)?.sessionRegistrations.has(sessionId) &&
|
|
749
|
+
!(binding.kind === 'lost' &&
|
|
750
|
+
provider.principalKind === 'local_owner' &&
|
|
751
|
+
this.#providers.get(binding.providerId)?.principalId === provider.principalId &&
|
|
752
|
+
this.#providers.get(binding.providerId)?.principalKind === provider.principalKind &&
|
|
753
|
+
input.sessionConfigurationId !== undefined &&
|
|
754
|
+
input.sessionConfigurationId === binding.sessionConfigurationId &&
|
|
755
|
+
input.offers.some((offer) => capabilityGroupId(offer) === contractId)));
|
|
756
|
+
});
|
|
757
|
+
if (crossConnectionConflict || conflicts || lostBinding) {
|
|
758
|
+
return {
|
|
759
|
+
ok: false,
|
|
760
|
+
error: {
|
|
761
|
+
code: 'session_binding_conflict',
|
|
762
|
+
message: 'Session MCP configuration conflicts with an active or frozen provider; restore with the same configuration or close the active attachment',
|
|
763
|
+
},
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
if (input.sessionId !== undefined &&
|
|
768
|
+
!provider.sessionRegistrations.has(input.sessionId) &&
|
|
769
|
+
provider.sessionRegistrations.size >= MAX_SESSION_REGISTRATIONS_PER_PROVIDER) {
|
|
702
770
|
return {
|
|
703
771
|
ok: false,
|
|
704
772
|
error: {
|
|
705
773
|
code: 'invalid_request',
|
|
706
|
-
message: 'Client Capability
|
|
774
|
+
message: 'Client Capability Session registration limit reached',
|
|
707
775
|
},
|
|
708
776
|
};
|
|
709
777
|
}
|
|
@@ -743,7 +811,14 @@ export class HostClientCapabilityCoordinator {
|
|
|
743
811
|
const previous = this.#currentRegistration(provider, registration.sessionId);
|
|
744
812
|
const previousConnectionId = provider.activeConnectionId;
|
|
745
813
|
if (registration.sessionId !== undefined) {
|
|
814
|
+
if (previous && previous.connectionId !== context.connectionId) {
|
|
815
|
+
const previousConnection = this.#connections.get(previous.connectionId);
|
|
816
|
+
previousConnection?.supersededSessionIds.add(registration.sessionId);
|
|
817
|
+
}
|
|
746
818
|
provider.sessionRegistrations.set(registration.sessionId, registration);
|
|
819
|
+
if (registration.sessionConfigurationId !== undefined) {
|
|
820
|
+
this.#reclaimLostBindings(registration);
|
|
821
|
+
}
|
|
747
822
|
}
|
|
748
823
|
else {
|
|
749
824
|
if (previousConnectionId && previousConnectionId !== context.connectionId) {
|
|
@@ -1064,6 +1139,40 @@ export class HostClientCapabilityCoordinator {
|
|
|
1064
1139
|
this.#storeSessionState(sessionId, { ...state, sessionBindings: next });
|
|
1065
1140
|
}
|
|
1066
1141
|
}
|
|
1142
|
+
#reclaimLostBindings(registration) {
|
|
1143
|
+
const sessionId = registration.sessionId;
|
|
1144
|
+
if (sessionId === undefined)
|
|
1145
|
+
return;
|
|
1146
|
+
const state = this.#sessions.get(sessionId);
|
|
1147
|
+
if (!state)
|
|
1148
|
+
return;
|
|
1149
|
+
const next = new Map(state.sessionBindings);
|
|
1150
|
+
const previousProviderIds = new Set();
|
|
1151
|
+
for (const [contractId, binding] of state.sessionBindings) {
|
|
1152
|
+
if (binding.kind !== 'lost' ||
|
|
1153
|
+
binding.sessionId !== sessionId ||
|
|
1154
|
+
binding.providerId === registration.providerId ||
|
|
1155
|
+
this.#providers.get(registration.providerId)?.principalKind !== 'local_owner' ||
|
|
1156
|
+
this.#providers.get(binding.providerId)?.principalId !==
|
|
1157
|
+
this.#providers.get(registration.providerId)?.principalId ||
|
|
1158
|
+
this.#providers.get(binding.providerId)?.principalKind !==
|
|
1159
|
+
this.#providers.get(registration.providerId)?.principalKind ||
|
|
1160
|
+
binding.sessionConfigurationId !== registration.sessionConfigurationId ||
|
|
1161
|
+
!registration.offersByContract.has(contractId) ||
|
|
1162
|
+
this.#providers.get(binding.providerId)?.sessionRegistrations.has(sessionId))
|
|
1163
|
+
continue;
|
|
1164
|
+
previousProviderIds.add(binding.providerId);
|
|
1165
|
+
next.set(contractId, { ...binding, kind: 'bound', providerId: registration.providerId });
|
|
1166
|
+
}
|
|
1167
|
+
if (!bindingMapsEqual(state.sessionBindings, next)) {
|
|
1168
|
+
this.#storeSessionState(sessionId, { ...state, sessionBindings: next });
|
|
1169
|
+
for (const providerId of previousProviderIds) {
|
|
1170
|
+
const previous = this.#providers.get(providerId);
|
|
1171
|
+
if (previous)
|
|
1172
|
+
this.#deleteProviderIfUnused(previous);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1067
1176
|
#retireBindings(providerId, contracts, scopeSessionId) {
|
|
1068
1177
|
for (const [sessionId, state] of this.#sessions) {
|
|
1069
1178
|
const bindings = state.sessionBindings;
|
|
@@ -1251,6 +1360,9 @@ function freezeRegistration(providerId, connectionId, input, trustedProvider) {
|
|
|
1251
1360
|
providerId,
|
|
1252
1361
|
connectionId,
|
|
1253
1362
|
registrationId: input.registrationId,
|
|
1363
|
+
...(input.sessionConfigurationId === undefined
|
|
1364
|
+
? {}
|
|
1365
|
+
: { sessionConfigurationId: input.sessionConfigurationId }),
|
|
1254
1366
|
...(input.sessionId === undefined ? {} : { sessionId: input.sessionId }),
|
|
1255
1367
|
trustedProvider,
|
|
1256
1368
|
offersByContract,
|
|
@@ -1467,7 +1579,8 @@ function bindingMapsEqual(left, right) {
|
|
|
1467
1579
|
if (!candidate ||
|
|
1468
1580
|
candidate.kind !== binding.kind ||
|
|
1469
1581
|
candidate.providerId !== binding.providerId ||
|
|
1470
|
-
candidate.sessionId !== binding.sessionId
|
|
1582
|
+
candidate.sessionId !== binding.sessionId ||
|
|
1583
|
+
candidate.sessionConfigurationId !== binding.sessionConfigurationId) {
|
|
1471
1584
|
return false;
|
|
1472
1585
|
}
|
|
1473
1586
|
}
|
|
@@ -1077,13 +1077,17 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
1077
1077
|
runtimeEventStore: stores.runtimeEventStore,
|
|
1078
1078
|
canonicalPermissionOutcomes,
|
|
1079
1079
|
});
|
|
1080
|
+
const sessionEffectModel = createHostSessionEffectModel({
|
|
1081
|
+
runtimePolicy: runtimePolicyStores,
|
|
1082
|
+
oauthCredentials,
|
|
1083
|
+
usage: openedUsageStores,
|
|
1084
|
+
requestDrain: context.requestDrain,
|
|
1085
|
+
});
|
|
1080
1086
|
const sessionEffectCoordinator = new HostSessionEffectCoordinator({
|
|
1081
|
-
model:
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
requestDrain: context.requestDrain,
|
|
1086
|
-
}),
|
|
1087
|
+
model: {
|
|
1088
|
+
...sessionEffectModel,
|
|
1089
|
+
generateTitle: dependencies.generateSessionTitle ?? sessionEffectModel.generateTitle,
|
|
1090
|
+
},
|
|
1087
1091
|
readModel: {
|
|
1088
1092
|
getSessionView: async (sessionId) => {
|
|
1089
1093
|
// A Session whose transcript predates the ledger projects an empty
|
|
@@ -1278,6 +1282,7 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
1278
1282
|
const state = await stores.sessionStore.probeSessionRemoval(sessionId);
|
|
1279
1283
|
return (state.kind === 'removed' || (state.kind === 'present' && state.record.header.isArchived));
|
|
1280
1284
|
},
|
|
1285
|
+
isSessionTurnBusy: (sessionId) => rootCoordinator?.hasActiveOrPendingTurn(sessionId) ?? false,
|
|
1281
1286
|
onModelToolsChanged: registerBackendInvalidation,
|
|
1282
1287
|
interactions,
|
|
1283
1288
|
grants: stores.interactionStore,
|
|
@@ -307,6 +307,11 @@ export class RootTurnCoordinator {
|
|
|
307
307
|
return undefined;
|
|
308
308
|
return this.#admissions.reserve(sessionId);
|
|
309
309
|
}
|
|
310
|
+
hasActiveOrPendingTurn(sessionId) {
|
|
311
|
+
return (this.#admissions.has(sessionId) ||
|
|
312
|
+
this.#executions.has(sessionId) ||
|
|
313
|
+
this.#recoveryPlansBySession.get(sessionId)?.rootReplayAdmission !== undefined);
|
|
314
|
+
}
|
|
310
315
|
parkContinuationAdmission(admission) {
|
|
311
316
|
this.#admissions.park(admission);
|
|
312
317
|
}
|
|
@@ -434,7 +434,6 @@ export class SessionContinuityCoordinator {
|
|
|
434
434
|
await this.#refreshTranscriptHighWater(sessionId, state);
|
|
435
435
|
const nextRevision = state.revision + 1;
|
|
436
436
|
const snapshot = createSessionContinuitySnapshot(canonical, nextRevision);
|
|
437
|
-
this.#invalidateSettledChoiceTranscript(state, canonical);
|
|
438
437
|
state.canonical = canonical;
|
|
439
438
|
state.revision = nextRevision;
|
|
440
439
|
delete state.terminalPublicationFence;
|
|
@@ -1285,7 +1284,6 @@ export class SessionContinuityCoordinator {
|
|
|
1285
1284
|
}
|
|
1286
1285
|
const nextRevision = state.revision + 1;
|
|
1287
1286
|
const value = createSessionContinuitySnapshot(canonical, nextRevision);
|
|
1288
|
-
this.#invalidateSettledChoiceTranscript(state, canonical);
|
|
1289
1287
|
state.canonical = canonical;
|
|
1290
1288
|
state.revision = nextRevision;
|
|
1291
1289
|
return { changed, state, value };
|
|
@@ -1296,25 +1294,11 @@ export class SessionContinuityCoordinator {
|
|
|
1296
1294
|
value: createSessionContinuitySnapshot(state.canonical, state.revision),
|
|
1297
1295
|
};
|
|
1298
1296
|
}
|
|
1299
|
-
#invalidateSettledChoiceTranscript(state, next) {
|
|
1300
|
-
const pending = new Set(next.interactions.pending.map((item) => item.interactionId));
|
|
1301
|
-
if (!state.canonical.interactions.pending.some((item) => (item.request.kind === 'form' || item.request.kind === 'question') &&
|
|
1302
|
-
!pending.has(item.interactionId)))
|
|
1303
|
-
return;
|
|
1304
|
-
// Outcomes can settle after their owner's last event. Their historical rows
|
|
1305
|
-
// then lie behind an already-consumed cursor: advancing the event high water
|
|
1306
|
-
// cannot deliver them. Close explicitly so observers rebuild their bounded tail.
|
|
1307
|
-
for (const subscriber of state.subscribers.values()) {
|
|
1308
|
-
if (subscriber.transcript)
|
|
1309
|
-
this.#closeSubscriber(subscriber, 'transcript_changed');
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
1297
|
#publishCanonical(state, canonical) {
|
|
1313
1298
|
if (isDeepStrictEqual(state.canonical, canonical))
|
|
1314
1299
|
return;
|
|
1315
1300
|
const nextRevision = state.revision + 1;
|
|
1316
1301
|
const snapshot = createSessionContinuitySnapshot(canonical, nextRevision);
|
|
1317
|
-
this.#invalidateSettledChoiceTranscript(state, canonical);
|
|
1318
1302
|
state.canonical = immutableClone(canonical);
|
|
1319
1303
|
state.revision = nextRevision;
|
|
1320
1304
|
this.#broadcastProjection(state, snapshot);
|
|
@@ -22,8 +22,7 @@ import { createRuntimeEventStoredMessageProjector, projectTranscriptToolResult,
|
|
|
22
22
|
import { foldTurnContribution } from '@maka/storage/session-message-projection';
|
|
23
23
|
const PERMISSION_OUTCOME_READ_CONCURRENCY = 8;
|
|
24
24
|
/** One event can emit content, a permission, usage, and terminal/notice rows. */
|
|
25
|
-
|
|
26
|
-
const EVENT_SEQUENCE_STRIDE = 4_096;
|
|
25
|
+
const EVENT_SEQUENCE_STRIDE = 8;
|
|
27
26
|
const TRANSCRIPT_TURN_MAX_MESSAGES = 4_096;
|
|
28
27
|
export const TRANSCRIPT_TURN_MAX_BYTES = 16 * 1024 * 1024;
|
|
29
28
|
const TRANSCRIPT_SOURCE_MAX_EVENTS = TRANSCRIPT_TURN_MAX_MESSAGES * 2;
|
|
@@ -78,35 +77,6 @@ function createDurableLedgerTranscriptReader(input) {
|
|
|
78
77
|
if (projected.diagnostics.some(isHardRuntimeEventReadModelDiagnostic)) {
|
|
79
78
|
throw new Error('Durable RuntimeEvent transcript projection is incomplete');
|
|
80
79
|
}
|
|
81
|
-
const interactions = await input.stores.interactionStore.listTurnInteractions(turn.invocation.sessionId, turn.invocation.turnId);
|
|
82
|
-
interactions.sort((a, b) => (a.outcome?.outcome.committedAt ?? a.request.createdAt) -
|
|
83
|
-
(b.outcome?.outcome.committedAt ?? b.request.createdAt));
|
|
84
|
-
for (const record of interactions) {
|
|
85
|
-
const { request, outcome } = record;
|
|
86
|
-
if (request.runId !== turn.invocation.runId ||
|
|
87
|
-
(request.request.kind !== 'form' && request.request.kind !== 'question') ||
|
|
88
|
-
!outcome ||
|
|
89
|
-
(outcome.outcome.kind !== 'form_answer' &&
|
|
90
|
-
outcome.outcome.kind !== 'question_answer' &&
|
|
91
|
-
outcome.outcome.kind !== 'closure'))
|
|
92
|
-
continue;
|
|
93
|
-
// Anchor after acceptance, so an incremental reader that already saw the
|
|
94
|
-
// pending request receives the settled history row as well.
|
|
95
|
-
const source = turn.projection.anchors.find((event) => event.ts >= outcome.outcome.committedAt) ??
|
|
96
|
-
turn.projection.anchors.at(-1);
|
|
97
|
-
if (!source)
|
|
98
|
-
continue;
|
|
99
|
-
projected.messages.push({
|
|
100
|
-
type: 'form_interaction',
|
|
101
|
-
id: request.requestId,
|
|
102
|
-
turnId: request.turnId,
|
|
103
|
-
ts: outcome.outcome.committedAt,
|
|
104
|
-
request: request.request,
|
|
105
|
-
outcome: outcome.outcome,
|
|
106
|
-
});
|
|
107
|
-
projected.sourceEventIds.push(source.id);
|
|
108
|
-
}
|
|
109
|
-
assertTurnPresentationBounded(projected.messages);
|
|
110
80
|
const admission = turn.invocation.sessionId === WORKHUB_COORDINATION_SESSION_ID
|
|
111
81
|
? await input.stores.agentRunStore.readRootTurnAdmission(turn.invocation.sessionId, turn.invocation.turnId)
|
|
112
82
|
: undefined;
|
|
@@ -115,8 +85,7 @@ function createDurableLedgerTranscriptReader(input) {
|
|
|
115
85
|
: undefined;
|
|
116
86
|
const ordinals = turn.ordinals;
|
|
117
87
|
const emitted = new Map();
|
|
118
|
-
return projected.messages
|
|
119
|
-
.map((message, index) => {
|
|
88
|
+
return projected.messages.map((message, index) => {
|
|
120
89
|
const ordinal = ordinals.get(projected.sourceEventIds[index]);
|
|
121
90
|
if (ordinal === undefined) {
|
|
122
91
|
throw new Error('Durable transcript message has no source RuntimeEvent');
|
|
@@ -132,8 +101,7 @@ function createDurableLedgerTranscriptReader(input) {
|
|
|
132
101
|
? { ...message, coordinationActionId: actionId }
|
|
133
102
|
: message,
|
|
134
103
|
};
|
|
135
|
-
})
|
|
136
|
-
.sort((a, b) => a.sequence - b.sequence);
|
|
104
|
+
});
|
|
137
105
|
};
|
|
138
106
|
const readRun = async (sessionId, request) => store.readTranscriptRun(sessionId, {
|
|
139
107
|
...request,
|
|
@@ -435,7 +403,6 @@ async function readCanonicalPermissionOutcomes(requestIds, reader) {
|
|
|
435
403
|
/** Keep only presentation state while the storage snapshot visits complete facts. */
|
|
436
404
|
function createTranscriptProjection(invocations) {
|
|
437
405
|
const canonicalPermissionOutcomes = new Map();
|
|
438
|
-
const anchors = [];
|
|
439
406
|
let messageCount = 0;
|
|
440
407
|
let messageBytes = 0;
|
|
441
408
|
let eventCount = 0;
|
|
@@ -452,9 +419,7 @@ function createTranscriptProjection(invocations) {
|
|
|
452
419
|
},
|
|
453
420
|
});
|
|
454
421
|
return {
|
|
455
|
-
anchors,
|
|
456
422
|
push(event) {
|
|
457
|
-
anchors.push({ id: event.id, ts: event.ts });
|
|
458
423
|
eventCount += 1;
|
|
459
424
|
const content = event.content;
|
|
460
425
|
// The durable model projection is never a transcript input. Large Bash
|
|
@@ -49,9 +49,6 @@ export function projectSharedSessionTranscriptMessage(message, sessionId) {
|
|
|
49
49
|
: { coordinationActionId: message.coordinationActionId }),
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
-
case 'form_interaction':
|
|
53
|
-
// Choice requests and answers are private decision evidence.
|
|
54
|
-
return null;
|
|
55
52
|
case 'assistant':
|
|
56
53
|
return {
|
|
57
54
|
type: message.type,
|
|
@@ -52,7 +52,6 @@ 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)),
|
|
56
55
|
listPending: (filter) => run(() => store.listPending(filter)),
|
|
57
56
|
readClientCapabilitySessionGrant: (key) => run(() => store.readClientCapabilitySessionGrant(key)),
|
|
58
57
|
});
|
|
@@ -120,7 +119,6 @@ export async function openSqliteInteractiveInteractionStoreForWrite(lease, store
|
|
|
120
119
|
access: 'write',
|
|
121
120
|
readInteraction: (requestId) => run(() => store.readInteraction(requestId)),
|
|
122
121
|
listSessionPending: (sessionId) => run(() => store.listSessionPending(sessionId)),
|
|
123
|
-
listTurnInteractions: (sessionId, turnId) => run(() => store.listTurnInteractions(sessionId, turnId)),
|
|
124
122
|
listPending: (filter) => run(() => store.listPending(filter)),
|
|
125
123
|
readClientCapabilitySessionGrant: (key) => run(() => store.readClientCapabilitySessionGrant(key)),
|
|
126
124
|
establishRequest: (input) => run(() => store.establishRequest(input)),
|
|
@@ -303,17 +301,6 @@ class SqliteInteractionStore {
|
|
|
303
301
|
assertId(requestId);
|
|
304
302
|
return readSqliteInteraction(this.#lease, requestId);
|
|
305
303
|
}
|
|
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
|
-
}
|
|
317
304
|
async listSessionPending(sessionId) {
|
|
318
305
|
return this.listPending({ sessionId });
|
|
319
306
|
}
|
|
@@ -70,7 +70,11 @@ export function partialRuntimeStream(event) {
|
|
|
70
70
|
identity = `${content.kind}:provider:${event.refs.providerEventId}`;
|
|
71
71
|
text = content.text;
|
|
72
72
|
}
|
|
73
|
-
else if (!content &&
|
|
73
|
+
else if (!content &&
|
|
74
|
+
event.refs?.toolCallId &&
|
|
75
|
+
hasOnlyKeys(event.refs, ['toolCallId', 'parentToolCallId', 'parentOperationId'])) {
|
|
76
|
+
// Code Mode heartbeats retain their enclosing call's identity, but remain
|
|
77
|
+
// presentation state replaced by the nested tool's durable result.
|
|
74
78
|
identity = `tool:call:${event.refs.toolCallId}`;
|
|
75
79
|
}
|
|
76
80
|
if (!identity)
|
|
@@ -105,9 +105,6 @@ export function migrateSqliteCoreExecutionDatabase(db) {
|
|
|
105
105
|
CREATE INDEX IF NOT EXISTS core_interaction_pending
|
|
106
106
|
ON core_interaction_requests(session_id, created_at, request_id);
|
|
107
107
|
|
|
108
|
-
CREATE INDEX IF NOT EXISTS core_interaction_requests_by_turn
|
|
109
|
-
ON core_interaction_requests(session_id, turn_id, created_at, request_id);
|
|
110
|
-
|
|
111
108
|
CREATE TABLE IF NOT EXISTS core_interaction_outcomes (
|
|
112
109
|
request_id TEXT PRIMARY KEY,
|
|
113
110
|
record_json TEXT NOT NULL,
|
|
@@ -183,6 +180,7 @@ export function migrateSqliteCoreExecutionDatabase(db) {
|
|
|
183
180
|
WHERE json_extract(record_json, '$.execution.kind') = 'safe_boundary_continuation';
|
|
184
181
|
|
|
185
182
|
DROP INDEX IF EXISTS core_agent_runs_identity;
|
|
183
|
+
DROP INDEX IF EXISTS core_interaction_requests_by_turn;
|
|
186
184
|
|
|
187
185
|
DROP TABLE IF EXISTS core_message_receipts;
|
|
188
186
|
DROP TABLE IF EXISTS core_message_host_epochs;
|