@every-app/sdk 0.2.0 → 0.3.0-rc.1
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 +608 -2
- package/dist/cloudflare/index.d.ts +22 -0
- package/dist/cloudflare/index.d.ts.map +1 -0
- package/dist/cloudflare/index.js +21 -0
- package/dist/cloudflare/sentinel.d.ts +69 -0
- package/dist/cloudflare/sentinel.d.ts.map +1 -0
- package/dist/cloudflare/sentinel.js +50 -0
- package/dist/cloudflare/worker.d.ts +511 -0
- package/dist/cloudflare/worker.d.ts.map +1 -0
- package/dist/cloudflare/worker.js +738 -0
- package/dist/dev/index.d.ts +8 -0
- package/dist/dev/index.d.ts.map +1 -0
- package/dist/dev/index.js +7 -0
- package/dist/dev/keypair.d.ts +24 -0
- package/dist/dev/keypair.d.ts.map +1 -0
- package/dist/dev/keypair.js +60 -0
- package/dist/internal/aiProviders.d.ts +67 -0
- package/dist/internal/aiProviders.d.ts.map +1 -0
- package/dist/internal/aiProviders.js +220 -0
- package/dist/internal/appSettings.d.ts +237 -0
- package/dist/internal/appSettings.d.ts.map +1 -0
- package/dist/internal/appSettings.js +374 -0
- package/dist/internal/capabilities.d.ts +1344 -0
- package/dist/internal/capabilities.d.ts.map +1 -0
- package/dist/internal/capabilities.js +1521 -0
- package/dist/internal/devProviders.d.ts +49 -0
- package/dist/internal/devProviders.d.ts.map +1 -0
- package/dist/internal/devProviders.js +62 -0
- package/dist/internal/email.d.ts +280 -0
- package/dist/internal/email.d.ts.map +1 -0
- package/dist/internal/email.js +613 -0
- package/dist/internal/events.d.ts +182 -0
- package/dist/internal/events.d.ts.map +1 -0
- package/dist/internal/events.js +324 -0
- package/dist/internal/gatewaySettings.d.ts +82 -0
- package/dist/internal/gatewaySettings.d.ts.map +1 -0
- package/dist/internal/gatewaySettings.js +209 -0
- package/dist/internal/identity.d.ts +18 -3
- package/dist/internal/identity.d.ts.map +1 -1
- package/dist/internal/identity.js +53 -14
- package/dist/internal/index.d.ts +17 -1
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +17 -1
- package/dist/internal/members.d.ts +35 -0
- package/dist/internal/members.d.ts.map +1 -0
- package/dist/internal/members.js +7 -0
- package/dist/internal/oauthClient.d.ts +63 -0
- package/dist/internal/oauthClient.d.ts.map +1 -0
- package/dist/internal/oauthClient.js +194 -0
- package/dist/internal/oauthScopes.d.ts +117 -0
- package/dist/internal/oauthScopes.d.ts.map +1 -0
- package/dist/internal/oauthScopes.js +416 -0
- package/dist/internal/organizationName.d.ts +18 -0
- package/dist/internal/organizationName.d.ts.map +1 -0
- package/dist/internal/organizationName.js +24 -0
- package/dist/internal/protocol.d.ts +86 -2
- package/dist/internal/protocol.d.ts.map +1 -1
- package/dist/internal/protocol.js +112 -1
- package/dist/internal/providerApps.d.ts +75 -0
- package/dist/internal/providerApps.d.ts.map +1 -0
- package/dist/internal/providerApps.js +59 -0
- package/dist/internal/providerRegistry.d.ts +147 -0
- package/dist/internal/providerRegistry.d.ts.map +1 -0
- package/dist/internal/providerRegistry.js +262 -0
- package/dist/internal/providerSpec.d.ts +55 -0
- package/dist/internal/providerSpec.d.ts.map +1 -0
- package/dist/internal/providerSpec.js +746 -0
- package/dist/internal/remoteMcp.d.ts +188 -0
- package/dist/internal/remoteMcp.d.ts.map +1 -0
- package/dist/internal/remoteMcp.js +543 -0
- package/dist/internal/tools.d.ts +115 -0
- package/dist/internal/tools.d.ts.map +1 -0
- package/dist/internal/tools.js +80 -0
- package/dist/server/attribution.d.ts +39 -0
- package/dist/server/attribution.d.ts.map +1 -0
- package/dist/server/attribution.js +67 -0
- package/dist/server/authorizeUrl.d.ts +43 -0
- package/dist/server/authorizeUrl.d.ts.map +1 -0
- package/dist/server/authorizeUrl.js +110 -0
- package/dist/server/emit.d.ts +63 -0
- package/dist/server/emit.d.ts.map +1 -0
- package/dist/server/emit.js +101 -0
- package/dist/server/everyApp.d.ts +38 -12
- package/dist/server/everyApp.d.ts.map +1 -1
- package/dist/server/everyApp.js +92 -28
- package/dist/server/gatewayFetch.d.ts +24 -8
- package/dist/server/gatewayFetch.d.ts.map +1 -1
- package/dist/server/gatewayFetch.js +81 -36
- package/dist/server/index.d.ts +10 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +8 -1
- package/dist/server/integrationFetch.d.ts +131 -0
- package/dist/server/integrationFetch.d.ts.map +1 -0
- package/dist/server/integrationFetch.js +526 -0
- package/dist/server/listMembers.d.ts +32 -0
- package/dist/server/listMembers.d.ts.map +1 -0
- package/dist/server/listMembers.js +74 -0
- package/dist/server/nodeServer.d.ts +48 -0
- package/dist/server/nodeServer.d.ts.map +1 -0
- package/dist/server/nodeServer.js +45 -0
- package/dist/server/sendEmail.d.ts +39 -0
- package/dist/server/sendEmail.d.ts.map +1 -0
- package/dist/server/sendEmail.js +114 -0
- package/dist/server/tools.d.ts +184 -0
- package/dist/server/tools.d.ts.map +1 -0
- package/dist/server/tools.js +347 -0
- package/dist/server/toolsEndpoint.d.ts +32 -0
- package/dist/server/toolsEndpoint.d.ts.map +1 -0
- package/dist/server/toolsEndpoint.js +231 -0
- package/package.json +30 -17
- package/dist/server/mcp.d.ts +0 -66
- package/dist/server/mcp.d.ts.map +0 -1
- package/dist/server/mcp.js +0 -147
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @every-app/sdk/dev — the well-known dev identity: the keypair `everyapp dev`
|
|
3
|
+
* signs with, its issuer and its key id. For the platform's local dev tools
|
|
4
|
+
* (the CLI, `@every-app/perimeter/dev`); never imported by a Worker.
|
|
5
|
+
*/
|
|
6
|
+
export { DEV_ISSUER, DEV_PRIVATE_KEY_PEM, DEV_PUBLIC_KEY_PEM, } from "./keypair.js";
|
|
7
|
+
export { IDENTITY_DEV_KEY_ID } from "../internal/protocol.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dev/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @every-app/sdk/dev — the well-known dev identity: the keypair `everyapp dev`
|
|
3
|
+
* signs with, its issuer and its key id. For the platform's local dev tools
|
|
4
|
+
* (the CLI, `@every-app/perimeter/dev`); never imported by a Worker.
|
|
5
|
+
*/
|
|
6
|
+
export { DEV_ISSUER, DEV_PRIVATE_KEY_PEM, DEV_PUBLIC_KEY_PEM, } from "./keypair.js";
|
|
7
|
+
export { IDENTITY_DEV_KEY_ID } from "../internal/protocol.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The well-known keypair and issuer of local dev identities.
|
|
3
|
+
*
|
|
4
|
+
* Public by design: the private key is in this file for anyone to read, so a
|
|
5
|
+
* token signed with it proves nothing outside dev. The SDK accepts it only
|
|
6
|
+
* under the dev key id, only behind the dev opt-in (`EVERYAPP_DEV`, which
|
|
7
|
+
* `everyAppWorker()` sets in development and a deploy never does), and only
|
|
8
|
+
* from {@link DEV_ISSUER}. Anything that reaches the local dev ports can mint
|
|
9
|
+
* a dev identity with it; that is the local-dev trust boundary, which is why
|
|
10
|
+
* `everyapp dev` listens on 127.0.0.1 unless told otherwise.
|
|
11
|
+
*
|
|
12
|
+
* A leaf module: `cloudflare.config.ts` loads it through
|
|
13
|
+
* `@every-app/sdk/cloudflare`, and the Vite plugin hides from the Worker
|
|
14
|
+
* every file the config loads, so the Worker never imports it. The Worker
|
|
15
|
+
* side keeps its own copy of the issuer (`internal/protocol.ts`); a test
|
|
16
|
+
* pins the two together.
|
|
17
|
+
*/
|
|
18
|
+
/** Issuer of locally minted dev identity tokens. */
|
|
19
|
+
export declare const DEV_ISSUER = "https://gateway.dev.localhost";
|
|
20
|
+
/** SPKI PEM public half of the dev keypair. */
|
|
21
|
+
export declare const DEV_PUBLIC_KEY_PEM = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAh40zWf+QK3rJdMTNoy+X\nF9iydV5raWSeEt4DXyeY98c8IZHRjy2UXaaYejweebRsv9Az+bZuL3cfJ0E7pOGd\n4VCOiSG1BjJglmTC1whV4Md6qhLDVOP6iztUJSxDwnlR85UtOyNJ4G5dYY6RrAWl\nPMMXPSYdGWqAP4n5QXAw+7uTFmJMdWy1W8KLbTj//NSGn3DCm+EZJIC8q9yDhMSc\nM0ejJnBVColvp4T8k8dt2kYGu2Wd7dCMrHv/lxUoqD58avpdMOzbaZtwsQ7BAaIa\nmIeQ1AKxmnCj1np23uWvYQmoaZocvupLSALK7fWGUyVDZ+RW4HtN5KqzZypfiyZ8\nkQIDAQAB\n-----END PUBLIC KEY-----\n";
|
|
22
|
+
/** PKCS#8 PEM private half of the dev keypair. Public, see above. */
|
|
23
|
+
export declare const DEV_PRIVATE_KEY_PEM = "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCHjTNZ/5Aresl0\nxM2jL5cX2LJ1XmtpZJ4S3gNfJ5j3xzwhkdGPLZRdpph6PB55tGy/0DP5tm4vdx8n\nQTuk4Z3hUI6JIbUGMmCWZMLXCFXgx3qqEsNU4/qLO1QlLEPCeVHzlS07I0ngbl1h\njpGsBaU8wxc9Jh0ZaoA/iflBcDD7u5MWYkx1bLVbwottOP/81IafcMKb4RkkgLyr\n3IOExJwzR6MmcFUKiW+nhPyTx23aRga7ZZ3t0Iyse/+XFSioPnxq+l0w7Ntpm3Cx\nDsEBohqYh5DUArGacKPWenbe5a9hCahpmhy+6ktIAsrt9YZTJUNn5Fbge03kqrNn\nKl+LJnyRAgMBAAECggEABCi9GAB3URw3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XuDNajQ\nsBwG4E6M/yUbgdbNjnv+AuVYS8Uyvf6x/xaWH3zssluIXhod0Two22bjtkPGJ2nx\n1ZXmbxSdWVGwLZn3GYRoRu6X6VGTbFAaK1mb7KDfwjoaauV7G3A2mw6M5xxg4zx/\nhsbx0DA4sMMIUEniw9W/YA==\n-----END PRIVATE KEY-----\n";
|
|
24
|
+
//# sourceMappingURL=keypair.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keypair.d.ts","sourceRoot":"","sources":["../../src/dev/keypair.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,oDAAoD;AACpD,eAAO,MAAM,UAAU,kCAAkC,CAAC;AAE1D,+CAA+C;AAC/C,eAAO,MAAM,kBAAkB,idAS9B,CAAC;AAEF,qEAAqE;AACrE,eAAO,MAAM,mBAAmB,ysDA4B/B,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The well-known keypair and issuer of local dev identities.
|
|
3
|
+
*
|
|
4
|
+
* Public by design: the private key is in this file for anyone to read, so a
|
|
5
|
+
* token signed with it proves nothing outside dev. The SDK accepts it only
|
|
6
|
+
* under the dev key id, only behind the dev opt-in (`EVERYAPP_DEV`, which
|
|
7
|
+
* `everyAppWorker()` sets in development and a deploy never does), and only
|
|
8
|
+
* from {@link DEV_ISSUER}. Anything that reaches the local dev ports can mint
|
|
9
|
+
* a dev identity with it; that is the local-dev trust boundary, which is why
|
|
10
|
+
* `everyapp dev` listens on 127.0.0.1 unless told otherwise.
|
|
11
|
+
*
|
|
12
|
+
* A leaf module: `cloudflare.config.ts` loads it through
|
|
13
|
+
* `@every-app/sdk/cloudflare`, and the Vite plugin hides from the Worker
|
|
14
|
+
* every file the config loads, so the Worker never imports it. The Worker
|
|
15
|
+
* side keeps its own copy of the issuer (`internal/protocol.ts`); a test
|
|
16
|
+
* pins the two together.
|
|
17
|
+
*/
|
|
18
|
+
/** Issuer of locally minted dev identity tokens. */
|
|
19
|
+
export const DEV_ISSUER = "https://gateway.dev.localhost";
|
|
20
|
+
/** SPKI PEM public half of the dev keypair. */
|
|
21
|
+
export const DEV_PUBLIC_KEY_PEM = `-----BEGIN PUBLIC KEY-----
|
|
22
|
+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAh40zWf+QK3rJdMTNoy+X
|
|
23
|
+
F9iydV5raWSeEt4DXyeY98c8IZHRjy2UXaaYejweebRsv9Az+bZuL3cfJ0E7pOGd
|
|
24
|
+
4VCOiSG1BjJglmTC1whV4Md6qhLDVOP6iztUJSxDwnlR85UtOyNJ4G5dYY6RrAWl
|
|
25
|
+
PMMXPSYdGWqAP4n5QXAw+7uTFmJMdWy1W8KLbTj//NSGn3DCm+EZJIC8q9yDhMSc
|
|
26
|
+
M0ejJnBVColvp4T8k8dt2kYGu2Wd7dCMrHv/lxUoqD58avpdMOzbaZtwsQ7BAaIa
|
|
27
|
+
mIeQ1AKxmnCj1np23uWvYQmoaZocvupLSALK7fWGUyVDZ+RW4HtN5KqzZypfiyZ8
|
|
28
|
+
kQIDAQAB
|
|
29
|
+
-----END PUBLIC KEY-----
|
|
30
|
+
`;
|
|
31
|
+
/** PKCS#8 PEM private half of the dev keypair. Public, see above. */
|
|
32
|
+
export const DEV_PRIVATE_KEY_PEM = `-----BEGIN PRIVATE KEY-----
|
|
33
|
+
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCHjTNZ/5Aresl0
|
|
34
|
+
xM2jL5cX2LJ1XmtpZJ4S3gNfJ5j3xzwhkdGPLZRdpph6PB55tGy/0DP5tm4vdx8n
|
|
35
|
+
QTuk4Z3hUI6JIbUGMmCWZMLXCFXgx3qqEsNU4/qLO1QlLEPCeVHzlS07I0ngbl1h
|
|
36
|
+
jpGsBaU8wxc9Jh0ZaoA/iflBcDD7u5MWYkx1bLVbwottOP/81IafcMKb4RkkgLyr
|
|
37
|
+
3IOEx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41zkWYUOUBmXfnnVSKFwOHB4B1dkiPA18UU
|
|
52
|
+
4Ur5002Kk0rJ4zmVs+yHbb1nwPgan0VDB0WsUr5W1CP8jaoGCO9GcHsRAoGAX6Xm
|
|
53
|
+
eOLupLx6DbxZBg99sXxoocN++QL7yU3jNI5+5fz9lKKESCMlJH09r18fcQCXph2b
|
|
54
|
+
Kd0aQF4nvCkwDQZqJzvVwCY8wsZ+1g5KKgizBudyiyErLeCS/f0nEZ0/QUdnskcz
|
|
55
|
+
DRd3XNYUYzFOWGnz8JhvPA3A6oGgqhiaxh7p2SECgYA+7s6WRfQLSad3dXuDNajQ
|
|
56
|
+
sBwG4E6M/yUbgdbNjnv+AuVYS8Uyvf6x/xaWH3zssluIXhod0Two22bjtkPGJ2nx
|
|
57
|
+
1ZXmbxSdWVGwLZn3GYRoRu6X6VGTbFAaK1mb7KDfwjoaauV7G3A2mw6M5xxg4zx/
|
|
58
|
+
hsbx0DA4sMMIUEniw9W/YA==
|
|
59
|
+
-----END PRIVATE KEY-----
|
|
60
|
+
`;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The gateway's AI providers as the SDK's local-dev fallback reaches them:
|
|
3
|
+
* with no gateway binding, a developer's own key, under the name of the
|
|
4
|
+
* gateway secret that holds it, goes to the provider directly. Deployed
|
|
5
|
+
* apps always go through the gateway, which holds the real keys. The
|
|
6
|
+
* providers themselves are the catalog's `ai` entries (./capabilities.ts);
|
|
7
|
+
* this derives the fallback's view of each, and holds the one response
|
|
8
|
+
* rewrite the gateway has (Workers AI's numeric tokens).
|
|
9
|
+
*/
|
|
10
|
+
import { type AiProviderCapability, type AiProviderId, type ApiKeyAuth, type CapabilitySettings } from "./capabilities.js";
|
|
11
|
+
export interface DevAiProviderSpec {
|
|
12
|
+
origin: string;
|
|
13
|
+
/** The gateway secret holding the provider key; in local dev, the `.dev.vars` name. */
|
|
14
|
+
keyEnv: string;
|
|
15
|
+
/** Where the key goes on a request (`authorizationOf`). */
|
|
16
|
+
auth: ApiKeyAuth;
|
|
17
|
+
/** Where an operator gets the key: the provider's API keys page. */
|
|
18
|
+
docs: string;
|
|
19
|
+
/** The everyapp skill's setup guide for it, relative to the skill (`setup/openai.md`). */
|
|
20
|
+
setup?: string;
|
|
21
|
+
/** Gateway settings the provider's URL needs besides the key, under the same names. */
|
|
22
|
+
alsoNeeds?: readonly string[];
|
|
23
|
+
/** The path every provider path is joined onto, from those settings. */
|
|
24
|
+
basePath?: (settings: Readonly<Record<string, string>>) => string;
|
|
25
|
+
/** Turns the provider's response at `path` into what OpenAI clients parse. */
|
|
26
|
+
normalizeResponse?: (path: string, response: Response) => Response;
|
|
27
|
+
}
|
|
28
|
+
export type DevAiProvider = AiProviderId;
|
|
29
|
+
/** The fallback's view of one `ai` catalog entry. */
|
|
30
|
+
export declare function devAiProviderSpec(capability: AiProviderCapability): DevAiProviderSpec;
|
|
31
|
+
export declare const DEV_AI_PROVIDERS: Readonly<Record<DevAiProvider, DevAiProviderSpec>>;
|
|
32
|
+
export declare function devAiProvider(name: string): DevAiProviderSpec | undefined;
|
|
33
|
+
/** Every setting a provider needs, its key first: the names `.dev.vars` and the gateway use. */
|
|
34
|
+
export declare function aiProviderSettings(spec: DevAiProviderSpec): string[];
|
|
35
|
+
/**
|
|
36
|
+
* An `ai` entry's `basePath` with each `{SETTING}` filled from the
|
|
37
|
+
* settings, URL-encoded (`/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai`
|
|
38
|
+
* with `acc 1` makes `/client/v4/accounts/acc%201/ai`), or null while a
|
|
39
|
+
* named setting is unset or blank.
|
|
40
|
+
*/
|
|
41
|
+
export declare function fillBasePath(template: string, settings: CapabilitySettings): string | null;
|
|
42
|
+
/**
|
|
43
|
+
* The base URL an `ai` entry's calls are joined onto, from the Gateway's
|
|
44
|
+
* settings: its origin and filled `basePath`, or null while a setting the
|
|
45
|
+
* path needs is unset.
|
|
46
|
+
*/
|
|
47
|
+
export declare function aiBaseUrl(capability: AiProviderCapability, settings: CapabilitySettings): string | null;
|
|
48
|
+
/** The account-scoped base path of Workers AI's REST API. */
|
|
49
|
+
export declare function workersAiBasePath(accountId: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* `base` with `path` joined onto its path (never replacing it) and
|
|
52
|
+
* `search` as its query: `https://api.cloudflare.com/client/v4/accounts/<id>/ai`
|
|
53
|
+
* and `/v1/chat/completions` make `…/ai/v1/chat/completions`. `path` starts
|
|
54
|
+
* with one slash; null when the result would leave `base`'s path.
|
|
55
|
+
*/
|
|
56
|
+
export declare function joinProviderUrl(base: string, path: string, search?: string): URL | null;
|
|
57
|
+
/**
|
|
58
|
+
* Workers AI's OpenAI-compatible chat completions on the vLLM-backed models
|
|
59
|
+
* (Meta's Llama among them) send a token made only of digits as a JSON
|
|
60
|
+
* number (`"delta":{"content":18}`), which OpenAI clients refuse:
|
|
61
|
+
* `@ai-sdk/openai-compatible` drops the token and reports an error part.
|
|
62
|
+
* This turns such numbers back into strings, in `choices[].delta` (streams)
|
|
63
|
+
* and `choices[].message` (whole JSON bodies); every other event or body
|
|
64
|
+
* passes through byte for byte. Remove it once Cloudflare sends strings.
|
|
65
|
+
*/
|
|
66
|
+
export declare function normalizeWorkersAiResponse(path: string, response: Response): Response;
|
|
67
|
+
//# sourceMappingURL=aiProviders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aiProviders.d.ts","sourceRoot":"","sources":["../../src/internal/aiProviders.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAGL,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,kBAAkB,EACxB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,uFAAuF;IACvF,MAAM,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,IAAI,EAAE,UAAU,CAAC;IACjB,oEAAoE;IAC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OZ;AAWD;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,QAAQ,GACjB,QAAQ,CAqBV"}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The gateway's AI providers as the SDK's local-dev fallback reaches them:
|
|
3
|
+
* with no gateway binding, a developer's own key, under the name of the
|
|
4
|
+
* gateway secret that holds it, goes to the provider directly. Deployed
|
|
5
|
+
* apps always go through the gateway, which holds the real keys. The
|
|
6
|
+
* providers themselves are the catalog's `ai` entries (./capabilities.ts);
|
|
7
|
+
* this derives the fallback's view of each, and holds the one response
|
|
8
|
+
* rewrite the gateway has (Workers AI's numeric tokens).
|
|
9
|
+
*/
|
|
10
|
+
import { CAPABILITIES, CAPABILITY_IDS, } from "./capabilities.js";
|
|
11
|
+
/** The fallback's view of one `ai` catalog entry. */
|
|
12
|
+
export function devAiProviderSpec(capability) {
|
|
13
|
+
const { basePath, normalize } = capability;
|
|
14
|
+
return {
|
|
15
|
+
origin: capability.origin,
|
|
16
|
+
keyEnv: capability.auth.secret,
|
|
17
|
+
auth: capability.auth,
|
|
18
|
+
docs: capability.docs,
|
|
19
|
+
...(capability.setup === undefined ? {} : { setup: capability.setup }),
|
|
20
|
+
...(capability.alsoNeeds === undefined
|
|
21
|
+
? {}
|
|
22
|
+
: { alsoNeeds: capability.alsoNeeds }),
|
|
23
|
+
...(basePath === undefined
|
|
24
|
+
? {}
|
|
25
|
+
: { basePath: (settings) => fillBasePath(basePath, settings) ?? "" }),
|
|
26
|
+
...(normalize === "workers-ai"
|
|
27
|
+
? { normalizeResponse: normalizeWorkersAiResponse }
|
|
28
|
+
: {}),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export const DEV_AI_PROVIDERS = Object.fromEntries(CAPABILITY_IDS.flatMap((id) => {
|
|
32
|
+
const capability = CAPABILITIES[id];
|
|
33
|
+
return capability.mode === "ai"
|
|
34
|
+
? [[id, devAiProviderSpec(capability)]]
|
|
35
|
+
: [];
|
|
36
|
+
}));
|
|
37
|
+
export function devAiProvider(name) {
|
|
38
|
+
return Object.hasOwn(DEV_AI_PROVIDERS, name)
|
|
39
|
+
? DEV_AI_PROVIDERS[name]
|
|
40
|
+
: undefined;
|
|
41
|
+
}
|
|
42
|
+
/** Every setting a provider needs, its key first: the names `.dev.vars` and the gateway use. */
|
|
43
|
+
export function aiProviderSettings(spec) {
|
|
44
|
+
return [spec.keyEnv, ...(spec.alsoNeeds ?? [])];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* An `ai` entry's `basePath` with each `{SETTING}` filled from the
|
|
48
|
+
* settings, URL-encoded (`/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai`
|
|
49
|
+
* with `acc 1` makes `/client/v4/accounts/acc%201/ai`), or null while a
|
|
50
|
+
* named setting is unset or blank.
|
|
51
|
+
*/
|
|
52
|
+
export function fillBasePath(template, settings) {
|
|
53
|
+
let missing = false;
|
|
54
|
+
const filled = template.replace(/\{([A-Z][A-Z0-9_]*)\}/g, (_, name) => {
|
|
55
|
+
const value = settings[name];
|
|
56
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
57
|
+
missing = true;
|
|
58
|
+
return "";
|
|
59
|
+
}
|
|
60
|
+
return encodeURIComponent(value.trim());
|
|
61
|
+
});
|
|
62
|
+
return missing ? null : filled;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The base URL an `ai` entry's calls are joined onto, from the Gateway's
|
|
66
|
+
* settings: its origin and filled `basePath`, or null while a setting the
|
|
67
|
+
* path needs is unset.
|
|
68
|
+
*/
|
|
69
|
+
export function aiBaseUrl(capability, settings) {
|
|
70
|
+
if (capability.basePath === undefined)
|
|
71
|
+
return capability.origin;
|
|
72
|
+
const path = fillBasePath(capability.basePath, settings);
|
|
73
|
+
return path === null ? null : `${capability.origin}${path}`;
|
|
74
|
+
}
|
|
75
|
+
/** The account-scoped base path of Workers AI's REST API. */
|
|
76
|
+
export function workersAiBasePath(accountId) {
|
|
77
|
+
return `/client/v4/accounts/${encodeURIComponent(accountId.trim())}/ai`;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* `base` with `path` joined onto its path (never replacing it) and
|
|
81
|
+
* `search` as its query: `https://api.cloudflare.com/client/v4/accounts/<id>/ai`
|
|
82
|
+
* and `/v1/chat/completions` make `…/ai/v1/chat/completions`. `path` starts
|
|
83
|
+
* with one slash; null when the result would leave `base`'s path.
|
|
84
|
+
*/
|
|
85
|
+
export function joinProviderUrl(base, path, search = "") {
|
|
86
|
+
const url = new URL(base);
|
|
87
|
+
const basePath = url.pathname.replace(/\/+$/, "");
|
|
88
|
+
url.pathname = `${basePath}${path}`;
|
|
89
|
+
url.search = search;
|
|
90
|
+
url.hash = "";
|
|
91
|
+
return url.pathname === `${basePath}${path}` ? url : null;
|
|
92
|
+
}
|
|
93
|
+
const WORKERS_AI_NORMALIZED_ROUTES = new Set([
|
|
94
|
+
"/v1/chat/completions",
|
|
95
|
+
]);
|
|
96
|
+
/** Text fields of a chat completion choice that OpenAI clients require as strings. */
|
|
97
|
+
const TEXT_FIELDS = ["content", "reasoning_content", "reasoning"];
|
|
98
|
+
const NUMERIC_TEXT_FIELD = /"(?:content|reasoning_content|reasoning)"\s*:\s*-?\d/;
|
|
99
|
+
/**
|
|
100
|
+
* Workers AI's OpenAI-compatible chat completions on the vLLM-backed models
|
|
101
|
+
* (Meta's Llama among them) send a token made only of digits as a JSON
|
|
102
|
+
* number (`"delta":{"content":18}`), which OpenAI clients refuse:
|
|
103
|
+
* `@ai-sdk/openai-compatible` drops the token and reports an error part.
|
|
104
|
+
* This turns such numbers back into strings, in `choices[].delta` (streams)
|
|
105
|
+
* and `choices[].message` (whole JSON bodies); every other event or body
|
|
106
|
+
* passes through byte for byte. Remove it once Cloudflare sends strings.
|
|
107
|
+
*/
|
|
108
|
+
export function normalizeWorkersAiResponse(path, response) {
|
|
109
|
+
if (!response.body || !WORKERS_AI_NORMALIZED_ROUTES.has(path)) {
|
|
110
|
+
return response;
|
|
111
|
+
}
|
|
112
|
+
const contentType = (response.headers.get("content-type") ?? "").toLowerCase();
|
|
113
|
+
const transform = contentType.startsWith("text/event-stream")
|
|
114
|
+
? normalizeSseLines()
|
|
115
|
+
: contentType.startsWith("application/json")
|
|
116
|
+
? normalizeJsonBody()
|
|
117
|
+
: null;
|
|
118
|
+
if (!transform)
|
|
119
|
+
return response;
|
|
120
|
+
const headers = new Headers(response.headers);
|
|
121
|
+
// The body may change length.
|
|
122
|
+
headers.delete("content-length");
|
|
123
|
+
return new Response(response.body.pipeThrough(transform), {
|
|
124
|
+
status: response.status,
|
|
125
|
+
statusText: response.statusText,
|
|
126
|
+
headers,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/** Stringify numeric text fields of every choice in a chat completion (chunk). */
|
|
130
|
+
function stringifyNumericText(payload) {
|
|
131
|
+
if (!isRecord(payload) || !Array.isArray(payload["choices"]))
|
|
132
|
+
return false;
|
|
133
|
+
let changed = false;
|
|
134
|
+
for (const choice of payload["choices"]) {
|
|
135
|
+
if (!isRecord(choice))
|
|
136
|
+
continue;
|
|
137
|
+
for (const part of [choice["delta"], choice["message"]]) {
|
|
138
|
+
if (!isRecord(part))
|
|
139
|
+
continue;
|
|
140
|
+
for (const field of TEXT_FIELDS) {
|
|
141
|
+
const value = part[field];
|
|
142
|
+
if (typeof value === "number") {
|
|
143
|
+
part[field] = String(value);
|
|
144
|
+
changed = true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return changed;
|
|
150
|
+
}
|
|
151
|
+
/** `json` with its numeric text fields as strings, or null when it has none. */
|
|
152
|
+
function normalizedJson(json) {
|
|
153
|
+
if (!NUMERIC_TEXT_FIELD.test(json))
|
|
154
|
+
return null;
|
|
155
|
+
let payload;
|
|
156
|
+
try {
|
|
157
|
+
payload = JSON.parse(json);
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
return stringifyNumericText(payload) ? JSON.stringify(payload) : null;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* An SSE stream, line by line: a `data:` line whose JSON has a numeric text
|
|
166
|
+
* field is rewritten, every other line (and its line ending) is kept.
|
|
167
|
+
*/
|
|
168
|
+
function normalizeSseLines() {
|
|
169
|
+
const decoder = new TextDecoder();
|
|
170
|
+
const encoder = new TextEncoder();
|
|
171
|
+
let pending = "";
|
|
172
|
+
const normalizeLine = (line) => {
|
|
173
|
+
const match = /^(data:[ ]?)(.*?)(\r?)$/s.exec(line);
|
|
174
|
+
if (!match)
|
|
175
|
+
return line;
|
|
176
|
+
const rewritten = normalizedJson(match[2]);
|
|
177
|
+
return rewritten === null ? line : `${match[1]}${rewritten}${match[3]}`;
|
|
178
|
+
};
|
|
179
|
+
return new TransformStream({
|
|
180
|
+
transform(chunk, controller) {
|
|
181
|
+
pending += decoder.decode(chunk, { stream: true });
|
|
182
|
+
const end = pending.lastIndexOf("\n");
|
|
183
|
+
if (end === -1)
|
|
184
|
+
return;
|
|
185
|
+
const complete = pending.slice(0, end + 1);
|
|
186
|
+
pending = pending.slice(end + 1);
|
|
187
|
+
controller.enqueue(encoder.encode(complete.split("\n").map(normalizeLine).join("\n")));
|
|
188
|
+
},
|
|
189
|
+
flush(controller) {
|
|
190
|
+
pending += decoder.decode();
|
|
191
|
+
if (pending)
|
|
192
|
+
controller.enqueue(encoder.encode(normalizeLine(pending)));
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
/** A whole JSON body: rewritten when it has a numeric text field, else kept as sent. */
|
|
197
|
+
function normalizeJsonBody() {
|
|
198
|
+
const chunks = [];
|
|
199
|
+
return new TransformStream({
|
|
200
|
+
transform(chunk) {
|
|
201
|
+
chunks.push(chunk);
|
|
202
|
+
},
|
|
203
|
+
flush(controller) {
|
|
204
|
+
const decoder = new TextDecoder();
|
|
205
|
+
const text = chunks
|
|
206
|
+
.map((chunk) => decoder.decode(chunk, { stream: true }))
|
|
207
|
+
.join("") + decoder.decode();
|
|
208
|
+
const rewritten = normalizedJson(text);
|
|
209
|
+
if (rewritten !== null) {
|
|
210
|
+
controller.enqueue(new TextEncoder().encode(rewritten));
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
for (const chunk of chunks)
|
|
214
|
+
controller.enqueue(chunk);
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
function isRecord(value) {
|
|
219
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
220
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an app needs set before it works, and whether it is: the model
|
|
3
|
+
* behind "needs setup" wherever an app is shown (the gateway's home and
|
|
4
|
+
* Admin → Apps, `everyapp status`, `everyapp secret list`, the end of
|
|
5
|
+
* `everyapp deploy`, and what `everyapp configure <app>` walks through).
|
|
6
|
+
*
|
|
7
|
+
* A manifest declares three kinds of setting. An AI provider
|
|
8
|
+
* (`providers`) and a capability (`capabilities`) are the Gateway's: their
|
|
9
|
+
* keys and clients live on the Gateway Worker, set once for every app
|
|
10
|
+
* with `everyapp secret set <NAME>`. The app's own secrets (`secrets`)
|
|
11
|
+
* live on its Worker, set from its directory. Each declaration carries a
|
|
12
|
+
* need: required (the default; the app doesn't open until it is set),
|
|
13
|
+
* optional (the app opens, and the feature says what is missing where it
|
|
14
|
+
* is used), or a member of a named any-of group (the app opens once any
|
|
15
|
+
* member is set; only for an app that picks among the set members at run
|
|
16
|
+
* time). Each may say `why` it is needed and where it comes from
|
|
17
|
+
* (`docs`, an https URL); for providers and capabilities the registries
|
|
18
|
+
* here supply a default.
|
|
19
|
+
*
|
|
20
|
+
* Everything in this module is pure and tenant-neutral: a manifest ships
|
|
21
|
+
* in a release, and what is set is asked of the caller (`isSet`), which
|
|
22
|
+
* reads the Gateway's env, cf's secret list, or the registry's record of
|
|
23
|
+
* the app Worker's secret names.
|
|
24
|
+
*/
|
|
25
|
+
import { type ApiKeyCapability, type CapabilityLookup } from "./capabilities.js";
|
|
26
|
+
/** A provider as `providers` lists it: its id, or an entry with a need. */
|
|
27
|
+
export interface ProviderEntry extends SettingNeedFields {
|
|
28
|
+
id: string;
|
|
29
|
+
}
|
|
30
|
+
/** A secret as `secrets` lists it: its name, or an entry with a need. */
|
|
31
|
+
export interface SecretEntry extends SettingNeedFields {
|
|
32
|
+
name: string;
|
|
33
|
+
}
|
|
34
|
+
/** What any declaration may say about its need. */
|
|
35
|
+
export interface SettingNeedFields {
|
|
36
|
+
/** Why the app needs it, for whoever sets it (200 characters at most). */
|
|
37
|
+
why?: string;
|
|
38
|
+
/** Where the key or client comes from: an https URL. */
|
|
39
|
+
docs?: string;
|
|
40
|
+
/** The app works without it; the feature using it says so where it is used. */
|
|
41
|
+
optional?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* For an app's own secret: its setup guide, relative to the everyapp
|
|
44
|
+
* skill (`setup/main-secret.md`). Providers and capabilities take theirs
|
|
45
|
+
* from the registries and can't override it.
|
|
46
|
+
*/
|
|
47
|
+
setup?: string;
|
|
48
|
+
/**
|
|
49
|
+
* The name of a group of which one set member is enough ("AI model").
|
|
50
|
+
* Only for an app that picks among the set members at run time: the
|
|
51
|
+
* gateway refuses a call to a provider whose key isn't set, whichever
|
|
52
|
+
* others are.
|
|
53
|
+
*/
|
|
54
|
+
anyOf?: string;
|
|
55
|
+
}
|
|
56
|
+
/** The manifest fields this module reads, as a stored or authored manifest has them. */
|
|
57
|
+
export interface SettingsManifestLike {
|
|
58
|
+
readonly providers?: ReadonlyArray<string | ProviderEntry>;
|
|
59
|
+
readonly capabilities?: {
|
|
60
|
+
readonly [id: string]: unknown;
|
|
61
|
+
};
|
|
62
|
+
readonly secrets?: ReadonlyArray<string | SecretEntry>;
|
|
63
|
+
readonly ai?: {
|
|
64
|
+
readonly routes?: readonly string[];
|
|
65
|
+
};
|
|
66
|
+
/** A remote MCP app's registration (./remoteMcp.ts): its credential is a required Gateway setting. */
|
|
67
|
+
readonly remote?: unknown;
|
|
68
|
+
readonly name?: string;
|
|
69
|
+
}
|
|
70
|
+
export type SettingKind = "provider" | "capability" | "secret" | "ai-routes"
|
|
71
|
+
/** A remote MCP app's credential (./remoteMcp.ts): one Gateway setting named by the row. */
|
|
72
|
+
| "remote-mcp";
|
|
73
|
+
/** Which Worker holds a setting: the Gateway's, or the app's own. */
|
|
74
|
+
export type SettingHolder = "gateway" | "app";
|
|
75
|
+
export type SettingNeed = {
|
|
76
|
+
kind: "required";
|
|
77
|
+
} | {
|
|
78
|
+
kind: "optional";
|
|
79
|
+
} | {
|
|
80
|
+
kind: "anyOf";
|
|
81
|
+
group: string;
|
|
82
|
+
};
|
|
83
|
+
/** One thing the app needs set, as the manifest declares it. */
|
|
84
|
+
export interface AppSetting {
|
|
85
|
+
kind: SettingKind;
|
|
86
|
+
/** The provider id, capability id or secret name; "ai-routes" for the AI proxy's extra routes. */
|
|
87
|
+
id: string;
|
|
88
|
+
/** "OpenRouter", "DataForSEO", "MAIN_SECRET", "AI proxy routes". */
|
|
89
|
+
label: string;
|
|
90
|
+
holder: SettingHolder;
|
|
91
|
+
/** Every one of these must be set for the setting to count as set. */
|
|
92
|
+
names: string[];
|
|
93
|
+
/** Read when set, never required (a capability's optional settings). */
|
|
94
|
+
alsoReads: string[];
|
|
95
|
+
need: SettingNeed;
|
|
96
|
+
why?: string;
|
|
97
|
+
docs?: string;
|
|
98
|
+
/**
|
|
99
|
+
* The everyapp skill's setup guide for it, relative to the skill
|
|
100
|
+
* (`setup/dataforseo.md`; in an app `.claude/skills/everyapp/setup/…`, in
|
|
101
|
+
* the checkout `packages/cli/skills/everyapp/setup/…`): what an agent
|
|
102
|
+
* reads to set it up end to end. From the registries for providers and
|
|
103
|
+
* capabilities; from the manifest entry for an app's own secret.
|
|
104
|
+
*/
|
|
105
|
+
setup?: string;
|
|
106
|
+
/**
|
|
107
|
+
* What the key is and where it comes from, in a sentence or three, from
|
|
108
|
+
* the provider's entry (its `hint`, and each secret's own after it):
|
|
109
|
+
* what the "Needs setup" dialog, `everyapp status` and `everyapp
|
|
110
|
+
* configure` show beside `why`. A provider registered on the gateway
|
|
111
|
+
* has no guide, so this is what an agent reads for it.
|
|
112
|
+
*/
|
|
113
|
+
hint?: string;
|
|
114
|
+
}
|
|
115
|
+
/** A setting with whether it is set, and whether that keeps the app closed. */
|
|
116
|
+
export interface EvaluatedSetting extends AppSetting {
|
|
117
|
+
/**
|
|
118
|
+
* True: every name is set. False: one isn't. Null: not known (an app
|
|
119
|
+
* Worker whose secret names were never recorded), which never blocks.
|
|
120
|
+
*/
|
|
121
|
+
set: boolean | null;
|
|
122
|
+
/** This setting keeps the app from opening: required and unset, or a member of an any-of group none of whose members is set. */
|
|
123
|
+
blocking: boolean;
|
|
124
|
+
}
|
|
125
|
+
/** An any-of group: met once any member is set. */
|
|
126
|
+
export interface AnyOfGroup {
|
|
127
|
+
group: string;
|
|
128
|
+
members: EvaluatedSetting[];
|
|
129
|
+
met: boolean;
|
|
130
|
+
}
|
|
131
|
+
/** What `evaluateAppSettings` finds: whether the app opens, and every setting's state. */
|
|
132
|
+
export interface AppSettingsReport {
|
|
133
|
+
/** No required setting is unset and every any-of group is met. */
|
|
134
|
+
ready: boolean;
|
|
135
|
+
/** Every setting, in manifest order: providers, capabilities, the AI routes, secrets. */
|
|
136
|
+
settings: EvaluatedSetting[];
|
|
137
|
+
groups: AnyOfGroup[];
|
|
138
|
+
/** The settings that keep the app closed, in manifest order. */
|
|
139
|
+
unmet: EvaluatedSetting[];
|
|
140
|
+
}
|
|
141
|
+
/** The need an entry declares; required unless it says otherwise. */
|
|
142
|
+
export declare function needOf(entry: SettingNeedFields | undefined): SettingNeed;
|
|
143
|
+
/** The providers the manifest lists, each as an entry whatever form it took. */
|
|
144
|
+
export declare function providerEntries(manifest: Pick<SettingsManifestLike, "providers">): ProviderEntry[];
|
|
145
|
+
/** The provider ids the manifest lists, in order. */
|
|
146
|
+
export declare function providerIds(manifest: Pick<SettingsManifestLike, "providers">): string[];
|
|
147
|
+
/** The app's own secrets the manifest lists, each as an entry whatever form it took. */
|
|
148
|
+
export declare function secretEntries(manifest: Pick<SettingsManifestLike, "secrets">): SecretEntry[];
|
|
149
|
+
/** The names of the app's own secrets, in order. */
|
|
150
|
+
export declare function secretNames(manifest: Pick<SettingsManifestLike, "secrets">): string[];
|
|
151
|
+
/**
|
|
152
|
+
* Every setting the manifest declares, in manifest order: its AI
|
|
153
|
+
* providers, its capabilities, the AI proxy's extra routes when `ai.routes`
|
|
154
|
+
* asks for any, then the app's own secrets. A provider or capability the
|
|
155
|
+
* gateway doesn't offer contributes nothing (the manifest validator refuses
|
|
156
|
+
* it elsewhere); so does a capability with nothing to set (`members`),
|
|
157
|
+
* which is always set. `lookup` is where ids are found: the catalog alone
|
|
158
|
+
* by default, or a gateway's registry with its registered rows.
|
|
159
|
+
*/
|
|
160
|
+
export declare function appSettings(manifest: SettingsManifestLike, lookup?: CapabilityLookup): AppSetting[];
|
|
161
|
+
export interface EvaluateOptions {
|
|
162
|
+
/**
|
|
163
|
+
* A capability's own readiness rule, where names alone don't say (the
|
|
164
|
+
* gateway's email is configured once a sender parses and a provider is
|
|
165
|
+
* selectable): a boolean or null overrides the names; undefined defers
|
|
166
|
+
* to them.
|
|
167
|
+
*/
|
|
168
|
+
readiness?: (setting: AppSetting) => boolean | null | undefined;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Every setting against what is set. `isSet` answers per holder and name:
|
|
172
|
+
* true, false, or null when it can't tell (the registry never recorded
|
|
173
|
+
* the app Worker's secret names), which never blocks. An any-of group is
|
|
174
|
+
* met once any member is set; while none is and none is unknown, every
|
|
175
|
+
* member blocks.
|
|
176
|
+
*/
|
|
177
|
+
export declare function evaluateAppSettings(settings: readonly AppSetting[], isSet: (holder: SettingHolder, name: string) => boolean | null, options?: EvaluateOptions): AppSettingsReport;
|
|
178
|
+
/** The one command that opens the app. */
|
|
179
|
+
export interface SetupCommand {
|
|
180
|
+
/**
|
|
181
|
+
* `everyapp configure <app>`: asks for every required setting the app
|
|
182
|
+
* lacks, then offers the optional ones, and sets each where it is held.
|
|
183
|
+
*/
|
|
184
|
+
command: string;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* What to run for an app that needs setup: `everyapp configure <app>`,
|
|
188
|
+
* which reads the app's manifest (from the registry, so it runs from
|
|
189
|
+
* anywhere), prompts for each unmet setting (one member of an any-of group
|
|
190
|
+
* is enough: it asks which) and sets them where they are held. Null when
|
|
191
|
+
* the app is ready. `cli` is how the operator runs everyapp (`pnpm
|
|
192
|
+
* everyapp` from a checkout). Scripts that set one name at a time use
|
|
193
|
+
* `everyapp secret set NAME [--app <id>]` instead.
|
|
194
|
+
*
|
|
195
|
+
* A provider app (`provider`: the gateway's own, with no Worker and no
|
|
196
|
+
* directory; `everyapp mcp on <id>`, an MCP app) has nothing to configure: its
|
|
197
|
+
* command is the `secret set` of its Gateway key (the first member of an
|
|
198
|
+
* unmet any-of group), as `mcp list` says it.
|
|
199
|
+
*/
|
|
200
|
+
export declare function setupCommand(report: Pick<AppSettingsReport, "unmet" | "groups">, { cli, appId, provider, }: {
|
|
201
|
+
cli: string;
|
|
202
|
+
appId: string;
|
|
203
|
+
provider?: boolean;
|
|
204
|
+
}): SetupCommand | null;
|
|
205
|
+
/** One setting as `AppSetup` carries it: the evaluation without what only the CLI reads. */
|
|
206
|
+
export type AppSetupSetting = Omit<EvaluatedSetting, "alsoReads">;
|
|
207
|
+
/**
|
|
208
|
+
* An app's setup state as every surface shows it, the same on the
|
|
209
|
+
* gateway's app lists (`setup`), `everyapp status --json`
|
|
210
|
+
* (`apps[].setup`) and `everyapp secret list --json`: whether it opens,
|
|
211
|
+
* every setting with its state, the any-of groups, and the one command
|
|
212
|
+
* that opens it, `everyapp configure <app>` (null when it is ready, or
|
|
213
|
+
* when whoever reads this can't run it: a shared app seen from another
|
|
214
|
+
* organization).
|
|
215
|
+
*/
|
|
216
|
+
export interface AppSetup {
|
|
217
|
+
ready: boolean;
|
|
218
|
+
settings: AppSetupSetting[];
|
|
219
|
+
unmet: AppSetupSetting[];
|
|
220
|
+
groups: Array<{
|
|
221
|
+
group: string;
|
|
222
|
+
met: boolean;
|
|
223
|
+
members: string[];
|
|
224
|
+
}>;
|
|
225
|
+
command: SetupCommand | null;
|
|
226
|
+
}
|
|
227
|
+
export declare function appSetupOf(report: AppSettingsReport, options: {
|
|
228
|
+
cli: string;
|
|
229
|
+
appId: string;
|
|
230
|
+
withCommand?: boolean;
|
|
231
|
+
provider?: boolean;
|
|
232
|
+
}): AppSetup;
|
|
233
|
+
/** The provider registry's labels, for anything that names a provider to a person. */
|
|
234
|
+
export declare function providerLabel(id: string, lookup?: CapabilityLookup): string;
|
|
235
|
+
/** The capability `id` names in `lookup`, as an API-key provider, or undefined. */
|
|
236
|
+
export declare function apiKeyCapabilityOf(id: string, lookup?: CapabilityLookup): ApiKeyCapability | undefined;
|
|
237
|
+
//# sourceMappingURL=appSettings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appSettings.d.ts","sourceRoot":"","sources":["../../src/internal/appSettings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAKL,KAAK,gBAAgB,EAErB,KAAK,gBAAgB,EACtB,MAAM,mBAAmB,CAAC;AAW3B,2EAA2E;AAC3E,MAAM,WAAW,aAAc,SAAQ,iBAAiB;IACtD,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,yEAAyE;AACzE,MAAM,WAAW,WAAY,SAAQ,iBAAiB;IACpD,IAAI,EAAE,MAAM,CAAC;CACd;AAED,mDAAmD;AACnD,MAAM,WAAW,iBAAiB;IAChC,0EAA0E;IAC1E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,IAAI,C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