@rivetkit/rivetkit-napi 0.0.0-main.41efcce → 0.0.0-main.4994268

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,32 @@ 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
+ }
50
74
  export interface JsActorConfig {
51
75
  name?: string
52
76
  icon?: string
53
77
  hasDatabase?: boolean
78
+ remoteSqlite?: boolean
79
+ enableActorRuntimeSocket?: boolean
54
80
  hasState?: boolean
55
81
  canHibernateWebsocket?: boolean
56
82
  stateSaveIntervalMs?: number
@@ -71,12 +97,12 @@ export interface JsActorConfig {
71
97
  connectionLivenessTimeoutMs?: number
72
98
  connectionLivenessIntervalMs?: number
73
99
  maxQueueSize?: number
100
+ maxSchedules?: number
74
101
  maxQueueMessageSize?: number
75
102
  maxIncomingMessageSize?: number
76
103
  maxOutgoingMessageSize?: number
77
- preloadMaxWorkflowBytes?: number
78
- preloadMaxConnectionsBytes?: number
79
104
  actions?: Array<JsActionDefinition>
105
+ inspectorTabs?: Array<JsInspectorTabEntry>
80
106
  }
81
107
  export interface JsBindParam {
82
108
  kind: string
@@ -92,6 +118,16 @@ export interface QueryResult {
92
118
  columns: Array<string>
93
119
  rows: Array<Array<any>>
94
120
  }
121
+ export interface NativeExecuteResult {
122
+ columns: Array<string>
123
+ rows: Array<Array<any>>
124
+ changes: number
125
+ lastInsertRowId?: number
126
+ }
127
+ export interface JsSqliteBatchStatement {
128
+ sql: string
129
+ params?: Array<JsBindParam>
130
+ }
95
131
  export interface JsSqliteVfsMetrics {
96
132
  requestBuildNs: number
97
133
  serializeNs: number
@@ -99,6 +135,17 @@ export interface JsSqliteVfsMetrics {
99
135
  stateUpdateNs: number
100
136
  totalNs: number
101
137
  commitCount: number
138
+ pageCacheEntries: number
139
+ pageCacheWeightedSize: number
140
+ pageCacheCapacityPages: number
141
+ writeBufferDirtyPages: number
142
+ dbSizePages: number
143
+ }
144
+ export interface JsHttpResponse {
145
+ status?: number
146
+ headers?: Record<string, string>
147
+ body?: Buffer
148
+ stream?: boolean
102
149
  }
103
150
  export interface JsQueueNextOptions {
104
151
  names?: Array<string>
@@ -143,6 +190,8 @@ export interface JsServeConfig {
143
190
  namespace: string
144
191
  poolName: string
145
192
  engineBinaryPath?: string
193
+ engineHost?: string
194
+ enginePort?: number
146
195
  handleInspectorHttpInRuntime?: boolean
147
196
  serverlessBasePath?: string
148
197
  serverlessPackageVersion: string
@@ -152,6 +201,16 @@ export interface JsServeConfig {
152
201
  serverlessValidateEndpoint: boolean
153
202
  serverlessMaxStartPayloadBytes: number
154
203
  }
204
+ export interface JsListenerConfig {
205
+ /** Host to bind. Defaults to `0.0.0.0` when not provided. */
206
+ host?: string
207
+ port: number
208
+ /**
209
+ * Optional static file root mounted as a fallback below the framework
210
+ * routes.
211
+ */
212
+ publicDir?: string
213
+ }
155
214
  export interface JsServerlessRequest {
156
215
  method: string
157
216
  url: string
@@ -162,11 +221,54 @@ export interface JsServerlessResponseHead {
162
221
  status: number
163
222
  headers: Record<string, string>
164
223
  }
224
+ export interface JsApplicationResponse {
225
+ status: number
226
+ headers: Record<string, string>
227
+ body?: Buffer
228
+ stream?: boolean
229
+ }
230
+ export interface JsRegistryRouteResponse {
231
+ status: number
232
+ headers: Record<string, string>
233
+ body: Buffer
234
+ }
165
235
  export interface JsServerlessStreamError {
166
236
  group: string
167
237
  code: string
168
238
  message: string
169
239
  }
240
+ export interface JsScheduledEventInfo {
241
+ id: string
242
+ action: string
243
+ args: Buffer
244
+ runAt: number
245
+ }
246
+ export interface JsCronJobInfo {
247
+ name: string
248
+ kind: string
249
+ action: string
250
+ args: Buffer
251
+ nextRunAt: number
252
+ lastRunAt?: number
253
+ expression?: string
254
+ timezone?: string
255
+ intervalMs?: number
256
+ maxHistory: number
257
+ }
258
+ export interface JsScheduleErrorInfo {
259
+ group: string
260
+ code: string
261
+ message: string
262
+ metadata?: any
263
+ }
264
+ export interface JsCronFire {
265
+ action: string
266
+ scheduledAt: number
267
+ firedAt: number
268
+ finishedAt?: number
269
+ result: string
270
+ error?: JsScheduleErrorInfo
271
+ }
170
272
  /** Options for KV list operations. */
171
273
  export interface JsKvListOptions {
172
274
  reverse?: boolean
@@ -179,12 +281,12 @@ export interface JsKvEntry {
179
281
  }
180
282
  /** N-API wrapper around `rivetkit-core::ActorContext`. */
181
283
  export declare class ActorContext {
182
- constructor(actorId: string, name: string, region: string)
183
284
  state(): Buffer
184
285
  beginOnStateChange(): void
185
286
  endOnStateChange(): void
186
287
  kv(): Kv
187
288
  sql(): JsNativeDatabase
289
+ provisionActorRuntimeSocket(): Promise<JsActorRuntimeSocketEndpointInfo>
188
290
  schedule(): Schedule
189
291
  queue(): Queue
190
292
  setAlarm(timestampMs?: number | undefined | null): void
@@ -199,6 +301,7 @@ export declare class ActorContext {
199
301
  takePendingHibernationChanges(): Array<string>
200
302
  dirtyHibernatableConns(): Array<ConnHandle>
201
303
  saveState(payload: StateDeltaPayload): Promise<void>
304
+ saveStateAndWorkflowBatch(writes: Array<WorkflowKvWritePayload>): Promise<void>
202
305
  actorId(): string
203
306
  name(): string
204
307
  key(): Array<JsActorKeySegment>
@@ -212,6 +315,9 @@ export declare class ActorContext {
212
315
  aborted(): boolean
213
316
  runHandlerActive(): boolean
214
317
  restartRunHandler(): void
318
+ beginKeepAwake(): number
319
+ endKeepAwake(regionId: number): void
320
+ keepAwake(promise: Promise<any>): void
215
321
  beginWebsocketCallback(): number
216
322
  endWebsocketCallback(regionId: number): void
217
323
  abortSignal(): AbortSignal
@@ -221,7 +327,8 @@ export declare class ActorContext {
221
327
  disconnectConns(predicate: (...args: any[]) => any): Promise<void>
222
328
  broadcast(name: string, args: Buffer): void
223
329
  waitUntil(promise: Promise<any>): void
224
- keepAwake(promise: Promise<any>): Promise<any>
330
+ waitForTrackedShutdownWork(): Promise<boolean>
331
+ waitForTrackedShutdownWorkUnbounded(): Promise<void>
225
332
  registerTask(promise: Promise<any>): void
226
333
  runtimeState(): object
227
334
  clearRuntimeState(): void
@@ -246,11 +353,32 @@ export declare class ConnHandle {
246
353
  }
247
354
  export declare class JsNativeDatabase {
248
355
  takeLastKvError(): string | null
249
- getSqliteVfsMetrics(): JsSqliteVfsMetrics | null
356
+ metrics(): JsSqliteVfsMetrics | null
250
357
  run(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<ExecuteResult>
251
358
  query(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<QueryResult>
359
+ execute(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<NativeExecuteResult>
360
+ executeBatch(statements: Array<JsSqliteBatchStatement>): Promise<Array<NativeExecuteResult>>
252
361
  exec(sql: string): Promise<QueryResult>
253
362
  close(): Promise<void>
363
+ beginTransaction(timeoutMs?: number | undefined | null): Promise<JsSqliteTransaction>
364
+ }
365
+ export declare class JsSqliteTransaction {
366
+ execute(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<NativeExecuteResult>
367
+ exec(sql: string): Promise<QueryResult>
368
+ commit(): Promise<void>
369
+ rollback(): Promise<void>
370
+ }
371
+ /** JavaScript-facing writer for a streaming actor HTTP response. */
372
+ export declare class HttpResponseBodyStream {
373
+ cancelled(): Promise<void>
374
+ write(chunk: Buffer): Promise<void>
375
+ end(): Promise<void>
376
+ error(message: string): Promise<void>
377
+ }
378
+ /** JavaScript-facing reader for a streaming actor HTTP request. */
379
+ export declare class HttpRequestBodyStream {
380
+ read(): Promise<Buffer | null>
381
+ cancel(): Promise<void>
254
382
  }
255
383
  export declare class Kv {
256
384
  get(key: Buffer): Promise<Buffer | null>
@@ -268,11 +396,12 @@ export declare class Queue {
268
396
  next(options?: JsQueueNextOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<QueueMessage | null>
269
397
  nextBatch(options?: JsQueueNextBatchOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<Array<QueueMessage>>
270
398
  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>
399
+ waitForNamesAvailable(names: Array<string>, options?: JsQueueWaitOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<void>
272
400
  enqueueAndWait(name: string, body: Buffer, options?: JsQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<Buffer | null>
273
401
  tryNext(options?: JsQueueTryNextOptions | undefined | null): QueueMessage | null
274
402
  tryNextBatch(options?: JsQueueTryNextBatchOptions | undefined | null): Array<QueueMessage>
275
403
  maxSize(): number
404
+ reset(): Promise<void>
276
405
  inspectMessages(): Promise<Array<JsQueueInspectMessage>>
277
406
  }
278
407
  export declare class QueueMessage {
@@ -287,6 +416,13 @@ export declare class CoreRegistry {
287
416
  constructor()
288
417
  register(name: string, factory: NapiActorFactory): void
289
418
  serve(config: JsServeConfig): Promise<void>
419
+ /**
420
+ * Wait until the serverful envoy has completed its Engine registration.
421
+ *
422
+ * Readiness is the envoy client's `ToEnvoyInit` signal, not HTTP health or
423
+ * merely constructing the envoy handle.
424
+ */
425
+ waitReady(): Promise<void>
290
426
  /**
291
427
  * Trip the shutdown token and tear down any live serverless runtime.
292
428
  *
@@ -295,11 +431,26 @@ export declare class CoreRegistry {
295
431
  * separately to avoid re-entrancy.
296
432
  */
297
433
  shutdown(): Promise<void>
434
+ actorStopThresholdMs(): Promise<number | null>
435
+ health(): Promise<JsRegistryRouteResponse>
436
+ metadata(): JsRegistryRouteResponse
437
+ metrics(): JsRegistryRouteResponse
438
+ serveApplicationListener(listener: JsListenerConfig, application: (...args: any[]) => any, config: JsServeConfig): Promise<void>
439
+ serveListener(listener: JsListenerConfig, config: JsServeConfig, application?: (...args: any[]) => any | undefined | null): Promise<void>
298
440
  handleServerlessRequest(req: JsServerlessRequest, onStreamEvent: (...args: any[]) => any, cancelToken: CancellationToken, config: JsServeConfig): Promise<JsServerlessResponseHead>
299
441
  }
300
442
  export declare class Schedule {
301
- after(durationMs: number, actionName: string, args: Buffer): void
302
- at(timestampMs: number, actionName: string, args: Buffer): void
443
+ after(durationMs: number, actionName: string, args: Buffer): Promise<string>
444
+ at(timestampMs: number, actionName: string, args: Buffer): Promise<string>
445
+ cancel(id: string): Promise<boolean>
446
+ get(id: string): Promise<JsScheduledEventInfo | null>
447
+ list(): Promise<Array<JsScheduledEventInfo>>
448
+ cronSet(name: string, expression: string, timezone: string | undefined | null, actionName: string, args: Buffer, maxHistory?: number | undefined | null): Promise<void>
449
+ cronEvery(name: string, intervalMs: number, actionName: string, args: Buffer, maxHistory?: number | undefined | null): Promise<void>
450
+ cronGet(name: string): Promise<JsCronJobInfo | null>
451
+ cronList(): Promise<Array<JsCronJobInfo>>
452
+ cronDelete(name: string): Promise<boolean>
453
+ cronHistory(name: string, limit?: number | undefined | null): Promise<Array<JsCronFire>>
303
454
  }
304
455
  export declare class WebSocket {
305
456
  send(data: Buffer, binary: boolean): void
package/index.js CHANGED
@@ -310,13 +310,18 @@ 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, 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.HttpResponseBodyStream = HttpResponseBodyStream
324
+ module.exports.HttpRequestBodyStream = HttpRequestBodyStream
320
325
  module.exports.Kv = Kv
321
326
  module.exports.Queue = Queue
322
327
  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.4994268",
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,19 @@
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.4994268"
47
48
  },
48
49
  "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"
50
+ "@rivetkit/rivetkit-napi-darwin-arm64": "0.0.0-main.4994268",
51
+ "@rivetkit/rivetkit-napi-darwin-x64": "0.0.0-main.4994268",
52
+ "@rivetkit/rivetkit-napi-linux-arm64-gnu": "0.0.0-main.4994268",
53
+ "@rivetkit/rivetkit-napi-linux-arm64-musl": "0.0.0-main.4994268",
54
+ "@rivetkit/rivetkit-napi-linux-x64-gnu": "0.0.0-main.4994268",
55
+ "@rivetkit/rivetkit-napi-linux-x64-musl": "0.0.0-main.4994268"
56
56
  }
57
57
  }
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" });