@teammy/server 0.2.10 → 0.2.12
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/main.js +551 -193
- package/dist/web/assets/Assistant-ZybseeC1.js +1 -0
- package/dist/web/assets/Computers-C645Mo7u.js +7 -0
- package/dist/web/assets/Computers-Ka8Efp9g.css +1 -0
- package/dist/web/assets/{Conversation-DiVjLVVt.js → Conversation-CUq1BIEY.js} +1 -1
- package/dist/web/assets/{Dashboard-C6M9c0SB.js → Dashboard-BC_H8n8e.js} +1 -1
- package/dist/web/assets/Dropdown-CwdAxWUl.js +55 -0
- package/dist/web/assets/Files-C3RODJPo.js +1 -0
- package/dist/web/assets/{Help-CDOqVRjJ.js → Help-tCApEn5T.js} +81 -45
- package/dist/web/assets/{HtmlPreview-BzvYKdju.js → HtmlPreview-BV0uMzl4.js} +1 -1
- package/dist/web/assets/{Markdown-zJQlHcvy.js → Markdown-CEXsFsOc.js} +4 -4
- package/dist/web/assets/MessageComposer-B81qPPy8.js +1 -0
- package/dist/web/assets/MessageComposer-hKEluJsT.css +1 -0
- package/dist/web/assets/ResourceLibrary-CC1mv2Bd.js +6 -0
- package/dist/web/assets/{TerminalPane-GU69G9Ak.js → TerminalPane-MtqNIaf5.js} +2 -2
- package/dist/web/assets/WorkspaceTree-DHRS8tWc.js +1 -0
- package/dist/web/assets/{file-links-V3R--z0b.js → file-links-Cd3KZGrF.js} +1 -1
- package/dist/web/assets/index-Ba19LzDv.js +10 -0
- package/dist/web/assets/index-DaHHMNVC.css +1 -0
- package/dist/web/downloads/teammy-inbox-skill.zip +0 -0
- package/dist/web/downloads/teammy-skill.zip +0 -0
- package/dist/web/index.html +3 -3
- package/package.json +1 -1
- package/dist/web/assets/Assistant-C9Zo5FN_.js +0 -1
- package/dist/web/assets/Computers-DNIWiHu4.js +0 -5
- package/dist/web/assets/Computers-XUdWIkZr.css +0 -1
- package/dist/web/assets/Dropdown-BnYLBw2s.js +0 -55
- package/dist/web/assets/Files-CQcAEYH9.js +0 -1
- package/dist/web/assets/MessageComposer-CBI6RiJq.js +0 -1
- package/dist/web/assets/MessageComposer-CJGxkvML.css +0 -1
- package/dist/web/assets/ResourceLibrary-CEFCe7QW.js +0 -6
- package/dist/web/assets/WorkspaceTree-BhDZe1go.js +0 -1
- package/dist/web/assets/index-D9m13C7l.js +0 -12
- package/dist/web/assets/index-qX1GRw9I.css +0 -1
package/dist/main.js
CHANGED
|
@@ -347,6 +347,7 @@ var LocalSessionSchema = z5.object({
|
|
|
347
347
|
member: z5.string(),
|
|
348
348
|
title: z5.string(),
|
|
349
349
|
pinned: z5.boolean().default(false),
|
|
350
|
+
hidden: z5.boolean().default(false),
|
|
350
351
|
metadataRevision: z5.number().int().default(1),
|
|
351
352
|
revision: z5.number().int(),
|
|
352
353
|
config: SessionConfigSchema,
|
|
@@ -373,8 +374,15 @@ var SessionCommandKindSchema = z5.enum([
|
|
|
373
374
|
"queue-edit",
|
|
374
375
|
"queue-cancel",
|
|
375
376
|
"diff",
|
|
376
|
-
"history"
|
|
377
|
+
"history",
|
|
378
|
+
"rewind"
|
|
377
379
|
]);
|
|
380
|
+
var SessionRewindSchema = z5.object({
|
|
381
|
+
messageId: z5.string().min(1),
|
|
382
|
+
body: z5.string().trim().min(1).max(2e5),
|
|
383
|
+
expectedLastMessage: z5.string().min(1)
|
|
384
|
+
});
|
|
385
|
+
var SessionRewindResultSchema = z5.object({ nativeSession: z5.string().min(1) });
|
|
378
386
|
var QueueChangeSchema = z5.object({
|
|
379
387
|
inputId: z5.string().min(1),
|
|
380
388
|
expectedRevision: z5.number().int().nonnegative(),
|
|
@@ -415,9 +423,15 @@ var SessionCommandSchema = z5.object({
|
|
|
415
423
|
error: z5.string().nullable()
|
|
416
424
|
});
|
|
417
425
|
var SessionRuntimeSchema = z5.object({
|
|
426
|
+
approvals: z5.array(z5.object({ id: z5.string(), autoApproveAt: z5.number().int().nonnegative() })).optional(),
|
|
418
427
|
nativeSession: NativeSessionIdSchema.nullable().optional(),
|
|
419
428
|
inputs: z5.array(
|
|
420
|
-
z5.object({
|
|
429
|
+
z5.object({
|
|
430
|
+
id: z5.string(),
|
|
431
|
+
state: z5.string(),
|
|
432
|
+
revision: z5.number().int().nonnegative(),
|
|
433
|
+
error: z5.string().nullable().optional()
|
|
434
|
+
})
|
|
421
435
|
).max(200).optional(),
|
|
422
436
|
id: z5.string(),
|
|
423
437
|
state: z5.enum(["idle", "working", "waiting", "queued", "uncertain"]),
|
|
@@ -490,7 +504,12 @@ var SessionActivitySchema = z5.object({
|
|
|
490
504
|
durationMs: z5.number().finite().nonnegative().optional()
|
|
491
505
|
});
|
|
492
506
|
var LocalSessionMessageSchema = z5.object({
|
|
493
|
-
queue: z5.object({
|
|
507
|
+
queue: z5.object({
|
|
508
|
+
revision: z5.number().int().nonnegative(),
|
|
509
|
+
state: z5.string(),
|
|
510
|
+
editable: z5.boolean(),
|
|
511
|
+
error: z5.string().nullable().optional()
|
|
512
|
+
}).optional(),
|
|
494
513
|
images: z5.array(SessionImageSchema).optional(),
|
|
495
514
|
id: z5.string(),
|
|
496
515
|
seq: z5.number().int(),
|
|
@@ -505,6 +524,7 @@ var LocalSessionMessageSchema = z5.object({
|
|
|
505
524
|
code: z5.string(),
|
|
506
525
|
state: z5.string(),
|
|
507
526
|
approval: z5.boolean(),
|
|
527
|
+
autoApproveAt: z5.number().int().nonnegative().nullable().default(null),
|
|
508
528
|
response: QuestionResponseSchema.nullable().default(null),
|
|
509
529
|
submissionState: z5.string().nullable().default(null),
|
|
510
530
|
...InteractionDetailsSchema.shape,
|
|
@@ -512,6 +532,7 @@ var LocalSessionMessageSchema = z5.object({
|
|
|
512
532
|
}).nullable()
|
|
513
533
|
});
|
|
514
534
|
var LocalSessionChatSchema = z5.object({
|
|
535
|
+
canRewind: z5.boolean().default(false),
|
|
515
536
|
cursor: z5.number().int(),
|
|
516
537
|
session: LocalSessionSchema,
|
|
517
538
|
messages: z5.array(LocalSessionMessageSchema),
|
|
@@ -522,10 +543,9 @@ var LocalSessionChatSchema = z5.object({
|
|
|
522
543
|
var ExecutionRef = z6.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9_.:-]{0,127}$/);
|
|
523
544
|
var text = (max) => z6.string().trim().min(1).max(max);
|
|
524
545
|
var SYNC_INTAKE_PAUSED = "\u540C\u6B65\u5DF2\u5173\u95ED\uFF0C\u6682\u505C Tim \u65B0\u589E\u8F6C\u4EA4";
|
|
525
|
-
var
|
|
526
|
-
var LOCAL_AGENT_CLOSED = "\u672C\u9879\u76EE\u6682\u672A\u5411\u4F60\u5F00\u653E\u672C\u5730 Agent \u529F\u80FD";
|
|
546
|
+
var LOCAL_AGENT_CLOSED = "\u5F53\u524D\u6210\u5458\u5DF2\u65E0\u6CD5\u8BBF\u95EE\u6B64\u9879\u76EE\uFF0C\u8BF7\u786E\u8BA4\u9879\u76EE\u6210\u5458\u8D44\u683C";
|
|
527
547
|
var ExecutionSettingsSchema = z6.object({
|
|
528
|
-
opened: z6.boolean().default(
|
|
548
|
+
opened: z6.boolean().default(true),
|
|
529
549
|
allowedMembers: z6.array(NameSchema).nullable(),
|
|
530
550
|
accessible: z6.boolean(),
|
|
531
551
|
enabled: z6.boolean(),
|
|
@@ -546,7 +566,8 @@ var DirectoryRegistrationSchema = z6.object({
|
|
|
546
566
|
name: text(80),
|
|
547
567
|
responsibilities: z6.string().trim().max(2e3).default(""),
|
|
548
568
|
expectedRevision: z6.number().int().nonnegative(),
|
|
549
|
-
|
|
569
|
+
// Accepted for older clients; registration itself enables intake.
|
|
570
|
+
enabled: z6.boolean().default(true),
|
|
550
571
|
provider: AgentProviderIdSchema
|
|
551
572
|
}).strict();
|
|
552
573
|
var ExecutionDirectorySchema = DirectoryRegistrationSchema.omit({
|
|
@@ -2068,30 +2089,29 @@ var MemberExecutionSettings = class {
|
|
|
2068
2089
|
}
|
|
2069
2090
|
hub;
|
|
2070
2091
|
config(project) {
|
|
2071
|
-
const row = this.hub.db.prepare(
|
|
2072
|
-
"SELECT opened,allowed_members_json,enabled,revision FROM member_agent_settings WHERE project_id=?"
|
|
2073
|
-
).get(project);
|
|
2092
|
+
const row = this.hub.db.prepare("SELECT revision FROM member_agent_settings WHERE project_id=?").get(project);
|
|
2074
2093
|
return {
|
|
2075
|
-
opened:
|
|
2076
|
-
allowedMembers:
|
|
2077
|
-
enabled:
|
|
2094
|
+
opened: true,
|
|
2095
|
+
allowedMembers: null,
|
|
2096
|
+
enabled: true,
|
|
2078
2097
|
revision: Number(row?.revision ?? 0)
|
|
2079
2098
|
};
|
|
2080
2099
|
}
|
|
2081
2100
|
accessible(identity) {
|
|
2082
|
-
|
|
2083
|
-
|
|
2101
|
+
try {
|
|
2102
|
+
this.assertOpen(identity);
|
|
2103
|
+
return true;
|
|
2104
|
+
} catch (error) {
|
|
2105
|
+
if (error instanceof HubError && error.code === "AI_MEMBER_UNAVAILABLE") return false;
|
|
2106
|
+
throw error;
|
|
2107
|
+
}
|
|
2084
2108
|
}
|
|
2085
2109
|
assertOpen(identity) {
|
|
2086
|
-
|
|
2087
|
-
throw new HubError(403, "LOCAL_AGENT_CLOSED", LOCAL_AGENT_CLOSED);
|
|
2088
|
-
}
|
|
2089
|
-
enabled(project) {
|
|
2090
|
-
return !!this.hub.db.prepare("SELECT enabled FROM member_agent_settings WHERE project_id=?").get(project)?.enabled;
|
|
2110
|
+
requireAnalysisAccess(this.hub, identity);
|
|
2091
2111
|
}
|
|
2092
2112
|
get(identity) {
|
|
2093
|
-
|
|
2094
|
-
return { ...this.config(identity.workspaceId), accessible:
|
|
2113
|
+
this.assertOpen(identity);
|
|
2114
|
+
return { ...this.config(identity.workspaceId), accessible: true };
|
|
2095
2115
|
}
|
|
2096
2116
|
save(identity, input) {
|
|
2097
2117
|
const value = ExecutionSettingsUpdateSchema.parse(input);
|
|
@@ -2103,19 +2123,9 @@ var MemberExecutionSettings = class {
|
|
|
2103
2123
|
"EXECUTION_SETTINGS_REVISION",
|
|
2104
2124
|
"\u9879\u76EE\u672C\u5730\u6267\u884C\u8BBE\u7F6E\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5\u3002"
|
|
2105
2125
|
);
|
|
2106
|
-
const allowedMembers = value.allowedMembers === void 0 ? current2.allowedMembers : value.allowedMembers === null ? null : [...new Set(value.allowedMembers)].sort();
|
|
2107
|
-
if (value.allowedMembers) {
|
|
2108
|
-
for (const member of allowedMembers) requireProjectActor(this.hub, identity, member);
|
|
2109
|
-
}
|
|
2110
2126
|
this.hub.db.prepare(
|
|
2111
2127
|
"INSERT INTO member_agent_settings(project_id,enabled,revision,opened,allowed_members_json) VALUES(?,?,?,?,?) ON CONFLICT(project_id) DO UPDATE SET enabled=excluded.enabled,revision=excluded.revision,opened=excluded.opened,allowed_members_json=excluded.allowed_members_json"
|
|
2112
|
-
).run(
|
|
2113
|
-
identity.workspaceId,
|
|
2114
|
-
Number(value.enabled ?? current2.enabled),
|
|
2115
|
-
current2.revision + 1,
|
|
2116
|
-
Number(value.opened ?? current2.opened),
|
|
2117
|
-
allowedMembers === null ? null : JSON.stringify(allowedMembers)
|
|
2118
|
-
);
|
|
2128
|
+
).run(identity.workspaceId, 1, current2.revision + 1, 1, null);
|
|
2119
2129
|
return this.get(identity);
|
|
2120
2130
|
});
|
|
2121
2131
|
}
|
|
@@ -2128,6 +2138,13 @@ UPDATE member_agent_settings SET opened=enabled;
|
|
|
2128
2138
|
var localAgentMemberAccessMigration = `
|
|
2129
2139
|
ALTER TABLE member_agent_settings ADD COLUMN allowed_members_json TEXT;
|
|
2130
2140
|
`;
|
|
2141
|
+
var automaticDirectoryIntakeMigration = `
|
|
2142
|
+
UPDATE member_agent_settings SET opened=1,enabled=1,allowed_members_json=NULL,revision=revision+1
|
|
2143
|
+
WHERE opened<>1 OR enabled<>1 OR allowed_members_json IS NOT NULL;
|
|
2144
|
+
UPDATE member_agent_directories SET enabled=1,revision=revision+1 WHERE enabled=0;
|
|
2145
|
+
INSERT OR IGNORE INTO member_agent_enrollments(project_id,member_id,activated_at)
|
|
2146
|
+
SELECT project_id,member_id,strftime('%Y-%m-%dT%H:%M:%fZ','now') FROM member_agent_directories;
|
|
2147
|
+
`;
|
|
2131
2148
|
|
|
2132
2149
|
// packages/protocol/event-routing.ts
|
|
2133
2150
|
import { z as z15 } from "zod";
|
|
@@ -2140,6 +2157,10 @@ var RoutingCategorySchema = z15.enum([
|
|
|
2140
2157
|
"channel.follow",
|
|
2141
2158
|
"diagnostic"
|
|
2142
2159
|
]);
|
|
2160
|
+
var notificationCategories = RoutingCategorySchema.options.filter(
|
|
2161
|
+
(c) => c !== "diagnostic"
|
|
2162
|
+
);
|
|
2163
|
+
var defaultAutoHandle = (category) => category === "member.request" || category === "mr.review";
|
|
2143
2164
|
var RoutingHandlerSchema = z15.enum(["human", "managed", "hook"]);
|
|
2144
2165
|
var RoutingReassignSchema = z15.object({
|
|
2145
2166
|
handler: RoutingHandlerSchema,
|
|
@@ -2150,6 +2171,7 @@ var RoutingPolicySchema = z15.object({
|
|
|
2150
2171
|
category: RoutingCategorySchema,
|
|
2151
2172
|
handler: RoutingHandlerSchema,
|
|
2152
2173
|
hookId: z15.uuid().nullable(),
|
|
2174
|
+
autoHandle: z15.boolean().default(false),
|
|
2153
2175
|
notify: z15.boolean(),
|
|
2154
2176
|
wecom: z15.boolean(),
|
|
2155
2177
|
revision: z15.number().int().nonnegative()
|
|
@@ -2158,7 +2180,9 @@ var RoutingPolicyUpdateSchema = RoutingPolicySchema.pick({
|
|
|
2158
2180
|
category: true,
|
|
2159
2181
|
notify: true,
|
|
2160
2182
|
wecom: true
|
|
2161
|
-
}).extend({
|
|
2183
|
+
}).partial().extend({
|
|
2184
|
+
category: RoutingCategorySchema.exclude(["diagnostic"]),
|
|
2185
|
+
autoHandle: z15.boolean().optional(),
|
|
2162
2186
|
expectedRevision: z15.number().int().nonnegative()
|
|
2163
2187
|
}).strict();
|
|
2164
2188
|
var RoutingModeSchema = z15.object({
|
|
@@ -2234,20 +2258,23 @@ var EventRouting = class {
|
|
|
2234
2258
|
agentStatus(identity) {
|
|
2235
2259
|
const execution = new MemberExecutionSettings(this.hub);
|
|
2236
2260
|
if (!execution.accessible(identity)) return "closed";
|
|
2237
|
-
const directories = this.hub.db.prepare("SELECT
|
|
2238
|
-
|
|
2239
|
-
return execution.enabled(identity.workspaceId) && directories.some((d) => d.enabled) ? "ready" : "disabled";
|
|
2261
|
+
const directories = this.hub.db.prepare("SELECT 1 FROM member_agent_directories WHERE project_id=? AND member_id=? LIMIT 1").get(identity.workspaceId, identity.memberId);
|
|
2262
|
+
return directories ? "ready" : "unregistered";
|
|
2240
2263
|
}
|
|
2241
2264
|
policy(identity, category) {
|
|
2242
2265
|
const row = this.hub.db.prepare("SELECT * FROM routing_policies WHERE project_id=? AND member_id=? AND category=?").get(identity.workspaceId, identity.memberId, category);
|
|
2243
2266
|
const mode = this.mode(identity);
|
|
2244
|
-
const
|
|
2267
|
+
const autoHandle = category !== "diagnostic" && (row ? !!row.auto_handle : defaultAutoHandle(category));
|
|
2268
|
+
const handler = !autoHandle ? "human" : mode.mode === "hook" ? "hook" : mode.mode === "managed" && this.agentStatus(identity) === "ready" ? "managed" : "human";
|
|
2245
2269
|
return {
|
|
2246
2270
|
category,
|
|
2247
2271
|
handler,
|
|
2248
|
-
|
|
2272
|
+
autoHandle,
|
|
2273
|
+
hookId: handler === "hook" ? mode.hookId : null,
|
|
2249
2274
|
notify: handler === "human" || (row ? !!row.notify : false),
|
|
2250
|
-
wecom: !!
|
|
2275
|
+
wecom: category === "diagnostic" ? !!this.hub.db.prepare(
|
|
2276
|
+
"SELECT wecom FROM routing_policies WHERE project_id=? AND member_id=? AND category='private.notice'"
|
|
2277
|
+
).get(identity.workspaceId, identity.memberId)?.wecom : !!row?.wecom,
|
|
2251
2278
|
revision: Number(row?.revision ?? 0)
|
|
2252
2279
|
};
|
|
2253
2280
|
}
|
|
@@ -2255,7 +2282,7 @@ var EventRouting = class {
|
|
|
2255
2282
|
requireProjectActor(this.hub, identity);
|
|
2256
2283
|
return {
|
|
2257
2284
|
mode: this.mode(identity),
|
|
2258
|
-
policies:
|
|
2285
|
+
policies: notificationCategories.map((category) => this.policy(identity, category)),
|
|
2259
2286
|
managedAvailable: this.agentStatus(identity) === "ready",
|
|
2260
2287
|
agentStatus: this.agentStatus(identity),
|
|
2261
2288
|
wecomAvailable: !!this.hub.db.prepare("SELECT 1 FROM wecom_bindings WHERE user_id=?").get(identity.memberId),
|
|
@@ -2277,7 +2304,7 @@ var EventRouting = class {
|
|
|
2277
2304
|
if (value.expectedRevision !== settings.mode.revision)
|
|
2278
2305
|
throw new HubError(409, "ROUTING_MODE_CHANGED", "\u8BBE\u7F6E\u5DF2\u66F4\u65B0\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5\u3002");
|
|
2279
2306
|
if (value.mode === "managed" && !settings.managedAvailable)
|
|
2280
|
-
throw new HubError(409, "ROUTING_AGENT_UNAVAILABLE", "\u8BF7\u5148\u63A5\u5165\u672C\u5730 Agent
|
|
2307
|
+
throw new HubError(409, "ROUTING_AGENT_UNAVAILABLE", "\u8BF7\u5148\u63A5\u5165\u672C\u5730 Agent\u3002");
|
|
2281
2308
|
if (value.mode === "hook" && !settings.hooks.some((h) => h.id === value.hookId && h.enabled && h.verified))
|
|
2282
2309
|
throw new HubError(409, "ROUTING_HOOK_UNAVAILABLE", "\u8BF7\u5148\u8FDE\u63A5\u5E76\u9A8C\u8BC1\u6536\u4EF6\u7BB1\u3002");
|
|
2283
2310
|
this.hub.db.prepare(
|
|
@@ -2298,18 +2325,22 @@ var EventRouting = class {
|
|
|
2298
2325
|
return diagnosticTransaction(this.hub, () => {
|
|
2299
2326
|
requireProjectActor(this.hub, identity);
|
|
2300
2327
|
const prior = this.policy(identity, value.category);
|
|
2328
|
+
const saved = this.hub.db.prepare(
|
|
2329
|
+
"SELECT notify,wecom FROM routing_policies WHERE project_id=? AND member_id=? AND category=?"
|
|
2330
|
+
).get(identity.workspaceId, identity.memberId, value.category);
|
|
2301
2331
|
if (value.expectedRevision !== prior.revision)
|
|
2302
2332
|
throw new HubError(409, "ROUTING_POLICY_CHANGED", "\u8BBE\u7F6E\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5\u3002");
|
|
2303
2333
|
this.hub.db.prepare(
|
|
2304
|
-
`INSERT INTO routing_policies(project_id,member_id,category,notify,wecom,revision) VALUES(
|
|
2305
|
-
ON CONFLICT(project_id,member_id,category) DO UPDATE SET notify=excluded.notify,wecom=excluded.wecom,revision=excluded.revision`
|
|
2334
|
+
`INSERT INTO routing_policies(project_id,member_id,category,notify,wecom,revision,auto_handle) VALUES(?,?,?,?,?,?,?)
|
|
2335
|
+
ON CONFLICT(project_id,member_id,category) DO UPDATE SET notify=excluded.notify,wecom=excluded.wecom,revision=excluded.revision,auto_handle=excluded.auto_handle`
|
|
2306
2336
|
).run(
|
|
2307
2337
|
identity.workspaceId,
|
|
2308
2338
|
identity.memberId,
|
|
2309
2339
|
value.category,
|
|
2310
|
-
Number(value.notify),
|
|
2311
|
-
Number(value.wecom),
|
|
2312
|
-
prior.revision + 1
|
|
2340
|
+
Number(value.notify ?? !!saved?.notify),
|
|
2341
|
+
Number(value.wecom ?? !!saved?.wecom),
|
|
2342
|
+
prior.revision + 1,
|
|
2343
|
+
Number(value.autoHandle ?? prior.autoHandle)
|
|
2313
2344
|
);
|
|
2314
2345
|
return this.settings(identity);
|
|
2315
2346
|
});
|
|
@@ -2383,7 +2414,7 @@ var EventRouting = class {
|
|
|
2383
2414
|
if (old) return String(old.id);
|
|
2384
2415
|
const policy = this.policy({ workspaceId: input.project, memberId: member }, category);
|
|
2385
2416
|
if (options.notificationOnly && policy.handler === "managed") policy.handler = "human";
|
|
2386
|
-
if (requiresHuman) {
|
|
2417
|
+
if (requiresHuman || category === "diagnostic") {
|
|
2387
2418
|
policy.handler = "human";
|
|
2388
2419
|
policy.hookId = null;
|
|
2389
2420
|
policy.notify = true;
|
|
@@ -2471,6 +2502,7 @@ var EventRouting = class {
|
|
|
2471
2502
|
return row ? !!JSON.parse(String(row.policy_json)).notify || row.outcome === "handoff_failed" : null;
|
|
2472
2503
|
}
|
|
2473
2504
|
canReassign(row) {
|
|
2505
|
+
if (JSON.parse(String(row.policy_json ?? "{}")).category === "diagnostic") return false;
|
|
2474
2506
|
if (row.handler === "fixed" || row.state !== "waiting" && row.outcome !== "handoff_failed")
|
|
2475
2507
|
return false;
|
|
2476
2508
|
if (row.input_id && this.hub.db.prepare("SELECT 1 FROM member_agent_inputs WHERE id=? AND state='accepted'").get(String(row.input_id)))
|
|
@@ -5407,6 +5439,7 @@ var diagnosticCodes = {
|
|
|
5407
5439
|
RUN_STARTED: ["\u5F00\u59CB\u6267\u884C", ""],
|
|
5408
5440
|
RUN_COMPLETED: ["\u6267\u884C\u5B8C\u6210", ""],
|
|
5409
5441
|
RUN_INTERRUPTED: ["\u6267\u884C\u4E2D\u65AD\u6216\u8F93\u5165\u5DF2\u66FF\u4EE3", ""],
|
|
5442
|
+
RUN_RESET: ["\u7BA1\u7406\u5458\u91CD\u7F6E\u4EFB\u52A1\uFF0C\u7B49\u5F85\u91CD\u8BD5", ""],
|
|
5410
5443
|
CONDITION_RECOVERED: ["\u8FD0\u884C\u6761\u4EF6\u5DF2\u6062\u590D", ""]
|
|
5411
5444
|
};
|
|
5412
5445
|
|
|
@@ -6255,6 +6288,85 @@ function acknowledgeQueueChange(hub, identity, session, kind2, argument) {
|
|
|
6255
6288
|
hub.db.prepare("UPDATE member_session_messages SET state='cancelled' WHERE id=?").run(`input:${change.inputId}`);
|
|
6256
6289
|
}
|
|
6257
6290
|
|
|
6291
|
+
// apps/server/member-execution/rewind.ts
|
|
6292
|
+
function rewindAvailable(hub, identity, session) {
|
|
6293
|
+
const runtime = new MemberExecution(hub).runtime(identity);
|
|
6294
|
+
const config = JSON.parse(String(runtime?.config_json ?? "{}"));
|
|
6295
|
+
return Number(runtime?.lease_until ?? 0) > Date.now() && config.capabilities?.includes(`local-agent-rewind-${session.provider}-v1`) === true;
|
|
6296
|
+
}
|
|
6297
|
+
function pendingRewind(hub, identity, session) {
|
|
6298
|
+
return !!hub.db.prepare(
|
|
6299
|
+
"SELECT 1 FROM member_session_commands WHERE project_id=? AND member_id=? AND session_id=? AND kind='rewind' AND state IN('queued','running','uncertain')"
|
|
6300
|
+
).get(identity.workspaceId, identity.memberId, session);
|
|
6301
|
+
}
|
|
6302
|
+
function supersededInput(hub, identity, input) {
|
|
6303
|
+
return !!hub.db.prepare(
|
|
6304
|
+
"SELECT 1 FROM member_session_messages WHERE project_id=? AND member_id=? AND id=? AND superseded_by IS NOT NULL"
|
|
6305
|
+
).get(identity.workspaceId, identity.memberId, `input:${input}`);
|
|
6306
|
+
}
|
|
6307
|
+
function validateRewind(hub, identity, session, argument) {
|
|
6308
|
+
const value = SessionRewindSchema.parse(JSON.parse(argument));
|
|
6309
|
+
if (!rewindAvailable(hub, identity, session))
|
|
6310
|
+
throw new HubError(409, "REWIND_UNAVAILABLE", "\u5F53\u524D\u5BA2\u6237\u7AEF\u6216 Agent \u4E0D\u652F\u6301\u4EC5\u56DE\u9000\u4F1A\u8BDD\u3002");
|
|
6311
|
+
if (session.archived || session.state !== "idle")
|
|
6312
|
+
throw new HubError(409, "SESSION_BUSY", "\u8BF7\u5148\u505C\u6B62\u5F53\u524D\u5DE5\u4F5C\uFF0C\u518D\u7F16\u8F91\u5386\u53F2\u6D88\u606F\u3002");
|
|
6313
|
+
const pending = hub.db.prepare(
|
|
6314
|
+
"SELECT state,argument FROM member_session_commands WHERE project_id=? AND member_id=? AND session_id=? AND kind='rewind' AND state IN('queued','running','uncertain')"
|
|
6315
|
+
).all(identity.workspaceId, identity.memberId, session.id);
|
|
6316
|
+
if (pending.some(
|
|
6317
|
+
(row) => row.state !== "uncertain" || JSON.parse(String(row.argument)).messageId !== value.messageId
|
|
6318
|
+
))
|
|
6319
|
+
throw new HubError(409, "REWIND_PENDING", "\u4E0A\u6B21\u56DE\u9000\u5C1A\u672A\u786E\u8BA4\uFF0C\u8BF7\u4ECE\u539F\u7F16\u8F91\u4F4D\u7F6E\u91CD\u8BD5\u3002");
|
|
6320
|
+
const rows = hub.db.prepare(
|
|
6321
|
+
"SELECT id,role FROM member_session_messages WHERE project_id=? AND member_id=? AND session_id=? AND superseded_by IS NULL ORDER BY seq"
|
|
6322
|
+
).all(identity.workspaceId, identity.memberId, session.id);
|
|
6323
|
+
const target2 = rows.find((r) => r.id === value.messageId);
|
|
6324
|
+
if (!target2 || target2.role !== "user" || !value.messageId.startsWith("input:"))
|
|
6325
|
+
throw new HubError(400, "REWIND_TARGET", "\u8BF7\u9009\u62E9\u5F53\u524D\u4F1A\u8BDD\u4E2D\u7684\u7528\u6237\u6D88\u606F\u3002");
|
|
6326
|
+
if (new MemberSessions(hub).chat(identity, session.id).messages.at(-1)?.id !== value.expectedLastMessage)
|
|
6327
|
+
throw new HubError(409, "REWIND_CHANGED", "\u4F1A\u8BDD\u5DF2\u6709\u65B0\u6D88\u606F\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u7F16\u8F91\u4F4D\u7F6E\u3002");
|
|
6328
|
+
const input = new MemberExecution(hub).input(identity, value.messageId.slice(6));
|
|
6329
|
+
if (input.interaction || input.source.type !== "web_session")
|
|
6330
|
+
throw new HubError(400, "REWIND_TARGET", "\u53EA\u80FD\u7F16\u8F91\u5728\u7F51\u9875\u4F1A\u8BDD\u4E2D\u53D1\u9001\u7684\u666E\u901A\u6D88\u606F\u3002");
|
|
6331
|
+
return value;
|
|
6332
|
+
}
|
|
6333
|
+
function completeRewind(hub, identity, session, commandId, argument, result) {
|
|
6334
|
+
const value = SessionRewindSchema.parse(JSON.parse(argument));
|
|
6335
|
+
const { nativeSession } = SessionRewindResultSchema.parse(JSON.parse(result));
|
|
6336
|
+
const target2 = hub.db.prepare(
|
|
6337
|
+
"SELECT seq FROM member_session_messages WHERE project_id=? AND member_id=? AND session_id=? AND id=? AND superseded_by IS NULL"
|
|
6338
|
+
).get(identity.workspaceId, identity.memberId, session.id, value.messageId);
|
|
6339
|
+
if (!target2) throw new HubError(409, "REWIND_TARGET", "\u539F\u6D88\u606F\u5DF2\u4E0D\u5728\u5F53\u524D\u4F1A\u8BDD\u4E2D\u3002");
|
|
6340
|
+
const store = new MemberExecution(hub), input = store.input(identity, value.messageId.slice(6));
|
|
6341
|
+
hub.db.prepare(
|
|
6342
|
+
"UPDATE member_session_commands SET state='failed',error='\u5DF2\u7531\u540E\u7EED\u56DE\u9000\u786E\u8BA4\u66FF\u4EE3\u3002' WHERE project_id=? AND member_id=? AND session_id=? AND kind='rewind' AND state='uncertain'"
|
|
6343
|
+
).run(identity.workspaceId, identity.memberId, session.id);
|
|
6344
|
+
hub.db.prepare(
|
|
6345
|
+
"UPDATE member_session_messages SET superseded_by=? WHERE project_id=? AND session_id=? AND superseded_by IS NULL AND seq>=?"
|
|
6346
|
+
).run(commandId, identity.workspaceId, session.id, target2.seq);
|
|
6347
|
+
hub.db.prepare(
|
|
6348
|
+
"UPDATE member_agent_questions SET state='expired' WHERE id IN(SELECT id FROM member_session_messages WHERE superseded_by=?) AND state='pending'"
|
|
6349
|
+
).run(commandId);
|
|
6350
|
+
hub.db.prepare(
|
|
6351
|
+
"UPDATE member_agent_sessions SET native_session=?,state='idle',error=NULL WHERE project_id=? AND id=?"
|
|
6352
|
+
).run(nativeSession, identity.workspaceId, session.id);
|
|
6353
|
+
store.offer(identity, {
|
|
6354
|
+
operation: `rewind:${commandId}`,
|
|
6355
|
+
kind: "directory.message",
|
|
6356
|
+
directory: session.directory,
|
|
6357
|
+
session: session.id,
|
|
6358
|
+
source: { type: "web_session", ref: commandId },
|
|
6359
|
+
delivery: "queue",
|
|
6360
|
+
content: { ...input.content, originalText: value.body, brief: value.body },
|
|
6361
|
+
...input.images ? { images: input.images } : {},
|
|
6362
|
+
...input.skills ? {
|
|
6363
|
+
skills: input.skills.filter(
|
|
6364
|
+
(skill) => /^(?:\/|\$)([^\s]+)(?:\s|$)/.exec(value.body)?.[1] === skill.name
|
|
6365
|
+
)
|
|
6366
|
+
} : {}
|
|
6367
|
+
});
|
|
6368
|
+
}
|
|
6369
|
+
|
|
6258
6370
|
// apps/server/member-execution/sessions.ts
|
|
6259
6371
|
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
6260
6372
|
import { z as z25 } from "zod";
|
|
@@ -6336,7 +6448,11 @@ var MemberSessions = class {
|
|
|
6336
6448
|
"SESSION_DIRECTORY",
|
|
6337
6449
|
"\u6B64\u539F\u751F\u4F1A\u8BDD\u5DF2\u63A5\u5165\u5176\u4ED6\u76EE\u5F55\uFF0C\u8BF7\u4ECE\u539F\u5165\u53E3\u7EE7\u7EED\u3002"
|
|
6338
6450
|
);
|
|
6339
|
-
|
|
6451
|
+
const session = this.get(identity, String(existing2.id));
|
|
6452
|
+
return session.hidden ? this.metadata(identity, session.id, {
|
|
6453
|
+
expectedRevision: session.metadataRevision,
|
|
6454
|
+
hidden: false
|
|
6455
|
+
}) : session;
|
|
6340
6456
|
}
|
|
6341
6457
|
}
|
|
6342
6458
|
let importedAt = null;
|
|
@@ -6390,7 +6506,11 @@ var MemberSessions = class {
|
|
|
6390
6506
|
const row = this.hub.db.prepare(
|
|
6391
6507
|
`SELECT s.*,
|
|
6392
6508
|
EXISTS(SELECT 1 FROM member_agent_bindings b WHERE b.project_id=s.project_id AND b.session_id=s.id) bound,
|
|
6393
|
-
EXISTS(SELECT 1 FROM member_session_messages m
|
|
6509
|
+
EXISTS(SELECT 1 FROM member_session_messages m
|
|
6510
|
+
WHERE m.project_id=s.project_id AND m.session_id=s.id AND m.seq>s.read_seq
|
|
6511
|
+
AND m.superseded_by IS NULL AND m.role='assistant' AND m.state IN('sent','succeeded','failed','interrupted','uncertain')
|
|
6512
|
+
AND (json_extract(m.activity_json,'$.kind')='turn'
|
|
6513
|
+
OR (m.activity_json IS NULL AND m.source='agent-final'))) unread
|
|
6394
6514
|
FROM member_agent_sessions s WHERE s.project_id=? AND s.member_id=? AND s.id=?`
|
|
6395
6515
|
).get(identity.workspaceId, identity.memberId, id);
|
|
6396
6516
|
if (!row) throw new HubError(404, "SESSION_NOT_FOUND", "\u627E\u4E0D\u5230\u672C\u4EBA\u7684\u4F1A\u8BDD\u3002");
|
|
@@ -6403,6 +6523,7 @@ var MemberSessions = class {
|
|
|
6403
6523
|
member: row.member_id,
|
|
6404
6524
|
title: row.title,
|
|
6405
6525
|
pinned: !!row.pinned,
|
|
6526
|
+
hidden: !!row.hidden,
|
|
6406
6527
|
metadataRevision: row.metadata_revision,
|
|
6407
6528
|
revision: row.revision,
|
|
6408
6529
|
config: JSON.parse(String(row.config_json)),
|
|
@@ -6427,7 +6548,7 @@ var MemberSessions = class {
|
|
|
6427
6548
|
return this.hub.db.prepare(
|
|
6428
6549
|
"SELECT id FROM member_agent_sessions WHERE project_id=? AND member_id=? AND (? IS NULL OR directory_id=?) ORDER BY created_at,id"
|
|
6429
6550
|
).all(identity.workspaceId, identity.memberId, directory ?? null, directory ?? null).map((row) => this.get(identity, String(row.id))).sort(
|
|
6430
|
-
(a, b) =>
|
|
6551
|
+
(a, b) => Date.parse(b.updatedAt) - Date.parse(a.updatedAt) || a.id.localeCompare(b.id)
|
|
6431
6552
|
);
|
|
6432
6553
|
}
|
|
6433
6554
|
forContext(identity, context) {
|
|
@@ -6454,7 +6575,7 @@ var MemberSessions = class {
|
|
|
6454
6575
|
return selected;
|
|
6455
6576
|
}
|
|
6456
6577
|
candidates(identity, directory) {
|
|
6457
|
-
return this.list(identity, directory).filter((s) => s.pinned && !s.archived);
|
|
6578
|
+
return this.list(identity, directory).filter((s) => s.pinned && !s.archived && !s.hidden);
|
|
6458
6579
|
}
|
|
6459
6580
|
metadata(identity, id, input) {
|
|
6460
6581
|
new MemberExecutionSettings(this.hub).assertOpen(identity);
|
|
@@ -6465,20 +6586,28 @@ var MemberSessions = class {
|
|
|
6465
6586
|
expectedRevision: z25.number().int(),
|
|
6466
6587
|
title: z25.string().trim().min(1).max(200).optional(),
|
|
6467
6588
|
pinned: z25.boolean().optional(),
|
|
6589
|
+
hidden: z25.boolean().optional(),
|
|
6468
6590
|
default: z25.boolean().optional()
|
|
6469
6591
|
}).strict().parse(input);
|
|
6470
6592
|
return diagnosticTransaction(this.hub, () => {
|
|
6471
6593
|
const session = this.get(identity, id);
|
|
6472
6594
|
if (session.metadataRevision !== value.expectedRevision)
|
|
6473
6595
|
throw new HubError(409, "SESSION_METADATA_REVISION", "\u4F1A\u8BDD\u4FE1\u606F\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u8BFB\u53D6\u3002");
|
|
6474
|
-
const
|
|
6596
|
+
const hidden = value.hidden ?? session.hidden;
|
|
6597
|
+
const pinned = !hidden && (value.default === true || (value.pinned ?? session.pinned));
|
|
6475
6598
|
if (session.archived && pinned)
|
|
6476
|
-
throw new HubError(409, "SESSION_ARCHIVED", "\u8BF7\u5148\u6062\u590D\u4F1A\u8BDD\u518D\
|
|
6599
|
+
throw new HubError(409, "SESSION_ARCHIVED", "\u8BF7\u5148\u6062\u590D\u4F1A\u8BDD\u518D\u5173\u8054\u3002");
|
|
6477
6600
|
this.hub.db.prepare(
|
|
6478
|
-
"UPDATE member_agent_sessions SET title=?,pinned=?,metadata_revision=metadata_revision+1 WHERE project_id=? AND id=?"
|
|
6479
|
-
).run(
|
|
6601
|
+
"UPDATE member_agent_sessions SET title=?,pinned=?,hidden=?,metadata_revision=metadata_revision+1 WHERE project_id=? AND id=?"
|
|
6602
|
+
).run(
|
|
6603
|
+
value.title ?? session.title,
|
|
6604
|
+
Number(pinned),
|
|
6605
|
+
Number(hidden),
|
|
6606
|
+
identity.workspaceId,
|
|
6607
|
+
id
|
|
6608
|
+
);
|
|
6480
6609
|
const dir = this.directory(identity, session.directory);
|
|
6481
|
-
const nextDefault = value.default === true ? id : (!pinned || value.default === false) && dir.default_session === id ? null : dir.default_session;
|
|
6610
|
+
const nextDefault = value.default === true && !hidden ? id : (!pinned || value.default === false) && dir.default_session === id ? null : dir.default_session;
|
|
6482
6611
|
if (nextDefault !== dir.default_session)
|
|
6483
6612
|
this.hub.db.prepare(
|
|
6484
6613
|
"UPDATE member_agent_directories SET default_session=?,revision=revision+1 WHERE project_id=? AND id=?"
|
|
@@ -6594,7 +6723,7 @@ var MemberSessions = class {
|
|
|
6594
6723
|
if (value.expectedRevision !== void 0 && value.expectedRevision !== Number(directory.revision))
|
|
6595
6724
|
throw new HubError(409, "DIRECTORY_REVISION", "\u76EE\u5F55\u914D\u7F6E\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u8BFB\u53D6\u3002");
|
|
6596
6725
|
const session = value.defaultSession ? this.get(identity, value.defaultSession) : null;
|
|
6597
|
-
if (session && (session.directory !== id || session.archived))
|
|
6726
|
+
if (session && (session.directory !== id || session.archived || session.hidden))
|
|
6598
6727
|
throw new HubError(409, "DEFAULT_SESSION", "\u8BF7\u9009\u62E9\u672C\u76EE\u5F55\u672A\u5F52\u6863\u7684\u4F1A\u8BDD\u3002");
|
|
6599
6728
|
const registrationChanged = value.name !== void 0 || value.responsibilities !== void 0 || value.enabled !== void 0;
|
|
6600
6729
|
if (registrationChanged)
|
|
@@ -6629,13 +6758,13 @@ var MemberSessions = class {
|
|
|
6629
6758
|
this.get(identity, session);
|
|
6630
6759
|
const written = this.hub.db.prepare(
|
|
6631
6760
|
`INSERT INTO member_session_messages(id,project_id,member_id,session_id,role,body,source,state,created_at,activity_json) VALUES(?,?,?,?,?,?,?,?,?,?)
|
|
6632
|
-
ON CONFLICT(id) DO UPDATE SET body=excluded.body,state=excluded.state,
|
|
6761
|
+
ON CONFLICT(id) DO UPDATE SET body=excluded.body,state=excluded.state,source=excluded.source,
|
|
6633
6762
|
activity_json=COALESCE(excluded.activity_json,member_session_messages.activity_json),
|
|
6634
6763
|
seq=CASE WHEN member_session_messages.role='assistant' AND member_session_messages.state='running' AND excluded.state<>'running' AND (member_session_messages.activity_json IS NULL OR json_extract(member_session_messages.activity_json,'$.kind')='answer') THEN excluded.seq ELSE member_session_messages.seq END,
|
|
6635
6764
|
created_at=CASE WHEN member_session_messages.role='assistant' AND member_session_messages.state='running' AND excluded.state<>'running' AND member_session_messages.activity_json IS NULL THEN excluded.created_at ELSE member_session_messages.created_at END
|
|
6636
6765
|
WHERE member_session_messages.project_id=excluded.project_id AND member_session_messages.member_id=excluded.member_id AND member_session_messages.session_id=excluded.session_id
|
|
6637
6766
|
AND NOT (member_session_messages.state<>'running' AND excluded.state='running')
|
|
6638
|
-
AND (member_session_messages.body IS NOT excluded.body OR member_session_messages.state IS NOT excluded.state OR (excluded.activity_json IS NOT NULL AND member_session_messages.activity_json IS NOT excluded.activity_json))`
|
|
6767
|
+
AND (member_session_messages.body IS NOT excluded.body OR member_session_messages.state IS NOT excluded.state OR member_session_messages.source IS NOT excluded.source OR (excluded.activity_json IS NOT NULL AND member_session_messages.activity_json IS NOT excluded.activity_json))`
|
|
6639
6768
|
).run(
|
|
6640
6769
|
value.role === "user" ? `input:${value.id}` : value.id,
|
|
6641
6770
|
identity.workspaceId,
|
|
@@ -6656,7 +6785,7 @@ var MemberSessions = class {
|
|
|
6656
6785
|
const rows = this.hub.db.prepare(
|
|
6657
6786
|
`SELECT m.*,i.state input_state,i.id input_id,i.payload_json,q.id question_id,q.code,q.state question_state,q.content_json FROM member_session_messages m
|
|
6658
6787
|
LEFT JOIN member_agent_inputs i ON 'input:'||i.id=m.id LEFT JOIN member_agent_questions q ON q.id=m.id
|
|
6659
|
-
WHERE m.project_id=? AND m.member_id=? AND m.session_id=? ORDER BY m.seq`
|
|
6788
|
+
WHERE m.project_id=? AND m.member_id=? AND m.session_id=? AND m.superseded_by IS NULL ORDER BY m.seq`
|
|
6660
6789
|
).all(identity.workspaceId, identity.memberId, id);
|
|
6661
6790
|
const replies = /* @__PURE__ */ new Map();
|
|
6662
6791
|
const questions = new Map(
|
|
@@ -6717,6 +6846,7 @@ var MemberSessions = class {
|
|
|
6717
6846
|
queue: {
|
|
6718
6847
|
revision: Number(edit?.revision ?? 0),
|
|
6719
6848
|
state,
|
|
6849
|
+
error: progress.get(String(row.input_id))?.error ?? null,
|
|
6720
6850
|
editable: !pending && ["offered", "received", "queued"].includes(state) && Number(runtime?.lease_until ?? 0) > Date.now()
|
|
6721
6851
|
}
|
|
6722
6852
|
};
|
|
@@ -6740,6 +6870,7 @@ var MemberSessions = class {
|
|
|
6740
6870
|
questions: JSON.parse(String(row.content_json)).questions,
|
|
6741
6871
|
kind: JSON.parse(String(row.content_json)).kind,
|
|
6742
6872
|
autoApprove: JSON.parse(String(row.content_json)).autoApprove,
|
|
6873
|
+
autoApproveAt: runtime && Number(runtime.lease_until) > Date.now() && row.question_state === "pending" && !replies.has(String(row.question_id)) ? runtimeConfig.sessions?.find((s) => s.id === id)?.approvals?.find((q) => q.id === row.question_id)?.autoApproveAt ?? null : null,
|
|
6743
6874
|
plan: JSON.parse(String(row.content_json)).plan,
|
|
6744
6875
|
planSource: JSON.parse(String(row.content_json)).planSource,
|
|
6745
6876
|
actions: JSON.parse(String(row.content_json)).actions,
|
|
@@ -6752,7 +6883,13 @@ var MemberSessions = class {
|
|
|
6752
6883
|
"SELECT COALESCE(MAX(seq),0) seq FROM member_session_events WHERE project_id=? AND session_id=?"
|
|
6753
6884
|
).get(identity.workspaceId, id).seq
|
|
6754
6885
|
);
|
|
6755
|
-
return {
|
|
6886
|
+
return {
|
|
6887
|
+
session,
|
|
6888
|
+
messages,
|
|
6889
|
+
commands: this.commands(identity, id),
|
|
6890
|
+
cursor,
|
|
6891
|
+
canRewind: rewindAvailable(this.hub, identity, session)
|
|
6892
|
+
};
|
|
6756
6893
|
}
|
|
6757
6894
|
read(identity, id) {
|
|
6758
6895
|
this.get(identity, id);
|
|
@@ -6793,6 +6930,8 @@ var MemberSessions = class {
|
|
|
6793
6930
|
throw new HubError(400, "COMMAND_UNSUPPORTED", "\u6B64 Agent \u4E0D\u652F\u6301 /goal \u547D\u4EE4\u3002");
|
|
6794
6931
|
const prior = this.hub.db.prepare("SELECT * FROM member_session_commands WHERE id=?").get(value.id);
|
|
6795
6932
|
const runtime = new MemberExecution(this.hub).runtime(identity);
|
|
6933
|
+
if (value.kind === "rewind" && !prior)
|
|
6934
|
+
validateRewind(this.hub, identity, session, value.argument);
|
|
6796
6935
|
if (value.kind === "history") {
|
|
6797
6936
|
NativeHistoryQuerySchema.parse(JSON.parse(value.argument));
|
|
6798
6937
|
if (!prior && !JSON.parse(String(runtime?.config_json ?? "{}")).capabilities?.includes(
|
|
@@ -6929,6 +7068,17 @@ var MemberSessions = class {
|
|
|
6929
7068
|
throw new HubError(409, "COMMAND_OWNED", "\u64CD\u4F5C\u7ED3\u679C\u9700\u8981\u6838\u5BF9\uFF0C\u4E0D\u80FD\u91CD\u590D\u6267\u884C\u3002");
|
|
6930
7069
|
this.hub.db.prepare("UPDATE member_session_commands SET state=?,instance=?,error=? WHERE id=?").run(value.state, value.instance, value.error, id);
|
|
6931
7070
|
if (value.state === "succeeded") {
|
|
7071
|
+
if (row.kind === "rewind") {
|
|
7072
|
+
completeRewind(
|
|
7073
|
+
this.hub,
|
|
7074
|
+
identity,
|
|
7075
|
+
this.get(identity, String(row.session_id)),
|
|
7076
|
+
id,
|
|
7077
|
+
String(row.argument),
|
|
7078
|
+
value.result ?? "{}"
|
|
7079
|
+
);
|
|
7080
|
+
return { ok: true };
|
|
7081
|
+
}
|
|
6932
7082
|
if (row.kind === "history") {
|
|
6933
7083
|
const history = NativeHistoryPageSchema.parse(JSON.parse(value.result ?? "{}"));
|
|
6934
7084
|
this.hub.db.prepare("UPDATE member_session_commands SET result_json=? WHERE id=?").run(JSON.stringify(history), id);
|
|
@@ -6989,26 +7139,16 @@ var MemberExecution = class {
|
|
|
6989
7139
|
requireProjectActor(this.hub, identity);
|
|
6990
7140
|
return diagnosticTransaction(this.hub, () => {
|
|
6991
7141
|
const previous = this.hub.db.prepare("SELECT * FROM member_agent_directories WHERE project_id=? AND id=?").get(identity.workspaceId, id);
|
|
6992
|
-
|
|
6993
|
-
if (!previous || value.enabled || value.name !== previous.name || value.responsibilities !== previous.responsibilities)
|
|
6994
|
-
new MemberExecutionSettings(this.hub).assertOpen(identity);
|
|
6995
|
-
if (enabling && !new MemberExecutionSettings(this.hub).enabled(identity.workspaceId))
|
|
6996
|
-
throw new HubError(409, "PROJECT_EXECUTION_DISABLED", PROJECT_INTAKE_PAUSED);
|
|
7142
|
+
new MemberExecutionSettings(this.hub).assertOpen(identity);
|
|
6997
7143
|
if (previous && (previous.member_id !== identity.memberId || previous.device_id !== identity.deviceId))
|
|
6998
7144
|
throw new HubError(403, "DIRECTORY_OWNER", "\u76EE\u5F55\u5C5E\u4E8E\u53E6\u4E00\u4E2A\u6210\u5458\u6216\u8BBE\u5907\uFF0C\u8BF7\u91CD\u65B0\u767B\u8BB0\u3002");
|
|
6999
7145
|
if (previous && Number(previous.revision) !== value.expectedRevision) {
|
|
7000
|
-
if (Number(previous.revision) === value.expectedRevision + 1 && previous.name === value.name && previous.responsibilities === value.responsibilities &&
|
|
7146
|
+
if (Number(previous.revision) === value.expectedRevision + 1 && previous.name === value.name && previous.responsibilities === value.responsibilities && previous.provider === value.provider)
|
|
7001
7147
|
return this.directory(identity, id);
|
|
7002
7148
|
throw new HubError(409, "DIRECTORY_REVISION", "\u76EE\u5F55\u914D\u7F6E\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u8BFB\u53D6\u3002");
|
|
7003
7149
|
}
|
|
7004
7150
|
if (!previous && value.expectedRevision !== 0)
|
|
7005
7151
|
throw new HubError(409, "DIRECTORY_REVISION", "\u76EE\u5F55\u5C1A\u672A\u767B\u8BB0\u3002");
|
|
7006
|
-
if (enabling && !this.sessionCapable(identity) && !this.binding(identity.workspaceId, id))
|
|
7007
|
-
throw new HubError(
|
|
7008
|
-
409,
|
|
7009
|
-
"DIRECTORY_UNBOUND",
|
|
7010
|
-
"\u5F53\u524D\u5BA2\u6237\u7AEF\u9700\u5148\u7ED1\u5B9A\u4E13\u7528\u7FA4\uFF1B\u5347\u7EA7\u5BA2\u6237\u7AEF\u540E\u4E5F\u53EF\u901A\u8FC7\u7F51\u9875\u4F1A\u8BDD\u63A5\u6536 Tim \u8F6C\u4EA4\u3002"
|
|
7011
|
-
);
|
|
7012
7152
|
this.hub.db.prepare(
|
|
7013
7153
|
`INSERT INTO member_agent_directories(project_id,member_id,id,device_id,name,responsibilities,provider,enabled,revision)
|
|
7014
7154
|
VALUES(?,?,?,?,?,?,?,?,?) ON CONFLICT(project_id,id) DO UPDATE SET name=excluded.name,responsibilities=excluded.responsibilities,enabled=excluded.enabled,revision=excluded.revision,
|
|
@@ -7021,12 +7161,11 @@ var MemberExecution = class {
|
|
|
7021
7161
|
value.name,
|
|
7022
7162
|
value.responsibilities,
|
|
7023
7163
|
value.provider,
|
|
7024
|
-
|
|
7164
|
+
1,
|
|
7025
7165
|
value.expectedRevision + 1
|
|
7026
7166
|
);
|
|
7027
7167
|
if (!previous) new MemberSessions(this.hub).initialize(identity, id);
|
|
7028
|
-
|
|
7029
|
-
this.hub.db.prepare("INSERT OR IGNORE INTO member_agent_enrollments VALUES(?,?,?)").run(identity.workspaceId, identity.memberId, new Date(this.now()).toISOString());
|
|
7168
|
+
this.hub.db.prepare("INSERT OR IGNORE INTO member_agent_enrollments VALUES(?,?,?)").run(identity.workspaceId, identity.memberId, new Date(this.now()).toISOString());
|
|
7030
7169
|
return this.directory(identity, id);
|
|
7031
7170
|
});
|
|
7032
7171
|
}
|
|
@@ -7056,7 +7195,7 @@ var MemberExecution = class {
|
|
|
7056
7195
|
name: row.name,
|
|
7057
7196
|
responsibilities: row.responsibilities,
|
|
7058
7197
|
provider: row.provider,
|
|
7059
|
-
enabled:
|
|
7198
|
+
enabled: true,
|
|
7060
7199
|
revision: row.revision,
|
|
7061
7200
|
bindingRevision: session?.bindingRevision ?? Number(row.binding_revision),
|
|
7062
7201
|
defaultSession: session?.id,
|
|
@@ -7126,11 +7265,9 @@ var MemberExecution = class {
|
|
|
7126
7265
|
runtime(identity) {
|
|
7127
7266
|
return this.hub.db.prepare("SELECT * FROM member_agent_runtimes WHERE project_id=? AND member_id=?").get(identity.workspaceId, identity.memberId);
|
|
7128
7267
|
}
|
|
7129
|
-
reason(identity, directory, newWork,
|
|
7268
|
+
reason(identity, directory, newWork, continuation = false) {
|
|
7130
7269
|
if (!continuation && !new MemberExecutionSettings(this.hub).accessible(identity))
|
|
7131
7270
|
return LOCAL_AGENT_CLOSED;
|
|
7132
|
-
if (projectIntake && !new MemberExecutionSettings(this.hub).enabled(identity.workspaceId))
|
|
7133
|
-
return PROJECT_INTAKE_PAUSED;
|
|
7134
7271
|
const row = this.hub.db.prepare("SELECT * FROM member_agent_directories WHERE project_id=? AND member_id=? AND id=?").get(identity.workspaceId, identity.memberId, directory);
|
|
7135
7272
|
if (!row) return "\u76EE\u5F55\u672A\u767B\u8BB0";
|
|
7136
7273
|
const runtime = this.runtime(identity);
|
|
@@ -7140,7 +7277,6 @@ var MemberExecution = class {
|
|
|
7140
7277
|
const config = ExecutionRuntimeSchema.parse(JSON.parse(String(runtime.config_json)));
|
|
7141
7278
|
if (newWork && !config.syncEnabled) return SYNC_INTAKE_PAUSED;
|
|
7142
7279
|
if (newWork && !config.syncRootValid) return "\u4EFB\u52A1\u540C\u6B65\u76EE\u5F55\u4E0D\u53EF\u7528\uFF0C\u6682\u505C Tim \u65B0\u589E\u8F6C\u4EA4";
|
|
7143
|
-
if (newWork && !row.enabled) return "\u6B64\u76EE\u5F55\u5C1A\u672A\u5141\u8BB8 Tim \u8F6C\u4EA4\u5DE5\u4F5C";
|
|
7144
7280
|
const ready = config.directories.find((item) => item.id === directory);
|
|
7145
7281
|
return ready?.ready ? null : ready?.reason ?? "\u76EE\u5F55 Provider \u6682\u4E0D\u53EF\u7528";
|
|
7146
7282
|
}
|
|
@@ -7178,11 +7314,8 @@ var MemberExecution = class {
|
|
|
7178
7314
|
}
|
|
7179
7315
|
const newWork = offer.kind === "work.requested";
|
|
7180
7316
|
const continuation = this.pendingAnswer(identity, offer);
|
|
7181
|
-
const projectIntake = !["directory.message", "work.revised"].includes(offer.kind);
|
|
7182
7317
|
const dirs = this.directories(identity);
|
|
7183
|
-
let reason = offer.directory ? this.reason(identity, offer.directory, newWork,
|
|
7184
|
-
(d) => this.reason(identity, d.id, newWork, projectIntake, continuation) === null
|
|
7185
|
-
) ? null : dirs[0] ? this.reason(identity, dirs[0].id, newWork, projectIntake, continuation) : "\u6CA1\u6709\u5DF2\u767B\u8BB0\u7684\u76EE\u5F55";
|
|
7318
|
+
let reason = offer.directory ? this.reason(identity, offer.directory, newWork, continuation) : dirs.some((d) => this.reason(identity, d.id, newWork, continuation) === null) ? null : dirs[0] ? this.reason(identity, dirs[0].id, newWork, continuation) : "\u6CA1\u6709\u5DF2\u767B\u8BB0\u7684\u76EE\u5F55";
|
|
7186
7319
|
if (offer.content.taskFolders?.length) {
|
|
7187
7320
|
const runtime = this.hub.db.prepare(
|
|
7188
7321
|
"SELECT config_json FROM member_agent_runtimes WHERE project_id=? AND member_id=?"
|
|
@@ -7199,16 +7332,18 @@ var MemberExecution = class {
|
|
|
7199
7332
|
let session = offer.session ? sessions2.get(identity, offer.session) : linked;
|
|
7200
7333
|
if (!session && direct && offer.directory)
|
|
7201
7334
|
session = sessions2.default(identity, offer.directory);
|
|
7335
|
+
if (session && pendingRewind(this.hub, identity, session.id))
|
|
7336
|
+
throw new HubError(409, "REWIND_PENDING", "\u4F1A\u8BDD\u6B63\u5728\u56DE\u9000\uFF0C\u8BF7\u786E\u8BA4\u5B8C\u6210\u540E\u7EE7\u7EED\u53D1\u9001\u3002");
|
|
7202
7337
|
if (session && offer.directory && session.directory !== offer.directory)
|
|
7203
7338
|
throw new HubError(409, "SESSION_DIRECTORY", "\u4F1A\u8BDD\u4E0D\u5C5E\u4E8E\u8BE5\u76EE\u5F55\u3002");
|
|
7204
7339
|
if (session && !direct && !linked && (!session.pinned || session.archived))
|
|
7205
|
-
throw new HubError(409, "SESSION_NOT_PINNED", "\u65B0\u5DE5\u4F5C\u53EA\u80FD\u5206\u914D\u7ED9\u5DF2\
|
|
7340
|
+
throw new HubError(409, "SESSION_NOT_PINNED", "\u65B0\u5DE5\u4F5C\u53EA\u80FD\u5206\u914D\u7ED9\u5DF2\u5173\u8054\u7684\u4F1A\u8BDD\u3002");
|
|
7206
7341
|
if (!session && !direct) {
|
|
7207
7342
|
const capabilities = JSON.parse(String(this.runtime(identity)?.config_json ?? "{}")).capabilities ?? [];
|
|
7208
7343
|
if (!capabilities.includes("local-agent-session-routing-v1"))
|
|
7209
|
-
reason ??= "\u8BF7\u5347\u7EA7\u5BA2\u6237\u7AEF\u540E\u4F7F\u7528\
|
|
7344
|
+
reason ??= "\u8BF7\u5347\u7EA7\u5BA2\u6237\u7AEF\u540E\u4F7F\u7528\u5173\u8054\u4F1A\u8BDD\u5206\u914D\u5DE5\u4F5C\u3002";
|
|
7210
7345
|
else if (!sessions2.candidates(identity, offer.directory).length)
|
|
7211
|
-
reason ??= "\u8BF7\u5148\u5728\u7F51\u9875\u300C\u7535\u8111\u300D\u4E2D\
|
|
7346
|
+
reason ??= "\u8BF7\u5148\u5728\u7F51\u9875\u300C\u7535\u8111\u300D\u4E2D\u5173\u8054\u4E00\u4E2A\u4F1A\u8BDD\uFF0C\u518D\u8F6C\u4EA4\u65B0\u5DE5\u4F5C\u3002";
|
|
7212
7347
|
}
|
|
7213
7348
|
if (!session && direct && offer.directory) reason ??= "\u8BF7\u6307\u5B9A\u4F1A\u8BDD\u540E\u7EE7\u7EED\u3002";
|
|
7214
7349
|
const directoryId = session?.directory ?? offer.directory;
|
|
@@ -7367,26 +7502,17 @@ var MemberExecution = class {
|
|
|
7367
7502
|
}
|
|
7368
7503
|
const directories = this.directories(identity);
|
|
7369
7504
|
const continuation = this.pendingAnswer(identity, input);
|
|
7370
|
-
const projectIntake = !["directory.message", "work.revised"].includes(input.kind);
|
|
7371
7505
|
const reason = input.target.directory ? this.reason(
|
|
7372
7506
|
identity,
|
|
7373
7507
|
input.target.directory,
|
|
7374
7508
|
input.kind === "work.requested",
|
|
7375
|
-
projectIntake,
|
|
7376
7509
|
continuation
|
|
7377
7510
|
) : directories.some(
|
|
7378
|
-
(d) => this.reason(
|
|
7379
|
-
identity,
|
|
7380
|
-
d.id,
|
|
7381
|
-
input.kind === "work.requested",
|
|
7382
|
-
projectIntake,
|
|
7383
|
-
continuation
|
|
7384
|
-
) === null
|
|
7511
|
+
(d) => this.reason(identity, d.id, input.kind === "work.requested", continuation) === null
|
|
7385
7512
|
) ? null : directories[0] ? this.reason(
|
|
7386
7513
|
identity,
|
|
7387
7514
|
directories[0].id,
|
|
7388
7515
|
input.kind === "work.requested",
|
|
7389
|
-
projectIntake,
|
|
7390
7516
|
continuation
|
|
7391
7517
|
) : "\u6CA1\u6709\u5DF2\u767B\u8BB0\u7684\u76EE\u5F55";
|
|
7392
7518
|
const binding = input.target.directory ? this.binding(identity.workspaceId, input.target.directory, input.target.session) : void 0;
|
|
@@ -7437,7 +7563,7 @@ var MemberExecution = class {
|
|
|
7437
7563
|
const sessions2 = new MemberSessions(this.hub);
|
|
7438
7564
|
const linked = sessions2.sourceSession(identity, directory, this.sourceKey(input));
|
|
7439
7565
|
const sessionId = input.target.session ?? linked?.id ?? selectedSession;
|
|
7440
|
-
if (!sessionId) throw new HubError(409, "SESSION_REQUIRED", "\u8BF7\u9009\u62E9\u672C\u8F6E\u5DF2\
|
|
7566
|
+
if (!sessionId) throw new HubError(409, "SESSION_REQUIRED", "\u8BF7\u9009\u62E9\u672C\u8F6E\u5DF2\u5173\u8054\u7684\u4F1A\u8BDD\u3002");
|
|
7441
7567
|
const session = sessions2.get(identity, sessionId);
|
|
7442
7568
|
if (session.directory !== directory || selectedSession && selectedSession !== sessionId)
|
|
7443
7569
|
throw new HubError(409, "SESSION_DIRECTORY", "\u539F\u5DE5\u4F5C\u5DF2\u5173\u8054\u5176\u4ED6\u4F1A\u8BDD\u6216\u76EE\u5F55\u3002");
|
|
@@ -7445,7 +7571,7 @@ var MemberExecution = class {
|
|
|
7445
7571
|
throw new HubError(
|
|
7446
7572
|
409,
|
|
7447
7573
|
"SESSION_NOT_PINNED",
|
|
7448
|
-
"\u4F1A\u8BDD\u5DF2\u53D6\u6D88\
|
|
7574
|
+
"\u4F1A\u8BDD\u5DF2\u53D6\u6D88\u5173\u8054\u6216\u5F52\u6863\uFF0C\u8BF7\u4ECE\u6700\u65B0\u5019\u9009\u91CD\u65B0\u9009\u62E9\u3002"
|
|
7449
7575
|
);
|
|
7450
7576
|
sessions2.bindSource(identity, session.id, this.sourceKey(input));
|
|
7451
7577
|
const payload = {
|
|
@@ -7706,6 +7832,7 @@ function flushEventRouting(hub) {
|
|
|
7706
7832
|
const input = row.input_id ? execution.input(identity, String(row.input_id)) : execution.offer(identity, {
|
|
7707
7833
|
operation: `routed:${row.request_id}:${row.revision}`,
|
|
7708
7834
|
kind: "local.query",
|
|
7835
|
+
delivery: "queue",
|
|
7709
7836
|
source: { type: "routed.event", ref: String(row.request_id) },
|
|
7710
7837
|
content: {
|
|
7711
7838
|
originalText: event.body,
|
|
@@ -7886,6 +8013,7 @@ var ExecutionBridge = class {
|
|
|
7886
8013
|
progress(identity, input) {
|
|
7887
8014
|
const value = ExecutionProgressSchema.parse(input);
|
|
7888
8015
|
const source = new MemberExecution(this.hub).input(identity, value.inputId);
|
|
8016
|
+
if (supersededInput(this.hub, identity, value.inputId)) return { ok: true };
|
|
7889
8017
|
const session = new MemberSessions(this.hub).forContext(identity, value.replyContext);
|
|
7890
8018
|
if (!session || source.state !== "accepted" || source.replyContext !== value.replyContext || source.target.session && source.target.session !== session.id)
|
|
7891
8019
|
throw new HubError(409, "REPLY_INPUT_MISMATCH", "\u589E\u91CF\u5FC5\u987B\u5173\u8054\u539F\u4F1A\u8BDD\u53CA\u5DF2\u63A5\u624B\u8F93\u5165\u3002");
|
|
@@ -7977,7 +8105,7 @@ var ExecutionBridge = class {
|
|
|
7977
8105
|
).run(context, revision, identity.workspaceId, session.id);
|
|
7978
8106
|
if (!new MemberExecution(this.hub).sessionCapable(identity)) {
|
|
7979
8107
|
this.hub.db.prepare(
|
|
7980
|
-
"UPDATE member_agent_directories SET binding_revision=binding_revision+1,
|
|
8108
|
+
"UPDATE member_agent_directories SET binding_revision=binding_revision+1,revision=revision+1 WHERE project_id=? AND id=?"
|
|
7981
8109
|
).run(identity.workspaceId, binding.directory_id);
|
|
7982
8110
|
for (const question of this.hub.db.prepare("SELECT id FROM member_agent_questions WHERE reply_context=? AND state='pending'").all(binding.reply_context))
|
|
7983
8111
|
new EventRouting(this.hub).endSource(
|
|
@@ -8141,6 +8269,8 @@ var ExecutionBridge = class {
|
|
|
8141
8269
|
...value.inputId ? [value.inputId] : [],
|
|
8142
8270
|
...value.inputIds ?? []
|
|
8143
8271
|
]);
|
|
8272
|
+
if ([...inputIds].some((id) => supersededInput(this.hub, identity, id)))
|
|
8273
|
+
return { operationId: value.operationId, state: "cancelled" };
|
|
8144
8274
|
if (target2.kind === "group" && session && !this.hub.db.prepare("SELECT group_sync FROM member_agent_sessions WHERE project_id=? AND id=?").get(identity.workspaceId, session.id)?.group_sync && ![...inputIds].some(
|
|
8145
8275
|
(id) => new MemberExecution(this.hub).input(identity, id).source.type === "dedicated_group"
|
|
8146
8276
|
))
|
|
@@ -8215,7 +8345,7 @@ var ExecutionBridge = class {
|
|
|
8215
8345
|
id: value.operationId,
|
|
8216
8346
|
role: "assistant",
|
|
8217
8347
|
body: value.body,
|
|
8218
|
-
source: "agent",
|
|
8348
|
+
source: value.final && !value.question ? "agent-final" : "agent",
|
|
8219
8349
|
state: "sent",
|
|
8220
8350
|
...value.activity ? { activity: value.activity } : {}
|
|
8221
8351
|
});
|
|
@@ -8570,9 +8700,7 @@ var WecomGroups = class {
|
|
|
8570
8700
|
if (command?.name === "bind") {
|
|
8571
8701
|
const bridge = new ExecutionBridge(this.hub);
|
|
8572
8702
|
if (bridge.bind(bot, chat, msg.from.userid, command.argument)) {
|
|
8573
|
-
notice(
|
|
8574
|
-
"\u672C\u7FA4\u5DF2\u8FDE\u63A5\u672C\u5730\u4F1A\u8BDD\uFF0C\u53EF\u76F4\u63A5\u4E0E\u76EE\u5F55 Agent \u5BF9\u8BDD\u3002\u5982\u9700\u63A5\u6536 Tim \u8F6C\u4EA4\u7684\u5DE5\u4F5C\uFF0C\u8BF7\u5728\u9879\u76EE\u548C\u76EE\u5F55\u8BBE\u7F6E\u4E2D\u5141\u8BB8\u8F6C\u4EA4\u3002"
|
|
8575
|
-
);
|
|
8703
|
+
notice("\u672C\u7FA4\u5DF2\u8FDE\u63A5\u672C\u5730\u4F1A\u8BDD\uFF0C\u53EF\u76F4\u63A5\u4E0E\u76EE\u5F55 Agent \u5BF9\u8BDD\u3002");
|
|
8576
8704
|
return;
|
|
8577
8705
|
}
|
|
8578
8706
|
if (bridge.group(bot, chat))
|
|
@@ -8776,7 +8904,7 @@ var WecomChannels = class {
|
|
|
8776
8904
|
const missingMentions = selected ? new AgentStore(this.hub).members(identity.workspaceId).filter(
|
|
8777
8905
|
(member) => !this.external(bot, String(selected.topic_id), identity.workspaceId, member)
|
|
8778
8906
|
) : [];
|
|
8779
|
-
const
|
|
8907
|
+
const failure3 = this.hub.db.prepare(
|
|
8780
8908
|
"SELECT error FROM wecom_deliveries WHERE bot_id=? AND project_id=? AND chat_type=3 AND state='pending' AND error IS NOT NULL ORDER BY rowid DESC LIMIT 1"
|
|
8781
8909
|
).get(bot, identity.workspaceId);
|
|
8782
8910
|
const incoming = selected ? this.hub.db.prepare(
|
|
@@ -8791,7 +8919,7 @@ var WecomChannels = class {
|
|
|
8791
8919
|
missingMentions,
|
|
8792
8920
|
refreshing: !state.error && (!state.updated_at || Number(state.due_at) === 0),
|
|
8793
8921
|
updatedAt: state.updated_at === null ? null : Number(state.updated_at),
|
|
8794
|
-
error: selected && !selected.present ? "\u673A\u5668\u4EBA\u5DF2\u4E0D\u5728\u8FD9\u4E2A\u9891\u9053\u4E2D\uFF0C\u8BF7\u91CD\u65B0\u52A0\u5165\u6216\u9009\u62E9\u5176\u4ED6\u9891\u9053\u3002" : String(
|
|
8922
|
+
error: selected && !selected.present ? "\u673A\u5668\u4EBA\u5DF2\u4E0D\u5728\u8FD9\u4E2A\u9891\u9053\u4E2D\uFF0C\u8BF7\u91CD\u65B0\u52A0\u5165\u6216\u9009\u62E9\u5176\u4ED6\u9891\u9053\u3002" : String(failure3?.error || incoming?.error || state.error || "") || null,
|
|
8795
8923
|
pending: Number(
|
|
8796
8924
|
this.hub.db.prepare(
|
|
8797
8925
|
"SELECT COUNT(*) n FROM wecom_deliveries WHERE bot_id=? AND project_id=? AND chat_type=3 AND state='pending'"
|
|
@@ -9366,9 +9494,11 @@ function settleBatch(hub, runId, state, error) {
|
|
|
9366
9494
|
import { randomUUID as randomUUID20 } from "node:crypto";
|
|
9367
9495
|
|
|
9368
9496
|
// apps/server/ai/retry.ts
|
|
9369
|
-
var MAX_AI_RETRIES =
|
|
9497
|
+
var MAX_AI_RETRIES = 5;
|
|
9498
|
+
var retryDelays = [5e3, 2e4, 6e4, 18e4, 6e5];
|
|
9370
9499
|
function aiRetryDelay(retryIndex, random = Math.random) {
|
|
9371
|
-
|
|
9500
|
+
const index = Math.max(0, Math.min(Math.floor(retryIndex), retryDelays.length - 1));
|
|
9501
|
+
return index === retryDelays.length - 1 ? retryDelays[index] : Math.round(retryDelays[index] * (0.8 + random() * 0.4));
|
|
9372
9502
|
}
|
|
9373
9503
|
|
|
9374
9504
|
// apps/server/agents/store.ts
|
|
@@ -9427,7 +9557,10 @@ var AgentStore = class {
|
|
|
9427
9557
|
chats: [
|
|
9428
9558
|
...this.hub.db.prepare(
|
|
9429
9559
|
`SELECT c.*,m.title matter_title,m.status matter_status,
|
|
9430
|
-
(
|
|
9560
|
+
COALESCE(
|
|
9561
|
+
(SELECT s.body FROM agent_messages s WHERE s.conversation_id=c.id AND s.role='user' ORDER BY s.seq DESC LIMIT 1),
|
|
9562
|
+
(SELECT s.body FROM agent_messages s WHERE s.conversation_id=c.id ORDER BY s.seq LIMIT 1)
|
|
9563
|
+
) title,
|
|
9431
9564
|
(SELECT state FROM project_agent_runs r WHERE r.conversation_id=c.id ORDER BY CASE WHEN state='running' THEN 0 WHEN state='queued' THEN 1 ELSE 2 END,r.rowid DESC LIMIT 1) state,
|
|
9432
9565
|
(SELECT MAX(updated_at) FROM project_agent_runs r WHERE r.conversation_id=c.id) updated_at,
|
|
9433
9566
|
NOT EXISTS(SELECT 1 FROM project_agent_recipients pr WHERE pr.message_id=n.message_id AND pr.user_id=c.owner AND pr.routing_silent=1) AND EXISTS(SELECT 1 FROM agent_messages s WHERE s.conversation_id=c.id AND s.role='assistant' AND s.state='succeeded' AND s.body<>'' AND s.seq>COALESCE(p.read_seq,n.read_seq,(SELECT read_seq FROM web_group_reads w WHERE w.conversation_id=c.id AND w.member_id=c.owner),0)) unread,
|
|
@@ -9451,10 +9584,11 @@ var AgentStore = class {
|
|
|
9451
9584
|
})),
|
|
9452
9585
|
...new WebGroups(this.hub).list(identity).map((row) => {
|
|
9453
9586
|
const messages = new AgentMessages(this.hub).list(String(row.id));
|
|
9587
|
+
const titleMessage = messages.filter((message) => message.role === "user").at(-1) ?? messages[0];
|
|
9454
9588
|
const read = this.hub.db.prepare("SELECT read_seq FROM web_group_reads WHERE conversation_id=? AND member_id=?").get(row.id, identity.memberId);
|
|
9455
9589
|
return {
|
|
9456
9590
|
id: String(row.id),
|
|
9457
|
-
title: `\u7FA4\u8BA8\u8BBA \xB7 ${
|
|
9591
|
+
title: `\u7FA4\u8BA8\u8BBA \xB7 ${titleMessage?.body.slice(0, 40) ?? "\u672A\u547D\u540D"}`,
|
|
9458
9592
|
kind: "group",
|
|
9459
9593
|
unread: messages.some((m) => m.seq > Number(read?.read_seq ?? 0)),
|
|
9460
9594
|
state: null,
|
|
@@ -9667,7 +9801,7 @@ var AgentStore = class {
|
|
|
9667
9801
|
if (!this.active(run)) return;
|
|
9668
9802
|
if (!error) answer = prCompletionAnswer(this.hub, run, answer);
|
|
9669
9803
|
this.hub.db.prepare("DELETE FROM agent_answer_drafts WHERE run_id=?").run(run.id);
|
|
9670
|
-
const retry = !!error && retryable && run.attempts <=
|
|
9804
|
+
const retry = !!error && retryable && run.attempts <= MAX_AI_RETRIES;
|
|
9671
9805
|
const state = retry ? "queued" : error ? "failed" : "succeeded";
|
|
9672
9806
|
if (error && !answer)
|
|
9673
9807
|
answer = String(
|
|
@@ -9829,12 +9963,12 @@ var AgentStore = class {
|
|
|
9829
9963
|
...routing?.context
|
|
9830
9964
|
}
|
|
9831
9965
|
};
|
|
9832
|
-
if (routing?.fixed) {
|
|
9966
|
+
if (routing?.fixed || value.to === "debug") {
|
|
9833
9967
|
for (const user of valid) {
|
|
9834
9968
|
const request = events.fixed(event, user, threads[user] ?? id, false);
|
|
9835
9969
|
const policy = events.policy(
|
|
9836
9970
|
{ workspaceId: project, memberId: user },
|
|
9837
|
-
routing
|
|
9971
|
+
value.to === "debug" ? "diagnostic" : routing?.category ?? "private.notice"
|
|
9838
9972
|
);
|
|
9839
9973
|
if (value.requiresHuman) policy.notify = true;
|
|
9840
9974
|
this.hub.db.prepare("UPDATE routing_requests SET policy_json=? WHERE id=?").run(JSON.stringify(policy), request);
|
|
@@ -9847,7 +9981,7 @@ var AgentStore = class {
|
|
|
9847
9981
|
const requests = events.route(
|
|
9848
9982
|
event,
|
|
9849
9983
|
valid,
|
|
9850
|
-
routing?.category ?? (value.
|
|
9984
|
+
routing?.category ?? (value.meaning === "request" ? "member.request" : "private.notice"),
|
|
9851
9985
|
value.requiresHuman
|
|
9852
9986
|
);
|
|
9853
9987
|
for (const request of requests) {
|
|
@@ -10179,6 +10313,27 @@ var ProjectActivitySchema = z29.object({
|
|
|
10179
10313
|
})
|
|
10180
10314
|
)
|
|
10181
10315
|
});
|
|
10316
|
+
var ProjectFaultSchema = z29.object({
|
|
10317
|
+
id: z29.string(),
|
|
10318
|
+
version: z29.string(),
|
|
10319
|
+
kind: z29.enum(["repository", "import", "tasks", "sessions", "materials", "project", "chat"]),
|
|
10320
|
+
state: z29.enum(["failed", "retrying"]),
|
|
10321
|
+
title: z29.string(),
|
|
10322
|
+
owner: z29.string().nullable(),
|
|
10323
|
+
error: z29.string(),
|
|
10324
|
+
attempts: z29.number().int().nonnegative(),
|
|
10325
|
+
nextRetryAt: z29.string().nullable(),
|
|
10326
|
+
occurredAt: z29.string().nullable(),
|
|
10327
|
+
diagnosticId: z29.string().nullable(),
|
|
10328
|
+
canReset: z29.boolean(),
|
|
10329
|
+
guidance: z29.string().nullable()
|
|
10330
|
+
});
|
|
10331
|
+
var ProjectHealthSchema = z29.object({
|
|
10332
|
+
worker: WorkerStatusSchema,
|
|
10333
|
+
modelAvailable: z29.boolean(),
|
|
10334
|
+
faults: z29.array(ProjectFaultSchema)
|
|
10335
|
+
});
|
|
10336
|
+
var ProjectFaultResetSchema = z29.object({ id: z29.string(), version: z29.string() }).strict();
|
|
10182
10337
|
|
|
10183
10338
|
// packages/protocol/bootstrap.ts
|
|
10184
10339
|
var SandboxStatusSchema = z30.object({
|
|
@@ -10442,7 +10597,7 @@ var ProjectWorkspace = class {
|
|
|
10442
10597
|
const credentialsIdentity = fingerprint2(
|
|
10443
10598
|
JSON.stringify(new AgentConfig(this.hub).secrets(this.project))
|
|
10444
10599
|
);
|
|
10445
|
-
if (exists && this.repoIdentity === identity && this.credentialsIdentity === credentialsIdentity && this.syncedAt && (config.fetchIntervalSeconds === null || Date.now() - this.syncedAt < config.fetchIntervalSeconds * 1e3))
|
|
10600
|
+
if (exists && new RuntimeStatus(this.hub).repository(this.project, identity).state !== "pending" && this.repoIdentity === identity && this.credentialsIdentity === credentialsIdentity && this.syncedAt && (config.fetchIntervalSeconds === null || Date.now() - this.syncedAt < config.fetchIntervalSeconds * 1e3))
|
|
10446
10601
|
return;
|
|
10447
10602
|
this.repoIdentity = identity;
|
|
10448
10603
|
this.credentialsIdentity = credentialsIdentity;
|
|
@@ -11726,6 +11881,10 @@ UPDATE routing_member_modes SET mode=CASE WHEN EXISTS (
|
|
|
11726
11881
|
))
|
|
11727
11882
|
) THEN 'managed' ELSE 'human' END WHERE mode='teammy';
|
|
11728
11883
|
`;
|
|
11884
|
+
var categoryHandlingMigration = `
|
|
11885
|
+
ALTER TABLE routing_policies ADD COLUMN auto_handle INTEGER NOT NULL DEFAULT 0;
|
|
11886
|
+
UPDATE routing_policies SET auto_handle=1 WHERE category IN('member.request','mr.review');
|
|
11887
|
+
`;
|
|
11729
11888
|
|
|
11730
11889
|
// apps/server/project-onboarding.ts
|
|
11731
11890
|
var projectOnboardingMigration = `
|
|
@@ -12025,6 +12184,12 @@ UPDATE member_agent_directories SET default_session=NULL WHERE NOT EXISTS(
|
|
|
12025
12184
|
var directorySessionDefaultsRemoval = `
|
|
12026
12185
|
ALTER TABLE member_agent_directories DROP COLUMN defaults_json;
|
|
12027
12186
|
`;
|
|
12187
|
+
var sessionVisibilityMigration = `
|
|
12188
|
+
ALTER TABLE member_agent_sessions ADD COLUMN hidden INTEGER NOT NULL DEFAULT 0;
|
|
12189
|
+
`;
|
|
12190
|
+
var sessionRewindMigration = `
|
|
12191
|
+
ALTER TABLE member_session_messages ADD COLUMN superseded_by TEXT;
|
|
12192
|
+
`;
|
|
12028
12193
|
|
|
12029
12194
|
// apps/server/session-library.ts
|
|
12030
12195
|
var columns = "id,workspace_id,owner,session_key,agent,native_id,cwd,title,revision,updated_at,message_count,hash,size";
|
|
@@ -13206,13 +13371,13 @@ function parseModelJson(text2) {
|
|
|
13206
13371
|
throw new SyntaxError("No complete final JSON value.");
|
|
13207
13372
|
}
|
|
13208
13373
|
function modelResultError(error, text2, message) {
|
|
13209
|
-
const
|
|
13210
|
-
|
|
13374
|
+
const failure3 = new HubError(422, "AI_RESULT_INVALID", message);
|
|
13375
|
+
failure3.cause = {
|
|
13211
13376
|
kind: error instanceof z38.ZodError ? "schema" : "json",
|
|
13212
13377
|
outputBytes: Buffer.byteLength(text2),
|
|
13213
13378
|
...error instanceof z38.ZodError ? { issues: error.issues.map(({ code, path }) => ({ code, path })) } : {}
|
|
13214
13379
|
};
|
|
13215
|
-
return
|
|
13380
|
+
return failure3;
|
|
13216
13381
|
}
|
|
13217
13382
|
|
|
13218
13383
|
// apps/server/ai/session-analysis.ts
|
|
@@ -13441,12 +13606,15 @@ function modelAccess(profile, key3, reasoning = false) {
|
|
|
13441
13606
|
function checkMessage(message) {
|
|
13442
13607
|
if (message.stopReason === "aborted")
|
|
13443
13608
|
throw new HubError(408, "AI_ABORTED", "Model request cancelled or timed out.");
|
|
13444
|
-
if (message.stopReason === "error")
|
|
13445
|
-
|
|
13609
|
+
if (message.stopReason === "error") {
|
|
13610
|
+
const error = new HubError(
|
|
13446
13611
|
502,
|
|
13447
13612
|
"AI_MODEL_ERROR",
|
|
13448
13613
|
"Model request failed; check endpoint, model and credentials."
|
|
13449
13614
|
);
|
|
13615
|
+
if (message.errorMessage) error.cause = new Error(message.errorMessage);
|
|
13616
|
+
throw error;
|
|
13617
|
+
}
|
|
13450
13618
|
if (message.stopReason === "length")
|
|
13451
13619
|
throw new HubError(
|
|
13452
13620
|
422,
|
|
@@ -17022,7 +17190,11 @@ var migrations = [
|
|
|
17022
17190
|
directorySessionDefaultsRemoval,
|
|
17023
17191
|
eventRoutingMigration,
|
|
17024
17192
|
unifiedRoutingModeMigration,
|
|
17025
|
-
explicitRoutingModeMigration
|
|
17193
|
+
explicitRoutingModeMigration,
|
|
17194
|
+
automaticDirectoryIntakeMigration,
|
|
17195
|
+
sessionVisibilityMigration,
|
|
17196
|
+
sessionRewindMigration,
|
|
17197
|
+
categoryHandlingMigration
|
|
17026
17198
|
];
|
|
17027
17199
|
var HubStore = class {
|
|
17028
17200
|
constructor(directory) {
|
|
@@ -18838,7 +19010,7 @@ async function runNativeAgent(profile, reader, key3, signal, progress, runtime,
|
|
|
18838
19010
|
const channel = new AgentChannel(child.stdout, child.stdin);
|
|
18839
19011
|
const active2 = new AbortController();
|
|
18840
19012
|
const requestSignal = AbortSignal.any([signal, active2.signal]);
|
|
18841
|
-
let
|
|
19013
|
+
let failure3, text2, rounds = 0;
|
|
18842
19014
|
const usage = { inputTokens: 0, outputTokens: 0 };
|
|
18843
19015
|
const stop = () => {
|
|
18844
19016
|
active2.abort();
|
|
@@ -18851,7 +19023,7 @@ async function runNativeAgent(profile, reader, key3, signal, progress, runtime,
|
|
|
18851
19023
|
};
|
|
18852
19024
|
const closed = new Promise((resolve6) => {
|
|
18853
19025
|
child.once("error", () => {
|
|
18854
|
-
|
|
19026
|
+
failure3 ??= new HubError(
|
|
18855
19027
|
503,
|
|
18856
19028
|
"AI_SANDBOX_UNAVAILABLE",
|
|
18857
19029
|
"Could not start Bubblewrap; check the Linux worker setup."
|
|
@@ -18859,7 +19031,7 @@ async function runNativeAgent(profile, reader, key3, signal, progress, runtime,
|
|
|
18859
19031
|
});
|
|
18860
19032
|
child.once("close", (code) => {
|
|
18861
19033
|
if (code !== 0 && !signal.aborted)
|
|
18862
|
-
|
|
19034
|
+
failure3 ??= new HubError(
|
|
18863
19035
|
503,
|
|
18864
19036
|
"AI_SANDBOX_FAILED",
|
|
18865
19037
|
"Sandbox exited unsuccessfully; check worker isolation support."
|
|
@@ -18914,7 +19086,7 @@ async function runNativeAgent(profile, reader, key3, signal, progress, runtime,
|
|
|
18914
19086
|
if (signal.aborted) stop();
|
|
18915
19087
|
for await (const message of channel.messages()) {
|
|
18916
19088
|
const task = handle(message).catch((error) => {
|
|
18917
|
-
|
|
19089
|
+
failure3 ??= error;
|
|
18918
19090
|
stop();
|
|
18919
19091
|
});
|
|
18920
19092
|
pending.add(task);
|
|
@@ -18923,14 +19095,14 @@ async function runNativeAgent(profile, reader, key3, signal, progress, runtime,
|
|
|
18923
19095
|
await closed;
|
|
18924
19096
|
await Promise.all(pending);
|
|
18925
19097
|
signal.throwIfAborted();
|
|
18926
|
-
if (
|
|
19098
|
+
if (failure3) throw failure3;
|
|
18927
19099
|
if (text2 === void 0) throw new HubError(422, "AI_RESULT_EMPTY", "No analysis result.");
|
|
18928
19100
|
return { text: text2, usage };
|
|
18929
19101
|
} catch (error) {
|
|
18930
19102
|
stop();
|
|
18931
19103
|
await closed;
|
|
18932
19104
|
signal.throwIfAborted();
|
|
18933
|
-
throw
|
|
19105
|
+
throw failure3 ?? error;
|
|
18934
19106
|
} finally {
|
|
18935
19107
|
signal.removeEventListener("abort", stop);
|
|
18936
19108
|
stop();
|
|
@@ -19354,7 +19526,7 @@ function resolveTaskFolders(hub, actor, paths2) {
|
|
|
19354
19526
|
// apps/server/member-execution/work.ts
|
|
19355
19527
|
var memberWorkDescriptions = {
|
|
19356
19528
|
retry_local_agent: "\u6062\u590D\u672C\u8F6E\u5F02\u5E38\u56DE\u62A5\u5BF9\u5E94\u7684\u539F\u672C\u5730\u4EA4\u63A5\uFF0C\u65E0\u9700\u53C2\u6570\u3002\u5BBF\u4E3B\u4FDD\u7559\u539F\u6210\u5458\u3001\u76EE\u5F55\u3001\u5185\u5BB9\u548C\u6388\u6743\uFF1B\u4EC5\u91CD\u8BD5\u786E\u5B9A\u672A\u63A5\u624B\u4E14\u5C1A\u672A\u8F6C\u7531\u4EBA\u627F\u63A5\u7684\u8BF7\u6C42\u3002\u5F53\u524D\u4E0D\u53EF\u63A5\u5355\u5219\u8FD4\u56DE\u539F\u56E0\uFF0C\u4E0D\u8865\u6D3E\uFF1B\u5DF2\u63A5\u624B\u4E0D\u91CD\u65B0\u6267\u884C\u3002\u91CD\u590D\u8C03\u7528\u590D\u7528\u540C\u4E00\u6B21\u6062\u590D\u3002",
|
|
19357
|
-
request_local_agent: "\u5C06\u5F53\u524D\u89D2\u8272\u8D1F\u8D23\u7684\u4E00\u6B21\u672C\u5730\u67E5\u8BE2\u6216\u6267\u884C\u4EA4\u7ED9\u6210\u5458\u76EE\u5F55 Agent\uFF0C\u5BF9\u8BE5\u672C\u5730\u8BF7\u6C42\u4E0D\u7B49\u5F85\u3001\u4E0D\u67E5\u8BE2\u6267\u884C\u7ED3\u679C\u3002\u6301\u7EED\u76EE\u6807\u7531\u4E8B\u9879\u8D1F\u8D23\u4EBA\u7EC4\u7EC7\u8FD9\u4E9B\u8BF7\u6C42\uFF0C\u4E0D\u7528\u672C\u5730\u8F6C\u4EA4\u4EE3\u66FF\u4E8B\u9879\u7EF4\u62A4\u3002\u7528\u6237\u53EF\u5728\u7F51\u9875\u300C\u7535\u8111\u300D\u7684\u5BF9\u5E94\u4F1A\u8BDD\u6216\u4F01\u4E1A\u5FAE\u4FE1\u4E13\u7528\u7FA4\uFF08\u5982\u5DF2\u7ED1\u5B9A\uFF09\u67E5\u770B\u7ED3\u679C\u5E76\u7EE7\u7EED\u5BF9\u8BDD\uFF0C\u53EA\u6709\u4EA4\u63A5\u5931\u8D25\u56DE\u8D1F\u8D23\u65B9\u3002text \u4FDD\u7559\u76EE\u5F55\u8303\u56F4\u548C\u7528\u6237\u9650\u5236\uFF0C\u5BBF\u4E3B\u9644\u539F\u8BDD\uFF1Bquery \u67E5\u8BE2\u5F53\u524D\u672C\u5730\u72B6\u6001\uFF0Crecord_only \u4EC5\u8BB0\u5F55\uFF0Cexecute \u6309\u8981\u6C42\u5B9E\u65BD\u3002\u660E\u786E\u76EE\u5F55\u65F6\u586B directory\uFF0C\u5426\u5219\u672C\u5730\u534F\u8C03\u8005\u9009\u62E9\uFF1B\u8C03\u5EA6\u53EA\u80FD\u9009\u62E9\u5DF2\
|
|
19529
|
+
request_local_agent: "\u5C06\u5F53\u524D\u89D2\u8272\u8D1F\u8D23\u7684\u4E00\u6B21\u672C\u5730\u67E5\u8BE2\u6216\u6267\u884C\u4EA4\u7ED9\u6210\u5458\u76EE\u5F55 Agent\uFF0C\u5BF9\u8BE5\u672C\u5730\u8BF7\u6C42\u4E0D\u7B49\u5F85\u3001\u4E0D\u67E5\u8BE2\u6267\u884C\u7ED3\u679C\u3002\u6301\u7EED\u76EE\u6807\u7531\u4E8B\u9879\u8D1F\u8D23\u4EBA\u7EC4\u7EC7\u8FD9\u4E9B\u8BF7\u6C42\uFF0C\u4E0D\u7528\u672C\u5730\u8F6C\u4EA4\u4EE3\u66FF\u4E8B\u9879\u7EF4\u62A4\u3002\u7528\u6237\u53EF\u5728\u7F51\u9875\u300C\u7535\u8111\u300D\u7684\u5BF9\u5E94\u4F1A\u8BDD\u6216\u4F01\u4E1A\u5FAE\u4FE1\u4E13\u7528\u7FA4\uFF08\u5982\u5DF2\u7ED1\u5B9A\uFF09\u67E5\u770B\u7ED3\u679C\u5E76\u7EE7\u7EED\u5BF9\u8BDD\uFF0C\u53EA\u6709\u4EA4\u63A5\u5931\u8D25\u56DE\u8D1F\u8D23\u65B9\u3002text \u4FDD\u7559\u76EE\u5F55\u8303\u56F4\u548C\u7528\u6237\u9650\u5236\uFF0C\u5BBF\u4E3B\u9644\u539F\u8BDD\uFF1Bquery \u67E5\u8BE2\u5F53\u524D\u672C\u5730\u72B6\u6001\uFF0Crecord_only \u4EC5\u8BB0\u5F55\uFF0Cexecute \u6309\u8981\u6C42\u5B9E\u65BD\u3002\u660E\u786E\u76EE\u5F55\u65F6\u586B directory\uFF0C\u5426\u5219\u672C\u5730\u534F\u8C03\u8005\u9009\u62E9\uFF1B\u8C03\u5EA6\u53EA\u80FD\u9009\u62E9\u5DF2\u5173\u8054\u4F1A\u8BDD\u3002\u5EF6\u7EED\u540C\u4E00\u5DE5\u4F5C\u65F6\uFF0CcontinueInput \u586B\u6B64\u524D\u4EA4\u63A5\u8FD4\u56DE\u7684 inputId\uFF1B\u65B0\u5DE5\u4F5C\u7701\u7565\uFF0C\u4E0D\u80FD\u5C06\u6574\u6BB5\u804A\u5929\u89C6\u4E3A\u540C\u4E00\u5DE5\u4F5C\u3002pending_acceptance \u8868\u793A\u5DF2\u767B\u8BB0\u6295\u9012\u3001\u5C1A\u672A\u786E\u8BA4\u63A5\u624B\uFF1Baccepted \u4EC5\u8868\u793A\u63A5\u624B\uFF1Bhuman_routed \u8868\u793A\u672A\u4EA4\u63A5\u4E14\u5DF2\u767B\u8BB0\u63D0\u793A\uFF0C\u4E0D\u91CD\u590D\u6D3E\u53D1\u3002\u4EFB\u52A1\u6587\u6863\u6574\u7406\u53EF\u53E6\u4EA4 task \u89D2\u8272\uFF1B\u6B64\u5DE5\u5177\u8D1F\u8D23\u672C\u5730\u4EA4\u63A5\u3002",
|
|
19358
19530
|
read_local_agent_messages: "\u4EC5\u5728\u5F53\u524D\u8BF7\u6C42\u660E\u786E\u8BE2\u95EE\u65E2\u6709\u5DE5\u4F5C\u7684\u8FDB\u5C55\u6216\u5386\u53F2\u53CD\u9988\u65F6\u8BFB\u53D6\u8BB0\u5F55\uFF0C\u4E0D\u7528\u4E8E\u4EA4\u63A5\u540E\u7684\u4F8B\u884C\u68C0\u67E5\u6216\u8865\u62A5\u3002\u8FD4\u56DE\u5386\u53F2\u8F93\u5165\u3001\u56DE\u590D\u3001\u65F6\u95F4\u548C\u6295\u9012\u72B6\u6001\uFF0C\u4E0D\u8BC1\u660E\u5F53\u524D\u6587\u4EF6\u72B6\u6001\uFF1B\u8BE2\u95EE\u5F53\u524D\u4EE3\u7801\u6216\u914D\u7F6E\u7528 request_local_agent \u4EA4\u7ED9\u672C\u5730\u68C0\u67E5\u3002\u672C\u4EBA\u79C1\u804A\u53EF\u67E5\u81EA\u5DF1\u7684\u76EE\u5F55\u6D88\u606F\uFF0C\u5176\u4ED6\u5165\u53E3\u53EA\u67E5\u5F53\u524D\u4F1A\u8BDD\u53D1\u8D77\u7684\u8F93\u5165\u53CA\u56DE\u590D\u3002member \u9ED8\u8BA4\u5F53\u524D\u53D1\u8A00\u8005\uFF0Cdirectory \u53EF\u586B\u540D\u79F0\u6216 ID\uFF0Cbefore \u5411\u524D\u7FFB\u9875\u3002\u63A5\u624B\u4E0D\u4EE3\u8868\u6B63\u5728\u6267\u884C\uFF0C\u65E0\u56DE\u590D\u4E0D\u4EE3\u8868\u4ECD\u5728\u8FD0\u884C\u3002"
|
|
19359
19531
|
};
|
|
19360
19532
|
function canRequestLocalAgent(hub, run) {
|
|
@@ -19362,8 +19534,8 @@ function canRequestLocalAgent(hub, run) {
|
|
|
19362
19534
|
return run.context_kind !== "material" && (!origin || origin.kind === "human");
|
|
19363
19535
|
}
|
|
19364
19536
|
function canRetryLocalAgent(hub, run) {
|
|
19365
|
-
const details2 = new Matters(hub).details(run),
|
|
19366
|
-
if (!
|
|
19537
|
+
const details2 = new Matters(hub).details(run), failure3 = details2.localHandoffFailure;
|
|
19538
|
+
if (!failure3 || failure3.retried || details2.routing?.inputKey !== `local-handoff-failed:${failure3.inputId}`)
|
|
19367
19539
|
return false;
|
|
19368
19540
|
return !!hub.db.prepare(
|
|
19369
19541
|
`
|
|
@@ -19375,7 +19547,7 @@ function canRetryLocalAgent(hub, run) {
|
|
|
19375
19547
|
AND i.state='human_routed' AND i.reason=?
|
|
19376
19548
|
`
|
|
19377
19549
|
).get(
|
|
19378
|
-
|
|
19550
|
+
failure3.inputId,
|
|
19379
19551
|
run.project_id,
|
|
19380
19552
|
run.conversation_id,
|
|
19381
19553
|
run.conversation_id,
|
|
@@ -19557,11 +19729,11 @@ var MemberWorks = class {
|
|
|
19557
19729
|
if (!canRetryLocalAgent(this.hub, run))
|
|
19558
19730
|
throw new HubError(403, "LOCAL_RETRY_UNAVAILABLE", "\u672C\u8F6E\u6CA1\u6709\u53EF\u6062\u590D\u7684\u672C\u5730\u4EA4\u63A5\u3002");
|
|
19559
19731
|
return diagnosticTransaction(this.hub, () => {
|
|
19560
|
-
const
|
|
19561
|
-
const row = this.hub.db.prepare("SELECT member_id FROM member_agent_inputs WHERE id=?").get(
|
|
19732
|
+
const failure3 = new Matters(this.hub).details(run).localHandoffFailure;
|
|
19733
|
+
const row = this.hub.db.prepare("SELECT member_id FROM member_agent_inputs WHERE id=?").get(failure3.inputId);
|
|
19562
19734
|
const identity = { workspaceId: run.project_id, memberId: String(row.member_id) };
|
|
19563
19735
|
requireProjectActor(this.hub, runActor(run), identity.memberId);
|
|
19564
|
-
const execution = new MemberExecution(this.hub), original = execution.input(identity,
|
|
19736
|
+
const execution = new MemberExecution(this.hub), original = execution.input(identity, failure3.inputId);
|
|
19565
19737
|
const operation = `local-retry:${original.id}`;
|
|
19566
19738
|
const prior = this.hub.db.prepare(
|
|
19567
19739
|
"SELECT id FROM member_agent_inputs WHERE project_id=? AND member_id=? AND operation=?"
|
|
@@ -20080,7 +20252,7 @@ async function mergePr(hub, run, input, signal) {
|
|
|
20080
20252
|
);
|
|
20081
20253
|
fence();
|
|
20082
20254
|
save({ ...attempt, status: "pending" });
|
|
20083
|
-
let
|
|
20255
|
+
let failure3;
|
|
20084
20256
|
try {
|
|
20085
20257
|
const result = await git2.merge(details2, input.method, signal);
|
|
20086
20258
|
if (result && merged(result))
|
|
@@ -20090,7 +20262,7 @@ async function mergePr(hub, run, input, signal) {
|
|
|
20090
20262
|
result.merged === true ? result.sha : void 0
|
|
20091
20263
|
);
|
|
20092
20264
|
} catch (error) {
|
|
20093
|
-
|
|
20265
|
+
failure3 = error;
|
|
20094
20266
|
}
|
|
20095
20267
|
if (!signal.aborted) {
|
|
20096
20268
|
try {
|
|
@@ -20099,12 +20271,12 @@ async function mergePr(hub, run, input, signal) {
|
|
|
20099
20271
|
} catch {
|
|
20100
20272
|
}
|
|
20101
20273
|
}
|
|
20102
|
-
if (
|
|
20103
|
-
save({ ...attempt, status: "rejected", upstreamStatus:
|
|
20274
|
+
if (failure3 instanceof GitHostError && [400, 401, 403, 404, 405, 409, 422].includes(failure3.upstreamStatus)) {
|
|
20275
|
+
save({ ...attempt, status: "rejected", upstreamStatus: failure3.upstreamStatus });
|
|
20104
20276
|
throw new HubError(
|
|
20105
20277
|
409,
|
|
20106
20278
|
"PR_MERGE_REJECTED",
|
|
20107
|
-
`\u5E73\u53F0\u62D2\u7EDD\u5408\u5E76\uFF08HTTP ${
|
|
20279
|
+
`\u5E73\u53F0\u62D2\u7EDD\u5408\u5E76\uFF08HTTP ${failure3.upstreamStatus}\uFF09\u3002\u8BF7\u6838\u5BF9\u51ED\u636E\u6743\u9650\u3001\u5F53\u524D\u63D0\u4EA4\u3001\u5206\u652F\u4FDD\u62A4\u3001\u5BA1\u6279\u53CA\u68C0\u67E5\u72B6\u6001\uFF1B\u672A\u7ED5\u8FC7\u5E73\u53F0\u89C4\u5219\u3002`
|
|
20108
20280
|
);
|
|
20109
20281
|
}
|
|
20110
20282
|
signal.throwIfAborted();
|
|
@@ -20792,6 +20964,8 @@ function projectInputContext(hub, run) {
|
|
|
20792
20964
|
// apps/server/agents/runtime.ts
|
|
20793
20965
|
function retryableAgentError(error) {
|
|
20794
20966
|
if (error instanceof z64.ZodError) return true;
|
|
20967
|
+
if (error instanceof HubError && error.code === "AI_MODEL_ERROR" && error.cause)
|
|
20968
|
+
return retryableAgentError(error.cause);
|
|
20795
20969
|
if (error instanceof GitHostError)
|
|
20796
20970
|
return error.upstreamStatus === 429 || error.upstreamStatus >= 500;
|
|
20797
20971
|
if (error instanceof HubError && ["AGENT_GITHUB_FORMAT", "AGENT_GIT_FORMAT", "PR_MERGE_UNCERTAIN"].includes(error.code))
|
|
@@ -21962,7 +22136,7 @@ function registerWeb(server, root) {
|
|
|
21962
22136
|
}
|
|
21963
22137
|
|
|
21964
22138
|
// apps/server/server.ts
|
|
21965
|
-
import { randomUUID as
|
|
22139
|
+
import { randomUUID as randomUUID39 } from "node:crypto";
|
|
21966
22140
|
import Fastify from "fastify";
|
|
21967
22141
|
|
|
21968
22142
|
// packages/protocol/index.ts
|
|
@@ -22065,29 +22239,60 @@ function registerControlRoutes(server, store) {
|
|
|
22065
22239
|
import { z as z73 } from "zod";
|
|
22066
22240
|
|
|
22067
22241
|
// apps/server/project-activity.ts
|
|
22068
|
-
function
|
|
22069
|
-
const db = hub.db, project = identity.workspaceId;
|
|
22070
|
-
const
|
|
22071
|
-
|
|
22072
|
-
|
|
22073
|
-
|
|
22074
|
-
|
|
22075
|
-
|
|
22242
|
+
function projectWork(hub, identity) {
|
|
22243
|
+
const db = hub.db, project = identity.workspaceId, items = [];
|
|
22244
|
+
const add = (kind2, row, title2, reset = false) => {
|
|
22245
|
+
if (!["queued", "running", "failed"].includes(String(row.state))) return;
|
|
22246
|
+
items.push({
|
|
22247
|
+
id: `${kind2}:${row.id}`,
|
|
22248
|
+
kind: kind2,
|
|
22249
|
+
state: row.state,
|
|
22250
|
+
title: title2,
|
|
22251
|
+
owner: row.owner == null ? null : String(row.owner),
|
|
22252
|
+
operation: row.operation == null ? null : String(row.operation),
|
|
22253
|
+
attempts: Number(row.attempts ?? 0),
|
|
22254
|
+
dueAt: Number(row.due_at) || null,
|
|
22255
|
+
error: row.error == null ? null : String(row.error),
|
|
22256
|
+
reset,
|
|
22257
|
+
stamp: fingerprint2(JSON.stringify(row))
|
|
22258
|
+
});
|
|
22076
22259
|
};
|
|
22077
22260
|
const runtime = new RuntimeStatus(hub);
|
|
22078
22261
|
const url = new AgentConfig(hub).get(project).repositoryUrl;
|
|
22079
22262
|
const repository = runtime.repository(project, url ? fingerprint2(url) : null);
|
|
22080
|
-
const importing = db.prepare("SELECT
|
|
22263
|
+
const importing = db.prepare("SELECT * FROM project_workspace_imports WHERE project_id=?").get(project);
|
|
22081
22264
|
if (repository.state === "cloning" || repository.state === "fetching")
|
|
22082
|
-
add("repository", "running");
|
|
22083
|
-
else if (importing
|
|
22084
|
-
add(
|
|
22085
|
-
|
|
22086
|
-
|
|
22087
|
-
|
|
22265
|
+
add("repository", { id: project, state: "running" }, "\u53C2\u8003\u4ED3\u5E93\u540C\u6B65");
|
|
22266
|
+
else if (importing && ["pending", "running", "failed"].includes(String(importing.state)))
|
|
22267
|
+
add(
|
|
22268
|
+
"import",
|
|
22269
|
+
{
|
|
22270
|
+
...importing,
|
|
22271
|
+
id: importing.request_id,
|
|
22272
|
+
state: importing.state === "pending" ? "queued" : importing.state,
|
|
22273
|
+
owner: importing.requester
|
|
22274
|
+
},
|
|
22275
|
+
"\u5DE5\u4F5C\u533A\u5BFC\u5165",
|
|
22276
|
+
true
|
|
22277
|
+
);
|
|
22278
|
+
else if (repository.state === "failed" || repository.state === "interrupted") {
|
|
22279
|
+
const row = db.prepare("SELECT * FROM runtime_repositories WHERE project_id=?").get(project);
|
|
22280
|
+
add(
|
|
22281
|
+
"repository",
|
|
22282
|
+
{
|
|
22283
|
+
...row,
|
|
22284
|
+
id: project,
|
|
22285
|
+
state: "failed",
|
|
22286
|
+
error: repository.state === "interrupted" ? "\u4ED3\u5E93\u540C\u6B65\u8FDB\u7A0B\u672A\u54CD\u5E94\uFF0C\u8BF7\u68C0\u67E5 Worker\u3002" : "\u53C2\u8003\u4ED3\u5E93\u540C\u6B65\u5931\u8D25\u3002"
|
|
22287
|
+
},
|
|
22288
|
+
"\u53C2\u8003\u4ED3\u5E93\u540C\u6B65",
|
|
22289
|
+
repository.state === "failed"
|
|
22290
|
+
);
|
|
22291
|
+
}
|
|
22088
22292
|
const members = db.prepare(
|
|
22089
|
-
`SELECT
|
|
22090
|
-
|
|
22293
|
+
`SELECT m.member_id owner,j.id,'ai:'||j.id operation,j.attempt_count attempts,
|
|
22294
|
+
j.next_retry_at due_at,j.error,j.updated_at,
|
|
22295
|
+
CASE WHEN j.status IN ('queued','running') THEN j.status
|
|
22091
22296
|
WHEN b.job_id IS NULL AND EXISTS(SELECT 1 FROM current_files f WHERE f.workspace_id=m.workspace_id AND f.owner=m.member_id) THEN 'queued'
|
|
22092
22297
|
WHEN j.status IN ('succeeded','failed','cancelled') AND
|
|
22093
22298
|
(json_extract(j.snapshot_json,'$.revision')<m.file_revision OR
|
|
@@ -22098,41 +22303,187 @@ function projectActivity(hub, identity) {
|
|
|
22098
22303
|
LEFT JOIN ai_jobs j ON j.id=b.job_id LEFT JOIN project_files pf ON pf.workspace_id=m.workspace_id
|
|
22099
22304
|
WHERE m.workspace_id=? AND m.enabled=1 AND u.enabled=1`
|
|
22100
22305
|
).all(project);
|
|
22101
|
-
for (const row of members) add("tasks", row
|
|
22102
|
-
const
|
|
22103
|
-
`SELECT j.status
|
|
22306
|
+
for (const row of members) add("tasks", row, "\u4EFB\u52A1\u770B\u677F\u6574\u7406", true);
|
|
22307
|
+
const sessions2 = db.prepare(
|
|
22308
|
+
`SELECT j.id,j.owner,j.kind,j.status state,j.attempts,j.due_at,j.error,
|
|
22309
|
+
j.source_revision,'session:'||j.id operation,s.title,s.native_id
|
|
22310
|
+
FROM session_analysis_jobs j
|
|
22104
22311
|
JOIN members m ON m.workspace_id=j.workspace_id AND m.member_id=j.owner JOIN users u ON u.id=m.member_id
|
|
22312
|
+
LEFT JOIN sessions s ON s.workspace_id=j.workspace_id AND s.owner=j.owner AND s.session_key=j.session_key
|
|
22105
22313
|
WHERE j.workspace_id=? AND m.enabled=1 AND u.enabled=1 AND j.status!='superseded'
|
|
22106
22314
|
AND NOT EXISTS(SELECT 1 FROM session_analysis_jobs n WHERE n.workspace_id=j.workspace_id
|
|
22107
22315
|
AND n.owner=j.owner AND n.session_key=j.session_key AND n.kind=j.kind AND n.source_revision>j.source_revision)`
|
|
22108
22316
|
).all(project);
|
|
22109
|
-
for (const row of
|
|
22317
|
+
for (const row of sessions2)
|
|
22318
|
+
add(
|
|
22319
|
+
"sessions",
|
|
22320
|
+
row,
|
|
22321
|
+
`${row.title || row.native_id || "\u4F1A\u8BDD"} \xB7 ${row.kind === "handoff" ? "\u4EA4\u63A5\u8BF4\u660E" : "\u6982\u89C8"}`,
|
|
22322
|
+
true
|
|
22323
|
+
);
|
|
22110
22324
|
const materials3 = db.prepare(
|
|
22111
|
-
`SELECT
|
|
22112
|
-
|
|
22113
|
-
|
|
22114
|
-
|
|
22115
|
-
|
|
22116
|
-
|
|
22325
|
+
`SELECT m.id,m.title,m.submitted_by owner,COALESCE(m.error,r.error) error,
|
|
22326
|
+
r.attempts,r.due_at,m.revision,'agent:'||r.id operation,
|
|
22327
|
+
CASE m.state WHEN 'waiting' THEN 'queued' WHEN 'failed' THEN 'failed'
|
|
22328
|
+
WHEN 'running' THEN CASE WHEN r.state IN ('queued','failed') THEN r.state ELSE 'running' END END state
|
|
22329
|
+
FROM materials m LEFT JOIN project_agent_runs r ON r.id=m.run_id
|
|
22330
|
+
WHERE m.project_id=? AND m.state!='ready'`
|
|
22117
22331
|
).all(project);
|
|
22118
|
-
for (const row of materials3) add("materials", row.
|
|
22332
|
+
for (const row of materials3) add("materials", row, String(row.title || "\u8D44\u6599\u6574\u7406"), true);
|
|
22119
22333
|
const inputs = db.prepare(
|
|
22120
|
-
`SELECT state
|
|
22121
|
-
|
|
22334
|
+
`SELECT i.task_id id,i.state,r.error,r.attempts,r.due_at,r.updated_at,
|
|
22335
|
+
'agent:'||r.id operation FROM project_agent_inbox i
|
|
22336
|
+
LEFT JOIN project_agent_runs r ON r.task_id=i.task_id AND r.conversation_id IN
|
|
22337
|
+
(SELECT id FROM project_agent_conversations WHERE project_id=i.project_id AND role='lifetime')
|
|
22338
|
+
WHERE i.project_id=? AND (i.state IN ('queued','running') OR i.task_id=(SELECT MAX(task_id) FROM project_agent_inbox WHERE project_id=?))`
|
|
22122
22339
|
).all(project, project);
|
|
22123
|
-
for (const row of inputs) add("project", row.
|
|
22340
|
+
for (const row of inputs) add("project", row, `\u9879\u76EE\u5206\u6790 #${row.id}`, !!row.operation);
|
|
22124
22341
|
const chats = db.prepare(
|
|
22125
|
-
`SELECT r.state
|
|
22126
|
-
|
|
22342
|
+
`SELECT r.id,r.state,c.owner,r.error,r.attempts,r.due_at,'agent:'||r.id operation
|
|
22343
|
+
FROM project_agent_runs r JOIN project_agent_conversations c ON c.id=r.conversation_id
|
|
22344
|
+
WHERE c.project_id=? AND (c.owner=? OR EXISTS(SELECT 1 FROM agent_matter_members m WHERE m.conversation_id=c.id AND m.member_id=?))
|
|
22345
|
+
AND c.role='instant' AND r.state IN ('queued','running')`
|
|
22127
22346
|
).all(project, identity.memberId, identity.memberId);
|
|
22128
|
-
for (const row of chats) add("chat", row
|
|
22347
|
+
for (const row of chats) add("chat", row, "\u5BF9\u8BDD\u56DE\u590D");
|
|
22348
|
+
return items;
|
|
22349
|
+
}
|
|
22350
|
+
function projectActivity(hub, identity) {
|
|
22351
|
+
const activities = [];
|
|
22352
|
+
for (const item of projectWork(hub, identity)) {
|
|
22353
|
+
const prior = activities.find((a) => a.kind === item.kind && a.state === item.state);
|
|
22354
|
+
if (prior) prior.count++;
|
|
22355
|
+
else activities.push({ kind: item.kind, state: item.state, count: 1 });
|
|
22356
|
+
}
|
|
22129
22357
|
return ProjectActivitySchema.parse({
|
|
22130
|
-
worker:
|
|
22131
|
-
modelAvailable: new AiDefaults(hub).project(
|
|
22358
|
+
worker: new RuntimeStatus(hub).worker().state,
|
|
22359
|
+
modelAvailable: new AiDefaults(hub).project(identity.workspaceId).available,
|
|
22132
22360
|
activities
|
|
22133
22361
|
});
|
|
22134
22362
|
}
|
|
22135
22363
|
|
|
22364
|
+
// apps/server/project-health.ts
|
|
22365
|
+
import { randomUUID as randomUUID35 } from "node:crypto";
|
|
22366
|
+
function failure2(hub, project, item) {
|
|
22367
|
+
const code = item.kind === "repository" ? "REPOSITORY_FAILED" : item.kind === "import" ? "WORKSPACE_IMPORT_FAILED" : null;
|
|
22368
|
+
const log = item.operation ? hub.db.prepare(
|
|
22369
|
+
`SELECT id,record_json FROM diagnostic_records WHERE project_id=? AND operation=?
|
|
22370
|
+
AND json_extract(record_json,'$.diagnostic.error') IS NOT NULL ORDER BY rowid DESC LIMIT 1`
|
|
22371
|
+
).get(project, item.operation) : code ? hub.db.prepare(
|
|
22372
|
+
`SELECT id,record_json FROM diagnostic_records WHERE project_id=? AND code=? ORDER BY rowid DESC LIMIT 1`
|
|
22373
|
+
).get(project, code) : null;
|
|
22374
|
+
const record = log ? JSON.parse(String(log.record_json)) : null;
|
|
22375
|
+
const error = record?.diagnostic?.error;
|
|
22376
|
+
const message = typeof error === "string" ? error : error?.cause?.message || error?.message;
|
|
22377
|
+
const fallback = new Diagnostics(hub).sanitize(item.error || "\u5904\u7406\u672A\u5B8C\u6210\u3002", project);
|
|
22378
|
+
return {
|
|
22379
|
+
id: item.id,
|
|
22380
|
+
version: `${item.stamp}:${log?.id ?? ""}`,
|
|
22381
|
+
kind: item.kind,
|
|
22382
|
+
state: item.state === "failed" ? "failed" : "retrying",
|
|
22383
|
+
title: item.title,
|
|
22384
|
+
owner: item.owner,
|
|
22385
|
+
error: message || (typeof fallback === "string" ? fallback : "\u8BE6\u7EC6\u9519\u8BEF\u6682\u4E0D\u53EF\u8BFB\u53D6\u3002"),
|
|
22386
|
+
attempts: item.attempts,
|
|
22387
|
+
nextRetryAt: item.state === "queued" && item.dueAt ? new Date(item.dueAt).toISOString() : null,
|
|
22388
|
+
occurredAt: record?.timestamp ?? null,
|
|
22389
|
+
diagnosticId: log ? String(log.id) : null,
|
|
22390
|
+
canReset: item.state === "failed" && item.reset,
|
|
22391
|
+
guidance: item.kind === "project" ? "\u5728\u539F\u4F1A\u8BDD\u91CD\u8BD5\uFF1B\u5982\u6D89\u53CA\u8BC4\u8BBA\u3001\u5408\u5E76\u7B49\u5916\u90E8\u64CD\u4F5C\uFF0C\u8BF7\u5148\u6838\u5BF9\u6267\u884C\u7ED3\u679C\u3002" : !item.reset ? "\u8BF7\u68C0\u67E5\u5BF9\u5E94\u670D\u52A1\u4E0E\u8FDE\u63A5\uFF0C\u6062\u590D\u540E\u72B6\u6001\u4F1A\u81EA\u52A8\u66F4\u65B0\u3002" : null
|
|
22392
|
+
};
|
|
22393
|
+
}
|
|
22394
|
+
function projectHealth(hub, identity) {
|
|
22395
|
+
requireSiteAdmin(identity);
|
|
22396
|
+
return ProjectHealthSchema.parse({
|
|
22397
|
+
worker: new RuntimeStatus(hub).worker(),
|
|
22398
|
+
modelAvailable: new AiDefaults(hub).project(identity.workspaceId).available,
|
|
22399
|
+
faults: projectWork(hub, identity).filter(
|
|
22400
|
+
(item) => item.state === "failed" || item.state === "queued" && item.error && item.dueAt
|
|
22401
|
+
).map((item) => failure2(hub, identity.workspaceId, item)).sort(
|
|
22402
|
+
(a, b) => Number(a.state !== "failed") - Number(b.state !== "failed") || (b.occurredAt ?? "").localeCompare(a.occurredAt ?? "") || a.id.localeCompare(b.id)
|
|
22403
|
+
)
|
|
22404
|
+
});
|
|
22405
|
+
}
|
|
22406
|
+
function resetProjectFault(hub, identity, id, version2) {
|
|
22407
|
+
requireSiteAdmin(identity);
|
|
22408
|
+
const find = () => {
|
|
22409
|
+
const item = projectWork(hub, identity).find((item2) => item2.id === id);
|
|
22410
|
+
if (!item || item.state !== "failed" || failure2(hub, identity.workspaceId, item).version !== version2)
|
|
22411
|
+
throw new HubError(409, "FAULT_CHANGED", "\u72B6\u6001\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u67E5\u770B\u3002");
|
|
22412
|
+
if (!item.reset) throw new HubError(409, "FAULT_NOT_RESETTABLE", "\u8BF7\u5148\u6062\u590D\u5BF9\u5E94\u670D\u52A1\u6216\u8FDE\u63A5\u3002");
|
|
22413
|
+
return item;
|
|
22414
|
+
};
|
|
22415
|
+
const audit = (item) => new Diagnostics(hub).record({
|
|
22416
|
+
project: identity.workspaceId,
|
|
22417
|
+
operation: item.operation ?? item.id,
|
|
22418
|
+
owner: item.owner ?? void 0,
|
|
22419
|
+
code: "RUN_RESET",
|
|
22420
|
+
details: { administrator: identity.memberId, fault: id }
|
|
22421
|
+
});
|
|
22422
|
+
const first = find();
|
|
22423
|
+
if (first.kind === "tasks") {
|
|
22424
|
+
new AiJobs(hub).retry(identity, id.slice("tasks:".length), randomUUID35());
|
|
22425
|
+
audit(first);
|
|
22426
|
+
} else
|
|
22427
|
+
transaction(hub.db, () => {
|
|
22428
|
+
const item = find(), project = identity.workspaceId, key3 = id.slice(item.kind.length + 1);
|
|
22429
|
+
switch (item.kind) {
|
|
22430
|
+
case "sessions":
|
|
22431
|
+
hub.db.prepare(
|
|
22432
|
+
`UPDATE session_analysis_jobs SET status='queued',attempts=0,due_at=?,error=NULL,
|
|
22433
|
+
runtime_json=NULL,profile_json=NULL,checkpoint_json=NULL,run_token=NULL,lease_until=NULL
|
|
22434
|
+
WHERE workspace_id=? AND id=? AND status='failed'`
|
|
22435
|
+
).run(Date.now(), project, key3);
|
|
22436
|
+
break;
|
|
22437
|
+
case "materials":
|
|
22438
|
+
hub.db.prepare(
|
|
22439
|
+
"UPDATE materials SET state='waiting',error=NULL,run_id=NULL WHERE project_id=? AND id=?"
|
|
22440
|
+
).run(project, key3);
|
|
22441
|
+
break;
|
|
22442
|
+
case "import": {
|
|
22443
|
+
const imports = new WorkspaceImports(hub);
|
|
22444
|
+
imports.request(identity, project, imports.status(project).source);
|
|
22445
|
+
break;
|
|
22446
|
+
}
|
|
22447
|
+
case "repository":
|
|
22448
|
+
hub.db.prepare(
|
|
22449
|
+
"UPDATE runtime_repositories SET state='pending',attempt=?,last_seen=? WHERE project_id=?"
|
|
22450
|
+
).run(randomUUID35(), Date.now(), project);
|
|
22451
|
+
break;
|
|
22452
|
+
case "project": {
|
|
22453
|
+
const runId = item.operation.slice("agent:".length);
|
|
22454
|
+
const run = hub.db.prepare("SELECT * FROM project_agent_runs WHERE id=?").get(runId);
|
|
22455
|
+
hub.db.prepare(
|
|
22456
|
+
`UPDATE project_agent_runs SET state='queued',attempts=0,due_at=0,error=NULL,
|
|
22457
|
+
run_token=NULL,lease_until=NULL,updated_at=? WHERE id=?`
|
|
22458
|
+
).run((/* @__PURE__ */ new Date()).toISOString(), runId);
|
|
22459
|
+
hub.db.prepare(
|
|
22460
|
+
"UPDATE project_agent_inbox SET state='queued' WHERE project_id=? AND task_id=?"
|
|
22461
|
+
).run(project, key3);
|
|
22462
|
+
hub.db.prepare(
|
|
22463
|
+
`UPDATE routing_requests SET state='waiting',outcome=NULL,response_json=NULL,ended_at=NULL
|
|
22464
|
+
WHERE state='ended' AND outcome='failed' AND json_extract(response_json,'$.run')=?
|
|
22465
|
+
AND event_id IN (SELECT id FROM routing_events WHERE project_id=?)`
|
|
22466
|
+
).run(runId, project);
|
|
22467
|
+
new AgentStore(hub).event(String(run.conversation_id), "state", {
|
|
22468
|
+
id: runId,
|
|
22469
|
+
state: "queued",
|
|
22470
|
+
error: null,
|
|
22471
|
+
answer: run.answer
|
|
22472
|
+
});
|
|
22473
|
+
new AgentMessages(hub).answer(
|
|
22474
|
+
String(run.conversation_id),
|
|
22475
|
+
runId,
|
|
22476
|
+
String(run.answer),
|
|
22477
|
+
"queued"
|
|
22478
|
+
);
|
|
22479
|
+
break;
|
|
22480
|
+
}
|
|
22481
|
+
}
|
|
22482
|
+
audit(item);
|
|
22483
|
+
});
|
|
22484
|
+
return projectHealth(hub, identity);
|
|
22485
|
+
}
|
|
22486
|
+
|
|
22136
22487
|
// apps/server/project-routes.ts
|
|
22137
22488
|
function registerProjectRoutes(server, store) {
|
|
22138
22489
|
const project = new ProjectRepository(store), site = new SiteRepository(store);
|
|
@@ -22162,6 +22513,15 @@ function registerProjectScopeRoutes(server, store) {
|
|
|
22162
22513
|
"/project/activity",
|
|
22163
22514
|
async (request) => projectActivity(store, authorizeWeb(store, request))
|
|
22164
22515
|
);
|
|
22516
|
+
server.get(
|
|
22517
|
+
"/project/health",
|
|
22518
|
+
async (request) => projectHealth(store, authorizeWeb(store, request))
|
|
22519
|
+
);
|
|
22520
|
+
server.post("/project/health/reset", async (request) => {
|
|
22521
|
+
webMutation(request);
|
|
22522
|
+
const input = ProjectFaultResetSchema.parse(request.body);
|
|
22523
|
+
return resetProjectFault(store, authorizeWeb(store, request), input.id, input.version);
|
|
22524
|
+
});
|
|
22165
22525
|
server.get(
|
|
22166
22526
|
"/project/workspace-import",
|
|
22167
22527
|
async (request) => new WorkspaceImports(store).status(authorizeWeb(store, request).workspaceId)
|
|
@@ -22935,7 +23295,7 @@ data: ${event.data}
|
|
|
22935
23295
|
return {
|
|
22936
23296
|
messages: store.chats(identity).chats.filter((c) => "unread" in c && c.unread).length + store.messages(identity).messages.filter((m) => !m.conversationId && !m.readAt && !m.archivedAt).length,
|
|
22937
23297
|
channels: topics.list(identity).topics.filter((t) => t.unread).length,
|
|
22938
|
-
computers: new MemberSessions(hub).list(identity).filter((s) => s.unread).length
|
|
23298
|
+
computers: new MemberSessions(hub).list(identity).filter((s) => !s.hidden && s.unread).length
|
|
22939
23299
|
};
|
|
22940
23300
|
});
|
|
22941
23301
|
server.get("/agents/outbox/unread", async (req) => {
|
|
@@ -23202,11 +23562,11 @@ function registerClientRelease(server) {
|
|
|
23202
23562
|
import { z as z83 } from "zod";
|
|
23203
23563
|
|
|
23204
23564
|
// apps/server/wecom/runtime.ts
|
|
23205
|
-
import { randomUUID as
|
|
23565
|
+
import { randomUUID as randomUUID38 } from "node:crypto";
|
|
23206
23566
|
import "@wecom/aibot-node-sdk";
|
|
23207
23567
|
|
|
23208
23568
|
// apps/server/wecom/store.ts
|
|
23209
|
-
import { createHash as createHash28, randomBytes as randomBytes12, randomUUID as
|
|
23569
|
+
import { createHash as createHash28, randomBytes as randomBytes12, randomUUID as randomUUID36 } from "node:crypto";
|
|
23210
23570
|
import { z as z82 } from "zod";
|
|
23211
23571
|
var hash2 = (text2) => createHash28("sha256").update(text2).digest("hex");
|
|
23212
23572
|
var referencePattern = /\bTM-([A-F0-9]{12})\b/i;
|
|
@@ -23306,7 +23666,7 @@ var WecomStore = class {
|
|
|
23306
23666
|
`INSERT OR IGNORE INTO wecom_deliveries
|
|
23307
23667
|
(id,bot_id,external_id,user_id,project_id,kind,source_id,reference,body,created_at) VALUES(?,?,?,?,?,?,?,?,?,?)`
|
|
23308
23668
|
).run(
|
|
23309
|
-
|
|
23669
|
+
randomUUID36(),
|
|
23310
23670
|
bot,
|
|
23311
23671
|
external,
|
|
23312
23672
|
identity?.memberId ?? null,
|
|
@@ -23623,7 +23983,7 @@ ${text2}` : text2;
|
|
|
23623
23983
|
|
|
23624
23984
|
// apps/server/wecom/transport.ts
|
|
23625
23985
|
import { EventEmitter } from "node:events";
|
|
23626
|
-
import { randomUUID as
|
|
23986
|
+
import { randomUUID as randomUUID37 } from "node:crypto";
|
|
23627
23987
|
import WebSocket2 from "ws";
|
|
23628
23988
|
var WecomTransport = class extends EventEmitter {
|
|
23629
23989
|
constructor(options, open5 = () => new WebSocket2("wss://openws.work.weixin.qq.com", { handshakeTimeout: 15e3 })) {
|
|
@@ -23653,7 +24013,7 @@ var WecomTransport = class extends EventEmitter {
|
|
|
23653
24013
|
socket.addEventListener("open", () => {
|
|
23654
24014
|
if (this.socket !== socket || this.stopped) return;
|
|
23655
24015
|
void this.reply(
|
|
23656
|
-
{ headers: { req_id:
|
|
24016
|
+
{ headers: { req_id: randomUUID37() } },
|
|
23657
24017
|
{ bot_id: this.options.botId, secret: this.options.secret },
|
|
23658
24018
|
"aibot_subscribe"
|
|
23659
24019
|
).then((frame) => {
|
|
@@ -23662,7 +24022,7 @@ var WecomTransport = class extends EventEmitter {
|
|
|
23662
24022
|
this.attempts = 0;
|
|
23663
24023
|
this.emit("authenticated");
|
|
23664
24024
|
this.heartbeat = setInterval(() => {
|
|
23665
|
-
void this.reply({ headers: { req_id:
|
|
24025
|
+
void this.reply({ headers: { req_id: randomUUID37() } }, {}, "ping").then((result) => {
|
|
23666
24026
|
if (result.errcode !== 0) socket.close();
|
|
23667
24027
|
}).catch(() => socket.close());
|
|
23668
24028
|
}, 25e3);
|
|
@@ -24257,7 +24617,7 @@ var WecomRuntime = class {
|
|
|
24257
24617
|
}
|
|
24258
24618
|
hub;
|
|
24259
24619
|
factory;
|
|
24260
|
-
owner =
|
|
24620
|
+
owner = randomUUID38();
|
|
24261
24621
|
store;
|
|
24262
24622
|
client;
|
|
24263
24623
|
revision = 0;
|
|
@@ -24324,7 +24684,7 @@ var WecomRuntime = class {
|
|
|
24324
24684
|
this.hub,
|
|
24325
24685
|
async (cmd, body) => {
|
|
24326
24686
|
if (!channelActive() || !this.own()) throw new Error("\u4F01\u4E1A\u5FAE\u4FE1\u8FDE\u63A5\u5DF2\u53D8\u66F4\u3002");
|
|
24327
|
-
const response = await client2.reply({ headers: { req_id:
|
|
24687
|
+
const response = await client2.reply({ headers: { req_id: randomUUID38() } }, body, cmd);
|
|
24328
24688
|
if (!channelActive()) throw new Error("\u4F01\u4E1A\u5FAE\u4FE1\u8FDE\u63A5\u5DF2\u53D8\u66F4\u3002");
|
|
24329
24689
|
return response;
|
|
24330
24690
|
},
|
|
@@ -24697,6 +25057,7 @@ function registerEventRouting(server, hub) {
|
|
|
24697
25057
|
outcome: r.outcome ? String(r.outcome) : null,
|
|
24698
25058
|
body: String(r.body),
|
|
24699
25059
|
kind: String(r.kind),
|
|
25060
|
+
category: JSON.parse(String(r.policy_json)).category,
|
|
24700
25061
|
createdAt: String(r.created_at),
|
|
24701
25062
|
revision: Number(r.revision),
|
|
24702
25063
|
canReassign: routing.canReassign(r),
|
|
@@ -24994,11 +25355,11 @@ data: ${JSON.stringify(snapshot)}
|
|
|
24994
25355
|
providers: config?.providers ?? [],
|
|
24995
25356
|
catalogs: config?.catalogs ?? [],
|
|
24996
25357
|
directories: store.directories(identity),
|
|
24997
|
-
sessions: sessions2.list(identity)
|
|
25358
|
+
sessions: sessions2.list(identity).filter((session) => !session.hidden)
|
|
24998
25359
|
};
|
|
24999
25360
|
});
|
|
25000
25361
|
server.get("/web/local-agents/:id/sessions", async (request) => ({
|
|
25001
|
-
sessions: sessions2.list(authorizeWeb(hub, request), id(request.params))
|
|
25362
|
+
sessions: sessions2.list(authorizeWeb(hub, request), id(request.params)).filter((session) => !session.hidden)
|
|
25002
25363
|
}));
|
|
25003
25364
|
server.post("/web/local-agents/:id/sessions", async (request) => {
|
|
25004
25365
|
webMutation(request);
|
|
@@ -25167,9 +25528,6 @@ data: ${JSON.stringify(snapshot)}
|
|
|
25167
25528
|
webMutation(request);
|
|
25168
25529
|
const identity = authorizeWeb(hub, request);
|
|
25169
25530
|
const value = ExecutionSettingsUpdateSchema.parse(request.body);
|
|
25170
|
-
if (value.opened !== void 0 || value.allowedMembers !== void 0)
|
|
25171
|
-
requireSiteAdmin(identity);
|
|
25172
|
-
if (value.enabled !== void 0 && identity.siteRole !== "admin") settings.assertOpen(identity);
|
|
25173
25531
|
return settings.save(identity, value);
|
|
25174
25532
|
});
|
|
25175
25533
|
server.post(
|
|
@@ -25323,7 +25681,7 @@ function buildServer(options) {
|
|
|
25323
25681
|
]
|
|
25324
25682
|
} : false,
|
|
25325
25683
|
requestIdHeader: false,
|
|
25326
|
-
genReqId: () =>
|
|
25684
|
+
genReqId: () => randomUUID39(),
|
|
25327
25685
|
bodyLimit: 1024 * 1024,
|
|
25328
25686
|
requestTimeout: BLOB_TRANSFER_TIMEOUT_MS
|
|
25329
25687
|
});
|