@openwop/openwop 1.1.1 → 1.1.3

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 (46) hide show
  1. package/README.md +4 -0
  2. package/dist/client.d.ts +80 -1
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +186 -0
  5. package/dist/client.js.map +1 -1
  6. package/dist/cost-attribution.d.ts +49 -0
  7. package/dist/cost-attribution.d.ts.map +1 -0
  8. package/dist/cost-attribution.js +65 -0
  9. package/dist/cost-attribution.js.map +1 -0
  10. package/dist/envelope-directive.d.ts +77 -0
  11. package/dist/envelope-directive.d.ts.map +1 -0
  12. package/dist/envelope-directive.js +89 -0
  13. package/dist/envelope-directive.js.map +1 -0
  14. package/dist/event-helpers.d.ts +95 -0
  15. package/dist/event-helpers.d.ts.map +1 -0
  16. package/dist/event-helpers.js +160 -0
  17. package/dist/event-helpers.js.map +1 -0
  18. package/dist/index.d.ts +14 -1
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +34 -0
  21. package/dist/index.js.map +1 -1
  22. package/dist/parse-refusal.d.ts +114 -0
  23. package/dist/parse-refusal.d.ts.map +1 -0
  24. package/dist/parse-refusal.js +216 -0
  25. package/dist/parse-refusal.js.map +1 -0
  26. package/dist/registry-helpers.d.ts +118 -0
  27. package/dist/registry-helpers.d.ts.map +1 -0
  28. package/dist/registry-helpers.js +82 -0
  29. package/dist/registry-helpers.js.map +1 -0
  30. package/dist/types.d.ts +376 -1
  31. package/dist/types.d.ts.map +1 -1
  32. package/dist/types.js.map +1 -1
  33. package/dist/webhook-helpers.d.ts +73 -0
  34. package/dist/webhook-helpers.d.ts.map +1 -0
  35. package/dist/webhook-helpers.js +97 -0
  36. package/dist/webhook-helpers.js.map +1 -0
  37. package/package.json +1 -1
  38. package/src/client.ts +218 -0
  39. package/src/cost-attribution.ts +72 -0
  40. package/src/envelope-directive.ts +110 -0
  41. package/src/event-helpers.ts +238 -0
  42. package/src/index.ts +117 -0
  43. package/src/parse-refusal.ts +311 -0
  44. package/src/registry-helpers.ts +173 -0
  45. package/src/types.ts +424 -0
  46. package/src/webhook-helpers.ts +131 -0
package/README.md CHANGED
@@ -84,10 +84,14 @@ npx tsc --noEmit # typecheck the SDK source
84
84
  | `GET /v1/runs/{id}/events` (SSE) | `client.runs.events(id, opts?)` (async iterable) |
85
85
  | `GET /v1/runs/{id}/events/poll` | `client.runs.pollEvents(id, opts?)` |
86
86
  | `POST /v1/runs/{id}/cancel` | `client.runs.cancel(id, body?)` |
87
+ | `POST /v1/runs:bulk-cancel` | `client.runs.bulkCancel(body, opts?)` |
88
+ | `POST /v1/runs/{id}:pause` | `client.runs.pause(id, body?, opts?)` |
89
+ | `POST /v1/runs/{id}:resume` | `client.runs.resume(id, body?, opts?)` |
87
90
  | `POST /v1/runs/{id}:fork` | `client.runs.fork(id, body)` |
88
91
  | `POST /v1/runs/{id}/interrupts/{nodeId}` | `client.interrupts.resolveByRun(id, nodeId, body)` |
89
92
  | `GET /v1/interrupts/{token}` | `client.interrupts.inspectByToken(token)` |
90
93
  | `POST /v1/interrupts/{token}` | `client.interrupts.resolveByToken(token, body)` |
94
+ | `GET /v1/audit/verify` | `client.audit.verify(fromSeq, toSeq)` |
91
95
 
92
96
  **Idempotency-Key** is supported via the `idempotencyKey` option on every mutation method.
93
97
 
package/dist/client.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  * ../../auth.md for credential format.
9
9
  */
10
10
  import { type EventsStreamOptions } from './sse.js';
11
- import { type AuditVerifyResult, type BulkCancelRunsRequest, type BulkCancelRunsResponse, type Capabilities, type CancelRunRequest, type CancelRunResponse, type CreateRunRequest, type CreateRunResponse, type ForkRunRequest, type ForkRunResponse, type InterruptByTokenInspection, type PollEventsResponse, type ResolveInterruptByTokenResponse, type ResolveInterruptRequest, type ResolveInterruptResponse, type RunEventDoc, type RunSnapshot } from './types.js';
11
+ import { type AuditVerifyResult, type BulkCancelRunsRequest, type BulkCancelRunsResponse, type Capabilities, type CancelRunRequest, type CancelRunResponse, type CreateRunRequest, type CreateRunResponse, type ForkRunRequest, type ForkRunResponse, type GetPromptRequest, type InterruptByTokenInspection, type DebugBundle, type DebugBundleOptions, type ListPromptsRequest, type ListPromptsResponse, type PromptTemplate, type RegisterWebhookRequest, type RegisterWebhookResponse, type PauseRunRequest, type PauseRunResponse, type PollEventsResponse, type RenderPromptRequest, type RenderPromptResponse, type ResolveInterruptByTokenResponse, type ResolveInterruptRequest, type ResolveInterruptResponse, type ResumeRunRequest, type ResumeRunResponse, type RunEventDoc, type RunSnapshot } from './types.js';
12
12
  export interface OpenwopClientOptions {
13
13
  /** Base URL of the openwop server, e.g., `https://api.example.com`. Trailing slash optional. */
14
14
  readonly baseUrl: string;
@@ -38,7 +38,22 @@ export declare class OpenwopClient {
38
38
  readonly runs: {
39
39
  create: (body: CreateRunRequest, opts?: MutationOptions) => Promise<CreateRunResponse>;
40
40
  get: (runId: string) => Promise<RunSnapshot>;
41
+ /**
42
+ * Fetch the portable JSON diagnostic export for a single run per
43
+ * `spec/v1/debug-bundle.md`. The bundle's `redactionMode` reflects
44
+ * the host's advertised `capabilities.compliance.defaultMode`; the
45
+ * caller MUST treat masked/omitted/hashed fields as the
46
+ * spec-canonical value. The `truncated` + `truncatedReason` fields
47
+ * indicate the host hit its size cap.
48
+ *
49
+ * Returns `null` when the host doesn't advertise
50
+ * `capabilities.debugBundle.supported: true` (the endpoint returns
51
+ * 404 in that case per `debug-bundle.md` §"Authorization").
52
+ */
53
+ debugBundle: (runId: string, opts?: DebugBundleOptions) => Promise<DebugBundle | null>;
41
54
  cancel: (runId: string, body?: CancelRunRequest, opts?: MutationOptions) => Promise<CancelRunResponse>;
55
+ pause: (runId: string, body?: PauseRunRequest, opts?: MutationOptions) => Promise<PauseRunResponse>;
56
+ resume: (runId: string, body?: ResumeRunRequest, opts?: MutationOptions) => Promise<ResumeRunResponse>;
42
57
  /**
43
58
  * Bulk-cancel a set of in-flight runs in a single request per
44
59
  * `rest-endpoints.md` §"POST /v1/runs:bulk-cancel" (closes R1).
@@ -78,6 +93,70 @@ export declare class OpenwopClient {
78
93
  */
79
94
  resolveByToken: (token: string, body: ResolveInterruptRequest, opts?: MutationOptions) => Promise<ResolveInterruptByTokenResponse>;
80
95
  };
96
+ readonly webhooks: {
97
+ /**
98
+ * Register a webhook subscription. Server signs deliveries with
99
+ * HMAC-SHA256 over `${timestamp}.${rawBody}` using the
100
+ * registration-time secret per `spec/v1/webhooks.md` §"Signature
101
+ * recipe". The secret is returned ONCE in the response — store it
102
+ * server-side for verification; the host cannot recover it.
103
+ */
104
+ register: (body: RegisterWebhookRequest, opts?: MutationOptions) => Promise<RegisterWebhookResponse>;
105
+ /**
106
+ * Unregister a webhook subscription. Returns void on success;
107
+ * throws `WopError` with `subscription_not_found` on unknown
108
+ * subscriptionId.
109
+ */
110
+ unregister: (subscriptionId: string) => Promise<void>;
111
+ };
112
+ readonly prompts: {
113
+ /**
114
+ * List prompt templates available to the caller per RFC 0028 §A
115
+ * (operationId `listPromptTemplates`). Supports kind / tag / modelClass
116
+ * / source filters + opaque cursor pagination.
117
+ */
118
+ list: (req?: ListPromptsRequest) => Promise<ListPromptsResponse>;
119
+ /**
120
+ * Fetch a single PromptTemplate by id per RFC 0028 §A
121
+ * (operationId `getPromptTemplate`). Optionally pin a SemVer
122
+ * `version`; supply `libraryId` to disambiguate when multiple installed
123
+ * packs ship the same templateId.
124
+ */
125
+ get: (req: GetPromptRequest) => Promise<PromptTemplate>;
126
+ /**
127
+ * Render a PromptTemplate with supplied variable bindings per RFC 0028
128
+ * §A (operationId `renderPromptTemplate`). Returns composed body +
129
+ * sha256 hash + per-variable hashes. The deterministic-hash invariant
130
+ * (RFC 0028 §A) requires the `hash` to match what a matching
131
+ * `prompt.composed` event would carry at dispatch time. Does NOT
132
+ * dispatch an LLM call. Secret-source variable values MUST be supplied
133
+ * as `[REDACTED:<credentialRef>]` markers per
134
+ * SECURITY/threat-model-secret-leakage.md §SR-1.
135
+ */
136
+ render: (req: RenderPromptRequest) => Promise<RenderPromptResponse>;
137
+ /**
138
+ * Create a new user-source PromptTemplate per RFC 0028 §A
139
+ * (operationId `createPromptTemplate`). Mutating endpoint —
140
+ * requires `capabilities.prompts.mutableLibrary: true`. Supports
141
+ * `Idempotency-Key` per the standard `MutationOptions` pattern.
142
+ */
143
+ create: (template: PromptTemplate, opts?: MutationOptions) => Promise<void>;
144
+ /**
145
+ * Replace an existing user-source PromptTemplate per RFC 0028 §A
146
+ * (operationId `updatePromptTemplate`). Submitted SemVer MUST be
147
+ * strictly greater than stored. Mutating endpoint — requires
148
+ * `capabilities.prompts.mutableLibrary: true`. Pack-sourced and
149
+ * host-built-in templates are read-only (host returns 403).
150
+ */
151
+ update: (templateId: string, template: PromptTemplate, opts?: MutationOptions) => Promise<PromptTemplate>;
152
+ /**
153
+ * Delete a user-source PromptTemplate per RFC 0028 §A
154
+ * (operationId `deletePromptTemplate`). Mutating endpoint —
155
+ * requires `capabilities.prompts.mutableLibrary: true`. Pack-sourced
156
+ * and host-built-in templates are read-only (host returns 403).
157
+ */
158
+ delete: (templateId: string) => Promise<void>;
159
+ };
81
160
  readonly audit: {
82
161
  /**
83
162
  * Verify the audit-log hash chain over `[fromSeq, toSeq]` per
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAgB,KAAK,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EAEtB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,0BAA0B,EAC/B,KAAK,kBAAkB,EACvB,KAAK,+BAA+B,EACpC,KAA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AC,KAAK;QACZ;;;;;;;;;;WAUG;0BACe,MAAM,SAAS,MAAM,KAAG,OAAO,CAAC,iBAAiB,CAAC;MASpE;CAsEH"}
package/dist/client.js CHANGED
@@ -48,12 +48,53 @@ export class OpenwopClient {
48
48
  method: 'GET',
49
49
  path: `/v1/runs/${encodeURIComponent(runId)}`,
50
50
  }),
51
+ /**
52
+ * Fetch the portable JSON diagnostic export for a single run per
53
+ * `spec/v1/debug-bundle.md`. The bundle's `redactionMode` reflects
54
+ * the host's advertised `capabilities.compliance.defaultMode`; the
55
+ * caller MUST treat masked/omitted/hashed fields as the
56
+ * spec-canonical value. The `truncated` + `truncatedReason` fields
57
+ * indicate the host hit its size cap.
58
+ *
59
+ * Returns `null` when the host doesn't advertise
60
+ * `capabilities.debugBundle.supported: true` (the endpoint returns
61
+ * 404 in that case per `debug-bundle.md` §"Authorization").
62
+ */
63
+ debugBundle: async (runId, opts = {}) => {
64
+ const params = new URLSearchParams();
65
+ if (opts.maxEvents !== undefined)
66
+ params.set('maxEvents', String(opts.maxEvents));
67
+ const query = params.toString();
68
+ const path = `/v1/runs/${encodeURIComponent(runId)}/debug-bundle${query ? `?${query}` : ''}`;
69
+ try {
70
+ return await this.#request({ method: 'GET', path });
71
+ }
72
+ catch (err) {
73
+ // Host doesn't advertise the capability → 404. Surface as null so callers
74
+ // can branch on capability discovery without try/catch.
75
+ if (err instanceof Error && /\b404\b/.test(err.message))
76
+ return null;
77
+ throw err;
78
+ }
79
+ },
51
80
  cancel: (runId, body = {}, opts = {}) => this.#request({
52
81
  method: 'POST',
53
82
  path: `/v1/runs/${encodeURIComponent(runId)}/cancel`,
54
83
  body,
55
84
  headers: this.#mutationHeaders(opts),
56
85
  }),
86
+ pause: (runId, body = {}, opts = {}) => this.#request({
87
+ method: 'POST',
88
+ path: `/v1/runs/${encodeURIComponent(runId)}:pause`,
89
+ body,
90
+ headers: this.#mutationHeaders(opts),
91
+ }),
92
+ resume: (runId, body = {}, opts = {}) => this.#request({
93
+ method: 'POST',
94
+ path: `/v1/runs/${encodeURIComponent(runId)}:resume`,
95
+ body,
96
+ headers: this.#mutationHeaders(opts),
97
+ }),
57
98
  /**
58
99
  * Bulk-cancel a set of in-flight runs in a single request per
59
100
  * `rest-endpoints.md` §"POST /v1/runs:bulk-cancel" (closes R1).
@@ -127,6 +168,151 @@ export class OpenwopClient {
127
168
  headers: this.#mutationHeaders(opts),
128
169
  }, false),
129
170
  };
171
+ // ── Webhook subscriptions (per spec/v1/webhooks.md) ─────────────────────
172
+ webhooks = {
173
+ /**
174
+ * Register a webhook subscription. Server signs deliveries with
175
+ * HMAC-SHA256 over `${timestamp}.${rawBody}` using the
176
+ * registration-time secret per `spec/v1/webhooks.md` §"Signature
177
+ * recipe". The secret is returned ONCE in the response — store it
178
+ * server-side for verification; the host cannot recover it.
179
+ */
180
+ register: (body, opts = {}) => this.#request({
181
+ method: 'POST',
182
+ path: '/v1/webhooks',
183
+ body,
184
+ headers: this.#mutationHeaders(opts),
185
+ }),
186
+ /**
187
+ * Unregister a webhook subscription. Returns void on success;
188
+ * throws `WopError` with `subscription_not_found` on unknown
189
+ * subscriptionId.
190
+ */
191
+ unregister: async (subscriptionId) => {
192
+ await this.#request({
193
+ method: 'DELETE',
194
+ path: `/v1/webhooks/${encodeURIComponent(subscriptionId)}`,
195
+ });
196
+ },
197
+ };
198
+ // ── Prompt library (RFC 0028; gated on capabilities.prompts.*) ──
199
+ //
200
+ // Read endpoints (list, get, render) gate on
201
+ // `capabilities.prompts.endpointsSupported: true`. Mutating endpoints
202
+ // (create, update, delete) additionally require
203
+ // `capabilities.prompts.mutableLibrary: true`. Hosts that don't advertise
204
+ // the relevant capability return `501 capability_not_provided`; the SDK
205
+ // surfaces that as a `WopError`. Clients SHOULD pre-flight via
206
+ // `getCapabilities()` before calling.
207
+ //
208
+ // NOTE: `capabilities.prompts.supported: true` (without
209
+ // `endpointsSupported: true`) ONLY gates node-execution PromptRef
210
+ // resolution per RFC 0027 Phase A; it does NOT imply these endpoints are
211
+ // available. See spec/v1/prompts.md §"Capability advertisement" for the
212
+ // two-axis gating split.
213
+ prompts = {
214
+ /**
215
+ * List prompt templates available to the caller per RFC 0028 §A
216
+ * (operationId `listPromptTemplates`). Supports kind / tag / modelClass
217
+ * / source filters + opaque cursor pagination.
218
+ */
219
+ list: (req = {}) => {
220
+ const search = new URLSearchParams();
221
+ if (req.kind)
222
+ search.set('kind', req.kind);
223
+ if (req.tag)
224
+ search.set('tag', req.tag);
225
+ if (req.modelClass)
226
+ search.set('modelClass', req.modelClass);
227
+ if (req.source)
228
+ search.set('source', req.source);
229
+ if (req.cursor)
230
+ search.set('cursor', req.cursor);
231
+ if (req.limit !== undefined)
232
+ search.set('limit', String(req.limit));
233
+ const query = search.toString();
234
+ return this.#request({
235
+ method: 'GET',
236
+ path: `/v1/prompts${query ? `?${query}` : ''}`,
237
+ });
238
+ },
239
+ /**
240
+ * Fetch a single PromptTemplate by id per RFC 0028 §A
241
+ * (operationId `getPromptTemplate`). Optionally pin a SemVer
242
+ * `version`; supply `libraryId` to disambiguate when multiple installed
243
+ * packs ship the same templateId.
244
+ */
245
+ get: (req) => {
246
+ const search = new URLSearchParams();
247
+ if (req.version)
248
+ search.set('version', req.version);
249
+ if (req.libraryId)
250
+ search.set('libraryId', req.libraryId);
251
+ const query = search.toString();
252
+ return this.#request({
253
+ method: 'GET',
254
+ path: `/v1/prompts/${encodeURIComponent(req.templateId)}${query ? `?${query}` : ''}`,
255
+ });
256
+ },
257
+ /**
258
+ * Render a PromptTemplate with supplied variable bindings per RFC 0028
259
+ * §A (operationId `renderPromptTemplate`). Returns composed body +
260
+ * sha256 hash + per-variable hashes. The deterministic-hash invariant
261
+ * (RFC 0028 §A) requires the `hash` to match what a matching
262
+ * `prompt.composed` event would carry at dispatch time. Does NOT
263
+ * dispatch an LLM call. Secret-source variable values MUST be supplied
264
+ * as `[REDACTED:<credentialRef>]` markers per
265
+ * SECURITY/threat-model-secret-leakage.md §SR-1.
266
+ */
267
+ render: (req) => {
268
+ return this.#request({
269
+ method: 'POST',
270
+ path: '/v1/prompts:render',
271
+ body: req,
272
+ });
273
+ },
274
+ /**
275
+ * Create a new user-source PromptTemplate per RFC 0028 §A
276
+ * (operationId `createPromptTemplate`). Mutating endpoint —
277
+ * requires `capabilities.prompts.mutableLibrary: true`. Supports
278
+ * `Idempotency-Key` per the standard `MutationOptions` pattern.
279
+ */
280
+ create: (template, opts = {}) => {
281
+ return this.#request({
282
+ method: 'POST',
283
+ path: '/v1/prompts',
284
+ body: template,
285
+ headers: this.#mutationHeaders(opts),
286
+ });
287
+ },
288
+ /**
289
+ * Replace an existing user-source PromptTemplate per RFC 0028 §A
290
+ * (operationId `updatePromptTemplate`). Submitted SemVer MUST be
291
+ * strictly greater than stored. Mutating endpoint — requires
292
+ * `capabilities.prompts.mutableLibrary: true`. Pack-sourced and
293
+ * host-built-in templates are read-only (host returns 403).
294
+ */
295
+ update: (templateId, template, opts = {}) => {
296
+ return this.#request({
297
+ method: 'PUT',
298
+ path: `/v1/prompts/${encodeURIComponent(templateId)}`,
299
+ body: template,
300
+ headers: this.#mutationHeaders(opts),
301
+ });
302
+ },
303
+ /**
304
+ * Delete a user-source PromptTemplate per RFC 0028 §A
305
+ * (operationId `deletePromptTemplate`). Mutating endpoint —
306
+ * requires `capabilities.prompts.mutableLibrary: true`. Pack-sourced
307
+ * and host-built-in templates are read-only (host returns 403).
308
+ */
309
+ delete: (templateId) => {
310
+ return this.#request({
311
+ method: 'DELETE',
312
+ path: `/v1/prompts/${encodeURIComponent(templateId)}`,
313
+ });
314
+ },
315
+ };
130
316
  // ── Audit-log integrity (gated on openwop-audit-log-integrity profile) ──
131
317
  audit = {
132
318
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAA4B,MAAM,UAAU,CAAC;AAClE,OAAO,EACL,QAAQ,GAmBT,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AAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,IAAI,MAAM,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC;oBACrF,GAAG,GAAG,MAAuB,CAAC;gBAChC,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,qCAAqC;YACvC,CAAC;YACD,MAAM,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;QACzD,CAAC;QAED,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,SAAc,CAAC;QAC7C,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAM,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,QAAQ,CAChB,GAAG,CAAC,MAAM,EACV,IAAI,EACJ;gBACE,KAAK,EAAE,cAAc;gBACrB,OAAO,EAAE,kDAAkD;aAC5D,EACD,WAAW,CACZ,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Cost-attribution allowlist + sanitizer helpers
3
+ * (`spec/v1/observability.md §"Cost attribution attributes"`).
4
+ *
5
+ * The spec MUSTs that hosts emitting `openwop.cost.*` OTel span attrs
6
+ * route them through an allowlist sanitizer that drops any attribute
7
+ * name outside the canonical set AND any non-primitive value. The
8
+ * `cost-attribution-allowlist-redaction` SECURITY invariant + the
9
+ * `cost-attribution.test.ts` conformance scenario are the public test
10
+ * surface; this module is the SDK-side helper that independent hosts
11
+ * (TypeScript / Python / Go) can share so the allowlist has a single
12
+ * source of truth instead of being re-derived in each runtime.
13
+ *
14
+ * Why this lives in the SDK and not just the conformance suite:
15
+ * implementations need the allowlist at HOST EMIT TIME (before spans
16
+ * are written). Importing from `@openwop/openwop` keeps the runtime
17
+ * + the conformance assertion in lockstep — if a future RFC adds an
18
+ * eighth attribute, one PR updates the constant and both surfaces
19
+ * pick it up.
20
+ *
21
+ * @see spec/v1/observability.md §"Cost attribution attributes"
22
+ * @see SECURITY/invariants.yaml row `cost-attribution-allowlist-redaction`
23
+ * @see conformance/src/scenarios/cost-attribution.test.ts
24
+ */
25
+ /** Canonical allowlist of cost-attribute names. Mutating this list is
26
+ * a wire-shape change — needs an RFC. */
27
+ export declare const OPENWOP_COST_ATTRIBUTE_NAMES: readonly ["openwop.cost.tokens.input", "openwop.cost.tokens.output", "openwop.cost.tokens.total", "openwop.cost.usd", "openwop.cost.currency", "openwop.cost.estimated", "openwop.cost.provider"];
28
+ /** Union of the canonical attribute names. Useful for typed
29
+ * sanitizer outputs in callers that pin the shape. */
30
+ export type OpenwopCostAttributeName = (typeof OPENWOP_COST_ATTRIBUTE_NAMES)[number];
31
+ /** Pure-function sanitizer. Returns a NEW object containing only
32
+ * allowlisted keys with primitive-typed values (number / string /
33
+ * boolean). Drops anything else — non-allowlisted keys, nested
34
+ * objects, arrays, functions, symbols, null, undefined.
35
+ *
36
+ * Callers SHOULD invoke this immediately before writing cost attrs
37
+ * to an OTel span:
38
+ *
39
+ * ```ts
40
+ * import { sanitizeCostAttributes } from '@openwop/openwop';
41
+ * for (const [k, v] of Object.entries(sanitizeCostAttributes(rawAttrs))) {
42
+ * span.setAttribute(k, v);
43
+ * }
44
+ * ```
45
+ *
46
+ * The reference workflow-engine host wires this via
47
+ * `apps/workflow-engine/backend/typescript/src/observability/costEmitter.ts`. */
48
+ export declare function sanitizeCostAttributes(input: Record<string, unknown>): Record<string, number | string | boolean>;
49
+ //# sourceMappingURL=cost-attribution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cost-attribution.d.ts","sourceRoot":"","sources":["../src/cost-attribution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH;0CAC0C;AAC1C,eAAO,MAAM,4BAA4B,mMAQ/B,CAAC;AAEX;uDACuD;AACvD,MAAM,MAAM,wBAAwB,GAAG,CAAC,OAAO,4BAA4B,CAAC,CAAC,MAAM,CAAC,CAAC;AAIrF;;;;;;;;;;;;;;;;kFAgBkF;AAClF,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAS3C"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Cost-attribution allowlist + sanitizer helpers
3
+ * (`spec/v1/observability.md §"Cost attribution attributes"`).
4
+ *
5
+ * The spec MUSTs that hosts emitting `openwop.cost.*` OTel span attrs
6
+ * route them through an allowlist sanitizer that drops any attribute
7
+ * name outside the canonical set AND any non-primitive value. The
8
+ * `cost-attribution-allowlist-redaction` SECURITY invariant + the
9
+ * `cost-attribution.test.ts` conformance scenario are the public test
10
+ * surface; this module is the SDK-side helper that independent hosts
11
+ * (TypeScript / Python / Go) can share so the allowlist has a single
12
+ * source of truth instead of being re-derived in each runtime.
13
+ *
14
+ * Why this lives in the SDK and not just the conformance suite:
15
+ * implementations need the allowlist at HOST EMIT TIME (before spans
16
+ * are written). Importing from `@openwop/openwop` keeps the runtime
17
+ * + the conformance assertion in lockstep — if a future RFC adds an
18
+ * eighth attribute, one PR updates the constant and both surfaces
19
+ * pick it up.
20
+ *
21
+ * @see spec/v1/observability.md §"Cost attribution attributes"
22
+ * @see SECURITY/invariants.yaml row `cost-attribution-allowlist-redaction`
23
+ * @see conformance/src/scenarios/cost-attribution.test.ts
24
+ */
25
+ /** Canonical allowlist of cost-attribute names. Mutating this list is
26
+ * a wire-shape change — needs an RFC. */
27
+ export const OPENWOP_COST_ATTRIBUTE_NAMES = [
28
+ 'openwop.cost.tokens.input',
29
+ 'openwop.cost.tokens.output',
30
+ 'openwop.cost.tokens.total',
31
+ 'openwop.cost.usd',
32
+ 'openwop.cost.currency',
33
+ 'openwop.cost.estimated',
34
+ 'openwop.cost.provider',
35
+ ];
36
+ const ALLOWLIST = new Set(OPENWOP_COST_ATTRIBUTE_NAMES);
37
+ /** Pure-function sanitizer. Returns a NEW object containing only
38
+ * allowlisted keys with primitive-typed values (number / string /
39
+ * boolean). Drops anything else — non-allowlisted keys, nested
40
+ * objects, arrays, functions, symbols, null, undefined.
41
+ *
42
+ * Callers SHOULD invoke this immediately before writing cost attrs
43
+ * to an OTel span:
44
+ *
45
+ * ```ts
46
+ * import { sanitizeCostAttributes } from '@openwop/openwop';
47
+ * for (const [k, v] of Object.entries(sanitizeCostAttributes(rawAttrs))) {
48
+ * span.setAttribute(k, v);
49
+ * }
50
+ * ```
51
+ *
52
+ * The reference workflow-engine host wires this via
53
+ * `apps/workflow-engine/backend/typescript/src/observability/costEmitter.ts`. */
54
+ export function sanitizeCostAttributes(input) {
55
+ const out = {};
56
+ for (const [key, value] of Object.entries(input)) {
57
+ if (!ALLOWLIST.has(key))
58
+ continue;
59
+ if (typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean') {
60
+ out[key] = value;
61
+ }
62
+ }
63
+ return out;
64
+ }
65
+ //# sourceMappingURL=cost-attribution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cost-attribution.js","sourceRoot":"","sources":["../src/cost-attribution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH;0CAC0C;AAC1C,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC1C,2BAA2B;IAC3B,4BAA4B;IAC5B,2BAA2B;IAC3B,kBAAkB;IAClB,uBAAuB;IACvB,wBAAwB;IACxB,uBAAuB;CACf,CAAC;AAMX,MAAM,SAAS,GAAwB,IAAI,GAAG,CAAS,4BAA4B,CAAC,CAAC;AAErF;;;;;;;;;;;;;;;;kFAgBkF;AAClF,MAAM,UAAU,sBAAsB,CACpC,KAA8B;IAE9B,MAAM,GAAG,GAA8C,EAAE,CAAC;IAC1D,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,SAAS;QAClC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;YACzF,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACnB,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * envelopeDirective — RFC 0030 §A `reasoning`-field prompt directive synthesis.
3
+ *
4
+ * Hosts that advertise `capabilities.envelopes.reasoning.supported: true`
5
+ * with `promptDirective: "advisory"` or `"mandatory"` inject a system-prompt
6
+ * directive instructing the model to populate the OPTIONAL `reasoning` field
7
+ * on envelope payload schemas that carry it. The directive is informational
8
+ * — hosts MUST NOT reject envelopes where `reasoning` is absent regardless
9
+ * of `promptDirective` strength (RFC 0030 §A).
10
+ *
11
+ * The directive fires only when the envelope's `responseSchema` declares a
12
+ * top-level `reasoning` property. Schemas without `reasoning` (e.g.,
13
+ * `schema.response` per RFC 0030 §A) do NOT receive the directive.
14
+ *
15
+ * Honest separation of concerns:
16
+ * - This module decides WHEN to inject (schema has `reasoning`).
17
+ * - The caller decides WHETHER to inject (read `promptDirective` from
18
+ * the host's discovery advertisement).
19
+ * - The model decides whether to ACTUALLY populate the field (the spec
20
+ * forbids rejecting envelopes where `reasoning` is absent).
21
+ *
22
+ * **Operational note on `"mandatory"`** (per RFC 0030 §A 2026-05-21
23
+ * amendment). Strict-output models may honor the mandatory wording
24
+ * literally and refuse mid-emission when reasoning would be vacuous.
25
+ * Hosts SHOULD prefer `"advisory"` unless empirical testing against the
26
+ * active model class confirms `"mandatory"` doesn't trigger refusals.
27
+ *
28
+ * @see RFCS/0030-envelope-reasoning-and-tier-one-subset.md §A
29
+ * @see spec/v1/ai-envelope.md §"Reasoning field (normative)"
30
+ */
31
+ /**
32
+ * The strength of the host's `reasoning`-directive prompt injection.
33
+ *
34
+ * `"off"` — no directive injected. Caller skips this module entirely.
35
+ * `"advisory"` — directive is suggestive ("populate `reasoning` with your
36
+ * analytical process if the schema permits it"). The
37
+ * spec-recommended default per RFC 0030 §C.
38
+ * `"mandatory"` — directive is firm ("you MUST populate `reasoning` before
39
+ * emitting the structured fields"). Hosts SHOULD prefer
40
+ * `"advisory"` unless model-class-specific testing shows
41
+ * `"mandatory"` is safe.
42
+ *
43
+ * Both `"advisory"` and `"mandatory"` are prompt-injection postures, NOT
44
+ * wire-level refusal contracts — the host accepts envelopes regardless of
45
+ * whether `reasoning` is populated (RFC 0030 §A normative MUST NOT).
46
+ */
47
+ export type ReasoningDirectiveStrength = 'off' | 'advisory' | 'mandatory';
48
+ /**
49
+ * Build the directive string to append to the system prompt, OR `null` if
50
+ * the schema does not declare a top-level `reasoning` property.
51
+ *
52
+ * Callers append the returned string to the existing system prompt with a
53
+ * separating newline. When `strength === 'off'`, callers SHOULD short-circuit
54
+ * before invoking this helper (returning `null` here is treated as "no
55
+ * applicable schema," not "directive disabled").
56
+ *
57
+ * The helper inspects only the top-level `properties.reasoning` slot.
58
+ * Nested `reasoning` fields (e.g., inside an `anyOf` branch's payload) are
59
+ * not auto-detected — vendor-kind authors who want per-branch directives
60
+ * synthesize their own.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * import { buildReasoningDirective } from '@openwop/openwop';
65
+ *
66
+ * const directive = buildReasoningDirective(
67
+ * { type: 'object', properties: { reasoning: { type: 'string' }, ... } },
68
+ * 'advisory',
69
+ * );
70
+ * // directive is a string ~80 words; null when schema lacks `reasoning`
71
+ * const systemPrompt = [originalSystemPrompt, schemaHint, directive]
72
+ * .filter((s): s is string => Boolean(s))
73
+ * .join('\n\n');
74
+ * ```
75
+ */
76
+ export declare function buildReasoningDirective(responseSchema: unknown, strength: ReasoningDirectiveStrength): string | null;
77
+ //# sourceMappingURL=envelope-directive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope-directive.d.ts","sourceRoot":"","sources":["../src/envelope-directive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,0BAA0B,GAAG,KAAK,GAAG,UAAU,GAAG,WAAW,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,OAAO,EACvB,QAAQ,EAAE,0BAA0B,GACnC,MAAM,GAAG,IAAI,CA6Bf"}