risicare 0.3.0 → 0.4.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 (42) hide show
  1. package/README.md +26 -10
  2. package/dist/frameworks/instructor.cjs.map +1 -1
  3. package/dist/frameworks/instructor.js.map +1 -1
  4. package/dist/frameworks/langchain.cjs.map +1 -1
  5. package/dist/frameworks/langchain.js.map +1 -1
  6. package/dist/frameworks/langgraph.cjs.map +1 -1
  7. package/dist/frameworks/langgraph.js.map +1 -1
  8. package/dist/frameworks/llamaindex.cjs.map +1 -1
  9. package/dist/frameworks/llamaindex.js.map +1 -1
  10. package/dist/index.cjs +212 -8
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +162 -6
  13. package/dist/index.d.ts +162 -6
  14. package/dist/index.js +209 -8
  15. package/dist/index.js.map +1 -1
  16. package/dist/providers/anthropic/index.cjs.map +1 -1
  17. package/dist/providers/anthropic/index.js.map +1 -1
  18. package/dist/providers/bedrock/index.cjs.map +1 -1
  19. package/dist/providers/bedrock/index.js.map +1 -1
  20. package/dist/providers/cerebras/index.cjs.map +1 -1
  21. package/dist/providers/cerebras/index.js.map +1 -1
  22. package/dist/providers/cohere/index.cjs.map +1 -1
  23. package/dist/providers/cohere/index.js.map +1 -1
  24. package/dist/providers/google/index.cjs.map +1 -1
  25. package/dist/providers/google/index.js.map +1 -1
  26. package/dist/providers/groq/index.cjs.map +1 -1
  27. package/dist/providers/groq/index.js.map +1 -1
  28. package/dist/providers/huggingface/index.cjs.map +1 -1
  29. package/dist/providers/huggingface/index.js.map +1 -1
  30. package/dist/providers/mistral/index.cjs.map +1 -1
  31. package/dist/providers/mistral/index.js.map +1 -1
  32. package/dist/providers/ollama/index.cjs.map +1 -1
  33. package/dist/providers/ollama/index.js.map +1 -1
  34. package/dist/providers/openai/index.cjs +16 -1327
  35. package/dist/providers/openai/index.cjs.map +1 -1
  36. package/dist/providers/openai/index.js +16 -1343
  37. package/dist/providers/openai/index.js.map +1 -1
  38. package/dist/providers/together/index.cjs.map +1 -1
  39. package/dist/providers/together/index.js.map +1 -1
  40. package/dist/providers/vercel-ai/index.cjs.map +1 -1
  41. package/dist/providers/vercel-ai/index.js.map +1 -1
  42. package/package.json +5 -4
package/dist/index.d.cts CHANGED
@@ -371,7 +371,7 @@ declare function getMetrics(): {
371
371
  queueUtilization: number;
372
372
  };
373
373
  /**
374
- * Report a caught exception to the self-healing pipeline.
374
+ * Report a caught exception to the error diagnosis pipeline.
375
375
  *
376
376
  * Creates an error span that triggers diagnosis and fix generation.
377
377
  * Deduplicates identical errors within a 5-minute window (SHA256 fingerprint).
@@ -430,6 +430,17 @@ declare function withAgent<T>(options: AgentOptions, fn: () => T): T;
430
430
  * Wraps a function to execute within an agent context. All spans created
431
431
  * inside will be tagged with the agent's identity.
432
432
  *
433
+ * Two equivalent calling forms are supported:
434
+ *
435
+ * // 2-arg form
436
+ * const research = agent({ name: 'researcher' }, async (q) => { ... });
437
+ *
438
+ * // Curried form (decorator factory)
439
+ * const research = agent({ name: 'researcher' })(async (q) => { ... });
440
+ *
441
+ * Both return a wrapped function — call it to actually run the body inside
442
+ * the agent context.
443
+ *
433
444
  * @example
434
445
  * const research = agent({ name: 'researcher', role: 'worker' }, async (query: string) => {
435
446
  * const result = await openai.chat.completions.create({ ... });
@@ -439,10 +450,8 @@ declare function withAgent<T>(options: AgentOptions, fn: () => T): T;
439
450
  * const answer = await research('What is quantum computing?');
440
451
  */
441
452
 
442
- /**
443
- * Wrap a function with agent context and an automatic span.
444
- */
445
453
  declare function agent<TArgs extends unknown[], TReturn>(options: AgentOptions, fn: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
454
+ declare function agent(options: AgentOptions): <TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => TReturn) => (...args: TArgs) => TReturn;
446
455
 
447
456
  /**
448
457
  * Session context — groups multiple traces from the same user interaction.
@@ -483,10 +492,19 @@ declare function withSession<T>(options: SessionOptions, fn: () => T): T;
483
492
  /**
484
493
  * Wrap a function with session context.
485
494
  *
495
+ * Two equivalent calling forms are supported (F-54 ergonomics):
496
+ *
497
+ * // 2-arg form
498
+ * const handle = session({ sessionId: 's1' }, async (req) => { ... });
499
+ *
500
+ * // Curried form (decorator factory)
501
+ * const handle = session({ sessionId: 's1' })(async (req) => { ... });
502
+ *
486
503
  * @param optionsOrResolver - Static session options, or a function that derives them from args
487
- * @param fn - The function to wrap
504
+ * @param fn - The function to wrap. If omitted, returns a decorator factory.
488
505
  */
489
506
  declare function session<TArgs extends unknown[], TReturn>(optionsOrResolver: SessionOptions | ((...args: TArgs) => SessionOptions), fn: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
507
+ declare function session<TArgs extends unknown[]>(optionsOrResolver: SessionOptions | ((...args: TArgs) => SessionOptions)): <TR>(fn: (...args: TArgs) => TR) => (...args: TArgs) => TR;
490
508
 
491
509
  /**
492
510
  * Phase decorators — decision phase tracking (Tier 4).
@@ -1163,4 +1181,142 @@ declare function initFixRuntime(config: FixRuntimeConfig): FixRuntime;
1163
1181
  */
1164
1182
  declare function shutdownFixRuntime(): void;
1165
1183
 
1166
- export { type ActiveFix, type AgentContext, type AgentOptions, AgentRole, type FixRuntimeConfig, MessageType, type RisicareConfig, SemanticPhase, type SessionContext, type SessionOptions, Span, SpanKind, type SpanOptions, SpanStatus, type StartSpanOptions, type TraceContext, type TracedStreamOptions, Tracer, agent, disable, enable, extractTraceContext, flush, getCurrentAgent, getCurrentAgentId, getCurrentContext, getCurrentPhase, getCurrentSession, getCurrentSessionId, getCurrentSpan, getCurrentSpanId, getCurrentTraceId, getFixRuntime, getMetrics, getSpanById, getTraceContent, getTraceContext, getTracer, init, initFixRuntime, injectTraceContext, isEnabled, isProviderInstrumentationSuppressed, registerSpan, reportError, score, session, shutdown, shutdownFixRuntime, suppressProviderInstrumentation, traceAct, traceCoordinate, traceDecide, traceDelegate, traceMessage, traceObserve, traceThink, tracedStream, unregisterSpan, withAgent, withPhase, withSession };
1184
+ /**
1185
+ * Webhook signature verification helpers (CON-195 / B-7, F-34).
1186
+ *
1187
+ * Customers receive Risicare webhooks at endpoints they configure. Each
1188
+ * delivery is signed by the sender (`packages/workers/src/workers/
1189
+ * webhook_dispatch.py`) with HMAC-SHA256 over `<timestamp>.<payload_bytes>`
1190
+ * using the per-webhook shared secret. The signature is delivered in the
1191
+ * `X-Risicare-Signature` header in Stripe-style format `t=<unix>,v1=<hex>`,
1192
+ * and the timestamp is also exposed verbatim as `X-Risicare-Timestamp`.
1193
+ *
1194
+ * This module is the TypeScript port of `risicare-sdk/src/risicare/
1195
+ * webhooks.py`. It enforces THREE checks (all must pass):
1196
+ *
1197
+ * 1. Header parsing — both headers must be present and well-formed.
1198
+ * 2. Time skew — `Math.abs(now - timestamp) <= toleranceS` (default
1199
+ * 5 minutes). This is what makes captured signed payloads
1200
+ * non-replayable past the tolerance window.
1201
+ * 3. HMAC equality — constant-time compare against a fresh signature
1202
+ * computed from the secret + the SAME timestamp + the raw body.
1203
+ *
1204
+ * Example (Express/Node receiver):
1205
+ *
1206
+ * import express from 'express';
1207
+ * import { verifyWebhookSignature, WebhookVerificationError } from 'risicare';
1208
+ *
1209
+ * const app = express();
1210
+ * // IMPORTANT: use raw body, not parsed JSON — the signature is
1211
+ * // over the EXACT bytes received; JSON re-serialization changes
1212
+ * // key ordering / whitespace and the signature will not match.
1213
+ * app.post('/risicare-webhook', express.raw({ type: '*\/*' }), (req, res) => {
1214
+ * try {
1215
+ * verifyWebhookSignature(req.body, req.headers, YOUR_WEBHOOK_SECRET);
1216
+ * } catch (e) {
1217
+ * if (e instanceof WebhookVerificationError) {
1218
+ * return res.status(401).send(e.message);
1219
+ * }
1220
+ * throw e;
1221
+ * }
1222
+ * // ... process the verified event ...
1223
+ * res.status(200).end();
1224
+ * });
1225
+ *
1226
+ * The helper is dependency-light (Node `crypto` stdlib only) so customers
1227
+ * can use it without pulling in the rest of the SDK if they only need
1228
+ * verification.
1229
+ *
1230
+ * Edge runtime note: this verifier is synchronous and uses Node's
1231
+ * `crypto.timingSafeEqual` + `crypto.createHmac`. It will not run in
1232
+ * Cloudflare Workers / Vercel Edge / Deno Deploy as-is. An async Web
1233
+ * Crypto variant can be added if customers request it.
1234
+ */
1235
+ /**
1236
+ * Default skew window (seconds). 5 minutes matches Stripe / GitHub /
1237
+ * common industry practice. Customers can override per-call if their
1238
+ * clock infrastructure warrants a tighter or looser bound.
1239
+ *
1240
+ * Mirrors `DEFAULT_TIMESTAMP_TOLERANCE_S` in the Python SDK.
1241
+ */
1242
+ declare const DEFAULT_TIMESTAMP_TOLERANCE_S = 300;
1243
+ /**
1244
+ * Raised when a webhook delivery fails any verification check.
1245
+ *
1246
+ * Customers should catch this specifically rather than a generic `Error`
1247
+ * so verification failures are not conflated with other input problems
1248
+ * (e.g. body-parsing errors at the framework layer).
1249
+ *
1250
+ * The `message` is safe to log — it never includes the secret, the
1251
+ * expected signature, or the computed signature.
1252
+ */
1253
+ declare class WebhookVerificationError extends Error {
1254
+ constructor(message: string);
1255
+ }
1256
+ /**
1257
+ * Options for `verifyWebhookSignature`. All fields are optional.
1258
+ */
1259
+ interface VerifyWebhookOptions {
1260
+ /**
1261
+ * Maximum clock-skew tolerance in seconds. Defaults to
1262
+ * `DEFAULT_TIMESTAMP_TOLERANCE_S` (300). Setting to 0 is supported
1263
+ * (strict same-second match) but discouraged in distributed
1264
+ * deployments.
1265
+ */
1266
+ toleranceS?: number;
1267
+ /**
1268
+ * Test hook — override "current time" in unix seconds.
1269
+ * Customers should not pass this.
1270
+ */
1271
+ _now?: number;
1272
+ }
1273
+ /**
1274
+ * Header-like inputs accepted by `verifyWebhookSignature`.
1275
+ *
1276
+ * Covers (a) Web API `Headers` (case-insensitive `.get`), (b) Node
1277
+ * `IncomingHttpHeaders` (plain object with lowercase keys, possibly
1278
+ * array-valued for multi-set headers), (c) `Map<string, string>`
1279
+ * (case-sensitive `.get`), and (d) plain `Record` (case-sensitive
1280
+ * property lookup, possibly array-valued).
1281
+ *
1282
+ * Lookup strategy: try the canonical mixed-case name first
1283
+ * (`X-Risicare-Signature`). If that returns undefined, fall back to the
1284
+ * lowercased form (`x-risicare-signature`). Mirrors the Python
1285
+ * `_get_header` helper.
1286
+ */
1287
+ type HeaderLookup = Headers | Map<string, string> | Record<string, string | string[] | undefined>;
1288
+ /**
1289
+ * Payload shapes accepted by `verifyWebhookSignature`.
1290
+ *
1291
+ * `Buffer extends Uint8Array` in Node, so callers passing `Buffer`
1292
+ * satisfy the `Uint8Array` arm. `ArrayBuffer` is explicitly accepted
1293
+ * for callers using Web-API request bodies. `string` is UTF-8 encoded
1294
+ * internally.
1295
+ *
1296
+ * Crucially, callers must pass the EXACT bytes received over the
1297
+ * wire. Parsing JSON and re-serializing changes byte order and
1298
+ * whitespace; the signature will not match.
1299
+ */
1300
+ type WebhookPayload = Uint8Array | ArrayBuffer | string;
1301
+ /**
1302
+ * Verify a Risicare webhook delivery. Throws `WebhookVerificationError`
1303
+ * on any failure; returns `undefined` on success.
1304
+ *
1305
+ * @param payload Raw request body bytes — the EXACT bytes received over
1306
+ * the wire. Re-serializing parsed JSON will change byte ordering and
1307
+ * break the signature.
1308
+ * @param headers Header lookup. Web `Headers`, `Map<string,string>`,
1309
+ * Node `IncomingHttpHeaders`, or plain `Record` all work. Lookup is
1310
+ * case-insensitive (canonical mixed-case tried first, then lowercase).
1311
+ * @param secret The shared secret configured on the Risicare webhook
1312
+ * record. Returned by `POST /v1/webhooks` once at create time.
1313
+ * @param opts Optional overrides — `toleranceS` (default 300) and
1314
+ * `_now` (test hook).
1315
+ *
1316
+ * @throws WebhookVerificationError on any of: missing headers, malformed
1317
+ * signature, timestamp outside tolerance, HMAC mismatch, or invalid
1318
+ * payload type.
1319
+ */
1320
+ declare function verifyWebhookSignature(payload: WebhookPayload, headers: HeaderLookup, secret: string, opts?: VerifyWebhookOptions): void;
1321
+
1322
+ export { type ActiveFix, type AgentContext, type AgentOptions, AgentRole, DEFAULT_TIMESTAMP_TOLERANCE_S, type FixRuntimeConfig, type HeaderLookup, MessageType, type RisicareConfig, SemanticPhase, type SessionContext, type SessionOptions, Span, SpanKind, type SpanOptions, SpanStatus, type StartSpanOptions, type TraceContext, type TracedStreamOptions, Tracer, type VerifyWebhookOptions, type WebhookPayload, WebhookVerificationError, agent, disable, enable, extractTraceContext, flush, getCurrentAgent, getCurrentAgentId, getCurrentContext, getCurrentPhase, getCurrentSession, getCurrentSessionId, getCurrentSpan, getCurrentSpanId, getCurrentTraceId, getFixRuntime, getMetrics, getSpanById, getTraceContent, getTraceContext, getTracer, init, initFixRuntime, injectTraceContext, isEnabled, isProviderInstrumentationSuppressed, registerSpan, reportError, score, session, shutdown, shutdownFixRuntime, suppressProviderInstrumentation, traceAct, traceCoordinate, traceDecide, traceDelegate, traceMessage, traceObserve, traceThink, tracedStream, unregisterSpan, verifyWebhookSignature, withAgent, withPhase, withSession };
package/dist/index.d.ts CHANGED
@@ -371,7 +371,7 @@ declare function getMetrics(): {
371
371
  queueUtilization: number;
372
372
  };
373
373
  /**
374
- * Report a caught exception to the self-healing pipeline.
374
+ * Report a caught exception to the error diagnosis pipeline.
375
375
  *
376
376
  * Creates an error span that triggers diagnosis and fix generation.
377
377
  * Deduplicates identical errors within a 5-minute window (SHA256 fingerprint).
@@ -430,6 +430,17 @@ declare function withAgent<T>(options: AgentOptions, fn: () => T): T;
430
430
  * Wraps a function to execute within an agent context. All spans created
431
431
  * inside will be tagged with the agent's identity.
432
432
  *
433
+ * Two equivalent calling forms are supported:
434
+ *
435
+ * // 2-arg form
436
+ * const research = agent({ name: 'researcher' }, async (q) => { ... });
437
+ *
438
+ * // Curried form (decorator factory)
439
+ * const research = agent({ name: 'researcher' })(async (q) => { ... });
440
+ *
441
+ * Both return a wrapped function — call it to actually run the body inside
442
+ * the agent context.
443
+ *
433
444
  * @example
434
445
  * const research = agent({ name: 'researcher', role: 'worker' }, async (query: string) => {
435
446
  * const result = await openai.chat.completions.create({ ... });
@@ -439,10 +450,8 @@ declare function withAgent<T>(options: AgentOptions, fn: () => T): T;
439
450
  * const answer = await research('What is quantum computing?');
440
451
  */
441
452
 
442
- /**
443
- * Wrap a function with agent context and an automatic span.
444
- */
445
453
  declare function agent<TArgs extends unknown[], TReturn>(options: AgentOptions, fn: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
454
+ declare function agent(options: AgentOptions): <TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => TReturn) => (...args: TArgs) => TReturn;
446
455
 
447
456
  /**
448
457
  * Session context — groups multiple traces from the same user interaction.
@@ -483,10 +492,19 @@ declare function withSession<T>(options: SessionOptions, fn: () => T): T;
483
492
  /**
484
493
  * Wrap a function with session context.
485
494
  *
495
+ * Two equivalent calling forms are supported (F-54 ergonomics):
496
+ *
497
+ * // 2-arg form
498
+ * const handle = session({ sessionId: 's1' }, async (req) => { ... });
499
+ *
500
+ * // Curried form (decorator factory)
501
+ * const handle = session({ sessionId: 's1' })(async (req) => { ... });
502
+ *
486
503
  * @param optionsOrResolver - Static session options, or a function that derives them from args
487
- * @param fn - The function to wrap
504
+ * @param fn - The function to wrap. If omitted, returns a decorator factory.
488
505
  */
489
506
  declare function session<TArgs extends unknown[], TReturn>(optionsOrResolver: SessionOptions | ((...args: TArgs) => SessionOptions), fn: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
507
+ declare function session<TArgs extends unknown[]>(optionsOrResolver: SessionOptions | ((...args: TArgs) => SessionOptions)): <TR>(fn: (...args: TArgs) => TR) => (...args: TArgs) => TR;
490
508
 
491
509
  /**
492
510
  * Phase decorators — decision phase tracking (Tier 4).
@@ -1163,4 +1181,142 @@ declare function initFixRuntime(config: FixRuntimeConfig): FixRuntime;
1163
1181
  */
1164
1182
  declare function shutdownFixRuntime(): void;
1165
1183
 
1166
- export { type ActiveFix, type AgentContext, type AgentOptions, AgentRole, type FixRuntimeConfig, MessageType, type RisicareConfig, SemanticPhase, type SessionContext, type SessionOptions, Span, SpanKind, type SpanOptions, SpanStatus, type StartSpanOptions, type TraceContext, type TracedStreamOptions, Tracer, agent, disable, enable, extractTraceContext, flush, getCurrentAgent, getCurrentAgentId, getCurrentContext, getCurrentPhase, getCurrentSession, getCurrentSessionId, getCurrentSpan, getCurrentSpanId, getCurrentTraceId, getFixRuntime, getMetrics, getSpanById, getTraceContent, getTraceContext, getTracer, init, initFixRuntime, injectTraceContext, isEnabled, isProviderInstrumentationSuppressed, registerSpan, reportError, score, session, shutdown, shutdownFixRuntime, suppressProviderInstrumentation, traceAct, traceCoordinate, traceDecide, traceDelegate, traceMessage, traceObserve, traceThink, tracedStream, unregisterSpan, withAgent, withPhase, withSession };
1184
+ /**
1185
+ * Webhook signature verification helpers (CON-195 / B-7, F-34).
1186
+ *
1187
+ * Customers receive Risicare webhooks at endpoints they configure. Each
1188
+ * delivery is signed by the sender (`packages/workers/src/workers/
1189
+ * webhook_dispatch.py`) with HMAC-SHA256 over `<timestamp>.<payload_bytes>`
1190
+ * using the per-webhook shared secret. The signature is delivered in the
1191
+ * `X-Risicare-Signature` header in Stripe-style format `t=<unix>,v1=<hex>`,
1192
+ * and the timestamp is also exposed verbatim as `X-Risicare-Timestamp`.
1193
+ *
1194
+ * This module is the TypeScript port of `risicare-sdk/src/risicare/
1195
+ * webhooks.py`. It enforces THREE checks (all must pass):
1196
+ *
1197
+ * 1. Header parsing — both headers must be present and well-formed.
1198
+ * 2. Time skew — `Math.abs(now - timestamp) <= toleranceS` (default
1199
+ * 5 minutes). This is what makes captured signed payloads
1200
+ * non-replayable past the tolerance window.
1201
+ * 3. HMAC equality — constant-time compare against a fresh signature
1202
+ * computed from the secret + the SAME timestamp + the raw body.
1203
+ *
1204
+ * Example (Express/Node receiver):
1205
+ *
1206
+ * import express from 'express';
1207
+ * import { verifyWebhookSignature, WebhookVerificationError } from 'risicare';
1208
+ *
1209
+ * const app = express();
1210
+ * // IMPORTANT: use raw body, not parsed JSON — the signature is
1211
+ * // over the EXACT bytes received; JSON re-serialization changes
1212
+ * // key ordering / whitespace and the signature will not match.
1213
+ * app.post('/risicare-webhook', express.raw({ type: '*\/*' }), (req, res) => {
1214
+ * try {
1215
+ * verifyWebhookSignature(req.body, req.headers, YOUR_WEBHOOK_SECRET);
1216
+ * } catch (e) {
1217
+ * if (e instanceof WebhookVerificationError) {
1218
+ * return res.status(401).send(e.message);
1219
+ * }
1220
+ * throw e;
1221
+ * }
1222
+ * // ... process the verified event ...
1223
+ * res.status(200).end();
1224
+ * });
1225
+ *
1226
+ * The helper is dependency-light (Node `crypto` stdlib only) so customers
1227
+ * can use it without pulling in the rest of the SDK if they only need
1228
+ * verification.
1229
+ *
1230
+ * Edge runtime note: this verifier is synchronous and uses Node's
1231
+ * `crypto.timingSafeEqual` + `crypto.createHmac`. It will not run in
1232
+ * Cloudflare Workers / Vercel Edge / Deno Deploy as-is. An async Web
1233
+ * Crypto variant can be added if customers request it.
1234
+ */
1235
+ /**
1236
+ * Default skew window (seconds). 5 minutes matches Stripe / GitHub /
1237
+ * common industry practice. Customers can override per-call if their
1238
+ * clock infrastructure warrants a tighter or looser bound.
1239
+ *
1240
+ * Mirrors `DEFAULT_TIMESTAMP_TOLERANCE_S` in the Python SDK.
1241
+ */
1242
+ declare const DEFAULT_TIMESTAMP_TOLERANCE_S = 300;
1243
+ /**
1244
+ * Raised when a webhook delivery fails any verification check.
1245
+ *
1246
+ * Customers should catch this specifically rather than a generic `Error`
1247
+ * so verification failures are not conflated with other input problems
1248
+ * (e.g. body-parsing errors at the framework layer).
1249
+ *
1250
+ * The `message` is safe to log — it never includes the secret, the
1251
+ * expected signature, or the computed signature.
1252
+ */
1253
+ declare class WebhookVerificationError extends Error {
1254
+ constructor(message: string);
1255
+ }
1256
+ /**
1257
+ * Options for `verifyWebhookSignature`. All fields are optional.
1258
+ */
1259
+ interface VerifyWebhookOptions {
1260
+ /**
1261
+ * Maximum clock-skew tolerance in seconds. Defaults to
1262
+ * `DEFAULT_TIMESTAMP_TOLERANCE_S` (300). Setting to 0 is supported
1263
+ * (strict same-second match) but discouraged in distributed
1264
+ * deployments.
1265
+ */
1266
+ toleranceS?: number;
1267
+ /**
1268
+ * Test hook — override "current time" in unix seconds.
1269
+ * Customers should not pass this.
1270
+ */
1271
+ _now?: number;
1272
+ }
1273
+ /**
1274
+ * Header-like inputs accepted by `verifyWebhookSignature`.
1275
+ *
1276
+ * Covers (a) Web API `Headers` (case-insensitive `.get`), (b) Node
1277
+ * `IncomingHttpHeaders` (plain object with lowercase keys, possibly
1278
+ * array-valued for multi-set headers), (c) `Map<string, string>`
1279
+ * (case-sensitive `.get`), and (d) plain `Record` (case-sensitive
1280
+ * property lookup, possibly array-valued).
1281
+ *
1282
+ * Lookup strategy: try the canonical mixed-case name first
1283
+ * (`X-Risicare-Signature`). If that returns undefined, fall back to the
1284
+ * lowercased form (`x-risicare-signature`). Mirrors the Python
1285
+ * `_get_header` helper.
1286
+ */
1287
+ type HeaderLookup = Headers | Map<string, string> | Record<string, string | string[] | undefined>;
1288
+ /**
1289
+ * Payload shapes accepted by `verifyWebhookSignature`.
1290
+ *
1291
+ * `Buffer extends Uint8Array` in Node, so callers passing `Buffer`
1292
+ * satisfy the `Uint8Array` arm. `ArrayBuffer` is explicitly accepted
1293
+ * for callers using Web-API request bodies. `string` is UTF-8 encoded
1294
+ * internally.
1295
+ *
1296
+ * Crucially, callers must pass the EXACT bytes received over the
1297
+ * wire. Parsing JSON and re-serializing changes byte order and
1298
+ * whitespace; the signature will not match.
1299
+ */
1300
+ type WebhookPayload = Uint8Array | ArrayBuffer | string;
1301
+ /**
1302
+ * Verify a Risicare webhook delivery. Throws `WebhookVerificationError`
1303
+ * on any failure; returns `undefined` on success.
1304
+ *
1305
+ * @param payload Raw request body bytes — the EXACT bytes received over
1306
+ * the wire. Re-serializing parsed JSON will change byte ordering and
1307
+ * break the signature.
1308
+ * @param headers Header lookup. Web `Headers`, `Map<string,string>`,
1309
+ * Node `IncomingHttpHeaders`, or plain `Record` all work. Lookup is
1310
+ * case-insensitive (canonical mixed-case tried first, then lowercase).
1311
+ * @param secret The shared secret configured on the Risicare webhook
1312
+ * record. Returned by `POST /v1/webhooks` once at create time.
1313
+ * @param opts Optional overrides — `toleranceS` (default 300) and
1314
+ * `_now` (test hook).
1315
+ *
1316
+ * @throws WebhookVerificationError on any of: missing headers, malformed
1317
+ * signature, timestamp outside tolerance, HMAC mismatch, or invalid
1318
+ * payload type.
1319
+ */
1320
+ declare function verifyWebhookSignature(payload: WebhookPayload, headers: HeaderLookup, secret: string, opts?: VerifyWebhookOptions): void;
1321
+
1322
+ export { type ActiveFix, type AgentContext, type AgentOptions, AgentRole, DEFAULT_TIMESTAMP_TOLERANCE_S, type FixRuntimeConfig, type HeaderLookup, MessageType, type RisicareConfig, SemanticPhase, type SessionContext, type SessionOptions, Span, SpanKind, type SpanOptions, SpanStatus, type StartSpanOptions, type TraceContext, type TracedStreamOptions, Tracer, type VerifyWebhookOptions, type WebhookPayload, WebhookVerificationError, agent, disable, enable, extractTraceContext, flush, getCurrentAgent, getCurrentAgentId, getCurrentContext, getCurrentPhase, getCurrentSession, getCurrentSessionId, getCurrentSpan, getCurrentSpanId, getCurrentTraceId, getFixRuntime, getMetrics, getSpanById, getTraceContent, getTraceContext, getTracer, init, initFixRuntime, injectTraceContext, isEnabled, isProviderInstrumentationSuppressed, registerSpan, reportError, score, session, shutdown, shutdownFixRuntime, suppressProviderInstrumentation, traceAct, traceCoordinate, traceDecide, traceDelegate, traceMessage, traceObserve, traceThink, tracedStream, unregisterSpan, verifyWebhookSignature, withAgent, withPhase, withSession };