@teammy/server 0.2.18 → 0.2.20
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 +490 -239
- package/dist/web/assets/Assistant-By7rPMl2.js +1 -0
- package/dist/web/assets/Computers-B4ZMJ8tu.js +13 -0
- package/dist/web/assets/{Computers-DAf8sobH.css → Computers-CBnQX-2p.css} +1 -1
- package/dist/web/assets/{Conversation-DN9pVRsf.js → Conversation-BjRCD81A.js} +1 -1
- package/dist/web/assets/Dashboard-DmtWx-WI.js +1 -0
- package/dist/web/assets/Dropdown-DXEtBxVr.js +55 -0
- package/dist/web/assets/Dropdown-ktgqMqAD.css +1 -0
- package/dist/web/assets/Files-4IxSFpqk.js +1 -0
- package/dist/web/assets/{Help-B21pS1RH.js → Help-BeJ09zt7.js} +28 -12
- package/dist/web/assets/{Markdown-Bh1l6OQM.js → Markdown-DGF8VSqv.js} +4 -4
- package/dist/web/assets/{MessageComposer-D9vqKUX5.js → MessageComposer-0eprbRl2.js} +1 -1
- package/dist/web/assets/ResourceLibrary-rlrdDWGo.js +6 -0
- package/dist/web/assets/TerminalPane-CEaXud0k.js +22 -0
- package/dist/web/assets/WorkspaceTree-CwGvdfr0.js +1 -0
- package/dist/web/assets/{file-links-DvISesr0.js → file-links-Bo7XBz3i.js} +1 -1
- package/dist/web/assets/index-CeKzFsxV.css +1 -0
- package/dist/web/assets/index-Cr9kdjwc.js +10 -0
- package/dist/web/assets/task-links-B7fExlHK.js +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 +4 -3
- package/package.json +1 -1
- package/dist/web/assets/Assistant-CfsrbTdh.js +0 -1
- package/dist/web/assets/Computers-CdwUaH3q.js +0 -13
- package/dist/web/assets/Dashboard-B0Dj-KMg.js +0 -1
- package/dist/web/assets/Dropdown-Cz5xKbpV.js +0 -55
- package/dist/web/assets/Files-B-iLyRvj.js +0 -1
- package/dist/web/assets/ResourceLibrary-qg568G4m.js +0 -6
- package/dist/web/assets/TerminalPane-hEQVsy4e.js +0 -22
- package/dist/web/assets/WorkspaceTree-BMZWhAXJ.js +0 -1
- package/dist/web/assets/index-_W-pw3aC.js +0 -10
- package/dist/web/assets/index-u6KD7Soy.css +0 -1
- package/dist/web/assets/task-links-BeRoF5ff.js +0 -1
package/dist/main.js
CHANGED
|
@@ -308,7 +308,28 @@ import { z as z6 } from "zod";
|
|
|
308
308
|
|
|
309
309
|
// packages/protocol/local-sessions.ts
|
|
310
310
|
import { z as z5 } from "zod";
|
|
311
|
-
var AgentProviderIdSchema = z5.enum([
|
|
311
|
+
var AgentProviderIdSchema = z5.enum([
|
|
312
|
+
"codex",
|
|
313
|
+
"claude",
|
|
314
|
+
"cursor",
|
|
315
|
+
"pi",
|
|
316
|
+
"opencode",
|
|
317
|
+
"codebuddy",
|
|
318
|
+
"dsh"
|
|
319
|
+
]);
|
|
320
|
+
var providerNames = {
|
|
321
|
+
codex: "Codex",
|
|
322
|
+
claude: "Claude Code",
|
|
323
|
+
cursor: "Cursor",
|
|
324
|
+
pi: "Pi",
|
|
325
|
+
opencode: "OpenCode",
|
|
326
|
+
codebuddy: "CodeBuddy",
|
|
327
|
+
dsh: "DSH"
|
|
328
|
+
};
|
|
329
|
+
var acpProvidersCapability = "local-agent-acp-providers-v1";
|
|
330
|
+
function isCodeBuddyOrDsh(provider) {
|
|
331
|
+
return provider === "codebuddy" || provider === "dsh";
|
|
332
|
+
}
|
|
312
333
|
var cursorModes = [
|
|
313
334
|
{ value: "agent", label: "Agent", description: "\u6267\u884C\u4EFB\u52A1\uFF0C\u5DE5\u5177\u64CD\u4F5C\u9075\u5FAA\u5BA1\u6279\u8BBE\u7F6E" },
|
|
314
335
|
{ value: "plan", label: "Plan", description: "\u5148\u63A2\u7D22\u5E76\u5236\u5B9A\u8BA1\u5212\uFF0C\u786E\u8BA4\u540E\u5B9E\u65BD" },
|
|
@@ -340,11 +361,11 @@ var SessionConfigSchema = z5.object({
|
|
|
340
361
|
var NativeSessionIdSchema = z5.string().min(1).max(200).regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/);
|
|
341
362
|
function defaultSessionConfig(provider) {
|
|
342
363
|
return SessionConfigSchema.parse(
|
|
343
|
-
provider === "pi" || provider === "opencode" ? { permission: "native" } : provider === "claude" ? { mode: "default" } : provider === "cursor" ? { mode: "agent" } : {}
|
|
364
|
+
provider === "pi" || provider === "opencode" || isCodeBuddyOrDsh(provider) ? { permission: "native" } : provider === "claude" ? { mode: "default" } : provider === "cursor" ? { mode: "agent" } : {}
|
|
344
365
|
);
|
|
345
366
|
}
|
|
346
367
|
function validNativeConfig(provider, config) {
|
|
347
|
-
return provider === "pi" ? config.permission === "native" && !config.mode && !Object.keys(config.options ?? {}).length : provider === "opencode" ? ["native", "full-access"].includes(config.permission) && !Object.keys(config.options ?? {}).length : config.permission !== "native";
|
|
368
|
+
return provider === "pi" || isCodeBuddyOrDsh(provider) ? config.permission === "native" && !config.mode && !Object.keys(config.options ?? {}).length : provider === "opencode" ? ["native", "full-access"].includes(config.permission) && !Object.keys(config.options ?? {}).length : config.permission !== "native";
|
|
348
369
|
}
|
|
349
370
|
var ProviderControlSchema = z5.object({
|
|
350
371
|
key: z5.enum(["mode", "permission"]),
|
|
@@ -507,6 +528,7 @@ var ProviderStatusSchema = z5.object({
|
|
|
507
528
|
id: AgentProviderIdSchema,
|
|
508
529
|
name: z5.string(),
|
|
509
530
|
available: z5.boolean(),
|
|
531
|
+
defaultImages: z5.boolean().optional(),
|
|
510
532
|
error: z5.string().nullable(),
|
|
511
533
|
models: z5.array(ProviderModelSchema)
|
|
512
534
|
});
|
|
@@ -534,7 +556,7 @@ var SessionActivitySchema = z5.object({
|
|
|
534
556
|
durationMs: z5.number().finite().nonnegative().optional(),
|
|
535
557
|
// A native turn can end while the work is still waiting for a reply.
|
|
536
558
|
// Null marks that distinction; older clients omit the result altogether.
|
|
537
|
-
completedWork: z5.object({ preview: z5.string().max(previewLength * 2) }).nullable().optional()
|
|
559
|
+
completedWork: z5.object({ preview: z5.string().max(previewLength * 2), answer: z5.string().optional() }).nullable().optional()
|
|
538
560
|
});
|
|
539
561
|
var LocalSessionMessageSchema = z5.object({
|
|
540
562
|
queue: z5.object({
|
|
@@ -565,9 +587,15 @@ var LocalSessionMessageSchema = z5.object({
|
|
|
565
587
|
questions: z5.array(InteractionPartSchema)
|
|
566
588
|
}).nullable()
|
|
567
589
|
});
|
|
590
|
+
var sessionMessagePageSize = 60;
|
|
591
|
+
function questionNeedsAnswer(question) {
|
|
592
|
+
return question.state === "pending" && (!question.response || ["human_routed", "failed", "handled"].includes(question.submissionState ?? ""));
|
|
593
|
+
}
|
|
568
594
|
var LocalSessionChatSchema = z5.object({
|
|
569
595
|
canRewind: z5.boolean().default(false),
|
|
570
596
|
cursor: z5.number().int(),
|
|
597
|
+
olderBefore: z5.number().int().positive().nullable().default(null),
|
|
598
|
+
pendingQuestions: z5.array(z5.object({ id: z5.string(), seq: z5.number().int() })).optional(),
|
|
571
599
|
session: LocalSessionSchema,
|
|
572
600
|
messages: z5.array(LocalSessionMessageSchema),
|
|
573
601
|
commands: z5.array(SessionCommandSchema)
|
|
@@ -6794,13 +6822,16 @@ function validateRewind(hub, identity, session, argument) {
|
|
|
6794
6822
|
(row) => row.state !== "uncertain" || JSON.parse(String(row.argument)).messageId !== value.messageId
|
|
6795
6823
|
))
|
|
6796
6824
|
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");
|
|
6797
|
-
const
|
|
6798
|
-
"SELECT
|
|
6799
|
-
).
|
|
6800
|
-
const target2 = rows.find((r) => r.id === value.messageId);
|
|
6825
|
+
const target2 = hub.db.prepare(
|
|
6826
|
+
"SELECT role FROM member_session_messages WHERE project_id=? AND member_id=? AND session_id=? AND id=? AND superseded_by IS NULL"
|
|
6827
|
+
).get(identity.workspaceId, identity.memberId, session.id, value.messageId);
|
|
6801
6828
|
if (!target2 || target2.role !== "user" || !value.messageId.startsWith("input:"))
|
|
6802
6829
|
throw new HubError(400, "REWIND_TARGET", "\u8BF7\u9009\u62E9\u5F53\u524D\u4F1A\u8BDD\u4E2D\u7684\u7528\u6237\u6D88\u606F\u3002");
|
|
6803
|
-
|
|
6830
|
+
const sessions2 = new MemberSessions(hub);
|
|
6831
|
+
let page = sessions2.chat(identity, session.id);
|
|
6832
|
+
while (!page.messages.length && page.olderBefore !== null)
|
|
6833
|
+
page = sessions2.chat(identity, session.id, { before: page.olderBefore });
|
|
6834
|
+
if (page.messages.at(-1)?.id !== value.expectedLastMessage)
|
|
6804
6835
|
throw new HubError(409, "REWIND_CHANGED", "\u4F1A\u8BDD\u5DF2\u6709\u65B0\u6D88\u606F\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u7F16\u8F91\u4F4D\u7F6E\u3002");
|
|
6805
6836
|
const input = new MemberExecution(hub).input(identity, value.messageId.slice(6));
|
|
6806
6837
|
if (input.interaction || input.source.type !== "web_session")
|
|
@@ -6845,6 +6876,34 @@ function completeRewind(hub, identity, session, commandId, argument, result) {
|
|
|
6845
6876
|
});
|
|
6846
6877
|
}
|
|
6847
6878
|
|
|
6879
|
+
// apps/server/member-execution/transcript.ts
|
|
6880
|
+
function transcriptPage(hub, identity, session, window) {
|
|
6881
|
+
const scope2 = [identity.workspaceId, identity.memberId, session];
|
|
6882
|
+
const filter2 = "m.project_id=? AND m.member_id=? AND m.session_id=? AND m.superseded_by IS NULL";
|
|
6883
|
+
const select = `SELECT m.*,i.state input_state,i.id input_id,i.read_at input_read_at,i.payload_json,
|
|
6884
|
+
q.id question_id,q.code,q.state question_state,q.content_json FROM member_session_messages m
|
|
6885
|
+
LEFT JOIN member_agent_inputs i ON m.role='user' AND i.id=substr(m.id,7) AND m.id='input:'||i.id
|
|
6886
|
+
LEFT JOIN member_agent_questions q ON q.id=m.id WHERE ${filter2}`;
|
|
6887
|
+
const range = (from) => {
|
|
6888
|
+
const rows2 = hub.db.prepare(select + " AND m.seq>=? ORDER BY m.seq").all(...scope2, from);
|
|
6889
|
+
const older = hub.db.prepare(`SELECT 1 FROM member_session_messages m WHERE ${filter2} AND m.seq<? LIMIT 1`).get(...scope2, from);
|
|
6890
|
+
return { rows: rows2, olderBefore: older ? from : null };
|
|
6891
|
+
};
|
|
6892
|
+
if (window.from !== void 0) return range(window.from);
|
|
6893
|
+
const rows = hub.db.prepare(select + " AND m.seq<? ORDER BY m.seq DESC LIMIT ?").all(...scope2, window.before ?? Number.MAX_SAFE_INTEGER, sessionMessagePageSize + 1);
|
|
6894
|
+
const hasOlder = rows.length > sessionMessagePageSize;
|
|
6895
|
+
if (hasOlder) rows.pop();
|
|
6896
|
+
rows.reverse();
|
|
6897
|
+
const olderBefore = hasOlder ? Number(rows[0].seq) : null;
|
|
6898
|
+
if (window.question && olderBefore !== null) {
|
|
6899
|
+
const target2 = hub.db.prepare(
|
|
6900
|
+
`SELECT m.seq FROM member_session_messages m JOIN member_agent_questions q ON q.id=m.id WHERE ${filter2} AND m.id=?`
|
|
6901
|
+
).get(...scope2, window.question);
|
|
6902
|
+
if (target2 && Number(target2.seq) < olderBefore) return range(Number(target2.seq));
|
|
6903
|
+
}
|
|
6904
|
+
return { rows, olderBefore };
|
|
6905
|
+
}
|
|
6906
|
+
|
|
6848
6907
|
// apps/server/member-execution/sessions.ts
|
|
6849
6908
|
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
6850
6909
|
import { z as z25 } from "zod";
|
|
@@ -6908,7 +6967,7 @@ var MemberSessions = class {
|
|
|
6908
6967
|
return diagnosticTransaction(this.hub, () => {
|
|
6909
6968
|
const dir = this.directory(identity, directory);
|
|
6910
6969
|
const provider = value.provider ?? AgentProviderIdSchema.parse(dir.provider);
|
|
6911
|
-
if (value.resumeSession && ["codex", "claude", "cursor"].includes(provider))
|
|
6970
|
+
if (value.resumeSession && ["codex", "claude", "cursor", "codebuddy", "dsh"].includes(provider))
|
|
6912
6971
|
z25.uuid().parse(value.resumeSession);
|
|
6913
6972
|
if (value.resumeSession && provider === "codex" && !JSON.parse(
|
|
6914
6973
|
String(new MemberExecution(this.hub).runtime(identity, directory)?.config_json ?? "{}")
|
|
@@ -7150,7 +7209,7 @@ var MemberSessions = class {
|
|
|
7150
7209
|
throw new HubError(
|
|
7151
7210
|
400,
|
|
7152
7211
|
"SESSION_MODE",
|
|
7153
|
-
|
|
7212
|
+
`\u8BF7\u9009\u62E9 ${providerNames[session.provider]} \u652F\u6301\u7684\u6743\u9650\u4E0E\u5DE5\u4F5C\u6A21\u5F0F\u3002`
|
|
7154
7213
|
);
|
|
7155
7214
|
if (session.provider === "codex" && value.config.mode)
|
|
7156
7215
|
throw new HubError(400, "SESSION_MODE", "Codex \u4F1A\u8BDD\u4E0D\u652F\u6301 Claude \u7684\u5DE5\u4F5C\u6A21\u5F0F\u3002");
|
|
@@ -7216,7 +7275,7 @@ var MemberSessions = class {
|
|
|
7216
7275
|
changes.push("\u6A21\u578B\u9009\u9879\u5DF2\u66F4\u65B0");
|
|
7217
7276
|
if (session.provider === "codex" && value.config.permission !== session.config.permission)
|
|
7218
7277
|
changes.push(
|
|
7219
|
-
`\u6743\u9650\u8BBE\u4E3A ${{ "read-only": "\u53EA\u8BFB", "workspace-write": "\u5DE5\u4F5C\u533A\u5199\u5165", "full-access": "\u5B8C\u5168\u8BBF\u95EE", native: "
|
|
7278
|
+
`\u6743\u9650\u8BBE\u4E3A ${{ "read-only": "\u53EA\u8BFB", "workspace-write": "\u5DE5\u4F5C\u533A\u5199\u5165", "full-access": "\u5B8C\u5168\u8BBF\u95EE", native: "\u539F\u751F\u89C4\u5219" }[value.config.permission]}`
|
|
7220
7279
|
);
|
|
7221
7280
|
if (target2 !== session.executionDirectory)
|
|
7222
7281
|
changes.push(`\u6267\u884C\u4F4D\u7F6E\u8BBE\u4E3A ${this.directory(identity, target2 ?? session.directory).name}`);
|
|
@@ -7303,20 +7362,48 @@ var MemberSessions = class {
|
|
|
7303
7362
|
this.hub.db.prepare("UPDATE member_agent_sessions SET activity_at=? WHERE project_id=? AND id=?").run((/* @__PURE__ */ new Date()).toISOString(), identity.workspaceId, session);
|
|
7304
7363
|
return !!written.changes;
|
|
7305
7364
|
}
|
|
7306
|
-
|
|
7365
|
+
eventCursor(identity, id) {
|
|
7366
|
+
const row = this.hub.db.prepare(
|
|
7367
|
+
`SELECT (SELECT COALESCE(MAX(seq),0) FROM member_session_events WHERE project_id=s.project_id AND session_id=s.id) seq
|
|
7368
|
+
FROM member_agent_sessions s WHERE s.project_id=? AND s.member_id=? AND s.id=?`
|
|
7369
|
+
).get(identity.workspaceId, identity.memberId, id);
|
|
7370
|
+
if (!row) throw new HubError(404, "SESSION_NOT_FOUND", "\u627E\u4E0D\u5230\u672C\u4EBA\u7684\u4F1A\u8BDD\u3002");
|
|
7371
|
+
return Number(row.seq);
|
|
7372
|
+
}
|
|
7373
|
+
chat(identity, id, window = {}) {
|
|
7374
|
+
const cursor = this.eventCursor(identity, id);
|
|
7307
7375
|
const session = this.get(identity, id);
|
|
7308
|
-
const rows = this.hub
|
|
7309
|
-
`SELECT m.*,i.state input_state,i.id input_id,i.read_at input_read_at,i.payload_json,q.id question_id,q.code,q.state question_state,q.content_json FROM member_session_messages m
|
|
7310
|
-
LEFT JOIN member_agent_inputs i ON 'input:'||i.id=m.id LEFT JOIN member_agent_questions q ON q.id=m.id
|
|
7311
|
-
WHERE m.project_id=? AND m.member_id=? AND m.session_id=? AND m.superseded_by IS NULL ORDER BY m.seq`
|
|
7312
|
-
).all(identity.workspaceId, identity.memberId, id);
|
|
7376
|
+
const { rows, olderBefore } = transcriptPage(this.hub, identity, id, window);
|
|
7313
7377
|
const replies = /* @__PURE__ */ new Map();
|
|
7314
|
-
const
|
|
7315
|
-
rows.filter((
|
|
7378
|
+
const inputs = new Map(
|
|
7379
|
+
rows.filter((r) => r.input_id).map((r) => [String(r.input_id), JSON.parse(String(r.payload_json))])
|
|
7380
|
+
);
|
|
7381
|
+
const questionIds = rows.flatMap((r) => r.question_id ? [String(r.question_id)] : []);
|
|
7382
|
+
for (const input of inputs.values())
|
|
7383
|
+
if (input.interaction?.action === "answer") questionIds.push(input.interaction.question);
|
|
7384
|
+
const questionRows = this.hub.db.prepare(
|
|
7385
|
+
`SELECT q.id question_id,q.content_json,q.state,m.seq
|
|
7386
|
+
FROM member_agent_questions q JOIN member_session_messages m ON m.id=q.id
|
|
7387
|
+
WHERE q.project_id=? AND q.member_id=? AND m.session_id=? AND m.superseded_by IS NULL AND
|
|
7388
|
+
(q.state='pending' OR q.id IN (SELECT value FROM json_each(?))
|
|
7389
|
+
OR json_extract(q.content_json,'$.response.inputId') IN (SELECT value FROM json_each(?))) ORDER BY m.seq`
|
|
7390
|
+
).all(
|
|
7391
|
+
identity.workspaceId,
|
|
7392
|
+
identity.memberId,
|
|
7393
|
+
id,
|
|
7394
|
+
JSON.stringify(questionIds),
|
|
7395
|
+
JSON.stringify([...inputs.keys()])
|
|
7316
7396
|
);
|
|
7397
|
+
const questions = new Map(questionRows.map((row) => [row.question_id, row]));
|
|
7317
7398
|
const folded = /* @__PURE__ */ new Set();
|
|
7318
|
-
|
|
7319
|
-
|
|
7399
|
+
const answerRows = questions.size ? this.hub.db.prepare(
|
|
7400
|
+
`SELECT i.id input_id,i.state input_state,i.payload_json
|
|
7401
|
+
FROM member_agent_inputs i JOIN member_session_messages m ON m.id='input:'||i.id
|
|
7402
|
+
WHERE i.project_id=? AND i.member_id=? AND json_extract(i.payload_json,'$.interaction.action')='answer'
|
|
7403
|
+
AND json_extract(i.payload_json,'$.interaction.question') IN (SELECT value FROM json_each(?))
|
|
7404
|
+
AND m.session_id=? AND m.superseded_by IS NULL ORDER BY m.seq`
|
|
7405
|
+
).all(identity.workspaceId, identity.memberId, JSON.stringify([...questions.keys()]), id) : [];
|
|
7406
|
+
for (const row of answerRows) {
|
|
7320
7407
|
const input = JSON.parse(String(row.payload_json));
|
|
7321
7408
|
if (input.source.type !== "web_session" || input.interaction?.action !== "answer") continue;
|
|
7322
7409
|
const question = questions.get(input.interaction.question);
|
|
@@ -7344,9 +7431,18 @@ var MemberSessions = class {
|
|
|
7344
7431
|
});
|
|
7345
7432
|
folded.add(String(row.input_id));
|
|
7346
7433
|
}
|
|
7347
|
-
|
|
7348
|
-
|
|
7434
|
+
const pendingQuestions = [];
|
|
7435
|
+
for (const row of questionRows) {
|
|
7436
|
+
const content = JSON.parse(String(row.content_json));
|
|
7437
|
+
const response = content.response;
|
|
7349
7438
|
if (response?.inputId) folded.add(response.inputId);
|
|
7439
|
+
const reply = replies.get(String(row.question_id));
|
|
7440
|
+
if (questionDelivery(content, session) === "async" && questionNeedsAnswer({
|
|
7441
|
+
state: String(row.state),
|
|
7442
|
+
response: response ?? reply?.response,
|
|
7443
|
+
submissionState: reply?.state
|
|
7444
|
+
}))
|
|
7445
|
+
pendingQuestions.push({ id: String(row.question_id), seq: Number(row.seq) });
|
|
7350
7446
|
}
|
|
7351
7447
|
const runtime = new MemberExecution(this.hub).runtime(identity, session.directory);
|
|
7352
7448
|
const runtimeConfig = JSON.parse(String(runtime?.config_json ?? "{}"));
|
|
@@ -7357,8 +7453,8 @@ var MemberSessions = class {
|
|
|
7357
7453
|
);
|
|
7358
7454
|
const queueInfo = (row) => {
|
|
7359
7455
|
if (!row.input_id || !row.payload_json) return {};
|
|
7360
|
-
const input =
|
|
7361
|
-
if (!input
|
|
7456
|
+
const input = inputs.get(String(row.input_id));
|
|
7457
|
+
if (!input?.delivery || input.source.type !== "web_session" || input.interaction) return {};
|
|
7362
7458
|
const queued = input.delivery === "queue";
|
|
7363
7459
|
const edit = queued ? this.hub.db.prepare("SELECT revision,cancelled FROM member_session_input_edits WHERE input_id=?").get(String(row.input_id)) : void 0;
|
|
7364
7460
|
const state = edit?.cancelled ? "cancelled" : progress.get(String(row.input_id))?.state ?? (row.input_read_at ? "handled" : row.input_state === "accepted" ? "queued" : String(row.input_state));
|
|
@@ -7375,6 +7471,7 @@ var MemberSessions = class {
|
|
|
7375
7471
|
};
|
|
7376
7472
|
};
|
|
7377
7473
|
const messages = rows.filter((row) => !row.input_id || !folded.has(String(row.input_id))).map((row) => {
|
|
7474
|
+
const input = inputs.get(String(row.input_id));
|
|
7378
7475
|
const content = row.question_id ? JSON.parse(String(row.content_json)) : null;
|
|
7379
7476
|
return {
|
|
7380
7477
|
...queueInfo(row),
|
|
@@ -7382,8 +7479,8 @@ var MemberSessions = class {
|
|
|
7382
7479
|
seq: Number(row.seq),
|
|
7383
7480
|
role: String(row.role),
|
|
7384
7481
|
body: String(row.body),
|
|
7385
|
-
...
|
|
7386
|
-
...
|
|
7482
|
+
...input?.attachments ? { attachments: input.attachments } : {},
|
|
7483
|
+
...input?.images ? { images: input.images } : {},
|
|
7387
7484
|
source: String(row.source),
|
|
7388
7485
|
state: String(row.input_state ?? row.state),
|
|
7389
7486
|
createdAt: String(row.created_at),
|
|
@@ -7406,14 +7503,11 @@ var MemberSessions = class {
|
|
|
7406
7503
|
} : null
|
|
7407
7504
|
};
|
|
7408
7505
|
});
|
|
7409
|
-
const cursor = Number(
|
|
7410
|
-
this.hub.db.prepare(
|
|
7411
|
-
"SELECT COALESCE(MAX(seq),0) seq FROM member_session_events WHERE project_id=? AND session_id=?"
|
|
7412
|
-
).get(identity.workspaceId, id).seq
|
|
7413
|
-
);
|
|
7414
7506
|
return {
|
|
7415
7507
|
session,
|
|
7416
7508
|
messages,
|
|
7509
|
+
olderBefore,
|
|
7510
|
+
pendingQuestions,
|
|
7417
7511
|
commands: this.commands(identity, id),
|
|
7418
7512
|
cursor,
|
|
7419
7513
|
canRewind: rewindAvailable(this.hub, identity, session)
|
|
@@ -7522,7 +7616,8 @@ var MemberSessions = class {
|
|
|
7522
7616
|
commands(identity, session) {
|
|
7523
7617
|
requireProjectActor(this.hub, identity);
|
|
7524
7618
|
return this.hub.db.prepare(
|
|
7525
|
-
`SELECT c
|
|
7619
|
+
`SELECT c.id,c.session_id,c.kind,c.argument,c.input_id,c.state,c.error
|
|
7620
|
+
FROM member_session_commands c JOIN member_agent_sessions s ON s.project_id=c.project_id AND s.id=c.session_id
|
|
7526
7621
|
JOIN member_agent_directories d ON d.project_id=s.project_id AND d.id=s.directory_id
|
|
7527
7622
|
WHERE c.project_id=? AND c.member_id=? AND (? IS NULL OR c.session_id=?) AND (? IS NULL OR d.device_id=?) ORDER BY c.rowid`
|
|
7528
7623
|
).all(
|
|
@@ -7605,6 +7700,16 @@ var MemberSessions = class {
|
|
|
7605
7700
|
if (!["queued", "running"].includes(String(row.state)) || row.instance && row.instance !== value.instance && value.state !== "uncertain")
|
|
7606
7701
|
throw new HubError(409, "COMMAND_OWNED", "\u64CD\u4F5C\u7ED3\u679C\u9700\u8981\u6838\u5BF9\uFF0C\u4E0D\u80FD\u91CD\u590D\u6267\u884C\u3002");
|
|
7607
7702
|
this.hub.db.prepare("UPDATE member_session_commands SET state=?,instance=?,error=? WHERE id=?").run(value.state, value.instance, value.error, id);
|
|
7703
|
+
if (row.kind === "stop" && (value.state === "running" || value.state === "succeeded")) {
|
|
7704
|
+
const report = JSON.parse(String(runtime.config_json));
|
|
7705
|
+
const input2 = runningSessionInput(report.sessions?.find((s) => s.id === row.session_id));
|
|
7706
|
+
if (value.state === "running" && input2)
|
|
7707
|
+
this.hub.db.prepare("UPDATE member_session_commands SET result_json=? WHERE id=?").run(JSON.stringify(input2), id);
|
|
7708
|
+
if (value.state === "succeeded" && (!row.result_json || !input2 || row.result_json === JSON.stringify(input2)))
|
|
7709
|
+
this.hub.db.prepare(
|
|
7710
|
+
"UPDATE member_agent_sessions SET state='idle' WHERE project_id=? AND id=? AND state IN ('working','waiting')"
|
|
7711
|
+
).run(identity.workspaceId, row.session_id);
|
|
7712
|
+
}
|
|
7608
7713
|
if (value.state === "succeeded") {
|
|
7609
7714
|
if (row.kind === "rewind") {
|
|
7610
7715
|
completeRewind(
|
|
@@ -8198,6 +8303,10 @@ function associateTaskFolders(hub, project, input) {
|
|
|
8198
8303
|
|
|
8199
8304
|
// apps/server/member-execution/store.ts
|
|
8200
8305
|
import { randomUUID as randomUUID15 } from "node:crypto";
|
|
8306
|
+
function runningSessionInput(report) {
|
|
8307
|
+
if (report?.state !== "working" && report?.state !== "waiting") return;
|
|
8308
|
+
return report.inputs?.filter((i) => i.state === "running" || i.state === "dispatching").at(-1)?.id;
|
|
8309
|
+
}
|
|
8201
8310
|
var MemberExecution = class {
|
|
8202
8311
|
constructor(hub, now6 = Date.now) {
|
|
8203
8312
|
this.hub = hub;
|
|
@@ -8301,6 +8410,7 @@ var MemberExecution = class {
|
|
|
8301
8410
|
this.now() + 45e3,
|
|
8302
8411
|
JSON.stringify(value)
|
|
8303
8412
|
);
|
|
8413
|
+
let previousSessions;
|
|
8304
8414
|
for (const item of value.sessions ?? []) {
|
|
8305
8415
|
const session = new MemberSessions(this.hub).get(identity, item.id);
|
|
8306
8416
|
const dir = new MemberSessions(this.hub).directory(identity, session.directory);
|
|
@@ -8318,10 +8428,17 @@ var MemberExecution = class {
|
|
|
8318
8428
|
state: "succeeded"
|
|
8319
8429
|
});
|
|
8320
8430
|
}
|
|
8431
|
+
let state = item.state;
|
|
8432
|
+
const input2 = runningSessionInput(item);
|
|
8433
|
+
if (session.state === "idle" && input2 && current2?.instance === value.instance) {
|
|
8434
|
+
previousSessions ??= JSON.parse(String(current2.config_json)).sessions ?? [];
|
|
8435
|
+
if (runningSessionInput(previousSessions.find((s) => s.id === item.id)) === input2)
|
|
8436
|
+
state = "idle";
|
|
8437
|
+
}
|
|
8321
8438
|
this.hub.db.prepare(
|
|
8322
8439
|
"UPDATE member_agent_sessions SET state=?,applied_revision=?,effective_json=?,cwd=?,error=?,native_session=COALESCE(?,native_session) WHERE project_id=? AND id=?"
|
|
8323
8440
|
).run(
|
|
8324
|
-
|
|
8441
|
+
state,
|
|
8325
8442
|
item.appliedRevision,
|
|
8326
8443
|
item.effectiveConfig ? JSON.stringify(item.effectiveConfig) : null,
|
|
8327
8444
|
item.cwd,
|
|
@@ -9027,7 +9144,11 @@ function replyToRoutedRequest(hub, identity, input) {
|
|
|
9027
9144
|
return diagnosticTransaction(hub, () => {
|
|
9028
9145
|
const source = new MemberExecution(hub).input(identity, value.inputId);
|
|
9029
9146
|
if (source.source.type !== "routed.event" || source.state !== "accepted")
|
|
9030
|
-
throw new HubError(
|
|
9147
|
+
throw new HubError(
|
|
9148
|
+
403,
|
|
9149
|
+
"ROUTED_REQUEST_REQUIRED",
|
|
9150
|
+
"\u5F53\u524D\u6CA1\u6709\u53EF\u7528\u6B64\u5DE5\u5177\u56DE\u5E94\u7684\u5DF2\u63A5\u624B\u4E8B\u4EF6\u3002\u666E\u901A\u4F1A\u8BDD\u8BF7\u76F4\u63A5\u7ED9\u51FA\u6700\u7EC8\u7B54\u590D\u3002"
|
|
9151
|
+
);
|
|
9031
9152
|
const row = hub.db.prepare("SELECT * FROM routing_requests WHERE id=? AND member_id=? AND input_id=?").get(source.source.ref, identity.memberId, source.id);
|
|
9032
9153
|
if (!row || row.handler !== "managed" || row.requires_human)
|
|
9033
9154
|
throw new HubError(403, "ROUTED_REQUEST_OWNER", "\u8BE5\u8BF7\u6C42\u4E0D\u7531\u5F53\u524D Agent \u56DE\u5E94\u3002");
|
|
@@ -9237,9 +9358,11 @@ var WecomStore = class {
|
|
|
9237
9358
|
computerCompletionCategory,
|
|
9238
9359
|
JSON.stringify([identity.workspaceId, session.id, turn.turnId]),
|
|
9239
9360
|
() => {
|
|
9240
|
-
|
|
9241
|
-
if (
|
|
9242
|
-
|
|
9361
|
+
if (turn.completedWork === null) return null;
|
|
9362
|
+
if (turn.completedWork === void 0 && this.legacyTurnWaiting(identity, input))
|
|
9363
|
+
return null;
|
|
9364
|
+
const answer = turn.completedWork?.answer ?? this.turnAnswer(identity, session, turn.turnId) ?? turn.completedWork?.preview;
|
|
9365
|
+
return "\u672C\u8F6E\u5DE5\u4F5C\u5DF2\u5B8C\u6210\u3002" + (answer ? "\n" + answer : "");
|
|
9243
9366
|
}
|
|
9244
9367
|
);
|
|
9245
9368
|
}
|
|
@@ -9266,35 +9389,36 @@ var WecomStore = class {
|
|
|
9266
9389
|
const directory = new MemberSessions(this.hub).directory(identity, session.directory);
|
|
9267
9390
|
const query2 = new URLSearchParams({ directory: session.directory, session: session.id });
|
|
9268
9391
|
if (category === computerQuestionCategory) query2.set("question", source);
|
|
9392
|
+
const base = new SiteRepository(this.hub).config().publicServerUrl;
|
|
9269
9393
|
const link4 = wecomLinks(
|
|
9270
9394
|
`[${category === computerQuestionCategory ? "\u67E5\u770B\u5E76\u5904\u7406" : "\u67E5\u770B\u4F1A\u8BDD"}](/projects/${encodeURIComponent(identity.workspaceId)}/computers?${query2})`,
|
|
9271
|
-
|
|
9395
|
+
base
|
|
9272
9396
|
);
|
|
9273
|
-
|
|
9274
|
-
|
|
9275
|
-
|
|
9276
|
-
|
|
9277
|
-
|
|
9278
|
-
|
|
9279
|
-
|
|
9280
|
-
|
|
9281
|
-
|
|
9282
|
-
}
|
|
9283
|
-
legacyTurnPreview(identity, session, turn, input) {
|
|
9284
|
-
const waiting = this.hub.db.prepare(
|
|
9397
|
+
const content = `${wecomLinkLabel(String(directory.name))} \xB7 ${wecomLinkLabel(session.title)}\uFF5C${wecomLinks(body, base)}`;
|
|
9398
|
+
const footer = "\n" + link4;
|
|
9399
|
+
const parts = wecomParts(content, 20480 - Buffer.byteLength(footer));
|
|
9400
|
+
parts[parts.length - 1] += footer;
|
|
9401
|
+
for (const [index, part] of parts.entries())
|
|
9402
|
+
this.queue(bot, external, category, index ? `${source}:${index}` : source, part, identity);
|
|
9403
|
+
}
|
|
9404
|
+
legacyTurnWaiting(identity, input) {
|
|
9405
|
+
return this.hub.db.prepare(
|
|
9285
9406
|
`SELECT 1 FROM member_agent_question_codes c LEFT JOIN member_agent_questions q ON q.id=c.id
|
|
9286
9407
|
WHERE c.project_id=? AND c.member_id=? AND c.reply_context=? AND
|
|
9287
9408
|
((q.id IS NULL AND c.reserved_after_input >= (SELECT seq FROM member_agent_inputs WHERE id=?)) OR
|
|
9288
9409
|
(q.state='pending' AND EXISTS (SELECT 1 FROM member_agent_message_inputs i WHERE i.operation_id=q.id AND i.input_id=?)))
|
|
9289
9410
|
LIMIT 1`
|
|
9290
9411
|
).get(identity.workspaceId, identity.memberId, input.replyContext, input.id, input.id);
|
|
9291
|
-
|
|
9412
|
+
}
|
|
9413
|
+
turnAnswer(identity, session, turn) {
|
|
9292
9414
|
const answer = this.hub.db.prepare(
|
|
9293
|
-
`SELECT body FROM member_session_messages
|
|
9294
|
-
|
|
9295
|
-
|
|
9415
|
+
`SELECT COALESCE(final.body,m.body) body FROM member_session_messages m
|
|
9416
|
+
LEFT JOIN member_agent_messages final ON final.operation_id=m.id
|
|
9417
|
+
WHERE m.project_id=? AND m.session_id=? AND m.superseded_by IS NULL
|
|
9418
|
+
AND m.role='assistant' AND m.state IN ('succeeded','sent') AND json_extract(m.activity_json,'$.kind')='answer'
|
|
9419
|
+
AND json_extract(m.activity_json,'$.turnId')=? ORDER BY m.seq DESC LIMIT 1`
|
|
9296
9420
|
).get(identity.workspaceId, session.id, turn);
|
|
9297
|
-
return
|
|
9421
|
+
return answer ? String(answer.body) : void 0;
|
|
9298
9422
|
}
|
|
9299
9423
|
subscribe(bot, external, code) {
|
|
9300
9424
|
const row = this.hub.db.prepare("SELECT * FROM wecom_codes WHERE code_hash=? AND bot_id=? AND expires_at>?").get(hash2(code.toUpperCase()), bot, Date.now());
|
|
@@ -9667,13 +9791,14 @@ var ExecutionBridge = class {
|
|
|
9667
9791
|
AND json_extract(activity_json,'$.turnId')=? LIMIT 1`
|
|
9668
9792
|
).get(identity.workspaceId, session.id, turn.turnId);
|
|
9669
9793
|
if (previous && previous.id !== value.operationId) return { ok: true };
|
|
9794
|
+
const activity = turn?.completedWork?.answer !== void 0 ? { ...turn, completedWork: { preview: turn.completedWork.preview } } : value.activity;
|
|
9670
9795
|
const written = sessions2.message(identity, session.id, {
|
|
9671
9796
|
id: value.operationId,
|
|
9672
9797
|
role: "assistant",
|
|
9673
9798
|
body: value.body,
|
|
9674
9799
|
source: "agent",
|
|
9675
9800
|
state: value.state,
|
|
9676
|
-
...
|
|
9801
|
+
...activity ? { activity } : {}
|
|
9677
9802
|
});
|
|
9678
9803
|
if (written && turn && !previous && turn.completedWork !== null)
|
|
9679
9804
|
new WecomStore(this.hub).queueComputerCompletion(identity, session, turn, source);
|
|
@@ -10265,12 +10390,13 @@ CREATE TABLE wecom_groups(bot_id TEXT NOT NULL,chat_id TEXT NOT NULL,project_id
|
|
|
10265
10390
|
CREATE TABLE wecom_group_requests(run_id TEXT PRIMARY KEY,bot_id TEXT NOT NULL,chat_id TEXT NOT NULL,project_id TEXT NOT NULL,user_id TEXT NOT NULL,collected INTEGER NOT NULL DEFAULT 0);
|
|
10266
10391
|
`;
|
|
10267
10392
|
var digest5 = (code) => createHash15("sha256").update(code.toUpperCase()).digest("hex");
|
|
10268
|
-
function wecomParts(text2) {
|
|
10393
|
+
function wecomParts(text2, maxBytes = 17e3) {
|
|
10394
|
+
if (Buffer.byteLength(text2) <= maxBytes) return text2 ? [text2] : [];
|
|
10269
10395
|
const parts = [];
|
|
10270
10396
|
let part = "", bytes3 = 0;
|
|
10271
10397
|
for (const char of text2) {
|
|
10272
10398
|
const size2 = Buffer.byteLength(char);
|
|
10273
|
-
if (bytes3 + size2 >
|
|
10399
|
+
if (bytes3 + size2 > maxBytes) {
|
|
10274
10400
|
parts.push(part);
|
|
10275
10401
|
part = "";
|
|
10276
10402
|
bytes3 = 0;
|
|
@@ -13850,6 +13976,10 @@ ALTER TABLE member_agent_sessions ADD COLUMN hidden INTEGER NOT NULL DEFAULT 0;
|
|
|
13850
13976
|
var sessionRewindMigration = `
|
|
13851
13977
|
ALTER TABLE member_session_messages ADD COLUMN superseded_by TEXT;
|
|
13852
13978
|
`;
|
|
13979
|
+
var sessionTranscriptIndexMigration = `
|
|
13980
|
+
CREATE INDEX IF NOT EXISTS member_input_question_answer ON member_agent_inputs(project_id,member_id,json_extract(payload_json,'$.interaction.question'))
|
|
13981
|
+
WHERE json_extract(payload_json,'$.interaction.action')='answer';
|
|
13982
|
+
`;
|
|
13853
13983
|
|
|
13854
13984
|
// apps/server/session-library.ts
|
|
13855
13985
|
var columns = "id,workspace_id,owner,session_key,agent,native_id,cwd,title,revision,updated_at,message_count,hash,size";
|
|
@@ -14257,6 +14387,14 @@ var controlMigration = String.raw`
|
|
|
14257
14387
|
var deviceMigration = String.raw`
|
|
14258
14388
|
CREATE TABLE device_enrollments(workspace_id TEXT NOT NULL, member_id TEXT NOT NULL, operation_id TEXT NOT NULL, fingerprint TEXT NOT NULL, PRIMARY KEY(workspace_id,member_id,operation_id));
|
|
14259
14389
|
`;
|
|
14390
|
+
var clientUpdateMigration = `
|
|
14391
|
+
CREATE TABLE IF NOT EXISTS client_update_devices(
|
|
14392
|
+
workspace_id TEXT NOT NULL, member_id TEXT NOT NULL, device_id TEXT NOT NULL, installation TEXT NOT NULL, status_json TEXT NOT NULL,
|
|
14393
|
+
PRIMARY KEY(workspace_id,member_id,device_id),
|
|
14394
|
+
FOREIGN KEY(workspace_id,member_id,device_id) REFERENCES member_devices(workspace_id,member_id,device_id) ON DELETE CASCADE);
|
|
14395
|
+
CREATE TABLE IF NOT EXISTS client_update_preferences(member_id TEXT NOT NULL,installation TEXT NOT NULL,enabled INTEGER NOT NULL,
|
|
14396
|
+
PRIMARY KEY(member_id,installation));
|
|
14397
|
+
`;
|
|
14260
14398
|
var multiDeviceMigration = `
|
|
14261
14399
|
CREATE TABLE member_devices (
|
|
14262
14400
|
workspace_id TEXT NOT NULL, member_id TEXT NOT NULL, device_id TEXT NOT NULL,
|
|
@@ -18748,7 +18886,9 @@ var migrations = [
|
|
|
18748
18886
|
multiDeviceMigration,
|
|
18749
18887
|
batchInputReceiptsMigration,
|
|
18750
18888
|
computerCompletionMigration,
|
|
18751
|
-
taskCardNumbersMigration
|
|
18889
|
+
taskCardNumbersMigration,
|
|
18890
|
+
sessionTranscriptIndexMigration,
|
|
18891
|
+
clientUpdateMigration
|
|
18752
18892
|
];
|
|
18753
18893
|
var HubStore = class {
|
|
18754
18894
|
constructor(directory) {
|
|
@@ -23899,6 +24039,19 @@ import { ZodError } from "zod";
|
|
|
23899
24039
|
|
|
23900
24040
|
// packages/protocol/devices.ts
|
|
23901
24041
|
import { z as z75 } from "zod";
|
|
24042
|
+
|
|
24043
|
+
// packages/protocol/release-version.ts
|
|
24044
|
+
var stableVersion = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/;
|
|
24045
|
+
function compareVersions(left, right) {
|
|
24046
|
+
const a = left.split(".").map(BigInt), b = right.split(".").map(BigInt);
|
|
24047
|
+
for (let i = 0; i < 3; i++) {
|
|
24048
|
+
if (a[i] < b[i]) return -1;
|
|
24049
|
+
if (a[i] > b[i]) return 1;
|
|
24050
|
+
}
|
|
24051
|
+
return 0;
|
|
24052
|
+
}
|
|
24053
|
+
|
|
24054
|
+
// packages/protocol/devices.ts
|
|
23902
24055
|
var CredentialSchema = z75.string().regex(/^tmy_[a-f0-9]{64}$/);
|
|
23903
24056
|
var EnrollmentSchema = z75.object({
|
|
23904
24057
|
operationId: z75.uuid(),
|
|
@@ -23930,6 +24083,17 @@ var DeviceStatusSchema = z75.object({
|
|
|
23930
24083
|
reportError: z75.string().max(2e3).nullable(),
|
|
23931
24084
|
lastSync: SyncSummarySchema.nullable()
|
|
23932
24085
|
}).strict();
|
|
24086
|
+
var release = z75.string().max(64).regex(stableVersion);
|
|
24087
|
+
var ClientUpdateStatusSchema = z75.object({
|
|
24088
|
+
running: z75.string().min(1).max(64),
|
|
24089
|
+
waiting: release.optional(),
|
|
24090
|
+
issue: z75.string().max(1500).optional()
|
|
24091
|
+
});
|
|
24092
|
+
var ClientUpdateReportSchema = ClientUpdateStatusSchema.extend({ installation: z75.uuid() });
|
|
24093
|
+
var ClientUpdatePolicySchema = z75.object({
|
|
24094
|
+
enabled: z75.boolean(),
|
|
24095
|
+
target: release.nullable()
|
|
24096
|
+
});
|
|
23933
24097
|
var WebDevicesSchema = z75.object({
|
|
23934
24098
|
devices: z75.array(
|
|
23935
24099
|
z75.object({
|
|
@@ -23938,13 +24102,46 @@ var WebDevicesSchema = z75.object({
|
|
|
23938
24102
|
name: z75.string().nullish(),
|
|
23939
24103
|
bound: z75.boolean(),
|
|
23940
24104
|
lastSeenAt: z75.string().nullable(),
|
|
23941
|
-
status: DeviceStatusSchema.nullable()
|
|
24105
|
+
status: DeviceStatusSchema.nullable(),
|
|
24106
|
+
autoUpdate: ClientUpdateStatusSchema.extend({ enabled: z75.boolean() }).optional()
|
|
23942
24107
|
})
|
|
23943
24108
|
)
|
|
23944
24109
|
});
|
|
23945
24110
|
|
|
23946
24111
|
// apps/server/control-routes.ts
|
|
23947
|
-
|
|
24112
|
+
import { z as z76 } from "zod";
|
|
24113
|
+
function registerControlRoutes(server, store, target2) {
|
|
24114
|
+
server.put("/devices/self/client-update", async (request) => {
|
|
24115
|
+
const { workspaceId, memberId, deviceId } = authorizeDevice(store, request);
|
|
24116
|
+
const { installation, ...status } = ClientUpdateReportSchema.parse(request.body);
|
|
24117
|
+
store.db.prepare(
|
|
24118
|
+
`INSERT INTO client_update_devices VALUES(?,?,?,?,?) ON CONFLICT(workspace_id,member_id,device_id)
|
|
24119
|
+
DO UPDATE SET installation=excluded.installation,status_json=excluded.status_json
|
|
24120
|
+
WHERE installation<>excluded.installation OR status_json<>excluded.status_json`
|
|
24121
|
+
).run(workspaceId, memberId, deviceId, installation, JSON.stringify(status));
|
|
24122
|
+
const preference = store.db.prepare(
|
|
24123
|
+
"SELECT enabled FROM client_update_preferences WHERE member_id=? AND installation=?"
|
|
24124
|
+
);
|
|
24125
|
+
const isEnabled = () => preference.get(memberId, installation)?.enabled !== 0;
|
|
24126
|
+
if (!isEnabled()) return { enabled: false, target: null };
|
|
24127
|
+
const release2 = await target2(status.running);
|
|
24128
|
+
const enabled = isEnabled();
|
|
24129
|
+
return { enabled, target: enabled ? release2 : null };
|
|
24130
|
+
});
|
|
24131
|
+
server.put("/web/devices/:device/client-update", async (request) => {
|
|
24132
|
+
webMutation(request);
|
|
24133
|
+
const { workspaceId, memberId } = authorizeWeb(store, request);
|
|
24134
|
+
const { device } = z76.object({ device: z76.uuid() }).parse(request.params);
|
|
24135
|
+
const { enabled } = z76.object({ enabled: z76.boolean() }).parse(request.body);
|
|
24136
|
+
const result = store.db.prepare(
|
|
24137
|
+
`INSERT INTO client_update_preferences(member_id,installation,enabled)
|
|
24138
|
+
SELECT member_id,installation,? FROM client_update_devices WHERE workspace_id=? AND member_id=? AND device_id=?
|
|
24139
|
+
ON CONFLICT(member_id,installation) DO UPDATE SET enabled=excluded.enabled`
|
|
24140
|
+
).run(Number(enabled), workspaceId, memberId, device);
|
|
24141
|
+
if (!result.changes)
|
|
24142
|
+
throw new HubError(404, "DEVICE_NOT_FOUND", "\u627E\u4E0D\u5230\u652F\u6301\u81EA\u52A8\u66F4\u65B0\u7684\u672C\u673A\u8FDE\u63A5\u3002");
|
|
24143
|
+
return { ok: true };
|
|
24144
|
+
});
|
|
23948
24145
|
server.put("/devices/self/status", async (request) => {
|
|
23949
24146
|
const identity = authorizeDevice(store, request);
|
|
23950
24147
|
new ProjectRepository(store).config(identity);
|
|
@@ -23963,16 +24160,25 @@ function registerControlRoutes(server, store) {
|
|
|
23963
24160
|
server.get("/web/devices", async (request) => {
|
|
23964
24161
|
const identity = authorizeWeb(store, request);
|
|
23965
24162
|
const devices = store.db.prepare(
|
|
23966
|
-
`SELECT m.member_id,b.device_id,COALESCE(json_extract(r.config_json,'$.computer.name'),NULLIF(b.label,''),b.device_id) name,d.seen_at,d.status_json
|
|
24163
|
+
`SELECT m.member_id,b.device_id,COALESCE(json_extract(r.config_json,'$.computer.name'),NULLIF(b.label,''),b.device_id) name,d.seen_at,d.status_json,
|
|
24164
|
+
u.status_json update_status,p.enabled update_enabled
|
|
23967
24165
|
FROM members m LEFT JOIN member_devices b USING(workspace_id,member_id)
|
|
23968
24166
|
LEFT JOIN device_status d ON d.workspace_id=b.workspace_id AND d.member_id=b.member_id AND d.device_id=b.device_id
|
|
23969
24167
|
LEFT JOIN member_agent_runtimes r ON r.project_id=m.workspace_id AND r.member_id=m.member_id AND r.device_id=b.device_id
|
|
24168
|
+
LEFT JOIN client_update_devices u ON u.workspace_id=b.workspace_id AND u.member_id=b.member_id AND u.device_id=b.device_id AND u.member_id=?
|
|
24169
|
+
LEFT JOIN client_update_preferences p ON p.member_id=u.member_id AND p.installation=u.installation
|
|
23970
24170
|
WHERE m.workspace_id=? ORDER BY m.member_id,name,b.device_id`
|
|
23971
|
-
).all(identity.workspaceId).map((row) => ({
|
|
24171
|
+
).all(identity.memberId, identity.workspaceId).map((row) => ({
|
|
23972
24172
|
memberId: String(row.member_id),
|
|
23973
24173
|
deviceId: row.device_id,
|
|
23974
24174
|
name: row.name,
|
|
23975
24175
|
bound: Boolean(row.device_id),
|
|
24176
|
+
...row.update_status ? {
|
|
24177
|
+
autoUpdate: {
|
|
24178
|
+
...JSON.parse(String(row.update_status)),
|
|
24179
|
+
enabled: row.update_enabled !== 0
|
|
24180
|
+
}
|
|
24181
|
+
} : {},
|
|
23976
24182
|
lastSeenAt: row.seen_at === null ? null : String(row.seen_at),
|
|
23977
24183
|
status: row.status_json ? DeviceStatusSchema.parse(JSON.parse(String(row.status_json))) : null
|
|
23978
24184
|
}));
|
|
@@ -23981,7 +24187,7 @@ function registerControlRoutes(server, store) {
|
|
|
23981
24187
|
}
|
|
23982
24188
|
|
|
23983
24189
|
// apps/server/project-routes.ts
|
|
23984
|
-
import { z as
|
|
24190
|
+
import { z as z77 } from "zod";
|
|
23985
24191
|
|
|
23986
24192
|
// apps/server/project-activity.ts
|
|
23987
24193
|
function projectWork(hub, identity) {
|
|
@@ -24251,7 +24457,7 @@ function registerProjectScopeRoutes(server, store) {
|
|
|
24251
24457
|
);
|
|
24252
24458
|
server.post("/project/onboarding", async (request) => {
|
|
24253
24459
|
webMutation(request);
|
|
24254
|
-
|
|
24460
|
+
z77.object({}).strict().parse(request.body ?? {});
|
|
24255
24461
|
return recordProjectOnboarding(store, authorizeWeb(store, request));
|
|
24256
24462
|
});
|
|
24257
24463
|
server.get(
|
|
@@ -24313,7 +24519,7 @@ function registerProjectScopeRoutes(server, store) {
|
|
|
24313
24519
|
});
|
|
24314
24520
|
server.patch("/web/members/:id", async (request) => {
|
|
24315
24521
|
webMutation(request);
|
|
24316
|
-
const { id } =
|
|
24522
|
+
const { id } = z77.object({ id: NameSchema }).parse(request.params);
|
|
24317
24523
|
return project.updateMember(
|
|
24318
24524
|
authorizeWeb(store, request),
|
|
24319
24525
|
id,
|
|
@@ -24322,23 +24528,23 @@ function registerProjectScopeRoutes(server, store) {
|
|
|
24322
24528
|
});
|
|
24323
24529
|
server.post("/web/members/:id/device-reset", async (request) => {
|
|
24324
24530
|
webMutation(request);
|
|
24325
|
-
const { id } =
|
|
24326
|
-
const { expectedRevision, deviceId } =
|
|
24327
|
-
expectedRevision:
|
|
24328
|
-
deviceId:
|
|
24531
|
+
const { id } = z77.object({ id: NameSchema }).parse(request.params);
|
|
24532
|
+
const { expectedRevision, deviceId } = z77.object({
|
|
24533
|
+
expectedRevision: z77.number().int().nonnegative().optional(),
|
|
24534
|
+
deviceId: z77.uuid().optional()
|
|
24329
24535
|
}).strict().parse(request.body ?? {});
|
|
24330
24536
|
return project.resetDevice(authorizeWeb(store, request), id, expectedRevision, deviceId);
|
|
24331
24537
|
});
|
|
24332
24538
|
}
|
|
24333
24539
|
|
|
24334
24540
|
// apps/server/diagnostics/routes.ts
|
|
24335
|
-
import { z as
|
|
24541
|
+
import { z as z78 } from "zod";
|
|
24336
24542
|
function registerDiagnosticRoutes(server, hub) {
|
|
24337
24543
|
for (const kind2 of ["file", "related"])
|
|
24338
24544
|
server.get(`/diagnostics/:id/${kind2}`, async (req, reply) => {
|
|
24339
24545
|
const identity = authorizeWeb(hub, req);
|
|
24340
24546
|
requireSiteAdmin(identity);
|
|
24341
|
-
const { id } =
|
|
24547
|
+
const { id } = z78.object({ id: z78.uuid() }).parse(req.params);
|
|
24342
24548
|
const logs = new Diagnostics(hub);
|
|
24343
24549
|
const row = logs.get(identity.workspaceId, id);
|
|
24344
24550
|
reply.header("x-content-type-options", "nosniff");
|
|
@@ -24352,7 +24558,7 @@ function registerDiagnosticRoutes(server, hub) {
|
|
|
24352
24558
|
}
|
|
24353
24559
|
|
|
24354
24560
|
// apps/server/site-routes.ts
|
|
24355
|
-
import { z as
|
|
24561
|
+
import { z as z79 } from "zod";
|
|
24356
24562
|
|
|
24357
24563
|
// apps/server/devices.ts
|
|
24358
24564
|
var DeviceRepository = class {
|
|
@@ -24481,7 +24687,7 @@ function registerSiteRoutes(server, store) {
|
|
|
24481
24687
|
"/api/v1/web/session",
|
|
24482
24688
|
{ onRequest: async (request) => webMutation(request) },
|
|
24483
24689
|
async (request, reply) => {
|
|
24484
|
-
const { id } =
|
|
24690
|
+
const { id } = z79.object({ id: NameSchema }).strict().parse(request.body);
|
|
24485
24691
|
if (server.teammyTaiAuth) {
|
|
24486
24692
|
if (id !== server.teammyTaiAuth.identity(request).loginName)
|
|
24487
24693
|
throw new HubError(403, "TAI_IDENTITY_MISMATCH", "\u767B\u5F55 ID \u5FC5\u987B\u4E0E\u5F53\u524D\u516C\u53F8\u8D26\u53F7\u4E00\u81F4\u3002");
|
|
@@ -24494,7 +24700,7 @@ function registerSiteRoutes(server, store) {
|
|
|
24494
24700
|
server.patch("/api/v1/web/session", async (request) => {
|
|
24495
24701
|
webMutation(request);
|
|
24496
24702
|
const identity = site.identity(cookieToken(request));
|
|
24497
|
-
const { displayName } =
|
|
24703
|
+
const { displayName } = z79.object({ displayName: z79.string().trim().max(120) }).strict().parse(request.body);
|
|
24498
24704
|
return site.renameSelf(identity, displayName);
|
|
24499
24705
|
});
|
|
24500
24706
|
server.delete("/api/v1/web/session", async (request, reply) => {
|
|
@@ -24545,7 +24751,7 @@ function registerSiteRoutes(server, store) {
|
|
|
24545
24751
|
}
|
|
24546
24752
|
|
|
24547
24753
|
// apps/server/session-routes.ts
|
|
24548
|
-
import { z as
|
|
24754
|
+
import { z as z80 } from "zod";
|
|
24549
24755
|
function registerSessionRoutes(server, store) {
|
|
24550
24756
|
const sessions2 = new SessionRepository(store);
|
|
24551
24757
|
server.get(
|
|
@@ -24555,7 +24761,7 @@ function registerSessionRoutes(server, store) {
|
|
|
24555
24761
|
server.put("/web/session-library", async (request) => {
|
|
24556
24762
|
webMutation(request);
|
|
24557
24763
|
const identity = authorizeWeb(store, request);
|
|
24558
|
-
const { enabled } =
|
|
24764
|
+
const { enabled } = z80.object({ enabled: z80.boolean() }).strict().parse(request.body);
|
|
24559
24765
|
return setSessionLibraryPreference(store, identity, enabled);
|
|
24560
24766
|
});
|
|
24561
24767
|
const device = (request) => typeof request.headers["x-teammy-device"] === "string" ? request.headers["x-teammy-device"] : void 0;
|
|
@@ -24565,9 +24771,9 @@ function registerSessionRoutes(server, store) {
|
|
|
24565
24771
|
authorize(request);
|
|
24566
24772
|
}
|
|
24567
24773
|
};
|
|
24568
|
-
const pagination =
|
|
24569
|
-
after:
|
|
24570
|
-
limit:
|
|
24774
|
+
const pagination = z80.object({
|
|
24775
|
+
after: z80.coerce.number().pipe(RevisionSchema).default(0),
|
|
24776
|
+
limit: z80.coerce.number().int().min(1).max(100).default(50)
|
|
24571
24777
|
});
|
|
24572
24778
|
server.post(
|
|
24573
24779
|
"/sessions/commits",
|
|
@@ -24581,17 +24787,17 @@ function registerSessionRoutes(server, store) {
|
|
|
24581
24787
|
server.get("/sessions", async (request) => {
|
|
24582
24788
|
const q = pagination.extend({
|
|
24583
24789
|
owner: NameSchema.optional(),
|
|
24584
|
-
order:
|
|
24790
|
+
order: z80.enum(["created", "title", "updated"]).default("created")
|
|
24585
24791
|
}).parse(request.query);
|
|
24586
24792
|
return sessions2.list(authorizeRead(store, request), q.after, q.limit, q.owner, q.order);
|
|
24587
24793
|
});
|
|
24588
24794
|
server.get("/sessions/stats", async (request) => sessions2.stats(authorizeRead(store, request)));
|
|
24589
24795
|
server.get("/sessions/search", async (request) => {
|
|
24590
24796
|
const q = pagination.extend({
|
|
24591
|
-
order:
|
|
24797
|
+
order: z80.enum(["created", "updated"]).default("created"),
|
|
24592
24798
|
owner: NameSchema.optional(),
|
|
24593
24799
|
sessionKey: HashSchema.optional(),
|
|
24594
|
-
q:
|
|
24800
|
+
q: z80.string().min(1).max(500).refine((s) => !s.includes("\0"))
|
|
24595
24801
|
}).parse(request.query);
|
|
24596
24802
|
return sessions2.search(
|
|
24597
24803
|
authorizeRead(store, request),
|
|
@@ -24603,17 +24809,17 @@ function registerSessionRoutes(server, store) {
|
|
|
24603
24809
|
);
|
|
24604
24810
|
});
|
|
24605
24811
|
server.get("/sessions/:owner/:key", async (request) => {
|
|
24606
|
-
const p =
|
|
24607
|
-
const q =
|
|
24812
|
+
const p = z80.object({ owner: NameSchema, key: HashSchema }).parse(request.params);
|
|
24813
|
+
const q = z80.object({ revision: z80.coerce.number().pipe(RevisionSchema).optional() }).parse(request.query);
|
|
24608
24814
|
return sessions2.read(authorizeRead(store, request), p.owner, p.key, q.revision);
|
|
24609
24815
|
});
|
|
24610
24816
|
server.get("/sessions/:owner/:key/baseline", guard, async (request) => {
|
|
24611
|
-
const p =
|
|
24817
|
+
const p = z80.object({ owner: NameSchema, key: HashSchema }).parse(request.params);
|
|
24612
24818
|
return sessions2.baseline(authorize(request), p.owner, p.key);
|
|
24613
24819
|
});
|
|
24614
24820
|
server.get("/sessions/:owner/:key/analysis/:kind", async (request) => {
|
|
24615
|
-
const p =
|
|
24616
|
-
const q =
|
|
24821
|
+
const p = z80.object({ owner: NameSchema, key: HashSchema, kind: SessionAnalysisKindSchema }).parse(request.params);
|
|
24822
|
+
const q = z80.object({ revision: z80.coerce.number().pipe(RevisionSchema).optional() }).parse(request.query);
|
|
24617
24823
|
const identity = authorizeRead(store, request);
|
|
24618
24824
|
return sessionAnalysisState(
|
|
24619
24825
|
store,
|
|
@@ -24625,13 +24831,13 @@ function registerSessionRoutes(server, store) {
|
|
|
24625
24831
|
});
|
|
24626
24832
|
server.post("/sessions/:owner/:key/handoff", async (request) => {
|
|
24627
24833
|
if (!request.headers.authorization) webMutation(request);
|
|
24628
|
-
const p =
|
|
24834
|
+
const p = z80.object({ owner: NameSchema, key: HashSchema }).parse(request.params);
|
|
24629
24835
|
return requestSessionHandoff(store, authorizeRead(store, request), p.owner, p.key);
|
|
24630
24836
|
});
|
|
24631
24837
|
}
|
|
24632
24838
|
|
|
24633
24839
|
// apps/server/file-routes.ts
|
|
24634
|
-
import { z as
|
|
24840
|
+
import { z as z81 } from "zod";
|
|
24635
24841
|
function registerFileRoutes(server, store) {
|
|
24636
24842
|
const files = new FileRepository(store);
|
|
24637
24843
|
const shared = new SharedFilesRepository(store);
|
|
@@ -24670,14 +24876,14 @@ function registerFileRoutes(server, store) {
|
|
|
24670
24876
|
missing: files.missing(authorize(request), BlobCheckSchema.parse(request.body).hashes)
|
|
24671
24877
|
}));
|
|
24672
24878
|
server.put("/blobs/:hash", { ...guard, bodyLimit: MAX_BLOB_BYTES }, async (request) => {
|
|
24673
|
-
const { hash: hash3 } =
|
|
24879
|
+
const { hash: hash3 } = z81.object({ hash: HashSchema }).parse(request.params);
|
|
24674
24880
|
if (!Buffer.isBuffer(request.body))
|
|
24675
24881
|
throw Object.assign(new Error("Expected binary content"), { statusCode: 400 });
|
|
24676
24882
|
return files.upload(request.headers.authorization, device(request), hash3, request.body);
|
|
24677
24883
|
});
|
|
24678
24884
|
server.get("/blobs/:hash", async (request, reply) => {
|
|
24679
|
-
const { hash: hash3 } =
|
|
24680
|
-
const { view } =
|
|
24885
|
+
const { hash: hash3 } = z81.object({ hash: HashSchema }).parse(request.params);
|
|
24886
|
+
const { view } = z81.object({ view: z81.literal("html").optional() }).parse(request.query);
|
|
24681
24887
|
const bytes3 = await files.download(authorizeRead(store, request), hash3);
|
|
24682
24888
|
if (view === "html") return sendHtmlPreview(reply, bytes3);
|
|
24683
24889
|
return reply.type("application/octet-stream").send(Buffer.from(bytes3.buffer, bytes3.byteOffset, bytes3.byteLength));
|
|
@@ -24720,7 +24926,7 @@ function registerFileRoutes(server, store) {
|
|
|
24720
24926
|
});
|
|
24721
24927
|
server.get("/files/self/operations/:operation", guard, async (request) => {
|
|
24722
24928
|
const actor = authorize(request);
|
|
24723
|
-
const { operation } =
|
|
24929
|
+
const { operation } = z81.object({ operation: z81.uuid() }).parse(request.params);
|
|
24724
24930
|
const row = store.db.prepare(
|
|
24725
24931
|
"SELECT revision FROM file_operations WHERE workspace_id=? AND owner=? AND operation_id=?"
|
|
24726
24932
|
).get(actor.workspaceId, actor.memberId, operation);
|
|
@@ -24728,7 +24934,7 @@ function registerFileRoutes(server, store) {
|
|
|
24728
24934
|
});
|
|
24729
24935
|
server.get("/files/_project/operations/:operation", guard, async (request) => {
|
|
24730
24936
|
const actor = authorize(request);
|
|
24731
|
-
const { operation } =
|
|
24937
|
+
const { operation } = z81.object({ operation: z81.uuid() }).parse(request.params);
|
|
24732
24938
|
const row = store.db.prepare(
|
|
24733
24939
|
"SELECT revision FROM file_operations WHERE workspace_id=? AND owner=? AND operation_id=?"
|
|
24734
24940
|
).get(actor.workspaceId, "_project", operation);
|
|
@@ -24736,7 +24942,7 @@ function registerFileRoutes(server, store) {
|
|
|
24736
24942
|
});
|
|
24737
24943
|
server.get("/files/:owner/operations/:operation", guard, async (request) => {
|
|
24738
24944
|
const actor = authorize(request);
|
|
24739
|
-
const { owner, operation } =
|
|
24945
|
+
const { owner, operation } = z81.object({ owner: FileOwnerSchema, operation: z81.uuid() }).parse(request.params);
|
|
24740
24946
|
const row = store.db.prepare(
|
|
24741
24947
|
"SELECT revision FROM file_operations WHERE workspace_id=? AND owner=? AND operation_id=?"
|
|
24742
24948
|
).get(actor.workspaceId, owner, operation);
|
|
@@ -24747,11 +24953,11 @@ function registerFileRoutes(server, store) {
|
|
|
24747
24953
|
return new TaskFiles(store).resolveName(authorize(request), input.path, input.expectedHash);
|
|
24748
24954
|
});
|
|
24749
24955
|
server.get("/files/:owner/manifest", async (request) => {
|
|
24750
|
-
const { owner } =
|
|
24751
|
-
const query2 =
|
|
24752
|
-
revision:
|
|
24753
|
-
after:
|
|
24754
|
-
limit:
|
|
24956
|
+
const { owner } = z81.object({ owner: FileOwnerSchema }).parse(request.params);
|
|
24957
|
+
const query2 = z81.object({
|
|
24958
|
+
revision: z81.coerce.number().int().min(0).max(Number.MAX_SAFE_INTEGER).optional(),
|
|
24959
|
+
after: z81.string().max(1024).default(""),
|
|
24960
|
+
limit: z81.coerce.number().int().min(1).max(500).default(200)
|
|
24755
24961
|
}).parse(request.query);
|
|
24756
24962
|
return files.manifest(
|
|
24757
24963
|
await fileIdentity(request, owner),
|
|
@@ -24762,20 +24968,20 @@ function registerFileRoutes(server, store) {
|
|
|
24762
24968
|
);
|
|
24763
24969
|
});
|
|
24764
24970
|
server.get("/files/:owner/entry", async (request) => {
|
|
24765
|
-
const { owner } =
|
|
24766
|
-
const q =
|
|
24971
|
+
const { owner } = z81.object({ owner: FileOwnerSchema }).parse(request.params);
|
|
24972
|
+
const q = z81.object({
|
|
24767
24973
|
path: FilePathSchema,
|
|
24768
|
-
revision:
|
|
24974
|
+
revision: z81.coerce.number().int().min(0).max(Number.MAX_SAFE_INTEGER).optional()
|
|
24769
24975
|
}).parse(request.query);
|
|
24770
24976
|
return files.entry(await fileIdentity(request, owner), owner, q.path, q.revision);
|
|
24771
24977
|
});
|
|
24772
24978
|
server.get("/files/:owner/tree", async (request) => {
|
|
24773
|
-
const { owner } =
|
|
24774
|
-
const q =
|
|
24775
|
-
path:
|
|
24776
|
-
revision:
|
|
24777
|
-
after:
|
|
24778
|
-
limit:
|
|
24979
|
+
const { owner } = z81.object({ owner: FileOwnerSchema }).parse(request.params);
|
|
24980
|
+
const q = z81.object({
|
|
24981
|
+
path: z81.union([z81.literal(""), FilePathSchema]).default(""),
|
|
24982
|
+
revision: z81.coerce.number().int().min(0).max(Number.MAX_SAFE_INTEGER).optional(),
|
|
24983
|
+
after: z81.string().max(255).default(""),
|
|
24984
|
+
limit: z81.coerce.number().int().min(1).max(200).default(100)
|
|
24779
24985
|
}).parse(request.query);
|
|
24780
24986
|
return files.tree(
|
|
24781
24987
|
await fileIdentity(request, owner),
|
|
@@ -24787,10 +24993,10 @@ function registerFileRoutes(server, store) {
|
|
|
24787
24993
|
);
|
|
24788
24994
|
});
|
|
24789
24995
|
server.get("/files/:owner/changes", async (request) => {
|
|
24790
|
-
const { owner } =
|
|
24791
|
-
const query2 =
|
|
24792
|
-
after:
|
|
24793
|
-
limit:
|
|
24996
|
+
const { owner } = z81.object({ owner: FileOwnerSchema }).parse(request.params);
|
|
24997
|
+
const query2 = z81.object({
|
|
24998
|
+
after: z81.coerce.number().int().min(0).max(Number.MAX_SAFE_INTEGER).default(0),
|
|
24999
|
+
limit: z81.coerce.number().int().min(1).max(100).default(100)
|
|
24794
25000
|
}).parse(request.query);
|
|
24795
25001
|
return files.changes(await fileIdentity(request, owner), owner, query2.after, query2.limit);
|
|
24796
25002
|
});
|
|
@@ -24833,7 +25039,7 @@ function clearUnread(hub, identity, scope2) {
|
|
|
24833
25039
|
|
|
24834
25040
|
// apps/server/agents/routes.ts
|
|
24835
25041
|
import { createHash as createHash29 } from "node:crypto";
|
|
24836
|
-
import { z as
|
|
25042
|
+
import { z as z82 } from "zod";
|
|
24837
25043
|
|
|
24838
25044
|
// apps/server/agents/ssh-key.ts
|
|
24839
25045
|
import { execFile as execFile2 } from "node:child_process";
|
|
@@ -24892,7 +25098,7 @@ function registerProjectAgentRoutes(server, hub) {
|
|
|
24892
25098
|
webMutation(req);
|
|
24893
25099
|
return topics.publish(authorizeWeb(hub, req), messageId(req.params));
|
|
24894
25100
|
});
|
|
24895
|
-
const messageId = (value) =>
|
|
25101
|
+
const messageId = (value) => z82.object({ id: z82.uuid() }).parse(value).id;
|
|
24896
25102
|
server.addHook("preClose", async () => {
|
|
24897
25103
|
for (const stream of streams) stream.end();
|
|
24898
25104
|
});
|
|
@@ -25054,7 +25260,7 @@ data: ${event.data}
|
|
|
25054
25260
|
server.post("/agents/chats/:id/read", async (req) => {
|
|
25055
25261
|
webMutation(req);
|
|
25056
25262
|
const identity = authorizeWeb(hub, req);
|
|
25057
|
-
const { cursor } =
|
|
25263
|
+
const { cursor } = z82.object({ cursor: z82.number().int().nonnegative() }).strict().parse(req.body);
|
|
25058
25264
|
const id = messageId(req.params);
|
|
25059
25265
|
markChatRead(hub, identity, id, cursor);
|
|
25060
25266
|
return { ok: true };
|
|
@@ -25062,7 +25268,7 @@ data: ${event.data}
|
|
|
25062
25268
|
server.get("/agents/outbox", async (req) => store.messages(authorizeWeb(hub, req)));
|
|
25063
25269
|
server.post("/communication/read", async (req) => {
|
|
25064
25270
|
webMutation(req);
|
|
25065
|
-
const { scope: scope2 } =
|
|
25271
|
+
const { scope: scope2 } = z82.object({ scope: z82.enum(["messages", "channels"]) }).strict().parse(req.body);
|
|
25066
25272
|
return clearUnread(hub, authorizeWeb(hub, req), scope2);
|
|
25067
25273
|
});
|
|
25068
25274
|
server.get("/communication/unread", async (req) => {
|
|
@@ -25191,39 +25397,39 @@ function registerBootstrapRoutes(server, hub) {
|
|
|
25191
25397
|
}
|
|
25192
25398
|
|
|
25193
25399
|
// apps/server/client-access.ts
|
|
25194
|
-
import { z as
|
|
25400
|
+
import { z as z84 } from "zod";
|
|
25195
25401
|
|
|
25196
25402
|
// packages/protocol/client-access.ts
|
|
25197
|
-
import { z as
|
|
25198
|
-
var ConnectSecretSchema =
|
|
25199
|
-
var BrowserConnectRequestSchema =
|
|
25200
|
-
id:
|
|
25403
|
+
import { z as z83 } from "zod";
|
|
25404
|
+
var ConnectSecretSchema = z83.string().regex(/^[a-f0-9]{64}$/);
|
|
25405
|
+
var BrowserConnectRequestSchema = z83.object({
|
|
25406
|
+
id: z83.uuid(),
|
|
25201
25407
|
projectId: NameSchema,
|
|
25202
25408
|
deviceId: DeviceIdSchema,
|
|
25203
25409
|
secret: ConnectSecretSchema,
|
|
25204
|
-
label:
|
|
25410
|
+
label: z83.string().min(1).max(255)
|
|
25205
25411
|
}).strict();
|
|
25206
|
-
var BrowserConnectStartSchema =
|
|
25207
|
-
id:
|
|
25208
|
-
expiresAt:
|
|
25209
|
-
verificationUrl:
|
|
25412
|
+
var BrowserConnectStartSchema = z83.object({
|
|
25413
|
+
id: z83.uuid(),
|
|
25414
|
+
expiresAt: z83.number(),
|
|
25415
|
+
verificationUrl: z83.string().url().optional()
|
|
25210
25416
|
});
|
|
25211
|
-
var BrowserConnectPollSchema =
|
|
25212
|
-
|
|
25213
|
-
|
|
25417
|
+
var BrowserConnectPollSchema = z83.discriminatedUnion("state", [
|
|
25418
|
+
z83.object({ state: z83.literal("pending") }),
|
|
25419
|
+
z83.object({ state: z83.literal("approved"), memberId: NameSchema })
|
|
25214
25420
|
]);
|
|
25215
|
-
var BrowserConnectInfoSchema =
|
|
25216
|
-
projectName:
|
|
25217
|
-
label:
|
|
25421
|
+
var BrowserConnectInfoSchema = z83.object({
|
|
25422
|
+
projectName: z83.string(),
|
|
25423
|
+
label: z83.string(),
|
|
25218
25424
|
approvedBy: NameSchema.nullable(),
|
|
25219
|
-
expiresAt:
|
|
25425
|
+
expiresAt: z83.number()
|
|
25220
25426
|
});
|
|
25221
25427
|
|
|
25222
25428
|
// apps/server/client-access.ts
|
|
25223
25429
|
function registerClientAccess(server, store) {
|
|
25224
25430
|
const project = new ProjectRepository(store);
|
|
25225
25431
|
const read = (id) => {
|
|
25226
|
-
const row = store.db.prepare("SELECT * FROM device_connect_requests WHERE id=?").get(
|
|
25432
|
+
const row = store.db.prepare("SELECT * FROM device_connect_requests WHERE id=?").get(z84.uuid().parse(id));
|
|
25227
25433
|
if (!row || Number(row.expires_at) <= Date.now())
|
|
25228
25434
|
throw new HubError(410, "CONNECT_EXPIRED", "\u8FDE\u63A5\u8BF7\u6C42\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u8FD0\u884C teammy connect\u3002");
|
|
25229
25435
|
return row;
|
|
@@ -25258,7 +25464,7 @@ function registerClientAccess(server, store) {
|
|
|
25258
25464
|
};
|
|
25259
25465
|
});
|
|
25260
25466
|
server.post("/api/v1/devices/connect/:id/poll", async (request) => {
|
|
25261
|
-
const { secret } =
|
|
25467
|
+
const { secret } = z84.object({ secret: ConnectSecretSchema }).strict().parse(request.body);
|
|
25262
25468
|
const row = read(request.params.id);
|
|
25263
25469
|
if (row.secret_hash !== digest(secret))
|
|
25264
25470
|
throw new HubError(
|
|
@@ -25302,19 +25508,21 @@ function registerClientAccess(server, store) {
|
|
|
25302
25508
|
}
|
|
25303
25509
|
|
|
25304
25510
|
// apps/server/client-release.ts
|
|
25305
|
-
import { z as
|
|
25306
|
-
|
|
25307
|
-
|
|
25308
|
-
|
|
25309
|
-
|
|
25511
|
+
import { z as z85 } from "zod";
|
|
25512
|
+
import { readFile as readFile8 } from "node:fs/promises";
|
|
25513
|
+
import { join as join30 } from "node:path";
|
|
25514
|
+
var ReleaseSchema = z85.object({
|
|
25515
|
+
name: z85.literal("@teammy/cli"),
|
|
25516
|
+
"dist-tags": z85.object({
|
|
25517
|
+
latest: z85.string().regex(/^\d+\.\d+\.\d+(?:-[\da-z.-]+)?(?:\+[\da-z.-]+)?$/i)
|
|
25310
25518
|
}),
|
|
25311
|
-
versions:
|
|
25519
|
+
versions: z85.record(z85.string(), z85.unknown())
|
|
25312
25520
|
});
|
|
25313
|
-
function registerClientRelease(server) {
|
|
25521
|
+
function registerClientRelease(server, version2, dataDir) {
|
|
25314
25522
|
let cached;
|
|
25315
25523
|
let expiresAt = 0;
|
|
25316
25524
|
let pending;
|
|
25317
|
-
|
|
25525
|
+
async function latest() {
|
|
25318
25526
|
if (Date.now() >= expiresAt) {
|
|
25319
25527
|
pending ??= (async () => {
|
|
25320
25528
|
try {
|
|
@@ -25323,10 +25531,10 @@ function registerClientRelease(server) {
|
|
|
25323
25531
|
signal: AbortSignal.timeout(5e3)
|
|
25324
25532
|
});
|
|
25325
25533
|
if (!response.ok) throw new Error("Registry unavailable.");
|
|
25326
|
-
const
|
|
25327
|
-
const
|
|
25328
|
-
if (!Object.hasOwn(
|
|
25329
|
-
cached = { version:
|
|
25534
|
+
const release2 = ReleaseSchema.parse(await response.json());
|
|
25535
|
+
const version3 = release2["dist-tags"].latest;
|
|
25536
|
+
if (!Object.hasOwn(release2.versions, version3)) throw new Error("Latest release missing.");
|
|
25537
|
+
cached = { version: version3, versions: Object.keys(release2.versions) };
|
|
25330
25538
|
expiresAt = Date.now() + 5 * 6e4;
|
|
25331
25539
|
} catch {
|
|
25332
25540
|
cached = void 0;
|
|
@@ -25340,11 +25548,25 @@ function registerClientRelease(server) {
|
|
|
25340
25548
|
if (!cached)
|
|
25341
25549
|
throw new HubError(503, "CLIENT_RELEASE_UNAVAILABLE", "\u6682\u65F6\u65E0\u6CD5\u83B7\u53D6\u6700\u65B0\u7248\u5BA2\u6237\u7AEF\u7248\u672C\u3002");
|
|
25342
25550
|
return cached;
|
|
25343
|
-
}
|
|
25551
|
+
}
|
|
25552
|
+
server.get("/api/v1/client/latest", latest);
|
|
25553
|
+
return async (running) => {
|
|
25554
|
+
let target2 = true ? "0.2.20" : version2;
|
|
25555
|
+
if (dataDir) {
|
|
25556
|
+
try {
|
|
25557
|
+
target2 = (await readFile8(join30(dataDir, "client-update-version"), "utf8")).trim();
|
|
25558
|
+
} catch (error) {
|
|
25559
|
+
if (error.code !== "ENOENT") throw error;
|
|
25560
|
+
}
|
|
25561
|
+
}
|
|
25562
|
+
if (!stableVersion.test(target2) || !stableVersion.test(running) || compareVersions(target2, running) <= 0)
|
|
25563
|
+
return null;
|
|
25564
|
+
return (await latest()).versions.includes(target2) ? target2 : null;
|
|
25565
|
+
};
|
|
25344
25566
|
}
|
|
25345
25567
|
|
|
25346
25568
|
// apps/server/wecom/routes.ts
|
|
25347
|
-
import { z as
|
|
25569
|
+
import { z as z86 } from "zod";
|
|
25348
25570
|
|
|
25349
25571
|
// apps/server/wecom/runtime.ts
|
|
25350
25572
|
import { randomUUID as randomUUID40 } from "node:crypto";
|
|
@@ -26141,6 +26363,20 @@ var WecomRuntime = class {
|
|
|
26141
26363
|
const channel = delivery.chat_type === 3 ? JSON.parse(delivery.channel_json) : null;
|
|
26142
26364
|
const target2 = channel ? `channel:${delivery.external_id}:${channel.conversationId}` : `${delivery.chat_type ?? 1}:${delivery.external_id}`;
|
|
26143
26365
|
if (targets.has(target2)) continue;
|
|
26366
|
+
const part = delivery.kind === computerCompletionCategory && /:(\d+)$/.exec(delivery.source_id);
|
|
26367
|
+
if (part) {
|
|
26368
|
+
const base = delivery.source_id.slice(0, part.index);
|
|
26369
|
+
const previous = Number(part[1]) - 1;
|
|
26370
|
+
if (!this.hub.db.prepare(
|
|
26371
|
+
"SELECT 1 FROM wecom_deliveries WHERE bot_id=? AND external_id=? AND kind=? AND source_id=? AND state='sent'"
|
|
26372
|
+
).get(
|
|
26373
|
+
delivery.bot_id,
|
|
26374
|
+
delivery.external_id,
|
|
26375
|
+
delivery.kind,
|
|
26376
|
+
previous ? `${base}:${previous}` : base
|
|
26377
|
+
))
|
|
26378
|
+
continue;
|
|
26379
|
+
}
|
|
26144
26380
|
if (channel?.action === "post" && this.hub.db.prepare(
|
|
26145
26381
|
`SELECT 1 FROM wecom_deliveries WHERE bot_id=? AND external_id=? AND chat_type=3 AND state='pending' AND json_extract(channel_json,'$.action')='post' AND rowid<(SELECT rowid FROM wecom_deliveries WHERE id=?)`
|
|
26146
26382
|
).get(delivery.bot_id, delivery.external_id, delivery.id))
|
|
@@ -26225,7 +26461,7 @@ function registerWecom(server, hub, env, factory) {
|
|
|
26225
26461
|
webMutation(req);
|
|
26226
26462
|
return channels2.bind(
|
|
26227
26463
|
authorizeWeb(hub, req),
|
|
26228
|
-
|
|
26464
|
+
z86.object({ topicId: z86.string().min(1).nullable() }).strict().parse(req.body).topicId
|
|
26229
26465
|
);
|
|
26230
26466
|
});
|
|
26231
26467
|
server.get(`${base}/groups`, async (req) => groups.list(authorizeWeb(hub, req)));
|
|
@@ -26237,7 +26473,7 @@ function registerWecom(server, hub, env, factory) {
|
|
|
26237
26473
|
webMutation(req);
|
|
26238
26474
|
return groups.remove(
|
|
26239
26475
|
authorizeWeb(hub, req),
|
|
26240
|
-
|
|
26476
|
+
z86.object({ chatId: z86.string().min(1) }).parse(req.params).chatId
|
|
26241
26477
|
);
|
|
26242
26478
|
});
|
|
26243
26479
|
server.get(base, async (req) => store.binding(authorizeWeb(hub, req)));
|
|
@@ -26379,20 +26615,20 @@ function registerTaiAuth(server, store, env) {
|
|
|
26379
26615
|
}
|
|
26380
26616
|
|
|
26381
26617
|
// packages/protocol/deployment-migration.ts
|
|
26382
|
-
import { z as
|
|
26618
|
+
import { z as z87 } from "zod";
|
|
26383
26619
|
var ANYDEV_MIGRATION = {
|
|
26384
26620
|
id: "anydev-20261112",
|
|
26385
26621
|
from: "https://ms-cm2lcn7d-100034032793-sw.gw.ap-zhongwei.ti.tencentcs.com/ms-cm2lcn7d",
|
|
26386
26622
|
previous: "https://teammy.woa.com/client",
|
|
26387
26623
|
to: "http://teammy.woa.com/client"
|
|
26388
26624
|
};
|
|
26389
|
-
var DeploymentMigrationSchema =
|
|
26390
|
-
migration:
|
|
26625
|
+
var DeploymentMigrationSchema = z87.object({
|
|
26626
|
+
migration: z87.string(),
|
|
26391
26627
|
binding: BindingSchema
|
|
26392
26628
|
});
|
|
26393
26629
|
|
|
26394
26630
|
// apps/server/messaging/routes.ts
|
|
26395
|
-
import { z as
|
|
26631
|
+
import { z as z88 } from "zod";
|
|
26396
26632
|
function registerEventRouting(server, hub) {
|
|
26397
26633
|
const routing = new EventRouting(hub);
|
|
26398
26634
|
server.get("/web/event-routing", async (req) => routing.settings(authorizeWeb(hub, req)));
|
|
@@ -26438,7 +26674,7 @@ function registerEventRouting(server, hub) {
|
|
|
26438
26674
|
webMutation(req);
|
|
26439
26675
|
return routing.reassign(
|
|
26440
26676
|
authorizeWeb(hub, req),
|
|
26441
|
-
|
|
26677
|
+
z88.object({ id: z88.uuid() }).parse(req.params).id,
|
|
26442
26678
|
req.body
|
|
26443
26679
|
);
|
|
26444
26680
|
});
|
|
@@ -26450,20 +26686,20 @@ function registerEventRouting(server, hub) {
|
|
|
26450
26686
|
"/event-hooks/:id",
|
|
26451
26687
|
async (req) => routing.setHook(
|
|
26452
26688
|
authorizeDevice(hub, req),
|
|
26453
|
-
|
|
26454
|
-
|
|
26689
|
+
z88.object({ id: z88.uuid() }).parse(req.params).id,
|
|
26690
|
+
z88.object({ enabled: z88.boolean() }).strict().parse(req.body).enabled
|
|
26455
26691
|
)
|
|
26456
26692
|
);
|
|
26457
26693
|
server.patch("/web/event-hooks/:id", async (req) => {
|
|
26458
26694
|
webMutation(req);
|
|
26459
26695
|
return routing.setHook(
|
|
26460
26696
|
authorizeWeb(hub, req),
|
|
26461
|
-
|
|
26462
|
-
|
|
26697
|
+
z88.object({ id: z88.uuid() }).parse(req.params).id,
|
|
26698
|
+
z88.object({ enabled: z88.boolean() }).strict().parse(req.body).enabled
|
|
26463
26699
|
);
|
|
26464
26700
|
});
|
|
26465
26701
|
server.get("/web/channel-topics/:id/subscription", async (req) => {
|
|
26466
|
-
const identity = authorizeWeb(hub, req), { id } =
|
|
26702
|
+
const identity = authorizeWeb(hub, req), { id } = z88.object({ id: z88.uuid() }).parse(req.params);
|
|
26467
26703
|
new AgentStore(hub).ownedChat(identity, id);
|
|
26468
26704
|
if (!new WebChannels(hub).isTopic(identity.workspaceId, id))
|
|
26469
26705
|
throw new HubError(404, "TOPIC_NOT_FOUND", "\u8BDD\u9898\u4E0D\u5B58\u5728\u3002");
|
|
@@ -26475,11 +26711,11 @@ function registerEventRouting(server, hub) {
|
|
|
26475
26711
|
});
|
|
26476
26712
|
server.put("/web/channel-topics/:id/subscription", async (req) => {
|
|
26477
26713
|
webMutation(req);
|
|
26478
|
-
const identity = authorizeWeb(hub, req), { id } =
|
|
26714
|
+
const identity = authorizeWeb(hub, req), { id } = z88.object({ id: z88.uuid() }).parse(req.params);
|
|
26479
26715
|
new AgentStore(hub).ownedChat(identity, id);
|
|
26480
26716
|
if (!new WebChannels(hub).isTopic(identity.workspaceId, id))
|
|
26481
26717
|
throw new HubError(404, "TOPIC_NOT_FOUND", "\u8BDD\u9898\u4E0D\u5B58\u5728\u3002");
|
|
26482
|
-
const { subscribed } =
|
|
26718
|
+
const { subscribed } = z88.object({ subscribed: z88.boolean() }).strict().parse(req.body);
|
|
26483
26719
|
if (subscribed)
|
|
26484
26720
|
hub.db.prepare("INSERT OR IGNORE INTO routing_topic_subscriptions VALUES(?,?,?)").run(identity.workspaceId, identity.memberId, id);
|
|
26485
26721
|
else
|
|
@@ -26489,7 +26725,7 @@ function registerEventRouting(server, hub) {
|
|
|
26489
26725
|
return { subscribed };
|
|
26490
26726
|
});
|
|
26491
26727
|
server.get("/web/local-agent-sessions/:id/group-sync", async (req) => {
|
|
26492
|
-
const identity = authorizeWeb(hub, req), { id } =
|
|
26728
|
+
const identity = authorizeWeb(hub, req), { id } = z88.object({ id: ExecutionRef }).parse(req.params);
|
|
26493
26729
|
new MemberSessions(hub).get(identity, id);
|
|
26494
26730
|
return {
|
|
26495
26731
|
enabled: !!hub.db.prepare("SELECT group_sync FROM member_agent_sessions WHERE project_id=? AND id=?").get(identity.workspaceId, id)?.group_sync
|
|
@@ -26497,9 +26733,9 @@ function registerEventRouting(server, hub) {
|
|
|
26497
26733
|
});
|
|
26498
26734
|
server.put("/web/local-agent-sessions/:id/group-sync", async (req) => {
|
|
26499
26735
|
webMutation(req);
|
|
26500
|
-
const identity = authorizeWeb(hub, req), { id } =
|
|
26736
|
+
const identity = authorizeWeb(hub, req), { id } = z88.object({ id: ExecutionRef }).parse(req.params);
|
|
26501
26737
|
new MemberSessions(hub).get(identity, id);
|
|
26502
|
-
const { enabled } =
|
|
26738
|
+
const { enabled } = z88.object({ enabled: z88.boolean() }).strict().parse(req.body);
|
|
26503
26739
|
hub.db.prepare("UPDATE member_agent_sessions SET group_sync=? WHERE project_id=? AND id=?").run(Number(enabled), identity.workspaceId, id);
|
|
26504
26740
|
return { enabled };
|
|
26505
26741
|
});
|
|
@@ -26512,41 +26748,41 @@ function registerHookInbox(server, hub) {
|
|
|
26512
26748
|
async (req) => routing.pollHook(token(req.headers.authorization))
|
|
26513
26749
|
);
|
|
26514
26750
|
server.post("/api/v1/event-hooks/inbox/:id/ack", async (req) => {
|
|
26515
|
-
const { id } =
|
|
26751
|
+
const { id } = z88.object({ id: z88.uuid() }).parse(req.params);
|
|
26516
26752
|
return routing.ackHook(token(req.headers.authorization), id);
|
|
26517
26753
|
});
|
|
26518
26754
|
}
|
|
26519
26755
|
|
|
26520
26756
|
// apps/server/member-execution/routes.ts
|
|
26521
|
-
import { z as
|
|
26757
|
+
import { z as z91 } from "zod";
|
|
26522
26758
|
|
|
26523
26759
|
// apps/server/member-execution/consult.ts
|
|
26524
|
-
import { z as
|
|
26760
|
+
import { z as z90 } from "zod";
|
|
26525
26761
|
|
|
26526
26762
|
// packages/protocol/external-tools.ts
|
|
26527
|
-
import { z as
|
|
26528
|
-
var ToolCatalogSchema =
|
|
26529
|
-
tools:
|
|
26530
|
-
|
|
26531
|
-
name:
|
|
26532
|
-
description:
|
|
26533
|
-
inputSchema:
|
|
26534
|
-
annotations:
|
|
26535
|
-
readOnlyHint:
|
|
26536
|
-
destructiveHint:
|
|
26537
|
-
idempotentHint:
|
|
26538
|
-
openWorldHint:
|
|
26763
|
+
import { z as z89 } from "zod";
|
|
26764
|
+
var ToolCatalogSchema = z89.object({
|
|
26765
|
+
tools: z89.array(
|
|
26766
|
+
z89.object({
|
|
26767
|
+
name: z89.string(),
|
|
26768
|
+
description: z89.string(),
|
|
26769
|
+
inputSchema: z89.object({ type: z89.literal("object") }).passthrough(),
|
|
26770
|
+
annotations: z89.object({
|
|
26771
|
+
readOnlyHint: z89.boolean(),
|
|
26772
|
+
destructiveHint: z89.boolean(),
|
|
26773
|
+
idempotentHint: z89.boolean(),
|
|
26774
|
+
openWorldHint: z89.boolean()
|
|
26539
26775
|
})
|
|
26540
26776
|
})
|
|
26541
26777
|
)
|
|
26542
26778
|
});
|
|
26543
|
-
var ToolResultSchema =
|
|
26544
|
-
var AskTeammySchema =
|
|
26545
|
-
text:
|
|
26546
|
-
conversationId:
|
|
26547
|
-
requestId:
|
|
26779
|
+
var ToolResultSchema = z89.object({ result: z89.unknown() });
|
|
26780
|
+
var AskTeammySchema = z89.object({
|
|
26781
|
+
text: z89.string().trim().min(1),
|
|
26782
|
+
conversationId: z89.uuid().optional(),
|
|
26783
|
+
requestId: z89.string().trim().min(1).max(200)
|
|
26548
26784
|
}).strict();
|
|
26549
|
-
var TeammyReplyQuerySchema =
|
|
26785
|
+
var TeammyReplyQuerySchema = z89.object({ conversationId: z89.uuid(), runId: z89.uuid() }).strict();
|
|
26550
26786
|
|
|
26551
26787
|
// apps/server/member-execution/team-consultations.ts
|
|
26552
26788
|
var TeamConsultations = class {
|
|
@@ -26595,14 +26831,14 @@ var TeamConsultations = class {
|
|
|
26595
26831
|
};
|
|
26596
26832
|
|
|
26597
26833
|
// apps/server/member-execution/consult.ts
|
|
26598
|
-
var ConsultSchema =
|
|
26834
|
+
var ConsultSchema = z90.object({
|
|
26599
26835
|
inputId: ExecutionRef,
|
|
26600
|
-
requestId:
|
|
26601
|
-
text:
|
|
26602
|
-
conversationId:
|
|
26836
|
+
requestId: z90.string().min(1).max(160),
|
|
26837
|
+
text: z90.string().trim().min(1),
|
|
26838
|
+
conversationId: z90.uuid().optional()
|
|
26603
26839
|
}).strict();
|
|
26604
26840
|
function readTeamConsultation(hub, identity, body) {
|
|
26605
|
-
const value =
|
|
26841
|
+
const value = z90.object({ conversationId: z90.uuid(), runId: z90.uuid() }).strict().parse(body);
|
|
26606
26842
|
const details2 = hub.db.prepare("SELECT details_json FROM agent_run_details WHERE run_id=?").get(value.runId);
|
|
26607
26843
|
const input = details2 && JSON.parse(String(details2.details_json)).localExecution?.inputId;
|
|
26608
26844
|
if (!input) throw new HubError(404, "TEAM_CONSULTATION_NOT_FOUND", "\u627E\u4E0D\u5230\u6258\u7BA1\u54A8\u8BE2\u3002");
|
|
@@ -26654,7 +26890,8 @@ function registerMemberExecution(server, hub, previews) {
|
|
|
26654
26890
|
});
|
|
26655
26891
|
server.get("/web/local-agent-sessions/:id/events", async (request, reply) => {
|
|
26656
26892
|
const identity = authorizeWeb(hub, request), session = id(request.params);
|
|
26657
|
-
|
|
26893
|
+
const updatesOnly = z91.object({ updates: z91.literal("1").optional() }).parse(request.query).updates === "1";
|
|
26894
|
+
let cursor = sessions2.eventCursor(identity, session);
|
|
26658
26895
|
reply.hijack();
|
|
26659
26896
|
const response = reply.raw;
|
|
26660
26897
|
response.writeHead(200, {
|
|
@@ -26663,21 +26900,29 @@ function registerMemberExecution(server, hub, previews) {
|
|
|
26663
26900
|
connection: "keep-alive",
|
|
26664
26901
|
"x-accel-buffering": "no"
|
|
26665
26902
|
});
|
|
26666
|
-
const send2 = () =>
|
|
26667
|
-
`id: ${
|
|
26903
|
+
const send2 = () => {
|
|
26904
|
+
if (updatesOnly) response.write(`id: ${cursor}
|
|
26905
|
+
event: change
|
|
26906
|
+
data: ${cursor}
|
|
26907
|
+
|
|
26908
|
+
`);
|
|
26909
|
+
else
|
|
26910
|
+
response.write(
|
|
26911
|
+
`id: ${cursor}
|
|
26668
26912
|
event: snapshot
|
|
26669
|
-
data: ${JSON.stringify(
|
|
26913
|
+
data: ${JSON.stringify(sessions2.chat(identity, session, { from: 1 }))}
|
|
26670
26914
|
|
|
26671
26915
|
`
|
|
26672
|
-
|
|
26916
|
+
);
|
|
26917
|
+
};
|
|
26673
26918
|
streams.add(response);
|
|
26674
26919
|
send2();
|
|
26675
26920
|
let ping = Date.now();
|
|
26676
26921
|
const timer2 = setInterval(() => {
|
|
26677
26922
|
try {
|
|
26678
|
-
const next = sessions2.
|
|
26679
|
-
if (next
|
|
26680
|
-
|
|
26923
|
+
const next = sessions2.eventCursor(authorizeWeb(hub, request), session);
|
|
26924
|
+
if (next !== cursor) {
|
|
26925
|
+
cursor = next;
|
|
26681
26926
|
send2();
|
|
26682
26927
|
}
|
|
26683
26928
|
if (Date.now() - ping > 15e3) {
|
|
@@ -26772,10 +27017,15 @@ data: ${JSON.stringify(snapshot)}
|
|
|
26772
27017
|
webMutation(request);
|
|
26773
27018
|
return sessions2.directorySettings(authorizeWeb(hub, request), id(request.params), request.body);
|
|
26774
27019
|
});
|
|
26775
|
-
server.get(
|
|
26776
|
-
|
|
26777
|
-
|
|
26778
|
-
|
|
27020
|
+
server.get("/web/local-agent-sessions/:id", async (request) => {
|
|
27021
|
+
const seq = z91.coerce.number().int().positive().max(Number.MAX_SAFE_INTEGER);
|
|
27022
|
+
const window = z91.object({
|
|
27023
|
+
before: seq.optional(),
|
|
27024
|
+
from: seq.optional(),
|
|
27025
|
+
question: z91.string().max(500).optional()
|
|
27026
|
+
}).parse(request.query);
|
|
27027
|
+
return sessions2.chat(authorizeWeb(hub, request), id(request.params), window);
|
|
27028
|
+
});
|
|
26779
27029
|
server.put("/web/local-agent-sessions/:id/metadata", async (request) => {
|
|
26780
27030
|
webMutation(request);
|
|
26781
27031
|
return sessions2.metadata(authorizeWeb(hub, request), id(request.params), request.body);
|
|
@@ -26783,7 +27033,7 @@ data: ${JSON.stringify(snapshot)}
|
|
|
26783
27033
|
server.post("/web/local-agents/:id/history", async (request) => {
|
|
26784
27034
|
webMutation(request);
|
|
26785
27035
|
const identity = authorizeWeb(hub, request);
|
|
26786
|
-
const value =
|
|
27036
|
+
const value = z91.object({ id: z91.uuid(), argument: z91.string() }).parse(request.body);
|
|
26787
27037
|
return sessions2.command(identity, sessions2.directoryHistory(identity, id(request.params)), {
|
|
26788
27038
|
...value,
|
|
26789
27039
|
kind: "history"
|
|
@@ -26791,7 +27041,7 @@ data: ${JSON.stringify(snapshot)}
|
|
|
26791
27041
|
});
|
|
26792
27042
|
server.get("/web/local-agents/:id/history/:command", async (request) => {
|
|
26793
27043
|
const identity = authorizeWeb(hub, request);
|
|
26794
|
-
const params2 =
|
|
27044
|
+
const params2 = z91.object({ id: z91.string(), command: z91.string() }).parse(request.params);
|
|
26795
27045
|
return sessions2.history(
|
|
26796
27046
|
identity,
|
|
26797
27047
|
sessions2.directoryHistory(identity, params2.id, params2.command),
|
|
@@ -26807,11 +27057,11 @@ data: ${JSON.stringify(snapshot)}
|
|
|
26807
27057
|
return sessions2.read(authorizeWeb(hub, request), id(request.params));
|
|
26808
27058
|
});
|
|
26809
27059
|
server.get("/web/local-agent-sessions/:id/diff/:command", async (request) => {
|
|
26810
|
-
const params2 =
|
|
27060
|
+
const params2 = z91.object({ id: z91.string(), command: z91.uuid() }).parse(request.params);
|
|
26811
27061
|
return sessions2.diff(authorizeWeb(hub, request), params2.id, params2.command);
|
|
26812
27062
|
});
|
|
26813
27063
|
server.get("/web/local-agent-sessions/:id/history/:command", async (request) => {
|
|
26814
|
-
const params2 =
|
|
27064
|
+
const params2 = z91.object({ id: z91.string(), command: z91.uuid() }).parse(request.params);
|
|
26815
27065
|
return sessions2.history(authorizeWeb(hub, request), params2.id, params2.command);
|
|
26816
27066
|
});
|
|
26817
27067
|
server.post("/web/local-agent-sessions/:id/commands", async (request) => {
|
|
@@ -26821,13 +27071,13 @@ data: ${JSON.stringify(snapshot)}
|
|
|
26821
27071
|
server.post("/web/local-agent-sessions/:id/messages", async (request) => {
|
|
26822
27072
|
webMutation(request);
|
|
26823
27073
|
const identity = authorizeWeb(hub, request), session = sessions2.get(identity, id(request.params));
|
|
26824
|
-
const value =
|
|
26825
|
-
id:
|
|
26826
|
-
body:
|
|
26827
|
-
delivery:
|
|
26828
|
-
images:
|
|
26829
|
-
attachments:
|
|
26830
|
-
skills:
|
|
27074
|
+
const value = z91.object({
|
|
27075
|
+
id: z91.uuid(),
|
|
27076
|
+
body: z91.string().trim().max(2e5),
|
|
27077
|
+
delivery: z91.enum(["auto", "queue"]).optional(),
|
|
27078
|
+
images: z91.array(z91.uuid()).max(MAX_SESSION_IMAGES).default([]),
|
|
27079
|
+
attachments: z91.array(z91.uuid()).max(MAX_SESSION_IMAGES).default([]),
|
|
27080
|
+
skills: z91.array(z91.object({ name: z91.string(), path: z91.string() })).optional()
|
|
26831
27081
|
}).parse(request.body);
|
|
26832
27082
|
if (!store.sessionCapable(identity, session.directory))
|
|
26833
27083
|
throw new HubError(409, "CLIENT_UPGRADE", "\u8BF7\u5347\u7EA7\u5BA2\u6237\u7AEF\u540E\u4F7F\u7528\u7535\u8111\u4F1A\u8BDD\u3002");
|
|
@@ -26881,7 +27131,7 @@ data: ${JSON.stringify(snapshot)}
|
|
|
26881
27131
|
}
|
|
26882
27132
|
});
|
|
26883
27133
|
});
|
|
26884
|
-
const questionParams =
|
|
27134
|
+
const questionParams = z91.object({ id: z91.string(), question: z91.string() });
|
|
26885
27135
|
server.post("/web/local-agent-sessions/:id/questions/:question/presented", async (request) => {
|
|
26886
27136
|
webMutation(request);
|
|
26887
27137
|
const params2 = questionParams.parse(request.params);
|
|
@@ -26890,13 +27140,13 @@ data: ${JSON.stringify(snapshot)}
|
|
|
26890
27140
|
server.post("/web/local-agent-sessions/:id/questions/:question/answers", async (request) => {
|
|
26891
27141
|
webMutation(request);
|
|
26892
27142
|
const identity = authorizeWeb(hub, request), params2 = questionParams.parse(request.params);
|
|
26893
|
-
const value =
|
|
26894
|
-
id:
|
|
26895
|
-
body:
|
|
26896
|
-
decision:
|
|
26897
|
-
actionId:
|
|
26898
|
-
selections:
|
|
26899
|
-
answers:
|
|
27143
|
+
const value = z91.object({
|
|
27144
|
+
id: z91.uuid(),
|
|
27145
|
+
body: z91.string().trim().min(1),
|
|
27146
|
+
decision: z91.boolean().optional(),
|
|
27147
|
+
actionId: z91.string().max(100).optional(),
|
|
27148
|
+
selections: z91.record(z91.string(), z91.array(z91.string().max(500)).max(20)).optional(),
|
|
27149
|
+
answers: z91.record(z91.string(), z91.string().max(12e3)).optional()
|
|
26900
27150
|
}).parse(request.body);
|
|
26901
27151
|
const session = sessions2.get(identity, params2.id), question = sessions2.question(identity, params2.id, params2.question);
|
|
26902
27152
|
const content = JSON.parse(String(question.content_json));
|
|
@@ -26971,7 +27221,7 @@ data: ${JSON.stringify(snapshot)}
|
|
|
26971
27221
|
"/local-agent/event-reply",
|
|
26972
27222
|
async (request) => replyToRoutedRequest(hub, authorizeDevice(hub, request), request.body)
|
|
26973
27223
|
);
|
|
26974
|
-
const id = (params2) =>
|
|
27224
|
+
const id = (params2) => z91.object({ id: ExecutionRef }).parse(params2).id;
|
|
26975
27225
|
server.get("/local-agent/directories", async (request) => ({
|
|
26976
27226
|
directories: store.directories(authorizeDevice(hub, request)).map(({ deviceId: _, ...directory }) => directory)
|
|
26977
27227
|
}));
|
|
@@ -26989,7 +27239,7 @@ data: ${JSON.stringify(snapshot)}
|
|
|
26989
27239
|
);
|
|
26990
27240
|
server.get("/local-agent/inputs", async (request) => {
|
|
26991
27241
|
const identity = authorizeDevice(hub, request);
|
|
26992
|
-
const query2 =
|
|
27242
|
+
const query2 = z91.object({ instance: z91.uuid(), cursor: z91.coerce.number().int().nonnegative().default(0) }).parse(request.query);
|
|
26993
27243
|
return store.poll(identity, query2.instance, query2.cursor);
|
|
26994
27244
|
});
|
|
26995
27245
|
server.get(
|
|
@@ -27027,10 +27277,10 @@ data: ${JSON.stringify(snapshot)}
|
|
|
27027
27277
|
server.get("/web/local-agents", async (request) => ({
|
|
27028
27278
|
directories: store.directories(authorizeWeb(hub, request))
|
|
27029
27279
|
}));
|
|
27030
|
-
const codeInput =
|
|
27280
|
+
const codeInput = z91.object({
|
|
27031
27281
|
directory: ExecutionRef,
|
|
27032
27282
|
session: ExecutionRef.optional(),
|
|
27033
|
-
expectedRevision:
|
|
27283
|
+
expectedRevision: z91.number().int().nonnegative()
|
|
27034
27284
|
}).strict();
|
|
27035
27285
|
server.post("/web/local-agent-bindings/codes", async (request) => {
|
|
27036
27286
|
webMutation(request);
|
|
@@ -27064,7 +27314,7 @@ data: ${JSON.stringify(snapshot)}
|
|
|
27064
27314
|
async (request) => bridge.messageStatus(authorizeDevice(hub, request), id(request.params))
|
|
27065
27315
|
);
|
|
27066
27316
|
server.post("/local-agent/questions/:id/reserve", async (request) => {
|
|
27067
|
-
const value =
|
|
27317
|
+
const value = z91.object({ replyContext: ExecutionRef }).strict().parse(request.body);
|
|
27068
27318
|
return bridge.reserveQuestion(
|
|
27069
27319
|
authorizeDevice(hub, request),
|
|
27070
27320
|
id(request.params),
|
|
@@ -27202,7 +27452,7 @@ function buildServer(options) {
|
|
|
27202
27452
|
return reply.code(status).send(body);
|
|
27203
27453
|
});
|
|
27204
27454
|
server.get("/healthz", async () => ({ status: "ok" }));
|
|
27205
|
-
registerClientRelease(server);
|
|
27455
|
+
const clientUpdateTarget = registerClientRelease(server, options.version, options.dataDir);
|
|
27206
27456
|
server.get("/api/v1/server", async () => ({
|
|
27207
27457
|
name: "teammy",
|
|
27208
27458
|
version: options.version,
|
|
@@ -27248,6 +27498,7 @@ function buildServer(options) {
|
|
|
27248
27498
|
"local-session-activity-v1",
|
|
27249
27499
|
"local-session-question-delivery-v1",
|
|
27250
27500
|
"local-agent-providers-v1",
|
|
27501
|
+
acpProvidersCapability,
|
|
27251
27502
|
"event-routing-v1",
|
|
27252
27503
|
"internal-team-consult-v1"
|
|
27253
27504
|
] : []
|
|
@@ -27281,7 +27532,7 @@ function buildServer(options) {
|
|
|
27281
27532
|
registerProjectScopeRoutes(scope2, store);
|
|
27282
27533
|
registerAiJobRoutes(scope2, store);
|
|
27283
27534
|
registerTaskRoutes(scope2, store);
|
|
27284
|
-
registerControlRoutes(scope2, store);
|
|
27535
|
+
registerControlRoutes(scope2, store, clientUpdateTarget);
|
|
27285
27536
|
registerFileRoutes(scope2, store);
|
|
27286
27537
|
registerMaterialRoutes(scope2, store);
|
|
27287
27538
|
registerMemoryRoutes(scope2, store);
|
|
@@ -27308,7 +27559,7 @@ function buildServer(options) {
|
|
|
27308
27559
|
|
|
27309
27560
|
// apps/server/main.ts
|
|
27310
27561
|
import { homedir } from "node:os";
|
|
27311
|
-
import { join as
|
|
27562
|
+
import { join as join31, resolve as resolve6 } from "node:path";
|
|
27312
27563
|
import { spawn as spawn4 } from "node:child_process";
|
|
27313
27564
|
var help = `teammy-server \u2014 the Teammy collaboration hub
|
|
27314
27565
|
|
|
@@ -27353,7 +27604,7 @@ async function runServerCli(args, version2) {
|
|
|
27353
27604
|
confirm: { type: "boolean" },
|
|
27354
27605
|
"data-dir": {
|
|
27355
27606
|
type: "string",
|
|
27356
|
-
default: process.env.TEAMMY_DATA_DIR ??
|
|
27607
|
+
default: process.env.TEAMMY_DATA_DIR ?? join31(homedir(), ".teammy", "server")
|
|
27357
27608
|
}
|
|
27358
27609
|
}
|
|
27359
27610
|
});
|
|
@@ -27376,7 +27627,7 @@ async function runServerCli(args, version2) {
|
|
|
27376
27627
|
options: {
|
|
27377
27628
|
"data-dir": {
|
|
27378
27629
|
type: "string",
|
|
27379
|
-
default: process.env.TEAMMY_DATA_DIR ??
|
|
27630
|
+
default: process.env.TEAMMY_DATA_DIR ?? join31(homedir(), ".teammy", "server")
|
|
27380
27631
|
},
|
|
27381
27632
|
once: { type: "boolean" }
|
|
27382
27633
|
}
|
|
@@ -27395,7 +27646,7 @@ async function runServerCli(args, version2) {
|
|
|
27395
27646
|
member: { type: "string" },
|
|
27396
27647
|
"data-dir": {
|
|
27397
27648
|
type: "string",
|
|
27398
|
-
default: process.env.TEAMMY_DATA_DIR ??
|
|
27649
|
+
default: process.env.TEAMMY_DATA_DIR ?? join31(homedir(), ".teammy", "server")
|
|
27399
27650
|
}
|
|
27400
27651
|
}
|
|
27401
27652
|
});
|
|
@@ -27423,7 +27674,7 @@ async function runServerCli(args, version2) {
|
|
|
27423
27674
|
port: { type: "string", default: process.env.TEAMMY_PORT ?? "4317" },
|
|
27424
27675
|
"data-dir": {
|
|
27425
27676
|
type: "string",
|
|
27426
|
-
default: process.env.TEAMMY_DATA_DIR ??
|
|
27677
|
+
default: process.env.TEAMMY_DATA_DIR ?? join31(homedir(), ".teammy", "server")
|
|
27427
27678
|
},
|
|
27428
27679
|
"with-worker": { type: "boolean", default: false }
|
|
27429
27680
|
}
|