rivetkit 2.3.12-rc.1 → 2.3.12-rc.3
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 +4 -0
- package/dist/browser/client.js +116 -60
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +1 -1
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/actor/errors.cjs +2 -2
- package/dist/tsup/actor/errors.d.cts +1 -1
- package/dist/tsup/actor/errors.d.ts +1 -1
- package/dist/tsup/actor/errors.js +1 -1
- package/dist/tsup/agent-os/index.cjs +2 -2
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +4 -0
- package/dist/tsup/agent-os/index.d.ts +4 -0
- package/dist/tsup/agent-os/index.js +2 -2
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-MT33DKU4.js → chunk-34Q4YVCX.js} +2 -2
- package/dist/tsup/{chunk-T4MKKCRF.cjs → chunk-4ESGNS3Z.cjs} +15 -10
- package/dist/tsup/chunk-4ESGNS3Z.cjs.map +1 -0
- package/dist/tsup/{chunk-VJ4KLJO5.cjs → chunk-EQKSWDIH.cjs} +3 -3
- package/dist/tsup/{chunk-VJ4KLJO5.cjs.map → chunk-EQKSWDIH.cjs.map} +1 -1
- package/dist/tsup/{chunk-BZX4LYYD.cjs → chunk-IJWTHKH6.cjs} +3 -3
- package/dist/tsup/{chunk-BZX4LYYD.cjs.map → chunk-IJWTHKH6.cjs.map} +1 -1
- package/dist/tsup/{chunk-ZZ3WBRPD.js → chunk-IXBD7BXC.js} +15 -4
- package/dist/tsup/chunk-IXBD7BXC.js.map +1 -0
- package/dist/tsup/{chunk-ZTPFJOBX.js → chunk-NHI5L7C7.js} +3 -3
- package/dist/tsup/{chunk-CMZBDX6Z.cjs → chunk-O6H3BUN4.cjs} +3 -3
- package/dist/tsup/{chunk-CMZBDX6Z.cjs.map → chunk-O6H3BUN4.cjs.map} +1 -1
- package/dist/tsup/{chunk-HVHDZDM2.js → chunk-OLGQYFUW.js} +8 -3
- package/dist/tsup/chunk-OLGQYFUW.js.map +1 -0
- package/dist/tsup/{chunk-BEPAAID2.cjs → chunk-OX6WVQE6.cjs} +10 -10
- package/dist/tsup/{chunk-BEPAAID2.cjs.map → chunk-OX6WVQE6.cjs.map} +1 -1
- package/dist/tsup/{chunk-KRPA4UOE.js → chunk-PSXMESQJ.js} +2 -2
- package/dist/tsup/{chunk-6ETWXXAZ.cjs → chunk-PZBWSCQR.cjs} +262 -213
- package/dist/tsup/chunk-PZBWSCQR.cjs.map +1 -0
- package/dist/tsup/{chunk-2D5PNV5A.cjs → chunk-QLOBB27M.cjs} +4 -4
- package/dist/tsup/{chunk-2D5PNV5A.cjs.map → chunk-QLOBB27M.cjs.map} +1 -1
- package/dist/tsup/{chunk-4FC7TVS6.cjs → chunk-SPJORZMM.cjs} +15 -4
- package/dist/tsup/chunk-SPJORZMM.cjs.map +1 -0
- package/dist/tsup/{chunk-DIHAXOB7.cjs → chunk-UBB32UOG.cjs} +7 -7
- package/dist/tsup/{chunk-DIHAXOB7.cjs.map → chunk-UBB32UOG.cjs.map} +1 -1
- package/dist/tsup/{chunk-OZWVDFCA.js → chunk-UN5JNDBT.js} +4 -4
- package/dist/tsup/{chunk-5UYNV4W6.js → chunk-WVFTFWJL.js} +2 -2
- package/dist/tsup/{chunk-JHHAMABO.js → chunk-XI4MEUUI.js} +2 -2
- package/dist/tsup/{chunk-A5BZEQOG.js → chunk-YYIDQBBM.js} +110 -61
- package/dist/tsup/chunk-YYIDQBBM.js.map +1 -0
- package/dist/tsup/client/mod.cjs +6 -6
- package/dist/tsup/client/mod.d.cts +5 -5
- package/dist/tsup/client/mod.d.ts +5 -5
- package/dist/tsup/client/mod.js +5 -5
- package/dist/tsup/common/log.cjs +3 -3
- package/dist/tsup/common/log.js +2 -2
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{config-DTGoWdkG.d.cts → config-BXSV17G7.d.cts} +2 -2
- package/dist/tsup/{config-C4OSv0QP.d.ts → config-Bi1r6gI7.d.ts} +2 -2
- package/dist/tsup/{context-C6cvDNyk.d.cts → context-4fJemY0D.d.cts} +1 -1
- package/dist/tsup/{context-CMygeBxS.d.ts → context-D4sNYboo.d.ts} +1 -1
- package/dist/tsup/db/drizzle.cjs +3 -3
- package/dist/tsup/db/drizzle.js +2 -2
- package/dist/tsup/db/mod.cjs +4 -4
- package/dist/tsup/db/mod.js +3 -3
- package/dist/tsup/dynamic/mod.d.cts +3 -3
- package/dist/tsup/dynamic/mod.d.ts +3 -3
- package/dist/tsup/inspector/mod.cjs +6 -6
- package/dist/tsup/inspector/mod.js +5 -5
- package/dist/tsup/inspector/workflow.cjs +5 -5
- package/dist/tsup/inspector/workflow.js +4 -4
- package/dist/tsup/inspector-tab/mod.d.cts +4 -4
- package/dist/tsup/inspector-tab/mod.d.ts +4 -4
- package/dist/tsup/mod.cjs +111 -110
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +5 -5
- package/dist/tsup/mod.d.ts +5 -5
- package/dist/tsup/mod.js +8 -7
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +7 -7
- package/dist/tsup/test/mod.d.cts +3 -3
- package/dist/tsup/test/mod.d.ts +3 -3
- package/dist/tsup/test/mod.js +5 -5
- package/dist/tsup/{utils-DQDCphrl.d.cts → utils-Bbz-3411.d.cts} +1 -1
- package/dist/tsup/{utils-CV0akuDD.d.ts → utils-BqdWVlzm.d.ts} +1 -1
- package/dist/tsup/{utils-CqDnC_PS.d.cts → utils-vvJQyygr.d.cts} +5 -0
- package/dist/tsup/{utils-CqDnC_PS.d.ts → utils-vvJQyygr.d.ts} +5 -0
- package/dist/tsup/utils.cjs +3 -3
- package/dist/tsup/utils.d.cts +2 -2
- package/dist/tsup/utils.d.ts +2 -2
- package/dist/tsup/utils.js +2 -2
- package/dist/tsup/workflow/mod.cjs +11 -11
- package/dist/tsup/workflow/mod.d.cts +5 -5
- package/dist/tsup/workflow/mod.d.ts +5 -5
- package/dist/tsup/workflow/mod.js +5 -5
- package/package.json +8 -8
- package/src/actor/errors.ts +29 -2
- package/src/client/actor-conn.ts +5 -4
- package/src/client/actor-handle.ts +47 -19
- package/src/client/actor-query.ts +8 -1
- package/src/client/errors.ts +2 -1
- package/src/client/raw-utils.ts +3 -5
- package/src/client/utils.ts +2 -0
- package/src/common/utils.ts +6 -0
- package/src/engine-client/mod.ts +51 -20
- package/src/registry/native.ts +1 -0
- package/dist/tsup/chunk-4FC7TVS6.cjs.map +0 -1
- package/dist/tsup/chunk-6ETWXXAZ.cjs.map +0 -1
- package/dist/tsup/chunk-A5BZEQOG.js.map +0 -1
- package/dist/tsup/chunk-HVHDZDM2.js.map +0 -1
- package/dist/tsup/chunk-T4MKKCRF.cjs.map +0 -1
- package/dist/tsup/chunk-ZZ3WBRPD.js.map +0 -1
- /package/dist/tsup/{chunk-MT33DKU4.js.map → chunk-34Q4YVCX.js.map} +0 -0
- /package/dist/tsup/{chunk-ZTPFJOBX.js.map → chunk-NHI5L7C7.js.map} +0 -0
- /package/dist/tsup/{chunk-KRPA4UOE.js.map → chunk-PSXMESQJ.js.map} +0 -0
- /package/dist/tsup/{chunk-OZWVDFCA.js.map → chunk-UN5JNDBT.js.map} +0 -0
- /package/dist/tsup/{chunk-5UYNV4W6.js.map → chunk-WVFTFWJL.js.map} +0 -0
- /package/dist/tsup/{chunk-JHHAMABO.js.map → chunk-XI4MEUUI.js.map} +0 -0
|
@@ -139,7 +139,10 @@ export class ActorHandleRaw {
|
|
|
139
139
|
): Promise<QueueSendResult | void> {
|
|
140
140
|
return await this.#queueSendMutex.run(async () => {
|
|
141
141
|
const maxAttempts = this.#getDynamicQueryMaxAttempts();
|
|
142
|
-
|
|
142
|
+
// Dynamic (get/getOrCreate) handles resolve at the gateway per
|
|
143
|
+
// request so cross-datacenter queries forward to the reserved dc,
|
|
144
|
+
// rather than pre-resolving via the non-forwarding PUT /actors path.
|
|
145
|
+
let useQueryTarget = isDynamicActorQuery(this.#actorResolutionState);
|
|
143
146
|
|
|
144
147
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
145
148
|
let actorId: string | undefined;
|
|
@@ -166,7 +169,7 @@ export class ActorHandleRaw {
|
|
|
166
169
|
},
|
|
167
170
|
}).send(name, body, options as any);
|
|
168
171
|
} catch (err) {
|
|
169
|
-
const { group, code, message, metadata, actor } =
|
|
172
|
+
const { group, code, message, metadata, rayId, actor } =
|
|
170
173
|
deconstructError(err, true);
|
|
171
174
|
|
|
172
175
|
if (
|
|
@@ -189,6 +192,7 @@ export class ActorHandleRaw {
|
|
|
189
192
|
actorId,
|
|
190
193
|
attempt,
|
|
191
194
|
maxAttempts,
|
|
195
|
+
rayId,
|
|
192
196
|
)
|
|
193
197
|
) {
|
|
194
198
|
useQueryTarget = true;
|
|
@@ -215,11 +219,12 @@ export class ActorHandleRaw {
|
|
|
215
219
|
code,
|
|
216
220
|
);
|
|
217
221
|
if (invalidated && attempt < maxAttempts - 1) {
|
|
218
|
-
|
|
222
|
+
const waitForReady =
|
|
219
223
|
code === "starting" ||
|
|
220
224
|
code === "stopping" ||
|
|
221
225
|
code.startsWith("destroyed_");
|
|
222
|
-
|
|
226
|
+
useQueryTarget = useQueryTarget || waitForReady;
|
|
227
|
+
if (waitForReady) {
|
|
223
228
|
await this.#waitForRetryWindow();
|
|
224
229
|
}
|
|
225
230
|
continue;
|
|
@@ -227,6 +232,7 @@ export class ActorHandleRaw {
|
|
|
227
232
|
|
|
228
233
|
throw new ActorError(group, code, message, {
|
|
229
234
|
metadata,
|
|
235
|
+
rayId,
|
|
230
236
|
actor,
|
|
231
237
|
});
|
|
232
238
|
}
|
|
@@ -274,7 +280,7 @@ export class ActorHandleRaw {
|
|
|
274
280
|
} & ActorActionOptions,
|
|
275
281
|
): Promise<unknown> {
|
|
276
282
|
const maxAttempts = this.#getDynamicQueryMaxAttempts();
|
|
277
|
-
let useQueryTarget =
|
|
283
|
+
let useQueryTarget = isDynamicActorQuery(this.#actorResolutionState);
|
|
278
284
|
const gatewayOptions = resolveActorGatewayOptions(
|
|
279
285
|
this.#gatewayOptions,
|
|
280
286
|
opts,
|
|
@@ -357,7 +363,7 @@ export class ActorHandleRaw {
|
|
|
357
363
|
}
|
|
358
364
|
return output;
|
|
359
365
|
} catch (err) {
|
|
360
|
-
const { group, code, message, metadata, actor } =
|
|
366
|
+
const { group, code, message, metadata, rayId, actor } =
|
|
361
367
|
deconstructError(err, true);
|
|
362
368
|
|
|
363
369
|
if (
|
|
@@ -367,6 +373,7 @@ export class ActorHandleRaw {
|
|
|
367
373
|
actorId,
|
|
368
374
|
attempt,
|
|
369
375
|
maxAttempts,
|
|
376
|
+
rayId,
|
|
370
377
|
)
|
|
371
378
|
) {
|
|
372
379
|
useQueryTarget = true;
|
|
@@ -398,7 +405,7 @@ export class ActorHandleRaw {
|
|
|
398
405
|
"actor",
|
|
399
406
|
"not_found",
|
|
400
407
|
"The actor does not exist or was destroyed.",
|
|
401
|
-
{ metadata, actor },
|
|
408
|
+
{ metadata, rayId, actor },
|
|
402
409
|
);
|
|
403
410
|
}
|
|
404
411
|
|
|
@@ -419,7 +426,11 @@ export class ActorHandleRaw {
|
|
|
419
426
|
continue;
|
|
420
427
|
}
|
|
421
428
|
|
|
422
|
-
throw new ActorError(group, code, message, {
|
|
429
|
+
throw new ActorError(group, code, message, {
|
|
430
|
+
metadata,
|
|
431
|
+
rayId,
|
|
432
|
+
actor,
|
|
433
|
+
});
|
|
423
434
|
}
|
|
424
435
|
}
|
|
425
436
|
|
|
@@ -514,6 +525,7 @@ export class ActorHandleRaw {
|
|
|
514
525
|
actorId: string | undefined,
|
|
515
526
|
attempt: number,
|
|
516
527
|
maxAttempts: number,
|
|
528
|
+
rayId?: string,
|
|
517
529
|
): Promise<boolean> {
|
|
518
530
|
if (
|
|
519
531
|
!isDynamicActorQuery(this.#actorResolutionState) ||
|
|
@@ -530,6 +542,7 @@ export class ActorHandleRaw {
|
|
|
530
542
|
actorId,
|
|
531
543
|
this.#actorResolutionState,
|
|
532
544
|
this.#driver,
|
|
545
|
+
rayId,
|
|
533
546
|
);
|
|
534
547
|
if (schedulingError) {
|
|
535
548
|
throw schedulingError;
|
|
@@ -639,7 +652,7 @@ export class ActorHandleRaw {
|
|
|
639
652
|
init?: ActorFetchInit,
|
|
640
653
|
) {
|
|
641
654
|
const maxAttempts = this.#getDynamicQueryMaxAttempts();
|
|
642
|
-
let useQueryTarget =
|
|
655
|
+
let useQueryTarget = isDynamicActorQuery(this.#actorResolutionState);
|
|
643
656
|
const { skipReadyWait, ...requestInit } = init ?? {};
|
|
644
657
|
const gatewayOptions = resolveActorGatewayOptions(
|
|
645
658
|
this.#gatewayOptions,
|
|
@@ -679,7 +692,7 @@ export class ActorHandleRaw {
|
|
|
679
692
|
}
|
|
680
693
|
return response;
|
|
681
694
|
} catch (err) {
|
|
682
|
-
const { group, code, message, metadata, actor } =
|
|
695
|
+
const { group, code, message, metadata, rayId, actor } =
|
|
683
696
|
deconstructError(err, true);
|
|
684
697
|
|
|
685
698
|
if (
|
|
@@ -689,6 +702,7 @@ export class ActorHandleRaw {
|
|
|
689
702
|
actorId,
|
|
690
703
|
attempt,
|
|
691
704
|
maxAttempts,
|
|
705
|
+
rayId,
|
|
692
706
|
)
|
|
693
707
|
) {
|
|
694
708
|
useQueryTarget = true;
|
|
@@ -715,17 +729,22 @@ export class ActorHandleRaw {
|
|
|
715
729
|
code,
|
|
716
730
|
);
|
|
717
731
|
if (invalidated && attempt < maxAttempts - 1) {
|
|
718
|
-
|
|
732
|
+
const waitForReady =
|
|
719
733
|
code === "starting" ||
|
|
720
734
|
code === "stopping" ||
|
|
721
735
|
code.startsWith("destroyed_");
|
|
722
|
-
|
|
736
|
+
useQueryTarget = useQueryTarget || waitForReady;
|
|
737
|
+
if (waitForReady) {
|
|
723
738
|
await this.#waitForRetryWindow();
|
|
724
739
|
}
|
|
725
740
|
continue;
|
|
726
741
|
}
|
|
727
742
|
|
|
728
|
-
throw new ActorError(group, code, message, {
|
|
743
|
+
throw new ActorError(group, code, message, {
|
|
744
|
+
metadata,
|
|
745
|
+
rayId,
|
|
746
|
+
actor,
|
|
747
|
+
});
|
|
729
748
|
}
|
|
730
749
|
}
|
|
731
750
|
|
|
@@ -750,7 +769,7 @@ export class ActorHandleRaw {
|
|
|
750
769
|
return null;
|
|
751
770
|
}
|
|
752
771
|
|
|
753
|
-
const { group, code } = error;
|
|
772
|
+
const { group, code, rayId } = error;
|
|
754
773
|
|
|
755
774
|
if (
|
|
756
775
|
await this.#shouldRetrySchedulingError(
|
|
@@ -759,6 +778,7 @@ export class ActorHandleRaw {
|
|
|
759
778
|
actorId,
|
|
760
779
|
attempt,
|
|
761
780
|
maxAttempts,
|
|
781
|
+
rayId,
|
|
762
782
|
)
|
|
763
783
|
) {
|
|
764
784
|
return {
|
|
@@ -784,13 +804,13 @@ export class ActorHandleRaw {
|
|
|
784
804
|
|
|
785
805
|
const invalidated = this.#invalidateResolvedActorId(group, code);
|
|
786
806
|
if (invalidated && attempt < maxAttempts - 1) {
|
|
787
|
-
const
|
|
807
|
+
const waitForReady =
|
|
788
808
|
code === "starting" ||
|
|
789
809
|
code === "stopping" ||
|
|
790
810
|
code.startsWith("destroyed_");
|
|
791
811
|
return {
|
|
792
|
-
useQueryTarget,
|
|
793
|
-
waitForRetryWindow:
|
|
812
|
+
useQueryTarget: true,
|
|
813
|
+
waitForRetryWindow: waitForReady,
|
|
794
814
|
};
|
|
795
815
|
}
|
|
796
816
|
|
|
@@ -802,6 +822,7 @@ export class ActorHandleRaw {
|
|
|
802
822
|
code: string;
|
|
803
823
|
message: string;
|
|
804
824
|
metadata?: unknown;
|
|
825
|
+
rayId?: string;
|
|
805
826
|
actor?: ActorSpecifier;
|
|
806
827
|
} | null> {
|
|
807
828
|
if (response.ok) {
|
|
@@ -814,7 +835,7 @@ export class ActorHandleRaw {
|
|
|
814
835
|
: this.#encoding;
|
|
815
836
|
|
|
816
837
|
try {
|
|
817
|
-
|
|
838
|
+
const error = deserializeWithEncoding<
|
|
818
839
|
protocol.HttpResponseError,
|
|
819
840
|
HttpResponseErrorJson,
|
|
820
841
|
{
|
|
@@ -822,6 +843,7 @@ export class ActorHandleRaw {
|
|
|
822
843
|
code: string;
|
|
823
844
|
message: string;
|
|
824
845
|
metadata?: unknown;
|
|
846
|
+
rayId?: string;
|
|
825
847
|
actor?: ActorSpecifier;
|
|
826
848
|
}
|
|
827
849
|
>(
|
|
@@ -854,6 +876,10 @@ export class ActorHandleRaw {
|
|
|
854
876
|
: undefined,
|
|
855
877
|
}),
|
|
856
878
|
);
|
|
879
|
+
return {
|
|
880
|
+
...error,
|
|
881
|
+
rayId: response.headers.get("x-rivet-ray-id") ?? undefined,
|
|
882
|
+
};
|
|
857
883
|
} catch {
|
|
858
884
|
return null;
|
|
859
885
|
}
|
|
@@ -927,7 +953,9 @@ export class ActorHandleRaw {
|
|
|
927
953
|
"actor",
|
|
928
954
|
"reload_failed",
|
|
929
955
|
`reload failed with status ${response.status}: ${body}`,
|
|
930
|
-
{
|
|
956
|
+
{
|
|
957
|
+
rayId: response.headers.get("x-rivet-ray-id") ?? undefined,
|
|
958
|
+
},
|
|
931
959
|
);
|
|
932
960
|
}
|
|
933
961
|
}
|
|
@@ -67,6 +67,7 @@ export async function checkForSchedulingError(
|
|
|
67
67
|
actorId: string,
|
|
68
68
|
query: ActorQuery,
|
|
69
69
|
driver: EngineControlClient,
|
|
70
|
+
rayId?: string,
|
|
70
71
|
): Promise<ActorSchedulingError | null> {
|
|
71
72
|
const name = getActorNameFromQuery(query);
|
|
72
73
|
|
|
@@ -79,7 +80,13 @@ export async function checkForSchedulingError(
|
|
|
79
80
|
actorId,
|
|
80
81
|
error: actor.error,
|
|
81
82
|
});
|
|
82
|
-
return actorSchedulingError(
|
|
83
|
+
return actorSchedulingError(
|
|
84
|
+
group,
|
|
85
|
+
code,
|
|
86
|
+
actorId,
|
|
87
|
+
actor.error,
|
|
88
|
+
rayId,
|
|
89
|
+
);
|
|
83
90
|
}
|
|
84
91
|
} catch (err) {
|
|
85
92
|
logger().warn({
|
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
|
|
package/src/client/raw-utils.ts
CHANGED
|
@@ -99,11 +99,9 @@ export async function rawHttpFetch(
|
|
|
99
99
|
return driver.sendRequest(target, proxyRequest, options);
|
|
100
100
|
} catch (err) {
|
|
101
101
|
// Standardize to ClientActorError instead of the native backend error
|
|
102
|
-
const { group, code, message, metadata, actor } =
|
|
103
|
-
err,
|
|
104
|
-
|
|
105
|
-
);
|
|
106
|
-
throw new ActorError(group, code, message, { metadata, actor });
|
|
102
|
+
const { group, code, message, metadata, rayId, actor } =
|
|
103
|
+
deconstructError(err, true);
|
|
104
|
+
throw new ActorError(group, code, message, { metadata, rayId, actor });
|
|
107
105
|
}
|
|
108
106
|
}
|
|
109
107
|
|
package/src/client/utils.ts
CHANGED
|
@@ -215,6 +215,7 @@ export async function sendHttpRequest<
|
|
|
215
215
|
code: responseData.code,
|
|
216
216
|
message: responseData.message,
|
|
217
217
|
metadata: responseData.metadata,
|
|
218
|
+
rayId,
|
|
218
219
|
actorId: responseData.actor?.actorId,
|
|
219
220
|
generation: responseData.actor?.generation,
|
|
220
221
|
actorKey: responseData.actor?.key,
|
|
@@ -226,6 +227,7 @@ export async function sendHttpRequest<
|
|
|
226
227
|
responseData.message,
|
|
227
228
|
{
|
|
228
229
|
metadata: responseData.metadata,
|
|
230
|
+
rayId: rayId ?? undefined,
|
|
229
231
|
actor: responseData.actor,
|
|
230
232
|
},
|
|
231
233
|
);
|
package/src/common/utils.ts
CHANGED
|
@@ -44,6 +44,7 @@ export interface DeconstructedError {
|
|
|
44
44
|
code: string;
|
|
45
45
|
message: string;
|
|
46
46
|
metadata?: unknown;
|
|
47
|
+
rayId?: string;
|
|
47
48
|
actor?: errors.ActorSpecifier;
|
|
48
49
|
}
|
|
49
50
|
|
|
@@ -80,6 +81,7 @@ export function deconstructError(
|
|
|
80
81
|
let code: string;
|
|
81
82
|
let message: string;
|
|
82
83
|
let metadata: unknown;
|
|
84
|
+
let rayId: string | undefined;
|
|
83
85
|
let actor: errors.ActorSpecifier | undefined;
|
|
84
86
|
// Structured errors from core or from pre-built `RivetError` instances are canonical.
|
|
85
87
|
// Only unstructured errors go through the classifier below.
|
|
@@ -96,6 +98,7 @@ export function deconstructError(
|
|
|
96
98
|
code = error.code;
|
|
97
99
|
message = error.message;
|
|
98
100
|
metadata = error.metadata;
|
|
101
|
+
rayId = error.rayId;
|
|
99
102
|
actor = error.actor;
|
|
100
103
|
} else if (errors.ActorError.isActorError(error) && error.public) {
|
|
101
104
|
// Check if error has statusCode (could be ActorError instance or DeconstructedError)
|
|
@@ -107,6 +110,7 @@ export function deconstructError(
|
|
|
107
110
|
code = error.code;
|
|
108
111
|
message = getErrorMessage(error);
|
|
109
112
|
metadata = error.metadata;
|
|
113
|
+
rayId = error.rayId;
|
|
110
114
|
actor = error.actor;
|
|
111
115
|
} else if (exposeInternalError) {
|
|
112
116
|
if (errors.ActorError.isActorError(error)) {
|
|
@@ -116,6 +120,7 @@ export function deconstructError(
|
|
|
116
120
|
code = error.code;
|
|
117
121
|
message = getErrorMessage(error);
|
|
118
122
|
metadata = error.metadata;
|
|
123
|
+
rayId = error.rayId;
|
|
119
124
|
actor = error.actor;
|
|
120
125
|
} else {
|
|
121
126
|
statusCode = 500;
|
|
@@ -146,6 +151,7 @@ export function deconstructError(
|
|
|
146
151
|
code,
|
|
147
152
|
message,
|
|
148
153
|
metadata,
|
|
154
|
+
rayId,
|
|
149
155
|
actor,
|
|
150
156
|
};
|
|
151
157
|
}
|
package/src/engine-client/mod.ts
CHANGED
|
@@ -182,28 +182,59 @@ export class RemoteEngineControlClient implements EngineControlClient {
|
|
|
182
182
|
key,
|
|
183
183
|
});
|
|
184
184
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
185
|
+
try {
|
|
186
|
+
const { actor, created } = await getOrCreateActor(this.#config, {
|
|
187
|
+
datacenter: region,
|
|
188
|
+
name,
|
|
189
|
+
key: serializeActorKey(key),
|
|
190
|
+
runner_name_selector: poolName ?? this.#config.poolName,
|
|
191
|
+
input: actorInput
|
|
192
|
+
? uint8ArrayToBase64(
|
|
193
|
+
encodeCborCompat(actorInput as JsonCompatValue),
|
|
194
|
+
)
|
|
195
|
+
: undefined,
|
|
196
|
+
crash_policy: crashPolicy ?? "sleep",
|
|
197
|
+
});
|
|
197
198
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
199
|
+
logger().info({
|
|
200
|
+
msg: "getOrCreateWithKey: actor ready",
|
|
201
|
+
actorId: actor.actor_id,
|
|
202
|
+
name,
|
|
203
|
+
key,
|
|
204
|
+
created,
|
|
205
|
+
});
|
|
205
206
|
|
|
206
|
-
|
|
207
|
+
return apiActorToOutput(actor);
|
|
208
|
+
} catch (error) {
|
|
209
|
+
// The key is reserved in a different datacenter, which means the
|
|
210
|
+
// actor already exists there. get-by-key forwards to the reserved
|
|
211
|
+
// datacenter, so retry as a get to resolve the existing actor.
|
|
212
|
+
if (
|
|
213
|
+
error instanceof EngineApiError &&
|
|
214
|
+
error.group === "actor" &&
|
|
215
|
+
error.code === "key_reserved_in_different_datacenter"
|
|
216
|
+
) {
|
|
217
|
+
logger().warn({
|
|
218
|
+
msg: "getOrCreateWithKey: key reserved in different datacenter, retrying as get",
|
|
219
|
+
name,
|
|
220
|
+
key,
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
const response = await getActorByKey(this.#config, name, key);
|
|
224
|
+
const existing = response.actors[0];
|
|
225
|
+
if (!existing) throw error;
|
|
226
|
+
|
|
227
|
+
logger().info({
|
|
228
|
+
msg: "getOrCreateWithKey: resolved existing actor via get",
|
|
229
|
+
actorId: existing.actor_id,
|
|
230
|
+
name,
|
|
231
|
+
key,
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
return apiActorToOutput(existing);
|
|
235
|
+
}
|
|
236
|
+
throw error;
|
|
237
|
+
}
|
|
207
238
|
}
|
|
208
239
|
|
|
209
240
|
async createActor({
|
package/src/registry/native.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/actors/actors/rivetkit-typescript/packages/rivetkit/dist/tsup/chunk-4FC7TVS6.cjs","../../src/actor/errors.ts"],"names":[],"mappings":"AAAA;ACEO,IAAM,oBAAA,EAAsB,gBAAA;AAC5B,IAAM,2BAAA,EAA6B,4BAAA;AAGnC,IAAM,gBAAA,EAAkB,YAAA;AACxB,IAAM,0BAAA,EAA4B,uBAAA;AA8CzC,SAAS,0BAAA,CACR,KAAA,EAC6B;AAC7B,EAAA,OACC,OAAO,MAAA,IAAU,SAAA,GACjB,MAAA,IAAU,KAAA,GAAA,CACT,SAAA,GAAY,MAAA,GACZ,WAAA,GAAc,MAAA,GACd,aAAA,GAAgB,MAAA,GAChB,QAAA,GAAW,MAAA,GACX,QAAA,GAAW,KAAA,CAAA;AAEd;AAEA,SAAS,eAAA,CAAgB,KAAA,EAAsD;AAC9E,EAAA,OAAO,MAAA,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A;AACD;AAEgB;AACT,EAAA;AACD,EAAA;AACJ,IAAA;AACD,EAAA;AAEO,EAAA;AACN,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AACF;AAEgB;AAMd,EAAA;AAEF;AAEgB;AAOR,EAAA;AACN,qBAAA;AACA,qBAAA;AACA,IAAA;AACA,IAAA;AACC,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACD,IAAA;AACD,EAAA;AACD;AAEgB;AACR,EAAA;AACN,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACC,MAAA;AACD,IAAA;AACD,EAAA;AACD;AAEgB;AACR,EAAA;AACN,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACC,MAAA;AACA,MAAA;AACD,IAAA;AACD,EAAA;AACD;AAEgB;AACR,EAAA;AACN,IAAA;AACA,IAAA;AACA,IAAA;AAGE,IAAA;AACH,EAAA;AACD;AAEgB;AACR,EAAA;AACN,IAAA;AACA,IAAA;AACA,IAAA;AACE,IAAA;AACH,EAAA;AACD;AAOgB;AACR,EAAA;AACN,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACC,MAAA;AACA,MAAA;AACA,MAAA;AACC,QAAA;AACA,QAAA;AACA,QAAA;AAGD,MAAA;AACD,IAAA;AACD,EAAA;AACD;AAEgB;AACR,EAAA;AACN,IAAA;AACA,IAAA;AACA,EAAA;AACF;AAEgB;AACR,EAAA;AACN,IAAA;AACA,IAAA;AACA,IAAA;AACD,EAAA;AACD;ADvKU;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/actors/actors/rivetkit-typescript/packages/rivetkit/dist/tsup/chunk-4FC7TVS6.cjs","sourcesContent":[null,"import type { DeconstructedError } from \"@/common/utils\";\n\nexport const INTERNAL_ERROR_CODE = \"internal_error\";\nexport const INTERNAL_ERROR_DESCRIPTION = \"An internal error occurred\";\nexport type InternalErrorMetadata = Record<string, never>;\n\nexport const USER_ERROR_CODE = \"user_error\";\nexport const BRIDGE_RIVET_ERROR_PREFIX = \"__RIVET_ERROR_JSON__:\";\n\nexport interface RivetErrorOptions extends ErrorOptions {\n\t/** Error data can safely be serialized in a response to the client. */\n\tpublic?: boolean;\n\t/** Metadata associated with this error. */\n\tmetadata?: unknown;\n\t/** Explicit HTTP status override for router responses. */\n\tstatusCode?: number;\n\t/** Actor context associated with this error. */\n\tactor?: ActorSpecifier;\n}\n\n/** Identifies the actor that was handling work when an error was produced. */\nexport interface ActorSpecifier {\n\tactorId: string;\n\tgeneration: number;\n\tkey?: string;\n}\n\nexport interface RivetErrorLike {\n\t__type?: \"ActorError\" | \"RivetError\";\n\tgroup: string;\n\tcode: string;\n\tmessage: string;\n\tmetadata?: unknown;\n\tpublic?: boolean;\n\tstatusCode?: number;\n\tactor?: ActorSpecifier;\n}\n\nexport interface BridgeRivetErrorPayload extends RivetErrorLike {}\n\nexport interface UserErrorOptions extends ErrorOptions {\n\t/**\n\t * Machine readable code for this error. Useful for catching different types of\n\t * errors in try-catch.\n\t */\n\tcode?: string;\n\t/**\n\t * Additional metadata related to the error. Useful for understanding context\n\t * about the error.\n\t */\n\tmetadata?: unknown;\n}\n\nfunction looksLikeRivetErrorOptions(\n\tvalue: unknown,\n): value is RivetErrorOptions {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\t(\"public\" in value ||\n\t\t\t\"metadata\" in value ||\n\t\t\t\"statusCode\" in value ||\n\t\t\t\"actor\" in value ||\n\t\t\t\"cause\" in value)\n\t);\n}\n\nfunction isTypedErrorTag(value: unknown): value is \"ActorError\" | \"RivetError\" {\n\treturn value === \"ActorError\" || value === \"RivetError\";\n}\n\nfunction errorMessage(error: unknown, fallback = String(error)): string {\n\tif (\n\t\terror &&\n\t\ttypeof error === \"object\" &&\n\t\t\"message\" in error &&\n\t\ttypeof error.message === \"string\"\n\t) {\n\t\treturn error.message;\n\t}\n\n\treturn fallback;\n}\n\nexport function isRivetErrorLike(\n\terror: unknown,\n): error is RivetError | DeconstructedError | RivetErrorLike {\n\treturn (\n\t\ttypeof error === \"object\" &&\n\t\terror !== null &&\n\t\t\"group\" in error &&\n\t\ttypeof error.group === \"string\" &&\n\t\t\"code\" in error &&\n\t\ttypeof error.code === \"string\" &&\n\t\t\"message\" in error &&\n\t\ttypeof error.message === \"string\" &&\n\t\t(!(\"__type\" in error) || isTypedErrorTag(error.__type))\n\t);\n}\n\n// Matches the `actor`/`aborted` error that core raises when an in-flight queue\n// wait is interrupted because the actor is going to sleep. This is the expected\n// way a parked `run` handler unwinds during sleep, not a failure.\nexport function isActorAbortedError(error: unknown): boolean {\n\treturn (\n\t\tisRivetErrorLike(error) &&\n\t\terror.group === \"actor\" &&\n\t\terror.code === \"aborted\"\n\t);\n}\n\nfunction isActorSpecifier(value: unknown): value is ActorSpecifier {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\t\"actorId\" in value &&\n\t\ttypeof value.actorId === \"string\" &&\n\t\t\"generation\" in value &&\n\t\ttypeof value.generation === \"number\" &&\n\t\t(!(\"key\" in value) ||\n\t\t\tvalue.key === undefined ||\n\t\t\ttypeof value.key === \"string\")\n\t);\n}\n\nexport class RivetError extends Error {\n\t__type = \"RivetError\" as const;\n\n\tpublic public: boolean;\n\tpublic metadata?: unknown;\n\tpublic statusCode: number;\n\tpublic actor?: ActorSpecifier;\n\tpublic readonly group: string;\n\tpublic readonly code: string;\n\n\tpublic static isRivetError(\n\t\terror: unknown,\n\t): error is RivetError | DeconstructedError {\n\t\treturn isRivetErrorLike(error);\n\t}\n\n\tpublic static isActorError(\n\t\terror: unknown,\n\t): error is RivetError | DeconstructedError {\n\t\treturn isRivetErrorLike(error);\n\t}\n\n\tconstructor(\n\t\tgroup: string,\n\t\tcode: string,\n\t\tmessage: string,\n\t\toptions?: RivetErrorOptions | unknown,\n\t) {\n\t\tconst normalized = looksLikeRivetErrorOptions(options)\n\t\t\t? options\n\t\t\t: { metadata: options };\n\n\t\tsuper(message, { cause: normalized.cause });\n\t\tthis.name = \"RivetError\";\n\t\tthis.group = group;\n\t\tthis.code = code;\n\t\tthis.public = normalized.public ?? false;\n\t\tthis.metadata = normalized.metadata;\n\t\tthis.statusCode = normalized.statusCode ?? (this.public ? 400 : 500);\n\t\tthis.actor = normalized.actor;\n\t}\n\n\ttoString() {\n\t\treturn this.message;\n\t}\n}\n\nexport { RivetError as ActorError };\n\nexport class UserError extends RivetError {\n\tconstructor(message: string, options?: UserErrorOptions) {\n\t\tsuper(\"user\", options?.code ?? USER_ERROR_CODE, message, {\n\t\t\tpublic: true,\n\t\t\tmetadata: options?.metadata,\n\t\t\tcause: options?.cause,\n\t\t});\n\t}\n}\n\nexport function toRivetError(\n\terror: unknown,\n\tfallback?: Partial<RivetErrorLike>,\n): RivetError {\n\tif (typeof error === \"string\") {\n\t\tconst bridged = decodeBridgeRivetError(error);\n\t\tif (bridged) {\n\t\t\treturn bridged;\n\t\t}\n\t}\n\n\tif (error instanceof Error) {\n\t\tconst bridged = decodeBridgeRivetError(error.message);\n\t\tif (bridged) {\n\t\t\treturn bridged;\n\t\t}\n\t}\n\n\tif (isRivetErrorLike(error)) {\n\t\treturn new RivetError(error.group, error.code, error.message, {\n\t\t\tpublic: error.public,\n\t\t\tstatusCode: error.statusCode,\n\t\t\tmetadata: error.metadata,\n\t\t\tactor: error.actor,\n\t\t\tcause: error instanceof Error ? error.cause : undefined,\n\t\t});\n\t}\n\n\treturn new RivetError(\n\t\tfallback?.group ?? \"actor\",\n\t\tfallback?.code ?? INTERNAL_ERROR_CODE,\n\t\terrorMessage(error, fallback?.message ?? \"Unknown error\"),\n\t\t{\n\t\t\tpublic: fallback?.public,\n\t\t\tstatusCode: fallback?.statusCode,\n\t\t\tmetadata: fallback?.metadata,\n\t\t\tactor: fallback?.actor,\n\t\t\tcause: error instanceof Error ? error : undefined,\n\t\t},\n\t);\n}\n\nexport function encodeBridgeRivetError(error: RivetErrorLike): string {\n\treturn `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify({\n\t\tgroup: error.group,\n\t\tcode: error.code,\n\t\tmessage: error.message,\n\t\tmetadata: error.metadata,\n\t\tpublic: error.public,\n\t\tstatusCode: error.statusCode,\n\t\tactor: error.actor,\n\t})}`;\n}\n\nexport function decodeBridgeRivetErrorPayload(\n\tvalue: string,\n): BridgeRivetErrorPayload | undefined {\n\tif (!value.startsWith(BRIDGE_RIVET_ERROR_PREFIX)) {\n\t\treturn undefined;\n\t}\n\n\ttry {\n\t\tconst payload = JSON.parse(\n\t\t\tvalue.slice(BRIDGE_RIVET_ERROR_PREFIX.length),\n\t\t) as BridgeRivetErrorPayload;\n\t\tif (!isRivetErrorLike(payload)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (\n\t\t\tpayload.actor !== undefined &&\n\t\t\tpayload.actor !== null &&\n\t\t\t!isActorSpecifier(payload.actor)\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn payload;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport function decodeBridgeRivetError(value: string): RivetError | undefined {\n\tconst payload = decodeBridgeRivetErrorPayload(value);\n\tif (!payload) {\n\t\treturn undefined;\n\t}\n\n\treturn new RivetError(payload.group, payload.code, payload.message, {\n\t\tmetadata: payload.metadata,\n\t\tpublic: payload.public,\n\t\tstatusCode: payload.statusCode,\n\t\tactor: payload.actor ?? undefined,\n\t});\n}\n\nexport function isRivetErrorCode(\n\terror: unknown,\n\tgroup: string,\n\tcode: string,\n): error is RivetError {\n\treturn (\n\t\tisRivetErrorLike(error) && error.group === group && error.code === code\n\t);\n}\n\nexport function internalError(\n\tmessage: string,\n\toptions?: Partial<RivetErrorOptions> & {\n\t\tgroup?: string;\n\t\tcode?: string;\n\t},\n): RivetError {\n\treturn new RivetError(\n\t\toptions?.group ?? \"actor\",\n\t\toptions?.code ?? INTERNAL_ERROR_CODE,\n\t\tmessage,\n\t\t{\n\t\t\tpublic: options?.public,\n\t\t\tstatusCode: options?.statusCode,\n\t\t\tmetadata: options?.metadata,\n\t\t\tactor: options?.actor,\n\t\t\tcause: options?.cause,\n\t\t},\n\t);\n}\n\nexport function invalidEncoding(format?: string): RivetError {\n\treturn new RivetError(\n\t\t\"encoding\",\n\t\t\"invalid\",\n\t\t`Invalid encoding \\`${format}\\`. (https://www.rivet.dev/docs/clients/javascript)`,\n\t\t{\n\t\t\tpublic: true,\n\t\t},\n\t);\n}\n\nexport function invalidRequest(error?: unknown): RivetError {\n\treturn new RivetError(\n\t\t\"request\",\n\t\t\"invalid\",\n\t\t`Invalid request: ${errorMessage(error, String(error))}`,\n\t\t{\n\t\t\tpublic: true,\n\t\t\tcause: error instanceof Error ? error : undefined,\n\t\t},\n\t);\n}\n\nexport function actorNotFound(identifier?: string): RivetError {\n\treturn new RivetError(\n\t\t\"actor\",\n\t\t\"not_found\",\n\t\tidentifier\n\t\t\t? `Actor not found: ${identifier} (https://www.rivet.dev/docs/clients/javascript)`\n\t\t\t: \"Actor not found (https://www.rivet.dev/docs/clients/javascript)\",\n\t\t{ public: true },\n\t);\n}\n\nexport function actorStopping(identifier?: string): RivetError {\n\treturn new RivetError(\n\t\t\"actor\",\n\t\t\"stopping\",\n\t\tidentifier ? `Actor stopping: ${identifier}` : \"Actor stopping\",\n\t\t{ public: true },\n\t);\n}\n\nexport interface ActorRestartingOptions {\n\tphase?: \"stopping\" | \"sleeping\" | \"waking\" | \"runner_shutdown\";\n\tretryAfterMs?: number;\n}\n\nexport function actorRestarting(opts?: ActorRestartingOptions): RivetError {\n\treturn new RivetError(\n\t\t\"actor\",\n\t\t\"restarting\",\n\t\t\"Actor is restarting. Retry the request.\",\n\t\t{\n\t\t\tpublic: true,\n\t\t\tstatusCode: 503,\n\t\t\tmetadata: {\n\t\t\t\tretryable: true,\n\t\t\t\t...(opts?.phase ? { phase: opts.phase } : {}),\n\t\t\t\t...(opts?.retryAfterMs !== undefined\n\t\t\t\t\t? { retryAfterMs: opts.retryAfterMs }\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t},\n\t);\n}\n\nexport function forbiddenError(): RivetError {\n\treturn new RivetError(\"auth\", \"forbidden\", \"Forbidden\", {\n\t\tpublic: true,\n\t\tstatusCode: 403,\n\t});\n}\n\nexport function unsupportedFeature(feature: string): RivetError {\n\treturn new RivetError(\n\t\t\"feature\",\n\t\t\"unsupported\",\n\t\t`Unsupported feature: ${feature}`,\n\t);\n}\n"]}
|