@modainteract/moda-interact-shared 5.6.0 → 5.8.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-KIHGDO35.js → chunk-2XZVIWQZ.js} +11 -3
- package/dist/chunk-2XZVIWQZ.js.map +1 -0
- package/dist/{chunk-QVPEX7KY.js → chunk-GCCT2BDE.js} +4 -4
- package/dist/chunk-QFUK7FIO.js +16 -0
- package/dist/chunk-QFUK7FIO.js.map +1 -0
- package/dist/{chunk-S42O2OCG.js → chunk-SW2AFMT7.js} +434 -321
- package/dist/chunk-SW2AFMT7.js.map +1 -0
- package/dist/chunk-WHZAAF2Q.js +25 -0
- package/dist/chunk-WHZAAF2Q.js.map +1 -0
- package/dist/commerce/index.d.ts +41 -5
- package/dist/commerce/index.js +20 -17
- package/dist/commerce/index.js.map +1 -1
- package/dist/commerce/model/node.d.ts +3 -3
- package/dist/commerce/model/node.js +3 -3
- package/dist/commerce/outreach/index.d.ts +1094 -0
- package/dist/commerce/outreach/index.js +1355 -0
- package/dist/commerce/outreach/index.js.map +1 -0
- package/dist/commerce/presentation/index.d.ts +103 -6
- package/dist/commerce/presentation/index.js +80 -13
- package/dist/commerce/presentation/index.js.map +1 -1
- package/dist/commerce/runner/index.d.ts +4 -4
- package/dist/commerce/runner/index.js +12 -28
- package/dist/commerce/runner/index.js.map +1 -1
- package/dist/{product-context-D3FuI6ah.d.ts → product-context-qfk6k9uk.d.ts} +1 -1
- package/dist/recovery-offer-proof.js +2 -2
- package/dist/{response-Cs4zC3d3.d.ts → response-DD6HXT8s.d.ts} +121 -1
- package/dist/{types-ByoKuP90.d.ts → types-BXeYmpeg.d.ts} +2 -2
- package/package.json +12 -6
- package/dist/chunk-KIHGDO35.js.map +0 -1
- package/dist/chunk-S42O2OCG.js.map +0 -1
- /package/dist/{chunk-QVPEX7KY.js.map → chunk-GCCT2BDE.js.map} +0 -0
|
@@ -355,6 +355,25 @@ declare const CommerceProductSelectedOptionsSchema: z.ZodPreprocess<z.ZodArray<z
|
|
|
355
355
|
value: z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodString>;
|
|
356
356
|
}, z.core.$strict>>>;
|
|
357
357
|
declare const CommerceProductSchema: z.ZodObject<{
|
|
358
|
+
description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
359
|
+
status: z.ZodEnum<{
|
|
360
|
+
AVAILABLE: "AVAILABLE";
|
|
361
|
+
NOT_PROVIDED: "NOT_PROVIDED";
|
|
362
|
+
PARTIAL: "PARTIAL";
|
|
363
|
+
}>;
|
|
364
|
+
text: z.ZodString;
|
|
365
|
+
}, z.core.$strict>>>;
|
|
366
|
+
attributes: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
367
|
+
status: z.ZodEnum<{
|
|
368
|
+
AVAILABLE: "AVAILABLE";
|
|
369
|
+
NOT_PROVIDED: "NOT_PROVIDED";
|
|
370
|
+
PARTIAL: "PARTIAL";
|
|
371
|
+
}>;
|
|
372
|
+
items: z.ZodArray<z.ZodObject<{
|
|
373
|
+
name: z.ZodString;
|
|
374
|
+
values: z.ZodArray<z.ZodString>;
|
|
375
|
+
}, z.core.$strict>>;
|
|
376
|
+
}, z.core.$strict>>>;
|
|
358
377
|
options: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
359
378
|
status: z.ZodEnum<{
|
|
360
379
|
AVAILABLE: "AVAILABLE";
|
|
@@ -642,6 +661,25 @@ declare const CommerceEvidenceSchema: z.ZodObject<{
|
|
|
642
661
|
type CommerceEvidence = z.infer<typeof CommerceEvidenceSchema>;
|
|
643
662
|
declare const CommerceAlternativeSchema: z.ZodObject<{
|
|
644
663
|
product: z.ZodObject<{
|
|
664
|
+
description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
665
|
+
status: z.ZodEnum<{
|
|
666
|
+
AVAILABLE: "AVAILABLE";
|
|
667
|
+
NOT_PROVIDED: "NOT_PROVIDED";
|
|
668
|
+
PARTIAL: "PARTIAL";
|
|
669
|
+
}>;
|
|
670
|
+
text: z.ZodString;
|
|
671
|
+
}, z.core.$strict>>>;
|
|
672
|
+
attributes: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
673
|
+
status: z.ZodEnum<{
|
|
674
|
+
AVAILABLE: "AVAILABLE";
|
|
675
|
+
NOT_PROVIDED: "NOT_PROVIDED";
|
|
676
|
+
PARTIAL: "PARTIAL";
|
|
677
|
+
}>;
|
|
678
|
+
items: z.ZodArray<z.ZodObject<{
|
|
679
|
+
name: z.ZodString;
|
|
680
|
+
values: z.ZodArray<z.ZodString>;
|
|
681
|
+
}, z.core.$strict>>;
|
|
682
|
+
}, z.core.$strict>>>;
|
|
645
683
|
options: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
646
684
|
status: z.ZodEnum<{
|
|
647
685
|
AVAILABLE: "AVAILABLE";
|
|
@@ -871,6 +909,7 @@ declare const CommerceResponseDispositionSchema: z.ZodEnum<{
|
|
|
871
909
|
OUT_OF_SCOPE_REDIRECT: "OUT_OF_SCOPE_REDIRECT";
|
|
872
910
|
SHIPPING_INFORMATION_UNVERIFIED: "SHIPPING_INFORMATION_UNVERIFIED";
|
|
873
911
|
PRODUCT_OPTIONS: "PRODUCT_OPTIONS";
|
|
912
|
+
PRODUCT_DETAILS: "PRODUCT_DETAILS";
|
|
874
913
|
}>;
|
|
875
914
|
type CommerceResponseDisposition = z.infer<typeof CommerceResponseDispositionSchema>;
|
|
876
915
|
declare const CommerceAnswerPresentationSelectionSchema: z.ZodObject<{
|
|
@@ -878,11 +917,16 @@ declare const CommerceAnswerPresentationSelectionSchema: z.ZodObject<{
|
|
|
878
917
|
productId: z.ZodString;
|
|
879
918
|
variantId: z.ZodNullable<z.ZodString>;
|
|
880
919
|
}, z.core.$strict>>>;
|
|
920
|
+
productDetailSelections: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
921
|
+
productId: z.ZodString;
|
|
922
|
+
variantId: z.ZodNullable<z.ZodString>;
|
|
923
|
+
}, z.core.$strict>>>;
|
|
881
924
|
responseDisposition: z.ZodOptional<z.ZodEnum<{
|
|
882
925
|
STANDARD: "STANDARD";
|
|
883
926
|
OUT_OF_SCOPE_REDIRECT: "OUT_OF_SCOPE_REDIRECT";
|
|
884
927
|
SHIPPING_INFORMATION_UNVERIFIED: "SHIPPING_INFORMATION_UNVERIFIED";
|
|
885
928
|
PRODUCT_OPTIONS: "PRODUCT_OPTIONS";
|
|
929
|
+
PRODUCT_DETAILS: "PRODUCT_DETAILS";
|
|
886
930
|
}>>;
|
|
887
931
|
shippingInformationSelection: z.ZodOptional<z.ZodObject<{
|
|
888
932
|
productId: z.ZodNullable<z.ZodString>;
|
|
@@ -1121,6 +1165,25 @@ declare const CommerceToolOutputs: {
|
|
|
1121
1165
|
}, z.core.$strict>;
|
|
1122
1166
|
commerce_search_products: z.ZodObject<{
|
|
1123
1167
|
products: z.ZodArray<z.ZodObject<{
|
|
1168
|
+
description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
1169
|
+
status: z.ZodEnum<{
|
|
1170
|
+
AVAILABLE: "AVAILABLE";
|
|
1171
|
+
NOT_PROVIDED: "NOT_PROVIDED";
|
|
1172
|
+
PARTIAL: "PARTIAL";
|
|
1173
|
+
}>;
|
|
1174
|
+
text: z.ZodString;
|
|
1175
|
+
}, z.core.$strict>>>;
|
|
1176
|
+
attributes: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
1177
|
+
status: z.ZodEnum<{
|
|
1178
|
+
AVAILABLE: "AVAILABLE";
|
|
1179
|
+
NOT_PROVIDED: "NOT_PROVIDED";
|
|
1180
|
+
PARTIAL: "PARTIAL";
|
|
1181
|
+
}>;
|
|
1182
|
+
items: z.ZodArray<z.ZodObject<{
|
|
1183
|
+
name: z.ZodString;
|
|
1184
|
+
values: z.ZodArray<z.ZodString>;
|
|
1185
|
+
}, z.core.$strict>>;
|
|
1186
|
+
}, z.core.$strict>>>;
|
|
1124
1187
|
options: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
1125
1188
|
status: z.ZodEnum<{
|
|
1126
1189
|
AVAILABLE: "AVAILABLE";
|
|
@@ -1162,6 +1225,25 @@ declare const CommerceToolOutputs: {
|
|
|
1162
1225
|
}, z.core.$strict>;
|
|
1163
1226
|
commerce_get_product: z.ZodObject<{
|
|
1164
1227
|
product: z.ZodNullable<z.ZodObject<{
|
|
1228
|
+
description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
1229
|
+
status: z.ZodEnum<{
|
|
1230
|
+
AVAILABLE: "AVAILABLE";
|
|
1231
|
+
NOT_PROVIDED: "NOT_PROVIDED";
|
|
1232
|
+
PARTIAL: "PARTIAL";
|
|
1233
|
+
}>;
|
|
1234
|
+
text: z.ZodString;
|
|
1235
|
+
}, z.core.$strict>>>;
|
|
1236
|
+
attributes: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
1237
|
+
status: z.ZodEnum<{
|
|
1238
|
+
AVAILABLE: "AVAILABLE";
|
|
1239
|
+
NOT_PROVIDED: "NOT_PROVIDED";
|
|
1240
|
+
PARTIAL: "PARTIAL";
|
|
1241
|
+
}>;
|
|
1242
|
+
items: z.ZodArray<z.ZodObject<{
|
|
1243
|
+
name: z.ZodString;
|
|
1244
|
+
values: z.ZodArray<z.ZodString>;
|
|
1245
|
+
}, z.core.$strict>>;
|
|
1246
|
+
}, z.core.$strict>>>;
|
|
1165
1247
|
options: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
1166
1248
|
status: z.ZodEnum<{
|
|
1167
1249
|
AVAILABLE: "AVAILABLE";
|
|
@@ -1383,6 +1465,25 @@ declare const CommerceToolOutputs: {
|
|
|
1383
1465
|
commerce_find_qualifying_products: z.ZodObject<{
|
|
1384
1466
|
alternatives: z.ZodArray<z.ZodObject<{
|
|
1385
1467
|
product: z.ZodObject<{
|
|
1468
|
+
description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
1469
|
+
status: z.ZodEnum<{
|
|
1470
|
+
AVAILABLE: "AVAILABLE";
|
|
1471
|
+
NOT_PROVIDED: "NOT_PROVIDED";
|
|
1472
|
+
PARTIAL: "PARTIAL";
|
|
1473
|
+
}>;
|
|
1474
|
+
text: z.ZodString;
|
|
1475
|
+
}, z.core.$strict>>>;
|
|
1476
|
+
attributes: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
1477
|
+
status: z.ZodEnum<{
|
|
1478
|
+
AVAILABLE: "AVAILABLE";
|
|
1479
|
+
NOT_PROVIDED: "NOT_PROVIDED";
|
|
1480
|
+
PARTIAL: "PARTIAL";
|
|
1481
|
+
}>;
|
|
1482
|
+
items: z.ZodArray<z.ZodObject<{
|
|
1483
|
+
name: z.ZodString;
|
|
1484
|
+
values: z.ZodArray<z.ZodString>;
|
|
1485
|
+
}, z.core.$strict>>;
|
|
1486
|
+
}, z.core.$strict>>>;
|
|
1386
1487
|
options: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
1387
1488
|
status: z.ZodEnum<{
|
|
1388
1489
|
AVAILABLE: "AVAILABLE";
|
|
@@ -1487,6 +1588,25 @@ declare const CommerceToolOutputs: {
|
|
|
1487
1588
|
commerce_find_similar_products: z.ZodObject<{
|
|
1488
1589
|
alternatives: z.ZodArray<z.ZodObject<{
|
|
1489
1590
|
product: z.ZodObject<{
|
|
1591
|
+
description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
1592
|
+
status: z.ZodEnum<{
|
|
1593
|
+
AVAILABLE: "AVAILABLE";
|
|
1594
|
+
NOT_PROVIDED: "NOT_PROVIDED";
|
|
1595
|
+
PARTIAL: "PARTIAL";
|
|
1596
|
+
}>;
|
|
1597
|
+
text: z.ZodString;
|
|
1598
|
+
}, z.core.$strict>>>;
|
|
1599
|
+
attributes: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
1600
|
+
status: z.ZodEnum<{
|
|
1601
|
+
AVAILABLE: "AVAILABLE";
|
|
1602
|
+
NOT_PROVIDED: "NOT_PROVIDED";
|
|
1603
|
+
PARTIAL: "PARTIAL";
|
|
1604
|
+
}>;
|
|
1605
|
+
items: z.ZodArray<z.ZodObject<{
|
|
1606
|
+
name: z.ZodString;
|
|
1607
|
+
values: z.ZodArray<z.ZodString>;
|
|
1608
|
+
}, z.core.$strict>>;
|
|
1609
|
+
}, z.core.$strict>>>;
|
|
1490
1610
|
options: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
|
|
1491
1611
|
status: z.ZodEnum<{
|
|
1492
1612
|
AVAILABLE: "AVAILABLE";
|
|
@@ -1647,4 +1767,4 @@ declare function verifyResponseContract(definition: unknown, hash: string, diges
|
|
|
1647
1767
|
/** JSON Schema branches retain the immutable envelope; only ANSWER details vary. */
|
|
1648
1768
|
declare function finalResponseToolSchema(definition: CommerceResponseContract): Json;
|
|
1649
1769
|
|
|
1650
|
-
export {
|
|
1770
|
+
export { CommerceShippingInformationSchema 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, CommerceProposalSchema as P, CommercePurposeOutputSchemaSchema as Q, CommerceReleaseIdentitySchema as R, type SubsetSchema as S, CommerceResolveAssertionSchema as T, type CommerceResponseContract as U, CommerceResponseContractSchema as V, type CommerceResponseDisposition as W, CommerceResponseDispositionSchema as X, type CommerceShippingInformation as Y, type CommerceShippingInformationInput as Z, CommerceShippingInformationInputSchema as _, type CommerceConversationGrant as a, CommerceToolOutputs as a0, CommerceToolResultSchema as a1, CommerceTurnIdentitySchema as a2, DetailsSchemaSchema as a3, EMPTY_RESPONSE_CONTRACT as a4, InputSchemaSchema as a5, type Json as a6, MONEY_PATTERN as a7, ReferralReasonSchema as a8, canonicalJson as a9, commerceToolResultSchema as aa, compileCommercePurposeOutputSchema as ab, compileSubset as ac, finalResponseSchema as ad, finalResponseToolSchema as ae, jsonBytes as af, matchesSubset as ag, normalizeCommerceProductOptions as ah, normalizeCommerceProductSelectedOptions as ai, productBelongsToDomain as aj, responseContractCanonicalJson as ak, safeName as al, safePath as am, validateCommercePurposeOutputSchema as an, validateSubset as ao, verifyResponseContract as ap, 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-qfk6k9uk.js';
|
|
2
|
+
import { C as CommerceTurnIdentity, a as CommerceConversationGrant, b as CommerceManifest, c as CommerceToolResult, D as Digest, d as CommerceFinalResponse } from './response-DD6HXT8s.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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modainteract/moda-interact-shared",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -134,6 +134,10 @@
|
|
|
134
134
|
"./commerce/presentation": {
|
|
135
135
|
"types": "./dist/commerce/presentation/index.d.ts",
|
|
136
136
|
"import": "./dist/commerce/presentation/index.js"
|
|
137
|
+
},
|
|
138
|
+
"./commerce/outreach": {
|
|
139
|
+
"types": "./dist/commerce/outreach/index.d.ts",
|
|
140
|
+
"import": "./dist/commerce/outreach/index.js"
|
|
137
141
|
}
|
|
138
142
|
},
|
|
139
143
|
"files": [
|
|
@@ -160,9 +164,13 @@
|
|
|
160
164
|
"test:arch033-incidents:postgres": "node scripts/test-arch033-incidents-postgres.mjs",
|
|
161
165
|
"validate:arch047-whatsapp-template-events": "node scripts/validate-whatsapp-template-events-entrypoint.mjs",
|
|
162
166
|
"test:product-discovery-contracts": "tsx --test src/commerce/product-discovery-contracts.test.ts src/commerce/product-discovery-projection.test.ts src/commerce/runner/built-in-tools.test.ts src/commerce/runner/runner.test.ts",
|
|
163
|
-
"validate:commerce-presentation": "node scripts/validate-commerce-presentation.mjs"
|
|
167
|
+
"validate:commerce-presentation": "node scripts/validate-commerce-presentation.mjs",
|
|
168
|
+
"validate:commerce-outreach": "node scripts/validate-commerce-outreach.mjs"
|
|
164
169
|
},
|
|
165
170
|
"dependencies": {
|
|
171
|
+
"@langchain/core": "1.2.13",
|
|
172
|
+
"@langchain/langgraph": "1.4.15",
|
|
173
|
+
"@langchain/openrouter": "0.4.15",
|
|
166
174
|
"@opentelemetry/api": "^1.9.0",
|
|
167
175
|
"@opentelemetry/api-logs": "0.221.0",
|
|
168
176
|
"@opentelemetry/context-async-hooks": "^2.10.0",
|
|
@@ -180,13 +188,11 @@
|
|
|
180
188
|
"bullmq-otel": "^2.0.1",
|
|
181
189
|
"intl-messageformat": "^10.7.18",
|
|
182
190
|
"libphonenumber-js": "1.12.30",
|
|
191
|
+
"parse5": "8.0.1",
|
|
183
192
|
"semver": "7.8.5",
|
|
184
193
|
"winston": "3.19.0",
|
|
185
194
|
"winston-loki": "6.1.7",
|
|
186
|
-
"zod": "^4.0.0"
|
|
187
|
-
"@langchain/openrouter": "0.4.15",
|
|
188
|
-
"@langchain/core": "1.2.13",
|
|
189
|
-
"@langchain/langgraph": "1.4.15"
|
|
195
|
+
"zod": "^4.0.0"
|
|
190
196
|
},
|
|
191
197
|
"devDependencies": {
|
|
192
198
|
"@types/node": "^26.4.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/commerce/selection.ts","../src/commerce/product-context.ts"],"sourcesContent":["import { IdSchema } from \"./primitives\";\nimport {\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","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":";;;;;;;;;;;;;;;;;;AAiBO,SAAS,mBACd,YAMA,OAGA;AACA,aAAW,aAAa,YAAY;AAClC,aAAS,MAAM,UAAU,GAAG;AAC5B,aAAS,MAAM,UAAU,SAAS;AAClC,QAAI,CAAC,OAAO,cAAc,UAAU,QAAQ,KAAK,UAAU,WAAW;AACpE,YAAM,IAAI,UAAU,6BAA6B;AAAA,EACrD;AACA,QAAM,WAAW,WACd,OAAO,CAAC,MAAM;AACb,QAAI,CAAC,EAAE,QAAS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