maka-agent 0.2.0-dev.53.20260927 → 0.2.0-dev.62.20260928
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 +6 -5
- package/dist/workspace-root.js +2 -2
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/acp-executor-plugin/dist/index.js +333 -28
- package/node_modules/@maka/acp-executor-plugin/dist/plugin.mjs +283 -27
- package/node_modules/@maka/core/dist/executor-catalog.js +10 -1
- package/node_modules/@maka/core/dist/message-queue-order.js +47 -0
- package/node_modules/@maka/core/dist/model-metadata.js +2 -1
- package/node_modules/@maka/core/dist/redaction.js +42 -3
- package/node_modules/@maka/core/dist/relative-time-policy.js +71 -0
- package/node_modules/@maka/core/dist/relative-time.js +3 -54
- package/node_modules/@maka/core/package.json +1 -0
- package/node_modules/@maka/eval/dist/egress-audit.js +127 -0
- package/node_modules/@maka/eval/dist/harness-executor.js +16 -96
- package/node_modules/@maka/eval/harbor/egress-proxy/entrypoint.sh +4 -4
- package/node_modules/@maka/eval/harbor/egress_filter.py +153 -104
- package/node_modules/@maka/eval/harbor/eval_framework.py +37 -14
- package/node_modules/@maka/eval/harbor/relay_agent.py +4 -6
- package/node_modules/@maka/eval/harbor/run_trial.py +11 -4
- package/node_modules/@maka/runtime/dist/agent-graph-supervisor-wake.js +33 -6
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +1 -1
- package/node_modules/@maka/runtime/dist/plugin-executor-backend.js +26 -5
- package/node_modules/@maka/runtime/dist/plugin-executor-service.js +36 -0
- package/node_modules/@maka/runtime/dist/provider-error-classification.js +8 -73
- package/node_modules/@maka/runtime/dist/provider-error-signals.js +31 -0
- package/node_modules/@maka/runtime/dist/provider-retry-policy.js +79 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +6 -4
- package/node_modules/@maka/runtime/dist/session-projection-helpers.js +2 -0
- package/node_modules/@maka/runtime/dist/shell-run-manager.js +8 -8
- package/node_modules/@maka/runtime/dist/terminal-run-commit.js +7 -1
- package/node_modules/@maka/runtime/dist/tool-runtime.js +5 -4
- package/node_modules/@maka/runtime-host/dist/adapter/provider-retry-projector.js +63 -0
- package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +7 -51
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +9 -3
- package/node_modules/@maka/runtime-host/dist/protocol/message-queue-limits.js +21 -0
- package/node_modules/@maka/runtime-host/dist/protocol/message.js +6 -104
- package/node_modules/@maka/runtime-host/dist/protocol/queue-mutation.js +136 -0
- package/node_modules/@maka/runtime-host/dist/protocol/turn-provider-retry.js +69 -0
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +2 -43
- package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +42 -5
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +105 -233
- package/node_modules/@maka/runtime-host/dist/server/message-queue-state.js +69 -0
- package/node_modules/@maka/runtime-host/dist/server/provider-retry-projection.js +71 -0
- package/node_modules/@maka/runtime-host/dist/server/queued-mutation-executor.js +94 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +9 -58
- package/node_modules/@maka/storage/dist/agent-run-store-contract.js +0 -3
- package/node_modules/@maka/storage/dist/agent-run-store.js +15 -6
- package/node_modules/@maka/storage/dist/execution-persistence-provider.js +1 -0
- package/node_modules/@maka/storage/dist/execution-stores.js +1 -0
- package/node_modules/@maka/storage/dist/project-catalog.js +41 -42
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +102 -31
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-schema.js +52 -1
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +34 -2
- package/package.json +1 -1
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
import { invalidProtocolFrame } from './errors.js';
|
|
20
|
-
import { assertExactKeys, requireCount, requireEntityId, requireExactRecord, requireId, requireRecord, requireShapedRecord,
|
|
20
|
+
import { assertExactKeys, requireCount, requireEntityId, requireExactRecord, requireId, requireRecord, requireShapedRecord, } from './codec.js';
|
|
21
21
|
import { defineOperation } from './operation-spec.js';
|
|
22
|
-
import { decodeMessageAdmissionContent, decodeSkillIds, decodeTurnOrchestration, decodeTurnSnapshot,
|
|
22
|
+
import { decodeMessageAdmissionContent, decodeSkillIds, decodeTurnOrchestration, decodeTurnSnapshot, } from './turn.js';
|
|
23
23
|
import { decodeSkillInvocationResult } from '@maka/core/skill-invocation';
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export
|
|
24
|
+
import { MESSAGE_OPERATION_RESULT_MAX_BYTES, MESSAGE_QUEUE_MAX_ENTRIES, MESSAGE_QUEUE_PROJECTION_MAX_BYTES, } from './message-queue-limits.js';
|
|
25
|
+
import { QUEUE_MUTATION_OPERATION_SPECS } from './queue-mutation.js';
|
|
26
|
+
export { MESSAGE_OPERATION_RESULT_MAX_BYTES, MESSAGE_QUEUE_MAX_ENTRIES, MESSAGE_QUEUE_PROJECTION_MAX_BYTES, } from './message-queue-limits.js';
|
|
27
27
|
const MESSAGE_OPERATION_ERRORS = [
|
|
28
28
|
'host_not_ready',
|
|
29
29
|
'host_draining',
|
|
@@ -64,34 +64,7 @@ export const MESSAGE_OPERATION_SPECS = {
|
|
|
64
64
|
decodeInput: decodeQueueRetractInput,
|
|
65
65
|
decodeOutput: decodeQueueRetractResult,
|
|
66
66
|
}),
|
|
67
|
-
|
|
68
|
-
mode: 'command',
|
|
69
|
-
availability: 'ready',
|
|
70
|
-
errors: MESSAGE_OPERATION_ERRORS,
|
|
71
|
-
decodeInput: decodeQueueEntryRetractInput,
|
|
72
|
-
decodeOutput: decodeQueueMutationResult,
|
|
73
|
-
}),
|
|
74
|
-
'queue.entry.promote': defineOperation({
|
|
75
|
-
mode: 'command',
|
|
76
|
-
availability: 'ready',
|
|
77
|
-
errors: MESSAGE_OPERATION_ERRORS,
|
|
78
|
-
decodeInput: decodeQueueEntryPromoteInput,
|
|
79
|
-
decodeOutput: decodeQueueMutationResult,
|
|
80
|
-
}),
|
|
81
|
-
'queue.entry.update': defineOperation({
|
|
82
|
-
mode: 'command',
|
|
83
|
-
availability: 'ready',
|
|
84
|
-
errors: MESSAGE_OPERATION_ERRORS,
|
|
85
|
-
decodeInput: decodeQueueEntryUpdateInput,
|
|
86
|
-
decodeOutput: decodeQueueMutationResult,
|
|
87
|
-
}),
|
|
88
|
-
'queue.entries.reorder': defineOperation({
|
|
89
|
-
mode: 'command',
|
|
90
|
-
availability: 'ready',
|
|
91
|
-
errors: MESSAGE_OPERATION_ERRORS,
|
|
92
|
-
decodeInput: decodeQueueEntriesReorderInput,
|
|
93
|
-
decodeOutput: decodeQueueMutationResult,
|
|
94
|
-
}),
|
|
67
|
+
...QUEUE_MUTATION_OPERATION_SPECS,
|
|
95
68
|
'turn.interrupt': defineOperation({
|
|
96
69
|
mode: 'control',
|
|
97
70
|
availability: 'ready',
|
|
@@ -297,77 +270,6 @@ function decodeQueueRetractResult(value) {
|
|
|
297
270
|
requireEncodedByteLimit(result, 'queue.retract result', MESSAGE_OPERATION_RESULT_MAX_BYTES);
|
|
298
271
|
return result;
|
|
299
272
|
}
|
|
300
|
-
function decodeQueueEntryRetractInput(value) {
|
|
301
|
-
const record = requireExactRecord(value, 'queue.entry.retract input', [
|
|
302
|
-
'originHostEpoch',
|
|
303
|
-
'sessionId',
|
|
304
|
-
'entryId',
|
|
305
|
-
'retractId',
|
|
306
|
-
]);
|
|
307
|
-
return {
|
|
308
|
-
originHostEpoch: requireId(record.originHostEpoch, 'originHostEpoch'),
|
|
309
|
-
sessionId: requireEntityId(record.sessionId, 'sessionId'),
|
|
310
|
-
entryId: requireEntityId(record.entryId, 'entryId'),
|
|
311
|
-
retractId: requireEntityId(record.retractId, 'retractId'),
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
function decodeQueueMutationResult(value) {
|
|
315
|
-
const record = requireExactRecord(value, 'queue mutation result', ['queueRevision']);
|
|
316
|
-
return { queueRevision: requireCount(record.queueRevision, 'queueRevision') };
|
|
317
|
-
}
|
|
318
|
-
function decodeQueueEntryPromoteInput(value) {
|
|
319
|
-
const record = requireExactRecord(value, 'queue.entry.promote input', [
|
|
320
|
-
'originHostEpoch',
|
|
321
|
-
'sessionId',
|
|
322
|
-
'entryId',
|
|
323
|
-
'promoteId',
|
|
324
|
-
]);
|
|
325
|
-
return {
|
|
326
|
-
originHostEpoch: requireId(record.originHostEpoch, 'originHostEpoch'),
|
|
327
|
-
sessionId: requireEntityId(record.sessionId, 'sessionId'),
|
|
328
|
-
entryId: requireEntityId(record.entryId, 'entryId'),
|
|
329
|
-
promoteId: requireEntityId(record.promoteId, 'promoteId'),
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
function decodeQueueEntryUpdateInput(value) {
|
|
333
|
-
const record = requireExactRecord(value, 'queue.entry.update input', [
|
|
334
|
-
'originHostEpoch',
|
|
335
|
-
'sessionId',
|
|
336
|
-
'entryId',
|
|
337
|
-
'updateId',
|
|
338
|
-
'expectedQueueRevision',
|
|
339
|
-
'text',
|
|
340
|
-
]);
|
|
341
|
-
const text = requireUtf8String(record.text, 'Message text', TURN_MESSAGE_TEXT_MAX_BYTES);
|
|
342
|
-
if (text.trim().length === 0)
|
|
343
|
-
throw invalidProtocolFrame('Invalid Message text');
|
|
344
|
-
return {
|
|
345
|
-
originHostEpoch: requireId(record.originHostEpoch, 'originHostEpoch'),
|
|
346
|
-
sessionId: requireEntityId(record.sessionId, 'sessionId'),
|
|
347
|
-
entryId: requireEntityId(record.entryId, 'entryId'),
|
|
348
|
-
updateId: requireEntityId(record.updateId, 'updateId'),
|
|
349
|
-
expectedQueueRevision: requireCount(record.expectedQueueRevision, 'expectedQueueRevision'),
|
|
350
|
-
text,
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
function decodeQueueEntriesReorderInput(value) {
|
|
354
|
-
const record = requireExactRecord(value, 'queue.entries.reorder input', [
|
|
355
|
-
'originHostEpoch',
|
|
356
|
-
'sessionId',
|
|
357
|
-
'reorderId',
|
|
358
|
-
'entryIds',
|
|
359
|
-
]);
|
|
360
|
-
const entryIds = requireBoundedArray(record.entryIds, 'reorder entry identities').map((entryId) => requireEntityId(entryId, 'entryId'));
|
|
361
|
-
if (new Set(entryIds).size !== entryIds.length) {
|
|
362
|
-
throw invalidProtocolFrame('Invalid reorder entry identities');
|
|
363
|
-
}
|
|
364
|
-
return {
|
|
365
|
-
originHostEpoch: requireId(record.originHostEpoch, 'originHostEpoch'),
|
|
366
|
-
sessionId: requireEntityId(record.sessionId, 'sessionId'),
|
|
367
|
-
reorderId: requireEntityId(record.reorderId, 'reorderId'),
|
|
368
|
-
entryIds,
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
273
|
function decodeTurnInterruptInput(value) {
|
|
372
274
|
const record = requireExactRecord(value, 'turn.interrupt input', [
|
|
373
275
|
'originHostEpoch',
|
|
@@ -0,0 +1,136 @@
|
|
|
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 { requireCount, requireEntityId, requireExactRecord, requireId, requireUtf8String, } from './codec.js';
|
|
20
|
+
import { invalidProtocolFrame } from './errors.js';
|
|
21
|
+
import { MESSAGE_QUEUE_MAX_ENTRIES } from './message-queue-limits.js';
|
|
22
|
+
import { defineOperation } from './operation-spec.js';
|
|
23
|
+
import { TURN_MESSAGE_TEXT_MAX_BYTES } from './turn.js';
|
|
24
|
+
const QUEUE_MUTATION_ERRORS = [
|
|
25
|
+
'host_not_ready',
|
|
26
|
+
'host_draining',
|
|
27
|
+
'operation_unavailable',
|
|
28
|
+
'not_found',
|
|
29
|
+
'session_archived',
|
|
30
|
+
'session_busy',
|
|
31
|
+
'operation_conflict',
|
|
32
|
+
'outcome_unknown',
|
|
33
|
+
'internal_failure',
|
|
34
|
+
];
|
|
35
|
+
export const QUEUE_MUTATION_OPERATION_SPECS = {
|
|
36
|
+
'queue.entry.retract': defineOperation({
|
|
37
|
+
mode: 'command',
|
|
38
|
+
availability: 'ready',
|
|
39
|
+
errors: QUEUE_MUTATION_ERRORS,
|
|
40
|
+
decodeInput: decodeQueueEntryRetractInput,
|
|
41
|
+
decodeOutput: decodeQueueMutationResult,
|
|
42
|
+
}),
|
|
43
|
+
'queue.entry.promote': defineOperation({
|
|
44
|
+
mode: 'command',
|
|
45
|
+
availability: 'ready',
|
|
46
|
+
errors: QUEUE_MUTATION_ERRORS,
|
|
47
|
+
decodeInput: decodeQueueEntryPromoteInput,
|
|
48
|
+
decodeOutput: decodeQueueMutationResult,
|
|
49
|
+
}),
|
|
50
|
+
'queue.entry.update': defineOperation({
|
|
51
|
+
mode: 'command',
|
|
52
|
+
availability: 'ready',
|
|
53
|
+
errors: QUEUE_MUTATION_ERRORS,
|
|
54
|
+
decodeInput: decodeQueueEntryUpdateInput,
|
|
55
|
+
decodeOutput: decodeQueueMutationResult,
|
|
56
|
+
}),
|
|
57
|
+
'queue.entries.reorder': defineOperation({
|
|
58
|
+
mode: 'command',
|
|
59
|
+
availability: 'ready',
|
|
60
|
+
errors: QUEUE_MUTATION_ERRORS,
|
|
61
|
+
decodeInput: decodeQueueEntriesReorderInput,
|
|
62
|
+
decodeOutput: decodeQueueMutationResult,
|
|
63
|
+
}),
|
|
64
|
+
};
|
|
65
|
+
export function decodeQueueEntryRetractInput(value) {
|
|
66
|
+
const command = decodeEntryCommand(value, 'queue.entry.retract input', 'retractId');
|
|
67
|
+
const { operationId, ...identity } = command;
|
|
68
|
+
return { ...identity, retractId: requireEntityId(operationId, 'retractId') };
|
|
69
|
+
}
|
|
70
|
+
export function decodeQueueEntryPromoteInput(value) {
|
|
71
|
+
const command = decodeEntryCommand(value, 'queue.entry.promote input', 'promoteId');
|
|
72
|
+
const { operationId, ...identity } = command;
|
|
73
|
+
return { ...identity, promoteId: requireEntityId(operationId, 'promoteId') };
|
|
74
|
+
}
|
|
75
|
+
export function decodeQueueEntryUpdateInput(value) {
|
|
76
|
+
const record = requireExactRecord(value, 'queue.entry.update input', [
|
|
77
|
+
'originHostEpoch',
|
|
78
|
+
'sessionId',
|
|
79
|
+
'entryId',
|
|
80
|
+
'updateId',
|
|
81
|
+
'expectedQueueRevision',
|
|
82
|
+
'text',
|
|
83
|
+
]);
|
|
84
|
+
const text = requireUtf8String(record.text, 'Message text', TURN_MESSAGE_TEXT_MAX_BYTES);
|
|
85
|
+
if (text.trim().length === 0)
|
|
86
|
+
throw invalidProtocolFrame('Invalid Message text');
|
|
87
|
+
return {
|
|
88
|
+
...decodeEntryIdentity(record),
|
|
89
|
+
updateId: requireEntityId(record.updateId, 'updateId'),
|
|
90
|
+
expectedQueueRevision: requireCount(record.expectedQueueRevision, 'expectedQueueRevision'),
|
|
91
|
+
text,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export function decodeQueueEntriesReorderInput(value) {
|
|
95
|
+
const record = requireExactRecord(value, 'queue.entries.reorder input', [
|
|
96
|
+
'originHostEpoch',
|
|
97
|
+
'sessionId',
|
|
98
|
+
'reorderId',
|
|
99
|
+
'expectedQueueRevision',
|
|
100
|
+
'entryIds',
|
|
101
|
+
]);
|
|
102
|
+
if (!Array.isArray(record.entryIds) || record.entryIds.length > MESSAGE_QUEUE_MAX_ENTRIES) {
|
|
103
|
+
throw invalidProtocolFrame('Invalid reorder entry identities');
|
|
104
|
+
}
|
|
105
|
+
const entryIds = record.entryIds.map((entryId) => requireEntityId(entryId, 'entryId'));
|
|
106
|
+
if (new Set(entryIds).size !== entryIds.length) {
|
|
107
|
+
throw invalidProtocolFrame('Invalid reorder entry identities');
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
originHostEpoch: requireId(record.originHostEpoch, 'originHostEpoch'),
|
|
111
|
+
sessionId: requireEntityId(record.sessionId, 'sessionId'),
|
|
112
|
+
reorderId: requireEntityId(record.reorderId, 'reorderId'),
|
|
113
|
+
expectedQueueRevision: requireCount(record.expectedQueueRevision, 'expectedQueueRevision'),
|
|
114
|
+
entryIds,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
export function decodeQueueMutationResult(value) {
|
|
118
|
+
const record = requireExactRecord(value, 'queue mutation result', ['queueRevision']);
|
|
119
|
+
return { queueRevision: requireCount(record.queueRevision, 'queueRevision') };
|
|
120
|
+
}
|
|
121
|
+
function decodeEntryCommand(value, label, operationIdKey) {
|
|
122
|
+
const record = requireExactRecord(value, label, [
|
|
123
|
+
'originHostEpoch',
|
|
124
|
+
'sessionId',
|
|
125
|
+
'entryId',
|
|
126
|
+
operationIdKey,
|
|
127
|
+
]);
|
|
128
|
+
return { ...decodeEntryIdentity(record), operationId: record[operationIdKey] };
|
|
129
|
+
}
|
|
130
|
+
function decodeEntryIdentity(record) {
|
|
131
|
+
return {
|
|
132
|
+
originHostEpoch: requireId(record.originHostEpoch, 'originHostEpoch'),
|
|
133
|
+
sessionId: requireEntityId(record.sessionId, 'sessionId'),
|
|
134
|
+
entryId: requireEntityId(record.entryId, 'entryId'),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
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 { assertExactKeys, requireCount, requireRecord } from './codec.js';
|
|
20
|
+
import { invalidProtocolFrame } from './errors.js';
|
|
21
|
+
const RETRY_REASONS = new Set([
|
|
22
|
+
'stream_truncated',
|
|
23
|
+
'network',
|
|
24
|
+
'provider_capacity',
|
|
25
|
+
'provider_unavailable',
|
|
26
|
+
'rate_limit',
|
|
27
|
+
'timeout',
|
|
28
|
+
'unknown',
|
|
29
|
+
]);
|
|
30
|
+
export function decodeTurnProviderRetry(value) {
|
|
31
|
+
const record = requireRecord(value, 'Turn provider retry');
|
|
32
|
+
const common = decodeAttempt(record);
|
|
33
|
+
if (record.phase === 'started') {
|
|
34
|
+
assertExactKeys(record, 'started Turn provider retry', [
|
|
35
|
+
'phase',
|
|
36
|
+
'attempt',
|
|
37
|
+
'maxAttempts',
|
|
38
|
+
'reason',
|
|
39
|
+
]);
|
|
40
|
+
return { phase: 'started', ...common };
|
|
41
|
+
}
|
|
42
|
+
if (record.phase === 'scheduled') {
|
|
43
|
+
const keys = ['phase', 'attempt', 'maxAttempts', 'delayMs', 'reason'];
|
|
44
|
+
assertExactKeys(record, 'scheduled Turn provider retry', record.ts === undefined ? keys : [...keys, 'ts']);
|
|
45
|
+
return {
|
|
46
|
+
phase: 'scheduled',
|
|
47
|
+
...common,
|
|
48
|
+
delayMs: requireCount(record.delayMs, 'delayMs'),
|
|
49
|
+
...(record.ts === undefined ? {} : { ts: requireCount(record.ts, 'ts') }),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
throw invalidProtocolFrame('Invalid Turn provider retry phase');
|
|
53
|
+
}
|
|
54
|
+
function decodeAttempt(record) {
|
|
55
|
+
const attempt = positiveCount(record.attempt, 'attempt');
|
|
56
|
+
const maxAttempts = positiveCount(record.maxAttempts, 'maxAttempts');
|
|
57
|
+
if (attempt > maxAttempts)
|
|
58
|
+
throw invalidProtocolFrame('Invalid Turn provider retry attempt');
|
|
59
|
+
if (!RETRY_REASONS.has(record.reason)) {
|
|
60
|
+
throw invalidProtocolFrame('Invalid Turn provider retry reason');
|
|
61
|
+
}
|
|
62
|
+
return { attempt, maxAttempts, reason: record.reason };
|
|
63
|
+
}
|
|
64
|
+
function positiveCount(value, label) {
|
|
65
|
+
const count = requireCount(value, label);
|
|
66
|
+
if (count === 0)
|
|
67
|
+
throw invalidProtocolFrame(`Invalid ${label}`);
|
|
68
|
+
return count;
|
|
69
|
+
}
|
|
@@ -24,6 +24,8 @@ import { decodeTurnOrigin } from '@maka/core/turn-origin';
|
|
|
24
24
|
import { invalidProtocolFrame } from './errors.js';
|
|
25
25
|
import { assertExactKeys, requireCount, requireEntityId, requireExactRecord, requireShapedRecord, requireId, requireRecord, requireString, } from './codec.js';
|
|
26
26
|
import { defineOperation } from './operation-spec.js';
|
|
27
|
+
import { decodeTurnProviderRetry } from './turn-provider-retry.js';
|
|
28
|
+
export { decodeTurnProviderRetry } from './turn-provider-retry.js';
|
|
27
29
|
export const TURN_FAILURE_MESSAGE_MAX_BYTES = 256;
|
|
28
30
|
export const TURN_MESSAGE_TEXT_MAX_BYTES = 48 * 1024;
|
|
29
31
|
export const TURN_MESSAGE_CONTENT_MAX_BYTES = 52 * 1024;
|
|
@@ -494,49 +496,6 @@ export function decodeContextCompactionOutcome(value) {
|
|
|
494
496
|
}
|
|
495
497
|
throw invalidProtocolFrame('Invalid context compaction outcome kind');
|
|
496
498
|
}
|
|
497
|
-
export function decodeTurnProviderRetry(value) {
|
|
498
|
-
const record = requireRecord(value, 'Turn provider retry');
|
|
499
|
-
const phase = record.phase;
|
|
500
|
-
const attempt = requirePositiveCount(record.attempt, 'attempt');
|
|
501
|
-
const maxAttempts = requirePositiveCount(record.maxAttempts, 'maxAttempts');
|
|
502
|
-
if (attempt > maxAttempts)
|
|
503
|
-
throw invalidProtocolFrame('Invalid Turn provider retry');
|
|
504
|
-
const reason = requireProviderRetryReason(record.reason);
|
|
505
|
-
if (phase === 'scheduled') {
|
|
506
|
-
const requiredKeys = ['phase', 'attempt', 'maxAttempts', 'delayMs', 'reason'];
|
|
507
|
-
assertExactKeys(record, 'scheduled Turn provider retry', record.ts === undefined ? requiredKeys : [...requiredKeys, 'ts']);
|
|
508
|
-
return {
|
|
509
|
-
phase,
|
|
510
|
-
attempt,
|
|
511
|
-
maxAttempts,
|
|
512
|
-
delayMs: requireCount(record.delayMs, 'delayMs'),
|
|
513
|
-
...(record.ts !== undefined ? { ts: requireCount(record.ts, 'ts') } : {}),
|
|
514
|
-
reason,
|
|
515
|
-
};
|
|
516
|
-
}
|
|
517
|
-
if (phase === 'started') {
|
|
518
|
-
assertExactKeys(record, 'started Turn provider retry', [
|
|
519
|
-
'phase',
|
|
520
|
-
'attempt',
|
|
521
|
-
'maxAttempts',
|
|
522
|
-
'reason',
|
|
523
|
-
]);
|
|
524
|
-
return { phase, attempt, maxAttempts, reason };
|
|
525
|
-
}
|
|
526
|
-
throw invalidProtocolFrame('Invalid Turn provider retry');
|
|
527
|
-
}
|
|
528
|
-
function requireProviderRetryReason(value) {
|
|
529
|
-
if (value === 'network' ||
|
|
530
|
-
value === 'provider_capacity' ||
|
|
531
|
-
value === 'provider_unavailable' ||
|
|
532
|
-
value === 'stream_truncated' ||
|
|
533
|
-
value === 'rate_limit' ||
|
|
534
|
-
value === 'timeout' ||
|
|
535
|
-
value === 'unknown') {
|
|
536
|
-
return value;
|
|
537
|
-
}
|
|
538
|
-
throw invalidProtocolFrame('Invalid Turn provider retry reason');
|
|
539
|
-
}
|
|
540
499
|
function requireTurnRunStatus(value) {
|
|
541
500
|
if (value === 'admitted' ||
|
|
542
501
|
value === 'created' ||
|
|
@@ -20,7 +20,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
20
20
|
import { sameGoalControlLease, } from '@maka/core/goal';
|
|
21
21
|
import { userFacingText } from '@maka/core/session';
|
|
22
22
|
import { GoalContinuationCoordinator, } from '@maka/runtime/goal-continuation';
|
|
23
|
-
import { GoalManager, GOAL_REASON_TEXT_LIMIT, TERMINAL_GOAL_STATUSES, truncateGoalText, } from '@maka/runtime/goal-state';
|
|
23
|
+
import { GoalManager, GOAL_REASON_TEXT_LIMIT, TERMINAL_GOAL_STATUSES, isGoalTextWithinLimit, truncateGoalText, } from '@maka/runtime/goal-state';
|
|
24
24
|
import { buildGoalTools } from '@maka/runtime/goal-tools';
|
|
25
25
|
import { isSessionNotFoundError } from '@maka/storage/execution-stores';
|
|
26
26
|
import { authenticateInteractiveGoalAuthorityWriter, } from '@maka/storage/goal-authority';
|
|
@@ -623,14 +623,51 @@ export class HostGoalCoordinator {
|
|
|
623
623
|
}
|
|
624
624
|
function recentContext(messages) {
|
|
625
625
|
return messages
|
|
626
|
-
.
|
|
627
|
-
.
|
|
628
|
-
|
|
626
|
+
.flatMap((message) => {
|
|
627
|
+
if (message.type !== 'user' && message.type !== 'assistant')
|
|
628
|
+
return [];
|
|
629
629
|
const text = message.type === 'user' ? userFacingText(message) : message.text;
|
|
630
|
-
|
|
630
|
+
// A step that only thought or called a tool stores an assistant row with
|
|
631
|
+
// no text: it would take one of the six places and tell the evaluator nothing.
|
|
632
|
+
return /\S/.test(text) ? [{ type: message.type, text }] : [];
|
|
631
633
|
})
|
|
634
|
+
.slice(-6)
|
|
635
|
+
.map(({ type, text }) => `[${type}]: ${evaluatorExcerpt(text)}`)
|
|
632
636
|
.join('\n');
|
|
633
637
|
}
|
|
638
|
+
const EXCERPT_GAP = ' … ';
|
|
639
|
+
const EXCERPT_END_LIMIT = Object.freeze({
|
|
640
|
+
codeUnits: Math.floor((GOAL_REASON_TEXT_LIMIT.codeUnits - EXCERPT_GAP.length) / 2),
|
|
641
|
+
utf8Bytes: Math.floor((GOAL_REASON_TEXT_LIMIT.utf8Bytes - Buffer.byteLength(EXCERPT_GAP, 'utf8')) / 2),
|
|
642
|
+
});
|
|
643
|
+
/**
|
|
644
|
+
* One message within the budget each context row has always had. A longer one
|
|
645
|
+
* keeps its opening and its end, since a report usually closes with what is
|
|
646
|
+
* verified and what remains.
|
|
647
|
+
*/
|
|
648
|
+
function evaluatorExcerpt(text) {
|
|
649
|
+
if (isGoalTextWithinLimit(text, GOAL_REASON_TEXT_LIMIT))
|
|
650
|
+
return text;
|
|
651
|
+
return `${truncateGoalText(text, EXCERPT_END_LIMIT)}${EXCERPT_GAP}${goalTextTail(text, EXCERPT_END_LIMIT)}`;
|
|
652
|
+
}
|
|
653
|
+
/** The longest end of `text` within `limit`, never splitting a surrogate pair. */
|
|
654
|
+
function goalTextTail(text, limit) {
|
|
655
|
+
// One code unit more than can fit: a pair cut by this slice leaves a lone
|
|
656
|
+
// half at the front, which the walk below always stops before.
|
|
657
|
+
const characters = Array.from(text.slice(-(limit.codeUnits + 1)));
|
|
658
|
+
let start = characters.length;
|
|
659
|
+
let codeUnits = 0;
|
|
660
|
+
let utf8Bytes = 0;
|
|
661
|
+
while (start > 0) {
|
|
662
|
+
const character = characters[start - 1];
|
|
663
|
+
codeUnits += character.length;
|
|
664
|
+
utf8Bytes += Buffer.byteLength(character, 'utf8');
|
|
665
|
+
if (codeUnits > limit.codeUnits || utf8Bytes > limit.utf8Bytes)
|
|
666
|
+
break;
|
|
667
|
+
start -= 1;
|
|
668
|
+
}
|
|
669
|
+
return characters.slice(start).join('');
|
|
670
|
+
}
|
|
634
671
|
function tokenCount(messages) {
|
|
635
672
|
return messages.reduce((total, message) => {
|
|
636
673
|
if (message.type !== 'token_usage')
|