agentfootprint 9.0.0 → 9.2.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.
Files changed (107) hide show
  1. package/README.md +15 -0
  2. package/dist/core/Agent.js +344 -18
  3. package/dist/core/Agent.js.map +1 -1
  4. package/dist/core/LLMCall.js +17 -0
  5. package/dist/core/LLMCall.js.map +1 -1
  6. package/dist/core/RunnerBase.js +22 -6
  7. package/dist/core/RunnerBase.js.map +1 -1
  8. package/dist/core/agent/AgentBuilder.js +20 -0
  9. package/dist/core/agent/AgentBuilder.js.map +1 -1
  10. package/dist/core/conversation.js +139 -0
  11. package/dist/core/conversation.js.map +1 -0
  12. package/dist/core/runCheckpoint.js +60 -2
  13. package/dist/core/runCheckpoint.js.map +1 -1
  14. package/dist/embedders/index.js +112 -0
  15. package/dist/embedders/index.js.map +1 -1
  16. package/dist/esm/core/Agent.d.ts +218 -3
  17. package/dist/esm/core/Agent.js +345 -19
  18. package/dist/esm/core/Agent.js.map +1 -1
  19. package/dist/esm/core/LLMCall.d.ts +9 -0
  20. package/dist/esm/core/LLMCall.js +17 -0
  21. package/dist/esm/core/LLMCall.js.map +1 -1
  22. package/dist/esm/core/RunnerBase.d.ts +22 -6
  23. package/dist/esm/core/RunnerBase.js +22 -6
  24. package/dist/esm/core/RunnerBase.js.map +1 -1
  25. package/dist/esm/core/agent/AgentBuilder.d.ts +5 -0
  26. package/dist/esm/core/agent/AgentBuilder.js +20 -0
  27. package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
  28. package/dist/esm/core/agent/types.d.ts +45 -3
  29. package/dist/esm/core/conversation.d.ts +96 -0
  30. package/dist/esm/core/conversation.js +133 -0
  31. package/dist/esm/core/conversation.js.map +1 -0
  32. package/dist/esm/core/runCheckpoint.d.ts +85 -1
  33. package/dist/esm/core/runCheckpoint.js +57 -1
  34. package/dist/esm/core/runCheckpoint.js.map +1 -1
  35. package/dist/esm/embedders/index.d.ts +31 -0
  36. package/dist/esm/embedders/index.js +112 -0
  37. package/dist/esm/embedders/index.js.map +1 -1
  38. package/dist/esm/hosting/standingAgent.d.ts +6 -2
  39. package/dist/esm/hosting/standingAgent.js +36 -27
  40. package/dist/esm/hosting/standingAgent.js.map +1 -1
  41. package/dist/esm/index.d.ts +2 -1
  42. package/dist/esm/index.js +5 -1
  43. package/dist/esm/index.js.map +1 -1
  44. package/dist/esm/lib/rag/indexDocuments.d.ts +18 -0
  45. package/dist/esm/lib/rag/indexDocuments.js +29 -0
  46. package/dist/esm/lib/rag/indexDocuments.js.map +1 -1
  47. package/dist/esm/memory/embedding/inputCeiling.d.ts +98 -0
  48. package/dist/esm/memory/embedding/inputCeiling.js +53 -0
  49. package/dist/esm/memory/embedding/inputCeiling.js.map +1 -0
  50. package/dist/esm/memory/embedding/mockEmbedder.js +13 -0
  51. package/dist/esm/memory/embedding/mockEmbedder.js.map +1 -1
  52. package/dist/esm/memory/embedding/types.d.ts +32 -0
  53. package/dist/esm/rag/indexCorpus.d.ts +16 -2
  54. package/dist/esm/rag/indexCorpus.js +27 -3
  55. package/dist/esm/rag/indexCorpus.js.map +1 -1
  56. package/dist/esm/rag/splitters/index.d.ts +22 -0
  57. package/dist/esm/rag/splitters/index.js +22 -0
  58. package/dist/esm/rag/splitters/index.js.map +1 -1
  59. package/dist/esm/rag/types.d.ts +9 -0
  60. package/dist/hosting/standingAgent.js +36 -27
  61. package/dist/hosting/standingAgent.js.map +1 -1
  62. package/dist/index.js +9 -1
  63. package/dist/index.js.map +1 -1
  64. package/dist/lib/rag/indexDocuments.js +29 -0
  65. package/dist/lib/rag/indexDocuments.js.map +1 -1
  66. package/dist/memory/embedding/inputCeiling.js +58 -0
  67. package/dist/memory/embedding/inputCeiling.js.map +1 -0
  68. package/dist/memory/embedding/mockEmbedder.js +13 -0
  69. package/dist/memory/embedding/mockEmbedder.js.map +1 -1
  70. package/dist/rag/indexCorpus.js +27 -3
  71. package/dist/rag/indexCorpus.js.map +1 -1
  72. package/dist/rag/splitters/index.js +22 -0
  73. package/dist/rag/splitters/index.js.map +1 -1
  74. package/dist/types/core/Agent.d.ts +218 -3
  75. package/dist/types/core/Agent.d.ts.map +1 -1
  76. package/dist/types/core/LLMCall.d.ts +9 -0
  77. package/dist/types/core/LLMCall.d.ts.map +1 -1
  78. package/dist/types/core/RunnerBase.d.ts +22 -6
  79. package/dist/types/core/RunnerBase.d.ts.map +1 -1
  80. package/dist/types/core/agent/AgentBuilder.d.ts +5 -0
  81. package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
  82. package/dist/types/core/agent/types.d.ts +45 -3
  83. package/dist/types/core/agent/types.d.ts.map +1 -1
  84. package/dist/types/core/conversation.d.ts +97 -0
  85. package/dist/types/core/conversation.d.ts.map +1 -0
  86. package/dist/types/core/runCheckpoint.d.ts +85 -1
  87. package/dist/types/core/runCheckpoint.d.ts.map +1 -1
  88. package/dist/types/embedders/index.d.ts +31 -0
  89. package/dist/types/embedders/index.d.ts.map +1 -1
  90. package/dist/types/hosting/standingAgent.d.ts +6 -2
  91. package/dist/types/hosting/standingAgent.d.ts.map +1 -1
  92. package/dist/types/index.d.ts +2 -1
  93. package/dist/types/index.d.ts.map +1 -1
  94. package/dist/types/lib/rag/indexDocuments.d.ts +18 -0
  95. package/dist/types/lib/rag/indexDocuments.d.ts.map +1 -1
  96. package/dist/types/memory/embedding/inputCeiling.d.ts +99 -0
  97. package/dist/types/memory/embedding/inputCeiling.d.ts.map +1 -0
  98. package/dist/types/memory/embedding/mockEmbedder.d.ts.map +1 -1
  99. package/dist/types/memory/embedding/types.d.ts +32 -0
  100. package/dist/types/memory/embedding/types.d.ts.map +1 -1
  101. package/dist/types/rag/indexCorpus.d.ts +16 -2
  102. package/dist/types/rag/indexCorpus.d.ts.map +1 -1
  103. package/dist/types/rag/splitters/index.d.ts +22 -0
  104. package/dist/types/rag/splitters/index.d.ts.map +1 -1
  105. package/dist/types/rag/types.d.ts +9 -0
  106. package/dist/types/rag/types.d.ts.map +1 -1
  107. package/package.json +1 -1
@@ -20,6 +20,8 @@ import { type RunnerPauseOutcome } from './pause.js';
20
20
  import type { WindowStrategy } from './agent/window/strategy.js';
21
21
  import { type CheckInBuilderOptions } from './checkin.js';
22
22
  import type { MemoryDefinition } from '../memory/define.types.js';
23
+ import type { MemoryIdentity } from '../memory/identity/types.js';
24
+ import type { SelfExplainBinding } from '../lib/trace-toolpack/selfExplain.js';
23
25
  import type { Injection, InjectionContext } from '../lib/injection-engine/types.js';
24
26
  import type { CursorMove, EntryScoring } from '../lib/injection-engine/skillGraph.js';
25
27
  import { type ResolvedOutputFallback } from './outputFallback.js';
@@ -55,6 +57,19 @@ export interface AgentRunOptions extends RunOptions {
55
57
  correlationId?: string;
56
58
  /** OTEL-style trace id — forwarded onto every emitted event's `EventMeta.traceId`. Falls back to `options.env?.traceId` when unset. */
57
59
  traceId?: string;
60
+ /**
61
+ * Who this run is for — the same tuple as `run({ identity })`, reachable
62
+ * from the doors whose input is a stored conversation rather than a
63
+ * message bag: `resumeOnError(checkpoint, { identity })` and
64
+ * `followUp(message, { identity })` (9.2.0).
65
+ *
66
+ * Before this existed, `resumeOnError` could not carry an identity at all,
67
+ * so every continued turn silently re-namespaced its memory under a fresh
68
+ * runId. Omitted, the conversation's own stored `identity` is used; given,
69
+ * it wins. On `run()` this is a second spelling of `run({ identity })` and
70
+ * the one on the input wins, since that is where the caller looked first.
71
+ */
72
+ identity?: MemoryIdentity;
58
73
  }
59
74
  export declare class Agent extends RunnerBase<AgentInput, AgentOutput> {
60
75
  readonly name: string;
@@ -245,6 +260,28 @@ export declare class Agent extends RunnerBase<AgentInput, AgentOutput> {
245
260
  * kept here rather than read back from the recording. Undefined after a run
246
261
  * that failed or paused. */
247
262
  private lastRunAnswer?;
263
+ /** The id the CONSUMER chose, or undefined when they took the default.
264
+ * `this.id` cannot answer that question — it is `'agent'` either way — and
265
+ * the stored-conversation fingerprint refuses only on ids somebody picked
266
+ * (see `AgentRunCheckpoint.agent`). */
267
+ private readonly explicitId?;
268
+ /** The identity the caller gave the last run, or undefined when they gave
269
+ * none. Only an EXPLICIT identity is carried onto `checkpoint()`: the
270
+ * default is derived from a runId, and storing that would pin a whole
271
+ * conversation to the id of the one run that started it. */
272
+ private lastRunIdentity?;
273
+ /** The run in flight, by id — the whole of the one-turn-at-a-time guard.
274
+ * Set before the executor is built and cleared in `finally`, so a run that
275
+ * throws does not leave the agent permanently refusing. */
276
+ private inFlightRunId?;
277
+ /** The question a person still owes this agent an answer to. Set when a run
278
+ * ends paused, cleared by `resume()`, `abandonPause()`, or a run that
279
+ * completes. Read by the `run()` guard — see `PendingQuestionError`. */
280
+ private pendingQuestion?;
281
+ /** The `.selfExplain()` binding, when the builder mounted one. Held so
282
+ * `canExplain()` can answer the same question the trace tools answer, from
283
+ * the same fact. Undefined on every agent that never called `.selfExplain()`. */
284
+ private selfExplainBinding?;
248
285
  /**
249
286
  * Optional `ToolProvider` set via the builder's `.toolProvider()`.
250
287
  * When present, the Tools slot subflow consults it per iteration
@@ -309,9 +346,17 @@ export declare class Agent extends RunnerBase<AgentInput, AgentOutput> {
309
346
  * prop) so consumers can scrub the execution timeline post-run without
310
347
  * threading a recorder through the call site.
311
348
  *
312
- * Returns `undefined` before the first run completes. Returns the
313
- * snapshot of the most recent run on every call after — including
314
- * across multiple turns of the same Agent instance.
349
+ * `undefined` until a run has STARTED. After that it is the most recent
350
+ * run's snapshot including across multiple turns of the same instance.
351
+ *
352
+ * **It is LIVE during a run, not a completed-runs-only view.** The executor
353
+ * is assigned at run start, so calling this from an event listener, a tool,
354
+ * or any other mid-run vantage point returns the IN-FLIGHT run, partially
355
+ * filled. That is deliberate (Lens scrubs a running agent through it), and
356
+ * it is why `.selfExplain()` captures at the terminal flush instead of
357
+ * resolving through this: evidence that is supposed to describe a FINISHED
358
+ * turn cannot be read from a getter that also answers about an unfinished
359
+ * one.
315
360
  */
316
361
  getLastSnapshot(): RuntimeSnapshot | undefined;
317
362
  /**
@@ -383,7 +428,112 @@ export declare class Agent extends RunnerBase<AgentInput, AgentOutput> {
383
428
  * pauses (use `run()` directly when pauses are expected).
384
429
  */
385
430
  runTyped<T = unknown>(input: AgentInput | string, options?: AgentRunOptions): Promise<T>;
431
+ /**
432
+ * Answer one turn.
433
+ *
434
+ * **`run()` is ONE turn, and it starts a new conversation every time.** The
435
+ * chart seeds its history from this call's `message` alone, so a second
436
+ * `run()` on the same agent does not continue the first: the model is shown
437
+ * one user message and will honestly tell your user it has not spoken to
438
+ * them before. That is deliberate — a primitive that quietly accumulated
439
+ * state across calls could never be used for one-shot work, and a hidden
440
+ * transcript is the most expensive thing an agent can carry.
441
+ *
442
+ * To continue a conversation, name it:
443
+ *
444
+ * - `agent.followUp(message)` — continue THIS agent's own last completed
445
+ * run. The one-liner, and what most callers want.
446
+ * - `run({ message, continueFrom })` — continue a conversation you are
447
+ * holding: `agent.checkpoint()` from an earlier turn, persisted anywhere
448
+ * and handed back. Works across a restart, a deploy, or a different
449
+ * machine, and is what `standingAgent` uses per session.
450
+ *
451
+ * Passing the same `identity.conversationId` to two `run()` calls does NOT
452
+ * continue anything — see {@link AgentInput.identity}. What a registered
453
+ * memory adds is *recall* of prior turns into the system-prompt slot, which
454
+ * is a different thing from the conversation itself.
455
+ *
456
+ * Two refusals guard the per-instance state this agent keeps; both replace
457
+ * behavior that used to succeed while quietly being wrong (9.2.0):
458
+ * {@link RunInFlightError} when a run is already in flight, and
459
+ * {@link PendingQuestionError} when the last run paused to ask a person
460
+ * something that nobody has answered.
461
+ *
462
+ * @example One turn, then a follow-up
463
+ * ```ts
464
+ * await agent.run({ message: 'Book me a table for two.' });
465
+ * await agent.followUp('Make it three.'); // remembers the table
466
+ * ```
467
+ */
386
468
  run(input: AgentInput | string, options?: AgentRunOptions): Promise<AgentOutput | RunnerPauseOutcome>;
469
+ /**
470
+ * Continue this agent's own last completed conversation.
471
+ *
472
+ * The one-liner for turn two and after. `run()` is one turn and starts a new
473
+ * conversation each time (see {@link Agent.run}); this reads the
474
+ * conversation off the last completed run, appends `message` as the next
475
+ * user turn, and runs from there — so the model sees what was actually said.
476
+ *
477
+ * Sugar over `run({ message, continueFrom: this.checkpoint() })` and nothing
478
+ * more: one restoration path, so the convenience cannot drift from the
479
+ * mechanism. Reach for `run({ continueFrom })` directly when the
480
+ * conversation comes from somewhere other than this instance's last run — a
481
+ * store, another process, a different machine.
482
+ *
483
+ * Refuses rather than guessing: {@link NoConversationError} when this agent
484
+ * has no completed run to continue (a "follow-up" that quietly became a
485
+ * first turn would be exactly the confusion this door exists to remove),
486
+ * and — through `run()` — {@link PendingQuestionError} when the last run
487
+ * paused to ask a person something, because a pause has its own door:
488
+ * `resume(checkpoint, decision)`.
489
+ *
490
+ * The conversation grows every turn and nothing here trims it; bounding what
491
+ * the model is shown is `.window()` / `.compaction()` / `.memory()`, not a
492
+ * silent cap on the way through.
493
+ *
494
+ * @example
495
+ * ```ts
496
+ * await agent.run({ message: 'Book me a table for two.' });
497
+ * await agent.followUp('Make it three.');
498
+ * await agent.followUp('And move it to 8pm.');
499
+ * ```
500
+ */
501
+ followUp(message: string, options?: AgentRunOptions): Promise<AgentOutput | RunnerPauseOutcome>;
502
+ /**
503
+ * Drop the question this agent's last run paused to ask, on the record.
504
+ *
505
+ * A paused run is waiting on a person. Sending a different message while one
506
+ * is outstanding is refused ({@link PendingQuestionError}) because silently
507
+ * discarding a pending question makes a consent gate something any later
508
+ * message can walk around. When the question really is being dropped —
509
+ * the user changed the subject, the session timed out, the approval is no
510
+ * longer wanted — say so with this, and the next `run()` proceeds.
511
+ *
512
+ * Returns what was dropped (`undefined` when nothing was pending), so a
513
+ * caller can log or audit the abandonment rather than perform it blind. It
514
+ * does not touch the paused run's checkpoint: if you still hold that, it
515
+ * remains resumable.
516
+ */
517
+ abandonPause(): {
518
+ readonly toolName?: string;
519
+ readonly toolCallId?: string;
520
+ readonly question?: string;
521
+ } | undefined;
522
+ /**
523
+ * Whether {@link Agent.selfExplain}'s why-questions have a run to answer
524
+ * from right now.
525
+ *
526
+ * `false` for two different reasons, both honest: this agent was not built
527
+ * with `.selfExplain()`, or it was and no turn has completed yet (evidence
528
+ * binds at the END of a run, never to the one in flight). Either way there
529
+ * is nothing to explain, which is what a caller routing a why-question needs
530
+ * to know before it routes.
531
+ *
532
+ * The model is told the same thing by the same fact — the trace tools answer
533
+ * "No completed run is available yet" and the skill body says to say so
534
+ * plainly. This is that answer, for the program.
535
+ */
536
+ canExplain(): boolean;
387
537
  /**
388
538
  * Resume an agent run from a checkpoint produced by a prior
389
539
  * `RunCheckpointError`. Unlike `agent.resume()` (which takes a
@@ -429,6 +579,13 @@ export declare class Agent extends RunnerBase<AgentInput, AgentOutput> {
429
579
  * ```
430
580
  */
431
581
  resumeOnError(checkpoint: AgentRunCheckpoint | unknown, options?: AgentRunOptions): Promise<AgentOutput | RunnerPauseOutcome>;
582
+ /**
583
+ * Which identity a continued turn runs under: the caller's if they named
584
+ * one, otherwise the conversation's own.
585
+ *
586
+ * @internal
587
+ */
588
+ private identityFor;
432
589
  /**
433
590
  * Install a per-run checkpoint tracker. Listens for the agent's
434
591
  * own iteration_end events on `this.dispatcher` and snapshots the
@@ -493,6 +650,64 @@ export declare class Agent extends RunnerBase<AgentInput, AgentOutput> {
493
650
  * @internal
494
651
  */
495
652
  private foldedSpansOf;
653
+ /**
654
+ * The two owner facts every conversation carrier stamps — who the run was
655
+ * for, and which agent ran it (9.2.0).
656
+ *
657
+ * One reader for `checkpoint()` and the crash checkpoint, the same rule
658
+ * `foldedSpansOf` follows: a fact kept on one carrier and lost on the other
659
+ * is worse than a fact kept on neither. Both are absent unless the caller
660
+ * chose them, which is what keeps the fingerprint refusal narrow and the
661
+ * default `conversationId` out of storage.
662
+ *
663
+ * @internal
664
+ */
665
+ private conversationOwner;
666
+ /**
667
+ * Restore a stored conversation onto the side channel `seed` reads.
668
+ *
669
+ * THE one restoration path — `run({ continueFrom })` and `resumeOnError()`
670
+ * both come through here, so the conversation door and the error door cannot
671
+ * disagree about what continuing means. It checks the agent fingerprint,
672
+ * restores history + folded spans, and adopts the conversation's identity so
673
+ * the continued turn writes its memory where the earlier turns are.
674
+ *
675
+ * `appendMessage` is the difference between the two callers, and it is the
676
+ * whole difference. Continuing a conversation ADDS this turn's user message
677
+ * to the stored history; resuming after an error does NOT, because there the
678
+ * message is already the last user turn in that history and appending it
679
+ * would ask the same question twice.
680
+ *
681
+ * @internal
682
+ */
683
+ private applyContinuation;
684
+ /** One turn at a time — see `RunInFlightError`. @internal */
685
+ private assertNotRunning;
686
+ /** A person's unanswered question outranks a new message — see
687
+ * `PendingQuestionError`. @internal */
688
+ private assertNoPendingQuestion;
689
+ /**
690
+ * Remember (or forget) the question this run ended on.
691
+ *
692
+ * A paused outcome sets it; anything else clears it, because a run that
693
+ * reached an answer has no outstanding question by definition. Reads the
694
+ * same `pauseData` fields `standingAgent.describePause` reads — the tool
695
+ * name and question the dispatch loop stamped — and invents nothing.
696
+ *
697
+ * @internal
698
+ */
699
+ private recordPendingQuestion;
700
+ /**
701
+ * Hand the `.selfExplain()` binding to the agent that owns it.
702
+ *
703
+ * Called once by `AgentBuilder.build()`, immediately after `bindTo`. The
704
+ * binding stays the tool provider's to read; the Agent holds it only so
705
+ * `canExplain()` answers from the same fact the trace tools answer from,
706
+ * rather than from a second guess about whether a run has completed.
707
+ *
708
+ * @internal
709
+ */
710
+ bindSelfExplain(binding: SelfExplainBinding): void;
496
711
  /**
497
712
  * Refuse, at run start, any declared messages-slot role this provider
498
713
  * cannot carry inside its message list (7.21, D2).