apps 0.0.1-beta.67 → 0.0.1-beta.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/framework-reference.json +1 -1
  2. package/js/{chunk-5NQDJMLY.js → chunk-3R3KFCDU.js} +172 -12
  3. package/js/{chunk-MWKHKOTL.js → chunk-7LMU3ER3.js} +35 -1
  4. package/js/{chunk-WFPDJ4R3.js → chunk-CXDAEGXB.js} +3 -3
  5. package/js/{chunk-ZA6YCHLZ.js → chunk-CY4MT7PI.js} +5 -5
  6. package/js/{chunk-524HNOCY.js → chunk-DZN5TQ53.js} +83 -16
  7. package/js/{chunk-AZIV4XRH.js → chunk-ECCWT5GJ.js} +2 -2
  8. package/js/{chunk-5EOB55ID.js → chunk-FZB6D6ZD.js} +20 -10
  9. package/js/{chunk-6RH2UYRB.js → chunk-GJSNQSR7.js} +2 -2
  10. package/js/{chunk-TLWLJ7PD.js → chunk-JW5LYSER.js} +94 -3
  11. package/js/{chunk-T3FPHPJJ.js → chunk-MHB7IFG7.js} +1 -1
  12. package/js/{chunk-AQU56EPI.js → chunk-RUP4JMKO.js} +17 -10
  13. package/js/{chunk-X36WUWBJ.js → chunk-ZEJ3IKEC.js} +2 -2
  14. package/js/{chunk-K2VZ3O27.js → chunk-ZR7QAG67.js} +1 -1
  15. package/js/contracts.js +34 -2
  16. package/js/effect.js +9 -9
  17. package/js/graphql.js +11 -11
  18. package/js/host.js +9 -9
  19. package/js/index.js +59 -12
  20. package/js/mcp/effect.js +11 -11
  21. package/js/mcp/stdio.js +11 -11
  22. package/js/mcp.js +13 -13
  23. package/js/openapi.js +7 -7
  24. package/js/skills.js +5 -5
  25. package/package.json +1 -1
  26. package/runtime.json +1 -1
  27. package/types/app-cache/src/contracts/cache.d.ts +2 -0
  28. package/types/apps/src/contracts/host.d.ts +600 -2
  29. package/types/apps/src/contracts/network.d.ts +36 -0
  30. package/types/apps/src/contracts/placement.d.ts +102 -0
  31. package/types/apps/src/contracts/protocol-version.d.ts +1 -1
  32. package/types/apps/src/contracts/protocols/current.d.ts +1368 -2
  33. package/types/apps/src/contracts/provider.d.ts +25 -0
  34. package/types/apps/src/contracts/sql.d.ts +5 -0
  35. package/types/apps/src/implementation/openapi-compile.d.ts +3 -3
  36. package/types/apps/src/implementation/placement.d.ts +60 -0
  37. package/types/apps/src/implementation/provider.d.ts +8 -2
  38. package/types/apps/src/index.d.ts +27 -3
@@ -1,5 +1,6 @@
1
1
  /** Provider declarations use native Effect schemas. The trusted host interprets them. */
2
2
  import { Data, type Effect, Schema } from "effect";
3
+ import type { Placement } from "./placement.js";
3
4
  import { type AccountId } from "./schema.js";
4
5
  /**
5
6
  * How app code sees a field of a provider that declares hosts. Unmarked string fields are secret:
@@ -16,6 +17,8 @@ export declare class SecretsMethod<Fields extends Schema.Decoder<unknown>> exten
16
17
  readonly fields: Fields;
17
18
  /** Fields marked with `plain()` or `raw()`. */
18
19
  readonly exposure?: Readonly<Record<string, FieldExposure>>;
20
+ /** The only places the outbound network sends this method's secret fields; see `Placement`. */
21
+ readonly request?: readonly Placement[];
19
22
  }> {
20
23
  }
21
24
  /** How an OAuth client authenticates at the token endpoint; raw Basic is an explicit provider compatibility option. */
@@ -124,6 +127,8 @@ export declare class OAuth2Method<Response extends Schema.Decoder<unknown>> exte
124
127
  readonly response: Response;
125
128
  /** Response fields marked with `plain()` or `raw()`. */
126
129
  readonly exposure?: Readonly<Record<string, FieldExposure>>;
130
+ /** The only places the outbound network sends this method's secret fields; see `Placement`. */
131
+ readonly request?: readonly Placement[];
127
132
  }> {
128
133
  }
129
134
  /** Supported declarations; these acquire credentials rather than normalize them. */
@@ -205,12 +210,32 @@ export declare class ManyAccounts<Auth extends AuthMethods> extends ManyAccounts
205
210
  }
206
211
  /** Infer the data for one method from its native Effect decoder. */
207
212
  export type AuthMethodData<Method> = Method extends SecretsMethod<infer Fields> ? Fields["Type"] : Method extends OAuth2Method<infer Response> ? Response["Type"] : never;
213
+ /**
214
+ * Render an account's credential placements. Each renders the method's `request` with the fields
215
+ * app code holds, so a request built with them is one the outbound network accepts.
216
+ */
217
+ export interface AccountRequest {
218
+ /**
219
+ * The headers the method's `request` places credentials in, by lowercase name. Spread them into
220
+ * a request's headers. Throws when the method declares no `request`.
221
+ */
222
+ headers(): Record<string, string>;
223
+ /**
224
+ * `input` with the query parameters the method's `request` places credentials in, replacing any
225
+ * of the same name. Throws when the method declares no `request`.
226
+ */
227
+ url(input: string | URL): string;
228
+ }
208
229
  /** One account for these methods, discriminated by its author-chosen method name. */
209
230
  export type AccountOfMethods<Auth extends AuthMethods> = {
210
231
  readonly [Method in keyof Auth & string]: {
211
232
  readonly id: AccountId;
212
233
  readonly method: Method;
213
234
  readonly fields: AuthMethodData<Auth[Method]>;
235
+ /** See `AccountRequest`. */
236
+ readonly headers: AccountRequest["headers"];
237
+ /** See `AccountRequest`. */
238
+ readonly url: AccountRequest["url"];
214
239
  };
215
240
  }[keyof Auth & string];
216
241
  /** One selected account, discriminated by its author-chosen method name. */
@@ -56,3 +56,8 @@ export interface AppSqlStorage {
56
56
  export declare const reservedTablePrefix = "_executor_";
57
57
  /** Where an app keeps its migrations: `0001_create_notes.sql`, applied in number order. */
58
58
  export declare const migrationsDirectory = "migrations";
59
+ /**
60
+ * The most values one statement may bind. Durable Object SQLite sets `SQLITE_LIMIT_VARIABLE_NUMBER`
61
+ * to 100 on every host; `ctx.sql` checks it first so the error names the limit.
62
+ */
63
+ export declare const sqlBindingsLimit = 100;
@@ -24,11 +24,13 @@ export declare const compileOpenApiDocument: (entry: OpenApiImport, inputDocumen
24
24
  readonly fallbackSecurity?: GeneratedOperation["request"]["security"];
25
25
  }) => Effect.Effect<{
26
26
  operations: {
27
+ readonly method: "HEAD" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS" | "QUERY";
27
28
  readonly description: string;
29
+ readonly name: string;
28
30
  readonly request: {
29
31
  readonly parameters: readonly {
32
+ readonly in: "header" | "query" | "path" | "querystring" | "cookie";
30
33
  readonly name: string;
31
- readonly in: "path" | "query" | "querystring" | "header" | "cookie";
32
34
  readonly required?: boolean;
33
35
  readonly schema?: {
34
36
  readonly [x: string]: Schema.Json;
@@ -64,11 +66,9 @@ export declare const compileOpenApiDocument: (entry: OpenApiImport, inputDocumen
64
66
  };
65
67
  };
66
68
  readonly path: string;
67
- readonly name: string;
68
69
  readonly input: {
69
70
  readonly [x: string]: Schema.Json;
70
71
  };
71
- readonly method: "HEAD" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS" | "QUERY";
72
72
  readonly securitySchemes: {
73
73
  readonly [x: string]: {
74
74
  readonly [x: string]: Schema.Json;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Authoring credential placements. A method's `request` callback runs once, when the provider is
3
+ * declared, with an opaque reference for each of the method's fields. It returns placements built
4
+ * from `header` or `query` and a value from `t`, `base64` and references; the result is stored
5
+ * as data. A reference is not a string: an untagged template literal fails when it is evaluated.
6
+ */
7
+ import { Placement, type PlacementPart } from "../contracts/placement.js";
8
+ import type { AccountRequest, FieldExposure } from "../contracts/provider.js";
9
+ /** Throw when JavaScript turns a placement into a string, so untagged templates fail. */
10
+ declare class NotAString {
11
+ #private;
12
+ constructor(described: string);
13
+ [Symbol.toPrimitive](): never;
14
+ toString(): never;
15
+ toJSON(): never;
16
+ }
17
+ /** A reference to one of the method's account fields, given to its `request` callback. */
18
+ export declare class FieldRef<Name extends string = string> extends NotAString {
19
+ readonly field: Name;
20
+ constructor(field: Name);
21
+ }
22
+ /** A value template built with `t` or `base64`. */
23
+ export declare class PlacementValue extends NotAString {
24
+ readonly parts: readonly PlacementPart[];
25
+ constructor(parts: readonly PlacementPart[]);
26
+ }
27
+ /** What a template may interpolate: literal text, a field reference or another value. */
28
+ export type PlacementInput = string | FieldRef | PlacementValue;
29
+ /** A value template: literal text with interpolated field references and values. */
30
+ export declare const t: (strings: TemplateStringsArray, ...values: readonly PlacementInput[]) => PlacementValue;
31
+ /** Base64 of a value's UTF-8 bytes, such as the `user:password` of Basic credentials. */
32
+ export declare const base64: (value: PlacementInput) => PlacementValue;
33
+ /** Send a value as the whole value of this header. The name is case-insensitive. */
34
+ export declare const header: (name: string, input: PlacementInput) => Placement;
35
+ /** Send a value as the whole value of this query parameter. */
36
+ export declare const query: (name: string, input: unknown) => Placement;
37
+ /** `Authorization: Bearer <token>`. */
38
+ export declare const bearer: (token: FieldRef) => Placement;
39
+ /** `Authorization: Basic base64(<user>:<password>)`. */
40
+ export declare const basic: (user: PlacementInput, password: PlacementInput) => Placement;
41
+ /** The field references a `request` callback receives, by field name. */
42
+ export type FieldRefs<Name extends string> = {
43
+ readonly [Key in Name]: FieldRef<Key>;
44
+ };
45
+ /** How a method declares its placements: called once with its field references. */
46
+ export type RequestPlacements<Name extends string> = (fields: FieldRefs<Name>) => Placement | readonly Placement[];
47
+ /**
48
+ * Run a method's `request` callback once and check its placements. Every reference names one of
49
+ * the method's fields, no `raw()` field appears, and each placement references a secret field.
50
+ */
51
+ export declare const declarePlacements: (method: string, names: readonly string[], exposure: Readonly<Record<string, FieldExposure>> | undefined, request: RequestPlacements<string>) => readonly Placement[];
52
+ /**
53
+ * Give a bound account `headers()` and `url()`, rendering the placements the host granted with the
54
+ * fields app code holds. They are not enumerable, so the account's JSON is unchanged.
55
+ */
56
+ export declare const withPlacements: <Account extends {
57
+ readonly method: string;
58
+ readonly fields: unknown;
59
+ }>(account: Account, placements: readonly Placement[] | undefined) => Account & AccountRequest;
60
+ export {};
@@ -2,15 +2,17 @@
2
2
  import { Effect, Schema } from "effect";
3
3
  import { type PromiseMethod } from "./authoring.js";
4
4
  import { type AccountCheck, type AuthMethods, type FieldExposure, OAuth2Config, OAuth2Method, Provider, SecretsMethod } from "../contracts/provider.js";
5
+ import type { Placement } from "../contracts/placement.js";
5
6
  import type { ValidationError } from "../contracts/schema.js";
6
7
  /** Declare a secrets method with an Effect decoder. */
7
8
  export declare const secrets: <Fields extends Schema.Decoder<unknown>>(options: {
8
9
  readonly label: string;
9
10
  readonly fields: Fields;
10
11
  readonly exposure?: Readonly<Record<string, FieldExposure>>;
12
+ readonly request?: readonly Placement[];
11
13
  }) => SecretsMethod<Fields>;
12
14
  /** Validate OAuth endpoints while declaring their app-visible response projection. */
13
- export declare const oauth2: <Response extends Schema.Decoder<unknown>>(config: OAuth2Config, response: Response, exposure?: Readonly<Record<string, FieldExposure>>) => Effect.Effect<OAuth2Method<Response>, ValidationError>;
15
+ export declare const oauth2: <Response extends Schema.Decoder<unknown>>(config: OAuth2Config, response: Response, exposure?: Readonly<Record<string, FieldExposure>>, request?: readonly Placement[]) => Effect.Effect<OAuth2Method<Response>, ValidationError>;
14
16
  /** Author options: the account check is an ordinary async function. */
15
17
  export interface ProviderOptions<Auth extends AuthMethods> {
16
18
  readonly name: string;
@@ -26,5 +28,9 @@ export interface ProviderOptions<Auth extends AuthMethods> {
26
28
  /** Verify a connected account with a safe read, optionally reporting its upstream identity. */
27
29
  readonly health?: PromiseMethod<AccountCheck<Auth>["run"]>;
28
30
  }
29
- /** Retain the provider and literal method names without registering or authenticating it. */
31
+ /**
32
+ * Retain the provider and literal method names without registering or authenticating it. A
33
+ * method's `request` restricts where its credentials go only among the provider's `hosts`, so a
34
+ * provider that declares a `request` declares `hosts` too.
35
+ */
30
36
  export declare const defineProvider: <const Auth extends AuthMethods>({ health, ...options }: ProviderOptions<Auth>) => Provider<Auth>;
@@ -12,11 +12,18 @@ import { type JsonResponse as NativeResponse } from "./contracts/http.js";
12
12
  import { type OAuth2Config as NativeOAuth2Config, type OAuth2Method as NativeOAuth2Method, type ReservedAuthorizationParam, type SecretsMethod as NativeSecretsMethod } from "./contracts/provider.js";
13
13
  import type { Webhook as NativeWebhook } from "./contracts/webhooks.js";
14
14
  import { type PromiseMethods } from "./implementation/authoring.js";
15
+ import { type PlacementInput, type RequestPlacements } from "./implementation/placement.js";
16
+ import type { Placement } from "./contracts/placement.js";
17
+ import type { AppContext as NativeAppContext, QueryContext as NativeQueryContext } from "./contracts/context.js";
18
+ import { query as operationQuery, type OperationOptions } from "./implementation/operations.js";
15
19
  import { type Fields, type Infer, type ObjectSchema, type Schema, type SecretFields, type SecretObject } from "./implementation/schema.js";
16
20
  export { type JsonObject, type JsonValue, ValidationError } from "./contracts/schema.js";
17
21
  export { type Fields, type Infer, type ObjectSchema, type ObjectValue, type Schema, array, boolean, json, jsonSchema, literal, number, object, record, string, plain, raw, type SecretString, } from "./implementation/schema.js";
18
22
  export { type AccountCheckContext, type AccountCheckResult, type AccountInfo, type AccountOf, type AuthMethod, type AuthMethodData, type AuthMethods, type ManyAccounts, type Provider, type ReservedAuthorizationParam, } from "./contracts/provider.js";
19
23
  export { defineProvider, type ProviderOptions } from "./implementation/provider.js";
24
+ export { base64, basic, bearer, header, t, type FieldRef, type FieldRefs, type PlacementInput, type PlacementValue, type RequestPlacements, } from "./implementation/placement.js";
25
+ export type { Placement };
26
+ export type { AccountRequest } from "./contracts/provider.js";
20
27
  export { accountRouter } from "./implementation/account-router.js";
21
28
  export { router, dynamicRouter, withApprovals, type OperationChild, type OperationDeclaration, type RouterDeclaration, type RouterChild, type RouterOptions, } from "./implementation/router.js";
22
29
  export type { RouterIcon } from "./contracts/router.js";
@@ -28,6 +35,8 @@ type AccountFields<S> = S extends ObjectSchema<infer F> ? SecretFields<F> : Secr
28
35
  export type SecretsMethod<Shape extends ObjectSchema<Fields>> = NativeSecretsMethod<EffectSchema.Decoder<AccountFields<Shape>>>;
29
36
  /** An OAuth declaration inferred from its author-facing response schema. */
30
37
  export type OAuth2Method<Response extends Schema<unknown, boolean>> = NativeOAuth2Method<EffectSchema.Decoder<AccountFields<Response>>>;
38
+ /** The names of an object schema's fields, which a method's `request` can reference. */
39
+ type FieldNameOf<S> = S extends ObjectSchema<infer F> ? keyof F & string : never;
31
40
  /** Default OAuth fields visible to app code. Host-only grants and clients stay private. */
32
41
  export declare const OAuth2AccessToken: Schema<{
33
42
  readonly access_token: string;
@@ -42,19 +51,28 @@ type WithoutReservedParams<Config> = Config extends unknown ? "authorizationPara
42
51
  readonly [Key in ReservedAuthorizationParam]?: never;
43
52
  };
44
53
  } : Config : never;
45
- /** Declare a secrets method without requiring an Effect schema from the author. */
54
+ /**
55
+ * Declare a secrets method without requiring an Effect schema from the author. `request` says
56
+ * where its secret fields may be sent, such as `({ token }) => bearer(token)`; it runs once, here.
57
+ */
46
58
  export declare const secrets: <const F extends Fields>(options: {
47
59
  readonly label: string;
48
60
  readonly fields: ObjectSchema<F>;
61
+ readonly request?: RequestPlacements<keyof F & string>;
49
62
  }) => SecretsMethod<ObjectSchema<F>>;
50
63
  /**
51
64
  * Declare OAuth discovery/endpoints and an optional app-visible response projection.
52
65
  * `authorizationParams` adds service-defined sign-in parameters; a declared `authorizationUrl`
53
66
  * keeps its own query. Neither can set host-owned parameters, and each parameter appears once.
67
+ * `request` says where the projected secret fields may be sent, such as
68
+ * `({ access_token }) => bearer(access_token)`; it runs once, here.
54
69
  */
55
- export declare function oauth2(options: OAuth2Config): OAuth2Method<typeof OAuth2AccessToken>;
70
+ export declare function oauth2(options: OAuth2Config & {
71
+ readonly request?: RequestPlacements<"access_token">;
72
+ }): OAuth2Method<typeof OAuth2AccessToken>;
56
73
  export declare function oauth2<Response extends Schema<unknown, boolean>>(options: OAuth2Config & {
57
74
  readonly response: Response;
75
+ readonly request?: RequestPlacements<FieldNameOf<Response>>;
58
76
  }): OAuth2Method<Response>;
59
77
  export type { AccountSlots } from "./contracts/app.js";
60
78
  export type { AppRequirements, AppContext, QueryContext, MutationContext, WebhookContext, } from "./contracts/context.js";
@@ -76,7 +94,13 @@ export declare const decodeJson: <T>(response: JsonResponse, schema: Schema<T, b
76
94
  export { NotImplemented } from "./contracts/app.js";
77
95
  export { ElicitationFailed, type FormElicitation, type ElicitationResponse, type Elicit, } from "./contracts/elicitation.js";
78
96
  export type { Sql, SqlCursor, SqlReader, SqlRow, SqlTransaction, SqlValue, } from "./contracts/sql.js";
79
- export { query, mutation, withApproval, toolAnnotations, type Operation, type OperationOptions, } from "./implementation/operations.js";
97
+ /**
98
+ * `query(options, run)` declares a read operation. `query(name, value)` inside a method's
99
+ * `request` places a credential in a query parameter, such as `query("key", key)`.
100
+ */
101
+ export declare function query(name: string, value: PlacementInput): Placement;
102
+ export declare function query<Input, Output, Context extends NativeAppContext = NativeQueryContext>(options: OperationOptions<Input, Output>, run: (context: Context, input: Input) => Promise<Output>): ReturnType<typeof operationQuery<Input, Output, Context>>;
103
+ export { mutation, withApproval, toolAnnotations, type Operation, type OperationOptions, } from "./implementation/operations.js";
80
104
  export type { OperationContext } from "./contracts/operations.js";
81
105
  export { workflow, type Workflow, type WorkflowDeclaration } from "./implementation/workflows.js";
82
106
  export { NonRetryableError, WorkflowFailure, type WorkflowContext, type WorkflowStepContext, type WorkflowStep, type WorkflowStepOptions, type WorkflowDuration, type WorkflowReads, type WorkflowControls, } from "./contracts/workflows.js";