@myagentroam/agent 0.9.173 → 0.9.175
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/extensions/compaction.d.ts +1 -1
- package/dist/agent-core/extensions/model-request.js +7 -1
- package/dist/agent-core/extensions/model-stream.js +5 -1
- package/dist/agent-core/model/anthropic-messages.js +35 -25
- package/dist/agent-core/model/catalog-file.d.ts +0 -2
- package/dist/agent-core/model/catalog-file.js +7 -0
- package/dist/agent-core/model/configuration.d.ts +0 -1
- package/dist/agent-core/model/configuration.js +0 -1
- package/dist/agent-core/model/contracts.d.ts +13 -0
- package/dist/agent-core/model/openai-responses.js +57 -48
- package/dist/agent-core/model/sse.js +59 -9
- package/dist/agent-core/prompts/compact.d.ts +0 -1
- package/dist/agent-core/prompts/compact.js +0 -56
- package/dist/agent-core/prompts/index.d.ts +0 -1
- package/dist/agent-core/prompts/index.js +2 -9
- package/dist/agent-core/runtime/compaction/history.d.ts +1 -2
- package/dist/agent-core/runtime/compaction/history.js +4 -4
- package/dist/agent-core/runtime/events.d.ts +1 -1
- package/dist/agent-core/runtime/execution.js +35 -24
- package/dist/agent-core/runtime/model-generation-timing.d.ts +12 -0
- package/dist/agent-core/runtime/model-generation-timing.js +39 -0
- package/dist/agent-core/sdk/session.js +7 -11
- package/dist/agent-core/tools/agent/agent-start.js +3 -1
- package/dist/agent-core/tools/code-mode/index.js +10 -5
- package/dist/agent-core/tools/definition-projection.d.ts +7 -0
- package/dist/agent-core/tools/definition-projection.js +26 -0
- package/dist/agent-core/tools/mcp/tool-search.js +12 -4
- package/dist/cli/main.js +6 -4
- package/package.json +1 -1
|
@@ -5,6 +5,7 @@ import { modelOutputContinuationMessage } from '../prompts/output.js';
|
|
|
5
5
|
import { executeRoundTools } from '../tools/execution.js';
|
|
6
6
|
import { publicHostedToolEvents, publicModelUsage } from './event-projection.js';
|
|
7
7
|
import { PlanOutputPrefix, splitPlanOutput } from './plan-output.js';
|
|
8
|
+
import { ModelGenerationTiming } from './model-generation-timing.js';
|
|
8
9
|
/** Own the single model/tool loop; the SDK owns its handle, terminal events and cleanup. */
|
|
9
10
|
export class ExecutionLoop {
|
|
10
11
|
input;
|
|
@@ -38,8 +39,7 @@ export class ExecutionLoop {
|
|
|
38
39
|
let sawModelSemanticEvent = false;
|
|
39
40
|
let requestStartedAt;
|
|
40
41
|
let firstModelResponseAt;
|
|
41
|
-
let
|
|
42
|
-
let lastOutputDeltaAt;
|
|
42
|
+
let generation = new ModelGenerationTiming();
|
|
43
43
|
let requestCompletedAt;
|
|
44
44
|
let requestOutputTokens;
|
|
45
45
|
const roundMessageCount = messages.length;
|
|
@@ -52,19 +52,18 @@ export class ExecutionLoop {
|
|
|
52
52
|
});
|
|
53
53
|
};
|
|
54
54
|
const emitFinalPerformance = async (completedAt) => {
|
|
55
|
-
if (mode === 'compact'
|
|
56
|
-
firstModelResponseAt === undefined ||
|
|
57
|
-
firstOutputDeltaAt === undefined ||
|
|
58
|
-
lastOutputDeltaAt === undefined ||
|
|
59
|
-
lastOutputDeltaAt - firstOutputDeltaAt < 1)
|
|
55
|
+
if (mode === 'compact')
|
|
60
56
|
return;
|
|
61
|
-
|
|
57
|
+
generation.finish(completedAt);
|
|
58
|
+
const outputDuration = generation.durationMs;
|
|
62
59
|
const outputTokens = requestOutputTokens;
|
|
63
|
-
if (outputTokens === undefined || outputDuration
|
|
60
|
+
if (outputTokens === undefined || outputDuration === undefined)
|
|
64
61
|
return;
|
|
65
62
|
await input.publish({
|
|
66
63
|
type: 'model.performance',
|
|
67
|
-
|
|
64
|
+
...(firstModelResponseAt === undefined
|
|
65
|
+
? {}
|
|
66
|
+
: { latencyMs: Math.max(0, Math.round(firstModelResponseAt - requestStartedAt)) }),
|
|
68
67
|
outputTokens,
|
|
69
68
|
outputDurationMs: Math.round(outputDuration),
|
|
70
69
|
tokensPerSecond: Number(((outputTokens * 1000) / outputDuration).toFixed(2))
|
|
@@ -91,14 +90,25 @@ export class ExecutionLoop {
|
|
|
91
90
|
retryState: modelRetryState
|
|
92
91
|
})) {
|
|
93
92
|
if (event.type === 'output.reset') {
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
generation = new ModelGenerationTiming();
|
|
94
|
+
requestCompletedAt = undefined;
|
|
96
95
|
requestOutputTokens = undefined;
|
|
97
96
|
continue;
|
|
98
97
|
}
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
const observedAt = Math.max(requestStartedAt, modelStreamEventObservedAt(event) ?? performance.now());
|
|
99
|
+
if (event.type === 'output.started') {
|
|
100
|
+
generation.start(observedAt);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (event.type === 'output.completed') {
|
|
104
|
+
generation.finish(observedAt);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (event.type === 'output.paused') {
|
|
108
|
+
generation.pause(observedAt);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const modelResponseAt = mode !== 'compact' && isModelResponseEvent(event) ? observedAt : undefined;
|
|
102
112
|
const isFirstModelResponse = modelResponseAt !== undefined && firstModelResponseAt === undefined;
|
|
103
113
|
if (modelResponseAt !== undefined) {
|
|
104
114
|
if (event.type !== 'output.delta')
|
|
@@ -106,8 +116,7 @@ export class ExecutionLoop {
|
|
|
106
116
|
firstModelResponseAt ??= modelResponseAt;
|
|
107
117
|
if (event.type === 'output.delta' ||
|
|
108
118
|
(event.type === 'text.delta' && event.delta.length > 0)) {
|
|
109
|
-
|
|
110
|
-
lastOutputDeltaAt = modelResponseAt;
|
|
119
|
+
generation.start(modelResponseAt);
|
|
111
120
|
}
|
|
112
121
|
}
|
|
113
122
|
if (event.type === 'response.item') {
|
|
@@ -185,14 +194,15 @@ export class ExecutionLoop {
|
|
|
185
194
|
}
|
|
186
195
|
else if (event.type === 'usage') {
|
|
187
196
|
latestUsage = event.usage;
|
|
197
|
+
if (event.final === true)
|
|
198
|
+
generation.finish(observedAt);
|
|
188
199
|
const outputTokens = typeof event.usage.outputTokens === 'number' &&
|
|
189
200
|
Number.isSafeInteger(event.usage.outputTokens) &&
|
|
190
201
|
event.usage.outputTokens >= 0
|
|
191
202
|
? event.usage.outputTokens
|
|
192
203
|
: undefined;
|
|
193
|
-
if (outputTokens !== undefined)
|
|
204
|
+
if (event.final !== false && (outputTokens !== undefined || event.final === true))
|
|
194
205
|
requestOutputTokens = outputTokens;
|
|
195
|
-
}
|
|
196
206
|
const reportedContext = event.usage.contextInputTokens ?? event.usage.inputTokens;
|
|
197
207
|
if (reportedContext !== undefined &&
|
|
198
208
|
Number.isSafeInteger(reportedContext) &&
|
|
@@ -235,15 +245,16 @@ export class ExecutionLoop {
|
|
|
235
245
|
}
|
|
236
246
|
else if (event.type === 'completed') {
|
|
237
247
|
stop = event.reason;
|
|
238
|
-
requestCompletedAt =
|
|
248
|
+
requestCompletedAt = observedAt;
|
|
239
249
|
}
|
|
240
250
|
if (isFirstModelResponse)
|
|
241
251
|
await emitLatency();
|
|
242
252
|
}
|
|
243
|
-
if (mode !== 'compact' &&
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
253
|
+
if (mode !== 'compact' &&
|
|
254
|
+
stop !== 'cancelled' &&
|
|
255
|
+
!input.signal.aborted &&
|
|
256
|
+
requestCompletedAt !== undefined)
|
|
257
|
+
await emitFinalPerformance(requestCompletedAt);
|
|
247
258
|
pendingOutputContinuation = undefined;
|
|
248
259
|
incompleteToolCall = pendingTools.some((call) => call.argumentError !== undefined);
|
|
249
260
|
if (!(stop === 'max_output' && incompleteToolCall)) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Request-local observed generation intervals, excluding explicit execution pauses. */
|
|
2
|
+
export declare class ModelGenerationTiming {
|
|
3
|
+
private startedAt;
|
|
4
|
+
private latestAt;
|
|
5
|
+
private duration;
|
|
6
|
+
private completed;
|
|
7
|
+
private valid;
|
|
8
|
+
start(at: number): void;
|
|
9
|
+
pause(at: number): void;
|
|
10
|
+
finish(at: number): void;
|
|
11
|
+
get durationMs(): number | undefined;
|
|
12
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Request-local observed generation intervals, excluding explicit execution pauses. */
|
|
2
|
+
export class ModelGenerationTiming {
|
|
3
|
+
startedAt;
|
|
4
|
+
latestAt;
|
|
5
|
+
duration = 0;
|
|
6
|
+
completed = false;
|
|
7
|
+
valid = true;
|
|
8
|
+
start(at) {
|
|
9
|
+
if (this.completed)
|
|
10
|
+
return;
|
|
11
|
+
if (!Number.isFinite(at) || (this.latestAt !== undefined && at < this.latestAt)) {
|
|
12
|
+
this.valid = false;
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
this.startedAt ??= at;
|
|
16
|
+
this.latestAt = at;
|
|
17
|
+
}
|
|
18
|
+
pause(at) {
|
|
19
|
+
if (this.completed || this.startedAt === undefined)
|
|
20
|
+
return;
|
|
21
|
+
if (!Number.isFinite(at) || at < (this.latestAt ?? this.startedAt))
|
|
22
|
+
this.valid = false;
|
|
23
|
+
else
|
|
24
|
+
this.duration += at - this.startedAt;
|
|
25
|
+
this.startedAt = undefined;
|
|
26
|
+
this.latestAt = at;
|
|
27
|
+
}
|
|
28
|
+
finish(at) {
|
|
29
|
+
if (this.completed)
|
|
30
|
+
return;
|
|
31
|
+
if (!Number.isFinite(at) || (this.latestAt !== undefined && at < this.latestAt))
|
|
32
|
+
this.valid = false;
|
|
33
|
+
this.pause(at);
|
|
34
|
+
this.completed = true;
|
|
35
|
+
}
|
|
36
|
+
get durationMs() {
|
|
37
|
+
return this.completed && this.valid && this.duration >= 1 ? this.duration : undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -109,7 +109,6 @@ export function createSessionOpener(services) {
|
|
|
109
109
|
.filter((tool) => !tool.name.startsWith('mcp__') &&
|
|
110
110
|
allowsDirectTool(tool, availableTools.some((candidate) => candidate.name === 'code_exec')))
|
|
111
111
|
.map((tool) => tool.name),
|
|
112
|
-
highDensityCompaction: selectedModel.highDensityCompaction,
|
|
113
112
|
extension: [
|
|
114
113
|
executionSystemInstruction,
|
|
115
114
|
skillCatalog,
|
|
@@ -1031,7 +1030,6 @@ export function createSessionOpener(services) {
|
|
|
1031
1030
|
if (!coreExtensions.hooks.hasInterceptors('compact.generate'))
|
|
1032
1031
|
return undefined;
|
|
1033
1032
|
const summaryTokenBudget = Math.min(10_000, selectedModel.maxOutputTokens, Math.max(1, Math.floor(selectedModel.contextWindowTokens / 4)));
|
|
1034
|
-
const highDensityCompaction = selectedModel.highDensityCompaction;
|
|
1035
1033
|
let diagnosticReports = 0;
|
|
1036
1034
|
let acceptsDiagnostics = true;
|
|
1037
1035
|
try {
|
|
@@ -1041,7 +1039,7 @@ export function createSessionOpener(services) {
|
|
|
1041
1039
|
messages: compactExtensionMessages(history),
|
|
1042
1040
|
...(focus === undefined ? {} : { focus }),
|
|
1043
1041
|
summaryTokenBudget,
|
|
1044
|
-
getPrompt: () => buildCompactionMessages(''
|
|
1042
|
+
getPrompt: () => buildCompactionMessages('')[1].content,
|
|
1045
1043
|
reportDiagnostic: async (value) => {
|
|
1046
1044
|
if (!acceptsDiagnostics || ++diagnosticReports > 8)
|
|
1047
1045
|
return;
|
|
@@ -1082,17 +1080,16 @@ export function createSessionOpener(services) {
|
|
|
1082
1080
|
const compactHistory = [...messages];
|
|
1083
1081
|
const projectedHistory = normalizeMessagesForModel(insertContextualWorldState(compactHistory, contextualWorldState.entries), { supportsImages: false });
|
|
1084
1082
|
const nativeMessages = buildNativeCompactionMessages(projectedHistory, {
|
|
1085
|
-
focus: compactFocus
|
|
1086
|
-
highDensityCompaction: selectedModel.highDensityCompaction
|
|
1083
|
+
focus: compactFocus
|
|
1087
1084
|
});
|
|
1088
|
-
const compactOverheadTokens = estimatedRequestTokens(compactSystemPrompt, buildCompactionMessages(''
|
|
1085
|
+
const compactOverheadTokens = estimatedRequestTokens(compactSystemPrompt, buildCompactionMessages(''), executionTools);
|
|
1089
1086
|
const compactInputTokens = selectedModel.contextWindowTokens - compactOverheadTokens;
|
|
1090
1087
|
if (compactInputTokens <= 0)
|
|
1091
1088
|
throw new MarAgentError('MAR_AGENT_CONTEXT_LIMIT', 'Compaction prompt exceeds the selected model context window.');
|
|
1092
1089
|
const fallbackMessages = () => buildCompactionMessages(buildCompactionInput(compactHistory, {
|
|
1093
1090
|
focus: compactFocus,
|
|
1094
1091
|
maxTokens: compactInputTokens
|
|
1095
|
-
})
|
|
1092
|
+
}));
|
|
1096
1093
|
const useNative = shouldUseNativeCompaction({
|
|
1097
1094
|
estimatedRequestTokens: estimatedRequestTokens(compactSystemPrompt, nativeMessages, executionTools),
|
|
1098
1095
|
contextWindowTokens: selectedModel.contextWindowTokens,
|
|
@@ -1138,10 +1135,9 @@ export function createSessionOpener(services) {
|
|
|
1138
1135
|
const compactSystemPrompt = await operation((call) => coreExtensions.compose(promptComposition(executionTools, 'run'), call));
|
|
1139
1136
|
const projectedHistory = normalizeMessagesForModel(insertContextualWorldState(compactHistory, contextualWorldState.entries), { supportsImages: false });
|
|
1140
1137
|
const nativeCompactMessages = buildNativeCompactionMessages(projectedHistory, {
|
|
1141
|
-
...(input.focus === undefined ? {} : { focus: input.focus })
|
|
1142
|
-
highDensityCompaction: selectedModel.highDensityCompaction
|
|
1138
|
+
...(input.focus === undefined ? {} : { focus: input.focus })
|
|
1143
1139
|
});
|
|
1144
|
-
const compactOverheadTokens = estimatedRequestTokens(compactSystemPrompt, buildCompactionMessages(''
|
|
1140
|
+
const compactOverheadTokens = estimatedRequestTokens(compactSystemPrompt, buildCompactionMessages(''), executionTools);
|
|
1145
1141
|
const compactInputTokens = Math.max(0, selectedModel.contextWindowTokens - compactOverheadTokens);
|
|
1146
1142
|
let usingNativeMessages = shouldUseNativeCompaction({
|
|
1147
1143
|
estimatedRequestTokens: estimatedRequestTokens(compactSystemPrompt, nativeCompactMessages, executionTools),
|
|
@@ -1153,7 +1149,7 @@ export function createSessionOpener(services) {
|
|
|
1153
1149
|
const fallbackMessages = () => buildCompactionMessages(buildCompactionInput(compactHistory, {
|
|
1154
1150
|
...(input.focus === undefined ? {} : { focus: input.focus }),
|
|
1155
1151
|
maxTokens: Math.max(1, compactInputTokens)
|
|
1156
|
-
})
|
|
1152
|
+
}));
|
|
1157
1153
|
let compactMessages = usingNativeMessages
|
|
1158
1154
|
? nativeCompactMessages
|
|
1159
1155
|
: fallbackMessages();
|
|
@@ -31,7 +31,9 @@ export const agentStartToolDefinition = {
|
|
|
31
31
|
export function agentStartToolDefinitionWithModels(models) {
|
|
32
32
|
if (models.length === 0)
|
|
33
33
|
return agentStartToolDefinition;
|
|
34
|
-
const modelLines = models
|
|
34
|
+
const modelLines = [...models]
|
|
35
|
+
.sort((left, right) => (left.id < right.id ? -1 : left.id > right.id ? 1 : 0))
|
|
36
|
+
.map((model) => {
|
|
35
37
|
const efforts = model.reasoningEfforts.length === 0
|
|
36
38
|
? ''
|
|
37
39
|
: `; reasoning efforts: ${model.reasoningEfforts.join(', ')}`;
|
|
@@ -7,6 +7,7 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
|
7
7
|
import { MarAgentError, describeMarAgentError } from '../../error.js';
|
|
8
8
|
import { directLocalProcessExecutor, signalProcessTree } from '../../host/local-process-executor.js';
|
|
9
9
|
import { allowsDirectTool, allowsToolCaller } from '../callers.js';
|
|
10
|
+
import { orderToolDefinitions, stableToolSchema, stableToolDefinition } from '../definition-projection.js';
|
|
10
11
|
import { CodeCells } from './cells.js';
|
|
11
12
|
import { newObservationId, renderObservations } from './observations.js';
|
|
12
13
|
import { parseCodeModeStateMutations } from './state.js';
|
|
@@ -100,16 +101,18 @@ export const codeExecWaitToolDefinition = {
|
|
|
100
101
|
/** Deferred definitions travel in search results, not in the stable Code Mode description. */
|
|
101
102
|
export function projectCodeModeTools(tools, residentTools = tools) {
|
|
102
103
|
const codeModeEnabled = tools.some((tool) => tool.name === 'code_exec' && allowsToolCaller(tool, 'direct'));
|
|
103
|
-
const direct = tools
|
|
104
|
+
const direct = tools
|
|
105
|
+
.filter((tool) => allowsDirectTool(tool, codeModeEnabled))
|
|
106
|
+
.map(stableToolDefinition);
|
|
104
107
|
if (!codeModeEnabled)
|
|
105
108
|
return direct;
|
|
106
|
-
const programmatic = residentTools.filter((tool) => allowsToolCaller(tool, 'programmatic'));
|
|
109
|
+
const programmatic = orderToolDefinitions(residentTools.filter((tool) => allowsToolCaller(tool, 'programmatic')));
|
|
107
110
|
const directory = JSON.stringify({
|
|
108
111
|
callableNames: programmatic.map((tool) => tool.name),
|
|
109
112
|
programmaticOnly: programmatic.map((tool) => ({
|
|
110
113
|
name: tool.name,
|
|
111
114
|
description: tool.description,
|
|
112
|
-
inputSchema: tool.inputSchema,
|
|
115
|
+
inputSchema: stableToolSchema(tool.inputSchema),
|
|
113
116
|
inputMode: tool.inputMode ?? 'json'
|
|
114
117
|
}))
|
|
115
118
|
});
|
|
@@ -129,14 +132,16 @@ export function projectCodeModeSearchResult(message, codeModeEnabled) {
|
|
|
129
132
|
if (!codeModeEnabled)
|
|
130
133
|
return {
|
|
131
134
|
...message,
|
|
132
|
-
toolSearchTools: message.toolSearchTools
|
|
135
|
+
toolSearchTools: message.toolSearchTools
|
|
136
|
+
.filter((tool) => allowsToolCaller(tool, 'direct'))
|
|
137
|
+
.map(stableToolDefinition)
|
|
133
138
|
};
|
|
134
139
|
const tools = message.toolSearchTools.map((tool) => ({
|
|
135
140
|
name: tool.name,
|
|
136
141
|
description: allowsToolCaller(tool, 'programmatic')
|
|
137
142
|
? `Call only as tools.${tool.name} inside code_exec, never as a direct model tool.\n${tool.description}`
|
|
138
143
|
: tool.description,
|
|
139
|
-
inputSchema: tool.inputSchema,
|
|
144
|
+
inputSchema: stableToolSchema(tool.inputSchema),
|
|
140
145
|
inputMode: tool.inputMode ?? 'json',
|
|
141
146
|
caller: allowsToolCaller(tool, 'programmatic') ? 'programmatic' : 'direct'
|
|
142
147
|
}));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ClientToolDefinition } from './contracts.js';
|
|
2
|
+
/** Stable model declarations, not a serializer for historical messages or tool results. */
|
|
3
|
+
export declare function stableToolSchema<T>(schema: T): T;
|
|
4
|
+
export declare function stableToolDefinition(definition: ClientToolDefinition): ClientToolDefinition;
|
|
5
|
+
export declare function orderToolDefinitions<T extends {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
}>(definitions: readonly T[]): T[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Stable model declarations, not a serializer for historical messages or tool results. */
|
|
2
|
+
export function stableToolSchema(schema) {
|
|
3
|
+
return stableSchemaValue(schema);
|
|
4
|
+
}
|
|
5
|
+
function stableSchemaValue(value) {
|
|
6
|
+
if (Array.isArray(value))
|
|
7
|
+
return value.map(stableSchemaValue);
|
|
8
|
+
if (value === null || typeof value !== 'object')
|
|
9
|
+
return value;
|
|
10
|
+
const prototype = Object.getPrototypeOf(value);
|
|
11
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
12
|
+
return value;
|
|
13
|
+
const fields = value;
|
|
14
|
+
return Object.fromEntries(Object.keys(fields)
|
|
15
|
+
.sort()
|
|
16
|
+
.map((key) => [key, stableSchemaValue(fields[key])]));
|
|
17
|
+
}
|
|
18
|
+
export function stableToolDefinition(definition) {
|
|
19
|
+
return {
|
|
20
|
+
...definition,
|
|
21
|
+
inputSchema: stableToolSchema(definition.inputSchema)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function orderToolDefinitions(definitions) {
|
|
25
|
+
return [...definitions].sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
|
|
26
|
+
}
|
|
@@ -2,6 +2,7 @@ import { MarAgentError } from '../../error.js';
|
|
|
2
2
|
import { countModelTokens } from '../../runtime/token-budget.js';
|
|
3
3
|
import { projectCodeModeSearchResult, projectCodeModeTools } from '../code-mode/index.js';
|
|
4
4
|
import { assertMcpToolCatalog } from './catalog.js';
|
|
5
|
+
import { orderToolDefinitions, stableToolDefinition } from '../definition-projection.js';
|
|
5
6
|
export const TOOL_SEARCH_LIMITS = Object.freeze({
|
|
6
7
|
defaultLimit: 5,
|
|
7
8
|
maximumLimit: 20,
|
|
@@ -65,7 +66,11 @@ export class DeferredMcpRegistry {
|
|
|
65
66
|
}
|
|
66
67
|
update(catalog, eligible, options = {}) {
|
|
67
68
|
assertMcpToolCatalog(catalog, options);
|
|
68
|
-
this.#catalog = {
|
|
69
|
+
this.#catalog = {
|
|
70
|
+
...catalog,
|
|
71
|
+
servers: [...catalog.servers].sort((left, right) => left.id < right.id ? -1 : left.id > right.id ? 1 : 0),
|
|
72
|
+
tools: catalog.tools.filter(eligible)
|
|
73
|
+
};
|
|
69
74
|
const validSession = new Set(this.#catalog.tools
|
|
70
75
|
.filter((tool) => tool.lifetime === 'session' && tool.exposure === 'deferred')
|
|
71
76
|
.map((tool) => tool.definition.name));
|
|
@@ -128,12 +133,12 @@ export class DeferredMcpRegistry {
|
|
|
128
133
|
});
|
|
129
134
|
}
|
|
130
135
|
projectDirect(base) {
|
|
131
|
-
return [
|
|
136
|
+
return orderToolDefinitions([
|
|
132
137
|
...base,
|
|
133
138
|
...this.#catalog.tools
|
|
134
139
|
.filter((tool) => tool.exposure === 'direct')
|
|
135
140
|
.map((tool) => tool.definition)
|
|
136
|
-
];
|
|
141
|
+
]).map(stableToolDefinition);
|
|
137
142
|
}
|
|
138
143
|
project(base, selection = this.#selected, executionSelection = this.#executionSelected) {
|
|
139
144
|
const deferred = new Map(this.#catalog.tools
|
|
@@ -145,7 +150,10 @@ export class DeferredMcpRegistry {
|
|
|
145
150
|
.map((name) => deferred.get(name))
|
|
146
151
|
.filter((tool) => tool?.lifetime === 'execution')
|
|
147
152
|
];
|
|
148
|
-
return [
|
|
153
|
+
return [
|
|
154
|
+
...this.projectDirect(base),
|
|
155
|
+
...active.map((tool) => stableToolDefinition(tool.definition))
|
|
156
|
+
];
|
|
149
157
|
}
|
|
150
158
|
search(query, limit) {
|
|
151
159
|
const exact = this.#catalog.tools.find((tool) => tool.definition.name === query);
|
package/dist/cli/main.js
CHANGED
|
@@ -20,7 +20,7 @@ Usage:
|
|
|
20
20
|
maragent run <prompt> [--reasoning-effort EFFORT] [--format text|json|stream-json] [--codex-auth-file PATH]
|
|
21
21
|
maragent resume [sessionId] [--reasoning-effort EFFORT] [--codex-auth-file PATH]
|
|
22
22
|
maragent sessions list|delete <sessionId>
|
|
23
|
-
maragent models list|add|edit|remove|test [id] [--default-reasoning-effort EFFORT] [--code-mode|--no-code-mode] [--
|
|
23
|
+
maragent models list|add|edit|remove|test [id] [--default-reasoning-effort EFFORT] [--code-mode|--no-code-mode] [--fast-mode|--no-fast-mode] [--codex-auth-file PATH]
|
|
24
24
|
`;
|
|
25
25
|
function takeOption(arguments_, name) {
|
|
26
26
|
const index = arguments_.indexOf(name);
|
|
@@ -63,6 +63,9 @@ async function readApiKey() {
|
|
|
63
63
|
return value.trim();
|
|
64
64
|
}
|
|
65
65
|
async function modelsCommand(home, arguments_, codexAuthFile) {
|
|
66
|
+
if (arguments_.includes('--high-density-compaction') ||
|
|
67
|
+
arguments_.includes('--no-high-density-compaction'))
|
|
68
|
+
throw new MarAgentError('MAR_AGENT_CLI_ARGUMENT_INVALID', 'High-density compaction is no longer a model option.');
|
|
66
69
|
if (arguments_.includes('--responses-encoding'))
|
|
67
70
|
throw new MarAgentError('MAR_AGENT_CLI_ARGUMENT_INVALID', 'Responses encoding is no longer configurable.');
|
|
68
71
|
const action = arguments_[1];
|
|
@@ -164,8 +167,8 @@ async function modelsCommand(home, arguments_, codexAuthFile) {
|
|
|
164
167
|
: required(existing?.apiKey?.reveal(), '--api-key-stdin'))
|
|
165
168
|
}),
|
|
166
169
|
modelId: required(option('--model', existing?.modelId), '--model'),
|
|
167
|
-
contextWindowTokens: integer('--context', existing?.contextWindowTokens ??
|
|
168
|
-
maxOutputTokens: integer('--max-output', existing?.maxOutputTokens ??
|
|
170
|
+
contextWindowTokens: integer('--context', existing?.contextWindowTokens ?? 256_000),
|
|
171
|
+
maxOutputTokens: integer('--max-output', existing?.maxOutputTokens ?? 32_000),
|
|
169
172
|
inputCapabilities: booleanFlag(arguments_, '--image', '--no-image', existing?.inputCapabilities.includes('IMAGE') ?? false)
|
|
170
173
|
? ['TEXT', 'IMAGE']
|
|
171
174
|
: ['TEXT'],
|
|
@@ -179,7 +182,6 @@ async function modelsCommand(home, arguments_, codexAuthFile) {
|
|
|
179
182
|
: parseReasoningEffort(defaultReasoningEffortOption, '--default-reasoning-effort'),
|
|
180
183
|
titleGeneration: existing?.titleGeneration ?? false,
|
|
181
184
|
codeMode: booleanFlag(arguments_, '--code-mode', '--no-code-mode', existing?.codeMode ?? false),
|
|
182
|
-
highDensityCompaction: booleanFlag(arguments_, '--high-density-compaction', '--no-high-density-compaction', existing?.highDensityCompaction ?? false),
|
|
183
185
|
...(credential === 'codex-auth-file' && fastMode ? { fastMode: true } : {}),
|
|
184
186
|
...(protocol === 'OPENAI_RESPONSES' && existing?.serviceTier !== undefined
|
|
185
187
|
? {
|