apps 1.0.0-beta.4 → 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.
- package/README.md +10 -48
- package/check-publish.mjs +7 -0
- package/package.json +27 -56
- package/src/Access.ts +37 -0
- package/src/Accounts.ts +468 -0
- package/src/App.ts +11 -0
- package/src/Ask.ts +156 -0
- package/src/Changes.ts +13 -0
- package/src/Http.ts +30 -0
- package/src/Provider.ts +146 -0
- package/src/Session.ts +52 -0
- package/src/Settings.ts +164 -0
- package/src/contract.ts +852 -0
- package/src/css-modules.d.ts +2 -0
- package/src/desktop/Desktop.ts +192 -0
- package/src/desktop/bridge.ts +62 -0
- package/src/desktop/errors.ts +88 -0
- package/src/desktop/index.ts +15 -0
- package/src/entry.ts +48 -0
- package/src/index.ts +16 -4
- package/src/internal/defects.ts +62 -0
- package/src/internal/files.ts +369 -0
- package/src/internal/host.ts +17 -0
- package/src/internal/query.ts +114 -0
- package/src/internal/records.ts +838 -0
- package/src/internal/retention.ts +87 -0
- package/src/internal/retries.ts +185 -0
- package/src/internal/telemetry.ts +167 -0
- package/src/migrations.ts +110 -0
- package/src/page/Accounts.ts +27 -0
- package/src/page/Changes.ts +126 -0
- package/src/page/Session.ts +46 -0
- package/src/page/client.ts +107 -0
- package/src/page/errors.ts +15 -0
- package/src/page/http.ts +21 -0
- package/src/page/index.ts +18 -0
- package/src/page/paths.ts +22 -0
- package/src/providers/anthropic.ts +26 -0
- package/src/providers/github.ts +49 -0
- package/src/providers/google.ts +67 -0
- package/src/providers/openai.ts +62 -0
- package/src/providers/slack.ts +81 -0
- package/src/runtime.ts +1540 -0
- package/src/testing.ts +660 -0
- package/src/text-modules.d.ts +5 -0
- package/src/theme.css +50 -0
- package/dist/authoring/index.d.ts +0 -422
- package/dist/authoring/index.js +0 -36
- package/dist/chunk-2DVKSPQH.js +0 -312
- package/dist/chunk-4OZFMCTT.js +0 -17
- package/dist/chunk-535V5K64.js +0 -155
- package/dist/chunk-B7NEUIJL.js +0 -14
- package/dist/chunk-DP6UJCMX.js +0 -27
- package/dist/chunk-QA72XJZU.js +0 -41
- package/dist/chunk-S5KFP4JQ.js +0 -20
- package/dist/chunk-XYT6GZ7M.js +0 -99
- package/dist/http/index.d.ts +0 -9
- package/dist/http/index.js +0 -6
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -48
- package/dist/manifest/contract.d.ts +0 -63
- package/dist/manifest/contract.js +0 -8
- package/dist/manifest/index.d.ts +0 -20
- package/dist/manifest/index.js +0 -16
- package/dist/mcp/client.d.ts +0 -9
- package/dist/mcp/index.d.ts +0 -11
- package/dist/mcp/index.js +0 -7
- package/dist/openapi/index.d.ts +0 -14
- package/dist/openapi/index.js +0 -7
- package/dist/openapi/mapper.d.ts +0 -7
- package/dist/runner/index.d.ts +0 -4
- package/dist/runner/index.js +0 -66
- package/dist/runner/protocol.d.ts +0 -33
- package/dist/runner/protocol.js +0 -8
- package/dist/runtime/index.d.ts +0 -83
- package/dist/runtime/index.js +0 -12
- package/dist/workerd/index.d.ts +0 -7
- package/dist/workerd/index.js +0 -10
- package/src/authoring/index.ts +0 -686
- package/src/http/index.ts +0 -26
- package/src/manifest/contract.ts +0 -64
- package/src/manifest/index.ts +0 -156
- package/src/mcp/client.ts +0 -59
- package/src/mcp/index.ts +0 -42
- package/src/openapi/index.ts +0 -70
- package/src/openapi/mapper.ts +0 -25
- package/src/runner/index.ts +0 -80
- package/src/runner/protocol.ts +0 -54
- package/src/runtime/index.ts +0 -554
- package/src/workerd/index.ts +0 -17
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Refresh on data change, with no code from the author.
|
|
3
|
+
*
|
|
4
|
+
* Executor tells an open page each time the app's data changed, over
|
|
5
|
+
* `/_executor/changes` (server-sent events). Every query made with
|
|
6
|
+
* `client(Api)` carries {@link dataKey}, and every `change` invalidates it, so
|
|
7
|
+
* whatever is on screen fetches again. It is coarse on purpose: one key for
|
|
8
|
+
* the whole app.
|
|
9
|
+
*
|
|
10
|
+
* After a reconnect the page may have missed a change, so it refreshes then
|
|
11
|
+
* too. When a new version of the app takes traffic, the page reloads.
|
|
12
|
+
*/
|
|
13
|
+
import { Cause, Context, Effect, Layer, Queue, Stream } from "effect";
|
|
14
|
+
import { Atom, Reactivity } from "effect/reactivity";
|
|
15
|
+
import { PageRequestFailed } from "./errors.ts";
|
|
16
|
+
import { PageOrigin } from "./http.ts";
|
|
17
|
+
import { CHANGE_EVENT, CHANGES_PATH, DEPLOYED_EVENT } from "./paths.ts";
|
|
18
|
+
|
|
19
|
+
/** The reactivity key every query from `client(Api)` carries. Invalidate it to refresh everything on screen. */
|
|
20
|
+
export const dataKey = "apps/page/data" as const;
|
|
21
|
+
|
|
22
|
+
export type ChangeEvent =
|
|
23
|
+
| { readonly _tag: "Changed" }
|
|
24
|
+
| { readonly _tag: "Deployed" }
|
|
25
|
+
| { readonly _tag: "Reconnected" };
|
|
26
|
+
|
|
27
|
+
/** The part of the browser's `EventSource` this module uses. */
|
|
28
|
+
export interface EventSourceLike {
|
|
29
|
+
readonly readyState: number;
|
|
30
|
+
addEventListener(type: string, listener: (event: unknown) => void): void;
|
|
31
|
+
close(): void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type EventSourceConstructor = new (url: string) => EventSourceLike;
|
|
35
|
+
|
|
36
|
+
/** The browser's `EventSource`. Set it only in tests. */
|
|
37
|
+
export const EventSourceImpl = Context.Reference<EventSourceConstructor | undefined>(
|
|
38
|
+
"apps/page/EventSource",
|
|
39
|
+
{
|
|
40
|
+
defaultValue: () => (globalThis as { EventSource?: EventSourceConstructor }).EventSource,
|
|
41
|
+
},
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
/** What the page does when a new version takes traffic: reload. Set it only in tests. */
|
|
45
|
+
export const OnDeployed = Context.Reference<Effect.Effect<void>>("apps/page/OnDeployed", {
|
|
46
|
+
defaultValue: () => Effect.sync(() => globalThis.location?.reload()),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const CLOSED = 2;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The events on `/_executor/changes`, while the stream is consumed. The
|
|
53
|
+
* browser reconnects by itself after a dropped connection; the stream fails
|
|
54
|
+
* only when Executor refuses it for good (the connection is closed).
|
|
55
|
+
*/
|
|
56
|
+
export const events: Stream.Stream<ChangeEvent, PageRequestFailed> = Stream.callback<
|
|
57
|
+
ChangeEvent,
|
|
58
|
+
PageRequestFailed
|
|
59
|
+
>((queue) =>
|
|
60
|
+
Effect.gen(function* () {
|
|
61
|
+
const Impl = yield* EventSourceImpl;
|
|
62
|
+
const origin = yield* PageOrigin;
|
|
63
|
+
if (Impl === undefined) {
|
|
64
|
+
return yield* new PageRequestFailed({ message: "This browser has no EventSource" });
|
|
65
|
+
}
|
|
66
|
+
yield* Effect.acquireRelease(
|
|
67
|
+
Effect.sync(() => {
|
|
68
|
+
const source = new Impl(`${origin}${CHANGES_PATH}`);
|
|
69
|
+
let opened = false;
|
|
70
|
+
source.addEventListener("open", () => {
|
|
71
|
+
if (opened) Queue.offerUnsafe(queue, { _tag: "Reconnected" });
|
|
72
|
+
opened = true;
|
|
73
|
+
});
|
|
74
|
+
source.addEventListener(CHANGE_EVENT, () => Queue.offerUnsafe(queue, { _tag: "Changed" }));
|
|
75
|
+
source.addEventListener(DEPLOYED_EVENT, () =>
|
|
76
|
+
Queue.offerUnsafe(queue, { _tag: "Deployed" }),
|
|
77
|
+
);
|
|
78
|
+
source.addEventListener("error", () => {
|
|
79
|
+
if (source.readyState === CLOSED) {
|
|
80
|
+
Queue.failCauseUnsafe(
|
|
81
|
+
queue,
|
|
82
|
+
Cause.fail(
|
|
83
|
+
new PageRequestFailed({ message: "Executor closed the page's change stream" }),
|
|
84
|
+
),
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return source;
|
|
89
|
+
}),
|
|
90
|
+
(source) => Effect.sync(() => source.close()),
|
|
91
|
+
);
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Follows {@link events} for as long as it is in use: invalidates
|
|
97
|
+
* {@link dataKey} on a change or a reconnect, and runs {@link OnDeployed} on a
|
|
98
|
+
* deploy. A page that cannot follow changes still works; it just does not
|
|
99
|
+
* refresh by itself, so a failure is logged, not raised.
|
|
100
|
+
*/
|
|
101
|
+
export const follow: Effect.Effect<void, never, Reactivity.Reactivity> = events.pipe(
|
|
102
|
+
Stream.runForEach((event) =>
|
|
103
|
+
event._tag === "Deployed"
|
|
104
|
+
? Effect.gen(function* () {
|
|
105
|
+
const onDeployed = yield* OnDeployed;
|
|
106
|
+
yield* onDeployed;
|
|
107
|
+
})
|
|
108
|
+
: Reactivity.invalidate([dataKey]),
|
|
109
|
+
),
|
|
110
|
+
Effect.catch((error) =>
|
|
111
|
+
Effect.logWarning("apps/page: not following data changes", error.message),
|
|
112
|
+
),
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
/** {@link follow} in the background, for as long as the layer is in use. */
|
|
116
|
+
export const layer: Layer.Layer<never, never, Reactivity.Reactivity> = Layer.effectDiscard(
|
|
117
|
+
Effect.forkScoped(follow),
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
const runtime = Atom.runtime(layer);
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Mounted by every query from `client(Api)`. While anything on screen is
|
|
124
|
+
* mounted, one change stream is open; when nothing is, it closes.
|
|
125
|
+
*/
|
|
126
|
+
export const changes: Atom.Atom<unknown> = runtime.atom(Effect.void);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who is signed in, in the browser. The same `Session` value the server sees,
|
|
3
|
+
* read from Executor's own `/_executor/session` on the app's address. The
|
|
4
|
+
* session cookie is the app's alone and `HttpOnly`, so the page never sees it.
|
|
5
|
+
*/
|
|
6
|
+
import { Effect, Schema } from "effect";
|
|
7
|
+
import { HttpClient, HttpClientRequest } from "effect/http";
|
|
8
|
+
import { Atom } from "effect/reactivity";
|
|
9
|
+
import { Session } from "../Session.ts";
|
|
10
|
+
import { NotSignedIn, PageRequestFailed } from "./errors.ts";
|
|
11
|
+
import { SESSION_PATH } from "./paths.ts";
|
|
12
|
+
import { pageHttpClient } from "./http.ts";
|
|
13
|
+
|
|
14
|
+
export { Session };
|
|
15
|
+
|
|
16
|
+
const decode = Schema.decodeUnknownEffect(Session);
|
|
17
|
+
|
|
18
|
+
/** The signed-in caller, or `NotSignedIn`. */
|
|
19
|
+
export const current: Effect.Effect<
|
|
20
|
+
Session,
|
|
21
|
+
NotSignedIn | PageRequestFailed,
|
|
22
|
+
HttpClient.HttpClient
|
|
23
|
+
> = Effect.gen(function* () {
|
|
24
|
+
const client = yield* HttpClient.HttpClient;
|
|
25
|
+
const response = yield* client
|
|
26
|
+
.execute(HttpClientRequest.get(SESSION_PATH))
|
|
27
|
+
.pipe(Effect.mapError((error) => new PageRequestFailed({ message: error.message })));
|
|
28
|
+
if (response.status === 401) return yield* new NotSignedIn({ message: "Nobody is signed in" });
|
|
29
|
+
if (response.status !== 200) {
|
|
30
|
+
return yield* new PageRequestFailed({
|
|
31
|
+
message: `Executor answered ${response.status} for the session`,
|
|
32
|
+
status: response.status,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const body = yield* response.json.pipe(
|
|
36
|
+
Effect.mapError((error) => new PageRequestFailed({ message: error.message })),
|
|
37
|
+
);
|
|
38
|
+
return yield* decode(body).pipe(
|
|
39
|
+
Effect.mapError(() => new PageRequestFailed({ message: "The session could not be read" })),
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/** {@link current} as an atom, for a component: `useAtomValue(session)`. */
|
|
44
|
+
export const session: Atom.Atom<
|
|
45
|
+
import("effect/reactivity").AsyncResult.AsyncResult<Session, NotSignedIn | PageRequestFailed>
|
|
46
|
+
> = Atom.make(current.pipe(Effect.provide(pageHttpClient)));
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page's typed client for the app's own backend: Effect's `AtomHttpApi`,
|
|
3
|
+
* made from the same `HttpApi` definition the server implements, so calls and
|
|
4
|
+
* results are typed from it.
|
|
5
|
+
*
|
|
6
|
+
* Two things are added, and nothing else:
|
|
7
|
+
*
|
|
8
|
+
* - Every query carries {@link dataKey}, and mounts the change stream, so it
|
|
9
|
+
* fetches again when the app's data changes.
|
|
10
|
+
* - Every mutation invalidates {@link dataKey} once it succeeds, so this tab
|
|
11
|
+
* refreshes at once instead of waiting for Executor's message.
|
|
12
|
+
*/
|
|
13
|
+
import type { HttpApi, HttpApiGroup } from "effect/http-api";
|
|
14
|
+
import { Atom, AtomHttpApi, type Reactivity } from "effect/reactivity";
|
|
15
|
+
import { changes, dataKey } from "./Changes.ts";
|
|
16
|
+
import { pageHttpClient } from "./http.ts";
|
|
17
|
+
|
|
18
|
+
/** Adds {@link dataKey} to whatever keys the caller gave. */
|
|
19
|
+
export const withDataKey = (keys: Reactivity.KeysInput | undefined): Reactivity.KeysInput => {
|
|
20
|
+
if (keys === undefined) return [dataKey];
|
|
21
|
+
if (Array.isArray(keys)) return keys.includes(dataKey) ? keys : [dataKey, ...keys];
|
|
22
|
+
const record = keys as Readonly<Record<string, ReadonlyArray<unknown>>>;
|
|
23
|
+
return dataKey in record ? record : { ...record, [dataKey]: [] };
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** A query atom that also keeps the change stream open while it is mounted. One wrapper per atom. */
|
|
27
|
+
const followed = new WeakMap<Atom.Atom<unknown>, Atom.Atom<unknown>>();
|
|
28
|
+
const follow = <A extends Atom.Atom<unknown>>(atom: A): A => {
|
|
29
|
+
let wrapped = followed.get(atom);
|
|
30
|
+
if (wrapped === undefined) {
|
|
31
|
+
wrapped = Atom.readable((get) => {
|
|
32
|
+
get.mount(changes);
|
|
33
|
+
get.subscribe(atom, (value) => get.setSelf(value));
|
|
34
|
+
return get.once(atom);
|
|
35
|
+
});
|
|
36
|
+
followed.set(atom, wrapped);
|
|
37
|
+
}
|
|
38
|
+
return wrapped as A;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** A mutation that invalidates {@link dataKey} once it succeeds. One wrapper per mutation. */
|
|
42
|
+
const invalidating = new WeakMap<Atom.Atom<unknown>, Atom.Atom<unknown>>();
|
|
43
|
+
const invalidate = <A extends Atom.Atom<unknown>>(atom: A): A => {
|
|
44
|
+
let wrapped = invalidating.get(atom);
|
|
45
|
+
if (wrapped === undefined) {
|
|
46
|
+
const inner = atom as unknown as Atom.Writable<unknown, unknown>;
|
|
47
|
+
wrapped = Atom.writable(
|
|
48
|
+
(get) => get(inner),
|
|
49
|
+
(ctx, value) => {
|
|
50
|
+
const isRequest = typeof value === "object" && value !== null;
|
|
51
|
+
ctx.set(
|
|
52
|
+
inner,
|
|
53
|
+
isRequest
|
|
54
|
+
? {
|
|
55
|
+
...(value as Record<string, unknown>),
|
|
56
|
+
reactivityKeys: withDataKey(
|
|
57
|
+
(value as { reactivityKeys?: Reactivity.KeysInput }).reactivityKeys,
|
|
58
|
+
),
|
|
59
|
+
}
|
|
60
|
+
: value,
|
|
61
|
+
);
|
|
62
|
+
},
|
|
63
|
+
(refresh) => refresh(inner),
|
|
64
|
+
);
|
|
65
|
+
invalidating.set(atom, wrapped);
|
|
66
|
+
}
|
|
67
|
+
return wrapped as A;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The typed client for an `HttpApi`:
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* const notes = client(Api)
|
|
75
|
+
* const list = notes.query("notes", "list", {})
|
|
76
|
+
* const add = notes.mutation("notes", "add")
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export const client = <const ApiId extends string, Groups extends HttpApiGroup.Constraint>(
|
|
80
|
+
api: HttpApi.HttpApi<ApiId, Groups>,
|
|
81
|
+
) => {
|
|
82
|
+
class Client extends AtomHttpApi.Service<Client>()(`apps/page/client/${api.identifier}`, {
|
|
83
|
+
api,
|
|
84
|
+
httpClient: pageHttpClient,
|
|
85
|
+
}) {}
|
|
86
|
+
const query: typeof Client.query = ((
|
|
87
|
+
group: never,
|
|
88
|
+
endpoint: never,
|
|
89
|
+
request: { reactivityKeys?: Reactivity.KeysInput },
|
|
90
|
+
) =>
|
|
91
|
+
follow(
|
|
92
|
+
Client.query(group, endpoint, {
|
|
93
|
+
...request,
|
|
94
|
+
reactivityKeys: withDataKey(request.reactivityKeys),
|
|
95
|
+
} as never),
|
|
96
|
+
)) as never;
|
|
97
|
+
const mutation: typeof Client.mutation = ((group: never, endpoint: never, options?: never) =>
|
|
98
|
+
invalidate(Client.mutation(group, endpoint, options))) as never;
|
|
99
|
+
return {
|
|
100
|
+
/** Effect's `AtomHttpApi` service, for calling the API from an Effect: `yield* notes.service`. */
|
|
101
|
+
service: Client,
|
|
102
|
+
/** The atom runtime the client runs in, for atoms of your own that call the API. */
|
|
103
|
+
runtime: Client.runtime,
|
|
104
|
+
query,
|
|
105
|
+
mutation,
|
|
106
|
+
};
|
|
107
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
/** Nobody is signed in on this page: an outsider on a public path, or a session that ended. */
|
|
4
|
+
export class NotSignedIn extends Schema.TaggedError<NotSignedIn>()("NotSignedIn", {
|
|
5
|
+
message: Schema.String,
|
|
6
|
+
}) {}
|
|
7
|
+
|
|
8
|
+
/** Executor could not be reached from the page, or answered with something the page could not read. */
|
|
9
|
+
export class PageRequestFailed extends Schema.TaggedError<PageRequestFailed>()(
|
|
10
|
+
"PageRequestFailed",
|
|
11
|
+
{
|
|
12
|
+
message: Schema.String,
|
|
13
|
+
status: Schema.optionalKey(Schema.Number),
|
|
14
|
+
},
|
|
15
|
+
) {}
|
package/src/page/http.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Context, Effect, Layer } from "effect";
|
|
2
|
+
import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";
|
|
3
|
+
|
|
4
|
+
/** The page's own origin: the app's address. Set it only in tests. */
|
|
5
|
+
export const PageOrigin = Context.Reference<string>("apps/page/PageOrigin", {
|
|
6
|
+
defaultValue: () => globalThis.location?.origin ?? "http://localhost",
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Effect's fetch client, aimed at the app's own address. The browser sends the
|
|
11
|
+
* app's session cookie with every same-origin request, and the `Origin` header
|
|
12
|
+
* Executor checks on anything but a `GET`.
|
|
13
|
+
*/
|
|
14
|
+
export const pageHttpClient: Layer.Layer<HttpClient.HttpClient> = Layer.effect(
|
|
15
|
+
HttpClient.HttpClient,
|
|
16
|
+
Effect.gen(function* () {
|
|
17
|
+
const origin = yield* PageOrigin;
|
|
18
|
+
const client = yield* HttpClient.HttpClient;
|
|
19
|
+
return HttpClient.mapRequest(client, HttpClientRequest.prependUrl(origin));
|
|
20
|
+
}),
|
|
21
|
+
).pipe(Layer.provide(FetchHttpClient.layer));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `apps/page`: what an app's page imports from Executor. All of it is Effect.
|
|
3
|
+
*
|
|
4
|
+
* - `Session`: who is signed in, the same value the server sees.
|
|
5
|
+
* - `client(Api)`: a typed client for the app's own `HttpApi`, whose queries
|
|
6
|
+
* refresh when the app's data changes.
|
|
7
|
+
* - `Changes`: the change stream underneath, for pages that want it directly.
|
|
8
|
+
* - `Accounts.link(name)`: send the person to link an account, and back.
|
|
9
|
+
*/
|
|
10
|
+
export * as Session from "./Session.ts";
|
|
11
|
+
export * as Changes from "./Changes.ts";
|
|
12
|
+
export * as Accounts from "./Accounts.ts";
|
|
13
|
+
export { client, withDataKey } from "./client.ts";
|
|
14
|
+
export { dataKey } from "./Changes.ts";
|
|
15
|
+
export { session } from "./Session.ts";
|
|
16
|
+
export { NotSignedIn, PageRequestFailed } from "./errors.ts";
|
|
17
|
+
export { PageOrigin, pageHttpClient } from "./http.ts";
|
|
18
|
+
export * from "./paths.ts";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paths on an app's own address that Executor answers itself. A request for
|
|
3
|
+
* one never reaches the app.
|
|
4
|
+
*/
|
|
5
|
+
export const HOST_PATH_PREFIX = "/_executor/" as const;
|
|
6
|
+
|
|
7
|
+
/** `GET`: the signed-in caller as JSON, or 401 when nobody is signed in. */
|
|
8
|
+
export const SESSION_PATH = "/_executor/session" as const;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* `GET`, `text/event-stream`: one `change` event each time the app's data
|
|
12
|
+
* changed, and one `deployed` event when a new version takes traffic. The
|
|
13
|
+
* events say only that something happened, never what.
|
|
14
|
+
*/
|
|
15
|
+
export const CHANGES_PATH = "/_executor/changes" as const;
|
|
16
|
+
|
|
17
|
+
/** `GET ?name=<account>&return=<path>`: starts linking the named account, then returns to `return`. */
|
|
18
|
+
export const LINK_ACCOUNT_PATH = "/_executor/accounts/link" as const;
|
|
19
|
+
|
|
20
|
+
/** The event names on {@link CHANGES_PATH}. */
|
|
21
|
+
export const CHANGE_EVENT = "change" as const;
|
|
22
|
+
export const DEPLOYED_EVENT = "deployed" as const;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as Provider from "../Provider.ts";
|
|
2
|
+
|
|
3
|
+
/** Anthropic: the same definition as today's catalog, so its id is `prv_15813b8671beed5b03d5c8809f8a4d074707fe02dfac21218dbaf472b6d1ec50`. */
|
|
4
|
+
export const Anthropic = Provider.make({
|
|
5
|
+
name: "Anthropic",
|
|
6
|
+
auth: {
|
|
7
|
+
apiKey: {
|
|
8
|
+
type: "secrets",
|
|
9
|
+
label: "API key",
|
|
10
|
+
fields: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: {
|
|
13
|
+
token: {
|
|
14
|
+
type: "string",
|
|
15
|
+
minLength: 1,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
required: ["token"],
|
|
19
|
+
additionalProperties: true,
|
|
20
|
+
$defs: {},
|
|
21
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
} as const,
|
|
25
|
+
hosts: ["api.anthropic.com"],
|
|
26
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as Provider from "../Provider.ts";
|
|
2
|
+
|
|
3
|
+
/** GitHub: the same definition as today's catalog, so its id is `prv_acf5b11676e3d9560deddc4fbb0508bbc81f6873be4bf8b1b55d89327e238635`. */
|
|
4
|
+
export const GitHub = Provider.make({
|
|
5
|
+
name: "GitHub",
|
|
6
|
+
auth: {
|
|
7
|
+
oauth: {
|
|
8
|
+
type: "oauth2",
|
|
9
|
+
tokenEndpointAuthMethod: "client_secret_post",
|
|
10
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
11
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
12
|
+
scopes: [],
|
|
13
|
+
response: {
|
|
14
|
+
type: "object",
|
|
15
|
+
properties: {
|
|
16
|
+
access_token: {
|
|
17
|
+
type: "string",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
required: ["access_token"],
|
|
21
|
+
additionalProperties: true,
|
|
22
|
+
$defs: {},
|
|
23
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
token: {
|
|
27
|
+
type: "secrets",
|
|
28
|
+
label: "Personal access token",
|
|
29
|
+
fields: {
|
|
30
|
+
type: "object",
|
|
31
|
+
properties: {
|
|
32
|
+
token: {
|
|
33
|
+
type: "string",
|
|
34
|
+
minLength: 1,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
required: ["token"],
|
|
38
|
+
additionalProperties: true,
|
|
39
|
+
$defs: {},
|
|
40
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
} as const,
|
|
44
|
+
hosts: ["api.github.com", "api.githubcopilot.com"],
|
|
45
|
+
profile: {
|
|
46
|
+
url: "https://api.github.com/user",
|
|
47
|
+
map: { externalId: "id", username: "login", avatarUrl: "avatar_url", profileUrl: "html_url" },
|
|
48
|
+
},
|
|
49
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as Provider from "../Provider.ts";
|
|
2
|
+
|
|
3
|
+
/** Gmail: the same definition as today's catalog, so its id is `prv_b570538340e0aac99cec141d53dc5258d2e8e4f929860ce795683d93172e18ff`. */
|
|
4
|
+
export const Gmail = Provider.make({
|
|
5
|
+
name: "Gmail",
|
|
6
|
+
auth: {
|
|
7
|
+
oauth: {
|
|
8
|
+
type: "oauth2",
|
|
9
|
+
authorizationParams: {
|
|
10
|
+
access_type: "offline",
|
|
11
|
+
prompt: "consent",
|
|
12
|
+
},
|
|
13
|
+
discover: "https://accounts.google.com",
|
|
14
|
+
scopes: ["https://mail.google.com/", "https://www.googleapis.com/auth/gmail.settings.basic"],
|
|
15
|
+
response: {
|
|
16
|
+
type: "object",
|
|
17
|
+
properties: {
|
|
18
|
+
access_token: {
|
|
19
|
+
type: "string",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
required: ["access_token"],
|
|
23
|
+
additionalProperties: true,
|
|
24
|
+
$defs: {},
|
|
25
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
} as const,
|
|
29
|
+
hosts: ["gmail.googleapis.com"],
|
|
30
|
+
profile: {
|
|
31
|
+
url: "https://gmail.googleapis.com/gmail/v1/users/me/profile",
|
|
32
|
+
map: { externalId: "emailAddress", email: "emailAddress" },
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/** Google Calendar: the same definition as today's catalog, so its id is `prv_0af167f65698340b50870a052d73a117e62fb1de458c954206c05b99ee880b32`. */
|
|
37
|
+
export const GoogleCalendar = Provider.make({
|
|
38
|
+
name: "Google Calendar",
|
|
39
|
+
auth: {
|
|
40
|
+
oauth: {
|
|
41
|
+
type: "oauth2",
|
|
42
|
+
authorizationParams: {
|
|
43
|
+
access_type: "offline",
|
|
44
|
+
prompt: "consent",
|
|
45
|
+
},
|
|
46
|
+
discover: "https://accounts.google.com",
|
|
47
|
+
scopes: ["https://www.googleapis.com/auth/calendar"],
|
|
48
|
+
response: {
|
|
49
|
+
type: "object",
|
|
50
|
+
properties: {
|
|
51
|
+
access_token: {
|
|
52
|
+
type: "string",
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
required: ["access_token"],
|
|
56
|
+
additionalProperties: true,
|
|
57
|
+
$defs: {},
|
|
58
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
} as const,
|
|
62
|
+
hosts: ["www.googleapis.com"],
|
|
63
|
+
profile: {
|
|
64
|
+
url: "https://www.googleapis.com/calendar/v3/users/me/calendarList/primary",
|
|
65
|
+
map: { externalId: "id", email: "id" },
|
|
66
|
+
},
|
|
67
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Layer } from "effect";
|
|
2
|
+
import { HttpClient } from "effect/http";
|
|
3
|
+
import type { Account } from "../Accounts.ts";
|
|
4
|
+
import * as Provider from "../Provider.ts";
|
|
5
|
+
|
|
6
|
+
/** OpenAI: the same definition as today's catalog, so its id is `prv_172d105ccd003723b202b2200320286309c76897936f1413eda3e55b089ef869`. */
|
|
7
|
+
export const OpenAI = Provider.make({
|
|
8
|
+
name: "OpenAI",
|
|
9
|
+
auth: {
|
|
10
|
+
apiKey: {
|
|
11
|
+
type: "secrets",
|
|
12
|
+
label: "API key",
|
|
13
|
+
fields: {
|
|
14
|
+
type: "object",
|
|
15
|
+
properties: {
|
|
16
|
+
token: {
|
|
17
|
+
type: "string",
|
|
18
|
+
minLength: 1,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
required: ["token"],
|
|
22
|
+
additionalProperties: true,
|
|
23
|
+
$defs: {},
|
|
24
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
adminKey: {
|
|
28
|
+
type: "secrets",
|
|
29
|
+
label: "Admin API key",
|
|
30
|
+
fields: {
|
|
31
|
+
type: "object",
|
|
32
|
+
properties: {
|
|
33
|
+
token: {
|
|
34
|
+
type: "string",
|
|
35
|
+
minLength: 1,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
required: ["token"],
|
|
39
|
+
additionalProperties: true,
|
|
40
|
+
$defs: {},
|
|
41
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
} as const,
|
|
45
|
+
hosts: ["api.openai.com"],
|
|
46
|
+
profile: { url: "https://api.openai.com/v1/models", map: {} },
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The HTTP client Effect's own `OpenAiClient` builds on, signed in as this
|
|
51
|
+
* account: the token goes on every request and a rejected one is reported and
|
|
52
|
+
* retried once. The app never sees the token.
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* const model = OpenAiLanguageModel.layer({ model: "gpt-5-mini" }).pipe(
|
|
56
|
+
* Layer.provide(OpenAiClient.layer({})),
|
|
57
|
+
* Layer.provide(signedIn(yield* accounts.app.openai))
|
|
58
|
+
* )
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export const signedIn = (account: Account): Layer.Layer<HttpClient.HttpClient> =>
|
|
62
|
+
Layer.succeed(HttpClient.HttpClient, account.http as unknown as HttpClient.HttpClient);
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as Provider from "../Provider.ts";
|
|
2
|
+
|
|
3
|
+
/** Slack: the same definition as today's catalog, so its id is `prv_332097ba3d781b4a83f9ac4aee1c7c27d64f40c47190ed8d6dd94df731e56a5f`. */
|
|
4
|
+
export const Slack = Provider.make({
|
|
5
|
+
name: "Slack",
|
|
6
|
+
auth: {
|
|
7
|
+
token: {
|
|
8
|
+
type: "secrets",
|
|
9
|
+
label: "Bot or user token (xoxb-/xoxp-)",
|
|
10
|
+
fields: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: {
|
|
13
|
+
token: {
|
|
14
|
+
type: "string",
|
|
15
|
+
minLength: 1,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
required: ["token"],
|
|
19
|
+
additionalProperties: true,
|
|
20
|
+
$defs: {},
|
|
21
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
oauth: {
|
|
25
|
+
type: "oauth2",
|
|
26
|
+
scopeSeparator: ",",
|
|
27
|
+
tokenEndpointAuthMethod: "client_secret_post",
|
|
28
|
+
authorizationUrl: "https://slack.com/oauth/v2/authorize",
|
|
29
|
+
tokenUrl: "https://slack.com/api/oauth.v2.access",
|
|
30
|
+
scopes: [
|
|
31
|
+
"channels:read",
|
|
32
|
+
"channels:history",
|
|
33
|
+
"channels:join",
|
|
34
|
+
"channels:manage",
|
|
35
|
+
"groups:read",
|
|
36
|
+
"groups:history",
|
|
37
|
+
"im:read",
|
|
38
|
+
"im:history",
|
|
39
|
+
"im:write",
|
|
40
|
+
"mpim:read",
|
|
41
|
+
"mpim:history",
|
|
42
|
+
"chat:write",
|
|
43
|
+
"reactions:read",
|
|
44
|
+
"reactions:write",
|
|
45
|
+
"pins:read",
|
|
46
|
+
"pins:write",
|
|
47
|
+
"files:read",
|
|
48
|
+
"files:write",
|
|
49
|
+
"users:read",
|
|
50
|
+
"users:read.email",
|
|
51
|
+
"users.profile:read",
|
|
52
|
+
"usergroups:read",
|
|
53
|
+
"team:read",
|
|
54
|
+
"emoji:read",
|
|
55
|
+
"bookmarks:read",
|
|
56
|
+
"bookmarks:write",
|
|
57
|
+
"reminders:read",
|
|
58
|
+
"reminders:write",
|
|
59
|
+
"canvases:read",
|
|
60
|
+
"canvases:write",
|
|
61
|
+
],
|
|
62
|
+
response: {
|
|
63
|
+
type: "object",
|
|
64
|
+
properties: {
|
|
65
|
+
access_token: {
|
|
66
|
+
type: "string",
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
required: ["access_token"],
|
|
70
|
+
additionalProperties: true,
|
|
71
|
+
$defs: {},
|
|
72
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
} as const,
|
|
76
|
+
hosts: ["slack.com"],
|
|
77
|
+
profile: {
|
|
78
|
+
url: "https://slack.com/api/auth.test",
|
|
79
|
+
map: { externalId: "team_id", username: "user", displayName: "team" },
|
|
80
|
+
},
|
|
81
|
+
});
|