@booki-aui/react 0.0.0-stage → 0.2.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/CHANGELOG.md +122 -0
- package/LICENSE +21 -0
- package/README.md +16 -2
- package/dist/access.d.ts +43 -0
- package/dist/access.js +15 -0
- package/dist/access.js.map +1 -0
- package/dist/account-picker.d.ts +40 -0
- package/dist/account-picker.js +25 -0
- package/dist/account-picker.js.map +1 -0
- package/dist/accounting-period-select.d.ts +34 -0
- package/dist/accounting-period-select.js +23 -0
- package/dist/accounting-period-select.js.map +1 -0
- package/dist/activity-timeline.d.ts +37 -0
- package/dist/activity-timeline.js +19 -0
- package/dist/activity-timeline.js.map +1 -0
- package/dist/aged-balances.d.ts +62 -0
- package/dist/aged-balances.js +31 -0
- package/dist/aged-balances.js.map +1 -0
- package/dist/agent-cursor.d.ts +34 -0
- package/dist/agent-cursor.js +14 -0
- package/dist/agent-cursor.js.map +1 -0
- package/dist/agent-presence.d.ts +110 -0
- package/dist/agent-presence.js +15 -0
- package/dist/agent-presence.js.map +1 -0
- package/dist/aging-chart.d.ts +41 -0
- package/dist/aging-chart.js +19 -0
- package/dist/aging-chart.js.map +1 -0
- package/dist/amount-field.d.ts +46 -0
- package/dist/amount-field.js +19 -0
- package/dist/amount-field.js.map +1 -0
- package/dist/amount-input.d.ts +18 -0
- package/dist/amount-input.js +12 -0
- package/dist/amount-input.js.map +1 -0
- package/dist/approval-chain.d.ts +36 -0
- package/dist/approval-chain.js +22 -0
- package/dist/approval-chain.js.map +1 -0
- package/dist/approval-gate.d.ts +19 -0
- package/dist/approval-gate.js +10 -0
- package/dist/approval-gate.js.map +1 -0
- package/dist/attestation-status.d.ts +31 -0
- package/dist/attestation-status.js +22 -0
- package/dist/attestation-status.js.map +1 -0
- package/dist/audit-findings.d.ts +40 -0
- package/dist/audit-findings.js +28 -0
- package/dist/audit-findings.js.map +1 -0
- package/dist/audit-trail.d.ts +22 -0
- package/dist/audit-trail.js +10 -0
- package/dist/audit-trail.js.map +1 -0
- package/dist/audit-workpaper.d.ts +56 -0
- package/dist/audit-workpaper.js +35 -0
- package/dist/audit-workpaper.js.map +1 -0
- package/dist/bank-account-input.d.ts +36 -0
- package/dist/bank-account-input.js +22 -0
- package/dist/bank-account-input.js.map +1 -0
- package/dist/bank-reconciliation.d.ts +38 -0
- package/dist/bank-reconciliation.js +20 -0
- package/dist/bank-reconciliation.js.map +1 -0
- package/dist/bar-chart.d.ts +38 -0
- package/dist/bar-chart.js +19 -0
- package/dist/bar-chart.js.map +1 -0
- package/dist/booki-agent.d.ts +153 -0
- package/dist/booki-agent.js +27 -0
- package/dist/booki-agent.js.map +1 -0
- package/dist/cashflow-waterfall.d.ts +36 -0
- package/dist/cashflow-waterfall.js +17 -0
- package/dist/cashflow-waterfall.js.map +1 -0
- package/dist/change-details-CWpEgc80.d.ts +14 -0
- package/dist/chunk-2HM7YSBC.js +92 -0
- package/dist/chunk-2HM7YSBC.js.map +1 -0
- package/dist/chunk-35QKOOAI.js +27 -0
- package/dist/chunk-35QKOOAI.js.map +1 -0
- package/dist/chunk-37GDU76M.js +86 -0
- package/dist/chunk-37GDU76M.js.map +1 -0
- package/dist/chunk-4EVVT6ME.js +136 -0
- package/dist/chunk-4EVVT6ME.js.map +1 -0
- package/dist/chunk-4GQUOBOG.js +132 -0
- package/dist/chunk-4GQUOBOG.js.map +1 -0
- package/dist/chunk-4KWEZTO5.js +86 -0
- package/dist/chunk-4KWEZTO5.js.map +1 -0
- package/dist/chunk-4WC76FUE.js +242 -0
- package/dist/chunk-4WC76FUE.js.map +1 -0
- package/dist/chunk-62G3T2AA.js +230 -0
- package/dist/chunk-62G3T2AA.js.map +1 -0
- package/dist/chunk-663UXACN.js +334 -0
- package/dist/chunk-663UXACN.js.map +1 -0
- package/dist/chunk-6CVPNV7N.js +106 -0
- package/dist/chunk-6CVPNV7N.js.map +1 -0
- package/dist/chunk-6HWFMC7V.js +140 -0
- package/dist/chunk-6HWFMC7V.js.map +1 -0
- package/dist/chunk-7MYFKLPB.js +301 -0
- package/dist/chunk-7MYFKLPB.js.map +1 -0
- package/dist/chunk-7YTOVA5F.js +312 -0
- package/dist/chunk-7YTOVA5F.js.map +1 -0
- package/dist/chunk-AIGQPM4Y.js +311 -0
- package/dist/chunk-AIGQPM4Y.js.map +1 -0
- package/dist/chunk-AKC6N4QO.js +414 -0
- package/dist/chunk-AKC6N4QO.js.map +1 -0
- package/dist/chunk-BZIOOU4I.js +421 -0
- package/dist/chunk-BZIOOU4I.js.map +1 -0
- package/dist/chunk-CDTDN4LY.js +212 -0
- package/dist/chunk-CDTDN4LY.js.map +1 -0
- package/dist/chunk-EDWQSKY7.js +161 -0
- package/dist/chunk-EDWQSKY7.js.map +1 -0
- package/dist/chunk-EKIWL37F.js +488 -0
- package/dist/chunk-EKIWL37F.js.map +1 -0
- package/dist/chunk-F3C77WLR.js +116 -0
- package/dist/chunk-F3C77WLR.js.map +1 -0
- package/dist/chunk-FBV7BFEQ.js +84 -0
- package/dist/chunk-FBV7BFEQ.js.map +1 -0
- package/dist/chunk-GVP2N3K6.js +89 -0
- package/dist/chunk-GVP2N3K6.js.map +1 -0
- package/dist/chunk-HKYEHBQT.js +19 -0
- package/dist/chunk-HKYEHBQT.js.map +1 -0
- package/dist/chunk-HQYIFZZT.js +169 -0
- package/dist/chunk-HQYIFZZT.js.map +1 -0
- package/dist/chunk-HT6HGOLM.js +151 -0
- package/dist/chunk-HT6HGOLM.js.map +1 -0
- package/dist/chunk-ISPUO3AQ.js +244 -0
- package/dist/chunk-ISPUO3AQ.js.map +1 -0
- package/dist/chunk-JPUVGWLO.js +207 -0
- package/dist/chunk-JPUVGWLO.js.map +1 -0
- package/dist/chunk-JWFGUI7A.js +73 -0
- package/dist/chunk-JWFGUI7A.js.map +1 -0
- package/dist/chunk-K72VT6RJ.js +57 -0
- package/dist/chunk-K72VT6RJ.js.map +1 -0
- package/dist/chunk-KLDUGI7L.js +150 -0
- package/dist/chunk-KLDUGI7L.js.map +1 -0
- package/dist/chunk-M2WLQIFE.js +40 -0
- package/dist/chunk-M2WLQIFE.js.map +1 -0
- package/dist/chunk-M3MCIKF2.js +143 -0
- package/dist/chunk-M3MCIKF2.js.map +1 -0
- package/dist/chunk-MBLQSZHE.js +77 -0
- package/dist/chunk-MBLQSZHE.js.map +1 -0
- package/dist/chunk-N7GIVDUU.js +191 -0
- package/dist/chunk-N7GIVDUU.js.map +1 -0
- package/dist/chunk-NMHTPP6I.js +62 -0
- package/dist/chunk-NMHTPP6I.js.map +1 -0
- package/dist/chunk-NNP6GNEW.js +65 -0
- package/dist/chunk-NNP6GNEW.js.map +1 -0
- package/dist/chunk-OTD7VUEC.js +35 -0
- package/dist/chunk-OTD7VUEC.js.map +1 -0
- package/dist/chunk-OXHKA3UZ.js +30 -0
- package/dist/chunk-OXHKA3UZ.js.map +1 -0
- package/dist/chunk-OYERLEER.js +21 -0
- package/dist/chunk-OYERLEER.js.map +1 -0
- package/dist/chunk-PFY3VJ2T.js +231 -0
- package/dist/chunk-PFY3VJ2T.js.map +1 -0
- package/dist/chunk-PUMSFFEU.js +228 -0
- package/dist/chunk-PUMSFFEU.js.map +1 -0
- package/dist/chunk-QE7KUQOI.js +84 -0
- package/dist/chunk-QE7KUQOI.js.map +1 -0
- package/dist/chunk-QGT7VI6I.js +35 -0
- package/dist/chunk-QGT7VI6I.js.map +1 -0
- package/dist/chunk-QGYS5HS3.js +214 -0
- package/dist/chunk-QGYS5HS3.js.map +1 -0
- package/dist/chunk-QPSBRSBH.js +167 -0
- package/dist/chunk-QPSBRSBH.js.map +1 -0
- package/dist/chunk-ROXGVKR2.js +59 -0
- package/dist/chunk-ROXGVKR2.js.map +1 -0
- package/dist/chunk-RPONJDFZ.js +310 -0
- package/dist/chunk-RPONJDFZ.js.map +1 -0
- package/dist/chunk-RTCKV4H2.js +65 -0
- package/dist/chunk-RTCKV4H2.js.map +1 -0
- package/dist/chunk-SHZFZRHV.js +259 -0
- package/dist/chunk-SHZFZRHV.js.map +1 -0
- package/dist/chunk-SOXPKIQK.js +91 -0
- package/dist/chunk-SOXPKIQK.js.map +1 -0
- package/dist/chunk-SR2HEE4U.js +76 -0
- package/dist/chunk-SR2HEE4U.js.map +1 -0
- package/dist/chunk-SX3U6DRW.js +462 -0
- package/dist/chunk-SX3U6DRW.js.map +1 -0
- package/dist/chunk-T4U2CT35.js +175 -0
- package/dist/chunk-T4U2CT35.js.map +1 -0
- package/dist/chunk-TSX6BD72.js +251 -0
- package/dist/chunk-TSX6BD72.js.map +1 -0
- package/dist/chunk-U6PR3V2Q.js +123 -0
- package/dist/chunk-U6PR3V2Q.js.map +1 -0
- package/dist/chunk-U7NPK4WO.js +135 -0
- package/dist/chunk-U7NPK4WO.js.map +1 -0
- package/dist/chunk-W6TKXS75.js +55 -0
- package/dist/chunk-W6TKXS75.js.map +1 -0
- package/dist/chunk-WDME4U42.js +14 -0
- package/dist/chunk-WDME4U42.js.map +1 -0
- package/dist/chunk-WS2YJSNS.js +62 -0
- package/dist/chunk-WS2YJSNS.js.map +1 -0
- package/dist/chunk-Y5EYY6WJ.js +174 -0
- package/dist/chunk-Y5EYY6WJ.js.map +1 -0
- package/dist/chunk-YBMO3W5O.js +191 -0
- package/dist/chunk-YBMO3W5O.js.map +1 -0
- package/dist/chunk-YOOWFGCU.js +90 -0
- package/dist/chunk-YOOWFGCU.js.map +1 -0
- package/dist/chunk-ZKNVWQDU.js +230 -0
- package/dist/chunk-ZKNVWQDU.js.map +1 -0
- package/dist/chunk-ZYLWSGWQ.js +29 -0
- package/dist/chunk-ZYLWSGWQ.js.map +1 -0
- package/dist/chunk-ZYPW7GCI.js +82 -0
- package/dist/chunk-ZYPW7GCI.js.map +1 -0
- package/dist/client-requests.d.ts +40 -0
- package/dist/client-requests.js +25 -0
- package/dist/client-requests.js.map +1 -0
- package/dist/close-checklist.d.ts +34 -0
- package/dist/close-checklist.js +22 -0
- package/dist/close-checklist.js.map +1 -0
- package/dist/confirm-dialog.d.ts +43 -0
- package/dist/confirm-dialog.js +10 -0
- package/dist/confirm-dialog.js.map +1 -0
- package/dist/country-toggle.d.ts +16 -0
- package/dist/country-toggle.js +10 -0
- package/dist/country-toggle.js.map +1 -0
- package/dist/currency-select.d.ts +32 -0
- package/dist/currency-select.js +23 -0
- package/dist/currency-select.js.map +1 -0
- package/dist/data-table.d.ts +77 -0
- package/dist/data-table.js +30 -0
- package/dist/data-table.js.map +1 -0
- package/dist/deal-pipeline.d.ts +46 -0
- package/dist/deal-pipeline.js +25 -0
- package/dist/deal-pipeline.js.map +1 -0
- package/dist/document-signoff.d.ts +45 -0
- package/dist/document-signoff.js +21 -0
- package/dist/document-signoff.js.map +1 -0
- package/dist/evidence-list.d.ts +35 -0
- package/dist/evidence-list.js +21 -0
- package/dist/evidence-list.js.map +1 -0
- package/dist/exception-banner.d.ts +15 -0
- package/dist/exception-banner.js +10 -0
- package/dist/exception-banner.js.map +1 -0
- package/dist/expense-claim.d.ts +43 -0
- package/dist/expense-claim.js +31 -0
- package/dist/expense-claim.js.map +1 -0
- package/dist/financial-date-field.d.ts +27 -0
- package/dist/financial-date-field.js +17 -0
- package/dist/financial-date-field.js.map +1 -0
- package/dist/fixed-asset-register.d.ts +59 -0
- package/dist/fixed-asset-register.js +31 -0
- package/dist/fixed-asset-register.js.map +1 -0
- package/dist/forecast-chart.d.ts +38 -0
- package/dist/forecast-chart.js +19 -0
- package/dist/forecast-chart.js.map +1 -0
- package/dist/form-props-Ct7zeZBH.d.ts +25 -0
- package/dist/funnel-chart.d.ts +27 -0
- package/dist/funnel-chart.js +17 -0
- package/dist/funnel-chart.js.map +1 -0
- package/dist/iban-input.d.ts +27 -0
- package/dist/iban-input.js +16 -0
- package/dist/iban-input.js.map +1 -0
- package/dist/index.d.ts +644 -0
- package/dist/index.js +1082 -0
- package/dist/index.js.map +1 -0
- package/dist/invoice-editor.d.ts +38 -0
- package/dist/invoice-editor.js +26 -0
- package/dist/invoice-editor.js.map +1 -0
- package/dist/invoice-number-input.d.ts +25 -0
- package/dist/invoice-number-input.js +17 -0
- package/dist/invoice-number-input.js.map +1 -0
- package/dist/kpi-stat.d.ts +34 -0
- package/dist/kpi-stat.js +15 -0
- package/dist/kpi-stat.js.map +1 -0
- package/dist/ledger-table.d.ts +85 -0
- package/dist/ledger-table.js +41 -0
- package/dist/ledger-table.js.map +1 -0
- package/dist/locale.d.ts +22 -0
- package/dist/locale.js +13 -0
- package/dist/locale.js.map +1 -0
- package/dist/money-amount.d.ts +15 -0
- package/dist/money-amount.js +10 -0
- package/dist/money-amount.js.map +1 -0
- package/dist/organization-number-input.d.ts +25 -0
- package/dist/organization-number-input.js +17 -0
- package/dist/organization-number-input.js.map +1 -0
- package/dist/payment-batch.d.ts +58 -0
- package/dist/payment-batch.js +31 -0
- package/dist/payment-batch.js.map +1 -0
- package/dist/payment-confirm.d.ts +19 -0
- package/dist/payment-confirm.js +11 -0
- package/dist/payment-confirm.js.map +1 -0
- package/dist/payment-reference-input.d.ts +27 -0
- package/dist/payment-reference-input.js +17 -0
- package/dist/payment-reference-input.js.map +1 -0
- package/dist/period-lock.d.ts +28 -0
- package/dist/period-lock.js +18 -0
- package/dist/period-lock.js.map +1 -0
- package/dist/recurring-revenue.d.ts +37 -0
- package/dist/recurring-revenue.js +18 -0
- package/dist/recurring-revenue.js.map +1 -0
- package/dist/sca-prompt.d.ts +16 -0
- package/dist/sca-prompt.js +10 -0
- package/dist/sca-prompt.js.map +1 -0
- package/dist/sheet-stack.d.ts +34 -0
- package/dist/sheet-stack.js +20 -0
- package/dist/sheet-stack.js.map +1 -0
- package/dist/stage-duration.d.ts +33 -0
- package/dist/stage-duration.js +16 -0
- package/dist/stage-duration.js.map +1 -0
- package/dist/supplier-invoice-inbox.d.ts +66 -0
- package/dist/supplier-invoice-inbox.js +38 -0
- package/dist/supplier-invoice-inbox.js.map +1 -0
- package/dist/tax-code-select.d.ts +33 -0
- package/dist/tax-code-select.js +23 -0
- package/dist/tax-code-select.js.map +1 -0
- package/dist/text-link.d.ts +33 -0
- package/dist/text-link.js +13 -0
- package/dist/text-link.js.map +1 -0
- package/dist/toasts.d.ts +53 -0
- package/dist/toasts.js +17 -0
- package/dist/toasts.js.map +1 -0
- package/dist/trend-chart.d.ts +43 -0
- package/dist/trend-chart.js +19 -0
- package/dist/trend-chart.js.map +1 -0
- package/dist/vat-return.d.ts +54 -0
- package/dist/vat-return.js +23 -0
- package/dist/vat-return.js.map +1 -0
- package/dist/voucher-composer.d.ts +69 -0
- package/dist/voucher-composer.js +15 -0
- package/dist/voucher-composer.js.map +1 -0
- package/dist/voucher-lines.d.ts +11 -0
- package/dist/voucher-lines.js +10 -0
- package/dist/voucher-lines.js.map +1 -0
- package/docs/llms.txt +214 -0
- package/package.json +308 -3
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/booki-agent.ts
|
|
4
|
+
import { createHistory as createBridgeHistory, describeEntry, stageChanges } from "@ui-sdk/react/history";
|
|
5
|
+
import { agentTools, createAgent, registerTools as registerBridgeTools } from "@ui-sdk/react/agent";
|
|
6
|
+
import { elementOf } from "@ui-sdk/react/observe";
|
|
7
|
+
import {
|
|
8
|
+
actAndRecord,
|
|
9
|
+
bookiAllow,
|
|
10
|
+
bookiRegisterTools,
|
|
11
|
+
markRefused
|
|
12
|
+
} from "@booki-aui/primitives/agent-policy";
|
|
13
|
+
import { isPersonOnly } from "@booki-aui/primitives/person-only";
|
|
14
|
+
import { BookiError } from "@booki-aui/core/msg";
|
|
15
|
+
var bridges = /* @__PURE__ */ new WeakMap();
|
|
16
|
+
var bridgeOf = (agent) => bridges.get(agent) ?? agent;
|
|
17
|
+
var restorers = /* @__PURE__ */ new WeakMap();
|
|
18
|
+
var restoringCount = 0;
|
|
19
|
+
function isHistoryRestoring() {
|
|
20
|
+
return restoringCount > 0;
|
|
21
|
+
}
|
|
22
|
+
function createBookiAgent(options = {}) {
|
|
23
|
+
const { timeout, agentId = "bridge", ruleVersion } = options;
|
|
24
|
+
const allow = bookiAllow(options);
|
|
25
|
+
const bridge = createAgent(allow ? { timeout, allow } : { timeout });
|
|
26
|
+
const language = options.language && options.language !== "en" ? options.language : void 0;
|
|
27
|
+
const run = async (input, actOptions) => {
|
|
28
|
+
const lone = Array.isArray(input?.steps) && input.steps.length === 1 ? input.steps[0] : void 0;
|
|
29
|
+
if (lone) currentStep.set(bridge, lone.action);
|
|
30
|
+
try {
|
|
31
|
+
return await bridge.act(input, actOptions);
|
|
32
|
+
} finally {
|
|
33
|
+
if (lone) currentStep.delete(bridge);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const act = async (input, actOptions) => {
|
|
37
|
+
let result = await run(input, actOptions);
|
|
38
|
+
const failed = result.ok ? void 0 : result.error;
|
|
39
|
+
const step = failed && Array.isArray(input?.steps) ? input.steps[failed.step] : void 0;
|
|
40
|
+
const person = step ? personOnlyPress(bridge, step) : null;
|
|
41
|
+
if (failed && step && person) {
|
|
42
|
+
markRefused({ ref: step.ref, label: person.entry.label, action: step.action });
|
|
43
|
+
options.audit?.({
|
|
44
|
+
actor: `agent:${agentId}`,
|
|
45
|
+
action: "agent.person-only",
|
|
46
|
+
target: person.entry.label ?? person.entry.ref,
|
|
47
|
+
detail: `${person.entry.component}.press: ${person.confirm}`,
|
|
48
|
+
...ruleVersion ? { ruleVersion } : {}
|
|
49
|
+
});
|
|
50
|
+
result = {
|
|
51
|
+
...result,
|
|
52
|
+
error: { ...failed, message: new BookiError("agent.person-only", { confirm: person.confirm }).message }
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (!language) return result;
|
|
56
|
+
const { localize } = await import("@booki-aui/core/messages");
|
|
57
|
+
return inLanguage(result, (text) => localize(text, language));
|
|
58
|
+
};
|
|
59
|
+
const agent = { ...bridge, act };
|
|
60
|
+
bridges.set(agent, bridge);
|
|
61
|
+
return agent;
|
|
62
|
+
}
|
|
63
|
+
var currentStep = /* @__PURE__ */ new WeakMap();
|
|
64
|
+
function personOnlyPress(bridge, step) {
|
|
65
|
+
if (step.action !== "press") return null;
|
|
66
|
+
const text = String(step.args?.[0] ?? "").replace(/\s+/g, " ").trim().toLowerCase();
|
|
67
|
+
if (!text) return null;
|
|
68
|
+
const entries = bridge.snapshot();
|
|
69
|
+
const entry = entries.find((item) => item.ref === step.ref) ?? entries.find((item) => item.label === step.ref) ?? entries.find((item) => item.component === step.ref);
|
|
70
|
+
if (!entry || entry.actions?.includes("press")) return null;
|
|
71
|
+
const root = elementOf(entry.ref);
|
|
72
|
+
if (!root) return null;
|
|
73
|
+
for (const button of root.querySelectorAll("button, [role='button']")) {
|
|
74
|
+
const own = (button.textContent ?? "").replace(/\s+/g, " ").trim().toLowerCase();
|
|
75
|
+
const label = (button.getAttribute("aria-label") ?? "").replace(/\s+/g, " ").trim().toLowerCase();
|
|
76
|
+
if (own !== text && label !== text && !label.startsWith(`${text}:`)) continue;
|
|
77
|
+
const confirm = button.closest("[data-agent-confirm]")?.getAttribute("data-agent-confirm");
|
|
78
|
+
if (confirm && isPersonOnly(confirm)) return { confirm, entry };
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
function inLanguage(value, say) {
|
|
83
|
+
if (Array.isArray(value)) return value.map((item) => inLanguage(item, say));
|
|
84
|
+
if (value === null || typeof value !== "object") return value;
|
|
85
|
+
const out = {};
|
|
86
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
87
|
+
if (key === "error" && inner && typeof inner === "object" && typeof inner.message === "string") {
|
|
88
|
+
out[key] = { ...inner, message: say(inner.message) };
|
|
89
|
+
} else if (key === "result" && typeof inner === "string") {
|
|
90
|
+
out[key] = say(inner);
|
|
91
|
+
} else out[key] = inLanguage(inner, say);
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
var registerWithGate = bookiRegisterTools(
|
|
96
|
+
(agent, options) => registerBridgeTools(bridgeOf(agent), options)
|
|
97
|
+
);
|
|
98
|
+
function registerTools(agent, options) {
|
|
99
|
+
if (options?.allow !== "bridge") {
|
|
100
|
+
if (options?.prefix) throw new Error('registerTools: a prefix needs allow: "bridge".');
|
|
101
|
+
return registerWithGate(agent, options);
|
|
102
|
+
}
|
|
103
|
+
const prefix = options.prefix ? `${String(options.prefix).replace(/[^A-Za-z0-9_-]/g, "")}_` : "";
|
|
104
|
+
const context = globalThis.document?.modelContext;
|
|
105
|
+
const controller = new AbortController();
|
|
106
|
+
const act = (input, signal) => options.audit ? actAndRecord(agent, input, options, { signal }) : agent.act(input, { signal });
|
|
107
|
+
for (const tool of agentTools) {
|
|
108
|
+
const definition = {
|
|
109
|
+
...tool,
|
|
110
|
+
name: `${prefix}${tool.name}`,
|
|
111
|
+
// Labels and text come from the page, which can hold what users wrote,
|
|
112
|
+
// and `act` can press any button, like one that deletes.
|
|
113
|
+
annotations: {
|
|
114
|
+
readOnlyHint: tool.name !== "act",
|
|
115
|
+
untrustedContentHint: true,
|
|
116
|
+
consequentialHint: tool.name === "act"
|
|
117
|
+
},
|
|
118
|
+
execute: (input, call) => tool.name === "act" ? act(input, call?.signal) : agent[tool.name](input)
|
|
119
|
+
};
|
|
120
|
+
try {
|
|
121
|
+
void Promise.resolve(context?.registerTool(definition, { signal: controller.signal })).catch(() => {
|
|
122
|
+
});
|
|
123
|
+
} catch {
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return () => controller.abort();
|
|
127
|
+
}
|
|
128
|
+
function domainAction(component, key) {
|
|
129
|
+
switch (component) {
|
|
130
|
+
case "amount-field":
|
|
131
|
+
if (key === "value" || key === "minor") return "amount.setMinor";
|
|
132
|
+
return `amount.${key}`;
|
|
133
|
+
case "voucher-composer":
|
|
134
|
+
if (key === "lines") return "voucher.lines";
|
|
135
|
+
return `voucher.${key}`;
|
|
136
|
+
case "bank-account":
|
|
137
|
+
return `bank.${key}`;
|
|
138
|
+
case "payment-reference":
|
|
139
|
+
return `paymentRef.${key}`;
|
|
140
|
+
case "tax-code-select":
|
|
141
|
+
return `tax.${key}`;
|
|
142
|
+
case "account-picker":
|
|
143
|
+
return `account.${key}`;
|
|
144
|
+
case "currency-select":
|
|
145
|
+
return `currency.${key}`;
|
|
146
|
+
default:
|
|
147
|
+
return `${component}.${key}`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function auditValue(value, max = 200) {
|
|
151
|
+
let text;
|
|
152
|
+
if (value === null || typeof value !== "object") text = String(value);
|
|
153
|
+
else {
|
|
154
|
+
try {
|
|
155
|
+
text = JSON.stringify(value);
|
|
156
|
+
} catch {
|
|
157
|
+
text = String(value);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return text.length > max ? `${text.slice(0, max - 1)}\u2026` : text;
|
|
161
|
+
}
|
|
162
|
+
var isRows = (value) => Array.isArray(value) && value.every(
|
|
163
|
+
(item) => item && typeof item === "object" && (typeof item.id === "string" || typeof item.id === "number")
|
|
164
|
+
);
|
|
165
|
+
var isPlain = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
166
|
+
var same = (a, b) => auditValue(a, 1e4) === auditValue(b, 1e4);
|
|
167
|
+
function rowChanges(next, before) {
|
|
168
|
+
const out = [];
|
|
169
|
+
for (const row of next) {
|
|
170
|
+
const old = before.find((item) => item.id === row.id);
|
|
171
|
+
if (!old) {
|
|
172
|
+
out.push(`+${row.id}`);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const fields = Object.keys({ ...old, ...row }).filter((key) => !same(row[key], old[key])).map((key) => `${key}=${auditValue(row[key], 40)} (was ${auditValue(old[key], 40)})`);
|
|
176
|
+
if (fields.length) out.push(`${row.id}: ${fields.join(", ")}`);
|
|
177
|
+
}
|
|
178
|
+
for (const old of before) if (!next.some((row) => row.id === old.id)) out.push(`-${old.id}`);
|
|
179
|
+
return out;
|
|
180
|
+
}
|
|
181
|
+
function changeText(key, value, previous) {
|
|
182
|
+
let parts = null;
|
|
183
|
+
if (isRows(value) && isRows(previous)) parts = rowChanges(value, previous);
|
|
184
|
+
else if (isPlain(value) && isPlain(previous)) {
|
|
185
|
+
parts = [];
|
|
186
|
+
for (const field of Object.keys({ ...previous, ...value })) {
|
|
187
|
+
const now = value[field];
|
|
188
|
+
const was = previous[field];
|
|
189
|
+
if (same(now, was)) continue;
|
|
190
|
+
if (isRows(now) && isRows(was)) parts.push(...rowChanges(now, was).map((line) => `${field} ${line}`));
|
|
191
|
+
else parts.push(`${field}=${auditValue(now, 60)} (was ${auditValue(was, 60)})`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (!parts || parts.length === 0) return `${key}=${auditValue(value)} (was ${auditValue(previous)})`;
|
|
195
|
+
return auditValue(parts.join("; ").replace(/^"|"$/g, ""), 200).replace(/^"|"$/g, "");
|
|
196
|
+
}
|
|
197
|
+
function attachAudit(agent, push, agentIdOrOptions = "bridge") {
|
|
198
|
+
const options = typeof agentIdOrOptions === "string" ? { agentId: agentIdOrOptions } : agentIdOrOptions;
|
|
199
|
+
const agentId = options.agentId ?? "bridge";
|
|
200
|
+
const ruleVersion = options.ruleVersion;
|
|
201
|
+
const bridge = bridgeOf(agent);
|
|
202
|
+
return agent.subscribe((change) => {
|
|
203
|
+
if (change.source !== "agent") return;
|
|
204
|
+
const key = change.key.endsWith("Shown") ? change.key.slice(0, -"Shown".length) : change.key;
|
|
205
|
+
const undoneBy = restorers.get(bridge);
|
|
206
|
+
const step = undoneBy ? void 0 : currentStep.get(bridge);
|
|
207
|
+
push({
|
|
208
|
+
actor: undoneBy ?? `agent:${agentId}`,
|
|
209
|
+
action: domainAction(change.component, key),
|
|
210
|
+
target: change.label ?? change.ref,
|
|
211
|
+
detail: `${step ? `${step}: ` : ""}${changeText(key, change.value, change.previous)}${undoneBy ? ", undo" : ""}`,
|
|
212
|
+
ruleVersion
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
async function proposeChanges(agent, changes) {
|
|
217
|
+
return stageChanges(bridgeOf(agent), changes);
|
|
218
|
+
}
|
|
219
|
+
var BOOKI_HISTORY_KEYS = ["value", "checked", "pressed", "minor", "lines", "digits", "matches"];
|
|
220
|
+
function createBookiHistory(agent, options) {
|
|
221
|
+
return createHistory(agent, { keys: BOOKI_HISTORY_KEYS, ...options });
|
|
222
|
+
}
|
|
223
|
+
function createHistory(agent, options = {}) {
|
|
224
|
+
const { by, ...rest } = options;
|
|
225
|
+
const bridge = bridgeOf(agent);
|
|
226
|
+
const history = createBridgeHistory(bridge, rest);
|
|
227
|
+
const asPerson = async (run) => {
|
|
228
|
+
const who = (typeof by === "function" ? by() : by) || "person";
|
|
229
|
+
const before = restorers.get(bridge);
|
|
230
|
+
restorers.set(bridge, who);
|
|
231
|
+
restoringCount++;
|
|
232
|
+
try {
|
|
233
|
+
return await run();
|
|
234
|
+
} finally {
|
|
235
|
+
restoringCount--;
|
|
236
|
+
if (before === void 0) restorers.delete(bridge);
|
|
237
|
+
else restorers.set(bridge, before);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
return {
|
|
241
|
+
...history,
|
|
242
|
+
seek: (to) => asPerson(() => history.seek(to)),
|
|
243
|
+
undoSource: (source) => asPerson(() => history.undoSource(source))
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export {
|
|
248
|
+
describeEntry,
|
|
249
|
+
stageChanges,
|
|
250
|
+
isHistoryRestoring,
|
|
251
|
+
createBookiAgent,
|
|
252
|
+
registerTools,
|
|
253
|
+
attachAudit,
|
|
254
|
+
proposeChanges,
|
|
255
|
+
BOOKI_HISTORY_KEYS,
|
|
256
|
+
createBookiHistory,
|
|
257
|
+
createHistory
|
|
258
|
+
};
|
|
259
|
+
//# sourceMappingURL=chunk-SHZFZRHV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/booki-agent.ts"],"sourcesContent":["import { createHistory as createBridgeHistory, describeEntry, stageChanges } from \"@ui-sdk/react/history\";\nimport { agentTools, createAgent, registerTools as registerBridgeTools } from \"@ui-sdk/react/agent\";\nimport { elementOf } from \"@ui-sdk/react/observe\";\nimport {\n actAndRecord,\n bookiAllow,\n bookiRegisterTools,\n markRefused,\n type AgentDecision,\n type AgentPolicyOptions,\n} from \"@booki-aui/primitives/agent-policy\";\nimport { isPersonOnly } from \"@booki-aui/primitives/person-only\";\nimport { BookiError, type MessageLanguage } from \"@booki-aui/core/msg\";\nimport type { AuditEvent } from \"./audit-trail.js\";\n\ntype AgentBridge = ReturnType<typeof createAgent>;\n\n/**\n * The bridge `createAgent` made, behind an agent that answers in another\n * language. ui-sdk's history and WebMCP tools find the bridge's internals by\n * the object and the `act` that `createAgent` returned, so they get that one.\n */\nconst bridges = new WeakMap<AgentBridge, AgentBridge>();\nconst bridgeOf = (agent: AgentBridge): AgentBridge => bridges.get(agent) ?? agent;\n\n/**\n * Who an undo running on a bridge is for. ui-sdk's history puts values back\n * through the bridge, so the change reports `source: \"agent\"`; this says it\n * was a person's undo.\n */\nconst restorers = new WeakMap<AgentBridge, string>();\nlet restoringCount = 0;\n\n/**\n * True while a Booki history (`createBookiHistory`, `createHistory`) is putting\n * values back for an undo or a seek. Those changes report `source: \"agent\"`,\n * because ui-sdk restores through the bridge; check this in your own change\n * callback to record them as the person's undo, not the agent's work.\n */\nfunction isHistoryRestoring(): boolean {\n return restoringCount > 0;\n}\n\nexport type CreateBookiAgentOptions = AgentPolicyOptions & {\n /** How long a step waits for `allow`, in ms. Default five minutes. */\n timeout?: number;\n /**\n * The language of Booki's refusals in `act` results. Default `\"en\"`. With\n * `\"nb\"` a refusal from a Booki control comes back in Norwegian, and so do the\n * bridge's own (\"Needs a person: …\", \"No component … on the page\", \"The person\n * said no to …\"), and so does a step's own sentence (`Pressed \"…\".`); a sentence the\n * catalogue does not know stays as written. History\n * (`createBookiHistory`) and WebMCP tools (`registerTools`) work with such an\n * agent; what they answer themselves is in ui-sdk's words.\n */\n language?: MessageLanguage;\n};\n\n/**\n * Finance-tuned agent bridge: irreversible `data-agent-confirm` steps need an\n * explicit `allow` answer (no silent approve), and a person's decision\n * (approve, sign, send, release) is refused whatever `allow` says. With\n * `audit`, every refused step and every confirmed one is recorded, with who\n * decided when `allow` answers `{ allow, by }`. Same snapshot/act/query/subscribe\n * surface as `createAgent`.\n */\nfunction createBookiAgent(options: CreateBookiAgentOptions = {}): AgentBridge {\n const { timeout, agentId = \"bridge\", ruleVersion } = options;\n // With neither `allow` nor `audit`, leave it unset: the bridge then runs\n // unmarked steps and refuses `data-agent-confirm` steps with \"Needs a\n // person: …\", which tells the agent what to do next. Answering `false` here\n // would read as \"The person said no\" although nobody was asked.\n const allow = bookiAllow(options);\n const bridge = createAgent(allow ? { timeout, allow } : { timeout });\n const language = options.language && options.language !== \"en\" ? options.language : undefined;\n\n /** Runs steps on the bridge, noting a lone step for `attachAudit`'s rows. */\n const run = async (input: ActInput, actOptions?: ActOptions) => {\n // A call without `steps` is ui-sdk's to refuse with a sentence: read it, never assume it.\n const lone = Array.isArray(input?.steps) && input.steps.length === 1 ? input.steps[0] : undefined;\n if (lone) currentStep.set(bridge, lone.action);\n try {\n return await bridge.act(input as never, actOptions);\n } finally {\n if (lone) currentStep.delete(bridge);\n }\n };\n\n const act = async (input: ActInput, actOptions?: ActOptions) => {\n let result = (await run(input, actOptions)) as ActResult;\n // A press on a Booki control's button that is a person's decision (sign off,\n // release): the bridge answers \"nothing to press now\", which tells the agent\n // nothing and leaves no trace. Checked after the call, when the button is on\n // the page even if an earlier step in it made the button appear.\n const failed = result.ok ? undefined : result.error;\n const step = failed && Array.isArray(input?.steps) ? input.steps[failed.step] : undefined;\n const person = step ? personOnlyPress(bridge, step) : null;\n if (failed && step && person) {\n markRefused({ ref: step.ref, label: person.entry.label, action: step.action });\n options.audit?.({\n actor: `agent:${agentId}`,\n action: \"agent.person-only\",\n target: person.entry.label ?? person.entry.ref,\n detail: `${person.entry.component}.press: ${person.confirm}`,\n ...(ruleVersion ? { ruleVersion } : {}),\n });\n result = {\n ...result,\n error: { ...failed, message: new BookiError(\"agent.person-only\", { confirm: person.confirm }).message },\n };\n }\n if (!language) return result;\n // Loaded only for an agent that asked for another language: the catalogue is not small.\n const { localize } = await import(\"@booki-aui/core/messages\");\n return inLanguage(result, (text) => localize(text, language));\n };\n\n const agent = { ...bridge, act } as AgentBridge;\n bridges.set(agent, bridge);\n return agent;\n}\n\ntype ActInput = { steps: { ref: string; action: string; args?: unknown[] }[] };\ntype ActOptions = { signal?: AbortSignal };\ntype ActResult = { ok: boolean; steps?: unknown[]; error?: { step: number; message: string } } & Record<\n string,\n unknown\n>;\ntype Entry = { ref: string; label?: string; component: string; actions?: string[] };\n\n/** The step a lone `act` is running, by bridge, for `attachAudit` to name in its rows. */\nconst currentStep = new WeakMap<AgentBridge, string>();\n\n/**\n * When a press step names a button on a Booki control that is a person's\n * decision, the confirm sentence and the control; otherwise null. Controls\n * that take `press` themselves (a ui-sdk Button) are left to the bridge, whose\n * `allow` refuses a person's decision already.\n */\nfunction personOnlyPress(\n bridge: AgentBridge,\n step: ActInput[\"steps\"][number],\n): { confirm: string; entry: Entry } | null {\n if (step.action !== \"press\") return null;\n const text = String(step.args?.[0] ?? \"\")\n .replace(/\\s+/g, \" \")\n .trim()\n .toLowerCase();\n if (!text) return null;\n const entries = bridge.snapshot() as unknown as Entry[];\n const entry =\n entries.find((item) => item.ref === step.ref) ??\n entries.find((item) => item.label === step.ref) ??\n entries.find((item) => item.component === step.ref);\n if (!entry || entry.actions?.includes(\"press\")) return null;\n const root = elementOf(entry.ref);\n if (!root) return null;\n for (const button of root.querySelectorAll(\"button, [role='button']\")) {\n const own = (button.textContent ?? \"\").replace(/\\s+/g, \" \").trim().toLowerCase();\n const label = (button.getAttribute(\"aria-label\") ?? \"\").replace(/\\s+/g, \" \").trim().toLowerCase();\n if (own !== text && label !== text && !label.startsWith(`${text}:`)) continue;\n const confirm = button.closest(\"[data-agent-confirm]\")?.getAttribute(\"data-agent-confirm\");\n if (confirm && isPersonOnly(confirm)) return { confirm, entry };\n }\n return null;\n}\n\n/**\n * The same result with every refusal (`error.message`, at any depth) and every\n * step's own sentence (`result`, like `Pressed \"Post\".`) written in another language.\n */\nfunction inLanguage<T>(value: T, say: (text: string) => string): T {\n if (Array.isArray(value)) return value.map((item) => inLanguage(item, say)) as T;\n if (value === null || typeof value !== \"object\") return value;\n const out: Record<string, unknown> = {};\n for (const [key, inner] of Object.entries(value as Record<string, unknown>)) {\n if (\n key === \"error\" &&\n inner &&\n typeof inner === \"object\" &&\n typeof (inner as { message?: unknown }).message === \"string\"\n ) {\n out[key] = { ...(inner as object), message: say((inner as { message: string }).message) };\n } else if (key === \"result\" && typeof inner === \"string\") {\n // A control's own answer comes back as it is when the catalogue does not know it.\n out[key] = say(inner);\n } else out[key] = inLanguage(inner, say);\n }\n return out as T;\n}\n\nexport type RegisterToolsOptions = Omit<AgentPolicyOptions, \"allow\"> & {\n /**\n * Decides each step the browser's agent takes. `\"bridge\"`: the agent's own\n * `allow` (from `createBookiAgent`) decides, once, and Booki registers the\n * tools itself, so they answer in the agent's language and, with `audit`, a\n * control's own refusals are recorded. A function: a second gate after the\n * bridge's, through ui-sdk's registration. Give the same dialog to both and\n * the person is asked twice.\n */\n allow: NonNullable<AgentPolicyOptions[\"allow\"]> | \"bridge\";\n /** Prefix for the tool names, like `\"acme\"` for `acme_snapshot`, `acme_act`, `acme_query`. Needs `allow: \"bridge\"`. */\n prefix?: string;\n};\n\nconst registerWithGate = bookiRegisterTools<AgentBridge>((agent, options) =>\n registerBridgeTools(bridgeOf(agent), options),\n);\n\n/**\n * Registers the agent's tools with the browser's own agent (WebMCP): `snapshot`,\n * `act` and `query`. A person's decision is refused whatever `allow` says. The\n * browser's agent acts in the person's session: keep this off until your\n * server can tell it from the person.\n */\nfunction registerTools(agent: AgentBridge, options: RegisterToolsOptions): () => void {\n if (options?.allow !== \"bridge\") {\n if (options?.prefix) throw new Error('registerTools: a prefix needs allow: \"bridge\".');\n return registerWithGate(agent, options as never);\n }\n const prefix = options.prefix ? `${String(options.prefix).replace(/[^A-Za-z0-9_-]/g, \"\")}_` : \"\";\n const context = (globalThis as { document?: { modelContext?: ModelContext } }).document?.modelContext;\n const controller = new AbortController();\n const act = (input: ActInput, signal?: AbortSignal) =>\n options.audit\n ? actAndRecord(agent as never, input as never, options, { signal })\n : agent.act(input as never, { signal });\n for (const tool of agentTools) {\n const definition = {\n ...tool,\n name: `${prefix}${tool.name}`,\n // Labels and text come from the page, which can hold what users wrote,\n // and `act` can press any button, like one that deletes.\n annotations: {\n readOnlyHint: tool.name !== \"act\",\n untrustedContentHint: true,\n consequentialHint: tool.name === \"act\",\n },\n execute: (input: unknown, call?: { signal?: AbortSignal }) =>\n tool.name === \"act\"\n ? act(input as ActInput, call?.signal)\n : (agent as unknown as Record<string, (input: unknown) => unknown>)[tool.name]!(input),\n };\n try {\n // A browser may answer with a promise or with nothing.\n void Promise.resolve(context?.registerTool(definition, { signal: controller.signal })).catch(() => {});\n } catch {\n /* Not allowed here: the page works without the tools. */\n }\n }\n return () => controller.abort();\n}\n\ntype ModelContext = { registerTool: (tool: unknown, options: { signal: AbortSignal }) => unknown };\n\nexport type AttachAuditPush = (event: Omit<AuditEvent, \"id\" | \"at\">) => void;\n\nexport type AttachAuditOptions = {\n agentId?: string;\n ruleVersion?: string;\n};\n\nfunction domainAction(component: string, key: string): string {\n switch (component) {\n case \"amount-field\":\n if (key === \"value\" || key === \"minor\") return \"amount.setMinor\";\n return `amount.${key}`;\n case \"voucher-composer\":\n if (key === \"lines\") return \"voucher.lines\";\n return `voucher.${key}`;\n case \"bank-account\":\n return `bank.${key}`;\n case \"payment-reference\":\n return `paymentRef.${key}`;\n case \"tax-code-select\":\n return `tax.${key}`;\n case \"account-picker\":\n return `account.${key}`;\n case \"currency-select\":\n return `currency.${key}`;\n default:\n return `${component}.${key}`;\n }\n}\n\n/** A change's value as audit text: objects as JSON (not \"[object Object]\"), capped. */\nfunction auditValue(value: unknown, max = 200): string {\n let text: string;\n if (value === null || typeof value !== \"object\") text = String(value);\n else {\n try {\n text = JSON.stringify(value);\n } catch {\n text = String(value);\n }\n }\n return text.length > max ? `${text.slice(0, max - 1)}…` : text;\n}\n\ntype Row = { id: string | number } & Record<string, unknown>;\nconst isRows = (value: unknown): value is Row[] =>\n Array.isArray(value) &&\n value.every(\n (item) => item && typeof item === \"object\" && (typeof item.id === \"string\" || typeof item.id === \"number\"),\n );\nconst isPlain = (value: unknown): value is Record<string, unknown> =>\n value !== null && typeof value === \"object\" && !Array.isArray(value);\nconst same = (a: unknown, b: unknown) => auditValue(a, 10_000) === auditValue(b, 10_000);\n\n/** What changed between two lists of records, by id: added, removed, and each changed field. */\nfunction rowChanges(next: Row[], before: Row[]): string[] {\n const out: string[] = [];\n for (const row of next) {\n const old = before.find((item) => item.id === row.id);\n if (!old) {\n out.push(`+${row.id}`);\n continue;\n }\n const fields = Object.keys({ ...old, ...row })\n .filter((key) => !same(row[key], old[key]))\n .map((key) => `${key}=${auditValue(row[key], 40)} (was ${auditValue(old[key], 40)})`);\n if (fields.length) out.push(`${row.id}: ${fields.join(\", \")}`);\n }\n for (const old of before) if (!next.some((row) => row.id === old.id)) out.push(`-${old.id}`);\n return out;\n}\n\n/**\n * A change in words a person can follow: for a list of records, what changed\n * per record; for a record (a workpaper, a claim), each field that changed,\n * and for its lists, the same per record. Anything else as before.\n */\nfunction changeText(key: string, value: unknown, previous: unknown): string {\n let parts: string[] | null = null;\n if (isRows(value) && isRows(previous)) parts = rowChanges(value, previous);\n else if (isPlain(value) && isPlain(previous)) {\n parts = [];\n for (const field of Object.keys({ ...previous, ...value })) {\n const now = value[field];\n const was = previous[field];\n if (same(now, was)) continue;\n if (isRows(now) && isRows(was)) parts.push(...rowChanges(now, was).map((line) => `${field} ${line}`));\n else parts.push(`${field}=${auditValue(now, 60)} (was ${auditValue(was, 60)})`);\n }\n }\n if (!parts || parts.length === 0) return `${key}=${auditValue(value)} (was ${auditValue(previous)})`;\n return auditValue(parts.join(\"; \").replace(/^\"|\"$/g, \"\"), 200).replace(/^\"|\"$/g, \"\");\n}\n\n/**\n * Subscribe to bridge changes and push audit rows when `source === \"agent\"`.\n * Returns the unsubscribe function.\n */\nfunction attachAudit(\n agent: AgentBridge,\n push: AttachAuditPush,\n agentIdOrOptions: string | AttachAuditOptions = \"bridge\",\n): () => void {\n const options: AttachAuditOptions =\n typeof agentIdOrOptions === \"string\" ? { agentId: agentIdOrOptions } : agentIdOrOptions;\n const agentId = options.agentId ?? \"bridge\";\n const ruleVersion = options.ruleVersion;\n\n const bridge = bridgeOf(agent);\n return agent.subscribe((change) => {\n if (change.source !== \"agent\") return;\n // A value with secrets is reported on `<key>Shown`, the copy without them.\n const key = change.key.endsWith(\"Shown\") ? change.key.slice(0, -\"Shown\".length) : change.key;\n // An undo goes through the bridge too, but it is the person's.\n const undoneBy = restorers.get(bridge);\n // The step a lone `act` ran, so the row says what the agent did, not only what changed.\n const step = undoneBy ? undefined : currentStep.get(bridge);\n push({\n actor: undoneBy ?? `agent:${agentId}`,\n action: domainAction(change.component, key),\n target: change.label ?? change.ref,\n detail: `${step ? `${step}: ` : \"\"}${changeText(key, change.value, change.previous)}${undoneBy ? \", undo\" : \"\"}`,\n ruleVersion,\n });\n });\n}\n\n/**\n * Stage preview changes for a propose → allow → commit loop.\n * Thin alias over UI SDK `stageChanges` (async).\n */\nasync function proposeChanges(agent: AgentBridge, changes: Parameters<typeof stageChanges>[1]) {\n return stageChanges(bridgeOf(agent), changes);\n}\n\n/**\n * State keys Booki primitives report changes on, each restorable through its\n * `set<Key>` agent action: `minor` (AmountField → setMinor), `lines`\n * (VoucherComposer → setLines), `digits` (OrganizationNumberInput →\n * setDigits), plus ui-sdk's defaults. Secret fields (bank account, IBAN) are\n * recorded as redacted and can't be restored by design.\n */\nconst BOOKI_HISTORY_KEYS = [\"value\", \"checked\", \"pressed\", \"minor\", \"lines\", \"digits\", \"matches\"];\n\nexport type BookiHistoryOptions = NonNullable<Parameters<typeof createBridgeHistory>[1]> & {\n /**\n * Who an undo or a seek is for, in `attachAudit` rows: the person's actor id,\n * like `\"person:kari\"`, or a function that returns the one signed in at the\n * moment of the undo. Default `\"person\"`.\n */\n by?: string | (() => string | undefined);\n};\n\n/**\n * History bound to a finance agent (undo agent work, describe entries).\n * Records Booki's keys by default (see `BOOKI_HISTORY_KEYS`); pass `keys` to\n * replace the list.\n */\nfunction createBookiHistory(agent: AgentBridge, options?: BookiHistoryOptions) {\n return createHistory(agent, { keys: BOOKI_HISTORY_KEYS, ...options });\n}\n\n/**\n * ui-sdk's `createHistory`, for any agent `createBookiAgent` made, also one with\n * a `language`: undo and redo run through the bridge itself, so their own\n * results are in ui-sdk's words. While `seek` or `undoSource` puts values\n * back, `attachAudit` records the changes under `by` (the person), not the\n * agent, and `isHistoryRestoring()` is true.\n */\nfunction createHistory(agent: AgentBridge, options: BookiHistoryOptions = {}) {\n const { by, ...rest } = options;\n const bridge = bridgeOf(agent);\n const history = createBridgeHistory(bridge, rest);\n const asPerson = async <T>(run: () => Promise<T>): Promise<T> => {\n const who = (typeof by === \"function\" ? by() : by) || \"person\";\n const before = restorers.get(bridge);\n restorers.set(bridge, who);\n restoringCount++;\n try {\n return await run();\n } finally {\n restoringCount--;\n if (before === undefined) restorers.delete(bridge);\n else restorers.set(bridge, before);\n }\n };\n return {\n ...history,\n seek: (to: number) => asPerson(() => history.seek(to)),\n undoSource: (source: string) => asPerson(() => history.undoSource(source)),\n };\n}\n\nexport {\n BOOKI_HISTORY_KEYS,\n attachAudit,\n createBookiAgent,\n createBookiHistory,\n createHistory,\n describeEntry,\n isHistoryRestoring,\n proposeChanges,\n registerTools,\n stageChanges,\n};\nexport type { AgentBridge, AgentDecision };\n"],"mappings":";;;AAAA,SAAS,iBAAiB,qBAAqB,eAAe,oBAAoB;AAClF,SAAS,YAAY,aAAa,iBAAiB,2BAA2B;AAC9E,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,S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AI,QAAQ,GAAG;AACzB;AACA,QAAI;AACF,aAAO,MAAM,IAAI;AAAA,IACnB,UAAE;AACA;AACA,UAAI,WAAW,OAAW,WAAU,OAAO,MAAM;AAAA,UAC5C,WAAU,IAAI,QAAQ,MAAM;AAAA,IACnC;AAAA,EACF;AACA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,MAAM,CAAC,OAAe,SAAS,MAAM,QAAQ,KAAK,EAAE,CAAC;AAAA,IACrD,YAAY,CAAC,WAAmB,SAAS,MAAM,QAAQ,WAAW,MAAM,CAAC;AAAA,EAC3E;AACF;","names":[]}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
useWorkflowCopy
|
|
4
|
+
} from "./chunk-U7NPK4WO.js";
|
|
5
|
+
import {
|
|
6
|
+
useAccessFor
|
|
7
|
+
} from "./chunk-K72VT6RJ.js";
|
|
8
|
+
import {
|
|
9
|
+
useBookiLocaleOptional,
|
|
10
|
+
useSay
|
|
11
|
+
} from "./chunk-GVP2N3K6.js";
|
|
12
|
+
|
|
13
|
+
// src/period-lock.tsx
|
|
14
|
+
import { formatPeriod } from "@booki-aui/core/period";
|
|
15
|
+
import { createParts } from "@ui-sdk/react/primitive";
|
|
16
|
+
import { periodLock } from "@booki-aui/primitives/period-lock";
|
|
17
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
18
|
+
var TAGS = { root: "div", set: "button" };
|
|
19
|
+
var parts = createParts(periodLock, TAGS);
|
|
20
|
+
var PeriodLockRoot = parts.Root;
|
|
21
|
+
var PeriodLockSet = parts.Set;
|
|
22
|
+
function PeriodLock({
|
|
23
|
+
codes,
|
|
24
|
+
periods,
|
|
25
|
+
defaultPeriods,
|
|
26
|
+
onPeriodsChange,
|
|
27
|
+
className,
|
|
28
|
+
"aria-label": ariaLabel
|
|
29
|
+
}) {
|
|
30
|
+
const copy = useWorkflowCopy();
|
|
31
|
+
const { profile } = useBookiLocaleOptional();
|
|
32
|
+
const say = useSay();
|
|
33
|
+
const access = useAccessFor({ setStatus: "period.close" });
|
|
34
|
+
const label = {
|
|
35
|
+
open: copy.open,
|
|
36
|
+
"soft-closed": copy.softClosed,
|
|
37
|
+
"hard-closed": copy.hardClosed
|
|
38
|
+
};
|
|
39
|
+
return /* @__PURE__ */ jsx(
|
|
40
|
+
PeriodLockRoot,
|
|
41
|
+
{
|
|
42
|
+
periods,
|
|
43
|
+
defaultPeriods,
|
|
44
|
+
denied: access.denied,
|
|
45
|
+
onPeriodsChange,
|
|
46
|
+
className,
|
|
47
|
+
"aria-label": ariaLabel ?? copy.periods,
|
|
48
|
+
children: (state) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
49
|
+
/* @__PURE__ */ jsxs("table", { "data-slot": "period-lock-table", children: [
|
|
50
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
51
|
+
/* @__PURE__ */ jsx("th", { children: copy.period }),
|
|
52
|
+
/* @__PURE__ */ jsx("th", { children: copy.status }),
|
|
53
|
+
/* @__PURE__ */ jsx("th", { children: /* @__PURE__ */ jsx("span", { "data-slot": "visually-hidden", children: copy.status }) })
|
|
54
|
+
] }) }),
|
|
55
|
+
/* @__PURE__ */ jsx("tbody", { children: codes.map((code) => {
|
|
56
|
+
const status = state.periods.find((p) => p.code === code)?.status ?? "open";
|
|
57
|
+
const name = formatPeriod(code, profile.locale);
|
|
58
|
+
return /* @__PURE__ */ jsxs("tr", { "data-status": status, children: [
|
|
59
|
+
/* @__PURE__ */ jsx("td", { children: name }),
|
|
60
|
+
/* @__PURE__ */ jsx("td", { "data-slot": "period-lock-status", children: label[status] }),
|
|
61
|
+
/* @__PURE__ */ jsxs("td", { "data-slot": "period-lock-actions", children: [
|
|
62
|
+
status === "open" ? /* @__PURE__ */ jsx(PeriodLockSet, { value: `${code}|soft-closed`, "aria-label": `${copy.closePeriod}: ${name}`, children: copy.closePeriod }) : null,
|
|
63
|
+
status === "soft-closed" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
64
|
+
/* @__PURE__ */ jsx(PeriodLockSet, { value: `${code}|hard-closed`, "aria-label": `${copy.lockPeriod}: ${name}`, children: copy.lockPeriod }),
|
|
65
|
+
/* @__PURE__ */ jsx(
|
|
66
|
+
PeriodLockSet,
|
|
67
|
+
{
|
|
68
|
+
value: `${code}|open`,
|
|
69
|
+
"data-variant": "secondary",
|
|
70
|
+
"aria-label": `${copy.reopenPeriod}: ${name}`,
|
|
71
|
+
children: copy.reopenPeriod
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
] }) : null
|
|
75
|
+
] })
|
|
76
|
+
] }, code);
|
|
77
|
+
}) })
|
|
78
|
+
] }),
|
|
79
|
+
state.refusal ? /* @__PURE__ */ jsx("p", { "data-slot": "period-lock-error", role: "alert", children: say(state.refusal) }) : null
|
|
80
|
+
] })
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export {
|
|
86
|
+
periodLock,
|
|
87
|
+
PeriodLockRoot,
|
|
88
|
+
PeriodLockSet,
|
|
89
|
+
PeriodLock
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=chunk-SOXPKIQK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/period-lock.tsx"],"sourcesContent":["import { formatPeriod } from \"@booki-aui/core/period\";\nimport type { BookiChangeDetails } from \"./change-details.js\";\nimport { type PeriodState, type PeriodStatus } from \"@booki-aui/core/period-lock\";\nimport { createParts, type Parts } from \"@ui-sdk/react/primitive\";\nimport { useAccessFor } from \"./access.js\";\nimport { useBookiLocaleOptional } from \"./locale.js\";\nimport { useSay } from \"./say.js\";\nimport { useWorkflowCopy } from \"./workflow-copy.js\";\nimport { periodLock } from \"@booki-aui/primitives/period-lock\";\n\nconst TAGS = { root: \"div\", set: \"button\" } as const;\n// Typed by name, so the declarations refer to the definition instead of spelling it out per part.\nconst parts: Parts<typeof periodLock, typeof TAGS> = createParts(periodLock, TAGS);\nconst PeriodLockRoot: (typeof parts)[\"Root\"] = parts.Root;\nconst PeriodLockSet: (typeof parts)[\"Set\"] = parts.Set;\n\nexport type PeriodLockProps = {\n /** The period codes to list, e.g. `[\"2026-01\", \"2026-02\"]`. */\n codes: string[];\n periods?: PeriodState[];\n defaultPeriods?: PeriodState[];\n onPeriodsChange?: (periods: PeriodState[], details: BookiChangeDetails) => void;\n className?: string;\n \"aria-label\"?: string;\n};\n\n/** Composed period list: each period, its status, and the buttons that change it. */\nfunction PeriodLock({\n codes,\n periods,\n defaultPeriods,\n onPeriodsChange,\n className,\n \"aria-label\": ariaLabel,\n}: PeriodLockProps) {\n const copy = useWorkflowCopy();\n const { profile } = useBookiLocaleOptional();\n const say = useSay();\n const access = useAccessFor({ setStatus: \"period.close\" });\n const label: Record<PeriodStatus, string> = {\n open: copy.open,\n \"soft-closed\": copy.softClosed,\n \"hard-closed\": copy.hardClosed,\n };\n return (\n <PeriodLockRoot\n periods={periods}\n defaultPeriods={defaultPeriods}\n denied={access.denied}\n onPeriodsChange={onPeriodsChange}\n className={className}\n aria-label={ariaLabel ?? copy.periods}\n >\n {(state: { periods: PeriodState[]; refusal: string }) => (\n <>\n <table data-slot=\"period-lock-table\">\n <thead>\n <tr>\n <th>{copy.period}</th>\n <th>{copy.status}</th>\n <th>\n <span data-slot=\"visually-hidden\">{copy.status}</span>\n </th>\n </tr>\n </thead>\n <tbody>\n {codes.map((code) => {\n const status = state.periods.find((p) => p.code === code)?.status ?? \"open\";\n const name = formatPeriod(code, profile.locale);\n return (\n <tr key={code} data-status={status}>\n <td>{name}</td>\n <td data-slot=\"period-lock-status\">{label[status]}</td>\n <td data-slot=\"period-lock-actions\">\n {status === \"open\" ? (\n <PeriodLockSet value={`${code}|soft-closed`} aria-label={`${copy.closePeriod}: ${name}`}>\n {copy.closePeriod}\n </PeriodLockSet>\n ) : null}\n {status === \"soft-closed\" ? (\n <>\n <PeriodLockSet value={`${code}|hard-closed`} aria-label={`${copy.lockPeriod}: ${name}`}>\n {copy.lockPeriod}\n </PeriodLockSet>\n <PeriodLockSet\n value={`${code}|open`}\n data-variant=\"secondary\"\n aria-label={`${copy.reopenPeriod}: ${name}`}\n >\n {copy.reopenPeriod}\n </PeriodLockSet>\n </>\n ) : null}\n </td>\n </tr>\n );\n })}\n </tbody>\n </table>\n {state.refusal ? (\n <p data-slot=\"period-lock-error\" role=\"alert\">\n {say(state.refusal)}\n </p>\n ) : null}\n </>\n )}\n </PeriodLockRoot>\n );\n}\n\nexport { PeriodLock, PeriodLockRoot, PeriodLockSet, periodLock };\nexport type { PeriodState, PeriodStatus };\n"],"mappings":";;;;;;;;;;;;;AAAA,SAAS,oBAAoB;AAG7B,SAAS,mBAA+B;AAKxC,SAAS,kBAAkB;AAiDb,SAuBU,UAtBR,KADF;AA/Cd,IAAM,OAAO,EAAE,MAAM,OAAO,KAAK,SAAS;AAE1C,IAAM,QAA+C,YAAY,YAAY,IAAI;AACjF,IAAM,iBAAyC,MAAM;AACrD,IAAM,gBAAuC,MAAM;AAanD,SAAS,WAAW;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,cAAc;AAChB,GAAoB;AAClB,QAAM,OAAO,gBAAgB;AAC7B,QAAM,EAAE,QAAQ,IAAI,uBAAuB;AAC3C,QAAM,MAAM,OAAO;AACnB,QAAM,SAAS,aAAa,EAAE,WAAW,eAAe,CAAC;AACzD,QAAM,QAAsC;AAAA,IAC1C,MAAM,KAAK;AAAA,IACX,eAAe,KAAK;AAAA,IACpB,eAAe,KAAK;AAAA,EACtB;AACA,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,QAAQ,OAAO;AAAA,MACf;AAAA,MACA;AAAA,MACA,cAAY,aAAa,KAAK;AAAA,MAE7B,WAAC,UACA,iCACE;AAAA,6BAAC,WAAM,aAAU,qBACf;AAAA,8BAAC,WACC,+B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OYERLEER.js";
|
|
5
|
+
import {
|
|
6
|
+
useBookiLocaleOptional
|
|
7
|
+
} from "./chunk-GVP2N3K6.js";
|
|
8
|
+
|
|
9
|
+
// src/organization-number-input.tsx
|
|
10
|
+
import { isValidOrganizationNumber } from "@booki-aui/core/organization-number";
|
|
11
|
+
import { Field, FieldDescription, FieldError, FieldLabel } from "@ui-sdk/react/field";
|
|
12
|
+
import { createParts } from "@ui-sdk/react/primitive";
|
|
13
|
+
import { organizationNumber } from "@booki-aui/primitives/organization-number-input";
|
|
14
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
+
var TAGS = {
|
|
16
|
+
root: "div",
|
|
17
|
+
input: "input"
|
|
18
|
+
};
|
|
19
|
+
var parts = createParts(organizationNumber, TAGS);
|
|
20
|
+
var OrganizationNumberRoot = parts.Root;
|
|
21
|
+
var OrganizationNumberField = parts.Input;
|
|
22
|
+
function OrganizationNumberInput({
|
|
23
|
+
value,
|
|
24
|
+
defaultValue,
|
|
25
|
+
onValueChange,
|
|
26
|
+
required,
|
|
27
|
+
name,
|
|
28
|
+
id,
|
|
29
|
+
disabled,
|
|
30
|
+
readOnly,
|
|
31
|
+
className,
|
|
32
|
+
...props
|
|
33
|
+
}) {
|
|
34
|
+
const { profile } = useBookiLocaleOptional();
|
|
35
|
+
const kind = profile.organizationNumber.kind;
|
|
36
|
+
return /* @__PURE__ */ jsx(
|
|
37
|
+
OrganizationNumberRoot,
|
|
38
|
+
{
|
|
39
|
+
kind,
|
|
40
|
+
...value !== void 0 ? { value } : { defaultValue },
|
|
41
|
+
label: profile.organizationNumber.label,
|
|
42
|
+
description: profile.organizationNumber.description,
|
|
43
|
+
onValueChange,
|
|
44
|
+
disabled,
|
|
45
|
+
readOnly,
|
|
46
|
+
className,
|
|
47
|
+
"aria-label": profile.organizationNumber.label,
|
|
48
|
+
...props,
|
|
49
|
+
children: (state) => {
|
|
50
|
+
const invalid = state.digits.length > 0 && !isValidOrganizationNumber(state.digits, state.kind);
|
|
51
|
+
return /* @__PURE__ */ jsxs(Field, { invalid, children: [
|
|
52
|
+
/* @__PURE__ */ jsx(FieldLabel, { children: profile.organizationNumber.label }),
|
|
53
|
+
/* @__PURE__ */ jsx(FieldDescription, { children: profile.organizationNumber.description }),
|
|
54
|
+
/* @__PURE__ */ jsx(FormValue, { name, value: state.digits, disabled }),
|
|
55
|
+
/* @__PURE__ */ jsx(
|
|
56
|
+
OrganizationNumberField,
|
|
57
|
+
{
|
|
58
|
+
id,
|
|
59
|
+
required,
|
|
60
|
+
placeholder: profile.organizationNumber.placeholder ?? (kind === "ein" ? "12-3456789" : "974 760 673")
|
|
61
|
+
}
|
|
62
|
+
),
|
|
63
|
+
invalid ? /* @__PURE__ */ jsx(FieldError, { children: profile.organizationNumber.invalid ?? (kind === "ein" ? "Invalid EIN" : "Ugyldig organisasjonsnummer") }) : null
|
|
64
|
+
] });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export {
|
|
71
|
+
organizationNumber,
|
|
72
|
+
OrganizationNumberRoot,
|
|
73
|
+
OrganizationNumberField,
|
|
74
|
+
OrganizationNumberInput
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=chunk-SR2HEE4U.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/organization-number-input.tsx"],"sourcesContent":["import { isValidOrganizationNumber, type OrganizationNumberKind } from \"@booki-aui/core/organization-number\";\nimport { Field, FieldDescription, FieldError, FieldLabel } from \"@ui-sdk/react/field\";\nimport { createParts, type Parts } from \"@ui-sdk/react/primitive\";\nimport type { ComponentProps } from \"react\";\nimport { FormValue, type BookiFormProps } from \"./form-props.js\";\nimport { useBookiLocaleOptional } from \"./locale.js\";\nimport { organizationNumber } from \"@booki-aui/primitives/organization-number-input\";\n\nconst TAGS = {\n root: \"div\",\n input: \"input\",\n} as const;\n// Typed by name, so the declarations refer to the definition instead of spelling it out per part.\nconst parts: Parts<typeof organizationNumber, typeof TAGS> = createParts(organizationNumber, TAGS);\n\nconst OrganizationNumberRoot: (typeof parts)[\"Root\"] = parts.Root;\nconst OrganizationNumberField: (typeof parts)[\"Input\"] = parts.Input;\n\nexport type OrganizationNumberInputProps = {\n /** Controlled value. Omit it (and use `defaultValue`) to let the field hold its own state. */\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n required?: boolean;\n className?: string;\n} & Omit<BookiFormProps, \"required\"> &\n Omit<ComponentProps<\"div\">, \"onChange\" | \"defaultValue\" | \"children\" | \"id\">;\n\nfunction OrganizationNumberInput({\n value,\n defaultValue,\n onValueChange,\n required,\n name,\n id,\n disabled,\n readOnly,\n className,\n ...props\n}: OrganizationNumberInputProps) {\n const { profile } = useBookiLocaleOptional();\n const kind = profile.organizationNumber.kind;\n\n return (\n <OrganizationNumberRoot\n kind={kind}\n {...(value !== undefined ? { value } : { defaultValue })}\n label={profile.organizationNumber.label}\n description={profile.organizationNumber.description}\n onValueChange={onValueChange}\n disabled={disabled}\n readOnly={readOnly}\n className={className}\n aria-label={profile.organizationNumber.label}\n {...props}\n >\n {(state: { kind: OrganizationNumberKind; digits: string }) => {\n const invalid = state.digits.length > 0 && !isValidOrganizationNumber(state.digits, state.kind);\n return (\n <Field invalid={invalid}>\n <FieldLabel>{profile.organizationNumber.label}</FieldLabel>\n <FieldDescription>{profile.organizationNumber.description}</FieldDescription>\n {/* Digits only, without the display grouping. */}\n <FormValue name={name} value={state.digits} disabled={disabled} />\n <OrganizationNumberField\n id={id}\n required={required}\n placeholder={profile.organizationNumber.placeholder ?? (kind === \"ein\" ? \"12-3456789\" : \"974 760 673\")}\n />\n {invalid ? (\n <FieldError>\n {profile.organizationNumber.invalid ?? (kind === \"ein\" ? \"Invalid EIN\" : \"Ugyldig organisasjonsnummer\")}\n </FieldError>\n ) : null}\n </Field>\n );\n }}\n </OrganizationNumberRoot>\n );\n}\n\nexport { OrganizationNumberInput, OrganizationNumberRoot,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