@rivetkit/rivetkit-napi 0.0.0-main.337772d → 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,11 +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
54
78
  remoteSqlite?: boolean
79
+ enableActorRuntimeSocket?: boolean
55
80
  hasState?: boolean
56
81
  canHibernateWebsocket?: boolean
57
82
  stateSaveIntervalMs?: number
@@ -72,12 +97,12 @@ export interface JsActorConfig {
72
97
  connectionLivenessTimeoutMs?: number
73
98
  connectionLivenessIntervalMs?: number
74
99
  maxQueueSize?: number
100
+ maxSchedules?: number
75
101
  maxQueueMessageSize?: number
76
102
  maxIncomingMessageSize?: number
77
103
  maxOutgoingMessageSize?: number
78
- preloadMaxWorkflowBytes?: number
79
- preloadMaxConnectionsBytes?: number
80
104
  actions?: Array<JsActionDefinition>
105
+ inspectorTabs?: Array<JsInspectorTabEntry>
81
106
  }
82
107
  export interface JsBindParam {
83
108
  kind: string
@@ -99,6 +124,10 @@ export interface NativeExecuteResult {
99
124
  changes: number
100
125
  lastInsertRowId?: number
101
126
  }
127
+ export interface JsSqliteBatchStatement {
128
+ sql: string
129
+ params?: Array<JsBindParam>
130
+ }
102
131
  export interface JsSqliteVfsMetrics {
103
132
  requestBuildNs: number
104
133
  serializeNs: number
@@ -112,6 +141,12 @@ export interface JsSqliteVfsMetrics {
112
141
  writeBufferDirtyPages: number
113
142
  dbSizePages: number
114
143
  }
144
+ export interface JsHttpResponse {
145
+ status?: number
146
+ headers?: Record<string, string>
147
+ body?: Buffer
148
+ stream?: boolean
149
+ }
115
150
  export interface JsQueueNextOptions {
116
151
  names?: Array<string>
117
152
  timeoutMs?: number
@@ -155,6 +190,8 @@ export interface JsServeConfig {
155
190
  namespace: string
156
191
  poolName: string
157
192
  engineBinaryPath?: string
193
+ engineHost?: string
194
+ enginePort?: number
158
195
  handleInspectorHttpInRuntime?: boolean
159
196
  serverlessBasePath?: string
160
197
  serverlessPackageVersion: string
@@ -164,6 +201,16 @@ export interface JsServeConfig {
164
201
  serverlessValidateEndpoint: boolean
165
202
  serverlessMaxStartPayloadBytes: number
166
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
+ }
167
214
  export interface JsServerlessRequest {
168
215
  method: string
169
216
  url: string
@@ -174,15 +221,54 @@ export interface JsServerlessResponseHead {
174
221
  status: number
175
222
  headers: Record<string, string>
176
223
  }
177
- export interface JsRegistryDiagnostics {
178
- mode: string
179
- envoyActiveActorCount?: number
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
180
234
  }
181
235
  export interface JsServerlessStreamError {
182
236
  group: string
183
237
  code: string
184
238
  message: string
185
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
+ }
186
272
  /** Options for KV list operations. */
187
273
  export interface JsKvListOptions {
188
274
  reverse?: boolean
@@ -195,12 +281,12 @@ export interface JsKvEntry {
195
281
  }
196
282
  /** N-API wrapper around `rivetkit-core::ActorContext`. */
197
283
  export declare class ActorContext {
198
- constructor(actorId: string, name: string, region: string)
199
284
  state(): Buffer
200
285
  beginOnStateChange(): void
201
286
  endOnStateChange(): void
202
287
  kv(): Kv
203
288
  sql(): JsNativeDatabase
289
+ provisionActorRuntimeSocket(): Promise<JsActorRuntimeSocketEndpointInfo>
204
290
  schedule(): Schedule
205
291
  queue(): Queue
206
292
  setAlarm(timestampMs?: number | undefined | null): void
@@ -215,6 +301,7 @@ export declare class ActorContext {
215
301
  takePendingHibernationChanges(): Array<string>
216
302
  dirtyHibernatableConns(): Array<ConnHandle>
217
303
  saveState(payload: StateDeltaPayload): Promise<void>
304
+ saveStateAndWorkflowBatch(writes: Array<WorkflowKvWritePayload>): Promise<void>
218
305
  actorId(): string
219
306
  name(): string
220
307
  key(): Array<JsActorKeySegment>
@@ -240,6 +327,8 @@ export declare class ActorContext {
240
327
  disconnectConns(predicate: (...args: any[]) => any): Promise<void>
241
328
  broadcast(name: string, args: Buffer): void
242
329
  waitUntil(promise: Promise<any>): void
330
+ waitForTrackedShutdownWork(): Promise<boolean>
331
+ waitForTrackedShutdownWorkUnbounded(): Promise<void>
243
332
  registerTask(promise: Promise<any>): void
244
333
  runtimeState(): object
245
334
  clearRuntimeState(): void
@@ -268,8 +357,28 @@ export declare class JsNativeDatabase {
268
357
  run(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<ExecuteResult>
269
358
  query(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<QueryResult>
270
359
  execute(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<NativeExecuteResult>
360
+ executeBatch(statements: Array<JsSqliteBatchStatement>): Promise<Array<NativeExecuteResult>>
271
361
  exec(sql: string): Promise<QueryResult>
272
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>
273
382
  }
274
383
  export declare class Kv {
275
384
  get(key: Buffer): Promise<Buffer | null>
@@ -287,11 +396,12 @@ export declare class Queue {
287
396
  next(options?: JsQueueNextOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<QueueMessage | null>
288
397
  nextBatch(options?: JsQueueNextBatchOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<Array<QueueMessage>>
289
398
  waitForNames(names: Array<string>, options?: JsQueueWaitOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<QueueMessage>
290
- 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>
291
400
  enqueueAndWait(name: string, body: Buffer, options?: JsQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<Buffer | null>
292
401
  tryNext(options?: JsQueueTryNextOptions | undefined | null): QueueMessage | null
293
402
  tryNextBatch(options?: JsQueueTryNextBatchOptions | undefined | null): Array<QueueMessage>
294
403
  maxSize(): number
404
+ reset(): Promise<void>
295
405
  inspectMessages(): Promise<Array<JsQueueInspectMessage>>
296
406
  }
297
407
  export declare class QueueMessage {
@@ -306,6 +416,13 @@ export declare class CoreRegistry {
306
416
  constructor()
307
417
  register(name: string, factory: NapiActorFactory): void
308
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>
309
426
  /**
310
427
  * Trip the shutdown token and tear down any live serverless runtime.
311
428
  *
@@ -314,12 +431,26 @@ export declare class CoreRegistry {
314
431
  * separately to avoid re-entrancy.
315
432
  */
316
433
  shutdown(): Promise<void>
317
- diagnostics(): Promise<JsRegistryDiagnostics>
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>
318
440
  handleServerlessRequest(req: JsServerlessRequest, onStreamEvent: (...args: any[]) => any, cancelToken: CancellationToken, config: JsServeConfig): Promise<JsServerlessResponseHead>
319
441
  }
320
442
  export declare class Schedule {
321
- after(durationMs: number, actionName: string, args: Buffer): void
322
- 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>>
323
454
  }
324
455
  export declare class WebSocket {
325
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.337772d",
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.337772d"
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.337772d",
50
- "@rivetkit/rivetkit-napi-darwin-x64": "0.0.0-main.337772d",
51
- "@rivetkit/rivetkit-napi-linux-arm64-gnu": "0.0.0-main.337772d",
52
- "@rivetkit/rivetkit-napi-linux-arm64-musl": "0.0.0-main.337772d",
53
- "@rivetkit/rivetkit-napi-linux-x64-gnu": "0.0.0-main.337772d",
54
- "@rivetkit/rivetkit-napi-linux-x64-musl": "0.0.0-main.337772d",
55
- "@rivetkit/rivetkit-napi-win32-x64-msvc": "0.0.0-main.337772d"
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" });