@memberjunction/ai-agents 6.2.0-edge.0 → 6.2.0-edge.2

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 (214) hide show
  1. package/README.md +43 -0
  2. package/dist/AgentDataPreloader.d.ts +4 -0
  3. package/dist/AgentDataPreloader.d.ts.map +1 -1
  4. package/dist/AgentDataPreloader.js +10 -2
  5. package/dist/AgentDataPreloader.js.map +1 -1
  6. package/dist/AgentDecisionService.d.ts +83 -0
  7. package/dist/AgentDecisionService.d.ts.map +1 -0
  8. package/dist/AgentDecisionService.js +155 -0
  9. package/dist/AgentDecisionService.js.map +1 -0
  10. package/dist/AgentRunner.d.ts +16 -4
  11. package/dist/AgentRunner.d.ts.map +1 -1
  12. package/dist/AgentRunner.js +55 -32
  13. package/dist/AgentRunner.js.map +1 -1
  14. package/dist/ArtifactToolManager.d.ts +4 -4
  15. package/dist/ArtifactToolManager.js +10 -10
  16. package/dist/ConversationToolManager.d.ts +16 -3
  17. package/dist/ConversationToolManager.d.ts.map +1 -1
  18. package/dist/ConversationToolManager.js +28 -5
  19. package/dist/ConversationToolManager.js.map +1 -1
  20. package/dist/KnowledgeAgent.d.ts.map +1 -1
  21. package/dist/KnowledgeAgent.js +6 -6
  22. package/dist/KnowledgeAgent.js.map +1 -1
  23. package/dist/PayloadChangeAnalyzer.d.ts +4 -0
  24. package/dist/PayloadChangeAnalyzer.d.ts.map +1 -1
  25. package/dist/PayloadChangeAnalyzer.js +10 -2
  26. package/dist/PayloadChangeAnalyzer.js.map +1 -1
  27. package/dist/PayloadFeedbackManager.d.ts +120 -13
  28. package/dist/PayloadFeedbackManager.d.ts.map +1 -1
  29. package/dist/PayloadFeedbackManager.js +244 -88
  30. package/dist/PayloadFeedbackManager.js.map +1 -1
  31. package/dist/PayloadManager.d.ts +27 -0
  32. package/dist/PayloadManager.d.ts.map +1 -1
  33. package/dist/PayloadManager.js +47 -15
  34. package/dist/PayloadManager.js.map +1 -1
  35. package/dist/agent-context-injector.d.ts +47 -3
  36. package/dist/agent-context-injector.d.ts.map +1 -1
  37. package/dist/agent-context-injector.js +77 -10
  38. package/dist/agent-context-injector.js.map +1 -1
  39. package/dist/agent-memory-context-builder.d.ts +13 -0
  40. package/dist/agent-memory-context-builder.d.ts.map +1 -1
  41. package/dist/agent-memory-context-builder.js +24 -5
  42. package/dist/agent-memory-context-builder.js.map +1 -1
  43. package/dist/agent-types/base-agent-type.d.ts +16 -0
  44. package/dist/agent-types/base-agent-type.d.ts.map +1 -1
  45. package/dist/agent-types/base-agent-type.js +20 -1
  46. package/dist/agent-types/base-agent-type.js.map +1 -1
  47. package/dist/agent-types/flow-agent-type.d.ts +106 -0
  48. package/dist/agent-types/flow-agent-type.d.ts.map +1 -1
  49. package/dist/agent-types/flow-agent-type.js +299 -29
  50. package/dist/agent-types/flow-agent-type.js.map +1 -1
  51. package/dist/agent-types/flow-graph-executor.d.ts +12 -1
  52. package/dist/agent-types/flow-graph-executor.d.ts.map +1 -1
  53. package/dist/agent-types/flow-graph-executor.js +25 -1
  54. package/dist/agent-types/flow-graph-executor.js.map +1 -1
  55. package/dist/agent-types/loop-agent-prompt-params.d.ts +258 -11
  56. package/dist/agent-types/loop-agent-prompt-params.d.ts.map +1 -1
  57. package/dist/agent-types/loop-agent-prompt-params.js +49 -2
  58. package/dist/agent-types/loop-agent-prompt-params.js.map +1 -1
  59. package/dist/agent-types/loop-agent-response-type.d.ts +12 -1
  60. package/dist/agent-types/loop-agent-response-type.d.ts.map +1 -1
  61. package/dist/agent-types/loop-agent-response-type.js.map +1 -1
  62. package/dist/agent-types/loop-agent-type.d.ts +6 -0
  63. package/dist/agent-types/loop-agent-type.d.ts.map +1 -1
  64. package/dist/agent-types/loop-agent-type.js +42 -3
  65. package/dist/agent-types/loop-agent-type.js.map +1 -1
  66. package/dist/artifact-target-plan.d.ts +2 -0
  67. package/dist/artifact-target-plan.d.ts.map +1 -1
  68. package/dist/artifact-target-plan.js +5 -1
  69. package/dist/artifact-target-plan.js.map +1 -1
  70. package/dist/base-agent.d.ts +886 -5
  71. package/dist/base-agent.d.ts.map +1 -1
  72. package/dist/base-agent.js +2567 -164
  73. package/dist/base-agent.js.map +1 -1
  74. package/dist/catalog-narrowing.d.ts +136 -0
  75. package/dist/catalog-narrowing.d.ts.map +1 -0
  76. package/dist/catalog-narrowing.js +212 -0
  77. package/dist/catalog-narrowing.js.map +1 -0
  78. package/dist/constants.d.ts +57 -0
  79. package/dist/constants.d.ts.map +1 -0
  80. package/dist/constants.js +70 -0
  81. package/dist/constants.js.map +1 -0
  82. package/dist/decision-discovery.d.ts +401 -0
  83. package/dist/decision-discovery.d.ts.map +1 -0
  84. package/dist/decision-discovery.js +511 -0
  85. package/dist/decision-discovery.js.map +1 -0
  86. package/dist/finish-if-mode-warnings.d.ts +39 -0
  87. package/dist/finish-if-mode-warnings.d.ts.map +1 -0
  88. package/dist/finish-if-mode-warnings.js +78 -0
  89. package/dist/finish-if-mode-warnings.js.map +1 -0
  90. package/dist/finish-if-state.d.ts +72 -0
  91. package/dist/finish-if-state.d.ts.map +1 -0
  92. package/dist/finish-if-state.js +109 -0
  93. package/dist/finish-if-state.js.map +1 -0
  94. package/dist/index.d.ts +9 -0
  95. package/dist/index.d.ts.map +1 -1
  96. package/dist/index.js +10 -0
  97. package/dist/index.js.map +1 -1
  98. package/dist/memory-manager-agent.d.ts +119 -13
  99. package/dist/memory-manager-agent.d.ts.map +1 -1
  100. package/dist/memory-manager-agent.js +237 -74
  101. package/dist/memory-manager-agent.js.map +1 -1
  102. package/dist/memory-note-gate.d.ts +208 -0
  103. package/dist/memory-note-gate.d.ts.map +1 -0
  104. package/dist/memory-note-gate.js +294 -0
  105. package/dist/memory-note-gate.js.map +1 -0
  106. package/dist/native-tools/action-tool-builder.d.ts +8 -0
  107. package/dist/native-tools/action-tool-builder.d.ts.map +1 -1
  108. package/dist/native-tools/action-tool-builder.js +22 -6
  109. package/dist/native-tools/action-tool-builder.js.map +1 -1
  110. package/dist/native-tools/control-tools.d.ts +8 -0
  111. package/dist/native-tools/control-tools.d.ts.map +1 -1
  112. package/dist/native-tools/control-tools.js +25 -9
  113. package/dist/native-tools/control-tools.js.map +1 -1
  114. package/dist/native-tools/dual-channel.d.ts +2 -0
  115. package/dist/native-tools/dual-channel.d.ts.map +1 -1
  116. package/dist/native-tools/dual-channel.js +5 -1
  117. package/dist/native-tools/dual-channel.js.map +1 -1
  118. package/dist/native-tools/tool-result-turns.d.ts +9 -0
  119. package/dist/native-tools/tool-result-turns.d.ts.map +1 -1
  120. package/dist/native-tools/tool-result-turns.js +15 -3
  121. package/dist/native-tools/tool-result-turns.js.map +1 -1
  122. package/dist/pipeline/coerce.d.ts +14 -0
  123. package/dist/pipeline/coerce.d.ts.map +1 -1
  124. package/dist/pipeline/coerce.js +37 -9
  125. package/dist/pipeline/coerce.js.map +1 -1
  126. package/dist/pipeline/jsonpath-eval.d.ts +4 -0
  127. package/dist/pipeline/jsonpath-eval.d.ts.map +1 -1
  128. package/dist/pipeline/jsonpath-eval.js +10 -2
  129. package/dist/pipeline/jsonpath-eval.js.map +1 -1
  130. package/dist/pipeline/operators.js +16 -16
  131. package/dist/pipeline/path.d.ts +6 -0
  132. package/dist/pipeline/path.d.ts.map +1 -1
  133. package/dist/pipeline/path.js +17 -5
  134. package/dist/pipeline/path.js.map +1 -1
  135. package/dist/pipeline/pipeline-executor.js +10 -10
  136. package/dist/pipeline/predicate.d.ts +4 -0
  137. package/dist/pipeline/predicate.d.ts.map +1 -1
  138. package/dist/pipeline/predicate.js +15 -7
  139. package/dist/pipeline/predicate.js.map +1 -1
  140. package/dist/pipeline/providers/action-provider.js +2 -2
  141. package/dist/pipeline/providers/artifact-tool-provider.js +2 -2
  142. package/dist/pipeline/providers/serialize.d.ts +4 -0
  143. package/dist/pipeline/providers/serialize.d.ts.map +1 -1
  144. package/dist/pipeline/providers/serialize.js +10 -2
  145. package/dist/pipeline/providers/serialize.js.map +1 -1
  146. package/dist/pipeline/template.d.ts +4 -0
  147. package/dist/pipeline/template.d.ts.map +1 -1
  148. package/dist/pipeline/template.js +15 -7
  149. package/dist/pipeline/template.js.map +1 -1
  150. package/dist/realtime/agent-media-library.d.ts +10 -0
  151. package/dist/realtime/agent-media-library.d.ts.map +1 -1
  152. package/dist/realtime/agent-media-library.js +29 -9
  153. package/dist/realtime/agent-media-library.js.map +1 -1
  154. package/dist/realtime/bridge-realtime-session-factory.d.ts +5 -2
  155. package/dist/realtime/bridge-realtime-session-factory.d.ts.map +1 -1
  156. package/dist/realtime/bridge-realtime-session-factory.js +7 -4
  157. package/dist/realtime/bridge-realtime-session-factory.js.map +1 -1
  158. package/dist/realtime/bridge-room-transcript-sink.d.ts.map +1 -1
  159. package/dist/realtime/bridge-room-transcript-sink.js +15 -9
  160. package/dist/realtime/bridge-room-transcript-sink.js.map +1 -1
  161. package/dist/realtime/media-channel-server.js +2 -2
  162. package/dist/realtime/meeting-controls-state.d.ts +2 -0
  163. package/dist/realtime/meeting-controls-state.d.ts.map +1 -1
  164. package/dist/realtime/meeting-controls-state.js +6 -2
  165. package/dist/realtime/meeting-controls-state.js.map +1 -1
  166. package/dist/realtime/realtime-channel-server-data-context.d.ts +2 -0
  167. package/dist/realtime/realtime-channel-server-data-context.d.ts.map +1 -1
  168. package/dist/realtime/realtime-channel-server-data-context.js +5 -1
  169. package/dist/realtime/realtime-channel-server-data-context.js.map +1 -1
  170. package/dist/realtime/realtime-channel-server-host.js +2 -2
  171. package/dist/realtime/realtime-client-session-service.d.ts +58 -12
  172. package/dist/realtime/realtime-client-session-service.d.ts.map +1 -1
  173. package/dist/realtime/realtime-client-session-service.js +91 -31
  174. package/dist/realtime/realtime-client-session-service.js.map +1 -1
  175. package/dist/realtime/realtime-coagent-config.d.ts +2 -0
  176. package/dist/realtime/realtime-coagent-config.d.ts.map +1 -1
  177. package/dist/realtime/realtime-coagent-config.js +6 -2
  178. package/dist/realtime/realtime-coagent-config.js.map +1 -1
  179. package/dist/realtime/realtime-recording-store.d.ts +15 -0
  180. package/dist/realtime/realtime-recording-store.d.ts.map +1 -1
  181. package/dist/realtime/realtime-recording-store.js +31 -7
  182. package/dist/realtime/realtime-recording-store.js.map +1 -1
  183. package/dist/realtime/realtime-session-runner.d.ts +4 -4
  184. package/dist/realtime/realtime-session-runner.js +9 -9
  185. package/dist/realtime/realtime-session-runner.js.map +1 -1
  186. package/dist/realtime/realtime-vendor-resolution.d.ts +8 -3
  187. package/dist/realtime/realtime-vendor-resolution.d.ts.map +1 -1
  188. package/dist/realtime/realtime-vendor-resolution.js +3 -3
  189. package/dist/realtime/realtime-vendor-resolution.js.map +1 -1
  190. package/dist/rubric-evaluation-agent-runner.d.ts +2 -0
  191. package/dist/rubric-evaluation-agent-runner.d.ts.map +1 -0
  192. package/dist/rubric-evaluation-agent-runner.js +38 -0
  193. package/dist/rubric-evaluation-agent-runner.js.map +1 -0
  194. package/dist/runtime-state-fragment.d.ts +101 -0
  195. package/dist/runtime-state-fragment.d.ts.map +1 -0
  196. package/dist/runtime-state-fragment.js +173 -0
  197. package/dist/runtime-state-fragment.js.map +1 -0
  198. package/dist/self-check.d.ts +98 -0
  199. package/dist/self-check.d.ts.map +1 -0
  200. package/dist/self-check.js +74 -0
  201. package/dist/self-check.js.map +1 -0
  202. package/dist/types/payload-operations.d.ts +8 -0
  203. package/dist/types/payload-operations.d.ts.map +1 -1
  204. package/dist/types/payload-operations.js +21 -5
  205. package/dist/types/payload-operations.js.map +1 -1
  206. package/dist/utils/ConversationMessageResolver.d.ts +4 -0
  207. package/dist/utils/ConversationMessageResolver.d.ts.map +1 -1
  208. package/dist/utils/ConversationMessageResolver.js +10 -2
  209. package/dist/utils/ConversationMessageResolver.js.map +1 -1
  210. package/dist/volatile-child-prompt.d.ts +33 -0
  211. package/dist/volatile-child-prompt.d.ts.map +1 -0
  212. package/dist/volatile-child-prompt.js +76 -0
  213. package/dist/volatile-child-prompt.js.map +1 -0
  214. package/package.json +21 -18
@@ -0,0 +1,208 @@
1
+ /**
2
+ * @fileoverview Pure typed-decision gate module for extracted memory notes.
3
+ *
4
+ * Implements question generation, state projection, Platt calibration application,
5
+ * and note filtering for durable memory candidates.
6
+ *
7
+ * @module @memberjunction/ai-agents
8
+ */
9
+ import { type AIModelConfiguration, type DecisionAnswer, type LikelihoodQuestion, type PlattCalibration } from '@memberjunction/ai';
10
+ import { type DecisionAnsweringModel, type DecisionModelCalibration, type MJAIPromptEntityExtended } from '@memberjunction/ai-core-plus';
11
+ import type { MJAIModelVendorEntity, MJAIPromptModelEntity } from '@memberjunction/core-entities';
12
+ /**
13
+ * Standard instructions used for Likelihood questions evaluating candidate memory notes.
14
+ */
15
+ export declare const MEMORY_NOTE_QUESTION_INSTRUCTIONS = "This note is a correct, durable fact or preference about the user, their organization or how they want the agent to work, that is worth remembering in future conversations; it is not a one-off request, a guess, or a detail of this conversation only.";
16
+ /**
17
+ * Maximum character limit for a candidate note's content in the decision state.
18
+ */
19
+ export declare const MEMORY_NOTE_MAX_CONTENT_CHARS = 1000;
20
+ /**
21
+ * Maximum character limit for conversation excerpts in the decision state.
22
+ */
23
+ export declare const MEMORY_NOTE_MAX_EXCERPT_CHARS = 4000;
24
+ /**
25
+ * The least **calibrated** probability at which a candidate note is kept.
26
+ *
27
+ * Set from the memory-note gate measurement (plan Task 3.4, 2026-09-29): 60 synthetic conversations,
28
+ * 337 candidate notes labelled durable, ephemeral, wrong or speculative, two repeats. At a calibrated
29
+ * 0.6, Jev kept durable notes at 96.1% precision and 95.4% recall, and kept 6.2% of the
30
+ * conversation-only (ephemeral) notes. A proxy self-report scorer's `confidence >= 80` kept 40.0% of
31
+ * them at 85.3% precision and 98.7% recall. Neither kept a wrong note; the gate kept 3.4% of the
32
+ * speculative ones, the proxy none.
33
+ *
34
+ * **The baseline is a proxy, not today's Memory Manager.** Its self-reported confidence came from a
35
+ * separate scoring call with a four-band rubric (90-100 stated, 75-89 strongly implied, 50-74
36
+ * possible, below 50 skip). Production's `Memory Manager - Extract Notes` template has three bands
37
+ * (90-100, 80-89, below 80 skip), and skip rules the proxy doesn't have: one-time requests, matters
38
+ * resolved within the conversation, and task-scoped clarifications. Those rules drop exactly the
39
+ * ephemeral notes counted here before any confidence filter runs, so production probably keeps fewer
40
+ * than 40% of them. The gate's own figures stand; the comparison is against the proxy.
41
+ */
42
+ export declare const MEMORY_NOTE_MIN_PROBABILITY = 0.6;
43
+ /**
44
+ * Platt calibration of the memory-note Likelihood, each tied to the exact model it was fitted on (see
45
+ * `FindDecisionCalibration` in `@memberjunction/ai-core-plus`): the MJ decision model that answered
46
+ * (`ModelName`, from `modelInfo.modelName`) and the model its driver reports behind it
47
+ * (`ResolvedModel`, from `DecisionResult.ResolvedModel`). Fitted on the memory-note gate measurement:
48
+ * - **Jev** at its pinned `APIName`, `typesafe/jev-1.13-20260917`, which it reports back as the
49
+ * resolved model.
50
+ *
51
+ * Only models that beat the proxy self-report scorer (see {@link MEMORY_NOTE_MIN_PROBABILITY}) are
52
+ * listed. LLM Decision was measured and left out: at any threshold it kept more wrong and speculative
53
+ * notes than the proxy's `confidence >= 80` (at a calibrated 0.6, 11.5% of wrong notes). A batch answered by any other model, including Jev at another version,
54
+ * falls back to the self-reported confidence rule, as a failed decision does. Refit, and add the new
55
+ * pair, whenever a model, its version or the question changes.
56
+ */
57
+ export declare const MEMORY_NOTE_DECISION_CALIBRATION: readonly DecisionModelCalibration<PlattCalibration>[];
58
+ /**
59
+ * Shape of a candidate note evaluated by the decision gate.
60
+ */
61
+ export interface MemoryNoteCandidate {
62
+ readonly type: 'Preference' | 'Constraint' | 'Context' | 'Issue' | string;
63
+ readonly content: string;
64
+ readonly confidence?: number;
65
+ readonly scopeLevel?: 'global' | 'company' | 'user' | string;
66
+ readonly agentId?: string | null;
67
+ readonly userId?: string | null;
68
+ readonly companyId?: string | null;
69
+ /** The conversation the note was extracted from: the one it is judged against. */
70
+ readonly sourceConversationId?: string | null;
71
+ }
72
+ /** One turn of the conversation a note came from, as the gate's state quotes it. */
73
+ export interface MemoryNoteExcerptTurn {
74
+ readonly role: string;
75
+ readonly text: string;
76
+ }
77
+ /** A conversation candidate notes may have come from. */
78
+ export interface MemoryNoteConversation {
79
+ readonly ConversationId: string;
80
+ readonly Turns: ReadonlyArray<MemoryNoteExcerptTurn>;
81
+ }
82
+ /** The candidate notes of one conversation, with that conversation's excerpt: one decision state. */
83
+ export interface MemoryNoteConversationBatch<T extends MemoryNoteCandidate = MemoryNoteCandidate> {
84
+ readonly ConversationId: string;
85
+ readonly Excerpt: string;
86
+ readonly Notes: T[];
87
+ }
88
+ /** Candidate notes grouped by the conversation they came from. */
89
+ export interface MemoryNoteConversationGrouping<T extends MemoryNoteCandidate = MemoryNoteCandidate> {
90
+ /** One batch per conversation with notes, in the conversations' order; each keeps its notes' order. */
91
+ readonly Batches: MemoryNoteConversationBatch<T>[];
92
+ /** The notes whose conversation could not be told: they must not be judged against any. */
93
+ readonly Unattributed: T[];
94
+ }
95
+ /**
96
+ * Projection of a candidate note in the decision state payload.
97
+ */
98
+ export interface MemoryNoteStateItem {
99
+ readonly type: string;
100
+ readonly scope: string;
101
+ readonly content: string;
102
+ }
103
+ /**
104
+ * Decision state object sent with the decision prompt.
105
+ */
106
+ export type MemoryNoteDecisionState = {
107
+ readonly notes: Record<string, MemoryNoteStateItem>;
108
+ readonly conversationExcerpt?: string;
109
+ };
110
+ /**
111
+ * Individual evaluated note verdict.
112
+ */
113
+ export interface JudgedMemoryNote<T extends MemoryNoteCandidate = MemoryNoteCandidate> {
114
+ readonly Note: T;
115
+ readonly Key: string;
116
+ readonly RawProbability?: number;
117
+ readonly CalibratedProbability?: number;
118
+ readonly Kept: boolean;
119
+ readonly Reason: string;
120
+ }
121
+ /**
122
+ * Aggregate verdict for a batch of evaluated memory notes.
123
+ */
124
+ export interface MemoryNoteGateVerdict<T extends MemoryNoteCandidate = MemoryNoteCandidate> {
125
+ readonly KeptNotes: T[];
126
+ readonly JudgedNotes: JudgedMemoryNote<T>[];
127
+ /** The model that answered, as the decision result reported it. */
128
+ readonly AnsweredBy: DecisionAnsweringModel;
129
+ readonly Calibrated: boolean;
130
+ }
131
+ /**
132
+ * What {@link MemoryNotePromptQuestionCap} reads from the AI engine to resolve the question limit.
133
+ * `AIEngine.Instance` satisfies it.
134
+ */
135
+ export interface MemoryNoteEngineSource {
136
+ readonly Prompts: ReadonlyArray<Pick<MJAIPromptEntityExtended, 'ID' | 'Name'>>;
137
+ readonly PromptModels: ReadonlyArray<Pick<MJAIPromptModelEntity, 'PromptID' | 'ModelID' | 'VendorID' | 'Status'>>;
138
+ readonly ModelVendors: ReadonlyArray<Pick<MJAIModelVendorEntity, 'ID' | 'ModelID' | 'VendorID'>>;
139
+ GetEffectiveModelConfiguration(modelID: string, vendorModelVendorID?: string): Pick<AIModelConfiguration, 'Decision'> | null;
140
+ }
141
+ /**
142
+ * Builds likelihood questions for each candidate note, keyed n1, n2, etc.
143
+ *
144
+ * Each question quotes its own note. Question keys are labels for code, not instructions to the
145
+ * model, and a native decision driver (Jev) may answer each question separately against the state,
146
+ * so a question that only named its key would ask the same thing about every note. Measured: with
147
+ * the note left out of the question, Jev's answers were at chance (AUC 0.51).
148
+ *
149
+ * @param notes The candidate notes to build questions for.
150
+ */
151
+ export declare function BuildMemoryNoteQuestions(notes: ReadonlyArray<MemoryNoteCandidate>): Record<string, LikelihoodQuestion>;
152
+ /** One note's question: the durable-memory test, then the note itself, capped. */
153
+ export declare function MemoryNoteQuestionInstructions(note: MemoryNoteCandidate): string;
154
+ /**
155
+ * The conversation a batch of notes came from, as the gate's state quotes it: one `[role]: text`
156
+ * line per turn. The measurement rig wrote its corpus excerpts with this, one conversation per
157
+ * state, which is what the Platt fit and the threshold were set on; {@link BuildMemoryNoteState}
158
+ * caps it.
159
+ *
160
+ * @param turns The conversation's turns, in order.
161
+ */
162
+ export declare function FormatMemoryNoteExcerpt(turns: ReadonlyArray<MemoryNoteExcerptTurn>): string;
163
+ /**
164
+ * Groups candidate notes by the conversation they came from, so each note is judged against its own
165
+ * conversation, as the gate was measured: one conversation per decision state. A note whose
166
+ * `sourceConversationId` names none of the conversations belongs to the only conversation when there
167
+ * is one; with several, it is unattributed, and must not be judged against another conversation.
168
+ *
169
+ * @param notes The candidate notes.
170
+ * @param conversations The conversations they were extracted from.
171
+ */
172
+ export declare function GroupMemoryNotesByConversation<T extends MemoryNoteCandidate>(notes: ReadonlyArray<T>, conversations: ReadonlyArray<MemoryNoteConversation>): MemoryNoteConversationGrouping<T>;
173
+ /**
174
+ * Builds the state object for the decision prompt, capping content and excerpts.
175
+ *
176
+ * @param notes Candidate notes to project.
177
+ * @param sourceExcerpts Optional conversation thread context.
178
+ */
179
+ export declare function BuildMemoryNoteState(notes: ReadonlyArray<MemoryNoteCandidate>, sourceExcerpts?: string | Record<string, string> | readonly string[]): MemoryNoteDecisionState;
180
+ /**
181
+ * Evaluates decision answers against candidate notes using Platt calibration.
182
+ *
183
+ * The calibration is the one fitted on the exact model that answered (`FindDecisionCalibration`).
184
+ * An answer from any other model, including a calibrated model at another version, is uncalibrated
185
+ * and keeps nothing (fails safe toward writing no durable memory).
186
+ *
187
+ * @param answers The answers returned by the decision runner.
188
+ * @param notes The candidate notes evaluated.
189
+ * @param answeredBy The model that answered: the MJ decision model and the model its driver resolved.
190
+ * @param threshold The calibrated probability at which a note is kept (default: {@link MEMORY_NOTE_MIN_PROBABILITY}, 0.6).
191
+ * @param calibrations Optional calibration table override (defaults to {@link MEMORY_NOTE_DECISION_CALIBRATION}).
192
+ */
193
+ export declare function JudgeMemoryNotes<T extends MemoryNoteCandidate = MemoryNoteCandidate>(answers: Record<string, DecisionAnswer> | undefined, notes: ReadonlyArray<T>, answeredBy?: DecisionAnsweringModel, threshold?: number, calibrations?: readonly DecisionModelCalibration<PlattCalibration>[]): MemoryNoteGateVerdict<T>;
194
+ /**
195
+ * Looks up the prompt's configured MaxQuestionsPerCall limit from active PromptModels.
196
+ *
197
+ * @param engine AIEngine metadata source.
198
+ * @param promptName Name of the decision prompt (default: 'Default Decision').
199
+ */
200
+ export declare function MemoryNotePromptQuestionCap(engine: MemoryNoteEngineSource, promptName?: string): number | undefined;
201
+ /**
202
+ * Splits candidate notes into chunks not exceeding the specified chunk size.
203
+ *
204
+ * @param notes The notes to chunk.
205
+ * @param chunkSize Maximum number of notes per chunk.
206
+ */
207
+ export declare function ChunkMemoryNotes<T>(notes: ReadonlyArray<T>, chunkSize?: number): T[][];
208
+ //# sourceMappingURL=memory-note-gate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-note-gate.d.ts","sourceRoot":"","sources":["../src/memory-note-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAEH,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAGH,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAChC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAGlG;;GAEG;AACH,eAAO,MAAM,iCAAiC,8PACiN,CAAC;AAEhQ;;GAEG;AACH,eAAO,MAAM,6BAA6B,OAAO,CAAC;AAElD;;GAEG;AACH,eAAO,MAAM,6BAA6B,OAAO,CAAC;AAElD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gCAAgC,EAAE,SAAS,wBAAwB,CAAC,gBAAgB,CAAC,EAEhG,CAAC;AAEH;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;IAC1E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,C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wB,CAAC,gBAAgB,CAAC,EAAqC,GACvG,qBAAqB,CAAC,CAAC,CAAC,CAuB1B;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACvC,MAAM,EAAE,sBAAsB,EAC9B,UAAU,GAAE,MAA2B,GACxC,MAAM,GAAG,SAAS,CAmBpB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,CAStF"}
@@ -0,0 +1,294 @@
1
+ /**
2
+ * @fileoverview Pure typed-decision gate module for extracted memory notes.
3
+ *
4
+ * Implements question generation, state projection, Platt calibration application,
5
+ * and note filtering for durable memory candidates.
6
+ *
7
+ * @module @memberjunction/ai-agents
8
+ */
9
+ import { ApplyPlattCalibration } from '@memberjunction/ai';
10
+ import { DescribeAnsweringModel, FindDecisionCalibration } from '@memberjunction/ai-core-plus';
11
+ import { UUIDsEqual } from '@memberjunction/global';
12
+ /**
13
+ * Standard instructions used for Likelihood questions evaluating candidate memory notes.
14
+ */
15
+ export const MEMORY_NOTE_QUESTION_INSTRUCTIONS = 'This note is a correct, durable fact or preference about the user, their organization or how they want the agent to work, that is worth remembering in future conversations; it is not a one-off request, a guess, or a detail of this conversation only.';
16
+ /**
17
+ * Maximum character limit for a candidate note's content in the decision state.
18
+ */
19
+ export const MEMORY_NOTE_MAX_CONTENT_CHARS = 1000;
20
+ /**
21
+ * Maximum character limit for conversation excerpts in the decision state.
22
+ */
23
+ export const MEMORY_NOTE_MAX_EXCERPT_CHARS = 4000;
24
+ /**
25
+ * The least **calibrated** probability at which a candidate note is kept.
26
+ *
27
+ * Set from the memory-note gate measurement (plan Task 3.4, 2026-09-29): 60 synthetic conversations,
28
+ * 337 candidate notes labelled durable, ephemeral, wrong or speculative, two repeats. At a calibrated
29
+ * 0.6, Jev kept durable notes at 96.1% precision and 95.4% recall, and kept 6.2% of the
30
+ * conversation-only (ephemeral) notes. A proxy self-report scorer's `confidence >= 80` kept 40.0% of
31
+ * them at 85.3% precision and 98.7% recall. Neither kept a wrong note; the gate kept 3.4% of the
32
+ * speculative ones, the proxy none.
33
+ *
34
+ * **The baseline is a proxy, not today's Memory Manager.** Its self-reported confidence came from a
35
+ * separate scoring call with a four-band rubric (90-100 stated, 75-89 strongly implied, 50-74
36
+ * possible, below 50 skip). Production's `Memory Manager - Extract Notes` template has three bands
37
+ * (90-100, 80-89, below 80 skip), and skip rules the proxy doesn't have: one-time requests, matters
38
+ * resolved within the conversation, and task-scoped clarifications. Those rules drop exactly the
39
+ * ephemeral notes counted here before any confidence filter runs, so production probably keeps fewer
40
+ * than 40% of them. The gate's own figures stand; the comparison is against the proxy.
41
+ */
42
+ export const MEMORY_NOTE_MIN_PROBABILITY = 0.6;
43
+ /**
44
+ * Platt calibration of the memory-note Likelihood, each tied to the exact model it was fitted on (see
45
+ * `FindDecisionCalibration` in `@memberjunction/ai-core-plus`): the MJ decision model that answered
46
+ * (`ModelName`, from `modelInfo.modelName`) and the model its driver reports behind it
47
+ * (`ResolvedModel`, from `DecisionResult.ResolvedModel`). Fitted on the memory-note gate measurement:
48
+ * - **Jev** at its pinned `APIName`, `typesafe/jev-1.13-20260917`, which it reports back as the
49
+ * resolved model.
50
+ *
51
+ * Only models that beat the proxy self-report scorer (see {@link MEMORY_NOTE_MIN_PROBABILITY}) are
52
+ * listed. LLM Decision was measured and left out: at any threshold it kept more wrong and speculative
53
+ * notes than the proxy's `confidence >= 80` (at a calibrated 0.6, 11.5% of wrong notes). A batch answered by any other model, including Jev at another version,
54
+ * falls back to the self-reported confidence rule, as a failed decision does. Refit, and add the new
55
+ * pair, whenever a model, its version or the question changes.
56
+ */
57
+ export const MEMORY_NOTE_DECISION_CALIBRATION = Object.freeze([
58
+ Object.freeze({ ModelName: 'Jev', ResolvedModel: 'typesafe/jev-1.13-20260917', Calibration: Object.freeze({ A: 3.6391, B: -5.7059 }) })
59
+ ]);
60
+ /**
61
+ * Builds likelihood questions for each candidate note, keyed n1, n2, etc.
62
+ *
63
+ * Each question quotes its own note. Question keys are labels for code, not instructions to the
64
+ * model, and a native decision driver (Jev) may answer each question separately against the state,
65
+ * so a question that only named its key would ask the same thing about every note. Measured: with
66
+ * the note left out of the question, Jev's answers were at chance (AUC 0.51).
67
+ *
68
+ * @param notes The candidate notes to build questions for.
69
+ */
70
+ export function BuildMemoryNoteQuestions(notes) {
71
+ const questions = {};
72
+ for (let i = 0; i < notes.length; i++) {
73
+ questions[`n${i + 1}`] = {
74
+ Kind: 'Likelihood',
75
+ Instructions: MemoryNoteQuestionInstructions(notes[i])
76
+ };
77
+ }
78
+ return questions;
79
+ }
80
+ /** One note's question: the durable-memory test, then the note itself, capped. */
81
+ export function MemoryNoteQuestionInstructions(note) {
82
+ const content = (note.content ?? '').slice(0, MEMORY_NOTE_MAX_CONTENT_CHARS);
83
+ return `${MEMORY_NOTE_QUESTION_INSTRUCTIONS}\n\nThe note (${note.type}, ${note.scopeLevel ?? 'user'} scope): "${content}"`;
84
+ }
85
+ /**
86
+ * The conversation a batch of notes came from, as the gate's state quotes it: one `[role]: text`
87
+ * line per turn. The measurement rig wrote its corpus excerpts with this, one conversation per
88
+ * state, which is what the Platt fit and the threshold were set on; {@link BuildMemoryNoteState}
89
+ * caps it.
90
+ *
91
+ * @param turns The conversation's turns, in order.
92
+ */
93
+ export function FormatMemoryNoteExcerpt(turns) {
94
+ return turns.map(turn => `[${turn.role}]: ${turn.text}`).join('\n');
95
+ }
96
+ /** The conversation a note names, compared as UUIDs, or null when it names none of them. */
97
+ function conversationOf(note, conversations) {
98
+ const source = note.sourceConversationId;
99
+ return source ? conversations.find(c => UUIDsEqual(c.ConversationId, source)) ?? null : null;
100
+ }
101
+ /**
102
+ * Groups candidate notes by the conversation they came from, so each note is judged against its own
103
+ * conversation, as the gate was measured: one conversation per decision state. A note whose
104
+ * `sourceConversationId` names none of the conversations belongs to the only conversation when there
105
+ * is one; with several, it is unattributed, and must not be judged against another conversation.
106
+ *
107
+ * @param notes The candidate notes.
108
+ * @param conversations The conversations they were extracted from.
109
+ */
110
+ export function GroupMemoryNotesByConversation(notes, conversations) {
111
+ const byConversation = new Map();
112
+ const unattributed = [];
113
+ for (const note of notes) {
114
+ const conversation = conversationOf(note, conversations) ?? (conversations.length === 1 ? conversations[0] : null);
115
+ if (!conversation) {
116
+ unattributed.push(note);
117
+ continue;
118
+ }
119
+ byConversation.set(conversation, [...(byConversation.get(conversation) ?? []), note]);
120
+ }
121
+ const batches = conversations
122
+ .filter(c => byConversation.has(c))
123
+ .map(c => ({ ConversationId: c.ConversationId, Excerpt: FormatMemoryNoteExcerpt(c.Turns), Notes: byConversation.get(c) ?? [] }));
124
+ return { Batches: batches, Unattributed: unattributed };
125
+ }
126
+ /**
127
+ * Formats source conversation excerpts into a single string within max character limits.
128
+ */
129
+ function formatExcerpt(sourceExcerpts) {
130
+ if (!sourceExcerpts) {
131
+ return undefined;
132
+ }
133
+ let text;
134
+ if (typeof sourceExcerpts === 'string') {
135
+ text = sourceExcerpts.trim();
136
+ }
137
+ else if (Array.isArray(sourceExcerpts)) {
138
+ text = sourceExcerpts.join('\n---\n').trim();
139
+ }
140
+ else {
141
+ text = Object.entries(sourceExcerpts)
142
+ .map(([id, excerpt]) => `[${id}]: ${excerpt}`)
143
+ .join('\n---\n')
144
+ .trim();
145
+ }
146
+ return text.length > 0 ? text.slice(0, MEMORY_NOTE_MAX_EXCERPT_CHARS) : undefined;
147
+ }
148
+ /**
149
+ * Builds the state object for the decision prompt, capping content and excerpts.
150
+ *
151
+ * @param notes Candidate notes to project.
152
+ * @param sourceExcerpts Optional conversation thread context.
153
+ */
154
+ export function BuildMemoryNoteState(notes, sourceExcerpts) {
155
+ const notesMap = {};
156
+ for (let i = 0; i < notes.length; i++) {
157
+ const note = notes[i];
158
+ const key = `n${i + 1}`;
159
+ notesMap[key] = {
160
+ type: note.type,
161
+ scope: note.scopeLevel ?? 'user',
162
+ content: (note.content ?? '').slice(0, MEMORY_NOTE_MAX_CONTENT_CHARS)
163
+ };
164
+ }
165
+ const excerpt = formatExcerpt(sourceExcerpts);
166
+ return excerpt ? { notes: notesMap, conversationExcerpt: excerpt } : { notes: notesMap };
167
+ }
168
+ /**
169
+ * Extracts raw probability from a decision answer if it is a valid Likelihood.
170
+ */
171
+ function extractRawProbability(answer) {
172
+ if (!answer || answer.Kind !== 'Likelihood') {
173
+ return undefined;
174
+ }
175
+ if (typeof answer.Probability !== 'number' || !Number.isFinite(answer.Probability)) {
176
+ return undefined;
177
+ }
178
+ return answer.Probability;
179
+ }
180
+ /**
181
+ * Judges a single note when the model is uncalibrated.
182
+ */
183
+ function judgeUncalibratedNote(note, key, rawProb, answeredBy) {
184
+ const reason = answeredBy.ModelName?.trim() || answeredBy.ResolvedModel?.trim()
185
+ ? `The answering model ${DescribeAnsweringModel(answeredBy)} has no memory-note calibration, so the gate keeps nothing`
186
+ : 'No answering model was reported, so the gate keeps nothing';
187
+ return {
188
+ Note: note,
189
+ Key: key,
190
+ RawProbability: rawProb,
191
+ Kept: false,
192
+ Reason: reason
193
+ };
194
+ }
195
+ /**
196
+ * Judges a single note when calibration parameters are present.
197
+ */
198
+ function judgeCalibratedNote(note, key, rawProb, calibration, threshold) {
199
+ if (rawProb === undefined) {
200
+ return {
201
+ Note: note,
202
+ Key: key,
203
+ Kept: false,
204
+ Reason: `Missing or invalid Likelihood answer for question '${key}'`
205
+ };
206
+ }
207
+ const calProb = ApplyPlattCalibration(rawProb, calibration);
208
+ const kept = calProb >= threshold;
209
+ const reason = kept
210
+ ? `Calibrated probability ${calProb.toFixed(4)} >= threshold ${threshold}`
211
+ : `Calibrated probability ${calProb.toFixed(4)} < threshold ${threshold}`;
212
+ return {
213
+ Note: note,
214
+ Key: key,
215
+ RawProbability: rawProb,
216
+ CalibratedProbability: calProb,
217
+ Kept: kept,
218
+ Reason: reason
219
+ };
220
+ }
221
+ /**
222
+ * Evaluates decision answers against candidate notes using Platt calibration.
223
+ *
224
+ * The calibration is the one fitted on the exact model that answered (`FindDecisionCalibration`).
225
+ * An answer from any other model, including a calibrated model at another version, is uncalibrated
226
+ * and keeps nothing (fails safe toward writing no durable memory).
227
+ *
228
+ * @param answers The answers returned by the decision runner.
229
+ * @param notes The candidate notes evaluated.
230
+ * @param answeredBy The model that answered: the MJ decision model and the model its driver resolved.
231
+ * @param threshold The calibrated probability at which a note is kept (default: {@link MEMORY_NOTE_MIN_PROBABILITY}, 0.6).
232
+ * @param calibrations Optional calibration table override (defaults to {@link MEMORY_NOTE_DECISION_CALIBRATION}).
233
+ */
234
+ export function JudgeMemoryNotes(answers, notes, answeredBy = {}, threshold = MEMORY_NOTE_MIN_PROBABILITY, calibrations = MEMORY_NOTE_DECISION_CALIBRATION) {
235
+ const calibration = FindDecisionCalibration(calibrations, answeredBy);
236
+ const judgedNotes = [];
237
+ for (let i = 0; i < notes.length; i++) {
238
+ const note = notes[i];
239
+ const key = `n${i + 1}`;
240
+ const rawProb = extractRawProbability(answers?.[key]);
241
+ const judged = calibration
242
+ ? judgeCalibratedNote(note, key, rawProb, calibration, threshold)
243
+ : judgeUncalibratedNote(note, key, rawProb, answeredBy);
244
+ judgedNotes.push(judged);
245
+ }
246
+ const keptNotes = judgedNotes.filter(j => j.Kept).map(j => j.Note);
247
+ return {
248
+ KeptNotes: keptNotes,
249
+ JudgedNotes: judgedNotes,
250
+ AnsweredBy: answeredBy,
251
+ Calibrated: calibration !== null
252
+ };
253
+ }
254
+ /**
255
+ * Looks up the prompt's configured MaxQuestionsPerCall limit from active PromptModels.
256
+ *
257
+ * @param engine AIEngine metadata source.
258
+ * @param promptName Name of the decision prompt (default: 'Default Decision').
259
+ */
260
+ export function MemoryNotePromptQuestionCap(engine, promptName = 'Default Decision') {
261
+ const target = promptName.trim().toLowerCase();
262
+ const prompt = engine.Prompts?.find(p => (p.Name ?? '').trim().toLowerCase() === target);
263
+ if (!prompt) {
264
+ return undefined;
265
+ }
266
+ const caps = (engine.PromptModels ?? [])
267
+ .filter(pm => UUIDsEqual(pm.PromptID, prompt.ID) && (pm.Status === 'Active' || pm.Status === 'Preview'))
268
+ .map(pm => {
269
+ const modelVendor = pm.VendorID
270
+ ? (engine.ModelVendors ?? []).find(mv => UUIDsEqual(mv.ModelID, pm.ModelID) && UUIDsEqual(mv.VendorID, pm.VendorID))
271
+ : undefined;
272
+ return engine.GetEffectiveModelConfiguration(pm.ModelID, modelVendor?.ID)?.Decision
273
+ ?.MaxQuestionsPerCall;
274
+ });
275
+ const declared = caps.filter((cap) => typeof cap === 'number' && cap > 0);
276
+ return declared.length > 0 ? Math.min(...declared) : undefined;
277
+ }
278
+ /**
279
+ * Splits candidate notes into chunks not exceeding the specified chunk size.
280
+ *
281
+ * @param notes The notes to chunk.
282
+ * @param chunkSize Maximum number of notes per chunk.
283
+ */
284
+ export function ChunkMemoryNotes(notes, chunkSize) {
285
+ if (!chunkSize || chunkSize <= 0 || !Number.isFinite(chunkSize) || notes.length <= chunkSize) {
286
+ return [Array.from(notes)];
287
+ }
288
+ const chunks = [];
289
+ for (let i = 0; i < notes.length; i += chunkSize) {
290
+ chunks.push(notes.slice(i, i + chunkSize));
291
+ }
292
+ return chunks;
293
+ }
294
+ //# sourceMappingURL=memory-note-gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-note-gate.js","sourceRoot":"","sources":["../src/memory-note-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACH,qBAAqB,EAKxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACH,sBAAsB,EACtB,uBAAuB,EAI1B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD;;GAEG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAC1C,2PAA2P,CAAC;AAEhQ;;GAEG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,IAAI,CAAC;AAElD;;GAEG;AACH,MAAM,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CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;QAC3F,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/B,CAAC;IACD,MAAM,MAAM,GAAU,EAAE,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,SAAS,EAAE,CAAC;QAC/C,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC"}
@@ -54,6 +54,8 @@ export declare const MAX_TOOL_DESCRIPTION_LENGTH = 1024;
54
54
  * the Action that produced it; the collision check lives in {@link buildActionToolSet} rather than
55
55
  * here, so this stays a pure function of the name.
56
56
  */
57
+ export declare function SanitizeToolName(actionName: string): string;
58
+ /** @deprecated Use {@link SanitizeToolName}. */
57
59
  export declare function sanitizeToolName(actionName: string): string;
58
60
  /**
59
61
  * Builds the `ChatTool` declaration for one Action.
@@ -61,6 +63,8 @@ export declare function sanitizeToolName(actionName: string): string;
61
63
  * Only `Input` and `Both` params are declared: an `Output` param is something the Action returns,
62
64
  * and declaring it would invite the model to supply it.
63
65
  */
66
+ export declare function BuildToolFromAction(action: MJActionEntityExtended, params: readonly MJActionParamEntity[]): ChatTool;
67
+ /** @deprecated Use {@link BuildToolFromAction}. */
64
68
  export declare function buildToolFromAction(action: MJActionEntityExtended, params: readonly MJActionParamEntity[]): ChatTool;
65
69
  /**
66
70
  * Builds the full tool set for an agent's available Actions, with the reverse map.
@@ -71,6 +75,8 @@ export declare function buildToolFromAction(action: MJActionEntityExtended, para
71
75
  * looks like a model error and would be found, if at all, by someone reading eval failures.
72
76
  * Failing at build time turns it into a metadata problem with a name attached.
73
77
  */
78
+ export declare function BuildActionToolSet(actions: readonly MJActionEntityExtended[], paramsByActionId: ReadonlyMap<string, readonly MJActionParamEntity[]>): ActionToolSet;
79
+ /** @deprecated Use {@link BuildActionToolSet}. */
74
80
  export declare function buildActionToolSet(actions: readonly MJActionEntityExtended[], paramsByActionId: ReadonlyMap<string, readonly MJActionParamEntity[]>): ActionToolSet;
75
81
  /** The two fields of an `MJ: AI Agent Actions` row that declaration control reads. */
76
82
  export interface AgentActionDeclarationRow {
@@ -88,5 +94,7 @@ export interface AgentActionDeclarationRow {
88
94
  * Note the consequence the design accepts: in native mode the prose catalog is not rendered, so an
89
95
  * action removed here is unreachable on that turn, not merely de-emphasised.
90
96
  */
97
+ export declare function FilterDeclarableActions(actions: readonly MJActionEntityExtended[], agentActionRows: ReadonlyArray<AgentActionDeclarationRow>): MJActionEntityExtended[];
98
+ /** @deprecated Use {@link FilterDeclarableActions}. */
91
99
  export declare function filterDeclarableActions(actions: readonly MJActionEntityExtended[], agentActionRows: ReadonlyArray<AgentActionDeclarationRow>): MJActionEntityExtended[];
92
100
  //# sourceMappingURL=action-tool-builder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"action-tool-builder.d.ts","sourceRoot":"","sources":["../../src/native-tools/action-tool-builder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAE3E,0EAA0E;AAC1E,MAAM,WAAW,iBAAiB;IAC9B,gFAAgF;IAChF,IAAI,EAAE,QAAQ,CAAC;IACf,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,qEAAqE;IACrE,MAAM,EAAE,sBAAsB,CAAC;IAC/B,IAAI,EAAE,QAAQ,CAAC;CAClB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC1B,KAAK,EAAE,QAA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BAAgB,uBAAuB,CACnC,OAAO,EAAE,SAAS,sBAAsB,EAAE,EAC1C,eAAe,EAAE,aAAa,CAAC,yBAAyB,CAAC,GAC1D,sBAAsB,EAAE,CAO1B;AAED,uDAAuD;AACvD,wBAAgB,uBAAuB,CACnC,OAAO,EAAE,SAAS,sBAAsB,EAAE,EAC1C,eAAe,EAAE,aAAa,CAAC,yBAAyB,CAAC,GAC1D,sBAAsB,EAAE,CAE1B"}
@@ -33,7 +33,7 @@ const DESCRIPTION_DETAIL_LEVELS = [160, 110, 70, 40, 0];
33
33
  * the Action that produced it; the collision check lives in {@link buildActionToolSet} rather than
34
34
  * here, so this stays a pure function of the name.
35
35
  */
36
- export function sanitizeToolName(actionName) {
36
+ export function SanitizeToolName(actionName) {
37
37
  return actionName
38
38
  .trim()
39
39
  .replace(/[^a-zA-Z0-9]+/g, '_')
@@ -41,6 +41,10 @@ export function sanitizeToolName(actionName) {
41
41
  .toLowerCase()
42
42
  .slice(0, MAX_TOOL_NAME_LENGTH);
43
43
  }
44
+ /** @deprecated Use {@link SanitizeToolName}. */
45
+ export function sanitizeToolName(actionName) {
46
+ return SanitizeToolName(actionName);
47
+ }
44
48
  /**
45
49
  * Maps one param's `ValueType` onto a JSON Schema fragment (§8.2 table).
46
50
  *
@@ -153,7 +157,7 @@ function describeTool(action, params) {
153
157
  * Only `Input` and `Both` params are declared: an `Output` param is something the Action returns,
154
158
  * and declaring it would invite the model to supply it.
155
159
  */
156
- export function buildToolFromAction(action, params) {
160
+ export function BuildToolFromAction(action, params) {
157
161
  const properties = {};
158
162
  const required = [];
159
163
  for (const param of params) {
@@ -174,11 +178,15 @@ export function buildToolFromAction(action, params) {
174
178
  inputSchema.required = required;
175
179
  }
176
180
  return {
177
- name: sanitizeToolName(action.Name),
181
+ name: SanitizeToolName(action.Name),
178
182
  description: describeTool(action, params),
179
183
  inputSchema
180
184
  };
181
185
  }
186
+ /** @deprecated Use {@link BuildToolFromAction}. */
187
+ export function buildToolFromAction(action, params) {
188
+ return BuildToolFromAction(action, params);
189
+ }
182
190
  /**
183
191
  * Builds the full tool set for an agent's available Actions, with the reverse map.
184
192
  *
@@ -188,11 +196,11 @@ export function buildToolFromAction(action, params) {
188
196
  * looks like a model error and would be found, if at all, by someone reading eval failures.
189
197
  * Failing at build time turns it into a metadata problem with a name attached.
190
198
  */
191
- export function buildActionToolSet(actions, paramsByActionId) {
199
+ export function BuildActionToolSet(actions, paramsByActionId) {
192
200
  const byToolName = new Map();
193
201
  const tools = [];
194
202
  for (const action of actions) {
195
- const tool = buildToolFromAction(action, paramsByActionId.get(action.ID) ?? []);
203
+ const tool = BuildToolFromAction(action, paramsByActionId.get(action.ID) ?? []);
196
204
  const existing = byToolName.get(tool.name);
197
205
  if (existing) {
198
206
  throw new Error(`Action tool name collision: '${existing.action.Name}' and '${action.Name}' both sanitize to `
@@ -206,6 +214,10 @@ export function buildActionToolSet(actions, paramsByActionId) {
206
214
  }
207
215
  return { tools, byToolName };
208
216
  }
217
+ /** @deprecated Use {@link BuildActionToolSet}. */
218
+ export function buildActionToolSet(actions, paramsByActionId) {
219
+ return BuildActionToolSet(actions, paramsByActionId);
220
+ }
209
221
  /**
210
222
  * Removes the Actions an agent has chosen not to declare as native tools.
211
223
  *
@@ -217,10 +229,14 @@ export function buildActionToolSet(actions, paramsByActionId) {
217
229
  * Note the consequence the design accepts: in native mode the prose catalog is not rendered, so an
218
230
  * action removed here is unreachable on that turn, not merely de-emphasised.
219
231
  */
220
- export function filterDeclarableActions(actions, agentActionRows) {
232
+ export function FilterDeclarableActions(actions, agentActionRows) {
221
233
  const excluded = new Set(agentActionRows
222
234
  .filter((row) => row.DeclareAsNativeTool === false && row.ActionID)
223
235
  .map((row) => row.ActionID.toLowerCase()));
224
236
  return actions.filter((action) => !excluded.has(action.ID.toLowerCase()));
225
237
  }
238
+ /** @deprecated Use {@link FilterDeclarableActions}. */
239
+ export function filterDeclarableActions(actions, agentActionRows) {
240
+ return FilterDeclarableActions(actions, agentActionRows);
241
+ }
226
242
  //# sourceMappingURL=action-tool-builder.js.map