@rivetkit/supabase 2.3.12-rc.4 → 2.3.12
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/dist/mod.js +396 -160
- package/dist/mod.mjs +396 -160
- package/package.json +3 -3
package/dist/mod.js
CHANGED
|
@@ -335,7 +335,7 @@ __export(mod_exports, {
|
|
|
335
335
|
module.exports = __toCommonJS(mod_exports);
|
|
336
336
|
var wasmBindings = __toESM(require("@rivetkit/rivetkit-wasm"));
|
|
337
337
|
|
|
338
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
338
|
+
// ../rivetkit/dist/tsup/chunk-OUQUIBVW.js
|
|
339
339
|
var INTERNAL_ERROR_CODE = "internal_error";
|
|
340
340
|
var INTERNAL_ERROR_DESCRIPTION = "An internal error occurred";
|
|
341
341
|
var USER_ERROR_CODE = "user_error";
|
|
@@ -519,7 +519,7 @@ function unsupportedFeature(feature) {
|
|
|
519
519
|
);
|
|
520
520
|
}
|
|
521
521
|
|
|
522
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
522
|
+
// ../rivetkit/dist/tsup/chunk-MF42PRF2.js
|
|
523
523
|
var import_pino = require("pino");
|
|
524
524
|
|
|
525
525
|
// ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/classic/external.js
|
|
@@ -13192,7 +13192,7 @@ var classic_default = external_exports;
|
|
|
13192
13192
|
// ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/index.js
|
|
13193
13193
|
var v4_default = classic_default;
|
|
13194
13194
|
|
|
13195
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
13195
|
+
// ../rivetkit/dist/tsup/chunk-MF42PRF2.js
|
|
13196
13196
|
var cbor = __toESM(require("cbor-x"), 1);
|
|
13197
13197
|
var import_invariant = __toESM(require_invariant(), 1);
|
|
13198
13198
|
var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
|
|
@@ -13211,6 +13211,10 @@ var getRivetRunEnginePort = () => {
|
|
|
13211
13211
|
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13212
13212
|
};
|
|
13213
13213
|
var getRivetRunEngineVersion = () => getEnvUniversal("RIVET_RUN_ENGINE_VERSION");
|
|
13214
|
+
var getRivetRunServices = () => {
|
|
13215
|
+
const value = getEnvUniversal("RIVET_RUN_SERVICES");
|
|
13216
|
+
return value === void 0 ? void 0 : value === "1";
|
|
13217
|
+
};
|
|
13214
13218
|
var getRivetEnvoyVersion = () => {
|
|
13215
13219
|
const value = getEnvUniversal("RIVET_ENVOY_VERSION");
|
|
13216
13220
|
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
@@ -13362,7 +13366,7 @@ function noopNext() {
|
|
|
13362
13366
|
}
|
|
13363
13367
|
var package_default = {
|
|
13364
13368
|
name: "rivetkit",
|
|
13365
|
-
version: "2.3.12
|
|
13369
|
+
version: "2.3.12",
|
|
13366
13370
|
description: "Lightweight libraries for building stateful actors on edge platforms",
|
|
13367
13371
|
license: "Apache-2.0",
|
|
13368
13372
|
keywords: [
|
|
@@ -13572,6 +13576,7 @@ var package_default = {
|
|
|
13572
13576
|
dependencies: {
|
|
13573
13577
|
"@hono/zod-openapi": "^1.1.5",
|
|
13574
13578
|
"@rivet-dev/agent-os-core": "^0.1.1",
|
|
13579
|
+
"@rivet-dev/services": "^0.1.3",
|
|
13575
13580
|
"@rivetkit/bare-ts": "^0.6.2",
|
|
13576
13581
|
"@rivetkit/engine-cli": "workspace:*",
|
|
13577
13582
|
"@rivetkit/engine-envoy-protocol": "workspace:*",
|
|
@@ -14665,7 +14670,7 @@ function Config({ initialBufferLength = 1024, maxBufferLength = 1024 * 1024 * 32
|
|
|
14665
14670
|
};
|
|
14666
14671
|
}
|
|
14667
14672
|
|
|
14668
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
14673
|
+
// ../rivetkit/dist/tsup/chunk-GEN4NHXM.js
|
|
14669
14674
|
var config2 = /* @__PURE__ */ Config({});
|
|
14670
14675
|
function readWorkflowCbor(bc) {
|
|
14671
14676
|
return readData(bc);
|
|
@@ -14963,7 +14968,7 @@ function decodeWorkflowHistoryTransport(data) {
|
|
|
14963
14968
|
return decodeWorkflowHistory(toUint8Array(data));
|
|
14964
14969
|
}
|
|
14965
14970
|
|
|
14966
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
14971
|
+
// ../rivetkit/dist/tsup/chunk-6W5VGLFT.js
|
|
14967
14972
|
function flattenActionHandlers(actions) {
|
|
14968
14973
|
const flattened = /* @__PURE__ */ Object.create(null);
|
|
14969
14974
|
for (const { name, handler } of collectActionEntries(actions)) {
|
|
@@ -15045,7 +15050,6 @@ function formatActionPath(path2) {
|
|
|
15045
15050
|
return path2.length === 0 ? "actions" : `Action \`${path2.join(".")}\``;
|
|
15046
15051
|
}
|
|
15047
15052
|
var DEFAULT_SLEEP_GRACE_PERIOD = 15e3;
|
|
15048
|
-
var DEFAULT_MAX_ACTIONS = 128;
|
|
15049
15053
|
var ACTOR_CONTEXT_INTERNAL_SYMBOL = /* @__PURE__ */ Symbol(
|
|
15050
15054
|
"rivetkit.actor_context_internal"
|
|
15051
15055
|
);
|
|
@@ -15212,8 +15216,6 @@ var GlobalActorOptionsBaseSchema = external_exports.object({
|
|
|
15212
15216
|
name: external_exports.string().optional(),
|
|
15213
15217
|
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
15214
15218
|
icon: external_exports.string().optional(),
|
|
15215
|
-
/** Maximum number of action handlers that may be defined on this actor. */
|
|
15216
|
-
maxActions: external_exports.number().int().nonnegative().default(DEFAULT_MAX_ACTIONS),
|
|
15217
15219
|
/** Enables the experimental Actor Runtime Socket for this actor. */
|
|
15218
15220
|
enableActorRuntimeSocket: external_exports.boolean().default(false),
|
|
15219
15221
|
/**
|
|
@@ -15305,26 +15307,12 @@ var ActorConfigSchema = external_exports.object({
|
|
|
15305
15307
|
message: "Cannot define both 'vars' and 'createVars'",
|
|
15306
15308
|
path: ["vars"]
|
|
15307
15309
|
}
|
|
15308
|
-
)
|
|
15309
|
-
const actionCount = Object.keys(
|
|
15310
|
-
flattenActionHandlers(data.actions)
|
|
15311
|
-
).length;
|
|
15312
|
-
if (actionCount > data.options.maxActions) {
|
|
15313
|
-
ctx.addIssue({
|
|
15314
|
-
code: "custom",
|
|
15315
|
-
message: `Actor defines ${actionCount} actions, but maxActions is ${data.options.maxActions}`,
|
|
15316
|
-
path: ["actions"]
|
|
15317
|
-
});
|
|
15318
|
-
}
|
|
15319
|
-
});
|
|
15310
|
+
);
|
|
15320
15311
|
var DocActorOptionsSchema = external_exports.object({
|
|
15321
15312
|
name: external_exports.string().optional().describe("Display name for the actor in the Inspector UI."),
|
|
15322
15313
|
icon: external_exports.string().optional().describe(
|
|
15323
15314
|
"Icon for the actor in the Inspector UI. Can be an emoji (e.g., '\u{1F680}') or FontAwesome icon name (e.g., 'rocket')."
|
|
15324
15315
|
),
|
|
15325
|
-
maxActions: external_exports.number().int().nonnegative().optional().describe(
|
|
15326
|
-
`Maximum number of action handlers that may be defined on this actor. Default: ${DEFAULT_MAX_ACTIONS}`
|
|
15327
|
-
),
|
|
15328
15316
|
enableActorRuntimeSocket: external_exports.boolean().optional().describe(
|
|
15329
15317
|
"Enables the experimental Actor Runtime Socket for this actor. Default: false"
|
|
15330
15318
|
),
|
|
@@ -15561,6 +15549,44 @@ function removePrefixFromKey(prefixedKey) {
|
|
|
15561
15549
|
return prefixedKey.slice(KEYS.KV.length);
|
|
15562
15550
|
}
|
|
15563
15551
|
|
|
15552
|
+
// ../rivetkit/dist/tsup/chunk-JYTXOMM7.js
|
|
15553
|
+
function logger() {
|
|
15554
|
+
return getLogger("actor-client");
|
|
15555
|
+
}
|
|
15556
|
+
var webSocketPromise = null;
|
|
15557
|
+
async function importWebSocket() {
|
|
15558
|
+
if (webSocketPromise !== null) {
|
|
15559
|
+
return webSocketPromise;
|
|
15560
|
+
}
|
|
15561
|
+
webSocketPromise = (async () => {
|
|
15562
|
+
let _WebSocket;
|
|
15563
|
+
if (typeof WebSocket !== "undefined") {
|
|
15564
|
+
_WebSocket = WebSocket;
|
|
15565
|
+
} else {
|
|
15566
|
+
try {
|
|
15567
|
+
const moduleName = "ws";
|
|
15568
|
+
const ws = await import(
|
|
15569
|
+
/* webpackIgnore: true */
|
|
15570
|
+
moduleName
|
|
15571
|
+
);
|
|
15572
|
+
_WebSocket = ws.default;
|
|
15573
|
+
logger().debug("using websocket from npm");
|
|
15574
|
+
} catch {
|
|
15575
|
+
_WebSocket = class MockWebSocket {
|
|
15576
|
+
constructor() {
|
|
15577
|
+
throw new Error(
|
|
15578
|
+
'WebSocket support requires installing the "ws" peer dependency.'
|
|
15579
|
+
);
|
|
15580
|
+
}
|
|
15581
|
+
};
|
|
15582
|
+
logger().debug("using mock websocket");
|
|
15583
|
+
}
|
|
15584
|
+
}
|
|
15585
|
+
return _WebSocket;
|
|
15586
|
+
})();
|
|
15587
|
+
return webSocketPromise;
|
|
15588
|
+
}
|
|
15589
|
+
|
|
15564
15590
|
// ../rivetkit/dist/tsup/chunk-JTHHCZCZ.js
|
|
15565
15591
|
var MIGRATION_TRANSACTION_TIMEOUT_MS = 5 * 6e4;
|
|
15566
15592
|
function isManualTransactionControl(query) {
|
|
@@ -15644,45 +15670,7 @@ var AsyncMutex = class {
|
|
|
15644
15670
|
}
|
|
15645
15671
|
};
|
|
15646
15672
|
|
|
15647
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15648
|
-
function logger() {
|
|
15649
|
-
return getLogger("actor-client");
|
|
15650
|
-
}
|
|
15651
|
-
var webSocketPromise = null;
|
|
15652
|
-
async function importWebSocket() {
|
|
15653
|
-
if (webSocketPromise !== null) {
|
|
15654
|
-
return webSocketPromise;
|
|
15655
|
-
}
|
|
15656
|
-
webSocketPromise = (async () => {
|
|
15657
|
-
let _WebSocket;
|
|
15658
|
-
if (typeof WebSocket !== "undefined") {
|
|
15659
|
-
_WebSocket = WebSocket;
|
|
15660
|
-
} else {
|
|
15661
|
-
try {
|
|
15662
|
-
const moduleName = "ws";
|
|
15663
|
-
const ws = await import(
|
|
15664
|
-
/* webpackIgnore: true */
|
|
15665
|
-
moduleName
|
|
15666
|
-
);
|
|
15667
|
-
_WebSocket = ws.default;
|
|
15668
|
-
logger().debug("using websocket from npm");
|
|
15669
|
-
} catch {
|
|
15670
|
-
_WebSocket = class MockWebSocket {
|
|
15671
|
-
constructor() {
|
|
15672
|
-
throw new Error(
|
|
15673
|
-
'WebSocket support requires installing the "ws" peer dependency.'
|
|
15674
|
-
);
|
|
15675
|
-
}
|
|
15676
|
-
};
|
|
15677
|
-
logger().debug("using mock websocket");
|
|
15678
|
-
}
|
|
15679
|
-
}
|
|
15680
|
-
return _WebSocket;
|
|
15681
|
-
})();
|
|
15682
|
-
return webSocketPromise;
|
|
15683
|
-
}
|
|
15684
|
-
|
|
15685
|
-
// ../rivetkit/dist/tsup/chunk-O74736N5.js
|
|
15673
|
+
// ../rivetkit/dist/tsup/chunk-VOYNLY57.js
|
|
15686
15674
|
var import_invariant2 = __toESM(require_invariant(), 1);
|
|
15687
15675
|
|
|
15688
15676
|
// ../../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
|
|
@@ -15860,7 +15848,7 @@ function createVersionedDataHandler(config3) {
|
|
|
15860
15848
|
return new VersionedDataHandler(config3);
|
|
15861
15849
|
}
|
|
15862
15850
|
|
|
15863
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15851
|
+
// ../rivetkit/dist/tsup/chunk-VOYNLY57.js
|
|
15864
15852
|
var import_invariant3 = __toESM(require_invariant(), 1);
|
|
15865
15853
|
var import_invariant4 = __toESM(require_invariant(), 1);
|
|
15866
15854
|
var PATH_CONNECT = "/connect";
|
|
@@ -15869,6 +15857,7 @@ var PATH_WEBSOCKET_PREFIX = "/websocket/";
|
|
|
15869
15857
|
var HEADER_ACTOR_QUERY = "x-rivet-query";
|
|
15870
15858
|
var HEADER_ENCODING = "x-rivet-encoding";
|
|
15871
15859
|
var HEADER_CONN_PARAMS = "x-rivet-conn-params";
|
|
15860
|
+
var HEADER_ORIGINAL_REQUEST_URL = "x-rivet-internal-original-request-url";
|
|
15872
15861
|
var HEADER_ACTOR_ID = "x-rivet-actor";
|
|
15873
15862
|
var HEADER_ACTOR_GENERATION = "x-rivet-actor-generation";
|
|
15874
15863
|
var HEADER_ACTOR_KEY = "x-rivet-actor-key";
|
|
@@ -17927,6 +17916,18 @@ async function checkForSchedulingError(group, code, actorId, query, driver, rayI
|
|
|
17927
17916
|
}
|
|
17928
17917
|
return null;
|
|
17929
17918
|
}
|
|
17919
|
+
function isUrlLike(value) {
|
|
17920
|
+
return typeof value === "object" && value !== null && typeof value.href === "string" && typeof value.pathname === "string" && typeof value.search === "string";
|
|
17921
|
+
}
|
|
17922
|
+
function isRequestLike(value) {
|
|
17923
|
+
return typeof value === "object" && value !== null && typeof value.url === "string" && typeof value.method === "string" && isHeadersLike(value.headers);
|
|
17924
|
+
}
|
|
17925
|
+
function isResponseLike(value) {
|
|
17926
|
+
return typeof value === "object" && value !== null && typeof value.status === "number" && isHeadersLike(value.headers) && typeof value.arrayBuffer === "function";
|
|
17927
|
+
}
|
|
17928
|
+
function isHeadersLike(value) {
|
|
17929
|
+
return typeof value === "object" && value !== null && typeof value.entries === "function";
|
|
17930
|
+
}
|
|
17930
17931
|
function* walkErrorChain(error46, maxDepth = 8) {
|
|
17931
17932
|
let current = error46;
|
|
17932
17933
|
let depth = 0;
|
|
@@ -18352,28 +18353,19 @@ function createQueueSender(senderOptions) {
|
|
|
18352
18353
|
send
|
|
18353
18354
|
};
|
|
18354
18355
|
}
|
|
18355
|
-
function isUrlLike(value) {
|
|
18356
|
-
return typeof value === "object" && value !== null && typeof value.href === "string" && typeof value.pathname === "string" && typeof value.search === "string";
|
|
18357
|
-
}
|
|
18358
|
-
function isRequestLike(value) {
|
|
18359
|
-
return typeof value === "object" && value !== null && typeof value.url === "string" && typeof value.method === "string" && isHeadersLike(value.headers);
|
|
18360
|
-
}
|
|
18361
|
-
function isResponseLike(value) {
|
|
18362
|
-
return typeof value === "object" && value !== null && typeof value.status === "number" && isHeadersLike(value.headers) && typeof value.arrayBuffer === "function";
|
|
18363
|
-
}
|
|
18364
|
-
function isHeadersLike(value) {
|
|
18365
|
-
return typeof value === "object" && value !== null && typeof value.entries === "function";
|
|
18366
|
-
}
|
|
18367
18356
|
async function rawHttpFetch(driver, target, params, input, init, options = {}) {
|
|
18368
18357
|
let path2;
|
|
18358
|
+
let originalUrl;
|
|
18369
18359
|
let mergedInit = init || {};
|
|
18370
18360
|
if (typeof input === "string") {
|
|
18371
18361
|
path2 = input;
|
|
18372
18362
|
} else if (isUrlLike(input)) {
|
|
18373
18363
|
path2 = input.pathname + input.search;
|
|
18364
|
+
originalUrl = input.toString();
|
|
18374
18365
|
} else if (isRequestLike(input)) {
|
|
18375
18366
|
const url2 = new URL(input.url);
|
|
18376
18367
|
path2 = url2.pathname + url2.search;
|
|
18368
|
+
originalUrl = url2.toString();
|
|
18377
18369
|
const requestHeaders = new Headers(input.headers);
|
|
18378
18370
|
const initHeaders = new Headers((init == null ? void 0 : init.headers) || {});
|
|
18379
18371
|
const mergedHeaders = new Headers(requestHeaders);
|
|
@@ -18415,6 +18407,10 @@ async function rawHttpFetch(driver, target, params, input, init, options = {}) {
|
|
|
18415
18407
|
const normalizedPath = path2.startsWith("/") ? path2.slice(1) : path2;
|
|
18416
18408
|
const url2 = new URL(`http://actor/request/${normalizedPath}`);
|
|
18417
18409
|
const proxyRequestHeaders = new Headers(mergedInit.headers);
|
|
18410
|
+
proxyRequestHeaders.delete(HEADER_ORIGINAL_REQUEST_URL);
|
|
18411
|
+
if (originalUrl) {
|
|
18412
|
+
proxyRequestHeaders.set(HEADER_ORIGINAL_REQUEST_URL, originalUrl);
|
|
18413
|
+
}
|
|
18418
18414
|
if (params) {
|
|
18419
18415
|
proxyRequestHeaders.set(HEADER_CONN_PARAMS, JSON.stringify(params));
|
|
18420
18416
|
}
|
|
@@ -18540,7 +18536,9 @@ var ActorHandleRaw = class {
|
|
|
18540
18536
|
async #sendQueueMessage(name, body, options) {
|
|
18541
18537
|
return await this.#queueSendMutex.run(async () => {
|
|
18542
18538
|
const maxAttempts = this.#getDynamicQueryMaxAttempts();
|
|
18543
|
-
let useQueryTarget = isDynamicActorQuery(
|
|
18539
|
+
let useQueryTarget = isDynamicActorQuery(
|
|
18540
|
+
this.#actorResolutionState
|
|
18541
|
+
);
|
|
18544
18542
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
18545
18543
|
let actorId;
|
|
18546
18544
|
try {
|
|
@@ -18889,9 +18887,10 @@ var ActorHandleRaw = class {
|
|
|
18889
18887
|
return this.#fetchWithResolvedActor(input, init);
|
|
18890
18888
|
}
|
|
18891
18889
|
async #fetchWithResolvedActor(input, init) {
|
|
18892
|
-
const maxAttempts = this.#getDynamicQueryMaxAttempts();
|
|
18893
|
-
let useQueryTarget = isDynamicActorQuery(this.#actorResolutionState);
|
|
18894
18890
|
const { skipReadyWait, ...requestInit } = init ?? {};
|
|
18891
|
+
const hasBody = requestInit.body !== void 0 ? requestInit.body !== null : isRequestLike(input) && input.body !== null;
|
|
18892
|
+
const maxAttempts = hasBody ? 1 : this.#getDynamicQueryMaxAttempts();
|
|
18893
|
+
let useQueryTarget = isDynamicActorQuery(this.#actorResolutionState);
|
|
18895
18894
|
const gatewayOptions = resolveActorGatewayOptions(
|
|
18896
18895
|
this.#gatewayOptions,
|
|
18897
18896
|
{
|
|
@@ -20659,23 +20658,19 @@ async function sendHttpRequestToGateway(runConfig, gatewayUrl, actorRequest, opt
|
|
|
20659
20658
|
if (actorRequest.bodyUsed) {
|
|
20660
20659
|
throw new Error("Request body has already been consumed");
|
|
20661
20660
|
}
|
|
20662
|
-
|
|
20663
|
-
|
|
20664
|
-
bodyToSend = reqBody;
|
|
20661
|
+
if (actorRequest.body) {
|
|
20662
|
+
bodyToSend = actorRequest.body;
|
|
20665
20663
|
guardHeaders.delete("transfer-encoding");
|
|
20666
20664
|
guardHeaders.delete("content-length");
|
|
20667
20665
|
}
|
|
20668
20666
|
}
|
|
20669
|
-
|
|
20667
|
+
return fetch(gatewayUrl, {
|
|
20670
20668
|
method: actorRequest.method,
|
|
20671
20669
|
headers: guardHeaders,
|
|
20672
20670
|
body: bodyToSend,
|
|
20673
|
-
signal: actorRequest.signal
|
|
20671
|
+
signal: actorRequest.signal,
|
|
20672
|
+
...bodyToSend ? { duplex: "half" } : {}
|
|
20674
20673
|
});
|
|
20675
|
-
return mutableResponse(await fetch(guardRequest));
|
|
20676
|
-
}
|
|
20677
|
-
function mutableResponse(fetchRes) {
|
|
20678
|
-
return new Response(fetchRes.body, fetchRes);
|
|
20679
20674
|
}
|
|
20680
20675
|
function buildGuardHeaders(runConfig, actorRequest, options) {
|
|
20681
20676
|
const headers = new Headers();
|
|
@@ -21625,7 +21620,7 @@ function apiActorToOutput(actor2) {
|
|
|
21625
21620
|
};
|
|
21626
21621
|
}
|
|
21627
21622
|
|
|
21628
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
21623
|
+
// ../rivetkit/dist/tsup/chunk-EBXARMGI.js
|
|
21629
21624
|
var nativeStateTransactionOpeners = /* @__PURE__ */ new WeakMap();
|
|
21630
21625
|
var nativeStateTransactionClientBinders = /* @__PURE__ */ new WeakMap();
|
|
21631
21626
|
function registerNativeStateTransactionOpener(provider, opener) {
|
|
@@ -23701,6 +23696,12 @@ var RegistryConfigSchema = external_exports.object({
|
|
|
23701
23696
|
enginePort: external_exports.number().int().min(1).max(65535).optional().default(() => getRivetRunEnginePort() ?? ENGINE_PORT),
|
|
23702
23697
|
/** @experimental */
|
|
23703
23698
|
engineVersion: external_exports.string().optional().default(() => getRivetRunEngineVersion() ?? VERSION),
|
|
23699
|
+
/**
|
|
23700
|
+
* Starts the first-party Services actor host when RivetKit manages
|
|
23701
|
+
* a local engine. Defaults to the local-engine decision. Set
|
|
23702
|
+
* RIVET_RUN_SERVICES=0 or 1 to override it.
|
|
23703
|
+
*/
|
|
23704
|
+
startServices: external_exports.boolean().optional(),
|
|
23704
23705
|
/**
|
|
23705
23706
|
* @experimental
|
|
23706
23707
|
*
|
|
@@ -23781,6 +23782,7 @@ var RegistryConfigSchema = external_exports.object({
|
|
|
23781
23782
|
config3.enginePort
|
|
23782
23783
|
);
|
|
23783
23784
|
const endpoint = config3.startEngine ? localEngineEndpoint : (parsedEndpoint == null ? void 0 : parsedEndpoint.endpoint) ?? (isDevEnv ? localEngineEndpoint : void 0);
|
|
23785
|
+
const startServices = config3.startServices ?? getRivetRunServices() ?? Boolean(endpoint && isLocalEngineEndpoint(endpoint));
|
|
23784
23786
|
const validateServerlessEndpoint = Boolean(
|
|
23785
23787
|
config3.startEngine || parsedEndpoint
|
|
23786
23788
|
);
|
|
@@ -23804,6 +23806,7 @@ var RegistryConfigSchema = external_exports.object({
|
|
|
23804
23806
|
...config3,
|
|
23805
23807
|
sqlite,
|
|
23806
23808
|
endpoint,
|
|
23809
|
+
startServices,
|
|
23807
23810
|
namespace,
|
|
23808
23811
|
token,
|
|
23809
23812
|
publicEndpoint,
|
|
@@ -23917,6 +23920,9 @@ var DocRegistryConfigSchema = external_exports.object({
|
|
|
23917
23920
|
engineVersion: external_exports.string().optional().describe(
|
|
23918
23921
|
"Version of the local engine package to use. Defaults to the current RivetKit version."
|
|
23919
23922
|
),
|
|
23923
|
+
startServices: external_exports.boolean().optional().describe(
|
|
23924
|
+
"Starts Services when RivetKit manages a local Engine. Defaults to the local-Engine decision. Set RIVET_RUN_SERVICES=0 or 1 to override."
|
|
23925
|
+
),
|
|
23920
23926
|
configurePool: DocConfigurePoolSchema.describe(
|
|
23921
23927
|
"Automatically configure serverless runners in the engine."
|
|
23922
23928
|
),
|
|
@@ -24426,16 +24432,30 @@ function toNapiApplication(application) {
|
|
|
24426
24432
|
if (!request) {
|
|
24427
24433
|
throw new Error("application fetch callback received no request");
|
|
24428
24434
|
}
|
|
24429
|
-
const response = await application(
|
|
24430
|
-
|
|
24431
|
-
|
|
24432
|
-
|
|
24435
|
+
const response = await application(
|
|
24436
|
+
{
|
|
24437
|
+
...request,
|
|
24438
|
+
body: new Uint8Array(request.body),
|
|
24439
|
+
cancelToken: request.cancelToken
|
|
24440
|
+
},
|
|
24441
|
+
request.responseBodyStream ? fromNapiHttpResponseBodyStream(
|
|
24442
|
+
request.responseBodyStream
|
|
24443
|
+
) : void 0
|
|
24444
|
+
);
|
|
24433
24445
|
return {
|
|
24434
24446
|
...response,
|
|
24435
|
-
body: toNapiBuffer(response.body)
|
|
24447
|
+
body: response.body === void 0 ? void 0 : toNapiBuffer(response.body)
|
|
24436
24448
|
};
|
|
24437
24449
|
};
|
|
24438
24450
|
}
|
|
24451
|
+
function fromNapiHttpResponseBodyStream(stream) {
|
|
24452
|
+
return {
|
|
24453
|
+
cancelled: () => stream.cancelled(),
|
|
24454
|
+
write: (chunk) => stream.write(Buffer.from(chunk)),
|
|
24455
|
+
end: () => stream.end(),
|
|
24456
|
+
error: (message) => stream.error(message)
|
|
24457
|
+
};
|
|
24458
|
+
}
|
|
24439
24459
|
function toNapiHttpRequest(request) {
|
|
24440
24460
|
if (!request) {
|
|
24441
24461
|
return request;
|
|
@@ -24978,6 +24998,147 @@ async function loadNapiRuntime() {
|
|
|
24978
24998
|
runtime: new NapiCoreRuntime(bindings)
|
|
24979
24999
|
};
|
|
24980
25000
|
}
|
|
25001
|
+
var HTTP_BODY_CHUNK_SIZE = 64 * 1024;
|
|
25002
|
+
function runtimeBytesToArrayBuffer(value) {
|
|
25003
|
+
return value.buffer.slice(
|
|
25004
|
+
value.byteOffset,
|
|
25005
|
+
value.byteOffset + value.byteLength
|
|
25006
|
+
);
|
|
25007
|
+
}
|
|
25008
|
+
function buildNativeHttpRequest(init) {
|
|
25009
|
+
var _a2;
|
|
25010
|
+
const headers = new Headers(init.headers);
|
|
25011
|
+
const originalUrl = headers.get(HEADER_ORIGINAL_REQUEST_URL);
|
|
25012
|
+
headers.delete(HEADER_ORIGINAL_REQUEST_URL);
|
|
25013
|
+
const url2 = originalUrl ?? (init.uri.startsWith("http") ? init.uri : new URL(init.uri, "http://127.0.0.1").toString());
|
|
25014
|
+
const method2 = init.method.toUpperCase();
|
|
25015
|
+
const bodyForbidden = method2 === "GET" || method2 === "HEAD";
|
|
25016
|
+
const body = bodyForbidden ? void 0 : init.bodyStream ? new ReadableStream({
|
|
25017
|
+
async pull(controller) {
|
|
25018
|
+
var _a22, _b;
|
|
25019
|
+
try {
|
|
25020
|
+
if (init.body && init.body.length > 0) {
|
|
25021
|
+
controller.enqueue(new Uint8Array(init.body));
|
|
25022
|
+
init.body = void 0;
|
|
25023
|
+
return;
|
|
25024
|
+
}
|
|
25025
|
+
const chunk = await ((_a22 = init.bodyStream) == null ? void 0 : _a22.read());
|
|
25026
|
+
if (!chunk) {
|
|
25027
|
+
controller.close();
|
|
25028
|
+
} else {
|
|
25029
|
+
controller.enqueue(new Uint8Array(chunk));
|
|
25030
|
+
}
|
|
25031
|
+
} catch (error46) {
|
|
25032
|
+
(_b = init.abortController) == null ? void 0 : _b.abort(error46);
|
|
25033
|
+
controller.error(error46);
|
|
25034
|
+
}
|
|
25035
|
+
},
|
|
25036
|
+
async cancel() {
|
|
25037
|
+
var _a22;
|
|
25038
|
+
await ((_a22 = init.bodyStream) == null ? void 0 : _a22.cancel());
|
|
25039
|
+
}
|
|
25040
|
+
}) : init.body && init.body.length > 0 ? runtimeBytesToArrayBuffer(init.body) : void 0;
|
|
25041
|
+
const streamInit = init.bodyStream && !bodyForbidden ? { duplex: "half" } : {};
|
|
25042
|
+
return new Request(url2, {
|
|
25043
|
+
method: method2,
|
|
25044
|
+
headers,
|
|
25045
|
+
body,
|
|
25046
|
+
signal: ((_a2 = init.abortController) == null ? void 0 : _a2.signal) ?? init.signal,
|
|
25047
|
+
...streamInit
|
|
25048
|
+
});
|
|
25049
|
+
}
|
|
25050
|
+
async function cancelNativeHttpRequestBody(bodyStream) {
|
|
25051
|
+
await (bodyStream == null ? void 0 : bodyStream.cancel());
|
|
25052
|
+
}
|
|
25053
|
+
async function writeResponseChunk(stream, chunk) {
|
|
25054
|
+
for (let offset = 0; offset < chunk.byteLength; offset += HTTP_BODY_CHUNK_SIZE) {
|
|
25055
|
+
await stream.write(
|
|
25056
|
+
chunk.subarray(offset, offset + HTTP_BODY_CHUNK_SIZE)
|
|
25057
|
+
);
|
|
25058
|
+
}
|
|
25059
|
+
}
|
|
25060
|
+
async function pumpResponseBody(reader, stream) {
|
|
25061
|
+
var _a2;
|
|
25062
|
+
const cancelled = stream.cancelled().then(() => ({ cancelled: true }));
|
|
25063
|
+
try {
|
|
25064
|
+
for (; ; ) {
|
|
25065
|
+
const read = reader.read().then((next2) => ({ cancelled: false, next: next2 }));
|
|
25066
|
+
const result = await Promise.race([read, cancelled]);
|
|
25067
|
+
if (result.cancelled) {
|
|
25068
|
+
void reader.cancel(
|
|
25069
|
+
new Error(
|
|
25070
|
+
"native http response stream receiver dropped"
|
|
25071
|
+
)
|
|
25072
|
+
).catch((error46) => {
|
|
25073
|
+
logger22().debug({
|
|
25074
|
+
msg: "failed to cancel native http response reader",
|
|
25075
|
+
error: error46
|
|
25076
|
+
});
|
|
25077
|
+
});
|
|
25078
|
+
return;
|
|
25079
|
+
}
|
|
25080
|
+
const { next } = result;
|
|
25081
|
+
if (next.done) {
|
|
25082
|
+
await stream.end();
|
|
25083
|
+
return;
|
|
25084
|
+
}
|
|
25085
|
+
if ((_a2 = next.value) == null ? void 0 : _a2.byteLength) {
|
|
25086
|
+
await writeResponseChunk(stream, next.value);
|
|
25087
|
+
}
|
|
25088
|
+
}
|
|
25089
|
+
} catch (error46) {
|
|
25090
|
+
try {
|
|
25091
|
+
await stream.error(stringifyError(error46));
|
|
25092
|
+
} catch (streamError) {
|
|
25093
|
+
logger22().debug({
|
|
25094
|
+
msg: "failed to report native http response stream error",
|
|
25095
|
+
error: streamError
|
|
25096
|
+
});
|
|
25097
|
+
}
|
|
25098
|
+
void reader.cancel(error46).catch(() => {
|
|
25099
|
+
});
|
|
25100
|
+
} finally {
|
|
25101
|
+
try {
|
|
25102
|
+
reader.releaseLock();
|
|
25103
|
+
} catch (error46) {
|
|
25104
|
+
logger22().debug({
|
|
25105
|
+
msg: "failed to release native http response reader lock",
|
|
25106
|
+
error: error46
|
|
25107
|
+
});
|
|
25108
|
+
}
|
|
25109
|
+
}
|
|
25110
|
+
}
|
|
25111
|
+
async function convertNativeHttpResponse(response, responseBodyStream) {
|
|
25112
|
+
const headers = Object.fromEntries(response.headers.entries());
|
|
25113
|
+
if (!response.body) {
|
|
25114
|
+
return {
|
|
25115
|
+
response: {
|
|
25116
|
+
status: response.status,
|
|
25117
|
+
headers,
|
|
25118
|
+
body: new Uint8Array()
|
|
25119
|
+
}
|
|
25120
|
+
};
|
|
25121
|
+
}
|
|
25122
|
+
if (responseBodyStream) {
|
|
25123
|
+
const reader = response.body.getReader();
|
|
25124
|
+
const bodyCompletion = pumpResponseBody(reader, responseBodyStream);
|
|
25125
|
+
return {
|
|
25126
|
+
response: {
|
|
25127
|
+
status: response.status,
|
|
25128
|
+
headers,
|
|
25129
|
+
stream: true
|
|
25130
|
+
},
|
|
25131
|
+
bodyCompletion
|
|
25132
|
+
};
|
|
25133
|
+
}
|
|
25134
|
+
return {
|
|
25135
|
+
response: {
|
|
25136
|
+
status: response.status,
|
|
25137
|
+
headers,
|
|
25138
|
+
body: new Uint8Array(await response.arrayBuffer())
|
|
25139
|
+
}
|
|
25140
|
+
};
|
|
25141
|
+
}
|
|
24981
25142
|
var CONN_PARAMS_KEY = "__conn_params__";
|
|
24982
25143
|
function validateActionArgs(schemas, name, args) {
|
|
24983
25144
|
if (!(schemas == null ? void 0 : schemas[name])) {
|
|
@@ -26426,7 +26587,7 @@ function toRuntimeBytes(value) {
|
|
|
26426
26587
|
function arrayBufferViewToRuntimeBytes(value) {
|
|
26427
26588
|
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
26428
26589
|
}
|
|
26429
|
-
function
|
|
26590
|
+
function runtimeBytesToArrayBuffer2(value) {
|
|
26430
26591
|
return value.buffer.slice(
|
|
26431
26592
|
value.byteOffset,
|
|
26432
26593
|
value.byteOffset + value.byteLength
|
|
@@ -26472,6 +26633,9 @@ function decodeNativeKvValue(value, options) {
|
|
|
26472
26633
|
async function loadEngineCli() {
|
|
26473
26634
|
return import(["@rivetkit", "engine-cli"].join("/"));
|
|
26474
26635
|
}
|
|
26636
|
+
async function loadServices() {
|
|
26637
|
+
return import(["@rivet-dev", "services"].join("/"));
|
|
26638
|
+
}
|
|
26475
26639
|
function decodeValue(value) {
|
|
26476
26640
|
if (!value || value.length === 0) {
|
|
26477
26641
|
return void 0;
|
|
@@ -26757,24 +26921,6 @@ function decodeArgs(value) {
|
|
|
26757
26921
|
const decoded = decodeValue(value);
|
|
26758
26922
|
return normalizeArgs(decoded);
|
|
26759
26923
|
}
|
|
26760
|
-
function buildRequest(init) {
|
|
26761
|
-
const url2 = init.uri.startsWith("http") ? init.uri : new URL(init.uri, "http://127.0.0.1").toString();
|
|
26762
|
-
const body = init.body && init.body.length > 0 ? runtimeBytesToArrayBuffer(init.body) : void 0;
|
|
26763
|
-
return new Request(url2, {
|
|
26764
|
-
method: init.method,
|
|
26765
|
-
headers: init.headers,
|
|
26766
|
-
body
|
|
26767
|
-
});
|
|
26768
|
-
}
|
|
26769
|
-
async function toRuntimeHttpResponse(response) {
|
|
26770
|
-
const headers = Object.fromEntries(response.headers.entries());
|
|
26771
|
-
const body = new Uint8Array(await response.arrayBuffer());
|
|
26772
|
-
return {
|
|
26773
|
-
status: response.status,
|
|
26774
|
-
headers,
|
|
26775
|
-
body
|
|
26776
|
-
};
|
|
26777
|
-
}
|
|
26778
26924
|
function toActorKey(segments) {
|
|
26779
26925
|
return segments.map(
|
|
26780
26926
|
(segment) => segment.kind === "number" ? String(segment.numberValue ?? 0) : segment.stringValue ?? ""
|
|
@@ -27487,7 +27633,7 @@ var NativeWebSocketAdapter = class {
|
|
|
27487
27633
|
this.#runtime.webSocketSetEventCallback(this.#ws, (event2) => {
|
|
27488
27634
|
if (event2.kind === "message") {
|
|
27489
27635
|
this.#virtual.triggerMessage(
|
|
27490
|
-
event2.binary ?
|
|
27636
|
+
event2.binary ? runtimeBytesToArrayBuffer2(event2.data) : event2.data,
|
|
27491
27637
|
event2.messageIndex
|
|
27492
27638
|
);
|
|
27493
27639
|
return;
|
|
@@ -28709,7 +28855,6 @@ function buildActorConfig(definition, registryConfig, runtimeKind) {
|
|
|
28709
28855
|
return {
|
|
28710
28856
|
name: options.name,
|
|
28711
28857
|
icon: options.icon,
|
|
28712
|
-
maxActions: options.maxActions,
|
|
28713
28858
|
hasDatabase: true,
|
|
28714
28859
|
remoteSqlite: usesRemoteSqlite,
|
|
28715
28860
|
sqliteProfiling,
|
|
@@ -28871,12 +29016,14 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
28871
29016
|
cancelToken,
|
|
28872
29017
|
run !== void 0
|
|
28873
29018
|
);
|
|
28874
|
-
const maybeHandleNativeInspectorRequest = async (ctx,
|
|
29019
|
+
const maybeHandleNativeInspectorRequest = async (ctx, rawRequest) => {
|
|
28875
29020
|
var _a22, _b, _c, _d;
|
|
28876
|
-
const
|
|
29021
|
+
const rawUrl = rawRequest.uri.startsWith("http") ? rawRequest.uri : new URL(rawRequest.uri, "http://127.0.0.1").toString();
|
|
29022
|
+
const url2 = new URL(rawUrl);
|
|
28877
29023
|
if (!url2.pathname.startsWith("/inspector/")) {
|
|
28878
29024
|
return void 0;
|
|
28879
29025
|
}
|
|
29026
|
+
const jsRequest = buildNativeHttpRequest(rawRequest);
|
|
28880
29027
|
const jsonResponse = (body, init) => new Response(JSON.stringify(body), {
|
|
28881
29028
|
status: (init == null ? void 0 : init.status) ?? 200,
|
|
28882
29029
|
headers: {
|
|
@@ -29407,7 +29554,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
29407
29554
|
);
|
|
29408
29555
|
const actorCtx = makeActorCtx(
|
|
29409
29556
|
ctx,
|
|
29410
|
-
request ?
|
|
29557
|
+
request ? buildNativeHttpRequest(request) : void 0
|
|
29411
29558
|
);
|
|
29412
29559
|
try {
|
|
29413
29560
|
await config3.onBeforeConnect(
|
|
@@ -29427,7 +29574,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
29427
29574
|
const { ctx, conn, params, request } = unwrapTsfnPayload(error46, payload);
|
|
29428
29575
|
const actorCtx = makeActorCtx(
|
|
29429
29576
|
ctx,
|
|
29430
|
-
request ?
|
|
29577
|
+
request ? buildNativeHttpRequest(request) : void 0
|
|
29431
29578
|
);
|
|
29432
29579
|
const connAdapter = new NativeConnAdapter(
|
|
29433
29580
|
runtime,
|
|
@@ -29465,7 +29612,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
29465
29612
|
);
|
|
29466
29613
|
const actorCtx = makeActorCtx(
|
|
29467
29614
|
ctx,
|
|
29468
|
-
request ?
|
|
29615
|
+
request ? buildNativeHttpRequest(request) : void 0
|
|
29469
29616
|
);
|
|
29470
29617
|
const connAdapter = new NativeConnAdapter(
|
|
29471
29618
|
runtime,
|
|
@@ -29572,27 +29719,45 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
29572
29719
|
onRequest: wrapNativeCallback(
|
|
29573
29720
|
async (error46, payload) => {
|
|
29574
29721
|
try {
|
|
29575
|
-
const { ctx, request, cancelToken } = unwrapTsfnPayload(
|
|
29576
|
-
|
|
29577
|
-
payload
|
|
29578
|
-
);
|
|
29579
|
-
const jsRequest = buildRequest(request);
|
|
29580
|
-
const inspectorResponse = await maybeHandleNativeInspectorRequest(
|
|
29581
|
-
ctx,
|
|
29582
|
-
request,
|
|
29583
|
-
jsRequest
|
|
29584
|
-
);
|
|
29722
|
+
const { ctx, request, cancelToken, responseBodyStream } = unwrapTsfnPayload(error46, payload);
|
|
29723
|
+
const inspectorResponse = await maybeHandleNativeInspectorRequest(ctx, request);
|
|
29585
29724
|
if (inspectorResponse) {
|
|
29586
|
-
|
|
29725
|
+
await cancelNativeHttpRequestBody(request.bodyStream);
|
|
29726
|
+
return (await convertNativeHttpResponse(
|
|
29727
|
+
inspectorResponse,
|
|
29728
|
+
responseBodyStream
|
|
29729
|
+
)).response;
|
|
29587
29730
|
}
|
|
29588
29731
|
if (typeof config3.onRequest !== "function") {
|
|
29589
|
-
|
|
29590
|
-
|
|
29591
|
-
|
|
29732
|
+
await cancelNativeHttpRequestBody(request.bodyStream);
|
|
29733
|
+
return (await convertNativeHttpResponse(
|
|
29734
|
+
new Response(null, { status: 404 }),
|
|
29735
|
+
responseBodyStream
|
|
29736
|
+
)).response;
|
|
29592
29737
|
}
|
|
29593
|
-
const
|
|
29738
|
+
const requestAbortController = new AbortController();
|
|
29739
|
+
const handlerRequest = buildNativeHttpRequest({
|
|
29740
|
+
...request,
|
|
29741
|
+
abortController: requestAbortController
|
|
29742
|
+
});
|
|
29743
|
+
const rawConnParams = handlerRequest.headers.get(HEADER_CONN_PARAMS);
|
|
29594
29744
|
let requestCtx;
|
|
29595
29745
|
let conn;
|
|
29746
|
+
let removeRequestAbortListener;
|
|
29747
|
+
let cleanupDeferredToBody = false;
|
|
29748
|
+
let cleanedUp = false;
|
|
29749
|
+
const cleanupRequest = async () => {
|
|
29750
|
+
if (cleanedUp) return;
|
|
29751
|
+
cleanedUp = true;
|
|
29752
|
+
removeRequestAbortListener == null ? void 0 : removeRequestAbortListener();
|
|
29753
|
+
try {
|
|
29754
|
+
await (requestCtx == null ? void 0 : requestCtx.dispose());
|
|
29755
|
+
} finally {
|
|
29756
|
+
if (conn) {
|
|
29757
|
+
await runtime.connDisconnect(conn);
|
|
29758
|
+
}
|
|
29759
|
+
}
|
|
29760
|
+
};
|
|
29596
29761
|
try {
|
|
29597
29762
|
const connParams = validateConnParams(
|
|
29598
29763
|
schemaConfig.connParamsSchema,
|
|
@@ -29608,23 +29773,56 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
29608
29773
|
requestCtx = makeConnCtx(
|
|
29609
29774
|
ctx,
|
|
29610
29775
|
conn,
|
|
29611
|
-
|
|
29776
|
+
handlerRequest,
|
|
29612
29777
|
cancelToken
|
|
29613
29778
|
);
|
|
29779
|
+
const ctxAbortSignal = requestCtx.abortSignal;
|
|
29780
|
+
const abortRequest = () => requestAbortController.abort(ctxAbortSignal.reason);
|
|
29781
|
+
if (ctxAbortSignal.aborted) {
|
|
29782
|
+
abortRequest();
|
|
29783
|
+
} else {
|
|
29784
|
+
ctxAbortSignal.addEventListener(
|
|
29785
|
+
"abort",
|
|
29786
|
+
abortRequest,
|
|
29787
|
+
{ once: true }
|
|
29788
|
+
);
|
|
29789
|
+
removeRequestAbortListener = () => ctxAbortSignal.removeEventListener(
|
|
29790
|
+
"abort",
|
|
29791
|
+
abortRequest
|
|
29792
|
+
);
|
|
29793
|
+
}
|
|
29614
29794
|
const response = await config3.onRequest(
|
|
29615
29795
|
requestCtx,
|
|
29616
|
-
|
|
29796
|
+
handlerRequest
|
|
29617
29797
|
);
|
|
29618
29798
|
if (!isResponseLike(response)) {
|
|
29619
29799
|
throw new Error(
|
|
29620
29800
|
"onRequest handler must return a Response"
|
|
29621
29801
|
);
|
|
29622
29802
|
}
|
|
29623
|
-
|
|
29803
|
+
const conversion = await convertNativeHttpResponse(
|
|
29804
|
+
response,
|
|
29805
|
+
responseBodyStream
|
|
29806
|
+
);
|
|
29807
|
+
if (conversion.bodyCompletion) {
|
|
29808
|
+
cleanupDeferredToBody = true;
|
|
29809
|
+
void conversion.bodyCompletion.then(cleanupRequest).catch((cleanupError) => {
|
|
29810
|
+
logger22().error({
|
|
29811
|
+
msg: "failed to clean up native streaming http request",
|
|
29812
|
+
error: cleanupError
|
|
29813
|
+
});
|
|
29814
|
+
});
|
|
29815
|
+
}
|
|
29816
|
+
return conversion.response;
|
|
29624
29817
|
} finally {
|
|
29625
|
-
|
|
29626
|
-
|
|
29627
|
-
|
|
29818
|
+
try {
|
|
29819
|
+
await cancelNativeHttpRequestBody(
|
|
29820
|
+
request.bodyStream
|
|
29821
|
+
);
|
|
29822
|
+
} finally {
|
|
29823
|
+
if (!cleanupDeferredToBody) {
|
|
29824
|
+
await cleanupRequest();
|
|
29825
|
+
}
|
|
29628
29826
|
}
|
|
29629
29827
|
}
|
|
29630
29828
|
} catch (error210) {
|
|
@@ -29639,7 +29837,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
29639
29837
|
onWebSocket: typeof config3.onWebSocket === "function" ? wrapNativeCallback(
|
|
29640
29838
|
async (error46, payload) => {
|
|
29641
29839
|
const { ctx, conn, ws, request } = unwrapTsfnPayload(error46, payload);
|
|
29642
|
-
const jsRequest = request ?
|
|
29840
|
+
const jsRequest = request ? buildNativeHttpRequest(request) : void 0;
|
|
29643
29841
|
const actorCtx = makeConnCtx(ctx, conn, jsRequest);
|
|
29644
29842
|
try {
|
|
29645
29843
|
await config3.onWebSocket(
|
|
@@ -29745,7 +29943,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
29745
29943
|
timeoutMs,
|
|
29746
29944
|
cancelToken
|
|
29747
29945
|
} = unwrapTsfnPayload(error46, payload);
|
|
29748
|
-
const jsRequest =
|
|
29946
|
+
const jsRequest = buildNativeHttpRequest(request);
|
|
29749
29947
|
const actorCtx = withConnContext(
|
|
29750
29948
|
runtime,
|
|
29751
29949
|
ctx,
|
|
@@ -29815,7 +30013,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
29815
30013
|
buildActorConfig(definition, registryConfig, runtime.kind)
|
|
29816
30014
|
);
|
|
29817
30015
|
}
|
|
29818
|
-
async function buildServeConfig(config3) {
|
|
30016
|
+
async function buildServeConfig(config3, resolveServicesBinary = true) {
|
|
29819
30017
|
var _a2;
|
|
29820
30018
|
if (!config3.endpoint) {
|
|
29821
30019
|
throw nativeEndpointNotConfiguredError();
|
|
@@ -29826,6 +30024,7 @@ async function buildServeConfig(config3) {
|
|
|
29826
30024
|
token: config3.token,
|
|
29827
30025
|
namespace: config3.namespace,
|
|
29828
30026
|
poolName: config3.envoy.poolName,
|
|
30027
|
+
startServices: resolveServicesBinary && config3.startServices,
|
|
29829
30028
|
handleInspectorHttpInRuntime: true,
|
|
29830
30029
|
serverlessBasePath: config3.serverless.basePath,
|
|
29831
30030
|
serverlessPackageVersion: VERSION,
|
|
@@ -29844,6 +30043,17 @@ async function buildServeConfig(config3) {
|
|
|
29844
30043
|
error: stringifyError(error46)
|
|
29845
30044
|
});
|
|
29846
30045
|
}
|
|
30046
|
+
if (resolveServicesBinary && config3.startServices) {
|
|
30047
|
+
try {
|
|
30048
|
+
const { getServicesPath } = await loadServices();
|
|
30049
|
+
serveConfig.servicesBinaryPath = getServicesPath();
|
|
30050
|
+
} catch (error46) {
|
|
30051
|
+
logger22().warn({
|
|
30052
|
+
msg: "could not resolve the Services binary; a local engine will fail with services.binary_unavailable \u2014 set RIVET_RUN_SERVICES=0 to disable Services or RIVET_SERVICES_BINARY to a local rivet-services binary",
|
|
30053
|
+
error: stringifyError(error46)
|
|
30054
|
+
});
|
|
30055
|
+
}
|
|
30056
|
+
}
|
|
29847
30057
|
serveConfig.engineHost = config3.engineHost;
|
|
29848
30058
|
serveConfig.enginePort = config3.enginePort;
|
|
29849
30059
|
if ((_a2 = config3.test) == null ? void 0 : _a2.enabled) {
|
|
@@ -29870,7 +30080,7 @@ async function buildRegistryWithRuntime(config3, runtime) {
|
|
|
29870
30080
|
return {
|
|
29871
30081
|
runtime,
|
|
29872
30082
|
registry: registry2,
|
|
29873
|
-
serveConfig: await buildServeConfig(config3)
|
|
30083
|
+
serveConfig: await buildServeConfig(config3, runtime.kind === "napi")
|
|
29874
30084
|
};
|
|
29875
30085
|
}
|
|
29876
30086
|
async function buildConfiguredRegistry(config3) {
|
|
@@ -29895,15 +30105,27 @@ function finishShutdownSignal(signal) {
|
|
|
29895
30105
|
}
|
|
29896
30106
|
process.kill(process.pid, signal);
|
|
29897
30107
|
}
|
|
29898
|
-
function createApplicationFetch(application) {
|
|
29899
|
-
return async (request) => {
|
|
30108
|
+
function createApplicationFetch(application, runtime) {
|
|
30109
|
+
return async (request, responseBodyStream) => {
|
|
29900
30110
|
const method2 = request.method.toUpperCase();
|
|
29901
30111
|
const body = method2 === "GET" || method2 === "HEAD" || request.body.length === 0 ? void 0 : Uint8Array.from(request.body).buffer;
|
|
30112
|
+
const abortController = new AbortController();
|
|
30113
|
+
if (request.cancelToken) {
|
|
30114
|
+
if (runtime.cancellationTokenAborted(request.cancelToken)) {
|
|
30115
|
+
abortController.abort();
|
|
30116
|
+
} else {
|
|
30117
|
+
runtime.onCancellationTokenCancelled(
|
|
30118
|
+
request.cancelToken,
|
|
30119
|
+
() => abortController.abort()
|
|
30120
|
+
);
|
|
30121
|
+
}
|
|
30122
|
+
}
|
|
29902
30123
|
const response = await application.fetch(
|
|
29903
30124
|
new Request(request.url, {
|
|
29904
30125
|
method: method2,
|
|
29905
30126
|
headers: request.headers,
|
|
29906
|
-
body
|
|
30127
|
+
body,
|
|
30128
|
+
signal: abortController.signal
|
|
29907
30129
|
})
|
|
29908
30130
|
);
|
|
29909
30131
|
if (!isResponseLike(response)) {
|
|
@@ -29911,10 +30133,23 @@ function createApplicationFetch(application) {
|
|
|
29911
30133
|
"registry.listen() application fetch must return a Response"
|
|
29912
30134
|
);
|
|
29913
30135
|
}
|
|
30136
|
+
const conversion = await convertNativeHttpResponse(
|
|
30137
|
+
response,
|
|
30138
|
+
responseBodyStream
|
|
30139
|
+
);
|
|
30140
|
+
if (conversion.bodyCompletion) {
|
|
30141
|
+
void conversion.bodyCompletion.catch((error46) => {
|
|
30142
|
+
logger22().error({
|
|
30143
|
+
msg: "application response stream failed",
|
|
30144
|
+
error: error46
|
|
30145
|
+
});
|
|
30146
|
+
});
|
|
30147
|
+
}
|
|
29914
30148
|
return {
|
|
29915
|
-
status: response.status,
|
|
29916
|
-
headers: Object.fromEntries(response.headers.entries()),
|
|
29917
|
-
body:
|
|
30149
|
+
status: conversion.response.status ?? response.status,
|
|
30150
|
+
headers: conversion.response.headers ?? Object.fromEntries(response.headers.entries()),
|
|
30151
|
+
body: conversion.response.body,
|
|
30152
|
+
stream: conversion.response.stream
|
|
29918
30153
|
};
|
|
29919
30154
|
};
|
|
29920
30155
|
}
|
|
@@ -30172,8 +30407,7 @@ var Registry = class {
|
|
|
30172
30407
|
const port = opts.port ?? parsePortEnv(process.env.RIVET_PORT) ?? 3e3;
|
|
30173
30408
|
const publicDir = opts.publicDir ?? getRivetkitPublicDir();
|
|
30174
30409
|
const config3 = this.parseConfig();
|
|
30175
|
-
|
|
30176
|
-
if (application && getRivetkitRuntimeMode() !== "serverless") {
|
|
30410
|
+
if (opts.application && getRivetkitRuntimeMode() !== "serverless") {
|
|
30177
30411
|
if (config3.runtime === "wasm") {
|
|
30178
30412
|
throw new Error(
|
|
30179
30413
|
"registry.listen() requires the native runtime; use an application-owned HTTP server with WebAssembly"
|
|
@@ -30192,13 +30426,18 @@ var Registry = class {
|
|
|
30192
30426
|
throw new Error("registry envoy startup did not initialize");
|
|
30193
30427
|
}
|
|
30194
30428
|
const { runtime: runtime2, registry: registry22, serveConfig: serveConfig2 } = await configuredRegistryPromise2;
|
|
30429
|
+
const application2 = createApplicationFetch(
|
|
30430
|
+
opts.application,
|
|
30431
|
+
runtime2
|
|
30432
|
+
);
|
|
30433
|
+
await readyPromise;
|
|
30195
30434
|
const listenerPromise = runtime2.serveApplicationListener(
|
|
30196
30435
|
registry22,
|
|
30197
30436
|
{
|
|
30198
30437
|
port,
|
|
30199
30438
|
host: opts.host,
|
|
30200
30439
|
publicDir,
|
|
30201
|
-
application
|
|
30440
|
+
application: application2
|
|
30202
30441
|
},
|
|
30203
30442
|
serveConfig2
|
|
30204
30443
|
);
|
|
@@ -30209,14 +30448,10 @@ var Registry = class {
|
|
|
30209
30448
|
"registry envoy serve lifecycle did not initialize"
|
|
30210
30449
|
);
|
|
30211
30450
|
}
|
|
30212
|
-
await Promise.all([
|
|
30213
|
-
readyPromise,
|
|
30214
|
-
listenerPromise,
|
|
30215
|
-
serveLifecyclePromise
|
|
30216
|
-
]);
|
|
30451
|
+
await Promise.all([listenerPromise, serveLifecyclePromise]);
|
|
30217
30452
|
return;
|
|
30218
30453
|
}
|
|
30219
|
-
const configuredRegistryPromise = buildConfiguredRegistry(config3);
|
|
30454
|
+
const configuredRegistryPromise = this.#buildConfiguredRegistry(config3);
|
|
30220
30455
|
this.#runtimeServeConfiguredPromise = configuredRegistryPromise;
|
|
30221
30456
|
this.#runtimeServerlessPromise = configuredRegistryPromise;
|
|
30222
30457
|
this.#installSignalHandlers(config3);
|
|
@@ -30227,6 +30462,7 @@ var Registry = class {
|
|
|
30227
30462
|
});
|
|
30228
30463
|
this.#ensureServerlessPoolConfigured(config3);
|
|
30229
30464
|
const { runtime, registry: registry2, serveConfig } = await configuredRegistryPromise;
|
|
30465
|
+
const application = opts.application ? createApplicationFetch(opts.application, runtime) : void 0;
|
|
30230
30466
|
await runtime.serveListener(
|
|
30231
30467
|
registry2,
|
|
30232
30468
|
{
|