@modainteract/moda-interact-shared 0.13.0 → 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.
@@ -218,41 +218,125 @@ var boundedJson = (bytes) => z2.unknown().refine((v) => {
218
218
  }
219
219
  });
220
220
 
221
- // src/commerce/definitions.ts
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
- var ToolNameSchema = z3.string().regex(/^[a-z][a-z0-9_]{0,127}$/).refine((n) => n !== "finalResponse");
225
- var ToolBindingSchema = z3.strictObject({
269
+
270
+ // src/commerce/definition-size.ts
271
+ function definitionStorageBytes(value) {
272
+ const normalized = JSON.parse(canonicalJson(value));
273
+ const bytes = (s) => new TextEncoder().encode(s).length;
274
+ function size(v) {
275
+ if (typeof v === "number") {
276
+ const text = JSON.stringify(v);
277
+ if (!text.includes("e")) return text.length;
278
+ const [coefficient, exponent] = text.split("e");
279
+ const sign = coefficient.startsWith("-") ? 1 : 0;
280
+ const unsigned = coefficient.slice(sign);
281
+ const digits = unsigned.replace(".", "").length;
282
+ const point = (unsigned.indexOf(".") < 0 ? unsigned.length : unsigned.indexOf(".")) + Number(exponent);
283
+ return sign + (point <= 0 ? 2 - point + digits : point >= digits ? point : digits + 1);
284
+ }
285
+ if (Array.isArray(v))
286
+ return 2 + Math.max(0, v.length - 1) * 2 + v.reduce((sum, item) => sum + size(item), 0);
287
+ if (v && typeof v === "object") {
288
+ const entries = Object.entries(v);
289
+ return 2 + Math.max(0, entries.length - 1) * 2 + entries.reduce(
290
+ (sum, [key, item]) => sum + bytes(JSON.stringify(key)) + 2 + size(item),
291
+ 0
292
+ );
293
+ }
294
+ return bytes(JSON.stringify(v));
295
+ }
296
+ return size(normalized);
297
+ }
298
+ var definitionFitsStorage = (value) => {
299
+ try {
300
+ return definitionStorageBytes(value) <= 65536;
301
+ } catch {
302
+ return false;
303
+ }
304
+ };
305
+ var DEFINITION_SIZE_MESSAGE = "Definition exceeds the 65536-byte jsonb text limit";
306
+
307
+ // src/commerce/definitions.ts
308
+ var ToolNameSchema = z4.string().regex(/^[a-z][a-z0-9_]{0,127}$/).refine((n) => n !== "finalResponse");
309
+ var ToolBindingSchema = z4.strictObject({
226
310
  toolId: IdSchema,
227
311
  toolRevisionId: IdSchema
228
312
  });
229
- var ToolBindingsSchema = z3.array(ToolBindingSchema).max(32).refine((v) => distinct(v.map((x) => x.toolId)));
230
- var GrantedToolSchema = z3.strictObject({
313
+ var ToolBindingsSchema = z4.array(ToolBindingSchema).max(32).refine((v) => distinct(v.map((x) => x.toolId)));
314
+ var GrantedToolSchema = z4.strictObject({
231
315
  toolId: IdSchema,
232
316
  toolRevisionId: IdSchema,
233
317
  toolName: ToolNameSchema,
234
318
  definitionVersion: SemverSchema,
235
- capabilityKeys: z3.array(IdSchema).min(1).max(32).refine((v) => distinct(v) && v.join("\0") === [...v].sort().join("\0"))
319
+ capabilityKeys: z4.array(IdSchema).min(1).max(32).refine((v) => distinct(v) && v.join("\0") === [...v].sort().join("\0"))
236
320
  });
237
- var GrantedToolsSchema = z3.array(GrantedToolSchema).max(32).refine(
321
+ var GrantedToolsSchema = z4.array(GrantedToolSchema).max(32).refine(
238
322
  (v) => distinct(v.map((x) => x.toolId)) && distinct(v.map((x) => x.toolName))
239
323
  );
240
- var ToolDescriptorSchema = z3.strictObject({
324
+ var ToolDescriptorSchema = z4.strictObject({
241
325
  toolId: IdSchema,
242
326
  toolRevisionId: IdSchema,
243
327
  name: ToolNameSchema,
244
328
  definitionVersion: SemverSchema,
245
- description: z3.string().min(1).max(4096),
329
+ description: z4.string().min(1).max(4096),
246
330
  inputSchema: InputSchemaSchema
247
331
  });
248
- var MappingSchema = z3.union([
249
- z3.strictObject({
250
- input: z3.string().refine(safeName),
251
- omitIfMissing: z3.literal(true).optional()
332
+ var MappingSchema = z4.union([
333
+ z4.strictObject({
334
+ input: z4.string().refine(safeName),
335
+ omitIfMissing: z4.literal(true).optional()
252
336
  }),
253
- z3.strictObject({ literal: boundedJson(8192) })
337
+ z4.strictObject({ literal: boundedJson(8192) })
254
338
  ]);
255
- var MappingsSchema = z3.record(z3.string().refine(safeName), MappingSchema).refine((v) => Object.keys(v).length <= 32);
339
+ var MappingsSchema = z4.record(z4.string().refine(safeName), MappingSchema).refine((v) => Object.keys(v).length <= 32);
256
340
  var POLICY_OPERATIONS = [
257
341
  "recovery.getBasket",
258
342
  "shopify.searchProducts",
@@ -261,23 +345,41 @@ var POLICY_OPERATIONS = [
261
345
  "products.findQualifying",
262
346
  "products.findSimilar"
263
347
  ];
264
- var CommerceExecutionSchema = z3.discriminatedUnion("kind", [
265
- z3.strictObject({
266
- kind: z3.literal("SHOPIFY_STOREFRONT_QUERY"),
267
- executorVersion: z3.literal("1.0.0"),
268
- apiVersion: z3.literal("2026-07"),
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"),
269
370
  schemaHash: HashSchema,
270
- document: z3.string().min(1).refine((v) => new TextEncoder().encode(v).length <= 16384),
271
- operationName: z3.string().refine(safeName),
371
+ document: z4.string().min(1).refine((v) => new TextEncoder().encode(v).length <= 16384),
372
+ operationName: z4.string().refine(safeName),
272
373
  variables: MappingsSchema,
273
- resultPath: z3.string().refine(safePath)
374
+ resultPath: z4.string().refine(safePath)
274
375
  }),
275
- z3.strictObject({
276
- kind: z3.literal("POLICY_OPERATION"),
277
- operation: z3.enum(POLICY_OPERATIONS),
278
- operationVersion: z3.literal("1.0.0"),
376
+ z4.strictObject({
377
+ kind: z4.literal("POLICY_OPERATION"),
378
+ operation: z4.enum(POLICY_OPERATIONS),
379
+ operationVersion: z4.literal("1.0.0"),
279
380
  arguments: MappingsSchema
280
- })
381
+ }),
382
+ ExternalHttpExecutionSchema
281
383
  ]);
282
384
  function tokensValid(text, root) {
283
385
  if (/[<>]/.test(text)) return false;
@@ -287,17 +389,17 @@ function tokensValid(text, root) {
287
389
  );
288
390
  return !residue.includes("{{") && !residue.includes("}}");
289
391
  }
290
- var fixed = z3.string().max(4096).refine((v) => !/[<>]|\{\{|\}\}/.test(v));
291
- var ResponseTemplateSchema = z3.discriminatedUnion("kind", [
292
- z3.strictObject({
293
- kind: z3.literal("text"),
294
- text: z3.string().max(4096).refine((v) => tokensValid(v, "result")),
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")),
295
397
  unavailable: fixed
296
398
  }),
297
- z3.strictObject({
298
- kind: z3.literal("items"),
299
- itemsPath: z3.string().refine(safePath),
300
- item: z3.string().max(4096).refine((v) => tokensValid(v, "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")),
301
403
  empty: fixed,
302
404
  unavailable: fixed
303
405
  })
@@ -305,15 +407,15 @@ var ResponseTemplateSchema = z3.discriminatedUnion("kind", [
305
407
  var identity = {
306
408
  name: ToolNameSchema,
307
409
  definitionVersion: SemverSchema,
308
- description: z3.string().min(1).max(4096)
410
+ description: z4.string().min(1).max(4096)
309
411
  };
310
412
  var forbiddenInput = /^(shopid|customerid|checkoutrecoveryid|conversationid|grantid|releaseid|token|accesstoken|domain|headers|url|graphql|document|authorization)$/i;
311
- var CommerceToolDefinitionSchema = z3.strictObject({
413
+ var CommerceToolDefinitionSchema = z4.strictObject({
312
414
  ...identity,
313
415
  inputSchema: InputSchemaSchema,
314
416
  execution: CommerceExecutionSchema,
315
417
  responseTemplate: ResponseTemplateSchema
316
- }).superRefine((d, ctx) => {
418
+ }).refine(definitionFitsStorage, { message: DEFINITION_SIZE_MESSAGE }).superRefine((d, ctx) => {
317
419
  const properties = d.inputSchema.properties;
318
420
  const containsAuthority = (schema) => Object.entries(schema.properties ?? {}).some(
319
421
  ([name, child]) => forbiddenInput.test(name) || containsAuthority(child)
@@ -323,7 +425,7 @@ var CommerceToolDefinitionSchema = z3.strictObject({
323
425
  code: "custom",
324
426
  message: "Authority/credential inputs are forbidden"
325
427
  });
326
- 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;
327
429
  for (const [name, m] of Object.entries(mapping))
328
430
  if ("input" in m && !Object.hasOwn(properties, m.input))
329
431
  ctx.addIssue({
@@ -331,16 +433,33 @@ var CommerceToolDefinitionSchema = z3.strictObject({
331
433
  path: ["execution", name],
332
434
  message: "Unknown mapped input"
333
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
+ }
334
445
  });
335
446
  var draftObject = boundedJson(65536).refine(
336
447
  (v) => !!v && typeof v === "object" && !Array.isArray(v)
337
448
  );
338
- var CommerceToolDraftDefinitionSchema = z3.strictObject({
449
+ var CommerceToolDraftDefinitionSchema = z4.strictObject({
339
450
  ...identity,
340
451
  inputSchema: draftObject,
341
452
  execution: draftObject,
342
453
  responseTemplate: draftObject
343
- }).refine((v) => new TextEncoder().encode(canonicalJson(v)).length <= 131072);
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
+ }
344
463
  function at(schema, path) {
345
464
  let current = schema;
346
465
  for (const part of path.split(".")) current = current?.properties?.[part];
@@ -348,10 +467,7 @@ function at(schema, path) {
348
467
  }
349
468
  function validateDefinitionForPublication(raw, compiler) {
350
469
  const definition = CommerceToolDefinitionSchema.parse(raw);
351
- const compiled = compiler.compile(
352
- definition.execution,
353
- definition.inputSchema
354
- );
470
+ const compiled = definition.execution.kind === "EXTERNAL_HTTP" ? { outputSchema: externalOutputSchema(definition.execution), validateMappedArguments: () => true } : compiler.compile(definition.execution, definition.inputSchema);
355
471
  if (!compiled.validateMappedArguments(definition.execution))
356
472
  throw new TypeError("Invalid variable/operation mapping");
357
473
  const template = definition.responseTemplate;
@@ -376,7 +492,7 @@ function definitionToMcpDescriptor(definition) {
376
492
  }
377
493
  function mapToolArguments(definition, raw) {
378
494
  const input = compileSubset(definition.inputSchema, "input").parse(raw);
379
- 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;
380
496
  const result = /* @__PURE__ */ Object.create(null);
381
497
  for (const [key, m] of Object.entries(mapping)) {
382
498
  if ("literal" in m) result[key] = m.literal;
@@ -407,12 +523,12 @@ function validateDefinitionVersion(proposed, highestPublished) {
407
523
  SemverSchema.parse(highestPublished);
408
524
  return gt(proposed, highestPublished);
409
525
  }
410
- var CommerceToolIdentitySchema = z3.strictObject({
526
+ var CommerceToolIdentitySchema = z4.strictObject({
411
527
  id: IdSchema,
412
528
  name: ToolNameSchema,
413
- enabled: z3.boolean()
529
+ enabled: z4.boolean()
414
530
  });
415
- var CommerceToolRevisionIdentitySchema = z3.strictObject({
531
+ var CommerceToolRevisionIdentitySchema = z4.strictObject({
416
532
  toolId: IdSchema,
417
533
  toolRevisionId: IdSchema,
418
534
  definitionVersion: SemverSchema,
@@ -423,10 +539,10 @@ var POLICY_OPERATION_DESCRIPTORS = POLICY_OPERATIONS.map(
423
539
  );
424
540
 
425
541
  // src/commerce/response.ts
426
- import { z as z4 } from "zod";
427
- var CommerceResponseContractSchema = z4.strictObject({
428
- version: z4.literal("response.v1"),
429
- instructions: z4.string().min(1).max(8e3),
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),
430
546
  detailsSchema: DetailsSchemaSchema
431
547
  }).refine((v) => jsonBytes(v) <= 32768);
432
548
  var EMPTY_RESPONSE_CONTRACT = {
@@ -439,20 +555,20 @@ var EMPTY_RESPONSE_CONTRACT = {
439
555
  additionalProperties: false
440
556
  }
441
557
  };
442
- var ReferralReasonSchema = z4.enum([
558
+ var ReferralReasonSchema = z5.enum([
443
559
  "INSUFFICIENT_TOOLS",
444
560
  "UNVERIFIABLE_FACTS",
445
561
  "TOOL_UNAVAILABLE",
446
562
  "TOOL_REVOKED"
447
563
  ]);
448
- var CommerceFinalResponseSchema = z4.strictObject({
449
- answerKind: z4.enum(["ANSWER", "REFER_TO_STORE"]),
450
- replyText: z4.string().min(1).max(4096),
564
+ var CommerceFinalResponseSchema = z5.strictObject({
565
+ answerKind: z5.enum(["ANSWER", "REFER_TO_STORE"]),
566
+ replyText: z5.string().min(1).max(4096),
451
567
  referralReason: ReferralReasonSchema.nullable(),
452
568
  detectedLanguageTag: LanguageSchema.nullable(),
453
- detectedLanguageConfidence: z4.number().min(0).max(1).nullable(),
454
- evidenceIds: z4.array(IdSchema).max(3).refine((v) => new Set(v).size === v.length),
455
- details: z4.record(z4.string(), z4.unknown()).refine((v) => {
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) => {
456
572
  try {
457
573
  return jsonBytes(v) <= 16384;
458
574
  } catch {
@@ -563,22 +679,22 @@ function finalResponseToolSchema(definition) {
563
679
  }
564
680
 
565
681
  // src/commerce/schemas.ts
566
- import { z as z5 } from "zod";
682
+ import { z as z6 } from "zod";
567
683
  import { validRange } from "semver";
568
- var CommerceTurnIdentitySchema = z5.strictObject({
684
+ var CommerceTurnIdentitySchema = z6.strictObject({
569
685
  contractVersion: ContractVersionSchema,
570
686
  shopId: IdSchema,
571
687
  checkoutRecoveryId: IdSchema,
572
688
  conversationId: IdSchema,
573
- inboundVersion: z5.number().int().positive()
689
+ inboundVersion: z6.number().int().positive()
574
690
  });
575
- var CommerceConversationGrantSchema = z5.strictObject({
691
+ var CommerceConversationGrantSchema = z6.strictObject({
576
692
  id: IdSchema,
577
693
  shopId: IdSchema,
578
694
  conversationId: IdSchema,
579
- initialInboundVersion: z5.number().int().positive(),
695
+ initialInboundVersion: z6.number().int().positive(),
580
696
  releaseId: IdSchema,
581
- selectedCapabilityKeys: z5.array(IdSchema).min(1).max(32).refine((v) => distinct(v) && v.includes("conversation_core")),
697
+ selectedCapabilityKeys: z6.array(IdSchema).min(1).max(32).refine((v) => distinct(v) && v.includes("conversation_core")),
582
698
  grantedTools: GrantedToolsSchema,
583
699
  runnerVersion: SemverSchema,
584
700
  createdAt: DateSchema,
@@ -591,25 +707,25 @@ var CommerceConversationGrantSchema = z5.strictObject({
591
707
  ))
592
708
  c.addIssue({ code: "custom", message: "Unselected grant provenance" });
593
709
  });
594
- var CommerceConfigurationSchema = z5.strictObject({
595
- maxRecommendations: z5.number().int().min(1).max(3).optional(),
596
- maxSearchResults: z5.number().int().min(1).max(20).optional()
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()
597
713
  });
598
- var CommerceManifestSchema = z5.strictObject({
714
+ var CommerceManifestSchema = z6.strictObject({
599
715
  contractVersion: ContractVersionSchema,
600
716
  releaseId: IdSchema,
601
- runnerCompatibility: z5.string().min(1).max(128).refine((v) => !!validRange(v)),
602
- capabilities: z5.array(
603
- z5.strictObject({
717
+ runnerCompatibility: z6.string().min(1).max(128).refine((v) => !!validRange(v)),
718
+ capabilities: z6.array(
719
+ z6.strictObject({
604
720
  key: IdSchema,
605
721
  revisionId: IdSchema,
606
- position: z5.number().int().nonnegative(),
607
- promptName: z5.string().min(1).max(512),
722
+ position: z6.number().int().nonnegative(),
723
+ promptName: z6.string().min(1).max(512),
608
724
  configuration: CommerceConfigurationSchema,
609
- toolDescriptors: z5.array(ToolDescriptorSchema).max(32)
725
+ toolDescriptors: z6.array(ToolDescriptorSchema).max(32)
610
726
  })
611
727
  ).min(1).max(32),
612
- selectedCapabilityKeys: z5.array(IdSchema).min(1).max(32).refine(distinct),
728
+ selectedCapabilityKeys: z6.array(IdSchema).min(1).max(32).refine(distinct),
613
729
  grantedTools: GrantedToolsSchema,
614
730
  responseContract: CommerceResponseContractSchema,
615
731
  responseContractHash: HashSchema
@@ -660,32 +776,32 @@ var CommerceManifestSchema = z5.strictObject({
660
776
  message: "Grant must equal selected binding union"
661
777
  });
662
778
  });
663
- var CommerceReleaseIdentitySchema = z5.strictObject({
779
+ var CommerceReleaseIdentitySchema = z6.strictObject({
664
780
  contractVersion: ContractVersionSchema,
665
781
  releaseId: IdSchema,
666
- runnerCompatibility: z5.string().min(1).max(128).refine((v) => !!validRange(v))
782
+ runnerCompatibility: z6.string().min(1).max(128).refine((v) => !!validRange(v))
667
783
  });
668
784
  var CommerceResolveAssertionSchema = CommerceTurnIdentitySchema.extend(
669
- { purpose: z5.literal("resolve") }
785
+ { purpose: z6.literal("resolve") }
670
786
  );
671
787
  var CommerceExecuteAssertionSchema = CommerceTurnIdentitySchema.extend(
672
- { purpose: z5.literal("execute"), grantId: IdSchema, releaseId: IdSchema }
788
+ { purpose: z6.literal("execute"), grantId: IdSchema, releaseId: IdSchema }
673
789
  );
674
- var CommerceAssertionSchema = z5.discriminatedUnion("purpose", [
790
+ var CommerceAssertionSchema = z6.discriminatedUnion("purpose", [
675
791
  CommerceResolveAssertionSchema,
676
792
  CommerceExecuteAssertionSchema
677
793
  ]);
678
- var qty = z5.number().int().min(1).max(999);
679
- var CommerceProposalSchema = z5.strictObject({
680
- operations: z5.array(
681
- z5.discriminatedUnion("kind", [
682
- z5.strictObject({
683
- kind: z5.literal("ADD"),
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"),
684
800
  variantId: IdSchema,
685
801
  quantity: qty
686
802
  }),
687
- z5.strictObject({
688
- kind: z5.literal("REPLACE"),
803
+ z6.strictObject({
804
+ kind: z6.literal("REPLACE"),
689
805
  lineId: IdSchema,
690
806
  variantId: IdSchema,
691
807
  quantity: qty
@@ -697,13 +813,13 @@ var CommerceProposalSchema = z5.strictObject({
697
813
  v.operations.flatMap((o) => o.kind === "REPLACE" ? [o.lineId] : [])
698
814
  )
699
815
  );
700
- var CommerceBasketSchema = z5.strictObject({
816
+ var CommerceBasketSchema = z6.strictObject({
701
817
  basketId: IdSchema,
702
- source: z5.enum(["RECOVERY_SNAPSHOT", "PROPOSED"]),
818
+ source: z6.enum(["RECOVERY_SNAPSHOT", "PROPOSED"]),
703
819
  observedAt: DateSchema,
704
820
  currency: CurrencySchema.nullable(),
705
- lines: z5.array(
706
- z5.strictObject({
821
+ lines: z6.array(
822
+ z6.strictObject({
707
823
  lineId: IdSchema,
708
824
  productId: IdSchema.nullable(),
709
825
  variantId: IdSchema.nullable(),
@@ -712,40 +828,40 @@ var CommerceBasketSchema = z5.strictObject({
712
828
  })
713
829
  ).max(100),
714
830
  fingerprint: HashSchema,
715
- unknownFields: z5.array(z5.string().min(1).max(256)).max(128)
831
+ unknownFields: z6.array(z6.string().min(1).max(256)).max(128)
716
832
  }).refine((v) => distinct(v.lines.map((line) => line.lineId)));
717
- var CommerceProductSchema = z5.strictObject({
833
+ var CommerceProductSchema = z6.strictObject({
718
834
  productId: IdSchema,
719
835
  variantId: IdSchema,
720
- title: z5.string().min(1).max(512),
721
- url: z5.url({ protocol: /^https$/ }).refine((v) => {
836
+ title: z6.string().min(1).max(512),
837
+ url: z6.url({ protocol: /^https$/ }).refine((v) => {
722
838
  const u = new URL(v);
723
839
  return !u.username && !u.password && !u.port;
724
840
  }).nullable(),
725
- available: z5.boolean().nullable(),
841
+ available: z6.boolean().nullable(),
726
842
  unitPrice: MoneySchema.nullable(),
727
843
  currency: CurrencySchema.nullable(),
728
- productType: z5.string().max(512).nullable(),
729
- vendor: z5.string().max(512).nullable(),
844
+ productType: z6.string().max(512).nullable(),
845
+ vendor: z6.string().max(512).nullable(),
730
846
  observedAt: DateSchema
731
847
  });
732
- var CommerceOfferSchema = z5.strictObject({
848
+ var CommerceOfferSchema = z6.strictObject({
733
849
  offerId: IdSchema,
734
- title: z5.string().min(1).max(512),
735
- method: z5.enum(["AUTOMATIC", "CODE"]),
736
- code: z5.string().min(1).max(128).nullable(),
850
+ title: z6.string().min(1).max(512),
851
+ method: z6.enum(["AUTOMATIC", "CODE"]),
852
+ code: z6.string().min(1).max(128).nullable(),
737
853
  startsAt: DateSchema.nullable(),
738
854
  endsAt: DateSchema.nullable(),
739
- support: z5.enum(["SUPPORTED", "UNSUPPORTED", "UNKNOWN"]),
740
- reasonCodes: z5.array(z5.string().min(1).max(64)).max(16)
855
+ support: z6.enum(["SUPPORTED", "UNSUPPORTED", "UNKNOWN"]),
856
+ reasonCodes: z6.array(z6.string().min(1).max(64)).max(16)
741
857
  }).refine(
742
858
  (v) => (v.startsAt === null || v.endsAt === null || Date.parse(v.startsAt) < Date.parse(v.endsAt)) && (v.method !== "AUTOMATIC" || v.code === null)
743
859
  );
744
- var condition = z5.strictObject({
745
- code: z5.string().min(1).max(64),
746
- description: z5.string().max(256)
860
+ var condition = z6.strictObject({
861
+ code: z6.string().min(1).max(64),
862
+ description: z6.string().max(256)
747
863
  });
748
- var CommerceEvidenceSchema = z5.strictObject({
864
+ var CommerceEvidenceSchema = z6.strictObject({
749
865
  evidenceId: HashSchema,
750
866
  turn: CommerceTurnIdentitySchema,
751
867
  grantId: IdSchema,
@@ -756,7 +872,7 @@ var CommerceEvidenceSchema = z5.strictObject({
756
872
  ruleFingerprint: HashSchema,
757
873
  evaluatedAt: DateSchema,
758
874
  expiresAt: DateSchema,
759
- outcome: z5.enum([
875
+ outcome: z6.enum([
760
876
  "QUALIFIES_FOR_KNOWN_RULES",
761
877
  "DOES_NOT_QUALIFY",
762
878
  "UNKNOWN",
@@ -765,8 +881,8 @@ var CommerceEvidenceSchema = z5.strictObject({
765
881
  currency: CurrencySchema.nullable(),
766
882
  savings: MoneySchema.nullable(),
767
883
  resultingTotal: MoneySchema.nullable(),
768
- evaluatedConditions: z5.array(condition).max(32),
769
- unresolvedConditions: z5.array(condition).max(32)
884
+ evaluatedConditions: z6.array(condition).max(32),
885
+ unresolvedConditions: z6.array(condition).max(32)
770
886
  }).superRefine((v, c) => {
771
887
  if (Date.parse(v.expiresAt) - Date.parse(v.evaluatedAt) > 6e4)
772
888
  c.addIssue({
@@ -776,16 +892,16 @@ var CommerceEvidenceSchema = z5.strictObject({
776
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))
777
893
  c.addIssue({ code: "custom", message: "Unsupported qualifying claim" });
778
894
  });
779
- var CommerceAlternativeSchema = z5.strictObject({
895
+ var CommerceAlternativeSchema = z6.strictObject({
780
896
  product: CommerceProductSchema,
781
897
  proposal: CommerceProposalSchema,
782
898
  extraSpend: MoneySchema.nullable(),
783
899
  resultingTotal: MoneySchema.nullable(),
784
900
  currency: CurrencySchema.nullable(),
785
901
  evidence: CommerceEvidenceSchema.nullable(),
786
- similarityReasons: z5.array(z5.string().max(256)).max(3)
902
+ similarityReasons: z6.array(z6.string().max(256)).max(3)
787
903
  }).refine((v) => v.product.available === true);
788
- var CommerceErrorCodeSchema = z5.enum([
904
+ var CommerceErrorCodeSchema = z6.enum([
789
905
  "INVALID_INPUT",
790
906
  "DENIED",
791
907
  "STALE_TURN",
@@ -796,66 +912,66 @@ var CommerceErrorCodeSchema = z5.enum([
796
912
  "INCOMPATIBLE_VERSION"
797
913
  ]);
798
914
  function commerceToolResultSchema(data) {
799
- return z5.union([
800
- z5.strictObject({
915
+ return z6.union([
916
+ z6.strictObject({
801
917
  contractVersion: ContractVersionSchema,
802
- status: z5.literal("OK"),
918
+ status: z6.literal("OK"),
803
919
  data,
804
- renderedText: z5.string().max(4096)
920
+ renderedText: z6.string().max(4096)
805
921
  }),
806
- z5.strictObject({
922
+ z6.strictObject({
807
923
  contractVersion: ContractVersionSchema,
808
- status: z5.literal("ERROR"),
924
+ status: z6.literal("ERROR"),
809
925
  code: CommerceErrorCodeSchema,
810
- retryable: z5.boolean(),
811
- renderedText: z5.string().max(4096).optional()
926
+ retryable: z6.boolean(),
927
+ renderedText: z6.string().max(4096).optional()
812
928
  })
813
929
  ]);
814
930
  }
815
931
  var CommerceToolResultSchema = commerceToolResultSchema(
816
932
  boundedJson(262144)
817
933
  );
818
- var limit = z5.number().int().min(1).max(3).default(3);
934
+ var limit = z6.number().int().min(1).max(3).default(3);
819
935
  var CommerceToolInputs = {
820
- commerce_get_basket: z5.strictObject({}),
821
- commerce_search_products: z5.strictObject({
822
- query: z5.string().min(1).max(200),
936
+ commerce_get_basket: z6.strictObject({}),
937
+ commerce_search_products: z6.strictObject({
938
+ query: z6.string().min(1).max(200),
823
939
  maximumPrice: MoneySchema.optional(),
824
- availableOnly: z5.boolean().default(true),
825
- limit: z5.number().int().min(1).max(20).default(10),
826
- cursor: z5.string().max(2048).nullable().default(null)
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)
827
943
  }),
828
- commerce_get_discount_options: z5.strictObject({}),
829
- commerce_evaluate_discount: z5.strictObject({
944
+ commerce_get_discount_options: z6.strictObject({}),
945
+ commerce_evaluate_discount: z6.strictObject({
830
946
  offerId: IdSchema,
831
947
  proposal: CommerceProposalSchema.nullable()
832
948
  }),
833
- commerce_find_qualifying_products: z5.strictObject({
949
+ commerce_find_qualifying_products: z6.strictObject({
834
950
  offerId: IdSchema,
835
- query: z5.string().min(1).max(200).nullable(),
951
+ query: z6.string().min(1).max(200).nullable(),
836
952
  limit
837
953
  }),
838
- commerce_find_similar_products: z5.strictObject({
954
+ commerce_find_similar_products: z6.strictObject({
839
955
  variantId: IdSchema,
840
956
  offerId: IdSchema.nullable(),
841
957
  limit
842
958
  })
843
959
  };
844
- var alternatives = z5.strictObject({
845
- alternatives: z5.array(CommerceAlternativeSchema).max(3),
846
- truncated: z5.boolean()
960
+ var alternatives = z6.strictObject({
961
+ alternatives: z6.array(CommerceAlternativeSchema).max(3),
962
+ truncated: z6.boolean()
847
963
  });
848
964
  var CommerceToolOutputs = {
849
965
  commerce_get_basket: CommerceBasketSchema,
850
- commerce_search_products: z5.strictObject({
851
- products: z5.array(CommerceProductSchema).max(20),
852
- cursor: z5.string().max(2048).nullable(),
853
- truncated: z5.boolean()
966
+ commerce_search_products: z6.strictObject({
967
+ products: z6.array(CommerceProductSchema).max(20),
968
+ cursor: z6.string().max(2048).nullable(),
969
+ truncated: z6.boolean()
854
970
  }),
855
- commerce_get_discount_options: z5.strictObject({
856
- mode: z5.enum(["NONE", "FIXED", "AI_BEST_APPLICABLE"]),
857
- offers: z5.array(CommerceOfferSchema).max(50),
858
- truncated: z5.boolean()
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()
859
975
  }),
860
976
  commerce_evaluate_discount: CommerceEvidenceSchema,
861
977
  commerce_find_qualifying_products: alternatives,
@@ -870,20 +986,20 @@ function productBelongsToDomain(product, verifiedDomain) {
870
986
  }
871
987
 
872
988
  // src/commerce/selection.ts
873
- import { z as z6 } from "zod";
874
- var CommerceCapabilityBindingSchema = z6.discriminatedUnion("kind", [
875
- z6.strictObject({
876
- kind: z6.literal("BASE"),
877
- key: z6.literal("conversation_core")
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")
878
994
  }),
879
- z6.strictObject({
880
- kind: z6.literal("FEATURE"),
995
+ z7.strictObject({
996
+ kind: z7.literal("FEATURE"),
881
997
  key: IdSchema,
882
998
  featureId: IdSchema
883
999
  }),
884
- z6.strictObject({
885
- kind: z6.literal("RECOVERY_POLICY"),
886
- key: z6.literal("discount_assistance")
1000
+ z7.strictObject({
1001
+ kind: z7.literal("RECOVERY_POLICY"),
1002
+ key: z7.literal("discount_assistance")
887
1003
  })
888
1004
  ]);
889
1005
  function selectCapabilities(candidates, facts) {
@@ -970,6 +1086,23 @@ export {
970
1086
  LanguageSchema,
971
1087
  distinct,
972
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,
973
1106
  ToolNameSchema,
974
1107
  ToolBindingSchema,
975
1108
  ToolBindingsSchema,
@@ -977,6 +1110,7 @@ export {
977
1110
  GrantedToolsSchema,
978
1111
  ToolDescriptorSchema,
979
1112
  POLICY_OPERATIONS,
1113
+ ExternalHttpExecutionSchema,
980
1114
  CommerceExecutionSchema,
981
1115
  ResponseTemplateSchema,
982
1116
  CommerceToolDefinitionSchema,
@@ -1024,4 +1158,4 @@ export {
1024
1158
  parseCommerceManifest,
1025
1159
  currentlyGrantedTools
1026
1160
  };
1027
- //# sourceMappingURL=chunk-QNANS4R4.js.map
1161
+ //# sourceMappingURL=chunk-GLNBHQKH.js.map