@modainteract/moda-interact-shared 0.13.1 → 0.14.0
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/dist/{chunk-OIRLIV5F.js → chunk-GLNBHQKH.js} +254 -159
- package/dist/chunk-GLNBHQKH.js.map +1 -0
- package/dist/commerce/index.d.ts +297 -3
- package/dist/commerce/index.js +37 -1
- package/dist/commerce/index.js.map +1 -1
- package/dist/commerce/runner/index.d.ts +1 -1
- package/dist/commerce/runner/index.js +1 -1
- package/dist/internationalization.d.ts +2 -2
- package/dist/{response-CrhM-N0k.d.ts → response-D3LgdEbH.d.ts} +301 -7
- package/dist/shopify/index.d.ts +12 -12
- package/package.json +2 -1
- package/dist/chunk-OIRLIV5F.js.map +0 -1
|
@@ -218,8 +218,53 @@ var boundedJson = (bytes) => z2.unknown().refine((v) => {
|
|
|
218
218
|
}
|
|
219
219
|
});
|
|
220
220
|
|
|
221
|
-
// src/commerce/
|
|
221
|
+
// src/commerce/external.ts
|
|
222
222
|
import { z as z3 } from "zod";
|
|
223
|
+
var utf8 = (value, maximum) => new TextEncoder().encode(value).length <= maximum;
|
|
224
|
+
var scalar = z3.union([z3.string().refine((value) => utf8(value, 2048)), z3.number().finite(), z3.boolean()]);
|
|
225
|
+
var scalarOrNull = z3.union([scalar, z3.null()]);
|
|
226
|
+
var record = (item, max) => z3.record(z3.string().refine(safeName), item).refine((value) => Object.keys(value).length <= max);
|
|
227
|
+
var ExternalQueryMappingSchema = z3.union([
|
|
228
|
+
z3.strictObject({ input: z3.string().refine(safeName), omitIfMissing: z3.literal(true).optional() }),
|
|
229
|
+
z3.strictObject({ literal: scalar })
|
|
230
|
+
]);
|
|
231
|
+
var ExternalQueryMappingsSchema = record(ExternalQueryMappingSchema, 32).superRefine((value, ctx) => {
|
|
232
|
+
const reserved = /^(authorization|cookie|set-cookie|host|x-api-key|api_key|apikey|access_token|token|secret|password)$/i;
|
|
233
|
+
for (const key of Object.keys(value)) if (reserved.test(key)) ctx.addIssue({ code: "custom", path: [key], message: "Reserved query key" });
|
|
234
|
+
});
|
|
235
|
+
var ExternalPathSchema = z3.string().max(1024).refine(
|
|
236
|
+
(value) => utf8(value, 1024) && /^\/(?:[A-Za-z0-9._~-]+\/)*[A-Za-z0-9._~-]*\/?$/.test(value) && !value.includes("//") && !value.includes("%") && !value.includes("\\") && !value.includes("?") && !value.includes("#") && !value.includes("{") && !value.includes("}")
|
|
237
|
+
);
|
|
238
|
+
var mediaType = z3.string().min(1).max(128).refine((value) => value === value.toLowerCase() && /^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/.test(value));
|
|
239
|
+
var ExternalResponseFormatSchema = z3.strictObject({ mode: z3.enum(["JSON", "TEXT"]), mediaTypes: z3.array(mediaType).min(1).max(8).refine((values) => new Set(values).size === values.length) });
|
|
240
|
+
var FieldProjectionSchema = record(z3.strictObject({ path: z3.string().refine(safePath), omitIfMissing: z3.literal(true).optional() }), 32).refine((value) => Object.keys(value).length >= 1);
|
|
241
|
+
var ResponseFilterSchema = z3.discriminatedUnion("op", [
|
|
242
|
+
z3.strictObject({ path: z3.string().refine(safePath), op: z3.enum(["EQ", "NE", "GT", "GTE", "LT", "LTE", "CONTAINS", "STARTS_WITH"]), value: scalarOrNull }),
|
|
243
|
+
z3.strictObject({ path: z3.string().refine(safePath), op: z3.literal("IN"), values: z3.array(scalarOrNull).min(1).max(20) })
|
|
244
|
+
]);
|
|
245
|
+
var visualObject = z3.strictObject({ kind: z3.literal("OBJECT"), fields: FieldProjectionSchema });
|
|
246
|
+
var visualList = z3.strictObject({ kind: z3.literal("LIST"), fields: FieldProjectionSchema, filters: z3.array(ResponseFilterSchema).max(8), sort: z3.union([z3.null(), z3.strictObject({ path: z3.string().refine(safePath), direction: z3.enum(["ASC", "DESC"]) })]), limit: z3.int().min(1).max(20) });
|
|
247
|
+
var VisualResponseProcessingSchema = z3.union([visualObject, visualList]);
|
|
248
|
+
var ResponseProcessingSchema = z3.union([VisualResponseProcessingSchema, z3.strictObject({ kind: z3.literal("JAVASCRIPT"), runtimeVersion: z3.literal("quickjs-sync.v1"), source: z3.string().min(1).refine((value) => utf8(value, 16384)) })]);
|
|
249
|
+
var TransformResponseSchema = z3.strictObject({ status: z3.int().min(200).max(299), contentType: z3.string().min(1).max(128), bodyText: z3.string().refine((value) => utf8(value, 262144)), json: z3.union([z3.null(), z3.json()]) });
|
|
250
|
+
var TransformSampleSchema = z3.strictObject({ status: z3.int().min(200).max(299), contentType: z3.string().min(1).max(128), bodyText: z3.string().refine((value) => utf8(value, 262144)) }).refine((value) => jsonBytes(value) <= 524288);
|
|
251
|
+
var ConnectionRevisionViewSchema = z3.strictObject({ id: IdSchema, connectionId: IdSchema, revisionNumber: z3.int().positive(), origin: z3.string().min(1).max(2048), scope: z3.enum(["PLATFORM", "PER_SHOP"]), authMode: z3.enum(["NONE", "BEARER", "API_KEY"]), authHeader: z3.string().min(1).max(128).nullable(), documentation: z3.string().max(16e3), createdAt: z3.iso.datetime({ offset: false }) });
|
|
252
|
+
var ConnectionViewSchema = z3.strictObject({ id: IdSchema, key: z3.string().regex(/^[a-z][a-z0-9_]{0,127}$/), displayName: z3.string().min(1).max(255), description: z3.string().max(4096), enabled: z3.boolean(), editVersion: z3.int().positive(), revisions: z3.array(ConnectionRevisionViewSchema) });
|
|
253
|
+
var CredentialStatusSchema = z3.strictObject({ connectionRevisionId: IdSchema, shopId: IdSchema.nullable(), configured: z3.boolean(), editVersion: z3.int().positive().nullable(), updatedAt: z3.iso.datetime({ offset: false }).nullable() });
|
|
254
|
+
var ConnectionCommandSchema = z3.strictObject({ operationId: IdSchema, reason: z3.string().trim().min(1).max(1e3) });
|
|
255
|
+
var RevisionInputSchema = z3.strictObject({ origin: z3.string().min(1).max(2048), scope: z3.enum(["PLATFORM", "PER_SHOP"]), authMode: z3.enum(["NONE", "BEARER", "API_KEY"]), authHeader: z3.string().min(1).max(128).nullable(), documentation: z3.string().max(16e3) });
|
|
256
|
+
var ConnectionIssueSchema = z3.strictObject({ path: z3.string().max(256), message: z3.string().min(1).max(512) });
|
|
257
|
+
var ConnectionResultSchema = (value) => z3.discriminatedUnion("kind", [
|
|
258
|
+
z3.strictObject({ kind: z3.literal("ok"), value }),
|
|
259
|
+
z3.strictObject({ kind: z3.literal("not-found") }),
|
|
260
|
+
z3.strictObject({ kind: z3.literal("forbidden") }),
|
|
261
|
+
z3.strictObject({ kind: z3.literal("unavailable") }),
|
|
262
|
+
z3.strictObject({ kind: z3.literal("invalid"), issues: z3.array(ConnectionIssueSchema).max(32) }),
|
|
263
|
+
z3.strictObject({ kind: z3.literal("conflict"), code: z3.enum(["STALE_CAS", "CONFLICTING_REPLAY"]) })
|
|
264
|
+
]);
|
|
265
|
+
|
|
266
|
+
// src/commerce/definitions.ts
|
|
267
|
+
import { z as z4 } from "zod";
|
|
223
268
|
import { gt } from "semver";
|
|
224
269
|
|
|
225
270
|
// src/commerce/definition-size.ts
|
|
@@ -260,38 +305,38 @@ var definitionFitsStorage = (value) => {
|
|
|
260
305
|
var DEFINITION_SIZE_MESSAGE = "Definition exceeds the 65536-byte jsonb text limit";
|
|
261
306
|
|
|
262
307
|
// src/commerce/definitions.ts
|
|
263
|
-
var ToolNameSchema =
|
|
264
|
-
var ToolBindingSchema =
|
|
308
|
+
var ToolNameSchema = z4.string().regex(/^[a-z][a-z0-9_]{0,127}$/).refine((n) => n !== "finalResponse");
|
|
309
|
+
var ToolBindingSchema = z4.strictObject({
|
|
265
310
|
toolId: IdSchema,
|
|
266
311
|
toolRevisionId: IdSchema
|
|
267
312
|
});
|
|
268
|
-
var ToolBindingsSchema =
|
|
269
|
-
var GrantedToolSchema =
|
|
313
|
+
var ToolBindingsSchema = z4.array(ToolBindingSchema).max(32).refine((v) => distinct(v.map((x) => x.toolId)));
|
|
314
|
+
var GrantedToolSchema = z4.strictObject({
|
|
270
315
|
toolId: IdSchema,
|
|
271
316
|
toolRevisionId: IdSchema,
|
|
272
317
|
toolName: ToolNameSchema,
|
|
273
318
|
definitionVersion: SemverSchema,
|
|
274
|
-
capabilityKeys:
|
|
319
|
+
capabilityKeys: z4.array(IdSchema).min(1).max(32).refine((v) => distinct(v) && v.join("\0") === [...v].sort().join("\0"))
|
|
275
320
|
});
|
|
276
|
-
var GrantedToolsSchema =
|
|
321
|
+
var GrantedToolsSchema = z4.array(GrantedToolSchema).max(32).refine(
|
|
277
322
|
(v) => distinct(v.map((x) => x.toolId)) && distinct(v.map((x) => x.toolName))
|
|
278
323
|
);
|
|
279
|
-
var ToolDescriptorSchema =
|
|
324
|
+
var ToolDescriptorSchema = z4.strictObject({
|
|
280
325
|
toolId: IdSchema,
|
|
281
326
|
toolRevisionId: IdSchema,
|
|
282
327
|
name: ToolNameSchema,
|
|
283
328
|
definitionVersion: SemverSchema,
|
|
284
|
-
description:
|
|
329
|
+
description: z4.string().min(1).max(4096),
|
|
285
330
|
inputSchema: InputSchemaSchema
|
|
286
331
|
});
|
|
287
|
-
var MappingSchema =
|
|
288
|
-
|
|
289
|
-
input:
|
|
290
|
-
omitIfMissing:
|
|
332
|
+
var MappingSchema = z4.union([
|
|
333
|
+
z4.strictObject({
|
|
334
|
+
input: z4.string().refine(safeName),
|
|
335
|
+
omitIfMissing: z4.literal(true).optional()
|
|
291
336
|
}),
|
|
292
|
-
|
|
337
|
+
z4.strictObject({ literal: boundedJson(8192) })
|
|
293
338
|
]);
|
|
294
|
-
var MappingsSchema =
|
|
339
|
+
var MappingsSchema = z4.record(z4.string().refine(safeName), MappingSchema).refine((v) => Object.keys(v).length <= 32);
|
|
295
340
|
var POLICY_OPERATIONS = [
|
|
296
341
|
"recovery.getBasket",
|
|
297
342
|
"shopify.searchProducts",
|
|
@@ -300,23 +345,41 @@ var POLICY_OPERATIONS = [
|
|
|
300
345
|
"products.findQualifying",
|
|
301
346
|
"products.findSimilar"
|
|
302
347
|
];
|
|
303
|
-
var
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
348
|
+
var ExternalHttpExecutionSchema = z4.strictObject({
|
|
349
|
+
kind: z4.literal("EXTERNAL_HTTP"),
|
|
350
|
+
executorVersion: z4.literal("1.0.0"),
|
|
351
|
+
connectionRevisionId: IdSchema,
|
|
352
|
+
method: z4.literal("GET"),
|
|
353
|
+
path: ExternalPathSchema,
|
|
354
|
+
query: ExternalQueryMappingsSchema,
|
|
355
|
+
responseFormat: ExternalResponseFormatSchema,
|
|
356
|
+
resultPath: z4.string().refine((value) => value === "" || safePath(value)),
|
|
357
|
+
responseProcessing: ResponseProcessingSchema,
|
|
358
|
+
resultSchema: DetailsSchemaSchema
|
|
359
|
+
}).superRefine((value, ctx) => {
|
|
360
|
+
if (value.responseProcessing.kind === "JAVASCRIPT" && value.resultPath !== "")
|
|
361
|
+
ctx.addIssue({ code: "custom", path: ["resultPath"], message: "JAVASCRIPT processing requires an empty resultPath" });
|
|
362
|
+
if (value.responseProcessing.kind !== "JAVASCRIPT" && value.responseFormat.mode !== "JSON")
|
|
363
|
+
ctx.addIssue({ code: "custom", path: ["responseFormat", "mode"], message: "Visual processing requires JSON" });
|
|
364
|
+
});
|
|
365
|
+
var CommerceExecutionSchema = z4.discriminatedUnion("kind", [
|
|
366
|
+
z4.strictObject({
|
|
367
|
+
kind: z4.literal("SHOPIFY_STOREFRONT_QUERY"),
|
|
368
|
+
executorVersion: z4.literal("1.0.0"),
|
|
369
|
+
apiVersion: z4.literal("2026-07"),
|
|
308
370
|
schemaHash: HashSchema,
|
|
309
|
-
document:
|
|
310
|
-
operationName:
|
|
371
|
+
document: z4.string().min(1).refine((v) => new TextEncoder().encode(v).length <= 16384),
|
|
372
|
+
operationName: z4.string().refine(safeName),
|
|
311
373
|
variables: MappingsSchema,
|
|
312
|
-
resultPath:
|
|
374
|
+
resultPath: z4.string().refine(safePath)
|
|
313
375
|
}),
|
|
314
|
-
|
|
315
|
-
kind:
|
|
316
|
-
operation:
|
|
317
|
-
operationVersion:
|
|
376
|
+
z4.strictObject({
|
|
377
|
+
kind: z4.literal("POLICY_OPERATION"),
|
|
378
|
+
operation: z4.enum(POLICY_OPERATIONS),
|
|
379
|
+
operationVersion: z4.literal("1.0.0"),
|
|
318
380
|
arguments: MappingsSchema
|
|
319
|
-
})
|
|
381
|
+
}),
|
|
382
|
+
ExternalHttpExecutionSchema
|
|
320
383
|
]);
|
|
321
384
|
function tokensValid(text, root) {
|
|
322
385
|
if (/[<>]/.test(text)) return false;
|
|
@@ -326,17 +389,17 @@ function tokensValid(text, root) {
|
|
|
326
389
|
);
|
|
327
390
|
return !residue.includes("{{") && !residue.includes("}}");
|
|
328
391
|
}
|
|
329
|
-
var fixed =
|
|
330
|
-
var ResponseTemplateSchema =
|
|
331
|
-
|
|
332
|
-
kind:
|
|
333
|
-
text:
|
|
392
|
+
var fixed = z4.string().max(4096).refine((v) => !/[<>]|\{\{|\}\}/.test(v));
|
|
393
|
+
var ResponseTemplateSchema = z4.discriminatedUnion("kind", [
|
|
394
|
+
z4.strictObject({
|
|
395
|
+
kind: z4.literal("text"),
|
|
396
|
+
text: z4.string().max(4096).refine((v) => tokensValid(v, "result")),
|
|
334
397
|
unavailable: fixed
|
|
335
398
|
}),
|
|
336
|
-
|
|
337
|
-
kind:
|
|
338
|
-
itemsPath:
|
|
339
|
-
item:
|
|
399
|
+
z4.strictObject({
|
|
400
|
+
kind: z4.literal("items"),
|
|
401
|
+
itemsPath: z4.string().refine(safePath),
|
|
402
|
+
item: z4.string().max(4096).refine((v) => tokensValid(v, "item")),
|
|
340
403
|
empty: fixed,
|
|
341
404
|
unavailable: fixed
|
|
342
405
|
})
|
|
@@ -344,10 +407,10 @@ var ResponseTemplateSchema = z3.discriminatedUnion("kind", [
|
|
|
344
407
|
var identity = {
|
|
345
408
|
name: ToolNameSchema,
|
|
346
409
|
definitionVersion: SemverSchema,
|
|
347
|
-
description:
|
|
410
|
+
description: z4.string().min(1).max(4096)
|
|
348
411
|
};
|
|
349
412
|
var forbiddenInput = /^(shopid|customerid|checkoutrecoveryid|conversationid|grantid|releaseid|token|accesstoken|domain|headers|url|graphql|document|authorization)$/i;
|
|
350
|
-
var CommerceToolDefinitionSchema =
|
|
413
|
+
var CommerceToolDefinitionSchema = z4.strictObject({
|
|
351
414
|
...identity,
|
|
352
415
|
inputSchema: InputSchemaSchema,
|
|
353
416
|
execution: CommerceExecutionSchema,
|
|
@@ -362,7 +425,7 @@ var CommerceToolDefinitionSchema = z3.strictObject({
|
|
|
362
425
|
code: "custom",
|
|
363
426
|
message: "Authority/credential inputs are forbidden"
|
|
364
427
|
});
|
|
365
|
-
const mapping = d.execution.kind === "POLICY_OPERATION" ? d.execution.arguments : d.execution.variables;
|
|
428
|
+
const mapping = d.execution.kind === "POLICY_OPERATION" ? d.execution.arguments : d.execution.kind === "SHOPIFY_STOREFRONT_QUERY" ? d.execution.variables : d.execution.query;
|
|
366
429
|
for (const [name, m] of Object.entries(mapping))
|
|
367
430
|
if ("input" in m && !Object.hasOwn(properties, m.input))
|
|
368
431
|
ctx.addIssue({
|
|
@@ -370,16 +433,33 @@ var CommerceToolDefinitionSchema = z3.strictObject({
|
|
|
370
433
|
path: ["execution", name],
|
|
371
434
|
message: "Unknown mapped input"
|
|
372
435
|
});
|
|
436
|
+
if (d.execution.kind === "EXTERNAL_HTTP") {
|
|
437
|
+
for (const [name, mapping2] of Object.entries(d.execution.query))
|
|
438
|
+
if ("input" in mapping2) {
|
|
439
|
+
const target = properties[mapping2.input];
|
|
440
|
+
const type = target && (Array.isArray(target.type) ? target.type[0] : target.type);
|
|
441
|
+
if (!["string", "integer", "boolean"].includes(type ?? ""))
|
|
442
|
+
ctx.addIssue({ code: "custom", path: ["execution", "query", name], message: "External mappings require a top-level scalar input" });
|
|
443
|
+
}
|
|
444
|
+
}
|
|
373
445
|
});
|
|
374
446
|
var draftObject = boundedJson(65536).refine(
|
|
375
447
|
(v) => !!v && typeof v === "object" && !Array.isArray(v)
|
|
376
448
|
);
|
|
377
|
-
var CommerceToolDraftDefinitionSchema =
|
|
449
|
+
var CommerceToolDraftDefinitionSchema = z4.strictObject({
|
|
378
450
|
...identity,
|
|
379
451
|
inputSchema: draftObject,
|
|
380
452
|
execution: draftObject,
|
|
381
453
|
responseTemplate: draftObject
|
|
382
454
|
}).refine(definitionFitsStorage, { message: DEFINITION_SIZE_MESSAGE });
|
|
455
|
+
function externalOutputSchema(execution) {
|
|
456
|
+
return {
|
|
457
|
+
type: "object",
|
|
458
|
+
properties: { values: execution.resultSchema },
|
|
459
|
+
required: ["values"],
|
|
460
|
+
additionalProperties: false
|
|
461
|
+
};
|
|
462
|
+
}
|
|
383
463
|
function at(schema, path) {
|
|
384
464
|
let current = schema;
|
|
385
465
|
for (const part of path.split(".")) current = current?.properties?.[part];
|
|
@@ -387,10 +467,7 @@ function at(schema, path) {
|
|
|
387
467
|
}
|
|
388
468
|
function validateDefinitionForPublication(raw, compiler) {
|
|
389
469
|
const definition = CommerceToolDefinitionSchema.parse(raw);
|
|
390
|
-
const compiled = compiler.compile(
|
|
391
|
-
definition.execution,
|
|
392
|
-
definition.inputSchema
|
|
393
|
-
);
|
|
470
|
+
const compiled = definition.execution.kind === "EXTERNAL_HTTP" ? { outputSchema: externalOutputSchema(definition.execution), validateMappedArguments: () => true } : compiler.compile(definition.execution, definition.inputSchema);
|
|
394
471
|
if (!compiled.validateMappedArguments(definition.execution))
|
|
395
472
|
throw new TypeError("Invalid variable/operation mapping");
|
|
396
473
|
const template = definition.responseTemplate;
|
|
@@ -415,7 +492,7 @@ function definitionToMcpDescriptor(definition) {
|
|
|
415
492
|
}
|
|
416
493
|
function mapToolArguments(definition, raw) {
|
|
417
494
|
const input = compileSubset(definition.inputSchema, "input").parse(raw);
|
|
418
|
-
const mapping = definition.execution.kind === "POLICY_OPERATION" ? definition.execution.arguments : definition.execution.variables;
|
|
495
|
+
const mapping = definition.execution.kind === "POLICY_OPERATION" ? definition.execution.arguments : definition.execution.kind === "SHOPIFY_STOREFRONT_QUERY" ? definition.execution.variables : definition.execution.query;
|
|
419
496
|
const result = /* @__PURE__ */ Object.create(null);
|
|
420
497
|
for (const [key, m] of Object.entries(mapping)) {
|
|
421
498
|
if ("literal" in m) result[key] = m.literal;
|
|
@@ -446,12 +523,12 @@ function validateDefinitionVersion(proposed, highestPublished) {
|
|
|
446
523
|
SemverSchema.parse(highestPublished);
|
|
447
524
|
return gt(proposed, highestPublished);
|
|
448
525
|
}
|
|
449
|
-
var CommerceToolIdentitySchema =
|
|
526
|
+
var CommerceToolIdentitySchema = z4.strictObject({
|
|
450
527
|
id: IdSchema,
|
|
451
528
|
name: ToolNameSchema,
|
|
452
|
-
enabled:
|
|
529
|
+
enabled: z4.boolean()
|
|
453
530
|
});
|
|
454
|
-
var CommerceToolRevisionIdentitySchema =
|
|
531
|
+
var CommerceToolRevisionIdentitySchema = z4.strictObject({
|
|
455
532
|
toolId: IdSchema,
|
|
456
533
|
toolRevisionId: IdSchema,
|
|
457
534
|
definitionVersion: SemverSchema,
|
|
@@ -462,10 +539,10 @@ var POLICY_OPERATION_DESCRIPTORS = POLICY_OPERATIONS.map(
|
|
|
462
539
|
);
|
|
463
540
|
|
|
464
541
|
// src/commerce/response.ts
|
|
465
|
-
import { z as
|
|
466
|
-
var CommerceResponseContractSchema =
|
|
467
|
-
version:
|
|
468
|
-
instructions:
|
|
542
|
+
import { z as z5 } from "zod";
|
|
543
|
+
var CommerceResponseContractSchema = z5.strictObject({
|
|
544
|
+
version: z5.literal("response.v1"),
|
|
545
|
+
instructions: z5.string().min(1).max(8e3),
|
|
469
546
|
detailsSchema: DetailsSchemaSchema
|
|
470
547
|
}).refine((v) => jsonBytes(v) <= 32768);
|
|
471
548
|
var EMPTY_RESPONSE_CONTRACT = {
|
|
@@ -478,20 +555,20 @@ var EMPTY_RESPONSE_CONTRACT = {
|
|
|
478
555
|
additionalProperties: false
|
|
479
556
|
}
|
|
480
557
|
};
|
|
481
|
-
var ReferralReasonSchema =
|
|
558
|
+
var ReferralReasonSchema = z5.enum([
|
|
482
559
|
"INSUFFICIENT_TOOLS",
|
|
483
560
|
"UNVERIFIABLE_FACTS",
|
|
484
561
|
"TOOL_UNAVAILABLE",
|
|
485
562
|
"TOOL_REVOKED"
|
|
486
563
|
]);
|
|
487
|
-
var CommerceFinalResponseSchema =
|
|
488
|
-
answerKind:
|
|
489
|
-
replyText:
|
|
564
|
+
var CommerceFinalResponseSchema = z5.strictObject({
|
|
565
|
+
answerKind: z5.enum(["ANSWER", "REFER_TO_STORE"]),
|
|
566
|
+
replyText: z5.string().min(1).max(4096),
|
|
490
567
|
referralReason: ReferralReasonSchema.nullable(),
|
|
491
568
|
detectedLanguageTag: LanguageSchema.nullable(),
|
|
492
|
-
detectedLanguageConfidence:
|
|
493
|
-
evidenceIds:
|
|
494
|
-
details:
|
|
569
|
+
detectedLanguageConfidence: z5.number().min(0).max(1).nullable(),
|
|
570
|
+
evidenceIds: z5.array(IdSchema).max(3).refine((v) => new Set(v).size === v.length),
|
|
571
|
+
details: z5.record(z5.string(), z5.unknown()).refine((v) => {
|
|
495
572
|
try {
|
|
496
573
|
return jsonBytes(v) <= 16384;
|
|
497
574
|
} catch {
|
|
@@ -602,22 +679,22 @@ function finalResponseToolSchema(definition) {
|
|
|
602
679
|
}
|
|
603
680
|
|
|
604
681
|
// src/commerce/schemas.ts
|
|
605
|
-
import { z as
|
|
682
|
+
import { z as z6 } from "zod";
|
|
606
683
|
import { validRange } from "semver";
|
|
607
|
-
var CommerceTurnIdentitySchema =
|
|
684
|
+
var CommerceTurnIdentitySchema = z6.strictObject({
|
|
608
685
|
contractVersion: ContractVersionSchema,
|
|
609
686
|
shopId: IdSchema,
|
|
610
687
|
checkoutRecoveryId: IdSchema,
|
|
611
688
|
conversationId: IdSchema,
|
|
612
|
-
inboundVersion:
|
|
689
|
+
inboundVersion: z6.number().int().positive()
|
|
613
690
|
});
|
|
614
|
-
var CommerceConversationGrantSchema =
|
|
691
|
+
var CommerceConversationGrantSchema = z6.strictObject({
|
|
615
692
|
id: IdSchema,
|
|
616
693
|
shopId: IdSchema,
|
|
617
694
|
conversationId: IdSchema,
|
|
618
|
-
initialInboundVersion:
|
|
695
|
+
initialInboundVersion: z6.number().int().positive(),
|
|
619
696
|
releaseId: IdSchema,
|
|
620
|
-
selectedCapabilityKeys:
|
|
697
|
+
selectedCapabilityKeys: z6.array(IdSchema).min(1).max(32).refine((v) => distinct(v) && v.includes("conversation_core")),
|
|
621
698
|
grantedTools: GrantedToolsSchema,
|
|
622
699
|
runnerVersion: SemverSchema,
|
|
623
700
|
createdAt: DateSchema,
|
|
@@ -630,25 +707,25 @@ var CommerceConversationGrantSchema = z5.strictObject({
|
|
|
630
707
|
))
|
|
631
708
|
c.addIssue({ code: "custom", message: "Unselected grant provenance" });
|
|
632
709
|
});
|
|
633
|
-
var CommerceConfigurationSchema =
|
|
634
|
-
maxRecommendations:
|
|
635
|
-
maxSearchResults:
|
|
710
|
+
var CommerceConfigurationSchema = z6.strictObject({
|
|
711
|
+
maxRecommendations: z6.number().int().min(1).max(3).optional(),
|
|
712
|
+
maxSearchResults: z6.number().int().min(1).max(20).optional()
|
|
636
713
|
});
|
|
637
|
-
var CommerceManifestSchema =
|
|
714
|
+
var CommerceManifestSchema = z6.strictObject({
|
|
638
715
|
contractVersion: ContractVersionSchema,
|
|
639
716
|
releaseId: IdSchema,
|
|
640
|
-
runnerCompatibility:
|
|
641
|
-
capabilities:
|
|
642
|
-
|
|
717
|
+
runnerCompatibility: z6.string().min(1).max(128).refine((v) => !!validRange(v)),
|
|
718
|
+
capabilities: z6.array(
|
|
719
|
+
z6.strictObject({
|
|
643
720
|
key: IdSchema,
|
|
644
721
|
revisionId: IdSchema,
|
|
645
|
-
position:
|
|
646
|
-
promptName:
|
|
722
|
+
position: z6.number().int().nonnegative(),
|
|
723
|
+
promptName: z6.string().min(1).max(512),
|
|
647
724
|
configuration: CommerceConfigurationSchema,
|
|
648
|
-
toolDescriptors:
|
|
725
|
+
toolDescriptors: z6.array(ToolDescriptorSchema).max(32)
|
|
649
726
|
})
|
|
650
727
|
).min(1).max(32),
|
|
651
|
-
selectedCapabilityKeys:
|
|
728
|
+
selectedCapabilityKeys: z6.array(IdSchema).min(1).max(32).refine(distinct),
|
|
652
729
|
grantedTools: GrantedToolsSchema,
|
|
653
730
|
responseContract: CommerceResponseContractSchema,
|
|
654
731
|
responseContractHash: HashSchema
|
|
@@ -699,32 +776,32 @@ var CommerceManifestSchema = z5.strictObject({
|
|
|
699
776
|
message: "Grant must equal selected binding union"
|
|
700
777
|
});
|
|
701
778
|
});
|
|
702
|
-
var CommerceReleaseIdentitySchema =
|
|
779
|
+
var CommerceReleaseIdentitySchema = z6.strictObject({
|
|
703
780
|
contractVersion: ContractVersionSchema,
|
|
704
781
|
releaseId: IdSchema,
|
|
705
|
-
runnerCompatibility:
|
|
782
|
+
runnerCompatibility: z6.string().min(1).max(128).refine((v) => !!validRange(v))
|
|
706
783
|
});
|
|
707
784
|
var CommerceResolveAssertionSchema = CommerceTurnIdentitySchema.extend(
|
|
708
|
-
{ purpose:
|
|
785
|
+
{ purpose: z6.literal("resolve") }
|
|
709
786
|
);
|
|
710
787
|
var CommerceExecuteAssertionSchema = CommerceTurnIdentitySchema.extend(
|
|
711
|
-
{ purpose:
|
|
788
|
+
{ purpose: z6.literal("execute"), grantId: IdSchema, releaseId: IdSchema }
|
|
712
789
|
);
|
|
713
|
-
var CommerceAssertionSchema =
|
|
790
|
+
var CommerceAssertionSchema = z6.discriminatedUnion("purpose", [
|
|
714
791
|
CommerceResolveAssertionSchema,
|
|
715
792
|
CommerceExecuteAssertionSchema
|
|
716
793
|
]);
|
|
717
|
-
var qty =
|
|
718
|
-
var CommerceProposalSchema =
|
|
719
|
-
operations:
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
kind:
|
|
794
|
+
var qty = z6.number().int().min(1).max(999);
|
|
795
|
+
var CommerceProposalSchema = z6.strictObject({
|
|
796
|
+
operations: z6.array(
|
|
797
|
+
z6.discriminatedUnion("kind", [
|
|
798
|
+
z6.strictObject({
|
|
799
|
+
kind: z6.literal("ADD"),
|
|
723
800
|
variantId: IdSchema,
|
|
724
801
|
quantity: qty
|
|
725
802
|
}),
|
|
726
|
-
|
|
727
|
-
kind:
|
|
803
|
+
z6.strictObject({
|
|
804
|
+
kind: z6.literal("REPLACE"),
|
|
728
805
|
lineId: IdSchema,
|
|
729
806
|
variantId: IdSchema,
|
|
730
807
|
quantity: qty
|
|
@@ -736,13 +813,13 @@ var CommerceProposalSchema = z5.strictObject({
|
|
|
736
813
|
v.operations.flatMap((o) => o.kind === "REPLACE" ? [o.lineId] : [])
|
|
737
814
|
)
|
|
738
815
|
);
|
|
739
|
-
var CommerceBasketSchema =
|
|
816
|
+
var CommerceBasketSchema = z6.strictObject({
|
|
740
817
|
basketId: IdSchema,
|
|
741
|
-
source:
|
|
818
|
+
source: z6.enum(["RECOVERY_SNAPSHOT", "PROPOSED"]),
|
|
742
819
|
observedAt: DateSchema,
|
|
743
820
|
currency: CurrencySchema.nullable(),
|
|
744
|
-
lines:
|
|
745
|
-
|
|
821
|
+
lines: z6.array(
|
|
822
|
+
z6.strictObject({
|
|
746
823
|
lineId: IdSchema,
|
|
747
824
|
productId: IdSchema.nullable(),
|
|
748
825
|
variantId: IdSchema.nullable(),
|
|
@@ -751,40 +828,40 @@ var CommerceBasketSchema = z5.strictObject({
|
|
|
751
828
|
})
|
|
752
829
|
).max(100),
|
|
753
830
|
fingerprint: HashSchema,
|
|
754
|
-
unknownFields:
|
|
831
|
+
unknownFields: z6.array(z6.string().min(1).max(256)).max(128)
|
|
755
832
|
}).refine((v) => distinct(v.lines.map((line) => line.lineId)));
|
|
756
|
-
var CommerceProductSchema =
|
|
833
|
+
var CommerceProductSchema = z6.strictObject({
|
|
757
834
|
productId: IdSchema,
|
|
758
835
|
variantId: IdSchema,
|
|
759
|
-
title:
|
|
760
|
-
url:
|
|
836
|
+
title: z6.string().min(1).max(512),
|
|
837
|
+
url: z6.url({ protocol: /^https$/ }).refine((v) => {
|
|
761
838
|
const u = new URL(v);
|
|
762
839
|
return !u.username && !u.password && !u.port;
|
|
763
840
|
}).nullable(),
|
|
764
|
-
available:
|
|
841
|
+
available: z6.boolean().nullable(),
|
|
765
842
|
unitPrice: MoneySchema.nullable(),
|
|
766
843
|
currency: CurrencySchema.nullable(),
|
|
767
|
-
productType:
|
|
768
|
-
vendor:
|
|
844
|
+
productType: z6.string().max(512).nullable(),
|
|
845
|
+
vendor: z6.string().max(512).nullable(),
|
|
769
846
|
observedAt: DateSchema
|
|
770
847
|
});
|
|
771
|
-
var CommerceOfferSchema =
|
|
848
|
+
var CommerceOfferSchema = z6.strictObject({
|
|
772
849
|
offerId: IdSchema,
|
|
773
|
-
title:
|
|
774
|
-
method:
|
|
775
|
-
code:
|
|
850
|
+
title: z6.string().min(1).max(512),
|
|
851
|
+
method: z6.enum(["AUTOMATIC", "CODE"]),
|
|
852
|
+
code: z6.string().min(1).max(128).nullable(),
|
|
776
853
|
startsAt: DateSchema.nullable(),
|
|
777
854
|
endsAt: DateSchema.nullable(),
|
|
778
|
-
support:
|
|
779
|
-
reasonCodes:
|
|
855
|
+
support: z6.enum(["SUPPORTED", "UNSUPPORTED", "UNKNOWN"]),
|
|
856
|
+
reasonCodes: z6.array(z6.string().min(1).max(64)).max(16)
|
|
780
857
|
}).refine(
|
|
781
858
|
(v) => (v.startsAt === null || v.endsAt === null || Date.parse(v.startsAt) < Date.parse(v.endsAt)) && (v.method !== "AUTOMATIC" || v.code === null)
|
|
782
859
|
);
|
|
783
|
-
var condition =
|
|
784
|
-
code:
|
|
785
|
-
description:
|
|
860
|
+
var condition = z6.strictObject({
|
|
861
|
+
code: z6.string().min(1).max(64),
|
|
862
|
+
description: z6.string().max(256)
|
|
786
863
|
});
|
|
787
|
-
var CommerceEvidenceSchema =
|
|
864
|
+
var CommerceEvidenceSchema = z6.strictObject({
|
|
788
865
|
evidenceId: HashSchema,
|
|
789
866
|
turn: CommerceTurnIdentitySchema,
|
|
790
867
|
grantId: IdSchema,
|
|
@@ -795,7 +872,7 @@ var CommerceEvidenceSchema = z5.strictObject({
|
|
|
795
872
|
ruleFingerprint: HashSchema,
|
|
796
873
|
evaluatedAt: DateSchema,
|
|
797
874
|
expiresAt: DateSchema,
|
|
798
|
-
outcome:
|
|
875
|
+
outcome: z6.enum([
|
|
799
876
|
"QUALIFIES_FOR_KNOWN_RULES",
|
|
800
877
|
"DOES_NOT_QUALIFY",
|
|
801
878
|
"UNKNOWN",
|
|
@@ -804,8 +881,8 @@ var CommerceEvidenceSchema = z5.strictObject({
|
|
|
804
881
|
currency: CurrencySchema.nullable(),
|
|
805
882
|
savings: MoneySchema.nullable(),
|
|
806
883
|
resultingTotal: MoneySchema.nullable(),
|
|
807
|
-
evaluatedConditions:
|
|
808
|
-
unresolvedConditions:
|
|
884
|
+
evaluatedConditions: z6.array(condition).max(32),
|
|
885
|
+
unresolvedConditions: z6.array(condition).max(32)
|
|
809
886
|
}).superRefine((v, c) => {
|
|
810
887
|
if (Date.parse(v.expiresAt) - Date.parse(v.evaluatedAt) > 6e4)
|
|
811
888
|
c.addIssue({
|
|
@@ -815,16 +892,16 @@ var CommerceEvidenceSchema = z5.strictObject({
|
|
|
815
892
|
if (v.outcome === "QUALIFIES_FOR_KNOWN_RULES" && (v.unresolvedConditions.length || Date.parse(v.expiresAt) <= Date.parse(v.evaluatedAt) || v.currency === null || v.savings === null || v.resultingTotal === null))
|
|
816
893
|
c.addIssue({ code: "custom", message: "Unsupported qualifying claim" });
|
|
817
894
|
});
|
|
818
|
-
var CommerceAlternativeSchema =
|
|
895
|
+
var CommerceAlternativeSchema = z6.strictObject({
|
|
819
896
|
product: CommerceProductSchema,
|
|
820
897
|
proposal: CommerceProposalSchema,
|
|
821
898
|
extraSpend: MoneySchema.nullable(),
|
|
822
899
|
resultingTotal: MoneySchema.nullable(),
|
|
823
900
|
currency: CurrencySchema.nullable(),
|
|
824
901
|
evidence: CommerceEvidenceSchema.nullable(),
|
|
825
|
-
similarityReasons:
|
|
902
|
+
similarityReasons: z6.array(z6.string().max(256)).max(3)
|
|
826
903
|
}).refine((v) => v.product.available === true);
|
|
827
|
-
var CommerceErrorCodeSchema =
|
|
904
|
+
var CommerceErrorCodeSchema = z6.enum([
|
|
828
905
|
"INVALID_INPUT",
|
|
829
906
|
"DENIED",
|
|
830
907
|
"STALE_TURN",
|
|
@@ -835,66 +912,66 @@ var CommerceErrorCodeSchema = z5.enum([
|
|
|
835
912
|
"INCOMPATIBLE_VERSION"
|
|
836
913
|
]);
|
|
837
914
|
function commerceToolResultSchema(data) {
|
|
838
|
-
return
|
|
839
|
-
|
|
915
|
+
return z6.union([
|
|
916
|
+
z6.strictObject({
|
|
840
917
|
contractVersion: ContractVersionSchema,
|
|
841
|
-
status:
|
|
918
|
+
status: z6.literal("OK"),
|
|
842
919
|
data,
|
|
843
|
-
renderedText:
|
|
920
|
+
renderedText: z6.string().max(4096)
|
|
844
921
|
}),
|
|
845
|
-
|
|
922
|
+
z6.strictObject({
|
|
846
923
|
contractVersion: ContractVersionSchema,
|
|
847
|
-
status:
|
|
924
|
+
status: z6.literal("ERROR"),
|
|
848
925
|
code: CommerceErrorCodeSchema,
|
|
849
|
-
retryable:
|
|
850
|
-
renderedText:
|
|
926
|
+
retryable: z6.boolean(),
|
|
927
|
+
renderedText: z6.string().max(4096).optional()
|
|
851
928
|
})
|
|
852
929
|
]);
|
|
853
930
|
}
|
|
854
931
|
var CommerceToolResultSchema = commerceToolResultSchema(
|
|
855
932
|
boundedJson(262144)
|
|
856
933
|
);
|
|
857
|
-
var limit =
|
|
934
|
+
var limit = z6.number().int().min(1).max(3).default(3);
|
|
858
935
|
var CommerceToolInputs = {
|
|
859
|
-
commerce_get_basket:
|
|
860
|
-
commerce_search_products:
|
|
861
|
-
query:
|
|
936
|
+
commerce_get_basket: z6.strictObject({}),
|
|
937
|
+
commerce_search_products: z6.strictObject({
|
|
938
|
+
query: z6.string().min(1).max(200),
|
|
862
939
|
maximumPrice: MoneySchema.optional(),
|
|
863
|
-
availableOnly:
|
|
864
|
-
limit:
|
|
865
|
-
cursor:
|
|
940
|
+
availableOnly: z6.boolean().default(true),
|
|
941
|
+
limit: z6.number().int().min(1).max(20).default(10),
|
|
942
|
+
cursor: z6.string().max(2048).nullable().default(null)
|
|
866
943
|
}),
|
|
867
|
-
commerce_get_discount_options:
|
|
868
|
-
commerce_evaluate_discount:
|
|
944
|
+
commerce_get_discount_options: z6.strictObject({}),
|
|
945
|
+
commerce_evaluate_discount: z6.strictObject({
|
|
869
946
|
offerId: IdSchema,
|
|
870
947
|
proposal: CommerceProposalSchema.nullable()
|
|
871
948
|
}),
|
|
872
|
-
commerce_find_qualifying_products:
|
|
949
|
+
commerce_find_qualifying_products: z6.strictObject({
|
|
873
950
|
offerId: IdSchema,
|
|
874
|
-
query:
|
|
951
|
+
query: z6.string().min(1).max(200).nullable(),
|
|
875
952
|
limit
|
|
876
953
|
}),
|
|
877
|
-
commerce_find_similar_products:
|
|
954
|
+
commerce_find_similar_products: z6.strictObject({
|
|
878
955
|
variantId: IdSchema,
|
|
879
956
|
offerId: IdSchema.nullable(),
|
|
880
957
|
limit
|
|
881
958
|
})
|
|
882
959
|
};
|
|
883
|
-
var alternatives =
|
|
884
|
-
alternatives:
|
|
885
|
-
truncated:
|
|
960
|
+
var alternatives = z6.strictObject({
|
|
961
|
+
alternatives: z6.array(CommerceAlternativeSchema).max(3),
|
|
962
|
+
truncated: z6.boolean()
|
|
886
963
|
});
|
|
887
964
|
var CommerceToolOutputs = {
|
|
888
965
|
commerce_get_basket: CommerceBasketSchema,
|
|
889
|
-
commerce_search_products:
|
|
890
|
-
products:
|
|
891
|
-
cursor:
|
|
892
|
-
truncated:
|
|
966
|
+
commerce_search_products: z6.strictObject({
|
|
967
|
+
products: z6.array(CommerceProductSchema).max(20),
|
|
968
|
+
cursor: z6.string().max(2048).nullable(),
|
|
969
|
+
truncated: z6.boolean()
|
|
893
970
|
}),
|
|
894
|
-
commerce_get_discount_options:
|
|
895
|
-
mode:
|
|
896
|
-
offers:
|
|
897
|
-
truncated:
|
|
971
|
+
commerce_get_discount_options: z6.strictObject({
|
|
972
|
+
mode: z6.enum(["NONE", "FIXED", "AI_BEST_APPLICABLE"]),
|
|
973
|
+
offers: z6.array(CommerceOfferSchema).max(50),
|
|
974
|
+
truncated: z6.boolean()
|
|
898
975
|
}),
|
|
899
976
|
commerce_evaluate_discount: CommerceEvidenceSchema,
|
|
900
977
|
commerce_find_qualifying_products: alternatives,
|
|
@@ -909,20 +986,20 @@ function productBelongsToDomain(product, verifiedDomain) {
|
|
|
909
986
|
}
|
|
910
987
|
|
|
911
988
|
// src/commerce/selection.ts
|
|
912
|
-
import { z as
|
|
913
|
-
var CommerceCapabilityBindingSchema =
|
|
914
|
-
|
|
915
|
-
kind:
|
|
916
|
-
key:
|
|
989
|
+
import { z as z7 } from "zod";
|
|
990
|
+
var CommerceCapabilityBindingSchema = z7.discriminatedUnion("kind", [
|
|
991
|
+
z7.strictObject({
|
|
992
|
+
kind: z7.literal("BASE"),
|
|
993
|
+
key: z7.literal("conversation_core")
|
|
917
994
|
}),
|
|
918
|
-
|
|
919
|
-
kind:
|
|
995
|
+
z7.strictObject({
|
|
996
|
+
kind: z7.literal("FEATURE"),
|
|
920
997
|
key: IdSchema,
|
|
921
998
|
featureId: IdSchema
|
|
922
999
|
}),
|
|
923
|
-
|
|
924
|
-
kind:
|
|
925
|
-
key:
|
|
1000
|
+
z7.strictObject({
|
|
1001
|
+
kind: z7.literal("RECOVERY_POLICY"),
|
|
1002
|
+
key: z7.literal("discount_assistance")
|
|
926
1003
|
})
|
|
927
1004
|
]);
|
|
928
1005
|
function selectCapabilities(candidates, facts) {
|
|
@@ -1009,6 +1086,23 @@ export {
|
|
|
1009
1086
|
LanguageSchema,
|
|
1010
1087
|
distinct,
|
|
1011
1088
|
boundedJson,
|
|
1089
|
+
ExternalQueryMappingSchema,
|
|
1090
|
+
ExternalQueryMappingsSchema,
|
|
1091
|
+
ExternalPathSchema,
|
|
1092
|
+
ExternalResponseFormatSchema,
|
|
1093
|
+
FieldProjectionSchema,
|
|
1094
|
+
ResponseFilterSchema,
|
|
1095
|
+
VisualResponseProcessingSchema,
|
|
1096
|
+
ResponseProcessingSchema,
|
|
1097
|
+
TransformResponseSchema,
|
|
1098
|
+
TransformSampleSchema,
|
|
1099
|
+
ConnectionRevisionViewSchema,
|
|
1100
|
+
ConnectionViewSchema,
|
|
1101
|
+
CredentialStatusSchema,
|
|
1102
|
+
ConnectionCommandSchema,
|
|
1103
|
+
RevisionInputSchema,
|
|
1104
|
+
ConnectionIssueSchema,
|
|
1105
|
+
ConnectionResultSchema,
|
|
1012
1106
|
ToolNameSchema,
|
|
1013
1107
|
ToolBindingSchema,
|
|
1014
1108
|
ToolBindingsSchema,
|
|
@@ -1016,6 +1110,7 @@ export {
|
|
|
1016
1110
|
GrantedToolsSchema,
|
|
1017
1111
|
ToolDescriptorSchema,
|
|
1018
1112
|
POLICY_OPERATIONS,
|
|
1113
|
+
ExternalHttpExecutionSchema,
|
|
1019
1114
|
CommerceExecutionSchema,
|
|
1020
1115
|
ResponseTemplateSchema,
|
|
1021
1116
|
CommerceToolDefinitionSchema,
|
|
@@ -1063,4 +1158,4 @@ export {
|
|
|
1063
1158
|
parseCommerceManifest,
|
|
1064
1159
|
currentlyGrantedTools
|
|
1065
1160
|
};
|
|
1066
|
-
//# sourceMappingURL=chunk-
|
|
1161
|
+
//# sourceMappingURL=chunk-GLNBHQKH.js.map
|