@contractspec/example.locale-jurisdiction-gate 0.0.0-canary-20260113162409
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$colon$bundle.log +56 -0
- package/.turbo/turbo-build.log +57 -0
- package/CHANGELOG.md +302 -0
- package/LICENSE +21 -0
- package/README.md +42 -0
- package/dist/docs/index.d.ts +1 -0
- package/dist/docs/index.js +1 -0
- package/dist/docs/locale-jurisdiction-gate.docblock.d.ts +1 -0
- package/dist/docs/locale-jurisdiction-gate.docblock.js +53 -0
- package/dist/docs/locale-jurisdiction-gate.docblock.js.map +1 -0
- package/dist/entities/index.d.ts +2 -0
- package/dist/entities/index.js +3 -0
- package/dist/entities/models.d.ts +186 -0
- package/dist/entities/models.d.ts.map +1 -0
- package/dist/entities/models.js +168 -0
- package/dist/entities/models.js.map +1 -0
- package/dist/events.d.ts +69 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +123 -0
- package/dist/events.js.map +1 -0
- package/dist/example.d.ts +7 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/example.js +47 -0
- package/dist/example.js.map +1 -0
- package/dist/handlers/demo.handlers.d.ts +59 -0
- package/dist/handlers/demo.handlers.d.ts.map +1 -0
- package/dist/handlers/demo.handlers.js +86 -0
- package/dist/handlers/demo.handlers.js.map +1 -0
- package/dist/handlers/index.d.ts +2 -0
- package/dist/handlers/index.js +3 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +12 -0
- package/dist/locale-jurisdiction-gate.feature.d.ts +7 -0
- package/dist/locale-jurisdiction-gate.feature.d.ts.map +1 -0
- package/dist/locale-jurisdiction-gate.feature.js +53 -0
- package/dist/locale-jurisdiction-gate.feature.js.map +1 -0
- package/dist/operations/assistant.d.ts +245 -0
- package/dist/operations/assistant.d.ts.map +1 -0
- package/dist/operations/assistant.js +115 -0
- package/dist/operations/assistant.js.map +1 -0
- package/dist/operations/index.d.ts +2 -0
- package/dist/operations/index.js +3 -0
- package/dist/policy/guard.d.ts +27 -0
- package/dist/policy/guard.d.ts.map +1 -0
- package/dist/policy/guard.js +73 -0
- package/dist/policy/guard.js.map +1 -0
- package/dist/policy/index.d.ts +3 -0
- package/dist/policy/index.js +3 -0
- package/dist/policy/types.d.ts +16 -0
- package/dist/policy/types.d.ts.map +1 -0
- package/dist/policy/types.js +0 -0
- package/example.ts +1 -0
- package/package.json +77 -0
- package/src/docs/index.ts +1 -0
- package/src/docs/locale-jurisdiction-gate.docblock.ts +46 -0
- package/src/entities/index.ts +1 -0
- package/src/entities/models.ts +110 -0
- package/src/events.ts +74 -0
- package/src/example.ts +34 -0
- package/src/handlers/demo.handlers.test.ts +54 -0
- package/src/handlers/demo.handlers.ts +160 -0
- package/src/handlers/index.ts +1 -0
- package/src/index.ts +15 -0
- package/src/locale-jurisdiction-gate.feature.ts +30 -0
- package/src/operations/assistant.ts +98 -0
- package/src/operations/index.ts +1 -0
- package/src/policy/guard.test.ts +25 -0
- package/src/policy/guard.ts +102 -0
- package/src/policy/index.ts +2 -0
- package/src/policy/types.ts +18 -0
- package/tsconfig.json +17 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsdown.config.js +17 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region src/handlers/demo.handlers.d.ts
|
|
2
|
+
type AllowedScope = 'education_only' | 'generic_info' | 'escalation_required';
|
|
3
|
+
interface AssistantAnswerIR {
|
|
4
|
+
locale: string;
|
|
5
|
+
jurisdiction: string;
|
|
6
|
+
allowedScope: AllowedScope;
|
|
7
|
+
sections: {
|
|
8
|
+
heading: string;
|
|
9
|
+
body: string;
|
|
10
|
+
}[];
|
|
11
|
+
citations: {
|
|
12
|
+
kbSnapshotId: string;
|
|
13
|
+
sourceType: string;
|
|
14
|
+
sourceId: string;
|
|
15
|
+
title?: string;
|
|
16
|
+
excerpt?: string;
|
|
17
|
+
}[];
|
|
18
|
+
disclaimers?: string[];
|
|
19
|
+
riskFlags?: string[];
|
|
20
|
+
refused?: boolean;
|
|
21
|
+
refusalReason?: string;
|
|
22
|
+
}
|
|
23
|
+
interface DemoAssistantHandlers {
|
|
24
|
+
answer(input: {
|
|
25
|
+
envelope: {
|
|
26
|
+
traceId: string;
|
|
27
|
+
locale: string;
|
|
28
|
+
kbSnapshotId: string;
|
|
29
|
+
allowedScope: AllowedScope;
|
|
30
|
+
regulatoryContext: {
|
|
31
|
+
jurisdiction: string;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
question: string;
|
|
35
|
+
}): Promise<AssistantAnswerIR>;
|
|
36
|
+
explainConcept(input: {
|
|
37
|
+
envelope: {
|
|
38
|
+
traceId: string;
|
|
39
|
+
locale: string;
|
|
40
|
+
kbSnapshotId: string;
|
|
41
|
+
allowedScope: AllowedScope;
|
|
42
|
+
regulatoryContext: {
|
|
43
|
+
jurisdiction: string;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
conceptKey: string;
|
|
47
|
+
}): Promise<AssistantAnswerIR>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Deterministic demo assistant handlers (no LLM).
|
|
51
|
+
*
|
|
52
|
+
* - Validates envelope
|
|
53
|
+
* - Requires citations
|
|
54
|
+
* - Enforces allowedScope (education_only blocks actionable language)
|
|
55
|
+
*/
|
|
56
|
+
declare function createDemoAssistantHandlers(): DemoAssistantHandlers;
|
|
57
|
+
//#endregion
|
|
58
|
+
export { DemoAssistantHandlers, createDemoAssistantHandlers };
|
|
59
|
+
//# sourceMappingURL=demo.handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"demo.handlers.d.ts","names":[],"sources":["../../src/handlers/demo.handlers.ts"],"sourcesContent":[],"mappings":";KAMK,YAAA;UAEK,iBAAA,CAFO;EAEP,MAAA,EAAA,MAAA;EAkBO,YAAA,EAAA,MAAA;EAMG,YAAA,EArBJ,YAqBI;EAIN,QAAA,EAAA;IAAR,OAAA,EAAA,MAAA;IAOc,IAAA,EAAA,MAAA;EAIN,CAAA,EAAA;EAAR,SAAA,EAAA;IAAO,YAAA,EAAA,MAAA;IAUG,UAAA,EAAA,MAAA;;;;;;;;;;UA/BC,qBAAA;;;;;;oBAMG;;;;;;MAId,QAAQ;;;;;;oBAOM;;;;;;MAId,QAAQ;;;;;;;;;iBAUE,2BAAA,CAAA,GAA+B"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { enforceAllowedScope, enforceCitations, validateEnvelope } from "../policy/guard.js";
|
|
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 ?? "UNKNOWN",
|
|
31
|
+
allowedScope: env.value.allowedScope ?? "education_only",
|
|
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 ?? "unknown",
|
|
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 };
|
|
86
|
+
//# sourceMappingURL=demo.handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"demo.handlers.js","names":[],"sources":["../../src/handlers/demo.handlers.ts"],"sourcesContent":["import {\n enforceAllowedScope,\n enforceCitations,\n validateEnvelope,\n} from '../policy/guard';\n\ntype AllowedScope = 'education_only' | 'generic_info' | 'escalation_required';\n\ninterface AssistantAnswerIR {\n locale: string;\n jurisdiction: string;\n allowedScope: AllowedScope;\n sections: { heading: string; body: string }[];\n citations: {\n kbSnapshotId: string;\n sourceType: string;\n sourceId: string;\n title?: string;\n excerpt?: string;\n }[];\n disclaimers?: string[];\n riskFlags?: string[];\n refused?: boolean;\n refusalReason?: string;\n}\n\nexport interface DemoAssistantHandlers {\n answer(input: {\n envelope: {\n traceId: string;\n locale: string;\n kbSnapshotId: string;\n allowedScope: AllowedScope;\n regulatoryContext: { jurisdiction: string };\n };\n question: string;\n }): Promise<AssistantAnswerIR>;\n\n explainConcept(input: {\n envelope: {\n traceId: string;\n locale: string;\n kbSnapshotId: string;\n allowedScope: AllowedScope;\n regulatoryContext: { jurisdiction: string };\n };\n conceptKey: string;\n }): Promise<AssistantAnswerIR>;\n}\n\n/**\n * Deterministic demo assistant handlers (no LLM).\n *\n * - Validates envelope\n * - Requires citations\n * - Enforces allowedScope (education_only blocks actionable language)\n */\nexport function createDemoAssistantHandlers(): DemoAssistantHandlers {\n async function answer(input: {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n envelope: DemoAssistantHandlers['answer'] extends (a: infer A) => any\n ? A extends { envelope: infer E }\n ? E\n : never\n : never;\n question: string;\n }): Promise<AssistantAnswerIR> {\n const env = validateEnvelope(input.envelope);\n if (!env.ok) {\n return {\n locale: input.envelope.locale ?? 'en-US',\n jurisdiction:\n input.envelope.regulatoryContext?.jurisdiction ?? 'UNKNOWN',\n allowedScope: input.envelope.allowedScope ?? 'education_only',\n sections: [\n {\n heading: 'Request blocked',\n body: env.error.message,\n },\n ],\n citations: [],\n disclaimers: [\n 'This system refuses to answer without a valid envelope.',\n ],\n riskFlags: [env.error.code],\n refused: true,\n refusalReason: env.error.code,\n };\n }\n\n const draft: AssistantAnswerIR = {\n locale: env.value.locale,\n jurisdiction: env.value.regulatoryContext?.jurisdiction ?? 'UNKNOWN',\n allowedScope: env.value.allowedScope ?? 'education_only',\n sections: [\n {\n heading: 'Answer (demo)',\n body: `You asked: \"${input.question}\". This demo answer is derived from the KB snapshot only.`,\n },\n ],\n citations: [\n {\n kbSnapshotId: env.value.kbSnapshotId ?? 'unknown',\n sourceType: 'ruleVersion',\n sourceId: 'rv_demo',\n title: 'Demo rule version',\n excerpt: 'Demo excerpt',\n },\n ],\n disclaimers: ['Educational demo only.'],\n riskFlags: [],\n };\n\n const scope = enforceAllowedScope(env.value.allowedScope, draft);\n if (!scope.ok) {\n return {\n ...draft,\n sections: [\n { heading: 'Escalation required', body: scope.error.message },\n ],\n citations: draft.citations,\n refused: true,\n refusalReason: scope.error.code,\n riskFlags: [...(draft.riskFlags ?? []), scope.error.code],\n };\n }\n\n const cited = enforceCitations(draft);\n if (!cited.ok) {\n return {\n ...draft,\n sections: [{ heading: 'Request blocked', body: cited.error.message }],\n citations: [],\n refused: true,\n refusalReason: cited.error.code,\n riskFlags: [...(draft.riskFlags ?? []), cited.error.code],\n };\n }\n\n return draft;\n }\n\n async function explainConcept(input: {\n envelope: DemoAssistantHandlers['explainConcept'] extends (\n a: infer A\n ) => any // eslint-disable-line @typescript-eslint/no-explicit-any\n ? A extends { envelope: infer E }\n ? E\n : never\n : never;\n conceptKey: string;\n }): Promise<AssistantAnswerIR> {\n return await answer({\n envelope: input.envelope,\n question: `Explain concept: ${input.conceptKey}`,\n });\n }\n\n return { answer, explainConcept };\n}\n"],"mappings":";;;;;;;;;;AAyDA,SAAgB,8BAAqD;CACnE,eAAe,OAAO,OAQS;EAC7B,MAAM,MAAM,iBAAiB,MAAM,SAAS;AAC5C,MAAI,CAAC,IAAI,GACP,QAAO;GACL,QAAQ,MAAM,SAAS,UAAU;GACjC,cACE,MAAM,SAAS,mBAAmB,gBAAgB;GACpD,cAAc,MAAM,SAAS,gBAAgB;GAC7C,UAAU,CACR;IACE,SAAS;IACT,MAAM,IAAI,MAAM;IACjB,CACF;GACD,WAAW,EAAE;GACb,aAAa,CACX,0DACD;GACD,WAAW,CAAC,IAAI,MAAM,KAAK;GAC3B,SAAS;GACT,eAAe,IAAI,MAAM;GAC1B;EAGH,MAAM,QAA2B;GAC/B,QAAQ,IAAI,MAAM;GAClB,cAAc,IAAI,MAAM,mBAAmB,gBAAgB;GAC3D,cAAc,IAAI,MAAM,gBAAgB;GACxC,UAAU,CACR;IACE,SAAS;IACT,MAAM,eAAe,MAAM,SAAS;IACrC,CACF;GACD,WAAW,CACT;IACE,cAAc,IAAI,MAAM,gBAAgB;IACxC,YAAY;IACZ,UAAU;IACV,OAAO;IACP,SAAS;IACV,CACF;GACD,aAAa,CAAC,yBAAyB;GACvC,WAAW,EAAE;GACd;EAED,MAAM,QAAQ,oBAAoB,IAAI,MAAM,cAAc,MAAM;AAChE,MAAI,CAAC,MAAM,GACT,QAAO;GACL,GAAG;GACH,UAAU,CACR;IAAE,SAAS;IAAuB,MAAM,MAAM,MAAM;IAAS,CAC9D;GACD,WAAW,MAAM;GACjB,SAAS;GACT,eAAe,MAAM,MAAM;GAC3B,WAAW,CAAC,GAAI,MAAM,aAAa,EAAE,EAAG,MAAM,MAAM,KAAK;GAC1D;EAGH,MAAM,QAAQ,iBAAiB,MAAM;AACrC,MAAI,CAAC,MAAM,GACT,QAAO;GACL,GAAG;GACH,UAAU,CAAC;IAAE,SAAS;IAAmB,MAAM,MAAM,MAAM;IAAS,CAAC;GACrE,WAAW,EAAE;GACb,SAAS;GACT,eAAe,MAAM,MAAM;GAC3B,WAAW,CAAC,GAAI,MAAM,aAAa,EAAE,EAAG,MAAM,MAAM,KAAK;GAC1D;AAGH,SAAO;;CAGT,eAAe,eAAe,OASC;AAC7B,SAAO,MAAM,OAAO;GAClB,UAAU,MAAM;GAChB,UAAU,oBAAoB,MAAM;GACrC,CAAC;;AAGJ,QAAO;EAAE;EAAQ;EAAgB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AllowedScopeEnum, AssistantAnswerIRModel, AssistantAnswerSectionModel, AssistantCitationModel, LLMCallEnvelopeModel, RegulatoryContextModel, UserProfileModel } from "./entities/models.js";
|
|
2
|
+
import "./entities/index.js";
|
|
3
|
+
import { AssistantAnswerBlockedEvent, AssistantAnswerDeliveredEvent, AssistantAnswerRequestedEvent } from "./events.js";
|
|
4
|
+
import example from "./example.js";
|
|
5
|
+
import { DemoAssistantHandlers, createDemoAssistantHandlers } from "./handlers/demo.handlers.js";
|
|
6
|
+
import { AssistantAnswerContract, AssistantExplainConceptContract } from "./operations/assistant.js";
|
|
7
|
+
import "./operations/index.js";
|
|
8
|
+
import { AllowedScope, GateError, GateResult } from "./policy/types.js";
|
|
9
|
+
import { enforceAllowedScope, enforceCitations, validateEnvelope } from "./policy/guard.js";
|
|
10
|
+
import { LocaleJurisdictionGateFeature } from "./locale-jurisdiction-gate.feature.js";
|
|
11
|
+
export { AllowedScope, AllowedScopeEnum, AssistantAnswerBlockedEvent, AssistantAnswerContract, AssistantAnswerDeliveredEvent, AssistantAnswerIRModel, AssistantAnswerRequestedEvent, AssistantAnswerSectionModel, AssistantCitationModel, AssistantExplainConceptContract, DemoAssistantHandlers, GateError, GateResult, LLMCallEnvelopeModel, LocaleJurisdictionGateFeature, RegulatoryContextModel, UserProfileModel, createDemoAssistantHandlers, enforceAllowedScope, enforceCitations, example, validateEnvelope };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AssistantAnswerBlockedEvent, AssistantAnswerDeliveredEvent, AssistantAnswerRequestedEvent } from "./events.js";
|
|
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 "./operations/assistant.js";
|
|
6
|
+
import "./operations/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 };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as _contractspec_lib_contracts3 from "@contractspec/lib.contracts";
|
|
2
|
+
|
|
3
|
+
//#region src/locale-jurisdiction-gate.feature.d.ts
|
|
4
|
+
declare const LocaleJurisdictionGateFeature: _contractspec_lib_contracts3.FeatureModuleSpec;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { LocaleJurisdictionGateFeature };
|
|
7
|
+
//# sourceMappingURL=locale-jurisdiction-gate.feature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale-jurisdiction-gate.feature.d.ts","names":[],"sources":["../src/locale-jurisdiction-gate.feature.ts"],"sourcesContent":[],"mappings":";;;cAEa,+BA2BX,4BAAA,CA3BwC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { defineFeature } from "@contractspec/lib.contracts";
|
|
2
|
+
|
|
3
|
+
//#region src/locale-jurisdiction-gate.feature.ts
|
|
4
|
+
const LocaleJurisdictionGateFeature = defineFeature({
|
|
5
|
+
meta: {
|
|
6
|
+
key: "locale-jurisdiction-gate",
|
|
7
|
+
version: "1.0.0",
|
|
8
|
+
title: "Locale + Jurisdiction Gate",
|
|
9
|
+
description: "Fail-closed gating for assistant calls requiring locale/jurisdiction/snapshot/scope and citations.",
|
|
10
|
+
domain: "knowledge",
|
|
11
|
+
owners: ["@examples"],
|
|
12
|
+
tags: [
|
|
13
|
+
"assistant",
|
|
14
|
+
"policy",
|
|
15
|
+
"locale",
|
|
16
|
+
"jurisdiction",
|
|
17
|
+
"knowledge"
|
|
18
|
+
],
|
|
19
|
+
stability: "experimental"
|
|
20
|
+
},
|
|
21
|
+
operations: [{
|
|
22
|
+
key: "assistant.answer",
|
|
23
|
+
version: "1.0.0"
|
|
24
|
+
}, {
|
|
25
|
+
key: "assistant.explainConcept",
|
|
26
|
+
version: "1.0.0"
|
|
27
|
+
}],
|
|
28
|
+
events: [
|
|
29
|
+
{
|
|
30
|
+
key: "assistant.answer.requested",
|
|
31
|
+
version: "1.0.0"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
key: "assistant.answer.blocked",
|
|
35
|
+
version: "1.0.0"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key: "assistant.answer.delivered",
|
|
39
|
+
version: "1.0.0"
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
presentations: [],
|
|
43
|
+
opToPresentation: [],
|
|
44
|
+
presentationsTargets: [],
|
|
45
|
+
capabilities: { requires: [{
|
|
46
|
+
key: "knowledge",
|
|
47
|
+
version: "1.0.0"
|
|
48
|
+
}] }
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
export { LocaleJurisdictionGateFeature };
|
|
53
|
+
//# sourceMappingURL=locale-jurisdiction-gate.feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale-jurisdiction-gate.feature.js","names":[],"sources":["../src/locale-jurisdiction-gate.feature.ts"],"sourcesContent":["import { defineFeature } from '@contractspec/lib.contracts';\n\nexport const LocaleJurisdictionGateFeature = defineFeature({\n meta: {\n key: 'locale-jurisdiction-gate',\n version: '1.0.0',\n title: 'Locale + Jurisdiction Gate',\n description:\n 'Fail-closed gating for assistant calls requiring locale/jurisdiction/snapshot/scope and citations.',\n domain: 'knowledge',\n owners: ['@examples'],\n tags: ['assistant', 'policy', 'locale', 'jurisdiction', 'knowledge'],\n stability: 'experimental',\n },\n operations: [\n { key: 'assistant.answer', version: '1.0.0' },\n { key: 'assistant.explainConcept', version: '1.0.0' },\n ],\n events: [\n { key: 'assistant.answer.requested', version: '1.0.0' },\n { key: 'assistant.answer.blocked', version: '1.0.0' },\n { key: 'assistant.answer.delivered', version: '1.0.0' },\n ],\n presentations: [],\n opToPresentation: [],\n presentationsTargets: [],\n capabilities: {\n requires: [{ key: 'knowledge', version: '1.0.0' }],\n },\n});\n"],"mappings":";;;AAEA,MAAa,gCAAgC,cAAc;CACzD,MAAM;EACJ,KAAK;EACL,SAAS;EACT,OAAO;EACP,aACE;EACF,QAAQ;EACR,QAAQ,CAAC,YAAY;EACrB,MAAM;GAAC;GAAa;GAAU;GAAU;GAAgB;GAAY;EACpE,WAAW;EACZ;CACD,YAAY,CACV;EAAE,KAAK;EAAoB,SAAS;EAAS,EAC7C;EAAE,KAAK;EAA4B,SAAS;EAAS,CACtD;CACD,QAAQ;EACN;GAAE,KAAK;GAA8B,SAAS;GAAS;EACvD;GAAE,KAAK;GAA4B,SAAS;GAAS;EACrD;GAAE,KAAK;GAA8B,SAAS;GAAS;EACxD;CACD,eAAe,EAAE;CACjB,kBAAkB,EAAE;CACpB,sBAAsB,EAAE;CACxB,cAAc,EACZ,UAAU,CAAC;EAAE,KAAK;EAAa,SAAS;EAAS,CAAC,EACnD;CACF,CAAC"}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import * as _contractspec_lib_contracts4 from "@contractspec/lib.contracts";
|
|
2
|
+
import * as _contractspec_lib_schema63 from "@contractspec/lib.schema";
|
|
3
|
+
|
|
4
|
+
//#region src/operations/assistant.d.ts
|
|
5
|
+
declare const AssistantAnswerContract: _contractspec_lib_contracts4.OperationSpec<_contractspec_lib_schema63.SchemaModel<{
|
|
6
|
+
envelope: {
|
|
7
|
+
type: _contractspec_lib_schema63.SchemaModel<{
|
|
8
|
+
traceId: {
|
|
9
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
10
|
+
isOptional: false;
|
|
11
|
+
};
|
|
12
|
+
locale: {
|
|
13
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
14
|
+
isOptional: false;
|
|
15
|
+
};
|
|
16
|
+
regulatoryContext: {
|
|
17
|
+
type: _contractspec_lib_schema63.SchemaModel<{
|
|
18
|
+
jurisdiction: {
|
|
19
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
20
|
+
isOptional: false;
|
|
21
|
+
};
|
|
22
|
+
region: {
|
|
23
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
24
|
+
isOptional: true;
|
|
25
|
+
};
|
|
26
|
+
clientType: {
|
|
27
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
28
|
+
isOptional: true;
|
|
29
|
+
};
|
|
30
|
+
allowedScope: {
|
|
31
|
+
type: _contractspec_lib_schema63.EnumType<[string, string, string]>;
|
|
32
|
+
isOptional: false;
|
|
33
|
+
};
|
|
34
|
+
}>;
|
|
35
|
+
isOptional: false;
|
|
36
|
+
};
|
|
37
|
+
kbSnapshotId: {
|
|
38
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
39
|
+
isOptional: false;
|
|
40
|
+
};
|
|
41
|
+
allowedScope: {
|
|
42
|
+
type: _contractspec_lib_schema63.EnumType<[string, string, string]>;
|
|
43
|
+
isOptional: false;
|
|
44
|
+
};
|
|
45
|
+
}>;
|
|
46
|
+
isOptional: false;
|
|
47
|
+
};
|
|
48
|
+
question: {
|
|
49
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
50
|
+
isOptional: false;
|
|
51
|
+
};
|
|
52
|
+
}>, _contractspec_lib_schema63.SchemaModel<{
|
|
53
|
+
locale: {
|
|
54
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
55
|
+
isOptional: false;
|
|
56
|
+
};
|
|
57
|
+
jurisdiction: {
|
|
58
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
59
|
+
isOptional: false;
|
|
60
|
+
};
|
|
61
|
+
allowedScope: {
|
|
62
|
+
type: _contractspec_lib_schema63.EnumType<[string, string, string]>;
|
|
63
|
+
isOptional: false;
|
|
64
|
+
};
|
|
65
|
+
sections: {
|
|
66
|
+
type: _contractspec_lib_schema63.SchemaModel<{
|
|
67
|
+
heading: {
|
|
68
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
69
|
+
isOptional: false;
|
|
70
|
+
};
|
|
71
|
+
body: {
|
|
72
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
73
|
+
isOptional: false;
|
|
74
|
+
};
|
|
75
|
+
}>;
|
|
76
|
+
isArray: true;
|
|
77
|
+
isOptional: false;
|
|
78
|
+
};
|
|
79
|
+
citations: {
|
|
80
|
+
type: _contractspec_lib_schema63.SchemaModel<{
|
|
81
|
+
kbSnapshotId: {
|
|
82
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
83
|
+
isOptional: false;
|
|
84
|
+
};
|
|
85
|
+
sourceType: {
|
|
86
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
87
|
+
isOptional: false;
|
|
88
|
+
};
|
|
89
|
+
sourceId: {
|
|
90
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
91
|
+
isOptional: false;
|
|
92
|
+
};
|
|
93
|
+
title: {
|
|
94
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
95
|
+
isOptional: true;
|
|
96
|
+
};
|
|
97
|
+
excerpt: {
|
|
98
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
99
|
+
isOptional: true;
|
|
100
|
+
};
|
|
101
|
+
}>;
|
|
102
|
+
isArray: true;
|
|
103
|
+
isOptional: false;
|
|
104
|
+
};
|
|
105
|
+
disclaimers: {
|
|
106
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
107
|
+
isArray: true;
|
|
108
|
+
isOptional: true;
|
|
109
|
+
};
|
|
110
|
+
riskFlags: {
|
|
111
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
112
|
+
isArray: true;
|
|
113
|
+
isOptional: true;
|
|
114
|
+
};
|
|
115
|
+
refused: {
|
|
116
|
+
type: _contractspec_lib_schema63.FieldType<boolean, boolean>;
|
|
117
|
+
isOptional: true;
|
|
118
|
+
};
|
|
119
|
+
refusalReason: {
|
|
120
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
121
|
+
isOptional: true;
|
|
122
|
+
};
|
|
123
|
+
}>, undefined>;
|
|
124
|
+
declare const AssistantExplainConceptContract: _contractspec_lib_contracts4.OperationSpec<_contractspec_lib_schema63.SchemaModel<{
|
|
125
|
+
envelope: {
|
|
126
|
+
type: _contractspec_lib_schema63.SchemaModel<{
|
|
127
|
+
traceId: {
|
|
128
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
129
|
+
isOptional: false;
|
|
130
|
+
};
|
|
131
|
+
locale: {
|
|
132
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
133
|
+
isOptional: false;
|
|
134
|
+
};
|
|
135
|
+
regulatoryContext: {
|
|
136
|
+
type: _contractspec_lib_schema63.SchemaModel<{
|
|
137
|
+
jurisdiction: {
|
|
138
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
139
|
+
isOptional: false;
|
|
140
|
+
};
|
|
141
|
+
region: {
|
|
142
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
143
|
+
isOptional: true;
|
|
144
|
+
};
|
|
145
|
+
clientType: {
|
|
146
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
147
|
+
isOptional: true;
|
|
148
|
+
};
|
|
149
|
+
allowedScope: {
|
|
150
|
+
type: _contractspec_lib_schema63.EnumType<[string, string, string]>;
|
|
151
|
+
isOptional: false;
|
|
152
|
+
};
|
|
153
|
+
}>;
|
|
154
|
+
isOptional: false;
|
|
155
|
+
};
|
|
156
|
+
kbSnapshotId: {
|
|
157
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
158
|
+
isOptional: false;
|
|
159
|
+
};
|
|
160
|
+
allowedScope: {
|
|
161
|
+
type: _contractspec_lib_schema63.EnumType<[string, string, string]>;
|
|
162
|
+
isOptional: false;
|
|
163
|
+
};
|
|
164
|
+
}>;
|
|
165
|
+
isOptional: false;
|
|
166
|
+
};
|
|
167
|
+
conceptKey: {
|
|
168
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
169
|
+
isOptional: false;
|
|
170
|
+
};
|
|
171
|
+
}>, _contractspec_lib_schema63.SchemaModel<{
|
|
172
|
+
locale: {
|
|
173
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
174
|
+
isOptional: false;
|
|
175
|
+
};
|
|
176
|
+
jurisdiction: {
|
|
177
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
178
|
+
isOptional: false;
|
|
179
|
+
};
|
|
180
|
+
allowedScope: {
|
|
181
|
+
type: _contractspec_lib_schema63.EnumType<[string, string, string]>;
|
|
182
|
+
isOptional: false;
|
|
183
|
+
};
|
|
184
|
+
sections: {
|
|
185
|
+
type: _contractspec_lib_schema63.SchemaModel<{
|
|
186
|
+
heading: {
|
|
187
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
188
|
+
isOptional: false;
|
|
189
|
+
};
|
|
190
|
+
body: {
|
|
191
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
192
|
+
isOptional: false;
|
|
193
|
+
};
|
|
194
|
+
}>;
|
|
195
|
+
isArray: true;
|
|
196
|
+
isOptional: false;
|
|
197
|
+
};
|
|
198
|
+
citations: {
|
|
199
|
+
type: _contractspec_lib_schema63.SchemaModel<{
|
|
200
|
+
kbSnapshotId: {
|
|
201
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
202
|
+
isOptional: false;
|
|
203
|
+
};
|
|
204
|
+
sourceType: {
|
|
205
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
206
|
+
isOptional: false;
|
|
207
|
+
};
|
|
208
|
+
sourceId: {
|
|
209
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
210
|
+
isOptional: false;
|
|
211
|
+
};
|
|
212
|
+
title: {
|
|
213
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
214
|
+
isOptional: true;
|
|
215
|
+
};
|
|
216
|
+
excerpt: {
|
|
217
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
218
|
+
isOptional: true;
|
|
219
|
+
};
|
|
220
|
+
}>;
|
|
221
|
+
isArray: true;
|
|
222
|
+
isOptional: false;
|
|
223
|
+
};
|
|
224
|
+
disclaimers: {
|
|
225
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
226
|
+
isArray: true;
|
|
227
|
+
isOptional: true;
|
|
228
|
+
};
|
|
229
|
+
riskFlags: {
|
|
230
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
231
|
+
isArray: true;
|
|
232
|
+
isOptional: true;
|
|
233
|
+
};
|
|
234
|
+
refused: {
|
|
235
|
+
type: _contractspec_lib_schema63.FieldType<boolean, boolean>;
|
|
236
|
+
isOptional: true;
|
|
237
|
+
};
|
|
238
|
+
refusalReason: {
|
|
239
|
+
type: _contractspec_lib_schema63.FieldType<string, string>;
|
|
240
|
+
isOptional: true;
|
|
241
|
+
};
|
|
242
|
+
}>, undefined>;
|
|
243
|
+
//#endregion
|
|
244
|
+
export { AssistantAnswerContract, AssistantExplainConceptContract };
|
|
245
|
+
//# sourceMappingURL=assistant.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assistant.d.ts","names":[],"sources":["../../src/operations/assistant.ts"],"sourcesContent":[],"mappings":";;;;cA0Ba,sDAAuB,yCAAA;;;;QAAvB,IAAA,EAmDX,0BAAA,CAAA,SAAA,CAAA,MAAA,EAAA,MAAA,CAAA;QAAA,UAAA,EAAA,KAAA;;;;;;;;;;;;UAnDkC,MAAA,EAAA;;;;;;;;;;;;;;;;;yBAAA;MAAA,CAAA;MAqDvB,YAAA,EAAA;QAkBX,IAAA,qCAAA,CAAA,CAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,CAAA;;;;;;;;;;;;IAlB0C,IAAA,EArDR,0BAAA,CAAA,SAqDQ,CAAA,MAAA,EAAA,MAAA,CAAA;;;;;;;;;;;;;;;;;;QAAA,IAAA,sCAAA,CAAA,MAAA,EAAA,MAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAA/B,8DAA+B,yCAAA;;;;cAkB1C,0BAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAlB0C,0BAAA,CAAA"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { AssistantAnswerIRModel, LLMCallEnvelopeModel } from "../entities/models.js";
|
|
2
|
+
import { defineCommand } from "@contractspec/lib.contracts";
|
|
3
|
+
import { ScalarTypeEnum, defineSchemaModel as defineSchemaModel$1 } from "@contractspec/lib.schema";
|
|
4
|
+
|
|
5
|
+
//#region src/operations/assistant.ts
|
|
6
|
+
const AssistantQuestionInput = defineSchemaModel$1({
|
|
7
|
+
name: "AssistantQuestionInput",
|
|
8
|
+
description: "Input for assistant calls with mandatory envelope.",
|
|
9
|
+
fields: {
|
|
10
|
+
envelope: {
|
|
11
|
+
type: LLMCallEnvelopeModel,
|
|
12
|
+
isOptional: false
|
|
13
|
+
},
|
|
14
|
+
question: {
|
|
15
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
16
|
+
isOptional: false
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const AssistantConceptInput = defineSchemaModel$1({
|
|
21
|
+
name: "AssistantConceptInput",
|
|
22
|
+
description: "Input for explaining a concept with mandatory envelope.",
|
|
23
|
+
fields: {
|
|
24
|
+
envelope: {
|
|
25
|
+
type: LLMCallEnvelopeModel,
|
|
26
|
+
isOptional: false
|
|
27
|
+
},
|
|
28
|
+
conceptKey: {
|
|
29
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
30
|
+
isOptional: false
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
const AssistantAnswerContract = defineCommand({
|
|
35
|
+
meta: {
|
|
36
|
+
key: "assistant.answer",
|
|
37
|
+
version: "1.0.0",
|
|
38
|
+
stability: "experimental",
|
|
39
|
+
owners: ["@examples"],
|
|
40
|
+
tags: [
|
|
41
|
+
"assistant",
|
|
42
|
+
"policy",
|
|
43
|
+
"locale",
|
|
44
|
+
"jurisdiction",
|
|
45
|
+
"knowledge"
|
|
46
|
+
],
|
|
47
|
+
description: "Answer a user question using a KB snapshot with strict locale/jurisdiction gating.",
|
|
48
|
+
goal: "Provide policy-safe answers that cite a KB snapshot or refuse.",
|
|
49
|
+
context: "Called by UI or workflows; must fail-closed if envelope is invalid or citations are missing."
|
|
50
|
+
},
|
|
51
|
+
io: {
|
|
52
|
+
input: AssistantQuestionInput,
|
|
53
|
+
output: AssistantAnswerIRModel,
|
|
54
|
+
errors: {
|
|
55
|
+
LOCALE_REQUIRED: {
|
|
56
|
+
description: "Locale is required and must be supported",
|
|
57
|
+
http: 400,
|
|
58
|
+
gqlCode: "LOCALE_REQUIRED",
|
|
59
|
+
when: "locale is missing or unsupported"
|
|
60
|
+
},
|
|
61
|
+
JURISDICTION_REQUIRED: {
|
|
62
|
+
description: "Jurisdiction is required",
|
|
63
|
+
http: 400,
|
|
64
|
+
gqlCode: "JURISDICTION_REQUIRED",
|
|
65
|
+
when: "jurisdiction is missing"
|
|
66
|
+
},
|
|
67
|
+
KB_SNAPSHOT_REQUIRED: {
|
|
68
|
+
description: "KB snapshot id is required",
|
|
69
|
+
http: 400,
|
|
70
|
+
gqlCode: "KB_SNAPSHOT_REQUIRED",
|
|
71
|
+
when: "kbSnapshotId is missing"
|
|
72
|
+
},
|
|
73
|
+
CITATIONS_REQUIRED: {
|
|
74
|
+
description: "Answers must include citations to a KB snapshot",
|
|
75
|
+
http: 422,
|
|
76
|
+
gqlCode: "CITATIONS_REQUIRED",
|
|
77
|
+
when: "answer has no citations"
|
|
78
|
+
},
|
|
79
|
+
SCOPE_VIOLATION: {
|
|
80
|
+
description: "Answer violates allowed scope and must be refused/escalated",
|
|
81
|
+
http: 403,
|
|
82
|
+
gqlCode: "SCOPE_VIOLATION",
|
|
83
|
+
when: "output includes forbidden content under the given allowedScope"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
policy: { auth: "user" }
|
|
88
|
+
});
|
|
89
|
+
const AssistantExplainConceptContract = defineCommand({
|
|
90
|
+
meta: {
|
|
91
|
+
key: "assistant.explainConcept",
|
|
92
|
+
version: "1.0.0",
|
|
93
|
+
stability: "experimental",
|
|
94
|
+
owners: ["@examples"],
|
|
95
|
+
tags: [
|
|
96
|
+
"assistant",
|
|
97
|
+
"policy",
|
|
98
|
+
"knowledge",
|
|
99
|
+
"concepts"
|
|
100
|
+
],
|
|
101
|
+
description: "Explain a concept using a KB snapshot with strict locale/jurisdiction gating.",
|
|
102
|
+
goal: "Explain concepts with citations or refuse.",
|
|
103
|
+
context: "Same constraints as assistant.answer."
|
|
104
|
+
},
|
|
105
|
+
io: {
|
|
106
|
+
input: AssistantConceptInput,
|
|
107
|
+
output: AssistantAnswerIRModel,
|
|
108
|
+
errors: AssistantAnswerContract.io.errors
|
|
109
|
+
},
|
|
110
|
+
policy: { auth: "user" }
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
//#endregion
|
|
114
|
+
export { AssistantAnswerContract, AssistantExplainConceptContract };
|
|
115
|
+
//# sourceMappingURL=assistant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assistant.js","names":["defineSchemaModel"],"sources":["../../src/operations/assistant.ts"],"sourcesContent":["import { defineCommand } from '@contractspec/lib.contracts';\nimport { ScalarTypeEnum, defineSchemaModel } from '@contractspec/lib.schema';\n\nimport {\n AssistantAnswerIRModel,\n LLMCallEnvelopeModel,\n} from '../entities/models';\n\nconst AssistantQuestionInput = defineSchemaModel({\n name: 'AssistantQuestionInput',\n description: 'Input for assistant calls with mandatory envelope.',\n fields: {\n envelope: { type: LLMCallEnvelopeModel, isOptional: false },\n question: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n },\n});\n\nconst AssistantConceptInput = defineSchemaModel({\n name: 'AssistantConceptInput',\n description: 'Input for explaining a concept with mandatory envelope.',\n fields: {\n envelope: { type: LLMCallEnvelopeModel, isOptional: false },\n conceptKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n },\n});\n\nexport const AssistantAnswerContract = defineCommand({\n meta: {\n key: 'assistant.answer',\n version: '1.0.0',\n stability: 'experimental',\n owners: ['@examples'],\n tags: ['assistant', 'policy', 'locale', 'jurisdiction', 'knowledge'],\n description:\n 'Answer a user question using a KB snapshot with strict locale/jurisdiction gating.',\n goal: 'Provide policy-safe answers that cite a KB snapshot or refuse.',\n context:\n 'Called by UI or workflows; must fail-closed if envelope is invalid or citations are missing.',\n },\n io: {\n input: AssistantQuestionInput,\n output: AssistantAnswerIRModel,\n errors: {\n LOCALE_REQUIRED: {\n description: 'Locale is required and must be supported',\n http: 400,\n gqlCode: 'LOCALE_REQUIRED',\n when: 'locale is missing or unsupported',\n },\n JURISDICTION_REQUIRED: {\n description: 'Jurisdiction is required',\n http: 400,\n gqlCode: 'JURISDICTION_REQUIRED',\n when: 'jurisdiction is missing',\n },\n KB_SNAPSHOT_REQUIRED: {\n description: 'KB snapshot id is required',\n http: 400,\n gqlCode: 'KB_SNAPSHOT_REQUIRED',\n when: 'kbSnapshotId is missing',\n },\n CITATIONS_REQUIRED: {\n description: 'Answers must include citations to a KB snapshot',\n http: 422,\n gqlCode: 'CITATIONS_REQUIRED',\n when: 'answer has no citations',\n },\n SCOPE_VIOLATION: {\n description:\n 'Answer violates allowed scope and must be refused/escalated',\n http: 403,\n gqlCode: 'SCOPE_VIOLATION',\n when: 'output includes forbidden content under the given allowedScope',\n },\n },\n },\n policy: { auth: 'user' },\n});\n\nexport const AssistantExplainConceptContract = defineCommand({\n meta: {\n key: 'assistant.explainConcept',\n version: '1.0.0',\n stability: 'experimental',\n owners: ['@examples'],\n tags: ['assistant', 'policy', 'knowledge', 'concepts'],\n description:\n 'Explain a concept using a KB snapshot with strict locale/jurisdiction gating.',\n goal: 'Explain concepts with citations or refuse.',\n context: 'Same constraints as assistant.answer.',\n },\n io: {\n input: AssistantConceptInput,\n output: AssistantAnswerIRModel,\n errors: AssistantAnswerContract.io.errors,\n },\n policy: { auth: 'user' },\n});\n"],"mappings":";;;;;AAQA,MAAM,yBAAyBA,oBAAkB;CAC/C,MAAM;CACN,aAAa;CACb,QAAQ;EACN,UAAU;GAAE,MAAM;GAAsB,YAAY;GAAO;EAC3D,UAAU;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EACxE;CACF,CAAC;AAEF,MAAM,wBAAwBA,oBAAkB;CAC9C,MAAM;CACN,aAAa;CACb,QAAQ;EACN,UAAU;GAAE,MAAM;GAAsB,YAAY;GAAO;EAC3D,YAAY;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EAC1E;CACF,CAAC;AAEF,MAAa,0BAA0B,cAAc;CACnD,MAAM;EACJ,KAAK;EACL,SAAS;EACT,WAAW;EACX,QAAQ,CAAC,YAAY;EACrB,MAAM;GAAC;GAAa;GAAU;GAAU;GAAgB;GAAY;EACpE,aACE;EACF,MAAM;EACN,SACE;EACH;CACD,IAAI;EACF,OAAO;EACP,QAAQ;EACR,QAAQ;GACN,iBAAiB;IACf,aAAa;IACb,MAAM;IACN,SAAS;IACT,MAAM;IACP;GACD,uBAAuB;IACrB,aAAa;IACb,MAAM;IACN,SAAS;IACT,MAAM;IACP;GACD,sBAAsB;IACpB,aAAa;IACb,MAAM;IACN,SAAS;IACT,MAAM;IACP;GACD,oBAAoB;IAClB,aAAa;IACb,MAAM;IACN,SAAS;IACT,MAAM;IACP;GACD,iBAAiB;IACf,aACE;IACF,MAAM;IACN,SAAS;IACT,MAAM;IACP;GACF;EACF;CACD,QAAQ,EAAE,MAAM,QAAQ;CACzB,CAAC;AAEF,MAAa,kCAAkC,cAAc;CAC3D,MAAM;EACJ,KAAK;EACL,SAAS;EACT,WAAW;EACX,QAAQ,CAAC,YAAY;EACrB,MAAM;GAAC;GAAa;GAAU;GAAa;GAAW;EACtD,aACE;EACF,MAAM;EACN,SAAS;EACV;CACD,IAAI;EACF,OAAO;EACP,QAAQ;EACR,QAAQ,wBAAwB,GAAG;EACpC;CACD,QAAQ,EAAE,MAAM,QAAQ;CACzB,CAAC"}
|