maka-agent 0.2.0-dev.32.20260914 → 0.2.0-dev.35.20260915

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.
Files changed (33) hide show
  1. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  2. package/node_modules/@maka/eval/dist/metering-checkpoint.js +4 -4
  3. package/node_modules/@maka/eval/harbor/relay_agent.py +1 -2
  4. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +2 -18
  5. package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +1 -2
  6. package/node_modules/@maka/runtime/dist/provider-error-classification.js +29 -38
  7. package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +4 -1
  8. package/node_modules/@maka/runtime-host/dist/client/wait-for-ready.js +1 -1
  9. package/node_modules/@maka/runtime-host/dist/control/endpoint.js +7 -6
  10. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +2 -2
  11. package/node_modules/@maka/runtime-host/dist/server/workhub-message-attachments.js +1 -0
  12. package/node_modules/@maka/storage/dist/agent-run-store-contract.js +942 -0
  13. package/node_modules/@maka/storage/dist/agent-run-store.js +3 -923
  14. package/node_modules/@maka/storage/dist/artifact-store.js +63 -7
  15. package/node_modules/@maka/storage/dist/execution-persistence-provider.js +54 -0
  16. package/node_modules/@maka/storage/dist/execution-stores.js +181 -58
  17. package/node_modules/@maka/storage/dist/goal-authority.js +39 -8
  18. package/node_modules/@maka/storage/dist/graph-control-values.js +126 -0
  19. package/node_modules/@maka/storage/dist/interaction-store-contract.js +231 -0
  20. package/node_modules/@maka/storage/dist/interaction-store.js +62 -217
  21. package/node_modules/@maka/storage/dist/local-execution-persistence.js +80 -0
  22. package/node_modules/@maka/storage/dist/root-authority.js +4 -0
  23. package/node_modules/@maka/storage/dist/runtime-event-store-contract.js +19 -0
  24. package/node_modules/@maka/storage/dist/runtime-partial-values.js +114 -0
  25. package/node_modules/@maka/storage/dist/session-store-contract.js +61 -0
  26. package/node_modules/@maka/storage/dist/session-store-values.js +342 -0
  27. package/node_modules/@maka/storage/dist/session-store.js +7 -351
  28. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +4 -185
  29. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +9 -129
  30. package/node_modules/@maka/storage/dist/storage-writer-composition.js +2 -3
  31. package/node_modules/@maka/storage/dist/tool-commit-validation.js +111 -0
  32. package/node_modules/@maka/storage/package.json +1 -0
  33. package/package.json +1 -1
@@ -0,0 +1,126 @@
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
+ import { assertSafeSessionId } from './session-store-contract.js';
20
+ import { AGENT_GRAPH_SUPERVISOR_WAKE_SCHEMA_VERSION, } from '@maka/core/agent-graph-supervisor-wake';
21
+ import { AGENT_GRAPH_CLIENT_PROJECTION_SCHEMA_VERSION, } from '@maka/core/agent-graph-client-projection';
22
+ export function assertGraphLookupIdentity(value, name) {
23
+ if (typeof value !== 'string' ||
24
+ value.length === 0 ||
25
+ value.length > 256 ||
26
+ value.trim() !== value ||
27
+ /[\u0000-\u001f\u007f]/.test(value)) {
28
+ throw new Error(`Invalid agent graph ${name}`);
29
+ }
30
+ }
31
+ export function assertAgentGraphSupervisorWakeClaim(request) {
32
+ if (request.schemaVersion !== AGENT_GRAPH_SUPERVISOR_WAKE_SCHEMA_VERSION) {
33
+ throw new Error('Invalid agent graph supervisor wake schema');
34
+ }
35
+ assertGraphLookupIdentity(request.graphId, 'graph id');
36
+ assertGraphLookupIdentity(request.wakeId, 'supervisor wake id');
37
+ assertGraphLookupIdentity(request.snapshotVersion, 'snapshot version');
38
+ assertSafeSessionId(request.rootSessionId);
39
+ }
40
+ export function assertAgentGraphSupervisorWakeAttempt(request) {
41
+ assertGraphLookupIdentity(request.graphId, 'graph id');
42
+ assertGraphLookupIdentity(request.wakeId, 'supervisor wake id');
43
+ assertGraphLookupIdentity(request.attemptId, 'supervisor wake attempt id');
44
+ assertGraphLookupIdentity(request.turnId, 'supervisor wake turn id');
45
+ }
46
+ export function assertAgentGraphSupervisorWakeCompletion(request) {
47
+ assertGraphLookupIdentity(request.graphId, 'graph id');
48
+ assertGraphLookupIdentity(request.wakeId, 'supervisor wake id');
49
+ assertGraphLookupIdentity(request.attemptId, 'supervisor wake attempt id');
50
+ if (request.status !== 'waiting_permission' &&
51
+ request.status !== 'delivered' &&
52
+ request.status !== 'superseded' &&
53
+ request.status !== 'retryable_failed') {
54
+ throw new Error('Invalid agent graph supervisor wake completion status');
55
+ }
56
+ if ((request.status === 'retryable_failed' || request.status === 'superseded') &&
57
+ (!request.failureReason?.trim() || request.failureReason.length > 4_000)) {
58
+ throw new Error('Agent graph supervisor wake failure reason must be non-empty and bounded');
59
+ }
60
+ }
61
+ export function assertAgentGraphClientProjectionRequest(request) {
62
+ if (request.schemaVersion !== AGENT_GRAPH_CLIENT_PROJECTION_SCHEMA_VERSION ||
63
+ (request.expectedSnapshotVersion !== null &&
64
+ typeof request.expectedSnapshotVersion !== 'string') ||
65
+ typeof request.replaceOperators !== 'boolean' ||
66
+ !Array.isArray(request.operators) ||
67
+ !Array.isArray(request.terminalActivities) ||
68
+ !Array.isArray(request.activityRecords)) {
69
+ throw new Error('Invalid agent graph client projection request');
70
+ }
71
+ assertGraphLookupIdentity(request.graphId, 'graph id');
72
+ assertSafeSessionId(request.rootSessionId);
73
+ if (request.expectedSnapshotVersion !== null) {
74
+ assertGraphLookupIdentity(request.expectedSnapshotVersion, 'expected snapshot version');
75
+ }
76
+ assertGraphLookupIdentity(request.snapshotVersion, 'snapshot version');
77
+ const operatorIds = new Set();
78
+ for (const operator of request.operators) {
79
+ assertGraphLookupIdentity(operator.operatorId, 'operator id');
80
+ if (operatorIds.has(operator.operatorId)) {
81
+ throw new Error(`Duplicate agent graph client operator ${operator.operatorId}`);
82
+ }
83
+ operatorIds.add(operator.operatorId);
84
+ }
85
+ const terminalIds = new Set();
86
+ for (const terminal of request.terminalActivities) {
87
+ assertGraphLookupIdentity(terminal.recordId, 'terminal record id');
88
+ assertGraphEventTime(terminal.eventTime);
89
+ if (terminalIds.has(terminal.recordId)) {
90
+ throw new Error(`Duplicate agent graph terminal activity ${terminal.recordId}`);
91
+ }
92
+ terminalIds.add(terminal.recordId);
93
+ }
94
+ const activityIds = new Set();
95
+ for (const record of request.activityRecords) {
96
+ assertGraphLookupIdentity(record.recordId, 'activity record id');
97
+ assertGraphEventTime(record.eventTime);
98
+ if (activityIds.has(record.recordId)) {
99
+ throw new Error(`Duplicate agent graph activity ${record.recordId}`);
100
+ }
101
+ activityIds.add(record.recordId);
102
+ }
103
+ if (request.incrementalRecordId !== undefined) {
104
+ assertGraphLookupIdentity(request.incrementalRecordId, 'incremental record id');
105
+ if (request.expectedSnapshotVersion === null || !activityIds.has(request.incrementalRecordId)) {
106
+ throw new Error('Invalid incremental agent graph projection record');
107
+ }
108
+ }
109
+ }
110
+ export function encodeProjectionPayload(payload, name) {
111
+ const encoded = JSON.stringify(payload);
112
+ if (encoded === undefined) {
113
+ throw new Error(`Invalid agent graph ${name} payload`);
114
+ }
115
+ return encoded;
116
+ }
117
+ export function assertGraphEventTime(value) {
118
+ if (!Number.isSafeInteger(value) || value < 0) {
119
+ throw new Error('Invalid agent graph terminal activity event time');
120
+ }
121
+ }
122
+ export function assertGraphIntentId(value) {
123
+ if (!/^graph_intent_[a-f0-9]{32}$/.test(value)) {
124
+ throw new Error('Invalid agent graph intent id');
125
+ }
126
+ }
@@ -0,0 +1,231 @@
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
+ import { isDeepStrictEqual } from 'node:util';
20
+ import { clientCapabilityScopeIdentity, decodeClientCapabilitySessionGrant, decodeClientCapabilitySessionGrantKey, } from '@maka/core/client-capability-grant';
21
+ import { decodeInteractionCanonicalOutcome, decodeInteractionRequest, isInteractionCanonicalOutcomeValidForRequest, projectInteractionFormRequest, projectInteractionQuestionRequest, } from '@maka/core/interaction';
22
+ import { isSafeStorageId } from './storage-id.js';
23
+ export const REMEMBER_SCOPE_ID = /^[0-9a-f]{64}$/;
24
+ export const STORED_INTERACTION_REQUEST_MAX_BYTES = 20 * 1024;
25
+ export const STORED_INTERACTION_OUTCOME_MAX_BYTES = 12 * 1024;
26
+ export const STORED_CLIENT_CAPABILITY_SESSION_GRANT_MAX_BYTES = 12 * 1024;
27
+ export class InteractionStoreError extends Error {
28
+ code;
29
+ constructor(code, message, options) {
30
+ super(message, options);
31
+ this.code = code;
32
+ this.name = 'InteractionStoreError';
33
+ }
34
+ }
35
+ export function sameGrantAuthority(left, right) {
36
+ return (left.sessionId === right.sessionId &&
37
+ left.providerId === right.providerId &&
38
+ left.contractId === right.contractId &&
39
+ left.capability === right.capability &&
40
+ left.scope.kind === right.scope.kind &&
41
+ clientCapabilityScopeIdentity(left.scope) === clientCapabilityScopeIdentity(right.scope));
42
+ }
43
+ export function sortPending(requests) {
44
+ return requests.sort((a, b) => a.createdAt - b.createdAt || a.requestId.localeCompare(b.requestId));
45
+ }
46
+ export function normalizeRequest(value, source) {
47
+ const record = closedRecord(value, ['sessionId', 'turnId', 'runId', 'requestId', 'createdAt', 'request'], ['rememberScopeId'], source);
48
+ const createdAt = record.createdAt;
49
+ if (!Number.isSafeInteger(createdAt) || createdAt < 0)
50
+ decodeFailure(source, 'createdAt must be a non-negative safe integer');
51
+ let request;
52
+ try {
53
+ request = decodeInteractionRequest(record.request);
54
+ if (request.kind === 'question') {
55
+ const canonical = projectInteractionQuestionRequest({
56
+ toolUseId: request.toolUseId,
57
+ questions: request.questions,
58
+ });
59
+ if (!isDeepStrictEqual(request, canonical))
60
+ decodeFailure(source, 'Interaction question request is not canonical safe text');
61
+ request = canonical;
62
+ }
63
+ else if (request.kind === 'form') {
64
+ const canonical = projectInteractionFormRequest({
65
+ toolUseId: request.toolUseId,
66
+ message: request.message,
67
+ requester: request.requester,
68
+ fields: request.fields,
69
+ });
70
+ if (!isDeepStrictEqual(request, canonical)) {
71
+ decodeFailure(source, 'Interaction form request is not canonical');
72
+ }
73
+ request = canonical;
74
+ }
75
+ }
76
+ catch (error) {
77
+ if (error instanceof InteractionStoreError)
78
+ throw error;
79
+ decodeFailure(source, 'Invalid Interaction request', error);
80
+ }
81
+ const rememberScopeId = record.rememberScopeId === undefined
82
+ ? undefined
83
+ : assertRememberScopeId(record.rememberScopeId, source);
84
+ if (rememberScopeId !== undefined && !isRememberScopeEligible(request))
85
+ decodeFailure(source, 'rememberScopeId requires a rememberable tool permission request');
86
+ return {
87
+ sessionId: assertId(record.sessionId, source),
88
+ turnId: assertId(record.turnId, source),
89
+ runId: assertId(record.runId, source),
90
+ requestId: assertId(record.requestId, source),
91
+ createdAt: createdAt,
92
+ request,
93
+ ...(rememberScopeId === undefined ? {} : { rememberScopeId }),
94
+ };
95
+ }
96
+ export function normalizeOutcome(value, request) {
97
+ const record = closedRecord(value, ['sessionId', 'turnId', 'runId', 'requestId', 'outcome'], [], 'record');
98
+ const storedIdentity = {
99
+ sessionId: assertId(record.sessionId, 'record'),
100
+ turnId: assertId(record.turnId, 'record'),
101
+ runId: assertId(record.runId, 'record'),
102
+ requestId: assertId(record.requestId, 'record'),
103
+ };
104
+ if (!isDeepStrictEqual(storedIdentity, identity(request)))
105
+ throw new InteractionStoreError('invalid_record', 'Outcome identity does not match request');
106
+ let outcome;
107
+ try {
108
+ outcome = decodeInteractionCanonicalOutcome(record.outcome);
109
+ }
110
+ catch (error) {
111
+ decodeFailure('record', 'Invalid stored Interaction outcome', error);
112
+ }
113
+ if (!isInteractionCanonicalOutcomeValidForRequest(request.request, outcome))
114
+ throw new InteractionStoreError('invalid_record', 'Stored outcome is invalid for request');
115
+ return { ...identity(request), outcome };
116
+ }
117
+ export function decodeGrant(value, source) {
118
+ try {
119
+ return decodeClientCapabilitySessionGrant(value);
120
+ }
121
+ catch (error) {
122
+ decodeFailure(source, 'Invalid Client Capability Session Grant', error);
123
+ }
124
+ }
125
+ export function decodeGrantKey(value, source) {
126
+ try {
127
+ return decodeClientCapabilitySessionGrantKey(value);
128
+ }
129
+ catch (error) {
130
+ decodeFailure(source, 'Invalid Client Capability Session Grant key', error);
131
+ }
132
+ }
133
+ export function decodeClientCapabilityOutcome(value) {
134
+ let outcome;
135
+ try {
136
+ outcome = decodeInteractionCanonicalOutcome(value);
137
+ }
138
+ catch (error) {
139
+ decodeFailure('input', 'Invalid Client Capability Interaction outcome', error);
140
+ }
141
+ if (outcome.kind !== 'client_capability_decision' && outcome.kind !== 'closure') {
142
+ decodeFailure('input', 'Invalid Client Capability Interaction outcome kind');
143
+ }
144
+ return outcome;
145
+ }
146
+ export function identity(value) {
147
+ return {
148
+ sessionId: value.sessionId,
149
+ turnId: value.turnId,
150
+ runId: value.runId,
151
+ requestId: value.requestId,
152
+ };
153
+ }
154
+ export function assertId(value, source = 'input', message = 'Invalid Interaction identity') {
155
+ if (!isSafeStorageId(value))
156
+ decodeFailure(source, message);
157
+ return value;
158
+ }
159
+ export function assertRememberScopeId(value, source) {
160
+ if (typeof value !== 'string' || !REMEMBER_SCOPE_ID.test(value))
161
+ decodeFailure(source, 'rememberScopeId must be a lowercase 64-character SHA-256 digest');
162
+ return value;
163
+ }
164
+ export function isRememberScopeEligible(request) {
165
+ return (request.kind === 'permission' &&
166
+ request.prompt.kind === 'tool_permission' &&
167
+ request.prompt.rememberForTurnAllowed);
168
+ }
169
+ export function closedRecord(value, required, optional, source) {
170
+ if (value === null || typeof value !== 'object' || Array.isArray(value))
171
+ decodeFailure(source, 'Stored Interaction request must be a plain object');
172
+ const prototype = Object.getPrototypeOf(value);
173
+ if (prototype !== Object.prototype && prototype !== null)
174
+ decodeFailure(source, 'Stored Interaction request must be a plain object');
175
+ const record = value;
176
+ const allowed = new Set([...required, ...optional]);
177
+ if (Reflect.ownKeys(record).some((key) => {
178
+ if (typeof key !== 'string' || !allowed.has(key))
179
+ return true;
180
+ const descriptor = Object.getOwnPropertyDescriptor(record, key);
181
+ return descriptor === undefined || !('value' in descriptor);
182
+ }) ||
183
+ required.some((key) => !Object.hasOwn(record, key)))
184
+ decodeFailure(source, 'Stored Interaction request has invalid fields');
185
+ return record;
186
+ }
187
+ export function parseJsonRecord(serialized, context) {
188
+ try {
189
+ return JSON.parse(serialized);
190
+ }
191
+ catch (error) {
192
+ throw new InteractionStoreError('invalid_record', `Invalid stored Interaction ${context}`, {
193
+ cause: error,
194
+ });
195
+ }
196
+ }
197
+ export function decodeFailure(source, message, cause) {
198
+ throw new InteractionStoreError(source === 'input' ? 'invalid_input' : 'invalid_record', message, {
199
+ cause,
200
+ });
201
+ }
202
+ export function encode(value, limit) {
203
+ const bytes = Buffer.from(`${JSON.stringify(value)}\n`);
204
+ if (bytes.length > limit)
205
+ throw new InteractionStoreError('invalid_input', 'Interaction document exceeds size limit');
206
+ return bytes;
207
+ }
208
+ export function failure(error, message) {
209
+ return error instanceof InteractionStoreError
210
+ ? error
211
+ : new InteractionStoreError('io_failed', message, { cause: error });
212
+ }
213
+ export function normalizeFilter(filter) {
214
+ for (const value of [filter.sessionId, filter.turnId, filter.runId])
215
+ if (value !== undefined)
216
+ assertId(value);
217
+ }
218
+ export function matches(request, filter) {
219
+ return ((filter.sessionId === undefined || filter.sessionId === request.sessionId) &&
220
+ (filter.turnId === undefined || filter.turnId === request.turnId) &&
221
+ (filter.runId === undefined || filter.runId === request.runId) &&
222
+ (filter.kind === undefined || filter.kind === request.request.kind));
223
+ }
224
+ export function deepFreeze(value) {
225
+ if (!value || typeof value !== 'object' || Object.isFrozen(value))
226
+ return value;
227
+ Object.freeze(value);
228
+ for (const nested of Object.values(value))
229
+ deepFreeze(nested);
230
+ return value;
231
+ }