@aparte/plugin-approval 1.10.0 → 1.11.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.
@@ -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;
@@ -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,kBAAkB,CAA6B;IACvD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAA6C;IAC5D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAUxB;IAEF,8FAA8F;IAC9F,IAAI,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAyB;IAC5E,IAAI,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,EAGrD;IAED,iDAAiD;IAC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7C,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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ModeChangeEventDetail>"
161
+ "text": "CustomEvent<ApprovalModeChangeDetail>"
162
162
  },
163
163
  "description": "After a switch: `{ mode, previousMode }`. Bubbles and crosses shadow roots.",
164
164
  "name": "aparte-approval-mode-change"
@@ -298,6 +298,14 @@
298
298
  "module": "./approval.js"
299
299
  }
300
300
  },
301
+ {
302
+ "kind": "js",
303
+ "name": "ApprovalModeChangeDetail",
304
+ "declaration": {
305
+ "name": "ApprovalModeChangeDetail",
306
+ "module": "./approval.js"
307
+ }
308
+ },
301
309
  {
302
310
  "kind": "js",
303
311
  "name": "APPROVAL_MODES",
@@ -449,6 +457,14 @@
449
457
  "module": "./approval.js"
450
458
  }
451
459
  },
460
+ {
461
+ "kind": "js",
462
+ "name": "ApprovalModeChangeDetail",
463
+ "declaration": {
464
+ "name": "ApprovalModeChangeDetail",
465
+ "module": "./approval.js"
466
+ }
467
+ },
452
468
  {
453
469
  "kind": "js",
454
470
  "name": "APPROVAL_MODES",
@@ -721,7 +737,7 @@
721
737
  "kind": "variable",
722
738
  "name": "approvalModeElement",
723
739
  "type": {
724
- "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: AparteApprovalModeChangeEventDetail };\n }\n>"
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>"
725
741
  },
726
742
  "default": "{ tag: 'aparte-approval-mode', attributes: [], properties: ['labels'], events: [ ['aparte-approval-mode-change', 'approvalModeChange'], ], initial: [], }",
727
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."
@@ -1 +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/** 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<AparteApprovalModeChangeEventDetail>(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 AparteApprovalModeChangeEventDetail,\n ApprovalMode,\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: AparteApprovalModeChangeEventDetail };\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,MAAI,SAAS,QAAQ;AAC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Q;AAAA,EACrB,QAAQ;AAAA,IACJ,CAAC,+BAA+B,oBAAoB;AAAA,EAAA;AAAA,EAExD,SAAS,CAAA;AACb;"}
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,S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AQO,SAAS,sBAAsB,SAAuB,oBAAoD;AAC7G,QAAM,aAAa,YAAY,IAAI,MAAM;AACzC,MAAI,CAAC,WAAY,QAAO;AACxB,SAAO,YAAY,MAAM,IAAI,aAAa;AAC9C;ACrJO,MAAM,sBAUT;AAAA,EACA,KAAK;AAAA,EACL,YAAY,CAAA;AAAA,EACZ,YAAY,CAAC,QAAQ;AAAA,EACrB,QAAQ;AAAA,IACJ,CAAC,+BAA+B,oBAAoB;AAAA,EAAA;AAAA,EAExD,SAAS,CAAA;AACb;"}
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import type { AparteElementSpec } from '@aparte/core';
10
10
  import type { AparteElementAttributes } from './element-attributes.js';
11
- import type { AparteApprovalModeChangeEventDetail, ApprovalMode } from '../index.js';
11
+ import type { ApprovalMode, ApprovalModeChangeDetail } from '../index.js';
12
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
13
  export declare const approvalModeElement: AparteElementSpec<AparteElementAttributes['aparte-approval-mode'], {
14
14
  /** The label of each mode, for a localised host. Missing entries keep the English default. */
@@ -17,7 +17,7 @@ export declare const approvalModeElement: AparteElementSpec<AparteElementAttribu
17
17
  /** After a switch: `{ mode, previousMode }`. Bubbles and crosses shadow roots. */
18
18
  'aparte-approval-mode-change': {
19
19
  name: 'approvalModeChange';
20
- detail: AparteApprovalModeChangeEventDetail;
20
+ detail: ApprovalModeChangeDetail;
21
21
  };
22
22
  }>;
23
23
  //# sourceMappingURL=element-specs.d.ts.map
@@ -1 +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,mCAAmC,EACnC,YAAY,EACf,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,mCAAmC,CAAA;KAAE,CAAC;CAC9G,CASJ,CAAC"}
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,7 +9,7 @@
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';
@@ -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;AAKtB,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,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.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, cssEscape, deferHydrationOf, dispatchChatEvent,\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 // Stamped with the chat it came from: a page with several acts on the right one.\n dispatchChatEvent<AparteApprovalModeChangeEventDetail>(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":";;;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;AAEzC,wBAAuD,MAAM,+BAA+B,EAAE,MAAM,MAAM,cAAc,UAAU;AAAA,IACtI;AAAA,EACJ;AAAA;AAAA,EAGA,IAAI,SAAgD;AAAE,WAAO,KAAK;AAAA,EAAS;AAAA,EAC3E,IAAI,OAAO,MAA6C;AACpD,SAAK,UAAU,QAAQ,CAAA;AACvB,QAAI,KAAK,YAAa,MAAK,SAAA;AAAA,EAC/B;AAAA;AAAA,EAGA,IAAI,OAA4B;AAAE,WAAO,KAAK,aAAa,QAAA,KAAa;AAAA,EAAM;AAAA,EAE9E,oBAA0B;AACtB,SAAK,MAAM,cAAc,IAAI,CAAC;AAK9B,SAAK,qBAAqB,sBAAsB,MAAM,MAAM,KAAK,MAAM,cAAc,IAAI,CAAC,CAAC;AAAA,EAC/F;AAAA,EAEA,uBAA6B;AACzB,SAAK,eAAA;AACL,SAAK,eAAe;AACpB,SAAK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Q,WAAiB;AACrB,UAAM,SAAS,KAAK,cAAc,eAAe;AACjD,QAAI,CAAC,QAAQ;AACT,WAAK,QAAA;AACL;AAAA,IACJ;AACA,eAAW,QAAQ,gBAAgB;AAC/B,YAAM,SAAS,OAAO,cAAc,wBAAwB,UAAU,IAAI,CAAC,IAAI;AAC/E,UAAI,CAAC,QAAQ;AACT,aAAK,QAAA;AACL;AAAA,MACJ;AACA,YAAM,QAAQ,KAAK,QAAQ,IAAI,KAAK,eAAe,IAAI;AACvD,UAAI,OAAO,gBAAgB,MAAO,QAAO,gBAAgB,KAAK;AAAA,IAClE;AAAA,EACJ;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,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;AAEzC,wBAA4C,MAAM,+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 @@
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';
@@ -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;AAKtB,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aparte/plugin-approval",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
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.10.0 <2.0.0"
56
+ "@aparte/core": ">=1.11.0 <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.10.0"
62
+ "@aparte/core": "1.11.0"
63
63
  },
64
64
  "keywords": [
65
65
  "aparte",