@sixb/client 0.1.18 → 0.1.19
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/README.md +8 -23
- package/dist/actions.d.ts +9 -50
- package/dist/actions.d.ts.map +1 -1
- package/dist/{chunk-pvmd5f18.js → chunk-j512cs3e.js} +12 -221
- package/dist/chunk-j512cs3e.js.map +17 -0
- package/dist/chunk-tkjkrcdt.js.map +2 -2
- package/dist/events-builder.d.ts +1 -26
- package/dist/events-builder.d.ts.map +1 -1
- package/dist/events-transport.d.ts +1 -3
- package/dist/events-transport.d.ts.map +1 -1
- package/dist/generated/@tanstack/react-query.gen.d.ts +96 -107
- package/dist/generated/@tanstack/react-query.gen.d.ts.map +1 -1
- package/dist/generated/sdk.gen.d.ts +2 -0
- package/dist/generated/sdk.gen.d.ts.map +1 -1
- package/dist/generated/types.gen.d.ts +136 -27
- package/dist/generated/types.gen.d.ts.map +1 -1
- package/dist/hooks.js +14 -25
- package/dist/hooks.js.map +4 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -11
- package/dist/index.js.map +1 -1
- package/dist/query-hooks.d.ts +5 -5
- package/dist/query-hooks.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/actions.ts +9 -288
- package/src/events-builder.ts +2 -78
- package/src/events-transport.ts +2 -5
- package/src/file.ts +5 -2
- package/src/generated/@tanstack/react-query.gen.ts +2 -0
- package/src/generated/sdk.gen.ts +2 -0
- package/src/generated/types.gen.ts +201 -63
- package/src/index.ts +2 -1
- package/src/query-hooks.ts +29 -44
- package/dist/chunk-pvmd5f18.js.map +0 -17
package/README.md
CHANGED
|
@@ -51,16 +51,16 @@ const { data: history } = await getTelemetryHistory({
|
|
|
51
51
|
query: { from: "2025-01-01T00:00:00Z", to: "2025-01-02T00:00:00Z", order: "asc" },
|
|
52
52
|
})
|
|
53
53
|
|
|
54
|
-
//
|
|
55
|
-
import {
|
|
54
|
+
// Run an action on an object. The response is the finished run; check its status.
|
|
55
|
+
import { requestAction } from "@sixb/client"
|
|
56
56
|
|
|
57
|
-
const run = await
|
|
57
|
+
const { data: run } = await requestAction({
|
|
58
58
|
path: { actionId: "setTemperature" },
|
|
59
59
|
body: {
|
|
60
60
|
subject: { kind: "object", objectTypeId: "thermostat", primaryId: "living-room" },
|
|
61
61
|
params: { target: 72 },
|
|
62
62
|
},
|
|
63
|
-
|
|
63
|
+
throwOnError: true,
|
|
64
64
|
})
|
|
65
65
|
```
|
|
66
66
|
|
|
@@ -161,7 +161,7 @@ const temperatureHistoryOptions = telemetryHistoryQueryOptions({
|
|
|
161
161
|
property: Thermostat.p.temperature,
|
|
162
162
|
})
|
|
163
163
|
|
|
164
|
-
// Action mutation whose success means the action run
|
|
164
|
+
// Action mutation whose success means the action run succeeded.
|
|
165
165
|
function SetTemperatureButton() {
|
|
166
166
|
const setTemperature = useActionRunMutation<{ target: number }>({
|
|
167
167
|
actionId: "setTemperature",
|
|
@@ -181,10 +181,8 @@ function SetTemperatureButton() {
|
|
|
181
181
|
}
|
|
182
182
|
```
|
|
183
183
|
|
|
184
|
-
Use `useActionRunMutation()` for app buttons
|
|
185
|
-
|
|
186
|
-
`requestAction()` for enqueue-only flows where accepting the request is enough, such as long
|
|
187
|
-
background work or screens that immediately navigate to a run detail view.
|
|
184
|
+
Use `useActionRunMutation()` for app buttons: a run that failed or was cancelled rejects with
|
|
185
|
+
`ActionRunFailedError`, so loading, success, and error states follow the action's outcome.
|
|
188
186
|
|
|
189
187
|
### Domain events
|
|
190
188
|
|
|
@@ -210,19 +208,6 @@ function LiveDashboard() {
|
|
|
210
208
|
}
|
|
211
209
|
```
|
|
212
210
|
|
|
213
|
-
Action events can be scoped by run, action id, or object subject when a screen needs custom
|
|
214
|
-
coordination:
|
|
215
|
-
|
|
216
|
-
```typescript
|
|
217
|
-
useEvents(events.actions().run("run_123").terminal(), (event) => {
|
|
218
|
-
console.log("action finished", event.payload.runId)
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
useEvents(events.actions().subject(Thermostat).byId("living-room").completed(), () => {
|
|
222
|
-
console.log("thermostat action succeeded")
|
|
223
|
-
})
|
|
224
|
-
```
|
|
225
|
-
|
|
226
211
|
Use `useInvalidateOnEvent(builder, resolveKeys)` to invalidate TanStack Query keys on
|
|
227
212
|
matching events. See `docs/client/events.md` for the full event builder and hook guide.
|
|
228
213
|
|
|
@@ -239,6 +224,6 @@ The models module provides normalized types and adapter functions that transform
|
|
|
239
224
|
|
|
240
225
|
| Entry point | What it provides |
|
|
241
226
|
|---|---|
|
|
242
|
-
| `@sixb/client` | `client`, all generated SDK functions (`listObjects`, `getObject`, `upsertObject`, `requestAction`, `getActionRun`, `getTelemetryHistory`, etc.),
|
|
227
|
+
| `@sixb/client` | `client`, all generated SDK functions (`listObjects`, `getObject`, `upsertObject`, `requestAction`, `getActionRun`, `getTelemetryHistory`, etc.), `ActionRunFailedError`, all generated types, and UI model types/adapters |
|
|
243
228
|
| `@sixb/client/hooks` | TanStack Query `queryOptions` factories (`listObjectsOptions`, `getObjectOptions`, `getTelemetryHistoryOptions`, `telemetryHistoryQueryOptions`, `listRelationshipsOptions`), typed hooks (`useTelemetryHistoryQuery`, object query hooks, `useActionRunMutation`), object-query key/invalidation helpers, the `events.object(Type)` builder, and event hooks (`useEvents`, `useLatest`, `useLatestByObject`, `useInvalidateOnEvent`, `SixbEventsProvider`) |
|
|
244
229
|
| `@sixb/client/models` | UI model types (`ObjectSummary`, `ObjectDetail`, `TelemetryHistory`, `RelationshipEdge`, etc.) and adapters (`toObjectSummary`, `toObjectDetail`, `toTelemetryHistoryWithRange`) |
|
package/dist/actions.d.ts
CHANGED
|
@@ -1,61 +1,20 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
import type { GetActionRunResponse, RequestActionData, RequestActionResponse } from "./generated/types.gen";
|
|
1
|
+
import type { GetActionRunResponse } from "./generated/types.gen";
|
|
2
|
+
/** An Action run as the API returns it: recorded once, when it ended. */
|
|
4
3
|
export type ActionRunDetail = GetActionRunResponse;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
readonly timeoutMs?: number;
|
|
8
|
-
/** Slow safety check while the event socket is healthy. */
|
|
9
|
-
readonly fallbackPollIntervalMs?: number;
|
|
10
|
-
/** Faster storage check while the event socket is disconnected or reconnecting. */
|
|
11
|
-
readonly disconnectedPollIntervalMs?: number;
|
|
12
|
-
readonly signal?: AbortSignal;
|
|
13
|
-
/**
|
|
14
|
-
* When true, failed and cancelled terminal runs reject the promise. This is
|
|
15
|
-
* the default because it maps naturally to mutation error states.
|
|
16
|
-
*/
|
|
17
|
-
readonly rejectOnTerminalFailure?: boolean;
|
|
18
|
-
}
|
|
19
|
-
export interface WaitForActionRunInput extends ActionWaitOptions {
|
|
20
|
-
readonly runId: string;
|
|
21
|
-
readonly client?: Client;
|
|
22
|
-
}
|
|
23
|
-
export type RequestActionAndWaitInput = Options<RequestActionData> & ActionWaitOptions & {
|
|
24
|
-
readonly onRequested?: (response: RequestActionResponse) => void | Promise<void>;
|
|
4
|
+
type FailedActionRunDetail = ActionRunDetail & {
|
|
5
|
+
readonly status: "failed";
|
|
25
6
|
};
|
|
7
|
+
/** An Action run that finished without succeeding. `run` is its terminal record. */
|
|
26
8
|
export declare class ActionRunFailedError extends Error {
|
|
27
9
|
readonly name = "ActionRunFailedError";
|
|
28
10
|
readonly run: ActionRunDetail;
|
|
29
11
|
readonly runId: string;
|
|
30
12
|
readonly actionId: string;
|
|
31
|
-
readonly status:
|
|
13
|
+
readonly status: "failed";
|
|
32
14
|
readonly subject: ActionRunDetail["subject"];
|
|
33
15
|
readonly error: ActionRunDetail["error"];
|
|
34
|
-
constructor(run:
|
|
35
|
-
readonly status: ActionRunTerminalFailureStatus;
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
export declare class ActionRunTimeoutError extends Error {
|
|
39
|
-
readonly name = "ActionRunTimeoutError";
|
|
40
|
-
readonly runId: string;
|
|
41
|
-
readonly timeoutMs: number;
|
|
42
|
-
constructor(params: {
|
|
43
|
-
readonly runId: string;
|
|
44
|
-
readonly timeoutMs: number;
|
|
45
|
-
});
|
|
16
|
+
constructor(run: FailedActionRunDetail);
|
|
46
17
|
}
|
|
47
|
-
export declare function
|
|
48
|
-
|
|
49
|
-
* Wait for a durable action run to reach a terminal status.
|
|
50
|
-
*
|
|
51
|
-
* Flow:
|
|
52
|
-
* 1. Fetch the run detail immediately, so very fast actions that finished
|
|
53
|
-
* before the event socket opened are still observed.
|
|
54
|
-
* 2. Treat action terminal events as wakeups, then fetch the run detail again;
|
|
55
|
-
* the detail endpoint is the source of truth and carries commit diff data.
|
|
56
|
-
* 3. Keep a slow safety poll while the socket is healthy, and use a faster
|
|
57
|
-
* fallback poll only while the socket is disconnected or reconnecting.
|
|
58
|
-
*/
|
|
59
|
-
export declare function waitForActionRun(input: WaitForActionRunInput): Promise<ActionRunDetail>;
|
|
60
|
-
export declare function isTerminalActionRun(run: Pick<ActionRunDetail, "status">): boolean;
|
|
18
|
+
export declare function isFailedActionRun(run: ActionRunDetail): run is FailedActionRunDetail;
|
|
19
|
+
export {};
|
|
61
20
|
//# sourceMappingURL=actions.d.ts.map
|
package/dist/actions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAEjE,yEAAyE;AACzE,MAAM,MAAM,eAAe,GAAG,oBAAoB,CAAA;AAElD,KAAK,qBAAqB,GAAG,eAAe,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAA;CAAE,CAAA;AAE5E,oFAAoF;AACpF,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,IAAI,0BAAyB;IACtC,QAAQ,CAAC,GAAG,EAAE,eAAe,CAAA;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAA;IACzB,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,CAAA;IAC5C,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,CAAA;gBAE5B,GAAG,EAAE,qBAAqB;CASvC;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,eAAe,GAAG,GAAG,IAAI,qBAAqB,CAEpF"}
|
|
@@ -6,14 +6,12 @@ import {
|
|
|
6
6
|
} from "./chunk-j9t5h44d.js";
|
|
7
7
|
import {
|
|
8
8
|
client2,
|
|
9
|
-
requestAction2,
|
|
10
9
|
uploadFileRaw2,
|
|
11
10
|
createFileUpload2,
|
|
12
11
|
uploadFileContent2,
|
|
13
12
|
signFileUploadPart2,
|
|
14
13
|
completeFileUpload2,
|
|
15
|
-
abortFileUpload2
|
|
16
|
-
getActionRun2
|
|
14
|
+
abortFileUpload2
|
|
17
15
|
} from "./chunk-tkjkrcdt.js";
|
|
18
16
|
import {
|
|
19
17
|
encodeObjectId2,
|
|
@@ -182,7 +180,7 @@ function isRecord2(value) {
|
|
|
182
180
|
|
|
183
181
|
// src/events-transport.ts
|
|
184
182
|
function createEventSocket2(options) {
|
|
185
|
-
const { topic, types, objectTypeId, primaryId,
|
|
183
|
+
const { topic, types, objectTypeId, primaryId, runId, limit } = options;
|
|
186
184
|
let latestCursor = options.afterCursor;
|
|
187
185
|
let transportState = {
|
|
188
186
|
connected: false,
|
|
@@ -217,7 +215,6 @@ function createEventSocket2(options) {
|
|
|
217
215
|
...types && types.length > 0 ? { types } : {},
|
|
218
216
|
...objectTypeId ? { objectTypeId } : {},
|
|
219
217
|
...primaryId ? { primaryId } : {},
|
|
220
|
-
...actionId ? { actionId } : {},
|
|
221
218
|
...runId ? { runId } : {},
|
|
222
219
|
...latestCursor ? { afterCursor: latestCursor } : {},
|
|
223
220
|
...limit ? { limit } : {}
|
|
@@ -317,7 +314,6 @@ function createWsSubscribeExecutor2(options) {
|
|
|
317
314
|
types: filter.types,
|
|
318
315
|
objectTypeId: filter.objectTypeId,
|
|
319
316
|
primaryId: filter.primaryId,
|
|
320
|
-
actionId: filter.actionId,
|
|
321
317
|
runId: filter.runId,
|
|
322
318
|
afterCursor: subscribeOptions?.afterCursor,
|
|
323
319
|
limit: subscribeOptions?.limit,
|
|
@@ -428,25 +424,12 @@ class EventsBuilderImpl {
|
|
|
428
424
|
run(runId) {
|
|
429
425
|
return this.withFilter({ runId });
|
|
430
426
|
}
|
|
431
|
-
action(actionId) {
|
|
432
|
-
return this.withFilter({ actionId });
|
|
433
|
-
}
|
|
434
|
-
subject(objectType) {
|
|
435
|
-
const objectTypeId = typeof objectType === "string" ? objectType : objectType.id;
|
|
436
|
-
return this.withFilter({ objectTypeId });
|
|
437
|
-
}
|
|
438
|
-
requested() {
|
|
439
|
-
return this.withFilter({ topic: "actions", types: ["action.requested"] });
|
|
440
|
-
}
|
|
441
|
-
completed() {
|
|
442
|
-
return this.withFilter({ topic: "actions", types: ["action.completed"] });
|
|
443
|
-
}
|
|
444
427
|
failed() {
|
|
445
428
|
const selector = this.params.selector;
|
|
446
429
|
if (selector && "failed" in selector) {
|
|
447
430
|
return this.withSelectorSpec(selector.failed());
|
|
448
431
|
}
|
|
449
|
-
return this
|
|
432
|
+
return this;
|
|
450
433
|
}
|
|
451
434
|
succeeded() {
|
|
452
435
|
const selector = this.params.selector;
|
|
@@ -462,9 +445,6 @@ class EventsBuilderImpl {
|
|
|
462
445
|
}
|
|
463
446
|
return this;
|
|
464
447
|
}
|
|
465
|
-
terminal() {
|
|
466
|
-
return this.withFilter({ topic: "actions", types: ["action.completed", "action.failed"] });
|
|
467
|
-
}
|
|
468
448
|
triggered() {
|
|
469
449
|
return this.withFilter({ topic: "rules", types: ["rule.triggered"] });
|
|
470
450
|
}
|
|
@@ -516,9 +496,6 @@ function topicBuilder(topic, options) {
|
|
|
516
496
|
function runBuilder(topic, options) {
|
|
517
497
|
return createBuilder({ topic }, options);
|
|
518
498
|
}
|
|
519
|
-
function actionBuilder(options) {
|
|
520
|
-
return createBuilder({ topic: "actions" }, options);
|
|
521
|
-
}
|
|
522
499
|
var eventsApi = {};
|
|
523
500
|
eventsApi.object = (objectType, options) => {
|
|
524
501
|
const selector = selectEvents.object(objectType);
|
|
@@ -531,8 +508,6 @@ eventsApi.all = (options) => createBuilder({}, options);
|
|
|
531
508
|
eventsApi.objects = (options) => topicBuilder("objects", options);
|
|
532
509
|
eventsApi.telemetry = (options) => topicBuilder("telemetry", options);
|
|
533
510
|
eventsApi.links = (options) => topicBuilder("links", options);
|
|
534
|
-
eventsApi.actions = (options) => actionBuilder(options);
|
|
535
|
-
eventsApi.action = (action, options) => createBuilder({ topic: "actions", actionId: action.id }, options);
|
|
536
511
|
eventsApi.rule = (rule, options) => createBuilder({ topic: "rules", ruleId: rule.id }, options);
|
|
537
512
|
eventsApi.dataset = (dataset, options) => {
|
|
538
513
|
const selector = selectEvents.dataset(dataset);
|
|
@@ -598,10 +573,6 @@ function normalizeTelemetryValue(value) {
|
|
|
598
573
|
}
|
|
599
574
|
}
|
|
600
575
|
// src/actions.ts
|
|
601
|
-
var DEFAULT_ACTION_WAIT_TIMEOUT_MS = 60000;
|
|
602
|
-
var DEFAULT_ACTION_WAIT_FALLBACK_POLL_MS = 1e4;
|
|
603
|
-
var DEFAULT_ACTION_WAIT_DISCONNECTED_POLL_MS = 1000;
|
|
604
|
-
|
|
605
576
|
class ActionRunFailedError2 extends Error {
|
|
606
577
|
name = "ActionRunFailedError";
|
|
607
578
|
run;
|
|
@@ -611,7 +582,7 @@ class ActionRunFailedError2 extends Error {
|
|
|
611
582
|
subject;
|
|
612
583
|
error;
|
|
613
584
|
constructor(run) {
|
|
614
|
-
super(run.error?.message ?? `Action run '${run.id}'
|
|
585
|
+
super(run.error?.message ?? `Action run '${run.id}' failed.`);
|
|
615
586
|
this.run = run;
|
|
616
587
|
this.runId = run.id;
|
|
617
588
|
this.actionId = run.actionId;
|
|
@@ -620,190 +591,8 @@ class ActionRunFailedError2 extends Error {
|
|
|
620
591
|
this.error = run.error;
|
|
621
592
|
}
|
|
622
593
|
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
name = "ActionRunTimeoutError";
|
|
626
|
-
runId;
|
|
627
|
-
timeoutMs;
|
|
628
|
-
constructor(params) {
|
|
629
|
-
super(`Action run '${params.runId}' did not finish within ${params.timeoutMs}ms.`);
|
|
630
|
-
this.runId = params.runId;
|
|
631
|
-
this.timeoutMs = params.timeoutMs;
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
async function requestActionAndWait2(input) {
|
|
635
|
-
const {
|
|
636
|
-
timeoutMs,
|
|
637
|
-
fallbackPollIntervalMs,
|
|
638
|
-
disconnectedPollIntervalMs,
|
|
639
|
-
rejectOnTerminalFailure,
|
|
640
|
-
onRequested,
|
|
641
|
-
...requestOptions
|
|
642
|
-
} = input;
|
|
643
|
-
const response = await requestAction2({
|
|
644
|
-
...requestOptions,
|
|
645
|
-
throwOnError: true
|
|
646
|
-
});
|
|
647
|
-
await onRequested?.(response.data);
|
|
648
|
-
return waitForActionRun2({
|
|
649
|
-
runId: response.data.runId,
|
|
650
|
-
client: input.client,
|
|
651
|
-
signal: input.signal,
|
|
652
|
-
timeoutMs,
|
|
653
|
-
fallbackPollIntervalMs,
|
|
654
|
-
disconnectedPollIntervalMs,
|
|
655
|
-
rejectOnTerminalFailure
|
|
656
|
-
});
|
|
657
|
-
}
|
|
658
|
-
function waitForActionRun2(input) {
|
|
659
|
-
const timeoutMs = input.timeoutMs ?? DEFAULT_ACTION_WAIT_TIMEOUT_MS;
|
|
660
|
-
const fallbackPollIntervalMs = input.fallbackPollIntervalMs ?? DEFAULT_ACTION_WAIT_FALLBACK_POLL_MS;
|
|
661
|
-
const disconnectedPollIntervalMs = input.disconnectedPollIntervalMs ?? DEFAULT_ACTION_WAIT_DISCONNECTED_POLL_MS;
|
|
662
|
-
const rejectOnTerminalFailure = input.rejectOnTerminalFailure ?? true;
|
|
663
|
-
const signal = input.signal;
|
|
664
|
-
const startedAt = Date.now();
|
|
665
|
-
if (signal?.aborted) {
|
|
666
|
-
return Promise.reject(signal.reason ?? new Error("aborted"));
|
|
667
|
-
}
|
|
668
|
-
return new Promise((resolve, reject) => {
|
|
669
|
-
let timeoutTimer;
|
|
670
|
-
let pollTimer;
|
|
671
|
-
let unsubscribeFromTerminalEvents;
|
|
672
|
-
let settled = false;
|
|
673
|
-
let checking = false;
|
|
674
|
-
let checkRequested = false;
|
|
675
|
-
let socketHealthy = false;
|
|
676
|
-
const clearTimer = (timer) => {
|
|
677
|
-
if (timer)
|
|
678
|
-
clearTimeout(timer);
|
|
679
|
-
};
|
|
680
|
-
const cleanup = () => {
|
|
681
|
-
if (settled)
|
|
682
|
-
return;
|
|
683
|
-
settled = true;
|
|
684
|
-
clearTimer(timeoutTimer);
|
|
685
|
-
clearTimer(pollTimer);
|
|
686
|
-
unsubscribeFromTerminalEvents?.();
|
|
687
|
-
signal?.removeEventListener("abort", onAbort);
|
|
688
|
-
};
|
|
689
|
-
const rejectWith = (error) => {
|
|
690
|
-
cleanup();
|
|
691
|
-
reject(error);
|
|
692
|
-
};
|
|
693
|
-
const resolveWith = (run) => {
|
|
694
|
-
cleanup();
|
|
695
|
-
if (rejectOnTerminalFailure && isTerminalFailureRun(run)) {
|
|
696
|
-
reject(new ActionRunFailedError2(run));
|
|
697
|
-
return;
|
|
698
|
-
}
|
|
699
|
-
resolve(run);
|
|
700
|
-
};
|
|
701
|
-
const currentPollIntervalMs = () => socketHealthy ? fallbackPollIntervalMs : disconnectedPollIntervalMs;
|
|
702
|
-
const schedulePoll = () => {
|
|
703
|
-
if (settled || pollTimer)
|
|
704
|
-
return;
|
|
705
|
-
pollTimer = setTimeout(() => {
|
|
706
|
-
pollTimer = undefined;
|
|
707
|
-
check();
|
|
708
|
-
}, currentPollIntervalMs());
|
|
709
|
-
};
|
|
710
|
-
const reschedulePoll = () => {
|
|
711
|
-
if (settled)
|
|
712
|
-
return;
|
|
713
|
-
clearTimer(pollTimer);
|
|
714
|
-
pollTimer = undefined;
|
|
715
|
-
schedulePoll();
|
|
716
|
-
};
|
|
717
|
-
const wakeAndCheck = () => {
|
|
718
|
-
clearTimer(pollTimer);
|
|
719
|
-
pollTimer = undefined;
|
|
720
|
-
check();
|
|
721
|
-
};
|
|
722
|
-
const check = async () => {
|
|
723
|
-
if (settled)
|
|
724
|
-
return;
|
|
725
|
-
if (checking) {
|
|
726
|
-
checkRequested = true;
|
|
727
|
-
return;
|
|
728
|
-
}
|
|
729
|
-
checking = true;
|
|
730
|
-
try {
|
|
731
|
-
const run = await fetchActionRun(input.runId, {
|
|
732
|
-
client: input.client,
|
|
733
|
-
signal
|
|
734
|
-
});
|
|
735
|
-
if (run && isTerminalActionRun2(run)) {
|
|
736
|
-
resolveWith(run);
|
|
737
|
-
return;
|
|
738
|
-
}
|
|
739
|
-
schedulePoll();
|
|
740
|
-
} catch (error) {
|
|
741
|
-
rejectWith(error);
|
|
742
|
-
} finally {
|
|
743
|
-
checking = false;
|
|
744
|
-
if (!settled && checkRequested) {
|
|
745
|
-
checkRequested = false;
|
|
746
|
-
wakeAndCheck();
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
};
|
|
750
|
-
const onAbort = () => {
|
|
751
|
-
rejectWith(signal?.reason ?? new Error("aborted"));
|
|
752
|
-
};
|
|
753
|
-
timeoutTimer = setTimeout(() => {
|
|
754
|
-
rejectWith(new ActionRunTimeoutError2({ runId: input.runId, timeoutMs }));
|
|
755
|
-
}, Math.max(0, timeoutMs - (Date.now() - startedAt)));
|
|
756
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
757
|
-
unsubscribeFromTerminalEvents = events2.actions({ client: input.client }).run(input.runId).terminal().subscribe(() => {
|
|
758
|
-
wakeAndCheck();
|
|
759
|
-
}, {
|
|
760
|
-
onError: () => {
|
|
761
|
-
return;
|
|
762
|
-
},
|
|
763
|
-
onStateChange: (state) => {
|
|
764
|
-
const nextSocketHealthy = state.connected && !state.reconnecting && !state.error;
|
|
765
|
-
if (nextSocketHealthy !== socketHealthy) {
|
|
766
|
-
socketHealthy = nextSocketHealthy;
|
|
767
|
-
if (socketHealthy) {
|
|
768
|
-
wakeAndCheck();
|
|
769
|
-
} else {
|
|
770
|
-
reschedulePoll();
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
});
|
|
775
|
-
check();
|
|
776
|
-
});
|
|
777
|
-
}
|
|
778
|
-
function isTerminalActionRun2(run) {
|
|
779
|
-
return run.status === "succeeded" || isTerminalFailureRun(run);
|
|
780
|
-
}
|
|
781
|
-
function isTerminalFailureRun(run) {
|
|
782
|
-
return run.status === "failed" || run.status === "cancelled";
|
|
783
|
-
}
|
|
784
|
-
async function fetchActionRun(runId, options) {
|
|
785
|
-
const result = await getActionRun2({
|
|
786
|
-
client: options.client,
|
|
787
|
-
path: { runId },
|
|
788
|
-
signal: options.signal,
|
|
789
|
-
throwOnError: false
|
|
790
|
-
});
|
|
791
|
-
if (result.data) {
|
|
792
|
-
return result.data;
|
|
793
|
-
}
|
|
794
|
-
if (result.response.status === 404) {
|
|
795
|
-
return null;
|
|
796
|
-
}
|
|
797
|
-
throw toActionRunRequestError(result.error, runId);
|
|
798
|
-
}
|
|
799
|
-
function toActionRunRequestError(error, runId) {
|
|
800
|
-
if (error instanceof Error) {
|
|
801
|
-
return error;
|
|
802
|
-
}
|
|
803
|
-
if (error && typeof error === "object" && "error" in error) {
|
|
804
|
-
return new Error(String(error.error));
|
|
805
|
-
}
|
|
806
|
-
return new Error(`[SixbClient] Failed to fetch action run '${runId}'.`);
|
|
594
|
+
function isFailedActionRun(run) {
|
|
595
|
+
return run.status === "failed";
|
|
807
596
|
}
|
|
808
597
|
|
|
809
598
|
// src/file.ts
|
|
@@ -1104,9 +893,10 @@ async function uploadFileStaged(file, options) {
|
|
|
1104
893
|
return toFileRef(completed, "complete");
|
|
1105
894
|
}
|
|
1106
895
|
async function putDirectUpload(input) {
|
|
896
|
+
const fetch = input.fetch;
|
|
1107
897
|
let response;
|
|
1108
898
|
try {
|
|
1109
|
-
response = await
|
|
899
|
+
response = await fetch(input.url, {
|
|
1110
900
|
method: input.method,
|
|
1111
901
|
headers: input.headers,
|
|
1112
902
|
body: input.file,
|
|
@@ -1120,6 +910,7 @@ async function putDirectUpload(input) {
|
|
|
1120
910
|
}
|
|
1121
911
|
}
|
|
1122
912
|
async function uploadMultipartFile(input) {
|
|
913
|
+
const fetch = input.fetch;
|
|
1123
914
|
const parts = [];
|
|
1124
915
|
let partNumber = 1;
|
|
1125
916
|
for (let offset = 0;offset < input.file.size; offset += input.partSizeBytes) {
|
|
@@ -1130,7 +921,7 @@ async function uploadMultipartFile(input) {
|
|
|
1130
921
|
}));
|
|
1131
922
|
let response;
|
|
1132
923
|
try {
|
|
1133
|
-
response = await
|
|
924
|
+
response = await fetch(signedPart.url, {
|
|
1134
925
|
method: signedPart.method,
|
|
1135
926
|
headers: signedPart.headers,
|
|
1136
927
|
body: input.file.slice(offset, Math.min(input.file.size, offset + input.partSizeBytes)),
|
|
@@ -1233,6 +1024,6 @@ function toFileRef(value, stage) {
|
|
|
1233
1024
|
};
|
|
1234
1025
|
}
|
|
1235
1026
|
|
|
1236
|
-
export { createSixbAgentsWebSocketUrl2, createAgentRunSocket2, createAgentActivitySocket2, parseAgentRunStreamServerMessage2, isSixbEvent2, createEventSocket2, createSixbEventsWebSocketUrl2, parseEventStreamMessage2, matchesSubscription2, createWsSubscribeExecutor2, buildEventPredicate2, events2, telemetryUpdateFromEvent2, objectIdAliases2, telemetryUpdateKey2, ActionRunFailedError2,
|
|
1027
|
+
export { createSixbAgentsWebSocketUrl2, createAgentRunSocket2, createAgentActivitySocket2, parseAgentRunStreamServerMessage2, isSixbEvent2, createEventSocket2, createSixbEventsWebSocketUrl2, parseEventStreamMessage2, matchesSubscription2, createWsSubscribeExecutor2, buildEventPredicate2, events2, telemetryUpdateFromEvent2, objectIdAliases2, telemetryUpdateKey2, ActionRunFailedError2, isFailedActionRun, objectFileContentUrl2, SixbFileUploadError2, uploadFile2 };
|
|
1237
1028
|
|
|
1238
|
-
//# debugId=
|
|
1029
|
+
//# debugId=4919889487A9375C64756E2164756E21
|