@tsantosfp_2026/piece-coach-migration-ai 1.0.1 → 2.0.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +788 -56
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsantosfp_2026/piece-coach-migration-ai",
3
- "version": "1.0.1",
3
+ "version": "2.0.0",
4
4
  "main": "./src/index.js",
5
5
  "dependencies": {},
6
6
  "files": [
package/src/index.js CHANGED
@@ -52796,9 +52796,29 @@ var require_output_schemas = __commonJS({
52796
52796
  { key: "source_text", label: "Source Text" },
52797
52797
  { key: "source_locators", label: "Source Locators", listItems: [] },
52798
52798
  { key: "source_evidence_references", label: "Source Evidence", labelKey: "canonical_field", listItems: evidenceFields },
52799
+ { key: "evidence_pool", label: "Evidence Pool", labelKey: "evidence_class", listItems: [
52800
+ { key: "evidence_reference", label: "Evidence Reference" },
52801
+ { key: "evidence_class", label: "Evidence Class" },
52802
+ { key: "canonical_field", label: "Canonical Field" },
52803
+ { key: "page_url", label: "Page URL", format: "url" },
52804
+ { key: "source_locator", label: "Source Locator" },
52805
+ { key: "source_text", label: "Source Text" },
52806
+ { key: "relevance_class", label: "Relevance Class" }
52807
+ ] },
52808
+ { key: "grounding", label: "Grounding Records", labelKey: "canonical_field", listItems: [
52809
+ { key: "canonical_field", label: "Canonical Field" },
52810
+ { key: "grounding_status", label: "Grounding Status" },
52811
+ { key: "grounding_evidence_references", label: "Grounding Evidence References", listItems: [] },
52812
+ { key: "grounding_basis", label: "Grounding Basis" }
52813
+ ] },
52799
52814
  { key: "evidence_status", label: "Evidence Status" },
52800
52815
  { key: "source_packet_digest", label: "Source Packet Digest" }
52801
52816
  ] },
52817
+ { key: "manualFinalizationFacts", label: "Manual Finalization Facts", labelKey: "canonical_field", listItems: [
52818
+ { key: "canonical_field", label: "Canonical Field" },
52819
+ { key: "disposition", label: "Disposition" },
52820
+ { key: "reason", label: "Reason" }
52821
+ ] },
52802
52822
  { key: "pendingNarrativeFields", label: "Pending Narrative Fields", listItems: [] },
52803
52823
  { key: "testimonialCandidates", label: "Testimonial Candidates", labelKey: "canonical_field", listItems: [{ key: "canonical_field", label: "Canonical Field" }, { key: "status", label: "Status" }, { key: "value", label: "Value" }] },
52804
52824
  { key: "humanReview", label: "Human Review", children: [{ key: "review_item_count", label: "Review Item Count", format: "number" }, { key: "items", label: "Review Items", listItems: [{ key: "canonical_field", label: "Canonical Field" }, { key: "status", label: "Status" }] }] },
@@ -52826,23 +52846,335 @@ var require_output_schemas = __commonJS({
52826
52846
  }
52827
52847
  });
52828
52848
 
52849
+ // dist/src/lib/source-policy.generated.js
52850
+ var require_source_policy_generated = __commonJS({
52851
+ "dist/src/lib/source-policy.generated.js"(exports2) {
52852
+ "use strict";
52853
+ Object.defineProperty(exports2, "__esModule", { value: true });
52854
+ exports2.SOURCE_EVIDENCE_POLICY = exports2.SOURCE_POLICY_AUTHORITY = void 0;
52855
+ exports2.SOURCE_POLICY_AUTHORITY = {
52856
+ contractId: "OPENCODE_AI_ENRICHMENT_V1_2",
52857
+ contractVersion: "1.2.0",
52858
+ sha256: "b0529ae1d72659e5b1d211d9d7ac500550e9cf65aca971dd0cc1f3df6acbd15b",
52859
+ producerRelevanceSha256: "200d2b9b876bd6d00806e9161b2d2a7cdbf976441b56ab0c5047337fff7a15cc"
52860
+ };
52861
+ exports2.SOURCE_EVIDENCE_POLICY = {
52862
+ "ABOUT_V1": {
52863
+ "groundingFieldAllowlist": [
52864
+ "about.hero.heading",
52865
+ "about.intro.body",
52866
+ "about.bio.long",
52867
+ "about.philosophy.heading",
52868
+ "about.philosophy.body",
52869
+ "about.why_coaching.heading",
52870
+ "about.why_coaching.body",
52871
+ "about.industries.heading",
52872
+ "about.industry_1.title",
52873
+ "about.industry_1.description",
52874
+ "about.industry_2.title",
52875
+ "about.industry_2.description",
52876
+ "about.industry_3.title",
52877
+ "about.industry_3.description",
52878
+ "coach.title",
52879
+ "coach.location.city",
52880
+ "coach.location.state",
52881
+ "coach.city_state",
52882
+ "coach.service_area_heading",
52883
+ "coach.service_area_line"
52884
+ ],
52885
+ "factFieldAllowlist": [
52886
+ "coach.title",
52887
+ "coach.first_name",
52888
+ "coach.last_name",
52889
+ "verified_context.approved_career_facts",
52890
+ "verified_context.verified_media",
52891
+ "verified_context.approved_service_labels"
52892
+ ],
52893
+ "destinationGroundingMap": {
52894
+ "about.hero.heading": {
52895
+ "relevant_relevance_classes": [
52896
+ "ABOUT_BIOGRAPHY_NARRATIVE",
52897
+ "IDENTITY_FACT",
52898
+ "PRACTICE_FACT"
52899
+ ],
52900
+ "missing_value_authority": "NONE"
52901
+ },
52902
+ "about.intro.body": {
52903
+ "relevant_relevance_classes": [
52904
+ "ABOUT_BIOGRAPHY_NARRATIVE",
52905
+ "IDENTITY_FACT",
52906
+ "PRACTICE_FACT"
52907
+ ],
52908
+ "missing_value_authority": "NONE"
52909
+ },
52910
+ "about.bio.long": {
52911
+ "relevant_relevance_classes": [
52912
+ "ABOUT_BIOGRAPHY_NARRATIVE",
52913
+ "PRACTICE_FACT"
52914
+ ],
52915
+ "missing_value_authority": "NONE"
52916
+ },
52917
+ "about.philosophy.heading": {
52918
+ "relevant_relevance_classes": [
52919
+ "ABOUT_PHILOSOPHY_NARRATIVE"
52920
+ ],
52921
+ "missing_value_authority": "NONE"
52922
+ },
52923
+ "about.philosophy.body": {
52924
+ "relevant_relevance_classes": [
52925
+ "ABOUT_PHILOSOPHY_NARRATIVE"
52926
+ ],
52927
+ "missing_value_authority": "NONE"
52928
+ },
52929
+ "about.why_coaching.heading": {
52930
+ "relevant_relevance_classes": [
52931
+ "ABOUT_WHY_COACHING_NARRATIVE"
52932
+ ],
52933
+ "missing_value_authority": "NONE"
52934
+ },
52935
+ "about.why_coaching.body": {
52936
+ "relevant_relevance_classes": [
52937
+ "ABOUT_WHY_COACHING_NARRATIVE"
52938
+ ],
52939
+ "missing_value_authority": "NONE"
52940
+ },
52941
+ "about.industries.heading": {
52942
+ "relevant_relevance_classes": [
52943
+ "INDUSTRIES_FACT"
52944
+ ],
52945
+ "missing_value_authority": "CONDITIONAL_OMISSION_INDUSTRIES_HEADING"
52946
+ }
52947
+ },
52948
+ "sourceFieldRelevanceMap": {
52949
+ "about.hero.heading": "ABOUT_BIOGRAPHY_NARRATIVE",
52950
+ "about.intro.body": "ABOUT_BIOGRAPHY_NARRATIVE",
52951
+ "about.bio.long": "ABOUT_BIOGRAPHY_NARRATIVE",
52952
+ "about.philosophy.heading": "ABOUT_PHILOSOPHY_NARRATIVE",
52953
+ "about.philosophy.body": "ABOUT_PHILOSOPHY_NARRATIVE",
52954
+ "about.why_coaching.heading": "ABOUT_WHY_COACHING_NARRATIVE",
52955
+ "about.why_coaching.body": "ABOUT_WHY_COACHING_NARRATIVE",
52956
+ "about.industries.heading": "INDUSTRIES_FACT",
52957
+ "about.industry_1.title": "INDUSTRIES_FACT",
52958
+ "about.industry_1.description": "INDUSTRIES_FACT",
52959
+ "about.industry_2.title": "INDUSTRIES_FACT",
52960
+ "about.industry_2.description": "INDUSTRIES_FACT",
52961
+ "about.industry_3.title": "INDUSTRIES_FACT",
52962
+ "about.industry_3.description": "INDUSTRIES_FACT",
52963
+ "coach.title": "PRACTICE_FACT",
52964
+ "coach.city_state": "PRACTICE_FACT",
52965
+ "coach.service_area_heading": "PRACTICE_FACT",
52966
+ "coach.service_area_line": "PRACTICE_FACT",
52967
+ "coach.first_name": "IDENTITY_FACT",
52968
+ "coach.last_name": "IDENTITY_FACT",
52969
+ "verified_context.approved_career_facts": "ABOUT_BIOGRAPHY_NARRATIVE",
52970
+ "verified_context.verified_media": "ABOUT_BIOGRAPHY_NARRATIVE",
52971
+ "verified_context.approved_service_labels": "PRACTICE_FACT"
52972
+ }
52973
+ },
52974
+ "BUSINESS_COACHING_V1": {
52975
+ "groundingFieldAllowlist": [
52976
+ "business_coaching.hero.heading",
52977
+ "business_coaching.hero.body",
52978
+ "business_coaching.intro.body",
52979
+ "coach.title",
52980
+ "coach.location.city",
52981
+ "coach.location.state",
52982
+ "coach.city_state",
52983
+ "coach.service_area_heading",
52984
+ "coach.service_area_line"
52985
+ ],
52986
+ "factFieldAllowlist": [
52987
+ "coach.title",
52988
+ "verified_context.approved_service_labels"
52989
+ ],
52990
+ "destinationGroundingMap": {
52991
+ "business_coaching.hero.heading": {
52992
+ "relevant_relevance_classes": [
52993
+ "BUSINESS_COACHING_NARRATIVE",
52994
+ "PRACTICE_FACT"
52995
+ ],
52996
+ "missing_value_authority": "NONE"
52997
+ },
52998
+ "business_coaching.hero.body": {
52999
+ "relevant_relevance_classes": [
53000
+ "BUSINESS_COACHING_NARRATIVE",
53001
+ "PRACTICE_FACT"
53002
+ ],
53003
+ "missing_value_authority": "NONE"
53004
+ },
53005
+ "business_coaching.intro.body": {
53006
+ "relevant_relevance_classes": [
53007
+ "BUSINESS_COACHING_NARRATIVE"
53008
+ ],
53009
+ "missing_value_authority": "NONE"
53010
+ }
53011
+ },
53012
+ "sourceFieldRelevanceMap": {
53013
+ "business_coaching.hero.heading": "BUSINESS_COACHING_NARRATIVE",
53014
+ "business_coaching.hero.body": "BUSINESS_COACHING_NARRATIVE",
53015
+ "business_coaching.intro.body": "BUSINESS_COACHING_NARRATIVE",
53016
+ "coach.title": "PRACTICE_FACT",
53017
+ "coach.city_state": "PRACTICE_FACT",
53018
+ "coach.service_area_heading": "PRACTICE_FACT",
53019
+ "coach.service_area_line": "PRACTICE_FACT",
53020
+ "verified_context.approved_service_labels": "PRACTICE_FACT"
53021
+ }
53022
+ },
53023
+ "EXECUTIVE_COACHING_V1": {
53024
+ "groundingFieldAllowlist": [
53025
+ "executive_coaching.hero.heading",
53026
+ "executive_coaching.hero.body",
53027
+ "coach.title",
53028
+ "coach.location.city",
53029
+ "coach.location.state",
53030
+ "coach.city_state",
53031
+ "coach.service_area_heading",
53032
+ "coach.service_area_line"
53033
+ ],
53034
+ "factFieldAllowlist": [
53035
+ "coach.title",
53036
+ "verified_context.approved_service_labels"
53037
+ ],
53038
+ "destinationGroundingMap": {
53039
+ "executive_coaching.hero.heading": {
53040
+ "relevant_relevance_classes": [
53041
+ "EXECUTIVE_COACHING_NARRATIVE",
53042
+ "PRACTICE_FACT"
53043
+ ],
53044
+ "missing_value_authority": "NONE"
53045
+ },
53046
+ "executive_coaching.hero.body": {
53047
+ "relevant_relevance_classes": [
53048
+ "EXECUTIVE_COACHING_NARRATIVE",
53049
+ "PRACTICE_FACT"
53050
+ ],
53051
+ "missing_value_authority": "NONE"
53052
+ }
53053
+ },
53054
+ "sourceFieldRelevanceMap": {
53055
+ "executive_coaching.hero.heading": "EXECUTIVE_COACHING_NARRATIVE",
53056
+ "executive_coaching.hero.body": "EXECUTIVE_COACHING_NARRATIVE",
53057
+ "coach.title": "PRACTICE_FACT",
53058
+ "coach.city_state": "PRACTICE_FACT",
53059
+ "coach.service_area_heading": "PRACTICE_FACT",
53060
+ "coach.service_area_line": "PRACTICE_FACT",
53061
+ "verified_context.approved_service_labels": "PRACTICE_FACT"
53062
+ }
53063
+ },
53064
+ "RESULTS_V1": {
53065
+ "groundingFieldAllowlist": [
53066
+ "results.intro.body"
53067
+ ],
53068
+ "factFieldAllowlist": [
53069
+ "coach.full_name",
53070
+ "coach.first_name",
53071
+ "coach.last_name",
53072
+ "verified_context.approved_career_facts",
53073
+ "verified_context.approved_service_labels"
53074
+ ],
53075
+ "destinationGroundingMap": {
53076
+ "results.intro.body": {
53077
+ "relevant_relevance_classes": [
53078
+ "RESULTS_NARRATIVE"
53079
+ ],
53080
+ "missing_value_authority": "D14_RESULTS_BASELINE"
53081
+ }
53082
+ },
53083
+ "sourceFieldRelevanceMap": {
53084
+ "results.intro.body": "RESULTS_NARRATIVE",
53085
+ "coach.full_name": "IDENTITY_FACT",
53086
+ "coach.first_name": "IDENTITY_FACT",
53087
+ "coach.last_name": "IDENTITY_FACT",
53088
+ "verified_context.approved_career_facts": "ABOUT_BIOGRAPHY_NARRATIVE",
53089
+ "verified_context.approved_service_labels": "PRACTICE_FACT"
53090
+ }
53091
+ },
53092
+ "CONTACT_V1": {
53093
+ "groundingFieldAllowlist": [
53094
+ "contact.hero.heading",
53095
+ "contact.intro.body"
53096
+ ],
53097
+ "factFieldAllowlist": [
53098
+ "coach.full_name",
53099
+ "coach.first_name",
53100
+ "coach.last_name",
53101
+ "verified_context.approved_service_labels"
53102
+ ],
53103
+ "destinationGroundingMap": {
53104
+ "contact.hero.heading": {
53105
+ "relevant_relevance_classes": [
53106
+ "CONTACT_NARRATIVE"
53107
+ ],
53108
+ "missing_value_authority": "D15_CONTACT_BASELINE"
53109
+ },
53110
+ "contact.intro.body": {
53111
+ "relevant_relevance_classes": [
53112
+ "CONTACT_NARRATIVE"
53113
+ ],
53114
+ "missing_value_authority": "D15_CONTACT_BASELINE"
53115
+ }
53116
+ },
53117
+ "sourceFieldRelevanceMap": {
53118
+ "contact.hero.heading": "CONTACT_NARRATIVE",
53119
+ "contact.intro.body": "CONTACT_NARRATIVE",
53120
+ "coach.full_name": "IDENTITY_FACT",
53121
+ "coach.first_name": "IDENTITY_FACT",
53122
+ "coach.last_name": "IDENTITY_FACT",
53123
+ "verified_context.approved_service_labels": "PRACTICE_FACT"
53124
+ }
53125
+ },
53126
+ "DISCOVERY_CALL_V1": {
53127
+ "groundingFieldAllowlist": [
53128
+ "discovery_call.hero.body"
53129
+ ],
53130
+ "factFieldAllowlist": [
53131
+ "coach.full_name",
53132
+ "coach.first_name",
53133
+ "coach.last_name",
53134
+ "verified_context.approved_service_labels"
53135
+ ],
53136
+ "destinationGroundingMap": {
53137
+ "discovery_call.hero.body": {
53138
+ "relevant_relevance_classes": [
53139
+ "DISCOVERY_CALL_NARRATIVE"
53140
+ ],
53141
+ "missing_value_authority": "D16_DISCOVERY_CALL_BASELINE"
53142
+ }
53143
+ },
53144
+ "sourceFieldRelevanceMap": {
53145
+ "discovery_call.hero.body": "DISCOVERY_CALL_NARRATIVE",
53146
+ "coach.full_name": "IDENTITY_FACT",
53147
+ "coach.first_name": "IDENTITY_FACT",
53148
+ "coach.last_name": "IDENTITY_FACT",
53149
+ "verified_context.approved_service_labels": "PRACTICE_FACT"
53150
+ }
53151
+ }
53152
+ };
53153
+ }
53154
+ });
53155
+
52829
53156
  // dist/src/lib/contract.js
52830
53157
  var require_contract = __commonJS({
52831
53158
  "dist/src/lib/contract.js"(exports2) {
52832
53159
  "use strict";
52833
53160
  Object.defineProperty(exports2, "__esModule", { value: true });
52834
53161
  exports2.ALL_OUTPUT_KEYS = exports2.PROMPT_DEFINITIONS = exports2.PROMPT_IDS = exports2.CONTRACT_VERSION = exports2.CONTRACT_ID = void 0;
53162
+ exports2.conditionallyOmittedKeys = conditionallyOmittedKeys;
53163
+ exports2.effectiveOutputKeys = effectiveOutputKeys;
53164
+ exports2.conditionallyOmittedKeysFromGrounding = conditionallyOmittedKeysFromGrounding;
52835
53165
  exports2.isObject = isObject;
52836
53166
  exports2.sha256Canonical = sha256Canonical;
52837
53167
  exports2.requiredOutputSchemaForPrompt = requiredOutputSchemaForPrompt;
53168
+ exports2.effectiveOutputSchemaForPrompt = effectiveOutputSchemaForPrompt;
52838
53169
  exports2.assertCanonicalSourcePacket = assertCanonicalSourcePacket;
52839
53170
  exports2.buildBoundedNarrativeJob = buildBoundedNarrativeJob;
52840
53171
  exports2.assertBoundedJob = assertBoundedJob;
52841
53172
  exports2.validateNarrativeResponse = validateNarrativeResponse;
52842
53173
  exports2.narrativeFailure = narrativeFailure;
52843
53174
  var node_crypto_1 = require("node:crypto");
52844
- exports2.CONTRACT_ID = "OPENCODE_AI_ENRICHMENT_V1_1";
52845
- exports2.CONTRACT_VERSION = "1.1.0";
53175
+ var source_policy_generated_1 = require_source_policy_generated();
53176
+ exports2.CONTRACT_ID = "OPENCODE_AI_ENRICHMENT_V1_2";
53177
+ exports2.CONTRACT_VERSION = "1.2.0";
52846
53178
  exports2.PROMPT_IDS = ["ABOUT_V1", "BUSINESS_COACHING_V1", "EXECUTIVE_COACHING_V1", "RESULTS_V1", "CONTACT_V1", "DISCOVERY_CALL_V1"];
52847
53179
  var COMMON_CONTEXT = ["coach.full_name", "coach.first_name", "coach.last_name", "coach.title"];
52848
53180
  var LOCATION_CONTEXT = ["coach_identity.location.city", "coach_identity.location.state"];
@@ -52861,48 +53193,111 @@ var require_contract = __commonJS({
52861
53193
  "about.industries.heading": "PLAIN_TEXT_STRING"
52862
53194
  },
52863
53195
  exactCopyKeys: [],
52864
- allowedContextKeys: [...COMMON_CONTEXT, ...LOCATION_CONTEXT, "about.industry_1.title", "about.industry_1.description", "about.industry_2.title", "about.industry_2.description", "about.industry_3.title", "about.industry_3.description", "verified_context.approved_career_facts", "verified_context.verified_media", "verified_context.approved_service_labels"]
53196
+ conditionalKeys: [{ canonicalField: "about.industries.heading", requiredWhen: "INDUSTRIES_GROUP populated_fields >= 1" }],
53197
+ allowedContextKeys: [...COMMON_CONTEXT, ...LOCATION_CONTEXT, "about.industry_1.title", "about.industry_1.description", "about.industry_2.title", "about.industry_2.description", "about.industry_3.title", "about.industry_3.description", "verified_context.approved_career_facts", "verified_context.verified_media", "verified_context.approved_service_labels"],
53198
+ sourcePolicy: source_policy_generated_1.SOURCE_EVIDENCE_POLICY.ABOUT_V1
52865
53199
  },
52866
53200
  BUSINESS_COACHING_V1: {
52867
53201
  packetName: "AI Source \u2014 Business Coaching",
52868
53202
  outputKeys: ["business_coaching.hero.heading", "business_coaching.hero.body", "business_coaching.intro.body"],
52869
53203
  formats: { "business_coaching.hero.heading": "PLAIN_TEXT_STRING", "business_coaching.hero.body": "PLAIN_TEXT_STRING", "business_coaching.intro.body": "HTML_FRAGMENT_STRING" },
52870
53204
  exactCopyKeys: [],
52871
- allowedContextKeys: [...COMMON_CONTEXT, ...LOCATION_CONTEXT, "verified_context.approved_service_labels", "verified_context.approved_career_facts"]
53205
+ conditionalKeys: [],
53206
+ allowedContextKeys: [...COMMON_CONTEXT, ...LOCATION_CONTEXT, "verified_context.approved_service_labels", "verified_context.approved_career_facts"],
53207
+ sourcePolicy: source_policy_generated_1.SOURCE_EVIDENCE_POLICY.BUSINESS_COACHING_V1
52872
53208
  },
52873
53209
  EXECUTIVE_COACHING_V1: {
52874
53210
  packetName: "AI Source \u2014 Executive Coaching",
52875
53211
  outputKeys: ["executive_coaching.hero.heading", "executive_coaching.hero.body"],
52876
53212
  formats: { "executive_coaching.hero.heading": "PLAIN_TEXT_STRING", "executive_coaching.hero.body": "PLAIN_TEXT_STRING" },
52877
53213
  exactCopyKeys: [],
52878
- allowedContextKeys: [...COMMON_CONTEXT, ...LOCATION_CONTEXT, "verified_context.approved_service_labels", "verified_context.approved_career_facts"]
53214
+ conditionalKeys: [],
53215
+ allowedContextKeys: [...COMMON_CONTEXT, ...LOCATION_CONTEXT, "verified_context.approved_service_labels", "verified_context.approved_career_facts"],
53216
+ sourcePolicy: source_policy_generated_1.SOURCE_EVIDENCE_POLICY.EXECUTIVE_COACHING_V1
52879
53217
  },
52880
53218
  RESULTS_V1: {
52881
53219
  packetName: "AI Source \u2014 Results",
52882
53220
  outputKeys: ["results.intro.body"],
52883
53221
  formats: { "results.intro.body": "PLAIN_TEXT_STRING" },
52884
53222
  exactCopyKeys: [],
52885
- allowedContextKeys: [...COMMON_CONTEXT, "verified_context.approved_career_facts", "verified_context.approved_service_labels"]
53223
+ conditionalKeys: [],
53224
+ allowedContextKeys: [...COMMON_CONTEXT, "verified_context.approved_career_facts", "verified_context.approved_service_labels"],
53225
+ sourcePolicy: source_policy_generated_1.SOURCE_EVIDENCE_POLICY.RESULTS_V1
52886
53226
  },
52887
53227
  CONTACT_V1: {
52888
53228
  packetName: "AI Source \u2014 Contact",
52889
53229
  outputKeys: ["contact.hero.heading", "contact.intro.body"],
52890
53230
  formats: { "contact.hero.heading": "PLAIN_TEXT_STRING", "contact.intro.body": "PLAIN_TEXT_STRING" },
52891
53231
  exactCopyKeys: ["contact.hero.heading", "contact.intro.body"],
52892
- allowedContextKeys: [...COMMON_CONTEXT, ...LOCATION_CONTEXT, "verified_context.approved_service_labels"]
53232
+ conditionalKeys: [],
53233
+ allowedContextKeys: [...COMMON_CONTEXT, ...LOCATION_CONTEXT, "verified_context.approved_service_labels"],
53234
+ sourcePolicy: source_policy_generated_1.SOURCE_EVIDENCE_POLICY.CONTACT_V1
52893
53235
  },
52894
53236
  DISCOVERY_CALL_V1: {
52895
53237
  packetName: "AI Source \u2014 Discovery Call",
52896
53238
  outputKeys: ["discovery_call.hero.body"],
52897
53239
  formats: { "discovery_call.hero.body": "PLAIN_TEXT_STRING" },
52898
53240
  exactCopyKeys: ["discovery_call.hero.body"],
52899
- allowedContextKeys: [...COMMON_CONTEXT, ...LOCATION_CONTEXT, "verified_context.approved_service_labels"]
53241
+ conditionalKeys: [],
53242
+ allowedContextKeys: [...COMMON_CONTEXT, ...LOCATION_CONTEXT, "verified_context.approved_service_labels"],
53243
+ sourcePolicy: source_policy_generated_1.SOURCE_EVIDENCE_POLICY.DISCOVERY_CALL_V1
52900
53244
  }
52901
53245
  };
52902
53246
  exports2.ALL_OUTPUT_KEYS = exports2.PROMPT_IDS.flatMap((id) => [...exports2.PROMPT_DEFINITIONS[id].outputKeys]);
52903
- var JOB_KEYS = ["prompt_id", "source_text", "source_evidence", "verified_factual_context", "required_output_schema", "source_locators", "source_packet_digest", "contract_version"];
53247
+ function conditionallyOmittedKeys(promptId, conditionalSectionStates) {
53248
+ const definition = exports2.PROMPT_DEFINITIONS[promptId];
53249
+ if (!definition.conditionalKeys.length)
53250
+ return [];
53251
+ const omitted = [];
53252
+ for (const conditional of definition.conditionalKeys) {
53253
+ if (conditional.requiredWhen !== "INDUSTRIES_GROUP populated_fields >= 1")
53254
+ throw new Error("BOUNDED_AI_CONDITIONAL_KEY_POLICY_INVALID");
53255
+ const industries = conditionalSectionStates.find((state) => state.group === "INDUSTRIES_GROUP");
53256
+ if (!industries)
53257
+ throw new Error("BOUNDED_AI_CONDITIONAL_STATE_REQUIRED");
53258
+ if (Number(industries.populated_fields ?? 0) === 0)
53259
+ omitted.push(conditional.canonicalField);
53260
+ }
53261
+ return omitted;
53262
+ }
53263
+ function effectiveOutputKeys(promptId, grounding) {
53264
+ const omitted = new Set(conditionallyOmittedKeysFromGrounding(promptId, grounding));
53265
+ return exports2.PROMPT_DEFINITIONS[promptId].outputKeys.filter((key) => !omitted.has(key));
53266
+ }
53267
+ function conditionallyOmittedKeysFromGrounding(promptId, grounding) {
53268
+ const conditionalFields = new Set(exports2.PROMPT_DEFINITIONS[promptId].conditionalKeys.map((key) => key.canonicalField));
53269
+ if (!conditionalFields.size) {
53270
+ for (const record of grounding)
53271
+ if (record.grounding_status === "CONDITIONALLY_OMITTED")
53272
+ throw new Error("BOUNDED_AI_CONDITIONAL_KEY_POLICY_INVALID");
53273
+ return [];
53274
+ }
53275
+ const omitted = [];
53276
+ const seen = /* @__PURE__ */ new Set();
53277
+ for (const record of grounding) {
53278
+ const field = String(record.canonical_field ?? "");
53279
+ if (!conditionalFields.has(field))
53280
+ continue;
53281
+ if (seen.has(field))
53282
+ throw new Error("BOUNDED_AI_GROUNDING_DUPLICATE");
53283
+ seen.add(field);
53284
+ if (record.grounding_status === "CONDITIONALLY_OMITTED")
53285
+ omitted.push(field);
53286
+ else if (record.grounding_status !== "GROUNDED" && record.grounding_status !== "NO_SUPPORTING_EVIDENCE")
53287
+ throw new Error("BOUNDED_AI_CONDITIONAL_STATUS_INVALID");
53288
+ }
53289
+ for (const field of conditionalFields)
53290
+ if (!seen.has(field))
53291
+ throw new Error("BOUNDED_AI_CONDITIONAL_STATE_REQUIRED");
53292
+ return omitted;
53293
+ }
53294
+ var GROUNDING_RECORD_KEYS = ["canonical_field", "grounding_status", "grounding_evidence_references", "grounding_basis"];
53295
+ var GROUNDING_STATUSES = ["GROUNDED", "NO_SUPPORTING_EVIDENCE", "CONDITIONALLY_OMITTED"];
53296
+ var TEMPLATE_BASELINE_KEYS = ["manifest_digest", "manifest_version", "elements"];
53297
+ var TEMPLATE_BASELINE_ELEMENT_KEYS = ["element_id", "element_type", "pages_rendered", "section_name", "captured_content", "content_sha256"];
53298
+ var JOB_KEYS = ["prompt_id", "source_text", "source_evidence", "verified_factual_context", "required_output_schema", "source_locators", "source_packet_digest", "contract_version", "grounding", "template_baseline"];
52904
53299
  var RESPONSE_KEYS = ["contract_id", "prompt_id", "status", "source_packet_digest", "outputs", "provenance", "no_new_facts_attestation", "errors"];
52905
- var PACKET_KEYS = ["packet_name", "prompt_id", "logical_source_column_name", "source_text", "source_locators", "source_page_references", "source_evidence_references", "evidence_status", "source_packet_digest"];
53300
+ var PACKET_KEYS = ["packet_name", "prompt_id", "logical_source_column_name", "source_text", "source_locators", "source_page_references", "source_evidence_references", "evidence_pool", "grounding", "evidence_status", "source_packet_digest"];
52906
53301
  var EVIDENCE_KEYS = ["evidence_reference", "canonical_field", "page_url", "page_title", "source_locator", "source_text"];
52907
53302
  var DIGEST = /^sha256:[0-9a-f]{64}$/;
52908
53303
  function isObject(value) {
@@ -52944,18 +53339,100 @@ var require_contract = __commonJS({
52944
53339
  properties: Object.fromEntries(definition.outputKeys.map((key) => [key, { type: "string", minLength: 1, output_format: definition.formats[key] }]))
52945
53340
  };
52946
53341
  }
52947
- function assertEvidence(evidence, definition, index) {
53342
+ function effectiveOutputSchemaForPrompt(promptId, grounding) {
53343
+ const definition = exports2.PROMPT_DEFINITIONS[promptId];
53344
+ const effective = effectiveOutputKeys(promptId, grounding);
53345
+ return {
53346
+ type: "object",
53347
+ additionalProperties: false,
53348
+ required: [...effective],
53349
+ properties: Object.fromEntries(effective.map((key) => [key, { type: "string", minLength: 1, output_format: definition.formats[key] }]))
53350
+ };
53351
+ }
53352
+ function assertEvidence(evidence, index) {
52948
53353
  assertExactKeys(evidence, EVIDENCE_KEYS, `SOURCE_EVIDENCE_${index}`);
52949
53354
  const { evidence_reference: reference, ...digestInput } = evidence;
52950
53355
  if (reference !== sha256Canonical(digestInput))
52951
53356
  throw new Error(`SOURCE_EVIDENCE_${index}_DIGEST_INVALID`);
52952
- if (typeof evidence.canonical_field !== "string" || !definition.outputKeys.includes(evidence.canonical_field))
53357
+ if (typeof evidence.canonical_field !== "string" || !evidence.canonical_field.trim())
52953
53358
  throw new Error(`SOURCE_EVIDENCE_${index}_FIELD_INVALID`);
52954
53359
  for (const key of ["page_url", "page_title", "source_locator", "source_text"])
52955
53360
  if (typeof evidence[key] !== "string" || !evidence[key].trim())
52956
53361
  throw new Error(`SOURCE_EVIDENCE_${index}_${key.toUpperCase()}_INVALID`);
52957
53362
  }
52958
- function assertCanonicalSourcePacket(value, expectedPromptId, requireReady = true) {
53363
+ var VERIFIED_CONTEXT_STATUSES = ["EXACT_SOURCE", "VERIFIED_FACT", "DERIVED"];
53364
+ var UNVERIFIED_CONTEXT_AUTHORITIES = ["LEGACY_WEBSITE_EXACT", "AI_REWRITE_FROM_SOURCE"];
53365
+ function verifiedContextAuthority(value, factualProvenance) {
53366
+ if (!isObject(value) || !isObject(value.values) || !isObject(value.evidence))
53367
+ throw new Error("SOURCE_PACKET_VERIFIED_CONTEXT_INVALID");
53368
+ const provenance = factualProvenance === void 0 ? void 0 : factualProvenance;
53369
+ if (provenance !== void 0 && !Array.isArray(provenance))
53370
+ throw new Error("SOURCE_PACKET_FACTUAL_PROVENANCE_INVALID");
53371
+ const eligibleProvenance = (Array.isArray(provenance) ? provenance : []).filter((entry) => isObject(entry) && VERIFIED_CONTEXT_STATUSES.includes(String(entry.status)) && typeof entry.source_authority === "string" && !UNVERIFIED_CONTEXT_AUTHORITIES.includes(entry.source_authority) && !(entry.source_authority === "DERIVED_DETERMINISTIC" && entry.requires_human_review === true) && Array.isArray(entry.source_refs));
53372
+ const provenanceByField = new Map(eligibleProvenance.map((entry) => [String(entry.canonical_field), entry]));
53373
+ const provenanceSourceRefs = new Set(eligibleProvenance.flatMap((entry) => entry.source_refs.map((ref) => JSON.stringify(canonicalize(ref)))));
53374
+ const keys = /* @__PURE__ */ new Set();
53375
+ for (const [key, rawEvidence] of Object.entries(value.evidence)) {
53376
+ const rawValue = getPath(value.values, key);
53377
+ if (rawValue === void 0 || !isObject(rawEvidence))
53378
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_ENTRY_INVALID:${key}`);
53379
+ assertExactKeys(rawEvidence, ["value", "source_authority", "source_refs", "status"], `SOURCE_PACKET_VERIFIED_CONTEXT_ENTRY:${key}`);
53380
+ if (JSON.stringify(canonicalize(rawEvidence.value)) !== JSON.stringify(canonicalize(rawValue)))
53381
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_VALUE_MISMATCH:${key}`);
53382
+ if (!VERIFIED_CONTEXT_STATUSES.includes(String(rawEvidence.status)))
53383
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_STATUS_INVALID:${key}`);
53384
+ if (typeof rawEvidence.source_authority !== "string" || UNVERIFIED_CONTEXT_AUTHORITIES.includes(rawEvidence.source_authority))
53385
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_AUTHORITY_INVALID:${key}`);
53386
+ if (!Array.isArray(rawEvidence.source_refs) || rawEvidence.source_refs.length === 0 || rawEvidence.source_refs.some((ref) => !isObject(ref)))
53387
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_SOURCE_REFS_INVALID:${key}`);
53388
+ if (provenance !== void 0) {
53389
+ for (const ref of rawEvidence.source_refs)
53390
+ if (!provenanceSourceRefs.has(JSON.stringify(canonicalize(ref))))
53391
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_SOURCE_REF_UNBOUND:${key}`);
53392
+ const provenanceField = key.replace(/^coach_identity\.location\./, "coach.location.");
53393
+ const direct = provenanceByField.get(provenanceField);
53394
+ const requiresDirectProvenance = !key.startsWith("verified_context.") && !key.startsWith("coach_identity.location.");
53395
+ if (requiresDirectProvenance && !direct)
53396
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_PROVENANCE_UNRESOLVED:${key}`);
53397
+ if (direct) {
53398
+ for (const member of ["value", "source_authority", "source_refs", "status"]) {
53399
+ if (JSON.stringify(canonicalize(rawEvidence[member])) !== JSON.stringify(canonicalize(direct[member])))
53400
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_PROVENANCE_MISMATCH:${key}:${member}`);
53401
+ }
53402
+ }
53403
+ if (key.startsWith("verified_context.")) {
53404
+ const aggregateDomains = {
53405
+ "verified_context.approved_career_facts": (entry) => String(entry.canonical_field).startsWith("about.stat_"),
53406
+ "verified_context.verified_media": (entry) => String(entry.canonical_field).startsWith("about.media."),
53407
+ "verified_context.approved_service_labels": (entry) => ["coach.title", "coach.service_area_heading", "coach.service_area_line"].includes(String(entry.canonical_field))
53408
+ };
53409
+ const inDomain = aggregateDomains[key];
53410
+ if (!inDomain || rawEvidence.source_authority !== "DERIVED_DETERMINISTIC" || rawEvidence.status !== "DERIVED")
53411
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_AGGREGATE_AUTHORITY_INVALID:${key}`);
53412
+ const records = key === "verified_context.approved_service_labels" ? ["coach.title", "coach.service_area_heading", "coach.service_area_line"].map((field) => provenanceByField.get(field)).filter((entry) => Boolean(entry)) : eligibleProvenance.filter(inDomain);
53413
+ const expectedValue = records.map((entry) => ({ canonical_field: entry.canonical_field, value: entry.value }));
53414
+ const expectedRefs = records.flatMap((entry) => entry.source_refs);
53415
+ if (JSON.stringify(canonicalize(rawEvidence.value)) !== JSON.stringify(canonicalize(expectedValue)))
53416
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_AGGREGATE_VALUE_INVALID:${key}`);
53417
+ if (JSON.stringify(canonicalize(rawEvidence.source_refs)) !== JSON.stringify(canonicalize(expectedRefs)))
53418
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_AGGREGATE_REFS_INVALID:${key}`);
53419
+ }
53420
+ }
53421
+ keys.add(key);
53422
+ }
53423
+ return { keys, values: value.values };
53424
+ }
53425
+ function sourceFieldAllowedForClass(definition, evidenceClass, canonicalField) {
53426
+ if (evidenceClass === "FIELD_EVIDENCE" || evidenceClass === "PAGE_SECTION_EXCERPT")
53427
+ return definition.sourcePolicy.groundingFieldAllowlist.includes(canonicalField);
53428
+ if (evidenceClass === "DETERMINISTIC_FACT" || evidenceClass === "VERIFIED_FACTUAL_CONTEXT" || evidenceClass === "PRACTICE_CONTEXT")
53429
+ return definition.sourcePolicy.factFieldAllowlist.includes(canonicalField);
53430
+ return false;
53431
+ }
53432
+ function jobSourceFieldAllowed(definition, canonicalField) {
53433
+ return definition.sourcePolicy.groundingFieldAllowlist.includes(canonicalField) || definition.sourcePolicy.factFieldAllowlist.includes(canonicalField);
53434
+ }
53435
+ function assertCanonicalSourcePacket(value, expectedPromptId, requireReady = true, verifiedFactualContext, factualProvenance) {
52959
53436
  assertExactKeys(value, PACKET_KEYS, "SOURCE_PACKET");
52960
53437
  const definition = promptDefinition(value.prompt_id);
52961
53438
  if (expectedPromptId && value.prompt_id !== expectedPromptId)
@@ -52966,13 +53443,22 @@ var require_contract = __commonJS({
52966
53443
  throw new Error("SOURCE_PACKET_EVIDENCE_STATUS_INVALID");
52967
53444
  if (requireReady && value.evidence_status !== "READY")
52968
53445
  throw new Error("SOURCE_PACKET_INSUFFICIENT_EVIDENCE");
52969
- if (!Array.isArray(value.source_evidence_references) || value.evidence_status === "READY" && value.source_evidence_references.length === 0)
53446
+ if (!Array.isArray(value.source_evidence_references))
52970
53447
  throw new Error("SOURCE_PACKET_EVIDENCE_REQUIRED");
52971
- value.source_evidence_references.forEach((entry, index) => assertEvidence(entry, definition, index));
52972
- const covered = new Set(value.source_evidence_references.map((entry) => String(entry.canonical_field)));
52973
- const missing = definition.outputKeys.filter((key) => !covered.has(key));
52974
- if (value.evidence_status === "READY" && missing.length)
52975
- throw new Error(`SOURCE_PACKET_EVIDENCE_INCOMPLETE:${missing.join(",")}`);
53448
+ const sourceReferences = /* @__PURE__ */ new Map();
53449
+ value.source_evidence_references.forEach((entry, index) => {
53450
+ assertEvidence(entry, index);
53451
+ const reference = String(entry.evidence_reference);
53452
+ if (sourceReferences.has(reference))
53453
+ throw new Error(`SOURCE_EVIDENCE_${index}_DUPLICATE_ID`);
53454
+ sourceReferences.set(reference, entry);
53455
+ });
53456
+ const contextAuthority = verifiedContextAuthority(verifiedFactualContext, factualProvenance);
53457
+ const pool = assertEvidencePool(value.evidence_pool, definition, sourceReferences, contextAuthority);
53458
+ assertGroundingRecords(value.grounding, definition, new Set(pool.pageEntries.keys()), new Set(pool.contextEntries.keys()), pool.relevanceByReference);
53459
+ const unresolved = (Array.isArray(value.grounding) ? value.grounding : []).filter((record) => record.grounding_status === "NO_SUPPORTING_EVIDENCE" && String(record.grounding_basis).endsWith("UNRESOLVED_POLICY"));
53460
+ if (value.evidence_status === "READY" && unresolved.length)
53461
+ throw new Error(`SOURCE_PACKET_UNRESOLVED_POLICY:${unresolved.map((record) => String(record.canonical_field)).join(",")}`);
52976
53462
  const expectedText = value.source_evidence_references.map((entry) => entry.source_text).join("\n\n");
52977
53463
  if (value.source_text !== expectedText)
52978
53464
  throw new Error("SOURCE_PACKET_TEXT_INVALID");
@@ -52986,20 +53472,146 @@ var require_contract = __commonJS({
52986
53472
  if (digest !== sha256Canonical(digestInput))
52987
53473
  throw new Error("SOURCE_PACKET_DIGEST_INVALID");
52988
53474
  }
53475
+ function assertGroundingRecords(grounding, definition, evidenceReferences, verifiedContextKeys, relevanceByReference) {
53476
+ if (!Array.isArray(grounding) || grounding.length !== definition.outputKeys.length)
53477
+ throw new Error("SOURCE_PACKET_GROUNDING_COUNT_INVALID");
53478
+ const seen = /* @__PURE__ */ new Set();
53479
+ grounding.forEach((raw) => {
53480
+ assertExactKeys(raw, GROUNDING_RECORD_KEYS, "SOURCE_PACKET_GROUNDING");
53481
+ const record = raw;
53482
+ const field = String(record.canonical_field);
53483
+ if (!definition.outputKeys.includes(field) || seen.has(field))
53484
+ throw new Error(`SOURCE_PACKET_GROUNDING_FIELD_INVALID:${field}`);
53485
+ seen.add(field);
53486
+ const status = String(record.grounding_status);
53487
+ if (!GROUNDING_STATUSES.includes(status))
53488
+ throw new Error("SOURCE_PACKET_GROUNDING_STATUS_INVALID");
53489
+ const refs = record.grounding_evidence_references;
53490
+ if (!Array.isArray(refs) || refs.some((ref) => typeof ref !== "string" || !ref.trim()) || new Set(refs).size !== refs.length)
53491
+ throw new Error("SOURCE_PACKET_GROUNDING_REFS_INVALID");
53492
+ if (status === "GROUNDED" && refs.length === 0)
53493
+ throw new Error("SOURCE_PACKET_GROUNDED_REQUIRES_REFERENCES");
53494
+ if (status !== "GROUNDED" && refs.length)
53495
+ throw new Error("SOURCE_PACKET_GROUNDING_REFS_UNEXPECTED");
53496
+ for (const ref of refs) {
53497
+ if (!evidenceReferences.has(ref) && !verifiedContextKeys.has(ref))
53498
+ throw new Error(`SOURCE_PACKET_GROUNDING_REFERENCE_UNRESOLVED:${ref}`);
53499
+ if (relevanceByReference) {
53500
+ const destinationPolicy = definition.sourcePolicy.destinationGroundingMap[field];
53501
+ const relevance = relevanceByReference.get(ref);
53502
+ if (!destinationPolicy || !relevance || !destinationPolicy.relevant_relevance_classes.includes(relevance)) {
53503
+ throw new Error(`SOURCE_PACKET_GROUNDING_RELEVANCE_INVALID:${field}:${ref}`);
53504
+ }
53505
+ }
53506
+ }
53507
+ if (typeof record.grounding_basis !== "string" || !record.grounding_basis.trim())
53508
+ throw new Error("SOURCE_PACKET_GROUNDING_BASIS_INVALID");
53509
+ });
53510
+ for (const key of definition.outputKeys)
53511
+ if (!seen.has(key))
53512
+ throw new Error(`SOURCE_PACKET_GROUNDING_MISSING:${key}`);
53513
+ }
53514
+ function assertEvidencePool(pool, definition, sourceReferences, verifiedContext) {
53515
+ if (!Array.isArray(pool))
53516
+ throw new Error("SOURCE_PACKET_EVIDENCE_POOL_REQUIRED");
53517
+ const pageAttributedClasses = ["FIELD_EVIDENCE", "PAGE_SECTION_EXCERPT", "DETERMINISTIC_FACT"];
53518
+ const contextClasses = ["VERIFIED_FACTUAL_CONTEXT", "PRACTICE_CONTEXT"];
53519
+ const pageEntries = /* @__PURE__ */ new Map();
53520
+ const contextEntries = /* @__PURE__ */ new Map();
53521
+ const relevanceByReference = /* @__PURE__ */ new Map();
53522
+ for (const raw of pool) {
53523
+ assertExactKeys(raw, ["evidence_reference", "evidence_class", "canonical_field", "page_url", "page_title", "source_locator", "source_text", "relevance_class"], "SOURCE_PACKET_EVIDENCE_POOL_ENTRY");
53524
+ const entry = raw;
53525
+ const reference = String(entry.evidence_reference ?? "");
53526
+ if (!reference)
53527
+ throw new Error("SOURCE_PACKET_EVIDENCE_REFERENCE_INVALID");
53528
+ if (pageEntries.has(reference) || contextEntries.has(reference))
53529
+ throw new Error(`SOURCE_PACKET_EVIDENCE_POOL_DUPLICATE_ID:${reference}`);
53530
+ const evidenceClass = String(entry.evidence_class);
53531
+ if (![...pageAttributedClasses, ...contextClasses].includes(evidenceClass))
53532
+ throw new Error(`SOURCE_PACKET_EVIDENCE_CLASS_INVALID:${evidenceClass}`);
53533
+ const canonicalField = String(entry.canonical_field ?? "");
53534
+ if (!canonicalField || !sourceFieldAllowedForClass(definition, evidenceClass, canonicalField))
53535
+ throw new Error(`SOURCE_PACKET_EVIDENCE_FIELD_INVALID:${evidenceClass}:${canonicalField}`);
53536
+ const relevance = String(entry.relevance_class ?? "");
53537
+ const authoritativeRelevance = definition.sourcePolicy.sourceFieldRelevanceMap[canonicalField];
53538
+ if (!authoritativeRelevance || relevance !== authoritativeRelevance)
53539
+ throw new Error(`SOURCE_PACKET_EVIDENCE_RELEVANCE_INVALID:${canonicalField}:${relevance}`);
53540
+ if (pageAttributedClasses.includes(evidenceClass)) {
53541
+ if (typeof entry.page_url !== "string" || !entry.page_url.trim() || typeof entry.page_title !== "string" || !entry.page_title.trim() || typeof entry.source_locator !== "string" || !entry.source_locator.trim())
53542
+ throw new Error(`SOURCE_PACKET_EVIDENCE_PROVENANCE_INVALID:${evidenceClass}`);
53543
+ const digestInput = { canonical_field: entry.canonical_field, page_url: entry.page_url, page_title: entry.page_title, source_locator: entry.source_locator, source_text: entry.source_text };
53544
+ if (entry.evidence_reference !== sha256Canonical(digestInput))
53545
+ throw new Error(`SOURCE_PACKET_EVIDENCE_DIGEST_INVALID:${String(entry.canonical_field)}`);
53546
+ pageEntries.set(reference, entry);
53547
+ } else {
53548
+ if (entry.page_url !== null || entry.page_title !== null || entry.source_locator !== null)
53549
+ throw new Error("SOURCE_PACKET_EVIDENCE_CONTEXT_PROVENANCE_UNEXPECTED");
53550
+ if (entry.evidence_reference !== String(entry.canonical_field ?? ""))
53551
+ throw new Error("SOURCE_PACKET_EVIDENCE_CONTEXT_KEY_INVALID");
53552
+ if (!verifiedContext.keys.has(canonicalField))
53553
+ throw new Error(`SOURCE_PACKET_EVIDENCE_CONTEXT_UNRESOLVED:${canonicalField}`);
53554
+ const contextValue = getPath(verifiedContext.values, canonicalField);
53555
+ if (entry.source_text !== JSON.stringify(canonicalize(contextValue)))
53556
+ throw new Error(`SOURCE_PACKET_EVIDENCE_CONTEXT_PROJECTION_INVALID:${canonicalField}`);
53557
+ contextEntries.set(reference, entry);
53558
+ }
53559
+ if (typeof entry.source_text !== "string" || !entry.source_text.trim())
53560
+ throw new Error("SOURCE_PACKET_EVIDENCE_TEXT_REQUIRED");
53561
+ if (entry.source_text.length > 2e3)
53562
+ throw new Error("SOURCE_PACKET_EVIDENCE_EXCERPT_OVERBOUND");
53563
+ relevanceByReference.set(reference, relevance);
53564
+ }
53565
+ if (pool.length > 48)
53566
+ throw new Error("SOURCE_PACKET_EVIDENCE_POOL_OVERBOUND");
53567
+ if (pageEntries.size !== sourceReferences.size)
53568
+ throw new Error("SOURCE_PACKET_EVIDENCE_POOL_PROJECTION_COUNT_INVALID");
53569
+ for (const [reference, source] of sourceReferences) {
53570
+ const entry = pageEntries.get(reference);
53571
+ if (!entry)
53572
+ throw new Error(`SOURCE_PACKET_EVIDENCE_POOL_REFERENCE_UNRESOLVED:${reference}`);
53573
+ for (const key of ["evidence_reference", "canonical_field", "page_url", "page_title", "source_locator", "source_text"]) {
53574
+ if (entry[key] !== source[key])
53575
+ throw new Error(`SOURCE_PACKET_EVIDENCE_PROJECTION_MISMATCH:${reference}:${key}`);
53576
+ }
53577
+ }
53578
+ return { pageEntries, contextEntries, relevanceByReference };
53579
+ }
53580
+ function assertPreAiPackageOwnership(input, promptId) {
53581
+ if (!isObject(input.pre_ai_package))
53582
+ throw new Error("BOUNDARY_PRE_AI_PACKAGE_MUST_BE_OBJECT");
53583
+ const { package_digest: packageDigest, ...packageBody } = input.pre_ai_package;
53584
+ if (typeof packageDigest !== "string" || packageDigest !== sha256Canonical(packageBody))
53585
+ throw new Error("BOUNDARY_PRE_AI_PACKAGE_DIGEST_INVALID");
53586
+ if (!Array.isArray(packageBody.aiSourcePackets))
53587
+ throw new Error("BOUNDARY_PRE_AI_PACKAGE_PACKETS_INVALID");
53588
+ const ownedPacket = packageBody.aiSourcePackets.find((packet) => isObject(packet) && packet.prompt_id === promptId && JSON.stringify(canonicalize(packet)) === JSON.stringify(canonicalize(input.source_packet)));
53589
+ if (!ownedPacket)
53590
+ throw new Error(`BOUNDARY_SOURCE_PACKET_NOT_OWNED_BY_PRE_AI_PACKAGE:${promptId}`);
53591
+ if (JSON.stringify(canonicalize(packageBody.verifiedFactualContext)) !== JSON.stringify(canonicalize(input.verified_factual_context))) {
53592
+ throw new Error("BOUNDARY_VERIFIED_CONTEXT_NOT_OWNED_BY_PRE_AI_PACKAGE");
53593
+ }
53594
+ return packageBody;
53595
+ }
52989
53596
  function buildBoundedNarrativeJob(input) {
52990
- assertExactKeys(input, ["contract_id", "prompt_id", "source_packet", "verified_factual_context", "required_output_schema"], "BOUNDARY_INPUT");
53597
+ assertExactKeys(input, ["contract_id", "prompt_id", "source_packet", "verified_factual_context", "pre_ai_package", "required_output_schema", "template_baseline"], "BOUNDARY_INPUT");
52991
53598
  if (input.contract_id !== exports2.CONTRACT_ID)
52992
53599
  throw new Error("BOUNDED_AI_CONTRACT_ID_INVALID");
52993
53600
  const definition = promptDefinition(input.prompt_id);
52994
53601
  const promptId = input.prompt_id;
52995
- assertCanonicalSourcePacket(input.source_packet, promptId);
52996
- const expectedSchema = requiredOutputSchemaForPrompt(promptId);
53602
+ const owningPackage = assertPreAiPackageOwnership(input, promptId);
53603
+ assertCanonicalSourcePacket(input.source_packet, promptId, true, input.verified_factual_context, owningPackage.factualProvenance);
53604
+ const packet = input.source_packet;
53605
+ if (!isObject(input.verified_factual_context))
53606
+ throw new Error("BOUNDED_AI_VERIFIED_CONTEXT_INVALID");
53607
+ const expectedSchema = effectiveOutputSchemaForPrompt(promptId, Array.isArray(packet.grounding) ? packet.grounding : []);
52997
53608
  if (JSON.stringify(canonicalize(input.required_output_schema)) !== JSON.stringify(canonicalize(expectedSchema)))
52998
53609
  throw new Error("BOUNDED_AI_OUTPUT_SCHEMA_INVALID");
52999
- if (!isObject(input.verified_factual_context))
53610
+ const contextSource = input.verified_factual_context;
53611
+ if (!isObject(contextSource))
53000
53612
  throw new Error("BOUNDED_AI_VERIFIED_CONTEXT_INVALID");
53001
- const values = isObject(input.verified_factual_context.values) ? input.verified_factual_context.values : {};
53002
- const evidence = isObject(input.verified_factual_context.evidence) ? input.verified_factual_context.evidence : {};
53613
+ const values = isObject(contextSource.values) ? contextSource.values : {};
53614
+ const evidence = isObject(contextSource.evidence) ? contextSource.evidence : {};
53003
53615
  const filteredContext = {};
53004
53616
  for (const key of definition.allowedContextKeys) {
53005
53617
  const rawEvidence = evidence[key];
@@ -53008,7 +53620,7 @@ var require_contract = __commonJS({
53008
53620
  continue;
53009
53621
  filteredContext[key] = { value: structuredClone(rawValue), evidence_refs: [...new Set(rawEvidence.source_refs.map((ref) => sha256Canonical(ref)))].sort() };
53010
53622
  }
53011
- const packet = input.source_packet;
53623
+ const templateBaseline = assertTemplateBaseline(input.template_baseline);
53012
53624
  const job = {
53013
53625
  prompt_id: promptId,
53014
53626
  source_text: String(packet.source_text),
@@ -53017,30 +53629,87 @@ var require_contract = __commonJS({
53017
53629
  required_output_schema: structuredClone(expectedSchema),
53018
53630
  source_locators: structuredClone(packet.source_locators),
53019
53631
  source_packet_digest: String(packet.source_packet_digest),
53020
- contract_version: exports2.CONTRACT_VERSION
53632
+ contract_version: exports2.CONTRACT_VERSION,
53633
+ grounding: structuredClone(packet.grounding),
53634
+ template_baseline: templateBaseline
53021
53635
  };
53022
53636
  assertBoundedJob(job);
53023
53637
  return job;
53024
53638
  }
53639
+ function assertTemplateBaseline(value) {
53640
+ assertExactKeys(value, TEMPLATE_BASELINE_KEYS, "TEMPLATE_BASELINE");
53641
+ const baseline = value;
53642
+ if (typeof baseline.manifest_digest !== "string" || !/^[0-9a-f]{64}$/.test(baseline.manifest_digest))
53643
+ throw new Error("TEMPLATE_BASELINE_DIGEST_INVALID");
53644
+ if (typeof baseline.manifest_version !== "string" || !baseline.manifest_version.trim())
53645
+ throw new Error("TEMPLATE_BASELINE_VERSION_INVALID");
53646
+ if (!Array.isArray(baseline.elements) || baseline.elements.length === 0)
53647
+ throw new Error("TEMPLATE_BASELINE_ELEMENTS_REQUIRED");
53648
+ for (const raw of baseline.elements) {
53649
+ assertExactKeys(raw, TEMPLATE_BASELINE_ELEMENT_KEYS, "TEMPLATE_BASELINE_ELEMENT");
53650
+ const element = raw;
53651
+ if (typeof element.captured_content !== "string" || !element.captured_content.trim())
53652
+ throw new Error("TEMPLATE_BASELINE_ELEMENT_CONTENT_REQUIRED");
53653
+ if (typeof element.content_sha256 !== "string" || element.content_sha256 !== (0, node_crypto_1.createHash)("sha256").update(String(element.captured_content), "utf8").digest("hex")) {
53654
+ throw new Error("TEMPLATE_BASELINE_ELEMENT_DIGEST_INVALID");
53655
+ }
53656
+ if (/POC-T\d/i.test(String(element.captured_content)))
53657
+ throw new Error("TEMPLATE_BASELINE_POC_RENDER_VALUE_REJECTED");
53658
+ }
53659
+ return structuredClone(value);
53660
+ }
53025
53661
  function assertBoundedJob(value) {
53026
53662
  assertExactKeys(value, JOB_KEYS, "BOUNDED_AI_JOB");
53027
53663
  const definition = promptDefinition(value.prompt_id);
53028
53664
  if (value.contract_version !== exports2.CONTRACT_VERSION)
53029
53665
  throw new Error("BOUNDED_AI_CONTRACT_VERSION_INVALID");
53030
- if (typeof value.source_text !== "string" || !value.source_text.trim())
53666
+ if (typeof value.source_text !== "string")
53031
53667
  throw new Error("BOUNDED_AI_SOURCE_TEXT_REQUIRED");
53032
- if (!Array.isArray(value.source_evidence) || value.source_evidence.length === 0)
53668
+ if (!Array.isArray(value.source_evidence))
53033
53669
  throw new Error("BOUNDED_AI_SOURCE_EVIDENCE_REQUIRED");
53034
- value.source_evidence.forEach((entry, index) => assertEvidence(entry, definition, index));
53035
- if (!Array.isArray(value.source_locators) || value.source_locators.some((entry) => typeof entry !== "string") || new Set(value.source_locators).size !== value.source_locators.length)
53036
- throw new Error("BOUNDED_AI_SOURCE_LOCATORS_INVALID");
53670
+ if (value.source_evidence.length > 0) {
53671
+ const seenEvidence = /* @__PURE__ */ new Set();
53672
+ value.source_evidence.forEach((entry, index) => {
53673
+ assertEvidence(entry, index);
53674
+ if (!jobSourceFieldAllowed(definition, String(entry.canonical_field)))
53675
+ throw new Error(`SOURCE_EVIDENCE_${index}_FIELD_INVALID`);
53676
+ const reference = String(entry.evidence_reference);
53677
+ if (seenEvidence.has(reference))
53678
+ throw new Error(`SOURCE_EVIDENCE_${index}_DUPLICATE_ID`);
53679
+ seenEvidence.add(reference);
53680
+ });
53681
+ if (typeof value.source_text !== "string" || !value.source_text.trim())
53682
+ throw new Error("BOUNDED_AI_SOURCE_TEXT_REQUIRED");
53683
+ if (!Array.isArray(value.source_locators) || value.source_locators.some((entry) => typeof entry !== "string") || new Set(value.source_locators).size !== value.source_locators.length)
53684
+ throw new Error("BOUNDED_AI_SOURCE_LOCATORS_INVALID");
53685
+ const expectedText = value.source_evidence.map((entry) => entry.source_text).join("\n\n");
53686
+ if (value.source_text !== expectedText)
53687
+ throw new Error("BOUNDED_AI_SOURCE_TEXT_INVALID");
53688
+ const expectedLocators = [...new Set(value.source_evidence.map((entry) => `${String(entry.page_url)}#${String(entry.source_locator)}`))].sort();
53689
+ if (JSON.stringify(value.source_locators) !== JSON.stringify(expectedLocators))
53690
+ throw new Error("BOUNDED_AI_SOURCE_LOCATORS_INVALID");
53691
+ } else {
53692
+ if (value.source_text !== "")
53693
+ throw new Error("BOUNDED_AI_SOURCE_TEXT_INVALID");
53694
+ if (!Array.isArray(value.source_locators) || value.source_locators.length !== 0)
53695
+ throw new Error("BOUNDED_AI_SOURCE_LOCATORS_INVALID");
53696
+ }
53037
53697
  if (!DIGEST.test(String(value.source_packet_digest)))
53038
53698
  throw new Error("BOUNDED_AI_PACKET_DIGEST_INVALID");
53039
53699
  if (!isObject(value.verified_factual_context) || Object.keys(value.verified_factual_context).some((key) => !definition.allowedContextKeys.includes(key)))
53040
53700
  throw new Error("BOUNDED_AI_VERIFIED_CONTEXT_INVALID");
53041
- if (JSON.stringify(canonicalize(value.required_output_schema)) !== JSON.stringify(canonicalize(requiredOutputSchemaForPrompt(value.prompt_id))))
53701
+ if (!Array.isArray(value.grounding))
53702
+ throw new Error("BOUNDED_AI_GROUNDING_REQUIRED");
53703
+ assertGroundingRecords(value.grounding, definition, evidenceReferenceSet(value.source_evidence), new Set(Object.keys(value.verified_factual_context)));
53704
+ if (typeof value.template_baseline !== "object" || value.template_baseline === null)
53705
+ throw new Error("TEMPLATE_BASELINE_REQUIRED");
53706
+ assertTemplateBaseline(value.template_baseline);
53707
+ if (JSON.stringify(canonicalize(value.required_output_schema)) !== JSON.stringify(canonicalize(effectiveOutputSchemaForPrompt(value.prompt_id, value.grounding))))
53042
53708
  throw new Error("BOUNDED_AI_OUTPUT_SCHEMA_INVALID");
53043
53709
  }
53710
+ function evidenceReferenceSet(sourceEvidence) {
53711
+ return new Set(sourceEvidence.map((entry) => String(entry.evidence_reference ?? "")));
53712
+ }
53044
53713
  function validateOutput(value, format, field, issues) {
53045
53714
  if (typeof value !== "string" || !value.trim()) {
53046
53715
  issues.push(`${field}:NON_EMPTY_STRING_REQUIRED`);
@@ -53089,15 +53758,23 @@ var require_contract = __commonJS({
53089
53758
  issues.push(...[...new Set(formatIssues)].map((issue) => `${field}:HTML_FRAGMENT_INVALID:${issue}`));
53090
53759
  }
53091
53760
  function validateFactMarkers(outputs, job, issues) {
53092
- const grounding = JSON.stringify(canonicalize({ source_text: job.source_text, verified_factual_context: job.verified_factual_context })).toLowerCase();
53093
- const patterns = [/https?:\/\/[^\s<>'"]+/gi, /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi, /(?:[$€£]\s?\d[\d,.]*|\b\d[\d,.]*\s?(?:%|percent|years?|clients?|businesses?|locations?|awards?|certifications?)\b)/gi, /\b(?:guaranteed?|award[- ]winning|certified|licensed|available 24\/7|speciali[sz](?:e|es|ed|ing) in)\b/gi];
53761
+ const coachCorpus = JSON.stringify(canonicalize({ source_text: job.source_text, verified_factual_context: job.verified_factual_context })).toLowerCase();
53762
+ const templateCorpus = JSON.stringify(canonicalize(job.template_baseline.elements ?? [])).toLowerCase();
53763
+ const personBoundPatterns = [/https?:\/\/[^\s<>'"]+/gi, /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi, /(?:[$€£]\s?\d[\d,.]*|\b\d[\d,.]*\s?(?:%|percent|years?|clients?|businesses?|locations?|awards?|certifications?)\b)/gi, /\b[A-Z][a-z]+\s+[A-Z][a-z]+\b/g];
53764
+ const genericClaimPatterns = [/\b(?:guaranteed?|award[- ]winning|certified|licensed|available 24\/7|speciali[sz](?:e|es|ed|ing) in)\b/gi];
53094
53765
  for (const [field, raw] of Object.entries(outputs)) {
53095
53766
  if (typeof raw !== "string")
53096
53767
  continue;
53097
- for (const pattern of patterns)
53768
+ for (const pattern of personBoundPatterns)
53098
53769
  for (const match of raw.matchAll(pattern))
53099
- if (!grounding.includes(match[0].toLowerCase().replace(/[.,;:!?]+$/, "")))
53770
+ if (!coachCorpus.includes(match[0].toLowerCase().replace(/[.,;:!?]+$/, "")))
53771
+ issues.push(`${field}:UNSUPPORTED_FACT_MARKER:${match[0]}`);
53772
+ for (const pattern of genericClaimPatterns)
53773
+ for (const match of raw.matchAll(pattern)) {
53774
+ const marker = match[0].toLowerCase();
53775
+ if (!coachCorpus.includes(marker) && !templateCorpus.includes(marker))
53100
53776
  issues.push(`${field}:UNSUPPORTED_FACT_MARKER:${match[0]}`);
53777
+ }
53101
53778
  }
53102
53779
  }
53103
53780
  function validateNarrativeResponse(value, job) {
@@ -53122,18 +53799,23 @@ var require_contract = __commonJS({
53122
53799
  issues.push("OUTPUTS_INVALID");
53123
53800
  if (!Array.isArray(value.provenance))
53124
53801
  issues.push("PROVENANCE_INVALID");
53802
+ const effectiveKeys = effectiveOutputKeys(job.prompt_id, job.grounding);
53803
+ const omittedKeys = new Set(conditionallyOmittedKeysFromGrounding(job.prompt_id, job.grounding));
53125
53804
  if (value.status === "OK" && isObject(value.outputs) && Array.isArray(value.provenance)) {
53126
53805
  try {
53127
- assertExactKeys(value.outputs, definition.outputKeys, "OUTPUTS");
53806
+ assertExactKeys(value.outputs, effectiveKeys, "OUTPUTS");
53128
53807
  } catch (error) {
53129
53808
  issues.push(error instanceof Error ? error.message : String(error));
53130
53809
  }
53131
- for (const key of definition.outputKeys)
53810
+ for (const key of omittedKeys)
53811
+ if (key in value.outputs)
53812
+ issues.push(`CONDITIONALLY_OMITTED_OUTPUT_PRESENT:${key}`);
53813
+ for (const key of effectiveKeys)
53132
53814
  validateOutput(value.outputs[key], definition.formats[key], key, issues);
53133
53815
  validateFactMarkers(value.outputs, job, issues);
53134
53816
  if (!Array.isArray(value.errors) || value.errors.length)
53135
53817
  issues.push("OK_ERRORS_MUST_BE_EMPTY");
53136
- if (value.provenance.length !== definition.outputKeys.length)
53818
+ if (value.provenance.length !== effectiveKeys.length)
53137
53819
  issues.push("PROVENANCE_COUNT_INVALID");
53138
53820
  const seen = /* @__PURE__ */ new Set();
53139
53821
  for (const [index, raw] of value.provenance.entries()) {
@@ -53144,23 +53826,34 @@ var require_contract = __commonJS({
53144
53826
  continue;
53145
53827
  }
53146
53828
  const field = String(raw.canonical_field);
53147
- if (!definition.outputKeys.includes(field) || seen.has(field))
53829
+ if (!effectiveKeys.includes(field) || seen.has(field))
53148
53830
  issues.push(`PROVENANCE_${index}_FIELD_INVALID`);
53149
53831
  else
53150
53832
  seen.add(field);
53151
- const allowedRefs = new Set(job.source_evidence.filter((entry) => entry.canonical_field === field).map((entry) => String(entry.evidence_reference)));
53152
- if (!Array.isArray(raw.source_refs) || raw.source_refs.length === 0 || raw.source_refs.some((ref) => typeof ref !== "string" || !allowedRefs.has(ref)))
53833
+ const groundingRecord = job.grounding.find((record) => record.canonical_field === field);
53834
+ const groundingRefs = new Set(groundingRecord?.grounding_evidence_references ?? []);
53835
+ const requestEvidenceRefs = new Set(job.source_evidence.map((entry) => String(entry.evidence_reference)));
53836
+ const authorizedEvidenceRefs = new Set([...groundingRefs].filter((ref) => requestEvidenceRefs.has(ref)));
53837
+ const authorizedContextRefs = new Set([...groundingRefs].filter((ref) => Object.hasOwn(job.verified_factual_context, ref)));
53838
+ if (!Array.isArray(raw.source_refs) || raw.source_refs.some((ref) => typeof ref !== "string" || !authorizedEvidenceRefs.has(ref)) || new Set(raw.source_refs).size !== raw.source_refs.length)
53153
53839
  issues.push(`PROVENANCE_${index}_SOURCE_REFS_INVALID`);
53154
- if (!Array.isArray(raw.verified_context_refs) || raw.verified_context_refs.some((ref) => typeof ref !== "string" || !Object.hasOwn(job.verified_factual_context, ref)))
53840
+ if (!Array.isArray(raw.verified_context_refs) || raw.verified_context_refs.some((ref) => typeof ref !== "string" || !authorizedContextRefs.has(ref)) || new Set(raw.verified_context_refs).size !== raw.verified_context_refs.length)
53155
53841
  issues.push(`PROVENANCE_${index}_CONTEXT_REFS_INVALID`);
53842
+ if (groundingRecord?.grounding_status === "GROUNDED" && Array.isArray(raw.source_refs) && raw.source_refs.length === 0 && Array.isArray(raw.verified_context_refs) && raw.verified_context_refs.length === 0)
53843
+ issues.push(`PROVENANCE_${index}_NO_GROUNDING`);
53156
53844
  }
53157
- for (const key of definition.outputKeys)
53845
+ for (const key of effectiveKeys)
53158
53846
  if (!seen.has(key))
53159
53847
  issues.push(`PROVENANCE_MISSING:${key}`);
53160
53848
  for (const key of definition.exactCopyKeys) {
53849
+ if (!effectiveKeys.includes(key))
53850
+ continue;
53161
53851
  const output = value.outputs[key];
53162
- const matches = job.source_evidence.filter((entry) => entry.canonical_field === key).some((entry) => String(entry.source_text).replace(/\s+/g, " ").trim() === String(output).replace(/\s+/g, " ").trim());
53163
- if (!matches)
53852
+ const groundingRecord = job.grounding.find((record) => record.canonical_field === key);
53853
+ const groundingRefs = new Set(groundingRecord?.grounding_evidence_references ?? []);
53854
+ const evidenceMatch = job.source_evidence.filter((entry) => groundingRefs.has(String(entry.evidence_reference))).some((entry) => String(entry.source_text).replace(/\s+/g, " ").trim() === String(output).replace(/\s+/g, " ").trim());
53855
+ const baselineMatch = (job.template_baseline.elements ?? []).some((element) => String(element.captured_content).replace(/\s+/g, " ").trim() === String(output).replace(/\s+/g, " ").trim());
53856
+ if (!evidenceMatch && !baselineMatch)
53164
53857
  issues.push(`${key}:EXACT_COPY_MISMATCH`);
53165
53858
  }
53166
53859
  } else if (statuses.includes(String(value.status))) {
@@ -53215,6 +53908,10 @@ var require_pre_ai_contract = __commonJS({
53215
53908
  "status",
53216
53909
  "factualCanonicalValues",
53217
53910
  "factualProvenance",
53911
+ "missingRequiredFacts",
53912
+ "reviewRequiredFacts",
53913
+ "requiredVerifiedAuthorityFacts",
53914
+ "manualFinalizationFacts",
53218
53915
  "rawPageEvidenceIssues",
53219
53916
  "manualApprovedCandidates",
53220
53917
  "mediaCandidates",
@@ -53232,6 +53929,8 @@ var require_pre_ai_contract = __commonJS({
53232
53929
  "package_digest"
53233
53930
  ];
53234
53931
  var FINAL_NARRATIVE_KEYS = new Set(contract_1.ALL_OUTPUT_KEYS);
53932
+ var MANUAL_FINALIZATION_FACT_KEYS = ["canonical_field", "disposition", "reason"];
53933
+ var MANUAL_FINALIZATION_DISPOSITIONS = ["MANUAL_GHL_FINALIZATION"];
53235
53934
  function exactKeys(value) {
53236
53935
  const actual = Object.keys(value);
53237
53936
  const missing = PRE_AI_KEYS.filter((key) => !actual.includes(key));
@@ -53260,6 +53959,25 @@ var require_pre_ai_contract = __commonJS({
53260
53959
  }
53261
53960
  return null;
53262
53961
  }
53962
+ function assertManualFinalizationFacts(value) {
53963
+ if (!Array.isArray(value))
53964
+ throw new Error("PRE_AI_PACKAGE_MANUAL_FINALIZATION_FACTS_INVALID");
53965
+ for (const entry of value) {
53966
+ if (!(0, contract_1.isObject)(entry))
53967
+ throw new Error("PRE_AI_PACKAGE_MANUAL_FINALIZATION_FACT_INVALID");
53968
+ const actual = Object.keys(entry);
53969
+ const missing = MANUAL_FINALIZATION_FACT_KEYS.filter((key) => !actual.includes(key));
53970
+ const extra = actual.filter((key) => !MANUAL_FINALIZATION_FACT_KEYS.includes(key));
53971
+ if (missing.length || extra.length)
53972
+ throw new Error(`PRE_AI_PACKAGE_MANUAL_FINALIZATION_FACT_INVALID:missing=${missing.join(",")}:extra=${extra.join(",")}`);
53973
+ if (typeof entry.canonical_field !== "string" || !entry.canonical_field.trim())
53974
+ throw new Error("PRE_AI_PACKAGE_MANUAL_FINALIZATION_FIELD_INVALID");
53975
+ if (typeof entry.reason !== "string" || !entry.reason.trim())
53976
+ throw new Error("PRE_AI_PACKAGE_MANUAL_FINALIZATION_REASON_INVALID");
53977
+ if (!MANUAL_FINALIZATION_DISPOSITIONS.includes(String(entry.disposition)))
53978
+ throw new Error("PRE_AI_PACKAGE_MANUAL_FINALIZATION_DISPOSITION_INVALID");
53979
+ }
53980
+ }
53263
53981
  function validatePreAiPackage(value) {
53264
53982
  if (!(0, contract_1.isObject)(value))
53265
53983
  throw new Error("PRE_AI_PACKAGE_MUST_BE_OBJECT");
@@ -53272,23 +53990,33 @@ var require_pre_ai_contract = __commonJS({
53272
53990
  throw new Error("PRE_AI_PACKAGE_AI_CONTRACT_INVALID");
53273
53991
  if (!["PRE_AI_READY", "PRE_AI_BLOCKED"].includes(String(value.status)))
53274
53992
  throw new Error("PRE_AI_PACKAGE_STATUS_INVALID");
53993
+ if (!(0, contract_1.isObject)(value.verifiedFactualContext) || !(0, contract_1.isObject)(value.verifiedFactualContext.values) || !(0, contract_1.isObject)(value.verifiedFactualContext.evidence))
53994
+ throw new Error("PRE_AI_PACKAGE_VERIFIED_CONTEXT_INVALID");
53275
53995
  if (!Array.isArray(value.aiSourcePackets) || value.aiSourcePackets.length !== 6)
53276
53996
  throw new Error("PRE_AI_PACKAGE_PACKET_COUNT_INVALID");
53277
53997
  const seenPrompts = /* @__PURE__ */ new Set();
53278
53998
  for (const packet of value.aiSourcePackets) {
53279
- (0, contract_1.assertCanonicalSourcePacket)(packet, void 0, false);
53999
+ (0, contract_1.assertCanonicalSourcePacket)(packet, void 0, false, value.verifiedFactualContext, value.factualProvenance);
53280
54000
  seenPrompts.add(String(packet.prompt_id));
53281
54001
  }
53282
54002
  if (seenPrompts.size !== 6 || contract_1.PROMPT_IDS.some((promptId) => !seenPrompts.has(promptId)))
53283
54003
  throw new Error("PRE_AI_PACKAGE_PROMPT_SET_INVALID");
53284
- if (!Array.isArray(value.pendingNarrativeFields) || JSON.stringify(value.pendingNarrativeFields) !== JSON.stringify(contract_1.ALL_OUTPUT_KEYS))
54004
+ if (!Array.isArray(value.pendingNarrativeFields))
54005
+ throw new Error("PRE_AI_PACKAGE_PENDING_NARRATIVES_INVALID");
54006
+ const industries = Array.isArray(value.conditionalSectionStates) ? value.conditionalSectionStates.find((state) => state.group === "INDUSTRIES_GROUP") : void 0;
54007
+ const populated = Number(industries?.populated_fields ?? 0);
54008
+ const expectedPending = populated > 0 ? contract_1.ALL_OUTPUT_KEYS : contract_1.ALL_OUTPUT_KEYS.filter((key) => key !== "about.industries.heading");
54009
+ if (JSON.stringify(value.pendingNarrativeFields) !== JSON.stringify(expectedPending))
53285
54010
  throw new Error("PRE_AI_PACKAGE_PENDING_NARRATIVES_INVALID");
54011
+ for (const key of ["missingRequiredFacts", "reviewRequiredFacts", "requiredVerifiedAuthorityFacts"]) {
54012
+ if (!Array.isArray(value[key]) || value[key].some((entry) => typeof entry !== "string" || !entry.trim()))
54013
+ throw new Error(`PRE_AI_PACKAGE_UNRESOLVED_FACT_STATE_INVALID:${key}`);
54014
+ }
54015
+ assertManualFinalizationFacts(value.manualFinalizationFacts);
53286
54016
  if (!Array.isArray(value.testimonialCandidates) || value.testimonialCandidates.length !== 12)
53287
54017
  throw new Error("PRE_AI_PACKAGE_TESTIMONIAL_COUNT_INVALID");
53288
54018
  if (!(0, contract_1.isObject)(value.frozenCountEvidence) || value.frozenCountEvidence.canonical_fields !== 76 || value.frozenCountEvidence.active_custom_values !== 67 || value.frozenCountEvidence.automated_ai_prompt_groups !== 6 || value.frozenCountEvidence.automated_ai_output_fields !== 17)
53289
54019
  throw new Error("PRE_AI_PACKAGE_FROZEN_COUNTS_INVALID");
53290
- if (!(0, contract_1.isObject)(value.verifiedFactualContext) || !(0, contract_1.isObject)(value.verifiedFactualContext.values) || !(0, contract_1.isObject)(value.verifiedFactualContext.evidence))
53291
- throw new Error("PRE_AI_PACKAGE_VERIFIED_CONTEXT_INVALID");
53292
54020
  const narrativePath = containsFinalNarrative(value.factualCanonicalValues);
53293
54021
  if (narrativePath)
53294
54022
  throw new Error(`PRE_AI_PACKAGE_FINAL_NARRATIVE_PRESENT:${narrativePath}`);
@@ -53310,7 +54038,7 @@ var require_extract_pre_ai_package = __commonJS({
53310
54038
  var pieces_common_1 = require_src4();
53311
54039
  var output_schemas_1 = require_output_schemas();
53312
54040
  var pre_ai_contract_1 = require_pre_ai_contract();
53313
- var PRIVATE_RUNTIME_URL = "http://172.25.0.6:3010/extract/pre-ai";
54041
+ var PRIVATE_RUNTIME_URL = "http://coach-migration-runtime:3010/extract/pre-ai";
53314
54042
  exports2.extractPreAiPackage = (0, pieces_framework_12.createAction)({
53315
54043
  name: "extract_pre_ai_package",
53316
54044
  displayName: "Extract Canonical PREAI Package",
@@ -53350,8 +54078,9 @@ var require_transform_narrative_job = __commonJS({
53350
54078
  var pieces_framework_12 = require_src2();
53351
54079
  var pieces_common_1 = require_src4();
53352
54080
  var contract_1 = require_contract();
54081
+ var pre_ai_contract_1 = require_pre_ai_contract();
53353
54082
  var output_schemas_1 = require_output_schemas();
53354
- var PRIVATE_RUNTIME_URL = "http://172.25.0.6:3010/narrative/transform";
54083
+ var PRIVATE_RUNTIME_URL = "http://coach-migration-runtime:3010/narrative/transform";
53355
54084
  exports2.transformNarrativeJob = (0, pieces_framework_12.createAction)({
53356
54085
  name: "transform_narrative_job",
53357
54086
  displayName: "Transform Bounded Narrative Job",
@@ -53376,12 +54105,15 @@ var require_transform_narrative_job = __commonJS({
53376
54105
  options: { disabled: false, options: contract_1.PROMPT_IDS.map((value) => ({ label: value, value })) }
53377
54106
  }),
53378
54107
  source_packet: pieces_framework_12.Property.Json({ displayName: "Canonical Source Packet", description: "Exactly one packet from Extract Canonical PREAI Package.", required: true }),
53379
- verified_factual_context: pieces_framework_12.Property.Json({ displayName: "Verified Factual Context", description: "The verifiedFactualContext object from the same PREAI package. It is filtered to the prompt allowlist.", required: true }),
53380
- required_output_schema: pieces_framework_12.Property.Json({ displayName: "Required Output Schema", description: "Frozen schema for the selected prompt; must match the contract exactly.", required: true })
54108
+ verified_factual_context: pieces_framework_12.Property.Json({ displayName: "Verified Factual Context", description: "The verifiedFactualContext object from the same PREAI package. It is filtered to the prompt allowlist and enforced as owned by the supplied PREAI package (B-1).", required: true }),
54109
+ pre_ai_package: pieces_framework_12.Property.Json({ displayName: "Owning PREAI Package", description: "The full PREAI package from the same Extract Canonical PREAI Package run as the source packet; its package_digest is the ownership identity binding the packet, verified factual context, and factual provenance (B-1).", required: true }),
54110
+ required_output_schema: pieces_framework_12.Property.Json({ displayName: "Required Output Schema", description: "Effective schema for the selected prompt; must match the contract-derived effective set exactly.", required: true }),
54111
+ template_baseline: pieces_framework_12.Property.Json({ displayName: "Template Narrative Baseline", description: "Verified FOCALPOINT_STANDARD template FORM baseline with its manifest digest; form authority only, never factual source.", required: true })
53381
54112
  },
53382
54113
  outputSchema: output_schemas_1.transformNarrativeJobOutputSchema,
53383
54114
  run: async (context) => {
53384
- const job = (0, contract_1.buildBoundedNarrativeJob)(context.propsValue);
54115
+ const validatedPackage = (0, pre_ai_contract_1.validatePreAiPackage)(context.propsValue.pre_ai_package);
54116
+ const job = (0, contract_1.buildBoundedNarrativeJob)({ ...context.propsValue, pre_ai_package: validatedPackage });
53385
54117
  try {
53386
54118
  const response = await pieces_common_1.httpClient.sendRequest({
53387
54119
  method: pieces_common_1.HttpMethod.POST,