stitchkit 0.30.0 → 0.31.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/dist/tools.d.ts CHANGED
@@ -4,7 +4,7 @@ export { type CliConfig, createCli } from './tools/cli';
4
4
  export type { ExitCodeMap } from './tools/cli-format';
5
5
  export type { CliWaitConfig } from './tools/cli-wait';
6
6
  export { coerceJsonArgs } from './tools/coerce';
7
- export type { ErrorHintFn, ToolCallHooks, ToolLifecycle, ToolResult } from './tools/execute';
7
+ export type { ErrorHintFn, ToolCallContext, ToolCallHooks, ToolLifecycle, ToolResult, } from './tools/execute';
8
8
  export { flattenDiscriminatedUnion, flattenUnionsDeep } from './tools/flatten';
9
9
  export { listToolNames, type ToolNameEntry } from './tools/list-names';
10
10
  export { buildToolManifest, type ToolManifestEntry } from './tools/manifest';
@@ -1 +1 @@
1
- {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,EAAE,KAAK,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxD,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,KA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059
  serverInfo, auth, services,
3060
3060
  hooks: {
3061
3061
  onToolError: (toolName, error, _context, endpoint) => {
3062
- // The request context is live here, so the cause lands on the HTTP log
3063
- // line for the MCP request as well as in your own sink.
3064
- setRequestError({
3065
- code: 'TOOL_FAILED',
3062
+ reportToolFailure({
3063
+ tool: toolName,
3064
+ action: endpoint.key,
3066
3065
  message: error instanceof Error ? error.message : String(error),
3067
- details: { tool: toolName, action: endpoint.key },
3066
+ stack: error instanceof Error ? error.stack : undefined,
3068
3067
  })
3069
3068
  },
3070
3069
  },
@@ -3087,6 +3086,36 @@ observe. (This is also why it lives on `ToolCallHooks` rather than being an
3087
3086
  `Response`, which a tool call has no use for, and a whole `createServer` hooks
3088
3087
  object must stay assignable to `ToolLifecycle`.)
3089
3088
 
3089
+ **`setRequestError` is the wrong sink here — mind which record you are filling.**
3090
+ It writes to the *request* context, and `createAuditHook`'s **tool** row does not
3091
+ read it: `errorCode` / `errorMessage` / `errorDetail` on a tool event come from
3092
+ the `ToolResult`, and only `userId` / `clientId` / `ipAddress` / `userAgent` /
3093
+ `dimensions` come from the context. So calling it in `onToolError` leaves the
3094
+ tool audit row exactly as scrubbed as before — and for MCP over HTTP it also
3095
+ writes the cause into the log line of the enclosing `/mcp` request, turning one
3096
+ incident into two records.
3097
+
3098
+ Route the cause to your own sink from `onToolError`, as above, and let the audit
3099
+ row stay the record of the *call*. If you want one row carrying both, correlate
3100
+ the two hooks yourself — key the cause by the call and read it back in
3101
+ `afterToolCall`:
3102
+
3103
+ ```ts
3104
+ const causes = new WeakMap<object, unknown>()
3105
+
3106
+ hooks: {
3107
+ onToolError: (_tool, error, context) => { causes.set(context, error) },
3108
+ afterToolCall: (toolName, _args, result, durationMs, context, endpoint) => {
3109
+ void writeRow({ toolName, result, durationMs, cause: causes.get(context), endpoint })
3110
+ },
3111
+ }
3112
+ ```
3113
+
3114
+ Every mount builds a fresh context object per call and hands the same reference
3115
+ to both hooks, so it is a safe key and nothing leaks. `setRequestError` remains
3116
+ right for the **HTTP** path, where the request *is* the record — see the fields
3117
+ section above.
3118
+
3090
3119
  ### Keying a row on (service, action)
3091
3120
 
3092
3121
  `createAuditHook` already keys every event by **service** and **action**
@@ -3861,6 +3890,7 @@ Server-only. Turns contracts into MCP and AI-agent tools. Needs the
3861
3890
  | `ToolCallHooks` | _type_ | `beforeToolCall` / `afterToolCall` / `onToolError` observability hooks — the last carries the value **as thrown**, before normalisation scrubs an unexpected error to `INTERNAL_SERVER_ERROR` ([guide](../guide/observability.md#the-cause-behind-a-failed-tool-call)) |
3862
3891
  | `ErrorHintFn` | _type_ | `(toolName, errorCode) => string \| null` — a per-tool recovery hint, shared by every mount |
3863
3892
  | `ToolResult` | _type_ | the result of one tool call |
3893
+ | `ToolCallContext` | _type_ | the context every tool hook receives — `{ source }` plus whatever the mount's `context` added |
3864
3894
  | `ToolNameEntry` | _type_ | one `listToolNames` row — `{ name, service, method, transports }` |
3865
3895
  | `IncompatibleSchemaPolicy` | _type_ | `'throw' \| 'skip' \| 'warn'` |
3866
3896
  | `McpMediaContent` | _type_ | a multimodal MCP content item |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stitchkit",
3
- "version": "0.30.0",
3
+ "version": "0.31.0",
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",