@sogni-ai/sogni-client 5.0.0-alpha.3 → 5.0.0-alpha.4
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/CHANGELOG.md +14 -0
- package/dist/Chat/hostedToolValidation.generated.d.ts +8 -46
- package/dist/Chat/hostedToolValidation.generated.js +17 -303
- package/dist/Chat/hostedToolValidation.generated.js.map +1 -1
- package/dist-esm/Chat/hostedToolValidation.generated.js +13 -300
- package/dist-esm/Chat/hostedToolValidation.generated.js.map +1 -1
- package/package.json +6 -4
- package/src/Chat/hostedToolValidation.generated.ts +25 -452
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [5.0.0-alpha.4](https://github.com/Sogni-AI/sogni-client/compare/v5.0.0-alpha.3...v5.0.0-alpha.4) (2026-05-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** point dev file:// at the renamed sogni-intelligence-client dir ([9e11029](https://github.com/Sogni-AI/sogni-client/commit/9e11029e0439c1140a7b85e4d3d7897e59ea3bac))
|
|
7
|
+
* **deps:** point file:// at canonical wrapper path ([173cff2](https://github.com/Sogni-AI/sogni-client/commit/173cff2eb35d711516acd59905012a87ad63ccb2))
|
|
8
|
+
* **deps:** regenerate lockfile to match renamed sogni-intelligence-client sibling ([d195c2f](https://github.com/Sogni-AI/sogni-client/commit/d195c2f238f72a41da06fb2f0a7c26556cc6724a))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **chat:** replace hostedToolValidation codegen with re-export ([f2fae51](https://github.com/Sogni-AI/sogni-client/commit/f2fae51bcbb42e85077cbe9deaff92f3aac17cd0))
|
|
14
|
+
|
|
1
15
|
# [5.0.0-alpha.3](https://github.com/Sogni-AI/sogni-client/compare/v5.0.0-alpha.2...v5.0.0-alpha.3) (2026-05-16)
|
|
2
16
|
|
|
3
17
|
|
|
@@ -1,46 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
minLength?: number;
|
|
10
|
-
maxLength?: number;
|
|
11
|
-
pattern?: string;
|
|
12
|
-
minItems?: number;
|
|
13
|
-
maxItems?: number;
|
|
14
|
-
items?: HostedToolSchemaProperty | HostedToolSchemaProperty[];
|
|
15
|
-
required?: string[];
|
|
16
|
-
properties?: Record<string, HostedToolSchemaProperty>;
|
|
17
|
-
additionalProperties?: boolean | HostedToolSchemaProperty;
|
|
18
|
-
anyOf?: HostedToolSchemaProperty[];
|
|
19
|
-
oneOf?: HostedToolSchemaProperty[];
|
|
20
|
-
allOf?: HostedToolSchemaProperty[];
|
|
21
|
-
}
|
|
22
|
-
export interface HostedToolSchema extends HostedToolSchemaProperty {
|
|
23
|
-
type?: string | string[];
|
|
24
|
-
}
|
|
25
|
-
export interface HostedToolDefinition {
|
|
26
|
-
function: {
|
|
27
|
-
name: string;
|
|
28
|
-
parameters?: HostedToolSchema;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
export interface ValidateHostedToolArgumentsOptions {
|
|
32
|
-
skipEnumProperties?: string[];
|
|
33
|
-
coercePrimitives?: boolean;
|
|
34
|
-
stripUnknownProperties?: boolean;
|
|
35
|
-
}
|
|
36
|
-
export interface HostedToolArgumentValidationResult {
|
|
37
|
-
ok: boolean;
|
|
38
|
-
errors: string[];
|
|
39
|
-
}
|
|
40
|
-
export interface NormalizeHostedToolArgumentsResult extends HostedToolArgumentValidationResult {
|
|
41
|
-
cleaned: Record<string, unknown>;
|
|
42
|
-
warnings: string[];
|
|
43
|
-
}
|
|
44
|
-
export declare function validateAndNormalizeHostedToolArguments(tools: HostedToolDefinition[], toolName: string, args: Record<string, unknown>, options?: ValidateHostedToolArgumentsOptions): NormalizeHostedToolArgumentsResult;
|
|
45
|
-
export declare function validateHostedToolArguments(tools: HostedToolDefinition[], toolName: string, args: Record<string, unknown>, options?: ValidateHostedToolArgumentsOptions): HostedToolArgumentValidationResult;
|
|
46
|
-
export declare function assertHostedToolArguments(tools: HostedToolDefinition[], toolName: string, args: Record<string, unknown>, options?: ValidateHostedToolArgumentsOptions): void;
|
|
1
|
+
/**
|
|
2
|
+
* Re-export shim for hosted tool validation. The validation logic now lives in
|
|
3
|
+
* `@sogni-ai/sogni-intelligence-client/contracts`; this file remains so existing
|
|
4
|
+
* internal callers (e.g. src/Chat/modelRouting.ts) keep working. New code should
|
|
5
|
+
* import directly from `@sogni-ai/sogni-intelligence-client/contracts`.
|
|
6
|
+
*/
|
|
7
|
+
export type { HostedToolSchemaProperty, HostedToolSchema, HostedToolDefinition, ValidateHostedToolArgumentsOptions, HostedToolArgumentValidationResult, NormalizeHostedToolArgumentsResult } from '@sogni-ai/sogni-intelligence-client/contracts';
|
|
8
|
+
export { validateAndNormalizeHostedToolArguments, validateHostedToolArguments, assertHostedToolArguments } from '@sogni-ai/sogni-intelligence-client/contracts';
|
|
@@ -1,306 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// @ts-nocheck — wrapper's tsconfig (and this file's) uses moduleResolution: 'node'
|
|
4
|
+
// (cannot read modern `exports` map at COMPILE time). At RUNTIME Node's
|
|
5
|
+
// exports-map require-condition resolves the subpath cleanly. The actual types
|
|
6
|
+
// resolve via the package's typesVersions for IDE intellisense; the type-check
|
|
7
|
+
// pass over this file is suppressed.
|
|
8
|
+
/**
|
|
9
|
+
* Re-export shim for hosted tool validation. The validation logic now lives in
|
|
10
|
+
* `@sogni-ai/sogni-intelligence-client/contracts`; this file remains so existing
|
|
11
|
+
* internal callers (e.g. src/Chat/modelRouting.ts) keep working. New code should
|
|
12
|
+
* import directly from `@sogni-ai/sogni-intelligence-client/contracts`.
|
|
13
|
+
*/
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateAndNormalizeHostedToolArguments =
|
|
4
|
-
|
|
5
|
-
exports.
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
case 'array':
|
|
9
|
-
return Array.isArray(value);
|
|
10
|
-
case 'integer':
|
|
11
|
-
return typeof value === 'number' && Number.isInteger(value);
|
|
12
|
-
case 'number':
|
|
13
|
-
return typeof value === 'number' && Number.isFinite(value);
|
|
14
|
-
case 'boolean':
|
|
15
|
-
return typeof value === 'boolean';
|
|
16
|
-
case 'object':
|
|
17
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
18
|
-
case 'string':
|
|
19
|
-
return typeof value === 'string';
|
|
20
|
-
case 'null':
|
|
21
|
-
return value === null;
|
|
22
|
-
default:
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
function typeLabel(type) {
|
|
27
|
-
if (Array.isArray(type))
|
|
28
|
-
return type.join(' or ');
|
|
29
|
-
return type !== null && type !== void 0 ? type : 'valid value';
|
|
30
|
-
}
|
|
31
|
-
function typeList(type) {
|
|
32
|
-
if (!type)
|
|
33
|
-
return [];
|
|
34
|
-
return Array.isArray(type) ? type : [type];
|
|
35
|
-
}
|
|
36
|
-
function formatEnum(values) {
|
|
37
|
-
return values.map(value => JSON.stringify(value)).join(', ');
|
|
38
|
-
}
|
|
39
|
-
function isRecord(value) {
|
|
40
|
-
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
41
|
-
}
|
|
42
|
-
function valuesEqual(left, right) {
|
|
43
|
-
if (Object.is(left, right))
|
|
44
|
-
return true;
|
|
45
|
-
if (typeof left !== typeof right)
|
|
46
|
-
return false;
|
|
47
|
-
if (left === null || right === null)
|
|
48
|
-
return left === right;
|
|
49
|
-
if (typeof left !== 'object')
|
|
50
|
-
return false;
|
|
51
|
-
try {
|
|
52
|
-
return JSON.stringify(left) === JSON.stringify(right);
|
|
53
|
-
}
|
|
54
|
-
catch (_a) {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function coerceValueForTypes(value, allowedTypes) {
|
|
59
|
-
if (typeof value !== 'string')
|
|
60
|
-
return { value, coerced: false };
|
|
61
|
-
const trimmed = value.trim();
|
|
62
|
-
if (!trimmed)
|
|
63
|
-
return { value, coerced: false };
|
|
64
|
-
if (allowedTypes.includes('integer') || allowedTypes.includes('number')) {
|
|
65
|
-
const numberValue = Number(trimmed);
|
|
66
|
-
if (Number.isFinite(numberValue)
|
|
67
|
-
&& (!allowedTypes.includes('integer') || Number.isInteger(numberValue))) {
|
|
68
|
-
return { value: numberValue, coerced: true };
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (allowedTypes.includes('boolean')) {
|
|
72
|
-
if (/^(?:true|false)$/i.test(trimmed)) {
|
|
73
|
-
return { value: trimmed.toLowerCase() === 'true', coerced: true };
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return { value, coerced: false };
|
|
77
|
-
}
|
|
78
|
-
function validateNumberBounds(path, value, schema, errors) {
|
|
79
|
-
if (schema.minimum !== undefined && value < schema.minimum) {
|
|
80
|
-
errors.push(`Argument "${path}" must be at least ${schema.minimum}`);
|
|
81
|
-
}
|
|
82
|
-
if (schema.maximum !== undefined && value > schema.maximum) {
|
|
83
|
-
errors.push(`Argument "${path}" must be at most ${schema.maximum}`);
|
|
84
|
-
}
|
|
85
|
-
if (typeof schema.exclusiveMinimum === 'number' && value <= schema.exclusiveMinimum) {
|
|
86
|
-
errors.push(`Argument "${path}" must be greater than ${schema.exclusiveMinimum}`);
|
|
87
|
-
}
|
|
88
|
-
if (typeof schema.exclusiveMaximum === 'number' && value >= schema.exclusiveMaximum) {
|
|
89
|
-
errors.push(`Argument "${path}" must be less than ${schema.exclusiveMaximum}`);
|
|
90
|
-
}
|
|
91
|
-
if (schema.exclusiveMinimum === true && schema.minimum !== undefined && value <= schema.minimum) {
|
|
92
|
-
errors.push(`Argument "${path}" must be greater than ${schema.minimum}`);
|
|
93
|
-
}
|
|
94
|
-
if (schema.exclusiveMaximum === true && schema.maximum !== undefined && value >= schema.maximum) {
|
|
95
|
-
errors.push(`Argument "${path}" must be less than ${schema.maximum}`);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
function validateStringConstraints(path, value, schema, errors) {
|
|
99
|
-
if (schema.minLength !== undefined && value.length < schema.minLength) {
|
|
100
|
-
errors.push(`Argument "${path}" must contain at least ${schema.minLength} character${schema.minLength === 1 ? '' : 's'}`);
|
|
101
|
-
}
|
|
102
|
-
if (schema.maxLength !== undefined && value.length > schema.maxLength) {
|
|
103
|
-
errors.push(`Argument "${path}" must contain at most ${schema.maxLength} character${schema.maxLength === 1 ? '' : 's'}`);
|
|
104
|
-
}
|
|
105
|
-
if (schema.pattern) {
|
|
106
|
-
try {
|
|
107
|
-
// Hosted-tool schema authors near-universally assume anchored matching
|
|
108
|
-
// for ID-like fields, but JSON Schema `pattern` is unanchored. Auto-anchor
|
|
109
|
-
// to prevent prefix/suffix injection (e.g. `pattern: 'safe-prefix-'` should
|
|
110
|
-
// reject `'evil-safe-prefix-suffix'`). Wrapping with `^(?:...)$` is safe
|
|
111
|
-
// even for already-anchored patterns — `^^…$$` still matches the same set.
|
|
112
|
-
if (!new RegExp(`^(?:${schema.pattern})$`).test(value)) {
|
|
113
|
-
errors.push(`Argument "${path}" must match pattern ${JSON.stringify(schema.pattern)}`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
catch (_a) {
|
|
117
|
-
errors.push(`Schema for "${path}" contains invalid pattern ${JSON.stringify(schema.pattern)}`);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
function validateCompositeSchema(path, value, schema, context) {
|
|
122
|
-
var _a, _b;
|
|
123
|
-
if (schema.allOf) {
|
|
124
|
-
let nextValue = value;
|
|
125
|
-
for (const childSchema of schema.allOf) {
|
|
126
|
-
const result = validateValueAgainstSchema(path, nextValue, childSchema, context);
|
|
127
|
-
nextValue = result.value;
|
|
128
|
-
}
|
|
129
|
-
return { matched: true, value: nextValue };
|
|
130
|
-
}
|
|
131
|
-
const alternatives = (_a = schema.oneOf) !== null && _a !== void 0 ? _a : schema.anyOf;
|
|
132
|
-
if (!alternatives)
|
|
133
|
-
return { matched: true, value };
|
|
134
|
-
const matches = [];
|
|
135
|
-
for (const childSchema of alternatives) {
|
|
136
|
-
const trial = Object.assign(Object.assign({}, context), { errors: [], warnings: [] });
|
|
137
|
-
const result = validateValueAgainstSchema(path, value, childSchema, trial);
|
|
138
|
-
if (trial.errors.length === 0)
|
|
139
|
-
matches.push(result.value);
|
|
140
|
-
}
|
|
141
|
-
if (schema.oneOf && matches.length !== 1) {
|
|
142
|
-
context.errors.push(`Argument "${path}" must match exactly one allowed schema`);
|
|
143
|
-
return { matched: false, value };
|
|
144
|
-
}
|
|
145
|
-
if (schema.anyOf && matches.length < 1) {
|
|
146
|
-
context.errors.push(`Argument "${path}" must match at least one allowed schema`);
|
|
147
|
-
return { matched: false, value };
|
|
148
|
-
}
|
|
149
|
-
return { matched: true, value: (_b = matches[0]) !== null && _b !== void 0 ? _b : value };
|
|
150
|
-
}
|
|
151
|
-
function validateObjectAgainstSchema(path, value, schema, context) {
|
|
152
|
-
var _a, _b;
|
|
153
|
-
const properties = (_a = schema.properties) !== null && _a !== void 0 ? _a : {};
|
|
154
|
-
const cleaned = {};
|
|
155
|
-
for (const required of (_b = schema.required) !== null && _b !== void 0 ? _b : []) {
|
|
156
|
-
const propValue = value[required];
|
|
157
|
-
// Empty string and empty array are treated as missing — schema authors
|
|
158
|
-
// assume `required` means "has a usable value", not "is non-undefined".
|
|
159
|
-
// Empty object is left untouched (some schemas legitimately accept `{}`).
|
|
160
|
-
const isMissing = propValue === undefined
|
|
161
|
-
|| propValue === null
|
|
162
|
-
|| propValue === ''
|
|
163
|
-
|| (Array.isArray(propValue) && propValue.length === 0);
|
|
164
|
-
if (isMissing) {
|
|
165
|
-
context.errors.push(`Missing required argument "${path ? `${path}.` : ''}${required}"`);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
for (const [name, entryValue] of Object.entries(value)) {
|
|
169
|
-
if (entryValue === undefined || entryValue === null) {
|
|
170
|
-
if (name in properties || !context.stripUnknownProperties)
|
|
171
|
-
cleaned[name] = entryValue;
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
const property = properties[name];
|
|
175
|
-
if (!property) {
|
|
176
|
-
if (schema.additionalProperties === false || context.stripUnknownProperties) {
|
|
177
|
-
context.warnings.push(`Stripped unknown argument "${path ? `${path}.` : ''}${name}"`);
|
|
178
|
-
}
|
|
179
|
-
else if (isRecord(schema.additionalProperties)) {
|
|
180
|
-
cleaned[name] = validateValueAgainstSchema(path ? `${path}.${name}` : name, entryValue, schema.additionalProperties, context).value;
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
cleaned[name] = entryValue;
|
|
184
|
-
}
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
cleaned[name] = validateValueAgainstSchema(path ? `${path}.${name}` : name, entryValue, property, context).value;
|
|
188
|
-
}
|
|
189
|
-
return cleaned;
|
|
190
|
-
}
|
|
191
|
-
function validateArrayAgainstSchema(path, value, schema, context) {
|
|
192
|
-
if (schema.minItems !== undefined && value.length < schema.minItems) {
|
|
193
|
-
context.errors.push(`Argument "${path}" must contain at least ${schema.minItems} item${schema.minItems === 1 ? '' : 's'}`);
|
|
194
|
-
}
|
|
195
|
-
if (schema.maxItems !== undefined && value.length > schema.maxItems) {
|
|
196
|
-
context.errors.push(`Argument "${path}" must contain at most ${schema.maxItems} item${schema.maxItems === 1 ? '' : 's'}`);
|
|
197
|
-
}
|
|
198
|
-
if (!schema.items)
|
|
199
|
-
return value;
|
|
200
|
-
if (Array.isArray(schema.items)) {
|
|
201
|
-
const tupleSchemas = schema.items;
|
|
202
|
-
return value.map((item, index) => {
|
|
203
|
-
const itemSchema = tupleSchemas[index];
|
|
204
|
-
return itemSchema
|
|
205
|
-
? validateValueAgainstSchema(`${path}[${index}]`, item, itemSchema, context).value
|
|
206
|
-
: item;
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
return value.map((item, index) => validateValueAgainstSchema(`${path}[${index}]`, item, schema.items, context).value);
|
|
210
|
-
}
|
|
211
|
-
function validateValueAgainstSchema(path, rawValue, schema, context) {
|
|
212
|
-
var _a;
|
|
213
|
-
const composite = validateCompositeSchema(path, rawValue, schema, context);
|
|
214
|
-
if (!composite.matched)
|
|
215
|
-
return { value: rawValue };
|
|
216
|
-
let value = composite.value;
|
|
217
|
-
const allowedTypes = typeList(schema.type);
|
|
218
|
-
if (context.coercePrimitives
|
|
219
|
-
&& allowedTypes.length > 0
|
|
220
|
-
&& !allowedTypes.some(type => matchesType(value, type))) {
|
|
221
|
-
const coerced = coerceValueForTypes(value, allowedTypes);
|
|
222
|
-
if (coerced.coerced) {
|
|
223
|
-
context.warnings.push(`Coerced argument "${path}" to ${typeof coerced.value}`);
|
|
224
|
-
value = coerced.value;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
if (allowedTypes.length > 0 && !allowedTypes.some(type => matchesType(value, type))) {
|
|
228
|
-
context.errors.push(`Argument "${path}" must be ${typeLabel(schema.type)}`);
|
|
229
|
-
return { value };
|
|
230
|
-
}
|
|
231
|
-
if (schema.const !== undefined && !valuesEqual(value, schema.const)) {
|
|
232
|
-
context.errors.push(`Argument "${path}" must be ${JSON.stringify(schema.const)}`);
|
|
233
|
-
}
|
|
234
|
-
if (schema.enum
|
|
235
|
-
&& !context.skipEnumProperties.has(path)
|
|
236
|
-
&& !context.skipEnumProperties.has((_a = path.split('.').at(-1)) !== null && _a !== void 0 ? _a : path)
|
|
237
|
-
&& !schema.enum.some(candidate => valuesEqual(candidate, value))) {
|
|
238
|
-
context.errors.push(`Argument "${path}" must be one of ${formatEnum(schema.enum)}`);
|
|
239
|
-
}
|
|
240
|
-
if (typeof value === 'number') {
|
|
241
|
-
validateNumberBounds(path, value, schema, context.errors);
|
|
242
|
-
}
|
|
243
|
-
if (typeof value === 'string') {
|
|
244
|
-
validateStringConstraints(path, value, schema, context.errors);
|
|
245
|
-
}
|
|
246
|
-
if (Array.isArray(value)) {
|
|
247
|
-
value = validateArrayAgainstSchema(path, value, schema, context);
|
|
248
|
-
}
|
|
249
|
-
if (isRecord(value)) {
|
|
250
|
-
value = validateObjectAgainstSchema(path, value, schema, context);
|
|
251
|
-
}
|
|
252
|
-
return { value };
|
|
253
|
-
}
|
|
254
|
-
function validateAndNormalizeHostedToolArguments(tools, toolName, args, options = {}) {
|
|
255
|
-
var _a, _b;
|
|
256
|
-
if (!args || typeof args !== 'object' || Array.isArray(args)) {
|
|
257
|
-
return {
|
|
258
|
-
ok: false,
|
|
259
|
-
errors: ['Tool arguments must be a JSON object'],
|
|
260
|
-
cleaned: {},
|
|
261
|
-
warnings: [],
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
const tool = tools.find(candidate => candidate.function.name === toolName);
|
|
265
|
-
if (!tool) {
|
|
266
|
-
return {
|
|
267
|
-
ok: false,
|
|
268
|
-
errors: [`Unknown hosted Sogni tool "${toolName}"`],
|
|
269
|
-
cleaned: args,
|
|
270
|
-
warnings: [],
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
const schema = tool.function.parameters;
|
|
274
|
-
if (!schema) {
|
|
275
|
-
return { ok: true, errors: [], cleaned: args, warnings: [] };
|
|
276
|
-
}
|
|
277
|
-
const context = {
|
|
278
|
-
skipEnumProperties: new Set((_a = options.skipEnumProperties) !== null && _a !== void 0 ? _a : ['model']),
|
|
279
|
-
coercePrimitives: options.coercePrimitives === true,
|
|
280
|
-
stripUnknownProperties: options.stripUnknownProperties === true,
|
|
281
|
-
errors: [],
|
|
282
|
-
warnings: [],
|
|
283
|
-
};
|
|
284
|
-
const normalizedSchema = Object.assign(Object.assign({}, schema), { type: (_b = schema.type) !== null && _b !== void 0 ? _b : 'object' });
|
|
285
|
-
const cleaned = validateValueAgainstSchema('', args, normalizedSchema, context).value;
|
|
286
|
-
return {
|
|
287
|
-
ok: context.errors.length === 0,
|
|
288
|
-
errors: context.errors,
|
|
289
|
-
cleaned: isRecord(cleaned) ? cleaned : args,
|
|
290
|
-
warnings: context.warnings,
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
function validateHostedToolArguments(tools, toolName, args, options = {}) {
|
|
294
|
-
const result = validateAndNormalizeHostedToolArguments(tools, toolName, args, options);
|
|
295
|
-
return {
|
|
296
|
-
ok: result.ok,
|
|
297
|
-
errors: result.errors,
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
function assertHostedToolArguments(tools, toolName, args, options) {
|
|
301
|
-
const result = validateHostedToolArguments(tools, toolName, args, options);
|
|
302
|
-
if (!result.ok) {
|
|
303
|
-
throw new Error(`Invalid ${toolName} arguments: ${result.errors.join('; ')}`);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
15
|
+
exports.assertHostedToolArguments = exports.validateHostedToolArguments = exports.validateAndNormalizeHostedToolArguments = void 0;
|
|
16
|
+
var contracts_1 = require("@sogni-ai/sogni-intelligence-client/contracts");
|
|
17
|
+
Object.defineProperty(exports, "validateAndNormalizeHostedToolArguments", { enumerable: true, get: function () { return contracts_1.validateAndNormalizeHostedToolArguments; } });
|
|
18
|
+
Object.defineProperty(exports, "validateHostedToolArguments", { enumerable: true, get: function () { return contracts_1.validateHostedToolArguments; } });
|
|
19
|
+
Object.defineProperty(exports, "assertHostedToolArguments", { enumerable: true, get: function () { return contracts_1.assertHostedToolArguments; } });
|
|
306
20
|
//# sourceMappingURL=hostedToolValidation.generated.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hostedToolValidation.generated.js","sourceRoot":"","sources":["../../src/Chat/hostedToolValidation.generated.ts"],"names":[],"mappings":";;AAyXA,0FAkDC;AAED,kEAWC;AAED,8DAUC;AA/YD,SAAS,WAAW,CAAC,KAAc,EAAE,IAAY;IAC/C,QAAQ,IAAI,EAAE,CAA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IAAI,EAAE,OAAO,CAAC,CAAC;IACvF,OAAO;QACL,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,MAAM,EAAE,MAAM,CAAC,MAAM;KACtB,CAAC;AACJ,CAAC;AAED,SAAgB,yBAAyB,CACvC,KAA6B,EAC7B,QAAgB,EAChB,IAA6B,EAC7B,OAA4C;IAE5C,MAAM,MAAM,GAAG,2BAA2B,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC3E,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,WAAW,QAAQ,eAAe,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAChF,CAAC;AACH,CAAC"}
|
|
1
|
+
{"version":3,"file":"hostedToolValidation.generated.js","sourceRoot":"","sources":["../../src/Chat/hostedToolValidation.generated.ts"],"names":[],"mappings":";AAAA,oBAAoB;AACpB,mFAAmF;AACnF,wEAAwE;AACxE,+EAA+E;AAC/E,+EAA+E;AAC/E,qCAAqC;AACrC;;;;;GAKG;;;AAUH,2EAIuD;AAHrD,oIAAA,uCAAuC,OAAA;AACvC,wHAAA,2BAA2B,OAAA;AAC3B,sHAAA,yBAAyB,OAAA"}
|
|
@@ -1,301 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return typeof value === 'string';
|
|
15
|
-
case 'null':
|
|
16
|
-
return value === null;
|
|
17
|
-
default:
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function typeLabel(type) {
|
|
22
|
-
if (Array.isArray(type))
|
|
23
|
-
return type.join(' or ');
|
|
24
|
-
return type !== null && type !== void 0 ? type : 'valid value';
|
|
25
|
-
}
|
|
26
|
-
function typeList(type) {
|
|
27
|
-
if (!type)
|
|
28
|
-
return [];
|
|
29
|
-
return Array.isArray(type) ? type : [type];
|
|
30
|
-
}
|
|
31
|
-
function formatEnum(values) {
|
|
32
|
-
return values.map(value => JSON.stringify(value)).join(', ');
|
|
33
|
-
}
|
|
34
|
-
function isRecord(value) {
|
|
35
|
-
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
36
|
-
}
|
|
37
|
-
function valuesEqual(left, right) {
|
|
38
|
-
if (Object.is(left, right))
|
|
39
|
-
return true;
|
|
40
|
-
if (typeof left !== typeof right)
|
|
41
|
-
return false;
|
|
42
|
-
if (left === null || right === null)
|
|
43
|
-
return left === right;
|
|
44
|
-
if (typeof left !== 'object')
|
|
45
|
-
return false;
|
|
46
|
-
try {
|
|
47
|
-
return JSON.stringify(left) === JSON.stringify(right);
|
|
48
|
-
}
|
|
49
|
-
catch (_a) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function coerceValueForTypes(value, allowedTypes) {
|
|
54
|
-
if (typeof value !== 'string')
|
|
55
|
-
return { value, coerced: false };
|
|
56
|
-
const trimmed = value.trim();
|
|
57
|
-
if (!trimmed)
|
|
58
|
-
return { value, coerced: false };
|
|
59
|
-
if (allowedTypes.includes('integer') || allowedTypes.includes('number')) {
|
|
60
|
-
const numberValue = Number(trimmed);
|
|
61
|
-
if (Number.isFinite(numberValue)
|
|
62
|
-
&& (!allowedTypes.includes('integer') || Number.isInteger(numberValue))) {
|
|
63
|
-
return { value: numberValue, coerced: true };
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (allowedTypes.includes('boolean')) {
|
|
67
|
-
if (/^(?:true|false)$/i.test(trimmed)) {
|
|
68
|
-
return { value: trimmed.toLowerCase() === 'true', coerced: true };
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return { value, coerced: false };
|
|
72
|
-
}
|
|
73
|
-
function validateNumberBounds(path, value, schema, errors) {
|
|
74
|
-
if (schema.minimum !== undefined && value < schema.minimum) {
|
|
75
|
-
errors.push(`Argument "${path}" must be at least ${schema.minimum}`);
|
|
76
|
-
}
|
|
77
|
-
if (schema.maximum !== undefined && value > schema.maximum) {
|
|
78
|
-
errors.push(`Argument "${path}" must be at most ${schema.maximum}`);
|
|
79
|
-
}
|
|
80
|
-
if (typeof schema.exclusiveMinimum === 'number' && value <= schema.exclusiveMinimum) {
|
|
81
|
-
errors.push(`Argument "${path}" must be greater than ${schema.exclusiveMinimum}`);
|
|
82
|
-
}
|
|
83
|
-
if (typeof schema.exclusiveMaximum === 'number' && value >= schema.exclusiveMaximum) {
|
|
84
|
-
errors.push(`Argument "${path}" must be less than ${schema.exclusiveMaximum}`);
|
|
85
|
-
}
|
|
86
|
-
if (schema.exclusiveMinimum === true && schema.minimum !== undefined && value <= schema.minimum) {
|
|
87
|
-
errors.push(`Argument "${path}" must be greater than ${schema.minimum}`);
|
|
88
|
-
}
|
|
89
|
-
if (schema.exclusiveMaximum === true && schema.maximum !== undefined && value >= schema.maximum) {
|
|
90
|
-
errors.push(`Argument "${path}" must be less than ${schema.maximum}`);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function validateStringConstraints(path, value, schema, errors) {
|
|
94
|
-
if (schema.minLength !== undefined && value.length < schema.minLength) {
|
|
95
|
-
errors.push(`Argument "${path}" must contain at least ${schema.minLength} character${schema.minLength === 1 ? '' : 's'}`);
|
|
96
|
-
}
|
|
97
|
-
if (schema.maxLength !== undefined && value.length > schema.maxLength) {
|
|
98
|
-
errors.push(`Argument "${path}" must contain at most ${schema.maxLength} character${schema.maxLength === 1 ? '' : 's'}`);
|
|
99
|
-
}
|
|
100
|
-
if (schema.pattern) {
|
|
101
|
-
try {
|
|
102
|
-
// Hosted-tool schema authors near-universally assume anchored matching
|
|
103
|
-
// for ID-like fields, but JSON Schema `pattern` is unanchored. Auto-anchor
|
|
104
|
-
// to prevent prefix/suffix injection (e.g. `pattern: 'safe-prefix-'` should
|
|
105
|
-
// reject `'evil-safe-prefix-suffix'`). Wrapping with `^(?:...)$` is safe
|
|
106
|
-
// even for already-anchored patterns — `^^…$$` still matches the same set.
|
|
107
|
-
if (!new RegExp(`^(?:${schema.pattern})$`).test(value)) {
|
|
108
|
-
errors.push(`Argument "${path}" must match pattern ${JSON.stringify(schema.pattern)}`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
catch (_a) {
|
|
112
|
-
errors.push(`Schema for "${path}" contains invalid pattern ${JSON.stringify(schema.pattern)}`);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
function validateCompositeSchema(path, value, schema, context) {
|
|
117
|
-
var _a, _b;
|
|
118
|
-
if (schema.allOf) {
|
|
119
|
-
let nextValue = value;
|
|
120
|
-
for (const childSchema of schema.allOf) {
|
|
121
|
-
const result = validateValueAgainstSchema(path, nextValue, childSchema, context);
|
|
122
|
-
nextValue = result.value;
|
|
123
|
-
}
|
|
124
|
-
return { matched: true, value: nextValue };
|
|
125
|
-
}
|
|
126
|
-
const alternatives = (_a = schema.oneOf) !== null && _a !== void 0 ? _a : schema.anyOf;
|
|
127
|
-
if (!alternatives)
|
|
128
|
-
return { matched: true, value };
|
|
129
|
-
const matches = [];
|
|
130
|
-
for (const childSchema of alternatives) {
|
|
131
|
-
const trial = Object.assign(Object.assign({}, context), { errors: [], warnings: [] });
|
|
132
|
-
const result = validateValueAgainstSchema(path, value, childSchema, trial);
|
|
133
|
-
if (trial.errors.length === 0)
|
|
134
|
-
matches.push(result.value);
|
|
135
|
-
}
|
|
136
|
-
if (schema.oneOf && matches.length !== 1) {
|
|
137
|
-
context.errors.push(`Argument "${path}" must match exactly one allowed schema`);
|
|
138
|
-
return { matched: false, value };
|
|
139
|
-
}
|
|
140
|
-
if (schema.anyOf && matches.length < 1) {
|
|
141
|
-
context.errors.push(`Argument "${path}" must match at least one allowed schema`);
|
|
142
|
-
return { matched: false, value };
|
|
143
|
-
}
|
|
144
|
-
return { matched: true, value: (_b = matches[0]) !== null && _b !== void 0 ? _b : value };
|
|
145
|
-
}
|
|
146
|
-
function validateObjectAgainstSchema(path, value, schema, context) {
|
|
147
|
-
var _a, _b;
|
|
148
|
-
const properties = (_a = schema.properties) !== null && _a !== void 0 ? _a : {};
|
|
149
|
-
const cleaned = {};
|
|
150
|
-
for (const required of (_b = schema.required) !== null && _b !== void 0 ? _b : []) {
|
|
151
|
-
const propValue = value[required];
|
|
152
|
-
// Empty string and empty array are treated as missing — schema authors
|
|
153
|
-
// assume `required` means "has a usable value", not "is non-undefined".
|
|
154
|
-
// Empty object is left untouched (some schemas legitimately accept `{}`).
|
|
155
|
-
const isMissing = propValue === undefined
|
|
156
|
-
|| propValue === null
|
|
157
|
-
|| propValue === ''
|
|
158
|
-
|| (Array.isArray(propValue) && propValue.length === 0);
|
|
159
|
-
if (isMissing) {
|
|
160
|
-
context.errors.push(`Missing required argument "${path ? `${path}.` : ''}${required}"`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
for (const [name, entryValue] of Object.entries(value)) {
|
|
164
|
-
if (entryValue === undefined || entryValue === null) {
|
|
165
|
-
if (name in properties || !context.stripUnknownProperties)
|
|
166
|
-
cleaned[name] = entryValue;
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
const property = properties[name];
|
|
170
|
-
if (!property) {
|
|
171
|
-
if (schema.additionalProperties === false || context.stripUnknownProperties) {
|
|
172
|
-
context.warnings.push(`Stripped unknown argument "${path ? `${path}.` : ''}${name}"`);
|
|
173
|
-
}
|
|
174
|
-
else if (isRecord(schema.additionalProperties)) {
|
|
175
|
-
cleaned[name] = validateValueAgainstSchema(path ? `${path}.${name}` : name, entryValue, schema.additionalProperties, context).value;
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
cleaned[name] = entryValue;
|
|
179
|
-
}
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
cleaned[name] = validateValueAgainstSchema(path ? `${path}.${name}` : name, entryValue, property, context).value;
|
|
183
|
-
}
|
|
184
|
-
return cleaned;
|
|
185
|
-
}
|
|
186
|
-
function validateArrayAgainstSchema(path, value, schema, context) {
|
|
187
|
-
if (schema.minItems !== undefined && value.length < schema.minItems) {
|
|
188
|
-
context.errors.push(`Argument "${path}" must contain at least ${schema.minItems} item${schema.minItems === 1 ? '' : 's'}`);
|
|
189
|
-
}
|
|
190
|
-
if (schema.maxItems !== undefined && value.length > schema.maxItems) {
|
|
191
|
-
context.errors.push(`Argument "${path}" must contain at most ${schema.maxItems} item${schema.maxItems === 1 ? '' : 's'}`);
|
|
192
|
-
}
|
|
193
|
-
if (!schema.items)
|
|
194
|
-
return value;
|
|
195
|
-
if (Array.isArray(schema.items)) {
|
|
196
|
-
const tupleSchemas = schema.items;
|
|
197
|
-
return value.map((item, index) => {
|
|
198
|
-
const itemSchema = tupleSchemas[index];
|
|
199
|
-
return itemSchema
|
|
200
|
-
? validateValueAgainstSchema(`${path}[${index}]`, item, itemSchema, context).value
|
|
201
|
-
: item;
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
return value.map((item, index) => validateValueAgainstSchema(`${path}[${index}]`, item, schema.items, context).value);
|
|
205
|
-
}
|
|
206
|
-
function validateValueAgainstSchema(path, rawValue, schema, context) {
|
|
207
|
-
var _a;
|
|
208
|
-
const composite = validateCompositeSchema(path, rawValue, schema, context);
|
|
209
|
-
if (!composite.matched)
|
|
210
|
-
return { value: rawValue };
|
|
211
|
-
let value = composite.value;
|
|
212
|
-
const allowedTypes = typeList(schema.type);
|
|
213
|
-
if (context.coercePrimitives
|
|
214
|
-
&& allowedTypes.length > 0
|
|
215
|
-
&& !allowedTypes.some(type => matchesType(value, type))) {
|
|
216
|
-
const coerced = coerceValueForTypes(value, allowedTypes);
|
|
217
|
-
if (coerced.coerced) {
|
|
218
|
-
context.warnings.push(`Coerced argument "${path}" to ${typeof coerced.value}`);
|
|
219
|
-
value = coerced.value;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
if (allowedTypes.length > 0 && !allowedTypes.some(type => matchesType(value, type))) {
|
|
223
|
-
context.errors.push(`Argument "${path}" must be ${typeLabel(schema.type)}`);
|
|
224
|
-
return { value };
|
|
225
|
-
}
|
|
226
|
-
if (schema.const !== undefined && !valuesEqual(value, schema.const)) {
|
|
227
|
-
context.errors.push(`Argument "${path}" must be ${JSON.stringify(schema.const)}`);
|
|
228
|
-
}
|
|
229
|
-
if (schema.enum
|
|
230
|
-
&& !context.skipEnumProperties.has(path)
|
|
231
|
-
&& !context.skipEnumProperties.has((_a = path.split('.').at(-1)) !== null && _a !== void 0 ? _a : path)
|
|
232
|
-
&& !schema.enum.some(candidate => valuesEqual(candidate, value))) {
|
|
233
|
-
context.errors.push(`Argument "${path}" must be one of ${formatEnum(schema.enum)}`);
|
|
234
|
-
}
|
|
235
|
-
if (typeof value === 'number') {
|
|
236
|
-
validateNumberBounds(path, value, schema, context.errors);
|
|
237
|
-
}
|
|
238
|
-
if (typeof value === 'string') {
|
|
239
|
-
validateStringConstraints(path, value, schema, context.errors);
|
|
240
|
-
}
|
|
241
|
-
if (Array.isArray(value)) {
|
|
242
|
-
value = validateArrayAgainstSchema(path, value, schema, context);
|
|
243
|
-
}
|
|
244
|
-
if (isRecord(value)) {
|
|
245
|
-
value = validateObjectAgainstSchema(path, value, schema, context);
|
|
246
|
-
}
|
|
247
|
-
return { value };
|
|
248
|
-
}
|
|
249
|
-
export function validateAndNormalizeHostedToolArguments(tools, toolName, args, options = {}) {
|
|
250
|
-
var _a, _b;
|
|
251
|
-
if (!args || typeof args !== 'object' || Array.isArray(args)) {
|
|
252
|
-
return {
|
|
253
|
-
ok: false,
|
|
254
|
-
errors: ['Tool arguments must be a JSON object'],
|
|
255
|
-
cleaned: {},
|
|
256
|
-
warnings: [],
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
const tool = tools.find(candidate => candidate.function.name === toolName);
|
|
260
|
-
if (!tool) {
|
|
261
|
-
return {
|
|
262
|
-
ok: false,
|
|
263
|
-
errors: [`Unknown hosted Sogni tool "${toolName}"`],
|
|
264
|
-
cleaned: args,
|
|
265
|
-
warnings: [],
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
const schema = tool.function.parameters;
|
|
269
|
-
if (!schema) {
|
|
270
|
-
return { ok: true, errors: [], cleaned: args, warnings: [] };
|
|
271
|
-
}
|
|
272
|
-
const context = {
|
|
273
|
-
skipEnumProperties: new Set((_a = options.skipEnumProperties) !== null && _a !== void 0 ? _a : ['model']),
|
|
274
|
-
coercePrimitives: options.coercePrimitives === true,
|
|
275
|
-
stripUnknownProperties: options.stripUnknownProperties === true,
|
|
276
|
-
errors: [],
|
|
277
|
-
warnings: [],
|
|
278
|
-
};
|
|
279
|
-
const normalizedSchema = Object.assign(Object.assign({}, schema), { type: (_b = schema.type) !== null && _b !== void 0 ? _b : 'object' });
|
|
280
|
-
const cleaned = validateValueAgainstSchema('', args, normalizedSchema, context).value;
|
|
281
|
-
return {
|
|
282
|
-
ok: context.errors.length === 0,
|
|
283
|
-
errors: context.errors,
|
|
284
|
-
cleaned: isRecord(cleaned) ? cleaned : args,
|
|
285
|
-
warnings: context.warnings,
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
export function validateHostedToolArguments(tools, toolName, args, options = {}) {
|
|
289
|
-
const result = validateAndNormalizeHostedToolArguments(tools, toolName, args, options);
|
|
290
|
-
return {
|
|
291
|
-
ok: result.ok,
|
|
292
|
-
errors: result.errors,
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
export function assertHostedToolArguments(tools, toolName, args, options) {
|
|
296
|
-
const result = validateHostedToolArguments(tools, toolName, args, options);
|
|
297
|
-
if (!result.ok) {
|
|
298
|
-
throw new Error(`Invalid ${toolName} arguments: ${result.errors.join('; ')}`);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// @ts-nocheck — wrapper's tsconfig (and this file's) uses moduleResolution: 'node'
|
|
3
|
+
// (cannot read modern `exports` map at COMPILE time). At RUNTIME Node's
|
|
4
|
+
// exports-map require-condition resolves the subpath cleanly. The actual types
|
|
5
|
+
// resolve via the package's typesVersions for IDE intellisense; the type-check
|
|
6
|
+
// pass over this file is suppressed.
|
|
7
|
+
/**
|
|
8
|
+
* Re-export shim for hosted tool validation. The validation logic now lives in
|
|
9
|
+
* `@sogni-ai/sogni-intelligence-client/contracts`; this file remains so existing
|
|
10
|
+
* internal callers (e.g. src/Chat/modelRouting.ts) keep working. New code should
|
|
11
|
+
* import directly from `@sogni-ai/sogni-intelligence-client/contracts`.
|
|
12
|
+
*/
|
|
13
|
+
export { validateAndNormalizeHostedToolArguments, validateHostedToolArguments, assertHostedToolArguments } from '@sogni-ai/sogni-intelligence-client/contracts';
|
|
301
14
|
//# sourceMappingURL=hostedToolValidation.generated.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hostedToolValidation.generated.js","sourceRoot":"","sources":["../../src/Chat/hostedToolValidation.generated.ts"],"names":[],"mappings":"AAqDA,SAAS,WAAW,CAAC,KAAc,EAAE,IAAY;IAC/C,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,OAAO;YACV,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC9B,KAAK,SAAS;YACZ,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC9D,KAAK,QAAQ;YACX,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC7D,KAAK,SAAS;YACZ,OAAO,OAAO,KAAK,KAAK,SAAS,CAAC;QACpC,KAAK,QAAQ;YACX,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QA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AAC;IAChF,CAAC;AACH,CAAC"}
|
|
1
|
+
{"version":3,"file":"hostedToolValidation.generated.js","sourceRoot":"","sources":["../../src/Chat/hostedToolValidation.generated.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,mFAAmF;AACnF,wEAAwE;AACxE,+EAA+E;AAC/E,+EAA+E;AAC/E,qCAAqC;AACrC;;;;;GAKG;AAUH,OAAO,EACL,uCAAuC,EACvC,2BAA2B,EAC3B,yBAAyB,EAC1B,MAAM,+CAA+C,CAAC"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "5.0.0-alpha.
|
|
6
|
+
"version": "5.0.0-alpha.4",
|
|
7
7
|
"engines": {
|
|
8
8
|
"node": ">=22"
|
|
9
9
|
},
|
|
@@ -57,9 +57,7 @@
|
|
|
57
57
|
"clean": "rimraf ./dist ./dist-esm",
|
|
58
58
|
"prepublishOnly": "npm run build",
|
|
59
59
|
"build": "npm run clean && tsc --project tsconfig.json && tsc --project tsconfig.esm.json && node scripts/write-dist-esm-package-json.mjs",
|
|
60
|
-
"test:chat-routing": "npm run
|
|
61
|
-
"sync:hosted-tool-validation": "node scripts/sync-hosted-tool-validation.mjs",
|
|
62
|
-
"check:hosted-tool-validation": "node scripts/sync-hosted-tool-validation.mjs --check",
|
|
60
|
+
"test:chat-routing": "npm run build && node scripts/check-chat-model-routing.cjs",
|
|
63
61
|
"sync:hosted-tools-manifest": "node scripts/sync-hosted-tools-manifest.mjs",
|
|
64
62
|
"check:hosted-tools-manifest": "node scripts/sync-hosted-tools-manifest.mjs --check",
|
|
65
63
|
"watch": "npm run clean && tsc --watch --project tsconfig.json",
|
|
@@ -93,11 +91,15 @@
|
|
|
93
91
|
"lodash": "^4.18.1",
|
|
94
92
|
"ws": "^8.18.0"
|
|
95
93
|
},
|
|
94
|
+
"peerDependencies": {
|
|
95
|
+
"@sogni-ai/sogni-intelligence-client": "^3.0.0-alpha.0"
|
|
96
|
+
},
|
|
96
97
|
"devDependencies": {
|
|
97
98
|
"@commitlint/cli": "^20.5.3",
|
|
98
99
|
"@commitlint/config-conventional": "^20.5.3",
|
|
99
100
|
"@semantic-release/changelog": "^6.0.3",
|
|
100
101
|
"@semantic-release/git": "^10.0.1",
|
|
102
|
+
"@sogni-ai/sogni-intelligence-client": "file:../sogni-intelligence-client",
|
|
101
103
|
"husky": "^9.1.7",
|
|
102
104
|
"prettier": "^3.3.3",
|
|
103
105
|
"rimraf": "^6.0.1",
|
|
@@ -1,453 +1,26 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export interface HostedToolSchema extends HostedToolSchemaProperty {
|
|
28
|
-
type?: string | string[];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface HostedToolDefinition {
|
|
32
|
-
function: {
|
|
33
|
-
name: string;
|
|
34
|
-
parameters?: HostedToolSchema;
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface ValidateHostedToolArgumentsOptions {
|
|
39
|
-
skipEnumProperties?: string[];
|
|
40
|
-
coercePrimitives?: boolean;
|
|
41
|
-
stripUnknownProperties?: boolean;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface HostedToolArgumentValidationResult {
|
|
45
|
-
ok: boolean;
|
|
46
|
-
errors: string[];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface NormalizeHostedToolArgumentsResult extends HostedToolArgumentValidationResult {
|
|
50
|
-
cleaned: Record<string, unknown>;
|
|
51
|
-
warnings: string[];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function matchesType(value: unknown, type: string): boolean {
|
|
55
|
-
switch (type) {
|
|
56
|
-
case 'array':
|
|
57
|
-
return Array.isArray(value);
|
|
58
|
-
case 'integer':
|
|
59
|
-
return typeof value === 'number' && Number.isInteger(value);
|
|
60
|
-
case 'number':
|
|
61
|
-
return typeof value === 'number' && Number.isFinite(value);
|
|
62
|
-
case 'boolean':
|
|
63
|
-
return typeof value === 'boolean';
|
|
64
|
-
case 'object':
|
|
65
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
66
|
-
case 'string':
|
|
67
|
-
return typeof value === 'string';
|
|
68
|
-
case 'null':
|
|
69
|
-
return value === null;
|
|
70
|
-
default:
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function typeLabel(type: string | string[] | undefined): string {
|
|
76
|
-
if (Array.isArray(type)) return type.join(' or ');
|
|
77
|
-
return type ?? 'valid value';
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function typeList(type: string | string[] | undefined): string[] {
|
|
81
|
-
if (!type) return [];
|
|
82
|
-
return Array.isArray(type) ? type : [type];
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function formatEnum(values: unknown[]): string {
|
|
86
|
-
return values.map(value => JSON.stringify(value)).join(', ');
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
90
|
-
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function valuesEqual(left: unknown, right: unknown): boolean {
|
|
94
|
-
if (Object.is(left, right)) return true;
|
|
95
|
-
if (typeof left !== typeof right) return false;
|
|
96
|
-
if (left === null || right === null) return left === right;
|
|
97
|
-
if (typeof left !== 'object') return false;
|
|
98
|
-
try {
|
|
99
|
-
return JSON.stringify(left) === JSON.stringify(right);
|
|
100
|
-
} catch {
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function coerceValueForTypes(
|
|
106
|
-
value: unknown,
|
|
107
|
-
allowedTypes: string[],
|
|
108
|
-
): { value: unknown; coerced: boolean } {
|
|
109
|
-
if (typeof value !== 'string') return { value, coerced: false };
|
|
110
|
-
const trimmed = value.trim();
|
|
111
|
-
if (!trimmed) return { value, coerced: false };
|
|
112
|
-
|
|
113
|
-
if (allowedTypes.includes('integer') || allowedTypes.includes('number')) {
|
|
114
|
-
const numberValue = Number(trimmed);
|
|
115
|
-
if (
|
|
116
|
-
Number.isFinite(numberValue)
|
|
117
|
-
&& (!allowedTypes.includes('integer') || Number.isInteger(numberValue))
|
|
118
|
-
) {
|
|
119
|
-
return { value: numberValue, coerced: true };
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (allowedTypes.includes('boolean')) {
|
|
124
|
-
if (/^(?:true|false)$/i.test(trimmed)) {
|
|
125
|
-
return { value: trimmed.toLowerCase() === 'true', coerced: true };
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return { value, coerced: false };
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
interface SchemaValidationContext {
|
|
133
|
-
skipEnumProperties: Set<string>;
|
|
134
|
-
coercePrimitives: boolean;
|
|
135
|
-
stripUnknownProperties: boolean;
|
|
136
|
-
errors: string[];
|
|
137
|
-
warnings: string[];
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function validateNumberBounds(
|
|
141
|
-
path: string,
|
|
142
|
-
value: number,
|
|
143
|
-
schema: HostedToolSchemaProperty,
|
|
144
|
-
errors: string[],
|
|
145
|
-
): void {
|
|
146
|
-
if (schema.minimum !== undefined && value < schema.minimum) {
|
|
147
|
-
errors.push(`Argument "${path}" must be at least ${schema.minimum}`);
|
|
148
|
-
}
|
|
149
|
-
if (schema.maximum !== undefined && value > schema.maximum) {
|
|
150
|
-
errors.push(`Argument "${path}" must be at most ${schema.maximum}`);
|
|
151
|
-
}
|
|
152
|
-
if (typeof schema.exclusiveMinimum === 'number' && value <= schema.exclusiveMinimum) {
|
|
153
|
-
errors.push(`Argument "${path}" must be greater than ${schema.exclusiveMinimum}`);
|
|
154
|
-
}
|
|
155
|
-
if (typeof schema.exclusiveMaximum === 'number' && value >= schema.exclusiveMaximum) {
|
|
156
|
-
errors.push(`Argument "${path}" must be less than ${schema.exclusiveMaximum}`);
|
|
157
|
-
}
|
|
158
|
-
if (schema.exclusiveMinimum === true && schema.minimum !== undefined && value <= schema.minimum) {
|
|
159
|
-
errors.push(`Argument "${path}" must be greater than ${schema.minimum}`);
|
|
160
|
-
}
|
|
161
|
-
if (schema.exclusiveMaximum === true && schema.maximum !== undefined && value >= schema.maximum) {
|
|
162
|
-
errors.push(`Argument "${path}" must be less than ${schema.maximum}`);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function validateStringConstraints(
|
|
167
|
-
path: string,
|
|
168
|
-
value: string,
|
|
169
|
-
schema: HostedToolSchemaProperty,
|
|
170
|
-
errors: string[],
|
|
171
|
-
): void {
|
|
172
|
-
if (schema.minLength !== undefined && value.length < schema.minLength) {
|
|
173
|
-
errors.push(`Argument "${path}" must contain at least ${schema.minLength} character${schema.minLength === 1 ? '' : 's'}`);
|
|
174
|
-
}
|
|
175
|
-
if (schema.maxLength !== undefined && value.length > schema.maxLength) {
|
|
176
|
-
errors.push(`Argument "${path}" must contain at most ${schema.maxLength} character${schema.maxLength === 1 ? '' : 's'}`);
|
|
177
|
-
}
|
|
178
|
-
if (schema.pattern) {
|
|
179
|
-
try {
|
|
180
|
-
// Hosted-tool schema authors near-universally assume anchored matching
|
|
181
|
-
// for ID-like fields, but JSON Schema `pattern` is unanchored. Auto-anchor
|
|
182
|
-
// to prevent prefix/suffix injection (e.g. `pattern: 'safe-prefix-'` should
|
|
183
|
-
// reject `'evil-safe-prefix-suffix'`). Wrapping with `^(?:...)$` is safe
|
|
184
|
-
// even for already-anchored patterns — `^^…$$` still matches the same set.
|
|
185
|
-
if (!new RegExp(`^(?:${schema.pattern})$`).test(value)) {
|
|
186
|
-
errors.push(`Argument "${path}" must match pattern ${JSON.stringify(schema.pattern)}`);
|
|
187
|
-
}
|
|
188
|
-
} catch {
|
|
189
|
-
errors.push(`Schema for "${path}" contains invalid pattern ${JSON.stringify(schema.pattern)}`);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function validateCompositeSchema(
|
|
195
|
-
path: string,
|
|
196
|
-
value: unknown,
|
|
197
|
-
schema: HostedToolSchemaProperty,
|
|
198
|
-
context: SchemaValidationContext,
|
|
199
|
-
): { matched: boolean; value: unknown } {
|
|
200
|
-
if (schema.allOf) {
|
|
201
|
-
let nextValue = value;
|
|
202
|
-
for (const childSchema of schema.allOf) {
|
|
203
|
-
const result = validateValueAgainstSchema(path, nextValue, childSchema, context);
|
|
204
|
-
nextValue = result.value;
|
|
205
|
-
}
|
|
206
|
-
return { matched: true, value: nextValue };
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const alternatives = schema.oneOf ?? schema.anyOf;
|
|
210
|
-
if (!alternatives) return { matched: true, value };
|
|
211
|
-
|
|
212
|
-
const matches: unknown[] = [];
|
|
213
|
-
for (const childSchema of alternatives) {
|
|
214
|
-
const trial: SchemaValidationContext = {
|
|
215
|
-
...context,
|
|
216
|
-
errors: [],
|
|
217
|
-
warnings: [],
|
|
218
|
-
};
|
|
219
|
-
const result = validateValueAgainstSchema(path, value, childSchema, trial);
|
|
220
|
-
if (trial.errors.length === 0) matches.push(result.value);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (schema.oneOf && matches.length !== 1) {
|
|
224
|
-
context.errors.push(`Argument "${path}" must match exactly one allowed schema`);
|
|
225
|
-
return { matched: false, value };
|
|
226
|
-
}
|
|
227
|
-
if (schema.anyOf && matches.length < 1) {
|
|
228
|
-
context.errors.push(`Argument "${path}" must match at least one allowed schema`);
|
|
229
|
-
return { matched: false, value };
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
return { matched: true, value: matches[0] ?? value };
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function validateObjectAgainstSchema(
|
|
236
|
-
path: string,
|
|
237
|
-
value: Record<string, unknown>,
|
|
238
|
-
schema: HostedToolSchemaProperty,
|
|
239
|
-
context: SchemaValidationContext,
|
|
240
|
-
): Record<string, unknown> {
|
|
241
|
-
const properties = schema.properties ?? {};
|
|
242
|
-
const cleaned: Record<string, unknown> = {};
|
|
243
|
-
|
|
244
|
-
for (const required of schema.required ?? []) {
|
|
245
|
-
const propValue = value[required];
|
|
246
|
-
// Empty string and empty array are treated as missing — schema authors
|
|
247
|
-
// assume `required` means "has a usable value", not "is non-undefined".
|
|
248
|
-
// Empty object is left untouched (some schemas legitimately accept `{}`).
|
|
249
|
-
const isMissing =
|
|
250
|
-
propValue === undefined
|
|
251
|
-
|| propValue === null
|
|
252
|
-
|| propValue === ''
|
|
253
|
-
|| (Array.isArray(propValue) && propValue.length === 0);
|
|
254
|
-
if (isMissing) {
|
|
255
|
-
context.errors.push(`Missing required argument "${path ? `${path}.` : ''}${required}"`);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
for (const [name, entryValue] of Object.entries(value)) {
|
|
260
|
-
if (entryValue === undefined || entryValue === null) {
|
|
261
|
-
if (name in properties || !context.stripUnknownProperties) cleaned[name] = entryValue;
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
const property = properties[name];
|
|
266
|
-
if (!property) {
|
|
267
|
-
if (schema.additionalProperties === false || context.stripUnknownProperties) {
|
|
268
|
-
context.warnings.push(`Stripped unknown argument "${path ? `${path}.` : ''}${name}"`);
|
|
269
|
-
} else if (isRecord(schema.additionalProperties)) {
|
|
270
|
-
cleaned[name] = validateValueAgainstSchema(
|
|
271
|
-
path ? `${path}.${name}` : name,
|
|
272
|
-
entryValue,
|
|
273
|
-
schema.additionalProperties,
|
|
274
|
-
context,
|
|
275
|
-
).value;
|
|
276
|
-
} else {
|
|
277
|
-
cleaned[name] = entryValue;
|
|
278
|
-
}
|
|
279
|
-
continue;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
cleaned[name] = validateValueAgainstSchema(
|
|
283
|
-
path ? `${path}.${name}` : name,
|
|
284
|
-
entryValue,
|
|
285
|
-
property,
|
|
286
|
-
context,
|
|
287
|
-
).value;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
return cleaned;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
function validateArrayAgainstSchema(
|
|
294
|
-
path: string,
|
|
295
|
-
value: unknown[],
|
|
296
|
-
schema: HostedToolSchemaProperty,
|
|
297
|
-
context: SchemaValidationContext,
|
|
298
|
-
): unknown[] {
|
|
299
|
-
if (schema.minItems !== undefined && value.length < schema.minItems) {
|
|
300
|
-
context.errors.push(`Argument "${path}" must contain at least ${schema.minItems} item${schema.minItems === 1 ? '' : 's'}`);
|
|
301
|
-
}
|
|
302
|
-
if (schema.maxItems !== undefined && value.length > schema.maxItems) {
|
|
303
|
-
context.errors.push(`Argument "${path}" must contain at most ${schema.maxItems} item${schema.maxItems === 1 ? '' : 's'}`);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
if (!schema.items) return value;
|
|
307
|
-
|
|
308
|
-
if (Array.isArray(schema.items)) {
|
|
309
|
-
const tupleSchemas = schema.items;
|
|
310
|
-
return value.map((item, index) => {
|
|
311
|
-
const itemSchema = tupleSchemas[index];
|
|
312
|
-
return itemSchema
|
|
313
|
-
? validateValueAgainstSchema(`${path}[${index}]`, item, itemSchema, context).value
|
|
314
|
-
: item;
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
return value.map((item, index) => validateValueAgainstSchema(`${path}[${index}]`, item, schema.items as HostedToolSchemaProperty, context).value);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
function validateValueAgainstSchema(
|
|
322
|
-
path: string,
|
|
323
|
-
rawValue: unknown,
|
|
324
|
-
schema: HostedToolSchemaProperty,
|
|
325
|
-
context: SchemaValidationContext,
|
|
326
|
-
): { value: unknown } {
|
|
327
|
-
const composite = validateCompositeSchema(path, rawValue, schema, context);
|
|
328
|
-
if (!composite.matched) return { value: rawValue };
|
|
329
|
-
let value = composite.value;
|
|
330
|
-
|
|
331
|
-
const allowedTypes = typeList(schema.type);
|
|
332
|
-
if (
|
|
333
|
-
context.coercePrimitives
|
|
334
|
-
&& allowedTypes.length > 0
|
|
335
|
-
&& !allowedTypes.some(type => matchesType(value, type))
|
|
336
|
-
) {
|
|
337
|
-
const coerced = coerceValueForTypes(value, allowedTypes);
|
|
338
|
-
if (coerced.coerced) {
|
|
339
|
-
context.warnings.push(`Coerced argument "${path}" to ${typeof coerced.value}`);
|
|
340
|
-
value = coerced.value;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
if (allowedTypes.length > 0 && !allowedTypes.some(type => matchesType(value, type))) {
|
|
345
|
-
context.errors.push(`Argument "${path}" must be ${typeLabel(schema.type)}`);
|
|
346
|
-
return { value };
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
if (schema.const !== undefined && !valuesEqual(value, schema.const)) {
|
|
350
|
-
context.errors.push(`Argument "${path}" must be ${JSON.stringify(schema.const)}`);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
if (
|
|
354
|
-
schema.enum
|
|
355
|
-
&& !context.skipEnumProperties.has(path)
|
|
356
|
-
&& !context.skipEnumProperties.has(path.split('.').at(-1) ?? path)
|
|
357
|
-
&& !schema.enum.some(candidate => valuesEqual(candidate, value))
|
|
358
|
-
) {
|
|
359
|
-
context.errors.push(`Argument "${path}" must be one of ${formatEnum(schema.enum)}`);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
if (typeof value === 'number') {
|
|
363
|
-
validateNumberBounds(path, value, schema, context.errors);
|
|
364
|
-
}
|
|
365
|
-
if (typeof value === 'string') {
|
|
366
|
-
validateStringConstraints(path, value, schema, context.errors);
|
|
367
|
-
}
|
|
368
|
-
if (Array.isArray(value)) {
|
|
369
|
-
value = validateArrayAgainstSchema(path, value, schema, context);
|
|
370
|
-
}
|
|
371
|
-
if (isRecord(value)) {
|
|
372
|
-
value = validateObjectAgainstSchema(path, value, schema, context);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
return { value };
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
export function validateAndNormalizeHostedToolArguments(
|
|
379
|
-
tools: HostedToolDefinition[],
|
|
380
|
-
toolName: string,
|
|
381
|
-
args: Record<string, unknown>,
|
|
382
|
-
options: ValidateHostedToolArgumentsOptions = {},
|
|
383
|
-
): NormalizeHostedToolArgumentsResult {
|
|
384
|
-
if (!args || typeof args !== 'object' || Array.isArray(args)) {
|
|
385
|
-
return {
|
|
386
|
-
ok: false,
|
|
387
|
-
errors: ['Tool arguments must be a JSON object'],
|
|
388
|
-
cleaned: {},
|
|
389
|
-
warnings: [],
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
const tool = tools.find(candidate => candidate.function.name === toolName);
|
|
394
|
-
if (!tool) {
|
|
395
|
-
return {
|
|
396
|
-
ok: false,
|
|
397
|
-
errors: [`Unknown hosted Sogni tool "${toolName}"`],
|
|
398
|
-
cleaned: args,
|
|
399
|
-
warnings: [],
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
const schema = tool.function.parameters;
|
|
404
|
-
if (!schema) {
|
|
405
|
-
return { ok: true, errors: [], cleaned: args, warnings: [] };
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
const context: SchemaValidationContext = {
|
|
409
|
-
skipEnumProperties: new Set(options.skipEnumProperties ?? ['model']),
|
|
410
|
-
coercePrimitives: options.coercePrimitives === true,
|
|
411
|
-
stripUnknownProperties: options.stripUnknownProperties === true,
|
|
412
|
-
errors: [],
|
|
413
|
-
warnings: [],
|
|
414
|
-
};
|
|
415
|
-
|
|
416
|
-
const normalizedSchema: HostedToolSchema = {
|
|
417
|
-
...schema,
|
|
418
|
-
type: schema.type ?? 'object',
|
|
419
|
-
};
|
|
420
|
-
const cleaned = validateValueAgainstSchema('', args, normalizedSchema, context).value;
|
|
421
|
-
|
|
422
|
-
return {
|
|
423
|
-
ok: context.errors.length === 0,
|
|
424
|
-
errors: context.errors,
|
|
425
|
-
cleaned: isRecord(cleaned) ? cleaned : args,
|
|
426
|
-
warnings: context.warnings,
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
export function validateHostedToolArguments(
|
|
431
|
-
tools: HostedToolDefinition[],
|
|
432
|
-
toolName: string,
|
|
433
|
-
args: Record<string, unknown>,
|
|
434
|
-
options: ValidateHostedToolArgumentsOptions = {},
|
|
435
|
-
): HostedToolArgumentValidationResult {
|
|
436
|
-
const result = validateAndNormalizeHostedToolArguments(tools, toolName, args, options);
|
|
437
|
-
return {
|
|
438
|
-
ok: result.ok,
|
|
439
|
-
errors: result.errors,
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
export function assertHostedToolArguments(
|
|
444
|
-
tools: HostedToolDefinition[],
|
|
445
|
-
toolName: string,
|
|
446
|
-
args: Record<string, unknown>,
|
|
447
|
-
options?: ValidateHostedToolArgumentsOptions,
|
|
448
|
-
): void {
|
|
449
|
-
const result = validateHostedToolArguments(tools, toolName, args, options);
|
|
450
|
-
if (!result.ok) {
|
|
451
|
-
throw new Error(`Invalid ${toolName} arguments: ${result.errors.join('; ')}`);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
2
|
+
// @ts-nocheck — wrapper's tsconfig (and this file's) uses moduleResolution: 'node'
|
|
3
|
+
// (cannot read modern `exports` map at COMPILE time). At RUNTIME Node's
|
|
4
|
+
// exports-map require-condition resolves the subpath cleanly. The actual types
|
|
5
|
+
// resolve via the package's typesVersions for IDE intellisense; the type-check
|
|
6
|
+
// pass over this file is suppressed.
|
|
7
|
+
/**
|
|
8
|
+
* Re-export shim for hosted tool validation. The validation logic now lives in
|
|
9
|
+
* `@sogni-ai/sogni-intelligence-client/contracts`; this file remains so existing
|
|
10
|
+
* internal callers (e.g. src/Chat/modelRouting.ts) keep working. New code should
|
|
11
|
+
* import directly from `@sogni-ai/sogni-intelligence-client/contracts`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export type {
|
|
15
|
+
HostedToolSchemaProperty,
|
|
16
|
+
HostedToolSchema,
|
|
17
|
+
HostedToolDefinition,
|
|
18
|
+
ValidateHostedToolArgumentsOptions,
|
|
19
|
+
HostedToolArgumentValidationResult,
|
|
20
|
+
NormalizeHostedToolArgumentsResult
|
|
21
|
+
} from '@sogni-ai/sogni-intelligence-client/contracts';
|
|
22
|
+
export {
|
|
23
|
+
validateAndNormalizeHostedToolArguments,
|
|
24
|
+
validateHostedToolArguments,
|
|
25
|
+
assertHostedToolArguments
|
|
26
|
+
} from '@sogni-ai/sogni-intelligence-client/contracts';
|