@memberjunction/ai-agents 6.2.0-edge.3 → 6.2.0-edge.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -7
- package/dist/AgentRunner.d.ts +55 -5
- package/dist/AgentRunner.d.ts.map +1 -1
- package/dist/AgentRunner.js +277 -59
- package/dist/AgentRunner.js.map +1 -1
- package/dist/ArtifactToolManager.d.ts +11 -3
- package/dist/ArtifactToolManager.d.ts.map +1 -1
- package/dist/ArtifactToolManager.js +72 -6
- package/dist/ArtifactToolManager.js.map +1 -1
- package/dist/ClientToolRequestManager.d.ts +11 -1
- package/dist/ClientToolRequestManager.d.ts.map +1 -1
- package/dist/ClientToolRequestManager.js +19 -6
- package/dist/ClientToolRequestManager.js.map +1 -1
- package/dist/ConversationCompactionManager.d.ts +2 -0
- package/dist/ConversationCompactionManager.d.ts.map +1 -1
- package/dist/ConversationCompactionManager.js +2 -2
- package/dist/ConversationCompactionManager.js.map +1 -1
- package/dist/ConversationToolManager.d.ts +13 -2
- package/dist/ConversationToolManager.d.ts.map +1 -1
- package/dist/ConversationToolManager.js +19 -3
- package/dist/ConversationToolManager.js.map +1 -1
- package/dist/KnowledgeAgent.d.ts.map +1 -1
- package/dist/KnowledgeAgent.js +6 -1
- package/dist/KnowledgeAgent.js.map +1 -1
- package/dist/MJAIAgentRequestEntityServer.d.ts +6 -0
- package/dist/MJAIAgentRequestEntityServer.d.ts.map +1 -1
- package/dist/MJAIAgentRequestEntityServer.js +26 -1
- package/dist/MJAIAgentRequestEntityServer.js.map +1 -1
- package/dist/PayloadChangeAnalyzer.d.ts.map +1 -1
- package/dist/PayloadChangeAnalyzer.js +53 -30
- package/dist/PayloadChangeAnalyzer.js.map +1 -1
- package/dist/PayloadManager.d.ts +35 -2
- package/dist/PayloadManager.d.ts.map +1 -1
- package/dist/PayloadManager.js +250 -149
- package/dist/PayloadManager.js.map +1 -1
- package/dist/ScratchpadManager.d.ts +18 -0
- package/dist/ScratchpadManager.d.ts.map +1 -1
- package/dist/ScratchpadManager.js +61 -0
- package/dist/ScratchpadManager.js.map +1 -1
- package/dist/agent-audience.d.ts +38 -0
- package/dist/agent-audience.d.ts.map +1 -0
- package/dist/agent-audience.js +99 -0
- package/dist/agent-audience.js.map +1 -0
- package/dist/agent-context-injector.d.ts +17 -2
- package/dist/agent-context-injector.d.ts.map +1 -1
- package/dist/agent-context-injector.js +23 -7
- package/dist/agent-context-injector.js.map +1 -1
- package/dist/agent-memory-context-builder.d.ts +7 -2
- package/dist/agent-memory-context-builder.d.ts.map +1 -1
- package/dist/agent-memory-context-builder.js +12 -3
- package/dist/agent-memory-context-builder.js.map +1 -1
- package/dist/agent-pre-execution-rag.d.ts +101 -9
- package/dist/agent-pre-execution-rag.d.ts.map +1 -1
- package/dist/agent-pre-execution-rag.js +224 -23
- package/dist/agent-pre-execution-rag.js.map +1 -1
- package/dist/agent-run-watchdog.d.ts +65 -5
- package/dist/agent-run-watchdog.d.ts.map +1 -1
- package/dist/agent-run-watchdog.js +143 -28
- package/dist/agent-run-watchdog.js.map +1 -1
- package/dist/agent-types/flow-agent-type.d.ts +8 -0
- package/dist/agent-types/flow-agent-type.d.ts.map +1 -1
- package/dist/agent-types/flow-agent-type.js +48 -6
- package/dist/agent-types/flow-agent-type.js.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.d.ts +7 -0
- package/dist/agent-types/loop-agent-prompt-params.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.js +1 -0
- package/dist/agent-types/loop-agent-prompt-params.js.map +1 -1
- package/dist/agent-types/loop-agent-response-type.d.ts +8 -2
- package/dist/agent-types/loop-agent-response-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-response-type.js.map +1 -1
- package/dist/agent-types/loop-agent-type.d.ts +9 -2
- package/dist/agent-types/loop-agent-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-type.js +60 -16
- package/dist/agent-types/loop-agent-type.js.map +1 -1
- package/dist/artifact-tools/SearchResultSetToolLibrary.js +4 -4
- package/dist/artifact-tools/SearchResultSetToolLibrary.js.map +1 -1
- package/dist/base-agent.d.ts +837 -43
- package/dist/base-agent.d.ts.map +1 -1
- package/dist/base-agent.js +3081 -663
- package/dist/base-agent.js.map +1 -1
- package/dist/client-tool-results.d.ts +45 -0
- package/dist/client-tool-results.d.ts.map +1 -0
- package/dist/client-tool-results.js +94 -0
- package/dist/client-tool-results.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/memory-manager-agent.d.ts.map +1 -1
- package/dist/memory-manager-agent.js +46 -34
- package/dist/memory-manager-agent.js.map +1 -1
- package/dist/native-tools/action-param-schema.d.ts +57 -0
- package/dist/native-tools/action-param-schema.d.ts.map +1 -0
- package/dist/native-tools/action-param-schema.js +238 -0
- package/dist/native-tools/action-param-schema.js.map +1 -0
- package/dist/native-tools/action-tool-builder.d.ts +5 -4
- package/dist/native-tools/action-tool-builder.d.ts.map +1 -1
- package/dist/native-tools/action-tool-builder.js +29 -71
- package/dist/native-tools/action-tool-builder.js.map +1 -1
- package/dist/native-tools/json-argument.d.ts +41 -0
- package/dist/native-tools/json-argument.d.ts.map +1 -0
- package/dist/native-tools/json-argument.js +79 -0
- package/dist/native-tools/json-argument.js.map +1 -0
- package/dist/prior-turn-tool-result-cache.d.ts +31 -12
- package/dist/prior-turn-tool-result-cache.d.ts.map +1 -1
- package/dist/prior-turn-tool-result-cache.js +59 -16
- package/dist/prior-turn-tool-result-cache.js.map +1 -1
- package/dist/query-builder-agent.d.ts +13 -4
- package/dist/query-builder-agent.d.ts.map +1 -1
- package/dist/query-builder-agent.js +102 -27
- package/dist/query-builder-agent.js.map +1 -1
- package/dist/realtime/bridge-realtime-session-factory.d.ts +44 -2
- package/dist/realtime/bridge-realtime-session-factory.d.ts.map +1 -1
- package/dist/realtime/bridge-realtime-session-factory.js +68 -20
- package/dist/realtime/bridge-realtime-session-factory.js.map +1 -1
- package/dist/realtime/bridge-realtime-usage-recorder.d.ts +81 -0
- package/dist/realtime/bridge-realtime-usage-recorder.d.ts.map +1 -0
- package/dist/realtime/bridge-realtime-usage-recorder.js +194 -0
- package/dist/realtime/bridge-realtime-usage-recorder.js.map +1 -0
- package/dist/realtime/client-only-channel-server.d.ts +83 -0
- package/dist/realtime/client-only-channel-server.d.ts.map +1 -0
- package/dist/realtime/client-only-channel-server.js +107 -0
- package/dist/realtime/client-only-channel-server.js.map +1 -0
- package/dist/realtime/identity-verification-channel-server.d.ts +50 -0
- package/dist/realtime/identity-verification-channel-server.d.ts.map +1 -0
- package/dist/realtime/identity-verification-channel-server.js +66 -0
- package/dist/realtime/identity-verification-channel-server.js.map +1 -0
- package/dist/realtime/interactive-component-channel-server.d.ts +39 -0
- package/dist/realtime/interactive-component-channel-server.d.ts.map +1 -0
- package/dist/realtime/interactive-component-channel-server.js +55 -0
- package/dist/realtime/interactive-component-channel-server.js.map +1 -0
- package/dist/realtime/realtime-avatar-resolution.d.ts +194 -0
- package/dist/realtime/realtime-avatar-resolution.d.ts.map +1 -0
- package/dist/realtime/realtime-avatar-resolution.js +208 -0
- package/dist/realtime/realtime-avatar-resolution.js.map +1 -0
- package/dist/realtime/realtime-channel-policy.d.ts +81 -0
- package/dist/realtime/realtime-channel-policy.d.ts.map +1 -0
- package/dist/realtime/realtime-channel-policy.js +91 -0
- package/dist/realtime/realtime-channel-policy.js.map +1 -0
- package/dist/realtime/realtime-channel-server-host.d.ts +14 -0
- package/dist/realtime/realtime-channel-server-host.d.ts.map +1 -1
- package/dist/realtime/realtime-channel-server-host.js +35 -0
- package/dist/realtime/realtime-channel-server-host.js.map +1 -1
- package/dist/realtime/realtime-client-session-service.d.ts +435 -34
- package/dist/realtime/realtime-client-session-service.d.ts.map +1 -1
- package/dist/realtime/realtime-client-session-service.js +806 -139
- package/dist/realtime/realtime-client-session-service.js.map +1 -1
- package/dist/realtime/realtime-coagent-config.d.ts +102 -16
- package/dist/realtime/realtime-coagent-config.d.ts.map +1 -1
- package/dist/realtime/realtime-coagent-config.js +126 -5
- package/dist/realtime/realtime-coagent-config.js.map +1 -1
- package/dist/realtime/realtime-recording-ledger.d.ts +130 -0
- package/dist/realtime/realtime-recording-ledger.d.ts.map +1 -0
- package/dist/realtime/realtime-recording-ledger.js +190 -0
- package/dist/realtime/realtime-recording-ledger.js.map +1 -0
- package/dist/realtime/realtime-recording-opus-assembly.d.ts +211 -0
- package/dist/realtime/realtime-recording-opus-assembly.d.ts.map +1 -0
- package/dist/realtime/realtime-recording-opus-assembly.js +706 -0
- package/dist/realtime/realtime-recording-opus-assembly.js.map +1 -0
- package/dist/realtime/realtime-recording-store.d.ts +174 -17
- package/dist/realtime/realtime-recording-store.d.ts.map +1 -1
- package/dist/realtime/realtime-recording-store.js +552 -58
- package/dist/realtime/realtime-recording-store.js.map +1 -1
- package/dist/realtime/realtime-session-runner.js +4 -4
- package/dist/realtime/realtime-session-runner.js.map +1 -1
- package/dist/realtime/realtime-turn-moderator.d.ts +2 -1
- package/dist/realtime/realtime-turn-moderator.d.ts.map +1 -1
- package/dist/realtime/realtime-turn-moderator.js +7 -1
- package/dist/realtime/realtime-turn-moderator.js.map +1 -1
- package/dist/realtime/realtime-vendor-resolution.d.ts +9 -0
- package/dist/realtime/realtime-vendor-resolution.d.ts.map +1 -1
- package/dist/realtime/realtime-vendor-resolution.js +16 -5
- package/dist/realtime/realtime-vendor-resolution.js.map +1 -1
- package/dist/realtime/realtime-video-output-gate.d.ts +83 -0
- package/dist/realtime/realtime-video-output-gate.d.ts.map +1 -0
- package/dist/realtime/realtime-video-output-gate.js +79 -0
- package/dist/realtime/realtime-video-output-gate.js.map +1 -0
- package/dist/tool-result-format.d.ts +14 -0
- package/dist/tool-result-format.d.ts.map +1 -1
- package/dist/tool-result-format.js.map +1 -1
- package/dist/volatile-child-prompt.js +3 -3
- package/package.json +21 -19
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The JSON Schema an Action param declares for its value, from `ActionParam.ValueSchema`
|
|
3
|
+
* when the param has one and from its coarse `ValueType` otherwise — and argument coercion that
|
|
4
|
+
* follows that schema.
|
|
5
|
+
* @module @memberjunction/ai-agents
|
|
6
|
+
*/
|
|
7
|
+
const SCHEMA_TYPE_NAMES = new Set(['string', 'number', 'integer', 'boolean', 'object', 'array', 'null']);
|
|
8
|
+
function isPlainObject(value) {
|
|
9
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
10
|
+
}
|
|
11
|
+
function isSchemaTypeName(value) {
|
|
12
|
+
return typeof value === 'string' && SCHEMA_TYPE_NAMES.has(value);
|
|
13
|
+
}
|
|
14
|
+
function isEnumValue(value) {
|
|
15
|
+
return value === null || ['string', 'number', 'boolean'].includes(typeof value);
|
|
16
|
+
}
|
|
17
|
+
/** Keeps a `type` that names only known JSON types; drops it otherwise. */
|
|
18
|
+
function sanitizeType(raw) {
|
|
19
|
+
if (isSchemaTypeName(raw)) {
|
|
20
|
+
return raw;
|
|
21
|
+
}
|
|
22
|
+
if (Array.isArray(raw) && raw.length > 0 && raw.every(isSchemaTypeName)) {
|
|
23
|
+
return raw;
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
/** Sanitizes each named property, keeping only those whose schema survives. */
|
|
28
|
+
function sanitizeProperties(raw) {
|
|
29
|
+
if (!isPlainObject(raw)) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const properties = {};
|
|
33
|
+
for (const [name, child] of Object.entries(raw)) {
|
|
34
|
+
const sanitized = SanitizeValueSchema(child);
|
|
35
|
+
if (sanitized) {
|
|
36
|
+
properties[name] = sanitized;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return properties;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Keeps a `required` list of names, minus any the schema does not declare as properties — a
|
|
43
|
+
* provider rejects a required name with no property behind it. Empty resolves to undefined.
|
|
44
|
+
*/
|
|
45
|
+
function sanitizeRequired(raw, properties) {
|
|
46
|
+
if (!Array.isArray(raw)) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const names = raw.filter((r) => typeof r === 'string' && (!properties || r in properties));
|
|
50
|
+
return names.length > 0 ? names : undefined;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Copies a stored schema down to the cross-provider subset, recursively.
|
|
54
|
+
*
|
|
55
|
+
* `ValueSchema` is hand-authored metadata, and providers reject a declaration over one bad keyword
|
|
56
|
+
* — the whole request fails, not just this tool. So anything outside the subset (`oneOf`, `$ref`,
|
|
57
|
+
* `format`, a misspelled key, a `type` that names no JSON type) is dropped here rather than passed
|
|
58
|
+
* through. The result is a fresh plain object: the entity accessor returns a live view, and a tool
|
|
59
|
+
* declaration must not write back into the record.
|
|
60
|
+
*
|
|
61
|
+
* @param raw The parsed `ValueSchema` value, or any nested schema inside it
|
|
62
|
+
* @returns The sanitized schema, or null when `raw` is not an object
|
|
63
|
+
*/
|
|
64
|
+
export function SanitizeValueSchema(raw) {
|
|
65
|
+
if (!isPlainObject(raw)) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const schema = {};
|
|
69
|
+
const type = sanitizeType(raw.type);
|
|
70
|
+
if (type !== undefined) {
|
|
71
|
+
schema.type = type;
|
|
72
|
+
}
|
|
73
|
+
if (typeof raw.description === 'string' && raw.description.trim().length > 0) {
|
|
74
|
+
schema.description = raw.description.trim();
|
|
75
|
+
}
|
|
76
|
+
if (Array.isArray(raw.enum) && raw.enum.length > 0 && raw.enum.every(isEnumValue)) {
|
|
77
|
+
schema.enum = [...raw.enum];
|
|
78
|
+
}
|
|
79
|
+
const items = SanitizeValueSchema(raw.items);
|
|
80
|
+
if (items) {
|
|
81
|
+
schema.items = items;
|
|
82
|
+
}
|
|
83
|
+
const properties = sanitizeProperties(raw.properties);
|
|
84
|
+
if (properties) {
|
|
85
|
+
schema.properties = properties;
|
|
86
|
+
}
|
|
87
|
+
const required = sanitizeRequired(raw.required, properties);
|
|
88
|
+
if (required) {
|
|
89
|
+
schema.required = required;
|
|
90
|
+
}
|
|
91
|
+
return schema;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Maps one param's `ValueType` onto a JSON Schema fragment (§8.2 table) — the fallback when the
|
|
95
|
+
* param has no `ValueSchema`.
|
|
96
|
+
*
|
|
97
|
+
* `ActionParam.ValueType` distinguishes only five coarse kinds, so this mapping is lossy by
|
|
98
|
+
* construction and the prose `Description` carries the real type. Choices settled by measurement:
|
|
99
|
+
*
|
|
100
|
+
* - **`Scalar` emits a union type.** It appears to violate the cross-provider common subset —
|
|
101
|
+
* OpenAPI 3.0, which Gemini's classic function declarations follow, has no union `type` — but it
|
|
102
|
+
* measured clean on every provider tested, so the plan's literal mapping stands.
|
|
103
|
+
* - **The opaque kinds emit `string`, not `object`.** `Run Ad-hoc Query.Query` is
|
|
104
|
+
* `ValueType: 'Other'` but holds SQL text, and typing it as an object made models emit
|
|
105
|
+
* `Query: {}` on 40% of calls — well-formed, dispatchable and useless. Switching to `string` took
|
|
106
|
+
* usable arguments from 60% to 100% on the same prompts. The structural type beats the prose
|
|
107
|
+
* description whenever the two disagree, so it must not disagree.
|
|
108
|
+
* - **`Simple Object` emits `object`.** Unlike the opaque kinds it says what the value is, and
|
|
109
|
+
* typing a real object as `string` fails the other way: the model JSON-encodes it, and an Action
|
|
110
|
+
* expecting an object receives text.
|
|
111
|
+
*/
|
|
112
|
+
function schemaForValueType(valueType) {
|
|
113
|
+
switch (valueType) {
|
|
114
|
+
case 'Scalar':
|
|
115
|
+
return { type: ['string', 'number', 'boolean'] };
|
|
116
|
+
case 'Simple Object':
|
|
117
|
+
return { type: 'object' };
|
|
118
|
+
default:
|
|
119
|
+
return { type: 'string' };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The param's stored `ValueSchema`, sanitized, or null when it has none or it cannot be read.
|
|
124
|
+
*
|
|
125
|
+
* Text that is not valid JSON makes the entity accessor throw. A broken schema on one param must
|
|
126
|
+
* not stop the agent from declaring its tools, so that case warns and falls back to `ValueType`.
|
|
127
|
+
*/
|
|
128
|
+
export function GetStoredValueSchema(param) {
|
|
129
|
+
try {
|
|
130
|
+
return SanitizeValueSchema(param.ValueSchemaObject);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
console.warn(`Action param '${param.Name}' has a ValueSchema that is not valid JSON; declaring it from ValueType '${param.ValueType}' instead.`, error);
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The schema of ONE value of this param: the stored `ValueSchema` when present, else the
|
|
139
|
+
* `ValueType` mapping. For an `IsArray` param this is the element schema; the caller wraps it.
|
|
140
|
+
*/
|
|
141
|
+
export function ResolveParamElementSchema(param) {
|
|
142
|
+
return GetStoredValueSchema(param) ?? schemaForValueType(param.ValueType);
|
|
143
|
+
}
|
|
144
|
+
/** The JSON types a schema allows, or null when it does not say. */
|
|
145
|
+
function allowedTypes(schema) {
|
|
146
|
+
if (schema.type === undefined) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
return new Set(Array.isArray(schema.type) ? schema.type : [schema.type]);
|
|
150
|
+
}
|
|
151
|
+
/** Turns a string back into the non-string value the schema asks for, when it unambiguously is one. */
|
|
152
|
+
function decodeString(value, types) {
|
|
153
|
+
const trimmed = value.trim();
|
|
154
|
+
if ((types.has('object') && trimmed.startsWith('{')) || (types.has('array') && trimmed.startsWith('['))) {
|
|
155
|
+
try {
|
|
156
|
+
const decoded = JSON.parse(trimmed);
|
|
157
|
+
const fits = Array.isArray(decoded) ? types.has('array') : isPlainObject(decoded) && types.has('object');
|
|
158
|
+
return fits ? decoded : value;
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return value;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if ((types.has('number') || types.has('integer')) && trimmed.length > 0 && Number.isFinite(Number(trimmed))) {
|
|
165
|
+
const n = Number(trimmed);
|
|
166
|
+
return types.has('number') || Number.isInteger(n) ? n : value;
|
|
167
|
+
}
|
|
168
|
+
if (types.has('boolean') && (trimmed === 'true' || trimmed === 'false')) {
|
|
169
|
+
return trimmed === 'true';
|
|
170
|
+
}
|
|
171
|
+
return value;
|
|
172
|
+
}
|
|
173
|
+
/** Coerces each declared property of an object; undeclared keys pass through untouched. */
|
|
174
|
+
function coerceProperties(value, properties) {
|
|
175
|
+
const result = { ...value };
|
|
176
|
+
for (const [name, child] of Object.entries(properties)) {
|
|
177
|
+
if (name in result) {
|
|
178
|
+
result[name] = CoerceValueToSchema(result[name], child);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Coerces one argument value toward its schema, recursively.
|
|
185
|
+
*
|
|
186
|
+
* Models follow a declared type most of the time, but sometimes send an object as JSON text, a
|
|
187
|
+
* number as `"10"`, or a boolean as `"true"` — and an Action expecting the real type receives text.
|
|
188
|
+
* A string is converted only when the schema does NOT allow strings and the text unambiguously
|
|
189
|
+
* encodes an allowed type; anything else is returned unchanged. A value that still does not fit is
|
|
190
|
+
* the Action's to reject with its own message rather than ours to guess at.
|
|
191
|
+
*
|
|
192
|
+
* @param value The value as the provider returned it
|
|
193
|
+
* @param schema The schema it was declared with
|
|
194
|
+
* @returns The coerced value; `value` is not mutated
|
|
195
|
+
*/
|
|
196
|
+
export function CoerceValueToSchema(value, schema) {
|
|
197
|
+
const types = allowedTypes(schema);
|
|
198
|
+
let current = value;
|
|
199
|
+
if (typeof current === 'string' && types && !types.has('string')) {
|
|
200
|
+
current = decodeString(current, types);
|
|
201
|
+
}
|
|
202
|
+
if (Array.isArray(current) && schema.items) {
|
|
203
|
+
const items = schema.items;
|
|
204
|
+
return current.map((item) => CoerceValueToSchema(item, items));
|
|
205
|
+
}
|
|
206
|
+
if (isPlainObject(current) && schema.properties) {
|
|
207
|
+
return coerceProperties(current, schema.properties);
|
|
208
|
+
}
|
|
209
|
+
return current;
|
|
210
|
+
}
|
|
211
|
+
/** The compact type text for one schema, e.g. `integer`, `"asc"|"desc"`, `{TopCount: integer}`. */
|
|
212
|
+
function inlineType(schema) {
|
|
213
|
+
if (schema.enum) {
|
|
214
|
+
return schema.enum.map((v) => JSON.stringify(v)).join('|');
|
|
215
|
+
}
|
|
216
|
+
const types = schema.type === undefined ? [] : Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
217
|
+
if (types.length === 1 && types[0] === 'array' && schema.items) {
|
|
218
|
+
return `${inlineType(schema.items)}[]`;
|
|
219
|
+
}
|
|
220
|
+
if (schema.properties && Object.keys(schema.properties).length > 0) {
|
|
221
|
+
const required = new Set(schema.required ?? []);
|
|
222
|
+
const fields = Object.entries(schema.properties)
|
|
223
|
+
.map(([name, child]) => `${name}${required.has(name) ? '' : '?'}: ${inlineType(child)}`);
|
|
224
|
+
return `{${fields.join(', ')}}`;
|
|
225
|
+
}
|
|
226
|
+
return types.length > 0 ? types.join('|') : 'any';
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Describes a stored `ValueSchema` in one line for the prose action catalog, so the envelope path
|
|
230
|
+
* tells the model the same type information a native tool declaration does.
|
|
231
|
+
*
|
|
232
|
+
* Nested descriptions are omitted to keep the catalog compact; the shape, required markers and
|
|
233
|
+
* allowed values are what discriminate.
|
|
234
|
+
*/
|
|
235
|
+
export function DescribeValueSchemaInline(schema) {
|
|
236
|
+
return inlineType(schema);
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=action-param-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action-param-schema.js","sourceRoot":"","sources":["../../src/native-tools/action-param-schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,MAAM,iBAAiB,GAAwB,IAAI,GAAG,CAAiB,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,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QAC7D,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;IAC3C,CAAC;IACD,IAAI,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACjE,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;QAChD,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC;aAC3C,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC7F,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;IACpC,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACtD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAAwB;IAC9D,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -60,11 +60,12 @@ export declare function SanitizeToolName(actionName: string): string;
|
|
|
60
60
|
/** @deprecated Use {@link SanitizeToolName}. */
|
|
61
61
|
export declare function sanitizeToolName(actionName: string): string;
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
63
|
+
* Coerces a call's arguments toward each param's declared schema, before the Action runs.
|
|
64
64
|
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
65
|
+
* Models sometimes send an object as a JSON string, a number as `"10"` or a boolean as `"true"`.
|
|
66
|
+
* Each declared param is coerced against the same schema its tool declaration used — the stored
|
|
67
|
+
* `ValueSchema` or the `ValueType` mapping, array-wrapped for `IsArray` — so a param declared as a
|
|
68
|
+
* string (an `Other` param, which may legitimately hold JSON-looking text) is never decoded.
|
|
68
69
|
*
|
|
69
70
|
* @param params The Action's params, as the tool was built from them
|
|
70
71
|
* @param args The call's arguments, as the provider returned them
|
|
@@ -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;
|
|
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;AAG3E,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;IACf,mGAAmG;IACnG,MAAM,EAAE,SAAS,mBAAmB,EAAE,CAAC;C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C,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,mBAAmB,EAAE,OAAO,CAAC;CAChC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,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"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* @fileoverview Maps MJ Actions onto native tool declarations (plan §8.2).
|
|
3
3
|
* @module @memberjunction/ai-agents
|
|
4
4
|
*/
|
|
5
|
+
import { CoerceValueToSchema, ResolveParamElementSchema } from './action-param-schema.js';
|
|
5
6
|
/** Providers cap tool names at 64 characters. */
|
|
6
7
|
const MAX_TOOL_NAME_LENGTH = 64;
|
|
7
8
|
/**
|
|
@@ -46,65 +47,12 @@ export function sanitizeToolName(actionName) {
|
|
|
46
47
|
return SanitizeToolName(actionName);
|
|
47
48
|
}
|
|
48
49
|
/**
|
|
49
|
-
*
|
|
50
|
+
* Coerces a call's arguments toward each param's declared schema, before the Action runs.
|
|
50
51
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* - **`Scalar` emits a union type.** It appears to violate the cross-provider common subset —
|
|
57
|
-
* OpenAPI 3.0, which Gemini's classic function declarations follow, has no union `type` — but it
|
|
58
|
-
* measured clean on every provider tested, so the plan's literal mapping stands.
|
|
59
|
-
* - **The opaque kinds emit `string`, not `object`.** §8.2 originally specified `object` for them,
|
|
60
|
-
* reasoning it was "exact parity with the prose catalog". It is not:
|
|
61
|
-
* `Run Ad-hoc Query.Query` is `ValueType: 'Other'` but holds SQL text, and typing it as an
|
|
62
|
-
* object made models emit `Query: {}` on 40% of calls — well-formed, dispatchable and useless,
|
|
63
|
-
* which no well-formedness check catches. Switching to `string` took usable arguments from
|
|
64
|
-
* 60% to 100% on the same prompts. The structural type beats the prose description whenever the
|
|
65
|
-
* two disagree, so it must not disagree.
|
|
66
|
-
* - **`Simple Object` emits `object`.** Unlike the opaque kinds it says what the value is, and
|
|
67
|
-
* typing a real object as `string` fails the other way: the model JSON-encodes it, and an Action
|
|
68
|
-
* expecting an object receives text. Models still stringify objects now and then, which
|
|
69
|
-
* {@link CoerceActionArguments} absorbs.
|
|
70
|
-
*
|
|
71
|
-
* Both are stopgaps until an action param can carry its own JSON Schema.
|
|
72
|
-
*/
|
|
73
|
-
function schemaForValueType(valueType) {
|
|
74
|
-
switch (valueType) {
|
|
75
|
-
case 'Scalar':
|
|
76
|
-
return { type: ['string', 'number', 'boolean'] };
|
|
77
|
-
case 'Simple Object':
|
|
78
|
-
return { type: 'object' };
|
|
79
|
-
default:
|
|
80
|
-
return { type: 'string' };
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Turns a JSON-encoded string back into the object or array a `Simple Object` param declares.
|
|
85
|
-
*
|
|
86
|
-
* Anything else is returned unchanged — a string that is not JSON, or JSON of the wrong shape, is
|
|
87
|
-
* the Action's to reject with its own message rather than ours to guess at.
|
|
88
|
-
*/
|
|
89
|
-
function decodeObjectValue(value, isArray) {
|
|
90
|
-
if (typeof value !== 'string') {
|
|
91
|
-
return value;
|
|
92
|
-
}
|
|
93
|
-
try {
|
|
94
|
-
const decoded = JSON.parse(value);
|
|
95
|
-
const shapeMatches = isArray ? Array.isArray(decoded) : decoded !== null && typeof decoded === 'object' && !Array.isArray(decoded);
|
|
96
|
-
return shapeMatches ? decoded : value;
|
|
97
|
-
}
|
|
98
|
-
catch {
|
|
99
|
-
return value;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Restores object-typed arguments a model sent as JSON strings, before the Action runs.
|
|
104
|
-
*
|
|
105
|
-
* Only `Simple Object` params are touched: an `Other` param is declared as `string` and may
|
|
106
|
-
* legitimately hold JSON-looking text. For an array param both the array itself and each element
|
|
107
|
-
* may arrive encoded.
|
|
52
|
+
* Models sometimes send an object as a JSON string, a number as `"10"` or a boolean as `"true"`.
|
|
53
|
+
* Each declared param is coerced against the same schema its tool declaration used — the stored
|
|
54
|
+
* `ValueSchema` or the `ValueType` mapping, array-wrapped for `IsArray` — so a param declared as a
|
|
55
|
+
* string (an `Other` param, which may legitimately hold JSON-looking text) is never decoded.
|
|
108
56
|
*
|
|
109
57
|
* @param params The Action's params, as the tool was built from them
|
|
110
58
|
* @param args The call's arguments, as the provider returned them
|
|
@@ -113,13 +61,12 @@ function decodeObjectValue(value, isArray) {
|
|
|
113
61
|
export function CoerceActionArguments(params, args) {
|
|
114
62
|
const coerced = { ...(args ?? {}) };
|
|
115
63
|
for (const param of params) {
|
|
116
|
-
if (
|
|
64
|
+
if (!(param.Name in coerced)) {
|
|
117
65
|
continue;
|
|
118
66
|
}
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
: value;
|
|
67
|
+
const element = ResolveParamElementSchema(param);
|
|
68
|
+
const schema = param.IsArray ? { type: 'array', items: element } : element;
|
|
69
|
+
coerced[param.Name] = CoerceValueToSchema(coerced[param.Name], schema);
|
|
123
70
|
}
|
|
124
71
|
return coerced;
|
|
125
72
|
}
|
|
@@ -129,10 +76,11 @@ export function CoerceActionArguments(params, args) {
|
|
|
129
76
|
* Dropping `DefaultValue` would make the tool strictly less informative than the prose catalog it
|
|
130
77
|
* replaces, which is the one thing this mapping must never be.
|
|
131
78
|
*/
|
|
132
|
-
function describeParam(param) {
|
|
79
|
+
function describeParam(param, schemaDescription) {
|
|
133
80
|
const parts = [];
|
|
134
|
-
|
|
135
|
-
|
|
81
|
+
const description = schemaDescription ?? param.Description;
|
|
82
|
+
if (description) {
|
|
83
|
+
parts.push(description.trim());
|
|
136
84
|
}
|
|
137
85
|
if (param.DefaultValue) {
|
|
138
86
|
parts.push(`Default: ${param.DefaultValue}.`);
|
|
@@ -205,6 +153,20 @@ function describeTool(action, params) {
|
|
|
205
153
|
}
|
|
206
154
|
return `${composeDescription(action, outputs, codes, 0).slice(0, MAX_TOOL_DESCRIPTION_LENGTH - 1).trimEnd()}…`;
|
|
207
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* The property schema one param is declared with.
|
|
158
|
+
*
|
|
159
|
+
* The element schema is the param's stored `ValueSchema` when it has one, else the `ValueType`
|
|
160
|
+
* mapping. `IsArray` wraps it rather than replacing it (§8.2), and the element keeps its own
|
|
161
|
+
* description inside `items`. On a non-array param a description in the stored schema takes the
|
|
162
|
+
* place of the param's `Description`, since the schema author wrote it for this declaration.
|
|
163
|
+
*/
|
|
164
|
+
function declareParam(param) {
|
|
165
|
+
const element = ResolveParamElementSchema(param);
|
|
166
|
+
const schema = param.IsArray ? { type: 'array', items: element } : element;
|
|
167
|
+
const description = describeParam(param, param.IsArray ? undefined : element.description);
|
|
168
|
+
return description ? { ...schema, description } : schema;
|
|
169
|
+
}
|
|
208
170
|
/**
|
|
209
171
|
* Builds the `ChatTool` declaration for one Action.
|
|
210
172
|
*
|
|
@@ -218,11 +180,7 @@ export function BuildToolFromAction(action, params) {
|
|
|
218
180
|
if (param.Type !== 'Input' && param.Type !== 'Both') {
|
|
219
181
|
continue;
|
|
220
182
|
}
|
|
221
|
-
|
|
222
|
-
// IsArray wraps the element schema rather than replacing it (§8.2).
|
|
223
|
-
const schema = param.IsArray ? { type: 'array', items: element } : element;
|
|
224
|
-
const description = describeParam(param);
|
|
225
|
-
properties[param.Name] = description ? { ...schema, description } : schema;
|
|
183
|
+
properties[param.Name] = declareParam(param);
|
|
226
184
|
if (param.IsRequired) {
|
|
227
185
|
required.push(param.Name);
|
|
228
186
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-tool-builder.js","sourceRoot":"","sources":["../../src/native-tools/action-tool-builder.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"action-tool-builder.js","sourceRoot":"","sources":["../../src/native-tools/action-tool-builder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,mBAAmB,EAAyB,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AA4B9G,iDAAiD;AACjD,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEhC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,IAAI,CAAC;AAEhD,4FAA4F;AAC5F,MAAM,yBAAyB,GAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AAE3E;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAAkB;IAC/C,OAAO,UAAU;SACZ,IAAI,EAAE;SACN,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC;SAC9B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,WAAW,EAAE;SACb,KAAK,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC;AACxC,CAAC;AAED,gDAAgD;AAChD,MAAM,UAAU,gBAAgB,CAAC,UAAkB;IAC/C,OAAO,gBAAgB,CAAC,UAAU,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,qBAAqB,CACjC,MAAsC,EACtC,IAAyC;IAEzC,MAAM,OAAO,GAA4B,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,CAAC;IAC7D,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QACzB,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,IAAI,OAAO,CAAC,EAAE,CAAC;YAC3B,SAAS;QACb,CAAC;QACD,MAAM,OAAO,GAAG,yBAAyB,CAAC,KAAK,CAAC,CAAC;QACjD,MAAM,MAA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AQ,GAAG,IAAI,GAAG,CACpB,eAAe;SACV,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,mBAAmB,KAAK,KAAK,IAAI,GAAG,CAAC,QAAQ,CAAC;SAClE,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAE,GAAG,CAAC,QAAmB,CAAC,WAAW,EAAE,CAAC,CAC5D,CAAC;IACF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;AAC9E,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,uBAAuB,CACnC,OAA0C,EAC1C,eAAyD;IAEzD,OAAO,uBAAuB,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;AAC7D,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":"A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