@contractspec/example.locale-jurisdiction-gate 3.7.20 → 3.7.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +12 -12
- package/CHANGELOG.md +20 -0
- package/dist/browser/example.js +1 -1
- package/dist/browser/index.js +3 -3
- package/dist/browser/locale-jurisdiction-gate.feature.js +1 -1
- package/dist/example.d.ts +3 -2
- package/dist/example.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -3
- package/dist/locale-jurisdiction-gate.feature.js +1 -1
- package/dist/node/example.js +1 -1
- package/dist/node/index.js +3 -3
- package/dist/node/locale-jurisdiction-gate.feature.js +1 -1
- package/package.json +3 -3
- package/src/example.ts +16 -22
- package/src/index.ts +2 -0
- package/src/locale-jurisdiction-gate.feature.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -2,10 +2,10 @@ $ contractspec-bun-build prebuild
|
|
|
2
2
|
$ bun run build:bundle && bun run build:types
|
|
3
3
|
$ contractspec-bun-build transpile
|
|
4
4
|
[contractspec-bun-build] transpile target=bun root=src entries=22 noBundle=false
|
|
5
|
-
Bundled 22 modules in
|
|
5
|
+
Bundled 22 modules in 20ms
|
|
6
6
|
|
|
7
7
|
docs/index.js 1.44 KB (entry point)
|
|
8
|
-
./index.js 21.
|
|
8
|
+
./index.js 21.40 KB (entry point)
|
|
9
9
|
policy/index.js 2.87 KB (entry point)
|
|
10
10
|
policy/types.js 8 bytes (entry point)
|
|
11
11
|
translations/index.js 4.65 KB (entry point)
|
|
@@ -14,7 +14,7 @@ Bundled 22 modules in 45ms
|
|
|
14
14
|
translations/assistant-gate.fr-FR.translation.js 1.56 KB (entry point)
|
|
15
15
|
handlers/index.js 2.68 KB (entry point)
|
|
16
16
|
handlers/demo.handlers.js 2.68 KB (entry point)
|
|
17
|
-
./locale-jurisdiction-gate.feature.js 2.
|
|
17
|
+
./locale-jurisdiction-gate.feature.js 2.68 KB (entry point)
|
|
18
18
|
operations/index.js 4.60 KB (entry point)
|
|
19
19
|
operations/assistant.js 4.60 KB (entry point)
|
|
20
20
|
policy/assistant-gate.policy.js 1.64 KB (entry point)
|
|
@@ -22,16 +22,16 @@ Bundled 22 modules in 45ms
|
|
|
22
22
|
docs/locale-jurisdiction-gate.docblock.js 1.44 KB (entry point)
|
|
23
23
|
entities/index.js 2.52 KB (entry point)
|
|
24
24
|
./events.js 2.0 KB (entry point)
|
|
25
|
-
./example.js 0.
|
|
25
|
+
./example.js 0.73 KB (entry point)
|
|
26
26
|
forms/index.js 4.71 KB (entry point)
|
|
27
27
|
forms/assistant-context.form.js 4.71 KB (entry point)
|
|
28
28
|
entities/models.js 2.52 KB (entry point)
|
|
29
29
|
|
|
30
30
|
[contractspec-bun-build] transpile target=node root=src entries=22 noBundle=false
|
|
31
|
-
Bundled 22 modules in
|
|
31
|
+
Bundled 22 modules in 27ms
|
|
32
32
|
|
|
33
33
|
docs/index.js 1.43 KB (entry point)
|
|
34
|
-
./index.js 21.
|
|
34
|
+
./index.js 21.35 KB (entry point)
|
|
35
35
|
policy/index.js 2.86 KB (entry point)
|
|
36
36
|
policy/types.js 0 KB (entry point)
|
|
37
37
|
translations/index.js 4.62 KB (entry point)
|
|
@@ -40,7 +40,7 @@ Bundled 22 modules in 41ms
|
|
|
40
40
|
translations/assistant-gate.fr-FR.translation.js 1.52 KB (entry point)
|
|
41
41
|
handlers/index.js 2.67 KB (entry point)
|
|
42
42
|
handlers/demo.handlers.js 2.67 KB (entry point)
|
|
43
|
-
./locale-jurisdiction-gate.feature.js 2.
|
|
43
|
+
./locale-jurisdiction-gate.feature.js 2.67 KB (entry point)
|
|
44
44
|
operations/index.js 4.60 KB (entry point)
|
|
45
45
|
operations/assistant.js 4.60 KB (entry point)
|
|
46
46
|
policy/assistant-gate.policy.js 1.63 KB (entry point)
|
|
@@ -48,16 +48,16 @@ Bundled 22 modules in 41ms
|
|
|
48
48
|
docs/locale-jurisdiction-gate.docblock.js 1.43 KB (entry point)
|
|
49
49
|
entities/index.js 2.51 KB (entry point)
|
|
50
50
|
./events.js 2.0 KB (entry point)
|
|
51
|
-
./example.js 0.
|
|
51
|
+
./example.js 0.72 KB (entry point)
|
|
52
52
|
forms/index.js 4.70 KB (entry point)
|
|
53
53
|
forms/assistant-context.form.js 4.70 KB (entry point)
|
|
54
54
|
entities/models.js 2.51 KB (entry point)
|
|
55
55
|
|
|
56
56
|
[contractspec-bun-build] transpile target=browser root=src entries=22 noBundle=false
|
|
57
|
-
Bundled 22 modules in
|
|
57
|
+
Bundled 22 modules in 28ms
|
|
58
58
|
|
|
59
59
|
docs/index.js 1.43 KB (entry point)
|
|
60
|
-
./index.js 21.
|
|
60
|
+
./index.js 21.35 KB (entry point)
|
|
61
61
|
policy/index.js 2.86 KB (entry point)
|
|
62
62
|
policy/types.js 0 KB (entry point)
|
|
63
63
|
translations/index.js 4.62 KB (entry point)
|
|
@@ -66,7 +66,7 @@ Bundled 22 modules in 26ms
|
|
|
66
66
|
translations/assistant-gate.fr-FR.translation.js 1.52 KB (entry point)
|
|
67
67
|
handlers/index.js 2.67 KB (entry point)
|
|
68
68
|
handlers/demo.handlers.js 2.67 KB (entry point)
|
|
69
|
-
./locale-jurisdiction-gate.feature.js 2.
|
|
69
|
+
./locale-jurisdiction-gate.feature.js 2.67 KB (entry point)
|
|
70
70
|
operations/index.js 4.60 KB (entry point)
|
|
71
71
|
operations/assistant.js 4.60 KB (entry point)
|
|
72
72
|
policy/assistant-gate.policy.js 1.63 KB (entry point)
|
|
@@ -74,7 +74,7 @@ Bundled 22 modules in 26ms
|
|
|
74
74
|
docs/locale-jurisdiction-gate.docblock.js 1.43 KB (entry point)
|
|
75
75
|
entities/index.js 2.51 KB (entry point)
|
|
76
76
|
./events.js 2.0 KB (entry point)
|
|
77
|
-
./example.js 0.
|
|
77
|
+
./example.js 0.72 KB (entry point)
|
|
78
78
|
forms/index.js 4.70 KB (entry point)
|
|
79
79
|
forms/assistant-context.form.js 4.70 KB (entry point)
|
|
80
80
|
entities/models.js 2.51 KB (entry point)
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @contractspec/example.locale-jurisdiction-gate
|
|
2
2
|
|
|
3
|
+
## 3.7.22
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- chore: auto-bump internal dependents
|
|
8
|
+
- Updated dependencies because of Stabilize Turborepo build caching by making generated artifacts deterministic, modeling web LLM generation explicitly, and avoiding no-op build-tool rewrites.
|
|
9
|
+
- @contractspec/lib.contracts-spec@5.5.1
|
|
10
|
+
- @contractspec/lib.schema@3.7.14
|
|
11
|
+
|
|
12
|
+
## 3.7.21
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- chore: auto-bump internal dependents
|
|
17
|
+
- Updated dependencies because of Add FormSpec layout hints, semantic field rendering, and portable text/textarea input-group addons.
|
|
18
|
+
- Updated dependencies because of Add ThemeSpec light/dark modes and a design-system Tailwind bridge for CSS variables, presets, CSS text, and OKLCH color pass-through.
|
|
19
|
+
- Updated dependencies because of Add a canonical typed result system for ContractSpec success and failure propagation across operations, workflows, jobs, server adapters, MCP, GraphQL, and React clients.
|
|
20
|
+
- @contractspec/lib.contracts-spec@5.5.0
|
|
21
|
+
- @contractspec/lib.schema@3.7.14
|
|
22
|
+
|
|
3
23
|
## 3.7.20
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/browser/example.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineExample as
|
|
1
|
+
import{defineExample as b}from"@contractspec/lib.contracts-spec/examples";var f=b({meta:{key:"examples.locale-jurisdiction-gate",version:"1.0.0",title:"Locale Jurisdiction Gate",description:"Example: enforce locale + jurisdiction + kbSnapshotId + allowed scope for assistant calls (fail-closed).",kind:"template",visibility:"experimental",stability:"experimental",owners:["@contractspec-core"],tags:["package","examples","locale-jurisdiction-gate"]},surfaces:{templates:!0,sandbox:{enabled:!0,modes:["playground","specs"]},studio:{enabled:!1,installable:!1},mcp:{enabled:!1}},entrypoints:{packageName:"@contractspec/example.locale-jurisdiction-gate"}}),j=f;export{j as default,f as ExamplesLocaleJurisdictionGateExample};
|
package/dist/browser/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{registerDocBlocks as
|
|
1
|
+
import{registerDocBlocks as V}from"@contractspec/lib.contracts-spec/docs";var z=[{id:"docs.examples.locale-jurisdiction-gate.goal",title:"Locale/Jurisdiction Gate — Goal",summary:"Fail-closed gate that forces locale + jurisdiction + kbSnapshotId + allowedScope for assistant calls.",kind:"goal",visibility:"public",route:"/docs/examples/locale-jurisdiction-gate/goal",tags:["assistant","policy","locale","jurisdiction","knowledge"],body:`## Why it matters
|
|
2
2
|
- Forces all assistant behavior to be bound to explicit inputs (no guessing).
|
|
3
3
|
- Requires KB snapshot citations to make answers traceable and regenerable.
|
|
4
4
|
|
|
@@ -16,5 +16,5 @@ import{registerDocBlocks as H}from"@contractspec/lib.contracts-spec/docs";var J=
|
|
|
16
16
|
## Events
|
|
17
17
|
- assistant.answer.requested
|
|
18
18
|
- assistant.answer.blocked
|
|
19
|
-
- assistant.answer.delivered`}];
|
|
20
|
-
`);if(P.some((u)=>u.test(_)))return{ok:!1,error:O("SCOPE_VIOLATION","answer violates education_only scope (contains actionable or promotional language)")};return{ok:!0,value:o}}function $r(){async function i(_){let g=Q(_.envelope);if(!g.ok)return{locale:_.envelope.locale??"en-US",jurisdiction:_.envelope.regulatoryContext?.jurisdiction??"UNKNOWN",allowedScope:_.envelope.allowedScope??"education_only",sections:[{heading:"Request blocked",body:g.error.message}],citations:[],disclaimers:["This system refuses to answer without a valid envelope."],riskFlags:[g.error.code],refused:!0,refusalReason:g.error.code};let u={locale:g.value.locale,jurisdiction:g.value.regulatoryContext?.jurisdiction??"UNKNOWN",allowedScope:g.value.allowedScope??"education_only",sections:[{heading:"Answer (demo)",body:`You asked: "${_.question}". This demo answer is derived from the KB snapshot only.`}],citations:[{kbSnapshotId:g.value.kbSnapshotId??"unknown",sourceType:"ruleVersion",sourceId:"rv_demo",title:"Demo rule version",excerpt:"Demo excerpt"}],disclaimers:["Educational demo only."],riskFlags:[]},e=K(g.value.allowedScope,u);if(!e.ok)return{...u,sections:[{heading:"Escalation required",body:e.error.message}],citations:u.citations,refused:!0,refusalReason:e.error.code,riskFlags:[...u.riskFlags??[],e.error.code]};let y=q(u);if(!y.ok)return{...u,sections:[{heading:"Request blocked",body:y.error.message}],citations:[],refused:!0,refusalReason:y.error.code,riskFlags:[...u.riskFlags??[],y.error.code]};return u}async function o(_){return await i({envelope:_.envelope,question:`Explain concept: ${_.conceptKey}`})}return{answer:i,explainConcept:o}}import{OwnersEnum as d,StabilityEnum as w,TagsEnum as b}from"@contractspec/lib.contracts-spec/ownership";import{definePolicy as T}from"@contractspec/lib.contracts-spec/policy";var C=T({meta:{key:"locale-jurisdiction-gate.policy.gate",version:"1.0.0",title:"Assistant Locale and Jurisdiction Gate",description:"Requires explicit locale, jurisdiction, knowledge snapshot, and allowed scope before assistant requests may proceed.",domain:"assistant",scope:"operation",owners:[d.PlatformFinance],tags:[b.I18n,"assistant","policy","jurisdiction"],stability:w.Experimental},rules:[{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!context.locale || !context.jurisdiction || !context.kbSnapshotId || !context.allowedScope"}],reason:"Assistant requests fail closed until locale, jurisdiction, kbSnapshotId, and allowedScope are explicit."},{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '')"}],reason:"Only the explicitly reviewed assistant locales are permitted."},{effect:"allow",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '') && !!context.jurisdiction && !!context.kbSnapshotId && !!context.allowedScope"}],reason:"Explicit context is present, so the request may continue to citation and scope validation."}],pii:{fields:["kbSnapshotId"],retentionDays:30}});import{defineFeature as v}from"@contractspec/lib.contracts-spec";var dr=v({meta:{key:"locale-jurisdiction-gate",version:"1.0.0",title:"Locale + Jurisdiction Gate",description:"Fail-closed gating for assistant calls requiring locale/jurisdiction/snapshot/scope and citations.",domain:"knowledge",owners:["@examples"],tags:["assistant","policy","locale","jurisdiction","knowledge"],stability:"experimental"},operations:[{key:"assistant.answer",version:"1.0.0"},{key:"assistant.explainConcept",version:"1.0.0"}],events:[{key:"assistant.answer.requested",version:"1.0.0"},{key:"assistant.answer.blocked",version:"1.0.0"},{key:"assistant.answer.delivered",version:"1.0.0"}],presentations:[],opToPresentation:[],presentationsTargets:[],capabilities:{requires:[{key:"knowledge",version:"1.0.0"}]},policies:[{key:C.meta.key,version:C.meta.version}],knowledge:[{key:"locale-jurisdiction-gate.knowledge.rules",version:"1.0.0"}],docs:["docs.examples.locale-jurisdiction-gate.goal","docs.examples.locale-jurisdiction-gate.reference"]});import{defineCommand as j}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as k,ScalarTypeEnum as G}from"@contractspec/lib.schema";var n=k({name:"AssistantQuestionInput",description:"Input for assistant calls with mandatory envelope.",fields:{envelope:{type:s,isOptional:!1},question:{type:G.String_unsecure(),isOptional:!1}}}),E=k({name:"AssistantConceptInput",description:"Input for explaining a concept with mandatory envelope.",fields:{envelope:{type:s,isOptional:!1},conceptKey:{type:G.String_unsecure(),isOptional:!1}}}),m=j({meta:{key:"assistant.answer",version:"1.0.0",stability:"experimental",owners:["@examples"],tags:["assistant","policy","locale","jurisdiction","knowledge"],description:"Answer a user question using a KB snapshot with strict locale/jurisdiction gating.",goal:"Provide policy-safe answers that cite a KB snapshot or refuse.",context:"Called by UI or workflows; must fail-closed if envelope is invalid or citations are missing."},io:{input:n,output:R,errors:{LOCALE_REQUIRED:{description:"Locale is required and must be supported",http:400,gqlCode:"LOCALE_REQUIRED",when:"locale is missing or unsupported"},JURISDICTION_REQUIRED:{description:"Jurisdiction is required",http:400,gqlCode:"JURISDICTION_REQUIRED",when:"jurisdiction is missing"},KB_SNAPSHOT_REQUIRED:{description:"KB snapshot id is required",http:400,gqlCode:"KB_SNAPSHOT_REQUIRED",when:"kbSnapshotId is missing"},CITATIONS_REQUIRED:{description:"Answers must include citations to a KB snapshot",http:422,gqlCode:"CITATIONS_REQUIRED",when:"answer has no citations"},SCOPE_VIOLATION:{description:"Answer violates allowed scope and must be refused/escalated",http:403,gqlCode:"SCOPE_VIOLATION",when:"output includes forbidden content under the given allowedScope"}}},policy:{auth:"user"}}),nr=j({meta:{key:"assistant.explainConcept",version:"1.0.0",stability:"experimental",owners:["@examples"],tags:["assistant","policy","knowledge","concepts"],description:"Explain a concept using a KB snapshot with strict locale/jurisdiction gating.",goal:"Explain concepts with citations or refuse.",context:"Same constraints as assistant.answer."},io:{input:E,output:R,errors:m.io.errors},policy:{auth:"user"}});import{OwnersEnum as a,StabilityEnum as c,TagsEnum as rr}from"@contractspec/lib.contracts-spec/ownership";import{defineTranslation as ir}from"@contractspec/lib.contracts-spec/translations/spec";var _i=ir({meta:{key:"locale-jurisdiction-gate.translation.assistant-gate.en-GB",version:"1.0.0",domain:"assistant",description:"British English messages for the assistant locale and jurisdiction gate.",owners:[a.PlatformFinance],stability:c.Experimental,tags:[rr.I18n,"assistant","policy"]},locale:"en-GB",fallback:"en-US",messages:{"assistantGate.locale.label":{value:"Locale"},"assistantGate.locale.description":{value:"Select the reviewed locale for the assistant response."},"assistantGate.jurisdiction.label":{value:"Jurisdiction"},"assistantGate.jurisdiction.placeholder":{value:"UK-FCA"},"assistantGate.kbSnapshotId.label":{value:"Knowledge snapshot ID"},"assistantGate.kbSnapshotId.placeholder":{value:"kb_2026_03_20_policy_reviewed"},"assistantGate.allowedScope.label":{value:"Permitted scope"},"assistantGate.allowedScope.educationOnly":{value:"Educational content only"},"assistantGate.allowedScope.genericInfo":{value:"General information"},"assistantGate.allowedScope.escalationRequired":{value:"Escalation required"},"assistantGate.question.label":{value:"Question"},"assistantGate.question.placeholder":{value:"What may I say about this product in the selected jurisdiction?"},"assistantGate.submit.label":{value:"Generate response"}}});import{OwnersEnum as tr,StabilityEnum as ur,TagsEnum as or}from"@contractspec/lib.contracts-spec/ownership";import{defineTranslation as _r}from"@contractspec/lib.contracts-spec/translations/spec";var fi=_r({meta:{key:"locale-jurisdiction-gate.translation.assistant-gate.en-US",version:"1.0.0",domain:"assistant",description:"US English messages for the assistant locale and jurisdiction gate.",owners:[tr.PlatformFinance],stability:ur.Experimental,tags:[or.I18n,"assistant","policy"]},locale:"en-US",messages:{"assistantGate.locale.label":{value:"Locale"},"assistantGate.locale.description":{value:"Choose the reviewed locale for the assistant answer."},"assistantGate.locale.enUs":{value:"English (United States)"},"assistantGate.locale.enGb":{value:"English (United Kingdom)"},"assistantGate.locale.frFr":{value:"French (France)"},"assistantGate.jurisdiction.label":{value:"Jurisdiction"},"assistantGate.jurisdiction.placeholder":{value:"US-SEC"},"assistantGate.kbSnapshotId.label":{value:"Knowledge snapshot ID"},"assistantGate.kbSnapshotId.placeholder":{value:"kb_2026_03_20_policy_reviewed"},"assistantGate.allowedScope.label":{value:"Allowed scope"},"assistantGate.allowedScope.educationOnly":{value:"Educational content only"},"assistantGate.allowedScope.genericInfo":{value:"Generic information"},"assistantGate.allowedScope.escalationRequired":{value:"Escalation required"},"assistantGate.question.label":{value:"Question"},"assistantGate.question.placeholder":{value:"What can I say about this product in the selected jurisdiction?"},"assistantGate.submit.label":{value:"Generate answer"}}});import{OwnersEnum as gr,StabilityEnum as Or,TagsEnum as xr}from"@contractspec/lib.contracts-spec/ownership";import{defineTranslation as fr}from"@contractspec/lib.contracts-spec/translations/spec";var si=fr({meta:{key:"locale-jurisdiction-gate.translation.assistant-gate.fr-FR",version:"1.0.0",domain:"assistant",description:"French messages for the assistant locale and jurisdiction gate.",owners:[gr.PlatformFinance],stability:Or.Experimental,tags:[xr.I18n,"assistant","policy"]},locale:"fr-FR",fallback:"en-US",messages:{"assistantGate.locale.label":{value:"Langue"},"assistantGate.locale.description":{value:"Sélectionnez la langue validée pour la réponse de l'assistant."},"assistantGate.jurisdiction.label":{value:"Juridiction"},"assistantGate.jurisdiction.placeholder":{value:"FR-AMF"},"assistantGate.kbSnapshotId.label":{value:"Identifiant du snapshot documentaire"},"assistantGate.kbSnapshotId.placeholder":{value:"kb_2026_03_20_policy_reviewed"},"assistantGate.allowedScope.label":{value:"Périmètre autorisé"},"assistantGate.allowedScope.educationOnly":{value:"Contenu éducatif uniquement"},"assistantGate.allowedScope.genericInfo":{value:"Information générale"},"assistantGate.allowedScope.escalationRequired":{value:"Escalade obligatoire"},"assistantGate.question.label":{value:"Question"},"assistantGate.question.placeholder":{value:"Que puis-je dire sur ce produit dans la juridiction sélectionnée ?"},"assistantGate.submit.label":{value:"Générer la réponse"}}});export{Q as validateEnvelope,$ as example,q as enforceCitations,K as enforceAllowedScope,$r as createDemoAssistantHandlers,sr as UserProfileModel,V as RegulatoryContextModel,dr as LocaleJurisdictionGateFeature,s as LLMCallEnvelopeModel,C as AssistantGatePolicy,si as AssistantGateMessagesFrFr,fi as AssistantGateMessagesEnUs,_i as AssistantGateMessagesEnGb,nr as AssistantExplainConceptContract,Ar as AssistantContextForm,z as AssistantCitationModel,A as AssistantAnswerSectionModel,qr as AssistantAnswerRequestedEvent,R as AssistantAnswerIRModel,jr as AssistantAnswerDeliveredEvent,m as AssistantAnswerContract,Kr as AssistantAnswerBlockedEvent,f as AllowedScopeEnum};
|
|
19
|
+
- assistant.answer.delivered`}];V(z);import{defineEnum as A,defineSchemaModel as x,ScalarTypeEnum as r}from"@contractspec/lib.schema";var f=A("AllowedScope",["education_only","generic_info","escalation_required"]),Rr=x({name:"UserProfile",description:"User profile inputs used to derive regulatory context.",fields:{preferredLocale:{type:r.String_unsecure(),isOptional:!0},residencyCountry:{type:r.String_unsecure(),isOptional:!0},taxResidenceCountry:{type:r.String_unsecure(),isOptional:!0},clientType:{type:r.String_unsecure(),isOptional:!0}}}),N=x({name:"RegulatoryContext",description:"Explicit regulatory context (no guessing).",fields:{jurisdiction:{type:r.String_unsecure(),isOptional:!1},region:{type:r.String_unsecure(),isOptional:!0},clientType:{type:r.String_unsecure(),isOptional:!0},allowedScope:{type:f,isOptional:!1}}}),R=x({name:"LLMCallEnvelope",description:"Mandatory envelope for assistant calls. All fields are explicit and required for policy gating.",fields:{traceId:{type:r.String_unsecure(),isOptional:!1},locale:{type:r.String_unsecure(),isOptional:!1},regulatoryContext:{type:N,isOptional:!1},kbSnapshotId:{type:r.String_unsecure(),isOptional:!1},allowedScope:{type:f,isOptional:!1}}}),S=x({name:"AssistantCitation",description:"Citation referencing a KB snapshot + a specific item within it.",fields:{kbSnapshotId:{type:r.String_unsecure(),isOptional:!1},sourceType:{type:r.String_unsecure(),isOptional:!1},sourceId:{type:r.String_unsecure(),isOptional:!1},title:{type:r.String_unsecure(),isOptional:!0},excerpt:{type:r.String_unsecure(),isOptional:!0}}}),W=x({name:"AssistantAnswerSection",description:"Structured answer section.",fields:{heading:{type:r.String_unsecure(),isOptional:!1},body:{type:r.String_unsecure(),isOptional:!1}}}),s=x({name:"AssistantAnswerIR",description:"Structured assistant answer with mandatory citations and explicit locale/jurisdiction.",fields:{locale:{type:r.String_unsecure(),isOptional:!1},jurisdiction:{type:r.String_unsecure(),isOptional:!1},allowedScope:{type:f,isOptional:!1},sections:{type:W,isArray:!0,isOptional:!1},citations:{type:S,isArray:!0,isOptional:!1},disclaimers:{type:r.String_unsecure(),isArray:!0,isOptional:!0},riskFlags:{type:r.String_unsecure(),isArray:!0,isOptional:!0},refused:{type:r.Boolean(),isOptional:!0},refusalReason:{type:r.String_unsecure(),isOptional:!0}}});import{defineEvent as U}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as p,ScalarTypeEnum as t}from"@contractspec/lib.schema";var X=p({name:"AssistantAnswerRequestedPayload",description:"Emitted when an assistant answer is requested (pre-gate).",fields:{traceId:{type:t.String_unsecure(),isOptional:!1},locale:{type:t.String_unsecure(),isOptional:!1},jurisdiction:{type:t.String_unsecure(),isOptional:!1},kbSnapshotId:{type:t.String_unsecure(),isOptional:!1},allowedScope:{type:t.String_unsecure(),isOptional:!1}}}),qr=U({meta:{key:"assistant.answer.requested",version:"1.0.0",description:"Assistant answer requested (policy gate will run).",stability:"experimental",owners:["@examples"],tags:["assistant","policy"]},payload:X}),Z=p({name:"AssistantAnswerBlockedPayload",description:"Emitted when a request is blocked by the gate.",fields:{traceId:{type:t.String_unsecure(),isOptional:!1},reasonCode:{type:t.String_unsecure(),isOptional:!1},reason:{type:t.String_unsecure(),isOptional:!1}}}),Kr=U({meta:{key:"assistant.answer.blocked",version:"1.0.0",description:"Assistant answer blocked (fail-closed).",stability:"experimental",owners:["@examples"],tags:["assistant","policy","blocked"]},payload:Z}),$=p({name:"AssistantAnswerDeliveredPayload",description:"Emitted when a structured, cited answer is delivered.",fields:{traceId:{type:t.String_unsecure(),isOptional:!1},locale:{type:t.String_unsecure(),isOptional:!1},jurisdiction:{type:t.String_unsecure(),isOptional:!1},kbSnapshotId:{type:t.String_unsecure(),isOptional:!1},allowedScope:{type:t.String_unsecure(),isOptional:!1},citationsCount:{type:t.Int_unsecure(),isOptional:!1}}}),jr=U({meta:{key:"assistant.answer.delivered",version:"1.0.0",description:"Assistant answer delivered (must include KB snapshot citations).",stability:"experimental",owners:["@examples"],tags:["assistant","policy","delivered"]},payload:$});import{defineExample as B}from"@contractspec/lib.contracts-spec/examples";var D=B({meta:{key:"examples.locale-jurisdiction-gate",version:"1.0.0",title:"Locale Jurisdiction Gate",description:"Example: enforce locale + jurisdiction + kbSnapshotId + allowed scope for assistant calls (fail-closed).",kind:"template",visibility:"experimental",stability:"experimental",owners:["@contractspec-core"],tags:["package","examples","locale-jurisdiction-gate"]},surfaces:{templates:!0,sandbox:{enabled:!0,modes:["playground","specs"]},studio:{enabled:!1,installable:!1},mcp:{enabled:!1}},entrypoints:{packageName:"@contractspec/example.locale-jurisdiction-gate"}}),G=D;import{defineFormSpec as J}from"@contractspec/lib.contracts-spec/forms";import{OwnersEnum as L,StabilityEnum as Y,TagsEnum as h}from"@contractspec/lib.contracts-spec/ownership";import{defineSchemaModel as M,ScalarTypeEnum as I}from"@contractspec/lib.schema";var F=M({name:"AssistantContextFormModel",description:"Form values required before a policy-gated assistant request can be executed.",fields:{locale:{type:I.String_unsecure(),isOptional:!1},jurisdiction:{type:I.String_unsecure(),isOptional:!1},kbSnapshotId:{type:I.String_unsecure(),isOptional:!1},allowedScope:{type:f,isOptional:!1},question:{type:I.String_unsecure(),isOptional:!1}}}),Wr=J({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:[L.PlatformFinance],tags:[h.I18n,"assistant","form","policy"],stability:Y.Experimental},model:F,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"}});var P=new Set(["en-US","en-GB","fr-FR"]);function O(i,u){return{code:i,message:u}}function Q(i){if(!i.locale||!P.has(i.locale))return{ok:!1,error:O("LOCALE_REQUIRED","locale is required and must be supported")};if(!i.regulatoryContext?.jurisdiction)return{ok:!1,error:O("JURISDICTION_REQUIRED","jurisdiction is required")};if(!i.kbSnapshotId)return{ok:!1,error:O("KB_SNAPSHOT_REQUIRED","kbSnapshotId is required")};if(!i.allowedScope)return{ok:!1,error:O("SCOPE_VIOLATION","allowedScope is required")};return{ok:!0,value:i}}function q(i){let u=i.citations??[];if(!Array.isArray(u)||u.length===0)return{ok:!1,error:O("CITATIONS_REQUIRED","answers must include at least one citation")};return{ok:!0,value:i}}var l=[/\b(buy|sell)\b/i,/\b(should\s+buy|should\s+sell)\b/i,/\b(guarantee(d)?|promise(d)?)\b/i];function K(i,u){if(!i)return{ok:!1,error:O("SCOPE_VIOLATION","allowedScope is required")};if(i!=="education_only")return{ok:!0,value:u};let _=(u.sections??[]).map((o)=>o.body).join(`
|
|
20
|
+
`);if(l.some((o)=>o.test(_)))return{ok:!1,error:O("SCOPE_VIOLATION","answer violates education_only scope (contains actionable or promotional language)")};return{ok:!0,value:u}}function Gr(){async function i(_){let g=Q(_.envelope);if(!g.ok)return{locale:_.envelope.locale??"en-US",jurisdiction:_.envelope.regulatoryContext?.jurisdiction??"UNKNOWN",allowedScope:_.envelope.allowedScope??"education_only",sections:[{heading:"Request blocked",body:g.error.message}],citations:[],disclaimers:["This system refuses to answer without a valid envelope."],riskFlags:[g.error.code],refused:!0,refusalReason:g.error.code};let o={locale:g.value.locale,jurisdiction:g.value.regulatoryContext?.jurisdiction??"UNKNOWN",allowedScope:g.value.allowedScope??"education_only",sections:[{heading:"Answer (demo)",body:`You asked: "${_.question}". This demo answer is derived from the KB snapshot only.`}],citations:[{kbSnapshotId:g.value.kbSnapshotId??"unknown",sourceType:"ruleVersion",sourceId:"rv_demo",title:"Demo rule version",excerpt:"Demo excerpt"}],disclaimers:["Educational demo only."],riskFlags:[]},y=K(g.value.allowedScope,o);if(!y.ok)return{...o,sections:[{heading:"Escalation required",body:y.error.message}],citations:o.citations,refused:!0,refusalReason:y.error.code,riskFlags:[...o.riskFlags??[],y.error.code]};let e=q(o);if(!e.ok)return{...o,sections:[{heading:"Request blocked",body:e.error.message}],citations:[],refused:!0,refusalReason:e.error.code,riskFlags:[...o.riskFlags??[],e.error.code]};return o}async function u(_){return await i({envelope:_.envelope,question:`Explain concept: ${_.conceptKey}`})}return{answer:i,explainConcept:u}}import{OwnersEnum as d,StabilityEnum as w,TagsEnum as b}from"@contractspec/lib.contracts-spec/ownership";import{definePolicy as T}from"@contractspec/lib.contracts-spec/policy";var C=T({meta:{key:"locale-jurisdiction-gate.policy.gate",version:"1.0.0",title:"Assistant Locale and Jurisdiction Gate",description:"Requires explicit locale, jurisdiction, knowledge snapshot, and allowed scope before assistant requests may proceed.",domain:"assistant",scope:"operation",owners:[d.PlatformFinance],tags:[b.I18n,"assistant","policy","jurisdiction"],stability:w.Experimental},rules:[{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!context.locale || !context.jurisdiction || !context.kbSnapshotId || !context.allowedScope"}],reason:"Assistant requests fail closed until locale, jurisdiction, kbSnapshotId, and allowedScope are explicit."},{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '')"}],reason:"Only the explicitly reviewed assistant locales are permitted."},{effect:"allow",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '') && !!context.jurisdiction && !!context.kbSnapshotId && !!context.allowedScope"}],reason:"Explicit context is present, so the request may continue to citation and scope validation."}],pii:{fields:["kbSnapshotId"],retentionDays:30}});import{defineFeature as v}from"@contractspec/lib.contracts-spec/features";var dr=v({meta:{key:"locale-jurisdiction-gate",version:"1.0.0",title:"Locale + Jurisdiction Gate",description:"Fail-closed gating for assistant calls requiring locale/jurisdiction/snapshot/scope and citations.",domain:"knowledge",owners:["@examples"],tags:["assistant","policy","locale","jurisdiction","knowledge"],stability:"experimental"},operations:[{key:"assistant.answer",version:"1.0.0"},{key:"assistant.explainConcept",version:"1.0.0"}],events:[{key:"assistant.answer.requested",version:"1.0.0"},{key:"assistant.answer.blocked",version:"1.0.0"},{key:"assistant.answer.delivered",version:"1.0.0"}],presentations:[],opToPresentation:[],presentationsTargets:[],capabilities:{requires:[{key:"knowledge",version:"1.0.0"}]},policies:[{key:C.meta.key,version:C.meta.version}],knowledge:[{key:"locale-jurisdiction-gate.knowledge.rules",version:"1.0.0"}],docs:["docs.examples.locale-jurisdiction-gate.goal","docs.examples.locale-jurisdiction-gate.reference"]});import{defineCommand as j}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as k,ScalarTypeEnum as H}from"@contractspec/lib.schema";var n=k({name:"AssistantQuestionInput",description:"Input for assistant calls with mandatory envelope.",fields:{envelope:{type:R,isOptional:!1},question:{type:H.String_unsecure(),isOptional:!1}}}),E=k({name:"AssistantConceptInput",description:"Input for explaining a concept with mandatory envelope.",fields:{envelope:{type:R,isOptional:!1},conceptKey:{type:H.String_unsecure(),isOptional:!1}}}),m=j({meta:{key:"assistant.answer",version:"1.0.0",stability:"experimental",owners:["@examples"],tags:["assistant","policy","locale","jurisdiction","knowledge"],description:"Answer a user question using a KB snapshot with strict locale/jurisdiction gating.",goal:"Provide policy-safe answers that cite a KB snapshot or refuse.",context:"Called by UI or workflows; must fail-closed if envelope is invalid or citations are missing."},io:{input:n,output:s,errors:{LOCALE_REQUIRED:{description:"Locale is required and must be supported",http:400,gqlCode:"LOCALE_REQUIRED",when:"locale is missing or unsupported"},JURISDICTION_REQUIRED:{description:"Jurisdiction is required",http:400,gqlCode:"JURISDICTION_REQUIRED",when:"jurisdiction is missing"},KB_SNAPSHOT_REQUIRED:{description:"KB snapshot id is required",http:400,gqlCode:"KB_SNAPSHOT_REQUIRED",when:"kbSnapshotId is missing"},CITATIONS_REQUIRED:{description:"Answers must include citations to a KB snapshot",http:422,gqlCode:"CITATIONS_REQUIRED",when:"answer has no citations"},SCOPE_VIOLATION:{description:"Answer violates allowed scope and must be refused/escalated",http:403,gqlCode:"SCOPE_VIOLATION",when:"output includes forbidden content under the given allowedScope"}}},policy:{auth:"user"}}),nr=j({meta:{key:"assistant.explainConcept",version:"1.0.0",stability:"experimental",owners:["@examples"],tags:["assistant","policy","knowledge","concepts"],description:"Explain a concept using a KB snapshot with strict locale/jurisdiction gating.",goal:"Explain concepts with citations or refuse.",context:"Same constraints as assistant.answer."},io:{input:E,output:s,errors:m.io.errors},policy:{auth:"user"}});import{OwnersEnum as a,StabilityEnum as c,TagsEnum as rr}from"@contractspec/lib.contracts-spec/ownership";import{defineTranslation as ir}from"@contractspec/lib.contracts-spec/translations/spec";var _i=ir({meta:{key:"locale-jurisdiction-gate.translation.assistant-gate.en-GB",version:"1.0.0",domain:"assistant",description:"British English messages for the assistant locale and jurisdiction gate.",owners:[a.PlatformFinance],stability:c.Experimental,tags:[rr.I18n,"assistant","policy"]},locale:"en-GB",fallback:"en-US",messages:{"assistantGate.locale.label":{value:"Locale"},"assistantGate.locale.description":{value:"Select the reviewed locale for the assistant response."},"assistantGate.jurisdiction.label":{value:"Jurisdiction"},"assistantGate.jurisdiction.placeholder":{value:"UK-FCA"},"assistantGate.kbSnapshotId.label":{value:"Knowledge snapshot ID"},"assistantGate.kbSnapshotId.placeholder":{value:"kb_2026_03_20_policy_reviewed"},"assistantGate.allowedScope.label":{value:"Permitted scope"},"assistantGate.allowedScope.educationOnly":{value:"Educational content only"},"assistantGate.allowedScope.genericInfo":{value:"General information"},"assistantGate.allowedScope.escalationRequired":{value:"Escalation required"},"assistantGate.question.label":{value:"Question"},"assistantGate.question.placeholder":{value:"What may I say about this product in the selected jurisdiction?"},"assistantGate.submit.label":{value:"Generate response"}}});import{OwnersEnum as tr,StabilityEnum as or,TagsEnum as ur}from"@contractspec/lib.contracts-spec/ownership";import{defineTranslation as _r}from"@contractspec/lib.contracts-spec/translations/spec";var fi=_r({meta:{key:"locale-jurisdiction-gate.translation.assistant-gate.en-US",version:"1.0.0",domain:"assistant",description:"US English messages for the assistant locale and jurisdiction gate.",owners:[tr.PlatformFinance],stability:or.Experimental,tags:[ur.I18n,"assistant","policy"]},locale:"en-US",messages:{"assistantGate.locale.label":{value:"Locale"},"assistantGate.locale.description":{value:"Choose the reviewed locale for the assistant answer."},"assistantGate.locale.enUs":{value:"English (United States)"},"assistantGate.locale.enGb":{value:"English (United Kingdom)"},"assistantGate.locale.frFr":{value:"French (France)"},"assistantGate.jurisdiction.label":{value:"Jurisdiction"},"assistantGate.jurisdiction.placeholder":{value:"US-SEC"},"assistantGate.kbSnapshotId.label":{value:"Knowledge snapshot ID"},"assistantGate.kbSnapshotId.placeholder":{value:"kb_2026_03_20_policy_reviewed"},"assistantGate.allowedScope.label":{value:"Allowed scope"},"assistantGate.allowedScope.educationOnly":{value:"Educational content only"},"assistantGate.allowedScope.genericInfo":{value:"Generic information"},"assistantGate.allowedScope.escalationRequired":{value:"Escalation required"},"assistantGate.question.label":{value:"Question"},"assistantGate.question.placeholder":{value:"What can I say about this product in the selected jurisdiction?"},"assistantGate.submit.label":{value:"Generate answer"}}});import{OwnersEnum as gr,StabilityEnum as Or,TagsEnum as xr}from"@contractspec/lib.contracts-spec/ownership";import{defineTranslation as fr}from"@contractspec/lib.contracts-spec/translations/spec";var Ri=fr({meta:{key:"locale-jurisdiction-gate.translation.assistant-gate.fr-FR",version:"1.0.0",domain:"assistant",description:"French messages for the assistant locale and jurisdiction gate.",owners:[gr.PlatformFinance],stability:Or.Experimental,tags:[xr.I18n,"assistant","policy"]},locale:"fr-FR",fallback:"en-US",messages:{"assistantGate.locale.label":{value:"Langue"},"assistantGate.locale.description":{value:"Sélectionnez la langue validée pour la réponse de l'assistant."},"assistantGate.jurisdiction.label":{value:"Juridiction"},"assistantGate.jurisdiction.placeholder":{value:"FR-AMF"},"assistantGate.kbSnapshotId.label":{value:"Identifiant du snapshot documentaire"},"assistantGate.kbSnapshotId.placeholder":{value:"kb_2026_03_20_policy_reviewed"},"assistantGate.allowedScope.label":{value:"Périmètre autorisé"},"assistantGate.allowedScope.educationOnly":{value:"Contenu éducatif uniquement"},"assistantGate.allowedScope.genericInfo":{value:"Information générale"},"assistantGate.allowedScope.escalationRequired":{value:"Escalade obligatoire"},"assistantGate.question.label":{value:"Question"},"assistantGate.question.placeholder":{value:"Que puis-je dire sur ce produit dans la juridiction sélectionnée ?"},"assistantGate.submit.label":{value:"Générer la réponse"}}});export{Q as validateEnvelope,G as example,q as enforceCitations,K as enforceAllowedScope,Gr as createDemoAssistantHandlers,Rr as UserProfileModel,N as RegulatoryContextModel,dr as LocaleJurisdictionGateFeature,R as LLMCallEnvelopeModel,D as ExamplesLocaleJurisdictionGateExample,C as AssistantGatePolicy,Ri as AssistantGateMessagesFrFr,fi as AssistantGateMessagesEnUs,_i as AssistantGateMessagesEnGb,nr as AssistantExplainConceptContract,Wr as AssistantContextForm,S as AssistantCitationModel,W as AssistantAnswerSectionModel,qr as AssistantAnswerRequestedEvent,s as AssistantAnswerIRModel,jr as AssistantAnswerDeliveredEvent,m as AssistantAnswerContract,Kr as AssistantAnswerBlockedEvent,f as AllowedScopeEnum};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{OwnersEnum as j,StabilityEnum as k,TagsEnum as q}from"@contractspec/lib.contracts-spec/ownership";import{definePolicy as v}from"@contractspec/lib.contracts-spec/policy";var h=v({meta:{key:"locale-jurisdiction-gate.policy.gate",version:"1.0.0",title:"Assistant Locale and Jurisdiction Gate",description:"Requires explicit locale, jurisdiction, knowledge snapshot, and allowed scope before assistant requests may proceed.",domain:"assistant",scope:"operation",owners:[j.PlatformFinance],tags:[q.I18n,"assistant","policy","jurisdiction"],stability:k.Experimental},rules:[{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!context.locale || !context.jurisdiction || !context.kbSnapshotId || !context.allowedScope"}],reason:"Assistant requests fail closed until locale, jurisdiction, kbSnapshotId, and allowedScope are explicit."},{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '')"}],reason:"Only the explicitly reviewed assistant locales are permitted."},{effect:"allow",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '') && !!context.jurisdiction && !!context.kbSnapshotId && !!context.allowedScope"}],reason:"Explicit context is present, so the request may continue to citation and scope validation."}],pii:{fields:["kbSnapshotId"],retentionDays:30}});import{defineFeature as x}from"@contractspec/lib.contracts-spec";var I=x({meta:{key:"locale-jurisdiction-gate",version:"1.0.0",title:"Locale + Jurisdiction Gate",description:"Fail-closed gating for assistant calls requiring locale/jurisdiction/snapshot/scope and citations.",domain:"knowledge",owners:["@examples"],tags:["assistant","policy","locale","jurisdiction","knowledge"],stability:"experimental"},operations:[{key:"assistant.answer",version:"1.0.0"},{key:"assistant.explainConcept",version:"1.0.0"}],events:[{key:"assistant.answer.requested",version:"1.0.0"},{key:"assistant.answer.blocked",version:"1.0.0"},{key:"assistant.answer.delivered",version:"1.0.0"}],presentations:[],opToPresentation:[],presentationsTargets:[],capabilities:{requires:[{key:"knowledge",version:"1.0.0"}]},policies:[{key:h.meta.key,version:h.meta.version}],knowledge:[{key:"locale-jurisdiction-gate.knowledge.rules",version:"1.0.0"}],docs:["docs.examples.locale-jurisdiction-gate.goal","docs.examples.locale-jurisdiction-gate.reference"]});export{I as LocaleJurisdictionGateFeature};
|
|
1
|
+
import{OwnersEnum as j,StabilityEnum as k,TagsEnum as q}from"@contractspec/lib.contracts-spec/ownership";import{definePolicy as v}from"@contractspec/lib.contracts-spec/policy";var h=v({meta:{key:"locale-jurisdiction-gate.policy.gate",version:"1.0.0",title:"Assistant Locale and Jurisdiction Gate",description:"Requires explicit locale, jurisdiction, knowledge snapshot, and allowed scope before assistant requests may proceed.",domain:"assistant",scope:"operation",owners:[j.PlatformFinance],tags:[q.I18n,"assistant","policy","jurisdiction"],stability:k.Experimental},rules:[{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!context.locale || !context.jurisdiction || !context.kbSnapshotId || !context.allowedScope"}],reason:"Assistant requests fail closed until locale, jurisdiction, kbSnapshotId, and allowedScope are explicit."},{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '')"}],reason:"Only the explicitly reviewed assistant locales are permitted."},{effect:"allow",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '') && !!context.jurisdiction && !!context.kbSnapshotId && !!context.allowedScope"}],reason:"Explicit context is present, so the request may continue to citation and scope validation."}],pii:{fields:["kbSnapshotId"],retentionDays:30}});import{defineFeature as x}from"@contractspec/lib.contracts-spec/features";var I=x({meta:{key:"locale-jurisdiction-gate",version:"1.0.0",title:"Locale + Jurisdiction Gate",description:"Fail-closed gating for assistant calls requiring locale/jurisdiction/snapshot/scope and citations.",domain:"knowledge",owners:["@examples"],tags:["assistant","policy","locale","jurisdiction","knowledge"],stability:"experimental"},operations:[{key:"assistant.answer",version:"1.0.0"},{key:"assistant.explainConcept",version:"1.0.0"}],events:[{key:"assistant.answer.requested",version:"1.0.0"},{key:"assistant.answer.blocked",version:"1.0.0"},{key:"assistant.answer.delivered",version:"1.0.0"}],presentations:[],opToPresentation:[],presentationsTargets:[],capabilities:{requires:[{key:"knowledge",version:"1.0.0"}]},policies:[{key:h.meta.key,version:h.meta.version}],knowledge:[{key:"locale-jurisdiction-gate.knowledge.rules",version:"1.0.0"}],docs:["docs.examples.locale-jurisdiction-gate.goal","docs.examples.locale-jurisdiction-gate.reference"]});export{I as LocaleJurisdictionGateFeature};
|
package/dist/example.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
export default
|
|
1
|
+
declare const ExamplesLocaleJurisdictionGateExample: import("@contractspec/lib.contracts-spec").ExampleSpec;
|
|
2
|
+
export default ExamplesLocaleJurisdictionGateExample;
|
|
3
|
+
export { ExamplesLocaleJurisdictionGateExample };
|
package/dist/example.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{defineExample as
|
|
2
|
+
import{defineExample as b}from"@contractspec/lib.contracts-spec/examples";var f=b({meta:{key:"examples.locale-jurisdiction-gate",version:"1.0.0",title:"Locale Jurisdiction Gate",description:"Example: enforce locale + jurisdiction + kbSnapshotId + allowed scope for assistant calls (fail-closed).",kind:"template",visibility:"experimental",stability:"experimental",owners:["@contractspec-core"],tags:["package","examples","locale-jurisdiction-gate"]},surfaces:{templates:!0,sandbox:{enabled:!0,modes:["playground","specs"]},studio:{enabled:!1,installable:!1},mcp:{enabled:!1}},entrypoints:{packageName:"@contractspec/example.locale-jurisdiction-gate"}}),j=f;export{j as default,f as ExamplesLocaleJurisdictionGateExample};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{registerDocBlocks as
|
|
2
|
+
import{registerDocBlocks as V}from"@contractspec/lib.contracts-spec/docs";var z=[{id:"docs.examples.locale-jurisdiction-gate.goal",title:"Locale/Jurisdiction Gate \u2014 Goal",summary:"Fail-closed gate that forces locale + jurisdiction + kbSnapshotId + allowedScope for assistant calls.",kind:"goal",visibility:"public",route:"/docs/examples/locale-jurisdiction-gate/goal",tags:["assistant","policy","locale","jurisdiction","knowledge"],body:`## Why it matters
|
|
3
3
|
- Forces all assistant behavior to be bound to explicit inputs (no guessing).
|
|
4
4
|
- Requires KB snapshot citations to make answers traceable and regenerable.
|
|
5
5
|
|
|
@@ -17,5 +17,5 @@ import{registerDocBlocks as H}from"@contractspec/lib.contracts-spec/docs";var J=
|
|
|
17
17
|
## Events
|
|
18
18
|
- assistant.answer.requested
|
|
19
19
|
- assistant.answer.blocked
|
|
20
|
-
- assistant.answer.delivered`}];
|
|
21
|
-
`);if(P.some((u)=>u.test(_)))return{ok:!1,error:O("SCOPE_VIOLATION","answer violates education_only scope (contains actionable or promotional language)")};return{ok:!0,value:o}}function $r(){async function i(_){let g=Q(_.envelope);if(!g.ok)return{locale:_.envelope.locale??"en-US",jurisdiction:_.envelope.regulatoryContext?.jurisdiction??"UNKNOWN",allowedScope:_.envelope.allowedScope??"education_only",sections:[{heading:"Request blocked",body:g.error.message}],citations:[],disclaimers:["This system refuses to answer without a valid envelope."],riskFlags:[g.error.code],refused:!0,refusalReason:g.error.code};let u={locale:g.value.locale,jurisdiction:g.value.regulatoryContext?.jurisdiction??"UNKNOWN",allowedScope:g.value.allowedScope??"education_only",sections:[{heading:"Answer (demo)",body:`You asked: "${_.question}". This demo answer is derived from the KB snapshot only.`}],citations:[{kbSnapshotId:g.value.kbSnapshotId??"unknown",sourceType:"ruleVersion",sourceId:"rv_demo",title:"Demo rule version",excerpt:"Demo excerpt"}],disclaimers:["Educational demo only."],riskFlags:[]},e=K(g.value.allowedScope,u);if(!e.ok)return{...u,sections:[{heading:"Escalation required",body:e.error.message}],citations:u.citations,refused:!0,refusalReason:e.error.code,riskFlags:[...u.riskFlags??[],e.error.code]};let y=q(u);if(!y.ok)return{...u,sections:[{heading:"Request blocked",body:y.error.message}],citations:[],refused:!0,refusalReason:y.error.code,riskFlags:[...u.riskFlags??[],y.error.code]};return u}async function o(_){return await i({envelope:_.envelope,question:`Explain concept: ${_.conceptKey}`})}return{answer:i,explainConcept:o}}import{OwnersEnum as d,StabilityEnum as w,TagsEnum as b}from"@contractspec/lib.contracts-spec/ownership";import{definePolicy as T}from"@contractspec/lib.contracts-spec/policy";var C=T({meta:{key:"locale-jurisdiction-gate.policy.gate",version:"1.0.0",title:"Assistant Locale and Jurisdiction Gate",description:"Requires explicit locale, jurisdiction, knowledge snapshot, and allowed scope before assistant requests may proceed.",domain:"assistant",scope:"operation",owners:[d.PlatformFinance],tags:[b.I18n,"assistant","policy","jurisdiction"],stability:w.Experimental},rules:[{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!context.locale || !context.jurisdiction || !context.kbSnapshotId || !context.allowedScope"}],reason:"Assistant requests fail closed until locale, jurisdiction, kbSnapshotId, and allowedScope are explicit."},{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '')"}],reason:"Only the explicitly reviewed assistant locales are permitted."},{effect:"allow",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '') && !!context.jurisdiction && !!context.kbSnapshotId && !!context.allowedScope"}],reason:"Explicit context is present, so the request may continue to citation and scope validation."}],pii:{fields:["kbSnapshotId"],retentionDays:30}});import{defineFeature as v}from"@contractspec/lib.contracts-spec";var dr=v({meta:{key:"locale-jurisdiction-gate",version:"1.0.0",title:"Locale + Jurisdiction Gate",description:"Fail-closed gating for assistant calls requiring locale/jurisdiction/snapshot/scope and citations.",domain:"knowledge",owners:["@examples"],tags:["assistant","policy","locale","jurisdiction","knowledge"],stability:"experimental"},operations:[{key:"assistant.answer",version:"1.0.0"},{key:"assistant.explainConcept",version:"1.0.0"}],events:[{key:"assistant.answer.requested",version:"1.0.0"},{key:"assistant.answer.blocked",version:"1.0.0"},{key:"assistant.answer.delivered",version:"1.0.0"}],presentations:[],opToPresentation:[],presentationsTargets:[],capabilities:{requires:[{key:"knowledge",version:"1.0.0"}]},policies:[{key:C.meta.key,version:C.meta.version}],knowledge:[{key:"locale-jurisdiction-gate.knowledge.rules",version:"1.0.0"}],docs:["docs.examples.locale-jurisdiction-gate.goal","docs.examples.locale-jurisdiction-gate.reference"]});import{defineCommand as j}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as k,ScalarTypeEnum as G}from"@contractspec/lib.schema";var n=k({name:"AssistantQuestionInput",description:"Input for assistant calls with mandatory envelope.",fields:{envelope:{type:s,isOptional:!1},question:{type:G.String_unsecure(),isOptional:!1}}}),E=k({name:"AssistantConceptInput",description:"Input for explaining a concept with mandatory envelope.",fields:{envelope:{type:s,isOptional:!1},conceptKey:{type:G.String_unsecure(),isOptional:!1}}}),m=j({meta:{key:"assistant.answer",version:"1.0.0",stability:"experimental",owners:["@examples"],tags:["assistant","policy","locale","jurisdiction","knowledge"],description:"Answer a user question using a KB snapshot with strict locale/jurisdiction gating.",goal:"Provide policy-safe answers that cite a KB snapshot or refuse.",context:"Called by UI or workflows; must fail-closed if envelope is invalid or citations are missing."},io:{input:n,output:R,errors:{LOCALE_REQUIRED:{description:"Locale is required and must be supported",http:400,gqlCode:"LOCALE_REQUIRED",when:"locale is missing or unsupported"},JURISDICTION_REQUIRED:{description:"Jurisdiction is required",http:400,gqlCode:"JURISDICTION_REQUIRED",when:"jurisdiction is missing"},KB_SNAPSHOT_REQUIRED:{description:"KB snapshot id is required",http:400,gqlCode:"KB_SNAPSHOT_REQUIRED",when:"kbSnapshotId is missing"},CITATIONS_REQUIRED:{description:"Answers must include citations to a KB snapshot",http:422,gqlCode:"CITATIONS_REQUIRED",when:"answer has no citations"},SCOPE_VIOLATION:{description:"Answer violates allowed scope and must be refused/escalated",http:403,gqlCode:"SCOPE_VIOLATION",when:"output includes forbidden content under the given allowedScope"}}},policy:{auth:"user"}}),nr=j({meta:{key:"assistant.explainConcept",version:"1.0.0",stability:"experimental",owners:["@examples"],tags:["assistant","policy","knowledge","concepts"],description:"Explain a concept using a KB snapshot with strict locale/jurisdiction gating.",goal:"Explain concepts with citations or refuse.",context:"Same constraints as assistant.answer."},io:{input:E,output:R,errors:m.io.errors},policy:{auth:"user"}});import{OwnersEnum as a,StabilityEnum as c,TagsEnum as rr}from"@contractspec/lib.contracts-spec/ownership";import{defineTranslation as ir}from"@contractspec/lib.contracts-spec/translations/spec";var _i=ir({meta:{key:"locale-jurisdiction-gate.translation.assistant-gate.en-GB",version:"1.0.0",domain:"assistant",description:"British English messages for the assistant locale and jurisdiction gate.",owners:[a.PlatformFinance],stability:c.Experimental,tags:[rr.I18n,"assistant","policy"]},locale:"en-GB",fallback:"en-US",messages:{"assistantGate.locale.label":{value:"Locale"},"assistantGate.locale.description":{value:"Select the reviewed locale for the assistant response."},"assistantGate.jurisdiction.label":{value:"Jurisdiction"},"assistantGate.jurisdiction.placeholder":{value:"UK-FCA"},"assistantGate.kbSnapshotId.label":{value:"Knowledge snapshot ID"},"assistantGate.kbSnapshotId.placeholder":{value:"kb_2026_03_20_policy_reviewed"},"assistantGate.allowedScope.label":{value:"Permitted scope"},"assistantGate.allowedScope.educationOnly":{value:"Educational content only"},"assistantGate.allowedScope.genericInfo":{value:"General information"},"assistantGate.allowedScope.escalationRequired":{value:"Escalation required"},"assistantGate.question.label":{value:"Question"},"assistantGate.question.placeholder":{value:"What may I say about this product in the selected jurisdiction?"},"assistantGate.submit.label":{value:"Generate response"}}});import{OwnersEnum as tr,StabilityEnum as ur,TagsEnum as or}from"@contractspec/lib.contracts-spec/ownership";import{defineTranslation as _r}from"@contractspec/lib.contracts-spec/translations/spec";var fi=_r({meta:{key:"locale-jurisdiction-gate.translation.assistant-gate.en-US",version:"1.0.0",domain:"assistant",description:"US English messages for the assistant locale and jurisdiction gate.",owners:[tr.PlatformFinance],stability:ur.Experimental,tags:[or.I18n,"assistant","policy"]},locale:"en-US",messages:{"assistantGate.locale.label":{value:"Locale"},"assistantGate.locale.description":{value:"Choose the reviewed locale for the assistant answer."},"assistantGate.locale.enUs":{value:"English (United States)"},"assistantGate.locale.enGb":{value:"English (United Kingdom)"},"assistantGate.locale.frFr":{value:"French (France)"},"assistantGate.jurisdiction.label":{value:"Jurisdiction"},"assistantGate.jurisdiction.placeholder":{value:"US-SEC"},"assistantGate.kbSnapshotId.label":{value:"Knowledge snapshot ID"},"assistantGate.kbSnapshotId.placeholder":{value:"kb_2026_03_20_policy_reviewed"},"assistantGate.allowedScope.label":{value:"Allowed scope"},"assistantGate.allowedScope.educationOnly":{value:"Educational content only"},"assistantGate.allowedScope.genericInfo":{value:"Generic information"},"assistantGate.allowedScope.escalationRequired":{value:"Escalation required"},"assistantGate.question.label":{value:"Question"},"assistantGate.question.placeholder":{value:"What can I say about this product in the selected jurisdiction?"},"assistantGate.submit.label":{value:"Generate answer"}}});import{OwnersEnum as gr,StabilityEnum as Or,TagsEnum as xr}from"@contractspec/lib.contracts-spec/ownership";import{defineTranslation as fr}from"@contractspec/lib.contracts-spec/translations/spec";var si=fr({meta:{key:"locale-jurisdiction-gate.translation.assistant-gate.fr-FR",version:"1.0.0",domain:"assistant",description:"French messages for the assistant locale and jurisdiction gate.",owners:[gr.PlatformFinance],stability:Or.Experimental,tags:[xr.I18n,"assistant","policy"]},locale:"fr-FR",fallback:"en-US",messages:{"assistantGate.locale.label":{value:"Langue"},"assistantGate.locale.description":{value:"S\xE9lectionnez la langue valid\xE9e pour la r\xE9ponse de l'assistant."},"assistantGate.jurisdiction.label":{value:"Juridiction"},"assistantGate.jurisdiction.placeholder":{value:"FR-AMF"},"assistantGate.kbSnapshotId.label":{value:"Identifiant du snapshot documentaire"},"assistantGate.kbSnapshotId.placeholder":{value:"kb_2026_03_20_policy_reviewed"},"assistantGate.allowedScope.label":{value:"P\xE9rim\xE8tre autoris\xE9"},"assistantGate.allowedScope.educationOnly":{value:"Contenu \xE9ducatif uniquement"},"assistantGate.allowedScope.genericInfo":{value:"Information g\xE9n\xE9rale"},"assistantGate.allowedScope.escalationRequired":{value:"Escalade obligatoire"},"assistantGate.question.label":{value:"Question"},"assistantGate.question.placeholder":{value:"Que puis-je dire sur ce produit dans la juridiction s\xE9lectionn\xE9e ?"},"assistantGate.submit.label":{value:"G\xE9n\xE9rer la r\xE9ponse"}}});export{Q as validateEnvelope,$ as example,q as enforceCitations,K as enforceAllowedScope,$r as createDemoAssistantHandlers,sr as UserProfileModel,V as RegulatoryContextModel,dr as LocaleJurisdictionGateFeature,s as LLMCallEnvelopeModel,C as AssistantGatePolicy,si as AssistantGateMessagesFrFr,fi as AssistantGateMessagesEnUs,_i as AssistantGateMessagesEnGb,nr as AssistantExplainConceptContract,Ar as AssistantContextForm,z as AssistantCitationModel,A as AssistantAnswerSectionModel,qr as AssistantAnswerRequestedEvent,R as AssistantAnswerIRModel,jr as AssistantAnswerDeliveredEvent,m as AssistantAnswerContract,Kr as AssistantAnswerBlockedEvent,f as AllowedScopeEnum};
|
|
20
|
+
- assistant.answer.delivered`}];V(z);import{defineEnum as A,defineSchemaModel as x,ScalarTypeEnum as r}from"@contractspec/lib.schema";var f=A("AllowedScope",["education_only","generic_info","escalation_required"]),Rr=x({name:"UserProfile",description:"User profile inputs used to derive regulatory context.",fields:{preferredLocale:{type:r.String_unsecure(),isOptional:!0},residencyCountry:{type:r.String_unsecure(),isOptional:!0},taxResidenceCountry:{type:r.String_unsecure(),isOptional:!0},clientType:{type:r.String_unsecure(),isOptional:!0}}}),N=x({name:"RegulatoryContext",description:"Explicit regulatory context (no guessing).",fields:{jurisdiction:{type:r.String_unsecure(),isOptional:!1},region:{type:r.String_unsecure(),isOptional:!0},clientType:{type:r.String_unsecure(),isOptional:!0},allowedScope:{type:f,isOptional:!1}}}),R=x({name:"LLMCallEnvelope",description:"Mandatory envelope for assistant calls. All fields are explicit and required for policy gating.",fields:{traceId:{type:r.String_unsecure(),isOptional:!1},locale:{type:r.String_unsecure(),isOptional:!1},regulatoryContext:{type:N,isOptional:!1},kbSnapshotId:{type:r.String_unsecure(),isOptional:!1},allowedScope:{type:f,isOptional:!1}}}),S=x({name:"AssistantCitation",description:"Citation referencing a KB snapshot + a specific item within it.",fields:{kbSnapshotId:{type:r.String_unsecure(),isOptional:!1},sourceType:{type:r.String_unsecure(),isOptional:!1},sourceId:{type:r.String_unsecure(),isOptional:!1},title:{type:r.String_unsecure(),isOptional:!0},excerpt:{type:r.String_unsecure(),isOptional:!0}}}),W=x({name:"AssistantAnswerSection",description:"Structured answer section.",fields:{heading:{type:r.String_unsecure(),isOptional:!1},body:{type:r.String_unsecure(),isOptional:!1}}}),s=x({name:"AssistantAnswerIR",description:"Structured assistant answer with mandatory citations and explicit locale/jurisdiction.",fields:{locale:{type:r.String_unsecure(),isOptional:!1},jurisdiction:{type:r.String_unsecure(),isOptional:!1},allowedScope:{type:f,isOptional:!1},sections:{type:W,isArray:!0,isOptional:!1},citations:{type:S,isArray:!0,isOptional:!1},disclaimers:{type:r.String_unsecure(),isArray:!0,isOptional:!0},riskFlags:{type:r.String_unsecure(),isArray:!0,isOptional:!0},refused:{type:r.Boolean(),isOptional:!0},refusalReason:{type:r.String_unsecure(),isOptional:!0}}});import{defineEvent as U}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as p,ScalarTypeEnum as t}from"@contractspec/lib.schema";var X=p({name:"AssistantAnswerRequestedPayload",description:"Emitted when an assistant answer is requested (pre-gate).",fields:{traceId:{type:t.String_unsecure(),isOptional:!1},locale:{type:t.String_unsecure(),isOptional:!1},jurisdiction:{type:t.String_unsecure(),isOptional:!1},kbSnapshotId:{type:t.String_unsecure(),isOptional:!1},allowedScope:{type:t.String_unsecure(),isOptional:!1}}}),qr=U({meta:{key:"assistant.answer.requested",version:"1.0.0",description:"Assistant answer requested (policy gate will run).",stability:"experimental",owners:["@examples"],tags:["assistant","policy"]},payload:X}),Z=p({name:"AssistantAnswerBlockedPayload",description:"Emitted when a request is blocked by the gate.",fields:{traceId:{type:t.String_unsecure(),isOptional:!1},reasonCode:{type:t.String_unsecure(),isOptional:!1},reason:{type:t.String_unsecure(),isOptional:!1}}}),Kr=U({meta:{key:"assistant.answer.blocked",version:"1.0.0",description:"Assistant answer blocked (fail-closed).",stability:"experimental",owners:["@examples"],tags:["assistant","policy","blocked"]},payload:Z}),$=p({name:"AssistantAnswerDeliveredPayload",description:"Emitted when a structured, cited answer is delivered.",fields:{traceId:{type:t.String_unsecure(),isOptional:!1},locale:{type:t.String_unsecure(),isOptional:!1},jurisdiction:{type:t.String_unsecure(),isOptional:!1},kbSnapshotId:{type:t.String_unsecure(),isOptional:!1},allowedScope:{type:t.String_unsecure(),isOptional:!1},citationsCount:{type:t.Int_unsecure(),isOptional:!1}}}),jr=U({meta:{key:"assistant.answer.delivered",version:"1.0.0",description:"Assistant answer delivered (must include KB snapshot citations).",stability:"experimental",owners:["@examples"],tags:["assistant","policy","delivered"]},payload:$});import{defineExample as B}from"@contractspec/lib.contracts-spec/examples";var D=B({meta:{key:"examples.locale-jurisdiction-gate",version:"1.0.0",title:"Locale Jurisdiction Gate",description:"Example: enforce locale + jurisdiction + kbSnapshotId + allowed scope for assistant calls (fail-closed).",kind:"template",visibility:"experimental",stability:"experimental",owners:["@contractspec-core"],tags:["package","examples","locale-jurisdiction-gate"]},surfaces:{templates:!0,sandbox:{enabled:!0,modes:["playground","specs"]},studio:{enabled:!1,installable:!1},mcp:{enabled:!1}},entrypoints:{packageName:"@contractspec/example.locale-jurisdiction-gate"}}),G=D;import{defineFormSpec as J}from"@contractspec/lib.contracts-spec/forms";import{OwnersEnum as L,StabilityEnum as Y,TagsEnum as h}from"@contractspec/lib.contracts-spec/ownership";import{defineSchemaModel as M,ScalarTypeEnum as I}from"@contractspec/lib.schema";var F=M({name:"AssistantContextFormModel",description:"Form values required before a policy-gated assistant request can be executed.",fields:{locale:{type:I.String_unsecure(),isOptional:!1},jurisdiction:{type:I.String_unsecure(),isOptional:!1},kbSnapshotId:{type:I.String_unsecure(),isOptional:!1},allowedScope:{type:f,isOptional:!1},question:{type:I.String_unsecure(),isOptional:!1}}}),Wr=J({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:[L.PlatformFinance],tags:[h.I18n,"assistant","form","policy"],stability:Y.Experimental},model:F,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"}});var P=new Set(["en-US","en-GB","fr-FR"]);function O(i,u){return{code:i,message:u}}function Q(i){if(!i.locale||!P.has(i.locale))return{ok:!1,error:O("LOCALE_REQUIRED","locale is required and must be supported")};if(!i.regulatoryContext?.jurisdiction)return{ok:!1,error:O("JURISDICTION_REQUIRED","jurisdiction is required")};if(!i.kbSnapshotId)return{ok:!1,error:O("KB_SNAPSHOT_REQUIRED","kbSnapshotId is required")};if(!i.allowedScope)return{ok:!1,error:O("SCOPE_VIOLATION","allowedScope is required")};return{ok:!0,value:i}}function q(i){let u=i.citations??[];if(!Array.isArray(u)||u.length===0)return{ok:!1,error:O("CITATIONS_REQUIRED","answers must include at least one citation")};return{ok:!0,value:i}}var l=[/\b(buy|sell)\b/i,/\b(should\s+buy|should\s+sell)\b/i,/\b(guarantee(d)?|promise(d)?)\b/i];function K(i,u){if(!i)return{ok:!1,error:O("SCOPE_VIOLATION","allowedScope is required")};if(i!=="education_only")return{ok:!0,value:u};let _=(u.sections??[]).map((o)=>o.body).join(`
|
|
21
|
+
`);if(l.some((o)=>o.test(_)))return{ok:!1,error:O("SCOPE_VIOLATION","answer violates education_only scope (contains actionable or promotional language)")};return{ok:!0,value:u}}function Gr(){async function i(_){let g=Q(_.envelope);if(!g.ok)return{locale:_.envelope.locale??"en-US",jurisdiction:_.envelope.regulatoryContext?.jurisdiction??"UNKNOWN",allowedScope:_.envelope.allowedScope??"education_only",sections:[{heading:"Request blocked",body:g.error.message}],citations:[],disclaimers:["This system refuses to answer without a valid envelope."],riskFlags:[g.error.code],refused:!0,refusalReason:g.error.code};let o={locale:g.value.locale,jurisdiction:g.value.regulatoryContext?.jurisdiction??"UNKNOWN",allowedScope:g.value.allowedScope??"education_only",sections:[{heading:"Answer (demo)",body:`You asked: "${_.question}". This demo answer is derived from the KB snapshot only.`}],citations:[{kbSnapshotId:g.value.kbSnapshotId??"unknown",sourceType:"ruleVersion",sourceId:"rv_demo",title:"Demo rule version",excerpt:"Demo excerpt"}],disclaimers:["Educational demo only."],riskFlags:[]},y=K(g.value.allowedScope,o);if(!y.ok)return{...o,sections:[{heading:"Escalation required",body:y.error.message}],citations:o.citations,refused:!0,refusalReason:y.error.code,riskFlags:[...o.riskFlags??[],y.error.code]};let e=q(o);if(!e.ok)return{...o,sections:[{heading:"Request blocked",body:e.error.message}],citations:[],refused:!0,refusalReason:e.error.code,riskFlags:[...o.riskFlags??[],e.error.code]};return o}async function u(_){return await i({envelope:_.envelope,question:`Explain concept: ${_.conceptKey}`})}return{answer:i,explainConcept:u}}import{OwnersEnum as d,StabilityEnum as w,TagsEnum as b}from"@contractspec/lib.contracts-spec/ownership";import{definePolicy as T}from"@contractspec/lib.contracts-spec/policy";var C=T({meta:{key:"locale-jurisdiction-gate.policy.gate",version:"1.0.0",title:"Assistant Locale and Jurisdiction Gate",description:"Requires explicit locale, jurisdiction, knowledge snapshot, and allowed scope before assistant requests may proceed.",domain:"assistant",scope:"operation",owners:[d.PlatformFinance],tags:[b.I18n,"assistant","policy","jurisdiction"],stability:w.Experimental},rules:[{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!context.locale || !context.jurisdiction || !context.kbSnapshotId || !context.allowedScope"}],reason:"Assistant requests fail closed until locale, jurisdiction, kbSnapshotId, and allowedScope are explicit."},{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '')"}],reason:"Only the explicitly reviewed assistant locales are permitted."},{effect:"allow",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '') && !!context.jurisdiction && !!context.kbSnapshotId && !!context.allowedScope"}],reason:"Explicit context is present, so the request may continue to citation and scope validation."}],pii:{fields:["kbSnapshotId"],retentionDays:30}});import{defineFeature as v}from"@contractspec/lib.contracts-spec/features";var dr=v({meta:{key:"locale-jurisdiction-gate",version:"1.0.0",title:"Locale + Jurisdiction Gate",description:"Fail-closed gating for assistant calls requiring locale/jurisdiction/snapshot/scope and citations.",domain:"knowledge",owners:["@examples"],tags:["assistant","policy","locale","jurisdiction","knowledge"],stability:"experimental"},operations:[{key:"assistant.answer",version:"1.0.0"},{key:"assistant.explainConcept",version:"1.0.0"}],events:[{key:"assistant.answer.requested",version:"1.0.0"},{key:"assistant.answer.blocked",version:"1.0.0"},{key:"assistant.answer.delivered",version:"1.0.0"}],presentations:[],opToPresentation:[],presentationsTargets:[],capabilities:{requires:[{key:"knowledge",version:"1.0.0"}]},policies:[{key:C.meta.key,version:C.meta.version}],knowledge:[{key:"locale-jurisdiction-gate.knowledge.rules",version:"1.0.0"}],docs:["docs.examples.locale-jurisdiction-gate.goal","docs.examples.locale-jurisdiction-gate.reference"]});import{defineCommand as j}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as k,ScalarTypeEnum as H}from"@contractspec/lib.schema";var n=k({name:"AssistantQuestionInput",description:"Input for assistant calls with mandatory envelope.",fields:{envelope:{type:R,isOptional:!1},question:{type:H.String_unsecure(),isOptional:!1}}}),E=k({name:"AssistantConceptInput",description:"Input for explaining a concept with mandatory envelope.",fields:{envelope:{type:R,isOptional:!1},conceptKey:{type:H.String_unsecure(),isOptional:!1}}}),m=j({meta:{key:"assistant.answer",version:"1.0.0",stability:"experimental",owners:["@examples"],tags:["assistant","policy","locale","jurisdiction","knowledge"],description:"Answer a user question using a KB snapshot with strict locale/jurisdiction gating.",goal:"Provide policy-safe answers that cite a KB snapshot or refuse.",context:"Called by UI or workflows; must fail-closed if envelope is invalid or citations are missing."},io:{input:n,output:s,errors:{LOCALE_REQUIRED:{description:"Locale is required and must be supported",http:400,gqlCode:"LOCALE_REQUIRED",when:"locale is missing or unsupported"},JURISDICTION_REQUIRED:{description:"Jurisdiction is required",http:400,gqlCode:"JURISDICTION_REQUIRED",when:"jurisdiction is missing"},KB_SNAPSHOT_REQUIRED:{description:"KB snapshot id is required",http:400,gqlCode:"KB_SNAPSHOT_REQUIRED",when:"kbSnapshotId is missing"},CITATIONS_REQUIRED:{description:"Answers must include citations to a KB snapshot",http:422,gqlCode:"CITATIONS_REQUIRED",when:"answer has no citations"},SCOPE_VIOLATION:{description:"Answer violates allowed scope and must be refused/escalated",http:403,gqlCode:"SCOPE_VIOLATION",when:"output includes forbidden content under the given allowedScope"}}},policy:{auth:"user"}}),nr=j({meta:{key:"assistant.explainConcept",version:"1.0.0",stability:"experimental",owners:["@examples"],tags:["assistant","policy","knowledge","concepts"],description:"Explain a concept using a KB snapshot with strict locale/jurisdiction gating.",goal:"Explain concepts with citations or refuse.",context:"Same constraints as assistant.answer."},io:{input:E,output:s,errors:m.io.errors},policy:{auth:"user"}});import{OwnersEnum as a,StabilityEnum as c,TagsEnum as rr}from"@contractspec/lib.contracts-spec/ownership";import{defineTranslation as ir}from"@contractspec/lib.contracts-spec/translations/spec";var _i=ir({meta:{key:"locale-jurisdiction-gate.translation.assistant-gate.en-GB",version:"1.0.0",domain:"assistant",description:"British English messages for the assistant locale and jurisdiction gate.",owners:[a.PlatformFinance],stability:c.Experimental,tags:[rr.I18n,"assistant","policy"]},locale:"en-GB",fallback:"en-US",messages:{"assistantGate.locale.label":{value:"Locale"},"assistantGate.locale.description":{value:"Select the reviewed locale for the assistant response."},"assistantGate.jurisdiction.label":{value:"Jurisdiction"},"assistantGate.jurisdiction.placeholder":{value:"UK-FCA"},"assistantGate.kbSnapshotId.label":{value:"Knowledge snapshot ID"},"assistantGate.kbSnapshotId.placeholder":{value:"kb_2026_03_20_policy_reviewed"},"assistantGate.allowedScope.label":{value:"Permitted scope"},"assistantGate.allowedScope.educationOnly":{value:"Educational content only"},"assistantGate.allowedScope.genericInfo":{value:"General information"},"assistantGate.allowedScope.escalationRequired":{value:"Escalation required"},"assistantGate.question.label":{value:"Question"},"assistantGate.question.placeholder":{value:"What may I say about this product in the selected jurisdiction?"},"assistantGate.submit.label":{value:"Generate response"}}});import{OwnersEnum as tr,StabilityEnum as or,TagsEnum as ur}from"@contractspec/lib.contracts-spec/ownership";import{defineTranslation as _r}from"@contractspec/lib.contracts-spec/translations/spec";var fi=_r({meta:{key:"locale-jurisdiction-gate.translation.assistant-gate.en-US",version:"1.0.0",domain:"assistant",description:"US English messages for the assistant locale and jurisdiction gate.",owners:[tr.PlatformFinance],stability:or.Experimental,tags:[ur.I18n,"assistant","policy"]},locale:"en-US",messages:{"assistantGate.locale.label":{value:"Locale"},"assistantGate.locale.description":{value:"Choose the reviewed locale for the assistant answer."},"assistantGate.locale.enUs":{value:"English (United States)"},"assistantGate.locale.enGb":{value:"English (United Kingdom)"},"assistantGate.locale.frFr":{value:"French (France)"},"assistantGate.jurisdiction.label":{value:"Jurisdiction"},"assistantGate.jurisdiction.placeholder":{value:"US-SEC"},"assistantGate.kbSnapshotId.label":{value:"Knowledge snapshot ID"},"assistantGate.kbSnapshotId.placeholder":{value:"kb_2026_03_20_policy_reviewed"},"assistantGate.allowedScope.label":{value:"Allowed scope"},"assistantGate.allowedScope.educationOnly":{value:"Educational content only"},"assistantGate.allowedScope.genericInfo":{value:"Generic information"},"assistantGate.allowedScope.escalationRequired":{value:"Escalation required"},"assistantGate.question.label":{value:"Question"},"assistantGate.question.placeholder":{value:"What can I say about this product in the selected jurisdiction?"},"assistantGate.submit.label":{value:"Generate answer"}}});import{OwnersEnum as gr,StabilityEnum as Or,TagsEnum as xr}from"@contractspec/lib.contracts-spec/ownership";import{defineTranslation as fr}from"@contractspec/lib.contracts-spec/translations/spec";var Ri=fr({meta:{key:"locale-jurisdiction-gate.translation.assistant-gate.fr-FR",version:"1.0.0",domain:"assistant",description:"French messages for the assistant locale and jurisdiction gate.",owners:[gr.PlatformFinance],stability:Or.Experimental,tags:[xr.I18n,"assistant","policy"]},locale:"fr-FR",fallback:"en-US",messages:{"assistantGate.locale.label":{value:"Langue"},"assistantGate.locale.description":{value:"S\xE9lectionnez la langue valid\xE9e pour la r\xE9ponse de l'assistant."},"assistantGate.jurisdiction.label":{value:"Juridiction"},"assistantGate.jurisdiction.placeholder":{value:"FR-AMF"},"assistantGate.kbSnapshotId.label":{value:"Identifiant du snapshot documentaire"},"assistantGate.kbSnapshotId.placeholder":{value:"kb_2026_03_20_policy_reviewed"},"assistantGate.allowedScope.label":{value:"P\xE9rim\xE8tre autoris\xE9"},"assistantGate.allowedScope.educationOnly":{value:"Contenu \xE9ducatif uniquement"},"assistantGate.allowedScope.genericInfo":{value:"Information g\xE9n\xE9rale"},"assistantGate.allowedScope.escalationRequired":{value:"Escalade obligatoire"},"assistantGate.question.label":{value:"Question"},"assistantGate.question.placeholder":{value:"Que puis-je dire sur ce produit dans la juridiction s\xE9lectionn\xE9e ?"},"assistantGate.submit.label":{value:"G\xE9n\xE9rer la r\xE9ponse"}}});export{Q as validateEnvelope,G as example,q as enforceCitations,K as enforceAllowedScope,Gr as createDemoAssistantHandlers,Rr as UserProfileModel,N as RegulatoryContextModel,dr as LocaleJurisdictionGateFeature,R as LLMCallEnvelopeModel,D as ExamplesLocaleJurisdictionGateExample,C as AssistantGatePolicy,Ri as AssistantGateMessagesFrFr,fi as AssistantGateMessagesEnUs,_i as AssistantGateMessagesEnGb,nr as AssistantExplainConceptContract,Wr as AssistantContextForm,S as AssistantCitationModel,W as AssistantAnswerSectionModel,qr as AssistantAnswerRequestedEvent,s as AssistantAnswerIRModel,jr as AssistantAnswerDeliveredEvent,m as AssistantAnswerContract,Kr as AssistantAnswerBlockedEvent,f as AllowedScopeEnum};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{OwnersEnum as j,StabilityEnum as k,TagsEnum as q}from"@contractspec/lib.contracts-spec/ownership";import{definePolicy as v}from"@contractspec/lib.contracts-spec/policy";var h=v({meta:{key:"locale-jurisdiction-gate.policy.gate",version:"1.0.0",title:"Assistant Locale and Jurisdiction Gate",description:"Requires explicit locale, jurisdiction, knowledge snapshot, and allowed scope before assistant requests may proceed.",domain:"assistant",scope:"operation",owners:[j.PlatformFinance],tags:[q.I18n,"assistant","policy","jurisdiction"],stability:k.Experimental},rules:[{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!context.locale || !context.jurisdiction || !context.kbSnapshotId || !context.allowedScope"}],reason:"Assistant requests fail closed until locale, jurisdiction, kbSnapshotId, and allowedScope are explicit."},{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '')"}],reason:"Only the explicitly reviewed assistant locales are permitted."},{effect:"allow",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '') && !!context.jurisdiction && !!context.kbSnapshotId && !!context.allowedScope"}],reason:"Explicit context is present, so the request may continue to citation and scope validation."}],pii:{fields:["kbSnapshotId"],retentionDays:30}});import{defineFeature as x}from"@contractspec/lib.contracts-spec";var I=x({meta:{key:"locale-jurisdiction-gate",version:"1.0.0",title:"Locale + Jurisdiction Gate",description:"Fail-closed gating for assistant calls requiring locale/jurisdiction/snapshot/scope and citations.",domain:"knowledge",owners:["@examples"],tags:["assistant","policy","locale","jurisdiction","knowledge"],stability:"experimental"},operations:[{key:"assistant.answer",version:"1.0.0"},{key:"assistant.explainConcept",version:"1.0.0"}],events:[{key:"assistant.answer.requested",version:"1.0.0"},{key:"assistant.answer.blocked",version:"1.0.0"},{key:"assistant.answer.delivered",version:"1.0.0"}],presentations:[],opToPresentation:[],presentationsTargets:[],capabilities:{requires:[{key:"knowledge",version:"1.0.0"}]},policies:[{key:h.meta.key,version:h.meta.version}],knowledge:[{key:"locale-jurisdiction-gate.knowledge.rules",version:"1.0.0"}],docs:["docs.examples.locale-jurisdiction-gate.goal","docs.examples.locale-jurisdiction-gate.reference"]});export{I as LocaleJurisdictionGateFeature};
|
|
2
|
+
import{OwnersEnum as j,StabilityEnum as k,TagsEnum as q}from"@contractspec/lib.contracts-spec/ownership";import{definePolicy as v}from"@contractspec/lib.contracts-spec/policy";var h=v({meta:{key:"locale-jurisdiction-gate.policy.gate",version:"1.0.0",title:"Assistant Locale and Jurisdiction Gate",description:"Requires explicit locale, jurisdiction, knowledge snapshot, and allowed scope before assistant requests may proceed.",domain:"assistant",scope:"operation",owners:[j.PlatformFinance],tags:[q.I18n,"assistant","policy","jurisdiction"],stability:k.Experimental},rules:[{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!context.locale || !context.jurisdiction || !context.kbSnapshotId || !context.allowedScope"}],reason:"Assistant requests fail closed until locale, jurisdiction, kbSnapshotId, and allowedScope are explicit."},{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '')"}],reason:"Only the explicitly reviewed assistant locales are permitted."},{effect:"allow",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '') && !!context.jurisdiction && !!context.kbSnapshotId && !!context.allowedScope"}],reason:"Explicit context is present, so the request may continue to citation and scope validation."}],pii:{fields:["kbSnapshotId"],retentionDays:30}});import{defineFeature as x}from"@contractspec/lib.contracts-spec/features";var I=x({meta:{key:"locale-jurisdiction-gate",version:"1.0.0",title:"Locale + Jurisdiction Gate",description:"Fail-closed gating for assistant calls requiring locale/jurisdiction/snapshot/scope and citations.",domain:"knowledge",owners:["@examples"],tags:["assistant","policy","locale","jurisdiction","knowledge"],stability:"experimental"},operations:[{key:"assistant.answer",version:"1.0.0"},{key:"assistant.explainConcept",version:"1.0.0"}],events:[{key:"assistant.answer.requested",version:"1.0.0"},{key:"assistant.answer.blocked",version:"1.0.0"},{key:"assistant.answer.delivered",version:"1.0.0"}],presentations:[],opToPresentation:[],presentationsTargets:[],capabilities:{requires:[{key:"knowledge",version:"1.0.0"}]},policies:[{key:h.meta.key,version:h.meta.version}],knowledge:[{key:"locale-jurisdiction-gate.knowledge.rules",version:"1.0.0"}],docs:["docs.examples.locale-jurisdiction-gate.goal","docs.examples.locale-jurisdiction-gate.reference"]});export{I as LocaleJurisdictionGateFeature};
|
package/dist/node/example.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineExample as
|
|
1
|
+
import{defineExample as b}from"@contractspec/lib.contracts-spec/examples";var f=b({meta:{key:"examples.locale-jurisdiction-gate",version:"1.0.0",title:"Locale Jurisdiction Gate",description:"Example: enforce locale + jurisdiction + kbSnapshotId + allowed scope for assistant calls (fail-closed).",kind:"template",visibility:"experimental",stability:"experimental",owners:["@contractspec-core"],tags:["package","examples","locale-jurisdiction-gate"]},surfaces:{templates:!0,sandbox:{enabled:!0,modes:["playground","specs"]},studio:{enabled:!1,installable:!1},mcp:{enabled:!1}},entrypoints:{packageName:"@contractspec/example.locale-jurisdiction-gate"}}),j=f;export{j as default,f as ExamplesLocaleJurisdictionGateExample};
|
package/dist/node/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{registerDocBlocks as
|
|
1
|
+
import{registerDocBlocks as V}from"@contractspec/lib.contracts-spec/docs";var z=[{id:"docs.examples.locale-jurisdiction-gate.goal",title:"Locale/Jurisdiction Gate — Goal",summary:"Fail-closed gate that forces locale + jurisdiction + kbSnapshotId + allowedScope for assistant calls.",kind:"goal",visibility:"public",route:"/docs/examples/locale-jurisdiction-gate/goal",tags:["assistant","policy","locale","jurisdiction","knowledge"],body:`## Why it matters
|
|
2
2
|
- Forces all assistant behavior to be bound to explicit inputs (no guessing).
|
|
3
3
|
- Requires KB snapshot citations to make answers traceable and regenerable.
|
|
4
4
|
|
|
@@ -16,5 +16,5 @@ import{registerDocBlocks as H}from"@contractspec/lib.contracts-spec/docs";var J=
|
|
|
16
16
|
## Events
|
|
17
17
|
- assistant.answer.requested
|
|
18
18
|
- assistant.answer.blocked
|
|
19
|
-
- assistant.answer.delivered`}];
|
|
20
|
-
`);if(P.some((u)=>u.test(_)))return{ok:!1,error:O("SCOPE_VIOLATION","answer violates education_only scope (contains actionable or promotional language)")};return{ok:!0,value:o}}function $r(){async function i(_){let g=Q(_.envelope);if(!g.ok)return{locale:_.envelope.locale??"en-US",jurisdiction:_.envelope.regulatoryContext?.jurisdiction??"UNKNOWN",allowedScope:_.envelope.allowedScope??"education_only",sections:[{heading:"Request blocked",body:g.error.message}],citations:[],disclaimers:["This system refuses to answer without a valid envelope."],riskFlags:[g.error.code],refused:!0,refusalReason:g.error.code};let u={locale:g.value.locale,jurisdiction:g.value.regulatoryContext?.jurisdiction??"UNKNOWN",allowedScope:g.value.allowedScope??"education_only",sections:[{heading:"Answer (demo)",body:`You asked: "${_.question}". This demo answer is derived from the KB snapshot only.`}],citations:[{kbSnapshotId:g.value.kbSnapshotId??"unknown",sourceType:"ruleVersion",sourceId:"rv_demo",title:"Demo rule version",excerpt:"Demo excerpt"}],disclaimers:["Educational demo only."],riskFlags:[]},e=K(g.value.allowedScope,u);if(!e.ok)return{...u,sections:[{heading:"Escalation required",body:e.error.message}],citations:u.citations,refused:!0,refusalReason:e.error.code,riskFlags:[...u.riskFlags??[],e.error.code]};let y=q(u);if(!y.ok)return{...u,sections:[{heading:"Request blocked",body:y.error.message}],citations:[],refused:!0,refusalReason:y.error.code,riskFlags:[...u.riskFlags??[],y.error.code]};return u}async function o(_){return await i({envelope:_.envelope,question:`Explain concept: ${_.conceptKey}`})}return{answer:i,explainConcept:o}}import{OwnersEnum as d,StabilityEnum as w,TagsEnum as b}from"@contractspec/lib.contracts-spec/ownership";import{definePolicy as T}from"@contractspec/lib.contracts-spec/policy";var C=T({meta:{key:"locale-jurisdiction-gate.policy.gate",version:"1.0.0",title:"Assistant Locale and Jurisdiction Gate",description:"Requires explicit locale, jurisdiction, knowledge snapshot, and allowed scope before assistant requests may proceed.",domain:"assistant",scope:"operation",owners:[d.PlatformFinance],tags:[b.I18n,"assistant","policy","jurisdiction"],stability:w.Experimental},rules:[{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!context.locale || !context.jurisdiction || !context.kbSnapshotId || !context.allowedScope"}],reason:"Assistant requests fail closed until locale, jurisdiction, kbSnapshotId, and allowedScope are explicit."},{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '')"}],reason:"Only the explicitly reviewed assistant locales are permitted."},{effect:"allow",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '') && !!context.jurisdiction && !!context.kbSnapshotId && !!context.allowedScope"}],reason:"Explicit context is present, so the request may continue to citation and scope validation."}],pii:{fields:["kbSnapshotId"],retentionDays:30}});import{defineFeature as v}from"@contractspec/lib.contracts-spec";var dr=v({meta:{key:"locale-jurisdiction-gate",version:"1.0.0",title:"Locale + Jurisdiction Gate",description:"Fail-closed gating for assistant calls requiring locale/jurisdiction/snapshot/scope and citations.",domain:"knowledge",owners:["@examples"],tags:["assistant","policy","locale","jurisdiction","knowledge"],stability:"experimental"},operations:[{key:"assistant.answer",version:"1.0.0"},{key:"assistant.explainConcept",version:"1.0.0"}],events:[{key:"assistant.answer.requested",version:"1.0.0"},{key:"assistant.answer.blocked",version:"1.0.0"},{key:"assistant.answer.delivered",version:"1.0.0"}],presentations:[],opToPresentation:[],presentationsTargets:[],capabilities:{requires:[{key:"knowledge",version:"1.0.0"}]},policies:[{key:C.meta.key,version:C.meta.version}],knowledge:[{key:"locale-jurisdiction-gate.knowledge.rules",version:"1.0.0"}],docs:["docs.examples.locale-jurisdiction-gate.goal","docs.examples.locale-jurisdiction-gate.reference"]});import{defineCommand as j}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as k,ScalarTypeEnum as G}from"@contractspec/lib.schema";var n=k({name:"AssistantQuestionInput",description:"Input for assistant calls with mandatory envelope.",fields:{envelope:{type:s,isOptional:!1},question:{type:G.String_unsecure(),isOptional:!1}}}),E=k({name:"AssistantConceptInput",description:"Input for explaining a concept with mandatory envelope.",fields:{envelope:{type:s,isOptional:!1},conceptKey:{type:G.String_unsecure(),isOptional:!1}}}),m=j({meta:{key:"assistant.answer",version:"1.0.0",stability:"experimental",owners:["@examples"],tags:["assistant","policy","locale","jurisdiction","knowledge"],description:"Answer a user question using a KB snapshot with strict locale/jurisdiction gating.",goal:"Provide policy-safe answers that cite a KB snapshot or refuse.",context:"Called by UI or workflows; must fail-closed if envelope is invalid or citations are missing."},io:{input:n,output:R,errors:{LOCALE_REQUIRED:{description:"Locale is required and must be supported",http:400,gqlCode:"LOCALE_REQUIRED",when:"locale is missing or unsupported"},JURISDICTION_REQUIRED:{description:"Jurisdiction is required",http:400,gqlCode:"JURISDICTION_REQUIRED",when:"jurisdiction is missing"},KB_SNAPSHOT_REQUIRED:{description:"KB snapshot id is required",http:400,gqlCode:"KB_SNAPSHOT_REQUIRED",when:"kbSnapshotId is missing"},CITATIONS_REQUIRED:{description:"Answers must include citations to a KB snapshot",http:422,gqlCode:"CITATIONS_REQUIRED",when:"answer has no citations"},SCOPE_VIOLATION:{description:"Answer violates allowed scope and must be refused/escalated",http:403,gqlCode:"SCOPE_VIOLATION",when:"output includes forbidden content under the given allowedScope"}}},policy:{auth:"user"}}),nr=j({meta:{key:"assistant.explainConcept",version:"1.0.0",stability:"experimental",owners:["@examples"],tags:["assistant","policy","knowledge","concepts"],description:"Explain a concept using a KB snapshot with strict locale/jurisdiction gating.",goal:"Explain concepts with citations or refuse.",context:"Same constraints as assistant.answer."},io:{input:E,output:R,errors:m.io.errors},policy:{auth:"user"}});import{OwnersEnum as a,StabilityEnum as c,TagsEnum as rr}from"@contractspec/lib.contracts-spec/ownership";import{defineTranslation as ir}from"@contractspec/lib.contracts-spec/translations/spec";var _i=ir({meta:{key:"locale-jurisdiction-gate.translation.assistant-gate.en-GB",version:"1.0.0",domain:"assistant",description:"British English messages for the assistant locale and jurisdiction gate.",owners:[a.PlatformFinance],stability:c.Experimental,tags:[rr.I18n,"assistant","policy"]},locale:"en-GB",fallback:"en-US",messages:{"assistantGate.locale.label":{value:"Locale"},"assistantGate.locale.description":{value:"Select the reviewed locale for the assistant response."},"assistantGate.jurisdiction.label":{value:"Jurisdiction"},"assistantGate.jurisdiction.placeholder":{value:"UK-FCA"},"assistantGate.kbSnapshotId.label":{value:"Knowledge snapshot ID"},"assistantGate.kbSnapshotId.placeholder":{value:"kb_2026_03_20_policy_reviewed"},"assistantGate.allowedScope.label":{value:"Permitted scope"},"assistantGate.allowedScope.educationOnly":{value:"Educational content only"},"assistantGate.allowedScope.genericInfo":{value:"General information"},"assistantGate.allowedScope.escalationRequired":{value:"Escalation required"},"assistantGate.question.label":{value:"Question"},"assistantGate.question.placeholder":{value:"What may I say about this product in the selected jurisdiction?"},"assistantGate.submit.label":{value:"Generate response"}}});import{OwnersEnum as tr,StabilityEnum as ur,TagsEnum as or}from"@contractspec/lib.contracts-spec/ownership";import{defineTranslation as _r}from"@contractspec/lib.contracts-spec/translations/spec";var fi=_r({meta:{key:"locale-jurisdiction-gate.translation.assistant-gate.en-US",version:"1.0.0",domain:"assistant",description:"US English messages for the assistant locale and jurisdiction gate.",owners:[tr.PlatformFinance],stability:ur.Experimental,tags:[or.I18n,"assistant","policy"]},locale:"en-US",messages:{"assistantGate.locale.label":{value:"Locale"},"assistantGate.locale.description":{value:"Choose the reviewed locale for the assistant answer."},"assistantGate.locale.enUs":{value:"English (United States)"},"assistantGate.locale.enGb":{value:"English (United Kingdom)"},"assistantGate.locale.frFr":{value:"French (France)"},"assistantGate.jurisdiction.label":{value:"Jurisdiction"},"assistantGate.jurisdiction.placeholder":{value:"US-SEC"},"assistantGate.kbSnapshotId.label":{value:"Knowledge snapshot ID"},"assistantGate.kbSnapshotId.placeholder":{value:"kb_2026_03_20_policy_reviewed"},"assistantGate.allowedScope.label":{value:"Allowed scope"},"assistantGate.allowedScope.educationOnly":{value:"Educational content only"},"assistantGate.allowedScope.genericInfo":{value:"Generic information"},"assistantGate.allowedScope.escalationRequired":{value:"Escalation required"},"assistantGate.question.label":{value:"Question"},"assistantGate.question.placeholder":{value:"What can I say about this product in the selected jurisdiction?"},"assistantGate.submit.label":{value:"Generate answer"}}});import{OwnersEnum as gr,StabilityEnum as Or,TagsEnum as xr}from"@contractspec/lib.contracts-spec/ownership";import{defineTranslation as fr}from"@contractspec/lib.contracts-spec/translations/spec";var si=fr({meta:{key:"locale-jurisdiction-gate.translation.assistant-gate.fr-FR",version:"1.0.0",domain:"assistant",description:"French messages for the assistant locale and jurisdiction gate.",owners:[gr.PlatformFinance],stability:Or.Experimental,tags:[xr.I18n,"assistant","policy"]},locale:"fr-FR",fallback:"en-US",messages:{"assistantGate.locale.label":{value:"Langue"},"assistantGate.locale.description":{value:"Sélectionnez la langue validée pour la réponse de l'assistant."},"assistantGate.jurisdiction.label":{value:"Juridiction"},"assistantGate.jurisdiction.placeholder":{value:"FR-AMF"},"assistantGate.kbSnapshotId.label":{value:"Identifiant du snapshot documentaire"},"assistantGate.kbSnapshotId.placeholder":{value:"kb_2026_03_20_policy_reviewed"},"assistantGate.allowedScope.label":{value:"Périmètre autorisé"},"assistantGate.allowedScope.educationOnly":{value:"Contenu éducatif uniquement"},"assistantGate.allowedScope.genericInfo":{value:"Information générale"},"assistantGate.allowedScope.escalationRequired":{value:"Escalade obligatoire"},"assistantGate.question.label":{value:"Question"},"assistantGate.question.placeholder":{value:"Que puis-je dire sur ce produit dans la juridiction sélectionnée ?"},"assistantGate.submit.label":{value:"Générer la réponse"}}});export{Q as validateEnvelope,$ as example,q as enforceCitations,K as enforceAllowedScope,$r as createDemoAssistantHandlers,sr as UserProfileModel,V as RegulatoryContextModel,dr as LocaleJurisdictionGateFeature,s as LLMCallEnvelopeModel,C as AssistantGatePolicy,si as AssistantGateMessagesFrFr,fi as AssistantGateMessagesEnUs,_i as AssistantGateMessagesEnGb,nr as AssistantExplainConceptContract,Ar as AssistantContextForm,z as AssistantCitationModel,A as AssistantAnswerSectionModel,qr as AssistantAnswerRequestedEvent,R as AssistantAnswerIRModel,jr as AssistantAnswerDeliveredEvent,m as AssistantAnswerContract,Kr as AssistantAnswerBlockedEvent,f as AllowedScopeEnum};
|
|
19
|
+
- assistant.answer.delivered`}];V(z);import{defineEnum as A,defineSchemaModel as x,ScalarTypeEnum as r}from"@contractspec/lib.schema";var f=A("AllowedScope",["education_only","generic_info","escalation_required"]),Rr=x({name:"UserProfile",description:"User profile inputs used to derive regulatory context.",fields:{preferredLocale:{type:r.String_unsecure(),isOptional:!0},residencyCountry:{type:r.String_unsecure(),isOptional:!0},taxResidenceCountry:{type:r.String_unsecure(),isOptional:!0},clientType:{type:r.String_unsecure(),isOptional:!0}}}),N=x({name:"RegulatoryContext",description:"Explicit regulatory context (no guessing).",fields:{jurisdiction:{type:r.String_unsecure(),isOptional:!1},region:{type:r.String_unsecure(),isOptional:!0},clientType:{type:r.String_unsecure(),isOptional:!0},allowedScope:{type:f,isOptional:!1}}}),R=x({name:"LLMCallEnvelope",description:"Mandatory envelope for assistant calls. All fields are explicit and required for policy gating.",fields:{traceId:{type:r.String_unsecure(),isOptional:!1},locale:{type:r.String_unsecure(),isOptional:!1},regulatoryContext:{type:N,isOptional:!1},kbSnapshotId:{type:r.String_unsecure(),isOptional:!1},allowedScope:{type:f,isOptional:!1}}}),S=x({name:"AssistantCitation",description:"Citation referencing a KB snapshot + a specific item within it.",fields:{kbSnapshotId:{type:r.String_unsecure(),isOptional:!1},sourceType:{type:r.String_unsecure(),isOptional:!1},sourceId:{type:r.String_unsecure(),isOptional:!1},title:{type:r.String_unsecure(),isOptional:!0},excerpt:{type:r.String_unsecure(),isOptional:!0}}}),W=x({name:"AssistantAnswerSection",description:"Structured answer section.",fields:{heading:{type:r.String_unsecure(),isOptional:!1},body:{type:r.String_unsecure(),isOptional:!1}}}),s=x({name:"AssistantAnswerIR",description:"Structured assistant answer with mandatory citations and explicit locale/jurisdiction.",fields:{locale:{type:r.String_unsecure(),isOptional:!1},jurisdiction:{type:r.String_unsecure(),isOptional:!1},allowedScope:{type:f,isOptional:!1},sections:{type:W,isArray:!0,isOptional:!1},citations:{type:S,isArray:!0,isOptional:!1},disclaimers:{type:r.String_unsecure(),isArray:!0,isOptional:!0},riskFlags:{type:r.String_unsecure(),isArray:!0,isOptional:!0},refused:{type:r.Boolean(),isOptional:!0},refusalReason:{type:r.String_unsecure(),isOptional:!0}}});import{defineEvent as U}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as p,ScalarTypeEnum as t}from"@contractspec/lib.schema";var X=p({name:"AssistantAnswerRequestedPayload",description:"Emitted when an assistant answer is requested (pre-gate).",fields:{traceId:{type:t.String_unsecure(),isOptional:!1},locale:{type:t.String_unsecure(),isOptional:!1},jurisdiction:{type:t.String_unsecure(),isOptional:!1},kbSnapshotId:{type:t.String_unsecure(),isOptional:!1},allowedScope:{type:t.String_unsecure(),isOptional:!1}}}),qr=U({meta:{key:"assistant.answer.requested",version:"1.0.0",description:"Assistant answer requested (policy gate will run).",stability:"experimental",owners:["@examples"],tags:["assistant","policy"]},payload:X}),Z=p({name:"AssistantAnswerBlockedPayload",description:"Emitted when a request is blocked by the gate.",fields:{traceId:{type:t.String_unsecure(),isOptional:!1},reasonCode:{type:t.String_unsecure(),isOptional:!1},reason:{type:t.String_unsecure(),isOptional:!1}}}),Kr=U({meta:{key:"assistant.answer.blocked",version:"1.0.0",description:"Assistant answer blocked (fail-closed).",stability:"experimental",owners:["@examples"],tags:["assistant","policy","blocked"]},payload:Z}),$=p({name:"AssistantAnswerDeliveredPayload",description:"Emitted when a structured, cited answer is delivered.",fields:{traceId:{type:t.String_unsecure(),isOptional:!1},locale:{type:t.String_unsecure(),isOptional:!1},jurisdiction:{type:t.String_unsecure(),isOptional:!1},kbSnapshotId:{type:t.String_unsecure(),isOptional:!1},allowedScope:{type:t.String_unsecure(),isOptional:!1},citationsCount:{type:t.Int_unsecure(),isOptional:!1}}}),jr=U({meta:{key:"assistant.answer.delivered",version:"1.0.0",description:"Assistant answer delivered (must include KB snapshot citations).",stability:"experimental",owners:["@examples"],tags:["assistant","policy","delivered"]},payload:$});import{defineExample as B}from"@contractspec/lib.contracts-spec/examples";var D=B({meta:{key:"examples.locale-jurisdiction-gate",version:"1.0.0",title:"Locale Jurisdiction Gate",description:"Example: enforce locale + jurisdiction + kbSnapshotId + allowed scope for assistant calls (fail-closed).",kind:"template",visibility:"experimental",stability:"experimental",owners:["@contractspec-core"],tags:["package","examples","locale-jurisdiction-gate"]},surfaces:{templates:!0,sandbox:{enabled:!0,modes:["playground","specs"]},studio:{enabled:!1,installable:!1},mcp:{enabled:!1}},entrypoints:{packageName:"@contractspec/example.locale-jurisdiction-gate"}}),G=D;import{defineFormSpec as J}from"@contractspec/lib.contracts-spec/forms";import{OwnersEnum as L,StabilityEnum as Y,TagsEnum as h}from"@contractspec/lib.contracts-spec/ownership";import{defineSchemaModel as M,ScalarTypeEnum as I}from"@contractspec/lib.schema";var F=M({name:"AssistantContextFormModel",description:"Form values required before a policy-gated assistant request can be executed.",fields:{locale:{type:I.String_unsecure(),isOptional:!1},jurisdiction:{type:I.String_unsecure(),isOptional:!1},kbSnapshotId:{type:I.String_unsecure(),isOptional:!1},allowedScope:{type:f,isOptional:!1},question:{type:I.String_unsecure(),isOptional:!1}}}),Wr=J({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:[L.PlatformFinance],tags:[h.I18n,"assistant","form","policy"],stability:Y.Experimental},model:F,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"}});var P=new Set(["en-US","en-GB","fr-FR"]);function O(i,u){return{code:i,message:u}}function Q(i){if(!i.locale||!P.has(i.locale))return{ok:!1,error:O("LOCALE_REQUIRED","locale is required and must be supported")};if(!i.regulatoryContext?.jurisdiction)return{ok:!1,error:O("JURISDICTION_REQUIRED","jurisdiction is required")};if(!i.kbSnapshotId)return{ok:!1,error:O("KB_SNAPSHOT_REQUIRED","kbSnapshotId is required")};if(!i.allowedScope)return{ok:!1,error:O("SCOPE_VIOLATION","allowedScope is required")};return{ok:!0,value:i}}function q(i){let u=i.citations??[];if(!Array.isArray(u)||u.length===0)return{ok:!1,error:O("CITATIONS_REQUIRED","answers must include at least one citation")};return{ok:!0,value:i}}var l=[/\b(buy|sell)\b/i,/\b(should\s+buy|should\s+sell)\b/i,/\b(guarantee(d)?|promise(d)?)\b/i];function K(i,u){if(!i)return{ok:!1,error:O("SCOPE_VIOLATION","allowedScope is required")};if(i!=="education_only")return{ok:!0,value:u};let _=(u.sections??[]).map((o)=>o.body).join(`
|
|
20
|
+
`);if(l.some((o)=>o.test(_)))return{ok:!1,error:O("SCOPE_VIOLATION","answer violates education_only scope (contains actionable or promotional language)")};return{ok:!0,value:u}}function Gr(){async function i(_){let g=Q(_.envelope);if(!g.ok)return{locale:_.envelope.locale??"en-US",jurisdiction:_.envelope.regulatoryContext?.jurisdiction??"UNKNOWN",allowedScope:_.envelope.allowedScope??"education_only",sections:[{heading:"Request blocked",body:g.error.message}],citations:[],disclaimers:["This system refuses to answer without a valid envelope."],riskFlags:[g.error.code],refused:!0,refusalReason:g.error.code};let o={locale:g.value.locale,jurisdiction:g.value.regulatoryContext?.jurisdiction??"UNKNOWN",allowedScope:g.value.allowedScope??"education_only",sections:[{heading:"Answer (demo)",body:`You asked: "${_.question}". This demo answer is derived from the KB snapshot only.`}],citations:[{kbSnapshotId:g.value.kbSnapshotId??"unknown",sourceType:"ruleVersion",sourceId:"rv_demo",title:"Demo rule version",excerpt:"Demo excerpt"}],disclaimers:["Educational demo only."],riskFlags:[]},y=K(g.value.allowedScope,o);if(!y.ok)return{...o,sections:[{heading:"Escalation required",body:y.error.message}],citations:o.citations,refused:!0,refusalReason:y.error.code,riskFlags:[...o.riskFlags??[],y.error.code]};let e=q(o);if(!e.ok)return{...o,sections:[{heading:"Request blocked",body:e.error.message}],citations:[],refused:!0,refusalReason:e.error.code,riskFlags:[...o.riskFlags??[],e.error.code]};return o}async function u(_){return await i({envelope:_.envelope,question:`Explain concept: ${_.conceptKey}`})}return{answer:i,explainConcept:u}}import{OwnersEnum as d,StabilityEnum as w,TagsEnum as b}from"@contractspec/lib.contracts-spec/ownership";import{definePolicy as T}from"@contractspec/lib.contracts-spec/policy";var C=T({meta:{key:"locale-jurisdiction-gate.policy.gate",version:"1.0.0",title:"Assistant Locale and Jurisdiction Gate",description:"Requires explicit locale, jurisdiction, knowledge snapshot, and allowed scope before assistant requests may proceed.",domain:"assistant",scope:"operation",owners:[d.PlatformFinance],tags:[b.I18n,"assistant","policy","jurisdiction"],stability:w.Experimental},rules:[{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!context.locale || !context.jurisdiction || !context.kbSnapshotId || !context.allowedScope"}],reason:"Assistant requests fail closed until locale, jurisdiction, kbSnapshotId, and allowedScope are explicit."},{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '')"}],reason:"Only the explicitly reviewed assistant locales are permitted."},{effect:"allow",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '') && !!context.jurisdiction && !!context.kbSnapshotId && !!context.allowedScope"}],reason:"Explicit context is present, so the request may continue to citation and scope validation."}],pii:{fields:["kbSnapshotId"],retentionDays:30}});import{defineFeature as v}from"@contractspec/lib.contracts-spec/features";var dr=v({meta:{key:"locale-jurisdiction-gate",version:"1.0.0",title:"Locale + Jurisdiction Gate",description:"Fail-closed gating for assistant calls requiring locale/jurisdiction/snapshot/scope and citations.",domain:"knowledge",owners:["@examples"],tags:["assistant","policy","locale","jurisdiction","knowledge"],stability:"experimental"},operations:[{key:"assistant.answer",version:"1.0.0"},{key:"assistant.explainConcept",version:"1.0.0"}],events:[{key:"assistant.answer.requested",version:"1.0.0"},{key:"assistant.answer.blocked",version:"1.0.0"},{key:"assistant.answer.delivered",version:"1.0.0"}],presentations:[],opToPresentation:[],presentationsTargets:[],capabilities:{requires:[{key:"knowledge",version:"1.0.0"}]},policies:[{key:C.meta.key,version:C.meta.version}],knowledge:[{key:"locale-jurisdiction-gate.knowledge.rules",version:"1.0.0"}],docs:["docs.examples.locale-jurisdiction-gate.goal","docs.examples.locale-jurisdiction-gate.reference"]});import{defineCommand as j}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as k,ScalarTypeEnum as H}from"@contractspec/lib.schema";var n=k({name:"AssistantQuestionInput",description:"Input for assistant calls with mandatory envelope.",fields:{envelope:{type:R,isOptional:!1},question:{type:H.String_unsecure(),isOptional:!1}}}),E=k({name:"AssistantConceptInput",description:"Input for explaining a concept with mandatory envelope.",fields:{envelope:{type:R,isOptional:!1},conceptKey:{type:H.String_unsecure(),isOptional:!1}}}),m=j({meta:{key:"assistant.answer",version:"1.0.0",stability:"experimental",owners:["@examples"],tags:["assistant","policy","locale","jurisdiction","knowledge"],description:"Answer a user question using a KB snapshot with strict locale/jurisdiction gating.",goal:"Provide policy-safe answers that cite a KB snapshot or refuse.",context:"Called by UI or workflows; must fail-closed if envelope is invalid or citations are missing."},io:{input:n,output:s,errors:{LOCALE_REQUIRED:{description:"Locale is required and must be supported",http:400,gqlCode:"LOCALE_REQUIRED",when:"locale is missing or unsupported"},JURISDICTION_REQUIRED:{description:"Jurisdiction is required",http:400,gqlCode:"JURISDICTION_REQUIRED",when:"jurisdiction is missing"},KB_SNAPSHOT_REQUIRED:{description:"KB snapshot id is required",http:400,gqlCode:"KB_SNAPSHOT_REQUIRED",when:"kbSnapshotId is missing"},CITATIONS_REQUIRED:{description:"Answers must include citations to a KB snapshot",http:422,gqlCode:"CITATIONS_REQUIRED",when:"answer has no citations"},SCOPE_VIOLATION:{description:"Answer violates allowed scope and must be refused/escalated",http:403,gqlCode:"SCOPE_VIOLATION",when:"output includes forbidden content under the given allowedScope"}}},policy:{auth:"user"}}),nr=j({meta:{key:"assistant.explainConcept",version:"1.0.0",stability:"experimental",owners:["@examples"],tags:["assistant","policy","knowledge","concepts"],description:"Explain a concept using a KB snapshot with strict locale/jurisdiction gating.",goal:"Explain concepts with citations or refuse.",context:"Same constraints as assistant.answer."},io:{input:E,output:s,errors:m.io.errors},policy:{auth:"user"}});import{OwnersEnum as a,StabilityEnum as c,TagsEnum as rr}from"@contractspec/lib.contracts-spec/ownership";import{defineTranslation as ir}from"@contractspec/lib.contracts-spec/translations/spec";var _i=ir({meta:{key:"locale-jurisdiction-gate.translation.assistant-gate.en-GB",version:"1.0.0",domain:"assistant",description:"British English messages for the assistant locale and jurisdiction gate.",owners:[a.PlatformFinance],stability:c.Experimental,tags:[rr.I18n,"assistant","policy"]},locale:"en-GB",fallback:"en-US",messages:{"assistantGate.locale.label":{value:"Locale"},"assistantGate.locale.description":{value:"Select the reviewed locale for the assistant response."},"assistantGate.jurisdiction.label":{value:"Jurisdiction"},"assistantGate.jurisdiction.placeholder":{value:"UK-FCA"},"assistantGate.kbSnapshotId.label":{value:"Knowledge snapshot ID"},"assistantGate.kbSnapshotId.placeholder":{value:"kb_2026_03_20_policy_reviewed"},"assistantGate.allowedScope.label":{value:"Permitted scope"},"assistantGate.allowedScope.educationOnly":{value:"Educational content only"},"assistantGate.allowedScope.genericInfo":{value:"General information"},"assistantGate.allowedScope.escalationRequired":{value:"Escalation required"},"assistantGate.question.label":{value:"Question"},"assistantGate.question.placeholder":{value:"What may I say about this product in the selected jurisdiction?"},"assistantGate.submit.label":{value:"Generate response"}}});import{OwnersEnum as tr,StabilityEnum as or,TagsEnum as ur}from"@contractspec/lib.contracts-spec/ownership";import{defineTranslation as _r}from"@contractspec/lib.contracts-spec/translations/spec";var fi=_r({meta:{key:"locale-jurisdiction-gate.translation.assistant-gate.en-US",version:"1.0.0",domain:"assistant",description:"US English messages for the assistant locale and jurisdiction gate.",owners:[tr.PlatformFinance],stability:or.Experimental,tags:[ur.I18n,"assistant","policy"]},locale:"en-US",messages:{"assistantGate.locale.label":{value:"Locale"},"assistantGate.locale.description":{value:"Choose the reviewed locale for the assistant answer."},"assistantGate.locale.enUs":{value:"English (United States)"},"assistantGate.locale.enGb":{value:"English (United Kingdom)"},"assistantGate.locale.frFr":{value:"French (France)"},"assistantGate.jurisdiction.label":{value:"Jurisdiction"},"assistantGate.jurisdiction.placeholder":{value:"US-SEC"},"assistantGate.kbSnapshotId.label":{value:"Knowledge snapshot ID"},"assistantGate.kbSnapshotId.placeholder":{value:"kb_2026_03_20_policy_reviewed"},"assistantGate.allowedScope.label":{value:"Allowed scope"},"assistantGate.allowedScope.educationOnly":{value:"Educational content only"},"assistantGate.allowedScope.genericInfo":{value:"Generic information"},"assistantGate.allowedScope.escalationRequired":{value:"Escalation required"},"assistantGate.question.label":{value:"Question"},"assistantGate.question.placeholder":{value:"What can I say about this product in the selected jurisdiction?"},"assistantGate.submit.label":{value:"Generate answer"}}});import{OwnersEnum as gr,StabilityEnum as Or,TagsEnum as xr}from"@contractspec/lib.contracts-spec/ownership";import{defineTranslation as fr}from"@contractspec/lib.contracts-spec/translations/spec";var Ri=fr({meta:{key:"locale-jurisdiction-gate.translation.assistant-gate.fr-FR",version:"1.0.0",domain:"assistant",description:"French messages for the assistant locale and jurisdiction gate.",owners:[gr.PlatformFinance],stability:Or.Experimental,tags:[xr.I18n,"assistant","policy"]},locale:"fr-FR",fallback:"en-US",messages:{"assistantGate.locale.label":{value:"Langue"},"assistantGate.locale.description":{value:"Sélectionnez la langue validée pour la réponse de l'assistant."},"assistantGate.jurisdiction.label":{value:"Juridiction"},"assistantGate.jurisdiction.placeholder":{value:"FR-AMF"},"assistantGate.kbSnapshotId.label":{value:"Identifiant du snapshot documentaire"},"assistantGate.kbSnapshotId.placeholder":{value:"kb_2026_03_20_policy_reviewed"},"assistantGate.allowedScope.label":{value:"Périmètre autorisé"},"assistantGate.allowedScope.educationOnly":{value:"Contenu éducatif uniquement"},"assistantGate.allowedScope.genericInfo":{value:"Information générale"},"assistantGate.allowedScope.escalationRequired":{value:"Escalade obligatoire"},"assistantGate.question.label":{value:"Question"},"assistantGate.question.placeholder":{value:"Que puis-je dire sur ce produit dans la juridiction sélectionnée ?"},"assistantGate.submit.label":{value:"Générer la réponse"}}});export{Q as validateEnvelope,G as example,q as enforceCitations,K as enforceAllowedScope,Gr as createDemoAssistantHandlers,Rr as UserProfileModel,N as RegulatoryContextModel,dr as LocaleJurisdictionGateFeature,R as LLMCallEnvelopeModel,D as ExamplesLocaleJurisdictionGateExample,C as AssistantGatePolicy,Ri as AssistantGateMessagesFrFr,fi as AssistantGateMessagesEnUs,_i as AssistantGateMessagesEnGb,nr as AssistantExplainConceptContract,Wr as AssistantContextForm,S as AssistantCitationModel,W as AssistantAnswerSectionModel,qr as AssistantAnswerRequestedEvent,s as AssistantAnswerIRModel,jr as AssistantAnswerDeliveredEvent,m as AssistantAnswerContract,Kr as AssistantAnswerBlockedEvent,f as AllowedScopeEnum};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{OwnersEnum as j,StabilityEnum as k,TagsEnum as q}from"@contractspec/lib.contracts-spec/ownership";import{definePolicy as v}from"@contractspec/lib.contracts-spec/policy";var h=v({meta:{key:"locale-jurisdiction-gate.policy.gate",version:"1.0.0",title:"Assistant Locale and Jurisdiction Gate",description:"Requires explicit locale, jurisdiction, knowledge snapshot, and allowed scope before assistant requests may proceed.",domain:"assistant",scope:"operation",owners:[j.PlatformFinance],tags:[q.I18n,"assistant","policy","jurisdiction"],stability:k.Experimental},rules:[{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!context.locale || !context.jurisdiction || !context.kbSnapshotId || !context.allowedScope"}],reason:"Assistant requests fail closed until locale, jurisdiction, kbSnapshotId, and allowedScope are explicit."},{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '')"}],reason:"Only the explicitly reviewed assistant locales are permitted."},{effect:"allow",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '') && !!context.jurisdiction && !!context.kbSnapshotId && !!context.allowedScope"}],reason:"Explicit context is present, so the request may continue to citation and scope validation."}],pii:{fields:["kbSnapshotId"],retentionDays:30}});import{defineFeature as x}from"@contractspec/lib.contracts-spec";var I=x({meta:{key:"locale-jurisdiction-gate",version:"1.0.0",title:"Locale + Jurisdiction Gate",description:"Fail-closed gating for assistant calls requiring locale/jurisdiction/snapshot/scope and citations.",domain:"knowledge",owners:["@examples"],tags:["assistant","policy","locale","jurisdiction","knowledge"],stability:"experimental"},operations:[{key:"assistant.answer",version:"1.0.0"},{key:"assistant.explainConcept",version:"1.0.0"}],events:[{key:"assistant.answer.requested",version:"1.0.0"},{key:"assistant.answer.blocked",version:"1.0.0"},{key:"assistant.answer.delivered",version:"1.0.0"}],presentations:[],opToPresentation:[],presentationsTargets:[],capabilities:{requires:[{key:"knowledge",version:"1.0.0"}]},policies:[{key:h.meta.key,version:h.meta.version}],knowledge:[{key:"locale-jurisdiction-gate.knowledge.rules",version:"1.0.0"}],docs:["docs.examples.locale-jurisdiction-gate.goal","docs.examples.locale-jurisdiction-gate.reference"]});export{I as LocaleJurisdictionGateFeature};
|
|
1
|
+
import{OwnersEnum as j,StabilityEnum as k,TagsEnum as q}from"@contractspec/lib.contracts-spec/ownership";import{definePolicy as v}from"@contractspec/lib.contracts-spec/policy";var h=v({meta:{key:"locale-jurisdiction-gate.policy.gate",version:"1.0.0",title:"Assistant Locale and Jurisdiction Gate",description:"Requires explicit locale, jurisdiction, knowledge snapshot, and allowed scope before assistant requests may proceed.",domain:"assistant",scope:"operation",owners:[j.PlatformFinance],tags:[q.I18n,"assistant","policy","jurisdiction"],stability:k.Experimental},rules:[{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!context.locale || !context.jurisdiction || !context.kbSnapshotId || !context.allowedScope"}],reason:"Assistant requests fail closed until locale, jurisdiction, kbSnapshotId, and allowedScope are explicit."},{effect:"deny",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"!['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '')"}],reason:"Only the explicitly reviewed assistant locales are permitted."},{effect:"allow",actions:["assistant.answer","assistant.explainConcept"],resource:{type:"assistant-call"},conditions:[{expression:"['en-US', 'en-GB', 'fr-FR'].includes(context.locale ?? '') && !!context.jurisdiction && !!context.kbSnapshotId && !!context.allowedScope"}],reason:"Explicit context is present, so the request may continue to citation and scope validation."}],pii:{fields:["kbSnapshotId"],retentionDays:30}});import{defineFeature as x}from"@contractspec/lib.contracts-spec/features";var I=x({meta:{key:"locale-jurisdiction-gate",version:"1.0.0",title:"Locale + Jurisdiction Gate",description:"Fail-closed gating for assistant calls requiring locale/jurisdiction/snapshot/scope and citations.",domain:"knowledge",owners:["@examples"],tags:["assistant","policy","locale","jurisdiction","knowledge"],stability:"experimental"},operations:[{key:"assistant.answer",version:"1.0.0"},{key:"assistant.explainConcept",version:"1.0.0"}],events:[{key:"assistant.answer.requested",version:"1.0.0"},{key:"assistant.answer.blocked",version:"1.0.0"},{key:"assistant.answer.delivered",version:"1.0.0"}],presentations:[],opToPresentation:[],presentationsTargets:[],capabilities:{requires:[{key:"knowledge",version:"1.0.0"}]},policies:[{key:h.meta.key,version:h.meta.version}],knowledge:[{key:"locale-jurisdiction-gate.knowledge.rules",version:"1.0.0"}],docs:["docs.examples.locale-jurisdiction-gate.goal","docs.examples.locale-jurisdiction-gate.reference"]});export{I as LocaleJurisdictionGateFeature};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contractspec/example.locale-jurisdiction-gate",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.22",
|
|
4
4
|
"description": "Example: enforce locale + jurisdiction + kbSnapshotId + allowed scope for assistant calls (fail-closed).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -176,13 +176,13 @@
|
|
|
176
176
|
"typecheck": "tsc --noEmit"
|
|
177
177
|
},
|
|
178
178
|
"dependencies": {
|
|
179
|
-
"@contractspec/lib.contracts-spec": "5.
|
|
179
|
+
"@contractspec/lib.contracts-spec": "5.5.1",
|
|
180
180
|
"@contractspec/lib.schema": "3.7.14"
|
|
181
181
|
},
|
|
182
182
|
"devDependencies": {
|
|
183
183
|
"@contractspec/tool.typescript": "3.7.13",
|
|
184
184
|
"typescript": "^5.9.3",
|
|
185
|
-
"@contractspec/tool.bun": "3.7.
|
|
185
|
+
"@contractspec/tool.bun": "3.7.17"
|
|
186
186
|
},
|
|
187
187
|
"publishConfig": {
|
|
188
188
|
"access": "public",
|
package/src/example.ts
CHANGED
|
@@ -1,34 +1,28 @@
|
|
|
1
|
-
import { defineExample } from '@contractspec/lib.contracts-spec';
|
|
1
|
+
import { defineExample } from '@contractspec/lib.contracts-spec/examples';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const ExamplesLocaleJurisdictionGateExample = defineExample({
|
|
4
4
|
meta: {
|
|
5
|
-
key: 'locale-jurisdiction-gate',
|
|
5
|
+
key: 'examples.locale-jurisdiction-gate',
|
|
6
6
|
version: '1.0.0',
|
|
7
|
-
title: 'Locale
|
|
7
|
+
title: 'Locale Jurisdiction Gate',
|
|
8
8
|
description:
|
|
9
|
-
'
|
|
10
|
-
kind: '
|
|
11
|
-
visibility: '
|
|
9
|
+
'Example: enforce locale + jurisdiction + kbSnapshotId + allowed scope for assistant calls (fail-closed).',
|
|
10
|
+
kind: 'template',
|
|
11
|
+
visibility: 'experimental',
|
|
12
12
|
stability: 'experimental',
|
|
13
|
-
owners: ['@
|
|
14
|
-
tags: ['
|
|
13
|
+
owners: ['@contractspec-core'],
|
|
14
|
+
tags: ['package', 'examples', 'locale-jurisdiction-gate'],
|
|
15
15
|
},
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
surfaces: {
|
|
17
|
+
templates: true,
|
|
18
|
+
sandbox: { enabled: true, modes: ['playground', 'specs'] },
|
|
19
|
+
studio: { enabled: false, installable: false },
|
|
20
|
+
mcp: { enabled: false },
|
|
18
21
|
},
|
|
19
22
|
entrypoints: {
|
|
20
23
|
packageName: '@contractspec/example.locale-jurisdiction-gate',
|
|
21
|
-
feature: './feature',
|
|
22
|
-
contracts: './contracts',
|
|
23
|
-
handlers: './handlers',
|
|
24
|
-
docs: './docs',
|
|
25
|
-
},
|
|
26
|
-
surfaces: {
|
|
27
|
-
templates: true,
|
|
28
|
-
sandbox: { enabled: true, modes: ['markdown', 'specs'] },
|
|
29
|
-
studio: { enabled: true, installable: true },
|
|
30
|
-
mcp: { enabled: true },
|
|
31
24
|
},
|
|
32
25
|
});
|
|
33
26
|
|
|
34
|
-
export default
|
|
27
|
+
export default ExamplesLocaleJurisdictionGateExample;
|
|
28
|
+
export { ExamplesLocaleJurisdictionGateExample };
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineFeature } from '@contractspec/lib.contracts-spec';
|
|
1
|
+
import { defineFeature } from '@contractspec/lib.contracts-spec/features';
|
|
2
2
|
import { AssistantGatePolicy } from './policy/assistant-gate.policy';
|
|
3
3
|
|
|
4
4
|
export const LocaleJurisdictionGateFeature = defineFeature({
|