toolnexus 0.9.5 → 0.10.0

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/src/client.ts CHANGED
@@ -155,10 +155,14 @@ export interface RunResult {
155
155
  usage: Usage
156
156
  /** The model used. */
157
157
  model: string
158
- /** "done" normally; "pending" iff a tool suspended and no waitFor was configured (§10). */
159
- status: "done" | "pending"
158
+ /** "done" normally; "pending" iff a tool suspended and no waitFor was configured (§10);
159
+ * "incomplete" iff a limit stopped the run loudly (§7D) — a maxTurns stop with no final
160
+ * text is never a silent "done". */
161
+ status: "done" | "pending" | "incomplete"
160
162
  /** The unresolved suspension — present iff status === "pending" (§10). */
161
163
  pending?: Request
164
+ /** The limit that stopped the run (e.g. "maxTurns") — present iff status === "incomplete". */
165
+ limit?: string
162
166
  }
163
167
 
164
168
  /** Events yielded by client.stream(). */
@@ -379,10 +383,11 @@ export class Client {
379
383
  this.opts.onMetric?.(ev)
380
384
  }
381
385
 
382
- /** Emit the terminal `run` metric event and build the RunResult. */
383
- private endRun(runStart: number, text: string, messages: any[], toolCalls: ToolCallRecord[], turns: number, usage: Usage): RunResult {
386
+ /** Emit the terminal `run` metric event and build the RunResult. `exhausted` marks a
387
+ * maxTurns loop exit — with no final text that is a LOUD "incomplete", never "done" (§7D). */
388
+ private endRun(runStart: number, text: string, messages: any[], toolCalls: ToolCallRecord[], turns: number, usage: Usage, exhausted = false): RunResult {
384
389
  this.emit({ event: "run", model: this.opts.model, turns, toolCalls: toolCalls.length, totalTokens: usage.totalTokens, ms: Date.now() - runStart })
385
- return this.result(text, messages, toolCalls, turns, usage)
390
+ return this.result(text, messages, toolCalls, turns, usage, exhausted)
386
391
  }
387
392
 
388
393
  /** Emit a `run` error metric event (once, on a thrown run). */
@@ -596,15 +601,18 @@ export class Client {
596
601
  if (s.halted) return this.pendingRun(runStart, s.halted, messages, toolCalls, turns, usage)
597
602
  }
598
603
  }
599
- return this.endRun(runStart, lastText(messages), messages, toolCalls, turns, usage)
604
+ return this.endRun(runStart, lastText(messages), messages, toolCalls, turns, usage, true)
600
605
  } catch (e) {
601
606
  this.emitRunError(runStart, toolCalls, turns, usage, e)
602
607
  throw e
603
608
  }
604
609
  }
605
610
 
606
- private result(text: string, messages: any[], toolCalls: ToolCallRecord[], turns: number, usage: Usage): RunResult {
607
- return { text, messages, toolCalls, toolCallCount: toolCalls.length, turns, usage, model: this.opts.model, status: "done" }
611
+ private result(text: string, messages: any[], toolCalls: ToolCallRecord[], turns: number, usage: Usage, exhausted = false): RunResult {
612
+ const incomplete = exhausted && text === ""
613
+ const r: RunResult = { text, messages, toolCalls, toolCallCount: toolCalls.length, turns, usage, model: this.opts.model, status: incomplete ? "incomplete" : "done" }
614
+ if (incomplete) r.limit = "maxTurns"
615
+ return r
608
616
  }
609
617
 
610
618
  /** §10: a run halted because a tool suspended and no `waitFor` was configured. */
@@ -702,7 +710,7 @@ export class Client {
702
710
  messages.push({ role: "user", content })
703
711
  if (halted) return this.pendingRun(runStart, halted, messages, toolCalls, turns, usage)
704
712
  }
705
- return this.endRun(runStart, "", messages, toolCalls, turns, usage)
713
+ return this.endRun(runStart, "", messages, toolCalls, turns, usage, true)
706
714
  } catch (e) {
707
715
  this.emitRunError(runStart, toolCalls, turns, usage, e)
708
716
  throw e
@@ -798,7 +806,7 @@ export class Client {
798
806
  yield { type: "tool_result", id: c.id, name: c.name, output: result.output, isError: result.isError }
799
807
  }
800
808
  }
801
- yield { type: "done", result: this.endRun(runStart, lastText(messages), messages, toolCalls, turns, usage) }
809
+ yield { type: "done", result: this.endRun(runStart, lastText(messages), messages, toolCalls, turns, usage, true) }
802
810
  } catch (e) {
803
811
  this.emitRunError(runStart, toolCalls, turns, usage, e)
804
812
  throw e
@@ -891,7 +899,7 @@ export class Client {
891
899
  }
892
900
  messages.push({ role: "user", content: results })
893
901
  }
894
- yield { type: "done", result: this.endRun(runStart, "", messages, toolCalls, turns, usage) }
902
+ yield { type: "done", result: this.endRun(runStart, "", messages, toolCalls, turns, usage, true) }
895
903
  } catch (e) {
896
904
  this.emitRunError(runStart, toolCalls, turns, usage, e)
897
905
  throw e
package/src/index.ts CHANGED
@@ -10,3 +10,4 @@ export * from "./mcpserve.js"
10
10
  export * from "./adapters.js"
11
11
  export * from "./toolkit.js"
12
12
  export * from "./client.js"
13
+ export * as agents from "./agents/index.js"