@epam/ai-dial-chat-hooks 1.3.0-dev.304 → 1.3.0-dev.309
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/catalog/use-publish-history.d.ts +19 -0
- package/catalog/use-publish-history.d.ts.map +1 -0
- package/catalog/use-publish-history.js +25 -0
- package/catalog.js +19 -18
- package/conversation/conversation-data-source.d.ts +47 -0
- package/conversation/conversation-data-source.d.ts.map +1 -0
- package/conversation/conversation-data-source.js +11 -0
- package/conversation/useConversationExport/useConversationExport.d.ts.map +1 -1
- package/conversation/useConversationExport/useConversationExport.js +76 -84
- package/conversation.js +33 -32
- package/entry-points/catalog.d.ts +1 -0
- package/entry-points/catalog.d.ts.map +1 -1
- package/entry-points/conversation.d.ts +1 -0
- package/entry-points/conversation.d.ts.map +1 -1
- package/entry-points/project.d.ts +5 -0
- package/entry-points/project.d.ts.map +1 -1
- package/entry-points/scheduled-tasks.d.ts +2 -0
- package/entry-points/scheduled-tasks.d.ts.map +1 -1
- package/index.d.ts +9 -0
- package/index.d.ts.map +1 -1
- package/index.js +191 -182
- package/package.json +18 -18
- package/project/create-project-chat.d.ts +34 -0
- package/project/create-project-chat.d.ts.map +1 -0
- package/project/create-project-chat.js +27 -0
- package/project/project-conversation-data-source.d.ts +36 -0
- package/project/project-conversation-data-source.d.ts.map +1 -0
- package/project/project-conversation-data-source.js +67 -0
- package/project/project-file-preview.d.ts +28 -0
- package/project/project-file-preview.d.ts.map +1 -0
- package/project/project-file-preview.js +20 -0
- package/project/use-project-draft.d.ts +46 -0
- package/project/use-project-draft.d.ts.map +1 -0
- package/project/use-project-draft.js +54 -0
- package/project/use-project-file-preview.d.ts +42 -0
- package/project/use-project-file-preview.d.ts.map +1 -0
- package/project/use-project-file-preview.js +46 -0
- package/project.js +15 -10
- package/scheduled-task/scheduled-task-display.d.ts +108 -0
- package/scheduled-task/scheduled-task-display.d.ts.map +1 -0
- package/scheduled-task/scheduled-task-display.js +70 -0
- package/scheduled-task/useStartScheduledTask.d.ts +41 -0
- package/scheduled-task/useStartScheduledTask.d.ts.map +1 -0
- package/scheduled-task/useStartScheduledTask.js +169 -0
- package/scheduled-tasks.js +13 -11
- package/shared/sleep.d.ts +3 -0
- package/shared/sleep.d.ts.map +1 -0
- package/shared/sleep.js +13 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { ConversationListItemDto, ScheduledTaskDto, ScheduledTaskRunDto } from '@epam/ai-dial-chat-api-client';
|
|
2
|
+
import { ScheduledTaskItem, ScheduledTaskRunItem } from '@epam/ai-dial-scheduled-tasks';
|
|
3
|
+
import { ApiErrorDetails } from '../api-error/api-error';
|
|
4
|
+
/** Host-translated wording for each schedule shape; every argument is already locale-formatted. */
|
|
5
|
+
export interface ScheduledTaskScheduleLabels {
|
|
6
|
+
/** A one-time run, e.g. "Once on {date}". */
|
|
7
|
+
onceAt: (date: string) => string;
|
|
8
|
+
/** A run every `count` minutes. */
|
|
9
|
+
everyNMinutes: (count: number) => string;
|
|
10
|
+
/** An hourly run at `minute` past the hour. */
|
|
11
|
+
hourlyAt: (minute: string) => string;
|
|
12
|
+
/** A daily run at `time` (`HH:mm`). */
|
|
13
|
+
dailyAt: (time: string) => string;
|
|
14
|
+
/** A weekly run on the weekday name `day` at `time`. */
|
|
15
|
+
weeklyAt: (day: string, time: string) => string;
|
|
16
|
+
/** A run every `count` weeks on the weekday name `day` at `time`. */
|
|
17
|
+
everyNWeeks: (count: number, day: string, time: string) => string;
|
|
18
|
+
/** A monthly run on day-of-month `day` at `time`. */
|
|
19
|
+
monthlyAt: (day: string, time: string) => string;
|
|
20
|
+
/** Label for a trigger that cannot be read. */
|
|
21
|
+
invalid: string;
|
|
22
|
+
/** Label for a recurring trigger no other shape describes. */
|
|
23
|
+
recurringFallback: string;
|
|
24
|
+
}
|
|
25
|
+
/** Host-translated duration units for a run. */
|
|
26
|
+
export interface ScheduledTaskRunDurationLabels {
|
|
27
|
+
/** `count` hours, e.g. "1h". */
|
|
28
|
+
hours: (count: number) => string;
|
|
29
|
+
/** `count` minutes, e.g. "2m". */
|
|
30
|
+
minutes: (count: number) => string;
|
|
31
|
+
/** `count` seconds, e.g. "3s". */
|
|
32
|
+
seconds: (count: number) => string;
|
|
33
|
+
/** Wraps the space-joined units, e.g. "(1h 2m 3s)". */
|
|
34
|
+
suffix: (duration: string) => string;
|
|
35
|
+
}
|
|
36
|
+
/** Host-translated wording for a run's start time. */
|
|
37
|
+
export interface ScheduledTaskRunTimestampLabels {
|
|
38
|
+
/** A run that started today at the short time `time`. */
|
|
39
|
+
todayAt: (time: string) => string;
|
|
40
|
+
/** A run that started on the short date `date` at `time`. */
|
|
41
|
+
dateAt: (date: string, time: string) => string;
|
|
42
|
+
}
|
|
43
|
+
/** Locale and timezone used to format a schedule label. */
|
|
44
|
+
export interface ScheduledTaskScheduleLabelOptions {
|
|
45
|
+
/** BCP 47 locale for dates and weekday names. Defaults to the runtime default. */
|
|
46
|
+
locale?: string;
|
|
47
|
+
/** IANA timezone the schedule is shown in. Defaults to the browser's resolved timezone. */
|
|
48
|
+
timeZone?: string;
|
|
49
|
+
}
|
|
50
|
+
/** Inputs for formatting a run's start time. */
|
|
51
|
+
export interface ScheduledTaskRunTimestampOptions {
|
|
52
|
+
/** Duration units; when supplied, a present duration is appended. */
|
|
53
|
+
durationLabels?: ScheduledTaskRunDurationLabels;
|
|
54
|
+
/** BCP 47 locale for the date and time. Defaults to the runtime default. */
|
|
55
|
+
locale?: string;
|
|
56
|
+
/** Reference "now" for the same-day check. Defaults to the current time. */
|
|
57
|
+
now?: Date;
|
|
58
|
+
}
|
|
59
|
+
/** Inputs for mapping a run DTO to a run item. */
|
|
60
|
+
export interface ScheduledTaskRunItemOptions {
|
|
61
|
+
/** Wording for the run's start time. */
|
|
62
|
+
timestampLabels: ScheduledTaskRunTimestampLabels;
|
|
63
|
+
/** Wording for the run's duration. */
|
|
64
|
+
durationLabels: ScheduledTaskRunDurationLabels;
|
|
65
|
+
/** Loaded conversation-list items used to resolve `isUnread`. */
|
|
66
|
+
conversations: ConversationListItemDto[];
|
|
67
|
+
/** Whether a conversation-list id and a run's `conversationId` name the same conversation. */
|
|
68
|
+
conversationIdsMatch: (left: string, right: string) => boolean;
|
|
69
|
+
/** BCP 47 locale for the start time. Defaults to the runtime default. */
|
|
70
|
+
locale?: string;
|
|
71
|
+
/** Reference "now" for the same-day check. Defaults to the current time. */
|
|
72
|
+
now?: Date;
|
|
73
|
+
}
|
|
74
|
+
/** Pre-translated messages {@link selectScheduledTaskErrorMessage} chooses between. */
|
|
75
|
+
export interface ScheduledTaskErrorMessages {
|
|
76
|
+
/** Shown when the scheduler's application consent was revoked. */
|
|
77
|
+
adminConsentRequired: string;
|
|
78
|
+
/** Shown when the scheduler gave no reason. */
|
|
79
|
+
fallback: string;
|
|
80
|
+
}
|
|
81
|
+
/** Which message a failed scheduled-task delete should show. */
|
|
82
|
+
export declare enum ScheduledTaskDeleteErrorKind {
|
|
83
|
+
/** The task no longer exists or is already deleted (404/409). */
|
|
84
|
+
NotFound = "notFound",
|
|
85
|
+
/** The scheduler failed and the delete can be retried (502). */
|
|
86
|
+
Retryable = "retryable",
|
|
87
|
+
/** Any other failure. */
|
|
88
|
+
Generic = "generic"
|
|
89
|
+
}
|
|
90
|
+
/** Returns the schedule label for a task's trigger, shown in `timeZone`. */
|
|
91
|
+
export declare const formatScheduledTaskScheduleLabel: (task: ScheduledTaskDto, labels: ScheduledTaskScheduleLabels, { locale, timeZone, }?: ScheduledTaskScheduleLabelOptions) => string;
|
|
92
|
+
/** Maps a scheduled-task DTO to the scheduled-tasks lib's card item. */
|
|
93
|
+
export declare const toScheduledTaskItem: (task: ScheduledTaskDto, labels: ScheduledTaskScheduleLabels, options?: ScheduledTaskScheduleLabelOptions) => ScheduledTaskItem;
|
|
94
|
+
/** Maps scheduled-task DTOs to card items, preserving order. */
|
|
95
|
+
export declare const toScheduledTaskItems: (tasks: ScheduledTaskDto[], labels: ScheduledTaskScheduleLabels, options?: ScheduledTaskScheduleLabelOptions) => ScheduledTaskItem[];
|
|
96
|
+
/** Returns a run's duration as non-zero hour/minute/second units, or `undefined` when it is absent. */
|
|
97
|
+
export declare const formatScheduledTaskRunDuration: (durationSeconds: number | null | undefined, labels: ScheduledTaskRunDurationLabels) => string | undefined;
|
|
98
|
+
/** Returns a run's start time as "today at" or "date at", followed by its duration when one is given. */
|
|
99
|
+
export declare const formatScheduledTaskRunTimestamp: (startTime: string, durationSeconds: number | null | undefined, labels: ScheduledTaskRunTimestampLabels, { durationLabels, locale, now, }?: ScheduledTaskRunTimestampOptions) => string;
|
|
100
|
+
/** Maps a scheduled-task run DTO to the scheduled-tasks lib's history item. */
|
|
101
|
+
export declare const toScheduledTaskRunItem: (run: ScheduledTaskRunDto, { timestampLabels, durationLabels, conversations, conversationIdsMatch, locale, now, }: ScheduledTaskRunItemOptions) => ScheduledTaskRunItem;
|
|
102
|
+
/** Maps scheduled-task run DTOs to history items, preserving order. */
|
|
103
|
+
export declare const toScheduledTaskRunItems: (runs: ScheduledTaskRunDto[], options: ScheduledTaskRunItemOptions) => ScheduledTaskRunItem[];
|
|
104
|
+
/** Returns which message a failed delete with HTTP `status` should show. */
|
|
105
|
+
export declare const classifyScheduledTaskDeleteError: (status: number | undefined) => ScheduledTaskDeleteErrorKind;
|
|
106
|
+
/** Returns the admin-consent message, else the scheduler's own trimmed reason, else the fallback. */
|
|
107
|
+
export declare const selectScheduledTaskErrorMessage: (details: Pick<ApiErrorDetails, "code" | "upstreamMessage">, { adminConsentRequired, fallback }: ScheduledTaskErrorMessages) => string;
|
|
108
|
+
//# sourceMappingURL=scheduled-task-display.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduled-task-display.d.ts","sourceRoot":"","sources":["../../src/scheduled-task/scheduled-task-display.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,E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C"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ScheduledTaskTriggerDescriptionKind as e, describeScheduledTaskTrigger as t } from "./scheduled-task-description.js";
|
|
2
|
+
import { ScheduledTaskErrorCode as n, ScheduledTaskRunDtoStatusEnum as r } from "@epam/ai-dial-chat-api-client";
|
|
3
|
+
import { ScheduledTaskRunStatus as i } from "@epam/ai-dial-scheduled-tasks";
|
|
4
|
+
//#region src/scheduled-task/scheduled-task-display.ts
|
|
5
|
+
var a = /* @__PURE__ */ function(e) {
|
|
6
|
+
return e.NotFound = "notFound", e.Retryable = "retryable", e.Generic = "generic", e;
|
|
7
|
+
}({}), o = 60, s = 3600, c = (e, t) => new Intl.DateTimeFormat(t, {
|
|
8
|
+
weekday: "long",
|
|
9
|
+
timeZone: "UTC"
|
|
10
|
+
}).format(new Date(Date.UTC(2023, 0, 2 + Number(e)))), l = (e, t) => e.getFullYear() === t.getFullYear() && e.getMonth() === t.getMonth() && e.getDate() === t.getDate(), u = (n, r, { locale: i, timeZone: a = Intl.DateTimeFormat().resolvedOptions().timeZone } = {}) => {
|
|
11
|
+
let o = t(n.trigger, { timeZone: a }), s = o.time ?? "";
|
|
12
|
+
switch (o.kind) {
|
|
13
|
+
case e.OneTime: return r.onceAt(new Intl.DateTimeFormat(i, {
|
|
14
|
+
dateStyle: "medium",
|
|
15
|
+
timeStyle: "short"
|
|
16
|
+
}).format(o.date));
|
|
17
|
+
case e.EveryNMinutes: return r.everyNMinutes(o.intervalMinutes ?? 0);
|
|
18
|
+
case e.Hourly: return r.hourlyAt(s);
|
|
19
|
+
case e.Daily: return r.dailyAt(s);
|
|
20
|
+
case e.Weekly: return r.weeklyAt(c(o.dayOfWeek, i), s);
|
|
21
|
+
case e.EveryNWeeks: return r.everyNWeeks(o.intervalWeeks ?? 0, c(o.dayOfWeek, i), s);
|
|
22
|
+
case e.Monthly: return r.monthlyAt(o.dayOfMonth ?? "", s);
|
|
23
|
+
case e.Invalid: return r.invalid;
|
|
24
|
+
default: return r.recurringFallback;
|
|
25
|
+
}
|
|
26
|
+
}, d = (e, t, n) => ({
|
|
27
|
+
id: e.id,
|
|
28
|
+
displayName: e.displayName,
|
|
29
|
+
descriptionPreview: e.description,
|
|
30
|
+
scheduleLabel: u(e, t, n),
|
|
31
|
+
isActive: e.isActive,
|
|
32
|
+
isCompleted: e.isCompleted
|
|
33
|
+
}), f = (e, t, n) => e.map((e) => d(e, t, n)), p = (e, t) => {
|
|
34
|
+
if (e == null) return;
|
|
35
|
+
let n = [
|
|
36
|
+
[Math.floor(e / s), t.hours],
|
|
37
|
+
[Math.floor(e % s / o), t.minutes],
|
|
38
|
+
[e % o, t.seconds]
|
|
39
|
+
].filter(([e]) => e > 0).map(([e, t]) => t(e));
|
|
40
|
+
return t.suffix(n.length ? n.join(" ") : t.seconds(0));
|
|
41
|
+
}, m = (e, t, n, { durationLabels: r, locale: i, now: a = /* @__PURE__ */ new Date() } = {}) => {
|
|
42
|
+
let o = new Date(e), s = new Intl.DateTimeFormat(i, { timeStyle: "short" }).format(o), c = l(o, a) ? n.todayAt(s) : n.dateAt(new Intl.DateTimeFormat(i, {
|
|
43
|
+
month: "short",
|
|
44
|
+
day: "numeric"
|
|
45
|
+
}).format(o), s), u = r ? p(t, r) : void 0;
|
|
46
|
+
return u ? `${c} ${u}` : c;
|
|
47
|
+
}, h = (e) => {
|
|
48
|
+
switch (e) {
|
|
49
|
+
case r.Success: return i.Success;
|
|
50
|
+
case r.Error: return i.Error;
|
|
51
|
+
case r.InProgress: return i.InProgress;
|
|
52
|
+
default: return i.Missed;
|
|
53
|
+
}
|
|
54
|
+
}, g = (e, { timestampLabels: t, durationLabels: n, conversations: r, conversationIdsMatch: i, locale: a, now: o }) => {
|
|
55
|
+
let { conversationId: s } = e, c = s ? r.find((e) => i(e.id, s)) : void 0;
|
|
56
|
+
return {
|
|
57
|
+
id: e.id,
|
|
58
|
+
status: h(e.status),
|
|
59
|
+
timestampLabel: m(e.startTime, void 0, t, {
|
|
60
|
+
locale: a,
|
|
61
|
+
now: o
|
|
62
|
+
}),
|
|
63
|
+
durationLabel: p(e.durationSeconds, n),
|
|
64
|
+
conversationId: s,
|
|
65
|
+
isUnread: c?.isUnread === !0,
|
|
66
|
+
errorText: e.errorText
|
|
67
|
+
};
|
|
68
|
+
}, _ = (e, t) => e.map((e) => g(e, t)), v = (e) => e === 404 || e === 409 ? "notFound" : e === 502 ? "retryable" : "generic", y = (e, { adminConsentRequired: t, fallback: r }) => e.code === n.ScheduledTaskAdminConsentRequired ? t : e.upstreamMessage?.trim() || r;
|
|
69
|
+
//#endregion
|
|
70
|
+
export { a as ScheduledTaskDeleteErrorKind, v as classifyScheduledTaskDeleteError, p as formatScheduledTaskRunDuration, m as formatScheduledTaskRunTimestamp, u as formatScheduledTaskScheduleLabel, y as selectScheduledTaskErrorMessage, d as toScheduledTaskItem, f as toScheduledTaskItems, g as toScheduledTaskRunItem, _ as toScheduledTaskRunItems };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ScheduledTaskRunDto } from '@epam/ai-dial-chat-api-client';
|
|
2
|
+
/** Why a manually started run's status is not shown as live. */
|
|
3
|
+
export declare enum ScheduledTaskRunStatusFeedback {
|
|
4
|
+
/** A status request failed; the last known state is shown. */
|
|
5
|
+
Unavailable = "unavailable",
|
|
6
|
+
/** The run is still in progress after the polling deadline. */
|
|
7
|
+
Delayed = "delayed"
|
|
8
|
+
}
|
|
9
|
+
/** Scheduler operations {@link useStartScheduledTask} calls, bound to an already configured client by the host. */
|
|
10
|
+
export interface StartScheduledTaskApi {
|
|
11
|
+
/** Starts one run of the saved schedule and resolves with the accepted run. */
|
|
12
|
+
startScheduledTask: (scheduleId: string) => Promise<ScheduledTaskRunDto>;
|
|
13
|
+
/** Resolves with the latest state of one run. */
|
|
14
|
+
getScheduledTaskRun: (scheduleId: string, runId: string, signal?: AbortSignal) => Promise<ScheduledTaskRunDto>;
|
|
15
|
+
}
|
|
16
|
+
/** Inputs controlling a manual scheduled-task launch for the current detail page. */
|
|
17
|
+
export interface UseStartScheduledTaskOptions {
|
|
18
|
+
/** Scheduler operations used to start the run and poll its status. */
|
|
19
|
+
api: StartScheduledTaskApi;
|
|
20
|
+
/** Identifier of the schedule currently displayed by the page. */
|
|
21
|
+
scheduleId: string;
|
|
22
|
+
/** Whether the scheduled-tasks feature is available to this user. */
|
|
23
|
+
enabled: boolean;
|
|
24
|
+
/** Whether the loaded task remains eligible for manual execution. */
|
|
25
|
+
canStart: boolean;
|
|
26
|
+
/** Runs from the ordinary history hook, used to stop fast polling on terminal state. */
|
|
27
|
+
loadedRuns?: ScheduledTaskRunDto[];
|
|
28
|
+
}
|
|
29
|
+
/** Combines accepted and server-loaded runs without allowing a terminal snapshot to regress. */
|
|
30
|
+
export declare const mergeScheduledTaskRuns: (acceptedRuns: ScheduledTaskRunDto[], loadedRuns: ScheduledTaskRunDto[]) => ScheduledTaskRunDto[];
|
|
31
|
+
/** Owns one page-scoped manual-run request and its accepted history entries. */
|
|
32
|
+
export declare const useStartScheduledTask: ({ api, scheduleId, enabled, canStart, loadedRuns, }: UseStartScheduledTaskOptions) => {
|
|
33
|
+
acceptedRuns: ScheduledTaskRunDto[];
|
|
34
|
+
isStarting: boolean;
|
|
35
|
+
isRefreshingStatus: boolean;
|
|
36
|
+
statusFeedback: ScheduledTaskRunStatusFeedback | undefined;
|
|
37
|
+
terminalRun: ScheduledTaskRunDto | undefined;
|
|
38
|
+
start: () => Promise<ScheduledTaskRunDto | undefined>;
|
|
39
|
+
refreshStatus: () => void;
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=useStartScheduledTask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStartScheduledTask.d.ts","sourceRoot":"","sources":["../../src/scheduled-task/useStartScheduledTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,+BAA+B,CAAC;AAavC,gEAAgE;AAChE,oBAAY,8BAA8B;IACxC,8DAA8D;IAC9D,WAAW,gBAAgB;IAC3B,+DAA+D;IAC/D,OAAO,YAAY;CACpB;AAaD,mHAAmH;AACnH,MAAM,WAAW,qBAAqB;IACpC,+EAA+E;IAC/E,kBAAkB,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACzE,iDAAiD;IACjD,mBAAmB,EAAE,CACnB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,WAAW,KACjB,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACnC;AAED,qFAAqF;AACrF,MAAM,WAAW,4BAA4B;IAC3C,sEAAsE;IACtE,GAAG,EAAE,qBAAqB,CAAC;IAC3B,kEAAkE;IAClE,UAAU,EAAE,MAAM,CAAC;IACnB,qEAAqE;IACrE,OAAO,EAAE,OAAO,CAAC;IACjB,qEAAqE;IACrE,QAAQ,EAAE,OAAO,CAAC;IAClB,wFAAwF;IACxF,UAAU,CAAC,EAAE,mBAAmB,EAAE,CAAC;CACpC;AAmBD,gGAAgG;AAChG,eAAO,MAAM,sBAAsB,GACjC,cAAc,mBAAmB,EAAE,EACnC,YAAY,mBAAmB,EAAE,KAChC,mBAAmB,EAsBrB,CAAC;AAEF,gFAAgF;AAChF,eAAO,MAAM,qBAAqB,GAAI,qDAMnC,4BAA4B;;;;;;iBA0PO,OAAO,CACzC,mBAAmB,GAAG,SAAS,CAChC;yBA+CqC,IAAI;CAkB3C,CAAC"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { getApiErrorDetails as e } from "../api-error/api-error.js";
|
|
2
|
+
import { ScheduledTaskRunDtoStatusEnum as t } from "@epam/ai-dial-chat-api-client";
|
|
3
|
+
import { useCallback as n, useEffect as r, useLayoutEffect as i, useRef as a, useState as o } from "react";
|
|
4
|
+
//#region src/scheduled-task/useStartScheduledTask.ts
|
|
5
|
+
var s = 2e3, c = 7e4, l = /* @__PURE__ */ function(e) {
|
|
6
|
+
return e.Unavailable = "unavailable", e.Delayed = "delayed", e;
|
|
7
|
+
}({}), u = (e) => e.status !== t.InProgress, d = (e) => {
|
|
8
|
+
if (typeof e != "object" || !e || !("response" in e)) return;
|
|
9
|
+
let t = e.response?.headers.get("retry-after");
|
|
10
|
+
if (!t) return;
|
|
11
|
+
let n = Number(t);
|
|
12
|
+
if (Number.isFinite(n) && n >= 0) return n * 1e3;
|
|
13
|
+
let r = Date.parse(t);
|
|
14
|
+
return Number.isFinite(r) ? Math.max(0, r - Date.now()) : void 0;
|
|
15
|
+
}, f = (e, n) => {
|
|
16
|
+
let r = [], i = /* @__PURE__ */ new Map();
|
|
17
|
+
for (let a of [...e, ...n]) {
|
|
18
|
+
let e = i.get(a.id);
|
|
19
|
+
e === void 0 ? (i.set(a.id, r.length), r.push(a)) : r[e].status === t.InProgress && a.status !== t.InProgress && (r[e] = a);
|
|
20
|
+
}
|
|
21
|
+
return r;
|
|
22
|
+
}, p = ({ api: l, scheduleId: p, enabled: m, canStart: h, loadedRuns: g = [] }) => {
|
|
23
|
+
let [_, v] = o([]), [y, b] = o(!1), [x, S] = o(!1), [C, w] = o(), [T, E] = o(), [D, O] = o(), k = a([]), A = a(!1), j = a(!1), M = a(0), N = a(void 0), P = a(void 0), F = a(void 0), I = a(void 0), L = a(h), R = a(g);
|
|
24
|
+
i(() => {
|
|
25
|
+
L.current = h;
|
|
26
|
+
}, [h]), i(() => {
|
|
27
|
+
R.current = g;
|
|
28
|
+
}, [g]);
|
|
29
|
+
let z = n((e = !1) => {
|
|
30
|
+
I.current &&= (clearTimeout(I.current), void 0), P.current &&= (clearTimeout(P.current), void 0), F.current?.abort(), F.current = void 0, e || (N.current = void 0), j.current = !1, O(void 0), S(!1);
|
|
31
|
+
}, []), B = n((e) => {
|
|
32
|
+
let t = f([e], k.current);
|
|
33
|
+
k.current = t, v(t);
|
|
34
|
+
}, []), V = n((e, t) => {
|
|
35
|
+
N.current && M.current === t && (P.current && clearTimeout(P.current), P.current = setTimeout(() => {
|
|
36
|
+
P.current = void 0, O({
|
|
37
|
+
generation: t,
|
|
38
|
+
allowPastDeadline: !1
|
|
39
|
+
});
|
|
40
|
+
}, e));
|
|
41
|
+
}, []);
|
|
42
|
+
return r(() => {
|
|
43
|
+
if (!D) return;
|
|
44
|
+
let { generation: t, allowPastDeadline: n } = D, r = !1;
|
|
45
|
+
return (async () => {
|
|
46
|
+
let i = N.current;
|
|
47
|
+
if (!i || j.current || M.current !== t || !m || document.visibilityState === "hidden" || r) return;
|
|
48
|
+
if (!n && Date.now() >= i.deadline) {
|
|
49
|
+
w("delayed"), z(!0);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (i.retryAt && Date.now() < i.retryAt) {
|
|
53
|
+
n || V(i.retryAt - Date.now(), t);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
j.current = !0, S(!0);
|
|
57
|
+
let a = new AbortController();
|
|
58
|
+
F.current = a;
|
|
59
|
+
try {
|
|
60
|
+
let e = await l.getScheduledTaskRun(p, i.id, a.signal);
|
|
61
|
+
if (M.current !== t || r || a.signal.aborted) return;
|
|
62
|
+
if (B(e), w(void 0), u(e)) {
|
|
63
|
+
E(e), z();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (Date.now() >= i.deadline) {
|
|
67
|
+
w("delayed"), z(!0);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
V(s, t);
|
|
71
|
+
} catch (n) {
|
|
72
|
+
if (M.current !== t || r || a.signal.aborted) return;
|
|
73
|
+
let { status: o } = await e(n);
|
|
74
|
+
if (M.current !== t || r || a.signal.aborted) return;
|
|
75
|
+
if (o === 401 || o === 403 || o === 404) {
|
|
76
|
+
w("unavailable"), z();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
w("unavailable");
|
|
80
|
+
let c = d(n), l = Math.max(s, c ?? 0);
|
|
81
|
+
if (i.retryAt = Date.now() + l, Date.now() + l >= i.deadline) {
|
|
82
|
+
w("delayed"), z(!0);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
V(l, t);
|
|
86
|
+
} finally {
|
|
87
|
+
M.current === t && F.current === a && (F.current = void 0, j.current = !1, S(!1));
|
|
88
|
+
}
|
|
89
|
+
})(), () => {
|
|
90
|
+
r = !0;
|
|
91
|
+
};
|
|
92
|
+
}, [
|
|
93
|
+
l,
|
|
94
|
+
z,
|
|
95
|
+
m,
|
|
96
|
+
D,
|
|
97
|
+
p,
|
|
98
|
+
V,
|
|
99
|
+
B
|
|
100
|
+
]), r(() => (M.current += 1, z(), A.current = !1, k.current = [], b(!1), v([]), w(void 0), E(void 0), () => {
|
|
101
|
+
M.current += 1, z();
|
|
102
|
+
}), [
|
|
103
|
+
z,
|
|
104
|
+
m,
|
|
105
|
+
p
|
|
106
|
+
]), r(() => {
|
|
107
|
+
let e = N.current;
|
|
108
|
+
if (!e) return;
|
|
109
|
+
let t = g.find((t) => t.id === e.id && u(t));
|
|
110
|
+
t && (B(t), w(void 0), E(t), z());
|
|
111
|
+
}, [
|
|
112
|
+
z,
|
|
113
|
+
g,
|
|
114
|
+
B
|
|
115
|
+
]), r(() => {
|
|
116
|
+
let e = () => {
|
|
117
|
+
if (document.visibilityState !== "visible") return;
|
|
118
|
+
let e = N.current;
|
|
119
|
+
if (!e || j.current) return;
|
|
120
|
+
let t = M.current;
|
|
121
|
+
Date.now() >= e.deadline ? (w("delayed"), z(!0)) : (P.current && clearTimeout(P.current), O({
|
|
122
|
+
generation: t,
|
|
123
|
+
allowPastDeadline: !1
|
|
124
|
+
}));
|
|
125
|
+
};
|
|
126
|
+
return document.addEventListener("visibilitychange", e), () => document.removeEventListener("visibilitychange", e);
|
|
127
|
+
}, [z]), {
|
|
128
|
+
acceptedRuns: _,
|
|
129
|
+
isStarting: y,
|
|
130
|
+
isRefreshingStatus: x,
|
|
131
|
+
statusFeedback: C,
|
|
132
|
+
terminalRun: T,
|
|
133
|
+
start: n(async () => {
|
|
134
|
+
if (!m || !p || !L.current || A.current || f(k.current, R.current).some((e) => e.status === t.InProgress)) return;
|
|
135
|
+
A.current = !0, b(!0);
|
|
136
|
+
let e = M.current;
|
|
137
|
+
try {
|
|
138
|
+
let t = await l.startScheduledTask(p);
|
|
139
|
+
return M.current === e ? (B(t), w(void 0), u(t) || (N.current = {
|
|
140
|
+
id: t.id,
|
|
141
|
+
deadline: Date.now() + c
|
|
142
|
+
}, V(s, e), I.current = setTimeout(() => {
|
|
143
|
+
M.current === e && (w("delayed"), z(!0));
|
|
144
|
+
}, c)), t) : void 0;
|
|
145
|
+
} catch (t) {
|
|
146
|
+
if (M.current !== e) return;
|
|
147
|
+
throw t;
|
|
148
|
+
} finally {
|
|
149
|
+
M.current === e && (A.current = !1, b(!1));
|
|
150
|
+
}
|
|
151
|
+
}, [
|
|
152
|
+
l,
|
|
153
|
+
z,
|
|
154
|
+
m,
|
|
155
|
+
V,
|
|
156
|
+
p,
|
|
157
|
+
B
|
|
158
|
+
]),
|
|
159
|
+
refreshStatus: n(() => {
|
|
160
|
+
let e = N.current;
|
|
161
|
+
e && !j.current && m && (e.retryAt && Date.now() < e.retryAt || (P.current && clearTimeout(P.current), O({
|
|
162
|
+
generation: M.current,
|
|
163
|
+
allowPastDeadline: !0
|
|
164
|
+
})));
|
|
165
|
+
}, [m])
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
//#endregion
|
|
169
|
+
export { l as ScheduledTaskRunStatusFeedback, f as mergeScheduledTaskRuns, p as useStartScheduledTask };
|
package/scheduled-tasks.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { UnsupportedTriggerReason as e } from "./scheduled-task/scheduled-task-mapping.js";
|
|
2
2
|
import { ScheduledTaskTriggerDescriptionKind as t, describeScheduledTaskTrigger as n } from "./scheduled-task/scheduled-task-description.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
3
|
+
import { ScheduledTaskDeleteErrorKind as r, classifyScheduledTaskDeleteError as i, formatScheduledTaskRunDuration as a, formatScheduledTaskRunTimestamp as o, formatScheduledTaskScheduleLabel as s, selectScheduledTaskErrorMessage as c, toScheduledTaskItem as l, toScheduledTaskItems as u, toScheduledTaskRunItem as d, toScheduledTaskRunItems as f } from "./scheduled-task/scheduled-task-display.js";
|
|
4
|
+
import { mapFormValuesToCreateBody as p, mapFormValuesToUpdateBody as m, mapScheduledTaskDtoToFormValues as h } from "./scheduled-task/scheduled-task-trigger.js";
|
|
5
|
+
import { prepareScheduledTaskCreateBody as g, prepareScheduledTaskUpdateBody as _ } from "./scheduled-task/scheduled-task-preparation.js";
|
|
6
|
+
import { createScheduledTasksApiClient as v } from "./scheduled-task/scheduled-tasks-api-client.js";
|
|
7
|
+
import { useScheduledTasks as y } from "./scheduled-task/use-scheduled-tasks.js";
|
|
8
|
+
import { mergeRunsById as b, useScheduledTaskRuns as x } from "./scheduled-task/use-scheduled-task-runs.js";
|
|
9
|
+
import { ScheduledTaskRunStatusFeedback as S, mergeScheduledTaskRuns as C, useStartScheduledTask as w } from "./scheduled-task/useStartScheduledTask.js";
|
|
10
|
+
import { getNextCronOccurrence as T } from "./scheduled-task/scheduled-task-next-occurrence.js";
|
|
11
|
+
import { checkScheduledTaskAuthSessionError as E } from "./scheduled-task/check-scheduled-task-auth-session-error.js";
|
|
12
|
+
import { useScheduledTaskSkillDisplayNames as D } from "./scheduled-task/useScheduledTaskSkillDisplayNames/useScheduledTaskSkillDisplayNames.js";
|
|
13
|
+
import { ActiveScheduledTaskDetailState as O, ActiveScheduledTaskStatus as k, resolveActiveScheduledTask as A } from "./scheduled-task/active-scheduled-task.js";
|
|
14
|
+
import { useActiveScheduledTaskDetails as j } from "./scheduled-task/useActiveScheduledTaskDetails.js";
|
|
15
|
+
export { O as ActiveScheduledTaskDetailState, k as ActiveScheduledTaskStatus, r as ScheduledTaskDeleteErrorKind, S as ScheduledTaskRunStatusFeedback, t as ScheduledTaskTriggerDescriptionKind, e as UnsupportedTriggerReason, E as checkScheduledTaskAuthSessionError, i as classifyScheduledTaskDeleteError, v as createScheduledTasksApiClient, n as describeScheduledTaskTrigger, a as formatScheduledTaskRunDuration, o as formatScheduledTaskRunTimestamp, s as formatScheduledTaskScheduleLabel, T as getNextCronOccurrence, p as mapFormValuesToCreateBody, m as mapFormValuesToUpdateBody, h as mapScheduledTaskDtoToFormValues, b as mergeRunsById, C as mergeScheduledTaskRuns, g as prepareScheduledTaskCreateBody, _ as prepareScheduledTaskUpdateBody, A as resolveActiveScheduledTask, c as selectScheduledTaskErrorMessage, l as toScheduledTaskItem, u as toScheduledTaskItems, d as toScheduledTaskRunItem, f as toScheduledTaskRunItems, j as useActiveScheduledTaskDetails, x as useScheduledTaskRuns, D as useScheduledTaskSkillDisplayNames, y as useScheduledTasks, w as useStartScheduledTask };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sleep.d.ts","sourceRoot":"","sources":["../../src/shared/sleep.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,eAAO,MAAM,KAAK,GAAI,IAAI,MAAM,EAAE,QAAQ,WAAW,KAAG,OAAO,CAAC,IAAI,CAehE,CAAC"}
|
package/shared/sleep.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/shared/sleep.ts
|
|
2
|
+
var e = (e, t) => new Promise((n) => {
|
|
3
|
+
if (t.aborted) {
|
|
4
|
+
n();
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
let r = setTimeout(n, e);
|
|
8
|
+
t.addEventListener("abort", () => {
|
|
9
|
+
clearTimeout(r), n();
|
|
10
|
+
}, { once: !0 });
|
|
11
|
+
});
|
|
12
|
+
//#endregion
|
|
13
|
+
export { e as sleep };
|