@dexto/tools-scheduler 1.7.1 → 1.8.0
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/errors.cjs +2 -2
- package/dist/errors.js +2 -2
- package/dist/index.d.cts +1 -0
- package/dist/manager.cjs +2 -2
- package/dist/manager.d.cts +3 -2
- package/dist/manager.d.ts +3 -2
- package/dist/manager.d.ts.map +1 -1
- package/dist/manager.js +2 -2
- package/dist/service/index.d.cts +1 -0
- package/dist/service.cjs +1 -1
- package/dist/service.d.cts +4 -3
- package/dist/service.d.ts +4 -3
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +1 -1
- package/dist/storage.cjs +33 -17
- package/dist/storage.d.cts +8 -3
- package/dist/storage.d.ts +8 -3
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +33 -17
- package/dist/tool-provider.cjs +3 -3
- package/dist/tool-provider.d.cts +1 -0
- package/dist/tool-provider.js +3 -3
- package/dist/tool-types.d.cts +1 -0
- package/dist/tools/create-schedule.d.cts +1 -0
- package/dist/tools/delete-schedule.d.cts +1 -0
- package/dist/tools/get-history.d.cts +1 -0
- package/dist/tools/get-schedule.d.cts +1 -0
- package/dist/tools/index.d.cts +1 -0
- package/dist/tools/list-schedules.d.cts +1 -0
- package/dist/tools/trigger-schedule.d.cts +1 -0
- package/dist/tools/update-schedule.d.cts +1 -0
- package/package.json +3 -3
package/dist/errors.cjs
CHANGED
|
@@ -41,9 +41,9 @@ class SchedulerError {
|
|
|
41
41
|
import_error_codes.SchedulerErrorCode.SCHEDULER_MISSING_STORAGE,
|
|
42
42
|
SCHEDULER_ERROR_SCOPE,
|
|
43
43
|
import_core.ErrorType.SYSTEM,
|
|
44
|
-
"
|
|
44
|
+
"Tool state store is required but not available",
|
|
45
45
|
void 0,
|
|
46
|
-
"Ensure
|
|
46
|
+
"Ensure DextoStores includes the toolState store"
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
49
|
static invalidConfig(details) {
|
package/dist/errors.js
CHANGED
|
@@ -17,9 +17,9 @@ class SchedulerError {
|
|
|
17
17
|
SchedulerErrorCode.SCHEDULER_MISSING_STORAGE,
|
|
18
18
|
SCHEDULER_ERROR_SCOPE,
|
|
19
19
|
ErrorType.SYSTEM,
|
|
20
|
-
"
|
|
20
|
+
"Tool state store is required but not available",
|
|
21
21
|
void 0,
|
|
22
|
-
"Ensure
|
|
22
|
+
"Ensure DextoStores includes the toolState store"
|
|
23
23
|
);
|
|
24
24
|
}
|
|
25
25
|
static invalidConfig(details) {
|
package/dist/index.d.cts
CHANGED
package/dist/manager.cjs
CHANGED
|
@@ -40,11 +40,11 @@ var import_storage = require("./storage.js");
|
|
|
40
40
|
var import_executor = require("./executor.js");
|
|
41
41
|
var import_errors = require("./errors.js");
|
|
42
42
|
class SchedulerManager {
|
|
43
|
-
constructor(
|
|
43
|
+
constructor(toolStateStore, config, logger, options) {
|
|
44
44
|
this.config = config;
|
|
45
45
|
this.logger = logger;
|
|
46
46
|
this.storage = new import_storage.ScheduleStorage(
|
|
47
|
-
|
|
47
|
+
toolStateStore,
|
|
48
48
|
config.maxExecutionHistory,
|
|
49
49
|
logger,
|
|
50
50
|
options?.storageNamespace
|
package/dist/manager.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Logger } from '@dexto/core';
|
|
2
|
+
import { ToolStateStore } from '@dexto/core/storage';
|
|
2
3
|
import { SchedulerToolsConfig, CreateScheduleInput, UpdateScheduleInput } from './schemas.cjs';
|
|
3
4
|
import { ScheduleExecutorFn, Schedule, ScheduleFilters, ExecutionLog } from './types.cjs';
|
|
4
5
|
import 'zod';
|
|
@@ -30,7 +31,7 @@ declare class SchedulerManager {
|
|
|
30
31
|
private initialized;
|
|
31
32
|
private started;
|
|
32
33
|
private cachedSchedules;
|
|
33
|
-
constructor(
|
|
34
|
+
constructor(toolStateStore: ToolStateStore, config: SchedulerToolsConfig, logger: Logger, options?: {
|
|
34
35
|
storageNamespace?: string;
|
|
35
36
|
});
|
|
36
37
|
/**
|
package/dist/manager.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Scheduler Manager - Core service for internal task scheduling
|
|
3
3
|
*/
|
|
4
|
-
import type {
|
|
4
|
+
import type { Logger } from '@dexto/core';
|
|
5
|
+
import type { ToolStateStore } from '@dexto/core/storage';
|
|
5
6
|
import type { SchedulerToolsConfig } from './schemas.js';
|
|
6
7
|
import { type CreateScheduleInput, type UpdateScheduleInput } from './schemas.js';
|
|
7
8
|
import type { Schedule, ExecutionLog, ScheduleFilters, ScheduleExecutorFn } from './types.js';
|
|
@@ -28,7 +29,7 @@ export declare class SchedulerManager {
|
|
|
28
29
|
private initialized;
|
|
29
30
|
private started;
|
|
30
31
|
private cachedSchedules;
|
|
31
|
-
constructor(
|
|
32
|
+
constructor(toolStateStore: ToolStateStore, config: SchedulerToolsConfig, logger: Logger, options?: {
|
|
32
33
|
storageNamespace?: string;
|
|
33
34
|
});
|
|
34
35
|
/**
|
package/dist/manager.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAGH,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EAC3B,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAK9F;;;;;;;;;;;;GAYG;AACH,qBAAa,gBAAgB;IAWrB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,MAAM;IAXlB,OAAO,CAAC,SAAS,CAA8C;IAC/D,OAAO,CAAC,OAAO,CAAkB;IACjC,OAAO,CAAC,QAAQ,CAAmB;IACnC,OAAO,CAAC,cAAc,CAAoC;IAC1D,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,eAAe,CAAyB;gBAG5C,cAAc,EAAE,cAAc,EACtB,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE;QAAE,gBAAgB,CAAC,EAAE,MAAM,CAAA;KAAE;IAW3C;;OAEG;IACH,WAAW,CAAC,EAAE,EAAE,kBAAkB,GAAG,IAAI;IAIzC;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAmB3B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA8B5B;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAgB3B;;;;;OAKG;IACG,cAAc,CAAC,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IA4F9F;;;;;;OAMG;IACG,cAAc,CAChB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,IAAI,CAAC,mBAAmB,EAAE,YAAY,CAAC,EAChD,gBAAgB,CAAC,EAAE,MAAM,GAC1B,OAAO,CAAC,QAAQ,CAAC;IA6HpB;;OAEG;IACG,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBvD;;OAEG;IACG,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAI/D;;OAEG;IACG,aAAa,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAenE;;OAEG;IACG,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAWnE;;OAEG;IACG,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAItF;;OAEG;IACH,SAAS,IAAI;QACT,WAAW,EAAE,OAAO,CAAC;QACrB,OAAO,EAAE,OAAO,CAAC;QACjB,eAAe,EAAE,MAAM,CAAC;KAC3B;IAQD;;OAEG;YACW,YAAY;IAwC1B;;OAEG;IACH,OAAO,CAAC,cAAc;IAStB;;OAEG;YACW,eAAe;YAIf,uBAAuB;IAmDrC,OAAO,CAAC,cAAc;IAStB;;OAEG;IACH,OAAO,CAAC,gBAAgB;CAc3B"}
|
package/dist/manager.js
CHANGED
|
@@ -10,11 +10,11 @@ import { ScheduleStorage } from "./storage.js";
|
|
|
10
10
|
import { ScheduleExecutor } from "./executor.js";
|
|
11
11
|
import { SchedulerError } from "./errors.js";
|
|
12
12
|
class SchedulerManager {
|
|
13
|
-
constructor(
|
|
13
|
+
constructor(toolStateStore, config, logger, options) {
|
|
14
14
|
this.config = config;
|
|
15
15
|
this.logger = logger;
|
|
16
16
|
this.storage = new ScheduleStorage(
|
|
17
|
-
|
|
17
|
+
toolStateStore,
|
|
18
18
|
config.maxExecutionHistory,
|
|
19
19
|
logger,
|
|
20
20
|
options?.storageNamespace
|
package/dist/service/index.d.cts
CHANGED
|
@@ -5,6 +5,7 @@ export { ScheduleExecutor } from '../executor.cjs';
|
|
|
5
5
|
export { ensureSchedulerManagerForAgent, getSchedulerManager, registerSchedulerManager, unregisterSchedulerManager } from '../tool-provider.cjs';
|
|
6
6
|
export { SchedulerManagerGetter } from '../tool-types.cjs';
|
|
7
7
|
import '@dexto/core';
|
|
8
|
+
import '@dexto/core/storage';
|
|
8
9
|
import '../schemas.cjs';
|
|
9
10
|
import 'zod';
|
|
10
11
|
import '../types.cjs';
|
package/dist/service.cjs
CHANGED
|
@@ -26,7 +26,7 @@ var import_manager = require("./manager.js");
|
|
|
26
26
|
async function createSchedulerService(options) {
|
|
27
27
|
const resolvedConfig = options.config ?? import_schemas.SchedulerToolsConfigSchema.parse({ type: "scheduler-tools" });
|
|
28
28
|
const manager = new import_manager.SchedulerManager(
|
|
29
|
-
options.
|
|
29
|
+
options.toolStateStore,
|
|
30
30
|
resolvedConfig,
|
|
31
31
|
options.logger,
|
|
32
32
|
options.storageNamespace ? { storageNamespace: options.storageNamespace } : void 0
|
package/dist/service.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Logger } from '@dexto/core';
|
|
2
|
+
import { ToolStateStore } from '@dexto/core/storage';
|
|
2
3
|
import { SchedulerToolsConfig } from './schemas.cjs';
|
|
3
4
|
import { ScheduleExecutorFn } from './types.cjs';
|
|
4
5
|
import { SchedulerManager } from './manager.cjs';
|
|
@@ -7,7 +8,7 @@ import 'zod';
|
|
|
7
8
|
/**
|
|
8
9
|
* Options for constructing a scheduler service.
|
|
9
10
|
*
|
|
10
|
-
* @property
|
|
11
|
+
* @property toolStateStore Store used for scheduler persistence.
|
|
11
12
|
* @property logger Logger used by the scheduler manager.
|
|
12
13
|
* @property config Optional scheduler config. Defaults to `SchedulerToolsConfigSchema` when omitted.
|
|
13
14
|
* @property storageNamespace Optional namespace for scheduler storage.
|
|
@@ -15,7 +16,7 @@ import 'zod';
|
|
|
15
16
|
* @property autoStart When false, initializes without starting the scheduler.
|
|
16
17
|
*/
|
|
17
18
|
type SchedulerServiceOptions = {
|
|
18
|
-
|
|
19
|
+
toolStateStore: ToolStateStore;
|
|
19
20
|
logger: Logger;
|
|
20
21
|
config?: SchedulerToolsConfig;
|
|
21
22
|
storageNamespace?: string;
|
package/dist/service.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import type { Logger
|
|
1
|
+
import type { Logger } from '@dexto/core';
|
|
2
|
+
import type { ToolStateStore } from '@dexto/core/storage';
|
|
2
3
|
import { type SchedulerToolsConfig } from './schemas.js';
|
|
3
4
|
import type { ScheduleExecutorFn } from './types.js';
|
|
4
5
|
import { SchedulerManager } from './manager.js';
|
|
5
6
|
/**
|
|
6
7
|
* Options for constructing a scheduler service.
|
|
7
8
|
*
|
|
8
|
-
* @property
|
|
9
|
+
* @property toolStateStore Store used for scheduler persistence.
|
|
9
10
|
* @property logger Logger used by the scheduler manager.
|
|
10
11
|
* @property config Optional scheduler config. Defaults to `SchedulerToolsConfigSchema` when omitted.
|
|
11
12
|
* @property storageNamespace Optional namespace for scheduler storage.
|
|
@@ -13,7 +14,7 @@ import { SchedulerManager } from './manager.js';
|
|
|
13
14
|
* @property autoStart When false, initializes without starting the scheduler.
|
|
14
15
|
*/
|
|
15
16
|
export type SchedulerServiceOptions = {
|
|
16
|
-
|
|
17
|
+
toolStateStore: ToolStateStore;
|
|
17
18
|
logger: Logger;
|
|
18
19
|
config?: SchedulerToolsConfig;
|
|
19
20
|
storageNamespace?: string;
|
package/dist/service.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAA8B,KAAK,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD;;;;;;;;;GASG;AACH,MAAM,MAAM,uBAAuB,GAAG;IAClC,cAAc,EAAE,cAAc,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CACxC,OAAO,EAAE,uBAAuB,GACjC,OAAO,CAAC,gBAAgB,CAAC,CAyB3B"}
|
package/dist/service.js
CHANGED
|
@@ -3,7 +3,7 @@ import { SchedulerManager } from "./manager.js";
|
|
|
3
3
|
async function createSchedulerService(options) {
|
|
4
4
|
const resolvedConfig = options.config ?? SchedulerToolsConfigSchema.parse({ type: "scheduler-tools" });
|
|
5
5
|
const manager = new SchedulerManager(
|
|
6
|
-
options.
|
|
6
|
+
options.toolStateStore,
|
|
7
7
|
resolvedConfig,
|
|
8
8
|
options.logger,
|
|
9
9
|
options.storageNamespace ? { storageNamespace: options.storageNamespace } : void 0
|
package/dist/storage.cjs
CHANGED
|
@@ -23,9 +23,10 @@ __export(storage_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(storage_exports);
|
|
24
24
|
var import_errors = require("./errors.js");
|
|
25
25
|
const DEFAULT_SCHEDULER_NAMESPACE = "default";
|
|
26
|
+
const SCHEDULER_TOOL_STATE_NAME = "scheduler";
|
|
26
27
|
class ScheduleStorage {
|
|
27
|
-
constructor(
|
|
28
|
-
this.
|
|
28
|
+
constructor(toolStateStore, maxExecutionHistory, logger, namespace) {
|
|
29
|
+
this.toolStateStore = toolStateStore;
|
|
29
30
|
this.maxExecutionHistory = maxExecutionHistory;
|
|
30
31
|
this.logger = logger;
|
|
31
32
|
const ns = namespace && namespace.trim().length > 0 ? namespace.trim() : DEFAULT_SCHEDULER_NAMESPACE;
|
|
@@ -44,14 +45,14 @@ class ScheduleStorage {
|
|
|
44
45
|
const key = `${this.schedulePrefix}${schedule.id}`;
|
|
45
46
|
let persisted = false;
|
|
46
47
|
try {
|
|
47
|
-
await this.
|
|
48
|
+
await this.setState(key, schedule);
|
|
48
49
|
persisted = true;
|
|
49
50
|
await this.addScheduleToList(schedule.id);
|
|
50
51
|
this.logger.debug(`Schedule ${schedule.id} saved to storage`, { name: schedule.name });
|
|
51
52
|
} catch (error) {
|
|
52
53
|
if (persisted) {
|
|
53
54
|
try {
|
|
54
|
-
await this.
|
|
55
|
+
await this.deleteState(key);
|
|
55
56
|
} catch (cleanupError) {
|
|
56
57
|
this.logger.error(
|
|
57
58
|
`Failed to rollback schedule ${schedule.id} after list update failure: ${cleanupError instanceof Error ? cleanupError.message : String(cleanupError)}`
|
|
@@ -70,7 +71,7 @@ class ScheduleStorage {
|
|
|
70
71
|
async loadSchedule(scheduleId) {
|
|
71
72
|
try {
|
|
72
73
|
const key = `${this.schedulePrefix}${scheduleId}`;
|
|
73
|
-
const schedule = await this.
|
|
74
|
+
const schedule = await this.getState(key);
|
|
74
75
|
return schedule || null;
|
|
75
76
|
} catch (error) {
|
|
76
77
|
throw import_errors.SchedulerError.storageReadFailed(
|
|
@@ -84,7 +85,7 @@ class ScheduleStorage {
|
|
|
84
85
|
*/
|
|
85
86
|
async listSchedules() {
|
|
86
87
|
try {
|
|
87
|
-
const scheduleIds = await this.
|
|
88
|
+
const scheduleIds = await this.getState(this.scheduleListKey) || [];
|
|
88
89
|
const schedules = [];
|
|
89
90
|
for (const scheduleId of scheduleIds) {
|
|
90
91
|
const schedule = await this.loadSchedule(scheduleId);
|
|
@@ -110,7 +111,7 @@ class ScheduleStorage {
|
|
|
110
111
|
const key = `${this.schedulePrefix}${scheduleId}`;
|
|
111
112
|
await this.removeScheduleFromList(scheduleId);
|
|
112
113
|
removedFromList = true;
|
|
113
|
-
await this.
|
|
114
|
+
await this.deleteState(key);
|
|
114
115
|
deletedSchedule = true;
|
|
115
116
|
await this.deleteExecutionLogs(scheduleId);
|
|
116
117
|
this.logger.debug(`Schedule ${scheduleId} deleted from storage`);
|
|
@@ -136,7 +137,7 @@ class ScheduleStorage {
|
|
|
136
137
|
async saveExecutionLog(log) {
|
|
137
138
|
try {
|
|
138
139
|
const key = `${this.executionLogPrefix}${log.scheduleId}:${log.id}`;
|
|
139
|
-
await this.
|
|
140
|
+
await this.setState(key, log);
|
|
140
141
|
await this.pruneExecutionHistory(log.scheduleId);
|
|
141
142
|
this.logger.debug(`Execution log ${log.id} saved for schedule ${log.scheduleId}`, {
|
|
142
143
|
status: log.status
|
|
@@ -154,10 +155,10 @@ class ScheduleStorage {
|
|
|
154
155
|
async getExecutionLogs(scheduleId, limit) {
|
|
155
156
|
try {
|
|
156
157
|
const prefix = `${this.executionLogPrefix}${scheduleId}:`;
|
|
157
|
-
const keys = await this.
|
|
158
|
+
const keys = await this.listStateKeys(prefix);
|
|
158
159
|
const logs = [];
|
|
159
160
|
for (const key of keys) {
|
|
160
|
-
const log = await this.
|
|
161
|
+
const log = await this.getState(key);
|
|
161
162
|
if (log) {
|
|
162
163
|
logs.push(log);
|
|
163
164
|
}
|
|
@@ -177,9 +178,9 @@ class ScheduleStorage {
|
|
|
177
178
|
async deleteExecutionLogs(scheduleId) {
|
|
178
179
|
try {
|
|
179
180
|
const prefix = `${this.executionLogPrefix}${scheduleId}:`;
|
|
180
|
-
const keys = await this.
|
|
181
|
+
const keys = await this.listStateKeys(prefix);
|
|
181
182
|
for (const key of keys) {
|
|
182
|
-
await this.
|
|
183
|
+
await this.deleteState(key);
|
|
183
184
|
}
|
|
184
185
|
this.logger.debug(`Execution logs deleted for schedule ${scheduleId}`);
|
|
185
186
|
} catch (error) {
|
|
@@ -198,7 +199,7 @@ class ScheduleStorage {
|
|
|
198
199
|
const logsToDelete = logs.slice(this.maxExecutionHistory);
|
|
199
200
|
for (const log of logsToDelete) {
|
|
200
201
|
const key = `${this.executionLogPrefix}${scheduleId}:${log.id}`;
|
|
201
|
-
await this.
|
|
202
|
+
await this.deleteState(key);
|
|
202
203
|
}
|
|
203
204
|
this.logger.debug(
|
|
204
205
|
`Pruned ${logsToDelete.length} old execution logs for schedule ${scheduleId}`
|
|
@@ -215,10 +216,10 @@ class ScheduleStorage {
|
|
|
215
216
|
*/
|
|
216
217
|
async addScheduleToList(scheduleId) {
|
|
217
218
|
await this.withListLock(async () => {
|
|
218
|
-
const scheduleIds = await this.
|
|
219
|
+
const scheduleIds = await this.getState(this.scheduleListKey) || [];
|
|
219
220
|
if (!scheduleIds.includes(scheduleId)) {
|
|
220
221
|
scheduleIds.push(scheduleId);
|
|
221
|
-
await this.
|
|
222
|
+
await this.setState(this.scheduleListKey, scheduleIds);
|
|
222
223
|
}
|
|
223
224
|
});
|
|
224
225
|
}
|
|
@@ -227,9 +228,9 @@ class ScheduleStorage {
|
|
|
227
228
|
*/
|
|
228
229
|
async removeScheduleFromList(scheduleId) {
|
|
229
230
|
await this.withListLock(async () => {
|
|
230
|
-
const scheduleIds = await this.
|
|
231
|
+
const scheduleIds = await this.getState(this.scheduleListKey) || [];
|
|
231
232
|
const filtered = scheduleIds.filter((id) => id !== scheduleId);
|
|
232
|
-
await this.
|
|
233
|
+
await this.setState(this.scheduleListKey, filtered);
|
|
233
234
|
});
|
|
234
235
|
}
|
|
235
236
|
async withListLock(handler) {
|
|
@@ -247,6 +248,21 @@ class ScheduleStorage {
|
|
|
247
248
|
}
|
|
248
249
|
}
|
|
249
250
|
}
|
|
251
|
+
async getState(key) {
|
|
252
|
+
return await this.toolStateStore.get({ toolName: SCHEDULER_TOOL_STATE_NAME, key });
|
|
253
|
+
}
|
|
254
|
+
async setState(key, value) {
|
|
255
|
+
await this.toolStateStore.set({ toolName: SCHEDULER_TOOL_STATE_NAME, key, value });
|
|
256
|
+
}
|
|
257
|
+
async deleteState(key) {
|
|
258
|
+
await this.toolStateStore.delete({ toolName: SCHEDULER_TOOL_STATE_NAME, key });
|
|
259
|
+
}
|
|
260
|
+
async listStateKeys(prefix) {
|
|
261
|
+
return await this.toolStateStore.listKeys({
|
|
262
|
+
toolName: SCHEDULER_TOOL_STATE_NAME,
|
|
263
|
+
prefix
|
|
264
|
+
});
|
|
265
|
+
}
|
|
250
266
|
}
|
|
251
267
|
// Annotate the CommonJS export names for ESM import in node:
|
|
252
268
|
0 && (module.exports = {
|
package/dist/storage.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Logger } from '@dexto/core';
|
|
2
|
+
import { ToolStateStore } from '@dexto/core/storage';
|
|
2
3
|
import { Schedule, ExecutionLog } from './types.cjs';
|
|
3
4
|
import './schemas.cjs';
|
|
4
5
|
import 'zod';
|
|
@@ -11,14 +12,14 @@ import 'zod';
|
|
|
11
12
|
* Storage layer for scheduler persistence
|
|
12
13
|
*/
|
|
13
14
|
declare class ScheduleStorage {
|
|
14
|
-
private
|
|
15
|
+
private toolStateStore;
|
|
15
16
|
private maxExecutionHistory;
|
|
16
17
|
private logger;
|
|
17
18
|
private listLock;
|
|
18
19
|
private schedulePrefix;
|
|
19
20
|
private executionLogPrefix;
|
|
20
21
|
private scheduleListKey;
|
|
21
|
-
constructor(
|
|
22
|
+
constructor(toolStateStore: ToolStateStore, maxExecutionHistory: number, logger: Logger, namespace?: string);
|
|
22
23
|
/**
|
|
23
24
|
* Save a schedule to persistent storage
|
|
24
25
|
*/
|
|
@@ -60,6 +61,10 @@ declare class ScheduleStorage {
|
|
|
60
61
|
*/
|
|
61
62
|
private removeScheduleFromList;
|
|
62
63
|
private withListLock;
|
|
64
|
+
private getState;
|
|
65
|
+
private setState;
|
|
66
|
+
private deleteState;
|
|
67
|
+
private listStateKeys;
|
|
63
68
|
}
|
|
64
69
|
|
|
65
70
|
export { ScheduleStorage };
|
package/dist/storage.d.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Storage layer for schedules and execution logs
|
|
3
3
|
*/
|
|
4
|
-
import type {
|
|
4
|
+
import type { Logger } from '@dexto/core';
|
|
5
|
+
import type { ToolStateStore } from '@dexto/core/storage';
|
|
5
6
|
import type { Schedule, ExecutionLog } from './types.js';
|
|
6
7
|
/**
|
|
7
8
|
* Storage layer for scheduler persistence
|
|
8
9
|
*/
|
|
9
10
|
export declare class ScheduleStorage {
|
|
10
|
-
private
|
|
11
|
+
private toolStateStore;
|
|
11
12
|
private maxExecutionHistory;
|
|
12
13
|
private logger;
|
|
13
14
|
private listLock;
|
|
14
15
|
private schedulePrefix;
|
|
15
16
|
private executionLogPrefix;
|
|
16
17
|
private scheduleListKey;
|
|
17
|
-
constructor(
|
|
18
|
+
constructor(toolStateStore: ToolStateStore, maxExecutionHistory: number, logger: Logger, namespace?: string);
|
|
18
19
|
/**
|
|
19
20
|
* Save a schedule to persistent storage
|
|
20
21
|
*/
|
|
@@ -56,5 +57,9 @@ export declare class ScheduleStorage {
|
|
|
56
57
|
*/
|
|
57
58
|
private removeScheduleFromList;
|
|
58
59
|
private withListLock;
|
|
60
|
+
private getState;
|
|
61
|
+
private setState;
|
|
62
|
+
private deleteState;
|
|
63
|
+
private listStateKeys;
|
|
59
64
|
}
|
|
60
65
|
//# sourceMappingURL=storage.d.ts.map
|
package/dist/storage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAMzD;;GAEG;AACH,qBAAa,eAAe;IAOpB,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,mBAAmB;IAC3B,OAAO,CAAC,MAAM;IARlB,OAAO,CAAC,QAAQ,CAAoC;IACpD,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,eAAe,CAAS;gBAGpB,cAAc,EAAE,cAAc,EAC9B,mBAAmB,EAAE,MAAM,EAC3B,MAAM,EAAE,MAAM,EACtB,SAAS,CAAC,EAAE,MAAM;IAWtB;;OAEG;IACG,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IA4BrD;;OAEG;IACG,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAahE;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAuB1C;;OAEG;IACG,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAsCvD;;OAEG;IACG,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBxD;;OAEG;IACG,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IA2BnF;;OAEG;YACW,mBAAmB;IAkBjC;;OAEG;YACW,qBAAqB;IAyBnC;;OAEG;YACW,iBAAiB;IAW/B;;OAEG;YACW,sBAAsB;YAUtB,YAAY;YAkBZ,QAAQ;YAIR,QAAQ;YAIR,WAAW;YAIX,aAAa;CAM9B"}
|
package/dist/storage.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { SchedulerError } from "./errors.js";
|
|
2
2
|
const DEFAULT_SCHEDULER_NAMESPACE = "default";
|
|
3
|
+
const SCHEDULER_TOOL_STATE_NAME = "scheduler";
|
|
3
4
|
class ScheduleStorage {
|
|
4
|
-
constructor(
|
|
5
|
-
this.
|
|
5
|
+
constructor(toolStateStore, maxExecutionHistory, logger, namespace) {
|
|
6
|
+
this.toolStateStore = toolStateStore;
|
|
6
7
|
this.maxExecutionHistory = maxExecutionHistory;
|
|
7
8
|
this.logger = logger;
|
|
8
9
|
const ns = namespace && namespace.trim().length > 0 ? namespace.trim() : DEFAULT_SCHEDULER_NAMESPACE;
|
|
@@ -21,14 +22,14 @@ class ScheduleStorage {
|
|
|
21
22
|
const key = `${this.schedulePrefix}${schedule.id}`;
|
|
22
23
|
let persisted = false;
|
|
23
24
|
try {
|
|
24
|
-
await this.
|
|
25
|
+
await this.setState(key, schedule);
|
|
25
26
|
persisted = true;
|
|
26
27
|
await this.addScheduleToList(schedule.id);
|
|
27
28
|
this.logger.debug(`Schedule ${schedule.id} saved to storage`, { name: schedule.name });
|
|
28
29
|
} catch (error) {
|
|
29
30
|
if (persisted) {
|
|
30
31
|
try {
|
|
31
|
-
await this.
|
|
32
|
+
await this.deleteState(key);
|
|
32
33
|
} catch (cleanupError) {
|
|
33
34
|
this.logger.error(
|
|
34
35
|
`Failed to rollback schedule ${schedule.id} after list update failure: ${cleanupError instanceof Error ? cleanupError.message : String(cleanupError)}`
|
|
@@ -47,7 +48,7 @@ class ScheduleStorage {
|
|
|
47
48
|
async loadSchedule(scheduleId) {
|
|
48
49
|
try {
|
|
49
50
|
const key = `${this.schedulePrefix}${scheduleId}`;
|
|
50
|
-
const schedule = await this.
|
|
51
|
+
const schedule = await this.getState(key);
|
|
51
52
|
return schedule || null;
|
|
52
53
|
} catch (error) {
|
|
53
54
|
throw SchedulerError.storageReadFailed(
|
|
@@ -61,7 +62,7 @@ class ScheduleStorage {
|
|
|
61
62
|
*/
|
|
62
63
|
async listSchedules() {
|
|
63
64
|
try {
|
|
64
|
-
const scheduleIds = await this.
|
|
65
|
+
const scheduleIds = await this.getState(this.scheduleListKey) || [];
|
|
65
66
|
const schedules = [];
|
|
66
67
|
for (const scheduleId of scheduleIds) {
|
|
67
68
|
const schedule = await this.loadSchedule(scheduleId);
|
|
@@ -87,7 +88,7 @@ class ScheduleStorage {
|
|
|
87
88
|
const key = `${this.schedulePrefix}${scheduleId}`;
|
|
88
89
|
await this.removeScheduleFromList(scheduleId);
|
|
89
90
|
removedFromList = true;
|
|
90
|
-
await this.
|
|
91
|
+
await this.deleteState(key);
|
|
91
92
|
deletedSchedule = true;
|
|
92
93
|
await this.deleteExecutionLogs(scheduleId);
|
|
93
94
|
this.logger.debug(`Schedule ${scheduleId} deleted from storage`);
|
|
@@ -113,7 +114,7 @@ class ScheduleStorage {
|
|
|
113
114
|
async saveExecutionLog(log) {
|
|
114
115
|
try {
|
|
115
116
|
const key = `${this.executionLogPrefix}${log.scheduleId}:${log.id}`;
|
|
116
|
-
await this.
|
|
117
|
+
await this.setState(key, log);
|
|
117
118
|
await this.pruneExecutionHistory(log.scheduleId);
|
|
118
119
|
this.logger.debug(`Execution log ${log.id} saved for schedule ${log.scheduleId}`, {
|
|
119
120
|
status: log.status
|
|
@@ -131,10 +132,10 @@ class ScheduleStorage {
|
|
|
131
132
|
async getExecutionLogs(scheduleId, limit) {
|
|
132
133
|
try {
|
|
133
134
|
const prefix = `${this.executionLogPrefix}${scheduleId}:`;
|
|
134
|
-
const keys = await this.
|
|
135
|
+
const keys = await this.listStateKeys(prefix);
|
|
135
136
|
const logs = [];
|
|
136
137
|
for (const key of keys) {
|
|
137
|
-
const log = await this.
|
|
138
|
+
const log = await this.getState(key);
|
|
138
139
|
if (log) {
|
|
139
140
|
logs.push(log);
|
|
140
141
|
}
|
|
@@ -154,9 +155,9 @@ class ScheduleStorage {
|
|
|
154
155
|
async deleteExecutionLogs(scheduleId) {
|
|
155
156
|
try {
|
|
156
157
|
const prefix = `${this.executionLogPrefix}${scheduleId}:`;
|
|
157
|
-
const keys = await this.
|
|
158
|
+
const keys = await this.listStateKeys(prefix);
|
|
158
159
|
for (const key of keys) {
|
|
159
|
-
await this.
|
|
160
|
+
await this.deleteState(key);
|
|
160
161
|
}
|
|
161
162
|
this.logger.debug(`Execution logs deleted for schedule ${scheduleId}`);
|
|
162
163
|
} catch (error) {
|
|
@@ -175,7 +176,7 @@ class ScheduleStorage {
|
|
|
175
176
|
const logsToDelete = logs.slice(this.maxExecutionHistory);
|
|
176
177
|
for (const log of logsToDelete) {
|
|
177
178
|
const key = `${this.executionLogPrefix}${scheduleId}:${log.id}`;
|
|
178
|
-
await this.
|
|
179
|
+
await this.deleteState(key);
|
|
179
180
|
}
|
|
180
181
|
this.logger.debug(
|
|
181
182
|
`Pruned ${logsToDelete.length} old execution logs for schedule ${scheduleId}`
|
|
@@ -192,10 +193,10 @@ class ScheduleStorage {
|
|
|
192
193
|
*/
|
|
193
194
|
async addScheduleToList(scheduleId) {
|
|
194
195
|
await this.withListLock(async () => {
|
|
195
|
-
const scheduleIds = await this.
|
|
196
|
+
const scheduleIds = await this.getState(this.scheduleListKey) || [];
|
|
196
197
|
if (!scheduleIds.includes(scheduleId)) {
|
|
197
198
|
scheduleIds.push(scheduleId);
|
|
198
|
-
await this.
|
|
199
|
+
await this.setState(this.scheduleListKey, scheduleIds);
|
|
199
200
|
}
|
|
200
201
|
});
|
|
201
202
|
}
|
|
@@ -204,9 +205,9 @@ class ScheduleStorage {
|
|
|
204
205
|
*/
|
|
205
206
|
async removeScheduleFromList(scheduleId) {
|
|
206
207
|
await this.withListLock(async () => {
|
|
207
|
-
const scheduleIds = await this.
|
|
208
|
+
const scheduleIds = await this.getState(this.scheduleListKey) || [];
|
|
208
209
|
const filtered = scheduleIds.filter((id) => id !== scheduleId);
|
|
209
|
-
await this.
|
|
210
|
+
await this.setState(this.scheduleListKey, filtered);
|
|
210
211
|
});
|
|
211
212
|
}
|
|
212
213
|
async withListLock(handler) {
|
|
@@ -224,6 +225,21 @@ class ScheduleStorage {
|
|
|
224
225
|
}
|
|
225
226
|
}
|
|
226
227
|
}
|
|
228
|
+
async getState(key) {
|
|
229
|
+
return await this.toolStateStore.get({ toolName: SCHEDULER_TOOL_STATE_NAME, key });
|
|
230
|
+
}
|
|
231
|
+
async setState(key, value) {
|
|
232
|
+
await this.toolStateStore.set({ toolName: SCHEDULER_TOOL_STATE_NAME, key, value });
|
|
233
|
+
}
|
|
234
|
+
async deleteState(key) {
|
|
235
|
+
await this.toolStateStore.delete({ toolName: SCHEDULER_TOOL_STATE_NAME, key });
|
|
236
|
+
}
|
|
237
|
+
async listStateKeys(prefix) {
|
|
238
|
+
return await this.toolStateStore.listKeys({
|
|
239
|
+
toolName: SCHEDULER_TOOL_STATE_NAME,
|
|
240
|
+
prefix
|
|
241
|
+
});
|
|
242
|
+
}
|
|
227
243
|
}
|
|
228
244
|
export {
|
|
229
245
|
ScheduleStorage
|
package/dist/tool-provider.cjs
CHANGED
|
@@ -78,12 +78,12 @@ async function ensureSchedulerManagerForAgent(agent, config, loggerOverride) {
|
|
|
78
78
|
logger.debug("Using default scheduler config", { agentId });
|
|
79
79
|
}
|
|
80
80
|
const initPromise = (async () => {
|
|
81
|
-
const
|
|
82
|
-
if (!
|
|
81
|
+
const toolStateStore = agent.services?.stores.getStore("toolState");
|
|
82
|
+
if (!toolStateStore) {
|
|
83
83
|
throw import_errors.SchedulerError.missingStorage();
|
|
84
84
|
}
|
|
85
85
|
const logger = loggerOverride ?? agent.logger;
|
|
86
|
-
const manager = new import_manager.SchedulerManager(
|
|
86
|
+
const manager = new import_manager.SchedulerManager(toolStateStore, resolvedConfig, logger);
|
|
87
87
|
const waitForAgentStart = async () => {
|
|
88
88
|
if (!agent || typeof agent.isStarted !== "function") {
|
|
89
89
|
return true;
|
package/dist/tool-provider.d.cts
CHANGED
package/dist/tool-provider.js
CHANGED
|
@@ -50,12 +50,12 @@ async function ensureSchedulerManagerForAgent(agent, config, loggerOverride) {
|
|
|
50
50
|
logger.debug("Using default scheduler config", { agentId });
|
|
51
51
|
}
|
|
52
52
|
const initPromise = (async () => {
|
|
53
|
-
const
|
|
54
|
-
if (!
|
|
53
|
+
const toolStateStore = agent.services?.stores.getStore("toolState");
|
|
54
|
+
if (!toolStateStore) {
|
|
55
55
|
throw SchedulerError.missingStorage();
|
|
56
56
|
}
|
|
57
57
|
const logger = loggerOverride ?? agent.logger;
|
|
58
|
-
const manager = new SchedulerManager(
|
|
58
|
+
const manager = new SchedulerManager(toolStateStore, resolvedConfig, logger);
|
|
59
59
|
const waitForAgentStart = async () => {
|
|
60
60
|
if (!agent || typeof agent.isStarted !== "function") {
|
|
61
61
|
return true;
|
package/dist/tool-types.d.cts
CHANGED
package/dist/tools/index.d.cts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dexto/tools-scheduler",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Scheduler tools provider for Dexto agents - enables proactive task scheduling",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"cron-parser": "^4.9.0",
|
|
31
31
|
"node-cron": "^4.2.1",
|
|
32
32
|
"zod": "^4.3.6",
|
|
33
|
-
"@dexto/agent-config": "1.
|
|
34
|
-
"@dexto/core": "1.
|
|
33
|
+
"@dexto/agent-config": "1.8.0",
|
|
34
|
+
"@dexto/core": "1.8.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"tsup": "^8.0.0",
|