@memberjunction/ai-agents 6.2.0-edge.4 → 6.2.0-edge.6

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 (161) hide show
  1. package/README.md +154 -7
  2. package/dist/AgentDataPreloader.d.ts +4 -2
  3. package/dist/AgentDataPreloader.d.ts.map +1 -1
  4. package/dist/AgentDataPreloader.js +21 -12
  5. package/dist/AgentDataPreloader.js.map +1 -1
  6. package/dist/AgentRunner.d.ts +61 -6
  7. package/dist/AgentRunner.d.ts.map +1 -1
  8. package/dist/AgentRunner.js +313 -68
  9. package/dist/AgentRunner.js.map +1 -1
  10. package/dist/AgentWakeTriggerService.d.ts +183 -0
  11. package/dist/AgentWakeTriggerService.d.ts.map +1 -0
  12. package/dist/AgentWakeTriggerService.js +478 -0
  13. package/dist/AgentWakeTriggerService.js.map +1 -0
  14. package/dist/ArtifactToolManager.d.ts +12 -3
  15. package/dist/ArtifactToolManager.d.ts.map +1 -1
  16. package/dist/ArtifactToolManager.js +77 -6
  17. package/dist/ArtifactToolManager.js.map +1 -1
  18. package/dist/ClientToolRequestManager.d.ts +11 -1
  19. package/dist/ClientToolRequestManager.d.ts.map +1 -1
  20. package/dist/ClientToolRequestManager.js +19 -6
  21. package/dist/ClientToolRequestManager.js.map +1 -1
  22. package/dist/ConversationToolManager.d.ts +1 -1
  23. package/dist/ConversationToolManager.d.ts.map +1 -1
  24. package/dist/ConversationToolManager.js +10 -4
  25. package/dist/ConversationToolManager.js.map +1 -1
  26. package/dist/MJAIAgentRequestEntityServer.d.ts.map +1 -1
  27. package/dist/MJAIAgentRequestEntityServer.js +20 -0
  28. package/dist/MJAIAgentRequestEntityServer.js.map +1 -1
  29. package/dist/PayloadChangeAnalyzer.d.ts.map +1 -1
  30. package/dist/PayloadChangeAnalyzer.js +53 -30
  31. package/dist/PayloadChangeAnalyzer.js.map +1 -1
  32. package/dist/PayloadManager.d.ts +35 -2
  33. package/dist/PayloadManager.d.ts.map +1 -1
  34. package/dist/PayloadManager.js +250 -149
  35. package/dist/PayloadManager.js.map +1 -1
  36. package/dist/ScratchpadManager.d.ts +18 -0
  37. package/dist/ScratchpadManager.d.ts.map +1 -1
  38. package/dist/ScratchpadManager.js +61 -0
  39. package/dist/ScratchpadManager.js.map +1 -1
  40. package/dist/agent-audience.d.ts +38 -0
  41. package/dist/agent-audience.d.ts.map +1 -0
  42. package/dist/agent-audience.js +99 -0
  43. package/dist/agent-audience.js.map +1 -0
  44. package/dist/agent-context-injector.d.ts +38 -6
  45. package/dist/agent-context-injector.d.ts.map +1 -1
  46. package/dist/agent-context-injector.js +72 -20
  47. package/dist/agent-context-injector.js.map +1 -1
  48. package/dist/agent-memory-context-builder.d.ts +7 -2
  49. package/dist/agent-memory-context-builder.d.ts.map +1 -1
  50. package/dist/agent-memory-context-builder.js +14 -5
  51. package/dist/agent-memory-context-builder.js.map +1 -1
  52. package/dist/agent-pre-execution-rag.d.ts +101 -9
  53. package/dist/agent-pre-execution-rag.d.ts.map +1 -1
  54. package/dist/agent-pre-execution-rag.js +227 -29
  55. package/dist/agent-pre-execution-rag.js.map +1 -1
  56. package/dist/agent-run-watchdog.d.ts +23 -8
  57. package/dist/agent-run-watchdog.d.ts.map +1 -1
  58. package/dist/agent-run-watchdog.js +141 -76
  59. package/dist/agent-run-watchdog.js.map +1 -1
  60. package/dist/agent-types/flow-agent-type.d.ts +15 -0
  61. package/dist/agent-types/flow-agent-type.d.ts.map +1 -1
  62. package/dist/agent-types/flow-agent-type.js +129 -13
  63. package/dist/agent-types/flow-agent-type.js.map +1 -1
  64. package/dist/agent-types/loop-agent-prompt-params.d.ts +6 -2
  65. package/dist/agent-types/loop-agent-prompt-params.d.ts.map +1 -1
  66. package/dist/agent-types/loop-agent-prompt-params.js.map +1 -1
  67. package/dist/agent-types/loop-agent-response-type.d.ts +8 -2
  68. package/dist/agent-types/loop-agent-response-type.d.ts.map +1 -1
  69. package/dist/agent-types/loop-agent-response-type.js.map +1 -1
  70. package/dist/agent-types/loop-agent-type.d.ts +85 -7
  71. package/dist/agent-types/loop-agent-type.d.ts.map +1 -1
  72. package/dist/agent-types/loop-agent-type.js +290 -66
  73. package/dist/agent-types/loop-agent-type.js.map +1 -1
  74. package/dist/base-agent.d.ts +809 -38
  75. package/dist/base-agent.d.ts.map +1 -1
  76. package/dist/base-agent.js +3308 -609
  77. package/dist/base-agent.js.map +1 -1
  78. package/dist/bound-action-params.d.ts +57 -0
  79. package/dist/bound-action-params.d.ts.map +1 -0
  80. package/dist/bound-action-params.js +91 -0
  81. package/dist/bound-action-params.js.map +1 -0
  82. package/dist/index.d.ts +9 -0
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +9 -0
  85. package/dist/index.js.map +1 -1
  86. package/dist/memory-cleanup-agent.d.ts.map +1 -1
  87. package/dist/memory-cleanup-agent.js +3 -0
  88. package/dist/memory-cleanup-agent.js.map +1 -1
  89. package/dist/memory-manager-agent.d.ts.map +1 -1
  90. package/dist/memory-manager-agent.js +52 -35
  91. package/dist/memory-manager-agent.js.map +1 -1
  92. package/dist/native-tools/action-param-schema.d.ts +57 -0
  93. package/dist/native-tools/action-param-schema.d.ts.map +1 -0
  94. package/dist/native-tools/action-param-schema.js +238 -0
  95. package/dist/native-tools/action-param-schema.js.map +1 -0
  96. package/dist/native-tools/action-tool-builder.d.ts +5 -4
  97. package/dist/native-tools/action-tool-builder.d.ts.map +1 -1
  98. package/dist/native-tools/action-tool-builder.js +29 -71
  99. package/dist/native-tools/action-tool-builder.js.map +1 -1
  100. package/dist/native-tools/agent-tools.d.ts +64 -0
  101. package/dist/native-tools/agent-tools.d.ts.map +1 -0
  102. package/dist/native-tools/agent-tools.js +23 -0
  103. package/dist/native-tools/agent-tools.js.map +1 -0
  104. package/dist/native-tools/control-tools.d.ts +26 -4
  105. package/dist/native-tools/control-tools.d.ts.map +1 -1
  106. package/dist/native-tools/control-tools.js +114 -42
  107. package/dist/native-tools/control-tools.js.map +1 -1
  108. package/dist/native-tools/framework-tools.d.ts +47 -0
  109. package/dist/native-tools/framework-tools.d.ts.map +1 -0
  110. package/dist/native-tools/framework-tools.js +187 -0
  111. package/dist/native-tools/framework-tools.js.map +1 -0
  112. package/dist/native-tools/json-argument.d.ts +41 -0
  113. package/dist/native-tools/json-argument.d.ts.map +1 -0
  114. package/dist/native-tools/json-argument.js +79 -0
  115. package/dist/native-tools/json-argument.js.map +1 -0
  116. package/dist/native-tools/native-control-config.d.ts +93 -0
  117. package/dist/native-tools/native-control-config.d.ts.map +1 -0
  118. package/dist/native-tools/native-control-config.js +104 -0
  119. package/dist/native-tools/native-control-config.js.map +1 -0
  120. package/dist/native-tools/tool-result-turns.d.ts +41 -8
  121. package/dist/native-tools/tool-result-turns.d.ts.map +1 -1
  122. package/dist/native-tools/tool-result-turns.js +76 -2
  123. package/dist/native-tools/tool-result-turns.js.map +1 -1
  124. package/dist/native-tools/turn-mode.d.ts +8 -0
  125. package/dist/native-tools/turn-mode.d.ts.map +1 -0
  126. package/dist/native-tools/turn-mode.js +14 -0
  127. package/dist/native-tools/turn-mode.js.map +1 -0
  128. package/dist/query-builder-agent.d.ts +33 -5
  129. package/dist/query-builder-agent.d.ts.map +1 -1
  130. package/dist/query-builder-agent.js +137 -30
  131. package/dist/query-builder-agent.js.map +1 -1
  132. package/dist/realtime/bridge-room-transcript-sink.js +1 -0
  133. package/dist/realtime/bridge-room-transcript-sink.js.map +1 -1
  134. package/dist/realtime/bridge-session-transcript-sink.js +1 -0
  135. package/dist/realtime/bridge-session-transcript-sink.js.map +1 -1
  136. package/dist/realtime/realtime-client-session-service.d.ts +5 -4
  137. package/dist/realtime/realtime-client-session-service.d.ts.map +1 -1
  138. package/dist/realtime/realtime-client-session-service.js +42 -30
  139. package/dist/realtime/realtime-client-session-service.js.map +1 -1
  140. package/dist/realtime/realtime-coagent-config.d.ts +8 -1
  141. package/dist/realtime/realtime-coagent-config.d.ts.map +1 -1
  142. package/dist/realtime/realtime-coagent-config.js +17 -1
  143. package/dist/realtime/realtime-coagent-config.js.map +1 -1
  144. package/dist/realtime/realtime-recording-ledger.d.ts +150 -0
  145. package/dist/realtime/realtime-recording-ledger.d.ts.map +1 -0
  146. package/dist/realtime/realtime-recording-ledger.js +206 -0
  147. package/dist/realtime/realtime-recording-ledger.js.map +1 -0
  148. package/dist/realtime/realtime-recording-opus-assembly.d.ts +211 -0
  149. package/dist/realtime/realtime-recording-opus-assembly.d.ts.map +1 -0
  150. package/dist/realtime/realtime-recording-opus-assembly.js +706 -0
  151. package/dist/realtime/realtime-recording-opus-assembly.js.map +1 -0
  152. package/dist/realtime/realtime-recording-store.d.ts +44 -6
  153. package/dist/realtime/realtime-recording-store.d.ts.map +1 -1
  154. package/dist/realtime/realtime-recording-store.js +105 -51
  155. package/dist/realtime/realtime-recording-store.js.map +1 -1
  156. package/dist/realtime/realtime-turn-moderator.d.ts +2 -1
  157. package/dist/realtime/realtime-turn-moderator.d.ts.map +1 -1
  158. package/dist/realtime/realtime-turn-moderator.js +7 -1
  159. package/dist/realtime/realtime-turn-moderator.js.map +1 -1
  160. package/dist/volatile-child-prompt.js +3 -3
  161. package/package.json +21 -19
@@ -1 +1 @@
1
- {"version":3,"file":"control-tools.d.ts","sourceRoot":"","sources":["../../src/native-tools/control-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAiD,KAAK,iBAAiB,EAAE,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAElI,eAAO,MAAM,mBAAmB,2BAA2B,CAAC;AAC5D,eAAO,MAAM,aAAa,aAAa,CAAC;AACxC,eAAO,MAAM,kBAAkB,kBAAkB,CAAC;AAClD,eAAO,MAAM,qBAAqB,iBAAiB,CAAC;AACpD,gGAAgG;AAChG,eAAO,MAAM,yBAAyB,EAAE,S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AAS,EAAE,SAAS,uBAAuB,EAAE,EAC7C,OAAO,GAAE,mBAAmD,EAC5D,UAAU,GAAE,SAAS,mBAAmB,EAAO,EAC/C,cAAc,GAAE,SAAS,mBAAmB,EAAO,GACpD,aAAa,CAgCf;AAED,kDAAkD;AAClD,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,uBAAuB,EAAE,GAAG,aAAa,CAEzH"}
@@ -1,4 +1,7 @@
1
1
  import { SanitizeToolName, MAX_TOOL_DESCRIPTION_LENGTH } from './action-tool-builder.js';
2
+ import { DEFAULT_NATIVE_CONTROL_CONFIG } from './native-control-config.js';
3
+ import { BuildAgentTool } from './agent-tools.js';
4
+ import { FRAMEWORK_TOOL_NAMES } from './framework-tools.js';
2
5
  export const PAYLOAD_CHANGE_TOOL = 'payload_change_request';
3
6
  export const ASK_USER_TOOL = 'ask_user';
4
7
  export const COMPLETE_TASK_TOOL = 'complete_task';
@@ -69,6 +72,34 @@ export function BuildAskUserTool() {
69
72
  export function buildAskUserTool() {
70
73
  return BuildAskUserTool();
71
74
  }
75
+ /** The four payload-change sections, as an object schema, for the object form of `complete_task`. */
76
+ function payloadChangeObjectSchema() {
77
+ const section = (what) => ({ type: 'object', description: what });
78
+ return {
79
+ type: 'object',
80
+ description: 'Optional. Final payload changes, applied before the task completes — same shape as payload_change_request.',
81
+ properties: {
82
+ newElements: section('Keys and values to ADD that are not in the payload yet.'),
83
+ updateElements: section('Existing keys to UPDATE — only the parts that change.'),
84
+ replaceElements: section('Existing objects to REPLACE entirely.'),
85
+ removeElements: section('Keys to REMOVE (value ignored).')
86
+ }
87
+ };
88
+ }
89
+ /** The `payloadChangeRequest` parameter of `complete_task`, in the declared form. */
90
+ function completeTaskPayloadParameter(form) {
91
+ if (form === 'object') {
92
+ return payloadChangeObjectSchema();
93
+ }
94
+ // A JSON string, not an object: complete_task is the call the framework forces on the
95
+ // final turn, and a forced call is schema-constrained, so an object whose sections
96
+ // declare no properties can only decode as `{}`. The loop decodes the string.
97
+ return {
98
+ type: 'string',
99
+ description: 'Optional. Final payload changes as a JSON object string, applied before the task completes: '
100
+ + '{"newElements"?: {...}, "updateElements"?: {...}, "replaceElements"?: {...}, "removeElements"?: {...}} — same shape as payload_change_request.'
101
+ };
102
+ }
72
103
  /**
73
104
  * `complete_task` — the terminal tool: apply the final payload write and finish, in ONE turn.
74
105
  *
@@ -79,28 +110,21 @@ export function buildAskUserTool() {
79
110
  * same reason (OpenAI Agents SDK `StopAtTools`, SWE-agent's `submit`). Plain text still ends the
80
111
  * turn, for agents whose answer is prose.
81
112
  */
82
- export function BuildCompleteTaskTool() {
113
+ export function BuildCompleteTaskTool(options = {}) {
114
+ const includePayload = options.IncludePayloadChange !== false;
115
+ const properties = {
116
+ message: { type: 'string', description: 'Your final answer or a brief summary of what you did.' },
117
+ ...(includePayload ? { payloadChangeRequest: completeTaskPayloadParameter(options.PayloadForm ?? 'string') } : {})
118
+ };
119
+ const writes = includePayload
120
+ ? 'put any final writes to the shared payload in payloadChangeRequest and your answer for the user or calling agent in message. The change is applied '
121
+ : 'put your answer for the user or calling agent in message. ';
83
122
  return {
84
123
  name: COMPLETE_TASK_TOOL,
85
- description: clip('Finish the task. Call this when your work is done and verified: put any final writes to the shared payload ' +
86
- 'in payloadChangeRequest and your answer for the user or calling agent in message. The change is applied ' +
124
+ description: clip(`Finish the task. Call this when your work is done and verified: ${writes}` +
87
125
  'and the run ends — unless the result fails validation, in which case you receive the reason and continue. ' +
88
126
  'Must be the only call on its turn.', MAX_TOOL_DESCRIPTION_LENGTH),
89
- inputSchema: {
90
- type: 'object',
91
- properties: {
92
- message: { type: 'string', description: 'Your final answer or a brief summary of what you did.' },
93
- // A JSON string, not an object: complete_task is the call the framework forces on the
94
- // final turn, and a forced call is schema-constrained, so an object whose sections
95
- // declare no properties can only decode as `{}`. The loop decodes the string.
96
- payloadChangeRequest: {
97
- type: 'string',
98
- description: 'Optional. Final payload changes as a JSON object string, applied before the task completes: '
99
- + '{"newElements"?: {...}, "updateElements"?: {...}, "replaceElements"?: {...}, "removeElements"?: {...}} — same shape as payload_change_request.'
100
- }
101
- },
102
- required: ['message']
103
- }
127
+ inputSchema: { type: 'object', properties, required: ['message'] }
104
128
  };
105
129
  }
106
130
  /** One tool per sub-agent: `delegate_to_<sanitized name>`, described by the agent's own description. */
@@ -124,40 +148,88 @@ export function buildSubAgentTool(agent) {
124
148
  return BuildSubAgentTool(agent);
125
149
  }
126
150
  /**
127
- * Actions, then sub-agents, then the fixed control tools — one reverse map for all of them.
128
- * Collisions and reserved-name clashes are hard errors, exactly as Action/Action collisions are.
151
+ * The fixed control tools this agent declares, with their bindings — `payload_change_request`,
152
+ * `ask_user` and `complete_task`, each unless its configuration turns it off.
153
+ */
154
+ function buildControlBindings(control) {
155
+ const bindings = [];
156
+ if (control.PayloadChangeTool) {
157
+ const payload = BuildPayloadChangeTool();
158
+ bindings.push({ kind: 'payloadChange', toolName: payload.name, tool: payload });
159
+ }
160
+ if (control.AskUser) {
161
+ const ask = BuildAskUserTool();
162
+ bindings.push({ kind: 'askUser', toolName: ask.name, tool: ask });
163
+ }
164
+ if (control.Terminal === 'tool') {
165
+ const complete = BuildCompleteTaskTool({ IncludePayloadChange: control.PayloadChangeTool, PayloadForm: control.CompleteTaskPayload });
166
+ bindings.push({ kind: 'complete', toolName: complete.name, tool: complete });
167
+ }
168
+ return bindings;
169
+ }
170
+ /** How a binding is named in a collision error. */
171
+ function describeBinding(binding) {
172
+ switch (binding.kind) {
173
+ case 'action': return `Action '${binding.action.Name}'`;
174
+ case 'subAgent': return `sub-agent '${binding.agent.Name}'`;
175
+ case 'agentTool': return `agent tool '${binding.toolName}'`;
176
+ default: return `'${binding.toolName}'`;
177
+ }
178
+ }
179
+ /** Adds one binding, rejecting a name another tool already declared. */
180
+ function addBinding(set, binding, isControl) {
181
+ const existing = set.byToolName.get(binding.toolName);
182
+ if (existing) {
183
+ throw new Error(`Tool name collision: ${describeBinding(binding)} and ${describeBinding(existing)} both declare '${binding.toolName}'. Rename one.`);
184
+ }
185
+ set.byToolName.set(binding.toolName, binding);
186
+ set.tools.push(binding.tool);
187
+ if (isControl) {
188
+ set.controlToolNames.push(binding.toolName);
189
+ }
190
+ }
191
+ /**
192
+ * Actions, then sub-agents, then the agent's own tools, then the control tools its configuration
193
+ * declares — one reverse map for all of them. Collisions and reserved-name clashes are hard
194
+ * errors, exactly as Action/Action collisions are. A reserved name stays reserved when its tool is
195
+ * turned off, so changing an agent's configuration can never make an Action's name collide.
196
+ *
197
+ * Agent tools are not control tools: like Actions, they are kept for every native model, hybrid
198
+ * included, so they are not listed in `controlToolNames`. Framework tools (native-only mode) ARE
199
+ * control tools: a hybrid model keeps the envelope fields they replace, so the runner strips them.
129
200
  */
130
- export function BuildNativeToolSet(actionSet, subAgents) {
131
- const byToolName = new Map(actionSet.byToolName);
132
- const tools = [...actionSet.tools];
133
- const controlToolNames = [];
201
+ export function BuildNativeToolSet(actionSet, subAgents, control = DEFAULT_NATIVE_CONTROL_CONFIG, agentTools = [], frameworkTools = []) {
134
202
  for (const reserved of NATIVE_CONTROL_TOOL_NAMES) {
135
203
  const clash = actionSet.byToolName.get(reserved);
136
204
  if (clash) {
137
205
  throw new Error(`Action '${clash.action.Name}' sanitizes to '${reserved}', which is a reserved control-tool name. Rename the Action.`);
138
206
  }
139
207
  }
208
+ for (const framework of frameworkTools) {
209
+ const clash = actionSet.byToolName.get(framework.Name);
210
+ if (clash) {
211
+ throw new Error(`Action '${clash.action.Name}' sanitizes to '${framework.Name}', the native-only framework tool of that name. `
212
+ + 'Rename the Action, or turn NativeControl.NativeOnly off for this agent.');
213
+ }
214
+ }
215
+ const set = { tools: [...actionSet.tools], byToolName: new Map(actionSet.byToolName), controlToolNames: [] };
140
216
  for (const agent of subAgents) {
141
217
  const tool = BuildSubAgentTool(agent);
142
- const existing = byToolName.get(tool.name);
143
- if (existing) {
144
- const other = existing.kind === 'action' ? `Action '${existing.action.Name}'`
145
- : existing.kind === 'subAgent' ? `sub-agent '${existing.agent.Name}'` : `'${existing.toolName}'`;
146
- throw new Error(`Tool name collision: sub-agent '${agent.Name}' and ${other} both declare '${tool.name}'. Rename one.`);
147
- }
148
- byToolName.set(tool.name, { kind: 'subAgent', toolName: tool.name, agent, tool });
149
- tools.push(tool);
150
- controlToolNames.push(tool.name);
218
+ addBinding(set, { kind: 'subAgent', toolName: tool.name, agent, tool }, true);
219
+ }
220
+ const reserved = [...NATIVE_CONTROL_TOOL_NAMES, ...FRAMEWORK_TOOL_NAMES];
221
+ for (const definition of agentTools) {
222
+ const tool = BuildAgentTool(definition, reserved, SUB_AGENT_TOOL_PREFIX);
223
+ addBinding(set, { kind: 'agentTool', toolName: tool.name, tool, definition }, false);
224
+ }
225
+ for (const definition of frameworkTools) {
226
+ const tool = { name: definition.Name, description: definition.Description, inputSchema: definition.InputSchema };
227
+ addBinding(set, { kind: 'agentTool', toolName: tool.name, tool, definition }, true);
228
+ }
229
+ for (const binding of buildControlBindings(control)) {
230
+ addBinding(set, binding, true);
151
231
  }
152
- const payload = BuildPayloadChangeTool();
153
- const ask = BuildAskUserTool();
154
- const complete = BuildCompleteTaskTool();
155
- byToolName.set(payload.name, { kind: 'payloadChange', toolName: payload.name, tool: payload });
156
- byToolName.set(ask.name, { kind: 'askUser', toolName: ask.name, tool: ask });
157
- byToolName.set(complete.name, { kind: 'complete', toolName: complete.name, tool: complete });
158
- tools.push(payload, ask, complete);
159
- controlToolNames.push(payload.name, ask.name, complete.name);
160
- return { tools, byToolName, controlToolNames };
232
+ return set;
161
233
  }
162
234
  /** @deprecated Use {@link BuildNativeToolSet}. */
163
235
  export function buildNativeToolSet(actionSet, subAgents) {
@@ -1 +1 @@
1
- {"version":3,"file":"control-tools.js","sourceRoot":"","sources":["../../src/native-tools/control-tools.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,gBAAgB,EAAE,2BAA2B,EAA8C,MAAM,uBAAuB,CAAC;AAElI,MAAM,CAAC,MAAM,m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ACnC,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AAED,kDAAkD;AAClD,MAAM,UAAU,kBAAkB,CAAC,SAAwB,EAAE,SAA6C;IACtG,OAAO,kBAAkB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AACpD,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @fileoverview The framework's own capabilities as native tools, for the native-only control
3
+ * plane (`NativeControl.NativeOnly`).
4
+ *
5
+ * Under the hybrid prompt the scratchpad, durable memory, artifact tools, conversation-history
6
+ * tools and decisions are fields of the JSON envelope. A turn that calls a tool skips envelope
7
+ * parsing, so a model that is calling tools cannot use any of them on that turn, and it is taught
8
+ * two protocols at once. Native-only mode declares each enabled capability as a tool instead, and
9
+ * every call is answered by its own tool result on the same turn.
10
+ *
11
+ * The tools are built on the agent-tool contract ({@link AgentToolDefinition}); the agent supplies
12
+ * the capability behind each through {@link FrameworkToolHost}.
13
+ * @module @memberjunction/ai-agents
14
+ */
15
+ import type { AgentDecisionRequest, AgentScratchpad } from '@memberjunction/ai-core-plus';
16
+ import type { AgentToolDefinition, AgentToolResult } from './agent-tools.js';
17
+ export declare const SCRATCHPAD_TOOL = "scratchpad_write";
18
+ export declare const MEMORY_WRITE_TOOL = "memory_write";
19
+ export declare const ARTIFACT_TOOL = "artifact_tool";
20
+ export declare const CONVERSATION_TOOL = "conversation_tool";
21
+ export declare const DECISION_TOOL = "ask_decisions";
22
+ /** Every framework tool name — reserved, like the control tools. */
23
+ export declare const FRAMEWORK_TOOL_NAMES: readonly string[];
24
+ /** Which framework capabilities this turn offers. */
25
+ export interface FrameworkToolAvailability {
26
+ Scratchpad: boolean;
27
+ MemoryWrites: boolean;
28
+ ArtifactTools: boolean;
29
+ ConversationTools: boolean;
30
+ Decisions: boolean;
31
+ }
32
+ /** The capabilities behind the framework tools, supplied by the running agent. Each returns the text the model reads. */
33
+ export interface FrameworkToolHost {
34
+ ApplyScratchpad(changes: AgentScratchpad): string;
35
+ WriteMemory(note: string, type: 'Preference' | 'Context', scopeHint: 'user' | 'agent' | undefined): Promise<AgentToolResult>;
36
+ RunArtifactTool(artifactId: string, tool: string, input: Record<string, unknown>): Promise<AgentToolResult>;
37
+ RunConversationTool(tool: string, input: Record<string, unknown>): Promise<AgentToolResult>;
38
+ RunDecisions(requests: AgentDecisionRequest[], payload: object): Promise<AgentToolResult>;
39
+ }
40
+ /**
41
+ * The framework tools this turn offers, in a fixed order.
42
+ *
43
+ * @param host The capabilities behind the tools
44
+ * @param availability Which capabilities are enabled for this agent and turn
45
+ */
46
+ export declare function BuildFrameworkTools(host: FrameworkToolHost, availability: FrameworkToolAvailability): AgentToolDefinition[];
47
+ //# sourceMappingURL=framework-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"framework-tools.d.ts","sourceRoot":"","sources":["../../src/native-tools/framework-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAa,MAAM,8BAA8B,CAAC;AACrG,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAE1E,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAChD,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAC7C,eAAO,MAAM,iBAAiB,sBAAsB,CAAC;AACrD,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAC7C,oEAAoE;AACpE,eAAO,MAAM,oBAAoB,EAAE,SAAS,MAAM,EAA0F,CAAC;AAE7I,qDAAqD;AACrD,MAAM,WAAW,yBAAyB;IACtC,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;IACvB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,SAAS,EAAE,OAAO,CAAC;CACtB;AAED,yHAAyH;AACzH,MAAM,WAAW,iBAAiB;IAC9B,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAAC;IAClD,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAC7H,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAC5G,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAC5F,YAAY,CAAC,QAAQ,EAAE,oBAAoB,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAC7F;AA0KD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,EAAE,YAAY,EAAE,yBAAyB,GAAG,mBAAmB,EAAE,CAQ3H"}
@@ -0,0 +1,187 @@
1
+ export const SCRATCHPAD_TOOL = 'scratchpad_write';
2
+ export const MEMORY_WRITE_TOOL = 'memory_write';
3
+ export const ARTIFACT_TOOL = 'artifact_tool';
4
+ export const CONVERSATION_TOOL = 'conversation_tool';
5
+ export const DECISION_TOOL = 'ask_decisions';
6
+ /** Every framework tool name — reserved, like the control tools. */
7
+ export const FRAMEWORK_TOOL_NAMES = [SCRATCHPAD_TOOL, MEMORY_WRITE_TOOL, ARTIFACT_TOOL, CONVERSATION_TOOL, DECISION_TOOL];
8
+ const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
9
+ const fail = (Content) => ({ Content, IsError: true });
10
+ function scratchpadTool(host) {
11
+ return {
12
+ Name: SCRATCHPAD_TOOL,
13
+ Description: 'Write to your private scratchpad: working notes and a task list that persist across your turns and are never shared. '
14
+ + 'Call this to record reasoning you will need later or to track work items. Keep it lean: it is shown to you on every turn.',
15
+ InputSchema: {
16
+ type: 'object',
17
+ properties: {
18
+ notes: { type: 'string', description: 'Replaces your notes. Omit to leave them as they are.' },
19
+ taskList: {
20
+ type: 'object',
21
+ description: 'Task changes: `upsert` adds or updates tasks by id; `remove` deletes tasks by id.',
22
+ properties: {
23
+ upsert: {
24
+ type: 'array',
25
+ items: {
26
+ type: 'object',
27
+ properties: {
28
+ id: { type: 'string' },
29
+ title: { type: 'string' },
30
+ status: { type: 'string', enum: ['pending', 'in_progress', 'completed', 'blocked'] },
31
+ notes: { type: 'string' }
32
+ },
33
+ required: ['id', 'title', 'status']
34
+ }
35
+ },
36
+ remove: { type: 'array', items: { type: 'string' } }
37
+ }
38
+ }
39
+ }
40
+ },
41
+ Execute: async (args) => {
42
+ const changes = readScratchpadChanges(args);
43
+ return typeof changes === 'string' ? fail(changes) : { Content: host.ApplyScratchpad(changes), IsError: false };
44
+ }
45
+ };
46
+ }
47
+ const TASK_STATUSES = ['pending', 'in_progress', 'completed', 'blocked'];
48
+ /** One task from `taskList.upsert`, or undefined when it lacks an id, a title or a known status. */
49
+ function readTask(raw) {
50
+ if (!isRecord(raw) || typeof raw.id !== 'string' || typeof raw.title !== 'string' || typeof raw.status !== 'string') {
51
+ return undefined;
52
+ }
53
+ const status = TASK_STATUSES.find((s) => s === raw.status);
54
+ if (!status) {
55
+ return undefined;
56
+ }
57
+ return { id: raw.id, title: raw.title, status, ...(typeof raw.notes === 'string' ? { notes: raw.notes } : {}) };
58
+ }
59
+ /** The scratchpad changes in a call's arguments, or a message saying what is wrong with them. */
60
+ function readScratchpadChanges(args) {
61
+ if (args.notes !== undefined && typeof args.notes !== 'string') {
62
+ return 'scratchpad_write.notes must be a string.';
63
+ }
64
+ const list = isRecord(args.taskList) ? args.taskList : {};
65
+ const upsertRaw = Array.isArray(list.upsert) ? list.upsert : [];
66
+ const upsert = upsertRaw.map(readTask);
67
+ if (upsert.some((t) => t === undefined)) {
68
+ return "Every task in taskList.upsert needs an id, a title and a status of 'pending', 'in_progress', 'completed' or 'blocked'.";
69
+ }
70
+ const remove = Array.isArray(list.remove) ? list.remove.filter((id) => typeof id === 'string') : [];
71
+ return {
72
+ ...(typeof args.notes === 'string' ? { notes: args.notes } : {}),
73
+ ...(upsert.length || remove.length ? { taskList: { upsert: upsert, remove } } : {})
74
+ };
75
+ }
76
+ function memoryTool(host) {
77
+ return {
78
+ Name: MEMORY_WRITE_TOOL,
79
+ Description: 'Record one durable memory that persists across runs: an atomic, third-person fact such as "User prefers bar charts over pie charts." '
80
+ + 'Call this the moment the user states a lasting preference or fact. Not for task state (use the scratchpad) and not for instructions.',
81
+ InputSchema: {
82
+ type: 'object',
83
+ properties: {
84
+ note: { type: 'string', description: 'The fact, as one declarative sentence.' },
85
+ type: { type: 'string', enum: ['Preference', 'Context'], description: 'Preference: likes, dislikes, choices. Context: situational facts.' },
86
+ scopeHint: { type: 'string', enum: ['user', 'agent'], description: "Optional. 'agent' stores it without tying it to the current user." }
87
+ },
88
+ required: ['note', 'type']
89
+ },
90
+ Execute: async (args) => {
91
+ const type = args.type === 'Preference' || args.type === 'Context' ? args.type : undefined;
92
+ if (typeof args.note !== 'string' || !args.note.trim() || !type) {
93
+ return fail("memory_write needs a non-empty note and a type of 'Preference' or 'Context'.");
94
+ }
95
+ const scope = args.scopeHint === 'user' || args.scopeHint === 'agent' ? args.scopeHint : undefined;
96
+ return host.WriteMemory(args.note, type, scope);
97
+ }
98
+ };
99
+ }
100
+ function artifactTool(host) {
101
+ return {
102
+ Name: ARTIFACT_TOOL,
103
+ Description: 'Run one artifact tool on an artifact listed in Available Artifacts, to explore or inspect it. '
104
+ + 'Call this with the artifact id (A, B, …), the tool name and its input; the result is returned to you on this turn.',
105
+ InputSchema: {
106
+ type: 'object',
107
+ properties: {
108
+ artifactId: { type: 'string', description: 'The artifact id from Available Artifacts, such as "A".' },
109
+ tool: { type: 'string', description: 'The artifact tool to run, as listed under Artifact Tools.' },
110
+ input: { type: 'object', description: "The tool's input parameters." }
111
+ },
112
+ required: ['artifactId', 'tool']
113
+ },
114
+ Execute: async (args) => {
115
+ if (typeof args.artifactId !== 'string' || typeof args.tool !== 'string') {
116
+ return fail('artifact_tool needs an artifactId and a tool name.');
117
+ }
118
+ return host.RunArtifactTool(args.artifactId, args.tool, isRecord(args.input) ? args.input : {});
119
+ }
120
+ };
121
+ }
122
+ function conversationTool(host) {
123
+ return {
124
+ Name: CONVERSATION_TOOL,
125
+ Description: 'Read stored conversation history: page exact messages back in by sequence number, search the history, or summarize a range. '
126
+ + 'Call this when you need exact wording, identifiers or numbers that a summary may have lost.',
127
+ InputSchema: {
128
+ type: 'object',
129
+ properties: {
130
+ tool: { type: 'string', enum: ['getMessageBySequence', 'getMessagesByRange', 'searchConversation', 'summarizeRange'] },
131
+ input: { type: 'object', description: 'The input for that tool, as listed under Conversation History Tools.' }
132
+ },
133
+ required: ['tool', 'input']
134
+ },
135
+ Execute: async (args) => {
136
+ if (typeof args.tool !== 'string') {
137
+ return fail('conversation_tool needs a tool name.');
138
+ }
139
+ return host.RunConversationTool(args.tool, isRecord(args.input) ? args.input : {});
140
+ }
141
+ };
142
+ }
143
+ function decisionTool(host) {
144
+ return {
145
+ Name: DECISION_TOOL,
146
+ Description: 'Ask typed decision questions (Likelihood, Choice, Score) answered by a fast decision model; the answers are returned to you on this turn. '
147
+ + 'Call this for classification, triage, relevance or threshold judgments over a small answer space — not for writing or open-ended reasoning.',
148
+ InputSchema: {
149
+ type: 'object',
150
+ properties: {
151
+ decisions: {
152
+ type: 'array',
153
+ description: 'Decision requests, the same shape as described under Decisions.',
154
+ items: { type: 'object' }
155
+ }
156
+ },
157
+ required: ['decisions']
158
+ },
159
+ Execute: async (args, context) => {
160
+ if (!Array.isArray(args.decisions) || args.decisions.length === 0) {
161
+ return fail('ask_decisions needs a non-empty decisions array.');
162
+ }
163
+ return host.RunDecisions(args.decisions, context.CurrentPayload);
164
+ }
165
+ };
166
+ }
167
+ /**
168
+ * The framework tools this turn offers, in a fixed order.
169
+ *
170
+ * @param host The capabilities behind the tools
171
+ * @param availability Which capabilities are enabled for this agent and turn
172
+ */
173
+ export function BuildFrameworkTools(host, availability) {
174
+ const tools = [];
175
+ if (availability.Scratchpad)
176
+ tools.push(scratchpadTool(host));
177
+ if (availability.MemoryWrites)
178
+ tools.push(memoryTool(host));
179
+ if (availability.ArtifactTools)
180
+ tools.push(artifactTool(host));
181
+ if (availability.ConversationTools)
182
+ tools.push(conversationTool(host));
183
+ if (availability.Decisions)
184
+ tools.push(decisionTool(host));
185
+ return tools;
186
+ }
187
+ //# sourceMappingURL=framework-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"framework-tools.js","sourceRoot":"","sources":["../../src/native-tools/framework-tools.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAC,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAClD,MAAM,CAAC,MAAM,iBAAiB,GAAG,cAAc,CAAC;AAChD,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC;AAC7C,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AACrD,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC;AAC7C,oEAAoE;AACpE,MAAM,CAAC,MAAM,oBAAoB,GAAsB,CAAC,eAAe,EAAE,iBAAiB,EAAE,aAAa,EAAE,iBAAiB,EAAE,aAAa,CAAC,CAAC;AAoB7I,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CAAC,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC5I,MAAM,IAAI,GAAG,CAAC,OAAe,EAAmB,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAEhF,SAAS,cAAc,CAAC,I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CAAC,IAAI,CAAC,CAAC,CAAC;IACvE,IAAI,YAAY,CAAC,SAAS;QAAE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3D,OAAO,KAAK,CAAC;AACjB,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @fileoverview Decoding a JSON document that a model sent as a string-typed tool argument.
3
+ *
4
+ * Some tool arguments are declared as JSON strings on purpose (see `complete_task.payloadChangeRequest`
5
+ * in control-tools.ts), which leaves the model writing JSON inside a string. Long documents come back
6
+ * with a recurring defect: part-way through, usually right after a long string value such as a SQL
7
+ * query, the model keeps writing the document's own layout as escape sequences — `"…ASC"\n }\n }\n}`
8
+ * — as if it were still inside that string. Gemini 3.8 Flash did exactly this on a forced final
9
+ * `complete_task` turn, and the run failed with a finished, correct answer in hand.
10
+ *
11
+ * A backslash is never valid JSON outside a string, so turning `\n`, `\r` and `\t` there back into
12
+ * the whitespace they stand for cannot change the meaning of a document that was already valid.
13
+ * Nothing else is repaired: a document that still does not parse is reported with the parser's own
14
+ * message, so the model learns where it went wrong.
15
+ */
16
+ /** The result of decoding a JSON argument: the parsed value, or why it could not be parsed. */
17
+ export type JSONArgumentDecodeResult = {
18
+ Success: true;
19
+ Value: unknown;
20
+ Repaired: boolean;
21
+ } | {
22
+ Success: false;
23
+ Error: string;
24
+ };
25
+ /**
26
+ * Parses `text` as JSON, repairing layout escapes written outside string literals if the plain parse
27
+ * fails.
28
+ *
29
+ * @param text the argument as the model sent it
30
+ * @returns the parsed value, with `Repaired` true when the repair was needed; or the original parse error
31
+ */
32
+ export declare function DecodeJSONArgument(text: string): JSONArgumentDecodeResult;
33
+ /**
34
+ * Replaces `\n`, `\r` and `\t` escape sequences that sit outside JSON string literals with the
35
+ * whitespace they stand for. Escapes inside strings, and every other character, are left alone.
36
+ *
37
+ * @param text JSON text, possibly with layout written as escape sequences
38
+ * @returns the text with those escapes outside strings turned into whitespace
39
+ */
40
+ export declare function RepairLayoutEscapesOutsideStrings(text: string): string;
41
+ //# sourceMappingURL=json-argument.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-argument.d.ts","sourceRoot":"","sources":["../../src/native-tools/json-argument.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,+FAA+F;AAC/F,MAAM,MAAM,wBAAwB,GAC9B;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GACpD;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAKxC;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,wBAAwB,CAiBzE;AAED;;;;;;GAMG;AACH,wBAAgB,iCAAiC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA0BtE"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @fileoverview Decoding a JSON document that a model sent as a string-typed tool argument.
3
+ *
4
+ * Some tool arguments are declared as JSON strings on purpose (see `complete_task.payloadChangeRequest`
5
+ * in control-tools.ts), which leaves the model writing JSON inside a string. Long documents come back
6
+ * with a recurring defect: part-way through, usually right after a long string value such as a SQL
7
+ * query, the model keeps writing the document's own layout as escape sequences — `"…ASC"\n }\n }\n}`
8
+ * — as if it were still inside that string. Gemini 3.8 Flash did exactly this on a forced final
9
+ * `complete_task` turn, and the run failed with a finished, correct answer in hand.
10
+ *
11
+ * A backslash is never valid JSON outside a string, so turning `\n`, `\r` and `\t` there back into
12
+ * the whitespace they stand for cannot change the meaning of a document that was already valid.
13
+ * Nothing else is repaired: a document that still does not parse is reported with the parser's own
14
+ * message, so the model learns where it went wrong.
15
+ */
16
+ /** Escapes a model writes for layout, mapped to the whitespace they stand for. */
17
+ const LAYOUT_ESCAPES = { n: '\n', r: '\r', t: '\t' };
18
+ /**
19
+ * Parses `text` as JSON, repairing layout escapes written outside string literals if the plain parse
20
+ * fails.
21
+ *
22
+ * @param text the argument as the model sent it
23
+ * @returns the parsed value, with `Repaired` true when the repair was needed; or the original parse error
24
+ */
25
+ export function DecodeJSONArgument(text) {
26
+ let originalError;
27
+ try {
28
+ return { Success: true, Value: JSON.parse(text), Repaired: false };
29
+ }
30
+ catch (error) {
31
+ originalError = error instanceof Error ? error.message : String(error);
32
+ }
33
+ const repaired = RepairLayoutEscapesOutsideStrings(text);
34
+ if (repaired !== text) {
35
+ try {
36
+ return { Success: true, Value: JSON.parse(repaired), Repaired: true };
37
+ }
38
+ catch {
39
+ // Fall through: report the error the model's own text produced, not the repair's.
40
+ }
41
+ }
42
+ return { Success: false, Error: originalError };
43
+ }
44
+ /**
45
+ * Replaces `\n`, `\r` and `\t` escape sequences that sit outside JSON string literals with the
46
+ * whitespace they stand for. Escapes inside strings, and every other character, are left alone.
47
+ *
48
+ * @param text JSON text, possibly with layout written as escape sequences
49
+ * @returns the text with those escapes outside strings turned into whitespace
50
+ */
51
+ export function RepairLayoutEscapesOutsideStrings(text) {
52
+ let output = '';
53
+ let inString = false;
54
+ for (let i = 0; i < text.length; i++) {
55
+ const char = text[i];
56
+ if (inString) {
57
+ output += char;
58
+ if (char === '\\' && i + 1 < text.length) {
59
+ output += text[++i];
60
+ }
61
+ else if (char === '"') {
62
+ inString = false;
63
+ }
64
+ continue;
65
+ }
66
+ const layout = char === '\\' ? LAYOUT_ESCAPES[text[i + 1]] : undefined;
67
+ if (layout !== undefined) {
68
+ output += layout;
69
+ i++;
70
+ continue;
71
+ }
72
+ if (char === '"') {
73
+ inString = true;
74
+ }
75
+ output += char;
76
+ }
77
+ return output;
78
+ }
79
+ //# sourceMappingURL=json-argument.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-argument.js","sourceRoot":"","sources":["../../src/native-tools/json-argument.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAOH,kFAAkF;AAClF,MAAM,cAAc,GAAqC,EAAE,C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