stitchkit 0.2.0 → 0.4.0

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 (136) hide show
  1. package/README.md +11 -10
  2. package/dist/browser/client.d.ts.map +1 -1
  3. package/dist/browser/http.d.ts +5 -0
  4. package/dist/browser/http.d.ts.map +1 -1
  5. package/dist/browser/socket-io.d.ts +17 -0
  6. package/dist/browser/socket-io.d.ts.map +1 -1
  7. package/dist/cli.d.ts +23 -0
  8. package/dist/cli.d.ts.map +1 -0
  9. package/dist/cli.js +21 -0
  10. package/dist/contract/define.d.ts +35 -2
  11. package/dist/contract/define.d.ts.map +1 -1
  12. package/dist/contract/index.d.ts +1 -1
  13. package/dist/contract/index.d.ts.map +1 -1
  14. package/dist/contract/index.js +2 -1
  15. package/dist/index-0ed3bx43.js +33 -0
  16. package/dist/index-0ma1eqv4.js +1007 -0
  17. package/dist/index-1cf8jkhf.js +219 -0
  18. package/dist/index-37x76zdn.js +4 -0
  19. package/dist/{index-v2z2v3mq.js → index-3qmtdfpa.js} +304 -62
  20. package/dist/index-48ffdxgk.js +6 -0
  21. package/dist/{index-5sxnvwb1.js → index-78q1qm7v.js} +6 -3
  22. package/dist/{index-kckky6zw.js → index-afzt3nmx.js} +1 -1
  23. package/dist/{index-n7bmdwmz.js → index-d4rwrjbc.js} +8 -4
  24. package/dist/index-kzfs85xp.js +9 -0
  25. package/dist/index-mwmpw6j1.js +60 -0
  26. package/dist/{index-a35v22fh.js → index-vhdvv00d.js} +13 -5
  27. package/dist/index-x3fcszf8.js +8 -0
  28. package/dist/index.js +17 -4
  29. package/dist/internal/errors.d.ts +13 -1
  30. package/dist/internal/errors.d.ts.map +1 -1
  31. package/dist/internal/http-input.d.ts +13 -0
  32. package/dist/internal/http-input.d.ts.map +1 -0
  33. package/dist/internal/safe-json.d.ts +19 -0
  34. package/dist/internal/safe-json.d.ts.map +1 -0
  35. package/dist/internal/secure-fetch.d.ts +27 -0
  36. package/dist/internal/secure-fetch.d.ts.map +1 -0
  37. package/dist/internal/within-dir.d.ts +7 -0
  38. package/dist/internal/within-dir.d.ts.map +1 -0
  39. package/dist/node.d.ts +10 -1
  40. package/dist/node.d.ts.map +1 -1
  41. package/dist/node.js +41 -7
  42. package/dist/observability/audit.d.ts.map +1 -1
  43. package/dist/observability/context.d.ts +9 -1
  44. package/dist/observability/context.d.ts.map +1 -1
  45. package/dist/observability/event.d.ts +4 -0
  46. package/dist/observability/event.d.ts.map +1 -1
  47. package/dist/observability/index.js +38 -15
  48. package/dist/observability/sanitize.d.ts.map +1 -1
  49. package/dist/react.js +2 -0
  50. package/dist/server/context.d.ts +3 -2
  51. package/dist/server/context.d.ts.map +1 -1
  52. package/dist/server/create.d.ts.map +1 -1
  53. package/dist/server/event-bus.d.ts +10 -1
  54. package/dist/server/event-bus.d.ts.map +1 -1
  55. package/dist/server/implement.d.ts.map +1 -1
  56. package/dist/server/index.d.ts +6 -3
  57. package/dist/server/index.d.ts.map +1 -1
  58. package/dist/server/index.js +203 -193
  59. package/dist/server/logger.d.ts +5 -4
  60. package/dist/server/logger.d.ts.map +1 -1
  61. package/dist/server/middleware/auth.d.ts +41 -1
  62. package/dist/server/middleware/auth.d.ts.map +1 -1
  63. package/dist/server/middleware/cookies.d.ts.map +1 -1
  64. package/dist/server/middleware/cors.d.ts +7 -0
  65. package/dist/server/middleware/cors.d.ts.map +1 -1
  66. package/dist/server/middleware/pkce.d.ts +17 -0
  67. package/dist/server/middleware/pkce.d.ts.map +1 -0
  68. package/dist/server/multipart.d.ts +2 -1
  69. package/dist/server/multipart.d.ts.map +1 -1
  70. package/dist/server/node.d.ts +9 -0
  71. package/dist/server/node.d.ts.map +1 -1
  72. package/dist/server/openapi.d.ts +52 -0
  73. package/dist/server/openapi.d.ts.map +1 -0
  74. package/dist/server/rate-limit.d.ts +7 -2
  75. package/dist/server/rate-limit.d.ts.map +1 -1
  76. package/dist/server/request.d.ts +27 -4
  77. package/dist/server/request.d.ts.map +1 -1
  78. package/dist/server/router.d.ts +4 -2
  79. package/dist/server/router.d.ts.map +1 -1
  80. package/dist/server/socket-io.d.ts +60 -15
  81. package/dist/server/socket-io.d.ts.map +1 -1
  82. package/dist/server/stream.d.ts +3 -1
  83. package/dist/server/stream.d.ts.map +1 -1
  84. package/dist/server/types.d.ts +17 -1
  85. package/dist/server/types.d.ts.map +1 -1
  86. package/dist/server/websocket.d.ts +73 -0
  87. package/dist/server/websocket.d.ts.map +1 -0
  88. package/dist/tools/cli-args.d.ts +68 -0
  89. package/dist/tools/cli-args.d.ts.map +1 -0
  90. package/dist/tools/cli-format.d.ts +39 -0
  91. package/dist/tools/cli-format.d.ts.map +1 -0
  92. package/dist/tools/cli-wait.d.ts +45 -0
  93. package/dist/tools/cli-wait.d.ts.map +1 -0
  94. package/dist/tools/cli.d.ts +77 -0
  95. package/dist/tools/cli.d.ts.map +1 -0
  96. package/dist/tools/coerce.d.ts +8 -4
  97. package/dist/tools/coerce.d.ts.map +1 -1
  98. package/dist/tools/execute.d.ts +1 -1
  99. package/dist/tools/execute.d.ts.map +1 -1
  100. package/dist/tools/json-schema.d.ts +29 -4
  101. package/dist/tools/json-schema.d.ts.map +1 -1
  102. package/dist/tools/manifest.d.ts +4 -0
  103. package/dist/tools/manifest.d.ts.map +1 -1
  104. package/dist/tools/mcp-app.d.ts +59 -0
  105. package/dist/tools/mcp-app.d.ts.map +1 -0
  106. package/dist/tools/mcp-handler.d.ts +18 -0
  107. package/dist/tools/mcp-handler.d.ts.map +1 -1
  108. package/dist/tools/mcp.d.ts +9 -0
  109. package/dist/tools/mcp.d.ts.map +1 -1
  110. package/dist/tools/mount-download.d.ts +30 -0
  111. package/dist/tools/mount-download.d.ts.map +1 -0
  112. package/dist/tools/mount-upload.d.ts +19 -0
  113. package/dist/tools/mount-upload.d.ts.map +1 -0
  114. package/dist/tools/mount-wait.d.ts +36 -0
  115. package/dist/tools/mount-wait.d.ts.map +1 -0
  116. package/dist/tools/mount.d.ts +8 -4
  117. package/dist/tools/mount.d.ts.map +1 -1
  118. package/dist/tools/native-result.d.ts +17 -0
  119. package/dist/tools/native-result.d.ts.map +1 -0
  120. package/dist/tools/oauth-metadata.d.ts +28 -0
  121. package/dist/tools/oauth-metadata.d.ts.map +1 -0
  122. package/dist/tools/oauth-provider.d.ts +85 -0
  123. package/dist/tools/oauth-provider.d.ts.map +1 -0
  124. package/dist/tools/remote.d.ts +2 -2
  125. package/dist/tools/remote.d.ts.map +1 -1
  126. package/dist/tools/toolkit.d.ts +51 -0
  127. package/dist/tools/toolkit.d.ts.map +1 -0
  128. package/dist/tools/view-file.d.ts +12 -0
  129. package/dist/tools/view-file.d.ts.map +1 -1
  130. package/dist/tools/wait-core.d.ts +33 -0
  131. package/dist/tools/wait-core.d.ts.map +1 -0
  132. package/dist/tools.d.ts +13 -2
  133. package/dist/tools.d.ts.map +1 -1
  134. package/dist/tools.js +637 -424
  135. package/package.json +22 -9
  136. package/dist/index-ke4mx4ea.js +0 -38
@@ -0,0 +1,85 @@
1
+ import type { RawRoute } from '../server/types';
2
+ /** A client as registered via DCR. Public clients (PKCE) carry no secret. */
3
+ export interface RegisteredClient {
4
+ clientId: string;
5
+ redirectUris: string[];
6
+ clientName?: string;
7
+ }
8
+ /** Metadata posted to `/register` (RFC 7591) before a client id is assigned. */
9
+ export interface ClientMetadata {
10
+ redirectUris: string[];
11
+ clientName?: string;
12
+ tokenEndpointAuthMethod?: string;
13
+ }
14
+ /** State persisted between `/authorize` and `/token`, keyed by the auth code. */
15
+ export interface AuthCodeData {
16
+ clientId: string;
17
+ redirectUri: string;
18
+ codeChallenge: string;
19
+ /** Always `S256` — `/authorize` rejects any other method (OAuth 2.1, public client). */
20
+ codeChallengeMethod: 'S256';
21
+ resource: string;
22
+ scope?: string;
23
+ userId: string;
24
+ expiresAt: number;
25
+ }
26
+ /** State persisted for a refresh token. */
27
+ export interface RefreshData {
28
+ clientId: string;
29
+ resource: string;
30
+ scope?: string;
31
+ userId: string;
32
+ }
33
+ /** The parsed `/authorize` request handed to the domain login/consent step. */
34
+ export interface AuthRequest {
35
+ clientId: string;
36
+ redirectUri: string;
37
+ scope?: string;
38
+ resource: string;
39
+ state?: string;
40
+ }
41
+ export interface OAuthProviderConfig {
42
+ /** Authorization-server issuer — its own origin, e.g. `https://api.example.com`. */
43
+ issuer: string;
44
+ /** HMAC secret used to sign access-token JWTs. */
45
+ signingSecret: string;
46
+ /** Canonical resource id (MCP URL) — the access-token `aud`. */
47
+ resource: string;
48
+ /** Access-token lifetime in seconds. Default `3600`. */
49
+ accessTokenTtlSec?: number;
50
+ /** Scopes advertised in server metadata. */
51
+ scopesSupported?: string[];
52
+ /** Path prefix for the OAuth endpoints. Default `/oauth`. */
53
+ basePath?: string;
54
+ /** Client registry (DCR). */
55
+ clients: {
56
+ register(metadata: ClientMetadata): Promise<RegisteredClient>;
57
+ get(clientId: string): Promise<RegisteredClient | null>;
58
+ };
59
+ /** Single-use authorization-code store. `take` must atomically read+delete. */
60
+ codes: {
61
+ save(code: string, data: AuthCodeData): Promise<void>;
62
+ take(code: string): Promise<AuthCodeData | null>;
63
+ };
64
+ /** Optional refresh-token store. Omit to disable the refresh grant. */
65
+ refreshTokens?: {
66
+ save(token: string, data: RefreshData): Promise<void>;
67
+ take(token: string): Promise<RefreshData | null>;
68
+ };
69
+ /**
70
+ * Authenticate the user and capture consent for an `/authorize` request.
71
+ * Return `{ userId }` to issue a code, or a `Response` (e.g. a redirect to a
72
+ * login page) to drive the browser through the domain's own login first.
73
+ */
74
+ authorizeUser(req: Request, authRequest: AuthRequest): Promise<{
75
+ userId: string;
76
+ } | Response>;
77
+ }
78
+ /**
79
+ * Build the OAuth 2.1 authorization-server routes for an MCP resource. Mount the
80
+ * returned routes in the server's `rawRoutes`, alongside
81
+ * `oauthProtectedResourceRoute` and an MCP handler whose `protectedResource`
82
+ * names this issuer.
83
+ */
84
+ export declare function mountOAuthProvider(config: OAuthProviderConfig): RawRoute[];
85
+ //# sourceMappingURL=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- import type { ContractDef, EndpointDef } from '../contract';
1
+ import { type HttpClient } from '../browser/http';
2
+ import { type ContractDef, type EndpointDef } from '../contract';
3
3
  import type { ServiceDef } from '../server/types';
4
4
  export interface ImplementRemoteOptions {
5
5
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../../src/tools/remote.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAkB,MAAM,aAAa,CAAC;AAE5E,OAAO,KAAK,EAAa,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAc7D,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,aAAa,CAAC,EAAE,CACd,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACjE;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACnE,QAAQ,EAAE,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,EAChC,IAAI,EAAE,UAAU,EAChB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,UAAU,CAsCZ"}
1
+ {"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../../src/tools/remote.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,WAAW,EAEjB,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAa,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAc7D,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,aAAa,CAAC,EAAE,CACd,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACjE;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACnE,QAAQ,EAAE,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,EAChC,IAAI,EAAE,UAAU,EAChB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,UAAU,CA8DZ"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Typed tool-path context — the tool-side mirror of `createImplement<TCtx>()`.
3
+ *
4
+ * A handler is already typed (`createImplement<AppContext>()` gives `ctx.user`
5
+ * its real type on every surface). What was untyped is the *wiring*: the
6
+ * `context` a tool transport injects, and a `ToolExtend.resolve` result, were
7
+ * `Record<string, unknown>` — TypeScript could not catch a missing or
8
+ * wrong-typed `user`. → ADR 0017.
9
+ *
10
+ * `createToolkit<AppContext>()` fixes the context shape once and returns the
11
+ * tool-mounting functions with `context` (and `extend.resolve`) checked against
12
+ * it — so the CLI, MCP and agent surfaces are born as type-safe as the handler.
13
+ * It is pure typing sugar: each method forwards verbatim to the underlying
14
+ * function, which still accepts the loose form for callers that do not opt in
15
+ * (ADR 0002 keeps the core context loose by default).
16
+ */
17
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
18
+ import type { ToolSet } from 'ai';
19
+ import type { ServiceDef } from '../server/types';
20
+ import { type AgentMountConfig } from './agent';
21
+ import { type CliConfig } from './cli';
22
+ import { type McpMountConfig, type McpServerBuildConfig } from './mcp';
23
+ import { type McpHandlerConfig } from './mcp-handler';
24
+ import { type StdioMcpServerConfig } from './mcp-stdio';
25
+ import type { ToolExtend } from './mount';
26
+ /** Re-type a config's static `context` (and `extend`) to the toolkit's `TContext`. */
27
+ type WithStaticContext<C, TContext extends Record<string, unknown>> = Omit<C, 'context' | 'extend'> & {
28
+ context?: TContext;
29
+ extend?: ToolExtend<TContext>;
30
+ };
31
+ /** Re-type a config's `(auth) => context` factory to the toolkit's `TContext`. */
32
+ type WithAuthContext<C, TAuth, TContext extends Record<string, unknown>> = Omit<C, 'context'> & {
33
+ context?: (auth: TAuth) => TContext;
34
+ };
35
+ /** The context-pinned tool surface returned by `createToolkit`. */
36
+ export interface Toolkit<TContext extends Record<string, unknown>> {
37
+ mountMcp(server: McpServer, services: ServiceDef | ServiceDef[], config?: WithStaticContext<McpMountConfig, TContext>): void;
38
+ mountAgent(services: ServiceDef | ServiceDef[], config?: WithStaticContext<AgentMountConfig, TContext>): ToolSet;
39
+ buildMcpServer<TAuth>(config: WithAuthContext<McpServerBuildConfig<TAuth>, TAuth, TContext>, auth: TAuth): McpServer;
40
+ createMcpHandler<TAuth>(config: WithAuthContext<McpHandlerConfig<TAuth>, TAuth, TContext>): (req: Request) => Promise<Response>;
41
+ createStdioMcpServer<TAuth>(config: WithAuthContext<StdioMcpServerConfig<TAuth>, TAuth, TContext>): Promise<McpServer>;
42
+ createCli<TAuth = unknown>(config: CliConfig<TAuth, TContext>): Promise<void>;
43
+ }
44
+ /**
45
+ * Fix the tool-handler context type once. `const tools =
46
+ * createToolkit<AppContext>()` — then `tools.createCli`, `tools.mountMcp`, … all
47
+ * type-check their injected `context` against `AppContext`.
48
+ */
49
+ export declare function createToolkit<TContext extends Record<string, unknown>>(): Toolkit<TContext>;
50
+ export {};
51
+ //# sourceMappingURL=toolkit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolkit.d.ts","sourceRoot":"","sources":["../../src/tools/toolkit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC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nC,MAAM,CAAC,EAAE,iBAAiB,CAAC,gBAAgB,EAAE,QAAQ,CAAC,GACrD,OAAO,CAAC;IACX,cAAc,CAAC,KAAK,EAClB,MAAM,EAAE,eAAe,CAAC,oBAAoB,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,EACrE,IAAI,EAAE,KAAK,GACV,SAAS,CAAC;IACb,gBAAgB,CAAC,KAAK,EACpB,MAAM,EAAE,eAAe,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,GAChE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvC,oBAAoB,CAAC,KAAK,EACxB,MAAM,EAAE,eAAe,CAAC,oBAAoB,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,GACpE,OAAO,CAAC,SAAS,CAAC,CAAC;IACtB,SAAS,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/E;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,CAS3F"}
@@ -13,6 +13,16 @@
13
13
  * sandboxed to a `baseDir`, and downloads are capped before they reach memory.
14
14
  */
15
15
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
16
+ /**
17
+ * Annotation telling the client who a content block is for. `audience` lists
18
+ * `'user'` (render for the human) and/or `'assistant'` (keep in model context);
19
+ * `priority` (0–1) hints how prominently. Same shape as the MCP resource/prompt
20
+ * annotation.
21
+ */
22
+ export interface McpAnnotations {
23
+ audience?: ('user' | 'assistant')[];
24
+ priority?: number;
25
+ }
16
26
  /** An MCP content block — text / image / audio (video cannot be inlined). */
17
27
  export type McpMediaContent = {
18
28
  type: 'text';
@@ -21,10 +31,12 @@ export type McpMediaContent = {
21
31
  type: 'image';
22
32
  data: string;
23
33
  mimeType: string;
34
+ annotations?: McpAnnotations;
24
35
  } | {
25
36
  type: 'audio';
26
37
  data: string;
27
38
  mimeType: string;
39
+ annotations?: McpAnnotations;
28
40
  };
29
41
  export interface ViewFileOptions {
30
42
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"view-file.d.ts","sourceRoot":"","sources":["../../src/tools/view-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAMH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAsBzE,6EAA6E;AAC7E,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACjD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AA6HD;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,eAAe,EAAE,CAAC,CA+B5B;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,GAAE,eAAoB,GAAG,IAAI,CA4BpF"}
1
+ {"version":3,"file":"view-file.d.ts","sourceRoot":"","sources":["../../src/tools/view-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAwBzE;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,CAAC,MAAM,GAAG,WAAW,CAAC,EAAE,CAAC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,6EAA6E;AAC7E,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,cAAc,CAAA;CAAE,GAC/E;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,cAAc,CAAA;CAAE,CAAC;AAEpF,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AA4DD;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,eAAe,EAAE,CAAC,CA4C5B;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,GAAE,eAAoB,GAAG,IAAI,CA+BpF"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The shared poll-until-done loop — one backoff/timeout engine behind both the
3
+ * CLI `--wait` (`pollUntilDone`) and the native MCP `mountWait` tool, so the
4
+ * polling mechanics live in exactly one place. Domain-free (ADR 0002): the
5
+ * caller supplies how to fetch a state (`poll`) and when it is terminal (`done`).
6
+ */
7
+ export interface PollUntilParams<T> {
8
+ /** Fetch the current state — called once per tick. */
9
+ poll: () => Promise<T>;
10
+ /** Stop when this returns `true` for a fetched state. */
11
+ done: (state: T) => boolean;
12
+ /** Backoff schedule in seconds; the last entry repeats. Default `[2,3,5,5,8,10]`. */
13
+ backoff?: number[];
14
+ /** Max seconds before giving up. Default `600`. */
15
+ timeoutSec?: number;
16
+ /** Injectable sleep for tests. */
17
+ sleepFn?: (ms: number) => Promise<void>;
18
+ /** Progress callback — `(attempt, elapsedSec)` after each non-terminal poll. */
19
+ onTick?: (attempt: number, elapsedSec: number) => void;
20
+ }
21
+ export interface PollUntilResult<T> {
22
+ /** The last fetched state. */
23
+ state: T;
24
+ /** `true` when the timeout was hit before `done`. */
25
+ timedOut: boolean;
26
+ }
27
+ /**
28
+ * Poll until `done` or the timeout. Polls first, then sleeps with backoff —
29
+ * returns the terminal state (`timedOut: false`) or the last state seen when
30
+ * the deadline passed (`timedOut: true`).
31
+ */
32
+ export declare function pollUntil<T>(params: PollUntilParams<T>): Promise<PollUntilResult<T>>;
33
+ //# sourceMappingURL=wait-core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wait-core.d.ts","sourceRoot":"","sources":["../../src/tools/wait-core.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,sDAAsD;IACtD,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC;IACvB,yDAAyD;IACzD,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC;IAC5B,qFAAqF;IACrF,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,mDAAmD;IACnD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,gFAAgF;IAChF,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;CACxD;AAED,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,8BAA8B;IAC9B,KAAK,EAAE,CAAC,CAAC;IACT,qDAAqD;IACrD,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAkB1F"}
package/dist/tools.d.ts CHANGED
@@ -1,12 +1,23 @@
1
+ export type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
1
2
  export { type AgentContext, type AgentMountConfig, mountAgent } from './tools/agent';
2
- export { withJsonCoercion } from './tools/coerce';
3
+ export { type CliConfig, createCli } from './tools/cli';
4
+ export type { ExitCodeMap } from './tools/cli-format';
5
+ export type { CliWaitConfig } from './tools/cli-wait';
6
+ export { coerceJsonArgs } from './tools/coerce';
3
7
  export type { ToolCallHooks, ToolLifecycle, ToolResult } from './tools/execute';
4
8
  export { flattenDiscriminatedUnion } from './tools/flatten';
5
9
  export { buildToolManifest, type ToolManifestEntry } from './tools/manifest';
6
- export { buildMcpServer, type IncompatibleSchemaPolicy, type McpMountConfig, type McpServerBuildConfig, mountMcp, validateMcpSchemas, } from './tools/mcp';
10
+ export { buildMcpServer, type IncompatibleSchemaPolicy, type McpMountConfig, type McpServerBuildConfig, mountMcp, mountMcpResource, validateMcpSchemas, } from './tools/mcp';
11
+ export { EXT_APPS_BUNDLE_PLACEHOLDER, inlineMcpAppBundle, type McpAppCsp, type McpAppResourceMeta, type McpResourceDef, RESOURCE_MIME_TYPE, } from './tools/mcp-app';
7
12
  export { createMcpHandler, type McpHandlerConfig } from './tools/mcp-handler';
8
13
  export { createStdioMcpServer, type StdioMcpServerConfig } from './tools/mcp-stdio';
9
14
  export { collectTools, type MountableTool, type ToolExtend } from './tools/mount';
15
+ export { type DownloadToolConfig, mountDownload } from './tools/mount-download';
16
+ export { mountUpload, type UploadToolConfig } from './tools/mount-upload';
17
+ export { mountWait, type WaitToolConfig } from './tools/mount-wait';
18
+ export { oauthProtectedResourceRoute, PROTECTED_RESOURCE_PATH, type ProtectedResourceConfig, protectedResourceMetadataUrl, wwwAuthenticateHeader, } from './tools/oauth-metadata';
19
+ export { type AuthCodeData, type AuthRequest, type ClientMetadata, mountOAuthProvider, type OAuthProviderConfig, type RefreshData, type RegisteredClient, } from './tools/oauth-provider';
10
20
  export { type ImplementRemoteOptions, implementRemote } from './tools/remote';
21
+ export { createToolkit, type Toolkit } from './tools/toolkit';
11
22
  export { type McpMediaContent, mountViewFile, resolveMedia } from './tools/view-file';
12
23
  //# sourceMappingURL=tools.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EACL,cAAc,EACd,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,QAAQ,EACR,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,KAAK,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAClF,OAAO,EAAE,KAAK,sBAAsB,EAA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