@rivetkit/rivetkit-napi 0.0.0-main.72cbc7c → 0.0.0-main.78336a1

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,11 +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
54
95
  remoteSqlite?: boolean
96
+ sqliteProfiling?: JsSqliteProfilingConfig
97
+ enableActorRuntimeSocket?: boolean
55
98
  hasState?: boolean
56
99
  canHibernateWebsocket?: boolean
57
100
  stateSaveIntervalMs?: number
@@ -72,12 +115,12 @@ export interface JsActorConfig {
72
115
  connectionLivenessTimeoutMs?: number
73
116
  connectionLivenessIntervalMs?: number
74
117
  maxQueueSize?: number
118
+ maxSchedules?: number
75
119
  maxQueueMessageSize?: number
76
120
  maxIncomingMessageSize?: number
77
121
  maxOutgoingMessageSize?: number
78
- preloadMaxWorkflowBytes?: number
79
- preloadMaxConnectionsBytes?: number
80
122
  actions?: Array<JsActionDefinition>
123
+ inspectorTabs?: Array<JsInspectorTabEntry>
81
124
  }
82
125
  export interface JsBindParam {
83
126
  kind: string
@@ -99,6 +142,10 @@ export interface NativeExecuteResult {
99
142
  changes: number
100
143
  lastInsertRowId?: number
101
144
  }
145
+ export interface JsSqliteBatchStatement {
146
+ sql: string
147
+ params?: Array<JsBindParam>
148
+ }
102
149
  export interface JsSqliteVfsMetrics {
103
150
  requestBuildNs: number
104
151
  serializeNs: number
@@ -112,6 +159,12 @@ export interface JsSqliteVfsMetrics {
112
159
  writeBufferDirtyPages: number
113
160
  dbSizePages: number
114
161
  }
162
+ export interface JsHttpResponse {
163
+ status?: number
164
+ headers?: Record<string, string>
165
+ body?: Buffer
166
+ stream?: boolean
167
+ }
115
168
  export interface JsQueueNextOptions {
116
169
  names?: Array<string>
117
170
  timeoutMs?: number
@@ -155,6 +208,10 @@ export interface JsServeConfig {
155
208
  namespace: string
156
209
  poolName: string
157
210
  engineBinaryPath?: string
211
+ startServices?: boolean
212
+ servicesBinaryPath?: string
213
+ engineHost?: string
214
+ enginePort?: number
158
215
  handleInspectorHttpInRuntime?: boolean
159
216
  serverlessBasePath?: string
160
217
  serverlessPackageVersion: string
@@ -164,6 +221,16 @@ export interface JsServeConfig {
164
221
  serverlessValidateEndpoint: boolean
165
222
  serverlessMaxStartPayloadBytes: number
166
223
  }
224
+ export interface JsListenerConfig {
225
+ /** Host to bind. Defaults to `0.0.0.0` when not provided. */
226
+ host?: string
227
+ port: number
228
+ /**
229
+ * Optional static file root mounted as a fallback below the framework
230
+ * routes.
231
+ */
232
+ publicDir?: string
233
+ }
167
234
  export interface JsServerlessRequest {
168
235
  method: string
169
236
  url: string
@@ -174,15 +241,54 @@ export interface JsServerlessResponseHead {
174
241
  status: number
175
242
  headers: Record<string, string>
176
243
  }
177
- export interface JsRegistryDiagnostics {
178
- mode: string
179
- envoyActiveActorCount?: number
244
+ export interface JsApplicationResponse {
245
+ status: number
246
+ headers: Record<string, string>
247
+ body?: Buffer
248
+ stream?: boolean
249
+ }
250
+ export interface JsRegistryRouteResponse {
251
+ status: number
252
+ headers: Record<string, string>
253
+ body: Buffer
180
254
  }
181
255
  export interface JsServerlessStreamError {
182
256
  group: string
183
257
  code: string
184
258
  message: string
185
259
  }
260
+ export interface JsScheduledEventInfo {
261
+ id: string
262
+ action: string
263
+ args: Buffer
264
+ runAt: number
265
+ }
266
+ export interface JsCronJobInfo {
267
+ name: string
268
+ kind: string
269
+ action: string
270
+ args: Buffer
271
+ nextRunAt: number
272
+ lastRunAt?: number
273
+ expression?: string
274
+ timezone?: string
275
+ intervalMs?: number
276
+ maxHistory: number
277
+ }
278
+ export interface JsScheduleErrorInfo {
279
+ group: string
280
+ code: string
281
+ message: string
282
+ metadata?: any
283
+ }
284
+ export interface JsCronFire {
285
+ action: string
286
+ scheduledAt: number
287
+ firedAt: number
288
+ finishedAt?: number
289
+ result: string
290
+ error?: JsScheduleErrorInfo
291
+ }
186
292
  /** Options for KV list operations. */
187
293
  export interface JsKvListOptions {
188
294
  reverse?: boolean
@@ -195,12 +301,12 @@ export interface JsKvEntry {
195
301
  }
196
302
  /** N-API wrapper around `rivetkit-core::ActorContext`. */
197
303
  export declare class ActorContext {
198
- constructor(actorId: string, name: string, region: string)
199
304
  state(): Buffer
200
305
  beginOnStateChange(): void
201
306
  endOnStateChange(): void
202
307
  kv(): Kv
203
308
  sql(): JsNativeDatabase
309
+ provisionActorRuntimeSocket(): Promise<JsActorRuntimeSocketEndpointInfo>
204
310
  schedule(): Schedule
205
311
  queue(): Queue
206
312
  setAlarm(timestampMs?: number | undefined | null): void
@@ -215,6 +321,8 @@ export declare class ActorContext {
215
321
  takePendingHibernationChanges(): Array<string>
216
322
  dirtyHibernatableConns(): Array<ConnHandle>
217
323
  saveState(payload: StateDeltaPayload): Promise<void>
324
+ beginStateTransaction(timeoutMs?: number | undefined | null): Promise<JsActorStateTransaction>
325
+ saveStateAndWorkflowBatch(writes: Array<WorkflowKvWritePayload>): Promise<void>
218
326
  actorId(): string
219
327
  name(): string
220
328
  key(): Array<JsActorKeySegment>
@@ -228,6 +336,7 @@ export declare class ActorContext {
228
336
  aborted(): boolean
229
337
  runHandlerActive(): boolean
230
338
  restartRunHandler(): void
339
+ setRunWakeAt(timestampMs?: number | undefined | null): Promise<void>
231
340
  beginKeepAwake(): number
232
341
  endKeepAwake(regionId: number): void
233
342
  keepAwake(promise: Promise<any>): void
@@ -241,6 +350,7 @@ export declare class ActorContext {
241
350
  broadcast(name: string, args: Buffer): void
242
351
  waitUntil(promise: Promise<any>): void
243
352
  waitForTrackedShutdownWork(): Promise<boolean>
353
+ waitForTrackedShutdownWorkUnbounded(): Promise<void>
244
354
  registerTask(promise: Promise<any>): void
245
355
  runtimeState(): object
246
356
  clearRuntimeState(): void
@@ -269,8 +379,33 @@ export declare class JsNativeDatabase {
269
379
  run(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<ExecuteResult>
270
380
  query(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<QueryResult>
271
381
  execute(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<NativeExecuteResult>
382
+ executeBatch(statements: Array<JsSqliteBatchStatement>): Promise<Array<NativeExecuteResult>>
272
383
  exec(sql: string): Promise<QueryResult>
273
384
  close(): Promise<void>
385
+ beginTransaction(timeoutMs?: number | undefined | null, name?: string | undefined | null): Promise<JsSqliteTransaction>
386
+ }
387
+ export declare class JsSqliteTransaction {
388
+ execute(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<NativeExecuteResult>
389
+ exec(sql: string): Promise<QueryResult>
390
+ commit(): Promise<void>
391
+ rollback(): Promise<void>
392
+ }
393
+ export declare class JsActorStateTransaction {
394
+ execute(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<NativeExecuteResult>
395
+ commit(payload: StateDeltaPayload): Promise<void>
396
+ rollback(): Promise<void>
397
+ }
398
+ /** JavaScript-facing writer for a streaming actor HTTP response. */
399
+ export declare class HttpResponseBodyStream {
400
+ cancelled(): Promise<void>
401
+ write(chunk: Buffer): Promise<void>
402
+ end(): Promise<void>
403
+ error(message: string): Promise<void>
404
+ }
405
+ /** JavaScript-facing reader for a streaming actor HTTP request. */
406
+ export declare class HttpRequestBodyStream {
407
+ read(): Promise<Buffer | null>
408
+ cancel(): Promise<void>
274
409
  }
275
410
  export declare class Kv {
276
411
  get(key: Buffer): Promise<Buffer | null>
@@ -288,11 +423,13 @@ export declare class Queue {
288
423
  next(options?: JsQueueNextOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<QueueMessage | null>
289
424
  nextBatch(options?: JsQueueNextBatchOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<Array<QueueMessage>>
290
425
  waitForNames(names: Array<string>, options?: JsQueueWaitOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<QueueMessage>
291
- waitForNamesAvailable(names: Array<string>, options?: JsQueueWaitOptions | undefined | null): Promise<void>
426
+ waitForNamesAvailable(names: Array<string>, options?: JsQueueWaitOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<void>
427
+ completePersisted(messageId: bigint, expectedName: string, response?: Buffer | undefined | null): Promise<boolean>
292
428
  enqueueAndWait(name: string, body: Buffer, options?: JsQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<Buffer | null>
293
429
  tryNext(options?: JsQueueTryNextOptions | undefined | null): QueueMessage | null
294
430
  tryNextBatch(options?: JsQueueTryNextBatchOptions | undefined | null): Array<QueueMessage>
295
431
  maxSize(): number
432
+ reset(): Promise<void>
296
433
  inspectMessages(): Promise<Array<JsQueueInspectMessage>>
297
434
  }
298
435
  export declare class QueueMessage {
@@ -307,6 +444,13 @@ export declare class CoreRegistry {
307
444
  constructor()
308
445
  register(name: string, factory: NapiActorFactory): void
309
446
  serve(config: JsServeConfig): Promise<void>
447
+ /**
448
+ * Wait until the serverful envoy has completed its Engine registration.
449
+ *
450
+ * Readiness is the envoy client's `ToEnvoyInit` signal, not HTTP health or
451
+ * merely constructing the envoy handle.
452
+ */
453
+ waitReady(): Promise<void>
310
454
  /**
311
455
  * Trip the shutdown token and tear down any live serverless runtime.
312
456
  *
@@ -315,12 +459,26 @@ export declare class CoreRegistry {
315
459
  * separately to avoid re-entrancy.
316
460
  */
317
461
  shutdown(): Promise<void>
318
- diagnostics(): Promise<JsRegistryDiagnostics>
462
+ actorStopThresholdMs(): Promise<number | null>
463
+ health(): Promise<JsRegistryRouteResponse>
464
+ metadata(): JsRegistryRouteResponse
465
+ metrics(): JsRegistryRouteResponse
466
+ serveApplicationListener(listener: JsListenerConfig, application: (...args: any[]) => any, config: JsServeConfig): Promise<void>
467
+ serveListener(listener: JsListenerConfig, config: JsServeConfig, application?: (...args: any[]) => any | undefined | null): Promise<void>
319
468
  handleServerlessRequest(req: JsServerlessRequest, onStreamEvent: (...args: any[]) => any, cancelToken: CancellationToken, config: JsServeConfig): Promise<JsServerlessResponseHead>
320
469
  }
321
470
  export declare class Schedule {
322
- after(durationMs: number, actionName: string, args: Buffer): void
323
- at(timestampMs: number, actionName: string, args: Buffer): void
471
+ after(durationMs: number, actionName: string, args: Buffer): Promise<string>
472
+ at(timestampMs: number, actionName: string, args: Buffer): Promise<string>
473
+ cancel(id: string): Promise<boolean>
474
+ get(id: string): Promise<JsScheduledEventInfo | null>
475
+ list(): Promise<Array<JsScheduledEventInfo>>
476
+ cronSet(name: string, expression: string, timezone: string | undefined | null, actionName: string, args: Buffer, maxHistory?: number | undefined | null): Promise<void>
477
+ cronEvery(name: string, intervalMs: number, actionName: string, args: Buffer, maxHistory?: number | undefined | null): Promise<void>
478
+ cronGet(name: string): Promise<JsCronJobInfo | null>
479
+ cronList(): Promise<Array<JsCronJobInfo>>
480
+ cronDelete(name: string): Promise<boolean>
481
+ cronHistory(name: string, limit?: number | undefined | null): Promise<Array<JsCronFire>>
324
482
  }
325
483
  export declare class WebSocket {
326
484
  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.72cbc7c",
3
+ "version": "0.0.0-main.78336a1",
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.72cbc7c"
47
+ "@rivetkit/engine-envoy-protocol": "0.0.0-main.78336a1"
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.72cbc7c",
50
- "@rivetkit/rivetkit-napi-darwin-x64": "0.0.0-main.72cbc7c",
51
- "@rivetkit/rivetkit-napi-linux-arm64-gnu": "0.0.0-main.72cbc7c",
52
- "@rivetkit/rivetkit-napi-linux-arm64-musl": "0.0.0-main.72cbc7c",
53
- "@rivetkit/rivetkit-napi-linux-x64-gnu": "0.0.0-main.72cbc7c",
54
- "@rivetkit/rivetkit-napi-linux-x64-musl": "0.0.0-main.72cbc7c",
55
- "@rivetkit/rivetkit-napi-win32-x64-msvc": "0.0.0-main.72cbc7c"
55
+ "@rivetkit/rivetkit-napi-darwin-arm64": "0.0.0-main.78336a1",
56
+ "@rivetkit/rivetkit-napi-darwin-x64": "0.0.0-main.78336a1",
57
+ "@rivetkit/rivetkit-napi-linux-arm64-gnu": "0.0.0-main.78336a1",
58
+ "@rivetkit/rivetkit-napi-linux-arm64-musl": "0.0.0-main.78336a1",
59
+ "@rivetkit/rivetkit-napi-linux-x64-gnu": "0.0.0-main.78336a1",
60
+ "@rivetkit/rivetkit-napi-linux-x64-musl": "0.0.0-main.78336a1"
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" });