stitchkit 0.68.3 → 0.68.4

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 (44) hide show
  1. package/dist/agent-runtime/context-refusal.d.ts +13 -0
  2. package/dist/agent-runtime/context-refusal.d.ts.map +1 -0
  3. package/dist/agent-runtime/run-execution.d.ts.map +1 -1
  4. package/dist/agent-runtime/runtime.d.ts +4 -0
  5. package/dist/agent-runtime/runtime.d.ts.map +1 -1
  6. package/dist/agent-runtime.d.ts +1 -0
  7. package/dist/agent-runtime.d.ts.map +1 -1
  8. package/dist/agent-runtime.js +15 -10
  9. package/dist/browser/contract-stream.d.ts.map +1 -1
  10. package/dist/browser/stream.d.ts +3 -0
  11. package/dist/browser/stream.d.ts.map +1 -1
  12. package/dist/cli.js +5 -5
  13. package/dist/contract/define.d.ts +39 -6
  14. package/dist/contract/define.d.ts.map +1 -1
  15. package/dist/contract/index.d.ts +1 -1
  16. package/dist/contract/index.d.ts.map +1 -1
  17. package/dist/contract/index.js +1 -1
  18. package/dist/{index-cz32amcb.js → index-04agqrs8.js} +2 -2
  19. package/dist/{index-cszjsxy5.js → index-1bmpkhj2.js} +3 -3
  20. package/dist/{index-wqyrvhzz.js → index-3ydx9j01.js} +2 -2
  21. package/dist/{index-69m2278y.js → index-51a19y3v.js} +1 -1
  22. package/dist/{index-3vq6we8m.js → index-6tqys26z.js} +16 -6
  23. package/dist/{index-7etq650s.js → index-88yyydag.js} +1 -1
  24. package/dist/{index-g2j2m6vv.js → index-9t2tdk1x.js} +2 -2
  25. package/dist/{index-9ky9hhg3.js → index-bmmtz6r9.js} +14 -0
  26. package/dist/{index-dafax5md.js → index-hmfpjnh7.js} +1 -1
  27. package/dist/{index-cq9q73nf.js → index-j2nq04z6.js} +14 -0
  28. package/dist/{index-v5bayx1z.js → index-r5s4wqb5.js} +7 -3
  29. package/dist/{index-2ve29dzn.js → index-thcy3w8c.js} +43 -20
  30. package/dist/{index-pr0qsmjy.js → index-z575awm9.js} +1 -1
  31. package/dist/index.js +48 -21
  32. package/dist/internal/bounded-lines.d.ts +1 -1
  33. package/dist/internal/bounded-lines.d.ts.map +1 -1
  34. package/dist/node.js +4 -4
  35. package/dist/observability/index.js +3 -3
  36. package/dist/remote.js +3 -3
  37. package/dist/server/contract-stream.d.ts.map +1 -1
  38. package/dist/server/index.js +10 -7
  39. package/dist/server/openapi.d.ts.map +1 -1
  40. package/dist/testing.js +3 -3
  41. package/dist/tool-invoker.js +5 -5
  42. package/dist/tools.js +9 -9
  43. package/llms-full.txt +71 -3
  44. package/package.json +1 -1
package/llms-full.txt CHANGED
@@ -1574,6 +1574,27 @@ multipart or tool exposure. They do not provide replay, cursors or durable
1574
1574
  subscriptions. Keep using `streamingRoute` for an application-owned protocol and
1575
1575
  `rawResponse` for arbitrary response bodies. → ADR 0117.
1576
1576
 
1577
+ For an existing schema-owned NDJSON protocol, opt into direct item frames and
1578
+ terminal-owned completion:
1579
+
1580
+ ```ts
1581
+ stream: {
1582
+ item: Item,
1583
+ framing: 'item',
1584
+ completion: 'terminal',
1585
+ terminal: z.object({ kind: z.literal('complete') }).loose(),
1586
+ finalLine: 'require-newline',
1587
+ }
1588
+ ```
1589
+
1590
+ `item` framing is NDJSON-only and requires terminal completion. The server
1591
+ writes each validated item directly, stops the source after the terminal and
1592
+ never reads trailing producer values. Because this wire has no framework error
1593
+ envelope, any producer/lifetime failure before terminal closes the response;
1594
+ the typed client reports `STREAM_TERMINAL_MISSING`. The terminal item therefore
1595
+ proves success without weakening safe post-header failure semantics. Existing
1596
+ streams retain the envelope and explicit end frame by default. → ADR 0126.
1597
+
1577
1598
  ### SSE streaming
1578
1599
 
1579
1600
  `streamSSE` returns a `Response`, so its endpoint declares
@@ -2407,6 +2428,26 @@ wire `end` frame and, when declared, at least one matching terminal item; EOF is
2407
2428
  converge on the request operation. See the
2408
2429
  [server half](./server.md#contract-first-streams). → ADR 0117.
2409
2430
 
2431
+ An established NDJSON protocol may keep its item schema as the complete wire
2432
+ frame. This mode requires a terminal item because an unwrapped response has no
2433
+ separate safe error/end envelope:
2434
+
2435
+ ```ts
2436
+ stream: {
2437
+ item: Progress,
2438
+ framing: 'item',
2439
+ completion: 'terminal',
2440
+ terminal: z.object({ kind: z.literal('complete') }).loose(),
2441
+ finalLine: 'require-newline',
2442
+ }
2443
+ ```
2444
+
2445
+ The matching terminal item ends the operation. Before `next()` returns that
2446
+ item, the client aborts the owned request and cancels its body reader; trailing
2447
+ frames are not read. EOF first is `STREAM_TERMINAL_MISSING`. The defaults remain
2448
+ `framing: 'envelope'`, `completion: 'stream-end'` and `finalLine: 'allow'`.
2449
+ → ADR 0126.
2450
+
2410
2451
  ## SSE
2411
2452
 
2412
2453
  For a streaming endpoint, consume the response with `parseSSE`:
@@ -2460,6 +2501,10 @@ implementations. One line is bounded by `maxLineBytes` (default 1 MiB), UTF-8 is
2460
2501
  decoded strictly and malformed input throws. Passing `onParseError` explicitly
2461
2502
  selects tolerant skip-and-report behaviour.
2462
2503
 
2504
+ Set `finalLine: 'require-newline'` when the final newline is part of the
2505
+ protocol's truncation proof. The default `allow` continues to accept one valid
2506
+ final JSON document without a newline.
2507
+
2463
2508
 
2464
2509
  ==============================================================================
2465
2510
  # Guide: MCP & agents (docs/guide/mcp-and-agents.md)
@@ -3721,6 +3766,7 @@ bun add @openrouter/ai-sdk-provider
3721
3766
  ```ts
3722
3767
  import { z } from 'zod'
3723
3768
  import {
3769
+ AgentContextOverflowError,
3724
3770
  composeAgentPrompt,
3725
3771
  createAgentRuntime,
3726
3772
  createMemoryAgentRuntimeStore,
@@ -4199,6 +4245,25 @@ is the reserved built-in policy name. `loop.prepareStep` is the controlled AI
4199
4245
  SDK step boundary for changing active tools, model, instructions or messages.
4200
4246
  It cannot replace the managed tool set or bypass its lifecycle fence.
4201
4247
 
4248
+ Context can grow between steps as tool results and deferred schemas enter the
4249
+ provider prompt. When application budgeting can prove that the next assembled
4250
+ step exceeds the selected model window, refuse it by type before that provider
4251
+ call:
4252
+
4253
+ ```ts
4254
+ prepareStep: (step) => {
4255
+ if (wouldExceedSelectedModelWindow(step)) {
4256
+ throw new AgentContextOverflowError('Prepared step exceeds the selected model window')
4257
+ }
4258
+ return chooseProductStepOptions(step)
4259
+ }
4260
+ ```
4261
+
4262
+ That deliberate refusal ends the run as `context_overflow` on the durable
4263
+ record, delivery terminal and operator event. Stitchkit does not inspect error
4264
+ messages: every other `prepareStep` or provider error remains
4265
+ `provider_failure`, and operator-only observability retains its original cause.
4266
+
4202
4267
  Completion validity belongs to the protocol and is checked before the terminal
4203
4268
  CAS. Protocols that require a visible answer opt in explicitly:
4204
4269
 
@@ -10909,8 +10974,10 @@ The browser-and-server entrypoint. Re-exports everything from
10909
10974
  | `bindRealtimeClient` | function | bind contract validation and typed acknowledgements to an existing Stitchkit client transport without owning its lifecycle |
10910
10975
  | `createRetainedTopics` | function | retained last-value store for sticky events — [guide](../guide/realtime.md#sticky-events) |
10911
10976
  | `parseSSE` | function | parse an SSE `Response` into an async generator — [guide](../guide/client.md#sse) |
10912
- | `parseNDJSON` | function | parse an NDJSON `Response`; blank keep-alive lines are skipped — [guide](../guide/client.md#ndjson) |
10913
- | `ContractStreamFrameSchema` / `ContractStreamFrame` | schema / _type_ | internal-on-the-wire `data` / safe `error` / `end` envelope of a contract-first stream |
10977
+ | `parseNDJSON` | function | parse bounded fatal-UTF-8 NDJSON; blank keep-alives are skipped and `finalLine: 'require-newline'` can make the delimiter mandatory — [guide](../guide/client.md#ndjson) |
10978
+ | `ContractStreamFrameSchema` / `ContractStreamFrame` | schema / _type_ | default on-the-wire `data` / safe `error` / `end` envelope of a contract-first stream |
10979
+ | `ContractStreamFraming` / `ContractStreamCompletion` | _types_ | opt-in item-vs-envelope framing and terminal-vs-stream-end completion policies |
10980
+ | `StreamFinalLinePolicy` | _type_ | permissive or newline-required final NDJSON line policy |
10914
10981
  | `DEFAULT_CONTRACT_STREAM_FRAME_BYTES` | const | default maximum encoded contract-stream frame: 256 KiB |
10915
10982
  | `SocketIOClient` | _type_ | low-level client handle; `emit` reports disconnected drops and `emitWithAck` exposes the native Promise primitive used by validated `request()` |
10916
10983
  | `SocketIOClientPeerLoaders` | _type_ | inject `socket.io-client` so a bundler can put it in a self-contained artifact |
@@ -10987,7 +11054,7 @@ from the root `stitchkit`.
10987
11054
  | `ContractDef` | _type_ | a defined contract |
10988
11055
  | `ContractMeta` | _type_ | a contract's `prefix` + optional `scope` and `meta` (a default every endpoint shallow-merges over) |
10989
11056
  | `EndpointDef` | _type_ | a single endpoint definition; `output` declares JSON response presence (`null` is data, `undefined` is invalid) |
10990
- | `EndpointStreamDescriptor` | _type_ | HTTP-only schema-derived stream declaration: item schema, NDJSON/SSE framing, frame/lifetime/heartbeat/idle bounds and optional terminal predicate — [guide](../guide/server.md#contract-first-streams) |
11057
+ | `EndpointStreamDescriptor` | _type_ | HTTP-only schema-derived stream declaration: item schema, envelope/item framing, stream-end/terminal completion, NDJSON/SSE encoding and frame/lifetime/heartbeat/idle bounds — [guide](../guide/server.md#contract-first-streams) |
10991
11058
  | `HeadEndpointDef` | _type_ | explicit HTTP-only, bodyless `HEAD` endpoint definition |
10992
11059
  | `EndpointResponseMeta` | _type_ | static success metadata declared by an HTTP-only typed-data endpoint |
10993
11060
  | `ResponseMetadata` | _type_ | per-request outbound collector exposed as `ctx.response` only for a `responseMeta` endpoint |
@@ -11444,6 +11511,7 @@ Server-only optional application runtime. See the
11444
11511
  | `createAgentSessionCoordinator` | function | strict process-local queue/interrupt/supersede lifecycle |
11445
11512
  | `AgentRuntimeStopPolicy` | _type_ | named custom AI SDK stop condition persisted and published on policy stop |
11446
11513
  | `AgentRuntimePrepareStep` | _type_ | per-run controlled step callback with typed domain context and managed run signal/fence |
11514
+ | `AgentContextOverflowError` | class | deliberate application budget refusal thrown from `loop.prepareStep`; terminalizes as `context_overflow` without classifying arbitrary error text |
11447
11515
  | `AgentRuntimeRecordIds` | _type_ | optional caller-provided input, run and assistant IDs for stable application records |
11448
11516
  | `AgentRuntimeAdmission` | _type_ | canonical committed input, assigned run, pending assistant projection, compatibility IDs and snapshot version |
11449
11517
  | `AgentAdmissionEventSchema` | schema | post-commit admission projection; removes store rereads but does not imply exactly-once delivery |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stitchkit",
3
- "version": "0.68.3",
3
+ "version": "0.68.4",
4
4
  "description": "Contract-first backend framework — one defineContract() into an HTTP API, MCP tools, AI-agent tools and a typed client. Bun and Node.",
5
5
  "keywords": [
6
6
  "bun",