stitchkit 0.103.12 → 0.104.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 (225) hide show
  1. package/CHANGELOG.md +112 -0
  2. package/darwin-native.cjs +12 -0
  3. package/darwin-native.d.cts +2 -0
  4. package/dist/agent-runtime/store-conformance-lifecycle.d.ts +10 -10
  5. package/dist/application/directory-inbox-accept.d.ts +13 -0
  6. package/dist/application/directory-inbox-accept.d.ts.map +1 -0
  7. package/dist/application/directory-inbox-contract.d.ts +42 -5
  8. package/dist/application/directory-inbox-contract.d.ts.map +1 -1
  9. package/dist/application/directory-inbox-delivery.d.ts +14 -0
  10. package/dist/application/directory-inbox-delivery.d.ts.map +1 -0
  11. package/dist/application/directory-inbox-files.d.ts +28 -0
  12. package/dist/application/directory-inbox-files.d.ts.map +1 -0
  13. package/dist/application/directory-inbox-state.d.ts +14 -0
  14. package/dist/application/directory-inbox-state.d.ts.map +1 -0
  15. package/dist/application/directory-inbox.d.ts +2 -1
  16. package/dist/application/directory-inbox.d.ts.map +1 -1
  17. package/dist/application/file-state-store.d.ts +2 -8
  18. package/dist/application/file-state-store.d.ts.map +1 -1
  19. package/dist/application/state-store.d.ts +6 -1
  20. package/dist/application/state-store.d.ts.map +1 -1
  21. package/dist/browser/client-arguments.d.ts +4 -0
  22. package/dist/browser/client-arguments.d.ts.map +1 -0
  23. package/dist/browser/client-executors.d.ts.map +1 -1
  24. package/dist/browser/client.d.ts.map +1 -1
  25. package/dist/browser/contract-stream.d.ts.map +1 -1
  26. package/dist/browser/http.d.ts +2 -1
  27. package/dist/browser/http.d.ts.map +1 -1
  28. package/dist/browser/native-fetch.d.ts +8 -0
  29. package/dist/browser/native-fetch.d.ts.map +1 -0
  30. package/dist/contract/errors.d.ts +16 -12
  31. package/dist/contract/errors.d.ts.map +1 -1
  32. package/dist/contract/normalize.d.ts +5 -1
  33. package/dist/contract/normalize.d.ts.map +1 -1
  34. package/dist/contract/stream.d.ts +1 -0
  35. package/dist/contract/stream.d.ts.map +1 -1
  36. package/dist/entrypoints/agent-runtime/browser.js +3 -3
  37. package/dist/entrypoints/agent-runtime/coding-tools.js +8 -6
  38. package/dist/entrypoints/agent-runtime/harness-tools.js +8 -8
  39. package/dist/entrypoints/agent-runtime/harness.js +12 -11
  40. package/dist/entrypoints/agent-runtime/realtime.js +3 -3
  41. package/dist/entrypoints/agent-runtime/sandbox.js +8 -6
  42. package/dist/entrypoints/agent-runtime.js +13 -13
  43. package/dist/entrypoints/application/diagnostic-journal.js +3 -2
  44. package/dist/entrypoints/application/directory-inbox.js +424 -119
  45. package/dist/entrypoints/application/grammy.js +1 -1
  46. package/dist/entrypoints/application.d.ts +2 -2
  47. package/dist/entrypoints/application.d.ts.map +1 -1
  48. package/dist/entrypoints/application.js +7 -3
  49. package/dist/entrypoints/cli.d.ts +2 -0
  50. package/dist/entrypoints/cli.d.ts.map +1 -1
  51. package/dist/entrypoints/cli.js +757 -136
  52. package/dist/entrypoints/contract.js +3 -3
  53. package/dist/entrypoints/files.js +11 -107
  54. package/dist/entrypoints/index.js +7 -7
  55. package/dist/entrypoints/node.js +8 -8
  56. package/dist/entrypoints/observability.js +2 -2
  57. package/dist/entrypoints/process.js +2 -1
  58. package/dist/entrypoints/react.js +1 -1
  59. package/dist/entrypoints/remote.js +19 -6
  60. package/dist/entrypoints/server.d.ts +1 -1
  61. package/dist/entrypoints/server.d.ts.map +1 -1
  62. package/dist/entrypoints/server.js +20 -14
  63. package/dist/entrypoints/telegram.d.ts +1 -0
  64. package/dist/entrypoints/telegram.d.ts.map +1 -1
  65. package/dist/entrypoints/telegram.js +214 -98
  66. package/dist/entrypoints/testing.js +7 -7
  67. package/dist/entrypoints/tools/connections.d.ts +2 -2
  68. package/dist/entrypoints/tools/connections.d.ts.map +1 -1
  69. package/dist/entrypoints/tools/connections.js +427 -294
  70. package/dist/entrypoints/tools/invoker.js +6 -6
  71. package/dist/entrypoints/tools/mcp.d.ts +12 -0
  72. package/dist/entrypoints/tools/mcp.d.ts.map +1 -0
  73. package/dist/entrypoints/tools/mcp.js +45 -0
  74. package/dist/entrypoints/tools.d.ts +1 -0
  75. package/dist/entrypoints/tools.d.ts.map +1 -1
  76. package/dist/entrypoints/tools.js +82 -1147
  77. package/dist/entrypoints/tracking.js +1 -1
  78. package/dist/files/boundary.d.ts +2 -8
  79. package/dist/files/boundary.d.ts.map +1 -1
  80. package/dist/files/file-io.d.ts +0 -5
  81. package/dist/files/file-io.d.ts.map +1 -1
  82. package/dist/files/read.d.ts +2 -2
  83. package/dist/files/read.d.ts.map +1 -1
  84. package/dist/index-1a6jtnd9.js +88 -0
  85. package/dist/{index-fyphpknh.js → index-22rhg58f.js} +1 -1
  86. package/dist/index-269zqj8m.js +77 -0
  87. package/dist/{index-r34mvse1.js → index-27a2pj09.js} +1 -1
  88. package/dist/{index-r956rndn.js → index-2hyavjjj.js} +3 -3
  89. package/dist/{index-m2xqkv55.js → index-2vnh05w4.js} +83 -14
  90. package/dist/{index-pw99k9h5.js → index-43p08g7t.js} +1 -1
  91. package/dist/{index-xwq9j1sf.js → index-4e0ah203.js} +9 -7
  92. package/dist/{index-nybn2err.js → index-5csmzesf.js} +1 -1
  93. package/dist/{index-qapzv4p5.js → index-5z6jn897.js} +1 -1
  94. package/dist/{index-ahvsksw5.js → index-6d9xaxw1.js} +1 -1
  95. package/dist/{index-ahtnte39.js → index-6drst9sg.js} +46 -35
  96. package/dist/{index-x87j7csh.js → index-77nxk6ay.js} +2 -2
  97. package/dist/{index-dnn9z96q.js → index-a0zzh8ak.js} +3 -3
  98. package/dist/{index-kmpzj1cq.js → index-a3wma1hk.js} +1 -1
  99. package/dist/{index-j8aw2c0e.js → index-bakgedh8.js} +35 -7
  100. package/dist/index-bhb950qs.js +1145 -0
  101. package/dist/{index-tgzhq07n.js → index-cvda079a.js} +1 -1
  102. package/dist/{index-n2gre124.js → index-fa4wg312.js} +4 -4
  103. package/dist/{index-zp4jpkp0.js → index-fk18k56k.js} +2 -2
  104. package/dist/{index-afjvjyck.js → index-g2j7pnak.js} +2 -134
  105. package/dist/index-g95fk660.js +116 -0
  106. package/dist/{index-ej331hah.js → index-gxm9rc97.js} +1 -1
  107. package/dist/{index-r5c4fedv.js → index-h2fhjqy7.js} +2 -1
  108. package/dist/{index-sybedc8b.js → index-hbd32c6a.js} +23 -94
  109. package/dist/index-jd470k6q.js +109 -0
  110. package/dist/{index-b2bz0kdm.js → index-kb8styz3.js} +4 -3
  111. package/dist/{index-0c419yx7.js → index-kemm0ej5.js} +12 -9
  112. package/dist/{index-806d5phm.js → index-ptn0g0gj.js} +7 -7
  113. package/dist/{index-w575evhq.js → index-r4r70zmh.js} +1 -1
  114. package/dist/{index-12m2v2a9.js → index-s4evrmp5.js} +1 -1
  115. package/dist/{index-1khy8y7n.js → index-t1sr4aks.js} +3 -3
  116. package/dist/index-v5ee8ath.js +88 -0
  117. package/dist/{index-45tdvqa3.js → index-wh0ecvyk.js} +1 -1
  118. package/dist/{index-n53mswt3.js → index-x928baz2.js} +8 -1
  119. package/dist/index-yk4g8805.js +133 -0
  120. package/dist/{index-ygkka6zn.js → index-ywppsaby.js} +28 -5
  121. package/dist/{index-xvdd2rbb.js → index-za6j7nwy.js} +19 -5
  122. package/dist/internal/bounded-file-read.d.ts +41 -0
  123. package/dist/internal/bounded-file-read.d.ts.map +1 -0
  124. package/dist/internal/darwin-binding-error.d.ts +24 -0
  125. package/dist/internal/darwin-binding-error.d.ts.map +1 -0
  126. package/dist/internal/darwin-binding.d.ts.map +1 -1
  127. package/dist/internal/exclusive-lock.d.ts +2 -0
  128. package/dist/internal/exclusive-lock.d.ts.map +1 -1
  129. package/dist/internal/with-exclusive-lock.d.ts +4 -2
  130. package/dist/internal/with-exclusive-lock.d.ts.map +1 -1
  131. package/dist/telegram/broadcast-delivery.d.ts +23 -0
  132. package/dist/telegram/broadcast-delivery.d.ts.map +1 -0
  133. package/dist/telegram/broadcast-failure.d.ts +22 -0
  134. package/dist/telegram/broadcast-failure.d.ts.map +1 -0
  135. package/dist/telegram/broadcast-state.d.ts +6 -3
  136. package/dist/telegram/broadcast-state.d.ts.map +1 -1
  137. package/dist/telegram/broadcast.d.ts +10 -5
  138. package/dist/telegram/broadcast.d.ts.map +1 -1
  139. package/dist/tools/cli/args-fields.d.ts +2 -0
  140. package/dist/tools/cli/args-fields.d.ts.map +1 -1
  141. package/dist/tools/cli/args.d.ts.map +1 -1
  142. package/dist/tools/cli/format.d.ts.map +1 -1
  143. package/dist/tools/cli/invoke.d.ts +2 -2
  144. package/dist/tools/cli/invoke.d.ts.map +1 -1
  145. package/dist/tools/cli/publication-assets.d.ts +10 -0
  146. package/dist/tools/cli/publication-assets.d.ts.map +1 -0
  147. package/dist/tools/cli/publication-contract.d.ts +75 -0
  148. package/dist/tools/cli/publication-contract.d.ts.map +1 -0
  149. package/dist/tools/cli/publication-control.d.ts +4 -0
  150. package/dist/tools/cli/publication-control.d.ts.map +1 -0
  151. package/dist/tools/cli/publication-storage.d.ts +32 -0
  152. package/dist/tools/cli/publication-storage.d.ts.map +1 -0
  153. package/dist/tools/cli/publication.d.ts +35 -0
  154. package/dist/tools/cli/publication.d.ts.map +1 -0
  155. package/dist/tools/cli/update.d.ts.map +1 -1
  156. package/dist/tools/connections/define.d.ts.map +1 -1
  157. package/dist/tools/connections/error-projection.d.ts +4 -0
  158. package/dist/tools/connections/error-projection.d.ts.map +1 -0
  159. package/dist/tools/connections/errors.d.ts +24 -8
  160. package/dist/tools/connections/errors.d.ts.map +1 -1
  161. package/dist/tools/connections/limits.d.ts +11 -31
  162. package/dist/tools/connections/limits.d.ts.map +1 -1
  163. package/dist/tools/connections/mcp-client.d.ts +6 -4
  164. package/dist/tools/connections/mcp-client.d.ts.map +1 -1
  165. package/dist/tools/connections/mcp.d.ts.map +1 -1
  166. package/dist/tools/connections/openapi.d.ts.map +1 -1
  167. package/dist/tools/connections/operation-limits.d.ts +25 -0
  168. package/dist/tools/connections/operation-limits.d.ts.map +1 -0
  169. package/dist/tools/connections/sse-frames.d.ts +11 -2
  170. package/dist/tools/connections/sse-frames.d.ts.map +1 -1
  171. package/dist/tools/connections/sse-session.d.ts +15 -2
  172. package/dist/tools/connections/sse-session.d.ts.map +1 -1
  173. package/dist/tools/connections/types.d.ts +19 -1
  174. package/dist/tools/connections/types.d.ts.map +1 -1
  175. package/dist/tools/execute-result.d.ts.map +1 -1
  176. package/dist/tools/execute.d.ts.map +1 -1
  177. package/dist/tools/internal/observe-hook.d.ts +3 -0
  178. package/dist/tools/internal/observe-hook.d.ts.map +1 -0
  179. package/dist/tools/internal/surface-projector.d.ts +2 -1
  180. package/dist/tools/internal/surface-projector.d.ts.map +1 -1
  181. package/dist/tools/mcp/mount.d.ts +2 -2
  182. package/dist/tools/mcp/mount.d.ts.map +1 -1
  183. package/dist/tools/mcp/prepare.d.ts +4 -5
  184. package/dist/tools/mcp/prepare.d.ts.map +1 -1
  185. package/dist/tools/mcp/register.d.ts +4 -1
  186. package/dist/tools/mcp/register.d.ts.map +1 -1
  187. package/dist/tools/mcp/runtime-tools.d.ts.map +1 -1
  188. package/dist/tools/remote.d.ts.map +1 -1
  189. package/dist/tools/runtime-tool-execution.d.ts +65 -0
  190. package/dist/tools/runtime-tool-execution.d.ts.map +1 -0
  191. package/dist/tools/runtime-tool-mcp.d.ts +27 -0
  192. package/dist/tools/runtime-tool-mcp.d.ts.map +1 -0
  193. package/dist/tools/runtime-tool.d.ts +9 -60
  194. package/dist/tools/runtime-tool.d.ts.map +1 -1
  195. package/dist/tools/surface.d.ts +12 -14
  196. package/dist/tools/surface.d.ts.map +1 -1
  197. package/llms/application.2.txt +221 -44
  198. package/llms/application.3.txt +3 -1
  199. package/llms/application.txt +1 -1
  200. package/llms/cli.2.txt +144 -1
  201. package/llms/cli.txt +133 -104
  202. package/llms/contract.txt +1 -1
  203. package/llms/process.txt +34 -5
  204. package/llms/server.4.txt +4 -1
  205. package/llms/server.5.txt +1 -0
  206. package/llms/stitchkit.2.txt +14 -0
  207. package/llms/stitchkit.txt +5 -4
  208. package/llms/telegram.txt +64 -2
  209. package/llms/tools-connections.txt +3 -0
  210. package/llms/tools-mcp.txt +29 -0
  211. package/llms/tools.2.txt +59 -0
  212. package/llms/tools.3.txt +1 -0
  213. package/llms/tools.txt +11 -52
  214. package/llms/upgrading-0.37.0-0.44.0.txt +444 -0
  215. package/llms/{upgrading-0.44.0-0.60.0.txt → upgrading-0.44.0-0.61.0.txt} +140 -271
  216. package/llms/{upgrading-0.61.0-0.74.0.txt → upgrading-0.62.0-0.79.0.txt} +171 -140
  217. package/llms/{upgrading-0.75.0-0.103.0.txt → upgrading-0.80.0-0.104.0.txt} +120 -171
  218. package/llms/upgrading.txt +4 -4
  219. package/llms-full.txt +677 -64
  220. package/llms.txt +13 -12
  221. package/package.json +10 -1
  222. package/dist/index-d4pa2bgs.js +0 -42
  223. package/dist/index-wykebpn9.js +0 -221
  224. package/llms/upgrading-0.37.0.txt +0 -176
  225. package/dist/{index-69nvze1q.js → index-pptyv13k.js} +3 -3
@@ -1,71 +1,20 @@
1
- import type { CallToolResult } from '@modelcontextprotocol/server';
2
1
  import type { Tool } from 'ai';
3
2
  import type { ZodObject, ZodType, z } from 'zod';
4
- import type { HttpMethod, ToolTransport } from '../contract/define.js';
5
- import type { McpCallContext, RuntimeContext } from '../contract/runtime-context.js';
6
- import type { EndpointMcpPolicy, EndpointToolAnnotations, EndpointUiMeta } from '../contract/tool-options.js';
7
- import type { LocalStepDurability } from '../durability/contract.js';
3
+ import type { HttpMethod } from '../contract/define.js';
4
+ import type { EndpointMcpPolicy } from '../contract/tool-options.js';
8
5
  import { type SurfaceAgentRuntimeToolDefinition } from './internal/surface-projector.js';
9
6
  import type { MountableTool } from './mount.js';
10
- export interface RuntimeToolIdentity {
11
- serviceName: string;
12
- action: string;
13
- scope?: string;
14
- /** Semantic operation verb for lifecycle and RequestEvent attribution. */
15
- method: HttpMethod;
16
- meta?: Record<string, unknown>;
17
- }
18
- export type RuntimeMcpInput<TMcp extends EndpointMcpPolicy | undefined> = TMcp extends EndpointMcpPolicy<infer TRequests> ? {
19
- mcpInput?: {
20
- [Request in TRequests[number] as Request['key']]: z.output<Request['schema']>;
21
- };
22
- } : unknown;
23
- export type RuntimeToolHandlerContext<TInput extends ZodObject, TMcp extends EndpointMcpPolicy | undefined = undefined> = RuntimeContext & {
24
- params: undefined;
25
- input: z.output<TInput>;
26
- step?: LocalStepDurability['step'];
27
- sleep?: LocalStepDurability['sleep'];
28
- waitFor?: LocalStepDurability['waitFor'];
29
- } & RuntimeMcpInput<TMcp>;
30
- export type RuntimeToolOutput<TOutput extends ZodType | undefined> = TOutput extends ZodType ? z.output<TOutput> : undefined;
31
- /** Parsed application context plus the canonical runtime-tool input fields. */
32
- export type RuntimeToolFactoryHandlerContext<TContext extends ZodObject, TInput extends ZodObject, TMcp extends EndpointMcpPolicy | undefined = undefined> = Omit<RuntimeContext, 'input' | 'params' | 'mcp'> & Omit<z.output<TContext>, 'input' | 'params' | 'mcp'> & {
33
- params: undefined;
34
- input: z.output<TInput>;
35
- mcp?: McpCallContext;
36
- } & RuntimeMcpInput<TMcp>;
37
- /** MCP-owned fields; validation and error state are always supplied by Stitchkit. */
38
- export type RuntimeMcpPresentation = Omit<CallToolResult, 'structuredContent' | 'isError'> & {
39
- structuredContent?: never;
40
- isError?: never;
41
- };
7
+ import type { RuntimeToolDefinitionWithoutOutput, RuntimeToolExecution, RuntimeToolExecutionWithOutput, RuntimeToolFactoryHandlerContext } from './runtime-tool-execution.js';
8
+ import type { RuntimeMcpToolPresenters } from './runtime-tool-mcp.js';
9
+ export type { RuntimeMcpInput, RuntimeToolDefinitionBase, RuntimeToolDefinitionWithoutOutput, RuntimeToolFactoryHandlerContext, RuntimeToolHandlerContext, RuntimeToolIdentity, RuntimeToolOutput, } from './runtime-tool-execution.js';
10
+ export type { RuntimeMcpPresentation } from './runtime-tool-mcp.js';
42
11
  export type RuntimeAgentModelOutput = Awaited<ReturnType<NonNullable<Tool<unknown, unknown>['toModelOutput']>>>;
43
- export interface RuntimeToolPresenters<TOutput> {
44
- mcp?: (output: TOutput) => RuntimeMcpPresentation | Promise<RuntimeMcpPresentation>;
12
+ export interface RuntimeToolPresenters<TOutput> extends RuntimeMcpToolPresenters<TOutput> {
45
13
  agent?: (output: TOutput) => RuntimeAgentModelOutput | PromiseLike<RuntimeAgentModelOutput>;
46
14
  }
47
- export interface RuntimeToolDefinitionBase<TInput extends ZodObject, TMcp extends EndpointMcpPolicy | undefined = undefined> {
48
- name: string;
49
- description: string;
50
- identity: RuntimeToolIdentity;
51
- input: TInput;
52
- /** Default: MCP and AGENT. CLI is always explicit opt-in. */
53
- transports?: readonly ToolTransport[];
54
- annotations?: EndpointToolAnnotations;
55
- ui?: EndpointUiMeta;
56
- /** Opt-in multi-round input gate on the MCP transport only. */
57
- mcp?: TMcp;
58
- }
59
- export interface RuntimeToolDefinitionWithOutput<TInput extends ZodObject, TOutput extends ZodType, TMcp extends EndpointMcpPolicy | undefined = undefined> extends RuntimeToolDefinitionBase<TInput, TMcp> {
60
- output: TOutput;
61
- handler: (context: RuntimeToolHandlerContext<TInput, TMcp>) => z.output<TOutput> | Promise<z.output<TOutput>>;
15
+ export interface RuntimeToolDefinitionWithOutput<TInput extends ZodObject, TOutput extends ZodType, TMcp extends EndpointMcpPolicy | undefined = undefined> extends RuntimeToolExecutionWithOutput<TInput, TOutput, TMcp> {
62
16
  present?: RuntimeToolPresenters<z.output<TOutput>>;
63
17
  }
64
- export interface RuntimeToolDefinitionWithoutOutput<TInput extends ZodObject, TMcp extends EndpointMcpPolicy | undefined = undefined> extends RuntimeToolDefinitionBase<TInput, TMcp> {
65
- output?: never;
66
- handler: (context: RuntimeToolHandlerContext<TInput, TMcp>) => void | Promise<void>;
67
- present?: never;
68
- }
69
18
  export type RuntimeToolDefinition = RuntimeToolDefinitionWithOutput<ZodObject, ZodType, EndpointMcpPolicy | undefined> | RuntimeToolDefinitionWithoutOutput<ZodObject, EndpointMcpPolicy | undefined>;
70
19
  export interface RuntimeToolFactoryConfig<TContext extends ZodObject> {
71
20
  serviceName: string;
@@ -96,7 +45,7 @@ export declare function defineRuntimeTool<TInput extends ZodObject, const TMcp e
96
45
  * call while keeping execution in the canonical tool runner.
97
46
  */
98
47
  export declare function createRuntimeToolFactory<TContext extends ZodObject>(config: RuntimeToolFactoryConfig<TContext>): RuntimeToolFactory<TContext>;
99
- export declare function runtimeToolMountable(definition: RuntimeToolDefinition, assertName?: boolean): MountableTool;
48
+ export declare function runtimeToolMountable(definition: RuntimeToolExecution, assertName?: boolean): MountableTool;
100
49
  /**
101
50
  * Agent-only public declarations use a peer-free structural tool definition.
102
51
  * Construction validates executable functions before this boundary restores
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-tool.d.ts","sourceRoot":"","sources":["../../src/tools/runtime-tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClF,OAAO,KAAK,EACV,iBAAiB,EACjB,uBAAuB,EACvB,cAAc,EACf,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAGlE,OAAO,EAEL,KAAK,iCAAiC,EACvC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,C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C,IAAI,SAAS,iBAAiB,GAAG,SAAS,GAAG,SAAS,EAE5D,UAAU,EAAE,kCAAkC,CAAC,MAAM,EAAE,IAAI,CAAC,GAC3D,kCAAkC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAQpD;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,SAAS,SAAS,EACjE,MAAM,EAAE,wBAAwB,CAAC,QAAQ,CAAC,GACzC,kBAAkB,CAAC,QAAQ,CAAC,CA4D9B;AAiBD,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,oBAAoB,EAChC,UAAU,UAAO,GAChB,aAAa,CAef;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,SAAS,iCAAiC,EAAE,GAClD,SAAS,qBAAqB,EAAE,CAelC"}
@@ -1,35 +1,33 @@
1
1
  import type { ToolTransport } from '../contract/define.js';
2
- import type { ServiceDef } from '../server/types.js';
3
- import { type ProjectedTool } from './internal/surface-projector.js';
2
+ import { type ProjectedTool, type ToolSurfaceProjection } from './internal/surface-projector.js';
4
3
  import { type CollectToolsConfig, type MountableTool } from './mount.js';
5
4
  import { type RuntimeToolDefinition } from './runtime-tool.js';
5
+ import type { RuntimeToolExecution } from './runtime-tool-execution.js';
6
6
  /** Contract and pathless runtime operations that form one tool surface. */
7
- export interface ToolSurfaceDefinition {
8
- services?: readonly ServiceDef[];
9
- runtimeTools?: readonly RuntimeToolDefinition[];
7
+ export interface ToolSurfaceDefinition<TRuntime extends RuntimeToolExecution = RuntimeToolDefinition> extends ToolSurfaceProjection<TRuntime> {
10
8
  }
11
- interface CollectedContractTool {
9
+ interface CollectedContractTool<TRuntime extends RuntimeToolExecution> {
12
10
  kind: 'contract';
13
11
  service: string;
14
12
  action: string;
15
13
  mountable: MountableTool;
16
- projection: Extract<ProjectedTool<RuntimeToolDefinition>, {
14
+ projection: Extract<ProjectedTool<TRuntime>, {
17
15
  kind: 'contract';
18
16
  }>;
19
17
  }
20
- interface CollectedRuntimeTool {
18
+ interface CollectedRuntimeTool<TRuntime extends RuntimeToolExecution> {
21
19
  kind: 'runtime';
22
20
  service: string;
23
21
  action: string;
24
22
  mountable: MountableTool;
25
- definition: RuntimeToolDefinition;
26
- projection: Extract<ProjectedTool<RuntimeToolDefinition>, {
23
+ definition: TRuntime;
24
+ projection: Extract<ProjectedTool<TRuntime>, {
27
25
  kind: 'runtime';
28
26
  }>;
29
27
  }
30
- export type CollectedToolSurfaceEntry = CollectedContractTool | CollectedRuntimeTool;
31
- export interface CollectToolSurfaceConfig extends CollectToolsConfig {
32
- surface: ToolSurfaceDefinition;
28
+ export type CollectedToolSurfaceEntry<TRuntime extends RuntimeToolExecution = RuntimeToolDefinition> = CollectedContractTool<TRuntime> | CollectedRuntimeTool<TRuntime>;
29
+ export interface CollectToolSurfaceConfig<TRuntime extends RuntimeToolExecution = RuntimeToolDefinition> extends CollectToolsConfig {
30
+ surface: ToolSurfaceDefinition<TRuntime>;
33
31
  transport: ToolTransport;
34
32
  /** Diagnostics disable this so they can report a broken surface. Default: true. */
35
33
  assertUniqueNames?: boolean;
@@ -38,6 +36,6 @@ export interface CollectToolSurfaceConfig extends CollectToolsConfig {
38
36
  * Resolve contracts and runtime definitions in their real mount order through
39
37
  * the same name, exposure and presentation-schema machinery as the mounts.
40
38
  */
41
- export declare function collectToolSurface({ surface, transport, assertUniqueNames, ...collectConfig }: CollectToolSurfaceConfig): CollectedToolSurfaceEntry[];
39
+ export declare function collectToolSurface<TRuntime extends RuntimeToolExecution>({ surface, transport, assertUniqueNames, ...collectConfig }: CollectToolSurfaceConfig<TRuntime>): CollectedToolSurfaceEntry<TRuntime>[];
42
40
  export {};
43
41
  //# sourceMappingURL=surface.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"surface.d.ts","sourceRoot":"","sources":["../../src/tools/surface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAA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,SAAS,oBAAoB,GAAG,qBAAqB,IAC3D,qBAAqB,CAAC,QAAQ,CAAC,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAC;AAErE,MAAM,WAAW,wBAAwB,CACvC,QAAQ,SAAS,oBAAoB,GAAG,qBAAqB,CAC7D,SAAQ,kBAAkB;IAC1B,OAAO,EAAE,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IACzC,SAAS,EAAE,aAAa,CAAC;IACzB,mFAAmF;IACnF,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,SAAS,oBAAoB,EAAE,EACxE,OAAO,EACP,SAAS,EACT,iBAAwB,EACxB,GAAG,aAAa,EACjB,EAAE,wBAAwB,CAAC,QAAQ,CAAC,GAAG,yBAAyB,CAAC,QAAQ,CAAC,EAAE,CAkC5E"}
@@ -122,49 +122,101 @@ deadline holds `stop()` — and so the resource's `force()` — for that one cal
122
122
  so give the transport a timeout. Superseding a key that is being sent right now
123
123
  does not recall it: the send completes, and only its receipt is not written.
124
124
 
125
- `createDirectoryInbox` is the receiving side for another program on the same
126
- host: it drops entries — a release transition, say — into a directory, and
127
- the application takes each one at least once. It is a managed resource of its
128
- own (`createDirectoryInbox({ id, directory, schema, handle })`, imported from
129
- `stitchkit/application/directory-inbox` because it touches files; its types
130
- and schemas are in `stitchkit/application`) and publishes a handle with
131
- `flush()` and `state()`. The producer writes each entry
132
- atomically as `<name>.json` — a temporary name, then a rename; names that start
133
- with a dot are never read. Entries are delivered in name order, and only after
134
- `activate`: none reaches the application before it is ready. `stopAdmission`
135
- stops taking new ones, `drain` waits for the one in flight, and `force` aborts
136
- the `signal` its handler was given.
137
-
138
- Taken and done are separate durable records. Before `handle` runs, the entry
139
- is claimed with a lease (`leaseMs`, default five minutes); after it returns,
140
- a receipt replaces the claim and only then is the file removed. A process that
141
- died mid-delivery leaves a claim, and the entry is taken again once the lease
142
- runs out — at least once, not exactly once, so a handler that sends somewhere
143
- should carry the entry's `key` as its idempotency key. A process that died
144
- after the receipt leaves only the file, which the next pass removes without
145
- delivering it again. A handler that throws is retried after a backoff from one
146
- second doubling to five minutes; an entry that fails `schema`, is over
147
- `maxEntryBytes` or was taken `maxAttempts` times (default 20 — the count
148
- survives restarts, so an entry whose handling kills the process is not taken
149
- forever) is moved to `rejected/` with its reason and reported to `onRejected`,
150
- and the entries after it keep flowing. The state lives in
151
- `<directory>/.inbox-state.json` under `createFileStateStore`'s inter-process
152
- lock unless a `store` is supplied.
153
-
154
- These primitives depend on the structural `StateStore`. On a server,
155
- `createFileStateStore` supplies the shared Zod-validated JSON adapter with an
156
- inter-process lock, unique temporary file, fsync and atomic rename. The lock
157
- is a file with a heartbeat: the holder refreshes its mtime every third of
158
- `staleLockMs` (default 3 s), a contender waits up to `lockTimeoutMs` (default
159
- 10 s), and the stale bound must sit inside the timeout — otherwise a crashed
160
- holder blocks every update until the lock ages out, which the constructor
161
- refuses. A lock whose heartbeat is stale is reclaimed once its recorded pid is
162
- gone; a live or unverifiable pid (a reused number, another user's process)
163
- keeps it for ten stale bounds — and never fewer than thirty missed heartbeats,
164
- so a scheduler stall on a loaded host cannot pull a live lock from under its
165
- holder — after which the heartbeat wins and the lock is abandoned. Temporary files a crashed writer left beside the state are swept on
166
- the store's first update. Ledger corruption may be declared reconstructable;
167
- an outbox must fail closed rather than silently discard pending delivery.
125
+ `createDirectoryInbox` receives entries from another program on the same host,
126
+ or directly from a transport adapter. Import the resource from
127
+ `stitchkit/application/directory-inbox`; its contracts live in
128
+ `stitchkit/application`. Its published handle has `accept({ source, key, entry })`,
129
+ `flush()` and `state()`:
130
+
131
+ ```ts
132
+ const inbox = createDirectoryInbox({
133
+ id: 'updates',
134
+ directory: env.INBOX_DIRECTORY,
135
+ schema: UpdateSchema,
136
+ handle: ({ identity, entry, signal }) => processUpdate(identity, entry, signal),
137
+ })
138
+ const ingress = defineManagedResource({
139
+ id: 'ingress',
140
+ dependsOn: [inbox],
141
+ start(context) {
142
+ const intake = context.use(inbox)
143
+ return { value: (key: string, entry: Update) =>
144
+ intake.accept({ source: 'client-updates', key, entry }) }
145
+ },
146
+ })
147
+ ```
148
+
149
+ `accept` is available after the resource starts, including before activation.
150
+ It validates the entry and full producer identity, writes a lossless JSON envelope,
151
+ syncs its file and parent directory, then returns
152
+ `{ status: 'accepted' | 'duplicate', filename }`. Automatic delivery starts at
153
+ `activate`; an explicit `flush()` is available before activation. A producer
154
+ should acknowledge its provider only after acceptance resolves. Failure after
155
+ publication can mean the entry was accepted but its acknowledgement was lost:
156
+ retry the same identity, and `duplicate` keeps the original payload.
157
+
158
+ The identity is the pair `source` (1–128 characters) and `key` (1–1024 characters).
159
+ A hash of the pair names the file; the full pair is retained inside its envelope
160
+ and checked against existing files and records. Two sources may use the same key.
161
+ The handler's legacy `key` remains the filename; programmatic entries additionally
162
+ carry `identity`. No Telegram numeric update id or MTProto event shape is invented.
163
+
164
+ The default `maxPendingEntries: 1000` refuses new programmatic entries when the
165
+ pending directory is full, without publishing another file; duplicate acceptance
166
+ still succeeds. `maxEntryBytes` defaults to 1 MiB and counts the complete UTF-8
167
+ envelope. A completed identity is deduplicated while its receipt is retained
168
+ (`retain`, default 1000); a rejected envelope also deduplicates while its file
169
+ remains in `rejected/`. Choose the retention and rejected-file cleanup policy to
170
+ match the provider's replay window. Provider cursors, identity extraction and
171
+ external-effect idempotency remain application responsibilities.
172
+
173
+ The original file-producer path also remains: atomically publish
174
+ `<name>.json`, using a temporary name followed by a rename. Names starting with
175
+ a dot are ignored; `intake-<64 hex characters>.json` is reserved for programmatic
176
+ envelopes. Entries are delivered in filename order. The reader refuses unsafe
177
+ leaf symlinks, multiple links and files changed during reading.
178
+ `stopAdmission` stops new acceptance and delivery, `drain` waits for accepted
179
+ storage operations and the handler in flight, and `force` aborts its handler
180
+ signal. A handler ignoring that signal may still finish an external effect;
181
+ the inbox leaves its entry unsettled rather than claiming it was cancelled.
182
+
183
+ Taken and done are separate durable records. Before `handle`, the entry is
184
+ claimed with a unique expiring lease (`leaseMs`, default five minutes). A
185
+ long handler renews that lease; an expired or replaced lease cannot complete,
186
+ reject, retry or remove the successor's file. Success first commits a receipt,
187
+ then removes only that file generation under a new protected transaction.
188
+ A crash after receipt commit is recovered by cleanup without redelivery. A crash
189
+ before receipt commit may redeliver: the guarantee is at least once, so use the
190
+ full producer identity as the external idempotency key.
191
+
192
+ A throwing handler retries after a backoff from one second to five minutes.
193
+ Schema failures, oversize files and `maxAttempts` exhaustion (default 20) are
194
+ recorded before their files move to `rejected/`, with `onRejected` reporting the
195
+ reason. The state defaults to `<directory>/.inbox-state.json`, or uses the supplied
196
+ `store`. Manual file producers are responsible for atomic publication and capacity.
197
+
198
+ These primitives share the structural `StateStore`. `update` owns one atomic
199
+ read/modify/write transaction and passes a `StateStoreUpdateContext` as the
200
+ transition's second argument. Its `await context.assertHeld()` checks that the
201
+ transaction is still active and its exclusive generation is still owned. A custom
202
+ store must implement both real serialization/atomic commit and this guard;
203
+ a no-op guard does not satisfy the contract. Ordinary one-argument transition
204
+ callbacks remain valid.
205
+
206
+ On a server, `createFileStateStore` uses the same process-instance lock as
207
+ `withExclusiveLock`, unique staging files and atomic directory-durable publication.
208
+ `lockTimeoutMs` (default 10 s, zero means one attempt) bounds acquisition only.
209
+ A live or unattributable owner is never replaced by age, including after an event
210
+ loop stall or `SIGSTOP`; only a provably dead local process instance is reclaimed.
211
+ Legacy readable pid/token records without a host are unknown owners and need
212
+ operator recovery after the old writer is verified stopped.
213
+
214
+ `staleLockMs` and `retryMs` are removed and are refused at runtime. The current
215
+ write removes its own staging file; unknown historical temporary files are
216
+ preserved, without an age sweep. Directory durability requires a filesystem
217
+ supporting directory sync (Linux and macOS); Windows is refused explicitly.
218
+ Ledger corruption may be declared reconstructable; an outbox must fail closed
219
+ rather than discard pending delivery.
168
220
 
169
221
  ## Recovering change subscriptions
170
222
 
@@ -232,7 +284,7 @@ description: Executable patterns for moving database, poller, queue and operatio
232
284
  type: architecture
233
285
  status: active
234
286
  created: 2026-08-24
235
- updated: 2026-08-24
287
+ updated: 2026-10-04 13:28 +07:00
236
288
  ---
237
289
 
238
290
  # Application migration recipes
@@ -266,6 +318,131 @@ The application still owns the client, ORM configuration, transactions,
266
318
  migrations and reconnect policy. The executable recipe deliberately fails after
267
319
  allocation and proves one rollback close.
268
320
 
321
+ ## Stateful clients, including MTProto
322
+
323
+ An application-owned client is an ordinary managed resource. Keep SDK creation,
324
+ credentials, authorization and reconnect policy in the application; no Telegram
325
+ client SDK is required by Stitchkit. Create a fresh client inside each `start`,
326
+ publish it after connection/readiness succeeds, and share one memoized destroy
327
+ promise between partial-start cleanup, `close` and `force`:
328
+
329
+ ```ts
330
+ let generation: { destroy(): Promise<void> } | undefined
331
+
332
+ const client = defineManagedResource({
333
+ id: 'client',
334
+ async start({ signal }) {
335
+ const connection = createClient() // Your SDK and configuration.
336
+ let destruction: Promise<void> | undefined
337
+ const destroy = () => destruction ??= Promise.resolve()
338
+ .then(() => connection.destroy())
339
+ generation = { destroy }
340
+ let ready = false
341
+ let startFailure: unknown
342
+ let startFailed = false
343
+ let cleanupFailure: unknown
344
+ let cleanupFailed = false
345
+ try {
346
+ await connection.connect(signal)
347
+ await connection.assertReady()
348
+ signal.throwIfAborted()
349
+ ready = true
350
+ } catch (error) {
351
+ startFailure = error
352
+ startFailed = true
353
+ } finally {
354
+ if (!ready) {
355
+ try { await destroy() }
356
+ catch (cleanup) {
357
+ cleanupFailure = cleanup
358
+ cleanupFailed = true
359
+ }
360
+ }
361
+ }
362
+ if (startFailed) {
363
+ if (cleanupFailed) throw new AggregateError([startFailure, cleanupFailure],
364
+ 'Client startup and cleanup failed', { cause: startFailure })
365
+ throw startFailure
366
+ }
367
+ return { value: connection }
368
+ },
369
+ close: () => generation?.destroy(),
370
+ force: () => generation?.destroy(),
371
+ })
372
+
373
+ const api = defineManagedResource({
374
+ id: 'api',
375
+ dependsOn: [client],
376
+ start(context) {
377
+ const connection = context.use(client)
378
+ return { value: async () => {
379
+ const lease = context.admission.acquire()
380
+ if (!lease) throw new ApplicationAdmissionError()
381
+ try { return await connection.invoke() }
382
+ finally { lease.release() }
383
+ } }
384
+ },
385
+ })
386
+ ```
387
+
388
+ `createClient` supplies a client whose `destroy` safely cleans partial connection
389
+ setup; its adapter must honor cancellation or otherwise reconcile late SDK effects.
390
+ The destroy cache belongs to one generation and is reset by the next `start`.
391
+ Successful startup keeps the connection alive. Dependants start after readiness,
392
+ requests acquire admission before invoking the client, and dependent HTTP resources
393
+ close before the client. A subtree restart builds a new client and new dependants.
394
+
395
+ The packed-consumer fixture
396
+ [`managed-client-composition.mjs`](../../packages/core/scripts/consumer-lane/fixtures/minimal/src/managed-client-composition.mjs)
397
+ proves readiness/admission, partial startup, close order, forced cleanup and restart
398
+ with a fake client on Bun and Node. It does not claim a live provider acceptance test.
399
+
400
+ ## Custom StateStore transaction guards
401
+
402
+ Transitions now receive `(current, context)`. Keep ordinary callbacks that only use
403
+ `current`; update custom store implementations to pass a real protected context.
404
+ For an in-memory test store, queue transactions and invalidate the context when
405
+ the transaction finishes:
406
+
407
+ ```ts
408
+ function memoryStore<T>(): StateStore<T> {
409
+ let state: T | null = null
410
+ let tail: Promise<unknown> = Promise.resolve()
411
+ return {
412
+ read: async () => state,
413
+ update(transition) {
414
+ const work = tail.then(async () => {
415
+ let active = true
416
+ const context: StateStoreUpdateContext = {
417
+ async assertHeld() {
418
+ if (!active) throw new Error('Transaction is no longer active')
419
+ },
420
+ }
421
+ try {
422
+ const next = await transition(state, context)
423
+ await context.assertHeld()
424
+ state = next.state
425
+ return next.result
426
+ } finally { active = false }
427
+ })
428
+ tail = work.catch(() => undefined)
429
+ return work
430
+ },
431
+ }
432
+ }
433
+ ```
434
+
435
+ This recipe is process-local and has no restart durability. A database store must
436
+ guard its real transaction/generation and commit atomically; an escaped or lost
437
+ guard must refuse. Filesystem mutations made inside inbox transactions call
438
+ `assertHeld` immediately before publication or cleanup.
439
+
440
+ For `createFileStateStore`, remove `staleLockMs` and `retryMs` from configuration.
441
+ `lockTimeoutMs` remains the acquisition budget. Timestamp age no longer revokes
442
+ a live or unknown writer. Stop and verify old writers before recovering a legacy
443
+ pid-only lock; do not invent owner metadata. Historical temporary files are no
444
+ longer deleted by age. See the [durable intake contract](application-kernel.md#durable-process-facts-and-owner-notifications).
445
+
269
446
  ## Long-running poller
270
447
 
271
448
  Return separate readiness and completion promises. Readiness says dependants may
@@ -36,7 +36,9 @@ cutovers are covered by the executable
36
36
  | `NotificationOutboxItem` / `NotificationOutboxReceipt` / `NotificationOutboxState` / `NotificationSend` / `NotificationFailureClassification` / `DroppedNotification` / `EnqueueNotification` | _type_ | versioned queue records, stable send identity and delivery decisions |
37
37
  | `notificationOutboxStateSchema` | function | strict persisted-state schema over an application payload schema |
38
38
  | `notificationOutboxResource` / `NotificationOutboxResource` / `NotificationOutboxResourceConfig` | function / _type_ | thin managed-resource scheduler over an outbox handle |
39
- | `createDirectoryInbox` (from `stitchkit/application/directory-inbox`) / `DirectoryInbox` / `DirectoryInboxConfig` / `DirectoryInboxDelivery` / `DirectoryInboxResource` | function / _type_ | managed resource delivering each `<name>.json` entry another program drops into a directory to the application at least once, after readiness; separate durable taken/done records, leases, bounded retry |
39
+ | `createDirectoryInbox` (from `stitchkit/application/directory-inbox`) / `DirectoryInbox` / `DirectoryInboxConfig` / `DirectoryInboxDelivery` / `DirectoryInboxResource` | function / _type_ | one managed directory inbox for files or durable `accept({ source, key, entry })`; first payload wins, bounded capacity/bytes/receipts and renewable fenced leases; delivery begins after readiness and effects remain at least once |
40
+ | `DirectoryInboxIdentitySchema` / `DirectoryInboxIdentity` / `DirectoryInboxAccept` / `DirectoryInboxAcceptResultSchema` / `DirectoryInboxAcceptResult` | schema / _type_ | validated source/key, typed entry and durable accepted/duplicate result with filename; duplicates do not replace the first payload |
41
+ | `StateStoreUpdateContext` | _type_ | real active protected transaction: `assertHeld()` refuses after ownership loss or completion; custom adapters supply this context to their transition |
40
42
  | `DirectoryInboxStateSchema` / `DirectoryInboxState` / `DirectoryInboxRejection` / `DirectoryInboxRejectionReasonSchema` / `DirectoryInboxRejectionReason` | schema / _type_ | the inbox's claims, receipts and rejections (`invalid`, `too-large`, `attempt-limit`) |
41
43
  | `ApplicationHandle.restart` | method | replace one resource and everything that depends on it, leaving the rest of the graph running and the process epoch unchanged |
42
44
  | `ApplicationRestartInputSchema` / `ApplicationRestartInput` | schema / _type_ | the resource to replace, by id, and optionally `gracePeriodMs` / `forceTimeoutMs` for this restart — the application's own shutdown budget otherwise |
@@ -19,7 +19,7 @@ description: Compose process-local resources, schedules, readiness, drain and op
19
19
  type: architecture
20
20
  status: active
21
21
  created: 2026-08-23
22
- updated: 2026-09-30 17:41 +07:00
22
+ updated: 2026-10-04 13:28 +07:00
23
23
  ---
24
24
 
25
25
  # Managed application kernel