apps 1.0.0-beta.3 → 2.0.0-next.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 (90) hide show
  1. package/README.md +10 -48
  2. package/check-publish.mjs +7 -0
  3. package/package.json +27 -56
  4. package/src/Access.ts +37 -0
  5. package/src/Accounts.ts +468 -0
  6. package/src/App.ts +11 -0
  7. package/src/Ask.ts +156 -0
  8. package/src/Changes.ts +13 -0
  9. package/src/Http.ts +30 -0
  10. package/src/Provider.ts +146 -0
  11. package/src/Session.ts +52 -0
  12. package/src/Settings.ts +164 -0
  13. package/src/contract.ts +852 -0
  14. package/src/css-modules.d.ts +2 -0
  15. package/src/desktop/Desktop.ts +192 -0
  16. package/src/desktop/bridge.ts +62 -0
  17. package/src/desktop/errors.ts +88 -0
  18. package/src/desktop/index.ts +15 -0
  19. package/src/entry.ts +48 -0
  20. package/src/index.ts +16 -4
  21. package/src/internal/defects.ts +62 -0
  22. package/src/internal/files.ts +369 -0
  23. package/src/internal/host.ts +17 -0
  24. package/src/internal/query.ts +114 -0
  25. package/src/internal/records.ts +838 -0
  26. package/src/internal/retention.ts +87 -0
  27. package/src/internal/retries.ts +185 -0
  28. package/src/internal/telemetry.ts +167 -0
  29. package/src/migrations.ts +110 -0
  30. package/src/page/Accounts.ts +27 -0
  31. package/src/page/Changes.ts +126 -0
  32. package/src/page/Session.ts +46 -0
  33. package/src/page/client.ts +107 -0
  34. package/src/page/errors.ts +15 -0
  35. package/src/page/http.ts +21 -0
  36. package/src/page/index.ts +18 -0
  37. package/src/page/paths.ts +22 -0
  38. package/src/providers/anthropic.ts +26 -0
  39. package/src/providers/github.ts +49 -0
  40. package/src/providers/google.ts +67 -0
  41. package/src/providers/openai.ts +62 -0
  42. package/src/providers/slack.ts +81 -0
  43. package/src/runtime.ts +1540 -0
  44. package/src/testing.ts +660 -0
  45. package/src/text-modules.d.ts +5 -0
  46. package/src/theme.css +50 -0
  47. package/dist/authoring/index.d.ts +0 -393
  48. package/dist/authoring/index.js +0 -36
  49. package/dist/chunk-4OZFMCTT.js +0 -17
  50. package/dist/chunk-A3H32P2J.js +0 -143
  51. package/dist/chunk-B7NEUIJL.js +0 -14
  52. package/dist/chunk-F7GZYEAC.js +0 -41
  53. package/dist/chunk-MUFMJRXR.js +0 -308
  54. package/dist/chunk-S5KFP4JQ.js +0 -20
  55. package/dist/chunk-Y6LLTN7W.js +0 -99
  56. package/dist/chunk-YUZ4TXOY.js +0 -27
  57. package/dist/http/index.d.ts +0 -9
  58. package/dist/http/index.js +0 -6
  59. package/dist/index.d.ts +0 -4
  60. package/dist/index.js +0 -48
  61. package/dist/manifest/contract.d.ts +0 -63
  62. package/dist/manifest/contract.js +0 -8
  63. package/dist/manifest/index.d.ts +0 -20
  64. package/dist/manifest/index.js +0 -16
  65. package/dist/mcp/client.d.ts +0 -9
  66. package/dist/mcp/index.d.ts +0 -11
  67. package/dist/mcp/index.js +0 -7
  68. package/dist/openapi/index.d.ts +0 -14
  69. package/dist/openapi/index.js +0 -7
  70. package/dist/openapi/mapper.d.ts +0 -7
  71. package/dist/runner/index.d.ts +0 -4
  72. package/dist/runner/index.js +0 -66
  73. package/dist/runner/protocol.d.ts +0 -33
  74. package/dist/runner/protocol.js +0 -8
  75. package/dist/runtime/index.d.ts +0 -83
  76. package/dist/runtime/index.js +0 -12
  77. package/dist/workerd/index.d.ts +0 -7
  78. package/dist/workerd/index.js +0 -10
  79. package/src/authoring/index.ts +0 -658
  80. package/src/http/index.ts +0 -26
  81. package/src/manifest/contract.ts +0 -64
  82. package/src/manifest/index.ts +0 -156
  83. package/src/mcp/client.ts +0 -59
  84. package/src/mcp/index.ts +0 -42
  85. package/src/openapi/index.ts +0 -70
  86. package/src/openapi/mapper.ts +0 -25
  87. package/src/runner/index.ts +0 -80
  88. package/src/runner/protocol.ts +0 -54
  89. package/src/runtime/index.ts +0 -550
  90. package/src/workerd/index.ts +0 -17
@@ -0,0 +1,2 @@
1
+ /** A page imports stylesheets for their effect (`import "apps/theme.css"`); Vite bundles them. */
2
+ declare module "*.css" {}
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Desktop features, as an optional service. Present when the page is open in
3
+ * the Executor desktop app, absent in a browser tab:
4
+ *
5
+ * ```ts
6
+ * const found = yield* Desktop.find
7
+ * if (Option.isNone(found)) return // a browser tab
8
+ * const presses = yield* found.value.shortcut("CommandOrControl+Shift+I") // held while the scope is open
9
+ * yield* Stream.runForEach(presses, () => openSearch)
10
+ * ```
11
+ *
12
+ * Notifications, the microphone and the camera are the web's own APIs; the
13
+ * desktop asks the person in front of them. This service has what the web has
14
+ * no API for.
15
+ */
16
+ import { Context, Effect, Layer, Option, Queue, Schedule, type Scope, Stream } from "effect";
17
+ import {
18
+ type Bridge,
19
+ findBridge,
20
+ type PermissionState,
21
+ SHORTCUT_EVENT,
22
+ WINDOW_EVENT,
23
+ type WindowOptions,
24
+ } from "./bridge.ts";
25
+ import {
26
+ type DesktopError,
27
+ type DesktopInvalidInput,
28
+ type DesktopPermissionDenied,
29
+ type DesktopUnsupported,
30
+ fromRejection,
31
+ type PermissionName,
32
+ type ShortcutTaken,
33
+ } from "./errors.ts";
34
+
35
+ export type { PermissionState, WindowOptions };
36
+
37
+ export interface DesktopShape {
38
+ /** Whether the person allowed `name`, without asking. */
39
+ readonly permission: (name: PermissionName) => Effect.Effect<PermissionState, DesktopError>;
40
+ /** Ask now, if the person has not answered yet, and return their answer. */
41
+ readonly requestPermission: (
42
+ name: PermissionName,
43
+ ) => Effect.Effect<PermissionState, DesktopError>;
44
+ /**
45
+ * Hold a global shortcut, in Electron's accelerator syntax, while the scope
46
+ * is open; its presses are the stream. Closing the scope gives it back.
47
+ */
48
+ readonly shortcut: (
49
+ accelerator: string,
50
+ ) => Effect.Effect<
51
+ Stream.Stream<void>,
52
+ ShortcutTaken | DesktopPermissionDenied | DesktopInvalidInput | DesktopUnsupported,
53
+ Scope.Scope
54
+ >;
55
+ readonly menuBar: {
56
+ /** Up to 24 characters beside the app's menu-bar icon; `null` shows the app's name. */
57
+ readonly setTitle: (text: string | null) => Effect.Effect<void, DesktopError>;
58
+ };
59
+ readonly window: {
60
+ readonly show: Effect.Effect<void, DesktopError>;
61
+ readonly hide: Effect.Effect<void, DesktopError>;
62
+ readonly focus: Effect.Effect<void, DesktopError>;
63
+ readonly toggle: Effect.Effect<void, DesktopError>;
64
+ /** Keep the window above others. Needs the `floating` permission. */
65
+ readonly setFloating: (on: boolean) => Effect.Effect<void, DesktopError>;
66
+ /** Open another window of the app at a path on its own address, or focus the one that shows it. */
67
+ readonly open: (path: string, options?: WindowOptions) => Effect.Effect<void, DesktopError>;
68
+ /** The page's window gaining and losing focus. */
69
+ readonly events: Stream.Stream<"focus" | "blur">;
70
+ };
71
+ readonly badge: {
72
+ /** A count on the app's icon; `null` or 0 removes it. */
73
+ readonly set: (count: number | null) => Effect.Effect<void, DesktopError>;
74
+ };
75
+ /** Ask for system audio; afterwards `getDisplayMedia` in this page captures what the computer plays. */
76
+ readonly systemAudio: Effect.Effect<void, DesktopError>;
77
+ }
78
+
79
+ export class Desktop extends Context.Service<Desktop, DesktopShape>()("apps/desktop/Desktop") {}
80
+
81
+ /** Where the bridge and its events are: the page's `window`. Set it only in tests. */
82
+ export const DesktopWindow = Context.Reference<unknown>("apps/desktop/DesktopWindow", {
83
+ defaultValue: () => globalThis,
84
+ });
85
+
86
+ const call = <A>(run: () => Promise<A>): Effect.Effect<A, DesktopError> =>
87
+ Effect.tryPromise({ try: run, catch: (cause) => cause }).pipe(
88
+ Effect.catch((cause) => {
89
+ const error = fromRejection(cause);
90
+ return error === undefined ? Effect.die(cause) : Effect.fail(error);
91
+ }),
92
+ );
93
+
94
+ interface Target {
95
+ addEventListener(type: string, listener: (event: unknown) => void): void;
96
+ removeEventListener(type: string, listener: (event: unknown) => void): void;
97
+ }
98
+
99
+ const detail = (event: unknown): Record<string, unknown> | undefined => {
100
+ const value = (event as { detail?: unknown } | null)?.detail;
101
+ return typeof value === "object" && value !== null
102
+ ? (value as Record<string, unknown>)
103
+ : undefined;
104
+ };
105
+
106
+ /** The service over a bridge, with presses and window events from `target`. */
107
+ export const make = (bridge: Bridge, target: Target): DesktopShape => ({
108
+ permission: (name) => call(() => bridge.permission(name)),
109
+ requestPermission: (name) => call(() => bridge.requestPermission(name)),
110
+ shortcut: (accelerator) =>
111
+ Effect.gen(function* () {
112
+ const presses = yield* Queue.unbounded<void>();
113
+ const { id } = yield* Effect.acquireRelease(
114
+ call(() => bridge.registerShortcut(accelerator)).pipe(
115
+ Effect.catchTag("SystemAudioBlocked", (error) => Effect.die(error)),
116
+ ),
117
+ ({ id }) =>
118
+ // external: the desktop app holds a shortcut until unregisterShortcut resolves, even across a page reload.
119
+ call(() => bridge.unregisterShortcut(id)).pipe(
120
+ Effect.retry({ schedule: Schedule.exponential("50 millis"), times: 4 }),
121
+ Effect.catch((error) =>
122
+ Effect.logWarning("apps/desktop: a shortcut could not be given back", error),
123
+ ),
124
+ ),
125
+ );
126
+ // external: the desktop app delivers every shortcut press to every window of the app.
127
+ const listener = (event: unknown) => {
128
+ if (detail(event)?.id === id) Queue.offerUnsafe(presses, undefined);
129
+ };
130
+ yield* Effect.acquireRelease(
131
+ Effect.sync(() => target.addEventListener(SHORTCUT_EVENT, listener)),
132
+ () =>
133
+ Effect.andThen(
134
+ Effect.sync(() => target.removeEventListener(SHORTCUT_EVENT, listener)),
135
+ Queue.shutdown(presses),
136
+ ),
137
+ );
138
+ return Stream.fromQueue(presses);
139
+ }),
140
+ menuBar: { setTitle: (text) => call(() => bridge.setMenuBarTitle(text)) },
141
+ window: {
142
+ show: call(() => bridge.windowAction("show")),
143
+ hide: call(() => bridge.windowAction("hide")),
144
+ focus: call(() => bridge.windowAction("focus")),
145
+ toggle: call(() => bridge.windowAction("toggle")),
146
+ setFloating: (on) => call(() => bridge.setFloating(on)),
147
+ open: (path, options) => call(() => bridge.openWindow(path, options ?? {})),
148
+ events: Stream.callback<"focus" | "blur">((queue) =>
149
+ Effect.acquireRelease(
150
+ Effect.sync(() => {
151
+ const listener = (event: unknown) => {
152
+ const type = detail(event)?.type;
153
+ if (type === "focus" || type === "blur") Queue.offerUnsafe(queue, type);
154
+ };
155
+ target.addEventListener(WINDOW_EVENT, listener);
156
+ return listener;
157
+ }),
158
+ (listener) => Effect.sync(() => target.removeEventListener(WINDOW_EVENT, listener)),
159
+ ),
160
+ ),
161
+ },
162
+ badge: { set: (count) => call(() => bridge.setBadge(count)) },
163
+ systemAudio: call(() => bridge.systemAudio()),
164
+ });
165
+
166
+ /** The desktop service if the page is in the desktop app, from the window itself. */
167
+ export const fromWindow: Effect.Effect<Option.Option<DesktopShape>> = Effect.gen(function* () {
168
+ const host = yield* DesktopWindow;
169
+ const bridge = findBridge(host);
170
+ return bridge === undefined ? Option.none() : Option.some(make(bridge, host as Target));
171
+ });
172
+
173
+ /**
174
+ * The desktop, when there is one: a provided {@link Desktop} first (a test or
175
+ * a stand-in), then the window's own bridge.
176
+ */
177
+ export const find: Effect.Effect<Option.Option<DesktopShape>> = Effect.gen(function* () {
178
+ const provided = yield* Effect.serviceOption(Desktop);
179
+ return Option.isSome(provided) ? provided : yield* fromWindow;
180
+ });
181
+
182
+ /**
183
+ * Provides {@link Desktop} in the desktop app and nothing in a browser tab, so
184
+ * code below it reads it with `Effect.serviceOption(Desktop)`.
185
+ */
186
+ export const layer: Layer.Layer<never> = Layer.unwrap(
187
+ Effect.map(fromWindow, (found) =>
188
+ Option.isSome(found)
189
+ ? (Layer.succeed(Desktop, found.value) as Layer.Layer<never>)
190
+ : Layer.empty,
191
+ ),
192
+ );
@@ -0,0 +1,62 @@
1
+ /**
2
+ * The Executor desktop app's page bridge, version 1, as a wire protocol. The
3
+ * desktop's preload puts it on `window` only in its own windows, and checks
4
+ * the page's origin on every call. These names and shapes are fixed by the
5
+ * desktop app; this file restates them so `apps` shares no code with today's
6
+ * app format.
7
+ */
8
+ import type { PermissionName } from "./errors.ts";
9
+
10
+ export const BRIDGE_GLOBAL = "__executorDesktop" as const;
11
+ export const BRIDGE_VERSION = 1 as const;
12
+ /** Dispatched on `window` with `detail` `{ id }` when a registered shortcut is pressed. */
13
+ export const SHORTCUT_EVENT = "executor:desktop-shortcut" as const;
14
+ /** Dispatched on `window` with `detail` `{ type: "focus" | "blur" }`. */
15
+ export const WINDOW_EVENT = "executor:desktop-window" as const;
16
+
17
+ export type PermissionState = "granted" | "denied" | "prompt" | "unavailable";
18
+
19
+ export interface WindowOptions {
20
+ readonly width?: number;
21
+ readonly height?: number;
22
+ readonly floating?: boolean;
23
+ }
24
+
25
+ export interface Bridge {
26
+ readonly version: typeof BRIDGE_VERSION;
27
+ readonly permission: (name: PermissionName) => Promise<PermissionState>;
28
+ readonly requestPermission: (name: PermissionName) => Promise<PermissionState>;
29
+ readonly setMenuBarTitle: (text: string | null) => Promise<void>;
30
+ readonly registerShortcut: (accelerator: string) => Promise<{ readonly id: string }>;
31
+ readonly unregisterShortcut: (id: string) => Promise<void>;
32
+ readonly setFloating: (on: boolean) => Promise<void>;
33
+ readonly windowAction: (action: "show" | "hide" | "focus" | "toggle") => Promise<void>;
34
+ readonly openWindow: (path: string, options: WindowOptions) => Promise<void>;
35
+ readonly setBadge: (count: number | null) => Promise<void>;
36
+ readonly systemAudio: () => Promise<void>;
37
+ }
38
+
39
+ const methods: ReadonlyArray<keyof Bridge> = [
40
+ "permission",
41
+ "requestPermission",
42
+ "setMenuBarTitle",
43
+ "registerShortcut",
44
+ "unregisterShortcut",
45
+ "setFloating",
46
+ "windowAction",
47
+ "openWindow",
48
+ "setBadge",
49
+ "systemAudio",
50
+ ];
51
+
52
+ /** The bridge on `host`, when it is one this module speaks. */
53
+ export const findBridge = (host: unknown): Bridge | undefined => {
54
+ if (typeof host !== "object" || host === null) return undefined;
55
+ const bridge = (host as Record<string, unknown>)[BRIDGE_GLOBAL];
56
+ if (typeof bridge !== "object" || bridge === null) return undefined;
57
+ const record = bridge as Record<string, unknown>;
58
+ if (record.version !== BRIDGE_VERSION) return undefined;
59
+ return methods.every((name) => typeof record[name] === "function")
60
+ ? (bridge as Bridge)
61
+ : undefined;
62
+ };
@@ -0,0 +1,88 @@
1
+ import { Schema } from "effect";
2
+
3
+ export const PermissionName = Schema.Literals([
4
+ "menuBar",
5
+ "shortcuts",
6
+ "floating",
7
+ "startAtLogin",
8
+ "microphone",
9
+ "camera",
10
+ "systemAudio",
11
+ "clipboardRead",
12
+ "notifications",
13
+ ]);
14
+ export type PermissionName = typeof PermissionName.Type;
15
+
16
+ /** The person did not allow this capability for the app. */
17
+ export class DesktopPermissionDenied extends Schema.TaggedError<DesktopPermissionDenied>()(
18
+ "DesktopPermissionDenied",
19
+ { permission: PermissionName },
20
+ ) {}
21
+
22
+ /** Another app or program already holds this global shortcut. */
23
+ export class ShortcutTaken extends Schema.TaggedError<ShortcutTaken>()("ShortcutTaken", {
24
+ accelerator: Schema.String,
25
+ }) {}
26
+
27
+ /** The desktop does not accept the input, such as a title that is too long. */
28
+ export class DesktopInvalidInput extends Schema.TaggedError<DesktopInvalidInput>()(
29
+ "DesktopInvalidInput",
30
+ {
31
+ message: Schema.String,
32
+ },
33
+ ) {}
34
+
35
+ /**
36
+ * The page is in the desktop app, but this computer cannot do this (system
37
+ * audio on Linux, for one), or the desktop closed the bridge.
38
+ */
39
+ export class DesktopUnsupported extends Schema.TaggedError<DesktopUnsupported>()(
40
+ "DesktopUnsupported",
41
+ {},
42
+ ) {}
43
+
44
+ /** The app may hear system audio, but macOS has not allowed Executor to record it. Try again after System Settings. */
45
+ export class SystemAudioBlocked extends Schema.TaggedError<SystemAudioBlocked>()(
46
+ "SystemAudioBlocked",
47
+ {},
48
+ ) {}
49
+
50
+ export type DesktopError =
51
+ | DesktopPermissionDenied
52
+ | ShortcutTaken
53
+ | DesktopInvalidInput
54
+ | DesktopUnsupported
55
+ | SystemAudioBlocked;
56
+
57
+ /** The plain tagged objects the bridge rejects with, as they cross the desktop's preload. */
58
+ const Rejection = Schema.Union([
59
+ Schema.TaggedStruct("DesktopUnavailable", {}),
60
+ Schema.TaggedStruct("DesktopPermissionDenied", { permission: PermissionName }),
61
+ Schema.TaggedStruct("ShortcutTaken", { accelerator: Schema.String }),
62
+ Schema.TaggedStruct("DesktopInvalidInput", { message: Schema.String }),
63
+ Schema.TaggedStruct("SystemAudioBlocked", {}),
64
+ ]);
65
+ const decodeRejection = Schema.decodeUnknownOption(Rejection);
66
+
67
+ /**
68
+ * A bridge rejection as a typed error. The page only gets here when the bridge
69
+ * exists, so the bridge's `DesktopUnavailable` means "not on this computer".
70
+ * Anything unrecognised is a defect.
71
+ */
72
+ export const fromRejection = (cause: unknown): DesktopError | undefined => {
73
+ const rejection = decodeRejection(cause);
74
+ if (rejection._tag === "None") return undefined;
75
+ const value = rejection.value;
76
+ switch (value._tag) {
77
+ case "DesktopUnavailable":
78
+ return new DesktopUnsupported();
79
+ case "DesktopPermissionDenied":
80
+ return new DesktopPermissionDenied({ permission: value.permission });
81
+ case "ShortcutTaken":
82
+ return new ShortcutTaken({ accelerator: value.accelerator });
83
+ case "DesktopInvalidInput":
84
+ return new DesktopInvalidInput({ message: value.message });
85
+ case "SystemAudioBlocked":
86
+ return new SystemAudioBlocked();
87
+ }
88
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * `apps/desktop`: the optional `Desktop` service, present when a page is open
3
+ * in the Executor desktop app and absent in a browser tab.
4
+ */
5
+ export { Desktop, DesktopWindow, find, fromWindow, layer, make } from "./Desktop.ts";
6
+ export type { DesktopShape, PermissionState, WindowOptions } from "./Desktop.ts";
7
+ export {
8
+ DesktopInvalidInput,
9
+ DesktopPermissionDenied,
10
+ DesktopUnsupported,
11
+ PermissionName,
12
+ ShortcutTaken,
13
+ SystemAudioBlocked,
14
+ } from "./errors.ts";
15
+ export type { DesktopError } from "./errors.ts";
package/src/entry.ts ADDED
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The source of a new-format app's bundle entry: the one module the build
3
+ * step bundles. The platform's build and `testing/build.ts` both call this, so
4
+ * the entry cannot drift from the runtime. No runtime imports: callable from
5
+ * Node and from inside workerd.
6
+ *
7
+ * The entry exports what the contract names: `App` (the Durable Object class)
8
+ * and a default `WorkerEntrypoint` (`describe()`).
9
+ */
10
+ export interface EntryOptions {
11
+ /** File names in the app's `migrations/` folder (`0001_name.sql` or `.ts`); others are ignored. */
12
+ readonly migrations: ReadonlyArray<string>;
13
+ /** The version of `apps` the app is built with. */
14
+ readonly appsVersion: string;
15
+ /** The version of `effect` bundled with the app. */
16
+ readonly effectVersion: string;
17
+ /** The app's server module, relative to the app's root. Default `./index.ts`. */
18
+ readonly appModule?: string | undefined;
19
+ /** Where `apps/runtime` resolves from. Default `apps/runtime`. */
20
+ readonly runtimeModule?: string | undefined;
21
+ /** Runtime options passed to `makeApp`, as JSON. */
22
+ readonly runtimeOptions?: Readonly<Record<string, unknown>> | undefined;
23
+ }
24
+
25
+ const migrationFile = /^(\d+)_([\w-]+)\.(sql|ts)$/u;
26
+
27
+ export const entrySource = (options: EntryOptions): string => {
28
+ const files = options.migrations.filter((file) => migrationFile.test(file)).sort();
29
+ const imports: Array<string> = [];
30
+ const entries: Array<string> = [];
31
+ files.forEach((file, i) => {
32
+ const key = JSON.stringify(file.replace(/\.(sql|ts)$/u, ""));
33
+ imports.push(`import migration${i} from ${JSON.stringify(`./migrations/${file}`)}`);
34
+ entries.push(
35
+ file.endsWith(".sql") ? `${key}: sqlMigration(migration${i})` : `${key}: migration${i}`,
36
+ );
37
+ });
38
+ const build = `{ migrations: { ${entries.join(", ")} }, appsVersion: ${JSON.stringify(options.appsVersion)}, effectVersion: ${JSON.stringify(options.effectVersion)} }`;
39
+ return [
40
+ `import app from ${JSON.stringify(options.appModule ?? "./index.ts")}`,
41
+ `import { makeApp, makeEntrypoint, sqlMigration } from ${JSON.stringify(options.runtimeModule ?? "apps/runtime")}`,
42
+ ...imports,
43
+ `const build = ${build}`,
44
+ `export const App = makeApp(app, build${options.runtimeOptions === undefined ? "" : `, ${JSON.stringify(options.runtimeOptions)}`})`,
45
+ `export default makeEntrypoint(app, build)`,
46
+ "",
47
+ ].join("\n");
48
+ };
package/src/index.ts CHANGED
@@ -1,4 +1,16 @@
1
- export * from "./authoring/index";
2
- export * from "./http/index";
3
- export * from "./mcp/index";
4
- export * from "./openapi/index";
1
+ // oxlint-disable-next-line typescript/triple-slash-reference -- external: a wildcard module declaration (*.md as text) only reaches an author's project through a reference from the package entry.
2
+ /// <reference path="./text-modules.d.ts" />
3
+ /**
4
+ * `apps`: what an Executor app imports that Effect does not have. Everything
5
+ * else (SQL, files, settings, routes, tools, the MCP server, workflows,
6
+ * scheduled jobs, logging and tracing) is Effect's own, under its own name.
7
+ */
8
+ export * as Session from "./Session.ts";
9
+ export * as App from "./App.ts";
10
+ export * as Accounts from "./Accounts.ts";
11
+ export * as Provider from "./Provider.ts";
12
+ export * as Settings from "./Settings.ts";
13
+ export * as Access from "./Access.ts";
14
+ export * as Http from "./Http.ts";
15
+ export * as Ask from "./Ask.ts";
16
+ export * as Changes from "./Changes.ts";
@@ -0,0 +1,62 @@
1
+ /**
2
+ * A request's first defect, for the host's records: Effect's McpServer (and the HTTP router)
3
+ * report a die or an unexpected failure through `ErrorReporter` before answering the generic
4
+ * "internal server error", and this reporter keeps the first one for the request it came from.
5
+ * The runtime sends it to the host as one response header, which the host strips; the caller's
6
+ * answer is unchanged.
7
+ */
8
+ import { Context, ErrorReporter } from "effect";
9
+
10
+ export const DEFECT_HEADER = "x-executor-app-defect";
11
+
12
+ export interface Defect {
13
+ readonly name: string;
14
+ readonly message: string;
15
+ readonly place: string | null;
16
+ }
17
+
18
+ export interface DefectSlot {
19
+ first: Defect | undefined;
20
+ }
21
+
22
+ export const CurrentDefectSlot = Context.Reference<DefectSlot | undefined>("apps/DefectSlot", {
23
+ defaultValue: () => undefined,
24
+ });
25
+
26
+ const nameOf = (error: Error): string => {
27
+ const tag = (error as { readonly _tag?: unknown })._tag;
28
+ return typeof tag === "string" ? tag : error.name;
29
+ };
30
+
31
+ const placeOf = (error: Error): string | null => {
32
+ for (const line of (error.stack ?? "").split("\n").slice(1)) {
33
+ const found = /\(?([^\s()]+:\d+:\d+)\)?\s*$/u.exec(line.trim());
34
+ if (found?.[1] !== undefined) return found[1];
35
+ }
36
+ return null;
37
+ };
38
+
39
+ export const reporter = ErrorReporter.make(({ error, fiber }) => {
40
+ const slot = fiber.getRef(CurrentDefectSlot);
41
+ if (slot === undefined || slot.first !== undefined) return;
42
+ slot.first = {
43
+ name: nameOf(error),
44
+ message: error.message.slice(0, 1_000),
45
+ place: placeOf(error),
46
+ };
47
+ });
48
+
49
+ export const encode = (defect: Defect): string => {
50
+ let binary = "";
51
+ for (const byte of new TextEncoder().encode(JSON.stringify(defect)))
52
+ binary += String.fromCharCode(byte);
53
+ return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/u, "");
54
+ };
55
+
56
+ /** The response with the request's first defect as a header, or as it was when there was none. */
57
+ export const withDefect = (response: Response, slot: DefectSlot): Response => {
58
+ if (slot.first === undefined) return response;
59
+ const marked = new Response(response.body, response);
60
+ marked.headers.set(DEFECT_HEADER, encode(slot.first));
61
+ return marked;
62
+ };