apps 0.0.1-beta.3 → 0.0.1-beta.30

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 (139) hide show
  1. package/README.md +68 -44
  2. package/framework-reference.json +1 -1
  3. package/js/{chunk-G7ZIRKMK.js → chunk-2D2PKLGQ.js} +118 -197
  4. package/js/chunk-3SPRHIEE.js +42 -0
  5. package/js/{chunk-FDNTX5QJ.js → chunk-4N26L465.js} +2 -2
  6. package/js/chunk-5ZHHO4OM.js +92 -0
  7. package/js/{chunk-EVJUVWN2.js → chunk-65SZ23BK.js} +2 -2
  8. package/js/{chunk-M6ZRRIBI.js → chunk-6JBTHTI5.js} +1 -1
  9. package/js/{chunk-J7O55ZV7.js → chunk-6NK26ONC.js} +332 -187
  10. package/js/chunk-6VWYEQ4X.js +254 -0
  11. package/js/{chunk-RN2MXB4R.js → chunk-AE4FWJQU.js} +128 -24
  12. package/js/{chunk-HDJH3RPR.js → chunk-BBTELEAN.js} +2 -2
  13. package/js/{chunk-LGIYBDWA.js → chunk-BRGF7VFN.js} +65 -1
  14. package/js/{chunk-MYYEW3RA.js → chunk-BSRU52RU.js} +984 -61
  15. package/js/{chunk-FZJOYIZO.js → chunk-BTJMXW4I.js} +1 -1
  16. package/js/{chunk-HDTGZWP2.js → chunk-IMCEF6KE.js} +139 -32
  17. package/js/chunk-KQCMHI3K.js +118 -0
  18. package/js/{chunk-BMOIAIVR.js → chunk-M2KEEOIQ.js} +49 -1
  19. package/js/{chunk-YEJOQEII.js → chunk-MYCVMDWI.js} +45 -7
  20. package/js/{chunk-FW5HBOIK.js → chunk-NXTXZ635.js} +1841 -1701
  21. package/js/chunk-OD3KFKZD.js +1617 -0
  22. package/js/{chunk-JN55AYQH.js → chunk-OI5CKSBU.js} +61 -32
  23. package/js/{chunk-NQ3OMCA5.js → chunk-P46HIAX6.js} +2 -2
  24. package/js/chunk-PUC24GZP.js +801 -0
  25. package/js/{chunk-SATWJKN6.js → chunk-PWF2DRJ3.js} +1 -1
  26. package/js/{chunk-D47C7KG5.js → chunk-VUVBMNKC.js} +2 -2
  27. package/js/{chunk-ZCAMUXSG.js → chunk-WGBI5MVX.js} +3 -4
  28. package/js/{chunk-T2LAZCAD.js → chunk-WQ5MVBTP.js} +1 -1
  29. package/js/{chunk-PLCMJREA.js → chunk-XBQTJP76.js} +60 -20
  30. package/js/{chunk-QKHR7BMF.js → chunk-XGN5IFOZ.js} +3 -3
  31. package/js/{chunk-WFSQXYUT.js → chunk-YML53Z7H.js} +42 -5
  32. package/js/{chunk-5MQZEB6Y.js → chunk-ZZOCEUTB.js} +37 -12
  33. package/js/client.js +120 -84
  34. package/js/contracts.js +110 -16
  35. package/js/effect.js +20 -20
  36. package/js/{es-APDZKREY.js → es-DIULA3ZF.js} +62 -1659
  37. package/js/graphql.js +58 -54
  38. package/js/host.js +20 -20
  39. package/js/index.js +247 -204
  40. package/js/mcp/effect.js +24 -22
  41. package/js/mcp/stdio.js +35 -30
  42. package/js/mcp.js +105 -68
  43. package/js/openapi.js +4087 -1503
  44. package/js/react.js +3 -3
  45. package/js/skills/effect.js +5 -3
  46. package/js/skills.js +15 -15
  47. package/js/storage/facet.js +4 -4
  48. package/js/ui/auth/contracts.js +2 -2
  49. package/js/ui/auth.js +5 -5
  50. package/js/ui/contracts.js +5 -4
  51. package/js/ui/serving.js +8516 -214
  52. package/package.json +1 -1
  53. package/runtime.json +1 -1
  54. package/types/app-data/src/contracts/database.d.ts +33 -6
  55. package/types/app-data/src/implementation/schema.d.ts +2 -17
  56. package/types/apps/src/contracts/api-response-error.d.ts +4 -0
  57. package/types/apps/src/contracts/app.d.ts +7 -6
  58. package/types/apps/src/contracts/failure.d.ts +54 -0
  59. package/types/apps/src/contracts/graphql.d.ts +2 -1
  60. package/types/apps/src/contracts/host.d.ts +34 -11
  61. package/types/apps/src/contracts/mcp.d.ts +91 -10
  62. package/types/apps/src/contracts/network.d.ts +84 -0
  63. package/types/apps/src/contracts/openapi-compile.d.ts +31 -3
  64. package/types/apps/src/contracts/openapi.d.ts +45 -9
  65. package/types/apps/src/contracts/operations.d.ts +5 -6
  66. package/types/apps/src/contracts/protocol-version.d.ts +2 -2
  67. package/types/apps/src/contracts/protocols/1.d.ts +251 -69
  68. package/types/apps/src/contracts/protocols/2.d.ts +710 -0
  69. package/types/apps/src/contracts/protocols/3.d.ts +716 -0
  70. package/types/apps/src/contracts/protocols/4.d.ts +1298 -0
  71. package/types/apps/src/contracts/protocols/5.d.ts +1174 -0
  72. package/types/apps/src/contracts/protocols/6.d.ts +1620 -0
  73. package/types/apps/src/contracts/protocols/7.d.ts +1784 -0
  74. package/types/apps/src/contracts/protocols/8.d.ts +1119 -0
  75. package/types/apps/src/contracts/protocols/oauth.d.ts +89 -0
  76. package/types/apps/src/contracts/provider-error.d.ts +9 -0
  77. package/types/apps/src/contracts/provider.d.ts +115 -10
  78. package/types/apps/src/contracts/router.d.ts +59 -0
  79. package/types/apps/src/contracts/skills.d.ts +18 -5
  80. package/types/apps/src/contracts/storage.d.ts +3 -3
  81. package/types/apps/src/contracts/ui.d.ts +18 -0
  82. package/types/apps/src/contracts/workflows.d.ts +34 -3
  83. package/types/apps/src/graphql.d.ts +1 -3
  84. package/types/apps/src/implementation/account-router.d.ts +12 -0
  85. package/types/apps/src/implementation/app.d.ts +5 -4
  86. package/types/apps/src/implementation/browser-scripts.gen.d.ts +6 -0
  87. package/types/apps/src/implementation/catalog-cache.d.ts +34 -4
  88. package/types/apps/src/implementation/elicitation.d.ts +9 -9
  89. package/types/apps/src/implementation/failure-detail.d.ts +46 -0
  90. package/types/apps/src/implementation/graphql-catalog.d.ts +4 -7
  91. package/types/apps/src/implementation/graphql.d.ts +4 -3
  92. package/types/apps/src/implementation/mcp-call.d.ts +6 -5
  93. package/types/apps/src/implementation/mcp-catalog.d.ts +7 -8
  94. package/types/apps/src/implementation/mcp-client.d.ts +49 -25
  95. package/types/apps/src/implementation/mcp-stdio.d.ts +1 -1
  96. package/types/apps/src/implementation/mcp-tools.d.ts +2 -1
  97. package/types/apps/src/implementation/mcp.d.ts +52 -25
  98. package/types/apps/src/implementation/network.d.ts +16 -0
  99. package/types/apps/src/implementation/openapi-compile.d.ts +27 -6
  100. package/types/apps/src/implementation/openapi-document.d.ts +35 -8
  101. package/types/apps/src/implementation/openapi-names.d.ts +9 -4
  102. package/types/apps/src/implementation/openapi-request.d.ts +10 -2
  103. package/types/apps/src/implementation/openapi-source.d.ts +8 -6
  104. package/types/apps/src/implementation/openapi-upgrade.d.ts +4 -0
  105. package/types/apps/src/implementation/operations.d.ts +36 -3
  106. package/types/apps/src/implementation/protocol-operations.d.ts +6 -4
  107. package/types/apps/src/implementation/provider-error.d.ts +28 -1
  108. package/types/apps/src/implementation/provider.d.ts +19 -5
  109. package/types/apps/src/implementation/router-catalog.d.ts +224 -0
  110. package/types/apps/src/implementation/router.d.ts +68 -0
  111. package/types/apps/src/implementation/runtime-yield.d.ts +7 -0
  112. package/types/apps/src/implementation/schema.d.ts +52 -1
  113. package/types/apps/src/implementation/skills.d.ts +2 -2
  114. package/types/apps/src/implementation/storage.d.ts +5 -3
  115. package/types/apps/src/implementation/ui-account-notice.d.ts +9 -0
  116. package/types/apps/src/implementation/ui-client.d.ts +2 -2
  117. package/types/apps/src/implementation/ui-document.d.ts +5 -0
  118. package/types/apps/src/implementation/ui-errors.d.ts +1 -1
  119. package/types/apps/src/implementation/ui-serving.d.ts +10 -4
  120. package/types/apps/src/implementation/ui-watch.d.ts +1 -1
  121. package/types/apps/src/implementation/upstream-error.d.ts +7 -0
  122. package/types/apps/src/implementation/webhooks.d.ts +1 -1
  123. package/types/apps/src/implementation/workflow-context.d.ts +11 -3
  124. package/types/apps/src/index.d.ts +29 -11
  125. package/types/apps/src/mcp-stdio.d.ts +2 -5
  126. package/types/apps/src/mcp.d.ts +25 -5
  127. package/types/apps/src/openapi.d.ts +6 -6
  128. package/types/apps/src/skills.d.ts +4 -4
  129. package/types/telemetry/src/browser-operations.d.ts +5 -2
  130. package/types/telemetry/src/config.d.ts +2 -2
  131. package/types/utils/src/api-error.d.ts +48 -0
  132. package/js/chunk-PYUYJRSK.js +0 -93
  133. package/js/chunk-SWPD52J7.js +0 -35
  134. package/js/chunk-W7D7WVSY.js +0 -18
  135. package/js/chunk-Z5NMEGJN.js +0 -29
  136. package/js/chunk-ZJWDMTE3.js +0 -63
  137. package/types/apps/src/contracts/dynamic-tools.d.ts +0 -13
  138. package/types/apps/src/implementation/account-operations.d.ts +0 -151
  139. package/types/apps/src/implementation/dynamic-tools.d.ts +0 -8
@@ -1,11 +1,32 @@
1
1
  import { Schema } from "effect";
2
2
  import { JsonObject } from "../contracts/schema.js";
3
- /** Resolve OpenAPI objects once with Swagger; schemas retain their original recursive references.
4
- * Scalar first upgrades Swagger 2.0 and OpenAPI 3.0 to 3.1, so the importer has one dialect and
5
- * 3.1 keywords that appear in 3.0 documents keep their meaning.
6
- * Unsupported versions, references and conversions throw TemplateError at the import boundary.
3
+ /**
4
+ * An object in a document that was validated as JSON when it was read. Compilation only turns JSON
5
+ * into JSON, so inside it an object's shape is checked, not its every leaf again: re-validating
6
+ * whole documents was most of a large API's compile time.
7
7
  */
8
- export declare function openApiDocument(input: unknown): Promise<{
8
+ export declare const DocumentObject: Schema.declare<{
9
+ readonly [x: string]: Schema.Json;
10
+ }, {
11
+ readonly [x: string]: Schema.Json;
12
+ }>;
13
+ export declare const documentObject: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => {
14
+ readonly [x: string]: Schema.Json;
15
+ };
16
+ /** One JSON Pointer reference token. */
17
+ export declare const pointerToken: (key: string) => string;
18
+ /**
19
+ * Decode one part of the definition, located by the JSON Pointer `at`. A mismatch names the
20
+ * pointer of the first failing value and what was expected there.
21
+ */
22
+ export declare const decodeDefinition: <S extends Schema.Decoder<unknown>>(schema: S, value: unknown, at: string, what: string) => S["Type"];
23
+ /** Resolve OpenAPI objects once; schemas retain their original recursive references.
24
+ * Scalar first upgrades Swagger 2.0 and OpenAPI 3.0 to 3.1, so the importer reads 3.1 and 3.2,
25
+ * whose Schema Objects share one dialect, and 3.1 keywords that appear in 3.0 documents keep
26
+ * their meaning. Unsupported versions, references and conversions throw TemplateError at the
27
+ * import boundary.
28
+ */
29
+ export declare function openApiDocument(input: JsonObject): Promise<{
9
30
  spec: {
10
31
  readonly openapi: string;
11
32
  readonly paths: {
@@ -38,14 +59,20 @@ export declare function openApiDocument(input: unknown): Promise<{
38
59
  definitions: Map<string, {
39
60
  readonly [x: string]: Schema.Json;
40
61
  }>;
62
+ /**
63
+ * The JSON Pointer of the object a local reference resolved to, so a diagnostic can locate
64
+ * a resolved Response, Parameter, Request Body or Path Item where the definition declares it.
65
+ */
66
+ origin(value: unknown): string | undefined;
41
67
  /** Inspect a component schema without expanding its children. OpenAPI object refs must already be resolved by Swagger. */
42
68
  resolve(value: JsonObject): JsonObject;
43
69
  /** Compose a Draft 2020-12 schema around API Schema Objects. Only values passed to
44
70
  * `api` use the document's OpenAPI dialect; Executor-authored wrappers are already
45
- * Draft 2020-12 and must not be reinterpreted. Reached components are converted once into
46
- * the shared `definitions` and stay references here; nothing is inlined or copied per operation.
71
+ * Draft 2020-12 and must not be reinterpreted. `api` takes the schema's JSON Pointer in the
72
+ * definition, which failures name. Reached components are converted once into the shared
73
+ * `definitions` and stay references here; nothing is inlined or copied per operation.
47
74
  */
48
- schema(build: (api: (input: Schema.Json) => JsonObject) => JsonObject): JsonObject;
75
+ schema(build: (api: (input: Schema.Json, at: string) => JsonObject) => JsonObject): JsonObject;
49
76
  }>;
50
77
  /** A parsed document with one reference scope and one schema dialect. */
51
78
  export type OpenApiDocument = Awaited<ReturnType<typeof openApiDocument>>;
@@ -11,8 +11,13 @@ export interface OperationNameInput {
11
11
  readonly path: string;
12
12
  }
13
13
  /**
14
- * Plan one name per input, in input order. Names that collide are refined together: first by
15
- * the path's version segment, then by the HTTP method, then by a stable hash. Refinement only
16
- * touches the colliding names, so adding an operation never renames an unrelated one.
14
+ * Name every input, in input order. Names that collide, whether or not they come from an
15
+ * operationId, are refined together: first by the path's version segment, then by the path
16
+ * segments that tell them apart (`GET /items` and `GET /items/{id}` are `items.getItems` and
17
+ * `items.getItemsById`), then by the whole path, then by the HTTP method, then by a stable hash.
18
+ * Refinement only touches the colliding names, so adding an operation never renames an unrelated
19
+ * one.
17
20
  */
18
- export declare const planOperationNames: (inputs: readonly OperationNameInput[]) => string[];
21
+ export declare const planOperationNames: <I extends OperationNameInput>(inputs: readonly I[]) => (I & {
22
+ readonly name: string;
23
+ })[];
@@ -1,3 +1,4 @@
1
+ import { NetworkRefused } from "../contracts/network.js";
1
2
  import { ProviderError } from "../contracts/provider-error.js";
2
3
  /** Swagger constructs requests; Effect owns HTTP policy and bounded results. */
3
4
  import { Effect, Schema } from "effect";
@@ -6,12 +7,19 @@ import { OpenapiError, type CredentialBinding, type OpenapiOperation, type Opena
6
7
  type DeclaredError = OpenapiErrorResponse & {
7
8
  readonly decoder: Schema.Decoder<Schema.Json>;
8
9
  };
10
+ /** What decides whether an account can call an operation: its transport and security. */
11
+ export interface OpenapiOperationAccess {
12
+ readonly streaming?: true;
13
+ readonly request: {
14
+ readonly security: OpenapiOperation["request"]["security"];
15
+ };
16
+ }
9
17
  /** Create request helpers from credential-free generated authentication metadata. */
10
18
  export declare function createRequest(config: {
11
19
  readonly methods: Readonly<Record<string, readonly CredentialBinding[]>>;
12
20
  readonly oauth: readonly string[];
13
21
  }): {
14
- available: (op: OpenapiOperation, account: OpenapiAccount | undefined) => boolean;
15
- call: (op: OpenapiOperation, input: unknown, account: OpenapiAccount | undefined, errors: readonly DeclaredError[]) => Effect.Effect<Schema.Json, ProviderError | OpenapiResponseError | OpenapiError, never>;
22
+ available: (op: OpenapiOperationAccess, account: OpenapiAccount | undefined) => boolean;
23
+ call: (op: OpenapiOperation, input: unknown, account: OpenapiAccount | undefined, errors: readonly DeclaredError[]) => Effect.Effect<Schema.Json, ProviderError | NetworkRefused | OpenapiResponseError | OpenapiError, never>;
16
24
  };
17
25
  export {};
@@ -3,8 +3,8 @@ import { Duration } from "effect";
3
3
  import type { AppCache } from "../contracts/cache.js";
4
4
  import { OpenapiOperation, type OpenapiToolsOptions } from "../contracts/openapi.js";
5
5
  import { JsonObject, JsonValue } from "../contracts/schema.js";
6
- import type { DynamicTools } from "../contracts/dynamic-tools.js";
7
6
  import { type OperationKinds } from "./protocol-operations.js";
7
+ import { type RouterDeclaration } from "./router.js";
8
8
  /** Static credential placement and destination are reviewed when the app is authored/imported. */
9
9
  export interface OpenapiSourceOptions extends Omit<OpenapiToolsOptions, "operations" | "definitions"> {
10
10
  readonly cache: AppCache;
@@ -16,6 +16,12 @@ export interface OpenapiSourceOptions extends Omit<OpenapiToolsOptions, "operati
16
16
  readonly allowedOrigin: string;
17
17
  readonly securitySchemes: Readonly<Record<string, JsonObject>>;
18
18
  readonly baseUrl?: string;
19
+ /**
20
+ * A path inserted between the server and every operation's path, for a definition that omits a
21
+ * leading segment, such as `/projects/{project}`. Each `{name}` becomes a required string path
22
+ * parameter of every tool, unless the operation already declares it without placing it.
23
+ */
24
+ readonly pathPrefix?: string;
19
25
  readonly freshFor?: Duration.Input;
20
26
  readonly staleFor?: Duration.Input;
21
27
  /**
@@ -33,8 +39,4 @@ export interface OpenapiSourceOptions extends Omit<OpenapiToolsOptions, "operati
33
39
  /** JSON-object patches are static app configuration and are reapplied to every revision. */
34
40
  export declare function patchOpenapi(root: JsonObject, patches: OpenapiSourceOptions["patches"]): JsonObject;
35
41
  /** No I/O during app construction. All accounts share credential-free compilation. */
36
- export declare const liveOpenapiOperations: (options: OpenapiSourceOptions) => {
37
- readonly queries: {};
38
- readonly mutations: {};
39
- readonly dynamicTools: DynamicTools;
40
- };
42
+ export declare const liveOpenapiRouter: (options: OpenapiSourceOptions) => RouterDeclaration;
@@ -0,0 +1,4 @@
1
+ type Node = Record<string, unknown>;
2
+ /** Upgrade a 3.0 document the caller owns. Any other version is returned unchanged. */
3
+ export declare const upgradeOpenApi30InPlace: (document: Node) => Node;
4
+ export {};
@@ -7,16 +7,39 @@ import type { ToolAnnotations } from "../contracts/tools.js";
7
7
  import type { JsonObject } from "../contracts/schema.js";
8
8
  import { type Schema } from "./schema.js";
9
9
  declare const NativeOperation: unique symbol;
10
- declare const HandlerContext: unique symbol;
11
- /** A server-only declaration with its category preserved for catalog validation. */
10
+ declare const QueryHandlerContext: unique symbol;
11
+ declare const MutationHandlerContext: unique symbol;
12
+ /**
13
+ * A server-only declaration with its category preserved for catalog validation. Queries and
14
+ * mutations carry their handler context under different phantom keys, so a router can type a
15
+ * query's handler from its query context alone.
16
+ */
12
17
  export interface OperationDeclaration<Kind extends "query" | "mutation", Context = never> {
13
- readonly [HandlerContext]?: (context: Context) => void;
18
+ readonly [QueryHandlerContext]?: "query" extends Kind ? (context: Context) => void : never;
19
+ readonly [MutationHandlerContext]?: "mutation" extends Kind ? (context: Context) => void : never;
14
20
  readonly kind: Kind;
15
21
  readonly [NativeOperation]: Omit<AppOperation<never>, "kind" | "input"> & {
16
22
  readonly kind: Kind;
17
23
  readonly input: EffectSchema.Decoder<unknown>;
18
24
  };
19
25
  }
26
+ /**
27
+ * A router declaration. The phantom contexts let `defineApp` type inline handlers; protocol
28
+ * routers accept any context because their operations only use the framework's own capabilities.
29
+ * The native router is held under a private key in implementation/router.ts.
30
+ */
31
+ export interface RouterDeclaration<Query = unknown, Mutation = unknown> {
32
+ readonly [QueryHandlerContext]?: (context: Query) => void;
33
+ readonly [MutationHandlerContext]?: (context: Mutation) => void;
34
+ readonly [NativeRouterKey]: unknown;
35
+ }
36
+ /** An operation or nested router under one key. Each child is typed only by its own kind's context. */
37
+ export interface RouterChild<Query, Mutation> {
38
+ readonly [QueryHandlerContext]?: (context: Query) => void;
39
+ readonly [MutationHandlerContext]?: (context: Mutation) => void;
40
+ }
41
+ /** Private key for a router's native definition. */
42
+ export declare const NativeRouterKey: unique symbol;
20
43
  /** Typed operation handles drive browser reference inference without bundling handlers. */
21
44
  export interface Operation<Input, Output, Kind extends "query" | "mutation", Context = AppContext> extends OperationDeclaration<Kind, Context> {
22
45
  readonly [NativeOperation]: AppOperation<Input, Output> & {
@@ -56,8 +79,18 @@ export declare const operationOptions: <Input, Output>(options: OperationOptions
56
79
  title?: string;
57
80
  description?: string;
58
81
  };
82
+ /**
83
+ * Replace a native operation's approval. Property descriptors are copied so an output schema that
84
+ * a protocol adapter builds only when read stays lazy.
85
+ */
86
+ export declare const approvedOperation: <Input, Native extends AppOperation<Input, unknown>>(operation: Native, approval: Approval<Input>) => Native;
59
87
  /** Attach the same approval function to a generated or shared operation. */
60
88
  export declare const withApproval: <Input, Output, Kind extends "query" | "mutation", Context>(operation: Operation<Input, Output, Kind, Context>, approval: Approval<Input>) => Operation<Input, Output, Kind, Context>;
89
+ /**
90
+ * The advisory hints an operation carries, such as an MCP server's `destructiveHint`. App code
91
+ * reads them to choose an approval; the framework never infers one from them.
92
+ */
93
+ export declare const toolAnnotations: (operation: OperationDeclaration<"query" | "mutation", never>) => ToolAnnotations | undefined;
61
94
  /** Read operation. External reads are allowed; only database writes are mechanically prohibited. */
62
95
  export declare const query: <Input, Output, Context extends AppContext = QueryContext>(options: OperationOptions<Input, Output>, run: (context: Context, input: Input) => Promise<Output>) => Operation<Input, Output, "query", Context>;
63
96
  /** Explicit write operation. Database writes roll back on failure; external effects cannot be undone. */
@@ -13,12 +13,14 @@ interface ProtocolOperation {
13
13
  readonly annotations?: ToolAnnotations | undefined;
14
14
  readonly _meta?: JsonObject | undefined;
15
15
  readonly input: Schema.Decoder<JsonValue>;
16
+ /** Checks and describes every returned value. */
17
+ readonly output?: Schema.Decoder<JsonValue> | undefined;
18
+ /** Describes the returned value without checking it; ignored when `output` is declared. */
16
19
  readonly outputSchema?: JsonObject | undefined;
17
20
  readonly run: (context: OperationContext, input: JsonValue) => Effect.Effect<unknown, unknown>;
18
21
  }
19
22
  /** Unknown behavior defaults to mutation. Classification never enforces an external service's behavior. */
20
- export declare const protocolOperations: (operations: Readonly<Record<string, ProtocolOperation>>, kinds?: OperationKinds) => {
21
- queries: Record<string, Operation<Schema.Json, unknown, "query", OperationContext>>;
22
- mutations: Record<string, Operation<Schema.Json, unknown, "mutation", OperationContext>>;
23
- };
23
+ export declare const protocolOperations: (operations: Readonly<Record<string, ProtocolOperation>>, kinds?: OperationKinds) => Record<string, Operation<Schema.Json, unknown, "query" | "mutation", OperationContext>>;
24
+ /** Operations already discovered, as a router keyed by upstream name. */
25
+ export declare const protocolRouter: (operations: Readonly<Record<string, ProtocolOperation>>, kinds?: OperationKinds) => import("./operations.js").RouterDeclaration<unknown, unknown>;
24
26
  export {};
@@ -1,10 +1,37 @@
1
1
  import { Option } from "effect";
2
+ import type { FailurePhase, UpstreamError } from "../contracts/failure.js";
2
3
  import { ProviderError } from "../contracts/provider-error.js";
4
+ import { AccountId } from "../contracts/schema.js";
5
+ /** A provider failure's fields, each optional one possibly absent. */
6
+ interface ProviderErrorFields {
7
+ readonly reason: ProviderError["reason"];
8
+ readonly status?: number | undefined;
9
+ readonly accountId?: AccountId | undefined;
10
+ readonly phase?: FailurePhase | undefined;
11
+ readonly upstream?: UpstreamError | undefined;
12
+ }
13
+ /**
14
+ * Construct a provider failure without keys for absent fields. Failures inside a catalog cross the
15
+ * boundary as JSON values, which have no `undefined`.
16
+ */
17
+ export declare const providerError: ({ reason, status, accountId, phase, upstream, }: ProviderErrorFields) => ProviderError;
3
18
  /** Parse and rebuild the allowlisted fields, including when the input is already an Error instance. */
4
19
  export declare function parseProviderError(error: unknown): Option.Option<ProviderError>;
5
- /** Classify only explicit HTTP evidence. Raw provider content never enters the error. */
20
+ /**
21
+ * The same failure with detail its raiser could not know: the phase it happened in, and the
22
+ * error the service stated. Detail the failure already carries is kept.
23
+ */
24
+ export declare function providerErrorDetail(error: ProviderError, detail: {
25
+ readonly phase?: FailurePhase;
26
+ readonly upstream?: UpstreamError | undefined;
27
+ }): ProviderError;
28
+ /**
29
+ * Classify only explicit HTTP evidence. Raw provider content never enters the error; a Bearer
30
+ * challenge's documented error code and description do.
31
+ */
6
32
  export declare function httpProviderError(status: number, headers?: Readonly<Record<string, string>>): ProviderError | undefined;
7
33
  /** Attach the account used by the enclosing operation, without preserving arbitrary thrown fields. */
8
34
  export declare function accountProviderError<E>(error: E, accountId: string): E | ProviderError;
9
35
  /** GraphQL has no standard auth code; recognize these documented codes without guessing from prose. */
10
36
  export declare function graphqlProviderError(errors: readonly unknown[], status: number): ProviderError | undefined;
37
+ export {};
@@ -1,16 +1,30 @@
1
1
  /** Pure constructors over the native provider contracts. */
2
2
  import { Effect, Schema } from "effect";
3
- import { type AuthMethods, OAuth2Config, OAuth2Method, Provider, SecretsMethod } from "../contracts/provider.js";
3
+ import { type PromiseMethod } from "./authoring.js";
4
+ import { type AccountCheck, type AuthMethods, type FieldExposure, OAuth2Config, OAuth2Method, Provider, SecretsMethod } from "../contracts/provider.js";
4
5
  import type { ValidationError } from "../contracts/schema.js";
5
6
  /** Declare a secrets method with an Effect decoder. */
6
7
  export declare const secrets: <Fields extends Schema.Decoder<unknown>>(options: {
7
8
  readonly label: string;
8
9
  readonly fields: Fields;
10
+ readonly exposure?: Readonly<Record<string, FieldExposure>>;
9
11
  }) => SecretsMethod<Fields>;
10
12
  /** Validate OAuth endpoints while declaring their app-visible response projection. */
11
- export declare const oauth2: <Response extends Schema.Decoder<unknown>>(config: OAuth2Config, response: Response) => Effect.Effect<OAuth2Method<Response>, ValidationError>;
12
- /** Retain the provider and literal method names without registering or authenticating it. */
13
- export declare const defineProvider: <const Auth extends AuthMethods>(options: {
13
+ export declare const oauth2: <Response extends Schema.Decoder<unknown>>(config: OAuth2Config, response: Response, exposure?: Readonly<Record<string, FieldExposure>>) => Effect.Effect<OAuth2Method<Response>, ValidationError>;
14
+ /** Author options: the account check is an ordinary async function. */
15
+ export interface ProviderOptions<Auth extends AuthMethods> {
14
16
  readonly name: string;
15
17
  readonly auth: Auth;
16
- }) => Provider<Auth>;
18
+ /**
19
+ * Hosts the credentials may be sent to: `api.example.com`, `api.example.com:8443`, or
20
+ * `*.example.com` for one level of subdomain. Secret fields then reach app code as handles
21
+ * that the outbound network replaces only on requests to these hosts. An account records the
22
+ * hosts it was connected for; changing them does not change the provider, but an existing
23
+ * account sends only to hosts it was connected for until it is connected again.
24
+ */
25
+ readonly hosts?: readonly string[];
26
+ /** Verify a connected account with a safe read, optionally reporting its upstream identity. */
27
+ readonly health?: PromiseMethod<AccountCheck<Auth>["run"]>;
28
+ }
29
+ /** Retain the provider and literal method names without registering or authenticating it. */
30
+ export declare const defineProvider: <const Auth extends AuthMethods>({ health, ...options }: ProviderOptions<Auth>) => Provider<Auth>;
@@ -0,0 +1,224 @@
1
+ /**
2
+ * Read a live router tree into tools, routers and router skills. A nested dynamic router that fails
3
+ * is reported on its own entry; the root failing fails the read, as a single-source app would.
4
+ */
5
+ import { Effect, Schema } from "effect";
6
+ import { HostDeclarationInvalid, HostEvaluationFailed, type HostRouterError } from "../contracts/host.js";
7
+ import type { AppOperation } from "../contracts/operations.js";
8
+ import type { AppRouter, DynamicRouter, RouterMeta } from "../contracts/router.js";
9
+ import { SkillLoadFailed } from "../contracts/skills.js";
10
+ import type { OperationSchedule } from "../contracts/schedules.js";
11
+ /**
12
+ * Keep only a failure's safe fields. Anything unrecognized becomes an evaluation failure with the
13
+ * error's name and bounded message, with the given account secrets replaced.
14
+ */
15
+ export declare const safeFailure: (error: unknown, secrets: readonly string[]) => HostRouterError;
16
+ /**
17
+ * Router skills are named `tools` for the root and `tools-<path>` below it, so a router's
18
+ * instructions never take an authored skill's name by accident.
19
+ */
20
+ export declare const routerSkillPrefix = "tools";
21
+ /**
22
+ * The skill name for a router path. A path of lowercase letters and digits is spelled out:
23
+ * `issues.open` is `tools-issues-open`. Any other path, or one too long, is a readable slug
24
+ * followed by a hash of the exact path, such as `tools-issues-list-0123456789`. Plain segments
25
+ * start with a letter and a hash is all digits, so the two forms never meet, and paths that slug
26
+ * alike, such as `issues_list` and `issues.list`, get different names.
27
+ */
28
+ export declare const routerSkillName: (path: string) => string;
29
+ /** A declared operation's catalog entry without schemas. `router` is its owning router's path. */
30
+ export declare const operationSummary: (name: string, router: string, operation: AppOperation, schedules?: readonly OperationSchedule[]) => Effect.Effect<{
31
+ readonly description: string;
32
+ readonly name: string;
33
+ readonly title?: string;
34
+ readonly annotations?: {
35
+ readonly title?: string;
36
+ readonly readOnlyHint?: boolean;
37
+ readonly destructiveHint?: boolean;
38
+ readonly idempotentHint?: boolean;
39
+ readonly openWorldHint?: boolean;
40
+ };
41
+ readonly schedules?: readonly {
42
+ readonly name: string;
43
+ readonly timing: {
44
+ readonly kind: "interval";
45
+ readonly milliseconds: number;
46
+ } | {
47
+ readonly kind: "cron";
48
+ readonly calendar: {
49
+ readonly expression: string;
50
+ readonly timezone: string;
51
+ };
52
+ };
53
+ readonly input: Schema.Json;
54
+ }[];
55
+ readonly readOnly?: boolean;
56
+ readonly router?: string;
57
+ readonly tags?: readonly string[];
58
+ }, HostDeclarationInvalid, never>;
59
+ /** A declared operation's full description, including rendered schemas. */
60
+ export declare const operationDescription: (name: string, router: string, operation: AppOperation, schedules?: readonly OperationSchedule[]) => Effect.Effect<{
61
+ readonly description: string;
62
+ readonly name: string;
63
+ readonly inputSchema: {
64
+ readonly [x: string]: Schema.Json;
65
+ };
66
+ readonly _meta?: {
67
+ readonly [x: string]: Schema.Json;
68
+ };
69
+ readonly title?: string;
70
+ readonly annotations?: {
71
+ readonly title?: string;
72
+ readonly readOnlyHint?: boolean;
73
+ readonly destructiveHint?: boolean;
74
+ readonly idempotentHint?: boolean;
75
+ readonly openWorldHint?: boolean;
76
+ };
77
+ readonly outputSchema?: {
78
+ readonly [x: string]: Schema.Json;
79
+ };
80
+ readonly schedules?: readonly {
81
+ readonly name: string;
82
+ readonly timing: {
83
+ readonly kind: "interval";
84
+ readonly milliseconds: number;
85
+ } | {
86
+ readonly kind: "cron";
87
+ readonly calendar: {
88
+ readonly expression: string;
89
+ readonly timezone: string;
90
+ };
91
+ };
92
+ readonly input: Schema.Json;
93
+ }[];
94
+ readonly readOnly?: boolean;
95
+ readonly router?: string;
96
+ readonly tags?: readonly string[];
97
+ }, HostDeclarationInvalid, never>;
98
+ /**
99
+ * A dynamic router over operations already discovered, such as an eager OpenAPI document or a
100
+ * stdio server. Upstream names can contain dots, which static router keys cannot.
101
+ */
102
+ export declare const fixedRouter: (operations: Readonly<Record<string, AppOperation>>, meta?: RouterMeta) => DynamicRouter;
103
+ export interface CatalogOptions {
104
+ /** Omit schemas. */
105
+ readonly summary: boolean;
106
+ /** Account secrets that a failure's message must not reveal. */
107
+ readonly secrets: readonly string[];
108
+ /** Only these full tool names. Routers with none of them are not read. */
109
+ readonly wanted?: ReadonlySet<string>;
110
+ /** Schedules that target a declared operation, by full name. */
111
+ readonly schedules: (name: string) => readonly OperationSchedule[];
112
+ /**
113
+ * Only declared operations that have schedules. Schedules never target dynamic routers, and
114
+ * their catalogs can be expensive to discover, so none is read.
115
+ */
116
+ readonly scheduled?: true;
117
+ }
118
+ /**
119
+ * Read a router tree. Every nested router is listed, for grouping; the root only when it has
120
+ * metadata. A nested dynamic source that fails is reported on its router's entry.
121
+ */
122
+ export declare const readCatalog: (root: AppRouter | DynamicRouter | undefined, options: CatalogOptions) => Effect.Effect<{
123
+ tools: ({
124
+ readonly description: string;
125
+ readonly name: string;
126
+ readonly inputSchema: {
127
+ readonly [x: string]: Schema.Json;
128
+ };
129
+ readonly _meta?: {
130
+ readonly [x: string]: Schema.Json;
131
+ };
132
+ readonly title?: string;
133
+ readonly annotations?: {
134
+ readonly title?: string;
135
+ readonly readOnlyHint?: boolean;
136
+ readonly destructiveHint?: boolean;
137
+ readonly idempotentHint?: boolean;
138
+ readonly openWorldHint?: boolean;
139
+ };
140
+ readonly outputSchema?: {
141
+ readonly [x: string]: Schema.Json;
142
+ };
143
+ readonly schedules?: readonly {
144
+ readonly name: string;
145
+ readonly timing: {
146
+ readonly kind: "interval";
147
+ readonly milliseconds: number;
148
+ } | {
149
+ readonly kind: "cron";
150
+ readonly calendar: {
151
+ readonly expression: string;
152
+ readonly timezone: string;
153
+ };
154
+ };
155
+ readonly input: Schema.Json;
156
+ }[];
157
+ readonly readOnly?: boolean;
158
+ readonly router?: string;
159
+ readonly tags?: readonly string[];
160
+ } | {
161
+ readonly description: string;
162
+ readonly name: string;
163
+ readonly title?: string;
164
+ readonly annotations?: {
165
+ readonly title?: string;
166
+ readonly readOnlyHint?: boolean;
167
+ readonly destructiveHint?: boolean;
168
+ readonly idempotentHint?: boolean;
169
+ readonly openWorldHint?: boolean;
170
+ };
171
+ readonly schedules?: readonly {
172
+ readonly name: string;
173
+ readonly timing: {
174
+ readonly kind: "interval";
175
+ readonly milliseconds: number;
176
+ } | {
177
+ readonly kind: "cron";
178
+ readonly calendar: {
179
+ readonly expression: string;
180
+ readonly timezone: string;
181
+ };
182
+ };
183
+ readonly input: Schema.Json;
184
+ }[];
185
+ readonly readOnly?: boolean;
186
+ readonly router?: string;
187
+ readonly tags?: readonly string[];
188
+ })[];
189
+ routers: {
190
+ readonly path: string;
191
+ readonly description?: string;
192
+ readonly error?: import("../index.js").ProviderError | SkillLoadFailed | HostDeclarationInvalid | HostEvaluationFailed | import("../mcp.js").McpError;
193
+ readonly title?: string;
194
+ readonly tags?: {
195
+ readonly [x: string]: string;
196
+ };
197
+ readonly icons?: readonly {
198
+ readonly src: string;
199
+ readonly mimeType?: string;
200
+ readonly sizes?: readonly string[];
201
+ readonly theme?: "light" | "dark";
202
+ }[];
203
+ readonly skill?: string;
204
+ }[];
205
+ }, import("../index.js").ProviderError | SkillLoadFailed | HostDeclarationInvalid | HostEvaluationFailed | import("../mcp.js").McpError, never>;
206
+ /**
207
+ * One skill for each router with instructions. Skills and tools fail independently: a dynamic
208
+ * router whose metadata cannot be read, including the root, contributes no skill and does not
209
+ * fail the others. Metadata comes through each source's catalog cache, like a tool listing.
210
+ */
211
+ export declare const routerSkills: (root: AppRouter | DynamicRouter | undefined) => Effect.Effect<{
212
+ readonly description: string;
213
+ readonly name: string;
214
+ readonly files: readonly {
215
+ readonly path: string;
216
+ readonly content: string;
217
+ }[];
218
+ readonly license?: string;
219
+ readonly compatibility?: string;
220
+ readonly metadata?: {
221
+ readonly [x: string]: string;
222
+ };
223
+ readonly "allowed-tools"?: string;
224
+ }[], never, never>;
@@ -0,0 +1,68 @@
1
+ import { HostedTool } from "../contracts/host.js";
2
+ import type { AppOperation } from "../contracts/operations.js";
3
+ import { RouterMeta, type AppRouter, type DynamicRouter, type RouterIcon } from "../contracts/router.js";
4
+ import type { Approval } from "../approval.js";
5
+ import { type OperationDeclaration, type RouterChild, type RouterDeclaration } from "./operations.js";
6
+ export type { RouterChild, RouterDeclaration } from "./operations.js";
7
+ /** Author metadata for a router. Instructions become a skill named after the router's path. */
8
+ export interface RouterOptions {
9
+ readonly title?: string;
10
+ readonly description?: string;
11
+ readonly instructions?: string;
12
+ readonly icons?: readonly RouterIcon[];
13
+ readonly tags?: Readonly<Record<string, string>>;
14
+ }
15
+ /** Wrap a native router. Protocol helpers use this for the routers they build. */
16
+ export declare const routerDeclaration: (node: AppRouter | DynamicRouter) => RouterDeclaration;
17
+ /** Accept only framework-created routers. */
18
+ export declare const nativeRouter: (value: unknown) => AppRouter | DynamicRouter | undefined;
19
+ /** Author fields win; a field the author omits keeps the source's value. */
20
+ export declare const mergeMeta: (base: RouterMeta | undefined, override: RouterMeta | undefined) => RouterMeta | undefined;
21
+ /**
22
+ * Group operations and routers under path keys, like tRPC's nested routers, with metadata an
23
+ * agent can read. Passing an existing router instead of children overrides its metadata:
24
+ * `router(mcpRouter(options), { description: "..." })`.
25
+ */
26
+ export declare function router<Query = unknown, Mutation = unknown>(children: Readonly<Record<string, RouterChild<Query, Mutation>>>, options?: RouterOptions): RouterDeclaration<Query, Mutation>;
27
+ export declare function router<Query, Mutation>(source: RouterDeclaration<Query, Mutation>, options: RouterOptions): RouterDeclaration<Query, Mutation>;
28
+ /**
29
+ * Declare a router whose tools are discovered when read. `list` returns tools with names relative
30
+ * to this router; mark queries with `readOnly: true`. `resolve` receives one of those names.
31
+ */
32
+ export declare const dynamicRouter: (source: {
33
+ readonly meta?: () => RouterOptions | Promise<RouterOptions>;
34
+ readonly list: () => readonly HostedTool[] | Promise<readonly HostedTool[]>;
35
+ readonly resolve: (name: string) => OperationDeclaration<"query" | "mutation", unknown> | undefined | Promise<OperationDeclaration<"query" | "mutation", unknown> | undefined>;
36
+ }) => RouterDeclaration;
37
+ /** Join a router path and a relative name. The root router's path is "". */
38
+ export declare const joinPath: (path: string, name: string) => string;
39
+ /** Where a full tool name points: a declared operation, or a name inside a dynamic router. */
40
+ export type Location = {
41
+ readonly kind: "operation";
42
+ readonly operation: AppOperation;
43
+ readonly router: string;
44
+ } | {
45
+ readonly kind: "dynamic";
46
+ readonly source: DynamicRouter;
47
+ readonly router: string;
48
+ readonly name: string;
49
+ };
50
+ /**
51
+ * Walk static keys until the name ends at an operation or enters a dynamic router, which receives
52
+ * the rest of the name. Static keys contain no dots, so every name has at most one location.
53
+ */
54
+ export declare const locate: (root: AppRouter | DynamicRouter | undefined, name: string) => Location | undefined;
55
+ /** Every declared operation with its full name and owning router. Dynamic routers are not listed. */
56
+ export declare const declaredOperations: (root: AppRouter | undefined, path?: string) => Array<{
57
+ readonly name: string;
58
+ readonly router: string;
59
+ readonly operation: AppOperation;
60
+ }>;
61
+ /**
62
+ * Choose an approval for each operation a router contains, including tools a dynamic router
63
+ * resolves later. `policy` receives the operation and its name relative to this router; returning
64
+ * undefined keeps the operation's own approval. Read hints with `toolAnnotations(operation)`.
65
+ * Apply it to each account's router before `accountRouter` combines them, so every account keeps
66
+ * its own tools' hints.
67
+ */
68
+ export declare const withApprovals: <Query, Mutation>(source: RouterDeclaration<Query, Mutation>, policy: (operation: OperationDeclaration<"query" | "mutation", never>, name: string) => Approval | undefined) => RouterDeclaration<Query, Mutation>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Let the runtime run its own tasks between long synchronous steps. In a Worker, a large OpenAPI
3
+ * compilation that never yields leaves the garbage collector only long, full pauses; yielding
4
+ * between steps measurably shortens it. A timer is used because a resolved promise would continue
5
+ * without leaving the current task.
6
+ */
7
+ export declare const yieldToRuntime: () => Promise<void>;