@modainteract/moda-interact-shared 5.9.0 → 5.11.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-SW2AFMT7.js → chunk-GADJQUWU.js} +24 -3
- package/dist/chunk-GADJQUWU.js.map +1 -0
- package/dist/{chunk-WHZAAF2Q.js → chunk-POCE2AES.js} +2 -2
- package/dist/{chunk-WHZAAF2Q.js.map → chunk-POCE2AES.js.map} +1 -1
- package/dist/{chunk-2XZVIWQZ.js → chunk-X3TXXIAX.js} +25 -6
- package/dist/chunk-X3TXXIAX.js.map +1 -0
- package/dist/commerce/index.d.ts +5 -5
- package/dist/commerce/index.js +8 -2
- package/dist/commerce/index.js.map +1 -1
- package/dist/commerce/model/node.d.ts +3 -3
- package/dist/commerce/model/node.js +1 -1
- package/dist/commerce/outreach/index.d.ts +718 -5
- package/dist/commerce/outreach/index.js +242 -203
- package/dist/commerce/outreach/index.js.map +1 -1
- package/dist/commerce/presentation/index.d.ts +30 -2
- package/dist/commerce/presentation/index.js +33 -6
- package/dist/commerce/presentation/index.js.map +1 -1
- package/dist/commerce/runner/index.d.ts +4 -4
- package/dist/commerce/runner/index.js +4 -4
- package/dist/commerce/runner/index.js.map +1 -1
- package/dist/{product-context-qfk6k9uk.d.ts → product-context-D1Xfe1FX.d.ts} +18 -2
- package/dist/{response-DD6HXT8s.d.ts → response-gHpvLkzy.d.ts} +96 -8
- package/dist/{types-BXeYmpeg.d.ts → types-CxiCD8Pw.d.ts} +2 -2
- package/package.json +1 -1
- package/dist/chunk-2XZVIWQZ.js.map +0 -1
- package/dist/chunk-SW2AFMT7.js.map +0 -1
|
@@ -41,6 +41,8 @@ declare function compileSubset(schema: SubsetSchema, mode: "input" | "details"):
|
|
|
41
41
|
type CommercePurposeOutputSchema = {
|
|
42
42
|
type?: string | [string, "null"];
|
|
43
43
|
anyOf?: CommercePurposeOutputSchema[];
|
|
44
|
+
oneOf?: CommercePurposeOutputSchema[];
|
|
45
|
+
const?: string | number | boolean | null;
|
|
44
46
|
description?: string;
|
|
45
47
|
properties?: Record<string, CommercePurposeOutputSchema>;
|
|
46
48
|
required?: string[];
|
|
@@ -354,7 +356,33 @@ declare const CommerceProductSelectedOptionsSchema: z.ZodPreprocess<z.ZodArray<z
|
|
|
354
356
|
name: z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodString>;
|
|
355
357
|
value: z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodString>;
|
|
356
358
|
}, z.core.$strict>>>;
|
|
359
|
+
declare const CommerceProductStockSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
360
|
+
status: z.ZodLiteral<"KNOWN">;
|
|
361
|
+
quantity: z.ZodNumber;
|
|
362
|
+
scope: z.ZodEnum<{
|
|
363
|
+
PRODUCT: "PRODUCT";
|
|
364
|
+
VARIANT: "VARIANT";
|
|
365
|
+
}>;
|
|
366
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
367
|
+
status: z.ZodLiteral<"NOT_TRACKED">;
|
|
368
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
369
|
+
status: z.ZodLiteral<"UNAVAILABLE">;
|
|
370
|
+
}, z.core.$strict>], "status">;
|
|
371
|
+
type CommerceProductStock = z.infer<typeof CommerceProductStockSchema>;
|
|
372
|
+
declare function normalizeCommerceStockQuantity(value: unknown): number | null;
|
|
357
373
|
declare const CommerceProductSchema: z.ZodObject<{
|
|
374
|
+
stock: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
375
|
+
status: z.ZodLiteral<"KNOWN">;
|
|
376
|
+
quantity: z.ZodNumber;
|
|
377
|
+
scope: z.ZodEnum<{
|
|
378
|
+
PRODUCT: "PRODUCT";
|
|
379
|
+
VARIANT: "VARIANT";
|
|
380
|
+
}>;
|
|
381
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
382
|
+
status: z.ZodLiteral<"NOT_TRACKED">;
|
|
383
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
384
|
+
status: z.ZodLiteral<"UNAVAILABLE">;
|
|
385
|
+
}, z.core.$strict>], "status">>;
|
|
358
386
|
description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
359
387
|
status: z.ZodEnum<{
|
|
360
388
|
AVAILABLE: "AVAILABLE";
|
|
@@ -430,8 +458,8 @@ declare const CommerceOfferSchema: z.ZodObject<{
|
|
|
430
458
|
}, z.core.$strict>;
|
|
431
459
|
declare const CommerceDiscountCombinationFactsSchema: z.ZodObject<{
|
|
432
460
|
discountClasses: z.ZodNullable<z.ZodArray<z.ZodEnum<{
|
|
433
|
-
ORDER: "ORDER";
|
|
434
461
|
PRODUCT: "PRODUCT";
|
|
462
|
+
ORDER: "ORDER";
|
|
435
463
|
SHIPPING: "SHIPPING";
|
|
436
464
|
}>>>;
|
|
437
465
|
shopifyPlus: z.ZodNullable<z.ZodBoolean>;
|
|
@@ -502,8 +530,8 @@ declare const CommerceDiscountConditionFactsSchema: z.ZodObject<{
|
|
|
502
530
|
individualUse: z.ZodNullable<z.ZodBoolean>;
|
|
503
531
|
combination: z.ZodObject<{
|
|
504
532
|
discountClasses: z.ZodNullable<z.ZodArray<z.ZodEnum<{
|
|
505
|
-
ORDER: "ORDER";
|
|
506
533
|
PRODUCT: "PRODUCT";
|
|
534
|
+
ORDER: "ORDER";
|
|
507
535
|
SHIPPING: "SHIPPING";
|
|
508
536
|
}>>>;
|
|
509
537
|
shopifyPlus: z.ZodNullable<z.ZodBoolean>;
|
|
@@ -594,8 +622,8 @@ declare const CommerceDiscountDetailsSchema: z.ZodObject<{
|
|
|
594
622
|
individualUse: z.ZodNullable<z.ZodBoolean>;
|
|
595
623
|
combination: z.ZodObject<{
|
|
596
624
|
discountClasses: z.ZodNullable<z.ZodArray<z.ZodEnum<{
|
|
597
|
-
ORDER: "ORDER";
|
|
598
625
|
PRODUCT: "PRODUCT";
|
|
626
|
+
ORDER: "ORDER";
|
|
599
627
|
SHIPPING: "SHIPPING";
|
|
600
628
|
}>>>;
|
|
601
629
|
shopifyPlus: z.ZodNullable<z.ZodBoolean>;
|
|
@@ -661,6 +689,18 @@ declare const CommerceEvidenceSchema: z.ZodObject<{
|
|
|
661
689
|
type CommerceEvidence = z.infer<typeof CommerceEvidenceSchema>;
|
|
662
690
|
declare const CommerceAlternativeSchema: z.ZodObject<{
|
|
663
691
|
product: z.ZodObject<{
|
|
692
|
+
stock: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
693
|
+
status: z.ZodLiteral<"KNOWN">;
|
|
694
|
+
quantity: z.ZodNumber;
|
|
695
|
+
scope: z.ZodEnum<{
|
|
696
|
+
PRODUCT: "PRODUCT";
|
|
697
|
+
VARIANT: "VARIANT";
|
|
698
|
+
}>;
|
|
699
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
700
|
+
status: z.ZodLiteral<"NOT_TRACKED">;
|
|
701
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
702
|
+
status: z.ZodLiteral<"UNAVAILABLE">;
|
|
703
|
+
}, z.core.$strict>], "status">>;
|
|
664
704
|
description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
665
705
|
status: z.ZodEnum<{
|
|
666
706
|
AVAILABLE: "AVAILABLE";
|
|
@@ -782,11 +822,11 @@ declare const CommerceAlternativeSchema: z.ZodObject<{
|
|
|
782
822
|
declare const CommerceErrorCodeSchema: z.ZodEnum<{
|
|
783
823
|
DEADLINE: "DEADLINE";
|
|
784
824
|
THROTTLED: "THROTTLED";
|
|
825
|
+
UNAVAILABLE: "UNAVAILABLE";
|
|
785
826
|
INVALID_INPUT: "INVALID_INPUT";
|
|
786
827
|
DENIED: "DENIED";
|
|
787
828
|
STALE_TURN: "STALE_TURN";
|
|
788
829
|
NOT_FOUND: "NOT_FOUND";
|
|
789
|
-
UNAVAILABLE: "UNAVAILABLE";
|
|
790
830
|
INCOMPATIBLE_VERSION: "INCOMPATIBLE_VERSION";
|
|
791
831
|
}>;
|
|
792
832
|
declare function commerceToolResultSchema<T extends z.ZodType>(data: T): z.ZodUnion<readonly [z.ZodObject<{
|
|
@@ -800,11 +840,11 @@ declare function commerceToolResultSchema<T extends z.ZodType>(data: T): z.ZodUn
|
|
|
800
840
|
code: z.ZodEnum<{
|
|
801
841
|
DEADLINE: "DEADLINE";
|
|
802
842
|
THROTTLED: "THROTTLED";
|
|
843
|
+
UNAVAILABLE: "UNAVAILABLE";
|
|
803
844
|
INVALID_INPUT: "INVALID_INPUT";
|
|
804
845
|
DENIED: "DENIED";
|
|
805
846
|
STALE_TURN: "STALE_TURN";
|
|
806
847
|
NOT_FOUND: "NOT_FOUND";
|
|
807
|
-
UNAVAILABLE: "UNAVAILABLE";
|
|
808
848
|
INCOMPATIBLE_VERSION: "INCOMPATIBLE_VERSION";
|
|
809
849
|
}>;
|
|
810
850
|
retryable: z.ZodBoolean;
|
|
@@ -821,11 +861,11 @@ declare const CommerceToolResultSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
821
861
|
code: z.ZodEnum<{
|
|
822
862
|
DEADLINE: "DEADLINE";
|
|
823
863
|
THROTTLED: "THROTTLED";
|
|
864
|
+
UNAVAILABLE: "UNAVAILABLE";
|
|
824
865
|
INVALID_INPUT: "INVALID_INPUT";
|
|
825
866
|
DENIED: "DENIED";
|
|
826
867
|
STALE_TURN: "STALE_TURN";
|
|
827
868
|
NOT_FOUND: "NOT_FOUND";
|
|
828
|
-
UNAVAILABLE: "UNAVAILABLE";
|
|
829
869
|
INCOMPATIBLE_VERSION: "INCOMPATIBLE_VERSION";
|
|
830
870
|
}>;
|
|
831
871
|
retryable: z.ZodBoolean;
|
|
@@ -1165,6 +1205,18 @@ declare const CommerceToolOutputs: {
|
|
|
1165
1205
|
}, z.core.$strict>;
|
|
1166
1206
|
commerce_search_products: z.ZodObject<{
|
|
1167
1207
|
products: z.ZodArray<z.ZodObject<{
|
|
1208
|
+
stock: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
1209
|
+
status: z.ZodLiteral<"KNOWN">;
|
|
1210
|
+
quantity: z.ZodNumber;
|
|
1211
|
+
scope: z.ZodEnum<{
|
|
1212
|
+
PRODUCT: "PRODUCT";
|
|
1213
|
+
VARIANT: "VARIANT";
|
|
1214
|
+
}>;
|
|
1215
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
1216
|
+
status: z.ZodLiteral<"NOT_TRACKED">;
|
|
1217
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
1218
|
+
status: z.ZodLiteral<"UNAVAILABLE">;
|
|
1219
|
+
}, z.core.$strict>], "status">>;
|
|
1168
1220
|
description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
1169
1221
|
status: z.ZodEnum<{
|
|
1170
1222
|
AVAILABLE: "AVAILABLE";
|
|
@@ -1225,6 +1277,18 @@ declare const CommerceToolOutputs: {
|
|
|
1225
1277
|
}, z.core.$strict>;
|
|
1226
1278
|
commerce_get_product: z.ZodObject<{
|
|
1227
1279
|
product: z.ZodNullable<z.ZodObject<{
|
|
1280
|
+
stock: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
1281
|
+
status: z.ZodLiteral<"KNOWN">;
|
|
1282
|
+
quantity: z.ZodNumber;
|
|
1283
|
+
scope: z.ZodEnum<{
|
|
1284
|
+
PRODUCT: "PRODUCT";
|
|
1285
|
+
VARIANT: "VARIANT";
|
|
1286
|
+
}>;
|
|
1287
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
1288
|
+
status: z.ZodLiteral<"NOT_TRACKED">;
|
|
1289
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
1290
|
+
status: z.ZodLiteral<"UNAVAILABLE">;
|
|
1291
|
+
}, z.core.$strict>], "status">>;
|
|
1228
1292
|
description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
1229
1293
|
status: z.ZodEnum<{
|
|
1230
1294
|
AVAILABLE: "AVAILABLE";
|
|
@@ -1398,8 +1462,8 @@ declare const CommerceToolOutputs: {
|
|
|
1398
1462
|
individualUse: z.ZodNullable<z.ZodBoolean>;
|
|
1399
1463
|
combination: z.ZodObject<{
|
|
1400
1464
|
discountClasses: z.ZodNullable<z.ZodArray<z.ZodEnum<{
|
|
1401
|
-
ORDER: "ORDER";
|
|
1402
1465
|
PRODUCT: "PRODUCT";
|
|
1466
|
+
ORDER: "ORDER";
|
|
1403
1467
|
SHIPPING: "SHIPPING";
|
|
1404
1468
|
}>>>;
|
|
1405
1469
|
shopifyPlus: z.ZodNullable<z.ZodBoolean>;
|
|
@@ -1465,6 +1529,18 @@ declare const CommerceToolOutputs: {
|
|
|
1465
1529
|
commerce_find_qualifying_products: z.ZodObject<{
|
|
1466
1530
|
alternatives: z.ZodArray<z.ZodObject<{
|
|
1467
1531
|
product: z.ZodObject<{
|
|
1532
|
+
stock: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
1533
|
+
status: z.ZodLiteral<"KNOWN">;
|
|
1534
|
+
quantity: z.ZodNumber;
|
|
1535
|
+
scope: z.ZodEnum<{
|
|
1536
|
+
PRODUCT: "PRODUCT";
|
|
1537
|
+
VARIANT: "VARIANT";
|
|
1538
|
+
}>;
|
|
1539
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
1540
|
+
status: z.ZodLiteral<"NOT_TRACKED">;
|
|
1541
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
1542
|
+
status: z.ZodLiteral<"UNAVAILABLE">;
|
|
1543
|
+
}, z.core.$strict>], "status">>;
|
|
1468
1544
|
description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
1469
1545
|
status: z.ZodEnum<{
|
|
1470
1546
|
AVAILABLE: "AVAILABLE";
|
|
@@ -1588,6 +1664,18 @@ declare const CommerceToolOutputs: {
|
|
|
1588
1664
|
commerce_find_similar_products: z.ZodObject<{
|
|
1589
1665
|
alternatives: z.ZodArray<z.ZodObject<{
|
|
1590
1666
|
product: z.ZodObject<{
|
|
1667
|
+
stock: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
1668
|
+
status: z.ZodLiteral<"KNOWN">;
|
|
1669
|
+
quantity: z.ZodNumber;
|
|
1670
|
+
scope: z.ZodEnum<{
|
|
1671
|
+
PRODUCT: "PRODUCT";
|
|
1672
|
+
VARIANT: "VARIANT";
|
|
1673
|
+
}>;
|
|
1674
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
1675
|
+
status: z.ZodLiteral<"NOT_TRACKED">;
|
|
1676
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
1677
|
+
status: z.ZodLiteral<"UNAVAILABLE">;
|
|
1678
|
+
}, z.core.$strict>], "status">>;
|
|
1591
1679
|
description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
1592
1680
|
status: z.ZodEnum<{
|
|
1593
1681
|
AVAILABLE: "AVAILABLE";
|
|
@@ -1767,4 +1855,4 @@ declare function verifyResponseContract(definition: unknown, hash: string, diges
|
|
|
1767
1855
|
/** JSON Schema branches retain the immutable envelope; only ANSWER details vary. */
|
|
1768
1856
|
declare function finalResponseToolSchema(definition: CommerceResponseContract): Json;
|
|
1769
1857
|
|
|
1770
|
-
export {
|
|
1858
|
+
export { type CommerceShippingInformationInput as $, CommerceExecuteAssertionSchema as A, CommerceFinalResponseSchema as B, type CommerceTurnIdentity as C, type Digest as D, CommerceManifestSchema as E, CommerceOfferSchema as F, type CommerceOptionalLookupUnavailable as G, CommerceOptionalLookupUnavailableSchema as H, type CommerceProduct as I, CommerceProductOptionsSchema as J, type CommerceProductRecommendationSelection as K, CommerceProductRecommendationSelectionSchema as L, type CommerceProductSaleEvidence as M, CommerceProductSaleEvidenceSchema as N, CommerceProductSelectedOptionsSchema as O, type CommerceProductStock as P, CommerceProductStockSchema as Q, CommerceProposalSchema as R, type SubsetSchema as S, CommercePurposeOutputSchemaSchema as T, CommerceReleaseIdentitySchema as U, CommerceResolveAssertionSchema as V, type CommerceResponseContract as W, CommerceResponseContractSchema as X, type CommerceResponseDisposition as Y, CommerceResponseDispositionSchema as Z, type CommerceShippingInformation as _, type CommerceConversationGrant as a, CommerceShippingInformationInputSchema as a0, CommerceShippingInformationSchema as a1, CommerceToolOutputs as a2, CommerceToolResultSchema as a3, CommerceTurnIdentitySchema as a4, DetailsSchemaSchema as a5, EMPTY_RESPONSE_CONTRACT as a6, InputSchemaSchema as a7, type Json as a8, MONEY_PATTERN as a9, ReferralReasonSchema as aa, canonicalJson as ab, commerceToolResultSchema as ac, compileCommercePurposeOutputSchema as ad, compileSubset as ae, finalResponseSchema as af, finalResponseToolSchema as ag, jsonBytes as ah, matchesSubset as ai, normalizeCommerceProductOptions as aj, normalizeCommerceProductSelectedOptions as ak, normalizeCommerceStockQuantity as al, productBelongsToDomain as am, responseContractCanonicalJson as an, safeName as ao, safePath as ap, validateCommercePurposeOutputSchema as aq, validateSubset as ar, verifyResponseContract as as, type CommerceManifest as b, type CommerceToolResult as c, type CommerceFinalResponse as d, type CommercePurposeOutputSchema as e, CommerceProductSchema as f, CommerceToolInputs as g, type CommerceAnswerPresentationSelection as h, CommerceAlternativeSchema as i, CommerceAnswerPresentationSelectionSchema as j, CommerceAssertionSchema as k, CommerceBasketSchema as l, type CommerceCategoryCandidate as m, CommerceCategoryCandidateSchema as n, type CommerceCategoryResolution as o, CommerceCategoryResolutionSchema as p, CommerceConversationGrantSchema as q, type CommerceDiscountCombinationFacts as r, CommerceDiscountCombinationFactsSchema as s, type CommerceDiscountConditionFacts as t, CommerceDiscountConditionFactsSchema as u, type CommerceDiscountDetails as v, CommerceDiscountDetailsSchema as w, CommerceErrorCodeSchema as x, type CommerceEvidence as y, CommerceEvidenceSchema as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CommerceExecutionPurpose, a as CommerceConversationProductContext, T as ToolDescriptor, G as GrantedTool } from './product-context-
|
|
2
|
-
import { C as CommerceTurnIdentity, a as CommerceConversationGrant, b as CommerceManifest, c as CommerceToolResult, D as Digest, d as CommerceFinalResponse } from './response-
|
|
1
|
+
import { C as CommerceExecutionPurpose, a as CommerceConversationProductContext, T as ToolDescriptor, G as GrantedTool } from './product-context-D1Xfe1FX.js';
|
|
2
|
+
import { C as CommerceTurnIdentity, a as CommerceConversationGrant, b as CommerceManifest, c as CommerceToolResult, D as Digest, d as CommerceFinalResponse } from './response-gHpvLkzy.js';
|
|
3
3
|
import { S as StructuredLogger } from './types-B32wDMLO.js';
|
|
4
4
|
|
|
5
5
|
/** Finite, non-customer-facing failure taxonomy for Commerce hosts and logs. */
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/commerce/selection.ts","../src/commerce/product-context.ts"],"sourcesContent":["import { IdSchema } from \"./primitives\";\nimport {\n CommerceAnswerPresentationSelectionSchema,\n type CommerceAnswerPresentationSelection,\n type CommerceManifest,\n CommerceManifestSchema,\n type CommerceConversationGrant,\n CommerceConversationGrantSchema,\n} from \"./schemas\";\nimport { GrantedToolsSchema, PublishedToolDescriptorSchema, type GrantedTool, type PublishedGrantedTool, type PublishedToolDescriptor, type CommerceBuiltInToolDescriptor, isBuiltInTool } from \"./definitions\";\nimport { isTrustedCommerceBuiltInDescriptor, isTrustedCommerceBuiltInGrant } from \"./built-in-tools\";\nimport { canonicalJson } from \"./canonical-json\";\nexport type FeatureFacts = {\n id: string;\n active: boolean;\n planMappingEnabled: boolean;\n mode: \"ALWAYS_ENABLED\" | \"MERCHANT_OPT_IN\";\n preferenceEnabled: boolean | null;\n};\nexport function selectCapabilities(\n candidates: Array<{\n key: string;\n featureId: string;\n enabled: boolean;\n position: number;\n }>,\n facts: {\n features: FeatureFacts[];\n },\n) {\n for (const candidate of candidates) {\n IdSchema.parse(candidate.key);\n IdSchema.parse(candidate.featureId);\n if (!Number.isSafeInteger(candidate.position) || candidate.position < 0)\n throw new TypeError(\"Invalid capability position\");\n }\n const selected = candidates\n .filter((c) => {\n if (!c.enabled) return false;\n const f = facts.features.find((f) => f.id === c.featureId);\n return (\n !!f &&\n f.active &&\n f.planMappingEnabled &&\n (f.mode === \"ALWAYS_ENABLED\" || f.preferenceEnabled === true)\n );\n })\n .sort((a, b) => a.position - b.position);\n if (\n new Set(selected.map((c) => c.key)).size !== selected.length ||\n new Set(selected.map((c) => c.position)).size !== selected.length\n )\n throw new TypeError(\"Duplicate release membership\");\n return selected.map((c) => c.key);\n}\nexport function deduplicateTools(\n capabilities: Array<{ key: string; toolDescriptor: PublishedToolDescriptor }>,\n builtInTools: readonly CommerceBuiltInToolDescriptor[] = [],\n): GrantedTool[] {\n const byId = new Map<string, { tool: PublishedGrantedTool; descriptor: string }>();\n const names = new Map<string, string>();\n for (const cap of capabilities) {\n const d = PublishedToolDescriptorSchema.parse(cap.toolDescriptor);\n const previous = byId.get(d.toolId);\n const descriptor = canonicalJson(d);\n if (\n (previous && previous.descriptor !== descriptor) ||\n (names.has(d.name) && names.get(d.name) !== d.toolId)\n )\n throw new TypeError(\"Conflicting tool association\");\n names.set(d.name, d.toolId);\n if (previous)\n previous.tool.capabilityKeys = [\n ...new Set([...previous.tool.capabilityKeys, cap.key]),\n ].sort();\n else\n byId.set(d.toolId, {\n descriptor,\n tool: {\n toolId: d.toolId,\n toolRevisionId: d.toolRevisionId,\n toolName: d.name,\n definitionVersion: d.definitionVersion,\n capabilityKeys: [cap.key],\n },\n });\n }\n if (builtInTools.some(tool => !isTrustedCommerceBuiltInDescriptor(tool)))\n throw new TypeError(\"Untrusted built-in descriptor\");\n return GrantedToolsSchema.parse([\n ...[...byId.values()].map(value => value.tool),\n ...builtInTools.map(tool => ({\n kind: \"BUILT_IN\" as const, toolName: tool.name,\n definitionVersion: tool.definitionVersion,\n })),\n ]).sort((a, b) => a.toolName.localeCompare(b.toolName, \"en\"));\n}\nexport function manifestMatchesGrant(\n manifest: CommerceManifest,\n grant: CommerceConversationGrant,\n) {\n if (!CommerceManifestSchema.safeParse(manifest).success || !CommerceConversationGrantSchema.safeParse(grant).success) return false;\n return (\n manifest.releaseId === grant.releaseId &&\n canonicalJson(manifest.purposeProfile ?? null) === canonicalJson(grant.purposeProfile ?? null) &&\n canonicalJson(manifest.selectedCapabilityKeys) ===\n canonicalJson(grant.selectedCapabilityKeys) &&\n canonicalJson(\n [...manifest.grantedTools].sort((a, b) =>\n a.toolName.localeCompare(b.toolName),\n ),\n ) ===\n canonicalJson(\n [...grant.grantedTools].sort((a, b) =>\n a.toolName.localeCompare(b.toolName),\n ),\n )\n );\n}\nexport const parseCommerceManifest = (raw: unknown) =>\n CommerceManifestSchema.parse(raw);\nexport function currentlyGrantedTools(\n grant: CommerceConversationGrant,\n eligibleCapabilityKeys: ReadonlySet<string>,\n enabledToolIds: ReadonlySet<string>,\n allowedBuiltInTools: readonly CommerceBuiltInToolDescriptor[] = [],\n) {\n return grant.grantedTools.filter(\n (t) =>\n isBuiltInTool(t)\n ? isTrustedCommerceBuiltInGrant(t) && allowedBuiltInTools.some(descriptor =>\n isTrustedCommerceBuiltInDescriptor(descriptor) && descriptor.name === t.toolName &&\n descriptor.definitionVersion === t.definitionVersion)\n : enabledToolIds.has(t.toolId) && t.capabilityKeys.some((k) => eligibleCapabilityKeys.has(k)),\n );\n}\n\n/** Validate model-selected identities; hosts must still authorize and freshly verify facts. */\nexport function verifyCommerceAnswerPresentationSelection(raw: unknown):\n | { kind: \"verified\"; selection: CommerceAnswerPresentationSelection }\n | { kind: \"limitation\"; reason: \"INVALID_SELECTION\" } {\n const parsed = CommerceAnswerPresentationSelectionSchema.safeParse(raw);\n if (!parsed.success || (parsed.data.productOptionSelections?.length && parsed.data.productDetailSelections?.length))\n return { kind: \"limitation\", reason: \"INVALID_SELECTION\" };\n return { kind: \"verified\", selection: parsed.data };\n}\n","import { z } from \"zod\";\nimport { CommerceProductSchema } from \"./schemas.js\";\nconst id = z.string().min(1).max(128);\nconst date = z.iso.datetime({offset:false});\nexport const CommerceConversationProductContextSchema = z.strictObject({schemaVersion:z.literal(1),shopId:id,conversationId:id,platform:z.enum([\"SHOPIFY\",\"WOOCOMMERCE\"]),references:z.array(z.strictObject({productId:id,variantId:id.nullable(),title:z.string().min(1).max(512),observedAt:date})).max(20),updatedAt:date}).superRefine((v,c)=>{\n const valid=(value:string,kind:string)=>v.platform === \"SHOPIFY\" ? new RegExp(`^gid://shopify/${kind}/[1-9][0-9]*$`).test(value) : /^[1-9][0-9]*$/.test(value) && Number.isSafeInteger(Number(value));\n if(v.references.some(r=>!valid(r.productId,\"Product\")||(r.variantId!==null&&!valid(r.variantId,\"ProductVariant\")))||new TextEncoder().encode(JSON.stringify(v)).length>32768)c.addIssue({code:\"custom\",message:\"Invalid product context\"});\n});\nexport type CommerceConversationProductContext = z.infer<typeof CommerceConversationProductContextSchema>;\nexport type CommerceProductObservation = {toolName:string;products:z.infer<typeof CommerceProductSchema>[];observedAt:string};\nexport type CommerceProductContextIdentity = {shopId:string;conversationId:string;platform:\"SHOPIFY\"|\"WOOCOMMERCE\";now:number};\nexport function mergeConversationProductContext(previous:CommerceConversationProductContext|null,observations:readonly CommerceProductObservation[],identity:CommerceProductContextIdentity):CommerceConversationProductContext {\n id.parse(identity.shopId);id.parse(identity.conversationId);z.enum([\"SHOPIFY\",\"WOOCOMMERCE\"]).parse(identity.platform);if(!Number.isFinite(identity.now))throw new Error(\"PRODUCT_CONTEXT_TIME_INVALID\");\n let admitted=false;\n if(previous){previous=CommerceConversationProductContextSchema.parse(previous);if(previous.shopId!==identity.shopId||previous.conversationId!==identity.conversationId||previous.platform!==identity.platform)throw new Error(\"PRODUCT_CONTEXT_IDENTITY_MISMATCH\");}\n const fresh=(time:string)=>Number.isFinite(Date.parse(time))&&Date.parse(time)<=identity.now&&Date.parse(time)>=identity.now-86400000;\n const entries=new Map<string,CommerceConversationProductContext[\"references\"][number]>();\n const add=(r:CommerceConversationProductContext[\"references\"][number])=>{if(!fresh(r.observedAt))return;const key=JSON.stringify([r.productId,r.variantId]);const old=entries.get(key);if(!old||Date.parse(r.observedAt)>=Date.parse(old.observedAt))entries.set(key,r);};\n if(previous&&fresh(previous.updatedAt))previous.references.forEach(add);\n for(const o of observations){if(![\"commerce_search_products\",\"commerce_get_product\"].includes(o.toolName)||!fresh(o.observedAt))continue;for(const raw of o.products){const p=CommerceProductSchema.parse(raw);admitted=true;add({productId:p.productId,variantId:p.variantId,title:p.title,observedAt:o.observedAt});}}\n const references=[...entries.values()].sort((a,b)=>Date.parse(b.observedAt)-Date.parse(a.observedAt)||(a.productId<b.productId?-1:a.productId>b.productId?1:0)||((a.variantId??\"\")<(b.variantId??\"\")?-1:(a.variantId??\"\")>(b.variantId??\"\")?1:0)).slice(0,20);\n const result={schemaVersion:1 as const,shopId:identity.shopId,conversationId:identity.conversationId,platform:identity.platform,references,updatedAt:admitted?new Date(identity.now).toISOString():previous&&fresh(previous.updatedAt)?previous.updatedAt:new Date(identity.now).toISOString()};\n while(references.length&&new TextEncoder().encode(JSON.stringify(result)).length>32768)references.pop();\n return CommerceConversationProductContextSchema.parse(result);\n}\nexport function resolveConversationProductReference(context:CommerceConversationProductContext,reference:{productId?:string;variantId?:string|null;title?:string}):{kind:\"MATCH\";productId:string;variantId:string|null}|{kind:\"AMBIGUOUS\"}|{kind:\"MISSING\"}{\n const parsed=CommerceConversationProductContextSchema.parse(context);\n const matches=parsed.references.filter(r=>(reference.productId!==undefined?r.productId===reference.productId:reference.title!==undefined&&r.title.trim().toLowerCase()===reference.title.trim().toLowerCase())&&(reference.variantId===undefined||r.variantId===reference.variantId));\n const unique=[...new Map(matches.map(r=>[JSON.stringify([r.productId,r.variantId]),r])).values()];return unique.length===1?{kind:\"MATCH\",productId:unique[0]!.productId,variantId:unique[0]!.variantId}:unique.length>1?{kind:\"AMBIGUOUS\"}:{kind:\"MISSING\"};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBO,SAAS,mBACd,YAMA,OAGA;AACA,aAAW,aAAa,YAAY;AAClC,aAAS,MAAM,UAAU,GAAG;AAC5B,aAAS,M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