@myagentroam/agent 0.9.140 → 0.9.142
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/agent-core/host/contracts.d.ts +64 -0
- package/dist/{host → agent-core/host}/local-agent-host.d.ts +6 -5
- package/dist/{host → agent-core/host}/local-agent-host.js +4 -4
- package/dist/{model → agent-core/model}/anthropic-messages.js +24 -7
- package/dist/{model → agent-core/model}/contracts.d.ts +6 -16
- package/dist/{model → agent-core/model}/openai-responses.js +28 -10
- package/dist/agent-core/model/recovery.d.ts +4 -0
- package/dist/agent-core/model/recovery.js +71 -0
- package/dist/{model → agent-core/model}/sse.d.ts +2 -0
- package/dist/{model → agent-core/model}/sse.js +11 -1
- package/dist/{prompts → agent-core/prompts}/core.d.ts +3 -13
- package/dist/{prompts → agent-core/prompts}/index.d.ts +1 -1
- package/dist/{prompts → agent-core/prompts}/modes.d.ts +1 -1
- package/dist/{prompts → agent-core/prompts}/resources.d.ts +1 -1
- package/dist/{runtime/compact.d.ts → agent-core/runtime/compaction/history.d.ts} +2 -23
- package/dist/{runtime/compact.js → agent-core/runtime/compaction/history.js} +2 -92
- package/dist/agent-core/runtime/compaction/operation.d.ts +22 -0
- package/dist/agent-core/runtime/compaction/operation.js +91 -0
- package/dist/agent-core/runtime/context/contracts.d.ts +12 -0
- package/dist/{runtime/environment-context.d.ts → agent-core/runtime/context/environment.d.ts} +2 -2
- package/dist/{runtime/environment-context.js → agent-core/runtime/context/environment.js} +1 -1
- package/dist/{runtime/context-gc-runtime.d.ts → agent-core/runtime/context/gc-runtime.d.ts} +4 -4
- package/dist/{runtime/context-gc-runtime.js → agent-core/runtime/context/gc-runtime.js} +3 -3
- package/dist/{runtime/context-gc-tokens.d.ts → agent-core/runtime/context/gc-tokens.d.ts} +2 -2
- package/dist/{runtime/context-gc-tokens.js → agent-core/runtime/context/gc-tokens.js} +3 -3
- package/dist/{runtime/context-gc.d.ts → agent-core/runtime/context/gc.d.ts} +3 -3
- package/dist/{runtime/context-gc.js → agent-core/runtime/context/gc.js} +6 -6
- package/dist/{runtime → agent-core/runtime/context}/instructions.d.ts +1 -1
- package/dist/{runtime → agent-core/runtime/context}/instructions.js +1 -1
- package/dist/{runtime → agent-core/runtime/context}/normalize.d.ts +1 -1
- package/dist/{runtime/context-projection.d.ts → agent-core/runtime/context/projection.d.ts} +3 -3
- package/dist/{runtime/context-projection.js → agent-core/runtime/context/projection.js} +4 -4
- package/dist/agent-core/runtime/context/request-budget.d.ts +6 -0
- package/dist/agent-core/runtime/context/request-budget.js +22 -0
- package/dist/agent-core/runtime/context/restore.d.ts +15 -0
- package/dist/agent-core/runtime/context/restore.js +85 -0
- package/dist/agent-core/runtime/context/usage.d.ts +18 -0
- package/dist/agent-core/runtime/context/usage.js +138 -0
- package/dist/agent-core/runtime/context/world-state.d.ts +35 -0
- package/dist/agent-core/runtime/context/world-state.js +133 -0
- package/dist/agent-core/runtime/contracts.d.ts +37 -0
- package/dist/agent-core/runtime/event-projection.d.ts +5 -0
- package/dist/agent-core/runtime/event-projection.js +17 -0
- package/dist/agent-core/runtime/events.d.ts +142 -0
- package/dist/agent-core/runtime/execution.d.ts +50 -0
- package/dist/agent-core/runtime/execution.js +393 -0
- package/dist/{runtime → agent-core/runtime}/rollout-budget.d.ts +1 -1
- package/dist/agent-core/sdk/agent.js +209 -0
- package/dist/agent-core/sdk/model-runtime.d.ts +13 -0
- package/dist/agent-core/sdk/model-runtime.js +63 -0
- package/dist/agent-core/sdk/session-title.d.ts +3 -0
- package/dist/agent-core/sdk/session-title.js +42 -0
- package/dist/agent-core/sdk/session.d.ts +62 -0
- package/dist/agent-core/sdk/session.js +1147 -0
- package/dist/agent-core/sdk/subagent-backend.d.ts +3 -0
- package/dist/agent-core/sdk/subagent-backend.js +46 -0
- package/dist/agent-core/sdk/types.d.ts +56 -0
- package/dist/{session → agent-core/session}/catalog.d.ts +2 -1
- package/dist/{session → agent-core/session}/context-gc-checkpoint.js +1 -1
- package/dist/{session → agent-core/session}/jsonl-store.d.ts +2 -2
- package/dist/{session → agent-core/session}/jsonl-store.js +1 -1
- package/dist/agent-core/subagent/contracts.d.ts +91 -0
- package/dist/agent-core/subagent/contracts.js +1 -0
- package/dist/agent-core/subagent/scheduler.d.ts +117 -0
- package/dist/{subagent → agent-core/subagent}/session-controller.d.ts +3 -2
- package/dist/agent-core/tools/agent/agent-cancel.d.ts +7 -0
- package/dist/{tools → agent-core/tools/agent}/agent-cancel.js +1 -1
- package/dist/agent-core/tools/agent/agent-message.d.ts +7 -0
- package/dist/{tools → agent-core/tools/agent}/agent-message.js +2 -2
- package/dist/{tools → agent-core/tools/agent}/agent-start.d.ts +3 -3
- package/dist/{tools → agent-core/tools/agent}/agent-start.js +3 -3
- package/dist/agent-core/tools/agent/agent-wait.d.ts +7 -0
- package/dist/{tools → agent-core/tools/agent}/agent-wait.js +2 -2
- package/dist/{tools → agent-core/tools/agent}/question.d.ts +2 -2
- package/dist/{tools → agent-core/tools/agent}/question.js +2 -2
- package/dist/{tools → agent-core/tools/agent}/skill.d.ts +2 -2
- package/dist/{tools → agent-core/tools/agent}/skill.js +2 -2
- package/dist/{tools → agent-core/tools/agent}/todo-read.d.ts +2 -2
- package/dist/{tools → agent-core/tools/agent}/todo-write.d.ts +2 -2
- package/dist/{tools → agent-core/tools/agent}/todo-write.js +2 -2
- package/dist/{tools → agent-core/tools/agent}/todo.d.ts +2 -9
- package/dist/{tools → agent-core/tools/agent}/todo.js +1 -1
- package/dist/{tools → agent-core/tools}/code-mode/cells.d.ts +1 -1
- package/dist/{tools → agent-core/tools}/code-mode/dispatch.d.ts +2 -4
- package/dist/{tools → agent-core/tools}/code-mode/dispatch.js +5 -4
- package/dist/{tools → agent-core/tools}/code-mode/engine.d.ts +1 -1
- package/dist/agent-core/tools/code-mode/engine.js +1 -0
- package/dist/{tools/code-mode.d.ts → agent-core/tools/code-mode/index.d.ts} +7 -7
- package/dist/{tools/code-mode.js → agent-core/tools/code-mode/index.js} +15 -16
- package/dist/{tools → agent-core/tools}/code-mode/quickjs-engine.js +12 -2
- package/dist/{tools → agent-core/tools}/code-mode/state.d.ts +2 -13
- package/dist/agent-core/tools/code-mode/worker.d.ts +1 -0
- package/dist/agent-core/tools/contracts.d.ts +168 -0
- package/dist/agent-core/tools/contracts.js +1 -0
- package/dist/agent-core/tools/execution.d.ts +34 -0
- package/dist/agent-core/tools/execution.js +102 -0
- package/dist/agent-core/tools/local/apply-patch.d.ts +19 -0
- package/dist/{tools → agent-core/tools/local}/apply-patch.js +8 -2
- package/dist/{tools → agent-core/tools/local}/exec.d.ts +5 -17
- package/dist/{tools → agent-core/tools/local}/exec.js +4 -4
- package/dist/{tools → agent-core/tools/local}/read.d.ts +7 -15
- package/dist/{tools → agent-core/tools/local}/read.js +185 -2
- package/dist/{tools/local-registry.d.ts → agent-core/tools/local/registry.d.ts} +5 -5
- package/dist/agent-core/tools/local/registry.js +101 -0
- package/dist/{tools → agent-core/tools/local}/view-image.d.ts +4 -9
- package/dist/{tools → agent-core/tools/local}/view-image.js +2 -2
- package/dist/agent-core/tools/local/web-fetch.d.ts +4 -0
- package/dist/agent-core/tools/local/web-fetch.js +85 -0
- package/dist/agent-core/tools/local/web-search.d.ts +7 -0
- package/dist/agent-core/tools/local/web-search.js +34 -0
- package/dist/{tools/local-workspace-tools.js → agent-core/tools/local/workspace-tools.js} +1 -1
- package/dist/{sdk/mcp-catalog.d.ts → agent-core/tools/mcp/catalog.d.ts} +1 -2
- package/dist/{sdk/mcp-catalog.js → agent-core/tools/mcp/catalog.js} +1 -1
- package/dist/agent-core/tools/mcp/history.d.ts +4 -0
- package/dist/agent-core/tools/mcp/history.js +33 -0
- package/dist/{tools → agent-core/tools/mcp}/tool-search.d.ts +3 -3
- package/dist/{tools → agent-core/tools/mcp}/tool-search.js +4 -4
- package/dist/agent-core/tools/output-projection.d.ts +14 -0
- package/dist/agent-core/tools/output-projection.js +189 -0
- package/dist/{tools → agent-core/tools}/registry.d.ts +1 -1
- package/dist/agent-core/tools/registry.js +47 -0
- package/dist/{tools → agent-core/tools}/runtime-context.d.ts +8 -7
- package/dist/agent-core/tools/runtime-context.js +1 -0
- package/dist/{tools → agent-core/tools}/runtime.d.ts +1 -1
- package/dist/cli/codex-auth-file.d.ts +1 -1
- package/dist/cli/codex-auth-file.js +2 -2
- package/dist/cli/main.js +9 -9
- package/dist/index.d.ts +17 -15
- package/dist/index.js +8 -8
- package/dist/sandbox/linux/bubblewrap-sandbox-executor.d.ts +1 -1
- package/dist/sandbox/linux/bubblewrap-sandbox-executor.js +1 -1
- package/package.json +3 -3
- package/dist/host/contracts.d.ts +0 -21
- package/dist/sdk/agent.js +0 -2524
- package/dist/sdk/types.d.ts +0 -349
- package/dist/subagent/scheduler.d.ts +0 -206
- package/dist/tools/agent-cancel.d.ts +0 -7
- package/dist/tools/agent-message.d.ts +0 -7
- package/dist/tools/agent-wait.d.ts +0 -7
- package/dist/tools/apply-patch.d.ts +0 -32
- package/dist/tools/local-registry.js +0 -373
- package/dist/tools/registry.js +0 -47
- package/dist/tools/web-fetch.d.ts +0 -2
- package/dist/tools/web-fetch.js +0 -12
- package/dist/tools/web-search.d.ts +0 -2
- package/dist/tools/web-search.js +0 -15
- package/dist/{error.d.ts → agent-core/error.d.ts} +0 -0
- package/dist/{error.js → agent-core/error.js} +0 -0
- package/dist/{host → agent-core/host}/contracts.js +0 -0
- package/dist/{host → agent-core/host}/local-process-executor.d.ts +0 -0
- package/dist/{host → agent-core/host}/local-process-executor.js +0 -0
- package/dist/{host → agent-core/host}/network.d.ts +0 -0
- package/dist/{host → agent-core/host}/network.js +0 -0
- package/dist/{model → agent-core/model}/anthropic-messages.d.ts +0 -0
- package/dist/{model → agent-core/model}/anthropic-thinking.d.ts +0 -0
- package/dist/{model → agent-core/model}/anthropic-thinking.js +0 -0
- package/dist/{model → agent-core/model}/catalog-file.d.ts +0 -0
- package/dist/{model → agent-core/model}/catalog-file.js +0 -0
- package/dist/{model → agent-core/model}/configuration.d.ts +0 -0
- package/dist/{model → agent-core/model}/configuration.js +0 -0
- package/dist/{model → agent-core/model}/contracts.js +0 -0
- package/dist/{model → agent-core/model}/http.d.ts +0 -0
- package/dist/{model → agent-core/model}/http.js +0 -0
- package/dist/{model → agent-core/model}/openai-responses.d.ts +0 -0
- package/dist/{model → agent-core/model}/runtime-credential.d.ts +0 -0
- package/dist/{model → agent-core/model}/runtime-credential.js +0 -0
- package/dist/{model → agent-core/model}/transport-test.d.ts +0 -0
- package/dist/{model → agent-core/model}/transport-test.js +0 -0
- package/dist/{prompts → agent-core/prompts}/compact.d.ts +0 -0
- package/dist/{prompts → agent-core/prompts}/compact.js +0 -0
- package/dist/{prompts → agent-core/prompts}/core.js +0 -0
- package/dist/{prompts → agent-core/prompts}/execution-budget.d.ts +0 -0
- package/dist/{prompts → agent-core/prompts}/execution-budget.js +0 -0
- package/dist/{prompts → agent-core/prompts}/index.js +0 -0
- package/dist/{prompts → agent-core/prompts}/modes.js +0 -0
- package/dist/{prompts → agent-core/prompts}/output.d.ts +0 -0
- package/dist/{prompts → agent-core/prompts}/output.js +0 -0
- package/dist/{prompts → agent-core/prompts}/resources.js +0 -0
- package/dist/{prompts → agent-core/prompts}/subagent.d.ts +0 -0
- package/dist/{prompts → agent-core/prompts}/subagent.js +0 -0
- package/dist/{prompts → agent-core/prompts}/title.d.ts +0 -0
- package/dist/{prompts → agent-core/prompts}/title.js +0 -0
- package/dist/{prompts → agent-core/prompts}/workflow.d.ts +0 -0
- package/dist/{prompts → agent-core/prompts}/workflow.js +0 -0
- package/dist/{runtime → agent-core/runtime}/async-queue.d.ts +0 -0
- package/dist/{runtime → agent-core/runtime}/async-queue.js +0 -0
- package/dist/{sdk/types.js → agent-core/runtime/context/contracts.js} +0 -0
- package/dist/{runtime → agent-core/runtime/context}/normalize.js +0 -0
- package/dist/{session/types.js → agent-core/runtime/contracts.js} +0 -0
- package/dist/{tools/code-mode/engine.js → agent-core/runtime/events.js} +0 -0
- package/dist/{runtime → agent-core/runtime}/execution-policy.d.ts +0 -0
- package/dist/{runtime → agent-core/runtime}/execution-policy.js +0 -0
- package/dist/{runtime → agent-core/runtime}/plan-output.d.ts +0 -0
- package/dist/{runtime → agent-core/runtime}/plan-output.js +0 -0
- package/dist/{runtime → agent-core/runtime}/rollout-budget.js +0 -0
- package/dist/{runtime → agent-core/runtime}/token-budget.d.ts +0 -0
- package/dist/{runtime → agent-core/runtime}/token-budget.js +0 -0
- package/dist/{sdk → agent-core/sdk}/agent.d.ts +0 -0
- package/dist/{tools/code-mode/worker.d.ts → agent-core/sdk/types.js} +0 -0
- package/dist/{session → agent-core/session}/catalog.js +0 -0
- package/dist/{session → agent-core/session}/context-gc-checkpoint.d.ts +0 -0
- package/dist/{session → agent-core/session}/context-gc-replacements.d.ts +0 -0
- package/dist/{session → agent-core/session}/context-gc-replacements.js +0 -0
- package/dist/{session → agent-core/session}/context-gc-subagent.d.ts +0 -0
- package/dist/{session → agent-core/session}/context-gc-subagent.js +0 -0
- package/dist/{session → agent-core/session}/transaction-recovery.d.ts +0 -0
- package/dist/{session → agent-core/session}/transaction-recovery.js +0 -0
- package/dist/{session → agent-core/session}/types.d.ts +0 -0
- package/dist/{tools/runtime-context.js → agent-core/session/types.js} +0 -0
- package/dist/{subagent → agent-core/subagent}/scheduler.js +0 -0
- package/dist/{subagent → agent-core/subagent}/session-controller.js +0 -0
- package/dist/{tools → agent-core/tools/agent}/todo-read.js +0 -0
- package/dist/{tools → agent-core/tools}/callers.d.ts +0 -0
- package/dist/{tools → agent-core/tools}/callers.js +0 -0
- package/dist/{tools → agent-core/tools}/code-mode/cells.js +1 -1
- /package/dist/{tools → agent-core/tools}/code-mode/quickjs-engine.d.ts +0 -0
- /package/dist/{tools → agent-core/tools}/code-mode/state.js +0 -0
- /package/dist/{tools → agent-core/tools}/code-mode/text-output.d.ts +0 -0
- /package/dist/{tools → agent-core/tools}/code-mode/text-output.js +0 -0
- /package/dist/{tools → agent-core/tools}/code-mode/worker.js +0 -0
- /package/dist/{tools → agent-core/tools}/execution-limits.d.ts +0 -0
- /package/dist/{tools → agent-core/tools}/execution-limits.js +0 -0
- /package/dist/{tools → agent-core/tools/local}/read-context.d.ts +0 -0
- /package/dist/{tools → agent-core/tools/local}/read-context.js +0 -0
- /package/dist/{tools/local-workspace-tools.d.ts → agent-core/tools/local/workspace-tools.d.ts} +0 -0
- /package/dist/{tools → agent-core/tools}/runtime.js +0 -0
- /package/dist/{tools → agent-core/tools}/scheduler.d.ts +0 -0
- /package/dist/{tools → agent-core/tools}/scheduler.js +0 -0
- /package/dist/{tools → agent-core/tools}/shared/path-resolver.d.ts +0 -0
- /package/dist/{tools → agent-core/tools}/shared/path-resolver.js +0 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { retainedSessionResourcesUpdate } from '../../prompts/resources.js';
|
|
2
|
+
import { compactSummaryFromCheckpoint } from '../../session/jsonl-store.js';
|
|
3
|
+
export function insertContextualWorldState(messages, entries) {
|
|
4
|
+
const result = [...messages];
|
|
5
|
+
let offset = 0;
|
|
6
|
+
for (const entry of entries) {
|
|
7
|
+
const insertionIndex = Math.max(0, Math.min(entry.index + offset, result.length));
|
|
8
|
+
result.splice(insertionIndex, 0, { role: 'user', content: entry.content });
|
|
9
|
+
offset++;
|
|
10
|
+
}
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
export function latestContextualWorldStateGeneration(records) {
|
|
14
|
+
let generation;
|
|
15
|
+
for (const record of records)
|
|
16
|
+
if (record.type === 'context.gc.completed' ||
|
|
17
|
+
compactSummaryFromCheckpoint(record) !== undefined)
|
|
18
|
+
generation = record.recordId;
|
|
19
|
+
return generation;
|
|
20
|
+
}
|
|
21
|
+
const MAX_CONTEXTUAL_WORLD_STATE_ENTRIES = 1_024;
|
|
22
|
+
const MAX_CONTEXTUAL_WORLD_STATE_CONTENT_BYTES = 8 * 1024 * 1024;
|
|
23
|
+
export function parsePersistedContextualWorldState(payload) {
|
|
24
|
+
if (payload === null || typeof payload !== 'object' || Array.isArray(payload))
|
|
25
|
+
return undefined;
|
|
26
|
+
const record = payload;
|
|
27
|
+
if (record.version !== 1)
|
|
28
|
+
return undefined;
|
|
29
|
+
const generation = record.generation === null
|
|
30
|
+
? undefined
|
|
31
|
+
: typeof record.generation === 'string' && record.generation.length <= 128
|
|
32
|
+
? record.generation
|
|
33
|
+
: null;
|
|
34
|
+
if (generation === null)
|
|
35
|
+
return undefined;
|
|
36
|
+
const instructionSnapshot = nullableWorldStateString(record.instructionSnapshot);
|
|
37
|
+
const resourceSnapshot = nullableWorldStateString(record.resourceSnapshot);
|
|
38
|
+
if (instructionSnapshot === null || resourceSnapshot === null || !Array.isArray(record.entries))
|
|
39
|
+
return undefined;
|
|
40
|
+
if (record.entries.length > MAX_CONTEXTUAL_WORLD_STATE_ENTRIES)
|
|
41
|
+
return undefined;
|
|
42
|
+
const entries = [];
|
|
43
|
+
let contentBytes = 0;
|
|
44
|
+
for (const value of record.entries) {
|
|
45
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
46
|
+
return undefined;
|
|
47
|
+
const entry = value;
|
|
48
|
+
if (!Number.isSafeInteger(entry.index) ||
|
|
49
|
+
entry.index < 0 ||
|
|
50
|
+
(entry.kind !== 'instructions' && entry.kind !== 'resources' && entry.kind !== 'mcp') ||
|
|
51
|
+
typeof entry.content !== 'string' ||
|
|
52
|
+
entry.content.length === 0)
|
|
53
|
+
return undefined;
|
|
54
|
+
contentBytes += Buffer.byteLength(entry.content);
|
|
55
|
+
if (contentBytes > MAX_CONTEXTUAL_WORLD_STATE_CONTENT_BYTES)
|
|
56
|
+
return undefined;
|
|
57
|
+
entries.push({
|
|
58
|
+
index: entry.index,
|
|
59
|
+
kind: entry.kind,
|
|
60
|
+
content: entry.content
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
generation,
|
|
65
|
+
initialized: true,
|
|
66
|
+
instructionSnapshot,
|
|
67
|
+
resourceSnapshot,
|
|
68
|
+
mcpSnapshot: typeof record.mcpSnapshot === 'string' ? record.mcpSnapshot : undefined,
|
|
69
|
+
entries
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function nullableWorldStateString(value) {
|
|
73
|
+
if (value === null)
|
|
74
|
+
return undefined;
|
|
75
|
+
return typeof value === 'string' &&
|
|
76
|
+
Buffer.byteLength(value) <= MAX_CONTEXTUAL_WORLD_STATE_CONTENT_BYTES
|
|
77
|
+
? value
|
|
78
|
+
: null;
|
|
79
|
+
}
|
|
80
|
+
export async function persistContextualWorldState(store, sessionId, state) {
|
|
81
|
+
await store.writeContextualWorldState(sessionId, {
|
|
82
|
+
version: 1,
|
|
83
|
+
generation: state.generation ?? null,
|
|
84
|
+
instructionSnapshot: state.instructionSnapshot ?? null,
|
|
85
|
+
resourceSnapshot: state.resourceSnapshot ?? null,
|
|
86
|
+
mcpSnapshot: state.mcpSnapshot ?? null,
|
|
87
|
+
entries: state.entries
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
export function compactHistoryMayContainRetainedResources(records) {
|
|
91
|
+
return records.some((record) => compactSummaryFromCheckpoint(record)?.includes('# Retained Session resources'));
|
|
92
|
+
}
|
|
93
|
+
export function updateContextualWorldState(state, index, current) {
|
|
94
|
+
const entries = [...state.entries];
|
|
95
|
+
if (!state.initialized || state.instructionSnapshot !== current.instructionSnapshot) {
|
|
96
|
+
if (current.instructionContent !== undefined)
|
|
97
|
+
entries.push({ index, kind: 'instructions', content: current.instructionContent });
|
|
98
|
+
}
|
|
99
|
+
const resourceContent = retainedSessionResourcesUpdate(current.resourceSnapshot, state.initialized ? state.resourceSnapshot : undefined, current.previousMayContainResources);
|
|
100
|
+
if (resourceContent !== undefined)
|
|
101
|
+
entries.push({ index, kind: 'resources', content: resourceContent });
|
|
102
|
+
return {
|
|
103
|
+
generation: state.generation,
|
|
104
|
+
mcpSnapshot: state.mcpSnapshot,
|
|
105
|
+
initialized: true,
|
|
106
|
+
instructionSnapshot: current.instructionSnapshot,
|
|
107
|
+
resourceSnapshot: current.resourceSnapshot,
|
|
108
|
+
entries
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export function resetContextualWorldState(generation, index, current) {
|
|
112
|
+
const entries = [];
|
|
113
|
+
if (current.instructionContent !== undefined)
|
|
114
|
+
entries.push({ index, kind: 'instructions', content: current.instructionContent });
|
|
115
|
+
const resourceContent = retainedSessionResourcesUpdate(current.resourceSnapshot, undefined, current.previousMayContainResources);
|
|
116
|
+
if (resourceContent !== undefined)
|
|
117
|
+
entries.push({ index, kind: 'resources', content: resourceContent });
|
|
118
|
+
return {
|
|
119
|
+
generation,
|
|
120
|
+
initialized: true,
|
|
121
|
+
instructionSnapshot: current.instructionSnapshot,
|
|
122
|
+
resourceSnapshot: current.resourceSnapshot,
|
|
123
|
+
entries
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
export function contextualInstructionInsertIndex(messages) {
|
|
127
|
+
let index = messages.findLastIndex((message) => message.role === 'user' && message.contextKind !== 'environment');
|
|
128
|
+
if (index < 0)
|
|
129
|
+
return 0;
|
|
130
|
+
if (index > 0 && messages[index - 1]?.contextKind === 'environment')
|
|
131
|
+
index--;
|
|
132
|
+
return index;
|
|
133
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { MarAgentReasoningEffort } from '../model/configuration.js';
|
|
2
|
+
/** @deprecated MAR Agent always executes tools directly through the Host. */
|
|
3
|
+
export type AccessMode = 'full-access';
|
|
4
|
+
export type ExecutionMode = 'run' | 'plan' | 'compact';
|
|
5
|
+
export interface RunInputImage {
|
|
6
|
+
name: string;
|
|
7
|
+
mimeType: string;
|
|
8
|
+
dataBase64: string;
|
|
9
|
+
}
|
|
10
|
+
export interface MarAgentImageMetadata {
|
|
11
|
+
name: string;
|
|
12
|
+
mimeType: string;
|
|
13
|
+
byteSize: number;
|
|
14
|
+
}
|
|
15
|
+
export interface RunInput {
|
|
16
|
+
prompt: string;
|
|
17
|
+
clientMessageId?: string;
|
|
18
|
+
modelId?: string;
|
|
19
|
+
reasoningEffort?: MarAgentReasoningEffort;
|
|
20
|
+
/** @deprecated Accepted for source compatibility and otherwise ignored. */
|
|
21
|
+
access?: AccessMode;
|
|
22
|
+
images?: readonly RunInputImage[];
|
|
23
|
+
}
|
|
24
|
+
export interface ExecutionResult {
|
|
25
|
+
executionId: string;
|
|
26
|
+
status: 'completed' | 'failed' | 'cancelled';
|
|
27
|
+
finalAnswer: string;
|
|
28
|
+
errorCode?: string;
|
|
29
|
+
errorMessage?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface RolloutBudgetOptions {
|
|
32
|
+
limitTokens?: number;
|
|
33
|
+
conserveAtRemainingTokens?: number;
|
|
34
|
+
finalizeAtRemainingTokens?: number;
|
|
35
|
+
samplingTokenWeight?: number;
|
|
36
|
+
prefillTokenWeight?: number;
|
|
37
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ModelUsage } from '../model/contracts.js';
|
|
2
|
+
import type { MarAgentEvent } from './events.js';
|
|
3
|
+
/** Keep streaming deltas live-only; exec output has one durable copy in model context records. */
|
|
4
|
+
export declare function eventForPersistence(event: MarAgentEvent): MarAgentEvent | undefined;
|
|
5
|
+
export declare function publicModelUsage(usage: ModelUsage): Omit<ModelUsage, 'rolloutBudgetUnits'>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Keep streaming deltas live-only; exec output has one durable copy in model context records. */
|
|
2
|
+
export function eventForPersistence(event) {
|
|
3
|
+
if (event.type === 'message.delta' ||
|
|
4
|
+
event.type === 'context.compacting' ||
|
|
5
|
+
event.type === 'model.performance' ||
|
|
6
|
+
event.type === 'message.performance')
|
|
7
|
+
return undefined;
|
|
8
|
+
if (event.type !== 'tool.completed' || event.toolName !== 'exec' || !event.data)
|
|
9
|
+
return event;
|
|
10
|
+
const metadata = Object.fromEntries(Object.entries(event.data).filter(([key]) => key !== 'stdout' && key !== 'stderr'));
|
|
11
|
+
return { ...event, data: metadata };
|
|
12
|
+
}
|
|
13
|
+
export function publicModelUsage(usage) {
|
|
14
|
+
const { rolloutBudgetUnits, ...publicUsage } = usage;
|
|
15
|
+
void rolloutBudgetUnits;
|
|
16
|
+
return publicUsage;
|
|
17
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { MarAgentReasoningEffort } from '../model/configuration.js';
|
|
2
|
+
import type { CodeCellEventData, MarAgentToolArtifact } from '../tools/contracts.js';
|
|
3
|
+
import type { ExecutionMode } from './contracts.js';
|
|
4
|
+
export interface MarAgentEventBase {
|
|
5
|
+
eventId: string;
|
|
6
|
+
sequence: number;
|
|
7
|
+
timestamp: string;
|
|
8
|
+
sessionId: string;
|
|
9
|
+
executionId: string;
|
|
10
|
+
turnId?: string;
|
|
11
|
+
}
|
|
12
|
+
export type MarAgentEvent = MarAgentEventBase & ({
|
|
13
|
+
type: 'execution.started';
|
|
14
|
+
mode: ExecutionMode;
|
|
15
|
+
} | {
|
|
16
|
+
type: 'message.delta';
|
|
17
|
+
itemId: string;
|
|
18
|
+
phase: 'commentary' | 'final_answer';
|
|
19
|
+
delta: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: 'message.completed';
|
|
22
|
+
itemId: string;
|
|
23
|
+
phase: 'commentary' | 'final_answer';
|
|
24
|
+
text: string;
|
|
25
|
+
modelId: string;
|
|
26
|
+
modelName: string;
|
|
27
|
+
} | {
|
|
28
|
+
type: 'model.performance';
|
|
29
|
+
latencyMs: number;
|
|
30
|
+
outputTokens?: number | undefined;
|
|
31
|
+
outputDurationMs?: number | undefined;
|
|
32
|
+
tokensPerSecond?: number | undefined;
|
|
33
|
+
} | {
|
|
34
|
+
/** Legacy history event; new executions publish model.performance instead. */
|
|
35
|
+
type: 'message.performance';
|
|
36
|
+
itemId: string;
|
|
37
|
+
ttftMs: number;
|
|
38
|
+
outputTokens?: number | undefined;
|
|
39
|
+
outputDurationMs?: number | undefined;
|
|
40
|
+
tokensPerSecond?: number | undefined;
|
|
41
|
+
} | {
|
|
42
|
+
type: 'plan.completed';
|
|
43
|
+
itemId: string;
|
|
44
|
+
text: string;
|
|
45
|
+
} | {
|
|
46
|
+
type: 'reasoning.summary';
|
|
47
|
+
text: string;
|
|
48
|
+
} | {
|
|
49
|
+
type: 'hosted_tool.updated';
|
|
50
|
+
itemId: string;
|
|
51
|
+
kind: 'WEB_SEARCH' | 'WEB_FETCH';
|
|
52
|
+
status: 'RUNNING' | 'COMPLETED' | 'FAILED';
|
|
53
|
+
summary: {
|
|
54
|
+
query?: string | undefined;
|
|
55
|
+
url?: string | undefined;
|
|
56
|
+
title?: string | undefined;
|
|
57
|
+
sources?: readonly {
|
|
58
|
+
url: string;
|
|
59
|
+
title?: string | undefined;
|
|
60
|
+
}[] | undefined;
|
|
61
|
+
sourcesTruncated?: boolean | undefined;
|
|
62
|
+
};
|
|
63
|
+
} | {
|
|
64
|
+
type: 'citation.added';
|
|
65
|
+
id: string;
|
|
66
|
+
url: string;
|
|
67
|
+
title?: string;
|
|
68
|
+
} | {
|
|
69
|
+
type: 'tool.started';
|
|
70
|
+
toolName: string;
|
|
71
|
+
callId: string;
|
|
72
|
+
parentCallId?: string;
|
|
73
|
+
input?: unknown;
|
|
74
|
+
} | {
|
|
75
|
+
type: 'tool.completed';
|
|
76
|
+
toolName: string;
|
|
77
|
+
callId: string;
|
|
78
|
+
parentCallId?: string;
|
|
79
|
+
summary: string;
|
|
80
|
+
truncated?: boolean;
|
|
81
|
+
artifacts?: readonly MarAgentToolArtifact[];
|
|
82
|
+
data?: CodeCellEventData | import('../tools/contracts.js').ExecResult | Omit<import('../tools/contracts.js').ExecResult, 'stdout' | 'stderr'> | import('../tools/contracts.js').ApplyPatchResult | import('../tools/contracts.js').ReadEventData | import('../tools/contracts.js').ViewImageResult | import('../subagent/contracts.js').SubagentTaskSnapshot;
|
|
83
|
+
} | {
|
|
84
|
+
type: 'tool.failed';
|
|
85
|
+
toolName: string;
|
|
86
|
+
callId: string;
|
|
87
|
+
parentCallId?: string;
|
|
88
|
+
code: string;
|
|
89
|
+
message?: string;
|
|
90
|
+
} | {
|
|
91
|
+
type: 'usage.updated';
|
|
92
|
+
inputTokens?: number | undefined;
|
|
93
|
+
contextInputTokens?: number | undefined;
|
|
94
|
+
outputTokens?: number | undefined;
|
|
95
|
+
cacheReadTokens?: number | undefined;
|
|
96
|
+
cacheWriteTokens?: number | undefined;
|
|
97
|
+
} | {
|
|
98
|
+
type: 'todo.updated';
|
|
99
|
+
revision: number;
|
|
100
|
+
items: readonly import('../tools/contracts.js').TodoItem[];
|
|
101
|
+
} | {
|
|
102
|
+
type: 'user_input.requested';
|
|
103
|
+
requestId: string;
|
|
104
|
+
questions: unknown[];
|
|
105
|
+
} | {
|
|
106
|
+
type: 'user_input.resolved';
|
|
107
|
+
requestId: string;
|
|
108
|
+
} | {
|
|
109
|
+
type: 'subagent.started';
|
|
110
|
+
agentId: string;
|
|
111
|
+
description: string;
|
|
112
|
+
modelId?: string;
|
|
113
|
+
modelName?: string;
|
|
114
|
+
reasoningEffort?: MarAgentReasoningEffort;
|
|
115
|
+
} | {
|
|
116
|
+
type: 'subagent.completed';
|
|
117
|
+
agentId: string;
|
|
118
|
+
description?: string;
|
|
119
|
+
status: string;
|
|
120
|
+
modelId?: string;
|
|
121
|
+
modelName?: string;
|
|
122
|
+
reasoningEffort?: MarAgentReasoningEffort;
|
|
123
|
+
latestMessage?: import('../subagent/contracts.js').SubagentLatestMessage;
|
|
124
|
+
latestActivity?: import('../subagent/contracts.js').SubagentLatestActivity;
|
|
125
|
+
errorCode?: string;
|
|
126
|
+
errorMessage?: string;
|
|
127
|
+
} | {
|
|
128
|
+
type: 'execution.completed';
|
|
129
|
+
} | {
|
|
130
|
+
type: 'execution.failed';
|
|
131
|
+
code: string;
|
|
132
|
+
message?: string;
|
|
133
|
+
} | {
|
|
134
|
+
type: 'execution.cancelled';
|
|
135
|
+
} | {
|
|
136
|
+
type: 'context.compacting';
|
|
137
|
+
compactionId: string;
|
|
138
|
+
} | {
|
|
139
|
+
type: 'context.compacted';
|
|
140
|
+
compactionId: string;
|
|
141
|
+
});
|
|
142
|
+
export type EventPayload<T = MarAgentEvent> = T extends MarAgentEvent ? Omit<T, 'eventId' | 'sequence' | 'timestamp' | 'sessionId' | 'executionId' | 'turnId'> : never;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { MarAgentModelConfiguration } from '../model/configuration.js';
|
|
2
|
+
import type { ModelEvent, ModelMessage, ModelRequest, ModelUsage } from '../model/contracts.js';
|
|
3
|
+
import { type RoundToolScope } from '../tools/execution.js';
|
|
4
|
+
import type { ToolRuntimeImage } from '../tools/runtime-context.js';
|
|
5
|
+
import type { AuthoritativeModelUsage } from './context/usage.js';
|
|
6
|
+
import type { ExecutionMode } from './contracts.js';
|
|
7
|
+
import type { EventPayload } from './events.js';
|
|
8
|
+
import type { RolloutBudget } from './rollout-budget.js';
|
|
9
|
+
export interface PreparedExecutionRound {
|
|
10
|
+
readonly request: ModelRequest;
|
|
11
|
+
readonly toolScope: RoundToolScope;
|
|
12
|
+
}
|
|
13
|
+
/** Internal execution-local ports. No Session/Agent object, OS handles or terminal publisher. */
|
|
14
|
+
export interface ExecutionLoopInput {
|
|
15
|
+
readonly mode: ExecutionMode;
|
|
16
|
+
readonly sourceType: 'user' | 'subagent';
|
|
17
|
+
readonly signal: AbortSignal;
|
|
18
|
+
readonly model: Pick<MarAgentModelConfiguration, 'id' | 'name'>;
|
|
19
|
+
readonly messages: ModelMessage[];
|
|
20
|
+
readonly toolImages: ToolRuntimeImage[];
|
|
21
|
+
readonly rolloutBudget: RolloutBudget | undefined;
|
|
22
|
+
readonly publish: (event: EventPayload) => Promise<void>;
|
|
23
|
+
readonly appendContext: (message: ModelMessage) => Promise<void>;
|
|
24
|
+
readonly prepareRound: (continuation: ModelMessage | undefined) => Promise<PreparedExecutionRound>;
|
|
25
|
+
readonly startModel: (request: ModelRequest) => AsyncIterable<ModelEvent>;
|
|
26
|
+
readonly recoverySignal: () => AbortSignal;
|
|
27
|
+
readonly compactContext: () => Promise<boolean>;
|
|
28
|
+
readonly compactionFallback?: (() => boolean) | undefined;
|
|
29
|
+
readonly observeUsage: (usage: Omit<AuthoritativeModelUsage, 'historyMessages'> | undefined) => void;
|
|
30
|
+
readonly observeContextTokens: (tokens: number) => void;
|
|
31
|
+
readonly checkpoint: (round: PreparedExecutionRound, usage: ModelUsage | undefined) => Promise<void>;
|
|
32
|
+
readonly mailbox: {
|
|
33
|
+
hasPending(): boolean;
|
|
34
|
+
append(): Promise<boolean>;
|
|
35
|
+
close(): void;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Own the single model/tool loop; the SDK owns its handle, terminal events and cleanup. */
|
|
39
|
+
export declare class ExecutionLoop {
|
|
40
|
+
#private;
|
|
41
|
+
private readonly input;
|
|
42
|
+
private readonly planOutputPrefixes;
|
|
43
|
+
get finalAnswer(): string;
|
|
44
|
+
private set finalAnswer(value);
|
|
45
|
+
constructor(input: ExecutionLoopInput);
|
|
46
|
+
run(): Promise<{
|
|
47
|
+
finalAnswer: string;
|
|
48
|
+
usage?: ModelUsage;
|
|
49
|
+
}>;
|
|
50
|
+
}
|