@goodtiming/baton-sdk 0.6.8 → 1.0.1
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/README.md +56 -4
- package/dist/index.cjs +808 -282
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +357 -139
- package/dist/index.d.ts +357 -139
- package/dist/index.js +808 -232
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @goodtiming/baton-sdk
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**Stable from 1.0.** This package follows [semver](https://semver.org). [What is public](#what-is-public) lists the public API and what in it is experimental. The wire format only grows: nothing is removed or changes meaning, except what SPEC marks experimental ([SPEC §13](https://github.com/good-timing/baton-spec/blob/main/SPEC.md#stability-from-10)).
|
|
4
4
|
|
|
5
5
|
MCP standardizes how agents discover and call your tools. It does not capture *why* a call happened or whether it helped the user. Baton instruments those interactions on the vendor side by wrapping your MCP server. It captures intent, the tool calls, expected outcomes and observed outcomes, plus friction signals, and hands each one to a sink.
|
|
6
6
|
|
|
@@ -122,6 +122,26 @@ app.use((req, res, next) =>
|
|
|
122
122
|
|
|
123
123
|
Capture never throws into your code. Only the constructor throws, on a bad config. Call `await baton.aclose()` at shutdown.
|
|
124
124
|
|
|
125
|
+
### Agent reports on your own API
|
|
126
|
+
|
|
127
|
+
`withBaton` gives agents a report tool, so an agent can tell you when a call went wrong or no tool covers what the user asked. On your own API, offer the same tool with `reportTool`. It has the name, description and input schema `withBaton` registers on a server with that name, so an agent reads the same words.
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import { reportTool } from "@goodtiming/baton-sdk";
|
|
131
|
+
|
|
132
|
+
const tool = reportTool({ vendorDisplayName: "Acme" });
|
|
133
|
+
// Offer tool.name, tool.description and tool.inputSchema to the agent.
|
|
134
|
+
// Serving MCP yourself? Send tool.instructions in place of INTENT_INSTRUCTIONS.
|
|
135
|
+
|
|
136
|
+
// When the agent calls it:
|
|
137
|
+
const options = tool.annotateArgs(args);
|
|
138
|
+
if (options === null) return { ok: false, error: tool.refusal };
|
|
139
|
+
await baton.annotate(options);
|
|
140
|
+
return { ok: true };
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
`annotateArgs` returns `null` when the agent sent no `what_happened`. Send `tool.refusal` back and nothing to Baton, because a call with no account is not a report. Call it inside the same `session(...)` block as the calls it is about, or use `await trace.annotate(options)` for one traced call.
|
|
144
|
+
|
|
125
145
|
## PII scrubbing
|
|
126
146
|
|
|
127
147
|
**On by default**, a rule-for-rule port of the Python SDK's ruleset: email, `Bearer` values, `sk-*` and `AKIA*` keys, JWTs, phone numbers, Luhn-checked card numbers, plus force-redaction on sensitive field names. Pass `identityScrub` to opt out, or supply your own `(value: unknown) => unknown`.
|
|
@@ -151,7 +171,7 @@ The hook runs on every tool call, every `tools/list` request and every resource
|
|
|
151
171
|
|
|
152
172
|
The id is sent exactly as your hook returns it, so the hook decides what is safe to send. To send a pseudonym instead, hash the id inside your hook and return `form: "hashed"` with it.
|
|
153
173
|
|
|
154
|
-
If your users belong to your customers' companies, return the company too
|
|
174
|
+
If your users belong to your customers' companies, return the company too. Each event then carries it:
|
|
155
175
|
|
|
156
176
|
```ts
|
|
157
177
|
{ principalId: "u_123", organization: { organizationId: "org_acme", displayName: "Acme" } }
|
|
@@ -175,6 +195,30 @@ Each affected event says so, in its own field (`result_capture: "off"`), rather
|
|
|
175
195
|
|
|
176
196
|
**What it costs you:** anything that needs to read a response body. A call that returns `200` with a useless body can no longer be detected, and those calls sit outside the denominator of body-level analysis rather than counting as passes or failures.
|
|
177
197
|
|
|
198
|
+
## Settings from the Console
|
|
199
|
+
|
|
200
|
+
**Change what is captured without a redeploy.** With `settings: "console"`, the SDK reads the settings saved on the Console's Capture page, and each caller gets the settings of the first audience that matches it. An audience can match on the caller's labels, the app it runs in (such as `claude-code`), a share of your callers, or several of these, and then all of them must match.
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
withBaton(server, { dsn, settings: "console" });
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
On a hosted server, `BATON_DSN` in the environment works here too. Pass `{ settings: "console" }` without a `dsn`. There is no environment variable for `settings` itself, so turning it on is a change to your code.
|
|
207
|
+
|
|
208
|
+
Three things can differ by audience.
|
|
209
|
+
|
|
210
|
+
| Setting | What it changes | When it applies |
|
|
211
|
+
|---|---|---|
|
|
212
|
+
| `results` | Whether results and error messages are sent, as `resultCaptureMode` does | The next call |
|
|
213
|
+
| `goal` | Whether the `user_goal` Baton adds is required or optional. A tool that declares its own `user_goal` keeps it as it is. | The next `tools/list` |
|
|
214
|
+
| `reports` | Whether the caller sees the report tool. A report from a caller with reports off, such as one from an older tool list, is still recorded. | The next `tools/list` |
|
|
215
|
+
|
|
216
|
+
The SDK reads the settings every 60 seconds, in the background: a read never delays startup or a call. Set `settingsRefreshMs` to change that, down to 15000. Until the first read succeeds, and while nothing is saved, the values in your config apply. Once settings are read, each event says which ones it ran under, in `capture`. One `createBaton` reads them once for every server it wraps.
|
|
217
|
+
|
|
218
|
+
`reportMode` is `"on"` by default here, so the Console decides who sees the report tool. Set `reportMode: "off"` to keep it off for everyone. The report sentence in your server's instructions stays while any audience has reports on. A client reads the instructions when it connects, so a change reaches new connections only.
|
|
219
|
+
|
|
220
|
+
Labels come from your `resolvePrincipal` hook, as `labels` on the `Principal` or the `Organization` it returns. Up to 20 per caller, sent on every event, so send only names you are happy for Baton to see. A share of callers is picked by the principal's id, so the same person always lands in the same group. A caller with no principal is never in a share, even with a company: to target a company, give it a label.
|
|
221
|
+
|
|
178
222
|
## Failures your handler never saw
|
|
179
223
|
|
|
180
224
|
A wrapper around your tool executor only sees calls that reach it. Three kinds
|
|
@@ -270,6 +314,14 @@ None of it blocks the quickstart above.
|
|
|
270
314
|
- `resources/templates/list` sends no events.
|
|
271
315
|
- v2's `createMcpHandler` is tested only for calls that pause for input. A server built per request by your own code is supported: see [A server per request](#a-server-per-request).
|
|
272
316
|
|
|
317
|
+
## What is public
|
|
318
|
+
|
|
319
|
+
The public API is the exports of `@goodtiming/baton-sdk`, its only entry point.
|
|
320
|
+
|
|
321
|
+
These are **experimental** and may change in a minor release: `EventSchema`, and `ClientReportEvent` with `ClientReportPayload`. [SPEC §13](https://github.com/good-timing/baton-spec/blob/main/SPEC.md#stability-from-10) lists what is experimental on the wire.
|
|
322
|
+
|
|
323
|
+
The event types are built with zod. `EventSchema` may change with a zod major; the event types may not, so 1.x moves to a new zod major only if they stay the same.
|
|
324
|
+
|
|
273
325
|
## Wire compatibility
|
|
274
326
|
|
|
275
327
|
Events from this package must be JSON-identical in shape to the Python SDK's, so a collector never branches on which SDK produced one. Both are checked against [baton-spec](https://github.com/good-timing/baton-spec), a neutral schema repo: every event type is validated against the shared JSON Schema, and this package's emitter is diffed field-by-field against captured Python output for the same scenario.
|
|
@@ -281,8 +333,8 @@ Keeping that submodule current is load-bearing for contributors: a stale pin mak
|
|
|
281
333
|
| | |
|
|
282
334
|
|---|---|
|
|
283
335
|
| [goodtiming.ai/docs.html#typescript](https://goodtiming.ai/docs.html#typescript) | The docs: configuration, what it captures, the Console |
|
|
284
|
-
| [`
|
|
285
|
-
| [`
|
|
336
|
+
| [`SPEC.md`](https://github.com/good-timing/baton-spec/blob/main/SPEC.md) | The wire protocol, in `baton-spec`. Applies here too |
|
|
337
|
+
| [`baton`'s design rules](https://github.com/good-timing/baton/blob/main/AGENTS.md#design-rules) | Why the SDK is thin. Read before architectural changes |
|
|
286
338
|
| [`CHANGELOG.md`](https://github.com/good-timing/baton-ts/blob/main/CHANGELOG.md) | What has shipped |
|
|
287
339
|
|
|
288
340
|
Apache-2.0.
|