@every-app/sdk 0.3.0-rc.11 → 0.3.0-rc.13
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 +6 -4
- package/dist/cloudflare/worker.d.ts +1 -1
- package/dist/cloudflare/worker.d.ts.map +1 -1
- package/dist/cloudflare/worker.js +1 -2
- package/dist/internal/aiDefault.d.ts +32 -76
- package/dist/internal/aiDefault.d.ts.map +1 -1
- package/dist/internal/aiDefault.js +41 -144
- package/dist/internal/appSettings.d.ts +26 -19
- package/dist/internal/appSettings.d.ts.map +1 -1
- package/dist/internal/appSettings.js +24 -31
- package/dist/internal/capabilities.d.ts +21 -8
- package/dist/internal/capabilities.d.ts.map +1 -1
- package/dist/internal/capabilities.js +2 -2
- package/dist/internal/catalog/commerce.js +1 -1
- package/dist/internal/gatewaySettings.d.ts +6 -16
- package/dist/internal/gatewaySettings.d.ts.map +1 -1
- package/dist/internal/gatewaySettings.js +5 -23
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +1 -0
- package/dist/internal/mcpOAuth.d.ts +210 -0
- package/dist/internal/mcpOAuth.d.ts.map +1 -0
- package/dist/internal/mcpOAuth.js +735 -0
- package/dist/internal/oauthBuiltIns.d.ts +1 -1
- package/dist/internal/oauthBuiltIns.js +1 -1
- package/dist/internal/oauthSpec.d.ts +1 -1
- package/dist/internal/oauthSpec.d.ts.map +1 -1
- package/dist/internal/oauthSpec.js +51 -1
- package/dist/internal/protocol.d.ts +5 -24
- package/dist/internal/protocol.d.ts.map +1 -1
- package/dist/internal/protocol.js +0 -19
- package/dist/internal/providerRegistry.d.ts +4 -3
- package/dist/internal/providerRegistry.d.ts.map +1 -1
- package/dist/internal/providerRegistry.js +11 -3
- package/dist/internal/remoteMcp.d.ts +162 -47
- package/dist/internal/remoteMcp.d.ts.map +1 -1
- package/dist/internal/remoteMcp.js +261 -124
- package/dist/internal/tools.d.ts +11 -7
- package/dist/internal/tools.d.ts.map +1 -1
- package/dist/internal/tools.js +8 -8
- package/dist/manifest.d.ts +9 -25
- package/dist/manifest.d.ts.map +1 -1
- package/dist/server/ai.d.ts +1 -93
- package/dist/server/ai.d.ts.map +1 -1
- package/dist/server/ai.js +17 -111
- package/dist/server/attribution.d.ts +1 -1
- package/dist/server/context.d.ts +12 -14
- package/dist/server/context.d.ts.map +1 -1
- package/dist/server/context.js +23 -25
- package/dist/server/everyApp.d.ts +4 -23
- package/dist/server/everyApp.d.ts.map +1 -1
- package/dist/server/everyApp.js +13 -46
- package/dist/server/gatewayFetch.d.ts +1 -1
- package/dist/server/gatewayFetch.js +1 -1
- package/dist/server/index.d.ts +3 -7
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +3 -7
- package/dist/server/integrationFetch.d.ts +1 -1
- package/dist/server/refusal.d.ts +0 -9
- package/dist/server/refusal.d.ts.map +1 -1
- package/dist/server/refusal.js +0 -22
- package/dist/server/tools.d.ts +11 -8
- package/dist/server/tools.d.ts.map +1 -1
- package/dist/server/tools.js +10 -4
- package/dist/server/toolsEndpoint.d.ts +2 -3
- package/dist/server/toolsEndpoint.d.ts.map +1 -1
- package/dist/server/toolsEndpoint.js +6 -11
- package/dist/testing/index.d.ts +2 -3
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +2 -6
- package/package.json +1 -1
- package/dist/server/aiBinding.d.ts +0 -68
- package/dist/server/aiBinding.d.ts.map +0 -1
- package/dist/server/aiBinding.js +0 -294
- package/dist/server/emailBinding.d.ts +0 -72
- package/dist/server/emailBinding.d.ts.map +0 -1
- package/dist/server/emailBinding.js +0 -124
- package/dist/server/fromMcpTools.d.ts +0 -89
- package/dist/server/fromMcpTools.d.ts.map +0 -1
- package/dist/server/fromMcpTools.js +0 -192
package/dist/manifest.d.ts
CHANGED
|
@@ -37,6 +37,13 @@ export interface EveryAppPublicRoute {
|
|
|
37
37
|
readonly path: string;
|
|
38
38
|
/** The methods it answers; `["GET"]` when left out. */
|
|
39
39
|
readonly methods?: readonly string[];
|
|
40
|
+
/**
|
|
41
|
+
* A bearer route: a native app or a script reaches it with its Gateway
|
|
42
|
+
* token only, on every method (no `methods`). The Gateway answers 401 to
|
|
43
|
+
* a request carrying its session cookie there, and Cloudflare Access
|
|
44
|
+
* lets it through like any public route.
|
|
45
|
+
*/
|
|
46
|
+
readonly bearer?: true;
|
|
40
47
|
}
|
|
41
48
|
/** A Durable Object or Workflow class: its binding, the class, and the helper Worker that defines it. */
|
|
42
49
|
export interface EveryAppClassResource {
|
|
@@ -151,7 +158,7 @@ export interface EveryAppSettingEntry {
|
|
|
151
158
|
/** One of the app's own secrets, with its need. */
|
|
152
159
|
export interface EveryAppSecretEntry extends EveryAppSettingNeed {
|
|
153
160
|
readonly name: string;
|
|
154
|
-
/** Its guide in the
|
|
161
|
+
/** Its setup guide, a path in the app (`"docs/setup/main-secret.md"`). */
|
|
155
162
|
readonly setup?: string;
|
|
156
163
|
}
|
|
157
164
|
/** `everyapp.config.ts`. */
|
|
@@ -163,8 +170,6 @@ export interface EveryAppManifest {
|
|
|
163
170
|
readonly description?: string;
|
|
164
171
|
/** The path of an SVG the app serves (`"/everyapp-icon.svg"`). */
|
|
165
172
|
readonly icon?: string;
|
|
166
|
-
/** Legacy: the entry comes from `cloudflare.config.ts`. */
|
|
167
|
-
readonly main?: string;
|
|
168
173
|
/** YYYY-MM-DD. */
|
|
169
174
|
readonly compatibilityDate?: string;
|
|
170
175
|
readonly resources?: EveryAppResources;
|
|
@@ -187,18 +192,6 @@ export interface EveryAppManifest {
|
|
|
187
192
|
* OG image): path patterns, GET and HEAD, never Worker code.
|
|
188
193
|
*/
|
|
189
194
|
readonly publicAssets?: readonly string[];
|
|
190
|
-
/**
|
|
191
|
-
* Routes a bearer client (a native app, a script with a personal token)
|
|
192
|
-
* reaches with its token only: `paths` in `public`'s glob syntax, every
|
|
193
|
-
* method, and `why` the app needs them, shown to the operator. The
|
|
194
|
-
* Gateway answers 401 to a request carrying its session cookie there,
|
|
195
|
-
* and `everyapp access on` lets these paths through Cloudflare Access.
|
|
196
|
-
* Default: none.
|
|
197
|
-
*/
|
|
198
|
-
readonly bearerRoutes?: {
|
|
199
|
-
readonly paths: readonly string[];
|
|
200
|
-
readonly why: string;
|
|
201
|
-
};
|
|
202
195
|
/** AI providers the Gateway calls for the app, by id or with their need. */
|
|
203
196
|
readonly providers?: readonly (string | (EveryAppSettingNeed & {
|
|
204
197
|
readonly id: string;
|
|
@@ -216,7 +209,7 @@ export interface EveryAppManifest {
|
|
|
216
209
|
readonly models?: readonly string[];
|
|
217
210
|
/** OpenAI API paths beyond inference (`"/v1/files"`). */
|
|
218
211
|
readonly routes?: readonly string[];
|
|
219
|
-
/** The app takes the
|
|
212
|
+
/** The app takes the workspace's default chat model (`/api/ai/default`, `aiBaseUrl()`). */
|
|
220
213
|
readonly chat?: boolean | EveryAppSettingNeed;
|
|
221
214
|
};
|
|
222
215
|
/** `inbound: true`: the Worker exports an `email()` handler. */
|
|
@@ -225,14 +218,10 @@ export interface EveryAppManifest {
|
|
|
225
218
|
};
|
|
226
219
|
/** Who can open the app once registered; `"admins"` by default. */
|
|
227
220
|
readonly access?: "everyone" | "admins";
|
|
228
|
-
readonly serverFnGuard?: boolean;
|
|
229
|
-
readonly serverFnBase?: string;
|
|
230
221
|
/** Shell command that builds the app; `cf build` by default. */
|
|
231
222
|
readonly build?: string;
|
|
232
223
|
/** Shell command `everyapp dev` starts; it must listen on PORT. */
|
|
233
224
|
readonly dev?: string;
|
|
234
|
-
/** Legacy: the port comes from PORT. */
|
|
235
|
-
readonly devPort?: number;
|
|
236
225
|
/** Dependency install command; false skips it. */
|
|
237
226
|
readonly install?: false | string;
|
|
238
227
|
readonly migrations?: {
|
|
@@ -242,11 +231,6 @@ export interface EveryAppManifest {
|
|
|
242
231
|
readonly config?: string;
|
|
243
232
|
readonly binding?: string;
|
|
244
233
|
};
|
|
245
|
-
/** Who answers `/mcp` on the app's own host, and why it needs to. */
|
|
246
|
-
readonly mcp?: {
|
|
247
|
-
readonly by: "gateway" | "app";
|
|
248
|
-
readonly why: string;
|
|
249
|
-
};
|
|
250
234
|
/**
|
|
251
235
|
* The Gateway events the app receives at `everyApp(handler, { events: {
|
|
252
236
|
* on } })`: types or patterns from `member.*` (but `member.password_reset`),
|
package/dist/manifest.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,yFAAyF;AACzF,MAAM,WAAW,mBAAmB;IAClC,yEAAyE;IACzE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,kEAAkE;IAClE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,2EAA2E;IAC3E,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,4DAA4D;IAC5D,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,oDAAoD;AACpD,MAAM,WAAW,mBAAmB;IAClC,gEAAgE;IAChE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,uDAAuD;IACvD,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,yFAAyF;AACzF,MAAM,WAAW,mBAAmB;IAClC,yEAAyE;IACzE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,kEAAkE;IAClE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,2EAA2E;IAC3E,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,4DAA4D;IAC5D,QAAQ,CAAC,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,CAAA;KAAE,CAAC;IAChD,mEAAmE;IACnE,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;IACxC,gEAAgE;IAChE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,mEAAmE;IACnE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,kDAAkD;IAClD,QAAQ,CAAC,OAAO,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAClC,QAAQ,CAAC,UAAU,CAAC,EAAE;QACpB,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;QACjD,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,YAAY,CAAC;QAC3C,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;KAC3B,CAAC;IACF;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE;QAChB,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;QACtC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,CAAC,CAAC,SAAS,gBAAgB,EAC7D,QAAQ,EAAE,CAAC,GACV,CAAC,CAEH"}
|
package/dist/server/ai.d.ts
CHANGED
|
@@ -1,95 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `ai()`: the Gateway's default chat model for an app that needs "a model"
|
|
3
|
-
* rather than one provider (docs/design/2026-10-model-providers.md). The
|
|
4
|
-
* manifest says `ai: { chat: true }` (or `{ chat: { why } }`); the Gateway's
|
|
5
|
-
* operator decides which provider and model that is (`everyapp ai
|
|
6
|
-
* default`, else OpenRouter → Workers AI → OpenAI → …, the first with its
|
|
7
|
-
* key set), and the app never names either: it sends OpenAI-shaped chat
|
|
8
|
-
* completions (and embeddings) to `/api/ai/default/v1/…` with `model:
|
|
9
|
-
* "default"` or no model at all, and the Gateway fills the model in.
|
|
10
|
-
*
|
|
11
|
-
* An OpenAI client takes `baseURL` and `fetch` as they are:
|
|
12
|
-
*
|
|
13
|
-
* const { baseURL, fetch, model } = ai({ env, for: request });
|
|
14
|
-
* const client = new OpenAI({ baseURL, fetch, apiKey: "gateway-managed" });
|
|
15
|
-
* await client.chat.completions.create({ model, messages });
|
|
16
|
-
*
|
|
17
|
-
* In local development with no Gateway, the developer's own key in
|
|
18
|
-
* `.dev.vars` decides the provider by the same order (createGatewayFetch's
|
|
19
|
-
* fallback). An app that needs one provider in particular keeps listing it
|
|
20
|
-
* under `providers` and calling `/api/ai/<provider>/…`.
|
|
21
|
-
*/
|
|
22
|
-
import { AI_DEFAULT_MODEL } from "../internal/index.js";
|
|
23
|
-
import { type GatewayCallFor } from "./attribution.js";
|
|
24
|
-
import { type CreateGatewayFetchOptions } from "./gatewayFetch.js";
|
|
25
|
-
import type { SetupInfo } from "./refusal.js";
|
|
26
|
-
export interface AiClient {
|
|
27
|
-
/** `http://every-app-gateway.internal/api/ai/default/v1`: an OpenAI client's base URL. */
|
|
28
|
-
baseURL: string;
|
|
29
|
-
/** The fetch that reaches the Gateway (or, in dev, the provider directly). */
|
|
30
|
-
fetch: typeof fetch;
|
|
31
|
-
/** The model name that means "whatever the Gateway's default is": `default`. */
|
|
32
|
-
model: typeof AI_DEFAULT_MODEL;
|
|
33
|
-
/** The default route's chat completions URL, for a plain `fetch`. */
|
|
34
|
-
chatCompletionsUrl: string;
|
|
35
|
-
/** The default route's embeddings URL, for a plain `fetch`. */
|
|
36
|
-
embeddingsUrl: string;
|
|
37
|
-
}
|
|
38
|
-
/** The base URL of the default route, as the SDK and the docs name it. */
|
|
39
|
-
export declare const AI_DEFAULT_BASE_URL = "http://every-app-gateway.internal/api/ai/default/v1";
|
|
40
|
-
/**
|
|
41
|
-
* The Gateway's default chat model as a client: a base URL, a fetch and
|
|
42
|
-
* the model name to send. Throws `ConfigurationError` where
|
|
43
|
-
* `createGatewayFetch` does (no binding and no dev key) and
|
|
44
|
-
* `AttributionError` where a shared app's call says nobody's.
|
|
45
|
-
*/
|
|
46
|
-
export declare function ai(options: CreateGatewayFetchOptions & {
|
|
47
|
-
optional: true;
|
|
48
|
-
}): AiClient | null;
|
|
49
|
-
export declare function ai(options: CreateGatewayFetchOptions): AiClient;
|
|
50
|
-
/** Whether model calls to a provider (or the default) would go through. */
|
|
51
|
-
export interface AiStatus extends SetupInfo {
|
|
52
|
-
/** The id asked about: `default`, or a provider's (`openrouter`, `workers-ai`, …). */
|
|
53
|
-
provider: string;
|
|
54
|
-
/** The manifest asks for it: `ai.chat` for `default`, else `providers`. */
|
|
55
|
-
requested: boolean;
|
|
56
|
-
/** The Gateway (in local dev, `.dev.vars`) holds every setting it needs. */
|
|
57
|
-
configured: boolean;
|
|
58
|
-
/** Calls would go through. */
|
|
59
|
-
ready: boolean;
|
|
60
|
-
/**
|
|
61
|
-
* For `default`: the provider and model calls go to now, or null while
|
|
62
|
-
* none is configured. Null for a named provider.
|
|
63
|
-
*/
|
|
64
|
-
resolved: {
|
|
65
|
-
provider: string;
|
|
66
|
-
label: string;
|
|
67
|
-
model: string;
|
|
68
|
-
} | null;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Whether the app can use a model right now, without calling one: gate
|
|
72
|
-
* an AI feature and show `setup` ("A chat model isn't set up on this
|
|
73
|
-
* Gateway: it needs OPENROUTER_API_KEY. An admin runs: pnpm everyapp
|
|
74
|
-
* configure inbox") up front instead of failing mid-task. `provider`
|
|
75
|
-
* defaults to `default`, the Gateway's default model (`ai: { chat: true }`);
|
|
76
|
-
* name one the manifest lists under `providers` to ask about it instead.
|
|
77
|
-
* The Gateway owns the wording: show `setup` and `command` as they are.
|
|
78
|
-
*
|
|
79
|
-
* Over the binding it sends `GET /api/ai/<provider>`; in local dev it
|
|
80
|
-
* answers from `.dev.vars` by the same rule `createGatewayFetch()` uses.
|
|
81
|
-
*/
|
|
82
|
-
export declare function aiStatus({ env, provider, for: explicitTarget, }: {
|
|
83
|
-
env: object;
|
|
84
|
-
provider?: string;
|
|
85
|
-
/**
|
|
86
|
-
* Whom the status is for: the default resolves on that organization's
|
|
87
|
-
* choice (`everyapp ai default`). Left out, the request `everyApp()` is
|
|
88
|
-
* serving or the organization `withOrganization()` named, as on every
|
|
89
|
-
* call.
|
|
90
|
-
*/
|
|
91
|
-
for?: GatewayCallFor;
|
|
92
|
-
}): Promise<AiStatus>;
|
|
93
1
|
/**
|
|
94
2
|
* A provider's root behind the Gateway, `http://every-app-gateway.internal/api/ai/<provider>`:
|
|
95
3
|
* join the provider's own paths onto it (`/api/v1/chat/completions` for
|
|
@@ -100,7 +8,7 @@ export declare function providerBaseUrl(provider: string): string;
|
|
|
100
8
|
/**
|
|
101
9
|
* The OpenAI-compatible base URL of `provider` behind the Gateway, for an
|
|
102
10
|
* OpenAI client's `baseURL` (with `fetch: createGatewayFetch(...)`):
|
|
103
|
-
* `default` (the default
|
|
11
|
+
* `default` (the default, and what it is when left out) is
|
|
104
12
|
* `…/api/ai/default/v1`; a catalog provider's is its root and the prefix
|
|
105
13
|
* of its chat route (`…/api/ai/openrouter/api/v1`, `…/api/ai/workers-ai/v1`,
|
|
106
14
|
* `…/api/ai/openai/v1`). Throws `ConfigurationError` for a provider with
|
package/dist/server/ai.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai.d.ts","sourceRoot":"","sources":["../../src/server/ai.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ai.d.ts","sourceRoot":"","sources":["../../src/server/ai.ts"],"names":[],"mappings":"AA2BA;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAExD;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,QAAQ,GAAE,MAA4B,GAAG,MAAM,CAaxE"}
|
package/dist/server/ai.js
CHANGED
|
@@ -1,116 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* default
|
|
7
|
-
*
|
|
8
|
-
* completions (and embeddings) to `/api/ai/default/v1/…` with `model:
|
|
9
|
-
* "default"` or no model at all, and the Gateway fills the model in.
|
|
2
|
+
* Where an app's model calls go behind the Gateway, for an OpenAI client's
|
|
3
|
+
* `baseURL` or a plain `fetch`, both sent with `createGatewayFetch()`:
|
|
4
|
+
* `aiBaseUrl("openai")` (a provider's OpenAI-compatible base), `aiBaseUrl()`
|
|
5
|
+
* (the Gateway's default model, `ai: { chat: true }`: send `model:
|
|
6
|
+
* "default"` or none and the Gateway fills in the workspace's model), and
|
|
7
|
+
* `providerBaseUrl("openai")` (a provider's root, for its own paths).
|
|
10
8
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* In local development with no Gateway, the developer's own key in
|
|
18
|
-
* `.dev.vars` decides the provider by the same order (createGatewayFetch's
|
|
19
|
-
* fallback). An app that needs one provider in particular keeps listing it
|
|
20
|
-
* under `providers` and calling `/api/ai/<provider>/…`.
|
|
9
|
+
* const client = new OpenAI({
|
|
10
|
+
* baseURL: aiBaseUrl(),
|
|
11
|
+
* fetch: createGatewayFetch({ env }),
|
|
12
|
+
* apiKey: "gateway-managed",
|
|
13
|
+
* });
|
|
14
|
+
* await client.chat.completions.create({ model: "default", messages });
|
|
21
15
|
*/
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export const AI_DEFAULT_BASE_URL = `${BINDING_ORIGIN}/api/ai/${AI_DEFAULT_PROVIDER}/v1`;
|
|
27
|
-
export function ai(options) {
|
|
28
|
-
const fetch = createGatewayFetch(options);
|
|
29
|
-
if (!fetch)
|
|
30
|
-
return null;
|
|
31
|
-
return {
|
|
32
|
-
baseURL: AI_DEFAULT_BASE_URL,
|
|
33
|
-
fetch,
|
|
34
|
-
model: AI_DEFAULT_MODEL,
|
|
35
|
-
chatCompletionsUrl: `${AI_DEFAULT_BASE_URL}/chat/completions`,
|
|
36
|
-
embeddingsUrl: `${AI_DEFAULT_BASE_URL}/embeddings`,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Whether the app can use a model right now, without calling one: gate
|
|
41
|
-
* an AI feature and show `setup` ("A chat model isn't set up on this
|
|
42
|
-
* Gateway: it needs OPENROUTER_API_KEY. An admin runs: pnpm everyapp
|
|
43
|
-
* configure inbox") up front instead of failing mid-task. `provider`
|
|
44
|
-
* defaults to `default`, the Gateway's default model (`ai: { chat: true }`);
|
|
45
|
-
* name one the manifest lists under `providers` to ask about it instead.
|
|
46
|
-
* The Gateway owns the wording: show `setup` and `command` as they are.
|
|
47
|
-
*
|
|
48
|
-
* Over the binding it sends `GET /api/ai/<provider>`; in local dev it
|
|
49
|
-
* answers from `.dev.vars` by the same rule `createGatewayFetch()` uses.
|
|
50
|
-
*/
|
|
51
|
-
export async function aiStatus({ env, provider = AI_DEFAULT_PROVIDER, for: explicitTarget, }) {
|
|
52
|
-
const target = attributionFor(env, explicitTarget, "aiStatus");
|
|
53
|
-
const values = env;
|
|
54
|
-
const binding = gatewayBinding(env);
|
|
55
|
-
const unavailable = {
|
|
56
|
-
provider,
|
|
57
|
-
requested: false,
|
|
58
|
-
configured: false,
|
|
59
|
-
ready: false,
|
|
60
|
-
resolved: null,
|
|
61
|
-
settings: [],
|
|
62
|
-
setup: null,
|
|
63
|
-
command: null,
|
|
64
|
-
};
|
|
65
|
-
if (binding && typeof binding.fetch === "function") {
|
|
66
|
-
const headers = new Headers();
|
|
67
|
-
if (target !== undefined)
|
|
68
|
-
applyAttribution(headers, target);
|
|
69
|
-
const response = await binding.fetch(`${BINDING_ORIGIN}/api/ai/${encodeURIComponent(provider)}`, { headers });
|
|
70
|
-
if (!response.ok)
|
|
71
|
-
return unavailable;
|
|
72
|
-
const body = (await response.json());
|
|
73
|
-
return {
|
|
74
|
-
...unavailable,
|
|
75
|
-
...body,
|
|
76
|
-
provider,
|
|
77
|
-
settings: Array.isArray(body.settings) ? body.settings : [],
|
|
78
|
-
setup: typeof body.setup === "string" ? body.setup : null,
|
|
79
|
-
command: typeof body.command === "string" ? body.command : null,
|
|
80
|
-
resolved: body.resolved ?? null,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
if (!values["EVERYAPP_DEV"])
|
|
84
|
-
return unavailable;
|
|
85
|
-
const isSet = (name) => typeof values[name] === "string" && values[name].trim() !== "";
|
|
86
|
-
const dev = (label, settings, configured, resolved, also = "") => ({
|
|
87
|
-
provider,
|
|
88
|
-
requested: true,
|
|
89
|
-
configured,
|
|
90
|
-
ready: configured,
|
|
91
|
-
resolved,
|
|
92
|
-
settings: configured ? [] : [...settings],
|
|
93
|
-
setup: configured
|
|
94
|
-
? null
|
|
95
|
-
: `${label} isn't set up for local development: set ${settings.join(" and ")}${also} in .dev.vars.`,
|
|
96
|
-
command: null,
|
|
97
|
-
});
|
|
98
|
-
if (provider === AI_DEFAULT_PROVIDER) {
|
|
99
|
-
const resolution = resolveAiDefault({ provider: null, isSet });
|
|
100
|
-
return dev("A chat model", resolution.settings, resolution.configured, resolution.configured
|
|
101
|
-
? {
|
|
102
|
-
provider: resolution.provider,
|
|
103
|
-
label: resolution.label,
|
|
104
|
-
model: resolution.model,
|
|
105
|
-
}
|
|
106
|
-
: null, " (or another model provider's key)");
|
|
107
|
-
}
|
|
108
|
-
const spec = devAiProvider(provider);
|
|
109
|
-
if (!spec)
|
|
110
|
-
return unavailable;
|
|
111
|
-
const settings = aiProviderSettings(spec);
|
|
112
|
-
return dev(CATALOG.get(provider)?.label ?? provider, settings, settings.every(isSet), null);
|
|
113
|
-
}
|
|
16
|
+
import { AI_DEFAULT_PROVIDER, CATALOG, ConfigurationError, } from "../internal/index.js";
|
|
17
|
+
import { BINDING_ORIGIN } from "./gatewayFetch.js";
|
|
18
|
+
/** The base URL of the default route, `…/api/ai/default/v1`. */
|
|
19
|
+
const AI_DEFAULT_BASE_URL = `${BINDING_ORIGIN}/api/ai/${AI_DEFAULT_PROVIDER}/v1`;
|
|
114
20
|
const CHAT_COMPLETIONS = "/chat/completions";
|
|
115
21
|
/**
|
|
116
22
|
* A provider's root behind the Gateway, `http://every-app-gateway.internal/api/ai/<provider>`:
|
|
@@ -124,7 +30,7 @@ export function providerBaseUrl(provider) {
|
|
|
124
30
|
/**
|
|
125
31
|
* The OpenAI-compatible base URL of `provider` behind the Gateway, for an
|
|
126
32
|
* OpenAI client's `baseURL` (with `fetch: createGatewayFetch(...)`):
|
|
127
|
-
* `default` (the default
|
|
33
|
+
* `default` (the default, and what it is when left out) is
|
|
128
34
|
* `…/api/ai/default/v1`; a catalog provider's is its root and the prefix
|
|
129
35
|
* of its chat route (`…/api/ai/openrouter/api/v1`, `…/api/ai/workers-ai/v1`,
|
|
130
36
|
* `…/api/ai/openai/v1`). Throws `ConfigurationError` for a provider with
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Whom a call through the gateway is for, which decides the organization
|
|
3
3
|
* it counts against. Left out, it comes from the request context: the
|
|
4
4
|
* request `everyApp()` is serving (its person, while the identity is good),
|
|
5
|
-
* or the organization
|
|
5
|
+
* or the organization the SDK's event delivery runs under. Given explicitly:
|
|
6
6
|
*
|
|
7
7
|
* - the inbound `Request`: its person, by the identity the gateway put on
|
|
8
8
|
* it (forwarded as is);
|
package/dist/server/context.d.ts
CHANGED
|
@@ -14,9 +14,9 @@ export interface ServedRequest {
|
|
|
14
14
|
*/
|
|
15
15
|
export declare const IDENTITY_EXPIRY_MARGIN_MS = 15000;
|
|
16
16
|
/**
|
|
17
|
-
* Code `request_context_missing`:
|
|
18
|
-
*
|
|
19
|
-
* `
|
|
17
|
+
* Code `request_context_missing`: a Gateway call with no `for`, outside
|
|
18
|
+
* any request `everyApp()` serves. Work no request started passes
|
|
19
|
+
* `for: { background: true }`.
|
|
20
20
|
*/
|
|
21
21
|
export declare class RequestContextError extends Error {
|
|
22
22
|
readonly code = "request_context_missing";
|
|
@@ -35,20 +35,18 @@ export declare function serveRequest<T>(served: ServedRequest, fn: () => T): T;
|
|
|
35
35
|
/**
|
|
36
36
|
* Run `fn` as `organizationId`'s background work: every Gateway call made
|
|
37
37
|
* inside it (and in what it awaits or schedules) is that organization's,
|
|
38
|
-
* with no person behind it.
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* organization's own request, the person stays attributed while their
|
|
44
|
-
* identity is good.
|
|
38
|
+
* with no person behind it. The SDK's event delivery (eventsEndpoint.ts)
|
|
39
|
+
* runs the app's `events.on` under it; apps pass `for` instead. Inside a
|
|
40
|
+
* request another organization's person is driving, it throws
|
|
41
|
+
* {@link OrganizationMismatchError}; inside that organization's own
|
|
42
|
+
* request, the person stays attributed while their identity is good.
|
|
45
43
|
*/
|
|
46
44
|
export declare function withOrganization<T>(organizationId: string, fn: () => T): T;
|
|
47
45
|
/**
|
|
48
|
-
* The verified user of the request being served
|
|
49
|
-
* `null` on a public route
|
|
50
|
-
*
|
|
51
|
-
*
|
|
46
|
+
* The verified user of the request being served (`everyApp()` reads it to
|
|
47
|
+
* reuse one verification): an `EveryAppUser`, or `null` on a public route
|
|
48
|
+
* and inside `withOrganization()`'s background work. Throws
|
|
49
|
+
* {@link RequestContextError} outside both.
|
|
52
50
|
*/
|
|
53
51
|
export declare function currentUser(): EveryAppUser | null;
|
|
54
52
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/server/context.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,2DAA2D;AAC3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,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAErE;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,cAAc,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAc1E;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,IAAI,YAAY,GAAG,IAAI,CAQjD;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,EACZ,GAAG,GAAE,MAAmB,GACvB,OAAO,GAAG;IAAE,UAAU,EAAE,IAAI,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAoBrE"}
|
package/dist/server/context.js
CHANGED
|
@@ -4,17 +4,17 @@
|
|
|
4
4
|
* `AsyncLocalStorage`, which every Every App Worker has (`nodejs_compat`).
|
|
5
5
|
*
|
|
6
6
|
* `everyApp()` opens it around the handler and around each tool call, with
|
|
7
|
-
* the verified user and the request the Gateway forwarded.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* is attributed to that person without a `for`.
|
|
7
|
+
* the verified user and the request the Gateway forwarded. Every call back
|
|
8
|
+
* to the Gateway made inside it (`integrationFetch`, `sendEmail`, `emit`,
|
|
9
|
+
* ...) is attributed to that person without a `for`.
|
|
11
10
|
*
|
|
12
11
|
* Work no request started (a cron, a Workflow step, a queue consumer, a
|
|
13
|
-
* Durable Object alarm) has no context of its own: it
|
|
14
|
-
* `
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
12
|
+
* Durable Object alarm) has no context of its own: it says whom each call
|
|
13
|
+
* is for, `for: { background: true }` (a shared app's Worker adds the
|
|
14
|
+
* `organizationId`). The SDK's own event delivery runs its handler under
|
|
15
|
+
* `withOrganization()`, which does the same for every call inside it. A
|
|
16
|
+
* Gateway call with neither is refused before it is made
|
|
17
|
+
* ({@link RequestContextError}): the SDK never acts as nobody.
|
|
18
18
|
*/
|
|
19
19
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
20
20
|
const scopes = new AsyncLocalStorage();
|
|
@@ -25,9 +25,9 @@ const scopes = new AsyncLocalStorage();
|
|
|
25
25
|
*/
|
|
26
26
|
export const IDENTITY_EXPIRY_MARGIN_MS = 15_000;
|
|
27
27
|
/**
|
|
28
|
-
* Code `request_context_missing`:
|
|
29
|
-
*
|
|
30
|
-
* `
|
|
28
|
+
* Code `request_context_missing`: a Gateway call with no `for`, outside
|
|
29
|
+
* any request `everyApp()` serves. Work no request started passes
|
|
30
|
+
* `for: { background: true }`.
|
|
31
31
|
*/
|
|
32
32
|
export class RequestContextError extends Error {
|
|
33
33
|
code = "request_context_missing";
|
|
@@ -54,13 +54,11 @@ export function serveRequest(served, fn) {
|
|
|
54
54
|
/**
|
|
55
55
|
* Run `fn` as `organizationId`'s background work: every Gateway call made
|
|
56
56
|
* inside it (and in what it awaits or schedules) is that organization's,
|
|
57
|
-
* with no person behind it.
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* organization's own request, the person stays attributed while their
|
|
63
|
-
* identity is good.
|
|
57
|
+
* with no person behind it. The SDK's event delivery (eventsEndpoint.ts)
|
|
58
|
+
* runs the app's `events.on` under it; apps pass `for` instead. Inside a
|
|
59
|
+
* request another organization's person is driving, it throws
|
|
60
|
+
* {@link OrganizationMismatchError}; inside that organization's own
|
|
61
|
+
* request, the person stays attributed while their identity is good.
|
|
64
62
|
*/
|
|
65
63
|
export function withOrganization(organizationId, fn) {
|
|
66
64
|
if (typeof organizationId !== "string" || organizationId.trim() === "") {
|
|
@@ -74,15 +72,15 @@ export function withOrganization(organizationId, fn) {
|
|
|
74
72
|
return scopes.run({ ...parent, organizationId }, fn);
|
|
75
73
|
}
|
|
76
74
|
/**
|
|
77
|
-
* The verified user of the request being served
|
|
78
|
-
* `null` on a public route
|
|
79
|
-
*
|
|
80
|
-
*
|
|
75
|
+
* The verified user of the request being served (`everyApp()` reads it to
|
|
76
|
+
* reuse one verification): an `EveryAppUser`, or `null` on a public route
|
|
77
|
+
* and inside `withOrganization()`'s background work. Throws
|
|
78
|
+
* {@link RequestContextError} outside both.
|
|
81
79
|
*/
|
|
82
80
|
export function currentUser() {
|
|
83
81
|
const scope = scopes.getStore();
|
|
84
82
|
if (!scope) {
|
|
85
|
-
throw new RequestContextError("currentUser() was called outside a request everyApp() serves
|
|
83
|
+
throw new RequestContextError("currentUser() was called outside a request everyApp() serves: there is no user here.");
|
|
86
84
|
}
|
|
87
85
|
return scope.served?.user ?? null;
|
|
88
86
|
}
|
|
@@ -99,7 +97,7 @@ export function currentUser() {
|
|
|
99
97
|
export function attributionFromContext(what, now = Date.now()) {
|
|
100
98
|
const scope = scopes.getStore();
|
|
101
99
|
if (!scope) {
|
|
102
|
-
throw new RequestContextError(`${what} was called with no \`for\`, outside a request everyApp() serves
|
|
100
|
+
throw new RequestContextError(`${what} was called with no \`for\`, outside a request everyApp() serves: the call would be nobody's. Pass for: request, or for: { background: true } for work no request started (a cron, a Workflow step, a queue consumer).`);
|
|
103
101
|
}
|
|
104
102
|
const served = scope.served;
|
|
105
103
|
if (served?.user) {
|
|
@@ -17,19 +17,18 @@
|
|
|
17
17
|
* event sink's deliveries (`/__everyapp/events`) for `events: { on }`.
|
|
18
18
|
*
|
|
19
19
|
* Around the handler and around each tool call it opens the request
|
|
20
|
-
* context (context.ts):
|
|
21
|
-
*
|
|
22
|
-
* `for`. A deployed Worker is pinned to its organization
|
|
20
|
+
* context (context.ts): every call back to the Gateway is attributed to
|
|
21
|
+
* the request without a `for`. A deployed Worker is pinned to its organization
|
|
23
22
|
* (`EVERY_APP_ORG_ID`), and an identity for any other is refused on both
|
|
24
23
|
* paths. The response leaves without `Set-Cookie`: the perimeter strips
|
|
25
24
|
* every `Cookie` before a request reaches the app, so a cookie the app's
|
|
26
25
|
* framework sets could never come back, and one named like the Gateway's
|
|
27
26
|
* session cookie would lock the person out of the app host.
|
|
28
27
|
*/
|
|
29
|
-
import { ConfigurationError,
|
|
28
|
+
import { ConfigurationError, isAdmin, type EveryAppUser, type IdentityResult, type OrgRole } from "../internal/index.js";
|
|
30
29
|
import type { ToolSet } from "./tools.js";
|
|
31
30
|
import { type AppEventsOptions } from "./eventsEndpoint.js";
|
|
32
|
-
export { ConfigurationError,
|
|
31
|
+
export { ConfigurationError, isAdmin };
|
|
33
32
|
export type { EveryAppUser, IdentityResult, OrgRole };
|
|
34
33
|
/**
|
|
35
34
|
* The runtime's `ExecutionContext`, which `everyApp()` passes to the handler
|
|
@@ -38,10 +37,6 @@ export type { EveryAppUser, IdentityResult, OrgRole };
|
|
|
38
37
|
* `fetch` themselves pass a stub cast to it.
|
|
39
38
|
*/
|
|
40
39
|
export type ExecutionContextLike = ExecutionContext;
|
|
41
|
-
export interface EveryAppManifestLike {
|
|
42
|
-
id: string;
|
|
43
|
-
[key: string]: unknown;
|
|
44
|
-
}
|
|
45
40
|
export interface EveryAppOptions<TEnv = Record<string, unknown>> {
|
|
46
41
|
/** Optional expected issuer (gateway URL). Defaults to env.EVERYAPP_IDENTITY_ISSUER when set. */
|
|
47
42
|
issuer?: string;
|
|
@@ -83,7 +78,6 @@ interface EveryAppExport<TEnv, TCtx extends ExecutionContextLike> {
|
|
|
83
78
|
* (a framework that hands out headers alone needs no made-up Request).
|
|
84
79
|
* Answers from the request context or the per-request cache first, then
|
|
85
80
|
* verifies the identity headers from the audience and public keys in env.
|
|
86
|
-
* Inside a handler `everyApp()` serves, `currentUser()` is the shorter way.
|
|
87
81
|
*/
|
|
88
82
|
export declare function getEveryAppUser(request: Request | Headers, env: object): Promise<EveryAppUser | null>;
|
|
89
83
|
/**
|
|
@@ -91,20 +85,7 @@ export declare function getEveryAppUser(request: Request | Headers, env: object)
|
|
|
91
85
|
* everyApp() when the request is public or unauthenticated.
|
|
92
86
|
*/
|
|
93
87
|
export declare function requireEveryAppUser(request: Request | Headers, env: object): Promise<EveryAppUser>;
|
|
94
|
-
/**
|
|
95
|
-
* The user of the request being served (`currentUser()`), or throw the
|
|
96
|
-
* same 401 JSON Response as `requireEveryAppUser()` on a public route.
|
|
97
|
-
* Outside a request (`withOrganization()` work, a handler not under
|
|
98
|
-
* `everyApp()`) it throws `RequestContextError`, as `currentUser()` does.
|
|
99
|
-
*/
|
|
100
|
-
export declare function requireCurrentUser(): EveryAppUser;
|
|
101
88
|
export declare function hasScope(user: EveryAppUser, scope: string): boolean;
|
|
102
89
|
/** Wrap a Worker fetch handler with Every App identity verification. */
|
|
103
90
|
export declare function everyApp<TEnv = Record<string, unknown>, TCtx extends ExecutionContextLike = ExecutionContext>(handler: EveryAppHandler<TEnv, TCtx>, options?: EveryAppOptions<TEnv>): EveryAppExport<TEnv, TCtx>;
|
|
104
|
-
/**
|
|
105
|
-
* @deprecated Drop the manifest: the app id now comes from
|
|
106
|
-
* `env.EVERYAPP_APP_ID` and the audience from `env.EVERYAPP_AUDIENCE`.
|
|
107
|
-
* When passed, it must match the app id.
|
|
108
|
-
*/
|
|
109
|
-
export declare function everyApp<TEnv = Record<string, unknown>, TCtx extends ExecutionContextLike = ExecutionContext>(handler: EveryAppHandler<TEnv, TCtx>, manifest: EveryAppManifestLike | undefined, options?: EveryAppOptions<TEnv>): EveryAppExport<TEnv, TCtx>;
|
|
110
91
|
//# sourceMappingURL=everyApp.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"everyApp.d.ts","sourceRoot":"","sources":["../../src/server/everyApp.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"everyApp.d.ts","sourceRoot":"","sources":["../../src/server/everyApp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAGL,kBAAkB,EAQlB,OAAO,EACP,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,OAAO,EAEb,MAAM,sBAAsB,CAAC;AAE9B,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