@mushinjs/core 0.0.0-stage → 0.2.0-next.20261112161842

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Setobox
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,83 @@
1
+ import { Context, Service } from "cordis";
2
+ import { z } from "zod";
3
+ declare module 'cordis' {
4
+ interface Context {
5
+ actions: Actions;
6
+ /** The instance directory: config file, data and local plugins live here. */
7
+ baseDir: string;
8
+ /** Set by `mushin test`: bots stay offline and nothing reaches the outside. The launcher always sets it. */
9
+ offline: boolean;
10
+ }
11
+ interface Events {
12
+ 'actions/changed'(): void;
13
+ 'actions/called'(record: ActionCallRecord): void;
14
+ }
15
+ }
16
+ export type Risk = 'read' | 'write' | 'dangerous';
17
+ export interface ActionCaller {
18
+ kind: 'api' | 'agent' | 'internal';
19
+ /** Agent session id, when the Agent made the call. */
20
+ session?: string;
21
+ /** Dashboard connection id, used to route client actions back to the right tab. */
22
+ client?: string;
23
+ }
24
+ export interface ActionDefinition<S extends z.ZodType = z.ZodType, R = unknown> {
25
+ /** Dotted lowercase name, such as `bots.create`. */
26
+ name: string;
27
+ /** Written for the Agent: what the action does and what it returns. */
28
+ description: string;
29
+ input: S;
30
+ /** JSON Schema shown instead of the one made from `input`, for tools described elsewhere (such as MCP tools). */
31
+ inputSchema?: JsonSchema;
32
+ risk: Risk;
33
+ /** Client actions run in the dashboard; the server relays them to the caller's tab. */
34
+ client?: boolean;
35
+ /**
36
+ * False keeps the action away from the Agent: dashboard plumbing (editor previews, debugger
37
+ * controls) that only makes sense next to a screen and would only distract the model.
38
+ */
39
+ agent?: false;
40
+ handler?: (input: z.output<S>, caller: ActionCaller) => R | Promise<R>;
41
+ }
42
+ export interface ActionInfo {
43
+ name: string;
44
+ description: string;
45
+ risk: Risk;
46
+ client: boolean;
47
+ /** False when the Agent never sees the action; see `ActionDefinition.agent`. */
48
+ agent: boolean;
49
+ plugin: string;
50
+ inputSchema: JsonSchema;
51
+ }
52
+ export interface ActionCallRecord {
53
+ name: string;
54
+ caller: ActionCaller;
55
+ ok: boolean;
56
+ durationMs: number;
57
+ error?: string;
58
+ }
59
+ export type JsonSchema = Record<string, any>;
60
+ export type ClientRelay = (name: string, input: unknown, caller: ActionCaller) => Promise<unknown>;
61
+ /** Converts a zod schema to the JSON Schema shown to LLMs and dashboard forms. */
62
+ export declare function toJsonSchema(schema: z.ZodType): JsonSchema;
63
+ /**
64
+ * The registry of typed operations. The HTTP API and the Agent both call actions,
65
+ * so a feature a plugin exposes here is reachable from the dashboard and by conversation.
66
+ */
67
+ export declare class Actions extends Service {
68
+ private store;
69
+ private relay?;
70
+ constructor(ctx: Context);
71
+ /** Registers an action. It is removed when the calling plugin unloads. */
72
+ define<S extends z.ZodType, R>(definition: ActionDefinition<S, R>): import("cordis").Disposable<Promise<void>>;
73
+ /** Lets the console relay client actions to dashboard tabs. */
74
+ setClientRelay(relay: ClientRelay): import("cordis").Disposable<Promise<void>>;
75
+ has(name: string): boolean;
76
+ get(name: string): ActionInfo | undefined;
77
+ list(): ActionInfo[];
78
+ private info;
79
+ call(name: string, input: unknown, caller?: ActionCaller): Promise<unknown>;
80
+ }
81
+ /** OpenAI tool names allow only letters, digits, `_` and `-`, so dots become double underscores. */
82
+ export declare function toToolName(action: string): string;
83
+ export declare function fromToolName(tool: string): string;
@@ -0,0 +1,114 @@
1
+ import { MushinError } from "./errors.js";
2
+ import { Service } from "cordis";
3
+ import { z } from "zod";
4
+ // src/actions.ts
5
+ /** Converts a zod schema to the JSON Schema shown to LLMs and dashboard forms. */
6
+ function toJsonSchema(schema) {
7
+ const { $schema, ...rest } = z.toJSONSchema(schema, {
8
+ io: "input",
9
+ unrepresentable: "any"
10
+ });
11
+ return rest;
12
+ }
13
+ const namePattern = /^[a-z][a-zA-Z0-9]*(\.[a-z][a-zA-Z0-9]*)+$/;
14
+ /**
15
+ * The registry of typed operations. The HTTP API and the Agent both call actions,
16
+ * so a feature a plugin exposes here is reachable from the dashboard and by conversation.
17
+ */
18
+ var Actions = class extends Service {
19
+ store = /* @__PURE__ */ new Map();
20
+ relay;
21
+ constructor(ctx) {
22
+ super(ctx, "actions");
23
+ }
24
+ /** Registers an action. It is removed when the calling plugin unloads. */
25
+ define(definition) {
26
+ if (!namePattern.test(definition.name)) throw new Error(`invalid action name "${definition.name}", expected a dotted name such as "bots.create"`);
27
+ if (!definition.client && !definition.handler) throw new Error(`action "${definition.name}" needs a handler`);
28
+ const ctx = this.ctx;
29
+ return ctx.effect(() => {
30
+ if (this.store.has(definition.name)) throw new Error(`action "${definition.name}" is already defined`);
31
+ this.store.set(definition.name, {
32
+ ...definition,
33
+ plugin: ctx.fiber.name
34
+ });
35
+ ctx.emit("actions/changed");
36
+ return () => {
37
+ this.store.delete(definition.name);
38
+ ctx.emit("actions/changed");
39
+ };
40
+ }, `actions.define(${definition.name})`);
41
+ }
42
+ /** Lets the console relay client actions to dashboard tabs. */
43
+ setClientRelay(relay) {
44
+ return this.ctx.effect(() => {
45
+ this.relay = relay;
46
+ return () => {
47
+ if (this.relay === relay) this.relay = void 0;
48
+ };
49
+ }, "actions.setClientRelay()");
50
+ }
51
+ has(name) {
52
+ return this.store.has(name);
53
+ }
54
+ get(name) {
55
+ const action = this.store.get(name);
56
+ return action && this.info(action);
57
+ }
58
+ list() {
59
+ return [...this.store.values()].map((action) => this.info(action)).sort((a, b) => a.name.localeCompare(b.name));
60
+ }
61
+ info(action) {
62
+ action.schema ??= action.inputSchema ?? toJsonSchema(action.input);
63
+ return {
64
+ name: action.name,
65
+ description: action.description,
66
+ risk: action.risk,
67
+ client: !!action.client,
68
+ agent: action.agent !== false,
69
+ plugin: action.plugin,
70
+ inputSchema: action.schema
71
+ };
72
+ }
73
+ async call(name, input, caller = { kind: "internal" }) {
74
+ const action = this.store.get(name);
75
+ if (!action) throw new MushinError("not_found", `Unknown action: ${name}`);
76
+ const parsed = action.input.safeParse(input ?? {});
77
+ if (!parsed.success) throw new MushinError("invalid_input", z.prettifyError(parsed.error), parsed.error.issues);
78
+ const start = Date.now();
79
+ try {
80
+ let result;
81
+ if (action.client) {
82
+ if (!this.relay) throw new MushinError("unavailable", "No dashboard is connected to run this action");
83
+ result = await this.relay(name, parsed.data, caller);
84
+ } else result = await action.handler(parsed.data, caller);
85
+ this.ctx.emit("actions/called", {
86
+ name,
87
+ caller,
88
+ ok: true,
89
+ durationMs: Date.now() - start
90
+ });
91
+ return result;
92
+ } catch (error) {
93
+ const message = error instanceof Error ? error.message : String(error);
94
+ this.ctx.emit("actions/called", {
95
+ name,
96
+ caller,
97
+ ok: false,
98
+ durationMs: Date.now() - start,
99
+ error: message
100
+ });
101
+ throw error;
102
+ }
103
+ }
104
+ };
105
+ /** OpenAI tool names allow only letters, digits, `_` and `-`, so dots become double underscores. */
106
+ function toToolName(action) {
107
+ return action.replaceAll(".", "__");
108
+ }
109
+ function fromToolName(tool) {
110
+ return tool.replaceAll("__", ".");
111
+ }
112
+ export { Actions, fromToolName, toJsonSchema, toToolName };
113
+
114
+ //# sourceMappingURL=actions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.js","names":[],"sources":["../src/actions.ts"],"sourcesContent":["import { Context, Service } from 'cordis'\nimport { z } from 'zod'\nimport { MushinError } from './errors'\n\ndeclare module 'cordis' {\n interface Context {\n actions: Actions\n /** The instance directory: config file, data and local plugins live here. */\n baseDir: string\n /** Set by `mushin test`: bots stay offline and nothing reaches the outside. The launcher always sets it. */\n offline: boolean\n }\n\n interface Events {\n 'actions/changed'(): void\n 'actions/called'(record: ActionCallRecord): void\n }\n}\n\nexport type Risk = 'read' | 'write' | 'dangerous'\n\nexport interface ActionCaller {\n kind: 'api' | 'agent' | 'internal'\n /** Agent session id, when the Agent made the call. */\n session?: string\n /** Dashboard connection id, used to route client actions back to the right tab. */\n client?: string\n}\n\nexport interface ActionDefinition<S extends z.ZodType = z.ZodType, R = unknown> {\n /** Dotted lowercase name, such as `bots.create`. */\n name: string\n /** Written for the Agent: what the action does and what it returns. */\n description: string\n input: S\n /** JSON Schema shown instead of the one made from `input`, for tools described elsewhere (such as MCP tools). */\n inputSchema?: JsonSchema\n risk: Risk\n /** Client actions run in the dashboard; the server relays them to the caller's tab. */\n client?: boolean\n /**\n * False keeps the action away from the Agent: dashboard plumbing (editor previews, debugger\n * controls) that only makes sense next to a screen and would only distract the model.\n */\n agent?: false\n handler?: (input: z.output<S>, caller: ActionCaller) => R | Promise<R>\n}\n\nexport interface ActionInfo {\n name: string\n description: string\n risk: Risk\n client: boolean\n /** False when the Agent never sees the action; see `ActionDefinition.agent`. */\n agent: boolean\n plugin: string\n inputSchema: JsonSchema\n}\n\nexport interface ActionCallRecord {\n name: string\n caller: ActionCaller\n ok: boolean\n durationMs: number\n error?: string\n}\n\nexport type JsonSchema = Record<string, any>\n\nexport type ClientRelay = (name: string, input: unknown, caller: ActionCaller) => Promise<unknown>\n\ninterface StoredAction extends ActionDefinition {\n plugin: string\n schema?: JsonSchema\n}\n\n/** Converts a zod schema to the JSON Schema shown to LLMs and dashboard forms. */\nexport function toJsonSchema(schema: z.ZodType): JsonSchema {\n const { $schema, ...rest } = z.toJSONSchema(schema, { io: 'input', unrepresentable: 'any' }) as JsonSchema\n return rest\n}\n\nconst namePattern = /^[a-z][a-zA-Z0-9]*(\\.[a-z][a-zA-Z0-9]*)+$/\n\n/**\n * The registry of typed operations. The HTTP API and the Agent both call actions,\n * so a feature a plugin exposes here is reachable from the dashboard and by conversation.\n */\nexport class Actions extends Service {\n private store = new Map<string, StoredAction>()\n private relay?: ClientRelay\n\n constructor(ctx: Context) {\n super(ctx, 'actions')\n }\n\n /** Registers an action. It is removed when the calling plugin unloads. */\n define<S extends z.ZodType, R>(definition: ActionDefinition<S, R>) {\n if (!namePattern.test(definition.name)) {\n throw new Error(`invalid action name \"${definition.name}\", expected a dotted name such as \"bots.create\"`)\n }\n if (!definition.client && !definition.handler) {\n throw new Error(`action \"${definition.name}\" needs a handler`)\n }\n const ctx = this.ctx\n return ctx.effect(() => {\n if (this.store.has(definition.name)) {\n throw new Error(`action \"${definition.name}\" is already defined`)\n }\n this.store.set(definition.name, { ...(definition as ActionDefinition), plugin: ctx.fiber.name })\n ctx.emit('actions/changed')\n return () => {\n this.store.delete(definition.name)\n ctx.emit('actions/changed')\n }\n }, `actions.define(${definition.name})`)\n }\n\n /** Lets the console relay client actions to dashboard tabs. */\n setClientRelay(relay: ClientRelay) {\n return this.ctx.effect(() => {\n this.relay = relay\n return () => {\n if (this.relay === relay) this.relay = undefined\n }\n }, 'actions.setClientRelay()')\n }\n\n has(name: string) {\n return this.store.has(name)\n }\n\n get(name: string): ActionInfo | undefined {\n const action = this.store.get(name)\n return action && this.info(action)\n }\n\n list(): ActionInfo[] {\n return [...this.store.values()].map((action) => this.info(action)).sort((a, b) => a.name.localeCompare(b.name))\n }\n\n private info(action: StoredAction): ActionInfo {\n action.schema ??= action.inputSchema ?? toJsonSchema(action.input)\n return {\n name: action.name,\n description: action.description,\n risk: action.risk,\n client: !!action.client,\n agent: action.agent !== false,\n plugin: action.plugin,\n inputSchema: action.schema,\n }\n }\n\n async call(name: string, input: unknown, caller: ActionCaller = { kind: 'internal' }): Promise<unknown> {\n const action = this.store.get(name)\n if (!action) throw new MushinError('not_found', `Unknown action: ${name}`)\n const parsed = action.input.safeParse(input ?? {})\n if (!parsed.success) {\n throw new MushinError('invalid_input', z.prettifyError(parsed.error), parsed.error.issues)\n }\n const start = Date.now()\n try {\n let result: unknown\n if (action.client) {\n if (!this.relay) throw new MushinError('unavailable', 'No dashboard is connected to run this action')\n result = await this.relay(name, parsed.data, caller)\n } else {\n result = await action.handler!(parsed.data, caller)\n }\n this.ctx.emit('actions/called', { name, caller, ok: true, durationMs: Date.now() - start })\n return result\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n this.ctx.emit('actions/called', { name, caller, ok: false, durationMs: Date.now() - start, error: message })\n throw error\n }\n }\n}\n\n/** OpenAI tool names allow only letters, digits, `_` and `-`, so dots become double underscores. */\nexport function toToolName(action: string) {\n return action.replaceAll('.', '__')\n}\n\nexport function fromToolName(tool: string) {\n return tool.replaceAll('__', '.')\n}\n"],"mappings":";;;;;AA6EA,SAAgB,aAAa,QAA+B;CAC1D,MAAM,EAAE,SAAS,GAAG,SAAS,EAAE,aAAa,QAAQ;EAAE,IAAI;EAAS,iBAAiB;CAAM,CAAC;CAC3F,OAAO;AACT;AAEA,MAAM,cAAc;;;;;AAMpB,IAAa,UAAb,cAA6B,QAAQ;CACnC,wBAAgB,IAAI,IAA0B;CAC9C;CAEA,YAAY,KAAc;EACxB,MAAM,KAAK,SAAS;CACtB;;CAGA,OAA+B,YAAoC;EACjE,IAAI,CAAC,YAAY,KAAK,WAAW,IAAI,GACnC,MAAM,IAAI,MAAM,wBAAwB,WAAW,KAAK,gDAAgD;EAE1G,IAAI,C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B,SAAuB,EAAE,MAAM,WAAW,GAAqB;EACtG,MAAM,SAAS,KAAK,MAAM,IAAI,IAAI;EAClC,IAAI,CAAC,QAAQ,MAAM,IAAI,YAAY,aAAa,mBAAmB,MAAM;EACzE,MAAM,SAAS,OAAO,MAAM,UAAU,SAAS,CAAC,CAAC;EACjD,IAAI,CAAC,OAAO,SACV,MAAM,IAAI,YAAY,iBAAiB,EAAE,cAAc,OAAO,KAAK,GAAG,OAAO,MAAM,MAAM;EAE3F,MAAM,QAAQ,KAAK,IAAI;EACvB,IAAI;GACF,IAAI;GACJ,IAAI,OAAO,QAAQ;IACjB,IAAI,CAAC,KAAK,OAAO,MAAM,IAAI,YAAY,eAAe,8CAA8C;IACpG,SAAS,MAAM,KAAK,MAAM,MAAM,OAAO,MAAM,MAAM;GACrD,OACE,SAAS,MAAM,OAAO,QAAS,OAAO,MAAM,MAAM;GAEpD,KAAK,IAAI,KAAK,kBAAkB;IAAE;IAAM;IAAQ,IAAI;IAAM,YAAY,KAAK,IAAI,IAAI;GAAM,CAAC;GAC1F,OAAO;EACT,SAAS,OAAO;GACd,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;GACrE,KAAK,IAAI,KAAK,kBAAkB;IAAE;IAAM;IAAQ,IAAI;IAAO,YAAY,KAAK,IAAI,IAAI;IAAO,OAAO;GAAQ,CAAC;GAC3G,MAAM;EACR;CACF;AACF;;AAGA,SAAgB,WAAW,QAAgB;CACzC,OAAO,OAAO,WAAW,KAAK,IAAI;AACpC;AAEA,SAAgB,aAAa,MAAc;CACzC,OAAO,KAAK,WAAW,MAAM,GAAG;AAClC"}
@@ -0,0 +1,110 @@
1
+ import { CatalogEntry, PluginManifest } from "./manifest.js";
2
+ /**
3
+ * How plugins depend on each other, from the `requires` and `optional` fields of their manifests.
4
+ * These are pure functions over the catalog and the configured entries, so the manager, the
5
+ * dashboard's API and tests share them.
6
+ */
7
+ /** Why a dependency does not count as met. */
8
+ export type DependencyProblem = 'not-installed' | 'version' | 'disabled' | 'not-app';
9
+ export interface DependencyState {
10
+ package: string;
11
+ range: string;
12
+ optional: boolean;
13
+ installed: boolean;
14
+ version?: string;
15
+ kind?: 'app' | 'bot';
16
+ /** For app plugins: an entry for it is enabled in mushin.config.json. */
17
+ enabled: boolean;
18
+ /** Id of its entry in mushin.config.json, when it has one. */
19
+ entry?: string;
20
+ problem?: DependencyProblem;
21
+ }
22
+ export interface DependentState {
23
+ package: string;
24
+ kind: 'app' | 'bot';
25
+ optional: boolean;
26
+ /** App plugins: an entry for it is enabled. Bot plugins: always false here; they are enabled per bot. */
27
+ enabled: boolean;
28
+ entry?: string;
29
+ }
30
+ export interface DependencyReport {
31
+ package: string;
32
+ /** The Mushin.js version range the plugin needs, if it states one. */
33
+ mushin?: {
34
+ range: string;
35
+ version: string;
36
+ ok: boolean;
37
+ };
38
+ requires: DependencyState[];
39
+ optional: DependencyState[];
40
+ /** Installed plugins that list this one. */
41
+ dependents: DependentState[];
42
+ }
43
+ export interface EntryLike {
44
+ id: string;
45
+ package: string;
46
+ enabled?: boolean;
47
+ }
48
+ export interface DependencyGraph {
49
+ catalog: CatalogEntry[];
50
+ entries: EntryLike[];
51
+ /** Manifests for packages that do not ship one, such as the HTTP server. */
52
+ known?: (name: string) => PluginManifest | undefined;
53
+ }
54
+ /** Dependencies, dependents and the Mushin.js version check of one package. */
55
+ export declare function dependencyReport(graph: DependencyGraph, name: string): DependencyReport;
56
+ /** Required dependencies that stop a package from running, as states. Bot plugins only need theirs installed and enabled. */
57
+ export declare function unmet(graph: DependencyGraph, name: string): DependencyState[];
58
+ export interface EnablePlan {
59
+ /** Installed app plugins to enable first, dependencies before the plugins that need them. */
60
+ enable: string[];
61
+ /** Required packages that are not installed, or whose version does not fit. */
62
+ blocked: DependencyState[];
63
+ /** The Mushin.js version does not fit a plugin in the chain. */
64
+ mushin: {
65
+ package: string;
66
+ range: string;
67
+ version: string;
68
+ }[];
69
+ }
70
+ /** What enabling a package takes: the disabled app plugins it needs, transitively. */
71
+ export declare function planEnable(graph: DependencyGraph, name: string): EnablePlan;
72
+ export interface DisablePlan {
73
+ /** Enabled app plugin entries that need this one and stop with it, those further away first. */
74
+ disable: {
75
+ id: string;
76
+ package: string;
77
+ }[];
78
+ /** Bot plugins that need it; they stop working on every bot. */
79
+ botPlugins: string[];
80
+ /** Plugins that keep running with fewer features. */
81
+ degraded: string[];
82
+ }
83
+ /** What disabling a package takes: the enabled app plugins that require it, transitively. */
84
+ export declare function planDisable(graph: DependencyGraph, name: string): DisablePlan;
85
+ /**
86
+ * Orders entries so each comes after the entries it requires. Entries in a cycle are left out and
87
+ * reported with the cycle, e.g. `a → b → a`.
88
+ */
89
+ export declare function loadOrder<E extends EntryLike>(graph: DependencyGraph, entries: E[]): {
90
+ order: E[];
91
+ cycles: {
92
+ entries: E[];
93
+ chain: string[];
94
+ }[];
95
+ };
96
+ /** Service names a plugin injects, from `inject` as an array or as `{ name: … }`. */
97
+ export declare function injectedServices(plugin: unknown): {
98
+ required: string[];
99
+ optional: string[];
100
+ };
101
+ /** The package that provides a service, per the catalog's `provides` fields. */
102
+ export declare function providerOf(graph: DependencyGraph, service: string): string | undefined;
103
+ /**
104
+ * Services a plugin injects that its manifest does not explain: the package providing the service
105
+ * is in neither `requires` nor `optional`. Helps plugin authors keep the two in step.
106
+ */
107
+ export declare function undeclaredServices(graph: DependencyGraph, name: string, plugin: unknown): {
108
+ service: string;
109
+ provider: string;
110
+ }[];
@@ -0,0 +1,220 @@
1
+ import { MUSHIN_VERSION, dependencyPlugins } from "./manifest.js";
2
+ import { satisfies } from "./semver.js";
3
+ // src/dependencies.ts
4
+ function manifestOf(graph, name) {
5
+ return graph.catalog.find((entry) => entry.package === name)?.manifest ?? graph.known?.(name);
6
+ }
7
+ function entryOf(graph, name) {
8
+ return graph.entries.find((entry) => entry.package === name && entry.enabled !== false) ?? graph.entries.find((entry) => entry.package === name);
9
+ }
10
+ function stateOf(graph, name, range, optional) {
11
+ const catalog = graph.catalog.find((entry) => entry.package === name);
12
+ const known = graph.known?.(name);
13
+ const installed = !!catalog || !!known;
14
+ const kind = catalog?.manifest.kind ?? known?.kind;
15
+ const entry = entryOf(graph, name);
16
+ const enabled = !!entry && entry.enabled !== false;
17
+ const version = catalog?.version;
18
+ let problem;
19
+ if (!installed) problem = "not-installed";
20
+ else if (catalog && !satisfies(catalog.version, range)) problem = "version";
21
+ else if (kind === "bot") problem = "not-app";
22
+ else if (!enabled) problem = "disabled";
23
+ return {
24
+ package: name,
25
+ range,
26
+ optional,
27
+ installed,
28
+ ...version ? { version } : {},
29
+ ...kind ? { kind } : {},
30
+ enabled,
31
+ ...entry ? { entry: entry.id } : {},
32
+ ...problem ? { problem } : {}
33
+ };
34
+ }
35
+ /** Dependencies, dependents and the Mushin.js version check of one package. */
36
+ function dependencyReport(graph, name) {
37
+ const manifest = manifestOf(graph, name);
38
+ const range = manifest?.requires?.mushin;
39
+ return {
40
+ package: name,
41
+ ...typeof range === "string" ? { mushin: {
42
+ range,
43
+ version: MUSHIN_VERSION,
44
+ ok: satisfies(MUSHIN_VERSION, range)
45
+ } } : {},
46
+ requires: dependencyPlugins(manifest, "requires").map(([dep, range]) => stateOf(graph, dep, range, false)),
47
+ optional: dependencyPlugins(manifest, "optional").map(([dep, range]) => stateOf(graph, dep, range, true)),
48
+ dependents: graph.catalog.flatMap((entry) => {
49
+ const required = dependencyPlugins(entry.manifest, "requires").some(([dep]) => dep === name);
50
+ const optional = !required && dependencyPlugins(entry.manifest, "optional").some(([dep]) => dep === name);
51
+ if (!required && !optional) return [];
52
+ const own = entry.manifest.kind === "app" ? entryOf(graph, entry.package) : void 0;
53
+ return [{
54
+ package: entry.package,
55
+ kind: entry.manifest.kind,
56
+ optional,
57
+ enabled: !!own && own.enabled !== false,
58
+ ...own ? { entry: own.id } : {}
59
+ }];
60
+ })
61
+ };
62
+ }
63
+ /** Required dependencies that stop a package from running, as states. Bot plugins only need theirs installed and enabled. */
64
+ function unmet(graph, name) {
65
+ return dependencyReport(graph, name).requires.filter((dep) => dep.problem && dep.problem !== "not-app");
66
+ }
67
+ /** What enabling a package takes: the disabled app plugins it needs, transitively. */
68
+ function planEnable(graph, name) {
69
+ const enable = [];
70
+ const blocked = [];
71
+ const mushin = [];
72
+ const seen = /* @__PURE__ */ new Set();
73
+ const visit = (pkg) => {
74
+ if (seen.has(pkg)) return;
75
+ seen.add(pkg);
76
+ const report = dependencyReport(graph, pkg);
77
+ if (report.mushin && !report.mushin.ok) mushin.push({
78
+ package: pkg,
79
+ range: report.mushin.range,
80
+ version: report.mushin.version
81
+ });
82
+ for (const dep of report.requires) {
83
+ if (dep.problem === "not-installed" || dep.problem === "version") {
84
+ blocked.push(dep);
85
+ continue;
86
+ }
87
+ if (dep.kind !== "app") continue;
88
+ visit(dep.package);
89
+ if (dep.problem === "disabled" && !enable.includes(dep.package)) enable.push(dep.package);
90
+ }
91
+ };
92
+ visit(name);
93
+ return {
94
+ enable: enable.filter((pkg) => pkg !== name),
95
+ blocked,
96
+ mushin
97
+ };
98
+ }
99
+ /** What disabling a package takes: the enabled app plugins that require it, transitively. */
100
+ function planDisable(graph, name) {
101
+ const disable = [];
102
+ const botPlugins = /* @__PURE__ */ new Set();
103
+ const degraded = /* @__PURE__ */ new Set();
104
+ const seen = /* @__PURE__ */ new Set([name]);
105
+ const visit = (pkg) => {
106
+ for (const dependent of dependencyReport(graph, pkg).dependents) {
107
+ if (dependent.optional) {
108
+ if (dependent.kind === "bot" || dependent.enabled) degraded.add(dependent.package);
109
+ continue;
110
+ }
111
+ if (dependent.kind === "bot") {
112
+ botPlugins.add(dependent.package);
113
+ continue;
114
+ }
115
+ if (!dependent.enabled || seen.has(dependent.package)) continue;
116
+ seen.add(dependent.package);
117
+ visit(dependent.package);
118
+ disable.push({
119
+ id: dependent.entry,
120
+ package: dependent.package
121
+ });
122
+ }
123
+ };
124
+ visit(name);
125
+ for (const item of disable) degraded.delete(item.package);
126
+ return {
127
+ disable,
128
+ botPlugins: [...botPlugins],
129
+ degraded: [...degraded]
130
+ };
131
+ }
132
+ /**
133
+ * Orders entries so each comes after the entries it requires. Entries in a cycle are left out and
134
+ * reported with the cycle, e.g. `a → b → a`.
135
+ */
136
+ function loadOrder(graph, entries) {
137
+ const byPackage = new Map(entries.map((entry) => [entry.package, entry]));
138
+ const needs = (entry) => dependencyPlugins(manifestOf(graph, entry.package), "requires").map(([dep]) => byPackage.get(dep)).filter((dep) => !!dep && dep !== entry);
139
+ const order = [];
140
+ const state = /* @__PURE__ */ new Map();
141
+ const cycles = [];
142
+ const stack = [];
143
+ const visit = (entry) => {
144
+ const current = state.get(entry);
145
+ if (current === "done") return true;
146
+ if (current === "cycle") return false;
147
+ if (current === "visiting") {
148
+ const loop = stack.slice(stack.indexOf(entry));
149
+ for (const item of loop) state.set(item, "cycle");
150
+ cycles.push({
151
+ entries: loop,
152
+ chain: [...loop, entry].map((item) => item.package)
153
+ });
154
+ return false;
155
+ }
156
+ state.set(entry, "visiting");
157
+ stack.push(entry);
158
+ for (const dep of needs(entry)) visit(dep);
159
+ stack.pop();
160
+ if (state.get(entry) === "cycle") return false;
161
+ state.set(entry, "done");
162
+ order.push(entry);
163
+ return true;
164
+ };
165
+ for (const entry of entries) visit(entry);
166
+ return {
167
+ order,
168
+ cycles
169
+ };
170
+ }
171
+ /** Service names a plugin injects, from `inject` as an array or as `{ name: … }`. */
172
+ function injectedServices(plugin) {
173
+ const inject = plugin?.inject;
174
+ if (!inject) return {
175
+ required: [],
176
+ optional: []
177
+ };
178
+ if (Array.isArray(inject)) return {
179
+ required: inject.map(String),
180
+ optional: []
181
+ };
182
+ if (typeof inject !== "object") return {
183
+ required: [],
184
+ optional: []
185
+ };
186
+ const required = [];
187
+ const optional = [];
188
+ for (const [name, value] of Object.entries(inject)) if (name === "required" && Array.isArray(value)) required.push(...value.map(String));
189
+ else if (name === "optional" && Array.isArray(value)) optional.push(...value.map(String));
190
+ else if (value && typeof value === "object" && value.required === false) optional.push(name);
191
+ else required.push(name);
192
+ return {
193
+ required,
194
+ optional
195
+ };
196
+ }
197
+ /** The package that provides a service, per the catalog's `provides` fields. */
198
+ function providerOf(graph, service) {
199
+ return graph.catalog.find((entry) => entry.manifest.provides?.includes(service))?.package ?? graph.entries.map((entry) => entry.package).find((pkg) => graph.known?.(pkg)?.provides?.includes(service));
200
+ }
201
+ /**
202
+ * Services a plugin injects that its manifest does not explain: the package providing the service
203
+ * is in neither `requires` nor `optional`. Helps plugin authors keep the two in step.
204
+ */
205
+ function undeclaredServices(graph, name, plugin) {
206
+ const manifest = manifestOf(graph, name);
207
+ const declared = new Set([...dependencyPlugins(manifest, "requires"), ...dependencyPlugins(manifest, "optional")].map(([dep]) => dep));
208
+ const { required, optional } = injectedServices(plugin);
209
+ return [.../* @__PURE__ */ new Set([...required, ...optional])].flatMap((service) => {
210
+ const provider = providerOf(graph, service);
211
+ if (!provider || provider === name || declared.has(provider)) return [];
212
+ return [{
213
+ service,
214
+ provider
215
+ }];
216
+ });
217
+ }
218
+ export { dependencyReport, injectedServices, loadOrder, planDisable, planEnable, providerOf, undeclaredServices, unmet };
219
+
220
+ //# sourceMappingURL=dependencies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependencies.js","names":[],"sources":["../src/dependencies.ts"],"sourcesContent":["import { type CatalogEntry, dependencyPlugins, MUSHIN_VERSION, type PluginManifest } from './manifest'\r\nimport { satisfies } from './semver'\r\n\r\n/**\r\n * How plugins depend on each other, from the `requires` and `optional` fields of their manifests.\r\n * These are pure functions over the catalog and the configured entries, so the manager, the\r\n * dashboard's API and tests share them.\r\n */\r\n\r\n/** Why a dependency does not count as met. */\r\nexport type DependencyProblem = 'not-installed' | 'version' | 'disabled' | 'not-app'\r\n\r\nexport interface DependencyState {\r\n package: string\r\n range: string\r\n optional: boolean\r\n installed: boolean\r\n version?: string\r\n kind?: 'app' | 'bot'\r\n /** For app plugins: an entry for it is enabled in mushin.config.json. */\r\n enabled: boolean\r\n /** Id of its entry in mushin.config.json, when it has one. */\r\n entry?: string\r\n problem?: DependencyProblem\r\n}\r\n\r\nexport interface DependentState {\r\n package: string\r\n kind: 'app' | 'bot'\r\n optional: boolean\r\n /** App plugins: an entry for it is enabled. Bot plugins: always false here; they are enabled per bot. */\r\n enabled: boolean\r\n entry?: string\r\n}\r\n\r\nexport interface DependencyReport {\r\n package: string\r\n /** The Mushin.js version range the plugin needs, if it states one. */\r\n mushin?: { range: string; version: string; ok: boolean }\r\n requires: DependencyState[]\r\n optional: DependencyState[]\r\n /** Installed plugins that list this one. */\r\n dependents: DependentState[]\r\n}\r\n\r\nexport interface EntryLike {\r\n id: string\r\n package: string\r\n enabled?: boolean\r\n}\r\n\r\nexport interface DependencyGraph {\r\n catalog: CatalogEntry[]\r\n entries: EntryLike[]\r\n /** Manifests for packages that do not ship one, such as the HTTP server. */\r\n known?: (name: string) => PluginManifest | undefined\r\n}\r\n\r\nfunction manifestOf(graph: DependencyGraph, name: string) {\r\n return graph.catalog.find((entry) => entry.package === name)?.manifest ?? graph.known?.(name)\r\n}\r\n\r\nfunction entryOf(graph: DependencyGraph, name: string) {\r\n return graph.entries.find((entry) => entry.package === name && entry.enabled !== false)\r\n ?? graph.entries.find((entry) => entry.package === name)\r\n}\r\n\r\nfunction stateOf(graph: DependencyGraph, name: string, range: string, optional: boolean): DependencyState {\r\n const catalog = graph.catalog.find((entry) => entry.package === name)\r\n const known = graph.known?.(name)\r\n const installed = !!catalog || !!known\r\n const kind = catalog?.manifest.kind ?? known?.kind\r\n const entry = entryOf(graph, name)\r\n const enabled = !!entry && entry.enabled !== false\r\n const version = catalog?.version\r\n let problem: DependencyProblem | undefined\r\n if (!installed) problem = 'not-installed'\r\n else if (catalog && !satisfies(catalog.version, range)) problem = 'version'\r\n else if (kind === 'bot') problem = 'not-app'\r\n else if (!enabled) problem = 'disabled'\r\n return { package: name, range, optional, installed, ...(version ? { version } : {}), ...(kind ? { kind } : {}), enabled, ...(entry ? { entry: entry.id } : {}), ...(problem ? { problem } : {}) }\r\n}\r\n\r\n/** Dependencies, dependents and the Mushin.js version check of one package. */\r\nexport function dependencyReport(graph: DependencyGraph, name: string): DependencyReport {\r\n const manifest = manifestOf(graph, name)\r\n const range = manifest?.requires?.mushin\r\n return {\r\n package: name,\r\n ...(typeof range === 'string' ? { mushin: { range, version: MUSHIN_VERSION, ok: satisfies(MUSHIN_VERSION, range) } } : {}),\r\n requires: dependencyPlugins(manifest, 'requires').map(([dep, range]) => stateOf(graph, dep, range, false)),\r\n optional: dependencyPlugins(manifest, 'optional').map(([dep, range]) => stateOf(graph, dep, range, true)),\r\n dependents: graph.catalog.flatMap((entry): DependentState[] => {\r\n const required = dependencyPlugins(entry.manifest, 'requires').some(([dep]) => dep === name)\r\n const optional = !required && dependencyPlugins(entry.manifest, 'optional').some(([dep]) => dep === name)\r\n if (!required && !optional) return []\r\n const own = entry.manifest.kind === 'app' ? entryOf(graph, entry.package) : undefined\r\n return [{ package: entry.package, kind: entry.manifest.kind, optional, enabled: !!own && own.enabled !== false, ...(own ? { entry: own.id } : {}) }]\r\n }),\r\n }\r\n}\r\n\r\n/** Required dependencies that stop a package from running, as states. Bot plugins only need theirs installed and enabled. */\r\nexport function unmet(graph: DependencyGraph, name: string) {\r\n return dependencyReport(graph, name).requires.filter((dep) => dep.problem && dep.problem !== 'not-app')\r\n}\r\n\r\nexport interface EnablePlan {\r\n /** Installed app plugins to enable first, dependencies before the plugins that need them. */\r\n enable: string[]\r\n /** Required packages that are not installed, or whose version does not fit. */\r\n blocked: DependencyState[]\r\n /** The Mushin.js version does not fit a plugin in the chain. */\r\n mushin: { package: string; range: string; version: string }[]\r\n}\r\n\r\n/** What enabling a package takes: the disabled app plugins it needs, transitively. */\r\nexport function planEnable(graph: DependencyGraph, name: string): EnablePlan {\r\n const enable: string[] = []\r\n const blocked: DependencyState[] = []\r\n const mushin: EnablePlan['mushin'] = []\r\n const seen = new Set<string>()\r\n const visit = (pkg: string) => {\r\n if (seen.has(pkg)) return\r\n seen.add(pkg)\r\n const report = dependencyReport(graph, pkg)\r\n if (report.mushin && !report.mushin.ok) mushin.push({ package: pkg, range: report.mushin.range, version: report.mushin.version })\r\n for (const dep of report.requires) {\r\n if (dep.problem === 'not-installed' || dep.problem === 'version') {\r\n blocked.push(dep)\r\n continue\r\n }\r\n if (dep.kind !== 'app') continue\r\n visit(dep.package)\r\n if (dep.problem === 'disabled' && !enable.includes(dep.package)) enable.push(dep.package)\r\n }\r\n }\r\n visit(name)\r\n return { enable: enable.filter((pkg) => pkg !== name), blocked, mushin }\r\n}\r\n\r\nexport interface DisablePlan {\r\n /** Enabled app plugin entries that need this one and stop with it, those further away first. */\r\n disable: { id: string; package: string }[]\r\n /** Bot plugins that need it; they stop working on every bot. */\r\n botPlugins: string[]\r\n /** Plugins that keep running with fewer features. */\r\n degraded: string[]\r\n}\r\n\r\n/** What disabling a package takes: the enabled app plugins that require it, transitively. */\r\nexport function planDisable(graph: DependencyGraph, name: string): DisablePlan {\r\n const disable: DisablePlan['disable'] = []\r\n const botPlugins = new Set<string>()\r\n const degraded = new Set<string>()\r\n const seen = new Set<string>([name])\r\n const visit = (pkg: string) => {\r\n for (const dependent of dependencyReport(graph, pkg).dependents) {\r\n if (dependent.optional) {\r\n if (dependent.kind === 'bot' || dependent.enabled) degraded.add(dependent.package)\r\n continue\r\n }\r\n if (dependent.kind === 'bot') {\r\n botPlugins.add(dependent.package)\r\n continue\r\n }\r\n if (!dependent.enabled || seen.has(dependent.package)) continue\r\n seen.add(dependent.package)\r\n visit(dependent.package)\r\n disable.push({ id: dependent.entry!, package: dependent.package })\r\n }\r\n }\r\n visit(name)\r\n for (const item of disable) degraded.delete(item.package)\r\n return { disable, botPlugins: [...botPlugins], degraded: [...degraded] }\r\n}\r\n\r\n/**\r\n * Orders entries so each comes after the entries it requires. Entries in a cycle are left out and\r\n * reported with the cycle, e.g. `a → b → a`.\r\n */\r\nexport function loadOrder<E extends EntryLike>(graph: DependencyGraph, entries: E[]): { order: E[]; cycles: { entries: E[]; chain: string[] }[] } {\r\n const byPackage = new Map(entries.map((entry) => [entry.package, entry]))\r\n const needs = (entry: E) => dependencyPlugins(manifestOf(graph, entry.package), 'requires')\r\n .map(([dep]) => byPackage.get(dep))\r\n .filter((dep): dep is E => !!dep && dep !== entry)\r\n const order: E[] = []\r\n const state = new Map<E, 'visiting' | 'done' | 'cycle'>()\r\n const cycles: { entries: E[]; chain: string[] }[] = []\r\n const stack: E[] = []\r\n const visit = (entry: E): boolean => {\r\n const current = state.get(entry)\r\n if (current === 'done') return true\r\n if (current === 'cycle') return false\r\n if (current === 'visiting') {\r\n const loop = stack.slice(stack.indexOf(entry))\r\n for (const item of loop) state.set(item, 'cycle')\r\n cycles.push({ entries: loop, chain: [...loop, entry].map((item) => item.package) })\r\n return false\r\n }\r\n state.set(entry, 'visiting')\r\n stack.push(entry)\r\n // A plugin that needs one in a cycle still loads; it waits, and its status names what is missing.\r\n for (const dep of needs(entry)) visit(dep)\r\n stack.pop()\r\n if (state.get(entry) === 'cycle') return false\r\n state.set(entry, 'done')\r\n order.push(entry)\r\n return true\r\n }\r\n for (const entry of entries) visit(entry)\r\n return { order, cycles }\r\n}\r\n\r\n/** Service names a plugin injects, from `inject` as an array or as `{ name: … }`. */\r\nexport function injectedServices(plugin: unknown): { required: string[]; optional: string[] } {\r\n const inject = (plugin as { inject?: unknown } | undefined)?.inject\r\n if (!inject) return { required: [], optional: [] }\r\n if (Array.isArray(inject)) return { required: inject.map(String), optional: [] }\r\n if (typeof inject !== 'object') return { required: [], optional: [] }\r\n const required: string[] = []\r\n const optional: string[] = []\r\n for (const [name, value] of Object.entries(inject as Record<string, any>)) {\r\n if (name === 'required' && Array.isArray(value)) required.push(...value.map(String))\r\n else if (name === 'optional' && Array.isArray(value)) optional.push(...value.map(String))\r\n else if (value && typeof value === 'object' && value.required === false) optional.push(name)\r\n else required.push(name)\r\n }\r\n return { required, optional }\r\n}\r\n\r\n/** The package that provides a service, per the catalog's `provides` fields. */\r\nexport function providerOf(graph: DependencyGraph, service: string) {\r\n return graph.catalog.find((entry) => entry.manifest.provides?.includes(service))?.package\r\n ?? graph.entries.map((entry) => entry.package).find((pkg) => graph.known?.(pkg)?.provides?.includes(service))\r\n}\r\n\r\n/**\r\n * Services a plugin injects that its manifest does not explain: the package providing the service\r\n * is in neither `requires` nor `optional`. Helps plugin authors keep the two in step.\r\n */\r\nexport function undeclaredServices(graph: DependencyGraph, name: string, plugin: unknown) {\r\n const manifest = manifestOf(graph, name)\r\n const declared = new Set([...dependencyPlugins(manifest, 'requires'), ...dependencyPlugins(manifest, 'optional')].map(([dep]) => dep))\r\n const { required, optional } = injectedServices(plugin)\r\n return [...new Set([...required, ...optional])].flatMap((service) => {\r\n const provider = providerOf(graph, service)\r\n if (!provider || provider === name || declared.has(provider)) return []\r\n return [{ service, provider }]\r\n })\r\n}\r\n"],"mappings":";;;AA0DA,SAAS,WAAW,OAAwB,MAAc;CACxD,OAAO,MAAM,QAAQ,MAAM,UAAU,MAAM,YAAY,IAAI,CAAC,EAAE,YAAY,MAAM,QAAQ,IAAI;AAC9F;AAEA,SAAS,QAAQ,OAAwB,MAAc;CACrD,OAAO,MAAM,QAAQ,MAAM,UAAU,MAAM,YAAY,QAAQ,MAAM,YAAY,KAAK,KACjF,MAAM,QAAQ,MAAM,UAAU,MAAM,YAAY,IAAI;AAC3D;AAEA,SAAS,QAAQ,OAAwB,MAAc,OAAe,UAAoC;CACxG,MAAM,UAAU,MAAM,QAAQ,MAAM,UAAU,MAAM,YAAY,IAAI;CACpE,MAAM,QAAQ,MAAM,QAAQ,IAAI;CAChC,MAAM,YAAY,CAAC,CAAC,WAAW,CAAC,CAAC;CACjC,MAAM,OAAO,SAAS,SAAS,QAAQ,OAAO;CAC9C,MAAM,QAAQ,QAAQ,OAAO,IAAI;CACjC,MAAM,UAAU,CAAC,CAAC,SAAS,MAAM,YAAY;CAC7C,MAAM,UAAU,SAAS;CACzB,IAAI;CACJ,IAAI,CAAC,WAAW,UAAU;MACrB,IAAI,W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AAU;CAAS;AAC9B;;AAGA,SAAgB,WAAW,OAAwB,SAAiB;CAClE,OAAO,MAAM,QAAQ,MAAM,UAAU,MAAM,SAAS,UAAU,SAAS,OAAO,CAAC,CAAC,EAAE,WAC7E,MAAM,QAAQ,KAAK,UAAU,MAAM,OAAO,CAAC,CAAC,MAAM,QAAQ,MAAM,QAAQ,GAAG,CAAC,EAAE,UAAU,SAAS,OAAO,CAAC;AAChH;;;;;AAMA,SAAgB,mBAAmB,OAAwB,MAAc,QAAiB;CACxF,MAAM,WAAW,WAAW,OAAO,IAAI;CACvC,MAAM,WAAW,IAAI,IAAI,CAAC,GAAG,kBAAkB,UAAU,UAAU,GAAG,GAAG,kBAAkB,UAAU,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC;CACrI,MAAM,EAAE,UAAU,aAAa,iBAAiB,MAAM;CACtD,OAAO,CAAC,mBAAG,IAAI,IAAI,CAAC,GAAG,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,YAAY;EACnE,MAAM,WAAW,WAAW,OAAO,OAAO;EAC1C,IAAI,CAAC,YAAY,aAAa,QAAQ,SAAS,IAAI,QAAQ,GAAG,OAAO,CAAC;EACtE,OAAO,CAAC;GAAE;GAAS;EAAS,CAAC;CAC/B,CAAC;AACH"}
@@ -0,0 +1,22 @@
1
+ export type ErrorCode = 'not_found' | 'invalid_input' | 'conflict' | 'forbidden' | 'unauthorized' | 'unavailable' | 'failed';
2
+ /** An error whose message is safe to show to users and to the Agent. */
3
+ export declare class MushinError extends Error {
4
+ code: ErrorCode;
5
+ details?: unknown | undefined;
6
+ name: string;
7
+ constructor(code: ErrorCode, message: string, details?: unknown | undefined);
8
+ get status(): number;
9
+ toJSON(): {
10
+ code: ErrorCode;
11
+ message: string;
12
+ details: unknown;
13
+ };
14
+ }
15
+ export declare function toErrorPayload(error: unknown): {
16
+ code: ErrorCode;
17
+ message: string;
18
+ details: unknown;
19
+ } | {
20
+ code: "failed";
21
+ message: string;
22
+ };