@rivetkit/rivetkit-napi 0.0.0-main.a904d4f → 0.0.0-main.b2d3b94

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/index.d.ts CHANGED
@@ -23,10 +23,16 @@ export interface StateDeltaPayload {
23
23
  connHibernation: Array<StateDeltaConnHibernationEntry>
24
24
  connHibernationRemoved: Array<string>
25
25
  }
26
+ export interface WorkflowKvWritePayload {
27
+ key: Buffer
28
+ value: Buffer
29
+ }
26
30
  export interface JsRequestSaveOpts {
27
31
  immediate?: boolean
28
32
  maxWaitMs?: number
29
33
  }
34
+ export declare function decodeInspectorRequest(bytes: Buffer, advertisedVersion: number): Buffer
35
+ export declare function encodeInspectorResponse(bytes: Buffer, targetVersion: number): Buffer
30
36
  export interface JsInspectorSnapshot {
31
37
  stateRevision: number
32
38
  connectionsRevision: number
@@ -35,10 +41,8 @@ export interface JsInspectorSnapshot {
35
41
  queueSize: number
36
42
  connectedClients: number
37
43
  }
38
- export interface JsHttpResponse {
39
- status?: number
40
- headers?: Record<string, string>
41
- body?: Buffer
44
+ export interface JsActorRuntimeSocketEndpointInfo {
45
+ path: string
42
46
  }
43
47
  export interface JsQueueSendResult {
44
48
  status: string
@@ -47,10 +51,50 @@ export interface JsQueueSendResult {
47
51
  export interface JsActionDefinition {
48
52
  name: string
49
53
  }
54
+ /**
55
+ * One entry in the actor's `inspector.tabs[]` declaration. Either a
56
+ * custom-tab descriptor (id + label + source dir) or a built-in modifier
57
+ * (id + hidden=true). Validation already happened on the TS side; the
58
+ * runtime just splits the discriminator.
59
+ */
60
+ export interface JsInspectorTabEntry {
61
+ id: string
62
+ /** Required for custom entries; omitted for HideBuiltin. */
63
+ label?: string
64
+ /** Required for custom entries — absolute path to the source directory. */
65
+ source?: string
66
+ /**
67
+ * Optional icon id for custom entries. Dashboard maps strings to
68
+ * glyphs; unknown ids fall back to a generic icon.
69
+ */
70
+ icon?: string
71
+ /** Set to true for HideBuiltin entries. */
72
+ hidden?: boolean
73
+ }
74
+ /**
75
+ * Experimental SQLite profiling configuration. This entire configuration
76
+ * surface is subject to change without notice.
77
+ */
78
+ export interface JsSqliteProfilingConfig {
79
+ enabled?: boolean
80
+ maxTrackedStatementFingerprints?: number
81
+ maxTrackedTransactionFingerprints?: number
82
+ maxPrometheusSeries?: number
83
+ maxStatementsPerTransactionTrace?: number
84
+ maxGetPagesRequestsPerTrace?: number
85
+ maxTransactionNameBytes?: number
86
+ slowOperationThresholdMs?: number
87
+ baselineSampleRate?: number
88
+ maxDiagnosticEventsPerMinute?: number
89
+ diagnosticEventQueueCapacity?: number
90
+ }
50
91
  export interface JsActorConfig {
51
92
  name?: string
52
93
  icon?: string
53
94
  hasDatabase?: boolean
95
+ remoteSqlite?: boolean
96
+ sqliteProfiling?: JsSqliteProfilingConfig
97
+ enableActorRuntimeSocket?: boolean
54
98
  hasState?: boolean
55
99
  canHibernateWebsocket?: boolean
56
100
  stateSaveIntervalMs?: number
@@ -71,12 +115,12 @@ export interface JsActorConfig {
71
115
  connectionLivenessTimeoutMs?: number
72
116
  connectionLivenessIntervalMs?: number
73
117
  maxQueueSize?: number
118
+ maxSchedules?: number
74
119
  maxQueueMessageSize?: number
75
120
  maxIncomingMessageSize?: number
76
121
  maxOutgoingMessageSize?: number
77
- preloadMaxWorkflowBytes?: number
78
- preloadMaxConnectionsBytes?: number
79
122
  actions?: Array<JsActionDefinition>
123
+ inspectorTabs?: Array<JsInspectorTabEntry>
80
124
  }
81
125
  export interface JsBindParam {
82
126
  kind: string
@@ -92,6 +136,16 @@ export interface QueryResult {
92
136
  columns: Array<string>
93
137
  rows: Array<Array<any>>
94
138
  }
139
+ export interface NativeExecuteResult {
140
+ columns: Array<string>
141
+ rows: Array<Array<any>>
142
+ changes: number
143
+ lastInsertRowId?: number
144
+ }
145
+ export interface JsSqliteBatchStatement {
146
+ sql: string
147
+ params?: Array<JsBindParam>
148
+ }
95
149
  export interface JsSqliteVfsMetrics {
96
150
  requestBuildNs: number
97
151
  serializeNs: number
@@ -99,6 +153,17 @@ export interface JsSqliteVfsMetrics {
99
153
  stateUpdateNs: number
100
154
  totalNs: number
101
155
  commitCount: number
156
+ pageCacheEntries: number
157
+ pageCacheWeightedSize: number
158
+ pageCacheCapacityPages: number
159
+ writeBufferDirtyPages: number
160
+ dbSizePages: number
161
+ }
162
+ export interface JsHttpResponse {
163
+ status?: number
164
+ headers?: Record<string, string>
165
+ body?: Buffer
166
+ stream?: boolean
102
167
  }
103
168
  export interface JsQueueNextOptions {
104
169
  names?: Array<string>
@@ -143,6 +208,8 @@ export interface JsServeConfig {
143
208
  namespace: string
144
209
  poolName: string
145
210
  engineBinaryPath?: string
211
+ engineHost?: string
212
+ enginePort?: number
146
213
  handleInspectorHttpInRuntime?: boolean
147
214
  serverlessBasePath?: string
148
215
  serverlessPackageVersion: string
@@ -152,6 +219,16 @@ export interface JsServeConfig {
152
219
  serverlessValidateEndpoint: boolean
153
220
  serverlessMaxStartPayloadBytes: number
154
221
  }
222
+ export interface JsListenerConfig {
223
+ /** Host to bind. Defaults to `0.0.0.0` when not provided. */
224
+ host?: string
225
+ port: number
226
+ /**
227
+ * Optional static file root mounted as a fallback below the framework
228
+ * routes.
229
+ */
230
+ publicDir?: string
231
+ }
155
232
  export interface JsServerlessRequest {
156
233
  method: string
157
234
  url: string
@@ -162,11 +239,54 @@ export interface JsServerlessResponseHead {
162
239
  status: number
163
240
  headers: Record<string, string>
164
241
  }
242
+ export interface JsApplicationResponse {
243
+ status: number
244
+ headers: Record<string, string>
245
+ body?: Buffer
246
+ stream?: boolean
247
+ }
248
+ export interface JsRegistryRouteResponse {
249
+ status: number
250
+ headers: Record<string, string>
251
+ body: Buffer
252
+ }
165
253
  export interface JsServerlessStreamError {
166
254
  group: string
167
255
  code: string
168
256
  message: string
169
257
  }
258
+ export interface JsScheduledEventInfo {
259
+ id: string
260
+ action: string
261
+ args: Buffer
262
+ runAt: number
263
+ }
264
+ export interface JsCronJobInfo {
265
+ name: string
266
+ kind: string
267
+ action: string
268
+ args: Buffer
269
+ nextRunAt: number
270
+ lastRunAt?: number
271
+ expression?: string
272
+ timezone?: string
273
+ intervalMs?: number
274
+ maxHistory: number
275
+ }
276
+ export interface JsScheduleErrorInfo {
277
+ group: string
278
+ code: string
279
+ message: string
280
+ metadata?: any
281
+ }
282
+ export interface JsCronFire {
283
+ action: string
284
+ scheduledAt: number
285
+ firedAt: number
286
+ finishedAt?: number
287
+ result: string
288
+ error?: JsScheduleErrorInfo
289
+ }
170
290
  /** Options for KV list operations. */
171
291
  export interface JsKvListOptions {
172
292
  reverse?: boolean
@@ -179,12 +299,12 @@ export interface JsKvEntry {
179
299
  }
180
300
  /** N-API wrapper around `rivetkit-core::ActorContext`. */
181
301
  export declare class ActorContext {
182
- constructor(actorId: string, name: string, region: string)
183
302
  state(): Buffer
184
303
  beginOnStateChange(): void
185
304
  endOnStateChange(): void
186
305
  kv(): Kv
187
306
  sql(): JsNativeDatabase
307
+ provisionActorRuntimeSocket(): Promise<JsActorRuntimeSocketEndpointInfo>
188
308
  schedule(): Schedule
189
309
  queue(): Queue
190
310
  setAlarm(timestampMs?: number | undefined | null): void
@@ -199,6 +319,8 @@ export declare class ActorContext {
199
319
  takePendingHibernationChanges(): Array<string>
200
320
  dirtyHibernatableConns(): Array<ConnHandle>
201
321
  saveState(payload: StateDeltaPayload): Promise<void>
322
+ beginStateTransaction(timeoutMs?: number | undefined | null): Promise<JsActorStateTransaction>
323
+ saveStateAndWorkflowBatch(writes: Array<WorkflowKvWritePayload>): Promise<void>
202
324
  actorId(): string
203
325
  name(): string
204
326
  key(): Array<JsActorKeySegment>
@@ -212,6 +334,10 @@ export declare class ActorContext {
212
334
  aborted(): boolean
213
335
  runHandlerActive(): boolean
214
336
  restartRunHandler(): void
337
+ setRunWakeAt(timestampMs?: number | undefined | null): Promise<void>
338
+ beginKeepAwake(): number
339
+ endKeepAwake(regionId: number): void
340
+ keepAwake(promise: Promise<any>): void
215
341
  beginWebsocketCallback(): number
216
342
  endWebsocketCallback(regionId: number): void
217
343
  abortSignal(): AbortSignal
@@ -221,7 +347,8 @@ export declare class ActorContext {
221
347
  disconnectConns(predicate: (...args: any[]) => any): Promise<void>
222
348
  broadcast(name: string, args: Buffer): void
223
349
  waitUntil(promise: Promise<any>): void
224
- keepAwake(promise: Promise<any>): Promise<any>
350
+ waitForTrackedShutdownWork(): Promise<boolean>
351
+ waitForTrackedShutdownWorkUnbounded(): Promise<void>
225
352
  registerTask(promise: Promise<any>): void
226
353
  runtimeState(): object
227
354
  clearRuntimeState(): void
@@ -246,11 +373,37 @@ export declare class ConnHandle {
246
373
  }
247
374
  export declare class JsNativeDatabase {
248
375
  takeLastKvError(): string | null
249
- getSqliteVfsMetrics(): JsSqliteVfsMetrics | null
376
+ metrics(): JsSqliteVfsMetrics | null
250
377
  run(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<ExecuteResult>
251
378
  query(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<QueryResult>
379
+ execute(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<NativeExecuteResult>
380
+ executeBatch(statements: Array<JsSqliteBatchStatement>): Promise<Array<NativeExecuteResult>>
252
381
  exec(sql: string): Promise<QueryResult>
253
382
  close(): Promise<void>
383
+ beginTransaction(timeoutMs?: number | undefined | null, name?: string | undefined | null): Promise<JsSqliteTransaction>
384
+ }
385
+ export declare class JsSqliteTransaction {
386
+ execute(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<NativeExecuteResult>
387
+ exec(sql: string): Promise<QueryResult>
388
+ commit(): Promise<void>
389
+ rollback(): Promise<void>
390
+ }
391
+ export declare class JsActorStateTransaction {
392
+ execute(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<NativeExecuteResult>
393
+ commit(payload: StateDeltaPayload): Promise<void>
394
+ rollback(): Promise<void>
395
+ }
396
+ /** JavaScript-facing writer for a streaming actor HTTP response. */
397
+ export declare class HttpResponseBodyStream {
398
+ cancelled(): Promise<void>
399
+ write(chunk: Buffer): Promise<void>
400
+ end(): Promise<void>
401
+ error(message: string): Promise<void>
402
+ }
403
+ /** JavaScript-facing reader for a streaming actor HTTP request. */
404
+ export declare class HttpRequestBodyStream {
405
+ read(): Promise<Buffer | null>
406
+ cancel(): Promise<void>
254
407
  }
255
408
  export declare class Kv {
256
409
  get(key: Buffer): Promise<Buffer | null>
@@ -268,11 +421,13 @@ export declare class Queue {
268
421
  next(options?: JsQueueNextOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<QueueMessage | null>
269
422
  nextBatch(options?: JsQueueNextBatchOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<Array<QueueMessage>>
270
423
  waitForNames(names: Array<string>, options?: JsQueueWaitOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<QueueMessage>
271
- waitForNamesAvailable(names: Array<string>, options?: JsQueueWaitOptions | undefined | null): Promise<void>
424
+ waitForNamesAvailable(names: Array<string>, options?: JsQueueWaitOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<void>
425
+ completePersisted(messageId: bigint, expectedName: string, response?: Buffer | undefined | null): Promise<boolean>
272
426
  enqueueAndWait(name: string, body: Buffer, options?: JsQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<Buffer | null>
273
427
  tryNext(options?: JsQueueTryNextOptions | undefined | null): QueueMessage | null
274
428
  tryNextBatch(options?: JsQueueTryNextBatchOptions | undefined | null): Array<QueueMessage>
275
429
  maxSize(): number
430
+ reset(): Promise<void>
276
431
  inspectMessages(): Promise<Array<JsQueueInspectMessage>>
277
432
  }
278
433
  export declare class QueueMessage {
@@ -287,6 +442,13 @@ export declare class CoreRegistry {
287
442
  constructor()
288
443
  register(name: string, factory: NapiActorFactory): void
289
444
  serve(config: JsServeConfig): Promise<void>
445
+ /**
446
+ * Wait until the serverful envoy has completed its Engine registration.
447
+ *
448
+ * Readiness is the envoy client's `ToEnvoyInit` signal, not HTTP health or
449
+ * merely constructing the envoy handle.
450
+ */
451
+ waitReady(): Promise<void>
290
452
  /**
291
453
  * Trip the shutdown token and tear down any live serverless runtime.
292
454
  *
@@ -295,11 +457,26 @@ export declare class CoreRegistry {
295
457
  * separately to avoid re-entrancy.
296
458
  */
297
459
  shutdown(): Promise<void>
460
+ actorStopThresholdMs(): Promise<number | null>
461
+ health(): Promise<JsRegistryRouteResponse>
462
+ metadata(): JsRegistryRouteResponse
463
+ metrics(): JsRegistryRouteResponse
464
+ serveApplicationListener(listener: JsListenerConfig, application: (...args: any[]) => any, config: JsServeConfig): Promise<void>
465
+ serveListener(listener: JsListenerConfig, config: JsServeConfig, application?: (...args: any[]) => any | undefined | null): Promise<void>
298
466
  handleServerlessRequest(req: JsServerlessRequest, onStreamEvent: (...args: any[]) => any, cancelToken: CancellationToken, config: JsServeConfig): Promise<JsServerlessResponseHead>
299
467
  }
300
468
  export declare class Schedule {
301
- after(durationMs: number, actionName: string, args: Buffer): void
302
- at(timestampMs: number, actionName: string, args: Buffer): void
469
+ after(durationMs: number, actionName: string, args: Buffer): Promise<string>
470
+ at(timestampMs: number, actionName: string, args: Buffer): Promise<string>
471
+ cancel(id: string): Promise<boolean>
472
+ get(id: string): Promise<JsScheduledEventInfo | null>
473
+ list(): Promise<Array<JsScheduledEventInfo>>
474
+ cronSet(name: string, expression: string, timezone: string | undefined | null, actionName: string, args: Buffer, maxHistory?: number | undefined | null): Promise<void>
475
+ cronEvery(name: string, intervalMs: number, actionName: string, args: Buffer, maxHistory?: number | undefined | null): Promise<void>
476
+ cronGet(name: string): Promise<JsCronJobInfo | null>
477
+ cronList(): Promise<Array<JsCronJobInfo>>
478
+ cronDelete(name: string): Promise<boolean>
479
+ cronHistory(name: string, limit?: number | undefined | null): Promise<Array<JsCronFire>>
303
480
  }
304
481
  export declare class WebSocket {
305
482
  send(data: Buffer, binary: boolean): void
package/index.js CHANGED
@@ -310,13 +310,19 @@ if (!nativeBinding) {
310
310
  throw new Error(`Failed to load native binding`)
311
311
  }
312
312
 
313
- const { ActorContext, NapiActorFactory, CancellationToken, ConnHandle, JsNativeDatabase, Kv, Queue, QueueMessage, CoreRegistry, Schedule, WebSocket } = nativeBinding
313
+ const { ActorContext, decodeInspectorRequest, encodeInspectorResponse, NapiActorFactory, CancellationToken, ConnHandle, JsNativeDatabase, JsSqliteTransaction, JsActorStateTransaction, HttpResponseBodyStream, HttpRequestBodyStream, Kv, Queue, QueueMessage, CoreRegistry, Schedule, WebSocket } = nativeBinding
314
314
 
315
315
  module.exports.ActorContext = ActorContext
316
+ module.exports.decodeInspectorRequest = decodeInspectorRequest
317
+ module.exports.encodeInspectorResponse = encodeInspectorResponse
316
318
  module.exports.NapiActorFactory = NapiActorFactory
317
319
  module.exports.CancellationToken = CancellationToken
318
320
  module.exports.ConnHandle = ConnHandle
319
321
  module.exports.JsNativeDatabase = JsNativeDatabase
322
+ module.exports.JsSqliteTransaction = JsSqliteTransaction
323
+ module.exports.JsActorStateTransaction = JsActorStateTransaction
324
+ module.exports.HttpResponseBodyStream = HttpResponseBodyStream
325
+ module.exports.HttpRequestBodyStream = HttpRequestBodyStream
320
326
  module.exports.Kv = Kv
321
327
  module.exports.Queue = Queue
322
328
  module.exports.QueueMessage = QueueMessage
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivetkit/rivetkit-napi",
3
- "version": "0.0.0-main.a904d4f",
3
+ "version": "0.0.0-main.b2d3b94",
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",
@@ -39,19 +39,24 @@
39
39
  "build": "node scripts/build.mjs",
40
40
  "build:release": "node scripts/build.mjs --release",
41
41
  "build:force": "node scripts/build.mjs --force",
42
- "build:force:release": "node scripts/build.mjs --force --release"
42
+ "build:force:release": "node scripts/build.mjs --force --release",
43
+ "build:embed": "node scripts/build.mjs"
43
44
  },
44
45
  "dependencies": {
45
46
  "@napi-rs/cli": "^2.18.4",
46
- "@rivetkit/engine-envoy-protocol": "0.0.0-main.a904d4f"
47
+ "@rivetkit/engine-envoy-protocol": "0.0.0-main.b2d3b94"
48
+ },
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "https://github.com/rivet-dev/actors.git",
52
+ "directory": "rivetkit-typescript/packages/rivetkit-napi"
47
53
  },
48
54
  "optionalDependencies": {
49
- "@rivetkit/rivetkit-napi-darwin-arm64": "0.0.0-main.a904d4f",
50
- "@rivetkit/rivetkit-napi-darwin-x64": "0.0.0-main.a904d4f",
51
- "@rivetkit/rivetkit-napi-linux-arm64-gnu": "0.0.0-main.a904d4f",
52
- "@rivetkit/rivetkit-napi-linux-arm64-musl": "0.0.0-main.a904d4f",
53
- "@rivetkit/rivetkit-napi-linux-x64-gnu": "0.0.0-main.a904d4f",
54
- "@rivetkit/rivetkit-napi-linux-x64-musl": "0.0.0-main.a904d4f",
55
- "@rivetkit/rivetkit-napi-win32-x64-msvc": "0.0.0-main.a904d4f"
55
+ "@rivetkit/rivetkit-napi-darwin-arm64": "0.0.0-main.b2d3b94",
56
+ "@rivetkit/rivetkit-napi-darwin-x64": "0.0.0-main.b2d3b94",
57
+ "@rivetkit/rivetkit-napi-linux-arm64-gnu": "0.0.0-main.b2d3b94",
58
+ "@rivetkit/rivetkit-napi-linux-arm64-musl": "0.0.0-main.b2d3b94",
59
+ "@rivetkit/rivetkit-napi-linux-x64-gnu": "0.0.0-main.b2d3b94",
60
+ "@rivetkit/rivetkit-napi-linux-x64-musl": "0.0.0-main.b2d3b94"
56
61
  }
57
62
  }
package/scripts/build.mjs CHANGED
@@ -16,6 +16,14 @@ if (process.env.SKIP_NAPI_BUILD === "1") {
16
16
  process.exit(0);
17
17
  }
18
18
 
19
+ // The per-actor inspector UI (frontend/dist/inspector-ui, embedded into
20
+ // rivetkit-core by its build.rs) must be built before this napi build runs.
21
+ // It is NOT built here: rivetkit-core's embed needs rivetkit/inspector-tab,
22
+ // which is downstream of this package in the build graph, so building it from
23
+ // the napi build would invert the dependency order. CI builds it via
24
+ // `turbo build:inspector-ui` in docker/build/*.Dockerfile before `napi build`;
25
+ // for local builds run `pnpm -F @rivetkit/engine-frontend build:inspector-ui`
26
+ // (or `turbo build:inspector-ui`) first.
19
27
  const cmd = ["build", "--platform", ...extraFlags];
20
28
  console.log(`[rivetkit-napi/build] running: napi ${cmd.join(" ")}`);
21
29
  execFileSync("napi", cmd, { stdio: "inherit" });