agent.libx.js 0.87.2 → 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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as AgentOptions, H as Hooks, g as RunResult } from './Agent-WTkHB8RY.js';
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 RecordingHooks, f as RecordingLifecycle, T as ToolUse, h as ToolUseMeta, i as composeHooks, p as planMode } from './Agent-WTkHB8RY.js';
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 {
@@ -2553,6 +2577,12 @@ var AgentOptions = class {
2553
2577
  /** Opt-in: after a write-class tool runs, run `command` over the VFS and append any failure to the tool result.
2554
2578
  * `tools` defaults to ['Write','Edit','MultiEdit','ApplyEdits']. */
2555
2579
  autoTest;
2580
+ /** Provider-specific options forwarded to ai.chat() (e.g. cursor mcpServers, cwd). */
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;
2556
2586
  };
2557
2587
  var Agent = class _Agent {
2558
2588
  options;
@@ -2568,6 +2598,12 @@ var Agent = class _Agent {
2568
2598
  // the assembled system prompt from the last prepare()
2569
2599
  started = false;
2570
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
+ }
2571
2607
  /** Inject tools into a running agent (e.g. dynamically mounted MCP servers). Takes effect on the next turn. */
2572
2608
  addTools(tools) {
2573
2609
  this.activeTools.push(...tools);
@@ -2749,12 +2785,17 @@ var Agent = class _Agent {
2749
2785
  steps++;
2750
2786
  let res;
2751
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
+ };
2752
2793
  try {
2753
2794
  if (useStream) {
2754
- 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 });
2755
2796
  res = await this.consumeStream(r);
2756
2797
  } else {
2757
- 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 });
2758
2799
  res = r;
2759
2800
  }
2760
2801
  } catch (err) {
@@ -3581,6 +3622,7 @@ export {
3581
3622
  planMode,
3582
3623
  raceAttempts,
3583
3624
  readTool,
3625
+ reasoningToChatFragment,
3584
3626
  reflectOnRun,
3585
3627
  registerHeadlessCommands2 as registerHeadlessCommands,
3586
3628
  relevanceScore,