@okrlinkhub/agent-factory 3.0.0 → 3.0.2
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/client/index.d.ts +42 -14
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +68 -2
- package/dist/client/index.js.map +1 -1
- package/dist/component/_generated/api.d.ts +2 -0
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +114 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/lib.d.ts +2 -1
- package/dist/component/lib.d.ts.map +1 -1
- package/dist/component/lib.js +2 -1
- package/dist/component/lib.js.map +1 -1
- package/dist/component/messageTemplates.d.ts +37 -0
- package/dist/component/messageTemplates.d.ts.map +1 -0
- package/dist/component/messageTemplates.js +177 -0
- package/dist/component/messageTemplates.js.map +1 -0
- package/dist/component/pushing.d.ts +14 -14
- package/dist/component/queue.d.ts +33 -0
- package/dist/component/queue.d.ts.map +1 -1
- package/dist/component/queue.js +89 -2
- package/dist/component/queue.js.map +1 -1
- package/dist/component/scheduler.d.ts.map +1 -1
- package/dist/component/scheduler.js +37 -10
- package/dist/component/scheduler.js.map +1 -1
- package/dist/component/schema.d.ts +34 -8
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/schema.js +14 -0
- package/dist/component/schema.js.map +1 -1
- package/package.json +1 -1
- package/src/client/index.ts +69 -2
- package/src/component/_generated/api.ts +2 -0
- package/src/component/_generated/component.ts +158 -0
- package/src/component/lib.test.ts +216 -1
- package/src/component/lib.ts +8 -0
- package/src/component/messageTemplates.ts +205 -0
- package/src/component/queue.ts +110 -2
- package/src/component/scheduler.ts +77 -14
- package/src/component/schema.ts +15 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageTemplates.d.ts","sourceRoot":"","sources":["../../src/component/messageTemplates.ts"],"names":[],"mappings":"AAmFA,eAAO,MAAM,qBAAqB;;;;;;;kEA+BhC,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;oBAoChC,CAAC;AAEH,eAAO,MAAM,qBAAqB;;oBAWhC,CAAC;AAEH,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;KAqCxC,CAAC"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { mutation, query } from "./_generated/server.js";
|
|
3
|
+
const messageTemplateViewValidator = v.object({
|
|
4
|
+
_id: v.id("messageTemplates"),
|
|
5
|
+
templateKey: v.string(),
|
|
6
|
+
title: v.string(),
|
|
7
|
+
text: v.string(),
|
|
8
|
+
tags: v.array(v.string()),
|
|
9
|
+
usageCount: v.number(),
|
|
10
|
+
enabled: v.boolean(),
|
|
11
|
+
createdBy: v.string(),
|
|
12
|
+
updatedBy: v.string(),
|
|
13
|
+
createdAt: v.number(),
|
|
14
|
+
updatedAt: v.number(),
|
|
15
|
+
});
|
|
16
|
+
function normalizeTemplateKey(value) {
|
|
17
|
+
return value.trim().toLowerCase();
|
|
18
|
+
}
|
|
19
|
+
function buildTemplateKeyBase(title) {
|
|
20
|
+
const normalized = title
|
|
21
|
+
.trim()
|
|
22
|
+
.toLowerCase()
|
|
23
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
24
|
+
.replace(/^-+|-+$/g, "");
|
|
25
|
+
return normalized || "message-template";
|
|
26
|
+
}
|
|
27
|
+
function normalizeTitle(value) {
|
|
28
|
+
return value.trim();
|
|
29
|
+
}
|
|
30
|
+
function normalizeText(value) {
|
|
31
|
+
return value.trim();
|
|
32
|
+
}
|
|
33
|
+
function normalizeTags(tags) {
|
|
34
|
+
return Array.from(new Set(tags
|
|
35
|
+
.map((tag) => tag.trim().toLowerCase())
|
|
36
|
+
.filter((tag) => tag.length > 0))).sort((left, right) => left.localeCompare(right));
|
|
37
|
+
}
|
|
38
|
+
function validateMessageTemplateFields(input) {
|
|
39
|
+
if (input.title !== undefined && input.title.length === 0) {
|
|
40
|
+
throw new Error("Template title is required");
|
|
41
|
+
}
|
|
42
|
+
if (input.text !== undefined && input.text.length === 0) {
|
|
43
|
+
throw new Error("Template text is required");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function resolveUniqueTemplateKey(ctx, title, currentTemplateId) {
|
|
47
|
+
const baseKey = buildTemplateKeyBase(title);
|
|
48
|
+
let candidate = baseKey;
|
|
49
|
+
let suffix = 2;
|
|
50
|
+
while (true) {
|
|
51
|
+
const existing = await ctx.db
|
|
52
|
+
.query("messageTemplates")
|
|
53
|
+
.withIndex("by_templateKey", (q) => q.eq("templateKey", candidate))
|
|
54
|
+
.unique();
|
|
55
|
+
if (!existing || String(existing._id) === currentTemplateId) {
|
|
56
|
+
return candidate;
|
|
57
|
+
}
|
|
58
|
+
candidate = `${baseKey}-${suffix}`;
|
|
59
|
+
suffix += 1;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export const createMessageTemplate = mutation({
|
|
63
|
+
args: {
|
|
64
|
+
title: v.string(),
|
|
65
|
+
text: v.string(),
|
|
66
|
+
tags: v.array(v.string()),
|
|
67
|
+
enabled: v.optional(v.boolean()),
|
|
68
|
+
actorUserId: v.string(),
|
|
69
|
+
nowMs: v.optional(v.number()),
|
|
70
|
+
},
|
|
71
|
+
returns: v.id("messageTemplates"),
|
|
72
|
+
handler: async (ctx, args) => {
|
|
73
|
+
const title = normalizeTitle(args.title);
|
|
74
|
+
const text = normalizeText(args.text);
|
|
75
|
+
const tags = normalizeTags(args.tags);
|
|
76
|
+
validateMessageTemplateFields({ title, text });
|
|
77
|
+
const templateKey = normalizeTemplateKey(await resolveUniqueTemplateKey(ctx, title));
|
|
78
|
+
const nowMs = args.nowMs ?? Date.now();
|
|
79
|
+
return await ctx.db.insert("messageTemplates", {
|
|
80
|
+
templateKey,
|
|
81
|
+
title,
|
|
82
|
+
text,
|
|
83
|
+
tags,
|
|
84
|
+
usageCount: 0,
|
|
85
|
+
enabled: args.enabled ?? true,
|
|
86
|
+
createdBy: args.actorUserId,
|
|
87
|
+
updatedBy: args.actorUserId,
|
|
88
|
+
createdAt: nowMs,
|
|
89
|
+
updatedAt: nowMs,
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
export const updateMessageTemplate = mutation({
|
|
94
|
+
args: {
|
|
95
|
+
templateId: v.id("messageTemplates"),
|
|
96
|
+
title: v.optional(v.string()),
|
|
97
|
+
text: v.optional(v.string()),
|
|
98
|
+
tags: v.optional(v.array(v.string())),
|
|
99
|
+
enabled: v.optional(v.boolean()),
|
|
100
|
+
actorUserId: v.string(),
|
|
101
|
+
nowMs: v.optional(v.number()),
|
|
102
|
+
},
|
|
103
|
+
returns: v.boolean(),
|
|
104
|
+
handler: async (ctx, args) => {
|
|
105
|
+
const template = await ctx.db.get(args.templateId);
|
|
106
|
+
if (!template)
|
|
107
|
+
return false;
|
|
108
|
+
const title = args.title !== undefined ? normalizeTitle(args.title) : template.title;
|
|
109
|
+
const text = args.text !== undefined ? normalizeText(args.text) : template.text;
|
|
110
|
+
const tags = args.tags !== undefined ? normalizeTags(args.tags) : template.tags;
|
|
111
|
+
validateMessageTemplateFields({ title, text });
|
|
112
|
+
const templateKey = title !== template.title
|
|
113
|
+
? normalizeTemplateKey(await resolveUniqueTemplateKey(ctx, title, String(template._id)))
|
|
114
|
+
: template.templateKey;
|
|
115
|
+
const nowMs = args.nowMs ?? Date.now();
|
|
116
|
+
await ctx.db.patch(template._id, {
|
|
117
|
+
templateKey,
|
|
118
|
+
title,
|
|
119
|
+
text,
|
|
120
|
+
tags,
|
|
121
|
+
enabled: args.enabled ?? template.enabled,
|
|
122
|
+
updatedBy: args.actorUserId,
|
|
123
|
+
updatedAt: nowMs,
|
|
124
|
+
});
|
|
125
|
+
return true;
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
export const deleteMessageTemplate = mutation({
|
|
129
|
+
args: {
|
|
130
|
+
templateId: v.id("messageTemplates"),
|
|
131
|
+
},
|
|
132
|
+
returns: v.boolean(),
|
|
133
|
+
handler: async (ctx, args) => {
|
|
134
|
+
const template = await ctx.db.get(args.templateId);
|
|
135
|
+
if (!template)
|
|
136
|
+
return false;
|
|
137
|
+
await ctx.db.delete(template._id);
|
|
138
|
+
return true;
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
export const listMessageTemplatesByCompany = query({
|
|
142
|
+
args: {
|
|
143
|
+
includeDisabled: v.optional(v.boolean()),
|
|
144
|
+
limit: v.optional(v.number()),
|
|
145
|
+
},
|
|
146
|
+
returns: v.array(messageTemplateViewValidator),
|
|
147
|
+
handler: async (ctx, args) => {
|
|
148
|
+
const includeDisabled = args.includeDisabled ?? false;
|
|
149
|
+
const limit = Math.max(1, Math.min(args.limit ?? 100, 200));
|
|
150
|
+
const rows = includeDisabled
|
|
151
|
+
? await ctx.db.query("messageTemplates").take(limit)
|
|
152
|
+
: await ctx.db
|
|
153
|
+
.query("messageTemplates")
|
|
154
|
+
.withIndex("by_enabled", (q) => q.eq("enabled", true))
|
|
155
|
+
.take(limit);
|
|
156
|
+
rows.sort((left, right) => {
|
|
157
|
+
if (right.usageCount !== left.usageCount) {
|
|
158
|
+
return right.usageCount - left.usageCount;
|
|
159
|
+
}
|
|
160
|
+
return right.updatedAt - left.updatedAt;
|
|
161
|
+
});
|
|
162
|
+
return rows.map((row) => ({
|
|
163
|
+
_id: row._id,
|
|
164
|
+
templateKey: row.templateKey,
|
|
165
|
+
title: row.title,
|
|
166
|
+
text: row.text,
|
|
167
|
+
tags: row.tags,
|
|
168
|
+
usageCount: row.usageCount,
|
|
169
|
+
enabled: row.enabled,
|
|
170
|
+
createdBy: row.createdBy,
|
|
171
|
+
updatedBy: row.updatedBy,
|
|
172
|
+
createdAt: row.createdAt,
|
|
173
|
+
updatedAt: row.updatedAt,
|
|
174
|
+
}));
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
//# sourceMappingURL=messageTemplates.js.map
|
|
@@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AC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;iBACrD,IAAI,CAAC,KAAK,CAAC,CAAC;QAEnB,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YACxB,IAAI,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU,EAAE,CAAC;gBACzC,OAAO,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;YAC5C,CAAC;YACD,OAAO,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAC1C,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACxB,GAAG,EAAE,GAAG,CAAC,GAAG;YACZ,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,UAAU,EAAE,GAAG,CAAC,UAAU;YAC1B,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,SAAS,EAAE,GAAG,CAAC,SAAS;SACzB,CAAC,CAAC,CAAC;IACN,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -2,11 +2,11 @@ import type { Id } from "./_generated/dataModel.js";
|
|
|
2
2
|
export declare const createPushTemplate: import("convex/server").RegisteredMutation<"public", {
|
|
3
3
|
nowMs?: number | undefined;
|
|
4
4
|
enabled?: boolean | undefined;
|
|
5
|
-
|
|
6
|
-
periodicity: "manual" | "daily" | "weekly" | "monthly";
|
|
5
|
+
actorUserId: string;
|
|
7
6
|
text: string;
|
|
8
7
|
title: string;
|
|
9
|
-
|
|
8
|
+
companyId: string;
|
|
9
|
+
periodicity: "manual" | "daily" | "weekly" | "monthly";
|
|
10
10
|
suggestedTimes: ({
|
|
11
11
|
kind: "daily";
|
|
12
12
|
time: string;
|
|
@@ -24,9 +24,9 @@ export declare const createPushTemplate: import("convex/server").RegisteredMutat
|
|
|
24
24
|
export declare const updatePushTemplate: import("convex/server").RegisteredMutation<"public", {
|
|
25
25
|
nowMs?: number | undefined;
|
|
26
26
|
enabled?: boolean | undefined;
|
|
27
|
-
periodicity?: "manual" | "daily" | "weekly" | "monthly" | undefined;
|
|
28
27
|
text?: string | undefined;
|
|
29
28
|
title?: string | undefined;
|
|
29
|
+
periodicity?: "manual" | "daily" | "weekly" | "monthly" | undefined;
|
|
30
30
|
suggestedTimes?: ({
|
|
31
31
|
kind: "daily";
|
|
32
32
|
time: string;
|
|
@@ -39,8 +39,8 @@ export declare const updatePushTemplate: import("convex/server").RegisteredMutat
|
|
|
39
39
|
time: string;
|
|
40
40
|
dayOfMonth: number | "last";
|
|
41
41
|
})[] | undefined;
|
|
42
|
-
templateId: import("convex/values").GenericId<"messagePushTemplates">;
|
|
43
42
|
actorUserId: string;
|
|
43
|
+
templateId: import("convex/values").GenericId<"messagePushTemplates">;
|
|
44
44
|
}, Promise<boolean>>;
|
|
45
45
|
export declare const deletePushTemplate: import("convex/server").RegisteredMutation<"public", {
|
|
46
46
|
templateId: import("convex/values").GenericId<"messagePushTemplates">;
|
|
@@ -99,6 +99,8 @@ export declare const createPushJobCustom: import("convex/server").RegisteredMuta
|
|
|
99
99
|
nowMs?: number | undefined;
|
|
100
100
|
enabled?: boolean | undefined;
|
|
101
101
|
consumerUserId: string;
|
|
102
|
+
text: string;
|
|
103
|
+
title: string;
|
|
102
104
|
companyId: string;
|
|
103
105
|
periodicity: "manual" | "daily" | "weekly" | "monthly";
|
|
104
106
|
schedule: {
|
|
@@ -115,13 +117,13 @@ export declare const createPushJobCustom: import("convex/server").RegisteredMuta
|
|
|
115
117
|
time: string;
|
|
116
118
|
dayOfMonth: number | "last";
|
|
117
119
|
};
|
|
118
|
-
text: string;
|
|
119
120
|
timezone: string;
|
|
120
|
-
title: string;
|
|
121
121
|
}, Promise<import("convex/values").GenericId<"messagePushJobs">>>;
|
|
122
122
|
export declare const updatePushJob: import("convex/server").RegisteredMutation<"public", {
|
|
123
123
|
nowMs?: number | undefined;
|
|
124
124
|
enabled?: boolean | undefined;
|
|
125
|
+
text?: string | undefined;
|
|
126
|
+
title?: string | undefined;
|
|
125
127
|
periodicity?: "manual" | "daily" | "weekly" | "monthly" | undefined;
|
|
126
128
|
schedule?: {
|
|
127
129
|
kind: "manual";
|
|
@@ -137,9 +139,7 @@ export declare const updatePushJob: import("convex/server").RegisteredMutation<"
|
|
|
137
139
|
time: string;
|
|
138
140
|
dayOfMonth: number | "last";
|
|
139
141
|
} | undefined;
|
|
140
|
-
text?: string | undefined;
|
|
141
142
|
timezone?: string | undefined;
|
|
142
|
-
title?: string | undefined;
|
|
143
143
|
jobId: import("convex/values").GenericId<"messagePushJobs">;
|
|
144
144
|
}, Promise<boolean>>;
|
|
145
145
|
export declare const deletePushJob: import("convex/server").RegisteredMutation<"public", {
|
|
@@ -232,9 +232,9 @@ export declare const sendBroadcastToAllActiveAgents: import("convex/server").Reg
|
|
|
232
232
|
volumePath: string;
|
|
233
233
|
volumeSizeGb: number;
|
|
234
234
|
} | undefined;
|
|
235
|
-
companyId: string;
|
|
236
235
|
text: string;
|
|
237
236
|
title: string;
|
|
237
|
+
companyId: string;
|
|
238
238
|
requestedBy: string;
|
|
239
239
|
}, Promise<{
|
|
240
240
|
broadcastId: import("convex/values").GenericId<"messagePushBroadcasts">;
|
|
@@ -316,6 +316,8 @@ export declare const createPushJobCustomForAgent: import("convex/server").Regist
|
|
|
316
316
|
enabled?: boolean | undefined;
|
|
317
317
|
agentKey: string;
|
|
318
318
|
consumerUserId: string;
|
|
319
|
+
text: string;
|
|
320
|
+
title: string;
|
|
319
321
|
companyId: string;
|
|
320
322
|
periodicity: "manual" | "daily" | "weekly" | "monthly";
|
|
321
323
|
schedule: {
|
|
@@ -332,13 +334,13 @@ export declare const createPushJobCustomForAgent: import("convex/server").Regist
|
|
|
332
334
|
time: string;
|
|
333
335
|
dayOfMonth: number | "last";
|
|
334
336
|
};
|
|
335
|
-
text: string;
|
|
336
337
|
timezone: string;
|
|
337
|
-
title: string;
|
|
338
338
|
}, Promise<import("convex/values").GenericId<"messagePushJobs">>>;
|
|
339
339
|
export declare const updatePushJobForAgent: import("convex/server").RegisteredMutation<"public", {
|
|
340
340
|
nowMs?: number | undefined;
|
|
341
341
|
enabled?: boolean | undefined;
|
|
342
|
+
text?: string | undefined;
|
|
343
|
+
title?: string | undefined;
|
|
342
344
|
periodicity?: "manual" | "daily" | "weekly" | "monthly" | undefined;
|
|
343
345
|
schedule?: {
|
|
344
346
|
kind: "manual";
|
|
@@ -354,9 +356,7 @@ export declare const updatePushJobForAgent: import("convex/server").RegisteredMu
|
|
|
354
356
|
time: string;
|
|
355
357
|
dayOfMonth: number | "last";
|
|
356
358
|
} | undefined;
|
|
357
|
-
text?: string | undefined;
|
|
358
359
|
timezone?: string | undefined;
|
|
359
|
-
title?: string | undefined;
|
|
360
360
|
agentKey: string;
|
|
361
361
|
consumerUserId: string;
|
|
362
362
|
jobId: import("convex/values").GenericId<"messagePushJobs">;
|
|
@@ -98,6 +98,13 @@ export declare const getWorkerSpawnOpenClawEnv: import("convex/server").Register
|
|
|
98
98
|
OPENCLAW_SERVICE_KEY?: string;
|
|
99
99
|
OPENCLAW_LINKING_SHARED_SECRET?: string;
|
|
100
100
|
}>>;
|
|
101
|
+
export declare const getActiveConversationsForScheduler: import("convex/server").RegisteredQuery<"internal", {
|
|
102
|
+
nowMs?: number | undefined;
|
|
103
|
+
limit?: number | undefined;
|
|
104
|
+
}, Promise<{
|
|
105
|
+
conversationId: string;
|
|
106
|
+
agentKey: string;
|
|
107
|
+
}[]>>;
|
|
101
108
|
export declare const getProviderRuntimeConfig: import("convex/server").RegisteredQuery<"internal", {}, Promise<{
|
|
102
109
|
appName: string;
|
|
103
110
|
kind: "fly" | "runpod" | "ecs";
|
|
@@ -564,6 +571,26 @@ export declare const sendMessageToUserAgent: import("convex/server").RegisteredM
|
|
|
564
571
|
consumerUserId: string;
|
|
565
572
|
content: string;
|
|
566
573
|
}, Promise<import("convex/values").GenericId<"messageQueue">>>;
|
|
574
|
+
export declare const sendMessageTemplateToUserAgent: import("convex/server").RegisteredMutation<"public", {
|
|
575
|
+
metadata?: Record<string, string> | undefined;
|
|
576
|
+
nowMs?: number | undefined;
|
|
577
|
+
providerConfig?: {
|
|
578
|
+
appName: string;
|
|
579
|
+
kind: "fly" | "runpod" | "ecs";
|
|
580
|
+
organizationSlug: string;
|
|
581
|
+
image: string;
|
|
582
|
+
region: string;
|
|
583
|
+
volumeName: string;
|
|
584
|
+
volumePath: string;
|
|
585
|
+
volumeSizeGb: number;
|
|
586
|
+
} | undefined;
|
|
587
|
+
agentKey: string;
|
|
588
|
+
consumerUserId: string;
|
|
589
|
+
templateId: import("convex/values").GenericId<"messageTemplates">;
|
|
590
|
+
}, Promise<{
|
|
591
|
+
messageId: import("convex/values").GenericId<"messageQueue">;
|
|
592
|
+
usageCount: number;
|
|
593
|
+
}>>;
|
|
567
594
|
export declare const listSnapshotsForConversation: import("convex/server").RegisteredQuery<"public", {
|
|
568
595
|
nowMs?: number | undefined;
|
|
569
596
|
limit?: number | undefined;
|
|
@@ -638,6 +665,12 @@ export declare const upsertWorkerState: import("convex/server").RegisteredMutati
|
|
|
638
665
|
machineId?: string | undefined;
|
|
639
666
|
scheduledShutdownAt?: number | undefined;
|
|
640
667
|
stoppedAt?: number | undefined;
|
|
668
|
+
assignment?: {
|
|
669
|
+
agentKey: string;
|
|
670
|
+
conversationId: string;
|
|
671
|
+
leaseId: string;
|
|
672
|
+
assignedAt: number;
|
|
673
|
+
} | null | undefined;
|
|
641
674
|
clearLastSnapshotId?: boolean | undefined;
|
|
642
675
|
clearMachineRef?: boolean | undefined;
|
|
643
676
|
status: "active" | "draining" | "stopping" | "stopped";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../src/component/queue.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../src/component/queue.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,2BAA2B,CAAC;AA0OpD,KAAK,0BAA0B,GAAG;IAChC,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,UAAU,CAAC;IACzD,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8DAezB,CAAC;AAEH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;GAiErC,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;+DAyB7B,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;GA6ChC,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;eAOZ,MAAM;eACN,OAAO;aACT,MAAM,GAAG,IAAI;KAiB1B,CAAC;AAEH,eAAO,MAAM,wBAAwB;;0BAiBnC,CAAC;AAEH,eAAO,MAAM,yBAAyB;0BAkBV,MAAM;2BACL,MAAM;qCACI,MAAM;GAa3C,CAAC;AAEH,eAAO,MAAM,kCAAkC;;;;oBAsBa,MAAM;cAAY,MAAM;KAiBlF,CAAC;AAEH,eAA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;AAEH,eAAO,MAAM,sBAAsB;;;mBAoBjC,CAAC;AAEH,eAAO,MAAM,4BAA4B;;;mBAyCvC,CAAC;AAEH,eAAO,MAAM,cAAc;;;;;;;;;;;GAsCzB,CAAC"}
|
package/dist/component/queue.js
CHANGED
|
@@ -121,6 +121,10 @@ const workerSpawnOpenClawEnvValidator = v.object({
|
|
|
121
121
|
OPENCLAW_SERVICE_KEY: v.optional(v.string()),
|
|
122
122
|
OPENCLAW_LINKING_SHARED_SECRET: v.optional(v.string()),
|
|
123
123
|
});
|
|
124
|
+
const schedulerConversationTargetValidator = v.object({
|
|
125
|
+
conversationId: v.string(),
|
|
126
|
+
agentKey: v.string(),
|
|
127
|
+
});
|
|
124
128
|
const messageRuntimeConfigValidator = v.object({
|
|
125
129
|
systemPrompt: v.optional(v.string()),
|
|
126
130
|
telegramAttachmentRetentionMs: v.optional(v.number()),
|
|
@@ -361,6 +365,37 @@ export const getWorkerSpawnOpenClawEnv = internalQuery({
|
|
|
361
365
|
return env;
|
|
362
366
|
},
|
|
363
367
|
});
|
|
368
|
+
export const getActiveConversationsForScheduler = internalQuery({
|
|
369
|
+
args: {
|
|
370
|
+
nowMs: v.optional(v.number()),
|
|
371
|
+
limit: v.optional(v.number()),
|
|
372
|
+
},
|
|
373
|
+
returns: v.array(schedulerConversationTargetValidator),
|
|
374
|
+
handler: async (ctx, args) => {
|
|
375
|
+
const nowMs = args.nowMs ?? Date.now();
|
|
376
|
+
const limit = Math.max(1, args.limit ?? 1000);
|
|
377
|
+
const queuedJobs = await ctx.db
|
|
378
|
+
.query("messageQueue")
|
|
379
|
+
.withIndex("by_status_and_scheduledFor", (q) => q.eq("status", "queued").lte("scheduledFor", nowMs))
|
|
380
|
+
.take(limit);
|
|
381
|
+
const processingJobs = await ctx.db
|
|
382
|
+
.query("messageQueue")
|
|
383
|
+
.withIndex("by_status_and_leaseExpiresAt", (q) => q.eq("status", "processing").gt("leaseExpiresAt", nowMs))
|
|
384
|
+
.take(limit);
|
|
385
|
+
const conversations = new Map();
|
|
386
|
+
for (const job of [...queuedJobs, ...processingJobs]) {
|
|
387
|
+
const key = `${job.agentKey}::${job.conversationId}`;
|
|
388
|
+
if (!conversations.has(key)) {
|
|
389
|
+
conversations.set(key, {
|
|
390
|
+
conversationId: job.conversationId,
|
|
391
|
+
agentKey: job.agentKey,
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return Array.from(conversations.values()).sort((left, right) => left.agentKey.localeCompare(right.agentKey) ||
|
|
396
|
+
left.conversationId.localeCompare(right.conversationId));
|
|
397
|
+
},
|
|
398
|
+
});
|
|
364
399
|
export const getProviderRuntimeConfig = internalQuery({
|
|
365
400
|
args: {},
|
|
366
401
|
returns: v.union(v.null(), providerConfigValidator),
|
|
@@ -1640,6 +1675,57 @@ export const sendMessageToUserAgent = mutation({
|
|
|
1640
1675
|
});
|
|
1641
1676
|
},
|
|
1642
1677
|
});
|
|
1678
|
+
export const sendMessageTemplateToUserAgent = mutation({
|
|
1679
|
+
args: {
|
|
1680
|
+
consumerUserId: v.string(),
|
|
1681
|
+
agentKey: v.string(),
|
|
1682
|
+
templateId: v.id("messageTemplates"),
|
|
1683
|
+
metadata: v.optional(v.record(v.string(), v.string())),
|
|
1684
|
+
nowMs: v.optional(v.number()),
|
|
1685
|
+
providerConfig: v.optional(providerConfigValidator),
|
|
1686
|
+
},
|
|
1687
|
+
returns: v.object({
|
|
1688
|
+
messageId: v.id("messageQueue"),
|
|
1689
|
+
usageCount: v.number(),
|
|
1690
|
+
}),
|
|
1691
|
+
handler: async (ctx, args) => {
|
|
1692
|
+
const template = await ctx.db.get(args.templateId);
|
|
1693
|
+
if (!template || !template.enabled) {
|
|
1694
|
+
throw new Error("Message template not found");
|
|
1695
|
+
}
|
|
1696
|
+
const nowMs = args.nowMs ?? Date.now();
|
|
1697
|
+
const target = await resolveConversationTargetForUserAgent(ctx, args.consumerUserId, args.agentKey, true);
|
|
1698
|
+
const providerUserId = target.telegramUserId ?? target.telegramChatId ?? args.consumerUserId;
|
|
1699
|
+
const usageCount = template.usageCount + 1;
|
|
1700
|
+
const messageId = await enqueueMessageRecord(ctx, {
|
|
1701
|
+
conversationId: target.conversationId,
|
|
1702
|
+
agentKey: args.agentKey,
|
|
1703
|
+
payload: {
|
|
1704
|
+
provider: target.provider,
|
|
1705
|
+
providerUserId,
|
|
1706
|
+
messageText: template.text,
|
|
1707
|
+
metadata: {
|
|
1708
|
+
...(args.metadata ?? {}),
|
|
1709
|
+
consumerUserId: args.consumerUserId,
|
|
1710
|
+
source: "message_template",
|
|
1711
|
+
templateId: String(template._id),
|
|
1712
|
+
templateKey: template.templateKey,
|
|
1713
|
+
...(target.telegramChatId ? { telegramChatId: target.telegramChatId } : {}),
|
|
1714
|
+
...(target.telegramUserId ? { telegramUserId: target.telegramUserId } : {}),
|
|
1715
|
+
},
|
|
1716
|
+
},
|
|
1717
|
+
scheduledFor: nowMs,
|
|
1718
|
+
providerConfig: args.providerConfig,
|
|
1719
|
+
});
|
|
1720
|
+
await ctx.db.patch(template._id, {
|
|
1721
|
+
usageCount,
|
|
1722
|
+
});
|
|
1723
|
+
return {
|
|
1724
|
+
messageId,
|
|
1725
|
+
usageCount,
|
|
1726
|
+
};
|
|
1727
|
+
},
|
|
1728
|
+
});
|
|
1643
1729
|
export const listSnapshotsForConversation = query({
|
|
1644
1730
|
args: {
|
|
1645
1731
|
conversationId: v.string(),
|
|
@@ -1816,6 +1902,7 @@ export const upsertWorkerState = internalMutation({
|
|
|
1816
1902
|
machineId: v.optional(v.string()),
|
|
1817
1903
|
appName: v.optional(v.string()),
|
|
1818
1904
|
region: v.optional(v.string()),
|
|
1905
|
+
assignment: v.optional(v.union(v.null(), workerAssignmentValidator)),
|
|
1819
1906
|
clearLastSnapshotId: v.optional(v.boolean()),
|
|
1820
1907
|
clearMachineRef: v.optional(v.boolean()),
|
|
1821
1908
|
},
|
|
@@ -1837,7 +1924,7 @@ export const upsertWorkerState = internalMutation({
|
|
|
1837
1924
|
stoppedAt: args.status === "stopped" || args.status === "stopping"
|
|
1838
1925
|
? (args.stoppedAt ?? nowMs)
|
|
1839
1926
|
: undefined,
|
|
1840
|
-
assignment: undefined,
|
|
1927
|
+
assignment: args.assignment ?? undefined,
|
|
1841
1928
|
machineRef: args.machineId && args.appName
|
|
1842
1929
|
? {
|
|
1843
1930
|
appName: args.appName,
|
|
@@ -1861,7 +1948,7 @@ export const upsertWorkerState = internalMutation({
|
|
|
1861
1948
|
? (args.stoppedAt ?? worker.stoppedAt ?? nowMs)
|
|
1862
1949
|
: undefined,
|
|
1863
1950
|
lastSnapshotId: args.clearLastSnapshotId ? undefined : worker.lastSnapshotId,
|
|
1864
|
-
assignment: worker.assignment,
|
|
1951
|
+
assignment: args.assignment === undefined ? worker.assignment : (args.assignment ?? undefined),
|
|
1865
1952
|
machineRef: args.clearMachineRef
|
|
1866
1953
|
? undefined
|
|
1867
1954
|
: args.machineId && args.appName
|