@genesislcap/ai-assistant 15.23.0 → 15.23.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.
Files changed (33) hide show
  1. package/dist/ai-assistant.api.json +269 -5
  2. package/dist/ai-assistant.d.ts +256 -31
  3. package/dist/chat-driver.cjs +125 -58
  4. package/dist/chat-driver.cjs.map +2 -2
  5. package/dist/chat-driver.mjs +125 -58
  6. package/dist/chat-driver.mjs.map +2 -2
  7. package/dist/custom-elements.json +125 -6
  8. package/dist/dts/components/ai-driver/ai-driver.d.ts +63 -0
  9. package/dist/dts/components/ai-driver/ai-driver.d.ts.map +1 -1
  10. package/dist/dts/components/chat-driver/chat-driver.d.ts +7 -0
  11. package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
  12. package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts +9 -1
  13. package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts.map +1 -1
  14. package/dist/dts/config/config.d.ts +53 -17
  15. package/dist/dts/config/config.d.ts.map +1 -1
  16. package/dist/dts/config/define-stateful-agent.d.ts +16 -1
  17. package/dist/dts/config/define-stateful-agent.d.ts.map +1 -1
  18. package/dist/dts/main/main.d.ts +102 -14
  19. package/dist/dts/main/main.d.ts.map +1 -1
  20. package/dist/dts/utils/context-tokens.d.ts +100 -43
  21. package/dist/dts/utils/context-tokens.d.ts.map +1 -1
  22. package/dist/dts/utils/history-transform.d.ts +7 -1
  23. package/dist/dts/utils/history-transform.d.ts.map +1 -1
  24. package/dist/dts/utils/resolve-context-budget.d.ts +8 -5
  25. package/dist/dts/utils/resolve-context-budget.d.ts.map +1 -1
  26. package/dist/esm/components/chat-driver/chat-driver.js +22 -2
  27. package/dist/esm/components/orchestrating-driver/orchestrating-driver.js +92 -0
  28. package/dist/esm/config/define-stateful-agent.js +1 -0
  29. package/dist/esm/main/main.js +170 -27
  30. package/dist/esm/utils/context-tokens.js +331 -106
  31. package/dist/esm/utils/history-transform.js +5 -5
  32. package/dist/esm/utils/resolve-context-budget.js +37 -7
  33. package/package.json +16 -16
@@ -2780,6 +2780,39 @@
2780
2780
  ],
2781
2781
  "name": "getCompactionPlan"
2782
2782
  },
2783
+ {
2784
+ "kind": "MethodSignature",
2785
+ "canonicalReference": "@genesislcap/ai-assistant!AiDriver#getContextReserve:member(1)",
2786
+ "docComment": "/**\n * Headroom the next turn could need, and which agent set that requirement (GENC-1582). `undefined` when no agent the turn could land on declares a `contextReserve`, which leaves the ambient default in force.\n *\n * The host cannot work this out for itself: it depends on the user pin, the flow-owner lock and the classifier's candidate set, none of which it can see. Reading the ACTIVE agent instead — which is what the gate did first — asks the wrong question, because the agent that last ran is not the agent about to run. Under automatic routing they are routinely different, and the turn that hands over is exactly the one that needs the room.\n *\n * Optional — only drivers that route implement it.\n */\n",
2787
+ "excerptTokens": [
2788
+ {
2789
+ "kind": "Content",
2790
+ "text": "getContextReserve?(): "
2791
+ },
2792
+ {
2793
+ "kind": "Reference",
2794
+ "text": "ContextReserveResolution",
2795
+ "canonicalReference": "@genesislcap/ai-assistant!~ContextReserveResolution:interface"
2796
+ },
2797
+ {
2798
+ "kind": "Content",
2799
+ "text": " | undefined"
2800
+ },
2801
+ {
2802
+ "kind": "Content",
2803
+ "text": ";"
2804
+ }
2805
+ ],
2806
+ "isOptional": true,
2807
+ "returnTypeTokenRange": {
2808
+ "startIndex": 1,
2809
+ "endIndex": 3
2810
+ },
2811
+ "releaseTag": "Beta",
2812
+ "overloadIndex": 1,
2813
+ "parameters": [],
2814
+ "name": "getContextReserve"
2815
+ },
2783
2816
  {
2784
2817
  "kind": "MethodSignature",
2785
2818
  "canonicalReference": "@genesislcap/ai-assistant!AiDriver#getExternalDiagnostics:member(1)",
@@ -2905,6 +2938,34 @@
2905
2938
  ],
2906
2939
  "name": "getInteractionContext"
2907
2940
  },
2941
+ {
2942
+ "kind": "MethodSignature",
2943
+ "canonicalReference": "@genesislcap/ai-assistant!AiDriver#getPreambleTokens:member(1)",
2944
+ "docComment": "/**\n * Token cost of the last request's preamble — system prompt, tool definitions and framed tail (GENC-1582). `undefined` before the first call of a turn.\n *\n * A live getter rather than a field stamped on each message, deliberately: every consumer wants the CURRENT preamble, never its history, and a message field would mean a type change in `@genesislcap/foundation-ai` plus churn in every persisted session for a value nobody reads twice.\n *\n * It exists because the preamble cannot be derived reliably. Inferring it as \"first measured prompt minus the messages it covered\" is accurate once and then goes stale, since each agent brings its own prompt and tool surface — and every attempt to compensate downstream ended up comparing stored characters against wire tokens. The driver is the only place that knows what it just sent.\n *\n * Optional — only drivers that build requests implement it.\n */\n",
2945
+ "excerptTokens": [
2946
+ {
2947
+ "kind": "Content",
2948
+ "text": "getPreambleTokens?(): "
2949
+ },
2950
+ {
2951
+ "kind": "Content",
2952
+ "text": "number | undefined"
2953
+ },
2954
+ {
2955
+ "kind": "Content",
2956
+ "text": ";"
2957
+ }
2958
+ ],
2959
+ "isOptional": true,
2960
+ "returnTypeTokenRange": {
2961
+ "startIndex": 1,
2962
+ "endIndex": 2
2963
+ },
2964
+ "releaseTag": "Beta",
2965
+ "overloadIndex": 1,
2966
+ "parameters": [],
2967
+ "name": "getPreambleTokens"
2968
+ },
2908
2969
  {
2909
2970
  "kind": "MethodSignature",
2910
2971
  "canonicalReference": "@genesislcap/ai-assistant!AiDriver#getRawHistory:member(1)",
@@ -5113,6 +5174,37 @@
5113
5174
  "isAbstract": false,
5114
5175
  "name": "getInteractionContext"
5115
5176
  },
5177
+ {
5178
+ "kind": "Method",
5179
+ "canonicalReference": "@genesislcap/ai-assistant!ChatDriver#getPreambleTokens:member(1)",
5180
+ "docComment": "/**\n * Token cost of the last request's preamble — system prompt, tool definitions and framed tail (GENC-1582). `undefined` before the first call of a turn.\n *\n * A live getter rather than a field stamped on each message, deliberately: every consumer wants the CURRENT preamble, never its history, and a message field would mean a type change in `@genesislcap/foundation-ai` plus churn in every persisted session for a value nobody reads twice.\n *\n * It exists because the preamble cannot be derived reliably. Inferring it as \"first measured prompt minus the messages it covered\" is accurate once and then goes stale, since each agent brings its own prompt and tool surface — and every attempt to compensate downstream ended up comparing stored characters against wire tokens. The driver is the only place that knows what it just sent.\n *\n * Optional — only drivers that build requests implement it.\n */\n",
5181
+ "excerptTokens": [
5182
+ {
5183
+ "kind": "Content",
5184
+ "text": "getPreambleTokens(): "
5185
+ },
5186
+ {
5187
+ "kind": "Content",
5188
+ "text": "number | undefined"
5189
+ },
5190
+ {
5191
+ "kind": "Content",
5192
+ "text": ";"
5193
+ }
5194
+ ],
5195
+ "isStatic": false,
5196
+ "returnTypeTokenRange": {
5197
+ "startIndex": 1,
5198
+ "endIndex": 2
5199
+ },
5200
+ "releaseTag": "Public",
5201
+ "isProtected": false,
5202
+ "overloadIndex": 1,
5203
+ "parameters": [],
5204
+ "isOptional": false,
5205
+ "isAbstract": false,
5206
+ "name": "getPreambleTokens"
5207
+ },
5116
5208
  {
5117
5209
  "kind": "Method",
5118
5210
  "canonicalReference": "@genesislcap/ai-assistant!ChatDriver#getRawHistory:member(1)",
@@ -6555,10 +6647,82 @@
6555
6647
  "endIndex": 7
6556
6648
  }
6557
6649
  },
6650
+ {
6651
+ "kind": "Interface",
6652
+ "canonicalReference": "@genesislcap/ai-assistant!ContextReserve:interface",
6653
+ "docComment": "/**\n * Context headroom an agent reserves for itself (GENC-1582).\n *\n * Two figures, because a turn has two costs and only one of them is permanent.\n *\n * @beta\n */\n",
6654
+ "excerptTokens": [
6655
+ {
6656
+ "kind": "Content",
6657
+ "text": "export interface ContextReserve "
6658
+ }
6659
+ ],
6660
+ "fileUrlPath": "src/config/config.ts",
6661
+ "releaseTag": "Beta",
6662
+ "name": "ContextReserve",
6663
+ "preserveMemberOrder": false,
6664
+ "members": [
6665
+ {
6666
+ "kind": "PropertySignature",
6667
+ "canonicalReference": "@genesislcap/ai-assistant!ContextReserve#tokens:member",
6668
+ "docComment": "/**\n * Tokens that must be free before one of this agent's turns may START — the agent's PEAK growth, not its lasting cost.\n *\n * The peak is the binding figure even for an agent that sheds most of it again: `condenseWhen` stubs a spent payload at the end of the turn, so the room has to be there while the turn is running, before any of that fires.\n */\n",
6669
+ "excerptTokens": [
6670
+ {
6671
+ "kind": "Content",
6672
+ "text": "tokens: "
6673
+ },
6674
+ {
6675
+ "kind": "Content",
6676
+ "text": "number"
6677
+ },
6678
+ {
6679
+ "kind": "Content",
6680
+ "text": ";"
6681
+ }
6682
+ ],
6683
+ "isReadonly": false,
6684
+ "isOptional": false,
6685
+ "releaseTag": "Beta",
6686
+ "name": "tokens",
6687
+ "propertyTypeTokenRange": {
6688
+ "startIndex": 1,
6689
+ "endIndex": 2
6690
+ }
6691
+ },
6692
+ {
6693
+ "kind": "PropertySignature",
6694
+ "canonicalReference": "@genesislcap/ai-assistant!ContextReserve#warnAheadTokens:member",
6695
+ "docComment": "/**\n * Extra tokens ABOVE {@link ContextReserve.tokens} at which the warning appears. Omit to fall back to `chatConfig.context.warnMultiplier`.\n *\n * The figure that belongs here is what one of this agent's turns costs PERMANENTLY — its growth measured after condensation, not at its peak. That makes the warning land exactly two turns before the block: at the warning line there is room for a full turn plus the residue it leaves, which is one turn, and then room for one more.\n *\n * It exists because the multiplier cannot express that. `warnMultiplier` scales the whole reserve, so an agent that peaks at 400k and keeps 30k gets a warning 800k below the window — a line every one of its turns crosses transiently and then clears, which is noise rather than a signal.\n */\n",
6696
+ "excerptTokens": [
6697
+ {
6698
+ "kind": "Content",
6699
+ "text": "warnAheadTokens?: "
6700
+ },
6701
+ {
6702
+ "kind": "Content",
6703
+ "text": "number"
6704
+ },
6705
+ {
6706
+ "kind": "Content",
6707
+ "text": ";"
6708
+ }
6709
+ ],
6710
+ "isReadonly": false,
6711
+ "isOptional": true,
6712
+ "releaseTag": "Beta",
6713
+ "name": "warnAheadTokens",
6714
+ "propertyTypeTokenRange": {
6715
+ "startIndex": 1,
6716
+ "endIndex": 2
6717
+ }
6718
+ }
6719
+ ],
6720
+ "extendsTokenRanges": []
6721
+ },
6558
6722
  {
6559
6723
  "kind": "TypeAlias",
6560
6724
  "canonicalReference": "@genesislcap/ai-assistant!ContextReserveInput:type",
6561
- "docComment": "/**\n * Context headroom an agent reserves for itself, in tokens.\n *\n * A plain number, unlike the value-or-resolver shape `provider` / `temperature` / `resumable` use. The resolver form was drafted for it and removed before release: the gate is recomputed from a synchronous getter with no turn context to resolve against, so no path could ever have invoked one. Accepting a type-correct option that is guaranteed to do nothing is worse than not offering it — a warning after the fact still leaves the configuration inert.\n *\n * It can widen to a resolver later without breaking a caller, since every existing `number` stays valid.\n *\n * @beta\n */\n",
6725
+ "docComment": "/**\n * Context headroom an agent reserves for itself: a token count, or a {@link ContextReserve} when the agent also wants to say where the warning goes.\n *\n * NOT the value-or-resolver shape `provider` / `temperature` / `resumable` use. The resolver form was drafted and removed before release: the gate is recomputed from a synchronous getter with no turn context to resolve against, so no path could ever have invoked one. Accepting a type-correct option guaranteed to do nothing is worse than not offering it.\n *\n * The object arm was added the way the plain form's docblock anticipated — additively, so every existing `number` stays valid and means what it did.\n *\n * @beta\n */\n",
6562
6726
  "excerptTokens": [
6563
6727
  {
6564
6728
  "kind": "Content",
@@ -6566,7 +6730,12 @@
6566
6730
  },
6567
6731
  {
6568
6732
  "kind": "Content",
6569
- "text": "number"
6733
+ "text": "number | "
6734
+ },
6735
+ {
6736
+ "kind": "Reference",
6737
+ "text": "ContextReserve",
6738
+ "canonicalReference": "@genesislcap/ai-assistant!ContextReserve:interface"
6570
6739
  },
6571
6740
  {
6572
6741
  "kind": "Content",
@@ -6578,7 +6747,7 @@
6578
6747
  "name": "ContextReserveInput",
6579
6748
  "typeTokenRange": {
6580
6749
  "startIndex": 1,
6581
- "endIndex": 2
6750
+ "endIndex": 3
6582
6751
  }
6583
6752
  },
6584
6753
  {
@@ -8855,7 +9024,7 @@
8855
9024
  {
8856
9025
  "kind": "Property",
8857
9026
  "canonicalReference": "@genesislcap/ai-assistant!FoundationAiAssistant#contextBudget:member",
8858
- "docComment": "/**\n * Context-headroom thresholds for the active model (GENC-1567) — the warning and block lines, plus the tail budget compaction aims at.\n *\n * The agent's own `contextReserve` is deliberately NOT folded in here. This is the AMBIENT budget, which protects any turn from any agent; a per-agent reserve is an additional, larger requirement checked when that agent takes ownership of a flow, where there is a turn context to resolve its function form against.\n *\n * Overhead is read off `messages` (the Redux mirror) rather than the driver's own history, which the compaction plan uses. That is safe rather than sloppy: `estimateSystemOverhead` only looks at messages BEFORE the first usage-bearing one, and the two lists agree completely that early — the drift between mirror and driver history is only ever at the tail.\n */\n",
9027
+ "docComment": "/**\n * Context-headroom thresholds for the active model (GENC-1567) — the warning and block lines, plus the tail budget compaction aims at.\n *\n * The per-agent `contextReserve` IS folded in, via the driver (GENC-1582). It used to be described here as a separate, later check made when an agent took ownership of a flow — but there is no such check, and by flow entry the send has already been allowed. Resolving it here, before the send, is what makes it a gate rather than a label.\n *\n * Overhead is read off `messages` (the Redux mirror) rather than the driver's own history, which the compaction plan uses. That is safe rather than sloppy: `estimateSystemOverhead` only looks at messages BEFORE the first usage-bearing one, and the two lists agree completely that early — the drift between mirror and driver history is only ever at the tail.\n */\n",
8859
9028
  "excerptTokens": [
8860
9029
  {
8861
9030
  "kind": "Content",
@@ -8886,7 +9055,7 @@
8886
9055
  {
8887
9056
  "kind": "Property",
8888
9057
  "canonicalReference": "@genesislcap/ai-assistant!FoundationAiAssistant#contextGate:member",
8889
- "docComment": "/**\n * How close this conversation is to the model's context window (GENC-1567).\n *\n * **Derived, never latched** — the opposite of {@link FoundationAiAssistant.blocked}. A budget wall stays set because nothing the user does fixes it; this clears itself the moment the conversation shrinks, which is precisely what the user is being asked to do. The two must not be conflated: `blocked` is also deliberately preserved across `resetSession`, and a context gate obviously must not survive starting a new chat.\n *\n * **A flow in progress is never blocked, only warned.** Machine state lives outside the transcript, so a stateful flow is not desynced by compaction — but the summary can still drop detail the flow's own prompt leans on, and blocking mid-journey would strand the user between a flow they cannot finish and a compaction that is a poor idea right there. Letting the flow complete and gating on the way out is the lesser harm; the headroom reserve exists so this is rare rather than routine.\n */\n",
9058
+ "docComment": "",
8890
9059
  "excerptTokens": [
8891
9060
  {
8892
9061
  "kind": "Content",
@@ -15622,6 +15791,42 @@
15622
15791
  "isAbstract": false,
15623
15792
  "name": "getCompactionPlan"
15624
15793
  },
15794
+ {
15795
+ "kind": "Method",
15796
+ "canonicalReference": "@genesislcap/ai-assistant!OrchestratingDriver#getContextReserve:member(1)",
15797
+ "docComment": "/**\n * Headroom the next turn could need, and which agent set that requirement (GENC-1582). `undefined` when no agent the turn could land on declares a `contextReserve`, which leaves the ambient default in force.\n *\n * The host cannot work this out for itself: it depends on the user pin, the flow-owner lock and the classifier's candidate set, none of which it can see. Reading the ACTIVE agent instead — which is what the gate did first — asks the wrong question, because the agent that last ran is not the agent about to run. Under automatic routing they are routinely different, and the turn that hands over is exactly the one that needs the room.\n *\n * Optional — only drivers that route implement it.\n */\n",
15798
+ "excerptTokens": [
15799
+ {
15800
+ "kind": "Content",
15801
+ "text": "getContextReserve(): "
15802
+ },
15803
+ {
15804
+ "kind": "Reference",
15805
+ "text": "ContextReserveResolution",
15806
+ "canonicalReference": "@genesislcap/ai-assistant!~ContextReserveResolution:interface"
15807
+ },
15808
+ {
15809
+ "kind": "Content",
15810
+ "text": " | undefined"
15811
+ },
15812
+ {
15813
+ "kind": "Content",
15814
+ "text": ";"
15815
+ }
15816
+ ],
15817
+ "isStatic": false,
15818
+ "returnTypeTokenRange": {
15819
+ "startIndex": 1,
15820
+ "endIndex": 3
15821
+ },
15822
+ "releaseTag": "Beta",
15823
+ "isProtected": false,
15824
+ "overloadIndex": 1,
15825
+ "parameters": [],
15826
+ "isOptional": false,
15827
+ "isAbstract": false,
15828
+ "name": "getContextReserve"
15829
+ },
15625
15830
  {
15626
15831
  "kind": "Method",
15627
15832
  "canonicalReference": "@genesislcap/ai-assistant!OrchestratingDriver#getExternalDiagnostics:member(1)",
@@ -15756,6 +15961,37 @@
15756
15961
  "isAbstract": false,
15757
15962
  "name": "getInteractionContext"
15758
15963
  },
15964
+ {
15965
+ "kind": "Method",
15966
+ "canonicalReference": "@genesislcap/ai-assistant!OrchestratingDriver#getPreambleTokens:member(1)",
15967
+ "docComment": "/**\n * Token cost of the last request's preamble — system prompt, tool definitions and framed tail (GENC-1582). `undefined` before the first call of a turn.\n *\n * A live getter rather than a field stamped on each message, deliberately: every consumer wants the CURRENT preamble, never its history, and a message field would mean a type change in `@genesislcap/foundation-ai` plus churn in every persisted session for a value nobody reads twice.\n *\n * It exists because the preamble cannot be derived reliably. Inferring it as \"first measured prompt minus the messages it covered\" is accurate once and then goes stale, since each agent brings its own prompt and tool surface — and every attempt to compensate downstream ended up comparing stored characters against wire tokens. The driver is the only place that knows what it just sent.\n *\n * Optional — only drivers that build requests implement it.\n */\n",
15968
+ "excerptTokens": [
15969
+ {
15970
+ "kind": "Content",
15971
+ "text": "getPreambleTokens(): "
15972
+ },
15973
+ {
15974
+ "kind": "Content",
15975
+ "text": "number | undefined"
15976
+ },
15977
+ {
15978
+ "kind": "Content",
15979
+ "text": ";"
15980
+ }
15981
+ ],
15982
+ "isStatic": false,
15983
+ "returnTypeTokenRange": {
15984
+ "startIndex": 1,
15985
+ "endIndex": 2
15986
+ },
15987
+ "releaseTag": "Beta",
15988
+ "isProtected": false,
15989
+ "overloadIndex": 1,
15990
+ "parameters": [],
15991
+ "isOptional": false,
15992
+ "isAbstract": false,
15993
+ "name": "getPreambleTokens"
15994
+ },
15759
15995
  {
15760
15996
  "kind": "Method",
15761
15997
  "canonicalReference": "@genesislcap/ai-assistant!OrchestratingDriver#getRawHistory:member(1)",
@@ -18631,6 +18867,34 @@
18631
18867
  "endIndex": 2
18632
18868
  }
18633
18869
  },
18870
+ {
18871
+ "kind": "PropertySignature",
18872
+ "canonicalReference": "@genesislcap/ai-assistant!StatefulAgentInit#contextReserve:member",
18873
+ "docComment": "/**\n * Tokens of context headroom to keep free for one of this agent's turns — see `AgentConfig.contextReserve`, which this is passed straight through to.\n *\n * The third member of the flow-safety group with {@link StatefulAgentInit.resumable} and {@link StatefulAgentInit.notResumableMessage}, and the one that was missing (GENC-1582): a stateful flow is the case the reserve was designed for — it is what runs the long tool loop — and yet the helper for building one could not express it. Both agents that needed it in the field are built here.\n *\n * Set it from measurement. Per-turn `inputTokens` is recorded for every call, so one real run of the flow gives you its peak growth; leaving it unset inherits the global default, which is the right starting position.\n */\n",
18874
+ "excerptTokens": [
18875
+ {
18876
+ "kind": "Content",
18877
+ "text": "contextReserve?: "
18878
+ },
18879
+ {
18880
+ "kind": "Reference",
18881
+ "text": "ContextReserveInput",
18882
+ "canonicalReference": "@genesislcap/ai-assistant!ContextReserveInput:type"
18883
+ },
18884
+ {
18885
+ "kind": "Content",
18886
+ "text": ";"
18887
+ }
18888
+ ],
18889
+ "isReadonly": false,
18890
+ "isOptional": true,
18891
+ "releaseTag": "Beta",
18892
+ "name": "contextReserve",
18893
+ "propertyTypeTokenRange": {
18894
+ "startIndex": 1,
18895
+ "endIndex": 2
18896
+ }
18897
+ },
18634
18898
  {
18635
18899
  "kind": "PropertySignature",
18636
18900
  "canonicalReference": "@genesislcap/ai-assistant!StatefulAgentInit#description:member",