@lssm/example.locale-jurisdiction-gate 0.0.0-canary-20251217083314 → 1.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +26 -43
- package/dist/contracts/assistant.js +1 -117
- package/dist/contracts/index.js +1 -3
- package/dist/docs/index.js +1 -1
- package/dist/docs/locale-jurisdiction-gate.docblock.js +3 -37
- package/dist/entities/index.js +1 -3
- package/dist/entities/models.js +1 -170
- package/dist/events.js +1 -102
- package/dist/example.js +1 -39
- package/dist/handlers/demo.handlers.js +1 -85
- package/dist/handlers/index.js +1 -3
- package/dist/index.js +1 -12
- package/dist/locale-jurisdiction-gate.feature.js +1 -49
- package/dist/policy/guard.js +2 -72
- package/dist/policy/index.js +1 -3
- package/package.json +20 -22
- package/tsconfig.tsbuildinfo +1 -1
- package/.turbo/turbo-build$colon$bundle.log +0 -232
- package/CHANGELOG.md +0 -13
- package/dist/contracts/assistant.d.ts +0 -244
- package/dist/contracts/index.d.ts +0 -2
- package/dist/docs/index.d.ts +0 -1
- package/dist/docs/locale-jurisdiction-gate.docblock.d.ts +0 -1
- package/dist/entities/index.d.ts +0 -2
- package/dist/entities/models.d.ts +0 -185
- package/dist/events.d.ts +0 -68
- package/dist/example.d.ts +0 -35
- package/dist/handlers/demo.handlers.d.ts +0 -58
- package/dist/handlers/index.d.ts +0 -2
- package/dist/index.d.ts +0 -9
- package/dist/libs/contracts/dist/capabilities/openbanking.js +0 -88
- package/dist/libs/contracts/dist/client/index.js +0 -5
- package/dist/libs/contracts/dist/client/react/feature-render.js +0 -2
- package/dist/libs/contracts/dist/client/react/form-render.js +0 -4
- package/dist/libs/contracts/dist/client/react/index.js +0 -4
- package/dist/libs/contracts/dist/contract-registry/index.js +0 -1
- package/dist/libs/contracts/dist/contract-registry/schemas.js +0 -60
- package/dist/libs/contracts/dist/docs/PUBLISHING.docblock.js +0 -16
- package/dist/libs/contracts/dist/docs/accessibility_wcag_compliance_specs.docblock.js +0 -16
- package/dist/libs/contracts/dist/docs/index.js +0 -29
- package/dist/libs/contracts/dist/docs/presentations.js +0 -71
- package/dist/libs/contracts/dist/docs/registry.js +0 -44
- package/dist/libs/contracts/dist/docs/tech/PHASE_1_QUICKSTART.docblock.js +0 -16
- package/dist/libs/contracts/dist/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +0 -16
- package/dist/libs/contracts/dist/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +0 -16
- package/dist/libs/contracts/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +0 -16
- package/dist/libs/contracts/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +0 -16
- package/dist/libs/contracts/dist/docs/tech/auth/better-auth-nextjs.docblock.js +0 -80
- package/dist/libs/contracts/dist/docs/tech/contracts/openapi-export.docblock.js +0 -57
- package/dist/libs/contracts/dist/docs/tech/lifecycle-stage-system.docblock.js +0 -16
- package/dist/libs/contracts/dist/docs/tech/llm/llm-integration.docblock.js +0 -357
- package/dist/libs/contracts/dist/docs/tech/mcp-endpoints.docblock.js +0 -37
- package/dist/libs/contracts/dist/docs/tech/presentation-runtime.docblock.js +0 -16
- package/dist/libs/contracts/dist/docs/tech/schema/README.docblock.js +0 -20
- package/dist/libs/contracts/dist/docs/tech/studio/learning-events.docblock.js +0 -48
- package/dist/libs/contracts/dist/docs/tech/studio/learning-journeys.docblock.js +0 -79
- package/dist/libs/contracts/dist/docs/tech/studio/platform-admin-panel.docblock.js +0 -84
- package/dist/libs/contracts/dist/docs/tech/studio/project-access-teams.docblock.js +0 -45
- package/dist/libs/contracts/dist/docs/tech/studio/project-routing.docblock.js +0 -67
- package/dist/libs/contracts/dist/docs/tech/studio/sandbox-unlogged.docblock.js +0 -40
- package/dist/libs/contracts/dist/docs/tech/studio/team-invitations.docblock.js +0 -69
- package/dist/libs/contracts/dist/docs/tech/studio/workspace-ops.docblock.js +0 -47
- package/dist/libs/contracts/dist/docs/tech/studio/workspaces.docblock.js +0 -62
- package/dist/libs/contracts/dist/docs/tech/telemetry-ingest.docblock.js +0 -155
- package/dist/libs/contracts/dist/docs/tech/templates/runtime.docblock.js +0 -20
- package/dist/libs/contracts/dist/docs/tech/vscode-extension.docblock.js +0 -101
- package/dist/libs/contracts/dist/docs/tech/workflows/overview.docblock.js +0 -20
- package/dist/libs/contracts/dist/events.js +0 -10
- package/dist/libs/contracts/dist/experiments/evaluator.js +0 -1
- package/dist/libs/contracts/dist/index.js +0 -71
- package/dist/libs/contracts/dist/install.js +0 -2
- package/dist/libs/contracts/dist/integrations/contracts.js +0 -377
- package/dist/libs/contracts/dist/integrations/index.js +0 -18
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/accounts.js +0 -228
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/balances.js +0 -159
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/index.js +0 -3
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/transactions.js +0 -210
- package/dist/libs/contracts/dist/integrations/openbanking/models.js +0 -242
- package/dist/libs/contracts/dist/integrations/openbanking/telemetry.js +0 -13
- package/dist/libs/contracts/dist/integrations/providers/elevenlabs.js +0 -52
- package/dist/libs/contracts/dist/integrations/providers/gcs-storage.js +0 -75
- package/dist/libs/contracts/dist/integrations/providers/gmail.js +0 -87
- package/dist/libs/contracts/dist/integrations/providers/google-calendar.js +0 -66
- package/dist/libs/contracts/dist/integrations/providers/index.js +0 -11
- package/dist/libs/contracts/dist/integrations/providers/mistral.js +0 -68
- package/dist/libs/contracts/dist/integrations/providers/postmark.js +0 -68
- package/dist/libs/contracts/dist/integrations/providers/powens.js +0 -116
- package/dist/libs/contracts/dist/integrations/providers/qdrant.js +0 -73
- package/dist/libs/contracts/dist/integrations/providers/registry.js +0 -10
- package/dist/libs/contracts/dist/integrations/providers/stripe.js +0 -83
- package/dist/libs/contracts/dist/integrations/providers/twilio-sms.js +0 -61
- package/dist/libs/contracts/dist/jsonschema.js +0 -1
- package/dist/libs/contracts/dist/knowledge/contracts.js +0 -306
- package/dist/libs/contracts/dist/knowledge/index.js +0 -7
- package/dist/libs/contracts/dist/knowledge/spaces/email-threads.js +0 -34
- package/dist/libs/contracts/dist/knowledge/spaces/financial-docs.js +0 -34
- package/dist/libs/contracts/dist/knowledge/spaces/financial-overview.js +0 -38
- package/dist/libs/contracts/dist/knowledge/spaces/index.js +0 -6
- package/dist/libs/contracts/dist/knowledge/spaces/product-canon.js +0 -34
- package/dist/libs/contracts/dist/knowledge/spaces/support-faq.js +0 -37
- package/dist/libs/contracts/dist/knowledge/spaces/uploaded-docs.js +0 -34
- package/dist/libs/contracts/dist/llm/exporters.js +0 -19
- package/dist/libs/contracts/dist/llm/index.js +0 -2
- package/dist/libs/contracts/dist/llm/prompts.js +0 -1
- package/dist/libs/contracts/dist/onboarding-base.js +0 -196
- package/dist/libs/contracts/dist/openapi.js +0 -1
- package/dist/libs/contracts/dist/ownership.js +0 -21
- package/dist/libs/contracts/dist/presentations.js +0 -1
- package/dist/libs/contracts/dist/presentations.v2.js +0 -11
- package/dist/libs/contracts/dist/prompt.js +0 -1
- package/dist/libs/contracts/dist/promptRegistry.js +0 -1
- package/dist/libs/contracts/dist/regenerator/index.js +0 -1
- package/dist/libs/contracts/dist/regenerator/service.js +0 -6
- package/dist/libs/contracts/dist/registry.js +0 -2
- package/dist/libs/contracts/dist/resources.js +0 -1
- package/dist/libs/contracts/dist/schema/dist/EnumType.js +0 -2
- package/dist/libs/contracts/dist/schema/dist/FieldType.js +0 -49
- package/dist/libs/contracts/dist/schema/dist/ScalarTypeEnum.js +0 -236
- package/dist/libs/contracts/dist/schema/dist/SchemaModel.js +0 -39
- package/dist/libs/contracts/dist/schema/dist/entity/defineEntity.js +0 -1
- package/dist/libs/contracts/dist/schema/dist/entity/index.js +0 -2
- package/dist/libs/contracts/dist/schema/dist/entity/types.js +0 -1
- package/dist/libs/contracts/dist/schema/dist/index.js +0 -6
- package/dist/libs/contracts/dist/server/graphql-pothos.js +0 -6
- package/dist/libs/contracts/dist/server/index.js +0 -8
- package/dist/libs/contracts/dist/server/mcp/createMcpServer.js +0 -4
- package/dist/libs/contracts/dist/server/mcp/registerPresentations.js +0 -2
- package/dist/libs/contracts/dist/server/mcp/registerPrompts.js +0 -1
- package/dist/libs/contracts/dist/server/mcp/registerResources.js +0 -2
- package/dist/libs/contracts/dist/server/mcp/registerTools.js +0 -1
- package/dist/libs/contracts/dist/server/provider-mcp.js +0 -1
- package/dist/libs/contracts/dist/server/rest-elysia.js +0 -1
- package/dist/libs/contracts/dist/server/rest-express.js +0 -1
- package/dist/libs/contracts/dist/server/rest-generic.js +0 -1
- package/dist/libs/contracts/dist/server/rest-next-app.js +0 -1
- package/dist/libs/contracts/dist/server/rest-next-pages.js +0 -1
- package/dist/libs/contracts/dist/spec.js +0 -34
- package/dist/libs/contracts/dist/telemetry/index.js +0 -1
- package/dist/libs/contracts/dist/telemetry/tracker.js +0 -1
- package/dist/libs/contracts/dist/tests/index.js +0 -1
- package/dist/libs/contracts/dist/tests/runner.js +0 -2
- package/dist/libs/contracts/dist/workflow/index.js +0 -1
- package/dist/libs/contracts/dist/workflow/runner.js +0 -1
- package/dist/libs/schema/dist/EnumType.js +0 -56
- package/dist/libs/schema/dist/FieldType.js +0 -49
- package/dist/libs/schema/dist/ScalarTypeEnum.js +0 -236
- package/dist/libs/schema/dist/SchemaModel.js +0 -39
- package/dist/libs/schema/dist/entity/defineEntity.js +0 -1
- package/dist/libs/schema/dist/entity/index.js +0 -2
- package/dist/libs/schema/dist/entity/types.js +0 -1
- package/dist/libs/schema/dist/index.js +0 -6
- package/dist/locale-jurisdiction-gate.feature.d.ts +0 -6
- package/dist/policy/guard.d.ts +0 -26
- package/dist/policy/index.d.ts +0 -3
- package/dist/policy/types.d.ts +0 -15
|
@@ -1,85 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/handlers/demo.handlers.ts
|
|
4
|
-
/**
|
|
5
|
-
* Deterministic demo assistant handlers (no LLM).
|
|
6
|
-
*
|
|
7
|
-
* - Validates envelope
|
|
8
|
-
* - Requires citations
|
|
9
|
-
* - Enforces allowedScope (education_only blocks actionable language)
|
|
10
|
-
*/
|
|
11
|
-
function createDemoAssistantHandlers() {
|
|
12
|
-
async function answer(input) {
|
|
13
|
-
const env = validateEnvelope(input.envelope);
|
|
14
|
-
if (!env.ok) return {
|
|
15
|
-
locale: input.envelope.locale ?? "en-US",
|
|
16
|
-
jurisdiction: input.envelope.regulatoryContext?.jurisdiction ?? "UNKNOWN",
|
|
17
|
-
allowedScope: input.envelope.allowedScope ?? "education_only",
|
|
18
|
-
sections: [{
|
|
19
|
-
heading: "Request blocked",
|
|
20
|
-
body: env.error.message
|
|
21
|
-
}],
|
|
22
|
-
citations: [],
|
|
23
|
-
disclaimers: ["This system refuses to answer without a valid envelope."],
|
|
24
|
-
riskFlags: [env.error.code],
|
|
25
|
-
refused: true,
|
|
26
|
-
refusalReason: env.error.code
|
|
27
|
-
};
|
|
28
|
-
const draft = {
|
|
29
|
-
locale: env.value.locale,
|
|
30
|
-
jurisdiction: env.value.regulatoryContext.jurisdiction,
|
|
31
|
-
allowedScope: env.value.allowedScope,
|
|
32
|
-
sections: [{
|
|
33
|
-
heading: "Answer (demo)",
|
|
34
|
-
body: `You asked: "${input.question}". This demo answer is derived from the KB snapshot only.`
|
|
35
|
-
}],
|
|
36
|
-
citations: [{
|
|
37
|
-
kbSnapshotId: env.value.kbSnapshotId,
|
|
38
|
-
sourceType: "ruleVersion",
|
|
39
|
-
sourceId: "rv_demo",
|
|
40
|
-
title: "Demo rule version",
|
|
41
|
-
excerpt: "Demo excerpt"
|
|
42
|
-
}],
|
|
43
|
-
disclaimers: ["Educational demo only."],
|
|
44
|
-
riskFlags: []
|
|
45
|
-
};
|
|
46
|
-
const scope = enforceAllowedScope(env.value.allowedScope, draft);
|
|
47
|
-
if (!scope.ok) return {
|
|
48
|
-
...draft,
|
|
49
|
-
sections: [{
|
|
50
|
-
heading: "Escalation required",
|
|
51
|
-
body: scope.error.message
|
|
52
|
-
}],
|
|
53
|
-
citations: draft.citations,
|
|
54
|
-
refused: true,
|
|
55
|
-
refusalReason: scope.error.code,
|
|
56
|
-
riskFlags: [...draft.riskFlags ?? [], scope.error.code]
|
|
57
|
-
};
|
|
58
|
-
const cited = enforceCitations(draft);
|
|
59
|
-
if (!cited.ok) return {
|
|
60
|
-
...draft,
|
|
61
|
-
sections: [{
|
|
62
|
-
heading: "Request blocked",
|
|
63
|
-
body: cited.error.message
|
|
64
|
-
}],
|
|
65
|
-
citations: [],
|
|
66
|
-
refused: true,
|
|
67
|
-
refusalReason: cited.error.code,
|
|
68
|
-
riskFlags: [...draft.riskFlags ?? [], cited.error.code]
|
|
69
|
-
};
|
|
70
|
-
return draft;
|
|
71
|
-
}
|
|
72
|
-
async function explainConcept(input) {
|
|
73
|
-
return await answer({
|
|
74
|
-
envelope: input.envelope,
|
|
75
|
-
question: `Explain concept: ${input.conceptKey}`
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
return {
|
|
79
|
-
answer,
|
|
80
|
-
explainConcept
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
//#endregion
|
|
85
|
-
export { createDemoAssistantHandlers };
|
|
1
|
+
import{enforceAllowedScope as e,enforceCitations as t,validateEnvelope as n}from"../policy/guard.js";function r(){async function r(r){let i=n(r.envelope);if(!i.ok)return{locale:r.envelope.locale??`en-US`,jurisdiction:r.envelope.regulatoryContext?.jurisdiction??`UNKNOWN`,allowedScope:r.envelope.allowedScope??`education_only`,sections:[{heading:`Request blocked`,body:i.error.message}],citations:[],disclaimers:[`This system refuses to answer without a valid envelope.`],riskFlags:[i.error.code],refused:!0,refusalReason:i.error.code};let a={locale:i.value.locale,jurisdiction:i.value.regulatoryContext.jurisdiction,allowedScope:i.value.allowedScope,sections:[{heading:`Answer (demo)`,body:`You asked: "${r.question}". This demo answer is derived from the KB snapshot only.`}],citations:[{kbSnapshotId:i.value.kbSnapshotId,sourceType:`ruleVersion`,sourceId:`rv_demo`,title:`Demo rule version`,excerpt:`Demo excerpt`}],disclaimers:[`Educational demo only.`],riskFlags:[]},o=e(i.value.allowedScope,a);if(!o.ok)return{...a,sections:[{heading:`Escalation required`,body:o.error.message}],citations:a.citations,refused:!0,refusalReason:o.error.code,riskFlags:[...a.riskFlags??[],o.error.code]};let s=t(a);return s.ok?a:{...a,sections:[{heading:`Request blocked`,body:s.error.message}],citations:[],refused:!0,refusalReason:s.error.code,riskFlags:[...a.riskFlags??[],s.error.code]}}async function i(e){return await r({envelope:e.envelope,question:`Explain concept: ${e.conceptKey}`})}return{answer:r,explainConcept:i}}export{r as createDemoAssistantHandlers};
|
package/dist/handlers/index.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,12 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import example_default from "./example.js";
|
|
3
|
-
import { AllowedScopeEnum, AssistantAnswerIRModel, AssistantAnswerSectionModel, AssistantCitationModel, LLMCallEnvelopeModel, RegulatoryContextModel, UserProfileModel } from "./entities/models.js";
|
|
4
|
-
import "./entities/index.js";
|
|
5
|
-
import { AssistantAnswerContract, AssistantExplainConceptContract } from "./contracts/assistant.js";
|
|
6
|
-
import "./contracts/index.js";
|
|
7
|
-
import { enforceAllowedScope, enforceCitations, validateEnvelope } from "./policy/guard.js";
|
|
8
|
-
import { createDemoAssistantHandlers } from "./handlers/demo.handlers.js";
|
|
9
|
-
import { LocaleJurisdictionGateFeature } from "./locale-jurisdiction-gate.feature.js";
|
|
10
|
-
import "./docs/index.js";
|
|
11
|
-
|
|
12
|
-
export { AllowedScopeEnum, AssistantAnswerBlockedEvent, AssistantAnswerContract, AssistantAnswerDeliveredEvent, AssistantAnswerIRModel, AssistantAnswerRequestedEvent, AssistantAnswerSectionModel, AssistantCitationModel, AssistantExplainConceptContract, LLMCallEnvelopeModel, LocaleJurisdictionGateFeature, RegulatoryContextModel, UserProfileModel, createDemoAssistantHandlers, enforceAllowedScope, enforceCitations, example_default as example, validateEnvelope };
|
|
1
|
+
import{AssistantAnswerBlockedEvent as e,AssistantAnswerDeliveredEvent as t,AssistantAnswerRequestedEvent as n}from"./events.js";import r from"./example.js";import{AllowedScopeEnum as i,AssistantAnswerIRModel as a,AssistantAnswerSectionModel as o,AssistantCitationModel as s,LLMCallEnvelopeModel as c,RegulatoryContextModel as l,UserProfileModel as u}from"./entities/models.js";import"./entities/index.js";import{AssistantAnswerContract as d,AssistantExplainConceptContract as f}from"./contracts/assistant.js";import"./contracts/index.js";import{enforceAllowedScope as p,enforceCitations as m,validateEnvelope as h}from"./policy/guard.js";import{createDemoAssistantHandlers as g}from"./handlers/demo.handlers.js";import{LocaleJurisdictionGateFeature as _}from"./locale-jurisdiction-gate.feature.js";import"./docs/index.js";export{i as AllowedScopeEnum,e as AssistantAnswerBlockedEvent,d as AssistantAnswerContract,t as AssistantAnswerDeliveredEvent,a as AssistantAnswerIRModel,n as AssistantAnswerRequestedEvent,o as AssistantAnswerSectionModel,s as AssistantCitationModel,f as AssistantExplainConceptContract,c as LLMCallEnvelopeModel,_ as LocaleJurisdictionGateFeature,l as RegulatoryContextModel,u as UserProfileModel,g as createDemoAssistantHandlers,p as enforceAllowedScope,m as enforceCitations,r as example,h as validateEnvelope};
|
|
@@ -1,49 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const LocaleJurisdictionGateFeature = {
|
|
3
|
-
meta: {
|
|
4
|
-
key: "locale-jurisdiction-gate",
|
|
5
|
-
title: "Locale + Jurisdiction Gate",
|
|
6
|
-
description: "Fail-closed gating for assistant calls requiring locale/jurisdiction/snapshot/scope and citations.",
|
|
7
|
-
domain: "knowledge",
|
|
8
|
-
owners: ["@examples"],
|
|
9
|
-
tags: [
|
|
10
|
-
"assistant",
|
|
11
|
-
"policy",
|
|
12
|
-
"locale",
|
|
13
|
-
"jurisdiction",
|
|
14
|
-
"knowledge"
|
|
15
|
-
],
|
|
16
|
-
stability: "experimental"
|
|
17
|
-
},
|
|
18
|
-
operations: [{
|
|
19
|
-
name: "assistant.answer",
|
|
20
|
-
version: 1
|
|
21
|
-
}, {
|
|
22
|
-
name: "assistant.explainConcept",
|
|
23
|
-
version: 1
|
|
24
|
-
}],
|
|
25
|
-
events: [
|
|
26
|
-
{
|
|
27
|
-
name: "assistant.answer.requested",
|
|
28
|
-
version: 1
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
name: "assistant.answer.blocked",
|
|
32
|
-
version: 1
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
name: "assistant.answer.delivered",
|
|
36
|
-
version: 1
|
|
37
|
-
}
|
|
38
|
-
],
|
|
39
|
-
presentations: [],
|
|
40
|
-
opToPresentation: [],
|
|
41
|
-
presentationsTargets: [],
|
|
42
|
-
capabilities: { requires: [{
|
|
43
|
-
key: "knowledge",
|
|
44
|
-
version: 1
|
|
45
|
-
}] }
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
//#endregion
|
|
49
|
-
export { LocaleJurisdictionGateFeature };
|
|
1
|
+
const e={meta:{key:`locale-jurisdiction-gate`,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:[{name:`assistant.answer`,version:1},{name:`assistant.explainConcept`,version:1}],events:[{name:`assistant.answer.requested`,version:1},{name:`assistant.answer.blocked`,version:1},{name:`assistant.answer.delivered`,version:1}],presentations:[],opToPresentation:[],presentationsTargets:[],capabilities:{requires:[{key:`knowledge`,version:1}]}};export{e as LocaleJurisdictionGateFeature};
|
package/dist/policy/guard.js
CHANGED
|
@@ -1,72 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
"en-US",
|
|
4
|
-
"en-GB",
|
|
5
|
-
"fr-FR"
|
|
6
|
-
]);
|
|
7
|
-
function err(code, message) {
|
|
8
|
-
return {
|
|
9
|
-
code,
|
|
10
|
-
message
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
function validateEnvelope(envelope) {
|
|
14
|
-
if (!envelope.locale || !SUPPORTED_LOCALES.has(envelope.locale)) return {
|
|
15
|
-
ok: false,
|
|
16
|
-
error: err("LOCALE_REQUIRED", "locale is required and must be supported")
|
|
17
|
-
};
|
|
18
|
-
if (!envelope.regulatoryContext?.jurisdiction) return {
|
|
19
|
-
ok: false,
|
|
20
|
-
error: err("JURISDICTION_REQUIRED", "jurisdiction is required")
|
|
21
|
-
};
|
|
22
|
-
if (!envelope.kbSnapshotId) return {
|
|
23
|
-
ok: false,
|
|
24
|
-
error: err("KB_SNAPSHOT_REQUIRED", "kbSnapshotId is required")
|
|
25
|
-
};
|
|
26
|
-
if (!envelope.allowedScope) return {
|
|
27
|
-
ok: false,
|
|
28
|
-
error: err("SCOPE_VIOLATION", "allowedScope is required")
|
|
29
|
-
};
|
|
30
|
-
return {
|
|
31
|
-
ok: true,
|
|
32
|
-
value: envelope
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
function enforceCitations(answer) {
|
|
36
|
-
const citations = answer.citations ?? [];
|
|
37
|
-
if (!Array.isArray(citations) || citations.length === 0) return {
|
|
38
|
-
ok: false,
|
|
39
|
-
error: err("CITATIONS_REQUIRED", "answers must include at least one citation")
|
|
40
|
-
};
|
|
41
|
-
return {
|
|
42
|
-
ok: true,
|
|
43
|
-
value: answer
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
const EDUCATION_ONLY_FORBIDDEN_PATTERNS = [
|
|
47
|
-
/\b(buy|sell)\b/i,
|
|
48
|
-
/\b(should\s+buy|should\s+sell)\b/i,
|
|
49
|
-
/\b(guarantee(d)?|promise(d)?)\b/i
|
|
50
|
-
];
|
|
51
|
-
function enforceAllowedScope(allowedScope, answer) {
|
|
52
|
-
if (!allowedScope) return {
|
|
53
|
-
ok: false,
|
|
54
|
-
error: err("SCOPE_VIOLATION", "allowedScope is required")
|
|
55
|
-
};
|
|
56
|
-
if (allowedScope !== "education_only") return {
|
|
57
|
-
ok: true,
|
|
58
|
-
value: answer
|
|
59
|
-
};
|
|
60
|
-
const bodies = (answer.sections ?? []).map((s) => s.body).join("\n");
|
|
61
|
-
if (EDUCATION_ONLY_FORBIDDEN_PATTERNS.some((re) => re.test(bodies))) return {
|
|
62
|
-
ok: false,
|
|
63
|
-
error: err("SCOPE_VIOLATION", "answer violates education_only scope (contains actionable or promotional language)")
|
|
64
|
-
};
|
|
65
|
-
return {
|
|
66
|
-
ok: true,
|
|
67
|
-
value: answer
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
//#endregion
|
|
72
|
-
export { enforceAllowedScope, enforceCitations, validateEnvelope };
|
|
1
|
+
const e=new Set([`en-US`,`en-GB`,`fr-FR`]);function t(e,t){return{code:e,message:t}}function n(n){return!n.locale||!e.has(n.locale)?{ok:!1,error:t(`LOCALE_REQUIRED`,`locale is required and must be supported`)}:n.regulatoryContext?.jurisdiction?n.kbSnapshotId?n.allowedScope?{ok:!0,value:n}:{ok:!1,error:t(`SCOPE_VIOLATION`,`allowedScope is required`)}:{ok:!1,error:t(`KB_SNAPSHOT_REQUIRED`,`kbSnapshotId is required`)}:{ok:!1,error:t(`JURISDICTION_REQUIRED`,`jurisdiction is required`)}}function r(e){let n=e.citations??[];return!Array.isArray(n)||n.length===0?{ok:!1,error:t(`CITATIONS_REQUIRED`,`answers must include at least one citation`)}:{ok:!0,value:e}}const i=[/\b(buy|sell)\b/i,/\b(should\s+buy|should\s+sell)\b/i,/\b(guarantee(d)?|promise(d)?)\b/i];function a(e,n){if(!e)return{ok:!1,error:t(`SCOPE_VIOLATION`,`allowedScope is required`)};if(e!==`education_only`)return{ok:!0,value:n};let r=(n.sections??[]).map(e=>e.body).join(`
|
|
2
|
+
`);return i.some(e=>e.test(r))?{ok:!1,error:t(`SCOPE_VIOLATION`,`answer violates education_only scope (contains actionable or promotional language)`)}:{ok:!0,value:n}}export{a as enforceAllowedScope,r as enforceCitations,n as validateEnvelope};
|
package/dist/policy/index.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export { enforceAllowedScope, enforceCitations, validateEnvelope };
|
|
1
|
+
import{enforceAllowedScope as e,enforceCitations as t,validateEnvelope as n}from"./guard.js";export{e as enforceAllowedScope,t as enforceCitations,n as validateEnvelope};
|
package/package.json
CHANGED
|
@@ -1,32 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lssm/example.locale-jurisdiction-gate",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.41.0",
|
|
4
4
|
"description": "Example: enforce locale + jurisdiction + kbSnapshotId + allowed scope for assistant calls (fail-closed).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
|
-
".": "./
|
|
11
|
-
"./contracts": "./
|
|
12
|
-
"./contracts/assistant": "./
|
|
13
|
-
"./docs": "./
|
|
14
|
-
"./docs/locale-jurisdiction-gate.docblock": "./
|
|
15
|
-
"./entities": "./
|
|
16
|
-
"./entities/models": "./
|
|
17
|
-
"./events": "./
|
|
18
|
-
"./example": "./
|
|
19
|
-
"./handlers": "./
|
|
20
|
-
"./handlers/demo.handlers": "./
|
|
21
|
-
"./locale-jurisdiction-gate.feature": "./
|
|
22
|
-
"./policy": "./
|
|
23
|
-
"./policy/guard": "./
|
|
24
|
-
"./policy/types": "./
|
|
10
|
+
".": "./src/index.ts",
|
|
11
|
+
"./contracts": "./src/contracts/index.ts",
|
|
12
|
+
"./contracts/assistant": "./src/contracts/assistant.ts",
|
|
13
|
+
"./docs": "./src/docs/index.ts",
|
|
14
|
+
"./docs/locale-jurisdiction-gate.docblock": "./src/docs/locale-jurisdiction-gate.docblock.ts",
|
|
15
|
+
"./entities": "./src/entities/index.ts",
|
|
16
|
+
"./entities/models": "./src/entities/models.ts",
|
|
17
|
+
"./events": "./src/events.ts",
|
|
18
|
+
"./example": "./src/example.ts",
|
|
19
|
+
"./handlers": "./src/handlers/index.ts",
|
|
20
|
+
"./handlers/demo.handlers": "./src/handlers/demo.handlers.ts",
|
|
21
|
+
"./locale-jurisdiction-gate.feature": "./src/locale-jurisdiction-gate.feature.ts",
|
|
22
|
+
"./policy": "./src/policy/index.ts",
|
|
23
|
+
"./policy/guard": "./src/policy/guard.ts",
|
|
24
|
+
"./policy/types": "./src/policy/types.ts",
|
|
25
25
|
"./*": "./*"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
|
-
"publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
|
|
29
|
-
"publish:pkg:canary": "bun publish:pkg --tag canary",
|
|
30
28
|
"build": "bun build:bundle && bun build:types",
|
|
31
29
|
"build:bundle": "tsdown",
|
|
32
30
|
"build:types": "tsc --noEmit",
|
|
@@ -38,13 +36,13 @@
|
|
|
38
36
|
"test": "bun test"
|
|
39
37
|
},
|
|
40
38
|
"dependencies": {
|
|
41
|
-
"@lssm/lib.contracts": "
|
|
42
|
-
"@lssm/lib.schema": "
|
|
39
|
+
"@lssm/lib.contracts": "workspace:*",
|
|
40
|
+
"@lssm/lib.schema": "workspace:*",
|
|
43
41
|
"zod": "^4.1.13"
|
|
44
42
|
},
|
|
45
43
|
"devDependencies": {
|
|
46
|
-
"@lssm/tool.tsdown": "
|
|
47
|
-
"@lssm/tool.typescript": "
|
|
44
|
+
"@lssm/tool.tsdown": "workspace:*",
|
|
45
|
+
"@lssm/tool.typescript": "workspace:*",
|
|
48
46
|
"tsdown": "^0.17.4",
|
|
49
47
|
"typescript": "^5.9.3"
|
|
50
48
|
},
|