@wheatley-ai/cli 0.0.0-stage → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/bin/wheatley.js +2 -0
- package/dist/approvals/gate.js +278 -0
- package/dist/approvals/module.js +21 -0
- package/dist/approvals/policy.js +30 -0
- package/dist/approvals/preview.js +17 -0
- package/dist/approvals/prompt.js +98 -0
- package/dist/approvals/rpc.js +16 -0
- package/dist/approvals/store.js +159 -0
- package/dist/cli/ask.js +94 -0
- package/dist/cli/chat.js +180 -0
- package/dist/cli/client.js +104 -0
- package/dist/cli/daemon.js +35 -0
- package/dist/cli/init.js +72 -0
- package/dist/cli/io.js +45 -0
- package/dist/cli/main.js +204 -0
- package/dist/cli/session.js +87 -0
- package/dist/cli/status.js +46 -0
- package/dist/contracts/approval-gate.js +1 -0
- package/dist/contracts/config-store.js +1 -0
- package/dist/contracts/delivery-outbox.js +1 -0
- package/dist/contracts/errors.js +28 -0
- package/dist/contracts/extension-catalog.js +1 -0
- package/dist/contracts/maintenance-runner.js +1 -0
- package/dist/contracts/memory-store.js +1 -0
- package/dist/contracts/module.js +7 -0
- package/dist/contracts/tool-names.js +43 -0
- package/dist/contracts/trigger-runtime.js +1 -0
- package/dist/contracts/webhook-ingress.js +2 -0
- package/dist/core/agent/agent-store.js +300 -0
- package/dist/core/agent/agent.js +1020 -0
- package/dist/core/agent/gated-models.js +89 -0
- package/dist/core/agent/pi-adapter.js +401 -0
- package/dist/core/agent/policy-gate.js +44 -0
- package/dist/core/builtin-catalog.js +20 -0
- package/dist/core/concurrency-gate.js +87 -0
- package/dist/core/config/atomic-file.js +61 -0
- package/dist/core/config/config-store.js +138 -0
- package/dist/core/config/pending-restart.js +53 -0
- package/dist/core/config/secret-references.js +69 -0
- package/dist/core/config/secret-store.js +147 -0
- package/dist/core/config/validate.js +55 -0
- package/dist/core/config/yaml-patch.js +57 -0
- package/dist/core/daemon.js +88 -0
- package/dist/core/deployment.js +347 -0
- package/dist/core/error-message.js +4 -0
- package/dist/core/events.js +25 -0
- package/dist/core/logger.js +81 -0
- package/dist/core/models.js +27 -0
- package/dist/core/module.js +42 -0
- package/dist/core/rpc/agent-handlers.js +82 -0
- package/dist/core/rpc/deployment-handlers.js +63 -0
- package/dist/core/rpc/router.js +95 -0
- package/dist/core/server/connection.js +170 -0
- package/dist/core/server/control-server.js +152 -0
- package/dist/core/server/static-files.js +79 -0
- package/dist/core/supervisor.js +206 -0
- package/dist/core/tool-routing.js +41 -0
- package/dist/dashboard/assets/index-3COz_MZq.css +2 -0
- package/dist/dashboard/assets/index-RnxedkKh.js +11 -0
- package/dist/dashboard/assets/sheet-presentation-U1UUymXc.js +1 -0
- package/dist/dashboard/index.html +13 -0
- package/dist/db/database.js +16 -0
- package/dist/db/migrations.js +184 -0
- package/dist/frontends/discord/approvals.js +199 -0
- package/dist/frontends/discord/attachments.js +115 -0
- package/dist/frontends/discord/binding.js +489 -0
- package/dist/frontends/discord/config.js +107 -0
- package/dist/frontends/discord/discord-runtime.js +52 -0
- package/dist/frontends/discord/errors.js +61 -0
- package/dist/frontends/discord/live-runs.js +189 -0
- package/dist/frontends/discord/module.js +39 -0
- package/dist/frontends/discord/recent-ids.js +20 -0
- package/dist/frontends/slack/approval-blocks.js +98 -0
- package/dist/frontends/slack/attachments.js +102 -0
- package/dist/frontends/slack/background-tasks.js +20 -0
- package/dist/frontends/slack/binding.js +405 -0
- package/dist/frontends/slack/bounded.js +9 -0
- package/dist/frontends/slack/chat-id.js +17 -0
- package/dist/frontends/slack/config.js +80 -0
- package/dist/frontends/slack/delivery-errors.js +81 -0
- package/dist/frontends/slack/inbound.js +76 -0
- package/dist/frontends/slack/live-progress.js +190 -0
- package/dist/frontends/slack/manifest.js +66 -0
- package/dist/frontends/slack/outbound.js +160 -0
- package/dist/frontends/slack/schemas.js +99 -0
- package/dist/frontends/slack/signature.js +30 -0
- package/dist/frontends/slack/slack-client.js +60 -0
- package/dist/frontends/slack/slack-frontend.js +38 -0
- package/dist/frontends/slack/state-store.js +112 -0
- package/dist/frontends/telegram/approvals.js +134 -0
- package/dist/frontends/telegram/attachments.js +126 -0
- package/dist/frontends/telegram/binding.js +144 -0
- package/dist/frontends/telegram/chat-key.js +43 -0
- package/dist/frontends/telegram/client.js +88 -0
- package/dist/frontends/telegram/config.js +93 -0
- package/dist/frontends/telegram/delivery.js +215 -0
- package/dist/frontends/telegram/frontend.js +42 -0
- package/dist/frontends/telegram/grammy-client.js +122 -0
- package/dist/frontends/telegram/http-status.js +6 -0
- package/dist/frontends/telegram/inbound.js +149 -0
- package/dist/frontends/telegram/live.js +182 -0
- package/dist/frontends/telegram/markdown.js +103 -0
- package/dist/frontends/telegram/recent-set.js +18 -0
- package/dist/frontends/telegram/serial-queue.js +23 -0
- package/dist/index.js +7 -0
- package/dist/mcp/content.js +61 -0
- package/dist/mcp/mcp-module.js +35 -0
- package/dist/mcp/mcp-tool-provider.js +93 -0
- package/dist/mcp/server-connection.js +297 -0
- package/dist/memory/consolidation.js +260 -0
- package/dist/memory/format.js +5 -0
- package/dist/memory/migrations.js +76 -0
- package/dist/memory/module.js +69 -0
- package/dist/memory/names.js +20 -0
- package/dist/memory/rows.js +22 -0
- package/dist/memory/rpc.js +49 -0
- package/dist/memory/snapshots.js +12 -0
- package/dist/memory/store.js +281 -0
- package/dist/memory/tools.js +158 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/config.d.ts +252 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/config.js +110 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/domain.d.ts +512 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/domain.js +441 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/duration.d.ts +8 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/duration.js +28 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/events.d.ts +234 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/events.js +124 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/index.d.ts +11 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/index.js +11 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/json-rpc.d.ts +81 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/json-rpc.js +157 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/json.d.ts +14 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/json.js +23 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/limits.d.ts +17 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/limits.js +17 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/methods.d.ts +1107 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/methods.js +201 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/rpc-error.d.ts +45 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/rpc-error.js +44 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/validation.d.ts +20 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/validation.js +11 -0
- package/dist/node_modules/@wheatley-ai/protocol/package.json +14 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/chunk.d.ts +11 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/chunk.js +162 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/commands.d.ts +48 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/commands.js +39 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/delivery-error.d.ts +29 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/delivery-error.js +27 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/frontend.d.ts +236 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/frontend.js +2 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/index.d.ts +10 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/index.js +7 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/json.d.ts +9 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/json.js +2 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/logger.d.ts +18 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/logger.js +2 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/plugin.d.ts +48 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/plugin.js +5 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/schema.d.ts +69 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/schema.js +3 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/tool.d.ts +69 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/tool.js +3 -0
- package/dist/node_modules/@wheatley-ai/sdk/package.json +11 -0
- package/dist/ops/backup.js +185 -0
- package/dist/ops/cli.js +195 -0
- package/dist/ops/command-runner.js +34 -0
- package/dist/ops/dashboard-assets.js +37 -0
- package/dist/ops/migrate.js +63 -0
- package/dist/ops/module.js +47 -0
- package/dist/ops/paths.js +55 -0
- package/dist/ops/service.js +376 -0
- package/dist/ops/update.js +145 -0
- package/dist/plugins/contributions.js +89 -0
- package/dist/plugins/guards.js +111 -0
- package/dist/plugins/load.js +76 -0
- package/dist/plugins/module.js +31 -0
- package/dist/plugins/provider.js +349 -0
- package/dist/plugins/schema.js +69 -0
- package/dist/skills/disclosure.js +142 -0
- package/dist/skills/discovery.js +120 -0
- package/dist/skills/fs-errors.js +8 -0
- package/dist/skills/read-skill-tool.js +3 -0
- package/dist/skills/skill-file.js +90 -0
- package/dist/skills/skills.js +140 -0
- package/dist/tools/builtin-tools.js +61 -0
- package/dist/tools/input.js +45 -0
- package/dist/tools/paths.js +6 -0
- package/dist/tools/read-file.js +65 -0
- package/dist/tools/shell.js +156 -0
- package/dist/tools/write-file.js +58 -0
- package/dist/triggers/delivery-codec.js +99 -0
- package/dist/triggers/delivery-outbox.js +313 -0
- package/dist/triggers/due-timer.js +14 -0
- package/dist/triggers/errors.js +2 -0
- package/dist/triggers/migrations.js +91 -0
- package/dist/triggers/module.js +104 -0
- package/dist/triggers/rpc.js +35 -0
- package/dist/triggers/schedule.js +52 -0
- package/dist/triggers/sql-row.js +59 -0
- package/dist/triggers/trigger-runtime.js +445 -0
- package/dist/triggers/trigger-tools.js +207 -0
- package/dist/triggers/webhook-ingress.js +216 -0
- package/dist/wiring/agent-services.js +144 -0
- package/dist/wiring/catalog.js +81 -0
- package/dist/wiring/daemon.js +83 -0
- package/dist/wiring/frontend-host.js +268 -0
- package/package.json +50 -3
- package/README.md +0 -3
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { access, constants, mkdir, realpath, stat, writeFile, } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { describeFailure } from "./command-runner.js";
|
|
5
|
+
import { envValue, HOME_ENV, isDocker, pathExists } from "./paths.js";
|
|
6
|
+
/** How long the daemon waits for active Runs after `SIGTERM` before it stops them, unless config sets `daemon.drainTimeout`. */
|
|
7
|
+
export const DEFAULT_DRAIN_TIMEOUT_MS = 30_000;
|
|
8
|
+
/**
|
|
9
|
+
* How long the service manager waits after `SIGTERM` before it sends `SIGKILL`. `stop_grace_period` in
|
|
10
|
+
* `docker/docker-compose.yml` must match it.
|
|
11
|
+
*/
|
|
12
|
+
export const STOP_GRACE_MS = 45_000;
|
|
13
|
+
/** The time that the daemon gets after the drain to close storage and child processes. */
|
|
14
|
+
const SHUTDOWN_MARGIN_MS = 15_000;
|
|
15
|
+
const MS_PER_SECOND = 1000;
|
|
16
|
+
/** How long systemd waits before it restarts a failed daemon. */
|
|
17
|
+
const RESTART_DELAY_SECONDS = 5;
|
|
18
|
+
/** Unit files and plists are world-readable, as the service managers expect. */
|
|
19
|
+
const UNIT_FILE_MODE = 0o644;
|
|
20
|
+
/** The CLI subcommand that runs the daemon in the foreground. The service units start it. */
|
|
21
|
+
export const DAEMON_SUBCOMMAND = "daemon";
|
|
22
|
+
export const SYSTEMD_UNIT_NAME = "wheatley.service";
|
|
23
|
+
export const LAUNCHD_LABEL = "wheatley.daemon";
|
|
24
|
+
/**
|
|
25
|
+
* Returns the stop grace period for a drain timeout: 45 seconds, or longer if the drain timeout leaves less than 15
|
|
26
|
+
* seconds for shutdown. The service manager thus never kills a daemon that still drains.
|
|
27
|
+
*/
|
|
28
|
+
export const stopGraceMs = (drainTimeoutMs = DEFAULT_DRAIN_TIMEOUT_MS) => Math.max(STOP_GRACE_MS, drainTimeoutMs + SHUTDOWN_MARGIN_MS);
|
|
29
|
+
const toSeconds = (ms) => Math.ceil(ms / MS_PER_SECOND);
|
|
30
|
+
const LINE_BREAK = /[\r\n]/u;
|
|
31
|
+
const SYSTEMD_BARE_WORD = /^[A-Za-z0-9_/.:@+=,-]+$/u;
|
|
32
|
+
const BACKSLASH = /\\/gu;
|
|
33
|
+
const DOUBLE_QUOTE = /"/gu;
|
|
34
|
+
const PERCENT = /%/gu;
|
|
35
|
+
const DOLLAR = /\$/gu;
|
|
36
|
+
const assertSingleLine = (value) => {
|
|
37
|
+
if (LINE_BREAK.test(value)) {
|
|
38
|
+
throw new Error(`Service values must not contain line breaks: ${value}`);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const quoteSystemd = (value) => `"${value.replaceAll(BACKSLASH, "\\\\").replaceAll(DOUBLE_QUOTE, String.raw `\"`)}"`;
|
|
42
|
+
/** Escapes one `ExecStart=` word: `%` specifiers, `$` variables, and quotes. */
|
|
43
|
+
const systemdArg = (value) => {
|
|
44
|
+
assertSingleLine(value);
|
|
45
|
+
const escaped = value.replaceAll(PERCENT, "%%").replaceAll(DOLLAR, "$$$$");
|
|
46
|
+
return SYSTEMD_BARE_WORD.test(escaped) ? escaped : quoteSystemd(escaped);
|
|
47
|
+
};
|
|
48
|
+
const systemdValue = (value) => {
|
|
49
|
+
assertSingleLine(value);
|
|
50
|
+
return quoteSystemd(value.replaceAll(PERCENT, "%%"));
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Renders the `systemd --user` unit. `KillMode=mixed` sends `SIGTERM` to the daemon only, so that it drains Runs and
|
|
54
|
+
* stops its own MCP Server processes. After the stop grace period, systemd kills every remaining process of the unit.
|
|
55
|
+
*/
|
|
56
|
+
export const renderSystemdUnit = (spec) => {
|
|
57
|
+
const environment = Object.entries(spec.environment)
|
|
58
|
+
.toSorted(([a], [b]) => a.localeCompare(b))
|
|
59
|
+
.map(([key, value]) => `Environment=${systemdValue(`${key}=${value}`)}`);
|
|
60
|
+
return [
|
|
61
|
+
"[Unit]",
|
|
62
|
+
"Description=Wheatley daemon",
|
|
63
|
+
"",
|
|
64
|
+
"[Service]",
|
|
65
|
+
"Type=exec",
|
|
66
|
+
`ExecStart=${spec.command.map(systemdArg).join(" ")}`,
|
|
67
|
+
`WorkingDirectory=${systemdValue(spec.workingDirectory)}`,
|
|
68
|
+
...environment,
|
|
69
|
+
"Restart=on-failure",
|
|
70
|
+
`RestartSec=${RESTART_DELAY_SECONDS}`,
|
|
71
|
+
"KillMode=mixed",
|
|
72
|
+
"KillSignal=SIGTERM",
|
|
73
|
+
`TimeoutStopSec=${toSeconds(stopGraceMs(spec.drainTimeoutMs))}`,
|
|
74
|
+
"",
|
|
75
|
+
"[Install]",
|
|
76
|
+
"WantedBy=default.target",
|
|
77
|
+
"",
|
|
78
|
+
].join("\n");
|
|
79
|
+
};
|
|
80
|
+
const XML_ESCAPES = new Map([
|
|
81
|
+
['"', """],
|
|
82
|
+
["&", "&"],
|
|
83
|
+
["'", "'"],
|
|
84
|
+
["<", "<"],
|
|
85
|
+
[">", ">"],
|
|
86
|
+
]);
|
|
87
|
+
const XML_SPECIAL = /["&'<>]/gu;
|
|
88
|
+
const xml = (value) => value.replaceAll(XML_SPECIAL, (char) => XML_ESCAPES.get(char) ?? char);
|
|
89
|
+
const plistString = (value) => `<string>${xml(value)}</string>`;
|
|
90
|
+
/**
|
|
91
|
+
* Renders the launchd agent plist. launchd restarts the daemon after a crash but not after a clean exit, and
|
|
92
|
+
* `ExitTimeOut` is the stop grace period before `SIGKILL`.
|
|
93
|
+
*/
|
|
94
|
+
export const renderLaunchdPlist = (spec) => {
|
|
95
|
+
const args = spec.command.map((arg) => ` ${plistString(arg)}`);
|
|
96
|
+
const environment = Object.entries(spec.environment)
|
|
97
|
+
.toSorted(([a], [b]) => a.localeCompare(b))
|
|
98
|
+
.flatMap(([key, value]) => [
|
|
99
|
+
` <key>${xml(key)}</key>`,
|
|
100
|
+
` ${plistString(value)}`,
|
|
101
|
+
]);
|
|
102
|
+
return [
|
|
103
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
104
|
+
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
|
|
105
|
+
'<plist version="1.0">',
|
|
106
|
+
"<dict>",
|
|
107
|
+
" <key>Label</key>",
|
|
108
|
+
` ${plistString(LAUNCHD_LABEL)}`,
|
|
109
|
+
" <key>ProgramArguments</key>",
|
|
110
|
+
" <array>",
|
|
111
|
+
...args,
|
|
112
|
+
" </array>",
|
|
113
|
+
" <key>EnvironmentVariables</key>",
|
|
114
|
+
" <dict>",
|
|
115
|
+
...environment,
|
|
116
|
+
" </dict>",
|
|
117
|
+
" <key>WorkingDirectory</key>",
|
|
118
|
+
` ${plistString(spec.workingDirectory)}`,
|
|
119
|
+
" <key>RunAtLoad</key>",
|
|
120
|
+
" <true/>",
|
|
121
|
+
" <key>KeepAlive</key>",
|
|
122
|
+
" <dict>",
|
|
123
|
+
" <key>SuccessfulExit</key>",
|
|
124
|
+
" <false/>",
|
|
125
|
+
" </dict>",
|
|
126
|
+
" <key>ProcessType</key>",
|
|
127
|
+
" <string>Background</string>",
|
|
128
|
+
" <key>ExitTimeOut</key>",
|
|
129
|
+
` <integer>${toSeconds(stopGraceMs(spec.drainTimeoutMs))}</integer>`,
|
|
130
|
+
" <key>StandardOutPath</key>",
|
|
131
|
+
` ${plistString(path.join(spec.logDir, "daemon.out.log"))}`,
|
|
132
|
+
" <key>StandardErrorPath</key>",
|
|
133
|
+
` ${plistString(path.join(spec.logDir, "daemon.err.log"))}`,
|
|
134
|
+
"</dict>",
|
|
135
|
+
"</plist>",
|
|
136
|
+
"",
|
|
137
|
+
].join("\n");
|
|
138
|
+
};
|
|
139
|
+
const isExecutable = async (file) => {
|
|
140
|
+
try {
|
|
141
|
+
await access(file, constants.X_OK);
|
|
142
|
+
const info = await stat(file);
|
|
143
|
+
return info.isFile();
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
const findOnPath = async (name, searchPath) => {
|
|
150
|
+
const candidates = searchPath.map((dir) => path.join(dir, name));
|
|
151
|
+
const executable = await Promise.all(candidates.map(isExecutable));
|
|
152
|
+
return candidates.find((_candidate, index) => executable[index] === true);
|
|
153
|
+
};
|
|
154
|
+
/** The `bin` script of this package, for a checkout that has no `wheatley` executable on `PATH`. */
|
|
155
|
+
export const packageBinScript = () => fileURLToPath(new URL("../../bin/wheatley.js", import.meta.url));
|
|
156
|
+
/**
|
|
157
|
+
* Builds the service spec for this host.
|
|
158
|
+
*
|
|
159
|
+
* The unit starts the `wheatley` executable from `PATH`, because npm and pnpm keep that path stable across updates.
|
|
160
|
+
* Without one, it runs `binScript` with Node.js. `PATH` in the unit starts with the real folder of the Node.js binary,
|
|
161
|
+
* so that the `#!/usr/bin/env node` line and MCP Server commands such as `npx` resolve to the same Node.js version.
|
|
162
|
+
*/
|
|
163
|
+
export const resolveServiceSpec = async (input) => {
|
|
164
|
+
const nodeDir = path.dirname(await realpath(input.execPath));
|
|
165
|
+
const searchPath = [
|
|
166
|
+
...new Set([
|
|
167
|
+
nodeDir,
|
|
168
|
+
...(input.env.PATH ?? "").split(path.delimiter).filter(Boolean),
|
|
169
|
+
]),
|
|
170
|
+
];
|
|
171
|
+
const executable = await findOnPath("wheatley", searchPath);
|
|
172
|
+
const command = executable === undefined
|
|
173
|
+
? [path.join(nodeDir, path.basename(input.execPath)), input.binScript]
|
|
174
|
+
: [executable];
|
|
175
|
+
const hasHomeOverride = envValue(input.env, HOME_ENV) !== undefined;
|
|
176
|
+
const pathValue = searchPath.join(path.delimiter);
|
|
177
|
+
const environment = new Map([["PATH", pathValue]]);
|
|
178
|
+
if (hasHomeOverride) {
|
|
179
|
+
environment.set(HOME_ENV, input.homeDir);
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
command: [...command, DAEMON_SUBCOMMAND],
|
|
183
|
+
environment: Object.fromEntries(environment),
|
|
184
|
+
logDir: path.join(input.homeDir, "logs"),
|
|
185
|
+
workingDirectory: input.homeDir,
|
|
186
|
+
drainTimeoutMs: input.drainTimeoutMs,
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
const run = async (runner, command, args) => {
|
|
190
|
+
const result = await runner.run(command, args);
|
|
191
|
+
if (result.exitCode !== 0) {
|
|
192
|
+
throw new Error(describeFailure(command, args, result));
|
|
193
|
+
}
|
|
194
|
+
return result;
|
|
195
|
+
};
|
|
196
|
+
const notInstalled = (unitPath) => new Error(`The Wheatley service is not installed (${unitPath}). Run: wheatley service install`);
|
|
197
|
+
const SYSTEMD_STATES = new Map([
|
|
198
|
+
["activating", "starting"],
|
|
199
|
+
["active", "running"],
|
|
200
|
+
["deactivating", "stopping"],
|
|
201
|
+
["failed", "failed"],
|
|
202
|
+
["inactive", "stopped"],
|
|
203
|
+
["reloading", "running"],
|
|
204
|
+
]);
|
|
205
|
+
const parseProperties = (text) => {
|
|
206
|
+
const properties = new Map();
|
|
207
|
+
for (const line of text.split("\n")) {
|
|
208
|
+
const separator = line.indexOf("=");
|
|
209
|
+
if (separator > 0) {
|
|
210
|
+
properties.set(line.slice(0, separator).trim(), line.slice(separator + 1).trim());
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return properties;
|
|
214
|
+
};
|
|
215
|
+
const parsePid = (value) => {
|
|
216
|
+
const pid = Number(value);
|
|
217
|
+
return Number.isInteger(pid) && pid > 0 ? pid : null;
|
|
218
|
+
};
|
|
219
|
+
const createSystemdManager = (options) => {
|
|
220
|
+
const configHome = envValue(options.env, "XDG_CONFIG_HOME") ??
|
|
221
|
+
path.join(options.userHome, ".config");
|
|
222
|
+
const unitPath = path.join(configHome, "systemd", "user", SYSTEMD_UNIT_NAME);
|
|
223
|
+
const systemctl = async (...args) => await run(options.runner, "systemctl", ["--user", ...args]);
|
|
224
|
+
const requireInstalled = async () => {
|
|
225
|
+
if (!(await pathExists(unitPath))) {
|
|
226
|
+
throw notInstalled(unitPath);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
return {
|
|
230
|
+
install: async (spec) => {
|
|
231
|
+
await mkdir(path.dirname(unitPath), { recursive: true });
|
|
232
|
+
await writeFile(unitPath, renderSystemdUnit(spec), {
|
|
233
|
+
mode: UNIT_FILE_MODE,
|
|
234
|
+
});
|
|
235
|
+
await systemctl("daemon-reload");
|
|
236
|
+
await systemctl("enable", SYSTEMD_UNIT_NAME);
|
|
237
|
+
return {
|
|
238
|
+
notes: [
|
|
239
|
+
"Run `wheatley service start` to start the daemon now.",
|
|
240
|
+
"Run `loginctl enable-linger` to keep the daemon running after you log out.",
|
|
241
|
+
],
|
|
242
|
+
unitPath,
|
|
243
|
+
};
|
|
244
|
+
},
|
|
245
|
+
kind: "systemd",
|
|
246
|
+
restart: async () => {
|
|
247
|
+
await requireInstalled();
|
|
248
|
+
await systemctl("restart", SYSTEMD_UNIT_NAME);
|
|
249
|
+
},
|
|
250
|
+
start: async () => {
|
|
251
|
+
await requireInstalled();
|
|
252
|
+
await systemctl("start", SYSTEMD_UNIT_NAME);
|
|
253
|
+
},
|
|
254
|
+
status: async () => {
|
|
255
|
+
if (!(await pathExists(unitPath))) {
|
|
256
|
+
return {
|
|
257
|
+
manager: "systemd",
|
|
258
|
+
pid: null,
|
|
259
|
+
state: "not_installed",
|
|
260
|
+
unitPath,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
const result = await systemctl("show", SYSTEMD_UNIT_NAME, "--property=ActiveState,MainPID");
|
|
264
|
+
const properties = parseProperties(result.stdout);
|
|
265
|
+
return {
|
|
266
|
+
manager: "systemd",
|
|
267
|
+
pid: parsePid(properties.get("MainPID")),
|
|
268
|
+
state: SYSTEMD_STATES.get(properties.get("ActiveState") ?? "") ?? "stopped",
|
|
269
|
+
unitPath,
|
|
270
|
+
};
|
|
271
|
+
},
|
|
272
|
+
stop: async () => {
|
|
273
|
+
await requireInstalled();
|
|
274
|
+
await systemctl("stop", SYSTEMD_UNIT_NAME);
|
|
275
|
+
},
|
|
276
|
+
unitPath,
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
const LAUNCHD_STATE = /^\s*state = (?<state>.+)$/mu;
|
|
280
|
+
const LAUNCHD_PID = /^\s*pid = (?<pid>\d+)$/mu;
|
|
281
|
+
const LAUNCHD_EXIT = /^\s*last exit code = (?<code>-?\d+)/mu;
|
|
282
|
+
const launchdState = (output) => {
|
|
283
|
+
if (LAUNCHD_STATE.exec(output)?.groups?.state === "running") {
|
|
284
|
+
return "running";
|
|
285
|
+
}
|
|
286
|
+
const exitCode = LAUNCHD_EXIT.exec(output)?.groups?.code;
|
|
287
|
+
return exitCode === undefined || exitCode === "0" ? "stopped" : "failed";
|
|
288
|
+
};
|
|
289
|
+
const createLaunchdManager = (options) => {
|
|
290
|
+
const unitPath = path.join(options.userHome, "Library", "LaunchAgents", `${LAUNCHD_LABEL}.plist`);
|
|
291
|
+
const domain = `gui/${options.uid}`;
|
|
292
|
+
const target = `${domain}/${LAUNCHD_LABEL}`;
|
|
293
|
+
const print = async () => await options.runner.run("launchctl", ["print", target]);
|
|
294
|
+
const isLoaded = async () => {
|
|
295
|
+
const result = await print();
|
|
296
|
+
return result.exitCode === 0;
|
|
297
|
+
};
|
|
298
|
+
const requireInstalled = async () => {
|
|
299
|
+
if (!(await pathExists(unitPath))) {
|
|
300
|
+
throw notInstalled(unitPath);
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
const start = async () => {
|
|
304
|
+
await requireInstalled();
|
|
305
|
+
await ((await isLoaded())
|
|
306
|
+
? run(options.runner, "launchctl", ["kickstart", target])
|
|
307
|
+
: run(options.runner, "launchctl", ["bootstrap", domain, unitPath]));
|
|
308
|
+
};
|
|
309
|
+
const stop = async () => {
|
|
310
|
+
await requireInstalled();
|
|
311
|
+
if (await isLoaded()) {
|
|
312
|
+
await run(options.runner, "launchctl", ["bootout", target]);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
return {
|
|
316
|
+
install: async (spec) => {
|
|
317
|
+
await mkdir(path.dirname(unitPath), { recursive: true });
|
|
318
|
+
await mkdir(spec.logDir, { recursive: true });
|
|
319
|
+
await writeFile(unitPath, renderLaunchdPlist(spec), {
|
|
320
|
+
mode: UNIT_FILE_MODE,
|
|
321
|
+
});
|
|
322
|
+
await run(options.runner, "plutil", ["-lint", unitPath]);
|
|
323
|
+
return {
|
|
324
|
+
notes: [
|
|
325
|
+
"Run `wheatley service start` to start the daemon now. launchd starts it at each login.",
|
|
326
|
+
],
|
|
327
|
+
unitPath,
|
|
328
|
+
};
|
|
329
|
+
},
|
|
330
|
+
kind: "launchd",
|
|
331
|
+
restart: async () => {
|
|
332
|
+
await stop();
|
|
333
|
+
await start();
|
|
334
|
+
},
|
|
335
|
+
start,
|
|
336
|
+
status: async () => {
|
|
337
|
+
if (!(await pathExists(unitPath))) {
|
|
338
|
+
return {
|
|
339
|
+
manager: "launchd",
|
|
340
|
+
pid: null,
|
|
341
|
+
state: "not_installed",
|
|
342
|
+
unitPath,
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
const result = await print();
|
|
346
|
+
if (result.exitCode !== 0) {
|
|
347
|
+
return { manager: "launchd", pid: null, state: "stopped", unitPath };
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
manager: "launchd",
|
|
351
|
+
pid: parsePid(LAUNCHD_PID.exec(result.stdout)?.groups?.pid),
|
|
352
|
+
state: launchdState(result.stdout),
|
|
353
|
+
unitPath,
|
|
354
|
+
};
|
|
355
|
+
},
|
|
356
|
+
stop,
|
|
357
|
+
unitPath,
|
|
358
|
+
};
|
|
359
|
+
};
|
|
360
|
+
/**
|
|
361
|
+
* Returns the service manager of this host: `systemd --user` on Linux and launchd on macOS.
|
|
362
|
+
*
|
|
363
|
+
* Errors: throws on another platform, and inside the Docker image, where Docker Compose runs the daemon.
|
|
364
|
+
*/
|
|
365
|
+
export const createServiceManager = (options) => {
|
|
366
|
+
if (isDocker(options.env)) {
|
|
367
|
+
throw new Error("wheatley service does not apply in Docker. Docker Compose runs the daemon.");
|
|
368
|
+
}
|
|
369
|
+
if (options.platform === "linux") {
|
|
370
|
+
return createSystemdManager(options);
|
|
371
|
+
}
|
|
372
|
+
if (options.platform === "darwin") {
|
|
373
|
+
return createLaunchdManager(options);
|
|
374
|
+
}
|
|
375
|
+
throw new Error(`wheatley service supports Linux (systemd) and macOS (launchd), not ${options.platform}`);
|
|
376
|
+
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { Type } from "typebox";
|
|
4
|
+
import { Value } from "typebox/value";
|
|
5
|
+
import { describeFailure } from "./command-runner.js";
|
|
6
|
+
import { isDocker } from "./paths.js";
|
|
7
|
+
/** The npm package name of the daemon and CLI. */
|
|
8
|
+
export const PACKAGE_NAME = "@wheatley-ai/cli";
|
|
9
|
+
/** The commands that update a Docker Compose Deployment. Run them in the folder of `docker-compose.yml`. */
|
|
10
|
+
export const DOCKER_UPDATE_COMMANDS = [
|
|
11
|
+
"docker compose pull",
|
|
12
|
+
"docker compose up -d",
|
|
13
|
+
];
|
|
14
|
+
const VERSION = /^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?<prerelease>-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u;
|
|
15
|
+
const parseVersion = (text) => {
|
|
16
|
+
const groups = VERSION.exec(text)?.groups;
|
|
17
|
+
if (groups === undefined) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
major: Number(groups.major),
|
|
22
|
+
minor: Number(groups.minor),
|
|
23
|
+
patch: Number(groups.patch),
|
|
24
|
+
prerelease: groups.prerelease !== undefined,
|
|
25
|
+
text,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
/** Orders by major, minor, and patch. A release sorts after a prerelease of the same numbers. */
|
|
29
|
+
const compareVersions = (a, b) => a.major - b.major ||
|
|
30
|
+
a.minor - b.minor ||
|
|
31
|
+
a.patch - b.patch ||
|
|
32
|
+
Number(b.prerelease) - Number(a.prerelease);
|
|
33
|
+
const newest = (versions) => versions.toSorted(compareVersions).at(-1);
|
|
34
|
+
/**
|
|
35
|
+
* Applies the major-version guard: picks the newest stable release with the same major version as `current` that is
|
|
36
|
+
* newer than `current`. It ignores prereleases and text that is not a version.
|
|
37
|
+
*
|
|
38
|
+
* Errors: throws if `current` is not a semantic version.
|
|
39
|
+
*/
|
|
40
|
+
export const selectUpdate = (current, available) => {
|
|
41
|
+
const installed = parseVersion(current);
|
|
42
|
+
if (installed === undefined) {
|
|
43
|
+
throw new Error(`The installed version is not a semantic version: ${current}`);
|
|
44
|
+
}
|
|
45
|
+
const releases = available
|
|
46
|
+
.flatMap((text) => parseVersion(text) ?? [])
|
|
47
|
+
.filter((version) => !version.prerelease && compareVersions(version, installed) > 0);
|
|
48
|
+
return {
|
|
49
|
+
newerMajor: newest(releases.filter((version) => version.major > installed.major))?.text,
|
|
50
|
+
target: newest(releases.filter((version) => version.major === installed.major))?.text,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
const segment = (...names) => `${path.sep}${names.join(path.sep)}${path.sep}`;
|
|
54
|
+
/**
|
|
55
|
+
* Detects the install method from the environment and the real path of the installed package folder.
|
|
56
|
+
*
|
|
57
|
+
* pnpm keeps global packages in a `pnpm/global/` folder and its store in `.pnpm/`. Any other `node_modules/` folder is
|
|
58
|
+
* an npm install. A folder outside `node_modules/` is a source checkout.
|
|
59
|
+
*/
|
|
60
|
+
export const detectInstallMethod = (env, packageDir) => {
|
|
61
|
+
if (isDocker(env)) {
|
|
62
|
+
return "docker";
|
|
63
|
+
}
|
|
64
|
+
const dir = `${packageDir}${path.sep}`;
|
|
65
|
+
if (dir.includes(segment("pnpm", "global")) ||
|
|
66
|
+
dir.includes(segment(".pnpm"))) {
|
|
67
|
+
return "pnpm";
|
|
68
|
+
}
|
|
69
|
+
return dir.includes(segment("node_modules")) ? "npm" : "source";
|
|
70
|
+
};
|
|
71
|
+
/** The global install command that updates Wheatley to `version`. */
|
|
72
|
+
export const installCommand = (manager, version) => manager === "pnpm"
|
|
73
|
+
? ["pnpm", "add", "--global", `${PACKAGE_NAME}@${version}`]
|
|
74
|
+
: ["npm", "install", "--global", `${PACKAGE_NAME}@${version}`];
|
|
75
|
+
/** `npm view <package> versions --json` prints a string for one version and an array for more. */
|
|
76
|
+
const VersionListSchema = Type.Union([
|
|
77
|
+
Type.String(),
|
|
78
|
+
Type.Array(Type.String()),
|
|
79
|
+
]);
|
|
80
|
+
const PackageJsonSchema = Type.Object({ version: Type.String() });
|
|
81
|
+
/** Lists the published versions of the package with `npm view`, which works for npm and pnpm installs. */
|
|
82
|
+
const publishedVersions = async (runner) => {
|
|
83
|
+
const args = ["view", PACKAGE_NAME, "versions", "--json"];
|
|
84
|
+
const result = await runner.run("npm", args);
|
|
85
|
+
if (result.exitCode !== 0) {
|
|
86
|
+
throw new Error(describeFailure("npm", args, result));
|
|
87
|
+
}
|
|
88
|
+
const parsed = JSON.parse(result.stdout);
|
|
89
|
+
if (!Value.Check(VersionListSchema, parsed)) {
|
|
90
|
+
throw new Error("npm view returned an unexpected version list");
|
|
91
|
+
}
|
|
92
|
+
return [parsed].flat();
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Decides what `wheatley update` does. It never installs anything.
|
|
96
|
+
*
|
|
97
|
+
* - Docker: returns the Docker Compose commands, without a registry query.
|
|
98
|
+
* - npm or pnpm: queries the registry and applies the major-version guard (`selectUpdate`).
|
|
99
|
+
*
|
|
100
|
+
* Errors: throws for a source checkout without a `manager` override, if `npm view` fails, or for an invalid current
|
|
101
|
+
* version.
|
|
102
|
+
*/
|
|
103
|
+
export const planUpdate = async (input) => {
|
|
104
|
+
if (input.method === "docker") {
|
|
105
|
+
return { commands: DOCKER_UPDATE_COMMANDS, kind: "docker" };
|
|
106
|
+
}
|
|
107
|
+
const manager = input.manager ?? (input.method === "source" ? undefined : input.method);
|
|
108
|
+
if (manager === undefined) {
|
|
109
|
+
throw new Error("This Wheatley runs from a source checkout. Update it with git, or pass --manager npm or --manager pnpm.");
|
|
110
|
+
}
|
|
111
|
+
const { newerMajor, target } = selectUpdate(input.current, await publishedVersions(input.runner));
|
|
112
|
+
if (target === undefined) {
|
|
113
|
+
return { current: input.current, kind: "up_to_date", newerMajor };
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
command: installCommand(manager, target),
|
|
117
|
+
current: input.current,
|
|
118
|
+
kind: "update",
|
|
119
|
+
newerMajor,
|
|
120
|
+
target,
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Runs the install command of an `update` plan with the standard streams attached.
|
|
125
|
+
*
|
|
126
|
+
* Errors: rejects if the package manager cannot start or exits with a non-zero code.
|
|
127
|
+
*/
|
|
128
|
+
export const applyUpdate = async (plan, runner) => {
|
|
129
|
+
const [command, ...args] = plan.command;
|
|
130
|
+
const result = await runner.run(command, args, { inheritStdio: true });
|
|
131
|
+
if (result.exitCode !== 0) {
|
|
132
|
+
throw new Error(describeFailure(command, args, result));
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
/** The folder of this package, which holds `package.json`, `bin/`, and `dist/`. */
|
|
136
|
+
export const packageDir = () => path.resolve(import.meta.dirname, "..", "..");
|
|
137
|
+
/** Reads the version of the installed package from its `package.json`. */
|
|
138
|
+
export const readPackageVersion = async (dir = packageDir()) => {
|
|
139
|
+
const file = path.join(dir, "package.json");
|
|
140
|
+
const parsed = JSON.parse(await readFile(file, "utf-8"));
|
|
141
|
+
if (!Value.Check(PackageJsonSchema, parsed)) {
|
|
142
|
+
throw new Error(`No version in ${file}`);
|
|
143
|
+
}
|
|
144
|
+
return parsed.version;
|
|
145
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { canonicalToolName } from "../contracts/tool-names.js";
|
|
2
|
+
import { errorMessage, hasDispose, isContributionsObject, isPluginFrontend, isPluginTool, } from "./guards.js";
|
|
3
|
+
import { compileSchema } from "./schema.js";
|
|
4
|
+
/** Plugin Tools have no built-in default, so a call without a matching Permission Policy rule asks. */
|
|
5
|
+
const PLUGIN_DEFAULT_ACTION = "ask";
|
|
6
|
+
const loadTool = (plugin, tool) => {
|
|
7
|
+
let schema;
|
|
8
|
+
try {
|
|
9
|
+
schema = compileSchema(tool.inputSchema);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
throw new TypeError(`Tool ${tool.name} has an invalid inputSchema: ${errorMessage(error)}`, { cause: error });
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
descriptor: {
|
|
16
|
+
defaultAction: PLUGIN_DEFAULT_ACTION,
|
|
17
|
+
description: tool.description,
|
|
18
|
+
inputSchema: schema.jsonSchema,
|
|
19
|
+
name: canonicalToolName({ kind: "plugin", plugin }, tool.name),
|
|
20
|
+
source: "plugin",
|
|
21
|
+
},
|
|
22
|
+
schema,
|
|
23
|
+
tool,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const loadFrontend = (frontend) => {
|
|
27
|
+
try {
|
|
28
|
+
compileSchema(frontend.configSchema);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
throw new TypeError(`Frontend ${frontend.type} has an invalid configSchema: ${errorMessage(error)}`, { cause: error });
|
|
32
|
+
}
|
|
33
|
+
return frontend;
|
|
34
|
+
};
|
|
35
|
+
const firstDuplicate = (values) => values.find((value, index) => values.indexOf(value) !== index);
|
|
36
|
+
/**
|
|
37
|
+
* Returns a function that calls the `dispose` function of what `setup` returned, so that a caller can release a
|
|
38
|
+
* Plugin whose contributions fail validation or arrive too late. `setup` is Plugin code, so `returned` is unchecked.
|
|
39
|
+
* The function does nothing if there is no `dispose` function.
|
|
40
|
+
*/
|
|
41
|
+
export const disposerOf = (returned) => {
|
|
42
|
+
if (!hasDispose(returned)) {
|
|
43
|
+
return async () => {
|
|
44
|
+
await Promise.resolve();
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return async () => {
|
|
48
|
+
await returned.dispose();
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Validates what `setup` of the Plugin `plugin` returned against `PluginContributions` of `@wheatley-ai/sdk` and names
|
|
53
|
+
* its Tools `<plugin>:<tool>`.
|
|
54
|
+
*
|
|
55
|
+
* Errors: throws a `TypeError` or `RangeError` with a message for Agent health if the value is not a contributions
|
|
56
|
+
* object, a Tool or Frontend breaks its contract, a Tool name breaks `^[a-z][a-z0-9_]*$`, two Tools share a name, two
|
|
57
|
+
* Frontends share a `type`, or `dispose` is not a function.
|
|
58
|
+
*/
|
|
59
|
+
export const loadContributions = (plugin, returned) => {
|
|
60
|
+
if (!isContributionsObject(returned)) {
|
|
61
|
+
throw new TypeError("setup did not return a contributions object with optional tools and frontends arrays");
|
|
62
|
+
}
|
|
63
|
+
if (returned.dispose !== undefined && !hasDispose(returned)) {
|
|
64
|
+
throw new TypeError("setup returned dispose that is not a function");
|
|
65
|
+
}
|
|
66
|
+
const toolValues = returned.tools ?? [];
|
|
67
|
+
const frontendValues = returned.frontends ?? [];
|
|
68
|
+
const tools = toolValues.map((tool, index) => {
|
|
69
|
+
if (!isPluginTool(tool)) {
|
|
70
|
+
throw new TypeError(`Tool ${index} breaks the Tool contract: it needs name and description strings, an inputSchema of plain JSON Schema or Standard JSON Schema, and an execute function`);
|
|
71
|
+
}
|
|
72
|
+
return loadTool(plugin, tool);
|
|
73
|
+
});
|
|
74
|
+
const frontends = frontendValues.map((frontend, index) => {
|
|
75
|
+
if (!isPluginFrontend(frontend)) {
|
|
76
|
+
throw new TypeError(`Frontend ${index} breaks the Frontend contract: it needs a type string, a configSchema of plain JSON Schema or Standard JSON Schema, and a createBinding function`);
|
|
77
|
+
}
|
|
78
|
+
return loadFrontend(frontend);
|
|
79
|
+
});
|
|
80
|
+
const duplicateTool = firstDuplicate(tools.map((tool) => tool.descriptor.name));
|
|
81
|
+
if (duplicateTool !== undefined) {
|
|
82
|
+
throw new TypeError(`setup returned two Tools named ${duplicateTool}`);
|
|
83
|
+
}
|
|
84
|
+
const duplicateFrontend = firstDuplicate(frontends.map((frontend) => frontend.type));
|
|
85
|
+
if (duplicateFrontend !== undefined) {
|
|
86
|
+
throw new TypeError(`setup returned two Frontends of type ${duplicateFrontend}`);
|
|
87
|
+
}
|
|
88
|
+
return { dispose: disposerOf(returned), frontends, tools };
|
|
89
|
+
};
|