stitchkit 0.121.0 → 0.122.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 (64) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/agent-runtime/browser-control-contract.d.ts +12 -0
  3. package/dist/agent-runtime/browser-control-contract.d.ts.map +1 -1
  4. package/dist/agent-runtime/control-schema.d.ts +27 -4
  5. package/dist/agent-runtime/control-schema.d.ts.map +1 -1
  6. package/dist/agent-runtime/event-schema.d.ts +33 -0
  7. package/dist/agent-runtime/event-schema.d.ts.map +1 -1
  8. package/dist/agent-runtime/run-acquisition.d.ts.map +1 -1
  9. package/dist/agent-runtime/run-execution-state.d.ts +6 -0
  10. package/dist/agent-runtime/run-execution-state.d.ts.map +1 -1
  11. package/dist/agent-runtime/run-model-attempts.d.ts.map +1 -1
  12. package/dist/agent-runtime/run-stream-parts.d.ts +11 -0
  13. package/dist/agent-runtime/run-stream-parts.d.ts.map +1 -1
  14. package/dist/agent-runtime/tool-progress.d.ts +21 -0
  15. package/dist/agent-runtime/tool-progress.d.ts.map +1 -0
  16. package/dist/entrypoints/agent-runtime/browser.js +7 -3
  17. package/dist/entrypoints/agent-runtime/harness.js +5 -5
  18. package/dist/entrypoints/agent-runtime/realtime.js +5 -5
  19. package/dist/entrypoints/agent-runtime.d.ts +1 -1
  20. package/dist/entrypoints/agent-runtime.d.ts.map +1 -1
  21. package/dist/entrypoints/agent-runtime.js +6 -4
  22. package/dist/entrypoints/cli.js +1 -1
  23. package/dist/entrypoints/server.d.ts +1 -0
  24. package/dist/entrypoints/server.d.ts.map +1 -1
  25. package/dist/entrypoints/server.js +107 -42
  26. package/dist/entrypoints/tools/agent.js +1 -1
  27. package/dist/entrypoints/tools/toolkit.js +2 -2
  28. package/dist/{index-7zwtbak8.js → index-1fyea34p.js} +9 -4
  29. package/dist/{index-4qnzda76.js → index-7qyv50r4.js} +1 -1
  30. package/dist/{index-qctbzmg9.js → index-am1h8c9v.js} +69 -27
  31. package/dist/{index-yt7gyg5x.js → index-b51tzcgh.js} +1 -1
  32. package/dist/{index-aw6zahv1.js → index-dqpesdck.js} +2 -2
  33. package/dist/{index-sb9dr3tq.js → index-eh71zr32.js} +4 -4
  34. package/dist/{index-mnkk1ffz.js → index-hs76yzt7.js} +13 -1
  35. package/dist/{index-b0w7rbpt.js → index-t05a2ry4.js} +39 -3
  36. package/dist/{index-0fra8xvy.js → index-v8yqk4w7.js} +20 -6
  37. package/dist/server/openapi-security.d.ts +73 -0
  38. package/dist/server/openapi-security.d.ts.map +1 -0
  39. package/dist/server/openapi.d.ts +12 -0
  40. package/dist/server/openapi.d.ts.map +1 -1
  41. package/dist/tools/agent.d.ts.map +1 -1
  42. package/dist/tools/cli/format.d.ts +11 -2
  43. package/dist/tools/cli/format.d.ts.map +1 -1
  44. package/dist/tools/cli/repeatable-read.d.ts +9 -0
  45. package/dist/tools/cli/repeatable-read.d.ts.map +1 -0
  46. package/dist/tools/cli/run-managed.d.ts.map +1 -1
  47. package/dist/tools/cli/run-native.d.ts.map +1 -1
  48. package/dist/tools/runtime-call-context.d.ts +15 -0
  49. package/dist/tools/runtime-call-context.d.ts.map +1 -0
  50. package/llms/agent-runtime-browser.txt +4 -1
  51. package/llms/agent-runtime.2.txt +13 -108
  52. package/llms/agent-runtime.3.txt +111 -1
  53. package/llms/cli.txt +21 -9
  54. package/llms/server.2.txt +48 -0
  55. package/llms/server.5.txt +2 -0
  56. package/llms/stitchkit.txt +3 -3
  57. package/llms/tools.txt +4 -1
  58. package/llms/{upgrading-0.106.0-0.121.0.txt → upgrading-0.106.0-0.122.0.txt} +31 -3
  59. package/llms/upgrading.txt +1 -1
  60. package/llms-full.txt +126 -15
  61. package/llms.txt +6 -6
  62. package/package.json +2 -1
  63. package/dist/tools/durability-context.d.ts +0 -7
  64. package/dist/tools/durability-context.d.ts.map +0 -1
@@ -0,0 +1,73 @@
1
+ /**
2
+ * How an OpenAPI document says what a protected operation needs from its
3
+ * caller: the standard `components.securitySchemes` and one `security`
4
+ * requirement per operation.
5
+ *
6
+ * The document describes the host's auth policy; it never enforces it. The
7
+ * runtime gate stays `createAuthHook` and its scope rules, so the mapping here
8
+ * is keyed by the same scope names the contracts already declare — no second
9
+ * copy of which endpoint is protected. The generator refuses to advertise a
10
+ * protected operation it cannot describe: a scope missing from the mapping
11
+ * would otherwise reach the spec as an open endpoint, and a generic client
12
+ * would call it without a credential.
13
+ */
14
+ import { z } from 'zod';
15
+ /** One way a request presents its credential — the OpenAPI Security Scheme Object. */
16
+ export declare const OpenApiSecuritySchemeSchema: z.ZodUnion<readonly [z.ZodObject<{
17
+ description: z.ZodOptional<z.ZodString>;
18
+ type: z.ZodLiteral<"http">;
19
+ scheme: z.ZodLiteral<"bearer">;
20
+ bearerFormat: z.ZodOptional<z.ZodString>;
21
+ }, z.core.$strict>, z.ZodObject<{
22
+ description: z.ZodOptional<z.ZodString>;
23
+ type: z.ZodLiteral<"http">;
24
+ scheme: z.ZodLiteral<"basic">;
25
+ }, z.core.$strict>, z.ZodObject<{
26
+ description: z.ZodOptional<z.ZodString>;
27
+ type: z.ZodLiteral<"apiKey">;
28
+ in: z.ZodEnum<{
29
+ cookie: "cookie";
30
+ header: "header";
31
+ query: "query";
32
+ }>;
33
+ name: z.ZodString;
34
+ }, z.core.$strict>]>;
35
+ export type OpenApiSecurityScheme = z.infer<typeof OpenApiSecuritySchemeSchema>;
36
+ export declare const OpenApiSecuritySchema: z.ZodObject<{
37
+ schemes: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
38
+ description: z.ZodOptional<z.ZodString>;
39
+ type: z.ZodLiteral<"http">;
40
+ scheme: z.ZodLiteral<"bearer">;
41
+ bearerFormat: z.ZodOptional<z.ZodString>;
42
+ }, z.core.$strict>, z.ZodObject<{
43
+ description: z.ZodOptional<z.ZodString>;
44
+ type: z.ZodLiteral<"http">;
45
+ scheme: z.ZodLiteral<"basic">;
46
+ }, z.core.$strict>, z.ZodObject<{
47
+ description: z.ZodOptional<z.ZodString>;
48
+ type: z.ZodLiteral<"apiKey">;
49
+ in: z.ZodEnum<{
50
+ cookie: "cookie";
51
+ header: "header";
52
+ query: "query";
53
+ }>;
54
+ name: z.ZodString;
55
+ }, z.core.$strict>]>>;
56
+ scopes: z.ZodRecord<z.ZodString, z.ZodReadonly<z.ZodArray<z.ZodString>>>;
57
+ defaultScope: z.ZodOptional<z.ZodString>;
58
+ }, z.core.$strict>;
59
+ export type OpenApiSecurity = z.infer<typeof OpenApiSecuritySchema>;
60
+ /** The scope that needs no credential, as `createAuthHook` and the 401/403 responses read it. */
61
+ export declare const PUBLIC_SCOPE = "public";
62
+ /** A configuration checked once, before any operation is emitted. */
63
+ export interface OpenApiSecurityPlan {
64
+ readonly schemes: Readonly<Record<string, OpenApiSecurityScheme>>;
65
+ /**
66
+ * The operation's `security` value, or `undefined` for an open one.
67
+ * `operation` names the endpoint in a refusal.
68
+ */
69
+ requirement(scope: string | undefined, operation: string): Array<Record<string, string[]>> | undefined;
70
+ }
71
+ /** Validate the host's security description, failing on the first contradiction. */
72
+ export declare function planOpenApiSecurity(input: OpenApiSecurity): OpenApiSecurityPlan;
73
+ //# sourceMappingURL=openapi-security.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openapi-security.d.ts","sourceRoot":"","sources":["../../src/server/openapi-security.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB,sFAAsF;AACtF,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;oBActC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEhF,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;kBAWhC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE,iGAAiG;AACjG,eAAO,MAAM,YAAY,WAAW,CAAC;AAErC,qEAAqE;AACrE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC;IAClE;;;OAGG;IACH,WAAW,CACT,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,SAAS,EAAE,MAAM,GAChB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;CAChD;AAMD,oFAAoF;AACpF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,eAAe,GAAG,mBAAmB,CAsC/E"}
@@ -10,6 +10,7 @@
10
10
  * emits — not a divergent code path. Schemas are inlined (valid OpenAPI);
11
11
  * `$ref` de-duplication can come later if a spec grows unwieldy.
12
12
  */
13
+ import { type OpenApiSecurity, type OpenApiSecurityScheme } from './openapi-security.js';
13
14
  import type { MethodDef, RawRoute, ServiceDef } from './types.js';
14
15
  export interface OpenApiInfo {
15
16
  title: string;
@@ -44,12 +45,23 @@ export interface OpenApiConfig {
44
45
  * separate filtered document for a public route (see the guide).
45
46
  */
46
47
  includeMethod?: (method: Readonly<MethodDef>) => boolean;
48
+ /**
49
+ * How a caller presents its credential, by the scopes the contracts already
50
+ * declare. Emits `components.securitySchemes` and a `security` requirement on
51
+ * every protected operation, so a generic client knows which header to send.
52
+ * Generation refuses a protected scope with no scheme rather than advertise
53
+ * the endpoint as open. Omit for a document without security metadata.
54
+ */
55
+ security?: OpenApiSecurity;
47
56
  }
48
57
  export interface OpenApiDocument {
49
58
  openapi: '3.1.0';
50
59
  info: OpenApiInfo;
51
60
  servers?: OpenApiServer[];
52
61
  paths: Record<string, Record<string, unknown>>;
62
+ components?: {
63
+ securitySchemes: Record<string, OpenApiSecurityScheme>;
64
+ };
53
65
  }
54
66
  /**
55
67
  * Generate an OpenAPI 3.1 document from contract services.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O,CAAC;IACzB,mEAAmE;IACnE,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC5D,+EAA+E;IAC/E,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gEAAgE;IAChE,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,2EAA2E;IAC3E,YAAY,CAAC,EAAE,SAAS,qBAAqB,EAAE,CAAC;IAChD;;;OAGG;IACH,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B;;;;;;;;;OASG;IACH,UAAU,CAAC,EAAE,qBAAqB,CAAC;CACpC;AAED,wBAAgB,UAAU,CACxB,QAAQ,EAAE,UAAU,GAAG,UAAU,EAAE,EACnC,MAAM,GAAE,gBAAqB,GAC5B,OAAO,CA2HT"}
@@ -47,8 +47,17 @@ export interface EmitOptions {
47
47
  */
48
48
  export declare function cliExitCode(result: ToolResult, exitCodes?: ExitCodeMap): number;
49
49
  export declare function emitResult(result: ToolResult, writers: CliWriters, opts: EmitOptions): number;
50
- /** A presentation failure cannot erase a successfully completed operation. */
50
+ /**
51
+ * A presentation failure cannot erase a successfully completed operation.
52
+ *
53
+ * A command with an effect prints its complete result, because a second call
54
+ * would repeat the effect instead of recovering the answer. A command that only
55
+ * reads withholds it: the answer is one corrected call away, and an unformatted
56
+ * payload is exactly what the caller asked not to receive.
57
+ */
51
58
  export declare function emitPresentationFailure(result: Extract<ToolResult, {
52
59
  ok: true;
53
- }>, failure: ToolFailure, writers: CliWriters, opts: EmitOptions): number;
60
+ }>, failure: ToolFailure, writers: CliWriters, opts: EmitOptions & {
61
+ repeatable: boolean;
62
+ }): number;
54
63
  //# sourceMappingURL=format.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,M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mB,CAAC;AAGjE,sDAAsD;AACtD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEjD;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAmBhC,CAAC;AAEF,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,WAAW;IAC1B,wEAAwE;IACxE,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,SAAS,CAAC,EAAE,WAAW,CAAC;CACzB;AAED;;;;GAIG;AACH;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC,EAAE,WAAW,GAAG,MAAM,CAY/E;AAED,wBAAgB,UAAU,CACxB,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,WAAW,GAChB,MAAM,CAeR;AAWD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,OAAO,CAAC,UAAU,EAAE;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,CAAC,EACzC,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,WAAW,GAAG;IAAE,UAAU,EAAE,OAAO,CAAA;CAAE,GAC1C,MAAM,CAsBR"}
@@ -0,0 +1,9 @@
1
+ import type { OperationIdentity } from '../../server/types.js';
2
+ /**
3
+ * Whether calling the operation again returns its answer without a new effect.
4
+ *
5
+ * The declared `readOnlyHint` decides in either direction; without one, `GET` is
6
+ * the contract's own statement that the endpoint reads.
7
+ */
8
+ export declare function isRepeatableRead(operation: Pick<OperationIdentity, 'method' | 'annotations'>): boolean;
9
+ //# sourceMappingURL=repeatable-read.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repeatable-read.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/repeatable-read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,IAAI,CAAC,iBAAiB,EAAE,QAAQ,GAAG,aAAa,CAAC,GAC3D,OAAO,CAET"}
@@ -1 +1 @@
1
- {"version":3,"file":"run-managed.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/run-managed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAWrC,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAkB,MAAM,WAAW,CAAC;AAQ3E,wFAAwF;AACxF,wBAAsB,oBAAoB,CACxC,KAAK,EACL,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,QAAQ,SAAS,SAAS,EAC1B,OAAO,EAAE,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAkC1F"}
1
+ {"version":3,"file":"run-managed.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/run-managed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAYrC,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAkB,MAAM,WAAW,CAAC;AAQ3E,wFAAwF;AACxF,wBAAsB,oBAAoB,CACxC,KAAK,EACL,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,QAAQ,SAAS,SAAS,EAC1B,OAAO,EAAE,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAkC1F"}
@@ -1 +1 @@
1
- {"version":3,"file":"run-native.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/run-native.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AACrC,OAAO,EACL,KAAK,oBAAoB,EAG1B,MAAM,WAAW,CAAC;AAInB,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAkB,MAAM,WAAW,CAAC;AAE3E;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EACL,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,QAAQ,SAAS,SAAS,EAE1B,OAAO,EAAE,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAC9C,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,EACzB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,IAAI,CAAC,CAyEf"}
1
+ {"version":3,"file":"run-native.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/run-native.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AACrC,OAAO,EACL,KAAK,oBAAoB,EAG1B,MAAM,WAAW,CAAC;AAInB,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAkB,MAAM,WAAW,CAAC;AAE3E;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EACL,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,QAAQ,SAAS,SAAS,EAE1B,OAAO,EAAE,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAC9C,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,EACzB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,IAAI,CAAC,CA0Ef"}
@@ -0,0 +1,15 @@
1
+ import type { McpReportProgress } from '../contract/runtime-context.js';
2
+ import type { LocalStepDurability } from '../durability/contract.js';
3
+ /** What the agent runtime hands one tool call beside the SDK's own options. */
4
+ export interface RuntimeToolCall {
5
+ /** The run's step ledger; absent when the runtime runs without durability. */
6
+ durability?: LocalStepDurability;
7
+ /** Publishes the call's progress into the run's event stream — the handler's `ctx.reportProgress`. */
8
+ reportProgress: McpReportProgress;
9
+ }
10
+ type Factory = (callId: string, signal?: AbortSignal) => RuntimeToolCall;
11
+ /** Opaque SDK context; no credentials, functions or runtime objects enter provider messages. */
12
+ export declare function createRuntimeToolContext(factory: Factory): object;
13
+ export declare function resolveRuntimeToolCall(context: unknown, callId: string, signal?: AbortSignal): RuntimeToolCall | undefined;
14
+ export {};
15
+ //# sourceMappingURL=runtime-call-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-call-context.d.ts","sourceRoot":"","sources":["../../src/tools/runtime-call-context.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAElE,+EAA+E;AAC/E,MAAM,WAAW,eAAe;IAC9B,8EAA8E;IAC9E,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC,sGAAsG;IACtG,cAAc,EAAE,iBAAiB,CAAC;CACnC;AAED,KAAK,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,eAAe,CAAC;AAGzE,gGAAgG;AAChG,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAIjE;AAED,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,WAAW,GACnB,eAAe,GAAG,SAAS,CAG7B"}
@@ -25,7 +25,10 @@ including `AgentAttemptResetEventSchema` for `attempt-reset`),
25
25
  `AgentControlErrorCodeSchema` / `AgentControlErrorCode` (the one vocabulary of every control
26
26
  error code: `FORBIDDEN`, `CONNECTION_CLOSED`, `REQUEST_CAPACITY`, `ATTACHMENT_CAPACITY`,
27
27
  `LEASE_CONFLICT`, `EVENT_OVERFLOW` and the rest), `AgentMultiSessionCursorSchema` /
28
- `AgentMultiSessionCursor`, `AgentConversationView`, `AgentControlView`,
28
+ `AgentMultiSessionCursor`, `AgentConversationView`, `AgentControlView`, `AgentRunTransient` (a
29
+ run's streamed text, reasoning and running tool calls before its next checkpoint),
30
+ `AgentToolActivity` (one running call with its last reported progress),
31
+ `AGENT_TOOL_PROGRESS_MESSAGE_MAX` (the longest progress message a run publishes),
29
32
  `advanceAgentMultiSessionCursor`, `createAgentControlView`, `reduceAgentControlSnapshot`,
30
33
  `reduceAgentControlEvent` and
31
34
  `agentDurableEventId`. It imports no model provider, executor, store, event sink
@@ -482,6 +482,19 @@ or it keeps the failed attempt's partial text on screen.
482
482
  start and output on completion. A mounted typed failure carries the same safe
483
483
  `{ error, retryable, details?, _hint? }` envelope as the durable result; an unknown
484
484
  internal cause remains generic and stays in local observability only;
485
+ - `tool-progress` is transient: what a running tool handler reported through
486
+ `ctx.reportProgress` — `message`, `progress` and `total`, the fields an MCP host
487
+ receives — with the call's `callId` and `toolName`. It never enters the
488
+ model's input or the durable history. A message longer than
489
+ `AGENT_TOOL_PROGRESS_MESSAGE_MAX` (280) is cut, reports of one call closer
490
+ than 250 ms apart are dropped, and a report after the call's terminal
491
+ `tool-status` or after its attempt was abandoned is dropped; the terminal
492
+ status carries the final word. `reduceAgentControlEvent` keeps the last
493
+ report of each running call in `transientByRun[runId].tools[callId]` and
494
+ removes it on that call's `completed`, `failed` or `interrupted`. The runtime
495
+ hands its reporter to a call through the SDK tool context, beside its step
496
+ ledger; a tool that declares its own `contextSchema` keeps that contract and
497
+ reports nowhere;
485
498
  - `terminal` follows the winning terminal CAS.
486
499
 
487
500
  `loop.checkpointEveryEvents` batches ordinary stream parts (default `20`) and
@@ -787,111 +800,3 @@ Deciding *when* to compact is yours: `AgentRuntimeRunContext.contextUsage`
787
800
  carries the last step's prompt size beside the model's window, and dividing them
788
801
  is one line where the threshold is decided. The core does not own that ratio, on
789
802
  purpose — see ADR 0142 for what it publishes and what it declines to.
790
-
791
- ## Observability
792
-
793
- `createAgentObservability` emits a separate operator-only `AgentRunEvent`. It
794
- reuses the same bounded sink lifecycle as request/tool observability without
795
- sending new event kinds to existing request sinks. Product events omit provider
796
- causes. Operator `internalCause` is also redacted by default; an operator-only sink must explicitly
797
- set `includeInternalCause` and own its retention policy.
798
-
799
- ### What a run says it spent
800
-
801
- Usage values carry `provider-reported`, `computed`, `estimated` or `unavailable`
802
- provenance, **per field**. Cost additionally carries an ISO currency code;
803
- OpenRouter-reported cost is normalized as USD.
804
-
805
- Read the provenance before the number (→ ADR 0109):
806
-
807
- - **`provider-reported`** — the provider handed us exactly this. On
808
- `step-finished`, that is what a step's figures are.
809
- - **`computed`** — a total, added up over steps. **Every figure on a terminal
810
- event is this**, tokens included: the AI SDK's `totalUsage` is a sum it
811
- performed, not a number a provider reported for the run. It is not a figure to
812
- bill against unchanged.
813
- - **`unavailable`** — nobody reported it. Not zero.
814
-
815
- Two rules follow from that last one, and they differ by field on purpose:
816
-
817
- - **A token total with an unreported step is a floor**, labelled `computed`. A
818
- token count is a diagnostic, and a floor is a useful one.
819
- - **A cost with an unreported step is `unavailable`, not a floor.** Money is what
820
- people bill against, and "at least $1.00" reported as `$1.00` is the same class
821
- of lie this whole section exists to remove. One step that did not report its
822
- cost makes the run's cost unknown — not smaller. It also stays unknown: later
823
- steps reporting normally cannot revive it.
824
-
825
- **A terminal event always carries `usage`.** A run that ended before the provider
826
- reported anything — superseded, interrupted, timed out, shut down, failed —
827
- carries every field `unavailable`. That is deliberately different from a run that
828
- spent nothing, and an omitted object could not tell you which one you had.
829
-
830
- Two costs in different currencies do not add: the sum reports `unavailable`
831
- rather than picking a label. The core records a currency and never converts one.
832
-
833
- `step-finished.response` identifies the provider response for that one step. The terminal event
834
- does not copy the last response: response identity remains per-step, while every terminal usage
835
- figure remains a `computed` aggregate.
836
-
837
- **A run's figure is durable, and that is where to read it when a channel loses
838
- it.** `AgentRun.usage` is written at every checkpoint and again with the terminal
839
- record, so a crashed process leaves behind what it had already spent and a
840
- dropped event is not a lost number:
841
-
842
- ```ts
843
- const snapshot = await store.loadSnapshot(conversationId)
844
- const spent = snapshot.runs.find((run) => run.id === runId)?.usage
845
- ```
846
-
847
- Two gaps are open and are stated rather than left to be discovered:
848
-
849
- - **Both event sinks are bounded and drop under load**, by arrival order — the
850
- event carrying the money is exactly as droppable as the one carrying nothing.
851
- The run record is the recovery, and this paragraph is the only place that says
852
- so.
853
- - **`AgentRuntimeResult.metrics` is `undefined` when this executor did not win
854
- the terminal race.** Read `result.run.usage` — the durable figure — rather than
855
- `result.metrics`, which is the channel that can go missing.
856
- - **Compaction spend is invisible unless you report it.** `config.history.compact`
857
- calls a model inside the turn and produces no step and no event of its own.
858
- Return `usage` from `AgentCompactionResult` and it joins the run's figure;
859
- omit it and the run under-reports by whatever summarising cost.
860
-
861
- What stitchkit does **not** keep is a ledger: one figure, on the run that
862
- produced it, never aggregated and never reconciled against a provider invoice
863
- (→ ADR 0110).
864
-
865
- ### Reconciling with the provider's own accounting
866
-
867
- Whether a provider bills for a call that was aborted mid-flight cannot be known
868
- inside the process: the authoritative number arrives later, from the provider's
869
- accounting. **stitchkit does not accept it back** (→ ADR 0110) — a terminal run
870
- is an absorbing state, and a write that reached it through the conversation
871
- aggregate could conflict a concurrent compaction into discarding a summary it had
872
- just paid a model to produce.
873
-
874
- The join is yours, and `runId` is the key:
875
-
876
- ```ts
877
- // when the run terminates — write what the runtime observed
878
- await ledger.record({
879
- runId: terminal.run.id,
880
- conversationId: terminal.run.conversationId,
881
- // The durable figure, not `terminal.metrics` — that one is absent whenever
882
- // this executor did not win the terminal race.
883
- costUsd: terminal.run.usage?.cost?.value ?? null, // null when `unavailable`
884
- provenance: terminal.run.usage?.cost?.provenance ?? 'unavailable',
885
- })
886
-
887
- // later — the provider's accounting names the same generation
888
- await ledger.reconcile({ runId, costUsd: billed, provenance: 'provider-reported' })
889
- ```
890
-
891
- Record the row even when the figure is `unavailable`: that row is the evidence
892
- that a run happened and cost something nobody has counted yet, and it is what the
893
- provider's later figure attaches to. A run with no row is a run you cannot
894
- reconcile.
895
-
896
- The sink deduplicates stable event IDs by default. Cross-crash exactly-once still requires a durable
897
- outbox.
@@ -14,6 +14,114 @@ Parts of this slice:
14
14
  # Guide: Agent application runtime (docs/guide/agent-runtime.md) (continued)
15
15
  ==============================================================================
16
16
 
17
+ ## Observability
18
+
19
+ `createAgentObservability` emits a separate operator-only `AgentRunEvent`. It
20
+ reuses the same bounded sink lifecycle as request/tool observability without
21
+ sending new event kinds to existing request sinks. Product events omit provider
22
+ causes. Operator `internalCause` is also redacted by default; an operator-only sink must explicitly
23
+ set `includeInternalCause` and own its retention policy.
24
+
25
+ ### What a run says it spent
26
+
27
+ Usage values carry `provider-reported`, `computed`, `estimated` or `unavailable`
28
+ provenance, **per field**. Cost additionally carries an ISO currency code;
29
+ OpenRouter-reported cost is normalized as USD.
30
+
31
+ Read the provenance before the number (→ ADR 0109):
32
+
33
+ - **`provider-reported`** — the provider handed us exactly this. On
34
+ `step-finished`, that is what a step's figures are.
35
+ - **`computed`** — a total, added up over steps. **Every figure on a terminal
36
+ event is this**, tokens included: the AI SDK's `totalUsage` is a sum it
37
+ performed, not a number a provider reported for the run. It is not a figure to
38
+ bill against unchanged.
39
+ - **`unavailable`** — nobody reported it. Not zero.
40
+
41
+ Two rules follow from that last one, and they differ by field on purpose:
42
+
43
+ - **A token total with an unreported step is a floor**, labelled `computed`. A
44
+ token count is a diagnostic, and a floor is a useful one.
45
+ - **A cost with an unreported step is `unavailable`, not a floor.** Money is what
46
+ people bill against, and "at least $1.00" reported as `$1.00` is the same class
47
+ of lie this whole section exists to remove. One step that did not report its
48
+ cost makes the run's cost unknown — not smaller. It also stays unknown: later
49
+ steps reporting normally cannot revive it.
50
+
51
+ **A terminal event always carries `usage`.** A run that ended before the provider
52
+ reported anything — superseded, interrupted, timed out, shut down, failed —
53
+ carries every field `unavailable`. That is deliberately different from a run that
54
+ spent nothing, and an omitted object could not tell you which one you had.
55
+
56
+ Two costs in different currencies do not add: the sum reports `unavailable`
57
+ rather than picking a label. The core records a currency and never converts one.
58
+
59
+ `step-finished.response` identifies the provider response for that one step. The terminal event
60
+ does not copy the last response: response identity remains per-step, while every terminal usage
61
+ figure remains a `computed` aggregate.
62
+
63
+ **A run's figure is durable, and that is where to read it when a channel loses
64
+ it.** `AgentRun.usage` is written at every checkpoint and again with the terminal
65
+ record, so a crashed process leaves behind what it had already spent and a
66
+ dropped event is not a lost number:
67
+
68
+ ```ts
69
+ const snapshot = await store.loadSnapshot(conversationId)
70
+ const spent = snapshot.runs.find((run) => run.id === runId)?.usage
71
+ ```
72
+
73
+ Two gaps are open and are stated rather than left to be discovered:
74
+
75
+ - **Both event sinks are bounded and drop under load**, by arrival order — the
76
+ event carrying the money is exactly as droppable as the one carrying nothing.
77
+ The run record is the recovery, and this paragraph is the only place that says
78
+ so.
79
+ - **`AgentRuntimeResult.metrics` is `undefined` when this executor did not win
80
+ the terminal race.** Read `result.run.usage` — the durable figure — rather than
81
+ `result.metrics`, which is the channel that can go missing.
82
+ - **Compaction spend is invisible unless you report it.** `config.history.compact`
83
+ calls a model inside the turn and produces no step and no event of its own.
84
+ Return `usage` from `AgentCompactionResult` and it joins the run's figure;
85
+ omit it and the run under-reports by whatever summarising cost.
86
+
87
+ What stitchkit does **not** keep is a ledger: one figure, on the run that
88
+ produced it, never aggregated and never reconciled against a provider invoice
89
+ (→ ADR 0110).
90
+
91
+ ### Reconciling with the provider's own accounting
92
+
93
+ Whether a provider bills for a call that was aborted mid-flight cannot be known
94
+ inside the process: the authoritative number arrives later, from the provider's
95
+ accounting. **stitchkit does not accept it back** (→ ADR 0110) — a terminal run
96
+ is an absorbing state, and a write that reached it through the conversation
97
+ aggregate could conflict a concurrent compaction into discarding a summary it had
98
+ just paid a model to produce.
99
+
100
+ The join is yours, and `runId` is the key:
101
+
102
+ ```ts
103
+ // when the run terminates — write what the runtime observed
104
+ await ledger.record({
105
+ runId: terminal.run.id,
106
+ conversationId: terminal.run.conversationId,
107
+ // The durable figure, not `terminal.metrics` — that one is absent whenever
108
+ // this executor did not win the terminal race.
109
+ costUsd: terminal.run.usage?.cost?.value ?? null, // null when `unavailable`
110
+ provenance: terminal.run.usage?.cost?.provenance ?? 'unavailable',
111
+ })
112
+
113
+ // later — the provider's accounting names the same generation
114
+ await ledger.reconcile({ runId, costUsd: billed, provenance: 'provider-reported' })
115
+ ```
116
+
117
+ Record the row even when the figure is `unavailable`: that row is the evidence
118
+ that a run happened and cost something nobody has counted yet, and it is what the
119
+ provider's later figure attaches to. A run with no row is a run you cannot
120
+ reconcile.
121
+
122
+ The sink deduplicates stable event IDs by default. Cross-crash exactly-once still requires a durable
123
+ outbox.
124
+
17
125
  ## Deterministic race and adapter proof
18
126
 
19
127
  `stitchkit/agent-runtime/testing` exports `createAgentRaceBarrier`, `createAgentRaceDriver`,
@@ -391,7 +499,9 @@ Delivery exports are `AgentAdmissionEventSchema`, `AgentAttemptResetEventSchema`
391
499
  `AgentRunStateEventSchema`, `AgentRunOperationEventSchema`, `AgentTerminalEventSchema`,
392
500
  `AgentTransientDeltaEventSchema`,
393
501
  `AgentReasoningStartEventSchema`, `AgentReasoningDeltaEventSchema`,
394
- `AgentReasoningEndEventSchema`, `AgentToolStatusEventSchema`, `AgentRuntimeEvent`,
502
+ `AgentReasoningEndEventSchema`, `AgentToolStatusEventSchema`, `AgentToolProgressEventSchema` (what a
503
+ running tool reported through `ctx.reportProgress`, transient and never part of the model's input),
504
+ `AgentRuntimeEvent`,
395
505
  `AgentRuntimeEventCursor`, `AgentRuntimeEventCursorSchema`, `AgentRuntimeCursorAdvance`,
396
506
  `advanceAgentRuntimeEventCursor`, `agentDurableEventId`, `AgentRuntimeEventSink`,
397
507
  `AgentRuntimeEventSinkConfig` and `createAgentRuntimeEventSink`. Cursor gaps require a canonical
package/llms/cli.txt CHANGED
@@ -702,15 +702,27 @@ Rules worth knowing before you rely on them:
702
702
  A failed call still reports its own error and exit code. An aggregate over an
703
703
  error is not an answer to the question that was asked.
704
704
 
705
- If the command succeeds but its requested view cannot be built, the CLI writes
706
- the complete original result to stdout, using the normal JSON format (`--json`
707
- still selects compact output). It writes a separate structured
708
- `CLI_PRESENTATION_FAILED` diagnostic to stderr and exits with `8`, configurable
709
- through `exitCodes`. Its `details.operationSucceeded: true` and `retryable: false`
710
- distinguish a presentation refusal from a failed operation; `details.cause`
711
- preserves the safe reason. Recover the answer from stdout instead of repeating
712
- the mutation. Domain retry hints are not appended to this diagnostic. CLI
713
- argument errors detected before execution still exit with `2`
705
+ If the command succeeds but its requested view cannot be built, the CLI writes a
706
+ structured `CLI_PRESENTATION_FAILED` diagnostic to stderr and exits with `8`,
707
+ configurable through `exitCodes`. Its `details.operationSucceeded: true` and
708
+ `retryable: false` distinguish a presentation refusal from a failed operation;
709
+ `details.cause` preserves the safe reason, such as the misspelled field and the
710
+ fields that are there. Domain retry hints are not appended to this diagnostic.
711
+
712
+ What reaches stdout depends on whether the command can be called again for its answer,
713
+ and `details.resultOnStdout` states which case occurred:
714
+
715
+ | Command | stdout | Recover the answer by |
716
+ |---|---|---|
717
+ | has an effect | the complete original result in the normal JSON format (`--json` still selects compact output) | reading stdout — never by repeating the mutation |
718
+ | only reads | nothing | repeating the command with a corrected view |
719
+
720
+ A managed command only reads when its tool declares `annotations.readOnlyHint: true`,
721
+ or declares no `readOnlyHint` and its method is `GET`. `readOnlyHint: false` on a `GET`
722
+ endpoint keeps the result on stdout. A native `defineCliCommand` declares neither fact,
723
+ so a failed `present` always keeps the validated result on stdout.
724
+
725
+ CLI argument errors detected before execution still exit with `2`
714
726
  and have no successful result to preserve.
715
727
 
716
728
  ## Named profiles
package/llms/server.2.txt CHANGED
@@ -507,3 +507,51 @@ is simply never emitted, so nothing about a hidden endpoint leaks.
507
507
  const internal = openApiRoute('/internal/openapi.json', fullDoc) // behind auth
508
508
  const publicSpec = openApiRoute('/openapi.json', publicDoc) // curated
509
509
  ```
510
+
511
+ ### Security schemes — `security`
512
+
513
+ A generic client reads the spec to learn how to authenticate, and a scope name
514
+ alone does not tell it which header to send. Pass `security` to describe that in
515
+ standard OpenAPI terms: named schemes become `components.securitySchemes`, and
516
+ every protected operation gets a `security` requirement. It is keyed by the
517
+ scopes your contracts already declare, so there is no second list of which
518
+ endpoint is protected:
519
+
520
+ ```ts
521
+ const publicDoc = generateOpenApiDocument({
522
+ info: { title: 'Public API', version: '1.0.0' },
523
+ services: [account],
524
+ includeMethod: (m) => m.meta?.public === true,
525
+ security: {
526
+ schemes: {
527
+ apiKey: { type: 'http', scheme: 'bearer', description: 'An account API key' },
528
+ },
529
+ // Each protected scope → the schemes that satisfy it, any one of them.
530
+ scopes: { account: ['apiKey'] },
531
+ },
532
+ })
533
+ ```
534
+
535
+ A scheme is `{ type: 'http', scheme: 'bearer' | 'basic' }` or
536
+ `{ type: 'apiKey', in: 'header' | 'query' | 'cookie', name }` (a session cookie
537
+ is the `cookie` form). An operation is described by the scope the auth hook
538
+ checks it under:
539
+
540
+ | The operation's scope | In the document |
541
+ |---|---|
542
+ | `'public'` | no `security`, no 401/403 |
543
+ | listed in `scopes` with schemes | `security: [{ apiKey: [] }, …]` and 401/403 |
544
+ | listed with an empty list — a custom scope whose rule is `'public'` | no `security`, no 401/403 |
545
+ | not listed | generation throws, naming the operation |
546
+ | none of its own | read as `defaultScope` — pass the same value as `createAuthHook({ defaultScope })` |
547
+
548
+ Generation refuses a protected scope it cannot describe instead of emitting the
549
+ operation as open — a client would otherwise call it without a credential. Only
550
+ the operations the document advertises need a mapping: a method `includeMethod`
551
+ filters out is never checked. A scheme `scopes` names but `schemes` does not
552
+ declare, and an entry for `'public'`, are refused the same way.
553
+
554
+ The metadata describes your policy; it does not enforce it. The auth hook is
555
+ still the only gate, and removing `security` changes the document, never a
556
+ 401 or 403. Credential values never belong here: describe where the key goes,
557
+ not what it is.
package/llms/server.5.txt CHANGED
@@ -236,6 +236,8 @@ Also re-exports the error helpers from `stitchkit/contract`.
236
236
  | `OpenApiConfig` | _type_ | config for `generateOpenApiDocument` (incl. `includeMethod` — curate a public subset) — [guide](../guide/server.md#curating-the-spec--includemethod) |
237
237
  | `OpenApiDocument` | _type_ | the generated document |
238
238
  | `OpenApiInfo` | _type_ | the spec `info` block |
239
+ | `OpenApiSecurity` | _type_ | `OpenApiConfig.security` — named schemes and the schemes each protected scope accepts — [guide](../guide/server.md#security-schemes--security) |
240
+ | `OpenApiSecurityScheme` | _type_ | one way a caller presents its credential: HTTP bearer or basic, or an API key in a header, query or cookie |
239
241
  | `OpenApiServer` | _type_ | a spec `servers` entry |
240
242
 
241
243
  ---
@@ -92,13 +92,13 @@ own, recorded as an ADR.
92
92
  | `stitchkit/xlsx` | browser **and** server | evolving | a workbook from rows and typed columns, with no dependency; text never runs as a formula |
93
93
  | `stitchkit/oauth` | browser **and** server | evolving | provider-neutral Authorization Code + PKCE request and one-shot callback transaction mechanics |
94
94
  | `stitchkit/google` | server (Bun or Node) | evolving | optional Google code exchange and verified OIDC identity adapter |
95
- | `stitchkit/observability` | server | stable<br>_redefined in 2 of the 66 minors since 0.56.2, most recently 0.92.0_ | request/tool event projections — `createObservability`, trace context, sanitisation |
95
+ | `stitchkit/observability` | server | stable<br>_redefined in 2 of the 67 minors since 0.56.2, most recently 0.92.0_ | request/tool event projections — `createObservability`, trace context, sanitisation |
96
96
  | `stitchkit/testing` | tests on Bun or Node | stable | in-process generated clients over a real Fetch handler, the managed-resource conformance kit and manual time for schedules and retries |
97
97
  | `stitchkit/declaration` | browser + build and deployment tooling (Bun or Node) | evolving | `ProjectDeclarationSchema` — the one machine-readable statement a repository makes about itself |
98
98
  | `stitchkit/react` | browser + server rendering | stable | `createCursorQuery`, `createCacheBridge`, QueryClient and `ApiError` retry policy |
99
99
  | `stitchkit/react/keyboard` | browser | evolving | which part of a screen gets a key — ordered layers, one Escape per level, list zones with real focus; see [keyboard guide](keyboard.md) |
100
100
  | `stitchkit/react/keyboard/testing` | server (Bun or Node) | evolving | the keyboard layers and zones without a DOM — fakes for the window, elements and key events beside the two engines, to test the order of layers, `scope`/`inert` and the edges of a zone in milliseconds |
101
- | `stitchkit/agent-runtime` | server | evolving<br>_redefined in 26 of the 66 minors since 0.56.2, most recently 0.121.0_ | optional durable conversation/run loop, history, models, prompts, fencing and events |
101
+ | `stitchkit/agent-runtime` | server | evolving<br>_redefined in 26 of the 67 minors since 0.56.2, most recently 0.121.0_ | optional durable conversation/run loop, history, models, prompts, fencing and events |
102
102
  | `stitchkit/agent-runtime/sandbox` | server | evolving | optional Linux Bubblewrap sessions, durable workspaces and a host HTTP credential gateway; see [sandbox guide](sandbox.md) |
103
103
  | `stitchkit/agent-runtime/testing` | tests on Bun or Node | evolving | credential-free replay, scripted provider faults, deterministic race controls and the agent-store conformance kit |
104
104
  | `stitchkit/agent-runtime/harness` | server | evolving | resource-aware process-local facade over the canonical Agent runtime; supervision stays outside |
@@ -110,7 +110,7 @@ own, recorded as an ADR.
110
110
  | `stitchkit/agent-runtime/sqlite/bun` | server (Bun) | evolving | durable built-in SQLite store for the agent runtime |
111
111
  | `stitchkit/agent-runtime/sqlite/node` | server (Node ≥ 22.5) | evolving | durable built-in SQLite store for the agent runtime |
112
112
  | `stitchkit-tui` | terminal (Bun) | evolving | optional official OpenTUI host over a caller-composed headless runtime |
113
- | `stitchkit/application` | browser + server | evolving<br>_redefined in 14 of the 66 minors since 0.56.2, most recently 0.110.0_ | managed resource graph, readiness, admission, schedules, subtree restart and bounded shutdown |
113
+ | `stitchkit/application` | browser + server | evolving<br>_redefined in 14 of the 67 minors since 0.56.2, most recently 0.110.0_ | managed resource graph, readiness, admission, schedules, subtree restart and bounded shutdown |
114
114
  | `stitchkit/application/grammy` | server | evolving | a grammY bot as application resources — configuration, then polling with updates admitted by batch — and the webhook adapter |
115
115
  | `stitchkit/application/opentelemetry` | server | evolving | maps application snapshots onto an injected OpenTelemetry `Meter` |
116
116
  | `stitchkit/application/schemas` | browser + server | evolving | the application's snapshot, health and shutdown schemas alone, without the kernel |
package/llms/tools.txt CHANGED
@@ -498,7 +498,10 @@ render: async (ctx) => {
498
498
 
499
499
  `reportProgress` is present on every **tool** call — MCP, agent and CLI — so a
500
500
  handler never branches on transport, and it does nothing wherever nobody is
501
- listening. It is absent on the HTTP transport, which has no channel for it, so a
501
+ listening. Under the agent runtime somebody is: each report becomes a transient
502
+ `tool-progress` event of the run, so the person watching the agent sees the
503
+ stage while the model still reads only the tool's result (see
504
+ [Agent runtime → events](./agent-runtime.md)). It is absent on the HTTP transport, which has no channel for it, so a
502
505
  handler that also serves HTTP writes `ctx.reportProgress?.(…)`. It never throws and never
503
506
  rejects: a message about work must not be able to kill the work it describes, so
504
507
  a refused notification leaves the host exactly where a host that never asked for