@contractspec/example.locale-jurisdiction-gate 3.7.16 → 3.7.18

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 (66) hide show
  1. package/.turbo/turbo-build.log +66 -66
  2. package/CHANGELOG.md +22 -0
  3. package/dist/browser/docs/index.js +3 -27
  4. package/dist/browser/docs/locale-jurisdiction-gate.docblock.js +3 -27
  5. package/dist/browser/entities/index.js +1 -110
  6. package/dist/browser/entities/models.js +1 -110
  7. package/dist/browser/events.js +1 -73
  8. package/dist/browser/example.js +1 -35
  9. package/dist/browser/forms/assistant-context.form.js +1 -213
  10. package/dist/browser/forms/index.js +1 -213
  11. package/dist/browser/handlers/demo.handlers.js +2 -152
  12. package/dist/browser/handlers/index.js +2 -152
  13. package/dist/browser/index.js +4 -844
  14. package/dist/browser/locale-jurisdiction-gate.feature.js +1 -105
  15. package/dist/browser/operations/assistant.js +1 -192
  16. package/dist/browser/operations/index.js +1 -192
  17. package/dist/browser/policy/assistant-gate.policy.js +1 -62
  18. package/dist/browser/policy/guard.js +2 -73
  19. package/dist/browser/policy/index.js +2 -134
  20. package/dist/browser/translations/assistant-gate.en-GB.translation.js +1 -48
  21. package/dist/browser/translations/assistant-gate.en-US.translation.js +1 -50
  22. package/dist/browser/translations/assistant-gate.fr-FR.translation.js +1 -52
  23. package/dist/browser/translations/index.js +1 -148
  24. package/dist/docs/index.js +3 -27
  25. package/dist/docs/locale-jurisdiction-gate.docblock.js +3 -27
  26. package/dist/entities/index.js +1 -110
  27. package/dist/entities/models.js +1 -110
  28. package/dist/events.js +1 -73
  29. package/dist/example.js +1 -35
  30. package/dist/forms/assistant-context.form.js +1 -213
  31. package/dist/forms/index.js +1 -213
  32. package/dist/handlers/demo.handlers.js +2 -152
  33. package/dist/handlers/index.js +2 -152
  34. package/dist/index.js +4 -844
  35. package/dist/locale-jurisdiction-gate.feature.js +1 -105
  36. package/dist/node/docs/index.js +3 -27
  37. package/dist/node/docs/locale-jurisdiction-gate.docblock.js +3 -27
  38. package/dist/node/entities/index.js +1 -110
  39. package/dist/node/entities/models.js +1 -110
  40. package/dist/node/events.js +1 -73
  41. package/dist/node/example.js +1 -35
  42. package/dist/node/forms/assistant-context.form.js +1 -213
  43. package/dist/node/forms/index.js +1 -213
  44. package/dist/node/handlers/demo.handlers.js +2 -152
  45. package/dist/node/handlers/index.js +2 -152
  46. package/dist/node/index.js +4 -844
  47. package/dist/node/locale-jurisdiction-gate.feature.js +1 -105
  48. package/dist/node/operations/assistant.js +1 -192
  49. package/dist/node/operations/index.js +1 -192
  50. package/dist/node/policy/assistant-gate.policy.js +1 -62
  51. package/dist/node/policy/guard.js +2 -73
  52. package/dist/node/policy/index.js +2 -134
  53. package/dist/node/translations/assistant-gate.en-GB.translation.js +1 -48
  54. package/dist/node/translations/assistant-gate.en-US.translation.js +1 -50
  55. package/dist/node/translations/assistant-gate.fr-FR.translation.js +1 -52
  56. package/dist/node/translations/index.js +1 -148
  57. package/dist/operations/assistant.js +1 -192
  58. package/dist/operations/index.js +1 -192
  59. package/dist/policy/assistant-gate.policy.js +1 -62
  60. package/dist/policy/guard.js +2 -73
  61. package/dist/policy/index.js +2 -134
  62. package/dist/translations/assistant-gate.en-GB.translation.js +1 -48
  63. package/dist/translations/assistant-gate.en-US.translation.js +1 -50
  64. package/dist/translations/assistant-gate.fr-FR.translation.js +1 -52
  65. package/dist/translations/index.js +1 -148
  66. package/package.json +7 -7
@@ -1,213 +1 @@
1
- // src/entities/models.ts
2
- import {
3
- defineEnum,
4
- defineSchemaModel,
5
- ScalarTypeEnum
6
- } from "@contractspec/lib.schema";
7
- var AllowedScopeEnum = defineEnum("AllowedScope", [
8
- "education_only",
9
- "generic_info",
10
- "escalation_required"
11
- ]);
12
- var UserProfileModel = defineSchemaModel({
13
- name: "UserProfile",
14
- description: "User profile inputs used to derive regulatory context.",
15
- fields: {
16
- preferredLocale: {
17
- type: ScalarTypeEnum.String_unsecure(),
18
- isOptional: true
19
- },
20
- residencyCountry: {
21
- type: ScalarTypeEnum.String_unsecure(),
22
- isOptional: true
23
- },
24
- taxResidenceCountry: {
25
- type: ScalarTypeEnum.String_unsecure(),
26
- isOptional: true
27
- },
28
- clientType: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
29
- }
30
- });
31
- var RegulatoryContextModel = defineSchemaModel({
32
- name: "RegulatoryContext",
33
- description: "Explicit regulatory context (no guessing).",
34
- fields: {
35
- jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
36
- region: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
37
- clientType: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
38
- allowedScope: { type: AllowedScopeEnum, isOptional: false }
39
- }
40
- });
41
- var LLMCallEnvelopeModel = defineSchemaModel({
42
- name: "LLMCallEnvelope",
43
- description: "Mandatory envelope for assistant calls. All fields are explicit and required for policy gating.",
44
- fields: {
45
- traceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
46
- locale: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
47
- regulatoryContext: { type: RegulatoryContextModel, isOptional: false },
48
- kbSnapshotId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
49
- allowedScope: { type: AllowedScopeEnum, isOptional: false }
50
- }
51
- });
52
- var AssistantCitationModel = defineSchemaModel({
53
- name: "AssistantCitation",
54
- description: "Citation referencing a KB snapshot + a specific item within it.",
55
- fields: {
56
- kbSnapshotId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
57
- sourceType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
58
- sourceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
59
- title: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
60
- excerpt: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
61
- }
62
- });
63
- var AssistantAnswerSectionModel = defineSchemaModel({
64
- name: "AssistantAnswerSection",
65
- description: "Structured answer section.",
66
- fields: {
67
- heading: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
68
- body: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
69
- }
70
- });
71
- var AssistantAnswerIRModel = defineSchemaModel({
72
- name: "AssistantAnswerIR",
73
- description: "Structured assistant answer with mandatory citations and explicit locale/jurisdiction.",
74
- fields: {
75
- locale: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
76
- jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
77
- allowedScope: { type: AllowedScopeEnum, isOptional: false },
78
- sections: {
79
- type: AssistantAnswerSectionModel,
80
- isArray: true,
81
- isOptional: false
82
- },
83
- citations: {
84
- type: AssistantCitationModel,
85
- isArray: true,
86
- isOptional: false
87
- },
88
- disclaimers: {
89
- type: ScalarTypeEnum.String_unsecure(),
90
- isArray: true,
91
- isOptional: true
92
- },
93
- riskFlags: {
94
- type: ScalarTypeEnum.String_unsecure(),
95
- isArray: true,
96
- isOptional: true
97
- },
98
- refused: { type: ScalarTypeEnum.Boolean(), isOptional: true },
99
- refusalReason: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
100
- }
101
- });
102
-
103
- // src/forms/assistant-context.form.ts
104
- import { defineFormSpec } from "@contractspec/lib.contracts-spec/forms";
105
- import {
106
- OwnersEnum,
107
- StabilityEnum,
108
- TagsEnum
109
- } from "@contractspec/lib.contracts-spec/ownership";
110
- import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
111
- var AssistantContextFormModel = defineSchemaModel2({
112
- name: "AssistantContextFormModel",
113
- description: "Form values required before a policy-gated assistant request can be executed.",
114
- fields: {
115
- locale: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
116
- jurisdiction: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
117
- kbSnapshotId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
118
- allowedScope: { type: AllowedScopeEnum, isOptional: false },
119
- question: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
120
- }
121
- });
122
- var AssistantContextForm = defineFormSpec({
123
- meta: {
124
- key: "locale-jurisdiction-gate.form.assistant-context",
125
- version: "1.0.0",
126
- title: "Assistant Context Gate",
127
- description: "Collects the explicit locale, jurisdiction, scope, and knowledge snapshot required by the assistant gate.",
128
- domain: "assistant",
129
- owners: [OwnersEnum.PlatformFinance],
130
- tags: [TagsEnum.I18n, "assistant", "form", "policy"],
131
- stability: StabilityEnum.Experimental
132
- },
133
- model: AssistantContextFormModel,
134
- fields: [
135
- {
136
- kind: "select",
137
- name: "locale",
138
- labelI18n: "assistantGate.locale.label",
139
- descriptionI18n: "assistantGate.locale.description",
140
- options: {
141
- kind: "static",
142
- options: [
143
- { labelI18n: "assistantGate.locale.enUs", value: "en-US" },
144
- { labelI18n: "assistantGate.locale.enGb", value: "en-GB" },
145
- { labelI18n: "assistantGate.locale.frFr", value: "fr-FR" }
146
- ]
147
- },
148
- required: true
149
- },
150
- {
151
- kind: "text",
152
- name: "jurisdiction",
153
- labelI18n: "assistantGate.jurisdiction.label",
154
- placeholderI18n: "assistantGate.jurisdiction.placeholder",
155
- required: true
156
- },
157
- {
158
- kind: "text",
159
- name: "kbSnapshotId",
160
- labelI18n: "assistantGate.kbSnapshotId.label",
161
- placeholderI18n: "assistantGate.kbSnapshotId.placeholder",
162
- required: true
163
- },
164
- {
165
- kind: "radio",
166
- name: "allowedScope",
167
- labelI18n: "assistantGate.allowedScope.label",
168
- options: {
169
- kind: "static",
170
- options: [
171
- {
172
- labelI18n: "assistantGate.allowedScope.educationOnly",
173
- value: "education_only"
174
- },
175
- {
176
- labelI18n: "assistantGate.allowedScope.genericInfo",
177
- value: "generic_info"
178
- },
179
- {
180
- labelI18n: "assistantGate.allowedScope.escalationRequired",
181
- value: "escalation_required"
182
- }
183
- ]
184
- },
185
- required: true
186
- },
187
- {
188
- kind: "textarea",
189
- name: "question",
190
- labelI18n: "assistantGate.question.label",
191
- placeholderI18n: "assistantGate.question.placeholder",
192
- required: true
193
- }
194
- ],
195
- actions: [
196
- {
197
- key: "submit",
198
- labelI18n: "assistantGate.submit.label",
199
- op: { name: "assistant.answer", version: "1.0.0" }
200
- }
201
- ],
202
- policy: {
203
- flags: [],
204
- pii: ["kbSnapshotId", "question"]
205
- },
206
- renderHints: {
207
- ui: "custom",
208
- form: "react-hook-form"
209
- }
210
- });
211
- export {
212
- AssistantContextForm
213
- };
1
+ import{defineEnum as s,defineSchemaModel as t,ScalarTypeEnum as e}from"@contractspec/lib.schema";var i=s("AllowedScope",["education_only","generic_info","escalation_required"]),g=t({name:"UserProfile",description:"User profile inputs used to derive regulatory context.",fields:{preferredLocale:{type:e.String_unsecure(),isOptional:!0},residencyCountry:{type:e.String_unsecure(),isOptional:!0},taxResidenceCountry:{type:e.String_unsecure(),isOptional:!0},clientType:{type:e.String_unsecure(),isOptional:!0}}}),r=t({name:"RegulatoryContext",description:"Explicit regulatory context (no guessing).",fields:{jurisdiction:{type:e.String_unsecure(),isOptional:!1},region:{type:e.String_unsecure(),isOptional:!0},clientType:{type:e.String_unsecure(),isOptional:!0},allowedScope:{type:i,isOptional:!1}}}),O=t({name:"LLMCallEnvelope",description:"Mandatory envelope for assistant calls. All fields are explicit and required for policy gating.",fields:{traceId:{type:e.String_unsecure(),isOptional:!1},locale:{type:e.String_unsecure(),isOptional:!1},regulatoryContext:{type:r,isOptional:!1},kbSnapshotId:{type:e.String_unsecure(),isOptional:!1},allowedScope:{type:i,isOptional:!1}}}),o=t({name:"AssistantCitation",description:"Citation referencing a KB snapshot + a specific item within it.",fields:{kbSnapshotId:{type:e.String_unsecure(),isOptional:!1},sourceType:{type:e.String_unsecure(),isOptional:!1},sourceId:{type:e.String_unsecure(),isOptional:!1},title:{type:e.String_unsecure(),isOptional:!0},excerpt:{type:e.String_unsecure(),isOptional:!0}}}),a=t({name:"AssistantAnswerSection",description:"Structured answer section.",fields:{heading:{type:e.String_unsecure(),isOptional:!1},body:{type:e.String_unsecure(),isOptional:!1}}}),S=t({name:"AssistantAnswerIR",description:"Structured assistant answer with mandatory citations and explicit locale/jurisdiction.",fields:{locale:{type:e.String_unsecure(),isOptional:!1},jurisdiction:{type:e.String_unsecure(),isOptional:!1},allowedScope:{type:i,isOptional:!1},sections:{type:a,isArray:!0,isOptional:!1},citations:{type:o,isArray:!0,isOptional:!1},disclaimers:{type:e.String_unsecure(),isArray:!0,isOptional:!0},riskFlags:{type:e.String_unsecure(),isArray:!0,isOptional:!0},refused:{type:e.Boolean(),isOptional:!0},refusalReason:{type:e.String_unsecure(),isOptional:!0}}});import{defineFormSpec as l}from"@contractspec/lib.contracts-spec/forms";import{OwnersEnum as p,StabilityEnum as u,TagsEnum as c}from"@contractspec/lib.contracts-spec/ownership";import{defineSchemaModel as d,ScalarTypeEnum as n}from"@contractspec/lib.schema";var y=d({name:"AssistantContextFormModel",description:"Form values required before a policy-gated assistant request can be executed.",fields:{locale:{type:n.String_unsecure(),isOptional:!1},jurisdiction:{type:n.String_unsecure(),isOptional:!1},kbSnapshotId:{type:n.String_unsecure(),isOptional:!1},allowedScope:{type:i,isOptional:!1},question:{type:n.String_unsecure(),isOptional:!1}}}),M=l({meta:{key:"locale-jurisdiction-gate.form.assistant-context",version:"1.0.0",title:"Assistant Context Gate",description:"Collects the explicit locale, jurisdiction, scope, and knowledge snapshot required by the assistant gate.",domain:"assistant",owners:[p.PlatformFinance],tags:[c.I18n,"assistant","form","policy"],stability:u.Experimental},model:y,fields:[{kind:"select",name:"locale",labelI18n:"assistantGate.locale.label",descriptionI18n:"assistantGate.locale.description",options:{kind:"static",options:[{labelI18n:"assistantGate.locale.enUs",value:"en-US"},{labelI18n:"assistantGate.locale.enGb",value:"en-GB"},{labelI18n:"assistantGate.locale.frFr",value:"fr-FR"}]},required:!0},{kind:"text",name:"jurisdiction",labelI18n:"assistantGate.jurisdiction.label",placeholderI18n:"assistantGate.jurisdiction.placeholder",required:!0},{kind:"text",name:"kbSnapshotId",labelI18n:"assistantGate.kbSnapshotId.label",placeholderI18n:"assistantGate.kbSnapshotId.placeholder",required:!0},{kind:"radio",name:"allowedScope",labelI18n:"assistantGate.allowedScope.label",options:{kind:"static",options:[{labelI18n:"assistantGate.allowedScope.educationOnly",value:"education_only"},{labelI18n:"assistantGate.allowedScope.genericInfo",value:"generic_info"},{labelI18n:"assistantGate.allowedScope.escalationRequired",value:"escalation_required"}]},required:!0},{kind:"textarea",name:"question",labelI18n:"assistantGate.question.label",placeholderI18n:"assistantGate.question.placeholder",required:!0}],actions:[{key:"submit",labelI18n:"assistantGate.submit.label",op:{name:"assistant.answer",version:"1.0.0"}}],policy:{flags:[],pii:["kbSnapshotId","question"]},renderHints:{ui:"custom",form:"react-hook-form"}});export{M as AssistantContextForm};
@@ -1,213 +1 @@
1
- // src/entities/models.ts
2
- import {
3
- defineEnum,
4
- defineSchemaModel,
5
- ScalarTypeEnum
6
- } from "@contractspec/lib.schema";
7
- var AllowedScopeEnum = defineEnum("AllowedScope", [
8
- "education_only",
9
- "generic_info",
10
- "escalation_required"
11
- ]);
12
- var UserProfileModel = defineSchemaModel({
13
- name: "UserProfile",
14
- description: "User profile inputs used to derive regulatory context.",
15
- fields: {
16
- preferredLocale: {
17
- type: ScalarTypeEnum.String_unsecure(),
18
- isOptional: true
19
- },
20
- residencyCountry: {
21
- type: ScalarTypeEnum.String_unsecure(),
22
- isOptional: true
23
- },
24
- taxResidenceCountry: {
25
- type: ScalarTypeEnum.String_unsecure(),
26
- isOptional: true
27
- },
28
- clientType: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
29
- }
30
- });
31
- var RegulatoryContextModel = defineSchemaModel({
32
- name: "RegulatoryContext",
33
- description: "Explicit regulatory context (no guessing).",
34
- fields: {
35
- jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
36
- region: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
37
- clientType: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
38
- allowedScope: { type: AllowedScopeEnum, isOptional: false }
39
- }
40
- });
41
- var LLMCallEnvelopeModel = defineSchemaModel({
42
- name: "LLMCallEnvelope",
43
- description: "Mandatory envelope for assistant calls. All fields are explicit and required for policy gating.",
44
- fields: {
45
- traceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
46
- locale: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
47
- regulatoryContext: { type: RegulatoryContextModel, isOptional: false },
48
- kbSnapshotId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
49
- allowedScope: { type: AllowedScopeEnum, isOptional: false }
50
- }
51
- });
52
- var AssistantCitationModel = defineSchemaModel({
53
- name: "AssistantCitation",
54
- description: "Citation referencing a KB snapshot + a specific item within it.",
55
- fields: {
56
- kbSnapshotId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
57
- sourceType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
58
- sourceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
59
- title: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
60
- excerpt: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
61
- }
62
- });
63
- var AssistantAnswerSectionModel = defineSchemaModel({
64
- name: "AssistantAnswerSection",
65
- description: "Structured answer section.",
66
- fields: {
67
- heading: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
68
- body: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
69
- }
70
- });
71
- var AssistantAnswerIRModel = defineSchemaModel({
72
- name: "AssistantAnswerIR",
73
- description: "Structured assistant answer with mandatory citations and explicit locale/jurisdiction.",
74
- fields: {
75
- locale: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
76
- jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
77
- allowedScope: { type: AllowedScopeEnum, isOptional: false },
78
- sections: {
79
- type: AssistantAnswerSectionModel,
80
- isArray: true,
81
- isOptional: false
82
- },
83
- citations: {
84
- type: AssistantCitationModel,
85
- isArray: true,
86
- isOptional: false
87
- },
88
- disclaimers: {
89
- type: ScalarTypeEnum.String_unsecure(),
90
- isArray: true,
91
- isOptional: true
92
- },
93
- riskFlags: {
94
- type: ScalarTypeEnum.String_unsecure(),
95
- isArray: true,
96
- isOptional: true
97
- },
98
- refused: { type: ScalarTypeEnum.Boolean(), isOptional: true },
99
- refusalReason: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
100
- }
101
- });
102
-
103
- // src/forms/assistant-context.form.ts
104
- import { defineFormSpec } from "@contractspec/lib.contracts-spec/forms";
105
- import {
106
- OwnersEnum,
107
- StabilityEnum,
108
- TagsEnum
109
- } from "@contractspec/lib.contracts-spec/ownership";
110
- import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
111
- var AssistantContextFormModel = defineSchemaModel2({
112
- name: "AssistantContextFormModel",
113
- description: "Form values required before a policy-gated assistant request can be executed.",
114
- fields: {
115
- locale: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
116
- jurisdiction: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
117
- kbSnapshotId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
118
- allowedScope: { type: AllowedScopeEnum, isOptional: false },
119
- question: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
120
- }
121
- });
122
- var AssistantContextForm = defineFormSpec({
123
- meta: {
124
- key: "locale-jurisdiction-gate.form.assistant-context",
125
- version: "1.0.0",
126
- title: "Assistant Context Gate",
127
- description: "Collects the explicit locale, jurisdiction, scope, and knowledge snapshot required by the assistant gate.",
128
- domain: "assistant",
129
- owners: [OwnersEnum.PlatformFinance],
130
- tags: [TagsEnum.I18n, "assistant", "form", "policy"],
131
- stability: StabilityEnum.Experimental
132
- },
133
- model: AssistantContextFormModel,
134
- fields: [
135
- {
136
- kind: "select",
137
- name: "locale",
138
- labelI18n: "assistantGate.locale.label",
139
- descriptionI18n: "assistantGate.locale.description",
140
- options: {
141
- kind: "static",
142
- options: [
143
- { labelI18n: "assistantGate.locale.enUs", value: "en-US" },
144
- { labelI18n: "assistantGate.locale.enGb", value: "en-GB" },
145
- { labelI18n: "assistantGate.locale.frFr", value: "fr-FR" }
146
- ]
147
- },
148
- required: true
149
- },
150
- {
151
- kind: "text",
152
- name: "jurisdiction",
153
- labelI18n: "assistantGate.jurisdiction.label",
154
- placeholderI18n: "assistantGate.jurisdiction.placeholder",
155
- required: true
156
- },
157
- {
158
- kind: "text",
159
- name: "kbSnapshotId",
160
- labelI18n: "assistantGate.kbSnapshotId.label",
161
- placeholderI18n: "assistantGate.kbSnapshotId.placeholder",
162
- required: true
163
- },
164
- {
165
- kind: "radio",
166
- name: "allowedScope",
167
- labelI18n: "assistantGate.allowedScope.label",
168
- options: {
169
- kind: "static",
170
- options: [
171
- {
172
- labelI18n: "assistantGate.allowedScope.educationOnly",
173
- value: "education_only"
174
- },
175
- {
176
- labelI18n: "assistantGate.allowedScope.genericInfo",
177
- value: "generic_info"
178
- },
179
- {
180
- labelI18n: "assistantGate.allowedScope.escalationRequired",
181
- value: "escalation_required"
182
- }
183
- ]
184
- },
185
- required: true
186
- },
187
- {
188
- kind: "textarea",
189
- name: "question",
190
- labelI18n: "assistantGate.question.label",
191
- placeholderI18n: "assistantGate.question.placeholder",
192
- required: true
193
- }
194
- ],
195
- actions: [
196
- {
197
- key: "submit",
198
- labelI18n: "assistantGate.submit.label",
199
- op: { name: "assistant.answer", version: "1.0.0" }
200
- }
201
- ],
202
- policy: {
203
- flags: [],
204
- pii: ["kbSnapshotId", "question"]
205
- },
206
- renderHints: {
207
- ui: "custom",
208
- form: "react-hook-form"
209
- }
210
- });
211
- export {
212
- AssistantContextForm
213
- };
1
+ import{defineEnum as s,defineSchemaModel as t,ScalarTypeEnum as e}from"@contractspec/lib.schema";var i=s("AllowedScope",["education_only","generic_info","escalation_required"]),g=t({name:"UserProfile",description:"User profile inputs used to derive regulatory context.",fields:{preferredLocale:{type:e.String_unsecure(),isOptional:!0},residencyCountry:{type:e.String_unsecure(),isOptional:!0},taxResidenceCountry:{type:e.String_unsecure(),isOptional:!0},clientType:{type:e.String_unsecure(),isOptional:!0}}}),r=t({name:"RegulatoryContext",description:"Explicit regulatory context (no guessing).",fields:{jurisdiction:{type:e.String_unsecure(),isOptional:!1},region:{type:e.String_unsecure(),isOptional:!0},clientType:{type:e.String_unsecure(),isOptional:!0},allowedScope:{type:i,isOptional:!1}}}),O=t({name:"LLMCallEnvelope",description:"Mandatory envelope for assistant calls. All fields are explicit and required for policy gating.",fields:{traceId:{type:e.String_unsecure(),isOptional:!1},locale:{type:e.String_unsecure(),isOptional:!1},regulatoryContext:{type:r,isOptional:!1},kbSnapshotId:{type:e.String_unsecure(),isOptional:!1},allowedScope:{type:i,isOptional:!1}}}),o=t({name:"AssistantCitation",description:"Citation referencing a KB snapshot + a specific item within it.",fields:{kbSnapshotId:{type:e.String_unsecure(),isOptional:!1},sourceType:{type:e.String_unsecure(),isOptional:!1},sourceId:{type:e.String_unsecure(),isOptional:!1},title:{type:e.String_unsecure(),isOptional:!0},excerpt:{type:e.String_unsecure(),isOptional:!0}}}),a=t({name:"AssistantAnswerSection",description:"Structured answer section.",fields:{heading:{type:e.String_unsecure(),isOptional:!1},body:{type:e.String_unsecure(),isOptional:!1}}}),S=t({name:"AssistantAnswerIR",description:"Structured assistant answer with mandatory citations and explicit locale/jurisdiction.",fields:{locale:{type:e.String_unsecure(),isOptional:!1},jurisdiction:{type:e.String_unsecure(),isOptional:!1},allowedScope:{type:i,isOptional:!1},sections:{type:a,isArray:!0,isOptional:!1},citations:{type:o,isArray:!0,isOptional:!1},disclaimers:{type:e.String_unsecure(),isArray:!0,isOptional:!0},riskFlags:{type:e.String_unsecure(),isArray:!0,isOptional:!0},refused:{type:e.Boolean(),isOptional:!0},refusalReason:{type:e.String_unsecure(),isOptional:!0}}});import{defineFormSpec as l}from"@contractspec/lib.contracts-spec/forms";import{OwnersEnum as p,StabilityEnum as u,TagsEnum as c}from"@contractspec/lib.contracts-spec/ownership";import{defineSchemaModel as d,ScalarTypeEnum as n}from"@contractspec/lib.schema";var y=d({name:"AssistantContextFormModel",description:"Form values required before a policy-gated assistant request can be executed.",fields:{locale:{type:n.String_unsecure(),isOptional:!1},jurisdiction:{type:n.String_unsecure(),isOptional:!1},kbSnapshotId:{type:n.String_unsecure(),isOptional:!1},allowedScope:{type:i,isOptional:!1},question:{type:n.String_unsecure(),isOptional:!1}}}),M=l({meta:{key:"locale-jurisdiction-gate.form.assistant-context",version:"1.0.0",title:"Assistant Context Gate",description:"Collects the explicit locale, jurisdiction, scope, and knowledge snapshot required by the assistant gate.",domain:"assistant",owners:[p.PlatformFinance],tags:[c.I18n,"assistant","form","policy"],stability:u.Experimental},model:y,fields:[{kind:"select",name:"locale",labelI18n:"assistantGate.locale.label",descriptionI18n:"assistantGate.locale.description",options:{kind:"static",options:[{labelI18n:"assistantGate.locale.enUs",value:"en-US"},{labelI18n:"assistantGate.locale.enGb",value:"en-GB"},{labelI18n:"assistantGate.locale.frFr",value:"fr-FR"}]},required:!0},{kind:"text",name:"jurisdiction",labelI18n:"assistantGate.jurisdiction.label",placeholderI18n:"assistantGate.jurisdiction.placeholder",required:!0},{kind:"text",name:"kbSnapshotId",labelI18n:"assistantGate.kbSnapshotId.label",placeholderI18n:"assistantGate.kbSnapshotId.placeholder",required:!0},{kind:"radio",name:"allowedScope",labelI18n:"assistantGate.allowedScope.label",options:{kind:"static",options:[{labelI18n:"assistantGate.allowedScope.educationOnly",value:"education_only"},{labelI18n:"assistantGate.allowedScope.genericInfo",value:"generic_info"},{labelI18n:"assistantGate.allowedScope.escalationRequired",value:"escalation_required"}]},required:!0},{kind:"textarea",name:"question",labelI18n:"assistantGate.question.label",placeholderI18n:"assistantGate.question.placeholder",required:!0}],actions:[{key:"submit",labelI18n:"assistantGate.submit.label",op:{name:"assistant.answer",version:"1.0.0"}}],policy:{flags:[],pii:["kbSnapshotId","question"]},renderHints:{ui:"custom",form:"react-hook-form"}});export{M as AssistantContextForm};
@@ -1,152 +1,2 @@
1
- // src/policy/guard.ts
2
- var SUPPORTED_LOCALES = new Set(["en-US", "en-GB", "fr-FR"]);
3
- function err(code, message) {
4
- return { code, message };
5
- }
6
- function validateEnvelope(envelope) {
7
- if (!envelope.locale || !SUPPORTED_LOCALES.has(envelope.locale)) {
8
- return {
9
- ok: false,
10
- error: err("LOCALE_REQUIRED", "locale is required and must be supported")
11
- };
12
- }
13
- if (!envelope.regulatoryContext?.jurisdiction) {
14
- return {
15
- ok: false,
16
- error: err("JURISDICTION_REQUIRED", "jurisdiction is required")
17
- };
18
- }
19
- if (!envelope.kbSnapshotId) {
20
- return {
21
- ok: false,
22
- error: err("KB_SNAPSHOT_REQUIRED", "kbSnapshotId is required")
23
- };
24
- }
25
- if (!envelope.allowedScope) {
26
- return {
27
- ok: false,
28
- error: err("SCOPE_VIOLATION", "allowedScope is required")
29
- };
30
- }
31
- return { ok: true, value: envelope };
32
- }
33
- function enforceCitations(answer) {
34
- const citations = answer.citations ?? [];
35
- if (!Array.isArray(citations) || citations.length === 0) {
36
- return {
37
- ok: false,
38
- error: err("CITATIONS_REQUIRED", "answers must include at least one citation")
39
- };
40
- }
41
- return { ok: true, value: answer };
42
- }
43
- var EDUCATION_ONLY_FORBIDDEN_PATTERNS = [
44
- /\b(buy|sell)\b/i,
45
- /\b(should\s+buy|should\s+sell)\b/i,
46
- /\b(guarantee(d)?|promise(d)?)\b/i
47
- ];
48
- function enforceAllowedScope(allowedScope, answer) {
49
- if (!allowedScope) {
50
- return {
51
- ok: false,
52
- error: err("SCOPE_VIOLATION", "allowedScope is required")
53
- };
54
- }
55
- if (allowedScope !== "education_only") {
56
- return { ok: true, value: answer };
57
- }
58
- const bodies = (answer.sections ?? []).map((s) => s.body).join(`
59
- `);
60
- const violations = EDUCATION_ONLY_FORBIDDEN_PATTERNS.some((re) => re.test(bodies));
61
- if (violations) {
62
- return {
63
- ok: false,
64
- error: err("SCOPE_VIOLATION", "answer violates education_only scope (contains actionable or promotional language)")
65
- };
66
- }
67
- return { ok: true, value: answer };
68
- }
69
-
70
- // src/handlers/demo.handlers.ts
71
- function createDemoAssistantHandlers() {
72
- async function answer(input) {
73
- const env = validateEnvelope(input.envelope);
74
- if (!env.ok) {
75
- return {
76
- locale: input.envelope.locale ?? "en-US",
77
- jurisdiction: input.envelope.regulatoryContext?.jurisdiction ?? "UNKNOWN",
78
- allowedScope: input.envelope.allowedScope ?? "education_only",
79
- sections: [
80
- {
81
- heading: "Request blocked",
82
- body: env.error.message
83
- }
84
- ],
85
- citations: [],
86
- disclaimers: [
87
- "This system refuses to answer without a valid envelope."
88
- ],
89
- riskFlags: [env.error.code],
90
- refused: true,
91
- refusalReason: env.error.code
92
- };
93
- }
94
- const draft = {
95
- locale: env.value.locale,
96
- jurisdiction: env.value.regulatoryContext?.jurisdiction ?? "UNKNOWN",
97
- allowedScope: env.value.allowedScope ?? "education_only",
98
- sections: [
99
- {
100
- heading: "Answer (demo)",
101
- body: `You asked: "${input.question}". This demo answer is derived from the KB snapshot only.`
102
- }
103
- ],
104
- citations: [
105
- {
106
- kbSnapshotId: env.value.kbSnapshotId ?? "unknown",
107
- sourceType: "ruleVersion",
108
- sourceId: "rv_demo",
109
- title: "Demo rule version",
110
- excerpt: "Demo excerpt"
111
- }
112
- ],
113
- disclaimers: ["Educational demo only."],
114
- riskFlags: []
115
- };
116
- const scope = enforceAllowedScope(env.value.allowedScope, draft);
117
- if (!scope.ok) {
118
- return {
119
- ...draft,
120
- sections: [
121
- { heading: "Escalation required", body: scope.error.message }
122
- ],
123
- citations: draft.citations,
124
- refused: true,
125
- refusalReason: scope.error.code,
126
- riskFlags: [...draft.riskFlags ?? [], scope.error.code]
127
- };
128
- }
129
- const cited = enforceCitations(draft);
130
- if (!cited.ok) {
131
- return {
132
- ...draft,
133
- sections: [{ heading: "Request blocked", body: cited.error.message }],
134
- citations: [],
135
- refused: true,
136
- refusalReason: cited.error.code,
137
- riskFlags: [...draft.riskFlags ?? [], cited.error.code]
138
- };
139
- }
140
- return draft;
141
- }
142
- async function explainConcept(input) {
143
- return await answer({
144
- envelope: input.envelope,
145
- question: `Explain concept: ${input.conceptKey}`
146
- });
147
- }
148
- return { answer, explainConcept };
149
- }
150
- export {
151
- createDemoAssistantHandlers
152
- };
1
+ var V=new Set(["en-US","en-GB","fr-FR"]);function G(h,k){return{code:h,message:k}}function K(h){if(!h.locale||!V.has(h.locale))return{ok:!1,error:G("LOCALE_REQUIRED","locale is required and must be supported")};if(!h.regulatoryContext?.jurisdiction)return{ok:!1,error:G("JURISDICTION_REQUIRED","jurisdiction is required")};if(!h.kbSnapshotId)return{ok:!1,error:G("KB_SNAPSHOT_REQUIRED","kbSnapshotId is required")};if(!h.allowedScope)return{ok:!1,error:G("SCOPE_VIOLATION","allowedScope is required")};return{ok:!0,value:h}}function M(h){let k=h.citations??[];if(!Array.isArray(k)||k.length===0)return{ok:!1,error:G("CITATIONS_REQUIRED","answers must include at least one citation")};return{ok:!0,value:h}}var W=[/\b(buy|sell)\b/i,/\b(should\s+buy|should\s+sell)\b/i,/\b(guarantee(d)?|promise(d)?)\b/i];function Q(h,k){if(!h)return{ok:!1,error:G("SCOPE_VIOLATION","allowedScope is required")};if(h!=="education_only")return{ok:!0,value:k};let q=(k.sections??[]).map((j)=>j.body).join(`
2
+ `);if(W.some((j)=>j.test(q)))return{ok:!1,error:G("SCOPE_VIOLATION","answer violates education_only scope (contains actionable or promotional language)")};return{ok:!0,value:k}}function $(){async function h(q){let z=K(q.envelope);if(!z.ok)return{locale:q.envelope.locale??"en-US",jurisdiction:q.envelope.regulatoryContext?.jurisdiction??"UNKNOWN",allowedScope:q.envelope.allowedScope??"education_only",sections:[{heading:"Request blocked",body:z.error.message}],citations:[],disclaimers:["This system refuses to answer without a valid envelope."],riskFlags:[z.error.code],refused:!0,refusalReason:z.error.code};let j={locale:z.value.locale,jurisdiction:z.value.regulatoryContext?.jurisdiction??"UNKNOWN",allowedScope:z.value.allowedScope??"education_only",sections:[{heading:"Answer (demo)",body:`You asked: "${q.question}". This demo answer is derived from the KB snapshot only.`}],citations:[{kbSnapshotId:z.value.kbSnapshotId??"unknown",sourceType:"ruleVersion",sourceId:"rv_demo",title:"Demo rule version",excerpt:"Demo excerpt"}],disclaimers:["Educational demo only."],riskFlags:[]},H=Q(z.value.allowedScope,j);if(!H.ok)return{...j,sections:[{heading:"Escalation required",body:H.error.message}],citations:j.citations,refused:!0,refusalReason:H.error.code,riskFlags:[...j.riskFlags??[],H.error.code]};let J=M(j);if(!J.ok)return{...j,sections:[{heading:"Request blocked",body:J.error.message}],citations:[],refused:!0,refusalReason:J.error.code,riskFlags:[...j.riskFlags??[],J.error.code]};return j}async function k(q){return await h({envelope:q.envelope,question:`Explain concept: ${q.conceptKey}`})}return{answer:h,explainConcept:k}}export{$ as createDemoAssistantHandlers};