@wheatley-ai/cli 0.3.0 → 0.4.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.
Files changed (63) hide show
  1. package/dist/cli/ask.js +8 -4
  2. package/dist/cli/chat.js +8 -4
  3. package/dist/cli/daemon.js +45 -0
  4. package/dist/cli/io.js +1 -0
  5. package/dist/cli/main.js +145 -163
  6. package/dist/cli/session.js +59 -3
  7. package/dist/cli/status.js +4 -4
  8. package/dist/cli/tui/app.js +14 -2
  9. package/dist/cli/tui/controller.js +80 -19
  10. package/dist/cli/tui/markdown.js +229 -104
  11. package/dist/cli/tui/model-picker.js +76 -0
  12. package/dist/cli/tui/picker-panel.js +39 -0
  13. package/dist/core/agent/agent.js +23 -12
  14. package/dist/core/config/config-store.js +11 -6
  15. package/dist/core/config/diagnostics.js +116 -0
  16. package/dist/core/config/secret-store.js +13 -9
  17. package/dist/core/deployment.js +19 -1
  18. package/dist/core/markdown-tokens.js +60 -0
  19. package/dist/core/model-catalog.js +54 -0
  20. package/dist/core/rpc/deployment-handlers.js +2 -1
  21. package/dist/core/server/control-server.js +19 -21
  22. package/dist/core/server/http-server.js +17 -0
  23. package/dist/core/server/static-files.js +40 -66
  24. package/dist/dashboard/assets/index-DGa2Ps9u.js +12 -0
  25. package/dist/dashboard/assets/index-DeERxJOJ.css +2 -0
  26. package/dist/dashboard/assets/{sheet-presentation-CkgiDsTg.js → sheet-presentation-CZ1dO2kr.js} +1 -1
  27. package/dist/dashboard/index.html +2 -2
  28. package/dist/frontends/discord/approvals.js +8 -43
  29. package/dist/frontends/discord/binding.js +81 -8
  30. package/dist/frontends/discord/json-file.js +57 -0
  31. package/dist/frontends/discord/model-picker.js +276 -0
  32. package/dist/frontends/slack/binding.js +33 -3
  33. package/dist/frontends/slack/inbound.js +21 -12
  34. package/dist/frontends/slack/model-picker-blocks.js +147 -0
  35. package/dist/frontends/slack/outbound.js +27 -2
  36. package/dist/frontends/slack/schemas.js +9 -2
  37. package/dist/frontends/telegram/approvals.js +13 -48
  38. package/dist/frontends/telegram/binding.js +5 -0
  39. package/dist/frontends/telegram/client.js +7 -0
  40. package/dist/frontends/telegram/delivery.js +19 -6
  41. package/dist/frontends/telegram/inbound.js +64 -8
  42. package/dist/frontends/telegram/markdown.js +120 -83
  43. package/dist/frontends/telegram/model-picker.js +160 -0
  44. package/dist/frontends/telegram/token-store.js +73 -0
  45. package/dist/node_modules/@wheatley-ai/protocol/dist/domain.d.ts +13 -0
  46. package/dist/node_modules/@wheatley-ai/protocol/dist/domain.js +11 -0
  47. package/dist/node_modules/@wheatley-ai/protocol/dist/index.d.ts +1 -1
  48. package/dist/node_modules/@wheatley-ai/protocol/dist/index.js +1 -1
  49. package/dist/node_modules/@wheatley-ai/protocol/dist/methods.d.ts +20 -0
  50. package/dist/node_modules/@wheatley-ai/protocol/dist/methods.js +9 -1
  51. package/dist/node_modules/@wheatley-ai/sdk/dist/commands.d.ts +2 -2
  52. package/dist/node_modules/@wheatley-ai/sdk/dist/commands.js +2 -2
  53. package/dist/node_modules/@wheatley-ai/sdk/dist/frontend.d.ts +23 -0
  54. package/dist/node_modules/@wheatley-ai/sdk/dist/index.d.ts +1 -1
  55. package/dist/node_modules/@wheatley-ai/sdk/package.json +1 -1
  56. package/dist/ops/cli.js +92 -98
  57. package/dist/ops/service.js +6 -1
  58. package/dist/ops/update.js +14 -27
  59. package/dist/triggers/delivery-codec.js +13 -0
  60. package/dist/triggers/webhook-ingress.js +89 -82
  61. package/package.json +9 -2
  62. package/dist/dashboard/assets/index-C9Rul5vE.css +0 -2
  63. package/dist/dashboard/assets/index-DThc2x_d.js +0 -11
@@ -1,79 +1,53 @@
1
- import { readFile, stat } from "node:fs/promises";
1
+ import { existsSync } from "node:fs";
2
2
  import path from "node:path";
3
+ import { serveStatic } from "@hono/node-server/serve-static";
3
4
  /** The dashboard entry file. Paths without a file extension fall back to it, so the SPA can route itself. */
4
5
  const INDEX_FILE = "index.html";
5
- const CONTENT_TYPES = new Map([
6
- [".css", "text/css; charset=utf-8"],
7
- [".html", "text/html; charset=utf-8"],
8
- [".ico", "image/x-icon"],
9
- [".js", "text/javascript; charset=utf-8"],
10
- [".json", "application/json; charset=utf-8"],
11
- [".map", "application/json; charset=utf-8"],
12
- [".png", "image/png"],
13
- [".svg", "image/svg+xml"],
14
- [".txt", "text/plain; charset=utf-8"],
15
- [".webp", "image/webp"],
16
- [".woff", "font/woff"],
17
- [".woff2", "font/woff2"],
18
- ]);
19
- const contentTypeOf = (file) => CONTENT_TYPES.get(path.extname(file).toLowerCase()) ??
20
- "application/octet-stream";
21
- const isFile = async (file) => {
22
- try {
23
- const info = await stat(file);
24
- return info.isFile();
25
- }
26
- catch {
27
- return false;
28
- }
6
+ /** A Hono path pattern for every path whose last segment has no file extension, such as `/agents/foo/chat`. */
7
+ const SPA_ROUTE = "/:route{(?:[^/]+/)*[^/.]*}";
8
+ /** The file that `serveStatic` found for a request. */
9
+ const servedFiles = new WeakMap();
10
+ const recordFile = (file, c) => {
11
+ servedFiles.set(c, file);
29
12
  };
30
13
  /**
31
- * Resolves the file for a URL path inside `root`, or `undefined`. A path that leaves `root` resolves `undefined`. A
32
- * path without a file extension resolves the SPA entry.
14
+ * Adds the cache and `nosniff` headers to a file response of `serve`. `serveStatic` builds its response before it
15
+ * calls `onFound`, so headers that `onFound` sets do not reach the response.
33
16
  */
34
- const resolveFile = async (root, urlPath) => {
35
- let decoded;
36
- try {
37
- decoded = decodeURIComponent(urlPath);
38
- }
39
- catch {
40
- return undefined;
41
- }
42
- const target = path.resolve(root, `.${path.posix.normalize(decoded)}`);
43
- const inside = target === root || target.startsWith(`${root}${path.sep}`);
44
- if (!inside) {
45
- return undefined;
46
- }
47
- if (await isFile(target)) {
48
- return target;
49
- }
50
- const entry = path.join(root, INDEX_FILE);
51
- const isRoute = path.extname(target) === "";
52
- return isRoute && (await isFile(entry)) ? entry : undefined;
17
+ const withHeaders = (serve) => async (c, next) => {
18
+ const response = await serve(c, next);
19
+ const file = servedFiles.get(c);
20
+ if (response instanceof Response && file !== undefined) {
21
+ response.headers.set("cache-control", path.basename(file) === INDEX_FILE ? "no-cache" : "max-age=3600");
22
+ response.headers.set("x-content-type-options", "nosniff");
23
+ }
24
+ return response;
25
+ };
26
+ const passOn = async (_c, proceed) => {
27
+ await proceed();
28
+ };
29
+ /**
30
+ * Runs the handler that `create` builds while `root` exists, and passes the request on while it does not. It checks on
31
+ * each request, so a dashboard built after the daemon starts is served without a restart. `serveStatic` logs an error
32
+ * for a missing root when it is built, so `create` runs on the first request that finds the folder.
33
+ */
34
+ const whileRootExists = (root, create) => {
35
+ let created;
36
+ return async (c, next) => {
37
+ const handler = existsSync(root) ? (created ??= create()) : passOn;
38
+ return await handler(c, next);
39
+ };
53
40
  };
54
41
  /**
55
- * Serves `GET` and `HEAD` requests from the bundled dashboard folder. Resolves `false` if no file matches, so the
56
- * caller can answer with its own response.
42
+ * Serves `GET` and `HEAD` requests from the bundled dashboard folder on `app`. A path without a file extension that
43
+ * matches no file serves the SPA entry. Requests that match no file fall through to the next handler, and so do all
44
+ * requests while the folder is missing, for example in a source checkout without a built dashboard.
57
45
  *
58
46
  * The dashboard is static and holds no data. It reads everything over `/ws`, where the Control Server checks the
59
47
  * browser `Origin`.
60
48
  */
61
- export const serveStaticFile = async (root, request, response) => {
62
- if (request.method !== "GET" && request.method !== "HEAD") {
63
- return false;
64
- }
65
- const { pathname } = new URL(request.url ?? "/", "http://localhost");
66
- const file = await resolveFile(path.resolve(root), pathname);
67
- if (file === undefined) {
68
- return false;
69
- }
70
- const body = await readFile(file);
71
- response.writeHead(200, {
72
- "cache-control": path.basename(file) === INDEX_FILE ? "no-cache" : "max-age=3600",
73
- "content-length": body.byteLength,
74
- "content-type": contentTypeOf(file),
75
- "x-content-type-options": "nosniff",
76
- });
77
- response.end(request.method === "HEAD" ? undefined : body);
78
- return true;
49
+ export const mountStaticFiles = (app, root) => {
50
+ const absolute = path.resolve(root);
51
+ app.get("*", whileRootExists(absolute, () => withHeaders(serveStatic({ onFound: recordFile, root: absolute }))));
52
+ app.get(SPA_ROUTE, whileRootExists(absolute, () => withHeaders(serveStatic({ onFound: recordFile, path: INDEX_FILE, root: absolute }))));
79
53
  };