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.
- package/CHANGELOG.md +112 -0
- package/darwin-native.cjs +12 -0
- package/darwin-native.d.cts +2 -0
- package/dist/agent-runtime/store-conformance-lifecycle.d.ts +10 -10
- package/dist/application/directory-inbox-accept.d.ts +13 -0
- package/dist/application/directory-inbox-accept.d.ts.map +1 -0
- package/dist/application/directory-inbox-contract.d.ts +42 -5
- package/dist/application/directory-inbox-contract.d.ts.map +1 -1
- package/dist/application/directory-inbox-delivery.d.ts +14 -0
- package/dist/application/directory-inbox-delivery.d.ts.map +1 -0
- package/dist/application/directory-inbox-files.d.ts +28 -0
- package/dist/application/directory-inbox-files.d.ts.map +1 -0
- package/dist/application/directory-inbox-state.d.ts +14 -0
- package/dist/application/directory-inbox-state.d.ts.map +1 -0
- package/dist/application/directory-inbox.d.ts +2 -1
- package/dist/application/directory-inbox.d.ts.map +1 -1
- package/dist/application/file-state-store.d.ts +2 -8
- package/dist/application/file-state-store.d.ts.map +1 -1
- package/dist/application/state-store.d.ts +6 -1
- package/dist/application/state-store.d.ts.map +1 -1
- package/dist/browser/client-arguments.d.ts +4 -0
- package/dist/browser/client-arguments.d.ts.map +1 -0
- package/dist/browser/client-executors.d.ts.map +1 -1
- package/dist/browser/client.d.ts.map +1 -1
- package/dist/browser/contract-stream.d.ts.map +1 -1
- package/dist/browser/http.d.ts +2 -1
- package/dist/browser/http.d.ts.map +1 -1
- package/dist/browser/native-fetch.d.ts +8 -0
- package/dist/browser/native-fetch.d.ts.map +1 -0
- package/dist/contract/errors.d.ts +16 -12
- package/dist/contract/errors.d.ts.map +1 -1
- package/dist/contract/normalize.d.ts +5 -1
- package/dist/contract/normalize.d.ts.map +1 -1
- package/dist/contract/stream.d.ts +1 -0
- package/dist/contract/stream.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/browser.js +3 -3
- package/dist/entrypoints/agent-runtime/coding-tools.js +8 -6
- package/dist/entrypoints/agent-runtime/harness-tools.js +8 -8
- package/dist/entrypoints/agent-runtime/harness.js +12 -11
- package/dist/entrypoints/agent-runtime/realtime.js +3 -3
- package/dist/entrypoints/agent-runtime/sandbox.js +8 -6
- package/dist/entrypoints/agent-runtime.js +13 -13
- package/dist/entrypoints/application/diagnostic-journal.js +3 -2
- package/dist/entrypoints/application/directory-inbox.js +424 -119
- package/dist/entrypoints/application/grammy.js +1 -1
- package/dist/entrypoints/application.d.ts +2 -2
- package/dist/entrypoints/application.d.ts.map +1 -1
- package/dist/entrypoints/application.js +7 -3
- package/dist/entrypoints/cli.d.ts +2 -0
- package/dist/entrypoints/cli.d.ts.map +1 -1
- package/dist/entrypoints/cli.js +757 -136
- package/dist/entrypoints/contract.js +3 -3
- package/dist/entrypoints/files.js +11 -107
- package/dist/entrypoints/index.js +7 -7
- package/dist/entrypoints/node.js +8 -8
- package/dist/entrypoints/observability.js +2 -2
- package/dist/entrypoints/process.js +2 -1
- package/dist/entrypoints/react.js +1 -1
- package/dist/entrypoints/remote.js +19 -6
- package/dist/entrypoints/server.d.ts +1 -1
- package/dist/entrypoints/server.d.ts.map +1 -1
- package/dist/entrypoints/server.js +20 -14
- package/dist/entrypoints/telegram.d.ts +1 -0
- package/dist/entrypoints/telegram.d.ts.map +1 -1
- package/dist/entrypoints/telegram.js +214 -98
- package/dist/entrypoints/testing.js +7 -7
- package/dist/entrypoints/tools/connections.d.ts +2 -2
- package/dist/entrypoints/tools/connections.d.ts.map +1 -1
- package/dist/entrypoints/tools/connections.js +427 -294
- package/dist/entrypoints/tools/invoker.js +6 -6
- package/dist/entrypoints/tools/mcp.d.ts +12 -0
- package/dist/entrypoints/tools/mcp.d.ts.map +1 -0
- package/dist/entrypoints/tools/mcp.js +45 -0
- package/dist/entrypoints/tools.d.ts +1 -0
- package/dist/entrypoints/tools.d.ts.map +1 -1
- package/dist/entrypoints/tools.js +82 -1147
- package/dist/entrypoints/tracking.js +1 -1
- package/dist/files/boundary.d.ts +2 -8
- package/dist/files/boundary.d.ts.map +1 -1
- package/dist/files/file-io.d.ts +0 -5
- package/dist/files/file-io.d.ts.map +1 -1
- package/dist/files/read.d.ts +2 -2
- package/dist/files/read.d.ts.map +1 -1
- package/dist/index-1a6jtnd9.js +88 -0
- package/dist/{index-fyphpknh.js → index-22rhg58f.js} +1 -1
- package/dist/index-269zqj8m.js +77 -0
- package/dist/{index-r34mvse1.js → index-27a2pj09.js} +1 -1
- package/dist/{index-r956rndn.js → index-2hyavjjj.js} +3 -3
- package/dist/{index-m2xqkv55.js → index-2vnh05w4.js} +83 -14
- package/dist/{index-pw99k9h5.js → index-43p08g7t.js} +1 -1
- package/dist/{index-xwq9j1sf.js → index-4e0ah203.js} +9 -7
- package/dist/{index-nybn2err.js → index-5csmzesf.js} +1 -1
- package/dist/{index-qapzv4p5.js → index-5z6jn897.js} +1 -1
- package/dist/{index-ahvsksw5.js → index-6d9xaxw1.js} +1 -1
- package/dist/{index-ahtnte39.js → index-6drst9sg.js} +46 -35
- package/dist/{index-x87j7csh.js → index-77nxk6ay.js} +2 -2
- package/dist/{index-dnn9z96q.js → index-a0zzh8ak.js} +3 -3
- package/dist/{index-kmpzj1cq.js → index-a3wma1hk.js} +1 -1
- package/dist/{index-j8aw2c0e.js → index-bakgedh8.js} +35 -7
- package/dist/index-bhb950qs.js +1145 -0
- package/dist/{index-tgzhq07n.js → index-cvda079a.js} +1 -1
- package/dist/{index-n2gre124.js → index-fa4wg312.js} +4 -4
- package/dist/{index-zp4jpkp0.js → index-fk18k56k.js} +2 -2
- package/dist/{index-afjvjyck.js → index-g2j7pnak.js} +2 -134
- package/dist/index-g95fk660.js +116 -0
- package/dist/{index-ej331hah.js → index-gxm9rc97.js} +1 -1
- package/dist/{index-r5c4fedv.js → index-h2fhjqy7.js} +2 -1
- package/dist/{index-sybedc8b.js → index-hbd32c6a.js} +23 -94
- package/dist/index-jd470k6q.js +109 -0
- package/dist/{index-b2bz0kdm.js → index-kb8styz3.js} +4 -3
- package/dist/{index-0c419yx7.js → index-kemm0ej5.js} +12 -9
- package/dist/{index-806d5phm.js → index-ptn0g0gj.js} +7 -7
- package/dist/{index-w575evhq.js → index-r4r70zmh.js} +1 -1
- package/dist/{index-12m2v2a9.js → index-s4evrmp5.js} +1 -1
- package/dist/{index-1khy8y7n.js → index-t1sr4aks.js} +3 -3
- package/dist/index-v5ee8ath.js +88 -0
- package/dist/{index-45tdvqa3.js → index-wh0ecvyk.js} +1 -1
- package/dist/{index-n53mswt3.js → index-x928baz2.js} +8 -1
- package/dist/index-yk4g8805.js +133 -0
- package/dist/{index-ygkka6zn.js → index-ywppsaby.js} +28 -5
- package/dist/{index-xvdd2rbb.js → index-za6j7nwy.js} +19 -5
- package/dist/internal/bounded-file-read.d.ts +41 -0
- package/dist/internal/bounded-file-read.d.ts.map +1 -0
- package/dist/internal/darwin-binding-error.d.ts +24 -0
- package/dist/internal/darwin-binding-error.d.ts.map +1 -0
- package/dist/internal/darwin-binding.d.ts.map +1 -1
- package/dist/internal/exclusive-lock.d.ts +2 -0
- package/dist/internal/exclusive-lock.d.ts.map +1 -1
- package/dist/internal/with-exclusive-lock.d.ts +4 -2
- package/dist/internal/with-exclusive-lock.d.ts.map +1 -1
- package/dist/telegram/broadcast-delivery.d.ts +23 -0
- package/dist/telegram/broadcast-delivery.d.ts.map +1 -0
- package/dist/telegram/broadcast-failure.d.ts +22 -0
- package/dist/telegram/broadcast-failure.d.ts.map +1 -0
- package/dist/telegram/broadcast-state.d.ts +6 -3
- package/dist/telegram/broadcast-state.d.ts.map +1 -1
- package/dist/telegram/broadcast.d.ts +10 -5
- package/dist/telegram/broadcast.d.ts.map +1 -1
- package/dist/tools/cli/args-fields.d.ts +2 -0
- package/dist/tools/cli/args-fields.d.ts.map +1 -1
- package/dist/tools/cli/args.d.ts.map +1 -1
- package/dist/tools/cli/format.d.ts.map +1 -1
- package/dist/tools/cli/invoke.d.ts +2 -2
- package/dist/tools/cli/invoke.d.ts.map +1 -1
- package/dist/tools/cli/publication-assets.d.ts +10 -0
- package/dist/tools/cli/publication-assets.d.ts.map +1 -0
- package/dist/tools/cli/publication-contract.d.ts +75 -0
- package/dist/tools/cli/publication-contract.d.ts.map +1 -0
- package/dist/tools/cli/publication-control.d.ts +4 -0
- package/dist/tools/cli/publication-control.d.ts.map +1 -0
- package/dist/tools/cli/publication-storage.d.ts +32 -0
- package/dist/tools/cli/publication-storage.d.ts.map +1 -0
- package/dist/tools/cli/publication.d.ts +35 -0
- package/dist/tools/cli/publication.d.ts.map +1 -0
- package/dist/tools/cli/update.d.ts.map +1 -1
- package/dist/tools/connections/define.d.ts.map +1 -1
- package/dist/tools/connections/error-projection.d.ts +4 -0
- package/dist/tools/connections/error-projection.d.ts.map +1 -0
- package/dist/tools/connections/errors.d.ts +24 -8
- package/dist/tools/connections/errors.d.ts.map +1 -1
- package/dist/tools/connections/limits.d.ts +11 -31
- package/dist/tools/connections/limits.d.ts.map +1 -1
- package/dist/tools/connections/mcp-client.d.ts +6 -4
- package/dist/tools/connections/mcp-client.d.ts.map +1 -1
- package/dist/tools/connections/mcp.d.ts.map +1 -1
- package/dist/tools/connections/openapi.d.ts.map +1 -1
- package/dist/tools/connections/operation-limits.d.ts +25 -0
- package/dist/tools/connections/operation-limits.d.ts.map +1 -0
- package/dist/tools/connections/sse-frames.d.ts +11 -2
- package/dist/tools/connections/sse-frames.d.ts.map +1 -1
- package/dist/tools/connections/sse-session.d.ts +15 -2
- package/dist/tools/connections/sse-session.d.ts.map +1 -1
- package/dist/tools/connections/types.d.ts +19 -1
- package/dist/tools/connections/types.d.ts.map +1 -1
- package/dist/tools/execute-result.d.ts.map +1 -1
- package/dist/tools/execute.d.ts.map +1 -1
- package/dist/tools/internal/observe-hook.d.ts +3 -0
- package/dist/tools/internal/observe-hook.d.ts.map +1 -0
- package/dist/tools/internal/surface-projector.d.ts +2 -1
- package/dist/tools/internal/surface-projector.d.ts.map +1 -1
- package/dist/tools/mcp/mount.d.ts +2 -2
- package/dist/tools/mcp/mount.d.ts.map +1 -1
- package/dist/tools/mcp/prepare.d.ts +4 -5
- package/dist/tools/mcp/prepare.d.ts.map +1 -1
- package/dist/tools/mcp/register.d.ts +4 -1
- package/dist/tools/mcp/register.d.ts.map +1 -1
- package/dist/tools/mcp/runtime-tools.d.ts.map +1 -1
- package/dist/tools/remote.d.ts.map +1 -1
- package/dist/tools/runtime-tool-execution.d.ts +65 -0
- package/dist/tools/runtime-tool-execution.d.ts.map +1 -0
- package/dist/tools/runtime-tool-mcp.d.ts +27 -0
- package/dist/tools/runtime-tool-mcp.d.ts.map +1 -0
- package/dist/tools/runtime-tool.d.ts +9 -60
- package/dist/tools/runtime-tool.d.ts.map +1 -1
- package/dist/tools/surface.d.ts +12 -14
- package/dist/tools/surface.d.ts.map +1 -1
- package/llms/application.2.txt +221 -44
- package/llms/application.3.txt +3 -1
- package/llms/application.txt +1 -1
- package/llms/cli.2.txt +144 -1
- package/llms/cli.txt +133 -104
- package/llms/contract.txt +1 -1
- package/llms/process.txt +34 -5
- package/llms/server.4.txt +4 -1
- package/llms/server.5.txt +1 -0
- package/llms/stitchkit.2.txt +14 -0
- package/llms/stitchkit.txt +5 -4
- package/llms/telegram.txt +64 -2
- package/llms/tools-connections.txt +3 -0
- package/llms/tools-mcp.txt +29 -0
- package/llms/tools.2.txt +59 -0
- package/llms/tools.3.txt +1 -0
- package/llms/tools.txt +11 -52
- package/llms/upgrading-0.37.0-0.44.0.txt +444 -0
- package/llms/{upgrading-0.44.0-0.60.0.txt → upgrading-0.44.0-0.61.0.txt} +140 -271
- package/llms/{upgrading-0.61.0-0.74.0.txt → upgrading-0.62.0-0.79.0.txt} +171 -140
- package/llms/{upgrading-0.75.0-0.103.0.txt → upgrading-0.80.0-0.104.0.txt} +120 -171
- package/llms/upgrading.txt +4 -4
- package/llms-full.txt +677 -64
- package/llms.txt +13 -12
- package/package.json +10 -1
- package/dist/index-d4pa2bgs.js +0 -42
- package/dist/index-wykebpn9.js +0 -221
- package/llms/upgrading-0.37.0.txt +0 -176
- 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
|
|
5
|
-
import type {
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
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:
|
|
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,
|
|
1
|
+
{"version":3,"file":"runtime-tool.d.ts","sourceRoot":"","sources":["../../src/tools/runtime-tool.ts"],"names":[],"mappings":"AAAA,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,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,OAAO,EAEL,KAAK,iCAAiC,EACvC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,EACV,kCAAkC,EAClC,oBAAoB,EACpB,8BAA8B,EAC9B,gCAAgC,EAGjC,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAEnE,YAAY,EACV,eAAe,EACf,yBAAyB,EACzB,kCAAkC,EAClC,gCAAgC,EAChC,yBAAyB,EACzB,mBAAmB,EACnB,iB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AS,EACxB,KAAK,CAAC,IAAI,SAAS,iBAAiB,GAAG,SAAS,GAAG,SAAS,EAE5D,UAAU,EAAE,yCAAyC,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,GAC5E,kCAAkC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;CACrD;AAED,8EAA8E;AAC9E,wBAAgB,iBAAiB,CAC/B,MAAM,SAAS,SAAS,EACxB,OAAO,SAAS,OAAO,EACvB,KAAK,CAAC,IAAI,SAAS,iBAAiB,GAAG,SAAS,GAAG,SAAS,EAE5D,UAAU,EAAE,+BAA+B,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,GACjE,+BAA+B,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;AAC1D,wBAAgB,iBAAiB,CAC/B,MAAM,SAAS,SAAS,EACxB,KAAK,CAAC,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"}
|
package/dist/tools/surface.d.ts
CHANGED
|
@@ -1,35 +1,33 @@
|
|
|
1
1
|
import type { ToolTransport } from '../contract/define.js';
|
|
2
|
-
import type
|
|
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<
|
|
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:
|
|
26
|
-
projection: Extract<ProjectedTool<
|
|
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,
|
|
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,EACL,KAAK,aAAa,EAElB,KAAK,qBAAqB,EAC3B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,KAAK,kBAAkB,EAAyB,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7F,OAAO,EAAE,KAAK,qBAAqB,EAAwB,MAAM,gBA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AAoB,EAAE,EACxE,OAAO,EACP,SAAS,EACT,iBAAwB,EACxB,GAAG,aAAa,EACjB,EAAE,wBAAwB,CAAC,QAAQ,CAAC,GAAG,yBAAyB,CAAC,QAAQ,CAAC,EAAE,CAkC5E"}
|
package/llms/application.2.txt
CHANGED
|
@@ -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`
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
`
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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-
|
|
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
|
package/llms/application.3.txt
CHANGED
|
@@ -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
|
|
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 |
|
package/llms/application.txt
CHANGED