@every-app/sdk 0.3.0-rc.11 → 0.3.0-rc.12
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 +14 -17
- package/dist/internal/appSettings.d.ts.map +1 -1
- package/dist/internal/appSettings.js +2 -16
- package/dist/internal/capabilities.d.ts +9 -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 +2 -2
- package/dist/internal/gatewaySettings.d.ts.map +1 -1
- package/dist/internal/gatewaySettings.js +0 -6
- 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/remoteMcp.d.ts +4 -6
- package/dist/internal/remoteMcp.d.ts.map +1 -1
- package/dist/internal/remoteMcp.js +7 -10
- 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
|
@@ -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,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,EAEL,KAAK,gBAAgB,EACtB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,CAAC;AACvC,YAAY,EA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,mBAAmB,CACvC,OAAO,EAAE,OAAO,GAAG,OAAO,EAC1B,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,YAAY,CAAC,CAevB;AA0BD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAEnE;AAED,wEAAwE;AACxE,wBAAgB,QAAQ,CACtB,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,IAAI,SAAS,oBAAoB,GAAG,gBAAgB,EAEpD,OAAO,EAAE,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,EACpC,OAAO,GAAE,eAAe,CAAC,IAAI,CAAM,GAClC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CA2D5B"}
|
package/dist/server/everyApp.js
CHANGED
|
@@ -17,20 +17,19 @@
|
|
|
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 { APP_ID_ENV, AUDIENCE_ENV, ConfigurationError, DEV_ENV, IdentityError, IDENTITY_HEADER, ISSUER_ENV, ORG_ID_ENV, PUBLIC_KEYS_ENV, getIdentityFromRequest, isAdmin,
|
|
28
|
+
import { APP_ID_ENV, AUDIENCE_ENV, ConfigurationError, DEV_ENV, IdentityError, IDENTITY_HEADER, ISSUER_ENV, ORG_ID_ENV, PUBLIC_KEYS_ENV, getIdentityFromRequest, isAdmin, } from "../internal/index.js";
|
|
30
29
|
import { currentUser, serveRequest } from "./context.js";
|
|
31
30
|
import { handleToolsRequest } from "./toolsEndpoint.js";
|
|
32
31
|
import { handleEventsRequest, } from "./eventsEndpoint.js";
|
|
33
|
-
export { ConfigurationError,
|
|
32
|
+
export { ConfigurationError, isAdmin };
|
|
34
33
|
const requestIdentities = new WeakMap();
|
|
35
34
|
function envValue(env, key) {
|
|
36
35
|
if (!env || typeof env !== "object")
|
|
@@ -38,9 +37,8 @@ function envValue(env, key) {
|
|
|
38
37
|
const value = env[key];
|
|
39
38
|
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
40
39
|
}
|
|
41
|
-
function configFrom(
|
|
40
|
+
function configFrom(options) {
|
|
42
41
|
return {
|
|
43
|
-
manifestAppId: manifest?.id,
|
|
44
42
|
issuer: options.issuer,
|
|
45
43
|
keysEnvVar: options.keysEnvVar ?? PUBLIC_KEYS_ENV,
|
|
46
44
|
publicKeys: options.publicKeys,
|
|
@@ -48,16 +46,9 @@ function configFrom(manifest, options = {}) {
|
|
|
48
46
|
now: options.now,
|
|
49
47
|
};
|
|
50
48
|
}
|
|
51
|
-
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
*/
|
|
55
|
-
function appIdFor(env, config) {
|
|
56
|
-
const fromEnv = envValue(env, APP_ID_ENV);
|
|
57
|
-
if (fromEnv && config.manifestAppId && fromEnv !== config.manifestAppId) {
|
|
58
|
-
throw new ConfigurationError(`${APP_ID_ENV} ("${fromEnv}") does not match the manifest id ("${config.manifestAppId}").`);
|
|
59
|
-
}
|
|
60
|
-
return fromEnv ?? config.manifestAppId;
|
|
49
|
+
/** The app id, from EVERYAPP_APP_ID (which `everyAppWorker()` sets). */
|
|
50
|
+
function appIdFor(env) {
|
|
51
|
+
return envValue(env, APP_ID_ENV);
|
|
61
52
|
}
|
|
62
53
|
function devIdentitiesAllowed(env, config) {
|
|
63
54
|
const devEnv = envValue(env, DEV_ENV);
|
|
@@ -73,7 +64,7 @@ function devIdentitiesAllowed(env, config) {
|
|
|
73
64
|
* app id stand in when EVERYAPP_AUDIENCE is unset.
|
|
74
65
|
*/
|
|
75
66
|
function audienceFor(env, config) {
|
|
76
|
-
const appId = appIdFor(env
|
|
67
|
+
const appId = appIdFor(env);
|
|
77
68
|
const audience = envValue(env, AUDIENCE_ENV);
|
|
78
69
|
if (audience)
|
|
79
70
|
return audience;
|
|
@@ -155,7 +146,6 @@ const servedRequests = new WeakMap();
|
|
|
155
146
|
* (a framework that hands out headers alone needs no made-up Request).
|
|
156
147
|
* Answers from the request context or the per-request cache first, then
|
|
157
148
|
* verifies the identity headers from the audience and public keys in env.
|
|
158
|
-
* Inside a handler `everyApp()` serves, `currentUser()` is the shorter way.
|
|
159
149
|
*/
|
|
160
150
|
export async function getEveryAppUser(request, env) {
|
|
161
151
|
const cached = requestIdentities.get(request);
|
|
@@ -189,19 +179,6 @@ export async function requireEveryAppUser(request, env) {
|
|
|
189
179
|
throw error;
|
|
190
180
|
}
|
|
191
181
|
}
|
|
192
|
-
/**
|
|
193
|
-
* The user of the request being served (`currentUser()`), or throw the
|
|
194
|
-
* same 401 JSON Response as `requireEveryAppUser()` on a public route.
|
|
195
|
-
* Outside a request (`withOrganization()` work, a handler not under
|
|
196
|
-
* `everyApp()`) it throws `RequestContextError`, as `currentUser()` does.
|
|
197
|
-
*/
|
|
198
|
-
export function requireCurrentUser() {
|
|
199
|
-
const user = currentUser();
|
|
200
|
-
if (!user) {
|
|
201
|
-
throw unauthorized("this request does not have an authenticated user");
|
|
202
|
-
}
|
|
203
|
-
return user;
|
|
204
|
-
}
|
|
205
182
|
/**
|
|
206
183
|
* `response` without `Set-Cookie`: the perimeter strips every `Cookie`
|
|
207
184
|
* before a request reaches the app, so no cookie the app sets ever comes
|
|
@@ -226,26 +203,16 @@ function withoutCookies(response) {
|
|
|
226
203
|
export function hasScope(user, scope) {
|
|
227
204
|
return user.scopes.includes("*") || user.scopes.includes(scope);
|
|
228
205
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
typeof value.id === "string");
|
|
233
|
-
}
|
|
234
|
-
export function everyApp(handler, manifestOrOptions, legacyOptions = {}) {
|
|
235
|
-
const manifest = isManifest(manifestOrOptions)
|
|
236
|
-
? manifestOrOptions
|
|
237
|
-
: undefined;
|
|
238
|
-
const options = manifest || manifestOrOptions === undefined
|
|
239
|
-
? legacyOptions
|
|
240
|
-
: manifestOrOptions;
|
|
241
|
-
const config = configFrom(manifest, options);
|
|
206
|
+
/** Wrap a Worker fetch handler with Every App identity verification. */
|
|
207
|
+
export function everyApp(handler, options = {}) {
|
|
208
|
+
const config = configFrom(options);
|
|
242
209
|
return {
|
|
243
210
|
async fetch(request, env, ctx) {
|
|
244
211
|
let audience;
|
|
245
212
|
let appId;
|
|
246
213
|
try {
|
|
247
214
|
audience = audienceFor(env, config);
|
|
248
|
-
appId = appIdFor(env
|
|
215
|
+
appId = appIdFor(env) ?? audience;
|
|
249
216
|
}
|
|
250
217
|
catch (err) {
|
|
251
218
|
if (err instanceof ConfigurationError) {
|
|
@@ -31,7 +31,7 @@ export interface CreateGatewayFetchOptions {
|
|
|
31
31
|
/**
|
|
32
32
|
* Whom the call is for. Left out, the request `everyApp()` is serving
|
|
33
33
|
* (its user, while the identity is good) or the organization
|
|
34
|
-
*
|
|
34
|
+
* an event delivery runs under; outside both, `RequestContextError`.
|
|
35
35
|
* Explicitly: the inbound request, or `{ background: true,
|
|
36
36
|
* organizationId }` for work no person started (crons, Workflows,
|
|
37
37
|
* queues). A shared app's Worker must end up with one or the other
|
|
@@ -179,7 +179,7 @@ function directProviderPath(input, env) {
|
|
|
179
179
|
// names a model sends it as it is).
|
|
180
180
|
const values = env;
|
|
181
181
|
const resolution = resolveAiDefault({
|
|
182
|
-
|
|
182
|
+
choice: null,
|
|
183
183
|
isSet: (name) => typeof values[name] === "string" &&
|
|
184
184
|
values[name].trim().length > 0,
|
|
185
185
|
});
|
package/dist/server/index.d.ts
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* There is intentionally no client-side export.
|
|
5
5
|
*/
|
|
6
|
-
export { ConfigurationError,
|
|
7
|
-
export { OrganizationMismatchError, RequestContextError, currentUser, withOrganization, } from "./context.js";
|
|
6
|
+
export { ConfigurationError, everyApp, getEveryAppUser, hasScope, isAdmin, requireEveryAppUser, type EveryAppOptions, type EveryAppHandler, type EveryAppUser, type IdentityResult, type OrgRole, } from "./everyApp.js";
|
|
8
7
|
export { AttributionError, type GatewayCallFor } from "./attribution.js";
|
|
9
8
|
export { gatewayUrl } from "./gatewayUrl.js";
|
|
10
9
|
export type { EveryAppEnv } from "./env.js";
|
|
@@ -12,13 +11,11 @@ export type { EveryAppEnv } from "./env.js";
|
|
|
12
11
|
export { GATEWAY_ERROR_HEADER } from "../internal/protocol.js";
|
|
13
12
|
export { connectPath, connectUrl, type ConnectUrlOptions, } from "./connectUrl.js";
|
|
14
13
|
export { createGatewayFetch, type CreateGatewayFetchOptions, } from "./gatewayFetch.js";
|
|
15
|
-
export {
|
|
16
|
-
export {
|
|
14
|
+
export { aiBaseUrl, providerBaseUrl } from "./ai.js";
|
|
15
|
+
export { GatewayRefusalError, gatewayRefusal, refusalFromError, type GatewayRefusal, type SetupInfo, } from "./refusal.js";
|
|
17
16
|
export { devAccessTokenName, integrationFetch, integrationStatus, type EmailIntegrationStatus, type IntegrationFetchOptions, type IntegrationStatus, type IntegrationStatusOf, type OAuthClientIntegrationStatus, } from "./integrationFetch.js";
|
|
18
17
|
export { nodeServerHandler, type NodeServer, type NodeServerHandlerOptions, } from "./nodeServer.js";
|
|
19
18
|
export { sendEmail, type SendEmailOptions } from "./sendEmail.js";
|
|
20
|
-
export { gatewayAiBinding, type GatewayAiBindingOptions } from "./aiBinding.js";
|
|
21
|
-
export { gatewayEmailBinding, type GatewayEmailBindingMessage, type GatewayEmailBindingOptions, } from "./emailBinding.js";
|
|
22
19
|
export { listMembers, type ListMembersOptions } from "./listMembers.js";
|
|
23
20
|
export { emit, type EmitOptions } from "./emit.js";
|
|
24
21
|
export { WEBHOOK_MAX_BYTES_DEFAULT, verifyWebhook, type VerifyWebhookOptions, type WebhookProvider, type WebhookRefusalReason, type WebhookVerification, } from "./webhooks.js";
|
|
@@ -26,5 +23,4 @@ export type { AppEvent, AppEventHandler, AppEventsOptions, } from "./eventsEndpo
|
|
|
26
23
|
export type { ApiKeyCapabilityId, CapabilityId, OAuthClientCapabilityId, EmailAddressInput, EmailAttachmentInput, SendEmailMessage, SendEmailResult, ListMembersResult, OrganizationMember, OrganizationMemberRole, EmitEventResult, } from "../internal/index.js";
|
|
27
24
|
export { ToolError, defineTools, toolResult, type DefineToolsOptions, type PlainToolSchema, type StandardSchemaWithJSON, type ToolContext, type ToolDefinition, type ToolResult, type ToolSchema, type ToolSet, } from "./tools.js";
|
|
28
25
|
export type { ToolRisk } from "../internal/index.js";
|
|
29
|
-
export { fromMcpTools, type FromMcpToolsOptions, type McpToolAnnotationsLike, type McpToolLike, type McpToolResultLike, type McpToolSchemaLike, } from "./fromMcpTools.js";
|
|
30
26
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,kBAAkB,EAClB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,kBAAkB,EAClB,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,OAAO,EACP,mBAAmB,EACnB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,OAAO,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAA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qB,CAAC;AAC7B,YAAY,EACV,kBAAkB,EAClB,YAAY,EACZ,uBAAuB,EACvB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,SAAS,EACT,WAAW,EACX,UAAU,EACV,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,OAAO,GACb,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/server/index.js
CHANGED
|
@@ -3,23 +3,19 @@
|
|
|
3
3
|
*
|
|
4
4
|
* There is intentionally no client-side export.
|
|
5
5
|
*/
|
|
6
|
-
export { ConfigurationError,
|
|
7
|
-
export { OrganizationMismatchError, RequestContextError, currentUser, withOrganization, } from "./context.js";
|
|
6
|
+
export { ConfigurationError, everyApp, getEveryAppUser, hasScope, isAdmin, requireEveryAppUser, } from "./everyApp.js";
|
|
8
7
|
export { AttributionError } from "./attribution.js";
|
|
9
8
|
export { gatewayUrl } from "./gatewayUrl.js";
|
|
10
9
|
/** The header a Gateway refusal carries its code in; `gatewayRefusal()` reads the rest. */
|
|
11
10
|
export { GATEWAY_ERROR_HEADER } from "../internal/protocol.js";
|
|
12
11
|
export { connectPath, connectUrl, } from "./connectUrl.js";
|
|
13
12
|
export { createGatewayFetch, } from "./gatewayFetch.js";
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
13
|
+
export { aiBaseUrl, providerBaseUrl } from "./ai.js";
|
|
14
|
+
export { GatewayRefusalError, gatewayRefusal, refusalFromError, } from "./refusal.js";
|
|
16
15
|
export { devAccessTokenName, integrationFetch, integrationStatus, } from "./integrationFetch.js";
|
|
17
16
|
export { nodeServerHandler, } from "./nodeServer.js";
|
|
18
17
|
export { sendEmail } from "./sendEmail.js";
|
|
19
|
-
export { gatewayAiBinding } from "./aiBinding.js";
|
|
20
|
-
export { gatewayEmailBinding, } from "./emailBinding.js";
|
|
21
18
|
export { listMembers } from "./listMembers.js";
|
|
22
19
|
export { emit } from "./emit.js";
|
|
23
20
|
export { WEBHOOK_MAX_BYTES_DEFAULT, verifyWebhook, } from "./webhooks.js";
|
|
24
21
|
export { ToolError, defineTools, toolResult, } from "./tools.js";
|
|
25
|
-
export { fromMcpTools, } from "./fromMcpTools.js";
|
|
@@ -21,7 +21,7 @@ export interface IntegrationFetchOptions {
|
|
|
21
21
|
/**
|
|
22
22
|
* Whom the call is for. Left out, the request `everyApp()` is serving
|
|
23
23
|
* (its person, while the identity is good) or the organization
|
|
24
|
-
*
|
|
24
|
+
* an event delivery runs under; outside both, `RequestContextError`.
|
|
25
25
|
* Explicitly: the inbound request, or `{ background: true,
|
|
26
26
|
* organizationId }` for work no person started (crons, Workflows,
|
|
27
27
|
* queues). A shared app's Worker must end up with one or the other
|
package/dist/server/refusal.d.ts
CHANGED
|
@@ -14,8 +14,6 @@ export interface GatewayRefusal extends SetupInfo {
|
|
|
14
14
|
code: string;
|
|
15
15
|
message: string;
|
|
16
16
|
}
|
|
17
|
-
/** The refusal codes that mean no model is set up for the call. */
|
|
18
|
-
export declare const AI_NOT_CONFIGURED_CODES: readonly string[];
|
|
19
17
|
/**
|
|
20
18
|
* A refusal the AppGateway binding made, thrown: what `sendEmail()` throws
|
|
21
19
|
* when the gateway won't send (`email_sender_not_allowed`,
|
|
@@ -45,11 +43,4 @@ export declare function gatewayRefusal(response: Response): Promise<GatewayRefus
|
|
|
45
43
|
* (`ai_provider_not_configured`, status 503, the `.dev.vars` names).
|
|
46
44
|
*/
|
|
47
45
|
export declare function refusalFromError(error: unknown): GatewayRefusal | null;
|
|
48
|
-
/**
|
|
49
|
-
* Whether `error` (or a refusal already read) means no model is set up:
|
|
50
|
-
* `ai_provider_not_configured` or `ai_default_not_configured`, from the
|
|
51
|
-
* Gateway or, in local development, from the SDK with no key in
|
|
52
|
-
* `.dev.vars`. Show `refusalFromError(error).setup` to the person.
|
|
53
|
-
*/
|
|
54
|
-
export declare function isAiNotConfigured(error: unknown): boolean;
|
|
55
46
|
//# sourceMappingURL=refusal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../../src/server/refusal.ts"],"names":[],"mappings":"AAgBA,wDAAwD;AACxD,MAAM,WAAW,SAAS;IACxB,kGAAkG;IAClG,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,8EAA8E;IAC9E,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,0EAA0E;IAC1E,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,sEAAsE;AACtE,MAAM,WAAW,cAAe,SAAQ,SAAS;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED
|
|
1
|
+
{"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../../src/server/refusal.ts"],"names":[],"mappings":"AAgBA,wDAAwD;AACxD,MAAM,WAAW,SAAS;IACxB,kGAAkG;IAClG,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,8EAA8E;IAC9E,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,0EAA0E;IAC1E,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,sEAAsE;AACtE,MAAM,WAAW,cAAe,SAAQ,SAAS;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,KAAM,YAAW,cAAc;IACtE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;gBAEpB,EACV,MAAM,EACN,IAAI,EACJ,OAAO,EACP,QAAa,EACb,KAAY,EACZ,OAAc,GACf,EAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC;CAS5E;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAKhC;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,CAWtE"}
|
package/dist/server/refusal.js
CHANGED
|
@@ -13,11 +13,6 @@
|
|
|
13
13
|
* match the message text or hardcode a setting name or a command.
|
|
14
14
|
*/
|
|
15
15
|
import { ConfigurationError, GATEWAY_ERROR_HEADER } from "../internal/index.js";
|
|
16
|
-
/** The refusal codes that mean no model is set up for the call. */
|
|
17
|
-
export const AI_NOT_CONFIGURED_CODES = [
|
|
18
|
-
"ai_provider_not_configured",
|
|
19
|
-
"ai_default_not_configured",
|
|
20
|
-
];
|
|
21
16
|
/**
|
|
22
17
|
* A refusal the AppGateway binding made, thrown: what `sendEmail()` throws
|
|
23
18
|
* when the gateway won't send (`email_sender_not_allowed`,
|
|
@@ -73,23 +68,6 @@ export function refusalFromError(error) {
|
|
|
73
68
|
}
|
|
74
69
|
return null;
|
|
75
70
|
}
|
|
76
|
-
/**
|
|
77
|
-
* Whether `error` (or a refusal already read) means no model is set up:
|
|
78
|
-
* `ai_provider_not_configured` or `ai_default_not_configured`, from the
|
|
79
|
-
* Gateway or, in local development, from the SDK with no key in
|
|
80
|
-
* `.dev.vars`. Show `refusalFromError(error).setup` to the person.
|
|
81
|
-
*/
|
|
82
|
-
export function isAiNotConfigured(error) {
|
|
83
|
-
const refusal = isRefusal(error) ? error : refusalFromError(error);
|
|
84
|
-
return refusal !== null && AI_NOT_CONFIGURED_CODES.includes(refusal.code);
|
|
85
|
-
}
|
|
86
|
-
function isRefusal(value) {
|
|
87
|
-
return (!!value &&
|
|
88
|
-
typeof value === "object" &&
|
|
89
|
-
!(value instanceof Error) &&
|
|
90
|
-
typeof value.code === "string" &&
|
|
91
|
-
typeof value.status === "number");
|
|
92
|
-
}
|
|
93
71
|
function refusalHere(error) {
|
|
94
72
|
// A Response is read with gatewayRefusal(), which can read its body.
|
|
95
73
|
if (error instanceof Response)
|
package/dist/server/tools.d.ts
CHANGED
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
*
|
|
18
18
|
* Apps never speak MCP. The gateway snapshots this catalog at deploy, serves
|
|
19
19
|
* MCP clients from the snapshot, and calls a tool over the internal tools
|
|
20
|
-
* contract (../internal/tools.ts) with a verified `chan: "mcp"`
|
|
21
|
-
*
|
|
20
|
+
* contract (../internal/tools.ts) with a verified `chan: "mcp"`
|
|
21
|
+
* identity.
|
|
22
22
|
*
|
|
23
23
|
* `input` and `output` accept any validator implementing Standard Schema and
|
|
24
24
|
* Standard JSON Schema (zod >= 4.2 does both), or a plain
|
|
@@ -83,9 +83,8 @@ export type ToolSchema<Output = unknown> = StandardSchemaWithJSON<unknown, Outpu
|
|
|
83
83
|
/** What a tool handler receives besides its validated input. */
|
|
84
84
|
export interface ToolContext<TEnv = Cloudflare.Env> {
|
|
85
85
|
/**
|
|
86
|
-
* The verified caller. `channel` is "mcp" (an AI client)
|
|
87
|
-
*
|
|
88
|
-
* its sponsor); `toolCall` names this call.
|
|
86
|
+
* The verified caller. `channel` is "mcp" (an AI client); `toolCall`
|
|
87
|
+
* names this call.
|
|
89
88
|
*/
|
|
90
89
|
user: EveryAppUser;
|
|
91
90
|
env: TEnv;
|
|
@@ -100,11 +99,15 @@ export interface ToolDefinition<TInput = unknown> {
|
|
|
100
99
|
/** What the tool does and when to use it. The model reads this. */
|
|
101
100
|
description: string;
|
|
102
101
|
/**
|
|
103
|
-
* `read` changes nothing
|
|
104
|
-
*
|
|
105
|
-
* destructive tools until approvals exist.
|
|
102
|
+
* `read` changes nothing; read-only connections and tokens may call it.
|
|
103
|
+
* `write` creates, changes or deletes data.
|
|
106
104
|
*/
|
|
107
105
|
risk: ToolRisk;
|
|
106
|
+
/**
|
|
107
|
+
* A write tool that deletes or can't be undone. Clients see
|
|
108
|
+
* `destructiveHint: true` and ask the person before calling it.
|
|
109
|
+
*/
|
|
110
|
+
destructive?: boolean;
|
|
108
111
|
/** Arguments schema; must describe an object. */
|
|
109
112
|
input: ToolSchema<TInput>;
|
|
110
113
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/server/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAE1D,4DAA4D;AAC5D,eAAO,MAAM,WAAW,UAAU,CAAC;AASnC;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM;CAI5B;AAID,KAAK,mBAAmB,GAAG,WAAW,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAA;CAAE,CAAC;AAEvE,UAAU,aAAa;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,mBA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CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;CAAE,EAC3D,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CA+BT;AAuOD,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAC3B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GACtB;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,WAAW,EAAE,CAAA;CAAE,CAAC;AAEzC,qCAAqC;AACrC,wBAAsB,kBAAkB,CAAC,CAAC,EACxC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EACrB,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAQ/B;AAiBD;;;GAGG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,cAAc,EAC1B,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,gBAAgB,CAAC,CAuC3B"}
|
package/dist/server/tools.js
CHANGED
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
*
|
|
18
18
|
* Apps never speak MCP. The gateway snapshots this catalog at deploy, serves
|
|
19
19
|
* MCP clients from the snapshot, and calls a tool over the internal tools
|
|
20
|
-
* contract (../internal/tools.ts) with a verified `chan: "mcp"`
|
|
21
|
-
*
|
|
20
|
+
* contract (../internal/tools.ts) with a verified `chan: "mcp"`
|
|
21
|
+
* identity.
|
|
22
22
|
*
|
|
23
23
|
* `input` and `output` accept any validator implementing Standard Schema and
|
|
24
24
|
* Standard JSON Schema (zod >= 4.2 does both), or a plain
|
|
@@ -115,7 +115,9 @@ function assertToolDefinition(name, definition) {
|
|
|
115
115
|
throw problem("needs a description");
|
|
116
116
|
}
|
|
117
117
|
if (!isToolRisk(definition.risk)) {
|
|
118
|
-
throw problem(
|
|
118
|
+
throw problem(definition.risk === "destructive"
|
|
119
|
+
? 'needs a risk: "read" or "write"; a tool that deletes is risk: "write" with destructive: true'
|
|
120
|
+
: 'needs a risk: "read" or "write"');
|
|
119
121
|
}
|
|
120
122
|
if (!isToolSchema(definition.input)) {
|
|
121
123
|
throw problem("input must be a Standard Schema with JSON Schema support (zod >= 4.2) or { jsonSchema, validate }");
|
|
@@ -129,12 +131,15 @@ function assertToolDefinition(name, definition) {
|
|
|
129
131
|
if (definition.title !== undefined && typeof definition.title !== "string") {
|
|
130
132
|
throw problem("title must be a string");
|
|
131
133
|
}
|
|
132
|
-
for (const flag of ["idempotent", "openWorld"]) {
|
|
134
|
+
for (const flag of ["destructive", "idempotent", "openWorld"]) {
|
|
133
135
|
if (definition[flag] !== undefined &&
|
|
134
136
|
typeof definition[flag] !== "boolean") {
|
|
135
137
|
throw problem(`${flag} must be a boolean`);
|
|
136
138
|
}
|
|
137
139
|
}
|
|
140
|
+
if (definition.destructive && definition.risk === "read") {
|
|
141
|
+
throw problem('is destructive, so its risk is "write"');
|
|
142
|
+
}
|
|
138
143
|
}
|
|
139
144
|
function isRecord(value) {
|
|
140
145
|
return ((typeof value === "object" || typeof value === "function") && value !== null);
|
|
@@ -197,6 +202,7 @@ function describeTool(name, definition) {
|
|
|
197
202
|
if (typeof outputSchema === "string")
|
|
198
203
|
return outputSchema;
|
|
199
204
|
const annotations = {
|
|
205
|
+
...(definition.destructive ? { destructiveHint: true } : {}),
|
|
200
206
|
...(definition.idempotent !== undefined
|
|
201
207
|
? { idempotentHint: definition.idempotent }
|
|
202
208
|
: {}),
|
|
@@ -7,9 +7,8 @@
|
|
|
7
7
|
* - `/__everyapp/tools/list` needs the gateway's system token for this app
|
|
8
8
|
* (purpose "tools.list"). It describes tools; it never runs them.
|
|
9
9
|
* - `/__everyapp/tools/call` needs an identity token minted for this exact
|
|
10
|
-
* call: `chan: "mcp"` (an AI client's MCP connection)
|
|
11
|
-
*
|
|
12
|
-
* plus a `tc` claim naming the tool and call id. The
|
|
10
|
+
* call: `chan: "mcp"` (an AI client's MCP connection) plus a `tc` claim
|
|
11
|
+
* naming the tool and call id. The
|
|
13
12
|
* token's scopes must include the scope the tool's risk requires; `*` does
|
|
14
13
|
* not count, because the ToolBus only ever mints explicit scopes.
|
|
15
14
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolsEndpoint.d.ts","sourceRoot":"","sources":["../../src/server/toolsEndpoint.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"toolsEndpoint.d.ts","sourceRoot":"","sources":["../../src/server/toolsEndpoint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAcL,KAAK,sBAAsB,EAO5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAOL,KAAK,OAAO,EACb,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC;IACd,sEAAsE;IACtE,QAAQ,EAAE,sBAAsB,CAAC;CAClC;AAoFD;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,oBAAoB,EACzB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAyB1B"}
|
|
@@ -7,16 +7,15 @@
|
|
|
7
7
|
* - `/__everyapp/tools/list` needs the gateway's system token for this app
|
|
8
8
|
* (purpose "tools.list"). It describes tools; it never runs them.
|
|
9
9
|
* - `/__everyapp/tools/call` needs an identity token minted for this exact
|
|
10
|
-
* call: `chan: "mcp"` (an AI client's MCP connection)
|
|
11
|
-
*
|
|
12
|
-
* plus a `tc` claim naming the tool and call id. The
|
|
10
|
+
* call: `chan: "mcp"` (an AI client's MCP connection) plus a `tc` claim
|
|
11
|
+
* naming the tool and call id. The
|
|
13
12
|
* token's scopes must include the scope the tool's risk requires; `*` does
|
|
14
13
|
* not count, because the ToolBus only ever mints explicit scopes.
|
|
15
14
|
*
|
|
16
15
|
* The perimeter also refuses these paths from outside and strips inbound
|
|
17
16
|
* `x-everyapp-*` headers, so only the gateway's ToolBus ever reaches them.
|
|
18
17
|
*/
|
|
19
|
-
import { ConfigurationError, IDENTITY_HEADER, IdentityError, SYSTEM_HEADER,
|
|
18
|
+
import { ConfigurationError, IDENTITY_HEADER, IdentityError, SYSTEM_HEADER, TOOLS_CALL_PATH, TOOLS_LIST_PATH, TOOLS_PROTOCOL_VERSION, assertOrganizationPin, catalogHash, requiredScopeForRisk, resolveVerifyOptions, verifyIdentity, verifySystemJwt, } from "../internal/index.js";
|
|
20
19
|
import { serveRequest } from "./context.js";
|
|
21
20
|
import { SDK_VERSION, ToolError, toToolResult, toolSetInternals, validateWithSchema, } from "./tools.js";
|
|
22
21
|
function toolsJson(status, body, headers = {}) {
|
|
@@ -164,11 +163,7 @@ async function callTool(request, env, ctx, verify, options) {
|
|
|
164
163
|
}
|
|
165
164
|
throw error;
|
|
166
165
|
}
|
|
167
|
-
if (!
|
|
168
|
-
!user.toolCall ||
|
|
169
|
-
// An agent call names its agent; a `chan: "agent"` token without one
|
|
170
|
-
// is not something the ToolBus mints.
|
|
171
|
-
(user.channel === "agent" && !isAgentCall(user))) {
|
|
166
|
+
if (user.channel !== "mcp" || !user.toolCall) {
|
|
172
167
|
return toolsError(403, "forbidden", "Tool calls need an identity the gateway minted for this call.");
|
|
173
168
|
}
|
|
174
169
|
const call = parseCallRequest(await readJsonBody(request));
|
|
@@ -204,8 +199,8 @@ async function callTool(request, env, ctx, verify, options) {
|
|
|
204
199
|
});
|
|
205
200
|
let result;
|
|
206
201
|
try {
|
|
207
|
-
// The call runs in the request context like a page would:
|
|
208
|
-
//
|
|
202
|
+
// The call runs in the request context like a page would: its Gateway
|
|
203
|
+
// calls are attributed to the caller.
|
|
209
204
|
const value = await serveRequest({ request, user, expiresAt }, () => tool.handler(input.value, {
|
|
210
205
|
user,
|
|
211
206
|
env: env,
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -67,9 +67,8 @@ export interface TestWorker {
|
|
|
67
67
|
export interface CallToolOptions {
|
|
68
68
|
user?: TestUser;
|
|
69
69
|
/**
|
|
70
|
-
* The caller's scopes. Default: `mcp:read
|
|
71
|
-
*
|
|
72
|
-
* refusal.
|
|
70
|
+
* The caller's scopes. Default: `mcp:read` and `mcp:write`, so every
|
|
71
|
+
* tool may be called; pass `["mcp:read"]` to test a refusal.
|
|
73
72
|
*/
|
|
74
73
|
scopes?: string[];
|
|
75
74
|
/** Default: {@link testEnv}() for the worker's app. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAuBA,OAAO,EAIL,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAuBA,OAAO,EAIL,eAAe,EAQf,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACzB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,CAAC;AAC3B,YAAY,EACV,gBAAgB,IAAI,cAAc,EAClC,mBAAmB,IAAI,gBAAgB,EACvC,mBAAmB,IAAI,iBAAiB,GACzC,CAAC;AAEF,iFAAiF;AACjF,MAAM,WAAW,QAAQ;IACvB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,sEAAsE;AACtE,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAKjD,CAAC;AAEH,0DAA0D;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CAUlB;AAED,2CAA2C;AAC3C,MAAM,WAAW,UAAU;IACzB,KAAK,CACH,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,KAAK,EACV,GAAG,EAAE,gBAAgB,GACpB,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,uDAAuD;IACvD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,gBAAgB,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,wBAAsB,QAAQ,CAC5B,GAAG,EAAE,UAAU,GAAG,OAAO,EACzB,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EAClC,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,mBAAmB,CAAC,CAoB9B;AAED,2EAA2E;AAC3E,wBAAsB,SAAS,CAC7B,GAAG,EAAE,UAAU,GAAG,OAAO,EACzB,OAAO,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,gBAAgB,CAAA;CAAO,GACrD,OAAO,CAAC,mBAAmB,CAAC,CAuB9B"}
|
package/dist/testing/index.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* deployed Worker. For tests only; a Worker never imports this module.
|
|
18
18
|
*/
|
|
19
19
|
import { DEV_ISSUER, DEV_PRIVATE_KEY_PEM, DEV_PUBLIC_KEY_PEM, } from "../dev/keypair.js";
|
|
20
|
-
import { APP_ID_ENV, AUDIENCE_ENV, IDENTITY_DEV_KEY_ID, IDENTITY_HEADER,
|
|
20
|
+
import { APP_ID_ENV, AUDIENCE_ENV, IDENTITY_DEV_KEY_ID, IDENTITY_HEADER, MCP_READ_SCOPE, MCP_WRITE_SCOPE, SYSTEM_HEADER, TOOLS_CALL_PATH, TOOLS_LIST_PATH, mintIdentityJwt, mintSystemJwt, } from "../internal/index.js";
|
|
21
21
|
import { everyApp } from "../server/everyApp.js";
|
|
22
22
|
export { IDENTITY_HEADER };
|
|
23
23
|
/** The person a test signs in by default: the owner of `org_test`. */
|
|
@@ -104,11 +104,7 @@ export async function callTool(app, name, args = {}, options = {}) {
|
|
|
104
104
|
user: options.user,
|
|
105
105
|
appId: audienceOf(env),
|
|
106
106
|
channel: "mcp",
|
|
107
|
-
scopes: options.scopes ?? [
|
|
108
|
-
MCP_READ_SCOPE,
|
|
109
|
-
MCP_WRITE_SCOPE,
|
|
110
|
-
MCP_DESTRUCTIVE_SCOPE,
|
|
111
|
-
],
|
|
107
|
+
scopes: options.scopes ?? [MCP_READ_SCOPE, MCP_WRITE_SCOPE],
|
|
112
108
|
toolCall: { id: callId, name },
|
|
113
109
|
});
|
|
114
110
|
const response = await workerOf(app).fetch(new Request(`https://app.test${TOOLS_CALL_PATH}`, {
|
package/package.json
CHANGED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `gatewayAiBinding(env)`: the Gateway's AI providers as a Workers AI
|
|
3
|
-
* binding, for code written against `env.AI.run(model, inputs, options)`.
|
|
4
|
-
*
|
|
5
|
-
* An app on Every App needs no `ai` binding of its own to call models: the
|
|
6
|
-
* Gateway holds the keys, counts the calls and keeps the app to `ai.models`.
|
|
7
|
-
* Code that already calls `env.AI.run()` (upstream code a port keeps, the
|
|
8
|
-
* Agents SDK, `workers-ai-provider`) gets this object in its place:
|
|
9
|
-
*
|
|
10
|
-
* const AI = gatewayAiBinding(env, { for: request });
|
|
11
|
-
* await AI.run("@cf/meta/llama-3.1-8b-instruct-fast", { messages });
|
|
12
|
-
*
|
|
13
|
-
* Each `run()` becomes an OpenAI-compatible call on the provider's route
|
|
14
|
-
* through the Gateway (`createGatewayFetch`): text generation (`messages`
|
|
15
|
-
* or `prompt`) on its chat completions route, text embeddings (`text`) on
|
|
16
|
-
* its embeddings route, answered in Workers AI's shapes (`{ response,
|
|
17
|
-
* tool_calls, usage }`, `{ shape, data }`, or a stream of `data:
|
|
18
|
-
* {"response": …}` events with `stream: true`). In local development
|
|
19
|
-
* without a Gateway, the developer's own key in `.dev.vars` is used, as
|
|
20
|
-
* `createGatewayFetch` does (WORKERS_AI_API_TOKEN and CLOUDFLARE_ACCOUNT_ID
|
|
21
|
-
* for Workers AI).
|
|
22
|
-
*/
|
|
23
|
-
import { AI_DEFAULT_PROVIDER, type AiProviderId } from "../internal/index.js";
|
|
24
|
-
import type { GatewayCallFor } from "./attribution.js";
|
|
25
|
-
export interface GatewayAiBindingOptions {
|
|
26
|
-
/**
|
|
27
|
-
* Whom the calls are for: the inbound request, or `{ background: true,
|
|
28
|
-
* organizationId }` (createGatewayFetch's `for`).
|
|
29
|
-
*/
|
|
30
|
-
for?: GatewayCallFor;
|
|
31
|
-
/**
|
|
32
|
-
* The Gateway provider the calls go to: an `ai` entry of the catalog
|
|
33
|
-
* with OpenAI-compatible routes (`workers-ai`, `openrouter`, `openai`,
|
|
34
|
-
* …), or `default`, the operator's model (`ai: { chat: true }`).
|
|
35
|
-
* Default: `workers-ai`, the provider `env.AI` reaches, so `@cf/…` model
|
|
36
|
-
* ids work as they are. The manifest lists the provider under
|
|
37
|
-
* `providers` (or says `ai.chat` for `default`).
|
|
38
|
-
*/
|
|
39
|
-
provider?: AiProviderId | typeof AI_DEFAULT_PROVIDER;
|
|
40
|
-
/**
|
|
41
|
-
* The model id to send for a model the code names, e.g.
|
|
42
|
-
* `{ "@cf/meta/llama-3.1-8b-instruct-fast": "meta-llama/llama-3.1-8b-instruct" }`
|
|
43
|
-
* with `provider: "openrouter"`. A model not listed is sent as it is,
|
|
44
|
-
* except that on `default` an `@cf/…` id becomes `default` (the
|
|
45
|
-
* operator's model).
|
|
46
|
-
*/
|
|
47
|
-
models?: Readonly<Record<string, string>>;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* A Workers AI binding (`Ai`) over the Gateway: pass it where code takes
|
|
51
|
-
* `env.AI`. `run()` covers text generation (messages or prompt; tools;
|
|
52
|
-
* `stream: true`; `returnRawResponse`, which returns the provider's
|
|
53
|
-
* OpenAI-shaped `Response`) and text embeddings; the binding's other
|
|
54
|
-
* methods (`gateway()`, `autorag()`, `models()`, `toMarkdown()`, …) and
|
|
55
|
-
* other tasks (images, audio, batches, websockets) throw
|
|
56
|
-
* `ConfigurationError`. `options.gateway` is ignored: the Gateway's
|
|
57
|
-
* operator decides whether calls go through Cloudflare AI Gateway
|
|
58
|
-
* (`everyapp ai gateway on`).
|
|
59
|
-
*
|
|
60
|
-
* Errors are thrown as a binding throws them: `GatewayRefusalError` when
|
|
61
|
-
* the Gateway refused (`ai_provider_not_configured`, `model_not_allowed`,
|
|
62
|
-
* …), `ConfigurationError` where createGatewayFetch throws one (no binding
|
|
63
|
-
* and no dev key), and an `Error` naming the status when the provider
|
|
64
|
-
* answered with an error. Nothing is checked when the binding is made, so
|
|
65
|
-
* making one per request costs nothing.
|
|
66
|
-
*/
|
|
67
|
-
export declare function gatewayAiBinding(env: object, options?: GatewayAiBindingOptions): Ai;
|
|
68
|
-
//# sourceMappingURL=aiBinding.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aiBinding.d.ts","sourceRoot":"","sources":["../../src/server/aiBinding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAEL,mBAAmB,EAInB,KAAK,YAAY,EAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIvD,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,YAAY,GAAG,OAAO,mBAAmB,CAAC;IACrD;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC3C;AAUD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,uBAA4B,GACpC,EAAE,CAoEJ"}
|