@rivetkit/rivetkit-napi 0.0.0-main.41efcce → 0.0.0-main.49693dc

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,6 +41,9 @@ export interface JsInspectorSnapshot {
35
41
  queueSize: number
36
42
  connectedClients: number
37
43
  }
44
+ export interface JsActorRuntimeSocketEndpointInfo {
45
+ path: string
46
+ }
38
47
  export interface JsHttpResponse {
39
48
  status?: number
40
49
  headers?: Record<string, string>
@@ -47,10 +56,50 @@ export interface JsQueueSendResult {
47
56
  export interface JsActionDefinition {
48
57
  name: string
49
58
  }
59
+ /**
60
+ * One entry in the actor's `inspector.tabs[]` declaration. Either a
61
+ * custom-tab descriptor (id + label + source dir) or a built-in modifier
62
+ * (id + hidden=true). Validation already happened on the TS side; the
63
+ * runtime just splits the discriminator.
64
+ */
65
+ export interface JsInspectorTabEntry {
66
+ id: string
67
+ /** Required for custom entries; omitted for HideBuiltin. */
68
+ label?: string
69
+ /** Required for custom entries — absolute path to the source directory. */
70
+ source?: string
71
+ /**
72
+ * Optional icon id for custom entries. Dashboard maps strings to
73
+ * glyphs; unknown ids fall back to a generic icon.
74
+ */
75
+ icon?: string
76
+ /** Set to true for HideBuiltin entries. */
77
+ hidden?: boolean
78
+ }
79
+ /**
80
+ * Experimental SQLite profiling configuration. This entire configuration
81
+ * surface is subject to change without notice.
82
+ */
83
+ export interface JsSqliteProfilingConfig {
84
+ enabled?: boolean
85
+ maxTrackedStatementFingerprints?: number
86
+ maxTrackedTransactionFingerprints?: number
87
+ maxPrometheusSeries?: number
88
+ maxStatementsPerTransactionTrace?: number
89
+ maxGetPagesRequestsPerTrace?: number
90
+ maxTransactionNameBytes?: number
91
+ slowOperationThresholdMs?: number
92
+ baselineSampleRate?: number
93
+ maxDiagnosticEventsPerMinute?: number
94
+ diagnosticEventQueueCapacity?: number
95
+ }
50
96
  export interface JsActorConfig {
51
97
  name?: string
52
98
  icon?: string
53
99
  hasDatabase?: boolean
100
+ remoteSqlite?: boolean
101
+ sqliteProfiling?: JsSqliteProfilingConfig
102
+ enableActorRuntimeSocket?: boolean
54
103
  hasState?: boolean
55
104
  canHibernateWebsocket?: boolean
56
105
  stateSaveIntervalMs?: number
@@ -71,12 +120,12 @@ export interface JsActorConfig {
71
120
  connectionLivenessTimeoutMs?: number
72
121
  connectionLivenessIntervalMs?: number
73
122
  maxQueueSize?: number
123
+ maxSchedules?: number
74
124
  maxQueueMessageSize?: number
75
125
  maxIncomingMessageSize?: number
76
126
  maxOutgoingMessageSize?: number
77
- preloadMaxWorkflowBytes?: number
78
- preloadMaxConnectionsBytes?: number
79
127
  actions?: Array<JsActionDefinition>
128
+ inspectorTabs?: Array<JsInspectorTabEntry>
80
129
  }
81
130
  export interface JsBindParam {
82
131
  kind: string
@@ -92,6 +141,16 @@ export interface QueryResult {
92
141
  columns: Array<string>
93
142
  rows: Array<Array<any>>
94
143
  }
144
+ export interface NativeExecuteResult {
145
+ columns: Array<string>
146
+ rows: Array<Array<any>>
147
+ changes: number
148
+ lastInsertRowId?: number
149
+ }
150
+ export interface JsSqliteBatchStatement {
151
+ sql: string
152
+ params?: Array<JsBindParam>
153
+ }
95
154
  export interface JsSqliteVfsMetrics {
96
155
  requestBuildNs: number
97
156
  serializeNs: number
@@ -99,6 +158,11 @@ export interface JsSqliteVfsMetrics {
99
158
  stateUpdateNs: number
100
159
  totalNs: number
101
160
  commitCount: number
161
+ pageCacheEntries: number
162
+ pageCacheWeightedSize: number
163
+ pageCacheCapacityPages: number
164
+ writeBufferDirtyPages: number
165
+ dbSizePages: number
102
166
  }
103
167
  export interface JsQueueNextOptions {
104
168
  names?: Array<string>
@@ -143,6 +207,8 @@ export interface JsServeConfig {
143
207
  namespace: string
144
208
  poolName: string
145
209
  engineBinaryPath?: string
210
+ engineHost?: string
211
+ enginePort?: number
146
212
  handleInspectorHttpInRuntime?: boolean
147
213
  serverlessBasePath?: string
148
214
  serverlessPackageVersion: string
@@ -152,6 +218,16 @@ export interface JsServeConfig {
152
218
  serverlessValidateEndpoint: boolean
153
219
  serverlessMaxStartPayloadBytes: number
154
220
  }
221
+ export interface JsListenerConfig {
222
+ /** Host to bind. Defaults to `0.0.0.0` when not provided. */
223
+ host?: string
224
+ port: number
225
+ /**
226
+ * Optional static file root mounted as a fallback below the framework
227
+ * routes.
228
+ */
229
+ publicDir?: string
230
+ }
155
231
  export interface JsServerlessRequest {
156
232
  method: string
157
233
  url: string
@@ -162,11 +238,53 @@ export interface JsServerlessResponseHead {
162
238
  status: number
163
239
  headers: Record<string, string>
164
240
  }
241
+ export interface JsApplicationResponse {
242
+ status: number
243
+ headers: Record<string, string>
244
+ body: Buffer
245
+ }
246
+ export interface JsRegistryRouteResponse {
247
+ status: number
248
+ headers: Record<string, string>
249
+ body: Buffer
250
+ }
165
251
  export interface JsServerlessStreamError {
166
252
  group: string
167
253
  code: string
168
254
  message: string
169
255
  }
256
+ export interface JsScheduledEventInfo {
257
+ id: string
258
+ action: string
259
+ args: Buffer
260
+ runAt: number
261
+ }
262
+ export interface JsCronJobInfo {
263
+ name: string
264
+ kind: string
265
+ action: string
266
+ args: Buffer
267
+ nextRunAt: number
268
+ lastRunAt?: number
269
+ expression?: string
270
+ timezone?: string
271
+ intervalMs?: number
272
+ maxHistory: number
273
+ }
274
+ export interface JsScheduleErrorInfo {
275
+ group: string
276
+ code: string
277
+ message: string
278
+ metadata?: any
279
+ }
280
+ export interface JsCronFire {
281
+ action: string
282
+ scheduledAt: number
283
+ firedAt: number
284
+ finishedAt?: number
285
+ result: string
286
+ error?: JsScheduleErrorInfo
287
+ }
170
288
  /** Options for KV list operations. */
171
289
  export interface JsKvListOptions {
172
290
  reverse?: boolean
@@ -179,12 +297,12 @@ export interface JsKvEntry {
179
297
  }
180
298
  /** N-API wrapper around `rivetkit-core::ActorContext`. */
181
299
  export declare class ActorContext {
182
- constructor(actorId: string, name: string, region: string)
183
300
  state(): Buffer
184
301
  beginOnStateChange(): void
185
302
  endOnStateChange(): void
186
303
  kv(): Kv
187
304
  sql(): JsNativeDatabase
305
+ provisionActorRuntimeSocket(): Promise<JsActorRuntimeSocketEndpointInfo>
188
306
  schedule(): Schedule
189
307
  queue(): Queue
190
308
  setAlarm(timestampMs?: number | undefined | null): void
@@ -199,6 +317,8 @@ export declare class ActorContext {
199
317
  takePendingHibernationChanges(): Array<string>
200
318
  dirtyHibernatableConns(): Array<ConnHandle>
201
319
  saveState(payload: StateDeltaPayload): Promise<void>
320
+ beginStateTransaction(timeoutMs?: number | undefined | null): Promise<JsActorStateTransaction>
321
+ saveStateAndWorkflowBatch(writes: Array<WorkflowKvWritePayload>): Promise<void>
202
322
  actorId(): string
203
323
  name(): string
204
324
  key(): Array<JsActorKeySegment>
@@ -212,6 +332,10 @@ export declare class ActorContext {
212
332
  aborted(): boolean
213
333
  runHandlerActive(): boolean
214
334
  restartRunHandler(): void
335
+ setRunWakeAt(timestampMs?: number | undefined | null): Promise<void>
336
+ beginKeepAwake(): number
337
+ endKeepAwake(regionId: number): void
338
+ keepAwake(promise: Promise<any>): void
215
339
  beginWebsocketCallback(): number
216
340
  endWebsocketCallback(regionId: number): void
217
341
  abortSignal(): AbortSignal
@@ -221,7 +345,8 @@ export declare class ActorContext {
221
345
  disconnectConns(predicate: (...args: any[]) => any): Promise<void>
222
346
  broadcast(name: string, args: Buffer): void
223
347
  waitUntil(promise: Promise<any>): void
224
- keepAwake(promise: Promise<any>): Promise<any>
348
+ waitForTrackedShutdownWork(): Promise<boolean>
349
+ waitForTrackedShutdownWorkUnbounded(): Promise<void>
225
350
  registerTask(promise: Promise<any>): void
226
351
  runtimeState(): object
227
352
  clearRuntimeState(): void
@@ -246,11 +371,25 @@ export declare class ConnHandle {
246
371
  }
247
372
  export declare class JsNativeDatabase {
248
373
  takeLastKvError(): string | null
249
- getSqliteVfsMetrics(): JsSqliteVfsMetrics | null
374
+ metrics(): JsSqliteVfsMetrics | null
250
375
  run(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<ExecuteResult>
251
376
  query(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<QueryResult>
377
+ execute(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<NativeExecuteResult>
378
+ executeBatch(statements: Array<JsSqliteBatchStatement>): Promise<Array<NativeExecuteResult>>
252
379
  exec(sql: string): Promise<QueryResult>
253
380
  close(): Promise<void>
381
+ beginTransaction(timeoutMs?: number | undefined | null, name?: string | undefined | null): Promise<JsSqliteTransaction>
382
+ }
383
+ export declare class JsSqliteTransaction {
384
+ execute(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<NativeExecuteResult>
385
+ exec(sql: string): Promise<QueryResult>
386
+ commit(): Promise<void>
387
+ rollback(): Promise<void>
388
+ }
389
+ export declare class JsActorStateTransaction {
390
+ execute(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<NativeExecuteResult>
391
+ commit(payload: StateDeltaPayload): Promise<void>
392
+ rollback(): Promise<void>
254
393
  }
255
394
  export declare class Kv {
256
395
  get(key: Buffer): Promise<Buffer | null>
@@ -268,11 +407,13 @@ export declare class Queue {
268
407
  next(options?: JsQueueNextOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<QueueMessage | null>
269
408
  nextBatch(options?: JsQueueNextBatchOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<Array<QueueMessage>>
270
409
  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>
410
+ waitForNamesAvailable(names: Array<string>, options?: JsQueueWaitOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<void>
411
+ completePersisted(messageId: bigint, expectedName: string, response?: Buffer | undefined | null): Promise<boolean>
272
412
  enqueueAndWait(name: string, body: Buffer, options?: JsQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<Buffer | null>
273
413
  tryNext(options?: JsQueueTryNextOptions | undefined | null): QueueMessage | null
274
414
  tryNextBatch(options?: JsQueueTryNextBatchOptions | undefined | null): Array<QueueMessage>
275
415
  maxSize(): number
416
+ reset(): Promise<void>
276
417
  inspectMessages(): Promise<Array<JsQueueInspectMessage>>
277
418
  }
278
419
  export declare class QueueMessage {
@@ -287,6 +428,13 @@ export declare class CoreRegistry {
287
428
  constructor()
288
429
  register(name: string, factory: NapiActorFactory): void
289
430
  serve(config: JsServeConfig): Promise<void>
431
+ /**
432
+ * Wait until the serverful envoy has completed its Engine registration.
433
+ *
434
+ * Readiness is the envoy client's `ToEnvoyInit` signal, not HTTP health or
435
+ * merely constructing the envoy handle.
436
+ */
437
+ waitReady(): Promise<void>
290
438
  /**
291
439
  * Trip the shutdown token and tear down any live serverless runtime.
292
440
  *
@@ -295,11 +443,26 @@ export declare class CoreRegistry {
295
443
  * separately to avoid re-entrancy.
296
444
  */
297
445
  shutdown(): Promise<void>
446
+ actorStopThresholdMs(): Promise<number | null>
447
+ health(): Promise<JsRegistryRouteResponse>
448
+ metadata(): JsRegistryRouteResponse
449
+ metrics(): JsRegistryRouteResponse
450
+ serveApplicationListener(listener: JsListenerConfig, application: (...args: any[]) => any, config: JsServeConfig): Promise<void>
451
+ serveListener(listener: JsListenerConfig, config: JsServeConfig, application?: (...args: any[]) => any | undefined | null): Promise<void>
298
452
  handleServerlessRequest(req: JsServerlessRequest, onStreamEvent: (...args: any[]) => any, cancelToken: CancellationToken, config: JsServeConfig): Promise<JsServerlessResponseHead>
299
453
  }
300
454
  export declare class Schedule {
301
- after(durationMs: number, actionName: string, args: Buffer): void
302
- at(timestampMs: number, actionName: string, args: Buffer): void
455
+ after(durationMs: number, actionName: string, args: Buffer): Promise<string>
456
+ at(timestampMs: number, actionName: string, args: Buffer): Promise<string>
457
+ cancel(id: string): Promise<boolean>
458
+ get(id: string): Promise<JsScheduledEventInfo | null>
459
+ list(): Promise<Array<JsScheduledEventInfo>>
460
+ cronSet(name: string, expression: string, timezone: string | undefined | null, actionName: string, args: Buffer, maxHistory?: number | undefined | null): Promise<void>
461
+ cronEvery(name: string, intervalMs: number, actionName: string, args: Buffer, maxHistory?: number | undefined | null): Promise<void>
462
+ cronGet(name: string): Promise<JsCronJobInfo | null>
463
+ cronList(): Promise<Array<JsCronJobInfo>>
464
+ cronDelete(name: string): Promise<boolean>
465
+ cronHistory(name: string, limit?: number | undefined | null): Promise<Array<JsCronFire>>
303
466
  }
304
467
  export declare class WebSocket {
305
468
  send(data: Buffer, binary: boolean): void
package/index.js CHANGED
@@ -310,13 +310,17 @@ 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, 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
320
324
  module.exports.Kv = Kv
321
325
  module.exports.Queue = Queue
322
326
  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.41efcce",
3
+ "version": "0.0.0-main.49693dc",
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.41efcce"
47
+ "@rivetkit/engine-envoy-protocol": "0.0.0-main.49693dc"
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.41efcce",
50
- "@rivetkit/rivetkit-napi-darwin-x64": "0.0.0-main.41efcce",
51
- "@rivetkit/rivetkit-napi-linux-arm64-gnu": "0.0.0-main.41efcce",
52
- "@rivetkit/rivetkit-napi-linux-arm64-musl": "0.0.0-main.41efcce",
53
- "@rivetkit/rivetkit-napi-linux-x64-gnu": "0.0.0-main.41efcce",
54
- "@rivetkit/rivetkit-napi-linux-x64-musl": "0.0.0-main.41efcce",
55
- "@rivetkit/rivetkit-napi-win32-x64-msvc": "0.0.0-main.41efcce"
55
+ "@rivetkit/rivetkit-napi-darwin-arm64": "0.0.0-main.49693dc",
56
+ "@rivetkit/rivetkit-napi-darwin-x64": "0.0.0-main.49693dc",
57
+ "@rivetkit/rivetkit-napi-linux-arm64-gnu": "0.0.0-main.49693dc",
58
+ "@rivetkit/rivetkit-napi-linux-arm64-musl": "0.0.0-main.49693dc",
59
+ "@rivetkit/rivetkit-napi-linux-x64-gnu": "0.0.0-main.49693dc",
60
+ "@rivetkit/rivetkit-napi-linux-x64-musl": "0.0.0-main.49693dc"
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" });