rivetkit 0.0.0-sqlite-query-metrics-v2.f5d3605 → 0.0.0-sqlite-query-metrics-v3.1dff84f
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/browser/client.d.ts +60 -10
- package/dist/browser/client.js +294 -40
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +4 -2
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/{chunk-HO76AEDH.cjs → chunk-22S5RCCJ.cjs} +3 -3
- package/dist/tsup/{chunk-HO76AEDH.cjs.map → chunk-22S5RCCJ.cjs.map} +1 -1
- package/dist/tsup/{chunk-EPRA2TCT.js → chunk-2CTZU7GL.js} +2 -2
- package/dist/tsup/{chunk-JI6GZ2C2.js → chunk-A2CF6PFH.js} +18 -1
- package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
- package/dist/tsup/{chunk-QR6EAWEC.cjs → chunk-CWN7N5AF.cjs} +7 -7
- package/dist/tsup/{chunk-QR6EAWEC.cjs.map → chunk-CWN7N5AF.cjs.map} +1 -1
- package/dist/tsup/{chunk-3URZ4UV5.js → chunk-D7DWNYEO.js} +2 -2
- package/dist/tsup/{chunk-F7IGTKGM.js → chunk-F5PWAGS7.js} +2 -2
- package/dist/tsup/{chunk-E2CUROR3.js → chunk-FT6VRK4C.js} +2 -2
- package/dist/tsup/{chunk-FYDB45YU.cjs → chunk-HFGXV2CC.cjs} +10 -10
- package/dist/tsup/{chunk-FYDB45YU.cjs.map → chunk-HFGXV2CC.cjs.map} +1 -1
- package/dist/tsup/{chunk-D4G35VTO.js → chunk-HRKFVQPS.js} +4 -4
- package/dist/tsup/{chunk-DHL2M2E2.cjs → chunk-HXJ5U2ZI.cjs} +3 -3
- package/dist/tsup/{chunk-DHL2M2E2.cjs.map → chunk-HXJ5U2ZI.cjs.map} +1 -1
- package/dist/tsup/{chunk-L3Z3W44Q.cjs → chunk-JJUSO7GJ.cjs} +3 -3
- package/dist/tsup/{chunk-L3Z3W44Q.cjs.map → chunk-JJUSO7GJ.cjs.map} +1 -1
- package/dist/tsup/{chunk-DDS7OOVF.cjs → chunk-NG5CUXMM.cjs} +420 -182
- package/dist/tsup/chunk-NG5CUXMM.cjs.map +1 -0
- package/dist/tsup/{chunk-USKGKQZM.js → chunk-NNCL4IBC.js} +12 -7
- package/dist/tsup/chunk-NNCL4IBC.js.map +1 -0
- package/dist/tsup/{chunk-PJ5EXY6F.js → chunk-QQIFRR3B.js} +283 -45
- package/dist/tsup/chunk-QQIFRR3B.js.map +1 -0
- package/dist/tsup/{chunk-MYWZCDML.cjs → chunk-RTWH3AX3.cjs} +19 -2
- package/dist/tsup/chunk-RTWH3AX3.cjs.map +1 -0
- package/dist/tsup/{chunk-HDVZ6YZG.cjs → chunk-SSF2XC33.cjs} +1 -1
- package/dist/tsup/chunk-SSF2XC33.cjs.map +1 -0
- package/dist/tsup/{chunk-KSP3NXGY.js → chunk-SW33HMM5.js} +3 -3
- package/dist/tsup/{chunk-6FEYCVZC.js → chunk-UXDASKP6.js} +1 -1
- package/dist/tsup/chunk-UXDASKP6.js.map +1 -0
- package/dist/tsup/{chunk-KDT56V3Y.cjs → chunk-Y4QLVCCS.cjs} +12 -7
- package/dist/tsup/chunk-Y4QLVCCS.cjs.map +1 -0
- package/dist/tsup/{chunk-JW2WPE6Z.cjs → chunk-Y5CFDGPA.cjs} +4 -4
- package/dist/tsup/{chunk-JW2WPE6Z.cjs.map → chunk-Y5CFDGPA.cjs.map} +1 -1
- package/dist/tsup/client/mod.cjs +6 -6
- package/dist/tsup/client/mod.d.cts +15 -3
- package/dist/tsup/client/mod.d.ts +15 -3
- package/dist/tsup/client/mod.js +5 -5
- package/dist/tsup/common/log.cjs +2 -2
- package/dist/tsup/common/log.js +1 -1
- package/dist/tsup/common/websocket.cjs +3 -3
- package/dist/tsup/common/websocket.js +2 -2
- package/dist/tsup/{config-Cw_BwH_G.d.ts → config-BiiS5T5M.d.ts} +45 -12
- package/dist/tsup/{config-CkmVg2fG.d.cts → config-BnMhcPHl.d.cts} +45 -12
- package/dist/tsup/{config-D4clT6mq.d.ts → config-CBTr4IhE.d.cts} +0 -2
- package/dist/tsup/{config-D4clT6mq.d.cts → config-CBTr4IhE.d.ts} +0 -2
- package/dist/tsup/{context-_xIcgBnE.d.cts → context-DVE8XMm1.d.cts} +2 -2
- package/dist/tsup/{context-BYOKTQJi.d.ts → context-iMxXq_Lt.d.ts} +2 -2
- package/dist/tsup/db/drizzle.cjs +2 -2
- package/dist/tsup/db/drizzle.d.cts +1 -1
- package/dist/tsup/db/drizzle.d.ts +1 -1
- package/dist/tsup/db/drizzle.js +1 -1
- package/dist/tsup/db/mod.cjs +3 -3
- package/dist/tsup/db/mod.d.cts +2 -2
- package/dist/tsup/db/mod.d.ts +2 -2
- package/dist/tsup/db/mod.js +2 -2
- package/dist/tsup/dynamic/mod.cjs +2 -2
- package/dist/tsup/dynamic/mod.d.cts +2 -2
- package/dist/tsup/dynamic/mod.d.ts +2 -2
- package/dist/tsup/dynamic/mod.js +1 -1
- package/dist/tsup/inspector/mod.cjs +5 -5
- package/dist/tsup/inspector/mod.js +4 -4
- package/dist/tsup/inspector/workflow.cjs +4 -4
- package/dist/tsup/inspector/workflow.js +3 -3
- package/dist/tsup/inspector-tab/mod.cjs +2 -2
- package/dist/tsup/inspector-tab/mod.d.cts +3 -3
- package/dist/tsup/inspector-tab/mod.d.ts +3 -3
- package/dist/tsup/inspector-tab/mod.js +1 -1
- package/dist/tsup/mod.cjs +298 -198
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +4 -4
- package/dist/tsup/mod.d.ts +4 -4
- package/dist/tsup/mod.js +192 -92
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +7 -7
- package/dist/tsup/test/mod.d.cts +2 -2
- package/dist/tsup/test/mod.d.ts +2 -2
- package/dist/tsup/test/mod.js +5 -5
- package/dist/tsup/unstable/migrations.d.cts +1 -1
- package/dist/tsup/unstable/migrations.d.ts +1 -1
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.js +1 -1
- package/dist/tsup/workflow/mod.cjs +25 -22
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +4 -4
- package/dist/tsup/workflow/mod.d.ts +4 -4
- package/dist/tsup/workflow/mod.js +11 -8
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +12 -10
- package/src/actor/config.ts +2 -0
- package/src/actor/keys.ts +86 -0
- package/src/client/actor-conn.ts +136 -24
- package/src/client/actor-handle.ts +64 -10
- package/src/client/client.ts +6 -0
- package/src/client/config.ts +12 -1
- package/src/client/lifecycle-errors.ts +35 -2
- package/src/client/raw-utils.ts +17 -3
- package/src/client/retry-budget.ts +78 -0
- package/src/client/utils.ts +17 -2
- package/src/common/database/config.ts +0 -2
- package/src/common/database/native-database.ts +17 -6
- package/src/common/router.ts +1 -1
- package/src/engine-api/actors.ts +3 -3
- package/src/engine-client/actor-websocket-client.ts +4 -2
- package/src/engine-client/api-endpoints.ts +44 -14
- package/src/engine-client/mod.ts +2 -2
- package/src/registry/config/envoy.ts +1 -1
- package/src/registry/config/index.ts +30 -30
- package/src/registry/index.ts +66 -21
- package/src/registry/napi-runtime.ts +4 -3
- package/src/registry/native.ts +147 -48
- package/src/registry/runtime.ts +27 -10
- package/src/registry/wasm-runtime.ts +6 -3
- package/src/utils/env-vars.ts +13 -6
- package/src/workflow/driver.ts +5 -3
- package/dist/tsup/chunk-6FEYCVZC.js.map +0 -1
- package/dist/tsup/chunk-DDS7OOVF.cjs.map +0 -1
- package/dist/tsup/chunk-HDVZ6YZG.cjs.map +0 -1
- package/dist/tsup/chunk-JI6GZ2C2.js.map +0 -1
- package/dist/tsup/chunk-KDT56V3Y.cjs.map +0 -1
- package/dist/tsup/chunk-MYWZCDML.cjs.map +0 -1
- package/dist/tsup/chunk-PJ5EXY6F.js.map +0 -1
- package/dist/tsup/chunk-USKGKQZM.js.map +0 -1
- package/src/actor/config.test.ts +0 -78
- package/src/actor/keys.test.ts +0 -275
- package/src/actor/utils.test.ts +0 -48
- package/src/client/test.ts +0 -44
- package/src/client/token-provider.test.ts +0 -86
- package/src/common/database/mod.test.ts +0 -364
- package/src/common/database/native-database.test.ts +0 -220
- package/src/common/inline-websocket-adapter.test.ts +0 -51
- package/src/db/drizzle.test.ts +0 -164
- package/src/registry/config/index.test.ts +0 -25
- package/src/registry/run-handler-coordinator.test.ts +0 -252
- package/src/registry/runtime.test.ts +0 -124
- package/src/unstable/migrations.test.ts +0 -170
- package/src/utils/endpoint-parser.test.ts +0 -206
- package/src/utils.test.ts +0 -34
- package/src/workflow/driver.test.ts +0 -62
- /package/dist/tsup/{chunk-EPRA2TCT.js.map → chunk-2CTZU7GL.js.map} +0 -0
- /package/dist/tsup/{chunk-3URZ4UV5.js.map → chunk-D7DWNYEO.js.map} +0 -0
- /package/dist/tsup/{chunk-F7IGTKGM.js.map → chunk-F5PWAGS7.js.map} +0 -0
- /package/dist/tsup/{chunk-E2CUROR3.js.map → chunk-FT6VRK4C.js.map} +0 -0
- /package/dist/tsup/{chunk-D4G35VTO.js.map → chunk-HRKFVQPS.js.map} +0 -0
- /package/dist/tsup/{chunk-KSP3NXGY.js.map → chunk-SW33HMM5.js.map} +0 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { ActorError } from "./errors";
|
|
2
|
+
|
|
3
|
+
/** How many retries a client may spend, as a share of the requests it sends. */
|
|
4
|
+
export interface RetryBudgetOptions {
|
|
5
|
+
/** Retries allowed per 100 requests (default 10). */
|
|
6
|
+
percent?: number;
|
|
7
|
+
/** Retries the client can bank for a burst of refusals; the budget starts full (default 100). */
|
|
8
|
+
maxTokens?: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const DEFAULT_PERCENT = 10;
|
|
12
|
+
const DEFAULT_MAX_TOKENS = 100;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Bounds the client's retries of refused requests. Each request adds a fraction of a token and
|
|
16
|
+
* each retry spends one, so retries stay a fixed share of traffic while the service sheds load
|
|
17
|
+
* instead of multiplying it.
|
|
18
|
+
*/
|
|
19
|
+
export class RetryBudget {
|
|
20
|
+
#tokens: number;
|
|
21
|
+
readonly #maxTokens: number;
|
|
22
|
+
readonly #deposit: number;
|
|
23
|
+
|
|
24
|
+
constructor(options: RetryBudgetOptions = {}) {
|
|
25
|
+
const percent = options.percent ?? DEFAULT_PERCENT;
|
|
26
|
+
const maxTokens = options.maxTokens ?? DEFAULT_MAX_TOKENS;
|
|
27
|
+
if (!(percent >= 0 && percent <= 100)) {
|
|
28
|
+
throw new Error("retryBudget.percent must be in 0..=100");
|
|
29
|
+
}
|
|
30
|
+
if (!(maxTokens >= 0)) {
|
|
31
|
+
throw new Error("retryBudget.maxTokens must be at least 0");
|
|
32
|
+
}
|
|
33
|
+
this.#maxTokens = maxTokens;
|
|
34
|
+
this.#tokens = maxTokens;
|
|
35
|
+
this.#deposit = percent / 100;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Credits one request sent. */
|
|
39
|
+
deposit(): void {
|
|
40
|
+
this.#tokens = Math.min(this.#maxTokens, this.#tokens + this.#deposit);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Spends one token. Returns `false` when the budget is spent. */
|
|
44
|
+
tryWithdraw(): boolean {
|
|
45
|
+
// Rounding guards against float drift: ten 0.1 deposits must make one token.
|
|
46
|
+
if (this.#tokens + 1e-9 < 1) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
this.#tokens = Math.max(0, this.#tokens - 1);
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The service's retry hint for a refused request, in milliseconds, when it sent one. */
|
|
55
|
+
export function retryAfterMs(error: unknown): number | undefined {
|
|
56
|
+
if (!(error instanceof ActorError)) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
const metadata = error.metadata;
|
|
60
|
+
if (metadata === null || typeof metadata !== "object") {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
const hint = (metadata as { retry_after_ms?: unknown }).retry_after_ms;
|
|
64
|
+
return typeof hint === "number" && hint >= 0 ? hint : undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The wait before retry `attempt` (0-based): jittered exponential backoff over
|
|
69
|
+
* `[initialDelayMs, maxDelayMs]`, never shorter than the service's hint.
|
|
70
|
+
*/
|
|
71
|
+
export function retryDelayMs(
|
|
72
|
+
attempt: number,
|
|
73
|
+
opts: { initialDelayMs: number; maxDelayMs: number; hintMs?: number },
|
|
74
|
+
): number {
|
|
75
|
+
const backoff = Math.min(opts.initialDelayMs * 2 ** attempt, opts.maxDelayMs);
|
|
76
|
+
const jittered = backoff / 2 + Math.random() * (backoff / 2);
|
|
77
|
+
return Math.max(jittered, opts.hintMs ?? 0);
|
|
78
|
+
}
|
package/src/client/utils.ts
CHANGED
|
@@ -19,21 +19,27 @@ export interface ParsedCloseReason {
|
|
|
19
19
|
group: string;
|
|
20
20
|
code: string;
|
|
21
21
|
rayId?: string;
|
|
22
|
+
/** The service's retry hint, from a `#retry_after_ms=<ms>` suffix. */
|
|
23
|
+
retryAfterMs?: number;
|
|
22
24
|
}
|
|
23
25
|
|
|
26
|
+
const RETRY_AFTER_SUFFIX = /^retry_after_ms=(\d+)$/;
|
|
27
|
+
|
|
24
28
|
/**
|
|
25
29
|
* Parses WebSocket close reason string into structured data.
|
|
26
30
|
*
|
|
27
31
|
* Expected format examples:
|
|
28
32
|
* - "guard.actor_runner_failed#t1s80so6h3irenp8ymzltfoittcl00"
|
|
29
33
|
* - "ws.client_closed"
|
|
34
|
+
* - "guard.service_unavailable#retry_after_ms=1000", a refusal with its retry hint. The hint
|
|
35
|
+
* rides after `#` so older clients still read the retryable `<group>.<code>`.
|
|
30
36
|
*
|
|
31
37
|
* Returns undefined if the format is invalid
|
|
32
38
|
*/
|
|
33
39
|
export function parseWebSocketCloseReason(
|
|
34
40
|
reason: string,
|
|
35
41
|
): ParsedCloseReason | undefined {
|
|
36
|
-
const [mainPart,
|
|
42
|
+
const [mainPart, suffix] = reason.split("#");
|
|
37
43
|
const [group, code] = mainPart.split(".");
|
|
38
44
|
|
|
39
45
|
if (!group || !code) {
|
|
@@ -41,10 +47,15 @@ export function parseWebSocketCloseReason(
|
|
|
41
47
|
return undefined;
|
|
42
48
|
}
|
|
43
49
|
|
|
50
|
+
const retryAfter = suffix?.match(RETRY_AFTER_SUFFIX);
|
|
51
|
+
if (retryAfter) {
|
|
52
|
+
return { group, code, retryAfterMs: Number(retryAfter[1]) };
|
|
53
|
+
}
|
|
54
|
+
|
|
44
55
|
return {
|
|
45
56
|
group,
|
|
46
57
|
code,
|
|
47
|
-
rayId,
|
|
58
|
+
rayId: suffix,
|
|
48
59
|
};
|
|
49
60
|
}
|
|
50
61
|
|
|
@@ -158,6 +169,10 @@ export async function sendHttpRequest<
|
|
|
158
169
|
}),
|
|
159
170
|
);
|
|
160
171
|
} catch (error) {
|
|
172
|
+
// Credential providers and custom transports can already supply a structured error.
|
|
173
|
+
if (ActorError.isRivetError(error)) {
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
161
176
|
throw new HttpRequestError(`Request failed: ${error}`, {
|
|
162
177
|
cause: error,
|
|
163
178
|
});
|
|
@@ -52,8 +52,6 @@ export interface SqliteTransactionOptions {
|
|
|
52
52
|
* to change without notice.
|
|
53
53
|
*/
|
|
54
54
|
export interface SqliteProfilingOptions {
|
|
55
|
-
/** Existing v2 switch. Default: true. */
|
|
56
|
-
enabled?: boolean;
|
|
57
55
|
/** Exact SQL filter. Union with filterQueryFingerprints; both empty means all queries. */
|
|
58
56
|
filterQueries?: string[];
|
|
59
57
|
/** Fingerprint filter, including transaction fingerprints. Filters metrics, not diagnostic logs. */
|
|
@@ -108,6 +108,11 @@ export type StateAwareSqliteDatabase = SqliteDatabase & {
|
|
|
108
108
|
): Promise<SqliteTransactionDatabase>;
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
+
type NativeSqliteDatabase = StateAwareSqliteDatabase & {
|
|
112
|
+
/** Stop JS calls while leaving the runtime-owned backend open. */
|
|
113
|
+
detachForShutdown(): Promise<void>;
|
|
114
|
+
};
|
|
115
|
+
|
|
111
116
|
export interface JsNativeTransactionLike {
|
|
112
117
|
exec(sql: string): Promise<NativeExecResult>;
|
|
113
118
|
execute(
|
|
@@ -311,7 +316,7 @@ class NativeCloseGate {
|
|
|
311
316
|
};
|
|
312
317
|
}
|
|
313
318
|
|
|
314
|
-
async close(callback
|
|
319
|
+
async close(callback?: () => Promise<void>): Promise<void> {
|
|
315
320
|
if (this.#closed) {
|
|
316
321
|
return;
|
|
317
322
|
}
|
|
@@ -319,15 +324,17 @@ class NativeCloseGate {
|
|
|
319
324
|
if (this.#active > 0) {
|
|
320
325
|
await new Promise<void>((resolve) => this.#waiters.push(resolve));
|
|
321
326
|
}
|
|
322
|
-
await callback();
|
|
327
|
+
await callback?.();
|
|
323
328
|
}
|
|
324
329
|
}
|
|
325
330
|
|
|
326
331
|
export function wrapJsNativeDatabase(
|
|
327
332
|
database: JsNativeDatabaseLike,
|
|
328
|
-
):
|
|
333
|
+
): NativeSqliteDatabase {
|
|
329
334
|
const gate = new NativeCloseGate();
|
|
330
|
-
|
|
335
|
+
// Detach and explicit close are mutually exclusive terminal operations.
|
|
336
|
+
// Whichever starts first defines whether the backend is physically closed.
|
|
337
|
+
let terminalPromise: Promise<void> | undefined;
|
|
331
338
|
let lastInsertRowId: number | null = null;
|
|
332
339
|
|
|
333
340
|
const executeNative = async (
|
|
@@ -485,8 +492,12 @@ export function wrapJsNativeDatabase(
|
|
|
485
492
|
return normalizeNativeMetrics(database.metrics?.());
|
|
486
493
|
},
|
|
487
494
|
async close(): Promise<void> {
|
|
488
|
-
|
|
489
|
-
await
|
|
495
|
+
terminalPromise ??= gate.close(() => database.close());
|
|
496
|
+
await terminalPromise;
|
|
497
|
+
},
|
|
498
|
+
async detachForShutdown(): Promise<void> {
|
|
499
|
+
terminalPromise ??= gate.close();
|
|
500
|
+
await terminalPromise;
|
|
490
501
|
},
|
|
491
502
|
};
|
|
492
503
|
}
|
package/src/common/router.ts
CHANGED
|
@@ -182,7 +182,7 @@ export function handleMetadataRequest(
|
|
|
182
182
|
version: VERSION,
|
|
183
183
|
envoy: {
|
|
184
184
|
kind: envoyKind,
|
|
185
|
-
version: config.
|
|
185
|
+
version: config.node.version,
|
|
186
186
|
},
|
|
187
187
|
envoyProtocolVersion: envoyProtocol.VERSION,
|
|
188
188
|
actorNames: buildActorNames(config),
|
package/src/engine-api/actors.ts
CHANGED
|
@@ -6,7 +6,7 @@ export const ActorSchema = z.object({
|
|
|
6
6
|
name: z.string(),
|
|
7
7
|
key: z.string(),
|
|
8
8
|
namespace_id: RivetIdSchema,
|
|
9
|
-
|
|
9
|
+
pool: z.string(),
|
|
10
10
|
create_ts: z.number(),
|
|
11
11
|
connectable_ts: z.number().nullable().optional(),
|
|
12
12
|
destroy_ts: z.number().nullable().optional(),
|
|
@@ -31,7 +31,7 @@ export type ActorsListResponse = z.infer<typeof ActorsListResponseSchema>;
|
|
|
31
31
|
export const ActorsCreateRequestSchema = z.object({
|
|
32
32
|
datacenter: z.string().optional(),
|
|
33
33
|
name: z.string(),
|
|
34
|
-
|
|
34
|
+
pool: z.string(),
|
|
35
35
|
crash_policy: z.string(),
|
|
36
36
|
key: z.string().nullable().optional(),
|
|
37
37
|
input: z.string().nullable().optional(),
|
|
@@ -48,7 +48,7 @@ export const ActorsGetOrCreateRequestSchema = z.object({
|
|
|
48
48
|
datacenter: z.string().optional(),
|
|
49
49
|
name: z.string(),
|
|
50
50
|
key: z.string(),
|
|
51
|
-
|
|
51
|
+
pool: z.string(),
|
|
52
52
|
crash_policy: z.string(),
|
|
53
53
|
input: z.string().nullable().optional(),
|
|
54
54
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { actorKeyToGatewayQuery } from "@/actor/keys";
|
|
1
2
|
import {
|
|
2
3
|
type ClientConfig,
|
|
3
4
|
DEFAULT_MAX_QUERY_INPUT_SIZE,
|
|
@@ -289,8 +290,9 @@ export function buildActorQueryGatewayUrl(
|
|
|
289
290
|
}
|
|
290
291
|
|
|
291
292
|
function pushKeyQueryParams(params: URLSearchParams, key: string[]): void {
|
|
292
|
-
|
|
293
|
-
|
|
293
|
+
const rvtKey = actorKeyToGatewayQuery(key);
|
|
294
|
+
if (rvtKey !== undefined) {
|
|
295
|
+
params.append("rvt-key", rvtKey);
|
|
294
296
|
}
|
|
295
297
|
}
|
|
296
298
|
|
|
@@ -167,17 +167,6 @@ export interface RunnerConfigsResponse {
|
|
|
167
167
|
runner_configs: Record<string, RunnerConfigDatacenters>;
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
export async function getRunnerConfig(
|
|
171
|
-
config: ClientConfig,
|
|
172
|
-
name: string,
|
|
173
|
-
): Promise<RunnerConfigsResponse> {
|
|
174
|
-
return apiCall<never, RunnerConfigsResponse>(
|
|
175
|
-
config,
|
|
176
|
-
"GET",
|
|
177
|
-
`/runner-configs?runner_name=${name}`,
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
170
|
// MARK: Update runner config
|
|
182
171
|
export interface RegistryConfigRequest {
|
|
183
172
|
datacenters: Record<
|
|
@@ -212,11 +201,11 @@ export async function updateRunnerConfig(
|
|
|
212
201
|
runnerName: string,
|
|
213
202
|
request: RegistryConfigRequest,
|
|
214
203
|
): Promise<void> {
|
|
215
|
-
return apiCall<
|
|
204
|
+
return apiCall<unknown, void>(
|
|
216
205
|
config,
|
|
217
206
|
"PUT",
|
|
218
|
-
`/
|
|
219
|
-
request,
|
|
207
|
+
`/pools/${encodeURIComponent(runnerName)}`,
|
|
208
|
+
Object.values(request.datacenters)[0],
|
|
220
209
|
);
|
|
221
210
|
}
|
|
222
211
|
|
|
@@ -237,3 +226,44 @@ export async function kvGet(
|
|
|
237
226
|
`/actors/${encodeURIComponent(actorId)}/kv/keys/${encodeURIComponent(key)}`,
|
|
238
227
|
);
|
|
239
228
|
}
|
|
229
|
+
|
|
230
|
+
/** Pool changes apply when each node next connects. */
|
|
231
|
+
export interface PoolConfig {
|
|
232
|
+
drain_on_version_upgrade?: boolean;
|
|
233
|
+
actor_eviction_delay?: number;
|
|
234
|
+
actor_eviction_period?: number;
|
|
235
|
+
actor_eviction_rate?: number;
|
|
236
|
+
metadata?: unknown;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function upsertPool(
|
|
240
|
+
config: ClientConfig,
|
|
241
|
+
name: string,
|
|
242
|
+
pool: PoolConfig,
|
|
243
|
+
): Promise<{ pool: PoolConfig & { name: string } }> {
|
|
244
|
+
return apiCall(config, "PUT", `/pools/${encodeURIComponent(name)}`, pool);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function getPool(
|
|
248
|
+
config: ClientConfig,
|
|
249
|
+
name: string,
|
|
250
|
+
): Promise<{ pool: PoolConfig & { name: string } }> {
|
|
251
|
+
return apiCall(config, "GET", `/pools/${encodeURIComponent(name)}`);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export function listPools(
|
|
255
|
+
config: ClientConfig,
|
|
256
|
+
page?: { limit?: number; cursor?: string },
|
|
257
|
+
): Promise<{
|
|
258
|
+
pools: Array<PoolConfig & { name: string }>;
|
|
259
|
+
pagination: { cursor: string | null };
|
|
260
|
+
}> {
|
|
261
|
+
const query = new URLSearchParams();
|
|
262
|
+
if (page?.limit !== undefined) query.set("limit", String(page.limit));
|
|
263
|
+
if (page?.cursor !== undefined) query.set("cursor", page.cursor);
|
|
264
|
+
return apiCall(config, "GET", `/pools?${query}`);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function deletePool(config: ClientConfig, name: string): Promise<void> {
|
|
268
|
+
return apiCall(config, "DELETE", `/pools/${encodeURIComponent(name)}`);
|
|
269
|
+
}
|
package/src/engine-client/mod.ts
CHANGED
|
@@ -254,7 +254,7 @@ export class RemoteEngineControlClient implements EngineControlClient {
|
|
|
254
254
|
datacenter: region,
|
|
255
255
|
name,
|
|
256
256
|
key: serializeActorKey(key),
|
|
257
|
-
|
|
257
|
+
pool: poolName ?? this.#config.poolName,
|
|
258
258
|
input: actorInput
|
|
259
259
|
? uint8ArrayToBase64(
|
|
260
260
|
encodeCborCompat(actorInput as JsonCompatValue),
|
|
@@ -325,7 +325,7 @@ export class RemoteEngineControlClient implements EngineControlClient {
|
|
|
325
325
|
createActor(config, {
|
|
326
326
|
datacenter: region,
|
|
327
327
|
name,
|
|
328
|
-
|
|
328
|
+
pool: poolName ?? this.#config.poolName,
|
|
329
329
|
key: serializeActorKey(key),
|
|
330
330
|
input: input
|
|
331
331
|
? uint8ArrayToBase64(
|
|
@@ -11,7 +11,7 @@ export const EnvoyConfigSchema = z.object({
|
|
|
11
11
|
|
|
12
12
|
// Deprecated.
|
|
13
13
|
totalSlots: z.number().default(() => getRivetTotalSlots() ?? 100000),
|
|
14
|
-
|
|
14
|
+
nodeKey: z.string().optional(),
|
|
15
15
|
});
|
|
16
16
|
export type EnvoyConfigInput = z.input<typeof EnvoyConfigSchema>;
|
|
17
17
|
export type EnvoyConfig = z.infer<typeof EnvoyConfigSchema>;
|
|
@@ -158,7 +158,7 @@ export const RegistryConfigSchema = z
|
|
|
158
158
|
// // created or must be imported async using `await import(...)`
|
|
159
159
|
// getUpgradeWebSocket: z.custom<GetUpgradeWebSocket>().optional(),
|
|
160
160
|
|
|
161
|
-
// MARK:
|
|
161
|
+
// MARK: Node Configuration
|
|
162
162
|
/**
|
|
163
163
|
* Endpoint to connect to for Rivet Engine.
|
|
164
164
|
*
|
|
@@ -251,14 +251,14 @@ export const RegistryConfigSchema = z
|
|
|
251
251
|
.default(() => getRivetRunEngineVersion() ?? VERSION),
|
|
252
252
|
/**
|
|
253
253
|
* Starts the first-party Services actor host when RivetKit manages
|
|
254
|
-
* a local engine.
|
|
255
|
-
* RIVET_RUN_SERVICES=0 or
|
|
254
|
+
* a local engine. Enabled by default for a managed local Engine. Set
|
|
255
|
+
* RIVET_RUN_SERVICES=0 or startServices: false to disable it.
|
|
256
256
|
*/
|
|
257
257
|
startServices: z.boolean().optional(),
|
|
258
258
|
/**
|
|
259
259
|
* @experimental
|
|
260
260
|
*
|
|
261
|
-
* Automatically configure serverless
|
|
261
|
+
* Automatically configure serverless nodes in the engine.
|
|
262
262
|
*/
|
|
263
263
|
configurePool: ConfigurePoolSchema.optional(),
|
|
264
264
|
|
|
@@ -266,7 +266,7 @@ export const RegistryConfigSchema = z
|
|
|
266
266
|
serverless: ServerlessConfigSchema.optional().default(() =>
|
|
267
267
|
ServerlessConfigSchema.parse({}),
|
|
268
268
|
),
|
|
269
|
-
|
|
269
|
+
node: EnvoyConfigSchema.optional().default(() =>
|
|
270
270
|
EnvoyConfigSchema.parse({}),
|
|
271
271
|
),
|
|
272
272
|
|
|
@@ -274,9 +274,9 @@ export const RegistryConfigSchema = z
|
|
|
274
274
|
/**
|
|
275
275
|
* Graceful shutdown configuration for SIGINT/SIGTERM.
|
|
276
276
|
*
|
|
277
|
-
* When a persistent
|
|
277
|
+
* When a persistent node is running (Mode A, started via `registry.start()`),
|
|
278
278
|
* rivetkit installs Node SIGINT/SIGTERM handlers that call into core's
|
|
279
|
-
* `shutdown()` and wait up to `gracePeriodMs` for the
|
|
279
|
+
* `shutdown()` and wait up to `gracePeriodMs` for the node to drain
|
|
280
280
|
* before re-raising the signal to let Node exit via its default path.
|
|
281
281
|
*
|
|
282
282
|
* Handlers are NOT installed when `handler(request)` is used alone
|
|
@@ -289,9 +289,12 @@ export const RegistryConfigSchema = z
|
|
|
289
289
|
/**
|
|
290
290
|
* Wait this many milliseconds for the serve promise to resolve
|
|
291
291
|
* after calling `CoreRegistry::shutdown()`. Defaults to the
|
|
292
|
-
* engine-provided actor stop threshold once the
|
|
292
|
+
* engine-provided actor stop threshold once the node connects. A
|
|
293
|
+
* signal-driven shutdown of a managed local development engine waits
|
|
294
|
+
* four seconds by default so actors can acknowledge stopping before
|
|
295
|
+
* a file watcher restarts the process.
|
|
293
296
|
*
|
|
294
|
-
*
|
|
297
|
+
* Set a longer period when a complete graceful node drain is required.
|
|
295
298
|
*/
|
|
296
299
|
gracePeriodMs: z.number().int().min(1_000).optional(),
|
|
297
300
|
/**
|
|
@@ -348,12 +351,12 @@ export const RegistryConfigSchema = z
|
|
|
348
351
|
});
|
|
349
352
|
}
|
|
350
353
|
|
|
351
|
-
//
|
|
352
|
-
if (config.configurePool
|
|
354
|
+
// Serverless pool configuration is disabled for v3.
|
|
355
|
+
if (config.configurePool) {
|
|
353
356
|
ctx.addIssue({
|
|
354
357
|
code: "custom",
|
|
355
|
-
message:
|
|
356
|
-
|
|
358
|
+
message: "serverless is disabled in this version",
|
|
359
|
+
path: ["configurePool"],
|
|
357
360
|
});
|
|
358
361
|
}
|
|
359
362
|
|
|
@@ -366,13 +369,9 @@ export const RegistryConfigSchema = z
|
|
|
366
369
|
? localEngineEndpoint
|
|
367
370
|
: (parsedEndpoint?.endpoint ??
|
|
368
371
|
(isDevEnv ? localEngineEndpoint : undefined));
|
|
369
|
-
|
|
370
|
-
// follows the same local-endpoint decision that causes core to manage the
|
|
371
|
-
// Engine, while explicit config and RIVET_RUN_SERVICES take precedence.
|
|
372
|
+
const engineSpawn = !parsedEndpoint && Boolean(endpoint);
|
|
372
373
|
const startServices =
|
|
373
|
-
config.startServices ??
|
|
374
|
-
getRivetRunServices() ??
|
|
375
|
-
Boolean(endpoint && isLocalEngineEndpoint(endpoint));
|
|
374
|
+
config.startServices ?? getRivetRunServices() ?? engineSpawn;
|
|
376
375
|
const validateServerlessEndpoint = Boolean(
|
|
377
376
|
config.startEngine || parsedEndpoint,
|
|
378
377
|
);
|
|
@@ -422,6 +421,7 @@ export const RegistryConfigSchema = z
|
|
|
422
421
|
...config,
|
|
423
422
|
sqlite,
|
|
424
423
|
endpoint,
|
|
424
|
+
engineSpawn,
|
|
425
425
|
startServices,
|
|
426
426
|
namespace,
|
|
427
427
|
token,
|
|
@@ -468,10 +468,10 @@ export function buildActorNames(
|
|
|
468
468
|
|
|
469
469
|
export const DocConfigurePoolSchema = z
|
|
470
470
|
.object({
|
|
471
|
-
name: z.string().optional().describe("Name of the
|
|
471
|
+
name: z.string().optional().describe("Name of the node pool."),
|
|
472
472
|
url: z
|
|
473
473
|
.string()
|
|
474
|
-
.describe("URL of the serverless platform to configure
|
|
474
|
+
.describe("URL of the serverless platform to configure nodes."),
|
|
475
475
|
headers: z
|
|
476
476
|
.record(z.string(), z.string())
|
|
477
477
|
.optional()
|
|
@@ -504,7 +504,7 @@ export const DocConfigurePoolSchema = z
|
|
|
504
504
|
.boolean()
|
|
505
505
|
.optional()
|
|
506
506
|
.describe(
|
|
507
|
-
"Drain
|
|
507
|
+
"Drain nodes when a new version is deployed. Defaults to true.",
|
|
508
508
|
),
|
|
509
509
|
})
|
|
510
510
|
.optional();
|
|
@@ -547,17 +547,17 @@ export const DocEnvoyConfigSchema = z
|
|
|
547
547
|
poolName: z
|
|
548
548
|
.string()
|
|
549
549
|
.optional()
|
|
550
|
-
.describe("Name of this
|
|
551
|
-
|
|
550
|
+
.describe("Name of this node pool. Default: 'default'"),
|
|
551
|
+
nodeKey: z
|
|
552
552
|
.string()
|
|
553
553
|
.optional()
|
|
554
|
-
.describe("Deprecated. Authentication key for the
|
|
554
|
+
.describe("Deprecated. Authentication key for the node."),
|
|
555
555
|
version: z
|
|
556
556
|
.number()
|
|
557
557
|
.optional()
|
|
558
|
-
.describe("Version number of this
|
|
558
|
+
.describe("Version number of this node. Default: 1"),
|
|
559
559
|
})
|
|
560
|
-
.describe("Configuration for
|
|
560
|
+
.describe("Configuration for node mode.");
|
|
561
561
|
|
|
562
562
|
export const DocSqliteConfigSchema = z
|
|
563
563
|
.object({
|
|
@@ -658,12 +658,12 @@ export const DocRegistryConfigSchema = z
|
|
|
658
658
|
.boolean()
|
|
659
659
|
.optional()
|
|
660
660
|
.describe(
|
|
661
|
-
"Starts Services when RivetKit manages a local Engine.
|
|
661
|
+
"Starts Services when RivetKit manages a local Engine. Enabled by default for a managed local Engine. Set RIVET_RUN_SERVICES=0 or startServices: false to disable.",
|
|
662
662
|
),
|
|
663
663
|
configurePool: DocConfigurePoolSchema.describe(
|
|
664
|
-
"Automatically configure serverless
|
|
664
|
+
"Automatically configure serverless nodes in the engine.",
|
|
665
665
|
),
|
|
666
666
|
serverless: DocServerlessConfigSchema.optional(),
|
|
667
|
-
|
|
667
|
+
node: DocEnvoyConfigSchema.optional(),
|
|
668
668
|
})
|
|
669
669
|
.describe("RivetKit registry configuration.");
|