@rivetkit/rivetkit-napi 2.3.18 → 2.3.20

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 (3) hide show
  1. package/index.d.ts +78 -0
  2. package/index.js +6 -1
  3. package/package.json +9 -9
package/index.d.ts CHANGED
@@ -8,6 +8,18 @@ export interface JsActorKeySegment {
8
8
  stringValue?: string
9
9
  numberValue?: number
10
10
  }
11
+ /** Active actor invocation correlation exposed to the TypeScript runtime adapter. */
12
+ export interface JsActorInvocationTraceContext {
13
+ rayId?: string
14
+ span?: JsActorInvocationSpanContext
15
+ }
16
+ /** W3C span context of the current invocation span, present only when tracing is active. */
17
+ export interface JsActorInvocationSpanContext {
18
+ traceId: string
19
+ spanId: string
20
+ traceFlags: number
21
+ tracestate?: string
22
+ }
11
23
  export interface JsHttpRequest {
12
24
  method: string
13
25
  uri: string
@@ -88,12 +100,19 @@ export interface JsSqliteProfilingConfig {
88
100
  maxDiagnosticEventsPerMinute?: number
89
101
  diagnosticEventQueueCapacity?: number
90
102
  }
103
+ /** Per-actor trace sample rates, from 0 to 1. */
104
+ export interface JsActorTracingConfig {
105
+ sampler?: number
106
+ /** Keyed by flattened, dot-separated action name. */
107
+ actions?: Record<string, number>
108
+ }
91
109
  export interface JsActorConfig {
92
110
  name?: string
93
111
  icon?: string
94
112
  hasDatabase?: boolean
95
113
  remoteSqlite?: boolean
96
114
  sqliteProfiling?: JsSqliteProfilingConfig
115
+ tracing?: JsActorTracingConfig
97
116
  enableActorRuntimeSocket?: boolean
98
117
  hasState?: boolean
99
118
  canHibernateWebsocket?: boolean
@@ -299,6 +318,13 @@ export interface JsKvEntry {
299
318
  key: Buffer
300
319
  value: Buffer
301
320
  }
321
+ /**
322
+ * Routes the OpenTelemetry SDK's own warnings, such as dropped spans, to the
323
+ * JavaScript logger. Each call replaces the previous sink. The sink is
324
+ * released by `shutdownTelemetry`.
325
+ */
326
+ export declare function setTelemetryLogSink(callback: (...args: any[]) => any): void
327
+ export declare function shutdownTelemetry(): Promise<void>
302
328
  /** N-API wrapper around `rivetkit-core::ActorContext`. */
303
329
  export declare class ActorContext {
304
330
  state(): Buffer
@@ -306,6 +332,22 @@ export declare class ActorContext {
306
332
  endOnStateChange(): void
307
333
  kv(): Kv
308
334
  sql(): JsNativeDatabase
335
+ sameActorInstance(other: ActorContext): boolean
336
+ /**
337
+ * Returns a handle for the same invocation whose Core spans parent to the
338
+ * application span active in JavaScript, given as W3C headers.
339
+ */
340
+ withApplicationSpan(traceparent?: string | undefined | null, tracestate?: string | undefined | null): ActorContext
341
+ invocationTraceContext(): JsActorInvocationTraceContext | null
342
+ /**
343
+ * Opens the span covering one call out to another actor. Returns nothing
344
+ * when this handle serves no invocation or tracing is disabled, in which
345
+ * case the caller sends its own context as before.
346
+ */
347
+ startCallSpan(actorName: string, actionName: string): OutboundCall | null
348
+ startWorkflowSpan(): Promise<WorkflowSpan>
349
+ /** Returns nothing outside a workflow run or when tracing is off. */
350
+ startWorkflowStepSpan(stepName: string, attempt: number): WorkflowStepSpan | null
309
351
  provisionActorRuntimeSocket(): Promise<JsActorRuntimeSocketEndpointInfo>
310
352
  schedule(): Schedule
311
353
  queue(): Queue
@@ -355,6 +397,42 @@ export declare class ActorContext {
355
397
  runtimeState(): object
356
398
  clearRuntimeState(): void
357
399
  }
400
+ /**
401
+ * One open call out to another actor.
402
+ *
403
+ * The call spans a request made by the host runtime, so it is opened and closed
404
+ * by two separate calls. Letting this be collected without finishing records
405
+ * the call as cancelled rather than silently losing it.
406
+ */
407
+ export declare class OutboundCall {
408
+ /**
409
+ * W3C context of this call's span, to send to the callee so it parents to
410
+ * the call rather than to the invocation that made it.
411
+ */
412
+ spanContext(): JsActorInvocationSpanContext | null
413
+ /**
414
+ * Records the call's outcome. `error` is the failure as the bridge encodes
415
+ * it, so a structured error keeps its group and code while anything else
416
+ * stays unstructured for Core to classify.
417
+ */
418
+ finish(error?: string | undefined | null): void
419
+ }
420
+ /**
421
+ * One open workflow run. Collecting it without `finish` records the run as
422
+ * abandoned.
423
+ */
424
+ export declare class WorkflowSpan {
425
+ /** The context workflow code runs under. */
426
+ ctx(): ActorContext
427
+ finish(outcome: string): Promise<void>
428
+ }
429
+ /** One open attempt at one workflow step. */
430
+ export declare class WorkflowStepSpan {
431
+ /** The context the step's callback runs under. */
432
+ ctx(): ActorContext
433
+ /** `error` is what the step threw, as the bridge encodes it. */
434
+ finish(outcome: string, error?: string | undefined | null): void
435
+ }
358
436
  export declare class NapiActorFactory {
359
437
  constructor(callbacks: object, config?: JsActorConfig | undefined | null)
360
438
  }
package/index.js CHANGED
@@ -310,11 +310,14 @@ if (!nativeBinding) {
310
310
  throw new Error(`Failed to load native binding`)
311
311
  }
312
312
 
313
- const { ActorContext, decodeInspectorRequest, encodeInspectorResponse, NapiActorFactory, CancellationToken, ConnHandle, JsNativeDatabase, JsSqliteTransaction, JsActorStateTransaction, HttpResponseBodyStream, HttpRequestBodyStream, Kv, Queue, QueueMessage, CoreRegistry, Schedule, WebSocket } = nativeBinding
313
+ const { ActorContext, decodeInspectorRequest, encodeInspectorResponse, OutboundCall, WorkflowSpan, WorkflowStepSpan, NapiActorFactory, CancellationToken, ConnHandle, JsNativeDatabase, JsSqliteTransaction, JsActorStateTransaction, HttpResponseBodyStream, HttpRequestBodyStream, Kv, Queue, QueueMessage, CoreRegistry, Schedule, WebSocket, setTelemetryLogSink, shutdownTelemetry } = nativeBinding
314
314
 
315
315
  module.exports.ActorContext = ActorContext
316
316
  module.exports.decodeInspectorRequest = decodeInspectorRequest
317
317
  module.exports.encodeInspectorResponse = encodeInspectorResponse
318
+ module.exports.OutboundCall = OutboundCall
319
+ module.exports.WorkflowSpan = WorkflowSpan
320
+ module.exports.WorkflowStepSpan = WorkflowStepSpan
318
321
  module.exports.NapiActorFactory = NapiActorFactory
319
322
  module.exports.CancellationToken = CancellationToken
320
323
  module.exports.ConnHandle = ConnHandle
@@ -329,3 +332,5 @@ module.exports.QueueMessage = QueueMessage
329
332
  module.exports.CoreRegistry = CoreRegistry
330
333
  module.exports.Schedule = Schedule
331
334
  module.exports.WebSocket = WebSocket
335
+ module.exports.setTelemetryLogSink = setTelemetryLogSink
336
+ module.exports.shutdownTelemetry = shutdownTelemetry
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivetkit/rivetkit-napi",
3
- "version": "2.3.18",
3
+ "version": "2.3.20",
4
4
  "description": "Native N-API addon for RivetKit providing envoy client and SQLite access",
5
5
  "license": "Apache-2.0",
6
6
  "main": "index.js",
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@napi-rs/cli": "^2.18.4",
47
- "@rivetkit/engine-envoy-protocol": "2.3.18"
47
+ "@rivetkit/engine-envoy-protocol": "2.3.20"
48
48
  },
49
49
  "repository": {
50
50
  "type": "git",
@@ -52,12 +52,12 @@
52
52
  "directory": "rivetkit-typescript/packages/rivetkit-napi"
53
53
  },
54
54
  "optionalDependencies": {
55
- "@rivetkit/rivetkit-napi-darwin-arm64": "2.3.18",
56
- "@rivetkit/rivetkit-napi-darwin-x64": "2.3.18",
57
- "@rivetkit/rivetkit-napi-linux-arm64-gnu": "2.3.18",
58
- "@rivetkit/rivetkit-napi-linux-arm64-musl": "2.3.18",
59
- "@rivetkit/rivetkit-napi-linux-x64-gnu": "2.3.18",
60
- "@rivetkit/rivetkit-napi-linux-x64-musl": "2.3.18",
61
- "@rivetkit/rivetkit-napi-win32-x64-msvc": "2.3.18"
55
+ "@rivetkit/rivetkit-napi-darwin-arm64": "2.3.20",
56
+ "@rivetkit/rivetkit-napi-darwin-x64": "2.3.20",
57
+ "@rivetkit/rivetkit-napi-linux-arm64-gnu": "2.3.20",
58
+ "@rivetkit/rivetkit-napi-linux-arm64-musl": "2.3.20",
59
+ "@rivetkit/rivetkit-napi-linux-x64-gnu": "2.3.20",
60
+ "@rivetkit/rivetkit-napi-linux-x64-musl": "2.3.20",
61
+ "@rivetkit/rivetkit-napi-win32-x64-msvc": "2.3.20"
62
62
  }
63
63
  }