agent.libx.js 0.87.3 → 0.89.1
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-tfPQy4k5.d.ts → Agent-B0l9qT_j.d.ts} +35 -1
- package/dist/cli.d.ts +4 -1
- package/dist/cli.js +422 -20
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +42 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as AgentOptions, H as Hooks,
|
|
2
|
-
export { A as Agent, D as DEFAULT_MUTATING, b as Decision, P as PermissionOptions, c as PermissionPolicy, d as PermissionRule, e as PreToolUseDecision, R as
|
|
1
|
+
import { a as AgentOptions, H as Hooks, h as RunResult } from './Agent-B0l9qT_j.js';
|
|
2
|
+
export { A as Agent, C as ChatFragment, D as DEFAULT_MUTATING, b as Decision, P as PermissionOptions, c as PermissionPolicy, d as PermissionRule, e as PreToolUseDecision, R as ReasoningEffort, f as RecordingHooks, g as RecordingLifecycle, T as ToolUse, i as ToolUseMeta, j as composeHooks, p as planMode, r as reasoningToChatFragment } from './Agent-B0l9qT_j.js';
|
|
3
3
|
import { IFilesystem, FileMetadata } from '@livx.cc/wcli/core';
|
|
4
4
|
export { CommandExecutor, FileMetadata, IFilesystem, IndexedDbFilesystem, MemFilesystem, registerHeadlessCommands } from '@livx.cc/wcli/core';
|
|
5
5
|
import { BodDB } from '@bod.ee/db';
|
package/dist/index.js
CHANGED
|
@@ -2478,6 +2478,30 @@ function checkSyntax(path, content) {
|
|
|
2478
2478
|
}
|
|
2479
2479
|
}
|
|
2480
2480
|
|
|
2481
|
+
// src/reasoning.ts
|
|
2482
|
+
var BUDGET = { low: 2048, medium: 8192, high: 24576 };
|
|
2483
|
+
function toLabel(effort) {
|
|
2484
|
+
if (typeof effort !== "number") return effort === "off" ? "low" : effort;
|
|
2485
|
+
return effort <= BUDGET.low ? "low" : effort < BUDGET.high ? "medium" : "high";
|
|
2486
|
+
}
|
|
2487
|
+
function toBudget(effort) {
|
|
2488
|
+
return typeof effort === "number" ? effort : BUDGET[effort];
|
|
2489
|
+
}
|
|
2490
|
+
function reasoningToChatFragment(model, effort) {
|
|
2491
|
+
if (effort == null || effort === "off") return {};
|
|
2492
|
+
const provider = model.split("/")[0];
|
|
2493
|
+
switch (provider) {
|
|
2494
|
+
case "anthropic": {
|
|
2495
|
+
const budget = toBudget(effort);
|
|
2496
|
+
return { providerOptions: { thinking: { type: "enabled", budget_tokens: budget } }, maxTokens: budget + 8192 };
|
|
2497
|
+
}
|
|
2498
|
+
case "openai":
|
|
2499
|
+
return { providerOptions: { reasoning_effort: toLabel(effort) } };
|
|
2500
|
+
default:
|
|
2501
|
+
return {};
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2481
2505
|
// src/Agent.ts
|
|
2482
2506
|
var log3 = forComponent("Agent");
|
|
2483
2507
|
var AgentOptions = class {
|
|
@@ -2555,6 +2579,10 @@ var AgentOptions = class {
|
|
|
2555
2579
|
autoTest;
|
|
2556
2580
|
/** Provider-specific options forwarded to ai.chat() (e.g. cursor mcpServers, cwd). */
|
|
2557
2581
|
providerOptions;
|
|
2582
|
+
/** Extended-thinking / reasoning effort, normalized across providers (anthropic, openai).
|
|
2583
|
+
* `'off'`/undefined = none; `'low'|'medium'|'high'` or a raw token budget. Mapped to the
|
|
2584
|
+
* provider-specific request shape via {@link reasoningToChatFragment}; explicit `providerOptions` wins. */
|
|
2585
|
+
reasoning;
|
|
2558
2586
|
};
|
|
2559
2587
|
var Agent = class _Agent {
|
|
2560
2588
|
options;
|
|
@@ -2570,6 +2598,12 @@ var Agent = class _Agent {
|
|
|
2570
2598
|
// the assembled system prompt from the last prepare()
|
|
2571
2599
|
started = false;
|
|
2572
2600
|
// session-start lifecycle hook fires once per conversation
|
|
2601
|
+
/** Force the next `send()`/`run()` to rebuild the system prompt, tools, plan-mode and permission hooks
|
|
2602
|
+
* from `options` — apply mid-conversation changes to `planMode`/`permissions`/`model` etc. (prepare()
|
|
2603
|
+
* is otherwise memoized per conversation). */
|
|
2604
|
+
reprepare() {
|
|
2605
|
+
this.prepared = false;
|
|
2606
|
+
}
|
|
2573
2607
|
/** Inject tools into a running agent (e.g. dynamically mounted MCP servers). Takes effect on the next turn. */
|
|
2574
2608
|
addTools(tools) {
|
|
2575
2609
|
this.activeTools.push(...tools);
|
|
@@ -2751,12 +2785,17 @@ var Agent = class _Agent {
|
|
|
2751
2785
|
steps++;
|
|
2752
2786
|
let res;
|
|
2753
2787
|
const sent = this.trimContext();
|
|
2788
|
+
const frag = reasoningToChatFragment(o.model, o.reasoning);
|
|
2789
|
+
const reasonOpts = {
|
|
2790
|
+
...frag,
|
|
2791
|
+
...o.providerOptions ? { providerOptions: { ...frag.providerOptions, ...o.providerOptions } } : {}
|
|
2792
|
+
};
|
|
2754
2793
|
try {
|
|
2755
2794
|
if (useStream) {
|
|
2756
|
-
const r = await o.ai.chat({ model: o.model, messages: sent, tools: wireTools, stream: true, signal: o.signal,
|
|
2795
|
+
const r = await o.ai.chat({ model: o.model, messages: sent, tools: wireTools, stream: true, signal: o.signal, ...reasonOpts });
|
|
2757
2796
|
res = await this.consumeStream(r);
|
|
2758
2797
|
} else {
|
|
2759
|
-
const r = await o.ai.chat({ model: o.model, messages: sent, tools: wireTools, stream: false, signal: o.signal,
|
|
2798
|
+
const r = await o.ai.chat({ model: o.model, messages: sent, tools: wireTools, stream: false, signal: o.signal, ...reasonOpts });
|
|
2760
2799
|
res = r;
|
|
2761
2800
|
}
|
|
2762
2801
|
} catch (err) {
|
|
@@ -3583,6 +3622,7 @@ export {
|
|
|
3583
3622
|
planMode,
|
|
3584
3623
|
raceAttempts,
|
|
3585
3624
|
readTool,
|
|
3625
|
+
reasoningToChatFragment,
|
|
3586
3626
|
reflectOnRun,
|
|
3587
3627
|
registerHeadlessCommands2 as registerHeadlessCommands,
|
|
3588
3628
|
relevanceScore,
|