@contractspec/example.policy-safe-knowledge-assistant 1.57.0 → 1.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/.turbo/turbo-build.log +58 -60
  2. package/.turbo/turbo-prebuild.log +1 -0
  3. package/CHANGELOG.md +41 -0
  4. package/dist/browser/docs/index.js +38 -0
  5. package/dist/browser/docs/policy-safe-knowledge-assistant.docblock.js +38 -0
  6. package/dist/browser/example.js +37 -0
  7. package/dist/browser/handlers/index.js +334 -0
  8. package/dist/browser/handlers/policy-safe-knowledge-assistant.handlers.js +334 -0
  9. package/dist/browser/index.js +917 -0
  10. package/dist/browser/orchestrator/buildAnswer.js +73 -0
  11. package/dist/browser/policy-safe-knowledge-assistant.feature.js +57 -0
  12. package/dist/browser/seed/fixtures.js +35 -0
  13. package/dist/browser/seed/index.js +35 -0
  14. package/dist/browser/seeders/index.js +12 -0
  15. package/dist/browser/ui/PolicySafeKnowledgeAssistantDashboard.js +420 -0
  16. package/dist/browser/ui/hooks/usePolicySafeKnowledgeAssistant.js +154 -0
  17. package/dist/browser/ui/index.js +420 -0
  18. package/dist/docs/index.d.ts +2 -1
  19. package/dist/docs/index.d.ts.map +1 -0
  20. package/dist/docs/index.js +39 -1
  21. package/dist/docs/policy-safe-knowledge-assistant.docblock.d.ts +2 -1
  22. package/dist/docs/policy-safe-knowledge-assistant.docblock.d.ts.map +1 -0
  23. package/dist/docs/policy-safe-knowledge-assistant.docblock.js +37 -33
  24. package/dist/example.d.ts +2 -6
  25. package/dist/example.d.ts.map +1 -1
  26. package/dist/example.js +36 -51
  27. package/dist/handlers/index.d.ts +2 -2
  28. package/dist/handlers/index.d.ts.map +1 -0
  29. package/dist/handlers/index.js +334 -2
  30. package/dist/handlers/policy-safe-knowledge-assistant.handlers.d.ts +124 -121
  31. package/dist/handlers/policy-safe-knowledge-assistant.handlers.d.ts.map +1 -1
  32. package/dist/handlers/policy-safe-knowledge-assistant.handlers.js +325 -254
  33. package/dist/index.d.ts +11 -8
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +918 -10
  36. package/dist/integration.test.d.ts +2 -0
  37. package/dist/integration.test.d.ts.map +1 -0
  38. package/dist/node/docs/index.js +38 -0
  39. package/dist/node/docs/policy-safe-knowledge-assistant.docblock.js +38 -0
  40. package/dist/node/example.js +37 -0
  41. package/dist/node/handlers/index.js +334 -0
  42. package/dist/node/handlers/policy-safe-knowledge-assistant.handlers.js +334 -0
  43. package/dist/node/index.js +917 -0
  44. package/dist/node/orchestrator/buildAnswer.js +73 -0
  45. package/dist/node/policy-safe-knowledge-assistant.feature.js +57 -0
  46. package/dist/node/seed/fixtures.js +35 -0
  47. package/dist/node/seed/index.js +35 -0
  48. package/dist/node/seeders/index.js +12 -0
  49. package/dist/node/ui/PolicySafeKnowledgeAssistantDashboard.js +420 -0
  50. package/dist/node/ui/hooks/usePolicySafeKnowledgeAssistant.js +154 -0
  51. package/dist/node/ui/index.js +420 -0
  52. package/dist/orchestrator/buildAnswer.d.ts +40 -42
  53. package/dist/orchestrator/buildAnswer.d.ts.map +1 -1
  54. package/dist/orchestrator/buildAnswer.js +72 -75
  55. package/dist/policy-safe-knowledge-assistant.feature.d.ts +1 -6
  56. package/dist/policy-safe-knowledge-assistant.feature.d.ts.map +1 -1
  57. package/dist/policy-safe-knowledge-assistant.feature.js +56 -148
  58. package/dist/seed/fixtures.d.ts +28 -31
  59. package/dist/seed/fixtures.d.ts.map +1 -1
  60. package/dist/seed/fixtures.js +35 -33
  61. package/dist/seed/index.d.ts +2 -2
  62. package/dist/seed/index.d.ts.map +1 -0
  63. package/dist/seed/index.js +36 -3
  64. package/dist/seeders/index.d.ts +4 -8
  65. package/dist/seeders/index.d.ts.map +1 -1
  66. package/dist/seeders/index.js +11 -14
  67. package/dist/ui/PolicySafeKnowledgeAssistantDashboard.d.ts +1 -6
  68. package/dist/ui/PolicySafeKnowledgeAssistantDashboard.d.ts.map +1 -1
  69. package/dist/ui/PolicySafeKnowledgeAssistantDashboard.js +415 -225
  70. package/dist/ui/hooks/usePolicySafeKnowledgeAssistant.d.ts +49 -51
  71. package/dist/ui/hooks/usePolicySafeKnowledgeAssistant.d.ts.map +1 -1
  72. package/dist/ui/hooks/usePolicySafeKnowledgeAssistant.js +147 -185
  73. package/dist/ui/index.d.ts +2 -2
  74. package/dist/ui/index.d.ts.map +1 -0
  75. package/dist/ui/index.js +420 -2
  76. package/package.json +173 -44
  77. package/tsdown.config.js +1 -2
  78. package/.turbo/turbo-build$colon$bundle.log +0 -60
  79. package/dist/docs/policy-safe-knowledge-assistant.docblock.js.map +0 -1
  80. package/dist/example.js.map +0 -1
  81. package/dist/handlers/policy-safe-knowledge-assistant.handlers.js.map +0 -1
  82. package/dist/orchestrator/buildAnswer.js.map +0 -1
  83. package/dist/policy-safe-knowledge-assistant.feature.js.map +0 -1
  84. package/dist/seed/fixtures.js.map +0 -1
  85. package/dist/seeders/index.js.map +0 -1
  86. package/dist/ui/PolicySafeKnowledgeAssistantDashboard.js.map +0 -1
  87. package/dist/ui/hooks/usePolicySafeKnowledgeAssistant.js.map +0 -1
  88. package/tsconfig.tsbuildinfo +0 -1
@@ -1,231 +1,421 @@
1
- 'use client';
1
+ // @bun
2
+ // src/ui/hooks/usePolicySafeKnowledgeAssistant.ts
3
+ import { useCallback, useEffect, useMemo, useState } from "react";
4
+ import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
5
+ "use client";
6
+ function isCitationLike(value) {
7
+ if (!value || typeof value !== "object")
8
+ return false;
9
+ const v = value;
10
+ return typeof v.kbSnapshotId === "string" && typeof v.sourceId === "string";
11
+ }
12
+ function toCitations(value) {
13
+ if (!Array.isArray(value))
14
+ return [];
15
+ return value.filter(isCitationLike).map((c) => ({
16
+ kbSnapshotId: c.kbSnapshotId,
17
+ sourceId: c.sourceId,
18
+ excerpt: c.excerpt
19
+ }));
20
+ }
21
+ function usePolicySafeKnowledgeAssistant() {
22
+ const { handlers, projectId } = useTemplateRuntime();
23
+ const api = handlers.policySafeKnowledgeAssistant;
24
+ const [state, setState] = useState({
25
+ context: null,
26
+ loading: true,
27
+ error: null,
28
+ lastAnswer: null,
29
+ lastRuleId: null,
30
+ lastRuleVersionId: null,
31
+ lastSnapshotId: null,
32
+ lastReviewTaskId: null
33
+ });
34
+ const refreshContext = useCallback(async () => {
35
+ try {
36
+ setState((s) => ({ ...s, loading: true, error: null }));
37
+ const ctx = await api.getUserContext({ projectId });
38
+ setState((s) => ({
39
+ ...s,
40
+ context: {
41
+ locale: ctx.locale,
42
+ jurisdiction: ctx.jurisdiction,
43
+ allowedScope: ctx.allowedScope,
44
+ kbSnapshotId: ctx.kbSnapshotId
45
+ },
46
+ loading: false
47
+ }));
48
+ } catch (e) {
49
+ setState((s) => ({
50
+ ...s,
51
+ loading: false,
52
+ error: e instanceof Error ? e : new Error("Unknown error")
53
+ }));
54
+ }
55
+ }, [api, projectId]);
56
+ useEffect(() => {
57
+ refreshContext();
58
+ }, [refreshContext]);
59
+ const setContext = useCallback(async (input) => {
60
+ const ctx = await api.setUserContext({ projectId, ...input });
61
+ setState((s) => ({
62
+ ...s,
63
+ context: {
64
+ locale: ctx.locale,
65
+ jurisdiction: ctx.jurisdiction,
66
+ allowedScope: ctx.allowedScope,
67
+ kbSnapshotId: ctx.kbSnapshotId
68
+ }
69
+ }));
70
+ }, [api, projectId]);
71
+ const askAssistant = useCallback(async (question) => {
72
+ const answerUnknown = await api.answer({ projectId, question });
73
+ const answer = answerUnknown;
74
+ setState((s) => ({
75
+ ...s,
76
+ lastAnswer: {
77
+ refused: answer.refused,
78
+ refusalReason: answer.refusalReason,
79
+ sections: answer.sections,
80
+ citations: toCitations(answerUnknown.citations)
81
+ }
82
+ }));
83
+ }, [api, projectId]);
84
+ const createDemoRule = useCallback(async () => {
85
+ const rule = await api.createRule({
86
+ projectId,
87
+ jurisdiction: state.context?.jurisdiction ?? "EU",
88
+ topicKey: "tax_reporting"
89
+ });
90
+ setState((s) => ({ ...s, lastRuleId: rule.id }));
91
+ return rule.id;
92
+ }, [api, projectId, state.context?.jurisdiction]);
93
+ const upsertRuleVersion = useCallback(async (input) => {
94
+ const rv = await api.upsertRuleVersion({
95
+ projectId,
96
+ ruleId: input.ruleId,
97
+ content: input.content,
98
+ sourceRefs: [{ sourceDocumentId: "src_demo", excerpt: "demo excerpt" }]
99
+ });
100
+ setState((s) => ({ ...s, lastRuleVersionId: rv.id }));
101
+ return rv.id;
102
+ }, [api, projectId]);
103
+ const approveRuleVersion = useCallback(async (ruleVersionId) => {
104
+ await api.approveRuleVersion({ ruleVersionId, approver: "demo_expert" });
105
+ }, [api]);
106
+ const publishSnapshot = useCallback(async () => {
107
+ const snap = await api.publishSnapshot({
108
+ projectId,
109
+ jurisdiction: state.context?.jurisdiction ?? "EU",
110
+ asOfDate: new Date("2026-02-01T00:00:00.000Z")
111
+ });
112
+ setState((s) => ({ ...s, lastSnapshotId: snap.id }));
113
+ await refreshContext();
114
+ return snap.id;
115
+ }, [api, projectId, refreshContext, state.context?.jurisdiction]);
116
+ const simulateHighRiskChangeAndApprove = useCallback(async (ruleVersionId) => {
117
+ const cand = await api.createChangeCandidate({
118
+ projectId,
119
+ jurisdiction: state.context?.jurisdiction ?? "EU",
120
+ diffSummary: "Simulated change (demo)",
121
+ riskLevel: "high",
122
+ proposedRuleVersionIds: [ruleVersionId]
123
+ });
124
+ const review = await api.createReviewTask({ changeCandidateId: cand.id });
125
+ setState((s) => ({ ...s, lastReviewTaskId: review.id }));
126
+ await api.submitDecision({
127
+ reviewTaskId: review.id,
128
+ decision: "approve",
129
+ decidedByRole: "expert",
130
+ decidedBy: "demo_expert"
131
+ });
132
+ await api.publishIfReady({
133
+ jurisdiction: state.context?.jurisdiction ?? "EU"
134
+ });
135
+ return review.id;
136
+ }, [api, projectId, state.context?.jurisdiction]);
137
+ const derived = useMemo(() => ({ projectId }), [projectId]);
138
+ return {
139
+ state,
140
+ derived,
141
+ actions: {
142
+ refreshContext,
143
+ setContext,
144
+ askAssistant,
145
+ createDemoRule,
146
+ upsertRuleVersion,
147
+ approveRuleVersion,
148
+ publishSnapshot,
149
+ simulateHighRiskChangeAndApprove
150
+ }
151
+ };
152
+ }
2
153
 
3
- import { usePolicySafeKnowledgeAssistant } from "./hooks/usePolicySafeKnowledgeAssistant.js";
4
- import { useCallback, useMemo, useState } from "react";
5
- import { Button, ErrorState, LoaderBlock, StatCard, StatCardGroup } from "@contractspec/lib.design-system";
154
+ // src/ui/PolicySafeKnowledgeAssistantDashboard.tsx
155
+ import { useCallback as useCallback2, useMemo as useMemo2, useState as useState2 } from "react";
156
+ import {
157
+ Button,
158
+ ErrorState,
159
+ LoaderBlock,
160
+ StatCard,
161
+ StatCardGroup
162
+ } from "@contractspec/lib.design-system";
6
163
  import { Card } from "@contractspec/lib.ui-kit-web/ui/card";
7
164
  import { Input } from "@contractspec/lib.ui-kit-web/ui/input";
8
165
  import { Textarea } from "@contractspec/lib.ui-kit-web/ui/textarea";
9
- import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@contractspec/lib.ui-kit-web/ui/select";
10
- import { jsx, jsxs } from "react/jsx-runtime";
11
-
12
- //#region src/ui/PolicySafeKnowledgeAssistantDashboard.tsx
166
+ import {
167
+ Select,
168
+ SelectContent,
169
+ SelectItem,
170
+ SelectTrigger,
171
+ SelectValue
172
+ } from "@contractspec/lib.ui-kit-web/ui/select";
173
+ import { jsxDEV } from "react/jsx-dev-runtime";
174
+ "use client";
13
175
  function PolicySafeKnowledgeAssistantDashboard() {
14
- const { state, actions } = usePolicySafeKnowledgeAssistant();
15
- const [question, setQuestion] = useState("reporting obligations");
16
- const [content, setContent] = useState("EU: Reporting obligations v2 (updated)");
17
- const [locale, setLocale] = useState("en-GB");
18
- const [jurisdiction, setJurisdiction] = useState("EU");
19
- const [allowedScope, setAllowedScope] = useState("education_only");
20
- const snapshotId = state.context?.kbSnapshotId ?? state.lastSnapshotId ?? null;
21
- const stats = useMemo(() => {
22
- return [
23
- {
24
- label: "Locale",
25
- value: state.context?.locale ?? ""
26
- },
27
- {
28
- label: "Jurisdiction",
29
- value: state.context?.jurisdiction ?? "—"
30
- },
31
- {
32
- label: "Scope",
33
- value: state.context?.allowedScope ?? "—"
34
- },
35
- {
36
- label: "KB Snapshot",
37
- value: snapshotId ?? "—"
38
- }
39
- ];
40
- }, [
41
- snapshotId,
42
- state.context?.allowedScope,
43
- state.context?.jurisdiction,
44
- state.context?.locale
45
- ]);
46
- const handleSetContext = useCallback(async () => {
47
- await actions.setContext({
48
- locale,
49
- jurisdiction,
50
- allowedScope
51
- });
52
- }, [
53
- actions,
54
- allowedScope,
55
- jurisdiction,
56
- locale
57
- ]);
58
- const handleAsk = useCallback(async () => {
59
- await actions.askAssistant(question);
60
- }, [actions, question]);
61
- const handleAdminPublishFlow = useCallback(async () => {
62
- const ruleId = state.lastRuleId ?? await actions.createDemoRule();
63
- const rvId = await actions.upsertRuleVersion({
64
- ruleId,
65
- content
66
- });
67
- await actions.approveRuleVersion(rvId);
68
- await actions.simulateHighRiskChangeAndApprove(rvId);
69
- await actions.publishSnapshot();
70
- }, [
71
- actions,
72
- content,
73
- state.lastRuleId
74
- ]);
75
- if (state.loading && !state.context) return /* @__PURE__ */ jsx(LoaderBlock, { label: "Loading demo..." });
76
- if (state.error) return /* @__PURE__ */ jsx(ErrorState, {
77
- title: "Failed to load demo",
78
- description: state.error.message,
79
- onRetry: actions.refreshContext,
80
- retryLabel: "Retry"
81
- });
82
- return /* @__PURE__ */ jsxs("div", {
83
- className: "space-y-6",
84
- children: [
85
- /* @__PURE__ */ jsx(StatCardGroup, { children: stats.map((s) => /* @__PURE__ */ jsx(StatCard, {
86
- label: s.label,
87
- value: String(s.value)
88
- }, s.label)) }),
89
- /* @__PURE__ */ jsxs(Card, {
90
- className: "p-4",
91
- children: [
92
- /* @__PURE__ */ jsx("h3", {
93
- className: "text-lg font-semibold",
94
- children: "1) Onboarding (explicit locale + jurisdiction)"
95
- }),
96
- /* @__PURE__ */ jsxs("div", {
97
- className: "mt-3 grid gap-3 md:grid-cols-3",
98
- children: [
99
- /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
100
- className: "text-muted-foreground mb-1 text-xs font-semibold tracking-wide uppercase",
101
- children: "Locale"
102
- }), /* @__PURE__ */ jsx(Input, {
103
- value: locale,
104
- onChange: (e) => setLocale(e.target.value)
105
- })] }),
106
- /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
107
- className: "text-muted-foreground mb-1 text-xs font-semibold tracking-wide uppercase",
108
- children: "Jurisdiction"
109
- }), /* @__PURE__ */ jsx(Input, {
110
- value: jurisdiction,
111
- onChange: (e) => setJurisdiction(e.target.value)
112
- })] }),
113
- /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
114
- className: "text-muted-foreground mb-1 text-xs font-semibold tracking-wide uppercase",
115
- children: "Allowed scope"
116
- }), /* @__PURE__ */ jsxs(Select, {
117
- value: allowedScope,
118
- onValueChange: (v) => setAllowedScope(v),
119
- children: [/* @__PURE__ */ jsx(SelectTrigger, { children: /* @__PURE__ */ jsx(SelectValue, { placeholder: "Select scope" }) }), /* @__PURE__ */ jsxs(SelectContent, { children: [
120
- /* @__PURE__ */ jsx(SelectItem, {
121
- value: "education_only",
122
- children: "education_only"
123
- }),
124
- /* @__PURE__ */ jsx(SelectItem, {
125
- value: "generic_info",
126
- children: "generic_info"
127
- }),
128
- /* @__PURE__ */ jsx(SelectItem, {
129
- value: "escalation_required",
130
- children: "escalation_required"
131
- })
132
- ] })]
133
- })] })
134
- ]
135
- }),
136
- /* @__PURE__ */ jsxs("div", {
137
- className: "mt-4 flex gap-2",
138
- children: [/* @__PURE__ */ jsx(Button, {
139
- onPress: handleSetContext,
140
- children: "Save context"
141
- }), /* @__PURE__ */ jsx(Button, {
142
- variant: "outline",
143
- onPress: actions.refreshContext,
144
- children: "Refresh"
145
- })]
146
- })
147
- ]
148
- }),
149
- /* @__PURE__ */ jsxs(Card, {
150
- className: "p-4",
151
- children: [
152
- /* @__PURE__ */ jsx("h3", {
153
- className: "text-lg font-semibold",
154
- children: "2) Ask the assistant (must cite KB snapshot)"
155
- }),
156
- /* @__PURE__ */ jsxs("div", {
157
- className: "mt-3 flex flex-col gap-3",
158
- children: [/* @__PURE__ */ jsx(Input, {
159
- value: question,
160
- onChange: (e) => setQuestion(e.target.value)
161
- }), /* @__PURE__ */ jsx("div", {
162
- className: "flex gap-2",
163
- children: /* @__PURE__ */ jsx(Button, {
164
- onPress: handleAsk,
165
- children: "Ask"
166
- })
167
- })]
168
- }),
169
- state.lastAnswer ? /* @__PURE__ */ jsxs("div", {
170
- className: "mt-4 space-y-3",
171
- children: [
172
- state.lastAnswer.refused ? /* @__PURE__ */ jsxs("div", {
173
- className: "text-sm text-red-600",
174
- children: ["Refused: ", state.lastAnswer.refusalReason ?? "UNKNOWN"]
175
- }) : null,
176
- state.lastAnswer.sections.map((s, idx) => /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
177
- className: "text-sm font-semibold",
178
- children: s.heading
179
- }), /* @__PURE__ */ jsx("div", {
180
- className: "text-muted-foreground text-sm",
181
- children: s.body
182
- })] }, `${s.heading}-${idx}`)),
183
- /* @__PURE__ */ jsx("div", {
184
- className: "text-sm font-semibold",
185
- children: "Citations"
186
- }),
187
- /* @__PURE__ */ jsx("ul", {
188
- className: "text-muted-foreground list-disc pl-5 text-sm",
189
- children: state.lastAnswer.citations.map((c) => /* @__PURE__ */ jsxs("li", { children: [
190
- c.kbSnapshotId,
191
- " ",
192
- c.sourceId
193
- ] }, `${c.kbSnapshotId}-${c.sourceId}`))
194
- })
195
- ]
196
- }) : null
197
- ]
198
- }),
199
- /* @__PURE__ */ jsxs(Card, {
200
- className: "p-4",
201
- children: [/* @__PURE__ */ jsx("h3", {
202
- className: "text-lg font-semibold",
203
- children: "3) Admin: publish a new snapshot (HITL)"
204
- }), /* @__PURE__ */ jsxs("div", {
205
- className: "mt-3 space-y-3",
206
- children: [/* @__PURE__ */ jsx(Textarea, {
207
- value: content,
208
- onChange: (e) => setContent(e.target.value)
209
- }), /* @__PURE__ */ jsx(Button, {
210
- onPress: handleAdminPublishFlow,
211
- children: "Simulate change → review → approve → publish snapshot"
212
- })]
213
- })]
214
- }),
215
- /* @__PURE__ */ jsxs(Card, {
216
- className: "p-4",
217
- children: [/* @__PURE__ */ jsx("h3", {
218
- className: "text-lg font-semibold",
219
- children: "4) Learning hub (patterns)"
220
- }), /* @__PURE__ */ jsx("p", {
221
- className: "text-muted-foreground mt-2 text-sm",
222
- children: "This template includes drills, ambient coach, and quests as reusable Learning Journey tracks. The interactive learning UI is demonstrated in dedicated Learning Journey examples."
223
- })]
224
- })
225
- ]
226
- });
176
+ const { state, actions } = usePolicySafeKnowledgeAssistant();
177
+ const [question, setQuestion] = useState2("reporting obligations");
178
+ const [content, setContent] = useState2("EU: Reporting obligations v2 (updated)");
179
+ const [locale, setLocale] = useState2("en-GB");
180
+ const [jurisdiction, setJurisdiction] = useState2("EU");
181
+ const [allowedScope, setAllowedScope] = useState2("education_only");
182
+ const snapshotId = state.context?.kbSnapshotId ?? state.lastSnapshotId ?? null;
183
+ const stats = useMemo2(() => {
184
+ return [
185
+ { label: "Locale", value: state.context?.locale ?? "\u2014" },
186
+ { label: "Jurisdiction", value: state.context?.jurisdiction ?? "\u2014" },
187
+ { label: "Scope", value: state.context?.allowedScope ?? "\u2014" },
188
+ { label: "KB Snapshot", value: snapshotId ?? "\u2014" }
189
+ ];
190
+ }, [
191
+ snapshotId,
192
+ state.context?.allowedScope,
193
+ state.context?.jurisdiction,
194
+ state.context?.locale
195
+ ]);
196
+ const handleSetContext = useCallback2(async () => {
197
+ await actions.setContext({ locale, jurisdiction, allowedScope });
198
+ }, [actions, allowedScope, jurisdiction, locale]);
199
+ const handleAsk = useCallback2(async () => {
200
+ await actions.askAssistant(question);
201
+ }, [actions, question]);
202
+ const handleAdminPublishFlow = useCallback2(async () => {
203
+ const ruleId = state.lastRuleId ?? await actions.createDemoRule();
204
+ const rvId = await actions.upsertRuleVersion({ ruleId, content });
205
+ await actions.approveRuleVersion(rvId);
206
+ await actions.simulateHighRiskChangeAndApprove(rvId);
207
+ await actions.publishSnapshot();
208
+ }, [actions, content, state.lastRuleId]);
209
+ if (state.loading && !state.context) {
210
+ return /* @__PURE__ */ jsxDEV(LoaderBlock, {
211
+ label: "Loading demo..."
212
+ }, undefined, false, undefined, this);
213
+ }
214
+ if (state.error) {
215
+ return /* @__PURE__ */ jsxDEV(ErrorState, {
216
+ title: "Failed to load demo",
217
+ description: state.error.message,
218
+ onRetry: actions.refreshContext,
219
+ retryLabel: "Retry"
220
+ }, undefined, false, undefined, this);
221
+ }
222
+ return /* @__PURE__ */ jsxDEV("div", {
223
+ className: "space-y-6",
224
+ children: [
225
+ /* @__PURE__ */ jsxDEV(StatCardGroup, {
226
+ children: stats.map((s) => /* @__PURE__ */ jsxDEV(StatCard, {
227
+ label: s.label,
228
+ value: String(s.value)
229
+ }, s.label, false, undefined, this))
230
+ }, undefined, false, undefined, this),
231
+ /* @__PURE__ */ jsxDEV(Card, {
232
+ className: "p-4",
233
+ children: [
234
+ /* @__PURE__ */ jsxDEV("h3", {
235
+ className: "text-lg font-semibold",
236
+ children: "1) Onboarding (explicit locale + jurisdiction)"
237
+ }, undefined, false, undefined, this),
238
+ /* @__PURE__ */ jsxDEV("div", {
239
+ className: "mt-3 grid gap-3 md:grid-cols-3",
240
+ children: [
241
+ /* @__PURE__ */ jsxDEV("div", {
242
+ children: [
243
+ /* @__PURE__ */ jsxDEV("div", {
244
+ className: "text-muted-foreground mb-1 text-xs font-semibold tracking-wide uppercase",
245
+ children: "Locale"
246
+ }, undefined, false, undefined, this),
247
+ /* @__PURE__ */ jsxDEV(Input, {
248
+ value: locale,
249
+ onChange: (e) => setLocale(e.target.value)
250
+ }, undefined, false, undefined, this)
251
+ ]
252
+ }, undefined, true, undefined, this),
253
+ /* @__PURE__ */ jsxDEV("div", {
254
+ children: [
255
+ /* @__PURE__ */ jsxDEV("div", {
256
+ className: "text-muted-foreground mb-1 text-xs font-semibold tracking-wide uppercase",
257
+ children: "Jurisdiction"
258
+ }, undefined, false, undefined, this),
259
+ /* @__PURE__ */ jsxDEV(Input, {
260
+ value: jurisdiction,
261
+ onChange: (e) => setJurisdiction(e.target.value)
262
+ }, undefined, false, undefined, this)
263
+ ]
264
+ }, undefined, true, undefined, this),
265
+ /* @__PURE__ */ jsxDEV("div", {
266
+ children: [
267
+ /* @__PURE__ */ jsxDEV("div", {
268
+ className: "text-muted-foreground mb-1 text-xs font-semibold tracking-wide uppercase",
269
+ children: "Allowed scope"
270
+ }, undefined, false, undefined, this),
271
+ /* @__PURE__ */ jsxDEV(Select, {
272
+ value: allowedScope,
273
+ onValueChange: (v) => setAllowedScope(v),
274
+ children: [
275
+ /* @__PURE__ */ jsxDEV(SelectTrigger, {
276
+ children: /* @__PURE__ */ jsxDEV(SelectValue, {
277
+ placeholder: "Select scope"
278
+ }, undefined, false, undefined, this)
279
+ }, undefined, false, undefined, this),
280
+ /* @__PURE__ */ jsxDEV(SelectContent, {
281
+ children: [
282
+ /* @__PURE__ */ jsxDEV(SelectItem, {
283
+ value: "education_only",
284
+ children: "education_only"
285
+ }, undefined, false, undefined, this),
286
+ /* @__PURE__ */ jsxDEV(SelectItem, {
287
+ value: "generic_info",
288
+ children: "generic_info"
289
+ }, undefined, false, undefined, this),
290
+ /* @__PURE__ */ jsxDEV(SelectItem, {
291
+ value: "escalation_required",
292
+ children: "escalation_required"
293
+ }, undefined, false, undefined, this)
294
+ ]
295
+ }, undefined, true, undefined, this)
296
+ ]
297
+ }, undefined, true, undefined, this)
298
+ ]
299
+ }, undefined, true, undefined, this)
300
+ ]
301
+ }, undefined, true, undefined, this),
302
+ /* @__PURE__ */ jsxDEV("div", {
303
+ className: "mt-4 flex gap-2",
304
+ children: [
305
+ /* @__PURE__ */ jsxDEV(Button, {
306
+ onPress: handleSetContext,
307
+ children: "Save context"
308
+ }, undefined, false, undefined, this),
309
+ /* @__PURE__ */ jsxDEV(Button, {
310
+ variant: "outline",
311
+ onPress: actions.refreshContext,
312
+ children: "Refresh"
313
+ }, undefined, false, undefined, this)
314
+ ]
315
+ }, undefined, true, undefined, this)
316
+ ]
317
+ }, undefined, true, undefined, this),
318
+ /* @__PURE__ */ jsxDEV(Card, {
319
+ className: "p-4",
320
+ children: [
321
+ /* @__PURE__ */ jsxDEV("h3", {
322
+ className: "text-lg font-semibold",
323
+ children: "2) Ask the assistant (must cite KB snapshot)"
324
+ }, undefined, false, undefined, this),
325
+ /* @__PURE__ */ jsxDEV("div", {
326
+ className: "mt-3 flex flex-col gap-3",
327
+ children: [
328
+ /* @__PURE__ */ jsxDEV(Input, {
329
+ value: question,
330
+ onChange: (e) => setQuestion(e.target.value)
331
+ }, undefined, false, undefined, this),
332
+ /* @__PURE__ */ jsxDEV("div", {
333
+ className: "flex gap-2",
334
+ children: /* @__PURE__ */ jsxDEV(Button, {
335
+ onPress: handleAsk,
336
+ children: "Ask"
337
+ }, undefined, false, undefined, this)
338
+ }, undefined, false, undefined, this)
339
+ ]
340
+ }, undefined, true, undefined, this),
341
+ state.lastAnswer ? /* @__PURE__ */ jsxDEV("div", {
342
+ className: "mt-4 space-y-3",
343
+ children: [
344
+ state.lastAnswer.refused ? /* @__PURE__ */ jsxDEV("div", {
345
+ className: "text-sm text-red-600",
346
+ children: [
347
+ "Refused: ",
348
+ state.lastAnswer.refusalReason ?? "UNKNOWN"
349
+ ]
350
+ }, undefined, true, undefined, this) : null,
351
+ state.lastAnswer.sections.map((s, idx) => /* @__PURE__ */ jsxDEV("div", {
352
+ children: [
353
+ /* @__PURE__ */ jsxDEV("div", {
354
+ className: "text-sm font-semibold",
355
+ children: s.heading
356
+ }, undefined, false, undefined, this),
357
+ /* @__PURE__ */ jsxDEV("div", {
358
+ className: "text-muted-foreground text-sm",
359
+ children: s.body
360
+ }, undefined, false, undefined, this)
361
+ ]
362
+ }, `${s.heading}-${idx}`, true, undefined, this)),
363
+ /* @__PURE__ */ jsxDEV("div", {
364
+ className: "text-sm font-semibold",
365
+ children: "Citations"
366
+ }, undefined, false, undefined, this),
367
+ /* @__PURE__ */ jsxDEV("ul", {
368
+ className: "text-muted-foreground list-disc pl-5 text-sm",
369
+ children: state.lastAnswer.citations.map((c) => /* @__PURE__ */ jsxDEV("li", {
370
+ children: [
371
+ c.kbSnapshotId,
372
+ " \u2014 ",
373
+ c.sourceId
374
+ ]
375
+ }, `${c.kbSnapshotId}-${c.sourceId}`, true, undefined, this))
376
+ }, undefined, false, undefined, this)
377
+ ]
378
+ }, undefined, true, undefined, this) : null
379
+ ]
380
+ }, undefined, true, undefined, this),
381
+ /* @__PURE__ */ jsxDEV(Card, {
382
+ className: "p-4",
383
+ children: [
384
+ /* @__PURE__ */ jsxDEV("h3", {
385
+ className: "text-lg font-semibold",
386
+ children: "3) Admin: publish a new snapshot (HITL)"
387
+ }, undefined, false, undefined, this),
388
+ /* @__PURE__ */ jsxDEV("div", {
389
+ className: "mt-3 space-y-3",
390
+ children: [
391
+ /* @__PURE__ */ jsxDEV(Textarea, {
392
+ value: content,
393
+ onChange: (e) => setContent(e.target.value)
394
+ }, undefined, false, undefined, this),
395
+ /* @__PURE__ */ jsxDEV(Button, {
396
+ onPress: handleAdminPublishFlow,
397
+ children: "Simulate change \u2192 review \u2192 approve \u2192 publish snapshot"
398
+ }, undefined, false, undefined, this)
399
+ ]
400
+ }, undefined, true, undefined, this)
401
+ ]
402
+ }, undefined, true, undefined, this),
403
+ /* @__PURE__ */ jsxDEV(Card, {
404
+ className: "p-4",
405
+ children: [
406
+ /* @__PURE__ */ jsxDEV("h3", {
407
+ className: "text-lg font-semibold",
408
+ children: "4) Learning hub (patterns)"
409
+ }, undefined, false, undefined, this),
410
+ /* @__PURE__ */ jsxDEV("p", {
411
+ className: "text-muted-foreground mt-2 text-sm",
412
+ children: "This template includes drills, ambient coach, and quests as reusable Learning Journey tracks. The interactive learning UI is demonstrated in dedicated Learning Journey examples."
413
+ }, undefined, false, undefined, this)
414
+ ]
415
+ }, undefined, true, undefined, this)
416
+ ]
417
+ }, undefined, true, undefined, this);
227
418
  }
228
-
229
- //#endregion
230
- export { PolicySafeKnowledgeAssistantDashboard };
231
- //# sourceMappingURL=PolicySafeKnowledgeAssistantDashboard.js.map
419
+ export {
420
+ PolicySafeKnowledgeAssistantDashboard
421
+ };