@aparte/plugin-approval 1.9.0 → 1.10.1

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.
@@ -26,7 +26,7 @@ import { type ApprovalMode } from './policy.js';
26
26
  * </aparte-composer>
27
27
  * ```
28
28
  *
29
- * @fires {CustomEvent<AparteApprovalModeChangeEventDetail>} aparte-approval-mode-change - After a switch: `{ mode, previousMode }`. Bubbles and crosses shadow roots.
29
+ * @fires {CustomEvent<ApprovalModeChangeDetail>} aparte-approval-mode-change - After a switch: `{ mode, previousMode }`. Bubbles and crosses shadow roots.
30
30
  */
31
31
  export declare class AparteApprovalMode extends HTMLElement implements AparteConfigAware {
32
32
  private _cfg;
@@ -47,6 +47,13 @@ export declare class AparteApprovalMode extends HTMLElement implements AparteCon
47
47
  aparteConfigChanged(next: AparteConfig): void;
48
48
  private _bind;
49
49
  private _render;
50
+ /**
51
+ * The new names written into the options already drawn. A wrapper hands `labels` again on
52
+ * every render of the app around it, and drawing the select again would close its list under
53
+ * the person's pointer and drop the focus. A text node replaced is a `childList` change the
54
+ * select watches, so its trigger follows.
55
+ */
56
+ private _relabel;
50
57
  private _syncValue;
51
58
  }
52
59
  //# sourceMappingURL=aparte-approval-mode.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"aparte-approval-mode.d.ts","sourceRoot":"","sources":["../src/aparte-approval-mode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAEH,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAE5C,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAwC,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAItF;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,kBAAmB,SAAQ,WAAY,YAAW,iBAAiB;IAC5E,OAAO,CAAC,IAAI,CAA6B;IACzC,OAAO,CAAC,WAAW,CAAiC;IACpD,OAAO,CAAC,YAAY,CAA6B;IACjD,OAAO,CAAC,kBA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AAyB;IAC5E,IAAI,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,EAGrD;IAED,iDAAiD;IACjD,IAAI,IAAI,IAAI,YAAY,GAAG,IAAI,CAAgD;IAE/E,iBAAiB,IAAI,IAAI;IASzB,oBAAoB,IAAI,IAAI;IAS5B,uFAAuF;IACvF,mBAAmB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAI7C,OAAO,CAAC,KAAK;IAuBb,OAAO,CAAC,OAAO;IAef;;;;;OAKG;IACH,OAAO,CAAC,QAAQ;IAiBhB,OAAO,CAAC,UAAU;CAKrB"}
@@ -7,7 +7,7 @@
7
7
  * survives exactly as long as the page, and a host that wants it remembered reads
8
8
  * `getMode()` / `onModeChange` and writes wherever it keeps its preferences.
9
9
  */
10
- import { type AparteConfig } from '@aparte/core';
10
+ import { type AparteApprovalModeChangeEventDetail, type AparteConfig } from '@aparte/core';
11
11
  import { type ApprovalMode, type ApprovalClassification, type ToolClass } from './policy.js';
12
12
  export interface ApprovalSetupOptions {
13
13
  /** Your tool names, by what they do. Unlisted names keep their own `needsApproval`. */
@@ -22,6 +22,18 @@ export interface ApprovalSetupOptions {
22
22
  /** Called after every switch, with the new and the previous mode. */
23
23
  onModeChange?: (mode: ApprovalMode, previous: ApprovalMode) => void;
24
24
  }
25
+ /**
26
+ * The detail of `aparte-approval-mode-change` as this plugin sends it, from the switch or the
27
+ * `/approval` command: core's `AparteApprovalModeChangeEventDetail` with the modes narrowed to
28
+ * the four this plugin knows. Core types them as strings so it names none of them; a framework
29
+ * wrapper's callback (`onApprovalModeChange` in React) receives this one.
30
+ */
31
+ export interface ApprovalModeChangeDetail extends AparteApprovalModeChangeEventDetail {
32
+ /** The mode just switched to. */
33
+ mode: ApprovalMode;
34
+ /** The mode it replaced. */
35
+ previousMode: ApprovalMode;
36
+ }
25
37
  /** What `setupApproval` returns: the mode, readable and switchable, and the way out. */
26
38
  export interface ApprovalController {
27
39
  /** The four modes, in the order a switch presents them. */
@@ -1 +1 @@
1
- {"version":3,"file":"approval.d.ts","sourceRoot":"","sources":["../src/approval.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAEH,KAAK,YAAY,EACpB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAEH,KAAK,YAAY,EAAE,KAAK,sBAAsB,EAAE,KAAK,SAAS,EACjE,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,oBAAoB;IACjC,uFAAuF;IACvF,QAAQ,EAAE,sBAAsB,CAAC;IACjC,yCAAyC;IACzC,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qEAAqE;IACrE,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,KAAK,IAAI,CAAC;CACvE;AAED,wFAAwF;AACxF,MAAM,WAAW,kBAAkB;IAC/B,2DAA2D;IAC3D,QAAQ,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,CAAC;IACxC,OAAO,IAAI,YAAY,CAAC;IACxB,yFAAyF;IACzF,OAAO,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;IAClC,8DAA8D;IAC9D,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;IAC9C,4GAA4G;IAC5G,SAAS,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACtF,oEAAoE;IACpE,OAAO,IAAI,IAAI,CAAC;CACnB;AAWD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,EAAE,MAAM,GAAE,YAAiC,GAAG,kBAAkB,CAoE1H;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,GAAE,Y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;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,EAAE,MAAM,GAAE,YAAiC,GAAG,kBAAkB,CAkE1H;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,GAAE,YAAiC,GAAG,kBAAkB,GAAG,SAAS,CAI/G"}
@@ -133,6 +133,17 @@
133
133
  }
134
134
  }
135
135
  },
136
+ {
137
+ "kind": "method",
138
+ "name": "_relabel",
139
+ "privacy": "private",
140
+ "return": {
141
+ "type": {
142
+ "text": "void"
143
+ }
144
+ },
145
+ "description": "The new names written into the options already drawn. A wrapper hands `labels` again on\nevery render of the app around it, and drawing the select again would close its list under\nthe person's pointer and drop the focus. A text node replaced is a `childList` change the\nselect watches, so its trigger follows."
146
+ },
136
147
  {
137
148
  "kind": "method",
138
149
  "name": "_syncValue",
@@ -147,7 +158,7 @@
147
158
  "events": [
148
159
  {
149
160
  "type": {
150
- "text": "CustomEvent<AparteApprovalModeChangeEventDetail>"
161
+ "text": "CustomEvent<ApprovalModeChangeDetail>"
151
162
  },
152
163
  "description": "After a switch: `{ mode, previousMode }`. Bubbles and crosses shadow roots.",
153
164
  "name": "aparte-approval-mode-change"
@@ -287,6 +298,14 @@
287
298
  "module": "./approval.js"
288
299
  }
289
300
  },
301
+ {
302
+ "kind": "js",
303
+ "name": "ApprovalModeChangeDetail",
304
+ "declaration": {
305
+ "name": "ApprovalModeChangeDetail",
306
+ "module": "./approval.js"
307
+ }
308
+ },
290
309
  {
291
310
  "kind": "js",
292
311
  "name": "APPROVAL_MODES",
@@ -390,6 +409,14 @@
390
409
  "name": "AparteApprovalModeChangeEventDetail",
391
410
  "package": "@aparte/core"
392
411
  }
412
+ },
413
+ {
414
+ "kind": "js",
415
+ "name": "approvalModeElement",
416
+ "declaration": {
417
+ "name": "approvalModeElement",
418
+ "module": "./generated/element-specs.js"
419
+ }
393
420
  }
394
421
  ]
395
422
  },
@@ -430,6 +457,14 @@
430
457
  "module": "./approval.js"
431
458
  }
432
459
  },
460
+ {
461
+ "kind": "js",
462
+ "name": "ApprovalModeChangeDetail",
463
+ "declaration": {
464
+ "name": "ApprovalModeChangeDetail",
465
+ "module": "./approval.js"
466
+ }
467
+ },
433
468
  {
434
469
  "kind": "js",
435
470
  "name": "APPROVAL_MODES",
@@ -533,6 +568,14 @@
533
568
  "name": "AparteApprovalModeChangeEventDetail",
534
569
  "package": "@aparte/core"
535
570
  }
571
+ },
572
+ {
573
+ "kind": "js",
574
+ "name": "approvalModeElement",
575
+ "declaration": {
576
+ "name": "approvalModeElement",
577
+ "module": "./generated/element-specs.js"
578
+ }
536
579
  }
537
580
  ]
538
581
  },
@@ -679,6 +722,37 @@
679
722
  }
680
723
  }
681
724
  ]
725
+ },
726
+ {
727
+ "kind": "javascript-module",
728
+ "path": "src/generated/element-attributes.ts",
729
+ "declarations": [],
730
+ "exports": []
731
+ },
732
+ {
733
+ "kind": "javascript-module",
734
+ "path": "src/generated/element-specs.ts",
735
+ "declarations": [
736
+ {
737
+ "kind": "variable",
738
+ "name": "approvalModeElement",
739
+ "type": {
740
+ "text": "AparteElementSpec<\n AparteElementAttributes['aparte-approval-mode'],\n {\n /** The label of each mode, for a localised host. Missing entries keep the English default. */\n labels?: Partial<Record<ApprovalMode, string>>;\n },\n {\n /** After a switch: `{ mode, previousMode }`. Bubbles and crosses shadow roots. */\n 'aparte-approval-mode-change': { name: 'approvalModeChange'; detail: ApprovalModeChangeDetail };\n }\n>"
741
+ },
742
+ "default": "{ tag: 'aparte-approval-mode', attributes: [], properties: ['labels'], events: [ ['aparte-approval-mode-change', 'approvalModeChange'], ], initial: [], }",
743
+ "description": "The spec of `<aparte-approval-mode>`, for a framework wrapper (see `AparteElementSpec`): A select over the four approval modes — plan, ask, auto-edit, auto — bound to the `setupApproval()` of the config this element resolves."
744
+ }
745
+ ],
746
+ "exports": [
747
+ {
748
+ "kind": "js",
749
+ "name": "approvalModeElement",
750
+ "declaration": {
751
+ "name": "approvalModeElement",
752
+ "module": "src/generated/element-specs.ts"
753
+ }
754
+ }
755
+ ]
682
756
  }
683
757
  ]
684
758
  }
@@ -1,4 +1,4 @@
1
- import { aparteGlobalConfig } from "@aparte/core";
1
+ import { aparteGlobalConfig, dispatchChatEvent } from "@aparte/core";
2
2
  const APPROVAL_MODES = ["plan", "ask", "auto-edit", "auto"];
3
3
  const APPROVAL_MODE_LABELS = {
4
4
  plan: "Plan",
@@ -80,11 +80,7 @@ function setupApproval(options, config = aparteGlobalConfig) {
80
80
  const previousMode = mode;
81
81
  controller.setMode(candidate);
82
82
  if (mode === previousMode) return;
83
- context.composer.dispatchEvent(new CustomEvent("aparte-approval-mode-change", {
84
- bubbles: true,
85
- composed: true,
86
- detail: { mode: candidate, previousMode }
87
- }));
83
+ dispatchChatEvent(context.composer, "aparte-approval-mode-change", { mode: candidate, previousMode });
88
84
  }
89
85
  }))
90
86
  });
@@ -102,13 +98,23 @@ function getApprovalController(config = aparteGlobalConfig) {
102
98
  if (!controller) return void 0;
103
99
  return isInstalled(config) ? controller : void 0;
104
100
  }
101
+ const approvalModeElement = {
102
+ tag: "aparte-approval-mode",
103
+ attributes: [],
104
+ properties: ["labels"],
105
+ events: [
106
+ ["aparte-approval-mode-change", "approvalModeChange"]
107
+ ],
108
+ initial: []
109
+ };
105
110
  export {
106
111
  APPROVAL_MODES as A,
107
- createApprovalPolicy as a,
108
- APPROVAL_MODE_LABELS as b,
112
+ approvalModeElement as a,
113
+ createApprovalPolicy as b,
109
114
  classifyTool as c,
115
+ APPROVAL_MODE_LABELS as d,
110
116
  getApprovalController as g,
111
117
  rulingFor as r,
112
118
  setupApproval as s
113
119
  };
114
- //# sourceMappingURL=approval-X5hcL8E6.js.map
120
+ //# sourceMappingURL=element-specs-DmnbTBz_.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element-specs-DmnbTBz_.js","sources":["../src/policy.ts","../src/approval.ts","../src/generated/element-specs.ts"],"sourcesContent":["/**\n * The modes, the classes, and the table that joins them.\n *\n * A MODE is what the person switches (\"plan\", \"auto\"); a CLASS is what a tool does\n * (`read`, `write`, `exec`), declared by the host on ITS tool names — the names are\n * wire format the host owns, and no library can know that `run_command` executes and\n * `search_docs` reads. The table below is the whole policy: nine cells, no\n * configuration, so a consumer can read it in one glance and predict every ruling.\n *\n * Nothing here executes anything, remembers anything, or draws anything: it is a pure\n * function from (mode, class, call) to a ruling core already knows how to honour.\n */\nimport type { AparteApprovalPolicy, AparteApprovalRuling, AparteToolCall } from '@aparte/core';\n\n/**\n * `plan` runs read-only tools and refuses the rest with a sentence the model reads;\n * `ask` asks before every write or execution; `auto-edit` lets writes through and asks\n * before an execution; `auto` never asks.\n */\nexport type ApprovalMode = 'plan' | 'ask' | 'auto-edit' | 'auto';\n\n/** The four modes, in the order a switch presents them. */\nexport const APPROVAL_MODES: readonly ApprovalMode[] = ['plan', 'ask', 'auto-edit', 'auto'];\n\n/** What each mode is called, unless a host says otherwise. */\nexport const APPROVAL_MODE_LABELS: Record<ApprovalMode, string> = {\n plan: 'Plan',\n ask: 'Ask',\n 'auto-edit': 'Auto-edit',\n auto: 'Auto',\n};\n\n/** What a tool does — the axis the modes decide on. */\nexport type ToolClass = 'read' | 'write' | 'exec';\n\n/** A tool name, exactly, or a pattern over names. */\nexport type ToolMatcher = string | RegExp;\n\n/**\n * The host's tool names, by what they do. A name in no list is UNCLASSIFIED: its\n * own `needsApproval` decides (and `auto` still lets it through — auto is auto).\n */\nexport interface ApprovalClassification {\n read?: readonly ToolMatcher[];\n write?: readonly ToolMatcher[];\n exec?: readonly ToolMatcher[];\n}\n\n// `search`, not `test`: `test` advances `lastIndex` on a `g` or `y` regex the caller\n// owns, so the same name would classify differently on alternate calls — and the gate\n// predicate and the answering channel evaluate the policy one after the other.\nconst matches = (name: string, m: ToolMatcher): boolean =>\n typeof m === 'string' ? m === name : name.search(m) !== -1;\n\n/** The class of a tool name under a classification, or `undefined` when it is in no list. */\nexport function classifyTool(name: string, classification: ApprovalClassification): ToolClass | undefined {\n if (classification.exec?.some((m) => matches(name, m))) return 'exec';\n if (classification.write?.some((m) => matches(name, m))) return 'write';\n if (classification.read?.some((m) => matches(name, m))) return 'read';\n return undefined;\n}\n\nconst NOUN: Record<ToolClass, string> = { read: 'reads', write: 'changes files or state', exec: 'runs a command' };\n\n/**\n * The ruling for one call, from the table. `undefined` means \"no opinion\" — the tool's\n * own `needsApproval` decides, which is what core does when a policy says nothing.\n */\nexport function rulingFor(mode: ApprovalMode, cls: ToolClass | undefined, call: AparteToolCall): AparteApprovalRuling | undefined {\n if (mode === 'auto') return { verdict: 'allow' };\n if (cls === undefined) return undefined;\n if (cls === 'read') return { verdict: 'allow' };\n if (mode === 'plan') {\n return {\n verdict: 'deny',\n reason: `Plan mode: \\`${call.name}\\` ${NOUN[cls]}, and only read-only tools run in this mode. ` +\n 'Describe what you would do instead; the user can switch the mode to let you do it.',\n };\n }\n if (mode === 'auto-edit') return cls === 'write' ? { verdict: 'allow' } : { verdict: 'ask' };\n return { verdict: 'ask' };\n}\n\n/**\n * A core `AparteApprovalPolicy` that reads the CURRENT mode on every call — so a\n * switch flipped mid-run applies to the next tool call, not the next conversation.\n */\nexport function createApprovalPolicy(getMode: () => ApprovalMode, classification: ApprovalClassification): AparteApprovalPolicy {\n return (call) => rulingFor(getMode(), classifyTool(call.name, classification), call);\n}\n","/**\n * `setupApproval` — one call installs a mode-driven approval policy on a config.\n *\n * The plugin owns the MODE (a value the person switches) and the TABLE (policy.ts);\n * core owns the mechanism — `setApprovalPolicy`, the gate, the panel that asks, the\n * refusal the model reads. Nothing is executed here and nothing is stored: a mode\n * survives exactly as long as the page, and a host that wants it remembered reads\n * `getMode()` / `onModeChange` and writes wherever it keeps its preferences.\n */\nimport {\n aparteGlobalConfig, dispatchChatEvent, type AparteApprovalModeChangeEventDetail, type AparteCollectCommandsEventDetail,\n type AparteConfig, type AparteApprovalPolicy,\n} from '@aparte/core';\nimport type { AparteApprovalMode } from './aparte-approval-mode.js';\nimport {\n APPROVAL_MODES, APPROVAL_MODE_LABELS, createApprovalPolicy, classifyTool,\n type ApprovalMode, type ApprovalClassification, type ToolClass,\n} from './policy.js';\n\nexport interface ApprovalSetupOptions {\n /** Your tool names, by what they do. Unlisted names keep their own `needsApproval`. */\n classify: ApprovalClassification;\n /** The starting mode. Default: `ask`. */\n mode?: ApprovalMode;\n /**\n * Answer `@aparte/plugin-triggers`' menu with an `/approval` command. Default: `true`,\n * and with no menu on the page nothing asks.\n */\n commands?: boolean;\n /** Called after every switch, with the new and the previous mode. */\n onModeChange?: (mode: ApprovalMode, previous: ApprovalMode) => void;\n}\n\n/**\n * The detail of `aparte-approval-mode-change` as this plugin sends it, from the switch or the\n * `/approval` command: core's `AparteApprovalModeChangeEventDetail` with the modes narrowed to\n * the four this plugin knows. Core types them as strings so it names none of them; a framework\n * wrapper's callback (`onApprovalModeChange` in React) receives this one.\n */\nexport interface ApprovalModeChangeDetail extends AparteApprovalModeChangeEventDetail {\n /** The mode just switched to. */\n mode: ApprovalMode;\n /** The mode it replaced. */\n previousMode: ApprovalMode;\n}\n\n/** What `setupApproval` returns: the mode, readable and switchable, and the way out. */\nexport interface ApprovalController {\n /** The four modes, in the order a switch presents them. */\n readonly modes: readonly ApprovalMode[];\n getMode(): ApprovalMode;\n /** Switch the mode; the next tool call is ruled under it. Unknown values are ignored. */\n setMode(mode: ApprovalMode): void;\n /** The class this setup gives a tool name, or `undefined`. */\n classify(name: string): ToolClass | undefined;\n /** Be told of every switch — from `setMode` or from a `<aparte-approval-mode>`. Returns the unsubscribe. */\n subscribe(listener: (mode: ApprovalMode, previous: ApprovalMode) => void): () => void;\n /** Remove the policy from the config and forget this controller. */\n dispose(): void;\n}\n\nconst controllers = new WeakMap<AparteConfig, ApprovalController>();\n// The policy each controller installed, so a controller whose policy is gone — a\n// `config.reset()`, a `setApprovalPolicy(null)` from elsewhere — reads as no setup\n// rather than as a switch wired to nothing.\nconst installed = new WeakMap<AparteConfig, AparteApprovalPolicy>();\n/** Whether the policy on `config` is still the one this module installed there. */\nconst isInstalled = (config: AparteConfig): boolean =>\n config.getApprovalPolicy() === installed.get(config);\n\n/**\n * Install the policy on `config` (the global one by default) and return its controller.\n *\n * Calling it twice on one config replaces the first setup — its policy is removed and\n * its listeners dropped — so a hot-reloading host does not stack policies.\n *\n * @example\n * ```ts\n * import { setupApproval } from '@aparte/plugin-approval';\n *\n * const approval = setupApproval({\n * classify: {\n * read: ['read_file', 'search', /^list_/],\n * write: ['write_file', 'edit_file'],\n * exec: ['run_command'],\n * },\n * mode: 'ask',\n * }); // the config last, like every setup*: it defaults to the global\n * approval.setMode('plan'); // or drop <aparte-approval-mode> in the composer's toolbar\n * ```\n */\nexport function setupApproval(options: ApprovalSetupOptions, config: AparteConfig = aparteGlobalConfig): ApprovalController {\n controllers.get(config)?.dispose();\n\n let mode: ApprovalMode = options.mode ?? 'ask';\n const listeners = new Set<(mode: ApprovalMode, previous: ApprovalMode) => void>();\n if (options.onModeChange) listeners.add(options.onModeChange);\n\n const controller: ApprovalController = {\n modes: APPROVAL_MODES,\n getMode: () => mode,\n setMode(next) {\n if (!APPROVAL_MODES.includes(next) || next === mode) return;\n const previous = mode;\n mode = next;\n for (const l of listeners) l(next, previous);\n },\n classify: (name) => classifyTool(name, options.classify),\n subscribe(listener) {\n listeners.add(listener);\n return () => { listeners.delete(listener); };\n },\n dispose() {\n if (answersCommands) window.removeEventListener('aparte-collect-commands', onCollectCommands);\n if (controllers.get(config) === controller) {\n // Only the policy this setup installed: a config whose policy was since\n // replaced by someone else keeps that replacement.\n if (isInstalled(config)) config.setApprovalPolicy(null);\n controllers.delete(config);\n installed.delete(config);\n }\n listeners.clear();\n },\n };\n\n const onCollectCommands = (e: Event): void => {\n const { detail } = e as CustomEvent<AparteCollectCommandsEventDetail>;\n if (detail.config !== config) return;\n const labels = detail.composer?.querySelector<AparteApprovalMode>('aparte-approval-mode')?.labels;\n detail.add({\n id: 'approval',\n order: 70,\n description: config.t('triggersCommandApproval'),\n children: APPROVAL_MODES.map((candidate) => ({\n id: candidate,\n label: labels?.[candidate] ?? APPROVAL_MODE_LABELS[candidate],\n ...(candidate === mode ? { icon: 'check' } : {}),\n run: (context) => {\n const previousMode = mode;\n controller.setMode(candidate);\n if (mode === previousMode) return;\n // As the switch does: an app saves the choice from this event.\n dispatchChatEvent<ApprovalModeChangeDetail>(context.composer, 'aparte-approval-mode-change', { mode: candidate, previousMode });\n },\n })),\n });\n };\n const answersCommands = options.commands !== false && typeof window !== 'undefined';\n if (answersCommands) window.addEventListener('aparte-collect-commands', onCollectCommands);\n\n const policy = createApprovalPolicy(() => mode, options.classify);\n // Bookkeeping BEFORE the config is told: `setApprovalPolicy` notifies, and a mounted\n // switch re-resolves its controller on that notify — it must find this one.\n controllers.set(config, controller);\n installed.set(config, policy);\n config.setApprovalPolicy(policy);\n return controller;\n}\n\n/**\n * The controller `setupApproval` installed on a config, or `undefined` — also when\n * its policy has since been removed from the config (a `reset()`, a\n * `setApprovalPolicy(null)`): a switch must not look wired to a policy that is gone.\n * What a `<aparte-approval-mode>` element resolves through the config it sits in.\n */\nexport function getApprovalController(config: AparteConfig = aparteGlobalConfig): ApprovalController | undefined {\n const controller = controllers.get(config);\n if (!controller) return undefined;\n return isInstalled(config) ? controller : undefined;\n}\n","// AUTO-GENERATED by scripts/gen-element-bindings.mjs from this package's\n// custom-elements.json. Do not edit: it is gitignored and rewritten every build.\n// The source of every fact below is the element's own JSDoc.\n\n/**\n * Each element of this package described for a framework wrapper: an `AparteElementSpec`.\n *\n * React makes a component of one — `createAparteElement(spec)` from `@aparte/react` — and Vue and\n * Svelte type the tag from its type — `AparteVueElement<typeof spec>`, `AparteSvelteElement<typeof\n * spec>`. Generated from the package's manifest, so an attribute, a property or an event added to\n * an element reaches every framework with no edit.\n */\nimport type { AparteElementSpec } from '@aparte/core';\nimport type { AparteElementAttributes } from './element-attributes.js';\nimport type {\n ApprovalMode,\n ApprovalModeChangeDetail,\n} from '../index.js';\n\n/** The spec of `<aparte-approval-mode>`, for a framework wrapper (see `AparteElementSpec`): A select over the four approval modes — plan, ask, auto-edit, auto — bound to the `setupApproval()` of the config this element resolves. */\nexport const approvalModeElement: AparteElementSpec<\n AparteElementAttributes['aparte-approval-mode'],\n {\n /** The label of each mode, for a localised host. Missing entries keep the English default. */\n labels?: Partial<Record<ApprovalMode, string>>;\n },\n {\n /** After a switch: `{ mode, previousMode }`. Bubbles and crosses shadow roots. */\n 'aparte-approval-mode-change': { name: 'approvalModeChange'; detail: ApprovalModeChangeDetail };\n }\n> = {\n tag: 'aparte-approval-mode',\n attributes: [],\n properties: ['labels'],\n events: [\n ['aparte-approval-mode-change', 'approvalModeChange'],\n ],\n initial: [],\n};\n"],"names":[],"mappings":";AAsBO,MAAM,iBAA0C,CAAC,QAAQ,OAAO,aAAa,MAAM;AAGnF,MAAM,uBAAqD;AAAA,EAC9D,MAAM;AAAA,EACN,KAAK;AAAA,EACL,aAAa;AAAA,EACb,MAAM;AACV;AAqBA,MAAM,UAAU,CAAC,MAAc,MAC3B,OAAO,MAAM,WAAW,MAAM,OAAO,KAAK,OAAO,CAAC,MAAM;AAGrD,SAAS,aAAa,MAAc,gBAA+D;AACtG,MAAI,eAAe,MAAM,KAAK,CAAC,MAAM,QAAQ,MAAM,CAAC,CAAC,EAAG,QAAO;AAC/D,MAAI,eAAe,OAAO,KAAK,CAAC,MAAM,QAAQ,MAAM,CAAC,CAAC,EAAG,QAAO;AAChE,MAAI,eAAe,MAAM,KAAK,CAAC,MAAM,QAAQ,MAAM,CAAC,CAAC,EAAG,QAAO;AAC/D,SAAO;AACX;AAEA,MAAM,OAAkC,EAAE,MAAM,SAAS,OAAO,0BAA0B,MAAM,iBAAA;AAMzF,SAAS,UAAU,MAAoB,KAA4B,MAAwD;AAC9H,MAAI,SAAS,OAAQ,QAAO,EAAE,SAAS,QAAA;AACvC,MAAI,QAAQ,OAAW,QAAO;AAC9B,MAAI,QAAQ,OAAQ,QAAO,EAAE,SAAS,QAAA;AACtC,MA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,YAAY,CAAC,QAAQ;AAAA,EACrB,QAAQ;AAAA,IACJ,CAAC,+BAA+B,oBAAoB;AAAA,EAAA;AAAA,EAExD,SAAS,CAAA;AACb;"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The elements that observe no attribute at all. An empty surface is the honest
3
+ * declaration — it says "checked, there are none", where an absent entry would only
4
+ * say "not looked at": `<aparte-approval-mode>`.
5
+ */
6
+ export type AparteNoAttributes = Record<never, never>;
7
+ /**
8
+ * Tag name to its attribute surface — the registry every wrapper maps over.
9
+ *
10
+ * Total by construction: it is generated from the manifest, so an element cannot be
11
+ * missing from it, which is the property a hand-written list could not have.
12
+ */
13
+ export interface AparteElementAttributes {
14
+ 'aparte-approval-mode': AparteNoAttributes;
15
+ }
16
+ /** Every tag this package defines, derived from the registry so the two cannot diverge. */
17
+ export type AparteElementTagName = keyof AparteElementAttributes;
18
+ //# sourceMappingURL=element-attributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element-attributes.d.ts","sourceRoot":"","sources":["../../src/generated/element-attributes.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,WAAW,uBAAuB;IACpC,sBAAsB,EAAE,kBAAkB,CAAC;CAC9C;AAED,2FAA2F;AAC3F,MAAM,MAAM,oBAAoB,GAAG,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Each element of this package described for a framework wrapper: an `AparteElementSpec`.
3
+ *
4
+ * React makes a component of one — `createAparteElement(spec)` from `@aparte/react` — and Vue and
5
+ * Svelte type the tag from its type — `AparteVueElement<typeof spec>`, `AparteSvelteElement<typeof
6
+ * spec>`. Generated from the package's manifest, so an attribute, a property or an event added to
7
+ * an element reaches every framework with no edit.
8
+ */
9
+ import type { AparteElementSpec } from '@aparte/core';
10
+ import type { AparteElementAttributes } from './element-attributes.js';
11
+ import type { ApprovalMode, ApprovalModeChangeDetail } from '../index.js';
12
+ /** The spec of `<aparte-approval-mode>`, for a framework wrapper (see `AparteElementSpec`): A select over the four approval modes — plan, ask, auto-edit, auto — bound to the `setupApproval()` of the config this element resolves. */
13
+ export declare const approvalModeElement: AparteElementSpec<AparteElementAttributes['aparte-approval-mode'], {
14
+ /** The label of each mode, for a localised host. Missing entries keep the English default. */
15
+ labels?: Partial<Record<ApprovalMode, string>>;
16
+ }, {
17
+ /** After a switch: `{ mode, previousMode }`. Bubbles and crosses shadow roots. */
18
+ 'aparte-approval-mode-change': {
19
+ name: 'approvalModeChange';
20
+ detail: ApprovalModeChangeDetail;
21
+ };
22
+ }>;
23
+ //# sourceMappingURL=element-specs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element-specs.d.ts","sourceRoot":"","sources":["../../src/generated/element-specs.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,KAAK,EACR,YAAY,EACZ,wBAAwB,EAC3B,MAAM,aAAa,CAAC;AAErB,wOAAwO;AACxO,eAAO,MAAM,mBAAmB,EAAE,iBAAiB,CAC/C,uBAAuB,CAAC,sBAAsB,CAAC,EAC/C;IACI,8FAA8F;IAC9F,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;CAClD,EACD;IACI,kFAAkF;IAClF,6BAA6B,EAAE;QAAE,IAAI,EAAE,oBAAoB,CAAC;QAAC,MAAM,EAAE,wBAAwB,CAAA;KAAE,CAAC;CACnG,CASJ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -9,9 +9,10 @@
9
9
  * nothing and stores nothing.
10
10
  */
11
11
  export { setupApproval, getApprovalController } from './approval.js';
12
- export type { ApprovalSetupOptions, ApprovalController } from './approval.js';
12
+ export type { ApprovalSetupOptions, ApprovalController, ApprovalModeChangeDetail } from './approval.js';
13
13
  export { APPROVAL_MODES, classifyTool, rulingFor, createApprovalPolicy } from './policy.js';
14
14
  export type { ApprovalMode, ToolClass, ToolMatcher, ApprovalClassification } from './policy.js';
15
15
  export { AparteApprovalMode } from './aparte-approval-mode.js';
16
16
  export type { AparteApprovalPolicy, AparteApprovalRuling, AparteToolCall, AparteApprovalModeChangeEventDetail, } from '@aparte/core';
17
+ export { approvalModeElement } from './generated/element-specs.js';
17
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACrE,YAAY,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC5F,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,YAAY,EACR,oBAAoB,EAAE,oBAAoB,EAAE,cAAc,EAAE,mCAAmC,GAClG,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACrE,YAAY,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACxG,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC5F,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,YAAY,EACR,oBAAoB,EAAE,oBAAoB,EAAE,cAAc,EAAE,mCAAmC,GAClG,MAAM,cAAc,CAAC;AAKtB,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { A as APPROVAL_MODES, g as getApprovalController, b as APPROVAL_MODE_LABELS } from "./approval-X5hcL8E6.js";
2
- import { c, a, r, s } from "./approval-X5hcL8E6.js";
3
- import { deferHydrationOf, resolveConfig, subscribeConfigChange, escapeAttr, escapeHtml } from "@aparte/core";
1
+ import { A as APPROVAL_MODES, g as getApprovalController, d as APPROVAL_MODE_LABELS } from "./element-specs-DmnbTBz_.js";
2
+ import { a, c, b, r, s } from "./element-specs-DmnbTBz_.js";
3
+ import { deferHydrationOf, dispatchChatEvent, resolveConfig, subscribeConfigChange, escapeAttr, escapeHtml, cssEscape } from "@aparte/core";
4
4
  const DEFAULT_LABELS = APPROVAL_MODE_LABELS;
5
5
  class AparteApprovalMode extends HTMLElement {
6
6
  _cfg = null;
@@ -16,11 +16,7 @@ class AparteApprovalMode extends HTMLElement {
16
16
  const previous = this._controller.getMode();
17
17
  this._controller.setMode(next);
18
18
  if (this._controller.getMode() !== previous) {
19
- this.dispatchEvent(new CustomEvent("aparte-approval-mode-change", {
20
- bubbles: true,
21
- composed: true,
22
- detail: { mode: next, previousMode: previous }
23
- }));
19
+ dispatchChatEvent(this, "aparte-approval-mode-change", { mode: next, previousMode: previous });
24
20
  }
25
21
  };
26
22
  /** The label of each mode, for a localised host. Missing entries keep the English default. */
@@ -29,7 +25,7 @@ class AparteApprovalMode extends HTMLElement {
29
25
  }
30
26
  set labels(next) {
31
27
  this._labels = next ?? {};
32
- if (this.isConnected) this._render();
28
+ if (this.isConnected) this._relabel();
33
29
  }
34
30
  /** The current mode, or `null` with no setup. */
35
31
  get mode() {
@@ -76,6 +72,28 @@ class AparteApprovalMode extends HTMLElement {
76
72
  this.innerHTML = `<aparte-select${current ? ` value="${escapeAttr(current)}"` : ""}${controller ? "" : " disabled"} aria-label="${escapeAttr(aria)}">${options}</aparte-select>`;
77
73
  this.querySelector("aparte-select")?.addEventListener("aparte-select-change", this._onChange);
78
74
  }
75
+ /**
76
+ * The new names written into the options already drawn. A wrapper hands `labels` again on
77
+ * every render of the app around it, and drawing the select again would close its list under
78
+ * the person's pointer and drop the focus. A text node replaced is a `childList` change the
79
+ * select watches, so its trigger follows.
80
+ */
81
+ _relabel() {
82
+ const select = this.querySelector("aparte-select");
83
+ if (!select) {
84
+ this._render();
85
+ return;
86
+ }
87
+ for (const mode of APPROVAL_MODES) {
88
+ const option = select.querySelector(`aparte-option[value="${cssEscape(mode)}"]`);
89
+ if (!option) {
90
+ this._render();
91
+ return;
92
+ }
93
+ const label = this._labels[mode] ?? DEFAULT_LABELS[mode];
94
+ if (option.textContent !== label) option.replaceChildren(label);
95
+ }
96
+ }
79
97
  _syncValue() {
80
98
  const select = this.querySelector("aparte-select");
81
99
  const mode = this._controller?.getMode();
@@ -89,8 +107,9 @@ if (typeof customElements !== "undefined" && !customElements.get("aparte-approva
89
107
  export {
90
108
  APPROVAL_MODES,
91
109
  AparteApprovalMode,
110
+ a as approvalModeElement,
92
111
  c as classifyTool,
93
- a as createApprovalPolicy,
112
+ b as createApprovalPolicy,
94
113
  getApprovalController,
95
114
  r as rulingFor,
96
115
  s as setupApproval
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/aparte-approval-mode.ts"],"sourcesContent":["/**\n * `<aparte-approval-mode>` — the switch between the four modes, for the composer's toolbar.\n *\n * Mounted where the host wants it, like `<aparte-model-selector>`: the composer is light\n * DOM with no registry, so a control is placed by writing its tag inside\n * `<aparte-composer-toolbar>`. It resolves the config it sits in (`resolveConfig`) and the\n * controller `setupApproval` installed there — with none, it renders disabled and says\n * so once in the console, the way core does for a missing presenter: an affordance that\n * cannot act is not offered.\n */\nimport {\n resolveConfig, subscribeConfigChange, escapeHtml, escapeAttr, deferHydrationOf,\n type AparteConfig, type AparteConfigAware, type AparteSelectChangeDetail,\n type AparteApprovalModeChangeEventDetail,\n} from '@aparte/core';\nimport { getApprovalController, type ApprovalController } from './approval.js';\nimport { APPROVAL_MODES, APPROVAL_MODE_LABELS, type ApprovalMode } from './policy.js';\n\nconst DEFAULT_LABELS = APPROVAL_MODE_LABELS;\n\n/**\n * A select over the four approval modes — plan, ask, auto-edit, auto — bound to the\n * `setupApproval()` of the config this element resolves.\n *\n * @element aparte-approval-mode\n *\n * @example Beside the model selector, in the composer's toolbar\n * ```html\n * <aparte-composer>\n * <aparte-composer-input></aparte-composer-input>\n * <aparte-composer-toolbar>\n * <aparte-approval-mode></aparte-approval-mode>\n * </aparte-composer-toolbar>\n * </aparte-composer>\n * ```\n *\n * @fires {CustomEvent<AparteApprovalModeChangeEventDetail>} aparte-approval-mode-change - After a switch: `{ mode, previousMode }`. Bubbles and crosses shadow roots.\n */\nexport class AparteApprovalMode extends HTMLElement implements AparteConfigAware {\n private _cfg: AparteConfig | null = null;\n private _controller: ApprovalController | undefined;\n private _unsubscribe: (() => void) | null = null;\n private _configUnsubscribe: (() => void) | null = null;\n private _bound = false;\n private _labels: Partial<Record<ApprovalMode, string>> = {};\n private readonly _onChange = (e: Event): void => {\n const detail = (e as CustomEvent<AparteSelectChangeDetail>).detail;\n const next = detail?.value as ApprovalMode;\n if (!this._controller || !APPROVAL_MODES.includes(next)) return;\n const previous = this._controller.getMode();\n this._controller.setMode(next);\n if (this._controller.getMode() !== previous) {\n this.dispatchEvent(new CustomEvent<AparteApprovalModeChangeEventDetail>('aparte-approval-mode-change', {\n bubbles: true, composed: true, detail: { mode: next, previousMode: previous },\n }));\n }\n };\n\n /** The label of each mode, for a localised host. Missing entries keep the English default. */\n get labels(): Partial<Record<ApprovalMode, string>> { return this._labels; }\n set labels(next: Partial<Record<ApprovalMode, string>>) {\n this._labels = next ?? {};\n if (this.isConnected) this._render();\n }\n\n /** The current mode, or `null` with no setup. */\n get mode(): ApprovalMode | null { return this._controller?.getMode() ?? null; }\n\n connectedCallback(): void {\n this._bind(resolveConfig(this));\n // A setup that arrives AFTER this element mounted (a later script, a dynamic\n // import), or one that goes away (`dispose()`, `config.reset()`): the config\n // notifies on `setApprovalPolicy`, and the switch re-resolves its controller\n // rather than staying disabled — or wired to nothing — for the life of the page.\n this._configUnsubscribe = subscribeConfigChange(this, () => this._bind(resolveConfig(this)));\n }\n\n disconnectedCallback(): void {\n this._unsubscribe?.();\n this._unsubscribe = null;\n this._configUnsubscribe?.();\n this._configUnsubscribe = null;\n this._bound = false;\n this.querySelector('aparte-select')?.removeEventListener('aparte-select-change', this._onChange);\n }\n\n /** See `AparteConfigAware`: a boundary moved, so the controller may be another one. */\n aparteConfigChanged(next: AparteConfig): void {\n this._bind(next);\n }\n\n private _bind(cfg: AparteConfig): void {\n const next = getApprovalController(cfg);\n // An unrelated notify (a locale, a provider) must not rebuild the select under an\n // open dropdown: same config, same controller, nothing to rebind.\n if (this._bound && cfg === this._cfg && next === this._controller) return;\n this._bound = true;\n this._cfg = cfg;\n this._unsubscribe?.();\n this._controller = next;\n if (!this._controller) {\n // Asked once the module that imported the plugin has run its body. Importing the\n // plugin defines this element, so a tag already in the page binds BEFORE the\n // `setupApproval()` that comes next in the documented order — and the warning\n // fired for a setup that was a line away.\n queueMicrotask(() => {\n if (this._controller || !this.isConnected) return;\n console.warn('[aparte] <aparte-approval-mode> found no approval setup on the config it resolves — call setupApproval() from @aparte/plugin-approval on that config (the scoped one if you passed a `config`, aparteGlobalConfig otherwise).');\n });\n }\n this._unsubscribe = this._controller?.subscribe(() => this._syncValue()) ?? null;\n this._render();\n }\n\n private _render(): void {\n const controller = this._controller;\n const current = controller?.getMode();\n const options = APPROVAL_MODES.map((m) =>\n `<aparte-option value=\"${escapeAttr(m)}\">${escapeHtml(this._labels[m] ?? DEFAULT_LABELS[m])}</aparte-option>`).join('');\n this.querySelector('aparte-select')?.removeEventListener('aparte-select-change', this._onChange);\n // The select carries no class of ours: `aparte-approval-mode aparte-select` is\n // already the address a consumer restyling it writes.\n // The accessible name follows the locale like the option labels do — a\n // literal here was the one string a localised host could not translate.\n const aria = String(this._cfg?.getLocale()['approvalModeLabel'] || 'Approval mode');\n this.innerHTML = `<aparte-select${current ? ` value=\"${escapeAttr(current)}\"` : ''}${controller ? '' : ' disabled'} aria-label=\"${escapeAttr(aria)}\">${options}</aparte-select>`;\n this.querySelector('aparte-select')?.addEventListener('aparte-select-change', this._onChange);\n }\n\n private _syncValue(): void {\n const select = this.querySelector('aparte-select') as (HTMLElement & { value: string }) | null;\n const mode = this._controller?.getMode();\n if (select && mode && select.value !== mode) select.value = mode;\n }\n}\n\nif (typeof customElements !== 'undefined' && !customElements.get('aparte-approval-mode')) {\n // Before defining, like core's own elements: in a server-rendered chat the tag waits\n // for the wrapper's release instead of drawing into the DOM the framework hydrates.\n deferHydrationOf(AparteApprovalMode);\n customElements.define('aparte-approval-mode', AparteApprovalMode);\n}\n"],"names":[],"mappings":";;;AAkBA,MAAM,iBAAiB;AAoBhB,MAAM,2BAA2B,YAAyC;AAAA,EACrE,OAA4B;AAAA,EAC5B;AAAA,EACA,eAAoC;AAAA,EACpC,qBAA0C;AAAA,EAC1C,SAAS;AAAA,EACT,UAAiD,CAAA;AAAA,EACxC,YAAY,CAAC,MAAmB;AAC7C,UAAM,SAAU,EAA4C;AAC5D,UAAM,OAAO,QAAQ;AACrB,QAAI,CAAC,KAAK,eAAe,CAAC,eAAe,SAAS,IAAI,EAAG;AACzD,UAAM,WAAW,KAAK,YAAY,QAAA;AAClC,SAAK,YAAY,QAAQ,IAAI;AAC7B,QAAI,KAAK,YAAY,QAAA,MAAc,UAAU;AACzC,WAAK,cAAc,IAAI,YAAiD,+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EACT;AAAA,EAEQ,UAAgB;AACpB,UAAM,aAAa,KAAK;AACxB,UAAM,UAAU,YAAY,QAAA;AAC5B,UAAM,UAAU,eAAe,IAAI,CAAC,MAChC,yBAAyB,WAAW,CAAC,CAAC,KAAK,WAAW,KAAK,QAAQ,CAAC,KAAK,eAAe,CAAC,CAAC,CAAC,kBAAkB,EAAE,KAAK,EAAE;AAC1H,SAAK,cAAc,eAAe,GAAG,oBAAoB,wBAAwB,KAAK,SAAS;AAK/F,UAAM,OAAO,OAAO,KAAK,MAAM,YAAY,mBAAmB,KAAK,eAAe;AAClF,SAAK,YAAY,iBAAiB,UAAU,WAAW,WAAW,OAAO,CAAC,MAAM,EAAE,GAAG,aAAa,KAAK,WAAW,gBAAgB,WAAW,IAAI,CAAC,KAAK,OAAO;AAC9J,SAAK,cAAc,eAAe,GAAG,iBAAiB,wBAAwB,KAAK,SAAS;AAAA,EAChG;AAAA,EAEQ,aAAmB;AACvB,UAAM,SAAS,KAAK,cAAc,eAAe;AACjD,UAAM,OAAO,KAAK,aAAa,QAAA;AAC/B,QAAI,UAAU,QAAQ,OAAO,UAAU,aAAa,QAAQ;AAAA,EAChE;AACJ;AAEA,IAAI,OAAO,mBAAmB,eAAe,CAAC,eAAe,IAAI,sBAAsB,GAAG;AAGtF,mBAAiB,kBAAkB;AACnC,iBAAe,OAAO,wBAAwB,kBAAkB;AACpE;"}
1
+ {"version":3,"file":"index.js","sources":["../src/aparte-approval-mode.ts"],"sourcesContent":["/**\n * `<aparte-approval-mode>` — the switch between the four modes, for the composer's toolbar.\n *\n * Mounted where the host wants it, like `<aparte-model-selector>`: the composer is light\n * DOM with no registry, so a control is placed by writing its tag inside\n * `<aparte-composer-toolbar>`. It resolves the config it sits in (`resolveConfig`) and the\n * controller `setupApproval` installed there — with none, it renders disabled and says\n * so once in the console, the way core does for a missing presenter: an affordance that\n * cannot act is not offered.\n */\nimport {\n resolveConfig, subscribeConfigChange, escapeHtml, escapeAttr, cssEscape, deferHydrationOf, dispatchChatEvent,\n type AparteConfig, type AparteConfigAware, type AparteSelectChangeDetail,\n} from '@aparte/core';\nimport { getApprovalController, type ApprovalController, type ApprovalModeChangeDetail } from './approval.js';\nimport { APPROVAL_MODES, APPROVAL_MODE_LABELS, type ApprovalMode } from './policy.js';\n\nconst DEFAULT_LABELS = APPROVAL_MODE_LABELS;\n\n/**\n * A select over the four approval modes — plan, ask, auto-edit, auto — bound to the\n * `setupApproval()` of the config this element resolves.\n *\n * @element aparte-approval-mode\n *\n * @example Beside the model selector, in the composer's toolbar\n * ```html\n * <aparte-composer>\n * <aparte-composer-input></aparte-composer-input>\n * <aparte-composer-toolbar>\n * <aparte-approval-mode></aparte-approval-mode>\n * </aparte-composer-toolbar>\n * </aparte-composer>\n * ```\n *\n * @fires {CustomEvent<ApprovalModeChangeDetail>} aparte-approval-mode-change - After a switch: `{ mode, previousMode }`. Bubbles and crosses shadow roots.\n */\nexport class AparteApprovalMode extends HTMLElement implements AparteConfigAware {\n private _cfg: AparteConfig | null = null;\n private _controller: ApprovalController | undefined;\n private _unsubscribe: (() => void) | null = null;\n private _configUnsubscribe: (() => void) | null = null;\n private _bound = false;\n private _labels: Partial<Record<ApprovalMode, string>> = {};\n private readonly _onChange = (e: Event): void => {\n const detail = (e as CustomEvent<AparteSelectChangeDetail>).detail;\n const next = detail?.value as ApprovalMode;\n if (!this._controller || !APPROVAL_MODES.includes(next)) return;\n const previous = this._controller.getMode();\n this._controller.setMode(next);\n if (this._controller.getMode() !== previous) {\n // Stamped with the chat it came from: a page with several acts on the right one.\n dispatchChatEvent<ApprovalModeChangeDetail>(this, 'aparte-approval-mode-change', { mode: next, previousMode: previous });\n }\n };\n\n /** The label of each mode, for a localised host. Missing entries keep the English default. */\n get labels(): Partial<Record<ApprovalMode, string>> { return this._labels; }\n set labels(next: Partial<Record<ApprovalMode, string>>) {\n this._labels = next ?? {};\n if (this.isConnected) this._relabel();\n }\n\n /** The current mode, or `null` with no setup. */\n get mode(): ApprovalMode | null { return this._controller?.getMode() ?? null; }\n\n connectedCallback(): void {\n this._bind(resolveConfig(this));\n // A setup that arrives AFTER this element mounted (a later script, a dynamic\n // import), or one that goes away (`dispose()`, `config.reset()`): the config\n // notifies on `setApprovalPolicy`, and the switch re-resolves its controller\n // rather than staying disabled — or wired to nothing — for the life of the page.\n this._configUnsubscribe = subscribeConfigChange(this, () => this._bind(resolveConfig(this)));\n }\n\n disconnectedCallback(): void {\n this._unsubscribe?.();\n this._unsubscribe = null;\n this._configUnsubscribe?.();\n this._configUnsubscribe = null;\n this._bound = false;\n this.querySelector('aparte-select')?.removeEventListener('aparte-select-change', this._onChange);\n }\n\n /** See `AparteConfigAware`: a boundary moved, so the controller may be another one. */\n aparteConfigChanged(next: AparteConfig): void {\n this._bind(next);\n }\n\n private _bind(cfg: AparteConfig): void {\n const next = getApprovalController(cfg);\n // An unrelated notify (a locale, a provider) must not rebuild the select under an\n // open dropdown: same config, same controller, nothing to rebind.\n if (this._bound && cfg === this._cfg && next === this._controller) return;\n this._bound = true;\n this._cfg = cfg;\n this._unsubscribe?.();\n this._controller = next;\n if (!this._controller) {\n // Asked once the module that imported the plugin has run its body. Importing the\n // plugin defines this element, so a tag already in the page binds BEFORE the\n // `setupApproval()` that comes next in the documented order — and the warning\n // fired for a setup that was a line away.\n queueMicrotask(() => {\n if (this._controller || !this.isConnected) return;\n console.warn('[aparte] <aparte-approval-mode> found no approval setup on the config it resolves — call setupApproval() from @aparte/plugin-approval on that config (the scoped one if you passed a `config`, aparteGlobalConfig otherwise).');\n });\n }\n this._unsubscribe = this._controller?.subscribe(() => this._syncValue()) ?? null;\n this._render();\n }\n\n private _render(): void {\n const controller = this._controller;\n const current = controller?.getMode();\n const options = APPROVAL_MODES.map((m) =>\n `<aparte-option value=\"${escapeAttr(m)}\">${escapeHtml(this._labels[m] ?? DEFAULT_LABELS[m])}</aparte-option>`).join('');\n this.querySelector('aparte-select')?.removeEventListener('aparte-select-change', this._onChange);\n // The select carries no class of ours: `aparte-approval-mode aparte-select` is\n // already the address a consumer restyling it writes.\n // The accessible name follows the locale like the option labels do — a\n // literal here was the one string a localised host could not translate.\n const aria = String(this._cfg?.getLocale()['approvalModeLabel'] || 'Approval mode');\n this.innerHTML = `<aparte-select${current ? ` value=\"${escapeAttr(current)}\"` : ''}${controller ? '' : ' disabled'} aria-label=\"${escapeAttr(aria)}\">${options}</aparte-select>`;\n this.querySelector('aparte-select')?.addEventListener('aparte-select-change', this._onChange);\n }\n\n /**\n * The new names written into the options already drawn. A wrapper hands `labels` again on\n * every render of the app around it, and drawing the select again would close its list under\n * the person's pointer and drop the focus. A text node replaced is a `childList` change the\n * select watches, so its trigger follows.\n */\n private _relabel(): void {\n const select = this.querySelector('aparte-select');\n if (!select) {\n this._render();\n return;\n }\n for (const mode of APPROVAL_MODES) {\n const option = select.querySelector(`aparte-option[value=\"${cssEscape(mode)}\"]`);\n if (!option) {\n this._render();\n return;\n }\n const label = this._labels[mode] ?? DEFAULT_LABELS[mode];\n if (option.textContent !== label) option.replaceChildren(label);\n }\n }\n\n private _syncValue(): void {\n const select = this.querySelector('aparte-select') as (HTMLElement & { value: string }) | null;\n const mode = this._controller?.getMode();\n if (select && mode && select.value !== mode) select.value = mode;\n }\n}\n\nif (typeof customElements !== 'undefined' && !customElements.get('aparte-approval-mode')) {\n // Before defining, like core's own elements: in a server-rendered chat the tag waits\n // for the wrapper's release instead of drawing into the DOM the framework hydrates.\n deferHydrationOf(AparteApprovalMode);\n customElements.define('aparte-approval-mode', AparteApprovalMode);\n}\n"],"names":[],"mappings":";;;AAiBA,MAAM,iBAAiB;AAoBhB,MAAM,2BAA2B,YAAyC;AAAA,EACrE,OAA4B;AAAA,EAC5B;AAAA,EACA,eAAoC;AAAA,EACpC,qBAA0C;AAAA,EAC1C,SAAS;AAAA,EACT,UAAiD,CAAA;AAAA,EACxC,YAAY,CAAC,MAAmB;AAC7C,UAAM,SAAU,EAA4C;AAC5D,UAAM,OAAO,QAAQ;AACrB,QAAI,CAAC,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,QAAQ;AAAA,EAChE;AACJ;AAEA,IAAI,OAAO,mBAAmB,eAAe,CAAC,eAAe,IAAI,sBAAsB,GAAG;AAGtF,mBAAiB,kBAAkB;AACnC,iBAAe,OAAO,wBAAwB,kBAAkB;AACpE;"}
@@ -8,9 +8,10 @@
8
8
  * this entry keeps importing without a DOM.
9
9
  */
10
10
  export { setupApproval, getApprovalController } from './approval.js';
11
- export type { ApprovalSetupOptions, ApprovalController } from './approval.js';
11
+ export type { ApprovalSetupOptions, ApprovalController, ApprovalModeChangeDetail } from './approval.js';
12
12
  export { APPROVAL_MODES, classifyTool, rulingFor, createApprovalPolicy } from './policy.js';
13
13
  export type { ApprovalMode, ToolClass, ToolMatcher, ApprovalClassification } from './policy.js';
14
14
  export type { AparteApprovalMode } from './aparte-approval-mode.js';
15
15
  export type { AparteApprovalPolicy, AparteApprovalRuling, AparteToolCall, AparteApprovalModeChangeEventDetail, } from '@aparte/core';
16
+ export { approvalModeElement } from './generated/element-specs.js';
16
17
  //# sourceMappingURL=index.node.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.node.d.ts","sourceRoot":"","sources":["../src/index.node.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACrE,YAAY,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC5F,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAGhG,YAAY,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,YAAY,EACR,oBAAoB,EAAE,oBAAoB,EAAE,cAAc,EAAE,mCAAmC,GAClG,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.node.d.ts","sourceRoot":"","sources":["../src/index.node.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACrE,YAAY,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACxG,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC5F,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAGhG,YAAY,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,YAAY,EACR,oBAAoB,EAAE,oBAAoB,EAAE,cAAc,EAAE,mCAAmC,GAClG,MAAM,cAAc,CAAC;AAKtB,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC"}
@@ -1,8 +1,9 @@
1
- import { A, c, a, g, r, s } from "./approval-X5hcL8E6.js";
1
+ import { A, a, c, b, g, r, s } from "./element-specs-DmnbTBz_.js";
2
2
  export {
3
3
  A as APPROVAL_MODES,
4
+ a as approvalModeElement,
4
5
  c as classifyTool,
5
- a as createApprovalPolicy,
6
+ b as createApprovalPolicy,
6
7
  g as getApprovalController,
7
8
  r as rulingFor,
8
9
  s as setupApproval
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aparte/plugin-approval",
3
- "version": "1.9.0",
3
+ "version": "1.10.1",
4
4
  "homepage": "https://apartejs.dev/components/approval-mode/",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -53,13 +53,13 @@
53
53
  "node": ">=18"
54
54
  },
55
55
  "peerDependencies": {
56
- "@aparte/core": ">=1.9.0 <2.0.0"
56
+ "@aparte/core": ">=1.10.1 <2.0.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@custom-elements-manifest/analyzer": "^0.11.0",
60
60
  "typescript": "^5.4.0",
61
61
  "vite": "^6.0.0",
62
- "@aparte/core": "1.9.0"
62
+ "@aparte/core": "1.10.1"
63
63
  },
64
64
  "keywords": [
65
65
  "aparte",
@@ -83,6 +83,7 @@
83
83
  "dev": "vite",
84
84
  "build": "vite build && tsc -b --emitDeclarationOnly --force && pnpm run analyze && node ../../../scripts/stamp-dist.mjs",
85
85
  "analyze": "cem analyze",
86
+ "gen": "pnpm run analyze && node ../../../scripts/gen-element-bindings.mjs packages/plugins/approval --registry packages/plugins/approval/src/generated --specs packages/plugins/approval/src/generated",
86
87
  "preview": "vite preview",
87
88
  "test": "vitest",
88
89
  "test:run": "vitest run",
@@ -1 +0,0 @@
1
- {"version":3,"file":"approval-X5hcL8E6.js","sources":["../src/policy.ts","../src/approval.ts"],"sourcesContent":["/**\n * The modes, the classes, and the table that joins them.\n *\n * A MODE is what the person switches (\"plan\", \"auto\"); a CLASS is what a tool does\n * (`read`, `write`, `exec`), declared by the host on ITS tool names — the names are\n * wire format the host owns, and no library can know that `run_command` executes and\n * `search_docs` reads. The table below is the whole policy: nine cells, no\n * configuration, so a consumer can read it in one glance and predict every ruling.\n *\n * Nothing here executes anything, remembers anything, or draws anything: it is a pure\n * function from (mode, class, call) to a ruling core already knows how to honour.\n */\nimport type { AparteApprovalPolicy, AparteApprovalRuling, AparteToolCall } from '@aparte/core';\n\n/**\n * `plan` runs read-only tools and refuses the rest with a sentence the model reads;\n * `ask` asks before every write or execution; `auto-edit` lets writes through and asks\n * before an execution; `auto` never asks.\n */\nexport type ApprovalMode = 'plan' | 'ask' | 'auto-edit' | 'auto';\n\n/** The four modes, in the order a switch presents them. */\nexport const APPROVAL_MODES: readonly ApprovalMode[] = ['plan', 'ask', 'auto-edit', 'auto'];\n\n/** What each mode is called, unless a host says otherwise. */\nexport const APPROVAL_MODE_LABELS: Record<ApprovalMode, string> = {\n plan: 'Plan',\n ask: 'Ask',\n 'auto-edit': 'Auto-edit',\n auto: 'Auto',\n};\n\n/** What a tool does — the axis the modes decide on. */\nexport type ToolClass = 'read' | 'write' | 'exec';\n\n/** A tool name, exactly, or a pattern over names. */\nexport type ToolMatcher = string | RegExp;\n\n/**\n * The host's tool names, by what they do. A name in no list is UNCLASSIFIED: its\n * own `needsApproval` decides (and `auto` still lets it through — auto is auto).\n */\nexport interface ApprovalClassification {\n read?: readonly ToolMatcher[];\n write?: readonly ToolMatcher[];\n exec?: readonly ToolMatcher[];\n}\n\n// `search`, not `test`: `test` advances `lastIndex` on a `g` or `y` regex the caller\n// owns, so the same name would classify differently on alternate calls — and the gate\n// predicate and the answering channel evaluate the policy one after the other.\nconst matches = (name: string, m: ToolMatcher): boolean =>\n typeof m === 'string' ? m === name : name.search(m) !== -1;\n\n/** The class of a tool name under a classification, or `undefined` when it is in no list. */\nexport function classifyTool(name: string, classification: ApprovalClassification): ToolClass | undefined {\n if (classification.exec?.some((m) => matches(name, m))) return 'exec';\n if (classification.write?.some((m) => matches(name, m))) return 'write';\n if (classification.read?.some((m) => matches(name, m))) return 'read';\n return undefined;\n}\n\nconst NOUN: Record<ToolClass, string> = { read: 'reads', write: 'changes files or state', exec: 'runs a command' };\n\n/**\n * The ruling for one call, from the table. `undefined` means \"no opinion\" — the tool's\n * own `needsApproval` decides, which is what core does when a policy says nothing.\n */\nexport function rulingFor(mode: ApprovalMode, cls: ToolClass | undefined, call: AparteToolCall): AparteApprovalRuling | undefined {\n if (mode === 'auto') return { verdict: 'allow' };\n if (cls === undefined) return undefined;\n if (cls === 'read') return { verdict: 'allow' };\n if (mode === 'plan') {\n return {\n verdict: 'deny',\n reason: `Plan mode: \\`${call.name}\\` ${NOUN[cls]}, and only read-only tools run in this mode. ` +\n 'Describe what you would do instead; the user can switch the mode to let you do it.',\n };\n }\n if (mode === 'auto-edit') return cls === 'write' ? { verdict: 'allow' } : { verdict: 'ask' };\n return { verdict: 'ask' };\n}\n\n/**\n * A core `AparteApprovalPolicy` that reads the CURRENT mode on every call — so a\n * switch flipped mid-run applies to the next tool call, not the next conversation.\n */\nexport function createApprovalPolicy(getMode: () => ApprovalMode, classification: ApprovalClassification): AparteApprovalPolicy {\n return (call) => rulingFor(getMode(), classifyTool(call.name, classification), call);\n}\n","/**\n * `setupApproval` — one call installs a mode-driven approval policy on a config.\n *\n * The plugin owns the MODE (a value the person switches) and the TABLE (policy.ts);\n * core owns the mechanism — `setApprovalPolicy`, the gate, the panel that asks, the\n * refusal the model reads. Nothing is executed here and nothing is stored: a mode\n * survives exactly as long as the page, and a host that wants it remembered reads\n * `getMode()` / `onModeChange` and writes wherever it keeps its preferences.\n */\nimport {\n aparteGlobalConfig, type AparteApprovalModeChangeEventDetail, type AparteCollectCommandsEventDetail,\n type AparteConfig, type AparteApprovalPolicy,\n} from '@aparte/core';\nimport type { AparteApprovalMode } from './aparte-approval-mode.js';\nimport {\n APPROVAL_MODES, APPROVAL_MODE_LABELS, createApprovalPolicy, classifyTool,\n type ApprovalMode, type ApprovalClassification, type ToolClass,\n} from './policy.js';\n\nexport interface ApprovalSetupOptions {\n /** Your tool names, by what they do. Unlisted names keep their own `needsApproval`. */\n classify: ApprovalClassification;\n /** The starting mode. Default: `ask`. */\n mode?: ApprovalMode;\n /**\n * Answer `@aparte/plugin-triggers`' menu with an `/approval` command. Default: `true`,\n * and with no menu on the page nothing asks.\n */\n commands?: boolean;\n /** Called after every switch, with the new and the previous mode. */\n onModeChange?: (mode: ApprovalMode, previous: ApprovalMode) => void;\n}\n\n/** What `setupApproval` returns: the mode, readable and switchable, and the way out. */\nexport interface ApprovalController {\n /** The four modes, in the order a switch presents them. */\n readonly modes: readonly ApprovalMode[];\n getMode(): ApprovalMode;\n /** Switch the mode; the next tool call is ruled under it. Unknown values are ignored. */\n setMode(mode: ApprovalMode): void;\n /** The class this setup gives a tool name, or `undefined`. */\n classify(name: string): ToolClass | undefined;\n /** Be told of every switch — from `setMode` or from a `<aparte-approval-mode>`. Returns the unsubscribe. */\n subscribe(listener: (mode: ApprovalMode, previous: ApprovalMode) => void): () => void;\n /** Remove the policy from the config and forget this controller. */\n dispose(): void;\n}\n\nconst controllers = new WeakMap<AparteConfig, ApprovalController>();\n// The policy each controller installed, so a controller whose policy is gone — a\n// `config.reset()`, a `setApprovalPolicy(null)` from elsewhere — reads as no setup\n// rather than as a switch wired to nothing.\nconst installed = new WeakMap<AparteConfig, AparteApprovalPolicy>();\n/** Whether the policy on `config` is still the one this module installed there. */\nconst isInstalled = (config: AparteConfig): boolean =>\n config.getApprovalPolicy() === installed.get(config);\n\n/**\n * Install the policy on `config` (the global one by default) and return its controller.\n *\n * Calling it twice on one config replaces the first setup — its policy is removed and\n * its listeners dropped — so a hot-reloading host does not stack policies.\n *\n * @example\n * ```ts\n * import { setupApproval } from '@aparte/plugin-approval';\n *\n * const approval = setupApproval({\n * classify: {\n * read: ['read_file', 'search', /^list_/],\n * write: ['write_file', 'edit_file'],\n * exec: ['run_command'],\n * },\n * mode: 'ask',\n * }); // the config last, like every setup*: it defaults to the global\n * approval.setMode('plan'); // or drop <aparte-approval-mode> in the composer's toolbar\n * ```\n */\nexport function setupApproval(options: ApprovalSetupOptions, config: AparteConfig = aparteGlobalConfig): ApprovalController {\n controllers.get(config)?.dispose();\n\n let mode: ApprovalMode = options.mode ?? 'ask';\n const listeners = new Set<(mode: ApprovalMode, previous: ApprovalMode) => void>();\n if (options.onModeChange) listeners.add(options.onModeChange);\n\n const controller: ApprovalController = {\n modes: APPROVAL_MODES,\n getMode: () => mode,\n setMode(next) {\n if (!APPROVAL_MODES.includes(next) || next === mode) return;\n const previous = mode;\n mode = next;\n for (const l of listeners) l(next, previous);\n },\n classify: (name) => classifyTool(name, options.classify),\n subscribe(listener) {\n listeners.add(listener);\n return () => { listeners.delete(listener); };\n },\n dispose() {\n if (answersCommands) window.removeEventListener('aparte-collect-commands', onCollectCommands);\n if (controllers.get(config) === controller) {\n // Only the policy this setup installed: a config whose policy was since\n // replaced by someone else keeps that replacement.\n if (isInstalled(config)) config.setApprovalPolicy(null);\n controllers.delete(config);\n installed.delete(config);\n }\n listeners.clear();\n },\n };\n\n const onCollectCommands = (e: Event): void => {\n const { detail } = e as CustomEvent<AparteCollectCommandsEventDetail>;\n if (detail.config !== config) return;\n const labels = detail.composer?.querySelector<AparteApprovalMode>('aparte-approval-mode')?.labels;\n detail.add({\n id: 'approval',\n order: 70,\n description: config.t('triggersCommandApproval'),\n children: APPROVAL_MODES.map((candidate) => ({\n id: candidate,\n label: labels?.[candidate] ?? APPROVAL_MODE_LABELS[candidate],\n ...(candidate === mode ? { icon: 'check' } : {}),\n run: (context) => {\n const previousMode = mode;\n controller.setMode(candidate);\n if (mode === previousMode) return;\n // As the switch does: an app saves the choice from this event.\n context.composer.dispatchEvent(new CustomEvent<AparteApprovalModeChangeEventDetail>('aparte-approval-mode-change', {\n bubbles: true, composed: true, detail: { mode: candidate, previousMode },\n }));\n },\n })),\n });\n };\n const answersCommands = options.commands !== false && typeof window !== 'undefined';\n if (answersCommands) window.addEventListener('aparte-collect-commands', onCollectCommands);\n\n const policy = createApprovalPolicy(() => mode, options.classify);\n // Bookkeeping BEFORE the config is told: `setApprovalPolicy` notifies, and a mounted\n // switch re-resolves its controller on that notify — it must find this one.\n controllers.set(config, controller);\n installed.set(config, policy);\n config.setApprovalPolicy(policy);\n return controller;\n}\n\n/**\n * The controller `setupApproval` installed on a config, or `undefined` — also when\n * its policy has since been removed from the config (a `reset()`, a\n * `setApprovalPolicy(null)`): a switch must not look wired to a policy that is gone.\n * What a `<aparte-approval-mode>` element resolves through the config it sits in.\n */\nexport function getApprovalController(config: AparteConfig = aparteGlobalConfig): ApprovalController | undefined {\n const controller = controllers.get(config);\n if (!controller) return undefined;\n return isInstalled(config) ? controller : undefined;\n}\n"],"names":[],"mappings":";AAsBO,MAAM,iBAA0C,CAAC,QAAQ,OAAO,aAAa,MAAM;AAGnF,MAAM,uBAAqD;AAAA,EAC9D,MAAM;AAAA,EACN,KAAK;AAAA,EACL,aAAa;AAAA,EACb,MAAM;AACV;AAqBA,MAAM,UAAU,CAAC,MAAc,MAC3B,OA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