rivetkit 0.0.0-sqlite-profiling-compat.87d61c0 → 0.0.0-sqlite-sync-3x-release.a00b07f
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 +1317 -765
- package/dist/browser/client.js +1457 -737
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +252 -129
- package/dist/browser/inspector/client.js +2042 -228
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/actor/errors.cjs +6 -2
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +1 -1
- package/dist/tsup/actor/errors.d.ts +1 -1
- package/dist/tsup/actor/errors.js +5 -1
- package/dist/tsup/agent-os/index.cjs +3 -2367
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +1 -2277
- package/dist/tsup/agent-os/index.d.ts +1 -2277
- package/dist/tsup/agent-os/index.js +3 -2367
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-E4LNLI3W.cjs → chunk-2MOLY6AM.cjs} +444 -29
- package/dist/tsup/chunk-2MOLY6AM.cjs.map +1 -0
- package/dist/tsup/{chunk-OAUFXOG7.js → chunk-3DONDAMG.js} +2 -2
- package/dist/tsup/{chunk-XIX5DOZN.js → chunk-6FEYCVZC.js} +196 -20
- package/dist/tsup/chunk-6FEYCVZC.js.map +1 -0
- package/dist/tsup/chunk-6KXVLIXL.cjs +14 -0
- package/dist/tsup/chunk-6KXVLIXL.cjs.map +1 -0
- package/dist/tsup/chunk-73RNTXHB.cjs +243 -0
- package/dist/tsup/chunk-73RNTXHB.cjs.map +1 -0
- package/dist/tsup/{chunk-HXUEHHJF.js → chunk-A2CF6PFH.js} +19 -11
- package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
- package/dist/tsup/{chunk-EFU4JW3T.js → chunk-BRH4PQS5.js} +436 -21
- package/dist/tsup/chunk-BRH4PQS5.js.map +1 -0
- package/dist/tsup/{chunk-GM45LG7L.cjs → chunk-BTSDFFDC.cjs} +18 -11
- package/dist/tsup/chunk-BTSDFFDC.cjs.map +1 -0
- package/dist/tsup/{chunk-B3GLD4IN.js → chunk-D5WUPE47.js} +50 -3
- package/dist/tsup/chunk-D5WUPE47.js.map +1 -0
- package/dist/tsup/{chunk-O3ZUMAN7.js → chunk-DJUBJQEQ.js} +3 -3
- package/dist/tsup/chunk-DJUBJQEQ.js.map +1 -0
- package/dist/tsup/{chunk-3MHDOUD7.cjs → chunk-HDVZ6YZG.cjs} +197 -21
- package/dist/tsup/chunk-HDVZ6YZG.cjs.map +1 -0
- package/dist/tsup/{chunk-JZ7TWV65.js → chunk-JTHHCZCZ.js} +24 -1
- package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
- package/dist/tsup/{chunk-D363DMNH.cjs → chunk-JUHXV3HF.cjs} +3 -3
- package/dist/tsup/chunk-JUHXV3HF.cjs.map +1 -0
- package/dist/tsup/chunk-JUWMP5O3.js +14 -0
- package/dist/tsup/chunk-JUWMP5O3.js.map +1 -0
- package/dist/tsup/{chunk-ZA7FLHKH.cjs → chunk-KVFIONKQ.cjs} +25 -2
- package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
- package/dist/tsup/{chunk-4FC7TVS6.cjs → chunk-MGI2VVF6.cjs} +39 -7
- package/dist/tsup/chunk-MGI2VVF6.cjs.map +1 -0
- package/dist/tsup/{chunk-BWERJMV6.cjs → chunk-OTVJYZ2L.cjs} +1139 -470
- package/dist/tsup/chunk-OTVJYZ2L.cjs.map +1 -0
- package/dist/tsup/{chunk-VE2X4KMG.cjs → chunk-RTWH3AX3.cjs} +18 -10
- package/dist/tsup/chunk-RTWH3AX3.cjs.map +1 -0
- package/dist/tsup/{chunk-DTRDGPHU.cjs → chunk-TM76Z7XT.cjs} +7 -7
- package/dist/tsup/chunk-TM76Z7XT.cjs.map +1 -0
- package/dist/tsup/{chunk-3GVMLSND.js → chunk-TRUHDXOU.js} +1023 -354
- package/dist/tsup/chunk-TRUHDXOU.js.map +1 -0
- package/dist/tsup/{chunk-PT7AC5PC.js → chunk-TSQTI6H6.js} +16 -9
- package/dist/tsup/chunk-TSQTI6H6.js.map +1 -0
- package/dist/tsup/{chunk-FNAXD5BQ.cjs → chunk-Z7E2G3JZ.cjs} +52 -5
- package/dist/tsup/chunk-Z7E2G3JZ.cjs.map +1 -0
- package/dist/tsup/{chunk-ZZ3WBRPD.js → chunk-ZOVJDAOW.js} +38 -6
- package/dist/tsup/chunk-ZOVJDAOW.js.map +1 -0
- package/dist/tsup/chunk-ZYK4B5WV.js +243 -0
- package/dist/tsup/chunk-ZYK4B5WV.js.map +1 -0
- package/dist/tsup/client/mod.cjs +8 -9
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +32 -6
- package/dist/tsup/client/mod.d.ts +32 -6
- package/dist/tsup/client/mod.js +7 -8
- package/dist/tsup/common/log.cjs +5 -3
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.d.cts +5 -1
- package/dist/tsup/common/log.d.ts +5 -1
- package/dist/tsup/common/log.js +6 -4
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.cjs.map +1 -1
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{config-BR1Nn0QQ.d.ts → config-B4erdavw.d.ts} +571 -65
- package/dist/tsup/{config-B0LNDrLY.d.cts → config-BfG1qpYz.d.cts} +80 -14
- package/dist/tsup/{config-B0LNDrLY.d.ts → config-BfG1qpYz.d.ts} +80 -14
- package/dist/tsup/{config-tCvkwzyN.d.cts → config-DK144OAw.d.cts} +571 -65
- package/dist/tsup/{context-D4WDwf9m.d.cts → context-Cvnf3BRe.d.cts} +3 -2
- package/dist/tsup/{context-oc9zhA3x.d.ts → context-Oxi6YWcG.d.ts} +3 -2
- package/dist/tsup/db/drizzle.cjs +127 -67
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +8 -4
- package/dist/tsup/db/drizzle.d.ts +8 -4
- package/dist/tsup/db/drizzle.js +127 -67
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +6 -126
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +8 -4
- package/dist/tsup/db/mod.d.ts +8 -4
- package/dist/tsup/db/mod.js +5 -125
- package/dist/tsup/db/mod.js.map +1 -1
- package/dist/tsup/dynamic/mod.cjs +2 -2
- package/dist/tsup/dynamic/mod.cjs.map +1 -1
- package/dist/tsup/dynamic/mod.d.cts +6 -4
- package/dist/tsup/dynamic/mod.d.ts +6 -4
- package/dist/tsup/dynamic/mod.js +1 -1
- package/dist/tsup/inspector/mod.cjs +47 -12
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +26 -136
- package/dist/tsup/inspector/mod.d.ts +26 -136
- package/dist/tsup/inspector/mod.js +46 -11
- package/dist/tsup/inspector/mod.js.map +1 -1
- package/dist/tsup/inspector/workflow.cjs +21 -0
- package/dist/tsup/inspector/workflow.cjs.map +1 -0
- package/dist/tsup/inspector/workflow.d.cts +144 -0
- package/dist/tsup/inspector/workflow.d.ts +144 -0
- package/dist/tsup/inspector/workflow.js +21 -0
- package/dist/tsup/inspector/workflow.js.map +1 -0
- package/dist/tsup/inspector-tab/mod.cjs +2 -13
- package/dist/tsup/inspector-tab/mod.cjs.map +1 -1
- package/dist/tsup/inspector-tab/mod.d.cts +9 -17
- package/dist/tsup/inspector-tab/mod.d.ts +9 -17
- package/dist/tsup/inspector-tab/mod.js +1 -12
- package/dist/tsup/inspector-tab/mod.js.map +1 -1
- package/dist/tsup/mod.cjs +2724 -611
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +9 -7
- package/dist/tsup/mod.d.ts +9 -7
- package/dist/tsup/mod.js +2641 -528
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +19 -17
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +6 -4
- package/dist/tsup/test/mod.d.ts +6 -4
- package/dist/tsup/test/mod.js +18 -16
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/unstable/migrations.cjs +101 -0
- package/dist/tsup/unstable/migrations.cjs.map +1 -0
- package/dist/tsup/unstable/migrations.d.cts +29 -0
- package/dist/tsup/unstable/migrations.d.ts +29 -0
- package/dist/tsup/unstable/migrations.js +101 -0
- package/dist/tsup/unstable/migrations.js.map +1 -0
- package/dist/tsup/{utils-CqDnC_PS.d.cts → utils-3rsE0JvI.d.cts} +25 -2
- package/dist/tsup/{utils-CqDnC_PS.d.ts → utils-3rsE0JvI.d.ts} +25 -2
- package/dist/tsup/utils-C1O-SklO.d.ts +162 -0
- package/dist/tsup/utils-C6b0aYUM.d.cts +162 -0
- package/dist/tsup/utils.cjs +7 -3
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +4 -147
- package/dist/tsup/utils.d.ts +4 -147
- package/dist/tsup/utils.js +6 -2
- package/dist/tsup/workflow/mod.cjs +260 -200
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +8 -6
- package/dist/tsup/workflow/mod.d.ts +8 -6
- package/dist/tsup/workflow/mod.js +249 -189
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +34 -14
- package/src/actor/actions.ts +155 -0
- package/src/actor/config.ts +403 -43
- package/src/actor/definition.ts +26 -7
- package/src/actor/errors.ts +87 -5
- package/src/actor/keys.ts +86 -0
- package/src/actor/mod.ts +15 -1
- package/src/actor/tracing.ts +28 -0
- package/src/agent-os/index.ts +5 -65
- package/src/client/actor-common.ts +8 -15
- package/src/client/actor-conn.ts +135 -8
- package/src/client/actor-handle.ts +180 -42
- package/src/client/actor-query.ts +8 -1
- package/src/client/auth.ts +37 -0
- package/src/client/client.ts +89 -21
- package/src/client/config.ts +27 -2
- package/src/client/errors.ts +2 -1
- package/src/client/lifecycle-errors.ts +16 -1
- package/src/client/mod.ts +9 -0
- package/src/client/outbound-telemetry.ts +66 -0
- package/src/client/query.ts +2 -0
- package/src/client/queue.ts +3 -0
- package/src/client/raw-utils.ts +37 -8
- package/src/client/resolve-gateway-target.ts +2 -0
- package/src/client/retry-budget.ts +78 -0
- package/src/client/token-provider.ts +93 -0
- package/src/client/utils.ts +16 -2
- package/src/common/actor-router-consts.ts +5 -0
- package/src/common/actor-telemetry-context.ts +19 -0
- package/src/common/bare/generated/actor-runtime-socket-protocol/v1.ts +848 -0
- package/src/common/bare/generated/inspector/v5.ts +1016 -0
- package/src/common/bare/generated/inspector/v6.ts +1367 -0
- package/src/common/bare/transport/v1.ts +36 -0
- package/src/common/database/config.ts +108 -15
- package/src/common/database/mod.ts +247 -76
- package/src/common/database/native-database.ts +433 -23
- package/src/common/database/shared.ts +24 -0
- package/src/common/encoding.ts +31 -21
- package/src/common/fetch-like.ts +63 -0
- package/src/common/inspector-transport.ts +12 -2
- package/src/common/log.ts +14 -8
- package/src/common/otel-context.ts +99 -0
- package/src/common/router.ts +1 -1
- package/src/common/utils.ts +7 -19
- package/src/db/drizzle.ts +182 -80
- package/src/db/mod.ts +2 -0
- package/src/dynamic/isolate-runtime.ts +0 -2
- package/src/engine-api/actors.ts +3 -3
- package/src/engine-client/actor-http-client.ts +29 -20
- package/src/engine-client/actor-websocket-client.ts +6 -3
- package/src/engine-client/api-endpoints.ts +72 -14
- package/src/engine-client/driver.ts +8 -15
- package/src/engine-client/mod.ts +248 -112
- package/src/inspector/client.browser.ts +134 -16
- package/src/inspector/mod.ts +1 -1
- package/src/inspector/workflow.ts +61 -0
- package/src/inspector-tab/mod.ts +1 -15
- package/src/registry/config/envoy.ts +2 -18
- package/src/registry/config/index.ts +53 -61
- package/src/registry/index.ts +311 -21
- package/src/registry/napi-runtime.ts +583 -39
- package/src/registry/native-http.ts +225 -0
- package/src/registry/native.ts +1365 -414
- package/src/registry/run-handler-coordinator.ts +219 -0
- package/src/registry/runtime.ts +372 -7
- package/src/registry/wasm-runtime.ts +490 -21
- package/src/registry/write-through-proxy.ts +101 -0
- package/src/test/mod.ts +1 -19
- package/src/test/ready.ts +22 -0
- package/src/unstable/migrations.ts +141 -0
- package/src/utils/env-vars.ts +15 -6
- package/src/utils/node.ts +44 -28
- package/src/utils.ts +3 -0
- package/src/workflow/context.ts +9 -27
- package/src/workflow/driver.ts +253 -116
- package/src/workflow/inspector.ts +23 -24
- package/src/workflow/mod.ts +50 -72
- package/dist/tsup/chunk-3GVMLSND.js.map +0 -1
- package/dist/tsup/chunk-3MHDOUD7.cjs.map +0 -1
- package/dist/tsup/chunk-4FC7TVS6.cjs.map +0 -1
- package/dist/tsup/chunk-B3GLD4IN.js.map +0 -1
- package/dist/tsup/chunk-BWERJMV6.cjs.map +0 -1
- package/dist/tsup/chunk-D363DMNH.cjs.map +0 -1
- package/dist/tsup/chunk-DTRDGPHU.cjs.map +0 -1
- package/dist/tsup/chunk-E4LNLI3W.cjs.map +0 -1
- package/dist/tsup/chunk-EFU4JW3T.js.map +0 -1
- package/dist/tsup/chunk-FNAXD5BQ.cjs.map +0 -1
- package/dist/tsup/chunk-GM45LG7L.cjs.map +0 -1
- package/dist/tsup/chunk-HXUEHHJF.js.map +0 -1
- package/dist/tsup/chunk-JZ7TWV65.js.map +0 -1
- package/dist/tsup/chunk-O3ZUMAN7.js.map +0 -1
- package/dist/tsup/chunk-P6F5MEWX.cjs +0 -382
- package/dist/tsup/chunk-P6F5MEWX.cjs.map +0 -1
- package/dist/tsup/chunk-PT7AC5PC.js.map +0 -1
- package/dist/tsup/chunk-UV7INX3N.js +0 -382
- package/dist/tsup/chunk-UV7INX3N.js.map +0 -1
- package/dist/tsup/chunk-VE2X4KMG.cjs.map +0 -1
- package/dist/tsup/chunk-XIX5DOZN.js.map +0 -1
- package/dist/tsup/chunk-ZA7FLHKH.cjs.map +0 -1
- package/dist/tsup/chunk-ZZ3WBRPD.js.map +0 -1
- package/src/actor/driver.ts +0 -141
- package/src/actor/instance/mod.ts +0 -2484
- package/src/actor/keys.test.ts +0 -275
- package/src/actor/utils.test.ts +0 -48
- package/src/agent-os/actor/cron.ts +0 -84
- package/src/agent-os/actor/db.ts +0 -54
- package/src/agent-os/actor/filesystem.ts +0 -131
- package/src/agent-os/actor/index.ts +0 -285
- package/src/agent-os/actor/network.ts +0 -58
- package/src/agent-os/actor/preview.ts +0 -190
- package/src/agent-os/actor/process.ts +0 -177
- package/src/agent-os/actor/session.ts +0 -518
- package/src/agent-os/actor/shell.ts +0 -60
- package/src/agent-os/config.ts +0 -79
- package/src/agent-os/fs/database-vfs.ts +0 -624
- package/src/agent-os/types.ts +0 -148
- package/src/client/test.ts +0 -44
- package/src/common/database/mod.test.ts +0 -137
- package/src/common/database/native-database.test.ts +0 -211
- package/src/common/inline-websocket-adapter.test.ts +0 -51
- package/src/drivers/engine/actor-driver.ts +0 -2473
- package/src/registry/process-metrics.ts +0 -250
- package/src/registry/runtime.test.ts +0 -50
- package/src/utils/endpoint-parser.test.ts +0 -206
- package/src/utils.test.ts +0 -34
- /package/dist/tsup/{chunk-OAUFXOG7.js.map → chunk-3DONDAMG.js.map} +0 -0
package/src/client/client.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { AnyActorDefinition } from "@/actor/definition";
|
|
2
|
+
import type { IssuedToken, IssueTokenOptions } from "@/client/auth";
|
|
2
3
|
import type { ActorQuery } from "@/client/query";
|
|
3
4
|
import type { Encoding } from "@/common/encoding";
|
|
4
5
|
import type { EngineControlClient } from "@/engine-client/driver";
|
|
5
6
|
import type { Registry } from "@/registry";
|
|
7
|
+
import type { StartCallSpan, CurrentActorInvocation } from "@/registry/runtime";
|
|
6
8
|
import type { ActorActionFunction, ActorGatewayOptions } from "./actor-common";
|
|
7
9
|
import {
|
|
8
10
|
type ActorConn,
|
|
@@ -12,6 +14,7 @@ import {
|
|
|
12
14
|
import { type ActorHandle, ActorHandleRaw } from "./actor-handle";
|
|
13
15
|
import { logger } from "./log";
|
|
14
16
|
import { resolveGatewayTarget } from "./resolve-gateway-target";
|
|
17
|
+
import { type RetryBudgetOptions, RetryBudget } from "./retry-budget";
|
|
15
18
|
|
|
16
19
|
export type { ClientConfig, ClientConfigInput } from "./config";
|
|
17
20
|
|
|
@@ -128,6 +131,11 @@ export interface GetOrCreateOptions extends QueryOptions {
|
|
|
128
131
|
createInRegion?: string;
|
|
129
132
|
/** Input data to pass to the actor. */
|
|
130
133
|
createWithInput?: unknown;
|
|
134
|
+
/**
|
|
135
|
+
* Name of the envoy pool to select for this actor if it is created.
|
|
136
|
+
* Overrides the client's configured `poolName` for this call.
|
|
137
|
+
*/
|
|
138
|
+
poolName?: string;
|
|
131
139
|
}
|
|
132
140
|
|
|
133
141
|
/**
|
|
@@ -140,6 +148,11 @@ export interface CreateOptions extends QueryOptions {
|
|
|
140
148
|
region?: string;
|
|
141
149
|
/** Input data to pass to the actor. */
|
|
142
150
|
input?: unknown;
|
|
151
|
+
/**
|
|
152
|
+
* Name of the envoy pool to select for this actor.
|
|
153
|
+
* Overrides the client's configured `poolName` for this call.
|
|
154
|
+
*/
|
|
155
|
+
poolName?: string;
|
|
143
156
|
}
|
|
144
157
|
|
|
145
158
|
/**
|
|
@@ -165,6 +178,22 @@ export interface Region {
|
|
|
165
178
|
export const ACTOR_CONNS_SYMBOL = Symbol("actorConns");
|
|
166
179
|
export const CREATE_ACTOR_CONN_PROXY = Symbol("createActorConnProxy");
|
|
167
180
|
|
|
181
|
+
/** Options for constructing a raw actor client. */
|
|
182
|
+
export interface ClientRawOptions {
|
|
183
|
+
encoding?: Encoding;
|
|
184
|
+
gateway?: ActorGatewayOptions;
|
|
185
|
+
/** Bounds retries of refused requests across every handle of this client. */
|
|
186
|
+
retryBudget?: RetryBudgetOptions;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Runtime-supplied wiring for clients created inside an actor. Set only by the native runtime. */
|
|
190
|
+
export interface ActorClientRuntimeOptions {
|
|
191
|
+
/** Supplies the calling actor's invocation so actor-to-actor clients propagate its trace and ray ID. */
|
|
192
|
+
currentActorInvocation?: CurrentActorInvocation;
|
|
193
|
+
/** Opens and finishes the Core span covering an actor-to-actor call. */
|
|
194
|
+
startCallSpan?: StartCallSpan;
|
|
195
|
+
}
|
|
196
|
+
|
|
168
197
|
/**
|
|
169
198
|
* Client for managing & connecting to actors.
|
|
170
199
|
*
|
|
@@ -173,25 +202,37 @@ export const CREATE_ACTOR_CONN_PROXY = Symbol("createActorConnProxy");
|
|
|
173
202
|
*/
|
|
174
203
|
export class ClientRaw {
|
|
175
204
|
#disposed = false;
|
|
205
|
+
/** Issue namespace-scoped tokens with an explicit grant list. */
|
|
206
|
+
readonly auth: {
|
|
207
|
+
issueToken(options: IssueTokenOptions): Promise<IssuedToken>;
|
|
208
|
+
};
|
|
176
209
|
|
|
177
210
|
[ACTOR_CONNS_SYMBOL] = new Set<ActorConnRaw>();
|
|
178
211
|
|
|
179
212
|
#driver: EngineControlClient;
|
|
180
213
|
#encodingKind: Encoding;
|
|
181
214
|
#gatewayOptions: ActorGatewayOptions;
|
|
215
|
+
#currentActorInvocation?: CurrentActorInvocation;
|
|
216
|
+
#startCallSpan?: StartCallSpan;
|
|
217
|
+
#retryBudget: RetryBudget;
|
|
182
218
|
|
|
183
219
|
/**
|
|
184
220
|
* Creates an instance of Client.
|
|
185
221
|
*/
|
|
186
222
|
public constructor(
|
|
187
223
|
driver: EngineControlClient,
|
|
188
|
-
|
|
189
|
-
gatewayOptions: ActorGatewayOptions = {},
|
|
224
|
+
options: ClientRawOptions & ActorClientRuntimeOptions = {},
|
|
190
225
|
) {
|
|
191
226
|
this.#driver = driver;
|
|
227
|
+
this.auth = {
|
|
228
|
+
issueToken: (issueOptions) => this.#driver.issueToken(issueOptions),
|
|
229
|
+
};
|
|
192
230
|
|
|
193
|
-
this.#encodingKind = encoding ?? "bare";
|
|
194
|
-
this.#gatewayOptions =
|
|
231
|
+
this.#encodingKind = options.encoding ?? "bare";
|
|
232
|
+
this.#gatewayOptions = options.gateway ?? {};
|
|
233
|
+
this.#currentActorInvocation = options.currentActorInvocation;
|
|
234
|
+
this.#startCallSpan = options.startCallSpan;
|
|
235
|
+
this.#retryBudget = new RetryBudget(options.retryBudget);
|
|
195
236
|
}
|
|
196
237
|
|
|
197
238
|
/**
|
|
@@ -226,6 +267,7 @@ export class ClientRaw {
|
|
|
226
267
|
opts?.params,
|
|
227
268
|
opts?.getParams,
|
|
228
269
|
actorQuery,
|
|
270
|
+
opts?.signal,
|
|
229
271
|
);
|
|
230
272
|
return createActorProxy(handle) as ActorHandle<AD>;
|
|
231
273
|
}
|
|
@@ -265,6 +307,7 @@ export class ClientRaw {
|
|
|
265
307
|
opts?.params,
|
|
266
308
|
opts?.getParams,
|
|
267
309
|
actorQuery,
|
|
310
|
+
opts?.signal,
|
|
268
311
|
);
|
|
269
312
|
return createActorProxy(handle) as ActorHandle<AD>;
|
|
270
313
|
}
|
|
@@ -300,6 +343,7 @@ export class ClientRaw {
|
|
|
300
343
|
key: keyArray,
|
|
301
344
|
input: opts?.createWithInput,
|
|
302
345
|
region: opts?.createInRegion,
|
|
346
|
+
poolName: opts?.poolName,
|
|
303
347
|
},
|
|
304
348
|
};
|
|
305
349
|
|
|
@@ -307,6 +351,7 @@ export class ClientRaw {
|
|
|
307
351
|
opts?.params,
|
|
308
352
|
opts?.getParams,
|
|
309
353
|
actorQuery,
|
|
354
|
+
opts?.signal,
|
|
310
355
|
);
|
|
311
356
|
return createActorProxy(handle) as ActorHandle<AD>;
|
|
312
357
|
}
|
|
@@ -366,6 +411,7 @@ export class ClientRaw {
|
|
|
366
411
|
opts?.params,
|
|
367
412
|
opts?.getParams,
|
|
368
413
|
getForIdQuery,
|
|
414
|
+
opts?.signal,
|
|
369
415
|
);
|
|
370
416
|
|
|
371
417
|
const proxy = createActorProxy(handle) as ActorHandle<AD>;
|
|
@@ -377,6 +423,7 @@ export class ClientRaw {
|
|
|
377
423
|
params: unknown,
|
|
378
424
|
getParams: (() => Promise<unknown>) | undefined,
|
|
379
425
|
actorQuery: ActorQuery,
|
|
426
|
+
signal?: AbortSignal,
|
|
380
427
|
): ActorHandleRaw {
|
|
381
428
|
return new ActorHandleRaw(
|
|
382
429
|
this,
|
|
@@ -386,6 +433,10 @@ export class ClientRaw {
|
|
|
386
433
|
this.#encodingKind,
|
|
387
434
|
actorQuery,
|
|
388
435
|
this.#gatewayOptions,
|
|
436
|
+
signal,
|
|
437
|
+
this.#currentActorInvocation,
|
|
438
|
+
this.#startCallSpan,
|
|
439
|
+
this.#retryBudget,
|
|
389
440
|
);
|
|
390
441
|
}
|
|
391
442
|
|
|
@@ -432,19 +483,23 @@ export class ClientRaw {
|
|
|
432
483
|
*
|
|
433
484
|
* @template A The actor registry type.
|
|
434
485
|
*/
|
|
435
|
-
export type Client<A extends Registry<any>> = ClientRaw &
|
|
436
|
-
|
|
437
|
-
|
|
486
|
+
export type Client<A extends Registry<any>> = ClientRaw &
|
|
487
|
+
Omit<
|
|
488
|
+
{
|
|
489
|
+
[K in keyof ExtractActorsFromRegistry<A>]: ActorAccessor<
|
|
490
|
+
ExtractActorsFromRegistry<A>[K]
|
|
491
|
+
>;
|
|
492
|
+
},
|
|
493
|
+
keyof ClientRaw
|
|
438
494
|
>;
|
|
439
|
-
};
|
|
440
495
|
|
|
441
496
|
export type AnyClient = Client<Registry<any>>;
|
|
442
497
|
|
|
443
498
|
export function createClientWithDriver<A extends Registry<any>>(
|
|
444
499
|
driver: EngineControlClient,
|
|
445
|
-
|
|
500
|
+
options: ClientRawOptions & ActorClientRuntimeOptions = {},
|
|
446
501
|
): Client<A> {
|
|
447
|
-
const client = new ClientRaw(driver,
|
|
502
|
+
const client = new ClientRaw(driver, options);
|
|
448
503
|
|
|
449
504
|
// Create proxy for accessing actors by name
|
|
450
505
|
return new Proxy(client, {
|
|
@@ -515,11 +570,30 @@ export function createClientWithDriver<A extends Registry<any>>(
|
|
|
515
570
|
/**
|
|
516
571
|
* Creates a proxy for a actor that enables calling actions without explicitly using `.action`.
|
|
517
572
|
**/
|
|
518
|
-
function createActorProxy<AD extends AnyActorDefinition>(
|
|
573
|
+
export function createActorProxy<AD extends AnyActorDefinition>(
|
|
519
574
|
handle: ActorHandleRaw | ActorConnRaw,
|
|
520
575
|
): ActorHandle<AD> | ActorConn<AD> {
|
|
521
|
-
// Stores returned action
|
|
576
|
+
// Stores returned action path proxies for faster calls.
|
|
522
577
|
const methodCache = new Map<string, ActorActionFunction>();
|
|
578
|
+
const actionPath = (name: string): ActorActionFunction => {
|
|
579
|
+
let method = methodCache.get(name);
|
|
580
|
+
if (method) return method;
|
|
581
|
+
|
|
582
|
+
method = new Proxy(
|
|
583
|
+
(...args: unknown[]) => handle.action({ name, args }),
|
|
584
|
+
{
|
|
585
|
+
get(target, prop: string | symbol) {
|
|
586
|
+
if (typeof prop === "symbol")
|
|
587
|
+
return Reflect.get(target, prop);
|
|
588
|
+
if (prop === "then") return undefined;
|
|
589
|
+
return actionPath(`${name}.${prop}`);
|
|
590
|
+
},
|
|
591
|
+
},
|
|
592
|
+
) as ActorActionFunction;
|
|
593
|
+
methodCache.set(name, method);
|
|
594
|
+
return method;
|
|
595
|
+
};
|
|
596
|
+
|
|
523
597
|
return new Proxy(handle, {
|
|
524
598
|
get(target: ActorHandleRaw, prop: string | symbol, receiver: unknown) {
|
|
525
599
|
// Handle built-in Symbol properties
|
|
@@ -542,13 +616,7 @@ function createActorProxy<AD extends AnyActorDefinition>(
|
|
|
542
616
|
// If JS is attempting to calling this as a promise, ignore it
|
|
543
617
|
if (prop === "then") return undefined;
|
|
544
618
|
|
|
545
|
-
|
|
546
|
-
if (!method) {
|
|
547
|
-
method = (...args: unknown[]) =>
|
|
548
|
-
target.action({ name: prop, args });
|
|
549
|
-
methodCache.set(prop, method);
|
|
550
|
-
}
|
|
551
|
-
return method;
|
|
619
|
+
return actionPath(prop);
|
|
552
620
|
}
|
|
553
621
|
},
|
|
554
622
|
|
|
@@ -575,6 +643,7 @@ function createActorProxy<AD extends AnyActorDefinition>(
|
|
|
575
643
|
target: ActorHandleRaw,
|
|
576
644
|
prop: string | symbol,
|
|
577
645
|
) {
|
|
646
|
+
if (prop === "then") return undefined;
|
|
578
647
|
const targetDescriptor = Reflect.getOwnPropertyDescriptor(
|
|
579
648
|
target,
|
|
580
649
|
prop,
|
|
@@ -588,8 +657,7 @@ function createActorProxy<AD extends AnyActorDefinition>(
|
|
|
588
657
|
configurable: true,
|
|
589
658
|
enumerable: false,
|
|
590
659
|
writable: false,
|
|
591
|
-
value: (
|
|
592
|
-
target.action({ name: prop, args }),
|
|
660
|
+
value: actionPath(prop),
|
|
593
661
|
};
|
|
594
662
|
}
|
|
595
663
|
return undefined;
|
package/src/client/config.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import z from "zod/v4";
|
|
2
2
|
import { EncodingSchema } from "@/common/encoding";
|
|
3
|
+
import { isLocalEngineEndpoint } from "@/common/engine";
|
|
3
4
|
import type { RegistryConfig } from "@/registry/config";
|
|
4
5
|
import type { GetUpgradeWebSocket } from "@/utils";
|
|
5
6
|
import { tryParseEndpoint } from "@/utils/endpoint-parser";
|
|
@@ -10,6 +11,7 @@ import {
|
|
|
10
11
|
getRivetPool,
|
|
11
12
|
getRivetToken,
|
|
12
13
|
} from "@/utils/env-vars";
|
|
14
|
+
import type { GetToken } from "./token-provider";
|
|
13
15
|
|
|
14
16
|
const DEFAULT_ENDPOINT = "http://localhost:6420";
|
|
15
17
|
export const DEFAULT_MAX_QUERY_INPUT_SIZE = 4 * 1024;
|
|
@@ -54,6 +56,9 @@ export const ClientConfigSchemaBase = z.object({
|
|
|
54
56
|
.optional()
|
|
55
57
|
.transform((val) => val ?? getRivetToken()),
|
|
56
58
|
|
|
59
|
+
/** Issue and renew a client token on demand. Overrides the static token when provided. */
|
|
60
|
+
getToken: z.custom<GetToken>().optional(),
|
|
61
|
+
|
|
57
62
|
/** Namespace to connect to. */
|
|
58
63
|
namespace: z
|
|
59
64
|
.string()
|
|
@@ -83,6 +88,20 @@ export const ClientConfigSchemaBase = z.object({
|
|
|
83
88
|
// `proxyWebSocket`
|
|
84
89
|
getUpgradeWebSocket: z.custom<GetUpgradeWebSocket>().optional(),
|
|
85
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Bounds retries of refused requests: `percent` retries per 100 requests (default 10), with
|
|
93
|
+
* up to `maxTokens` banked for bursts (default 100). A refusal past the budget is thrown.
|
|
94
|
+
*/
|
|
95
|
+
retryBudget: z
|
|
96
|
+
.object({
|
|
97
|
+
percent: z.number().min(0).max(100).optional(),
|
|
98
|
+
maxTokens: z.number().int().min(0).optional(),
|
|
99
|
+
})
|
|
100
|
+
.optional(),
|
|
101
|
+
|
|
102
|
+
/** Replaces global fetch for actor HTTP gateway requests. */
|
|
103
|
+
fetch: z.custom<typeof globalThis.fetch>().optional(),
|
|
104
|
+
|
|
86
105
|
/** Whether to automatically perform health checks when the client is created. */
|
|
87
106
|
disableMetadataLookup: z.boolean().optional().default(false),
|
|
88
107
|
|
|
@@ -131,7 +150,12 @@ export function transformClientConfig(
|
|
|
131
150
|
...config,
|
|
132
151
|
endpoint: parsedEndpoint?.endpoint,
|
|
133
152
|
namespace: parsedEndpoint?.namespace ?? config.namespace ?? "default",
|
|
134
|
-
token:
|
|
153
|
+
token:
|
|
154
|
+
parsedEndpoint?.token ??
|
|
155
|
+
config.token ??
|
|
156
|
+
(config.endpoint && isLocalEngineEndpoint(config.endpoint)
|
|
157
|
+
? "default"
|
|
158
|
+
: undefined),
|
|
135
159
|
};
|
|
136
160
|
}
|
|
137
161
|
|
|
@@ -151,8 +175,9 @@ export function convertRegistryConfigToClientConfig(
|
|
|
151
175
|
return {
|
|
152
176
|
endpoint: config.endpoint,
|
|
153
177
|
token: config.token,
|
|
178
|
+
getToken: undefined,
|
|
154
179
|
namespace: config.namespace,
|
|
155
|
-
poolName: config.
|
|
180
|
+
poolName: config.node.poolName,
|
|
156
181
|
headers: config.headers,
|
|
157
182
|
gateway: { skipReadyWait: false },
|
|
158
183
|
encoding: "bare",
|
package/src/client/errors.ts
CHANGED
|
@@ -51,12 +51,13 @@ export function actorSchedulingError(
|
|
|
51
51
|
code: string,
|
|
52
52
|
actorId: string,
|
|
53
53
|
details: unknown,
|
|
54
|
+
rayId?: string,
|
|
54
55
|
): RivetError {
|
|
55
56
|
return new RivetError(
|
|
56
57
|
group,
|
|
57
58
|
code,
|
|
58
59
|
`Actor failed to start (${actorId}): ${JSON.stringify(details)}`,
|
|
59
|
-
{ metadata: { actorId, details } },
|
|
60
|
+
{ metadata: { actorId, details }, rayId },
|
|
60
61
|
);
|
|
61
62
|
}
|
|
62
63
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ActorError, HttpRequestError } from "./errors";
|
|
2
|
+
import { type RetryBudget, retryAfterMs, retryDelayMs } from "./retry-budget";
|
|
2
3
|
|
|
3
4
|
export interface LifecycleBoundaryInfo {
|
|
4
5
|
kind: "request_retry" | "reconnect_only";
|
|
@@ -271,6 +272,11 @@ async function waitWithSignal(ms: number, signal?: AbortSignal) {
|
|
|
271
272
|
});
|
|
272
273
|
}
|
|
273
274
|
|
|
275
|
+
/**
|
|
276
|
+
* Runs `run`, retrying retryable lifecycle and refusal errors with jittered exponential backoff
|
|
277
|
+
* that honors the service's `retry_after_ms` hint. With a `budget`, the call credits it once and
|
|
278
|
+
* every retry spends a token; a spent budget returns the error instead of retrying.
|
|
279
|
+
*/
|
|
274
280
|
export async function retryOnLifecycleBoundary<T>(
|
|
275
281
|
run: () => Promise<T>,
|
|
276
282
|
opts?: {
|
|
@@ -278,11 +284,13 @@ export async function retryOnLifecycleBoundary<T>(
|
|
|
278
284
|
initialDelayMs?: number;
|
|
279
285
|
maxDelayMs?: number;
|
|
280
286
|
signal?: AbortSignal;
|
|
287
|
+
budget?: RetryBudget;
|
|
281
288
|
},
|
|
282
289
|
): Promise<T> {
|
|
283
290
|
const maxAttempts = opts?.maxAttempts ?? 5;
|
|
284
291
|
const initialDelayMs = opts?.initialDelayMs ?? 25;
|
|
285
292
|
const maxDelayMs = opts?.maxDelayMs ?? 200;
|
|
293
|
+
opts?.budget?.deposit();
|
|
286
294
|
|
|
287
295
|
let lastError: unknown;
|
|
288
296
|
for (let attempt = 0; attempt < maxAttempts; attempt += 1) {
|
|
@@ -299,8 +307,15 @@ export async function retryOnLifecycleBoundary<T>(
|
|
|
299
307
|
if (attempt === maxAttempts - 1) {
|
|
300
308
|
break;
|
|
301
309
|
}
|
|
310
|
+
if (opts?.budget && !opts.budget.tryWithdraw()) {
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
302
313
|
|
|
303
|
-
const delayMs =
|
|
314
|
+
const delayMs = retryDelayMs(attempt, {
|
|
315
|
+
initialDelayMs,
|
|
316
|
+
maxDelayMs,
|
|
317
|
+
hintMs: retryAfterMs(error),
|
|
318
|
+
});
|
|
304
319
|
await waitWithSignal(delayMs, opts?.signal);
|
|
305
320
|
}
|
|
306
321
|
}
|
package/src/client/mod.ts
CHANGED
|
@@ -19,6 +19,14 @@ export {
|
|
|
19
19
|
UserError,
|
|
20
20
|
} from "@/client/errors";
|
|
21
21
|
export type { CreateRequest } from "@/client/query";
|
|
22
|
+
export type {
|
|
23
|
+
ActorIssueTokenOptions,
|
|
24
|
+
ActorTokenPermissions,
|
|
25
|
+
ActorTokenResource,
|
|
26
|
+
IssuedToken,
|
|
27
|
+
IssueTokenOptions,
|
|
28
|
+
TokenGrant,
|
|
29
|
+
} from "./auth";
|
|
22
30
|
export type { Encoding } from "@/common/encoding";
|
|
23
31
|
export type {
|
|
24
32
|
ActorActionFunction,
|
|
@@ -49,6 +57,7 @@ export type {
|
|
|
49
57
|
QueryOptions,
|
|
50
58
|
Region,
|
|
51
59
|
} from "./client";
|
|
60
|
+
export type { GetToken } from "./token-provider";
|
|
52
61
|
|
|
53
62
|
/**
|
|
54
63
|
* Creates a client with the actor accessor proxy.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HEADER_RIVET_RAY_ID,
|
|
3
|
+
HEADER_TRACEPARENT,
|
|
4
|
+
HEADER_TRACESTATE,
|
|
5
|
+
} from "@/common/actor-router-consts";
|
|
6
|
+
import type { ActorInvocationTraceContext } from "@/common/actor-telemetry-context";
|
|
7
|
+
import {
|
|
8
|
+
actorInvocationTraceHeaders,
|
|
9
|
+
readActiveRayId,
|
|
10
|
+
readActiveTraceHeaders,
|
|
11
|
+
} from "@/common/otel-context";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Headers that carry a caller's ray ID and trace context into an actor. One
|
|
15
|
+
* rule for every kind of outbound call, so an action call and a queue send
|
|
16
|
+
* made from the same place land in the same trace under the same ray ID.
|
|
17
|
+
*
|
|
18
|
+
* The ray ID is the calling invocation's when the caller is itself inside an
|
|
19
|
+
* actor, else the one placed in OpenTelemetry baggage by the surrounding
|
|
20
|
+
* request handler. The trace context is `callSpan` when the runtime opened a
|
|
21
|
+
* span for this call, else the application span active in this JavaScript
|
|
22
|
+
* context, else the calling actor's own Core invocation span.
|
|
23
|
+
*/
|
|
24
|
+
export function outboundTelemetryHeaders(
|
|
25
|
+
invocation: ActorInvocationTraceContext | undefined,
|
|
26
|
+
callSpan?: ActorInvocationTraceContext["span"],
|
|
27
|
+
): Record<string, string> {
|
|
28
|
+
const headers: Record<string, string> = {};
|
|
29
|
+
const rayId = invocation?.rayId ?? readActiveRayId();
|
|
30
|
+
if (rayId) {
|
|
31
|
+
headers[HEADER_RIVET_RAY_ID] = rayId;
|
|
32
|
+
}
|
|
33
|
+
const traceHeaders =
|
|
34
|
+
actorInvocationTraceHeaders(callSpan) ??
|
|
35
|
+
readActiveTraceHeaders() ??
|
|
36
|
+
actorInvocationTraceHeaders(invocation?.span);
|
|
37
|
+
if (traceHeaders) {
|
|
38
|
+
headers[HEADER_TRACEPARENT] = traceHeaders.traceparent;
|
|
39
|
+
if (traceHeaders.tracestate) {
|
|
40
|
+
headers[HEADER_TRACESTATE] = traceHeaders.tracestate;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return headers;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Adds outbound telemetry headers to a request whose caller may have set
|
|
48
|
+
* some already. A header the caller set wins. `traceparent` and `tracestate`
|
|
49
|
+
* describe one span between them, so when the caller set either, both stay
|
|
50
|
+
* as the caller set them and neither is added.
|
|
51
|
+
*/
|
|
52
|
+
export function addOutboundTelemetryHeaders(
|
|
53
|
+
headers: Headers,
|
|
54
|
+
telemetry: Record<string, string>,
|
|
55
|
+
): void {
|
|
56
|
+
const callerSetTraceContext =
|
|
57
|
+
headers.has(HEADER_TRACEPARENT) || headers.has(HEADER_TRACESTATE);
|
|
58
|
+
for (const [name, value] of Object.entries(telemetry)) {
|
|
59
|
+
const isTraceContext =
|
|
60
|
+
name === HEADER_TRACEPARENT || name === HEADER_TRACESTATE;
|
|
61
|
+
if (isTraceContext ? callerSetTraceContext : headers.has(name)) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
headers.set(name, value);
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/client/query.ts
CHANGED
|
@@ -31,6 +31,7 @@ export const CreateRequestSchema = z.object({
|
|
|
31
31
|
key: ActorKeySchema,
|
|
32
32
|
input: z.unknown().optional(),
|
|
33
33
|
region: z.string().optional(),
|
|
34
|
+
poolName: z.string().optional(),
|
|
34
35
|
});
|
|
35
36
|
|
|
36
37
|
export const GetForKeyRequestSchema = z.object({
|
|
@@ -43,6 +44,7 @@ export const GetOrCreateRequestSchema = z.object({
|
|
|
43
44
|
key: ActorKeySchema,
|
|
44
45
|
input: z.unknown().optional(),
|
|
45
46
|
region: z.string().optional(),
|
|
47
|
+
poolName: z.string().optional(),
|
|
46
48
|
});
|
|
47
49
|
|
|
48
50
|
export const ActorQuerySchema = z.union([
|
package/src/client/queue.ts
CHANGED
|
@@ -54,6 +54,8 @@ export interface QueueSendResult<TResponse = unknown> {
|
|
|
54
54
|
interface QueueSenderOptions {
|
|
55
55
|
encoding: Encoding;
|
|
56
56
|
params: unknown;
|
|
57
|
+
/** Ray ID and trace context headers, read per send. */
|
|
58
|
+
telemetryHeaders: () => Record<string, string>;
|
|
57
59
|
customFetch: (request: Request) => Promise<Response>;
|
|
58
60
|
}
|
|
59
61
|
|
|
@@ -90,6 +92,7 @@ export function createQueueSender(
|
|
|
90
92
|
method: "POST",
|
|
91
93
|
headers: {
|
|
92
94
|
[HEADER_ENCODING]: senderOptions.encoding,
|
|
95
|
+
...senderOptions.telemetryHeaders(),
|
|
93
96
|
...(senderOptions.params !== undefined
|
|
94
97
|
? {
|
|
95
98
|
[HEADER_CONN_PARAMS]: JSON.stringify(
|
package/src/client/raw-utils.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
HEADER_CONN_PARAMS,
|
|
3
|
+
HEADER_ORIGINAL_REQUEST_URL,
|
|
3
4
|
PATH_WEBSOCKET_PREFIX,
|
|
4
5
|
} from "@/common/actor-router-consts";
|
|
5
6
|
import { deconstructError } from "@/common/utils";
|
|
7
|
+
import { isRequestLike, isUrlLike, readRequestBody } from "@/common/fetch-like";
|
|
6
8
|
import type {
|
|
7
9
|
EngineControlClient,
|
|
8
10
|
GatewayRequestOptions,
|
|
@@ -10,6 +12,21 @@ import type {
|
|
|
10
12
|
} from "@/engine-client/driver";
|
|
11
13
|
import { ActorError } from "./errors";
|
|
12
14
|
import { logger } from "./log";
|
|
15
|
+
import { addOutboundTelemetryHeaders } from "./outbound-telemetry";
|
|
16
|
+
|
|
17
|
+
/** Buffer a one-shot ReadableStream body to bytes so every retry attempt can re-send it. */
|
|
18
|
+
export async function prepareRetryableInit(
|
|
19
|
+
init: RequestInit,
|
|
20
|
+
): Promise<RequestInit> {
|
|
21
|
+
if (init.body instanceof ReadableStream) {
|
|
22
|
+
return {
|
|
23
|
+
...init,
|
|
24
|
+
body: new Uint8Array(await new Response(init.body).arrayBuffer()),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return init;
|
|
29
|
+
}
|
|
13
30
|
|
|
14
31
|
/**
|
|
15
32
|
* Shared implementation for raw HTTP fetch requests
|
|
@@ -21,19 +38,23 @@ export async function rawHttpFetch(
|
|
|
21
38
|
input: string | URL | Request,
|
|
22
39
|
init?: RequestInit,
|
|
23
40
|
options: GatewayRequestOptions = {},
|
|
41
|
+
telemetryHeaders: Record<string, string> = {},
|
|
24
42
|
): Promise<Response> {
|
|
25
43
|
// Extract path and merge init options
|
|
26
44
|
let path: string;
|
|
45
|
+
let originalUrl: string | undefined;
|
|
27
46
|
let mergedInit: RequestInit = init || {};
|
|
28
47
|
|
|
29
48
|
if (typeof input === "string") {
|
|
30
49
|
path = input;
|
|
31
|
-
} else if (input
|
|
50
|
+
} else if (isUrlLike(input)) {
|
|
32
51
|
path = input.pathname + input.search;
|
|
33
|
-
|
|
52
|
+
originalUrl = input.toString();
|
|
53
|
+
} else if (isRequestLike(input)) {
|
|
34
54
|
// Extract path from Request URL
|
|
35
55
|
const url = new URL(input.url);
|
|
36
56
|
path = url.pathname + url.search;
|
|
57
|
+
originalUrl = url.toString();
|
|
37
58
|
// Merge Request properties with init
|
|
38
59
|
const requestHeaders = new Headers(input.headers);
|
|
39
60
|
const initHeaders = new Headers(init?.headers || {});
|
|
@@ -44,9 +65,14 @@ export async function rawHttpFetch(
|
|
|
44
65
|
mergedHeaders.set(key, value);
|
|
45
66
|
});
|
|
46
67
|
|
|
68
|
+
const readsInputBody =
|
|
69
|
+
init?.body === undefined &&
|
|
70
|
+
input.method !== "GET" &&
|
|
71
|
+
input.method !== "HEAD";
|
|
72
|
+
|
|
47
73
|
mergedInit = {
|
|
48
74
|
method: input.method,
|
|
49
|
-
body: input
|
|
75
|
+
body: readsInputBody ? await readRequestBody(input) : undefined,
|
|
50
76
|
mode: input.mode,
|
|
51
77
|
credentials: input.credentials,
|
|
52
78
|
redirect: input.redirect,
|
|
@@ -85,9 +111,14 @@ export async function rawHttpFetch(
|
|
|
85
111
|
|
|
86
112
|
// Forward conn params if provided
|
|
87
113
|
const proxyRequestHeaders = new Headers(mergedInit.headers);
|
|
114
|
+
proxyRequestHeaders.delete(HEADER_ORIGINAL_REQUEST_URL);
|
|
115
|
+
if (originalUrl) {
|
|
116
|
+
proxyRequestHeaders.set(HEADER_ORIGINAL_REQUEST_URL, originalUrl);
|
|
117
|
+
}
|
|
88
118
|
if (params) {
|
|
89
119
|
proxyRequestHeaders.set(HEADER_CONN_PARAMS, JSON.stringify(params));
|
|
90
120
|
}
|
|
121
|
+
addOutboundTelemetryHeaders(proxyRequestHeaders, telemetryHeaders);
|
|
91
122
|
|
|
92
123
|
// Forward the request to the actor
|
|
93
124
|
const proxyRequest = new Request(url, {
|
|
@@ -98,11 +129,9 @@ export async function rawHttpFetch(
|
|
|
98
129
|
return driver.sendRequest(target, proxyRequest, options);
|
|
99
130
|
} catch (err) {
|
|
100
131
|
// Standardize to ClientActorError instead of the native backend error
|
|
101
|
-
const { group, code, message, metadata, actor } =
|
|
102
|
-
err,
|
|
103
|
-
|
|
104
|
-
);
|
|
105
|
-
throw new ActorError(group, code, message, { metadata, actor });
|
|
132
|
+
const { group, code, message, metadata, rayId, actor } =
|
|
133
|
+
deconstructError(err, true);
|
|
134
|
+
throw new ActorError(group, code, message, { metadata, rayId, actor });
|
|
106
135
|
}
|
|
107
136
|
}
|
|
108
137
|
|
|
@@ -41,6 +41,7 @@ export async function resolveGatewayTarget(
|
|
|
41
41
|
key: target.getOrCreateForKey.key,
|
|
42
42
|
input: target.getOrCreateForKey.input,
|
|
43
43
|
region: target.getOrCreateForKey.region,
|
|
44
|
+
poolName: target.getOrCreateForKey.poolName,
|
|
44
45
|
});
|
|
45
46
|
return output.actorId;
|
|
46
47
|
}
|
|
@@ -51,6 +52,7 @@ export async function resolveGatewayTarget(
|
|
|
51
52
|
key: target.create.key,
|
|
52
53
|
input: target.create.input,
|
|
53
54
|
region: target.create.region,
|
|
55
|
+
poolName: target.create.poolName,
|
|
54
56
|
});
|
|
55
57
|
return output.actorId;
|
|
56
58
|
}
|