@mlx-node/agent 0.0.9 → 0.0.10
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.
|
@@ -30,5 +30,5 @@ export interface ResolvedReasoningMode {
|
|
|
30
30
|
* option was present.
|
|
31
31
|
*/
|
|
32
32
|
export declare function resolveReasoningMode(reasoning: ThinkingLevel | undefined): ResolvedReasoningMode;
|
|
33
|
-
export declare function buildChatConfig(modelType: ModelType, options: SimpleStreamOptions | undefined, tools: ToolDefinition[] | undefined, rootCacheOwnerId?: string, resolvedReasoning?: ResolvedReasoningMode): ChatConfig;
|
|
33
|
+
export declare function buildChatConfig(modelType: ModelType, options: SimpleStreamOptions | undefined, tools: ToolDefinition[] | undefined, rootCacheOwnerId?: string, resolvedReasoning?: ResolvedReasoningMode, modelMaxTokens?: unknown): ChatConfig;
|
|
34
34
|
//# sourceMappingURL=chat-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-config.d.ts","sourceRoot":"","sources":["../../src/provider/chat-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA0BrE;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,SAAS,GAAG,YAAY,GAAG,SAAS,CAE9E;AAgBD,MAAM,WAAW,qBAAqB;IACpC,eAAe,EAAE,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IACpD,8EAA8E;IAC9E,eAAe,EAAE,OAAO,CAAC;CAC1B;
|
|
1
|
+
{"version":3,"file":"chat-config.d.ts","sourceRoot":"","sources":["../../src/provider/chat-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA0BrE;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,SAAS,GAAG,YAAY,GAAG,SAAS,CAE9E;AAgBD,MAAM,WAAW,qBAAqB;IACpC,eAAe,EAAE,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IACpD,8EAA8E;IAC9E,eAAe,EAAE,OAAO,CAAC;CAC1B;AAMD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,aAAa,GAAG,SAAS,GAAG,qBAAqB,CAMhG;AAED,wBAAgB,eAAe,CAC7B,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,mBAAmB,GAAG,SAAS,EACxC,KAAK,EAAE,cAAc,EAAE,GAAG,SAAS,EACnC,gBAAgB,CAAC,EAAE,MAAM,EACzB,iBAAiB,wBAA2C,EAC5D,cAAc,CAAC,EAAE,OAAO,GACvB,UAAU,CAsCZ"}
|
|
@@ -54,6 +54,9 @@ const THINKING_LEVEL_TO_EFFORT = {
|
|
|
54
54
|
xhigh: 'high',
|
|
55
55
|
max: 'high',
|
|
56
56
|
};
|
|
57
|
+
function isPositiveSafeInteger(value) {
|
|
58
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value > 0;
|
|
59
|
+
}
|
|
57
60
|
/**
|
|
58
61
|
* Resolve Pi's thinking level once for both native config and persisted replay
|
|
59
62
|
* provenance. Keeping these values together prevents a low/minimal turn from
|
|
@@ -67,7 +70,7 @@ export function resolveReasoningMode(reasoning) {
|
|
|
67
70
|
thinkingEnabled: reasoningEffort === 'medium' || reasoningEffort === 'high',
|
|
68
71
|
};
|
|
69
72
|
}
|
|
70
|
-
export function buildChatConfig(modelType, options, tools, rootCacheOwnerId, resolvedReasoning = resolveReasoningMode(options?.reasoning)) {
|
|
73
|
+
export function buildChatConfig(modelType, options, tools, rootCacheOwnerId, resolvedReasoning = resolveReasoningMode(options?.reasoning), modelMaxTokens) {
|
|
71
74
|
const preset = launchPresetFor(modelType);
|
|
72
75
|
if (!preset) {
|
|
73
76
|
const known = [...new Set([...Object.keys(LAUNCH_PRESETS), ...Object.keys(AGENT_LAUNCH_PRESETS)])].join(', ');
|
|
@@ -92,8 +95,17 @@ export function buildChatConfig(modelType, options, tools, rootCacheOwnerId, res
|
|
|
92
95
|
// which branch the bounded GDN sidecar store protects from child eviction.
|
|
93
96
|
if (rootCacheOwnerId !== undefined)
|
|
94
97
|
config.cacheRootOwnerId = rootCacheOwnerId;
|
|
95
|
-
|
|
96
|
-
|
|
98
|
+
const explicitMaxTokens = options?.maxTokens;
|
|
99
|
+
if (isPositiveSafeInteger(explicitMaxTokens)) {
|
|
100
|
+
// A valid per-call provider option is the topmost layer.
|
|
101
|
+
config.maxNewTokens = explicitMaxTokens;
|
|
102
|
+
}
|
|
103
|
+
else if (isPositiveSafeInteger(modelMaxTokens)) {
|
|
104
|
+
// Normal Pi agent turns omit SimpleStreamOptions.maxTokens. Honor the
|
|
105
|
+
// composed Model metadata (including models.json modelOverrides) without
|
|
106
|
+
// allowing malformed/hostile metadata to replace the family preset.
|
|
107
|
+
config.maxNewTokens = modelMaxTokens;
|
|
108
|
+
}
|
|
97
109
|
if (options?.temperature !== undefined)
|
|
98
110
|
config.temperature = options.temperature;
|
|
99
111
|
if (tools && tools.length > 0)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-adapter.d.ts","sourceRoot":"","sources":["../../src/provider/stream-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,KAAK,EACV,GAAG,EACH,gB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AAE,WAAW,EAAE,kBAAkB,KAAK,IAAI,CAAC;AACvG,MAAM,MAAM,sBAAsB,GAAG,MAAM,MAAM,GAAG,SAAS,CAAC;AAC9D,qFAAqF;AACrF,MAAM,MAAM,uBAAuB,GAAG,MAAM,MAAM,GAAG,SAAS,CAAC;AAE/D;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iFAAiF;IACjF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,eAAe,CAAC;IACvB,sFAAsF;IACtF,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,8FAA8F;IAC9F,QAAQ,EAAE,OAAO,CAAC;CACnB,KAAK,IAAI,CAAC;AAwGX,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,gBAAgB,EACtB,aAAa,CAAC,EAAE,mBAAmB,EACnC,qBAAqB,CAAC,EAAE,sBAAsB,EAC9C,YAAY,CAAC,EAAE,YAAY,EAC3B,WAAW,CAAC,EAAE,MAAM,IAAI,EACxB,sBAAsB,CAAC,EAAE,uBAAuB,GAC/C,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,mBAAmB,KAAK,2BAA2B,CA6RrG"}
|
|
@@ -51,6 +51,16 @@ function safeString(read, fallback) {
|
|
|
51
51
|
return fallback;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
+
/** Read numeric model metadata without trusting a user-configurable getter. */
|
|
55
|
+
function readPositiveSafeInteger(read) {
|
|
56
|
+
try {
|
|
57
|
+
const value = read();
|
|
58
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value > 0 ? value : undefined;
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
54
64
|
/**
|
|
55
65
|
* Publish the native model's load-time physical context limit onto pi's shared
|
|
56
66
|
* model object. The parent session and every in-process subagent resolve this
|
|
@@ -62,13 +72,18 @@ function safeString(read, fallback) {
|
|
|
62
72
|
* discovery-time limit here, and never let metadata synchronization break an
|
|
63
73
|
* otherwise valid inference turn.
|
|
64
74
|
*/
|
|
65
|
-
function publishEffectiveContextWindow(model, session) {
|
|
75
|
+
function publishEffectiveContextWindow(model, session, configuredModelMaxTokens) {
|
|
66
76
|
try {
|
|
67
77
|
const effective = Math.floor(session.contextLimits()?.effectiveWindowTokens ?? 0);
|
|
68
78
|
if (!Number.isSafeInteger(effective) || effective <= 0)
|
|
69
79
|
return;
|
|
70
80
|
model.contextWindow = Math.min(model.contextWindow, effective);
|
|
71
|
-
|
|
81
|
+
// Use the already-validated snapshot. Reading the shared metadata here
|
|
82
|
+
// would let Math.min coerce invalid user configuration into a valid value
|
|
83
|
+
// that a later turn would then trust.
|
|
84
|
+
if (configuredModelMaxTokens !== undefined) {
|
|
85
|
+
model.maxTokens = Math.min(configuredModelMaxTokens, model.contextWindow);
|
|
86
|
+
}
|
|
72
87
|
}
|
|
73
88
|
catch {
|
|
74
89
|
// Exact native preflight still protects capacity; keep serving the turn.
|
|
@@ -272,7 +287,12 @@ export function makeMlxStreamSimple(host, onPerformance, resolveRootCacheOwner,
|
|
|
272
287
|
// Telemetry snapshot is best-effort; never break inference.
|
|
273
288
|
}
|
|
274
289
|
}
|
|
275
|
-
|
|
290
|
+
// Snapshot the composed budget before publishing native context limits.
|
|
291
|
+
// The advisory publisher must not read this raw value itself:
|
|
292
|
+
// Math.min can coerce hostile metadata (for example "512" or Infinity)
|
|
293
|
+
// into a finite number that a later turn would then trust.
|
|
294
|
+
const configuredModelMaxTokens = readPositiveSafeInteger(() => model.maxTokens);
|
|
295
|
+
publishEffectiveContextWindow(model, session, configuredModelMaxTokens);
|
|
276
296
|
const supportsImages = publishImageCapability(model, session);
|
|
277
297
|
const discovered = host.modelInfo(model.id);
|
|
278
298
|
if (!discovered) {
|
|
@@ -299,7 +319,7 @@ export function makeMlxStreamSimple(host, onPerformance, resolveRootCacheOwner,
|
|
|
299
319
|
return;
|
|
300
320
|
try {
|
|
301
321
|
session.primeHistory(contextToChatMessages(context, supportsImages));
|
|
302
|
-
const config = buildChatConfig(discovered.modelType, options, toolsToDefinitions(context.tools), rootCacheOwnerId, resolvedReasoning);
|
|
322
|
+
const config = buildChatConfig(discovered.modelType, options, toolsToDefinitions(context.tools), rootCacheOwnerId, resolvedReasoning, configuredModelMaxTokens);
|
|
303
323
|
for await (const event of session.startFromHistoryStream(config, signal)) {
|
|
304
324
|
if (event.done) {
|
|
305
325
|
if (event.finishReason === 'error') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlx-node/agent",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"homepage": "https://github.com/mlx-node/mlx-node",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/mlx-node/mlx-node/issues"
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@earendil-works/pi-ai": "0.81.1",
|
|
35
35
|
"@earendil-works/pi-coding-agent": "0.81.1",
|
|
36
|
-
"@mlx-node/core": "0.0.
|
|
37
|
-
"@mlx-node/lm": "0.0.
|
|
38
|
-
"@mlx-node/server": "0.0.
|
|
36
|
+
"@mlx-node/core": "0.0.10",
|
|
37
|
+
"@mlx-node/lm": "0.0.10",
|
|
38
|
+
"@mlx-node/server": "0.0.10",
|
|
39
39
|
"typebox": "1.3.6"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|