dsh-multigameassistant 2.0.5 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cordis.patch.yml +178 -4
- package/lib/analyzer.js +5 -3
- package/lib/browser.js +279 -0
- package/lib/{chunk-KHO3SRUJ.js → chunk-77ZYHRN7.js} +4 -2
- package/lib/{chunk-PAJOD6LV.js → chunk-EOWM56PA.js} +384 -54
- package/lib/{chunk-IOBYH4RN.js → chunk-FH64SAZU.js} +76 -1
- package/lib/{chunk-TD4YFQWE.js → chunk-MEKSHT6V.js} +623 -165
- package/lib/chunk-RESS7WVY.js +157 -0
- package/lib/{chunk-BTT2GBTQ.js → chunk-SHTX4AGU.js} +1 -3670
- package/lib/{chunk-4Q4EH73S.js → chunk-TWUATN5X.js} +13 -9
- package/lib/chunk-V2X4PLF5.js +3730 -0
- package/lib/emulator.js +5 -3
- package/lib/feishu.js +8 -6
- package/lib/game-intel.js +90 -9
- package/lib/gateway.js +9 -6
- package/lib/guard.js +5 -3
- package/lib/intervene.js +62 -18
- package/lib/low-context.js +13 -2
- package/lib/monitor.js +90 -10
- package/lib/notify.js +6 -5
- package/lib/orchestrator.js +14 -10
- package/lib/qqbot.js +8 -6
- package/lib/runner.js +18 -5
- package/lib/scheduler.js +4 -2
- package/lib/script-registry.js +190 -208
- package/package.json +5 -4
- package/skills/pipeline-planning.md +1 -1
- package/skills/web-reading.md +2 -0
- package/web/assets/index-C-csjWiw.js +244 -0
- package/web/assets/index-C-csjWiw.js.map +1 -0
- package/web/assets/index-CjtVfcDS.css +1 -0
- package/web/index.html +2 -2
- package/lib/chunk-CCAB6XXZ.js +0 -34
- package/web/assets/index-BuStplKb.js +0 -242
- package/web/assets/index-BuStplKb.js.map +0 -1
- package/web/assets/index-CSB3B28L.css +0 -1
|
@@ -2,10 +2,10 @@ import { createRequire as __adgCreateRequire } from 'node:module'; import { dirn
|
|
|
2
2
|
import {
|
|
3
3
|
SUMMARIES_FILE,
|
|
4
4
|
summariesReader
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-FH64SAZU.js";
|
|
6
6
|
import {
|
|
7
7
|
writeFileAtomic
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-RESS7WVY.js";
|
|
9
9
|
import {
|
|
10
10
|
AGENTS_CAPABILITY,
|
|
11
11
|
AGENT_AREAS,
|
|
@@ -36,11 +36,13 @@ import {
|
|
|
36
36
|
SKILL_NAME,
|
|
37
37
|
areaOf,
|
|
38
38
|
classify,
|
|
39
|
-
external_exports,
|
|
40
39
|
personaOf,
|
|
41
40
|
personaPrompt,
|
|
42
41
|
threadsBetween
|
|
43
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-V2X4PLF5.js";
|
|
43
|
+
import {
|
|
44
|
+
external_exports
|
|
45
|
+
} from "./chunk-SHTX4AGU.js";
|
|
44
46
|
import {
|
|
45
47
|
__commonJS,
|
|
46
48
|
__require,
|
|
@@ -3235,7 +3237,7 @@ var require_stream = __commonJS({
|
|
|
3235
3237
|
};
|
|
3236
3238
|
duplex._final = function(callback) {
|
|
3237
3239
|
if (ws.readyState === ws.CONNECTING) {
|
|
3238
|
-
ws.once("open", function
|
|
3240
|
+
ws.once("open", function open2() {
|
|
3239
3241
|
duplex._final(callback);
|
|
3240
3242
|
});
|
|
3241
3243
|
return;
|
|
@@ -3256,7 +3258,7 @@ var require_stream = __commonJS({
|
|
|
3256
3258
|
};
|
|
3257
3259
|
duplex._write = function(chunk, encoding, callback) {
|
|
3258
3260
|
if (ws.readyState === ws.CONNECTING) {
|
|
3259
|
-
ws.once("open", function
|
|
3261
|
+
ws.once("open", function open2() {
|
|
3260
3262
|
duplex._write(chunk, encoding, callback);
|
|
3261
3263
|
});
|
|
3262
3264
|
return;
|
|
@@ -3718,11 +3720,11 @@ var require_websocket_server = __commonJS({
|
|
|
3718
3720
|
});
|
|
3719
3721
|
|
|
3720
3722
|
// packages/gateway/lib/index.js
|
|
3721
|
-
import { execFile } from "node:child_process";
|
|
3723
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
3722
3724
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
3723
|
-
import { existsSync, mkdirSync as
|
|
3724
|
-
import { dirname as
|
|
3725
|
-
import { fileURLToPath } from "node:url";
|
|
3725
|
+
import { existsSync, mkdirSync as mkdirSync6, readFileSync as readFileSync3, writeFileSync } from "node:fs";
|
|
3726
|
+
import { dirname as dirname7, join as join8 } from "node:path";
|
|
3727
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
3726
3728
|
import { Service } from "@deepseek-ai/cordis";
|
|
3727
3729
|
|
|
3728
3730
|
// packages/gateway/lib/credentials.js
|
|
@@ -3788,18 +3790,39 @@ function toProviderModel(entry) {
|
|
|
3788
3790
|
};
|
|
3789
3791
|
}
|
|
3790
3792
|
var RETRY_POLICY = { mode: "normal", maxRetries: 3, retryableCodes: ["EMPTY_RESPONSE", "RATE_LIMIT", "SERVER", "TIMEOUT", "TRANSPORT", "PI_AI_ERROR"] };
|
|
3791
|
-
|
|
3793
|
+
function needsSystemRole(profile) {
|
|
3794
|
+
if (profile.api !== "openai-completions")
|
|
3795
|
+
return false;
|
|
3796
|
+
if (originOf(str(profile.baseURL)) === OPENAI_ORIGIN)
|
|
3797
|
+
return false;
|
|
3798
|
+
const compat = profile.compat;
|
|
3799
|
+
return compat?.supportsDeveloperRole === void 0;
|
|
3800
|
+
}
|
|
3801
|
+
var SYSTEM_ROLE_OP = (id) => ({ op: "set", path: ["providers", id, "compat", "supportsDeveloperRole"], value: false });
|
|
3802
|
+
async function addRouteDefaults(settings, namespace) {
|
|
3792
3803
|
const descriptor = settings.describe({ redactSecrets: true }).find((d) => d.ns === namespace);
|
|
3793
3804
|
if (descriptor === void 0)
|
|
3794
3805
|
return 0;
|
|
3795
|
-
|
|
3806
|
+
let routes = 0;
|
|
3807
|
+
const effective = routesOf(descriptor.value);
|
|
3808
|
+
const ops = Object.entries(routesOf(descriptor.user)).flatMap(([id, profile]) => {
|
|
3809
|
+
const route = [
|
|
3810
|
+
...profile.retryPolicy === void 0 ? [{ op: "set", path: ["providers", id, "retryPolicy"], value: structuredClone(RETRY_POLICY) }] : [],
|
|
3811
|
+
// The effective value, so a base layer's api or baseURL counts too.
|
|
3812
|
+
...needsSystemRole(effective[id] ?? profile) ? [SYSTEM_ROLE_OP(id)] : []
|
|
3813
|
+
];
|
|
3814
|
+
if (route.length > 0)
|
|
3815
|
+
routes += 1;
|
|
3816
|
+
return route;
|
|
3817
|
+
});
|
|
3796
3818
|
if (ops.length > 0)
|
|
3797
3819
|
await settings.mutate(namespace, ops, descriptor.revision);
|
|
3798
|
-
return
|
|
3820
|
+
return routes;
|
|
3799
3821
|
}
|
|
3800
3822
|
var OFFICIAL_PROVIDER = "deepseek-official";
|
|
3801
3823
|
var OFFICIAL_NAMESPACE = "llm-deepseek-api-key";
|
|
3802
3824
|
var DEEPSEEK_ORIGIN = "https://api.deepseek.com";
|
|
3825
|
+
var OPENAI_ORIGIN = "https://api.openai.com";
|
|
3803
3826
|
var BALANCE_URL = `${DEEPSEEK_ORIGIN}/user/balance`;
|
|
3804
3827
|
var BALANCE_TIMEOUT_MS = 15e3;
|
|
3805
3828
|
var originOf = (url) => {
|
|
@@ -3971,7 +3994,8 @@ function providersCapability(deps) {
|
|
|
3971
3994
|
api: params.api,
|
|
3972
3995
|
baseURL: params.baseURL,
|
|
3973
3996
|
models,
|
|
3974
|
-
retryPolicy: structuredClone(RETRY_POLICY)
|
|
3997
|
+
retryPolicy: structuredClone(RETRY_POLICY),
|
|
3998
|
+
...needsSystemRole(params) ? { compat: { supportsDeveloperRole: false } } : {}
|
|
3975
3999
|
}
|
|
3976
4000
|
}] : [
|
|
3977
4001
|
displayName === "" ? { op: "unset", path: [...base, "displayName"] } : { op: "set", path: [...base, "displayName"], value: displayName },
|
|
@@ -3979,7 +4003,9 @@ function providersCapability(deps) {
|
|
|
3979
4003
|
{ op: "set", path: [...base, "baseURL"], value: params.baseURL },
|
|
3980
4004
|
{ op: "set", path: [...base, "models"], value: models },
|
|
3981
4005
|
...currentRef === void 0 && apiKeyRef !== void 0 ? [{ op: "set", path: [...base, "apiKeyEnv"], value: apiKeyRef }] : [],
|
|
3982
|
-
...existing?.retryPolicy === void 0 ? [{ op: "set", path: [...base, "retryPolicy"], value: structuredClone(RETRY_POLICY) }] : []
|
|
4006
|
+
...existing?.retryPolicy === void 0 ? [{ op: "set", path: [...base, "retryPolicy"], value: structuredClone(RETRY_POLICY) }] : [],
|
|
4007
|
+
// Switched to Chat Completions, or moved off OpenAI's own API: its gateway may not take `developer`.
|
|
4008
|
+
...needsSystemRole({ api: params.api, baseURL: params.baseURL, compat: existing?.compat }) ? [SYSTEM_ROLE_OP(params.id)] : []
|
|
3983
4009
|
];
|
|
3984
4010
|
const revision = await write(ops, params.expectedRevision);
|
|
3985
4011
|
if (storesKey && apiKeyRef !== void 0)
|
|
@@ -4145,6 +4171,59 @@ function aboutCapability(deps = {}) {
|
|
|
4145
4171
|
};
|
|
4146
4172
|
}
|
|
4147
4173
|
|
|
4174
|
+
// packages/gateway/lib/image-file.js
|
|
4175
|
+
import { readFile, stat } from "node:fs/promises";
|
|
4176
|
+
import { isAbsolute, resolve } from "node:path";
|
|
4177
|
+
import { fileURLToPath } from "node:url";
|
|
4178
|
+
var IMAGE_TYPES = {
|
|
4179
|
+
png: "image/png",
|
|
4180
|
+
jpg: "image/jpeg",
|
|
4181
|
+
jpeg: "image/jpeg",
|
|
4182
|
+
gif: "image/gif",
|
|
4183
|
+
webp: "image/webp",
|
|
4184
|
+
bmp: "image/bmp"
|
|
4185
|
+
};
|
|
4186
|
+
var IMAGE_FILE_MAX_BYTES = 25 * 1024 * 1024;
|
|
4187
|
+
function imageFilePath(written, workspace) {
|
|
4188
|
+
let path = written.trim();
|
|
4189
|
+
if (/^file:/i.test(path)) {
|
|
4190
|
+
try {
|
|
4191
|
+
path = fileURLToPath(path);
|
|
4192
|
+
} catch {
|
|
4193
|
+
throw new RpcError(ErrorCode.InvalidParams, `\u4E0D\u662F\u6709\u6548\u7684\u6587\u4EF6\u5730\u5740\uFF1A${written}`);
|
|
4194
|
+
}
|
|
4195
|
+
}
|
|
4196
|
+
try {
|
|
4197
|
+
path = decodeURIComponent(path);
|
|
4198
|
+
} catch {
|
|
4199
|
+
}
|
|
4200
|
+
const drive = /^\/([A-Za-z])\/(.*)$/.exec(path);
|
|
4201
|
+
if (drive !== null && process.platform === "win32")
|
|
4202
|
+
path = `${drive[1].toUpperCase()}:/${drive[2]}`;
|
|
4203
|
+
path = path.replace(/[?#].*$/, "");
|
|
4204
|
+
if (!isAbsolute(path)) {
|
|
4205
|
+
if (workspace === void 0)
|
|
4206
|
+
throw new RpcError(ErrorCode.InvalidParams, `\u4E0D\u77E5\u9053\u76F8\u5BF9\u8DEF\u5F84\u4ECE\u54EA\u91CC\u7B97\u8D77\uFF1A${written}`);
|
|
4207
|
+
path = resolve(workspace, path);
|
|
4208
|
+
}
|
|
4209
|
+
return resolve(path);
|
|
4210
|
+
}
|
|
4211
|
+
function imageMediaType(path) {
|
|
4212
|
+
return IMAGE_TYPES[/\.([A-Za-z0-9]+)$/.exec(path)?.[1]?.toLowerCase() ?? ""];
|
|
4213
|
+
}
|
|
4214
|
+
async function readImageFile(written, workspace) {
|
|
4215
|
+
const path = imageFilePath(written, workspace);
|
|
4216
|
+
const mediaType = imageMediaType(path);
|
|
4217
|
+
if (mediaType === void 0)
|
|
4218
|
+
throw new RpcError(ErrorCode.InvalidParams, `\u4E0D\u662F\u56FE\u7247\u6587\u4EF6\uFF1A${path}`);
|
|
4219
|
+
const info = await stat(path).catch(() => void 0);
|
|
4220
|
+
if (info === void 0 || !info.isFile())
|
|
4221
|
+
throw new RpcError(ErrorCode.NotFound, `\u627E\u4E0D\u5230\u8FD9\u4E2A\u6587\u4EF6\uFF1A${path}`);
|
|
4222
|
+
if (info.size > IMAGE_FILE_MAX_BYTES)
|
|
4223
|
+
throw new RpcError(ErrorCode.InvalidParams, `\u56FE\u7247\u592A\u5927\uFF08${Math.round(info.size / 1024 / 1024)} MB\uFF09\uFF0C\u6253\u5F00\u6587\u4EF6\u770B`);
|
|
4224
|
+
return { mediaType, data: (await readFile(path)).toString("base64"), path };
|
|
4225
|
+
}
|
|
4226
|
+
|
|
4148
4227
|
// packages/gateway/lib/approvals.js
|
|
4149
4228
|
var ApprovalBroker = class {
|
|
4150
4229
|
pending = /* @__PURE__ */ new Map();
|
|
@@ -4180,13 +4259,13 @@ var ApprovalBroker = class {
|
|
|
4180
4259
|
...ask.reason === void 0 ? {} : { reason: ask.reason },
|
|
4181
4260
|
...ask.displayReason === void 0 ? {} : { displayReason: { ...ask.displayReason } }
|
|
4182
4261
|
};
|
|
4183
|
-
return new Promise((
|
|
4262
|
+
return new Promise((resolve4) => {
|
|
4184
4263
|
const onAbort = () => this.settle(approvalId, "cancelled");
|
|
4185
4264
|
this.pending.set(approvalId, {
|
|
4186
4265
|
request,
|
|
4187
4266
|
settle: (outcome) => {
|
|
4188
4267
|
ask.signal?.removeEventListener("abort", onAbort);
|
|
4189
|
-
|
|
4268
|
+
resolve4(outcome);
|
|
4190
4269
|
}
|
|
4191
4270
|
});
|
|
4192
4271
|
ask.signal?.addEventListener("abort", onAbort, { once: true });
|
|
@@ -4230,7 +4309,7 @@ function safely(fn, fallback) {
|
|
|
4230
4309
|
}
|
|
4231
4310
|
|
|
4232
4311
|
// packages/gateway/lib/skill-save.js
|
|
4233
|
-
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
4312
|
+
import { mkdir, readFile as readFile2, rm, writeFile } from "node:fs/promises";
|
|
4234
4313
|
import { join } from "node:path";
|
|
4235
4314
|
var Args = external_exports.object({
|
|
4236
4315
|
name: external_exports.string().regex(SKILL_NAME, "\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u77ED\u6A2A\u7EBF\uFF0C\u4F8B\u5982 maa-daily-check").max(MAX_SKILL_NAME),
|
|
@@ -4249,7 +4328,7 @@ async function saveSkill(deps, input) {
|
|
|
4249
4328
|
throw new Error(`\u300C${name}\u300D\u662F\u811A\u672C\u5305\u6216\u8F6F\u4EF6\u81EA\u5E26\u7684\u6280\u80FD\uFF0C\u6362\u4E00\u4E2A\u540D\u5B57`);
|
|
4250
4329
|
const folder = join(deps.dir, name);
|
|
4251
4330
|
const file = join(folder, "SKILL.md");
|
|
4252
|
-
const existing = await
|
|
4331
|
+
const existing = await readFile2(file, "utf8").catch(() => void 0);
|
|
4253
4332
|
if (existing !== void 0 && replace !== true)
|
|
4254
4333
|
throw new Error(`\u5DF2\u7ECF\u6709\u6280\u80FD\u300C${name}\u300D\uFF08${file}\uFF09\u3002\u8981\u66F4\u65B0\u5B83\u5C31\u52A0 replace=true\uFF0C\u6216\u8005\u6362\u4E00\u4E2A\u540D\u5B57`);
|
|
4255
4334
|
await mkdir(folder, { recursive: true });
|
|
@@ -4273,7 +4352,7 @@ async function removeSkill(dir, name) {
|
|
|
4273
4352
|
if (!SKILL_NAME.test(name))
|
|
4274
4353
|
return false;
|
|
4275
4354
|
const folder = join(dir, name);
|
|
4276
|
-
if (await
|
|
4355
|
+
if (await readFile2(join(folder, "SKILL.md"), "utf8").catch(() => void 0) === void 0)
|
|
4277
4356
|
return false;
|
|
4278
4357
|
await rm(folder, { recursive: true, force: true });
|
|
4279
4358
|
return true;
|
|
@@ -4319,7 +4398,7 @@ async function userSkills(dir) {
|
|
|
4319
4398
|
if (!entry.isDirectory())
|
|
4320
4399
|
continue;
|
|
4321
4400
|
const path = join(dir, entry.name, "SKILL.md");
|
|
4322
|
-
const text = await
|
|
4401
|
+
const text = await readFile2(path, "utf8").catch(() => void 0);
|
|
4323
4402
|
const match = text === void 0 ? null : /^\uFEFF?---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/.exec(text);
|
|
4324
4403
|
if (match === null)
|
|
4325
4404
|
continue;
|
|
@@ -4355,7 +4434,7 @@ async function userSkills(dir) {
|
|
|
4355
4434
|
}
|
|
4356
4435
|
|
|
4357
4436
|
// packages/gateway/lib/skill-scope.js
|
|
4358
|
-
import { readFile as
|
|
4437
|
+
import { readFile as readFile3 } from "node:fs/promises";
|
|
4359
4438
|
import { join as join2 } from "node:path";
|
|
4360
4439
|
var PROVIDER = "adg";
|
|
4361
4440
|
var RANK = 250;
|
|
@@ -4409,8 +4488,8 @@ var SkillScope = class {
|
|
|
4409
4488
|
* What else a script in a focus stands for: its pack's id (the pack's skill
|
|
4410
4489
|
* names that), and the games it plays, whose skills it sees too.
|
|
4411
4490
|
*/
|
|
4412
|
-
resolveScripts(
|
|
4413
|
-
this.#relations =
|
|
4491
|
+
resolveScripts(resolve4) {
|
|
4492
|
+
this.#relations = resolve4;
|
|
4414
4493
|
this.#invalidate();
|
|
4415
4494
|
}
|
|
4416
4495
|
/**
|
|
@@ -4481,7 +4560,7 @@ var SkillScope = class {
|
|
|
4481
4560
|
if (this.#file === void 0)
|
|
4482
4561
|
return;
|
|
4483
4562
|
try {
|
|
4484
|
-
const value = JSON.parse(await
|
|
4563
|
+
const value = JSON.parse(await readFile3(this.#file, "utf8"));
|
|
4485
4564
|
for (const [id, focus] of Object.entries(value.sessions ?? {})) {
|
|
4486
4565
|
this.#focus.set(id, { scripts: strings(focus.scripts), games: strings(focus.games) });
|
|
4487
4566
|
}
|
|
@@ -4601,7 +4680,7 @@ function skillFocusTool(scope) {
|
|
|
4601
4680
|
}
|
|
4602
4681
|
|
|
4603
4682
|
// packages/gateway/lib/persona.js
|
|
4604
|
-
import { mkdir as mkdir2, readFile as
|
|
4683
|
+
import { mkdir as mkdir2, readFile as readFile4, rename, writeFile as writeFile2 } from "node:fs/promises";
|
|
4605
4684
|
import { join as join3 } from "node:path";
|
|
4606
4685
|
var DEFAULT_PERSONA = { persona: { style: "default" }, agents: {} };
|
|
4607
4686
|
var IDENTITY_PROMPT = [
|
|
@@ -4661,7 +4740,7 @@ var PersonaStore = class {
|
|
|
4661
4740
|
}
|
|
4662
4741
|
async load() {
|
|
4663
4742
|
try {
|
|
4664
|
-
this.#current = parseFile(JSON.parse(await
|
|
4743
|
+
this.#current = parseFile(JSON.parse(await readFile4(this.#file, "utf8"))) ?? DEFAULT_PERSONA;
|
|
4665
4744
|
} catch {
|
|
4666
4745
|
}
|
|
4667
4746
|
}
|
|
@@ -4820,7 +4899,7 @@ import { readFileSync as readFileSync2 } from "node:fs";
|
|
|
4820
4899
|
import { mkdir as mkdir3, rename as rename2, writeFile as writeFile3 } from "node:fs/promises";
|
|
4821
4900
|
import { join as join4 } from "node:path";
|
|
4822
4901
|
var COMPACTION_FILE = "compaction.json";
|
|
4823
|
-
var DEFAULT_COMPACTION = { auto: true, threshold: DEFAULT_COMPACTION_THRESHOLD, lowContext: false, archiveDays: null };
|
|
4902
|
+
var DEFAULT_COMPACTION = { auto: true, threshold: DEFAULT_COMPACTION_THRESHOLD, lowContext: false, archiveDays: null, ptcSubagents: true };
|
|
4824
4903
|
var CompactionStore = class {
|
|
4825
4904
|
#file;
|
|
4826
4905
|
/** As read at start: what dsh runs with. */
|
|
@@ -4835,12 +4914,12 @@ var CompactionStore = class {
|
|
|
4835
4914
|
return { settings: this.#current, applied: { ...this.applied, lowContext: this.#current.lowContext, archiveDays: this.#current.archiveDays } };
|
|
4836
4915
|
}
|
|
4837
4916
|
async set(settings) {
|
|
4838
|
-
const
|
|
4917
|
+
const clean4 = CompactionSettings.parse(settings);
|
|
4839
4918
|
await mkdir3(join4(this.#file, ".."), { recursive: true });
|
|
4840
|
-
await writeFile3(`${this.#file}.tmp`, `${JSON.stringify(
|
|
4919
|
+
await writeFile3(`${this.#file}.tmp`, `${JSON.stringify(clean4, null, 2)}
|
|
4841
4920
|
`);
|
|
4842
4921
|
await rename2(`${this.#file}.tmp`, this.#file);
|
|
4843
|
-
this.#current =
|
|
4922
|
+
this.#current = clean4;
|
|
4844
4923
|
return this.state();
|
|
4845
4924
|
}
|
|
4846
4925
|
};
|
|
@@ -4855,7 +4934,7 @@ function readSettings(file) {
|
|
|
4855
4934
|
}
|
|
4856
4935
|
|
|
4857
4936
|
// packages/gateway/lib/memory.js
|
|
4858
|
-
import { appendFile, mkdir as mkdir4, readFile as
|
|
4937
|
+
import { appendFile, mkdir as mkdir4, readFile as readFile5 } from "node:fs/promises";
|
|
4859
4938
|
import { randomBytes } from "node:crypto";
|
|
4860
4939
|
import { dirname, join as join5 } from "node:path";
|
|
4861
4940
|
|
|
@@ -5104,7 +5183,7 @@ var MemoryStore = class {
|
|
|
5104
5183
|
if (this.#file === void 0)
|
|
5105
5184
|
return;
|
|
5106
5185
|
try {
|
|
5107
|
-
const saved = JSON.parse(await
|
|
5186
|
+
const saved = JSON.parse(await readFile5(this.#file, "utf8"));
|
|
5108
5187
|
const items = Array.isArray(saved.items) ? saved.items : [];
|
|
5109
5188
|
this.#items = items.flatMap((item) => {
|
|
5110
5189
|
const parsed = MemoryEntry.safeParse(item);
|
|
@@ -5180,7 +5259,7 @@ var HOW_TO_WRITE = [
|
|
|
5180
5259
|
].join("\n");
|
|
5181
5260
|
var HISTORY = [
|
|
5182
5261
|
"## \u4EE5\u524D\u7684\u5BF9\u8BDD",
|
|
5183
|
-
"\u5BF9\u8BDD\u8F83\u65E9\u7684\u90E8\u5206\u53EF\u80FD\u5DF2\u7ECF\u538B\u7F29\u6210\u4E86\u6458\u8981\uFF08\u6253\u5F00\u4E86\u4F4E\u4E0A\u4E0B\u6587\u6A21\u5F0F\u65F6\uFF0C\u53EA\u7559\u6700\u8FD1 12 \u5C0F\u65F6\u7684\u5BF9\u8BDD\uFF1B\u5F00\u4E86\u5F52\u6863\u65F6\uFF0C\u66F4\u65E9\u7684\u6458\u8981\u4E5F\u4F1A\u79FB\u51FA\u4E0A\u4E0B\u6587\uFF0C\u53EA\u7559\u4E00\u884C\u8BF4\u660E\uFF09\uFF0C\u66F4\u65E9\u7684\u5BF9\u8BDD\u4F60\u4E5F\u770B\u4E0D\u5230\u3002\u65E5\u8BB0\u662F\u4F60\u505A\u8FC7\u7684\u4E8B\u7684\u7D22\u5F15\uFF1A\u6807\u7740\u300C\u53EF\u67E5\u539F\u6587\u300D\u7684\u8BB0\u5FC6\uFF0C\u7528 history_read \u7684 memory_id \u5C31\u80FD\u8BFB\u5230\u5F53\u65F6\u7684\u5BF9\u8BDD\u3002\u6458\u8981\u548C\u8BB0\u5FC6\u4E0D\u591F\u7528\u65F6\u2014\u2014\u8981\u7528\u6237\u7684\u539F\u8BDD\u3001\u5177\u4F53\u7684\u6570\u5B57\u548C\u540D\u5B57\u3001\u5F53\u65F6\u7684\u8F93\u51FA\u2014\u2014\u7528 history_search \u6309\u5173\u952E\u8BCD\u67E5\u4EE5\u524D\u7684\u5BF9\u8BDD\u539F\u6587\u548C\u5F52\u6863\u7684\u6458\u8981\uFF0C\u518D\u7528 history_read \u6309 #\u7F16\u53F7\u8BFB\u90A3\u4E00\u6BB5\u7684\u524D\u540E\u6587\u3002\u4E0D\u8981\u51ED\u5370\u8C61\u731C\u4EE5\u524D\u8BF4\u8FC7\u4EC0\u4E48\u3002"
|
|
5262
|
+
"\u5BF9\u8BDD\u8F83\u65E9\u7684\u90E8\u5206\u53EF\u80FD\u5DF2\u7ECF\u538B\u7F29\u6210\u4E86\u6458\u8981\uFF08\u6253\u5F00\u4E86\u4F4E\u4E0A\u4E0B\u6587\u6A21\u5F0F\u65F6\uFF0C\u53EA\u7559\u6700\u8FD1 12 \u5C0F\u65F6\u7684\u5BF9\u8BDD\uFF1B\u5BF9\u8BDD\u5B89\u9759\u8D85\u8FC7 4 \u5C0F\u65F6\u540E\u518D\u6765\u65B0\u6D88\u606F\uFF0C\u4E4B\u524D\u7684\u5185\u5BB9\u4F1A\u5148\u5168\u90E8\u538B\u6210\u6458\u8981\uFF0C\u4F60\u4ECE\u6458\u8981\u5F00\u59CB\uFF1B\u5F00\u4E86\u5F52\u6863\u65F6\uFF0C\u66F4\u65E9\u7684\u6458\u8981\u4E5F\u4F1A\u79FB\u51FA\u4E0A\u4E0B\u6587\uFF0C\u53EA\u7559\u4E00\u884C\u8BF4\u660E\uFF09\uFF0C\u66F4\u65E9\u7684\u5BF9\u8BDD\u4F60\u4E5F\u770B\u4E0D\u5230\u3002\u65E5\u8BB0\u662F\u4F60\u505A\u8FC7\u7684\u4E8B\u7684\u7D22\u5F15\uFF1A\u6807\u7740\u300C\u53EF\u67E5\u539F\u6587\u300D\u7684\u8BB0\u5FC6\uFF0C\u7528 history_read \u7684 memory_id \u5C31\u80FD\u8BFB\u5230\u5F53\u65F6\u7684\u5BF9\u8BDD\u3002\u6458\u8981\u548C\u8BB0\u5FC6\u4E0D\u591F\u7528\u65F6\u2014\u2014\u8981\u7528\u6237\u7684\u539F\u8BDD\u3001\u5177\u4F53\u7684\u6570\u5B57\u548C\u540D\u5B57\u3001\u5F53\u65F6\u7684\u8F93\u51FA\u2014\u2014\u7528 history_search \u6309\u5173\u952E\u8BCD\u67E5\u4EE5\u524D\u7684\u5BF9\u8BDD\u539F\u6587\u548C\u5F52\u6863\u7684\u6458\u8981\uFF0C\u518D\u7528 history_read \u6309 #\u7F16\u53F7\u8BFB\u90A3\u4E00\u6BB5\u7684\u524D\u540E\u6587\u3002\u4E0D\u8981\u51ED\u5370\u8C61\u731C\u4EE5\u524D\u8BF4\u8FC7\u4EC0\u4E48\u3002"
|
|
5184
5263
|
].join("\n");
|
|
5185
5264
|
var MEMORY_HEADING = "# \u957F\u671F\u8BB0\u5FC6";
|
|
5186
5265
|
function memoryTail(lead) {
|
|
@@ -5354,13 +5433,13 @@ function shownLines(section) {
|
|
|
5354
5433
|
return lines;
|
|
5355
5434
|
}
|
|
5356
5435
|
function memorySectionIn(prompt, lead) {
|
|
5357
|
-
const
|
|
5436
|
+
const open2 = `${MEMORY_HEADING}
|
|
5358
5437
|
|
|
5359
5438
|
`;
|
|
5360
5439
|
const inside = prompt.indexOf(`
|
|
5361
5440
|
|
|
5362
|
-
${
|
|
5363
|
-
const start = prompt.startsWith(
|
|
5441
|
+
${open2}`);
|
|
5442
|
+
const start = prompt.startsWith(open2) ? 0 : inside < 0 ? -1 : inside + 2;
|
|
5364
5443
|
if (start < 0)
|
|
5365
5444
|
return void 0;
|
|
5366
5445
|
const tail = memoryTail(lead);
|
|
@@ -5644,7 +5723,7 @@ function keptFrom(session, nodes) {
|
|
|
5644
5723
|
}
|
|
5645
5724
|
|
|
5646
5725
|
// packages/gateway/lib/memory-auto.js
|
|
5647
|
-
import { readFile as
|
|
5726
|
+
import { readFile as readFile6 } from "node:fs/promises";
|
|
5648
5727
|
|
|
5649
5728
|
// packages/gateway/lib/history.js
|
|
5650
5729
|
var HARNESS_NOTES = /* @__PURE__ */ new Set([
|
|
@@ -5667,10 +5746,10 @@ function textOf(content) {
|
|
|
5667
5746
|
return content.filter((p) => p.type === "text" && typeof p.text === "string").map((p) => p.text).join("\n").trim();
|
|
5668
5747
|
}
|
|
5669
5748
|
function unframed(text) {
|
|
5670
|
-
const
|
|
5671
|
-
const at = text.indexOf(
|
|
5749
|
+
const open2 = "<compacted-summary>";
|
|
5750
|
+
const at = text.indexOf(open2);
|
|
5672
5751
|
const end = text.lastIndexOf("</compacted-summary>");
|
|
5673
|
-
return at >= 0 && end > at ? text.slice(at +
|
|
5752
|
+
return at >= 0 && end > at ? text.slice(at + open2.length, end).trim() : text;
|
|
5674
5753
|
}
|
|
5675
5754
|
function saidIn(events) {
|
|
5676
5755
|
const out = [];
|
|
@@ -6179,7 +6258,7 @@ var AutoMemory = class {
|
|
|
6179
6258
|
if (this.#deps.file === void 0)
|
|
6180
6259
|
return;
|
|
6181
6260
|
try {
|
|
6182
|
-
const saved = JSON.parse(await
|
|
6261
|
+
const saved = JSON.parse(await readFile6(this.#deps.file, "utf8"));
|
|
6183
6262
|
const settings = external_exports.object({ auto: external_exports.boolean(), model: external_exports.object({ provider: external_exports.string(), model: external_exports.string(), reasoningEffort: external_exports.string().optional() }).nullable() }).safeParse(saved.settings);
|
|
6184
6263
|
if (settings.success)
|
|
6185
6264
|
this.#settings = settings.data;
|
|
@@ -6730,14 +6809,14 @@ var QuestionBroker = class {
|
|
|
6730
6809
|
...q.multiSelect === void 0 ? {} : { multiSelect: q.multiSelect }
|
|
6731
6810
|
}))
|
|
6732
6811
|
};
|
|
6733
|
-
return new Promise((
|
|
6812
|
+
return new Promise((resolve4, reject) => {
|
|
6734
6813
|
const onAbort = () => this.settle(questionId, "cancelled");
|
|
6735
6814
|
this.pending.set(questionId, {
|
|
6736
6815
|
request,
|
|
6737
6816
|
settle: (outcome, answer) => {
|
|
6738
6817
|
ask.signal?.removeEventListener("abort", onAbort);
|
|
6739
6818
|
if (outcome === "answered" && answer !== void 0)
|
|
6740
|
-
|
|
6819
|
+
resolve4(answer);
|
|
6741
6820
|
else
|
|
6742
6821
|
reject(new QuestionClosed(outcome === "answered" ? "unavailable" : outcome));
|
|
6743
6822
|
}
|
|
@@ -6912,10 +6991,7 @@ function builtinCapabilities(deps) {
|
|
|
6912
6991
|
const created = await sessions.create({ ...cwd === void 0 ? {} : { cwd }, ...deps.agentPreset === void 0 ? {} : { agentPreset: deps.agentPreset } });
|
|
6913
6992
|
await deps.adopt?.(created.sessionId);
|
|
6914
6993
|
if (params.role !== void 0) {
|
|
6915
|
-
|
|
6916
|
-
if (model !== void 0)
|
|
6917
|
-
await sessions.selectModel({ sessionId: created.sessionId, provider: model.provider, model: model.model, ...model.reasoningEffort === void 0 ? {} : { reasoningEffort: model.reasoningEffort } }).catch(() => {
|
|
6918
|
-
});
|
|
6994
|
+
await deps.tagRole?.(created.sessionId, params.role);
|
|
6919
6995
|
}
|
|
6920
6996
|
if (params.focus !== void 0)
|
|
6921
6997
|
await deps.focus?.(created.sessionId, params.focus);
|
|
@@ -7081,18 +7157,15 @@ function builtinCapabilities(deps) {
|
|
|
7081
7157
|
failures: catalog.failures.map((f) => ({ id: f.id, name: f.name, message: f.message }))
|
|
7082
7158
|
};
|
|
7083
7159
|
},
|
|
7160
|
+
// The model picker beside the input: this conversation's model, not the default (that is set in 设置 → 模型).
|
|
7084
7161
|
"session/selectModel": async (params) => {
|
|
7085
|
-
const
|
|
7086
|
-
|
|
7087
|
-
provider: params.provider,
|
|
7088
|
-
model: params.model,
|
|
7089
|
-
...params.reasoningEffort === void 0 ? {} : { reasoningEffort: params.reasoningEffort }
|
|
7090
|
-
});
|
|
7162
|
+
const wanted = { provider: params.provider, model: params.model, ...params.reasoningEffort === void 0 ? {} : { reasoningEffort: params.reasoningEffort } };
|
|
7163
|
+
const selected = deps.selectModel !== void 0 ? await deps.selectModel(params.sessionId, wanted) : (await sessions.selectModel({ sessionId: sid(params.sessionId), ...wanted })).selected;
|
|
7091
7164
|
return {
|
|
7092
7165
|
selected: {
|
|
7093
|
-
provider:
|
|
7094
|
-
model:
|
|
7095
|
-
...
|
|
7166
|
+
provider: selected.provider,
|
|
7167
|
+
model: selected.model,
|
|
7168
|
+
...selected.reasoningEffort === void 0 ? {} : { reasoningEffort: selected.reasoningEffort }
|
|
7096
7169
|
}
|
|
7097
7170
|
};
|
|
7098
7171
|
},
|
|
@@ -7120,7 +7193,7 @@ function builtinCapabilities(deps) {
|
|
|
7120
7193
|
}
|
|
7121
7194
|
|
|
7122
7195
|
// packages/gateway/lib/homes.js
|
|
7123
|
-
import { readFile as
|
|
7196
|
+
import { readFile as readFile7 } from "node:fs/promises";
|
|
7124
7197
|
import { mkdirSync } from "node:fs";
|
|
7125
7198
|
import { dirname as dirname2 } from "node:path";
|
|
7126
7199
|
var AgentHomes = class {
|
|
@@ -7162,7 +7235,7 @@ var AgentHomes = class {
|
|
|
7162
7235
|
if (this.#file === void 0)
|
|
7163
7236
|
return;
|
|
7164
7237
|
try {
|
|
7165
|
-
const saved = JSON.parse(await
|
|
7238
|
+
const saved = JSON.parse(await readFile7(this.#file, "utf8"));
|
|
7166
7239
|
if (saved === null || typeof saved !== "object")
|
|
7167
7240
|
return;
|
|
7168
7241
|
for (const [agent, session] of Object.entries(saved))
|
|
@@ -7229,7 +7302,7 @@ var HandOffs = class {
|
|
|
7229
7302
|
if (this.#file === void 0)
|
|
7230
7303
|
return;
|
|
7231
7304
|
try {
|
|
7232
|
-
const saved = JSON.parse(await
|
|
7305
|
+
const saved = JSON.parse(await readFile7(this.#file, "utf8"));
|
|
7233
7306
|
if (!Array.isArray(saved))
|
|
7234
7307
|
return;
|
|
7235
7308
|
for (const item of saved) {
|
|
@@ -7244,17 +7317,26 @@ var HandOffs = class {
|
|
|
7244
7317
|
|
|
7245
7318
|
// packages/gateway/lib/reminders.js
|
|
7246
7319
|
var WEEKDAY = ["", "\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D", "\u65E5"];
|
|
7320
|
+
var BYDAY = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
|
|
7247
7321
|
function remindersOf(entries, agentOf) {
|
|
7248
|
-
return entries.filter((e) => e.status === "active").map((e) =>
|
|
7249
|
-
|
|
7250
|
-
|
|
7251
|
-
|
|
7252
|
-
|
|
7253
|
-
|
|
7254
|
-
|
|
7255
|
-
|
|
7256
|
-
|
|
7257
|
-
|
|
7322
|
+
return entries.filter((e) => e.status === "active" && typeof e.target?.sessionId === "string").map((e) => {
|
|
7323
|
+
const sessionId = e.target.sessionId;
|
|
7324
|
+
return {
|
|
7325
|
+
id: e.id,
|
|
7326
|
+
agent: agentOf(sessionId),
|
|
7327
|
+
sessionId,
|
|
7328
|
+
title: e.title?.trim() || e.prompt.split("\n")[0].slice(0, 40),
|
|
7329
|
+
prompt: e.prompt,
|
|
7330
|
+
rule: ruleText(e),
|
|
7331
|
+
repeats: repeats(e),
|
|
7332
|
+
next: Date.parse(e.scheduledAt)
|
|
7333
|
+
};
|
|
7334
|
+
}).filter((r) => Number.isFinite(r.next)).sort((a, b) => a.next - b.next);
|
|
7335
|
+
}
|
|
7336
|
+
function repeats(entry) {
|
|
7337
|
+
if (entry.kind === "rrule")
|
|
7338
|
+
return rruleParts(entry.rrule).get("COUNT") !== "1";
|
|
7339
|
+
return entry.kind !== "at" && entry.kind !== "after";
|
|
7258
7340
|
}
|
|
7259
7341
|
function ruleText(entry) {
|
|
7260
7342
|
const time = (entry.time ?? "").slice(0, 5);
|
|
@@ -7262,15 +7344,58 @@ function ruleText(entry) {
|
|
|
7262
7344
|
case "daily":
|
|
7263
7345
|
return `\u6BCF\u5929 ${time}`;
|
|
7264
7346
|
case "weekly":
|
|
7265
|
-
return `\u6BCF\u5468${(entry.weekdays ?? [])
|
|
7347
|
+
return `\u6BCF\u5468${weekdays(entry.weekdays ?? [])} ${time}`;
|
|
7266
7348
|
case "every":
|
|
7267
7349
|
return `\u6BCF ${duration(entry.everySeconds ?? 0)}`;
|
|
7268
7350
|
case "cron":
|
|
7269
7351
|
return `cron ${entry.expression ?? ""}`.trim();
|
|
7352
|
+
case "rrule":
|
|
7353
|
+
return rruleText(entry.rrule);
|
|
7270
7354
|
default:
|
|
7271
7355
|
return "\u4E00\u6B21";
|
|
7272
7356
|
}
|
|
7273
7357
|
}
|
|
7358
|
+
function rruleParts(rrule) {
|
|
7359
|
+
const line2 = (rrule ?? "").split(/\r?\n/).find((l) => l.startsWith("RRULE:"));
|
|
7360
|
+
return new Map((line2?.slice("RRULE:".length) ?? "").split(";").filter((p) => p.includes("=")).map((p) => p.split("=", 2)));
|
|
7361
|
+
}
|
|
7362
|
+
function rruleText(rrule) {
|
|
7363
|
+
const parts = rruleParts(rrule);
|
|
7364
|
+
if (parts.get("COUNT") === "1")
|
|
7365
|
+
return "\u4E00\u6B21";
|
|
7366
|
+
const start = /^DTSTART[^:]*:\d{8}T(\d{2})(\d{2})/m.exec(rrule ?? "");
|
|
7367
|
+
const time = start === null ? "" : ` ${start[1]}:${start[2]}`;
|
|
7368
|
+
const interval = Number(parts.get("INTERVAL") ?? "1");
|
|
7369
|
+
const plain2 = [...parts.keys()].every((k) => ["FREQ", "INTERVAL", "BYDAY", "WKST"].includes(k));
|
|
7370
|
+
const every = (unit, seconds) => interval === 1 ? `\u6BCF${unit}` : `\u6BCF ${duration(interval * seconds)}`;
|
|
7371
|
+
if (plain2 && Number.isInteger(interval) && interval > 0) {
|
|
7372
|
+
switch (parts.get("FREQ")) {
|
|
7373
|
+
case "DAILY":
|
|
7374
|
+
if (!parts.has("BYDAY"))
|
|
7375
|
+
return `${interval === 1 ? "\u6BCF\u5929" : `\u6BCF ${interval} \u5929`}${time}`;
|
|
7376
|
+
break;
|
|
7377
|
+
case "WEEKLY": {
|
|
7378
|
+
const days = (parts.get("BYDAY") ?? "").split(",").filter((d) => d !== "").map((d) => BYDAY[d]);
|
|
7379
|
+
if (interval === 1 && days.length > 0 && days.every((d) => d !== void 0))
|
|
7380
|
+
return `\u6BCF\u5468${weekdays(days)}${time}`;
|
|
7381
|
+
break;
|
|
7382
|
+
}
|
|
7383
|
+
case "HOURLY":
|
|
7384
|
+
if (!parts.has("BYDAY"))
|
|
7385
|
+
return every("\u5C0F\u65F6", 3600);
|
|
7386
|
+
break;
|
|
7387
|
+
case "MINUTELY":
|
|
7388
|
+
if (!parts.has("BYDAY"))
|
|
7389
|
+
return every("\u5206\u949F", 60);
|
|
7390
|
+
break;
|
|
7391
|
+
}
|
|
7392
|
+
}
|
|
7393
|
+
const line2 = (rrule ?? "").split(/\r?\n/).find((l) => l.startsWith("RRULE:"));
|
|
7394
|
+
return line2 === void 0 ? "\u91CD\u590D" : line2.slice("RRULE:".length);
|
|
7395
|
+
}
|
|
7396
|
+
function weekdays(days) {
|
|
7397
|
+
return days.map((d) => WEEKDAY[d] ?? String(d)).join("\u3001");
|
|
7398
|
+
}
|
|
7274
7399
|
function duration(seconds) {
|
|
7275
7400
|
if (seconds % 86400 === 0)
|
|
7276
7401
|
return `${seconds / 86400} \u5929`;
|
|
@@ -7345,7 +7470,7 @@ function plain(markdown) {
|
|
|
7345
7470
|
}
|
|
7346
7471
|
|
|
7347
7472
|
// packages/gateway/lib/roles.js
|
|
7348
|
-
import { readFile as
|
|
7473
|
+
import { readFile as readFile8 } from "node:fs/promises";
|
|
7349
7474
|
import { mkdirSync as mkdirSync2 } from "node:fs";
|
|
7350
7475
|
import { dirname as dirname3 } from "node:path";
|
|
7351
7476
|
function keeps(tools, name) {
|
|
@@ -7358,11 +7483,13 @@ var NOBODY = ["subagent_fork"];
|
|
|
7358
7483
|
var TOGETHER = ["agent_delegate", "agent_message", "agent_threads"];
|
|
7359
7484
|
var MEMORY_TOOLS = ["memory_save", "memory_forget", "memory_search", "history_search", "history_read"];
|
|
7360
7485
|
var ALWAYS = [...TOGETHER, ...MEMORY_TOOLS];
|
|
7361
|
-
var COORDINATION = ["agent_delegate", "agent_message", "agent_threads", "notice_act", "ask_user_question", "exit_plan_mode", "subagent", "list_agents", "interrupt_agent", "schedule_create", "
|
|
7486
|
+
var COORDINATION = ["agent_delegate", "agent_message", "agent_threads", "notice_act", "ask_user_question", "exit_plan_mode", "subagent", "list_agents", "interrupt_agent", "schedule_create", "schedule_list", "schedule_view", "schedule_edit", "schedule_task_*", "create_goal", "update_goal", "get_goal", "intervention_done", "memory_save", "memory_forget"];
|
|
7362
7487
|
var HANDS_ON = [
|
|
7363
7488
|
...AGENT_AREAS.filter((area) => ["run", "scripts-config", "scripts-install", "screen", "games", "shell"].includes(area.id)).flatMap((area) => area.tools).filter((tool) => tool !== "pipeline_run"),
|
|
7364
7489
|
// Screenshots are not in an area (they change nothing), and they weigh the most.
|
|
7365
7490
|
"screen_*",
|
|
7491
|
+
// The built-in browser: every step answers with the whole page.
|
|
7492
|
+
"browser_*",
|
|
7366
7493
|
// Runs a program that calls the tools: the same work, by another door.
|
|
7367
7494
|
"workflow"
|
|
7368
7495
|
];
|
|
@@ -7390,11 +7517,13 @@ function subAgentSpec(parent) {
|
|
|
7390
7517
|
`\u4F60\u7684\u56DE\u590D\u53EA\u6709\u300C${name}\u300D\u8BFB\uFF0C\u7528\u6237\u770B\u4E0D\u5230\uFF1A\u7528\u5DE5\u5177\u628A\u4E8B\u505A\u5B8C\uFF0C\u6700\u540E\u4E00\u6BB5\u56DE\u590D\u5199\u7ED3\u679C\uFF0C\u5199\u5B83\u8981\u7684\u4E1C\u897F\uFF0C\u4E0D\u5BD2\u6684\u3002`,
|
|
7391
7518
|
`\u4F60\u95EE\u4E0D\u4E86\u7528\u6237\uFF0C\u4E5F\u4E0D\u80FD\u4EA4\u7ED9\u522B\u7684 agent\uFF1A\u7F3A\u4EC0\u4E48\u5C31\u5199\u8FDB\u56DE\u590D\uFF0C\u7531\u300C${name}\u300D\u53BB\u95EE\u3002\u9700\u8981\u7528\u6237\u6279\u51C6\u7684\u64CD\u4F5C\u4F1A\u8BF7\u7528\u6237\u6279\u51C6\uFF0C\u7B49\u7ED3\u679C\u5C31\u662F\uFF1B\u88AB\u62D2\u7EDD\u4E86\u4E0D\u8981\u6362\u4E2A\u529E\u6CD5\u7ED5\u8FC7\u53BB\uFF0C\u628A\u6CA1\u505A\u6210\u7684\u548C\u539F\u56E0\u5199\u8FDB\u56DE\u590D\u3002`,
|
|
7392
7519
|
"\u80FD\u7528\u5DE5\u5177\u3001\u547D\u4EE4\u884C\u3001\u8BFB\u6587\u4EF6\uFF08\u914D\u7F6E\u3001\u65E5\u5FD7\u3001\u7248\u672C\u53F7\uFF09\u6216\u811A\u672C\u81EA\u5DF1\u7684\u547D\u4EE4\u548C\u8BBE\u7F6E\u505A\u5230\u3001\u786E\u8BA4\u5230\u7684\uFF0C\u5C31\u8FD9\u6837\u505A\uFF1B\u622A\u56FE\u3001\u770B\u753B\u9762\u3001\u70B9\u5C4F\u5E55\u662F\u6700\u540E\u7684\u529E\u6CD5\u3002",
|
|
7520
|
+
// Only where the parent's tools take the browser in (and it may be missing: dsh's own app has none).
|
|
7521
|
+
...keeps(parent.tools, "browser_navigate") ? ["\u4F60\u6709\u5185\u7F6E\u6D4F\u89C8\u5668\uFF08browser_* \u5DE5\u5177\uFF09\uFF1A\u8981\u8BFB\u7684\u7F51\u9875\u7528 web_fetch \u53EA\u62FF\u5230\u6807\u9898\u6216\u7A7A\u58F3\uFF08\u524D\u7AEF\u6E32\u67D3\u7684\u5B98\u7F51\u3001\u516C\u544A\u9875\u5E38\u8FD9\u6837\uFF09\uFF0C\u6216\u8005\u8981\u70B9\u5F00\u3001\u7FFB\u9875\u3001\u5C55\u5F00\u624D\u770B\u5F97\u5230\u65F6\uFF0C\u5C31\u7528\u5B83\u2014\u2014browser_navigate \u6253\u5F00\uFF0Cbrowser_text \u8BFB\u6E32\u67D3\u540E\u7684\u5168\u90E8\u6587\u5B57\uFF0Cbrowser_click / browser_scroll \u7FFB\u627E\u3002\u8BFB\u5230\u8981\u7684\u5C31\u505C\uFF0C\u56DE\u590D\u91CC\u53EA\u5199\u8981\u7684\u5185\u5BB9\u548C\u51FA\u5904\uFF0C\u4E0D\u590D\u8FF0\u6574\u9875\u3002\u4E0D\u767B\u5F55\u3001\u4E0D\u586B\u4E2A\u4EBA\u4FE1\u606F\u3001\u4E0D\u4ED8\u6B3E\uFF1B\u9047\u5230\u767B\u5F55\u6216\u9A8C\u8BC1\u7801\u5C31\u505C\u4E0B\u5199\u8FDB\u56DE\u590D\u3002"] : [],
|
|
7393
7522
|
...parent.duty === void 0 ? [] : [`\u4E0B\u9762\u662F\u300C${name}\u300D\u7684\u804C\u8D23\uFF0C\u4F60\u5728\u8FD9\u4E2A\u8303\u56F4\u91CC\u505A\u4E8B\uFF1B\u6536\u5C3E\u548C\u5BF9\u5916\u8BF4\u660E\u7531\u5B83\u6765\u505A\uFF1A`, parent.duty.replace(/^# .*\n/, "")]
|
|
7394
7523
|
].join("\n")
|
|
7395
7524
|
};
|
|
7396
7525
|
}
|
|
7397
|
-
function teamPrompt(self, main, leads) {
|
|
7526
|
+
function teamPrompt(self, main, leads, options = {}) {
|
|
7398
7527
|
const who = (m) => `\u300C${m.name}\u300D\uFF08${m.id}${m.alias === void 0 ? "" : `\uFF0C\u7528\u6237\u4E5F\u53EB\u5B83\u300C${m.alias}\u300D`}\uFF09`;
|
|
7399
7528
|
const line2 = (m) => `- ${who(m)}${m.description === "" ? "" : `\uFF1A${m.description}`}`;
|
|
7400
7529
|
const colleagues = leads.filter((m) => m.id !== self.id);
|
|
@@ -7404,7 +7533,8 @@ function teamPrompt(self, main, leads) {
|
|
|
7404
7533
|
isMain ? `\u4F60\u662F\u300C${self.name}\u300D\uFF08${self.id}\uFF09\uFF0C\u662F\u6700\u4E0A\u7EA7\u7684 agent\uFF1A\u548C\u7528\u6237\u5BF9\u8BDD\uFF0C\u628A\u4E8B\u5206\u7ED9\u4E0B\u9762\u7684\u4E3B agent\uFF0C\u6C47\u603B\u7ED3\u679C\u5E76\u505A\u51B3\u5B9A\u3002` : `\u4F60\u662F\u300C${self.name}\u300D\uFF08${self.id}\uFF09\uFF0C\u662F\u4E00\u4E2A\u4E3B agent\uFF1A\u8D1F\u8D23\u81EA\u5DF1\u8FD9\u5757\u4E8B\uFF0C\u505A\u51B3\u5B9A\u3001\u6C47\u603B\u7ED3\u679C\u3002\u4E0A\u7EA7\u662F${who(main)}\uFF1A\u5B83\u548C\u7528\u6237\u5BF9\u8BDD\u3001\u5206\u53D1\u4EFB\u52A1\u3001\u505A\u51B3\u5B9A\u3002`,
|
|
7405
7534
|
colleagues.length === 0 ? isMain ? "\u73B0\u5728\u6CA1\u6709\u5176\u4ED6\u4E3B agent\u3002" : "\u73B0\u5728\u6CA1\u6709\u5176\u4ED6\u540C\u4E8B\u3002" : `${isMain ? "\u4E0B\u9762\u7684\u4E3B agent" : "\u540C\u4E8B"}\uFF1A
|
|
7406
7535
|
${colleagues.map(line2).join("\n")}`,
|
|
7407
|
-
"\u5177\u4F53\u7684\u6D3B\u90FD\u7531\u5B50 agent \u505A\uFF08subagent\uFF09\uFF1A\u8FD0\u884C\u547D\u4EE4\u3001\u6539\u6587\u4EF6\u3001\u622A\u56FE\u70B9\u51FB\u3001\u8FD0\u884C\u548C\u5B89\u88C5\u811A\u672C\u3001\u542F\u52A8\u6E38\u620F\uFF0C\u8FD9\u4E9B\u5DE5\u5177\u4E0D\u5728\u4F60\u7684\u5BF9\u8BDD\u91CC\uFF0C\u53EA\u6709\u5B50 agent \u6709\uFF1B\u522B\u5904\u63D0\u5230\u8FD9\u4E9B\u5DE5\u5177\uFF0C\u4E5F\u662F\u8BA9\u5B50 agent \u53BB\u7528\u3002\u4F60\u7684\u5BF9\u8BDD\u7559\u7ED9\u5224\u65AD\u548C\u6C47\u603B\uFF1A\u8981\u505A\u4EC0\u4E48\u5C31\u5F00\u4E00\u4E2A\u5B50 agent\uFF0C\u628A\u4EFB\u52A1\u5199\u5B8C\u6574\uFF08\u5B83\u770B\u4E0D\u5230\u4F60\u7684\u5BF9\u8BDD\uFF09\uFF0C\u7ED3\u679C\u4EA4\u56DE\u540E\u7531\u4F60\u5224\u65AD\u3001\u6C47\u603B\u3002\u67E5\u72B6\u6001\u3001\u8BFB\u4E00\u4E0B\u6587\u4EF6\u8FD9\u79CD\u770B\u4E00\u773C\u7684\u4E8B\u53EF\u4EE5\u81EA\u5DF1\u6765\u3002\u51E0\u4EF6\u4E92\u4E0D\u76F8\u5173\u7684\u4E8B\u53EF\u4EE5\u540C\u65F6\u5F00\u3002\u5B50 agent \u53EA\u5BF9\u4F60\u8D1F\u8D23\uFF0C\u53EA\u628A\u7ED3\u679C\u4EA4\u56DE\u7ED9\u4F60\uFF1B\u5B83\u8981\u7528\u6237\u6279\u51C6\u7684\u64CD\u4F5C\uFF0C\u4F1A\u5728\u4F60\u7684\u5BF9\u8BDD\u91CC\u8BF7\u7528\u6237\u6279\u51C6\u3002",
|
|
7536
|
+
"\u5177\u4F53\u7684\u6D3B\u90FD\u7531\u5B50 agent \u505A\uFF08subagent\uFF09\uFF1A\u8FD0\u884C\u547D\u4EE4\u3001\u6539\u6587\u4EF6\u3001\u622A\u56FE\u70B9\u51FB\u3001\u8FD0\u884C\u548C\u5B89\u88C5\u811A\u672C\u3001\u542F\u52A8\u6E38\u620F\uFF0C\u8FD9\u4E9B\u5DE5\u5177\u4E0D\u5728\u4F60\u7684\u5BF9\u8BDD\u91CC\uFF0C\u53EA\u6709\u5B50 agent \u6709\uFF1B\u522B\u5904\u63D0\u5230\u8FD9\u4E9B\u5DE5\u5177\uFF0C\u4E5F\u662F\u8BA9\u5B50 agent \u53BB\u7528\u3002\u4F60\u7684\u5BF9\u8BDD\u7559\u7ED9\u5224\u65AD\u548C\u6C47\u603B\uFF1A\u8981\u505A\u4EC0\u4E48\u5C31\u5F00\u4E00\u4E2A\u5B50 agent\uFF0C\u628A\u4EFB\u52A1\u5199\u5B8C\u6574\uFF08\u5B83\u770B\u4E0D\u5230\u4F60\u7684\u5BF9\u8BDD\uFF09\uFF0C\u7ED3\u679C\u4EA4\u56DE\u540E\u7531\u4F60\u5224\u65AD\u3001\u6C47\u603B\u3002\u67E5\u72B6\u6001\u3001\u8BFB\u4E00\u4E0B\u6587\u4EF6\u8FD9\u79CD\u770B\u4E00\u773C\u7684\u4E8B\u53EF\u4EE5\u81EA\u5DF1\u6765\u3002\u51E0\u4EF6\u4E92\u4E0D\u76F8\u5173\u7684\u4E8B\u53EF\u4EE5\u540C\u65F6\u5F00\u3002\u5F00\u4E86\u4EE5\u540E\u53EA\u5269\u7B49\u7ED3\u679C\u65F6\uFF0C\u7528 wait_agent \u7B49\uFF08timeout_ms \u6309\u5B83\u5927\u6982\u8981\u591A\u4E45\u586B\uFF09\uFF0C\u6216\u8005\u7ED3\u675F\u8FD9\u4E00\u8F6E\uFF0C\u7ED3\u679C\u4F1A\u4F5C\u4E3A\u65B0\u6D88\u606F\u53D1\u6765\uFF1B\u8981\u7B49\u4E00\u6B21\u811A\u672C\u8FD0\u884C\u7ED3\u675F\uFF0C\u7528 script_runs \u5E26\u4E0A run_id \u548C wait_seconds\uFF0C\u5B83\u7B49\u5230\u7ED3\u675F\uFF08\u91CD\u65B0\u8FD0\u884C\u7684\u8BDD\u8DDF\u5230\u6700\u540E\u90A3\u6B21\uFF09\u624D\u8FD4\u56DE\u3002\u4E0D\u8981\u7528 glob\u3001list_agents\u3001script_runs\u3001window_list \u4E00\u904D\u904D\u67E5\u505A\u5230\u54EA\u4E86\uFF1A\u4F60\u5BF9\u8BDD\u91CC\u7684\u6BCF\u4E00\u6B65\u90FD\u8981\u628A\u6574\u4E2A\u5BF9\u8BDD\u91CD\u65B0\u53D1\u7ED9\u6A21\u578B\u4E00\u6B21\uFF0C\u8FD9\u6837\u7B49\u6700\u8D39\u3002\u5B50 agent \u53EA\u5BF9\u4F60\u8D1F\u8D23\uFF0C\u53EA\u628A\u7ED3\u679C\u4EA4\u56DE\u7ED9\u4F60\uFF1B\u5B83\u8981\u7528\u6237\u6279\u51C6\u7684\u64CD\u4F5C\uFF0C\u4F1A\u5728\u4F60\u7684\u5BF9\u8BDD\u91CC\u8BF7\u7528\u6237\u6279\u51C6\u3002",
|
|
7537
|
+
options.browser === true && keeps(self.tools, "browser_navigate") ? "\u7F51\u9875\u4E5F\u4E00\u6837\uFF1Aweb_fetch \u53EA\u62FF\u5230\u7A7A\u58F3\uFF08\u524D\u7AEF\u6E32\u67D3\u7684\u5B98\u7F51\u3001\u516C\u544A\u9875\u5E38\u8FD9\u6837\uFF09\u6216\u8981\u70B9\u5F00\u3001\u7FFB\u9875\u624D\u770B\u5F97\u5230\u65F6\uFF0C\u5F00\u5B50 agent \u7528\u5185\u7F6E\u6D4F\u89C8\u5668\u53BB\u8BFB\uFF0C\u4EFB\u52A1\u91CC\u5199\u660E\u300C\u7528\u5185\u7F6E\u6D4F\u89C8\u5668\uFF08browser_navigate \u6253\u5F00\uFF0Cbrowser_text \u8BFB\u6E32\u67D3\u540E\u7684\u6587\u5B57\uFF09\u300D\u3002\u5B83\u6253\u5F00\u7684\u9875\u9762\u7528\u6237\u5728\u6D4F\u89C8\u5668\u9762\u677F\u91CC\u770B\u5F97\u5230\u3002" : "",
|
|
7408
7538
|
isMain ? "" : `\u9700\u8981\u540C\u4E8B\u7684\u90A3\u90E8\u5206\uFF0C\u7528 agent_delegate \u76F4\u63A5\u4EA4\u7ED9\u5B83\uFF0C\u4E0D\u7528\u7ED5\u8FC7\u300C${main.name}\u300D\u3002\u4EA4\u7ED9\u4F60\u7684\u4E8B\u6CA1\u8BF4\u6E05\u695A\u65F6\uFF0C\u7528 agent_message \u95EE\u4EA4\u7ED9\u4F60\u7684\u4E00\u65B9\uFF0C\u4E0D\u8981\u81EA\u5DF1\u53BB\u95EE\u7528\u6237\uFF08\u8981\u4E0D\u8981\u95EE\u7528\u6237\u7531\u5BF9\u65B9\u51B3\u5B9A\uFF09\uFF0C\u95EE\u6E05\u695A\u518D\u505A\uFF1B\u505A\u5B8C\u7528 agent_message \u7684 done \u4EA4\u56DE\u7ED3\u8BBA\uFF0C\u6216\u8005\u628A\u7ED3\u8BBA\u5199\u5728\u8FD9\u4E00\u8F6E\u6700\u540E\u4E00\u6BB5\u56DE\u590D\u91CC\u3002`,
|
|
7409
7539
|
"\u548C\u5176\u4ED6 agent \u8BF4\u8BDD\u4E0D\u662F\u4E00\u95EE\u4E00\u7B54\uFF1A\u505A\u7684\u8FC7\u7A0B\u4E2D\u8981\u8BA9\u5BF9\u65B9\u77E5\u9053\u7684\uFF0C\u7528 agent_message \u7684 update\uFF0C\u9A6C\u4E0A\u9001\u5230\u5B83\u7684\u5BF9\u8BDD\u91CC\uFF0C\u8BF4\u51E0\u6B21\u90FD\u884C\uFF1B\u4E00\u4EF6\u4E8B\u4EA4\u56DE\u7ED3\u8BBA\u4EE5\u540E\u8FD8\u6709\u8BDD\uFF08\u6BD4\u5982\u5B9A\u65F6\u63D0\u9192\u5230\u4E86\uFF09\uFF0C\u540C\u6837\u7528 agent_message \u53D1\u5230\u90A3\u6761\u7EBF\u7D22\uFF0C\u4F60\u7684\u666E\u901A\u56DE\u590D\u5BF9\u65B9\u770B\u4E0D\u5230\u3002",
|
|
7410
7540
|
"\u548C\u5176\u4ED6 agent \u4EE5\u524D\u8BF4\u8FC7\u7684\u4E8B\u4E0D\u53EA\u5728\u8FD9\u4E2A\u5BF9\u8BDD\u91CC\uFF1A\u5BF9\u8BDD\u88AB\u538B\u7F29\u6216\u6362\u8FC7\uFF0Cagent_threads\uFF08with \u586B\u5BF9\u65B9\uFF09\u4E5F\u80FD\u770B\u5230\u4F60\u4EEC\u4EE5\u524D\u7684\u6765\u5F80\uFF0C\u522B\u7684 agent \u4EA4\u7ED9\u4F60\u4E8B\u65F6\u4E5F\u4F1A\u9644\u4E0A\u6700\u8FD1\u51E0\u6761\u3002\u63A5\u7740\u4EE5\u524D\u7684\u4E8B\u627E\u5B83\u4E4B\u524D\u5148\u770B\u4E00\u773C\uFF0C\u4E0D\u8981\u8BA9\u5B83\u4ECE\u5934\u6765\u3002",
|
|
@@ -7500,7 +7630,7 @@ var SessionRoles = class {
|
|
|
7500
7630
|
if (this.#file === void 0)
|
|
7501
7631
|
return;
|
|
7502
7632
|
try {
|
|
7503
|
-
const saved = JSON.parse(await
|
|
7633
|
+
const saved = JSON.parse(await readFile8(this.#file, "utf8"));
|
|
7504
7634
|
if (saved !== null && typeof saved === "object" && !Array.isArray(saved)) {
|
|
7505
7635
|
for (const [id, tag] of Object.entries(saved)) {
|
|
7506
7636
|
if (typeof tag === "string")
|
|
@@ -7515,38 +7645,87 @@ var SessionRoles = class {
|
|
|
7515
7645
|
}
|
|
7516
7646
|
}
|
|
7517
7647
|
};
|
|
7518
|
-
|
|
7648
|
+
|
|
7649
|
+
// packages/gateway/lib/agent-models.js
|
|
7650
|
+
import { readFile as readFile9 } from "node:fs/promises";
|
|
7651
|
+
import { mkdirSync as mkdirSync3 } from "node:fs";
|
|
7652
|
+
import { dirname as dirname4 } from "node:path";
|
|
7653
|
+
var LEGACY_ROLES = ["intervene", "games", "scripts", "pipelines"];
|
|
7654
|
+
var EMPTY = { agents: {}, subAgents: null, subAgentsOf: {} };
|
|
7655
|
+
var AgentModels = class {
|
|
7519
7656
|
#file;
|
|
7520
|
-
#
|
|
7657
|
+
#legacyFile;
|
|
7658
|
+
#state = EMPTY;
|
|
7521
7659
|
loaded;
|
|
7522
|
-
|
|
7660
|
+
/** @param legacyFile - `role-model.json`, read when `file` was never written. */
|
|
7661
|
+
constructor(file, legacyFile) {
|
|
7523
7662
|
this.#file = file;
|
|
7663
|
+
this.#legacyFile = legacyFile;
|
|
7524
7664
|
this.loaded = this.#load();
|
|
7525
7665
|
}
|
|
7526
|
-
|
|
7527
|
-
return this.#
|
|
7666
|
+
state() {
|
|
7667
|
+
return this.#state;
|
|
7668
|
+
}
|
|
7669
|
+
/** The model set for an agent's own conversations; undefined: the default model. */
|
|
7670
|
+
of(agentId) {
|
|
7671
|
+
return this.#state.agents[agentId];
|
|
7528
7672
|
}
|
|
7529
|
-
|
|
7673
|
+
/** The model set for an agent's sub-agents (theirs, else every sub-agent's); undefined: the same as the agent. */
|
|
7674
|
+
subOf(agentId) {
|
|
7675
|
+
return this.#state.subAgentsOf[agentId] ?? this.#state.subAgents ?? void 0;
|
|
7676
|
+
}
|
|
7677
|
+
/** @param selection - null: follow the layer above again. */
|
|
7678
|
+
async set(target, selection) {
|
|
7530
7679
|
await this.loaded;
|
|
7531
|
-
|
|
7680
|
+
if (target.agentId === void 0 && target.sub !== true)
|
|
7681
|
+
throw new Error("\u8981\u8BF4\u660E\u662F\u54EA\u4E2A agent \u7684\u6A21\u578B");
|
|
7682
|
+
const value = selection === null ? void 0 : clean3(selection);
|
|
7683
|
+
const without = (record, key) => Object.fromEntries(Object.entries(record).filter(([k]) => k !== key));
|
|
7684
|
+
const put = (record, key) => value === void 0 ? without(record, key) : { ...record, [key]: value };
|
|
7685
|
+
const state = this.#state;
|
|
7686
|
+
this.#state = target.sub !== true ? { ...state, agents: put(state.agents, target.agentId) } : target.agentId === void 0 ? { ...state, subAgents: value ?? null } : { ...state, subAgentsOf: put(state.subAgentsOf, target.agentId) };
|
|
7532
7687
|
if (this.#file === void 0)
|
|
7533
7688
|
return;
|
|
7534
|
-
|
|
7535
|
-
await writeFileAtomic(this.#file, `${JSON.stringify(this.#
|
|
7689
|
+
mkdirSync3(dirname4(this.#file), { recursive: true });
|
|
7690
|
+
await writeFileAtomic(this.#file, `${JSON.stringify(this.#state)}
|
|
7536
7691
|
`);
|
|
7537
7692
|
}
|
|
7538
7693
|
async #load() {
|
|
7539
7694
|
if (this.#file === void 0)
|
|
7540
7695
|
return;
|
|
7541
|
-
|
|
7542
|
-
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
7546
|
-
|
|
7696
|
+
const saved = await readJson(this.#file);
|
|
7697
|
+
if (saved !== void 0) {
|
|
7698
|
+
const record = (value) => Object.fromEntries(Object.entries(isObject(value) ? value : {}).flatMap(([id, s]) => {
|
|
7699
|
+
const selection = selectionOf(s);
|
|
7700
|
+
return selection === void 0 ? [] : [[id, selection]];
|
|
7701
|
+
}));
|
|
7702
|
+
const state = isObject(saved) ? saved : {};
|
|
7703
|
+
this.#state = { agents: record(state["agents"]), subAgents: selectionOf(state["subAgents"]) ?? null, subAgentsOf: record(state["subAgentsOf"]) };
|
|
7704
|
+
return;
|
|
7547
7705
|
}
|
|
7706
|
+
const legacy = this.#legacyFile === void 0 ? void 0 : selectionOf(await readJson(this.#legacyFile));
|
|
7707
|
+
if (legacy !== void 0)
|
|
7708
|
+
this.#state = { ...EMPTY, agents: Object.fromEntries(LEGACY_ROLES.map((id) => [id, legacy])) };
|
|
7548
7709
|
}
|
|
7549
7710
|
};
|
|
7711
|
+
async function readJson(file) {
|
|
7712
|
+
try {
|
|
7713
|
+
return JSON.parse(await readFile9(file, "utf8"));
|
|
7714
|
+
} catch {
|
|
7715
|
+
return void 0;
|
|
7716
|
+
}
|
|
7717
|
+
}
|
|
7718
|
+
function isObject(value) {
|
|
7719
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
7720
|
+
}
|
|
7721
|
+
function selectionOf(value) {
|
|
7722
|
+
if (!isObject(value) || typeof value["provider"] !== "string" || typeof value["model"] !== "string")
|
|
7723
|
+
return void 0;
|
|
7724
|
+
return clean3(value);
|
|
7725
|
+
}
|
|
7726
|
+
function clean3(selection) {
|
|
7727
|
+
return { provider: selection.provider, model: selection.model, ...typeof selection.reasoningEffort === "string" ? { reasoningEffort: selection.reasoningEffort } : {} };
|
|
7728
|
+
}
|
|
7550
7729
|
|
|
7551
7730
|
// packages/gateway/lib/peer.js
|
|
7552
7731
|
var CANCEL_REQUEST = "$/cancelRequest";
|
|
@@ -7701,10 +7880,106 @@ function toRpcError(error) {
|
|
|
7701
7880
|
return new RpcError(ErrorCode.InternalError, String(error));
|
|
7702
7881
|
}
|
|
7703
7882
|
|
|
7883
|
+
// packages/gateway/lib/pick.js
|
|
7884
|
+
import { execFile } from "node:child_process";
|
|
7885
|
+
import { isAbsolute as isAbsolute2, normalize } from "node:path";
|
|
7886
|
+
var SCRIPT = String.raw`
|
|
7887
|
+
$ErrorActionPreference = 'Stop'
|
|
7888
|
+
$ProgressPreference = 'SilentlyContinue'
|
|
7889
|
+
Add-Type -AssemblyName System.Windows.Forms, System.Drawing
|
|
7890
|
+
# Started hidden (so no console flashes up), Windows keeps the dialog hidden too: show it once it is there.
|
|
7891
|
+
Add-Type -Namespace Adg -Name Win -MemberDefinition @'
|
|
7892
|
+
[DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
|
|
7893
|
+
[DllImport("user32.dll")] public static extern IntPtr GetWindow(IntPtr hWnd, uint cmd);
|
|
7894
|
+
[DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr hWnd);
|
|
7895
|
+
[DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hWnd);
|
|
7896
|
+
'@
|
|
7897
|
+
[System.Windows.Forms.Application]::EnableVisualStyles()
|
|
7898
|
+
$folder = $env:ADG_PICK_KIND -eq 'folder'
|
|
7899
|
+
$start = $env:ADG_PICK_PATH
|
|
7900
|
+
$area = [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea
|
|
7901
|
+
$owner = New-Object System.Windows.Forms.Form -Property @{ TopMost = $true; ShowInTaskbar = $false; FormBorderStyle = 'None'; StartPosition = 'Manual'; Width = 1; Height = 1; Opacity = 0 }
|
|
7902
|
+
$owner.Location = New-Object System.Drawing.Point ([Math]::Max($area.X, $area.X + ($area.Width - 960) / 2)), ([Math]::Max($area.Y, $area.Y + ($area.Height - 560) / 2))
|
|
7903
|
+
$owner.Show()
|
|
7904
|
+
$owner.Activate()
|
|
7905
|
+
$reveal = New-Object System.Windows.Forms.Timer -Property @{ Interval = 100 }
|
|
7906
|
+
$reveal.add_Tick({
|
|
7907
|
+
$popup = [Adg.Win]::GetWindow($owner.Handle, 6)
|
|
7908
|
+
if ($popup -ne [IntPtr]::Zero -and $popup -ne $owner.Handle) {
|
|
7909
|
+
if (-not [Adg.Win]::IsWindowVisible($popup)) { [void][Adg.Win]::ShowWindow($popup, 5) }
|
|
7910
|
+
[void][Adg.Win]::SetForegroundWindow($popup)
|
|
7911
|
+
$reveal.Stop()
|
|
7912
|
+
}
|
|
7913
|
+
})
|
|
7914
|
+
$reveal.Start()
|
|
7915
|
+
$dialog = New-Object System.Windows.Forms.OpenFileDialog
|
|
7916
|
+
$dialog.Title = $env:ADG_PICK_TITLE
|
|
7917
|
+
if ($folder) {
|
|
7918
|
+
$placeholder = '选择此文件夹'
|
|
7919
|
+
$dialog.ValidateNames = $false
|
|
7920
|
+
$dialog.CheckFileExists = $false
|
|
7921
|
+
$dialog.CheckPathExists = $true
|
|
7922
|
+
$dialog.FileName = $placeholder
|
|
7923
|
+
$dialog.Filter = '文件夹|*.adg-folder-only'
|
|
7924
|
+
if ($start -and [IO.Directory]::Exists($start)) { $dialog.InitialDirectory = $start }
|
|
7925
|
+
} else {
|
|
7926
|
+
$dialog.CheckFileExists = $true
|
|
7927
|
+
if ($env:ADG_PICK_FILTER) { $dialog.Filter = $env:ADG_PICK_FILTER }
|
|
7928
|
+
if ($start) {
|
|
7929
|
+
if ([IO.Directory]::Exists($start)) { $dialog.InitialDirectory = $start }
|
|
7930
|
+
elseif ([IO.File]::Exists($start)) { $dialog.InitialDirectory = [IO.Path]::GetDirectoryName($start); $dialog.FileName = [IO.Path]::GetFileName($start) }
|
|
7931
|
+
}
|
|
7932
|
+
}
|
|
7933
|
+
$path = $null
|
|
7934
|
+
if ($dialog.ShowDialog($owner) -eq 'OK') {
|
|
7935
|
+
$path = $dialog.FileName
|
|
7936
|
+
if ($folder) { $path = if ([IO.Directory]::Exists($path)) { $path } else { [IO.Path]::GetDirectoryName($path) } }
|
|
7937
|
+
}
|
|
7938
|
+
$owner.Close()
|
|
7939
|
+
if ($path) { [Console]::Out.Write([Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($path))) }
|
|
7940
|
+
`;
|
|
7941
|
+
var open;
|
|
7942
|
+
function pickPath(options, signal) {
|
|
7943
|
+
if (process.platform !== "win32")
|
|
7944
|
+
return Promise.reject(new Error("\u53EA\u6709 Windows \u4E0A\u80FD\u6253\u5F00\u9009\u62E9\u7A97\u53E3\uFF0C\u8BF7\u76F4\u63A5\u586B\u5199\u8DEF\u5F84"));
|
|
7945
|
+
if (open !== void 0)
|
|
7946
|
+
return Promise.reject(new Error("\u5DF2\u7ECF\u6253\u5F00\u4E86\u4E00\u4E2A\u9009\u62E9\u7A97\u53E3\uFF0C\u5148\u628A\u5B83\u5173\u6389"));
|
|
7947
|
+
const extensions = (options.extensions ?? []).filter((e) => /^\w+$/.test(e));
|
|
7948
|
+
const filter = extensions.length === 0 ? "" : `${(options.filterName ?? "\u6587\u4EF6").replace(/\|/g, "")}|${extensions.map((e) => `*.${e}`).join(";")}|\u6240\u6709\u6587\u4EF6|*.*`;
|
|
7949
|
+
const pending = new Promise((resolve4, reject) => {
|
|
7950
|
+
execFile("powershell.exe", ["-NoProfile", "-NonInteractive", "-STA", "-ExecutionPolicy", "Bypass", "-EncodedCommand", Buffer.from(SCRIPT, "utf16le").toString("base64")], {
|
|
7951
|
+
windowsHide: true,
|
|
7952
|
+
signal,
|
|
7953
|
+
maxBuffer: 1 << 20,
|
|
7954
|
+
env: {
|
|
7955
|
+
...process.env,
|
|
7956
|
+
ADG_PICK_KIND: options.kind,
|
|
7957
|
+
ADG_PICK_TITLE: options.title ?? (options.kind === "folder" ? "\u9009\u62E9\u6587\u4EF6\u5939" : "\u9009\u62E9\u6587\u4EF6"),
|
|
7958
|
+
ADG_PICK_PATH: options.defaultPath !== void 0 && isAbsolute2(options.defaultPath) ? normalize(options.defaultPath) : "",
|
|
7959
|
+
ADG_PICK_FILTER: filter
|
|
7960
|
+
}
|
|
7961
|
+
}, (error, stdout, stderr) => {
|
|
7962
|
+
if (error !== null) {
|
|
7963
|
+
reject(new Error(`\u6253\u4E0D\u5F00\u9009\u62E9\u7A97\u53E3\uFF1A${(String(stderr) || error.message).trim().split("\n")[0]}`));
|
|
7964
|
+
return;
|
|
7965
|
+
}
|
|
7966
|
+
const out = String(stdout).trim();
|
|
7967
|
+
resolve4(out === "" ? void 0 : Buffer.from(out, "base64").toString("utf8"));
|
|
7968
|
+
});
|
|
7969
|
+
});
|
|
7970
|
+
open = pending;
|
|
7971
|
+
const done = () => {
|
|
7972
|
+
if (open === pending)
|
|
7973
|
+
open = void 0;
|
|
7974
|
+
};
|
|
7975
|
+
pending.then(done, done);
|
|
7976
|
+
return pending;
|
|
7977
|
+
}
|
|
7978
|
+
|
|
7704
7979
|
// packages/gateway/lib/permissions.js
|
|
7705
|
-
import { readFile as
|
|
7706
|
-
import { mkdirSync as
|
|
7707
|
-
import { dirname as
|
|
7980
|
+
import { readFile as readFile10 } from "node:fs/promises";
|
|
7981
|
+
import { mkdirSync as mkdirSync4 } from "node:fs";
|
|
7982
|
+
import { dirname as dirname5 } from "node:path";
|
|
7708
7983
|
var PRESET = { ask: "workspace-write", full: "full-access" };
|
|
7709
7984
|
var KEEP_RECENT = 50;
|
|
7710
7985
|
var Permissions = class {
|
|
@@ -7723,7 +7998,7 @@ var Permissions = class {
|
|
|
7723
7998
|
if (this.#file === void 0)
|
|
7724
7999
|
return;
|
|
7725
8000
|
try {
|
|
7726
|
-
const saved = JSON.parse(await
|
|
8001
|
+
const saved = JSON.parse(await readFile10(this.#file, "utf8"));
|
|
7727
8002
|
if (saved.mode === "full")
|
|
7728
8003
|
this.#mode = "full";
|
|
7729
8004
|
if (typeof saved.since === "number")
|
|
@@ -7760,7 +8035,7 @@ var Permissions = class {
|
|
|
7760
8035
|
async #save() {
|
|
7761
8036
|
if (this.#file === void 0)
|
|
7762
8037
|
return;
|
|
7763
|
-
|
|
8038
|
+
mkdirSync4(dirname5(this.#file), { recursive: true });
|
|
7764
8039
|
await writeFileAtomic(this.#file, `${JSON.stringify({ mode: this.#mode, since: this.#since, areas: this.#areas }, null, 2)}
|
|
7765
8040
|
`);
|
|
7766
8041
|
}
|
|
@@ -7814,7 +8089,7 @@ var CapabilityRegistry = class {
|
|
|
7814
8089
|
// packages/gateway/lib/server.js
|
|
7815
8090
|
import { createReadStream, statSync } from "node:fs";
|
|
7816
8091
|
import { createServer } from "node:http";
|
|
7817
|
-
import { extname, join as join6, normalize, resolve, sep } from "node:path";
|
|
8092
|
+
import { extname, join as join6, normalize as normalize2, resolve as resolve2, sep } from "node:path";
|
|
7818
8093
|
import { timingSafeEqual } from "node:crypto";
|
|
7819
8094
|
|
|
7820
8095
|
// node_modules/.pnpm/ws@8.21.3/node_modules/ws/wrapper.mjs
|
|
@@ -7891,11 +8166,11 @@ function serveMounted(root, req, res) {
|
|
|
7891
8166
|
res.writeHead(404, { "content-type": "text/plain; charset=utf-8" }).end("\u8FD9\u4E2A\u5B89\u88C5\u6CA1\u6709\u5E26\u754C\u9762");
|
|
7892
8167
|
return;
|
|
7893
8168
|
}
|
|
7894
|
-
serveStatic(
|
|
8169
|
+
serveStatic(resolve2(root), req, res, pathname.slice(MOUNT.length));
|
|
7895
8170
|
}
|
|
7896
8171
|
function serveStatic(root, req, res, path) {
|
|
7897
8172
|
const pathname = decodeURIComponent(path ?? new URL(req.url ?? "/", "http://local").pathname);
|
|
7898
|
-
const target =
|
|
8173
|
+
const target = normalize2(join6(root, pathname));
|
|
7899
8174
|
const inside = target === root || target.startsWith(root.endsWith(sep) ? root : root + sep);
|
|
7900
8175
|
let file = inside ? target : join6(root, "index.html");
|
|
7901
8176
|
try {
|
|
@@ -7919,7 +8194,7 @@ function serveStatic(root, req, res, path) {
|
|
|
7919
8194
|
}
|
|
7920
8195
|
}
|
|
7921
8196
|
async function startServer(options) {
|
|
7922
|
-
const staticRoot = options.staticDir === void 0 ? void 0 :
|
|
8197
|
+
const staticRoot = options.staticDir === void 0 ? void 0 : resolve2(options.staticDir);
|
|
7923
8198
|
const server = createServer((req, res) => {
|
|
7924
8199
|
if (!authorityAllowed(req.headers.host, options.trustedHosts)) {
|
|
7925
8200
|
res.writeHead(403).end("forbidden host");
|
|
@@ -7988,9 +8263,9 @@ Content-Length: 0\r
|
|
|
7988
8263
|
}
|
|
7989
8264
|
|
|
7990
8265
|
// packages/gateway/lib/instances.js
|
|
7991
|
-
import { mkdir as mkdir5, readdir, readFile as
|
|
8266
|
+
import { mkdir as mkdir5, readdir, readFile as readFile11, rm as rm2 } from "node:fs/promises";
|
|
7992
8267
|
import { tmpdir } from "node:os";
|
|
7993
|
-
import { join as join7, resolve as
|
|
8268
|
+
import { join as join7, resolve as resolve3 } from "node:path";
|
|
7994
8269
|
var INSTANCES_DIR = join7(tmpdir(), "MultiGameAssistant", "instances");
|
|
7995
8270
|
var STALE_MS = 3 * 6e4;
|
|
7996
8271
|
var FORGET_MS = 24 * 60 * 6e4;
|
|
@@ -8004,7 +8279,7 @@ function copyLabel(shared, env = process.env) {
|
|
|
8004
8279
|
function sameDir(a, b) {
|
|
8005
8280
|
if (a === void 0 || b === void 0)
|
|
8006
8281
|
return false;
|
|
8007
|
-
const norm2 = (dir) => process.platform === "win32" ?
|
|
8282
|
+
const norm2 = (dir) => process.platform === "win32" ? resolve3(dir).toLowerCase() : resolve3(dir);
|
|
8008
8283
|
return norm2(a) === norm2(b);
|
|
8009
8284
|
}
|
|
8010
8285
|
function clashes(self, other) {
|
|
@@ -8110,7 +8385,7 @@ var Instances = class {
|
|
|
8110
8385
|
continue;
|
|
8111
8386
|
let other;
|
|
8112
8387
|
try {
|
|
8113
|
-
other = JSON.parse(await
|
|
8388
|
+
other = JSON.parse(await readFile11(join7(this.#dir, name), "utf8"));
|
|
8114
8389
|
} catch {
|
|
8115
8390
|
continue;
|
|
8116
8391
|
}
|
|
@@ -8142,9 +8417,9 @@ var Instances = class {
|
|
|
8142
8417
|
};
|
|
8143
8418
|
|
|
8144
8419
|
// packages/gateway/lib/shared.js
|
|
8145
|
-
import { readFile as
|
|
8146
|
-
import { mkdirSync as
|
|
8147
|
-
import { dirname as
|
|
8420
|
+
import { readFile as readFile12 } from "node:fs/promises";
|
|
8421
|
+
import { mkdirSync as mkdirSync5 } from "node:fs";
|
|
8422
|
+
import { dirname as dirname6 } from "node:path";
|
|
8148
8423
|
var AGENT_PRESET = "mga";
|
|
8149
8424
|
var MAX_KEPT3 = 5e3;
|
|
8150
8425
|
var OwnSessions = class {
|
|
@@ -8167,7 +8442,7 @@ var OwnSessions = class {
|
|
|
8167
8442
|
this.#ids.delete(this.#ids.values().next().value);
|
|
8168
8443
|
if (this.#file === void 0)
|
|
8169
8444
|
return;
|
|
8170
|
-
|
|
8445
|
+
mkdirSync5(dirname6(this.#file), { recursive: true });
|
|
8171
8446
|
await writeFileAtomic(this.#file, `${JSON.stringify([...this.#ids])}
|
|
8172
8447
|
`);
|
|
8173
8448
|
}
|
|
@@ -8175,7 +8450,7 @@ var OwnSessions = class {
|
|
|
8175
8450
|
if (this.#file === void 0)
|
|
8176
8451
|
return;
|
|
8177
8452
|
try {
|
|
8178
|
-
const saved = JSON.parse(await
|
|
8453
|
+
const saved = JSON.parse(await readFile12(this.#file, "utf8"));
|
|
8179
8454
|
if (Array.isArray(saved)) {
|
|
8180
8455
|
for (const id of saved)
|
|
8181
8456
|
if (typeof id === "string")
|
|
@@ -8247,11 +8522,60 @@ function toolNames(scope) {
|
|
|
8247
8522
|
return names;
|
|
8248
8523
|
}
|
|
8249
8524
|
|
|
8525
|
+
// packages/gateway/lib/new-input.js
|
|
8526
|
+
var NEW_INPUT = "new-input";
|
|
8527
|
+
var NewInput = class {
|
|
8528
|
+
#watchers = /* @__PURE__ */ new Map();
|
|
8529
|
+
/**
|
|
8530
|
+
* Input already reported to one model call. Inside a run_code program the
|
|
8531
|
+
* input reaches the model only after the program ends, so a later wait of
|
|
8532
|
+
* the same program must not end on it again (it would only spin).
|
|
8533
|
+
*/
|
|
8534
|
+
#reported = /* @__PURE__ */ new WeakMap();
|
|
8535
|
+
constructor(ctx) {
|
|
8536
|
+
ctx.on("agent/inbox/inserted", (({ agent }) => {
|
|
8537
|
+
for (const check of this.#watchers.get(agent) ?? [])
|
|
8538
|
+
check();
|
|
8539
|
+
}));
|
|
8540
|
+
}
|
|
8541
|
+
watch(call) {
|
|
8542
|
+
const controller = new AbortController();
|
|
8543
|
+
const agent = call.agent;
|
|
8544
|
+
if (agent === void 0 || agent === null)
|
|
8545
|
+
return { signal: controller.signal, dispose: () => {
|
|
8546
|
+
} };
|
|
8547
|
+
const previous = this.#reported.get(agent);
|
|
8548
|
+
const seen = previous?.rootCallId === call.rootCallId ? previous.ids : void 0;
|
|
8549
|
+
const check = () => {
|
|
8550
|
+
if (controller.signal.aborted)
|
|
8551
|
+
return;
|
|
8552
|
+
const pending = agent.inbox?.nextStep ?? [];
|
|
8553
|
+
if (!pending.some((message) => seen?.has(message.id) !== true))
|
|
8554
|
+
return;
|
|
8555
|
+
this.#reported.set(agent, { rootCallId: call.rootCallId, ids: new Set(pending.map((message) => message.id)) });
|
|
8556
|
+
dispose();
|
|
8557
|
+
controller.abort(NEW_INPUT);
|
|
8558
|
+
};
|
|
8559
|
+
const dispose = () => {
|
|
8560
|
+
const set2 = this.#watchers.get(agent);
|
|
8561
|
+
set2?.delete(check);
|
|
8562
|
+
if (set2?.size === 0)
|
|
8563
|
+
this.#watchers.delete(agent);
|
|
8564
|
+
};
|
|
8565
|
+
let set = this.#watchers.get(agent);
|
|
8566
|
+
if (set === void 0)
|
|
8567
|
+
this.#watchers.set(agent, set = /* @__PURE__ */ new Set());
|
|
8568
|
+
set.add(check);
|
|
8569
|
+
check();
|
|
8570
|
+
return { signal: controller.signal, dispose };
|
|
8571
|
+
}
|
|
8572
|
+
};
|
|
8573
|
+
|
|
8250
8574
|
// packages/gateway/lib/index.js
|
|
8251
|
-
var BUNDLED_UI =
|
|
8575
|
+
var BUNDLED_UI = fileURLToPath2(new URL("../web/", import.meta.url));
|
|
8252
8576
|
function openInBrowser(url, log) {
|
|
8253
8577
|
const [command, args] = process.platform === "win32" ? ["rundll32", ["url.dll,FileProtocolHandler", url]] : process.platform === "darwin" ? ["open", [url]] : ["xdg-open", [url]];
|
|
8254
|
-
|
|
8578
|
+
execFile2(command, args, { windowsHide: true }, (error) => {
|
|
8255
8579
|
if (error !== null)
|
|
8256
8580
|
log.warn(`could not open the browser: ${error.message}`);
|
|
8257
8581
|
});
|
|
@@ -8269,7 +8593,7 @@ function keptToken(dataDir, log) {
|
|
|
8269
8593
|
}
|
|
8270
8594
|
const token = fresh();
|
|
8271
8595
|
try {
|
|
8272
|
-
|
|
8596
|
+
mkdirSync6(dataDir, { recursive: true });
|
|
8273
8597
|
writeFileSync(file, `${token}
|
|
8274
8598
|
`);
|
|
8275
8599
|
} catch (error) {
|
|
@@ -8313,7 +8637,9 @@ var MAIN_AGENT = {
|
|
|
8313
8637
|
"monitor_incidents",
|
|
8314
8638
|
"monitor_stall_check",
|
|
8315
8639
|
"emulator_status",
|
|
8316
|
-
"window_list"
|
|
8640
|
+
"window_list",
|
|
8641
|
+
// The built-in browser, for its sub-agents (its own conversation hands it out: roles.ts HANDS_ON).
|
|
8642
|
+
"browser_*"
|
|
8317
8643
|
],
|
|
8318
8644
|
// Saving a pipeline outright is 编排's: 助手 drafts one for the user, or hands the change to 编排.
|
|
8319
8645
|
hide: ["pipeline_save"]
|
|
@@ -8321,6 +8647,9 @@ var MAIN_AGENT = {
|
|
|
8321
8647
|
function memoryOwnerOf(spec) {
|
|
8322
8648
|
return spec.subAgentOf === void 0 ? spec.id : spec.id.replace(/:sub$/, "");
|
|
8323
8649
|
}
|
|
8650
|
+
function sameRoute(a, b) {
|
|
8651
|
+
return a.provider === b.provider && a.model === b.model && (a.reasoningEffort ?? void 0) === (b.reasoningEffort ?? void 0);
|
|
8652
|
+
}
|
|
8324
8653
|
var MAIN_AGENT_MEMBER = { id: MAIN_AGENT.id, name: MAIN_AGENT.name, description: "\u548C\u7528\u6237\u5BF9\u8BDD\uFF0C\u5206\u53D1\u4EFB\u52A1\uFF0C\u505A\u51B3\u5B9A" };
|
|
8325
8654
|
function mainDuty(roles) {
|
|
8326
8655
|
return [
|
|
@@ -8341,7 +8670,7 @@ var AdgGateway = class extends Service {
|
|
|
8341
8670
|
registry = new CapabilityRegistry();
|
|
8342
8671
|
workspace;
|
|
8343
8672
|
archived = /* @__PURE__ */ new Set();
|
|
8344
|
-
/** The latest context projections per session (control
|
|
8673
|
+
/** The latest context projections per session (a control frame carries only the keys its event changed). */
|
|
8345
8674
|
contexts = /* @__PURE__ */ new Map();
|
|
8346
8675
|
peers = /* @__PURE__ */ new Set();
|
|
8347
8676
|
approvals;
|
|
@@ -8367,8 +8696,10 @@ var AdgGateway = class extends Service {
|
|
|
8367
8696
|
own;
|
|
8368
8697
|
/** The role agents and which sessions are theirs (roles.ts). */
|
|
8369
8698
|
roles;
|
|
8370
|
-
/**
|
|
8371
|
-
|
|
8699
|
+
/** Which model each agent and its sub-agents use (agent-models.ts). */
|
|
8700
|
+
agentModels;
|
|
8701
|
+
/** Choosing a session's model runs one at a time: each puts the default back as it found it (selectSessionModel). */
|
|
8702
|
+
modelChoices = Promise.resolve();
|
|
8372
8703
|
/** Each agent's one conversation, and the work they hand each other (homes.ts). */
|
|
8373
8704
|
homes;
|
|
8374
8705
|
handOffs;
|
|
@@ -8376,6 +8707,7 @@ var AdgGateway = class extends Service {
|
|
|
8376
8707
|
handOffDesk;
|
|
8377
8708
|
homeMaking = /* @__PURE__ */ new Map();
|
|
8378
8709
|
parts;
|
|
8710
|
+
newInput;
|
|
8379
8711
|
sockets;
|
|
8380
8712
|
/** Bring one session's permission preset in line with the mode. */
|
|
8381
8713
|
presetOf = () => {
|
|
@@ -8402,7 +8734,8 @@ var AdgGateway = class extends Service {
|
|
|
8402
8734
|
this.shared = config.shared === true;
|
|
8403
8735
|
this.own = new OwnSessions(this.shared && config.dataDir !== void 0 ? join8(config.dataDir, "own-sessions.json") : void 0);
|
|
8404
8736
|
this.parts = new AgentParts(log);
|
|
8405
|
-
this.
|
|
8737
|
+
this.newInput = new NewInput(ctx);
|
|
8738
|
+
this.agentModels = new AgentModels(config.dataDir === void 0 ? void 0 : join8(config.dataDir, "agent-models.json"), config.dataDir === void 0 ? void 0 : join8(config.dataDir, "role-model.json"));
|
|
8406
8739
|
this.roles = new SessionRoles(config.dataDir === void 0 ? void 0 : join8(config.dataDir, "session-roles.json"), () => this.broadcast("roles/changed", { items: this.roles.list() }));
|
|
8407
8740
|
this.homes = new AgentHomes(config.dataDir === void 0 ? void 0 : join8(config.dataDir, "agent-homes.json"));
|
|
8408
8741
|
this.handOffs = new HandOffs(config.dataDir === void 0 ? void 0 : join8(config.dataDir, "handoffs.json"), (item) => this.broadcast("handoffs/changed", { item }));
|
|
@@ -8444,7 +8777,7 @@ var AdgGateway = class extends Service {
|
|
|
8444
8777
|
});
|
|
8445
8778
|
if (config.workspaceDir !== void 0) {
|
|
8446
8779
|
try {
|
|
8447
|
-
|
|
8780
|
+
mkdirSync6(config.workspaceDir, { recursive: true });
|
|
8448
8781
|
} catch (error) {
|
|
8449
8782
|
log.warn(`cannot create the workspace ${config.workspaceDir}: ${String(error)}`);
|
|
8450
8783
|
}
|
|
@@ -8462,8 +8795,9 @@ var AdgGateway = class extends Service {
|
|
|
8462
8795
|
// A task given on a role agent's page: you asked for it.
|
|
8463
8796
|
tagRole: async (sessionId, role) => {
|
|
8464
8797
|
await this.tagSession(sessionId, role, "\u4F60");
|
|
8465
|
-
|
|
8798
|
+
await this.applyAgentModel(sessionId, role);
|
|
8466
8799
|
},
|
|
8800
|
+
selectModel: (sessionId, selection) => this.selectSessionModel(sessionId, selection),
|
|
8467
8801
|
lastReplies: new LastReplies(ctx.sessionController),
|
|
8468
8802
|
approvals: this.approvals,
|
|
8469
8803
|
serverInfo: { name: "adg-gateway", version: "0.1.0" },
|
|
@@ -8565,9 +8899,10 @@ var AdgGateway = class extends Service {
|
|
|
8565
8899
|
ctx.on("session/created", ((session) => {
|
|
8566
8900
|
void this.permissionsReady.then(() => presetFor(session));
|
|
8567
8901
|
}));
|
|
8568
|
-
ctx.on("agent/created", ((payload) => {
|
|
8902
|
+
ctx.on("agent/created", (async (payload) => {
|
|
8569
8903
|
this.agents.set(payload.agent.session.id, payload.agent);
|
|
8570
8904
|
this.narrow(payload.agent);
|
|
8905
|
+
await this.routeSubAgent(payload.agent);
|
|
8571
8906
|
}));
|
|
8572
8907
|
ctx.on("tools/execute", ((exec, next) => {
|
|
8573
8908
|
if (exec.name === "schedule_create" && exec.agent !== void 0 && typeof exec.arguments.prompt === "string") {
|
|
@@ -8626,10 +8961,10 @@ var AdgGateway = class extends Service {
|
|
|
8626
8961
|
this.broadcast("providers/changed", {});
|
|
8627
8962
|
});
|
|
8628
8963
|
};
|
|
8629
|
-
void
|
|
8964
|
+
void addRouteDefaults(scoped.settings, config.providersNamespace ?? "llm-pi-ai").then((n) => {
|
|
8630
8965
|
if (n > 0)
|
|
8631
|
-
ctx.logger("adg-gateway").info(`
|
|
8632
|
-
}).catch((error) => ctx.logger("adg-gateway").warn(`
|
|
8966
|
+
ctx.logger("adg-gateway").info(`updated ${n} model route(s) with the retry policy or the system role`);
|
|
8967
|
+
}).catch((error) => ctx.logger("adg-gateway").warn(`updating model routes failed: ${String(error)}`));
|
|
8633
8968
|
scoped.effect(() => this.registry.register(providersCapability({
|
|
8634
8969
|
settings: scoped.settings,
|
|
8635
8970
|
llm: scoped.llm,
|
|
@@ -8656,31 +8991,50 @@ var AdgGateway = class extends Service {
|
|
|
8656
8991
|
methods: {
|
|
8657
8992
|
"models/setDefault": async (params) => {
|
|
8658
8993
|
const p = params;
|
|
8659
|
-
|
|
8994
|
+
const selection = { provider: p.provider, model: p.model, ...p.reasoningEffort === void 0 ? {} : { reasoningEffort: p.reasoningEffort } };
|
|
8995
|
+
await this.oneModelChoice(() => scoped.agentDefaultModel.saveSelection(selection));
|
|
8660
8996
|
this.broadcast("providers/changed", {});
|
|
8997
|
+
void this.refreshHomes([MAIN_AGENT.id, ...this.roles.list().map((r) => r.id).filter((id) => this.agentModels.of(id) === void 0)]);
|
|
8661
8998
|
return {};
|
|
8662
8999
|
}
|
|
8663
9000
|
}
|
|
8664
9001
|
}), "adg-gateway capability model-default");
|
|
8665
9002
|
});
|
|
8666
9003
|
ctx.effect(() => this.registry.register({
|
|
8667
|
-
id: "
|
|
9004
|
+
id: "files",
|
|
8668
9005
|
version: 1,
|
|
8669
9006
|
methods: {
|
|
8670
|
-
"
|
|
8671
|
-
await
|
|
8672
|
-
return {
|
|
8673
|
-
},
|
|
8674
|
-
"models/setRoleModel": async (params) => {
|
|
8675
|
-
const { model } = params;
|
|
8676
|
-
await this.roleModelStore.set(model ?? void 0);
|
|
8677
|
-
if (model === null)
|
|
8678
|
-
return {};
|
|
8679
|
-
const info = await ctx.get("llm")?.resolveModelInfo(model.provider, model.model, AbortSignal.timeout(1e4)).catch(() => void 0);
|
|
8680
|
-
return info !== void 0 && info.inputModalities?.includes("image") !== true ? { warning: `${model.model} \u4E0D\u80FD\u770B\u56FE\u7247\uFF1A\u5E72\u9884\u548C\u8BFB\u6E38\u620F\u8981\u770B\u622A\u56FE\uFF0C\u6362\u4E00\u4E2A\u80FD\u770B\u56FE\u7684\u6A21\u578B\u3002` } : {};
|
|
9007
|
+
"files/pick": async (params, call) => {
|
|
9008
|
+
const path = await pickPath(params, call.signal);
|
|
9009
|
+
return path === void 0 ? {} : { path };
|
|
8681
9010
|
}
|
|
8682
9011
|
}
|
|
8683
|
-
}), "adg-gateway capability
|
|
9012
|
+
}), "adg-gateway capability files");
|
|
9013
|
+
ctx.effect(() => this.registry.register({
|
|
9014
|
+
id: "agent-models",
|
|
9015
|
+
version: 1,
|
|
9016
|
+
methods: {
|
|
9017
|
+
"models/agentModels": async () => {
|
|
9018
|
+
await this.agentModels.loaded;
|
|
9019
|
+
return this.agentModels.state();
|
|
9020
|
+
},
|
|
9021
|
+
"models/setAgentModel": async (params) => {
|
|
9022
|
+
const { agentId, sub, model } = params;
|
|
9023
|
+
const target = { agentId, sub };
|
|
9024
|
+
if (agentId !== void 0 && agentId !== MAIN_AGENT.id && this.roles.spec(agentId) === void 0)
|
|
9025
|
+
throw new RpcError(ErrorCode.InvalidParams, `\u6CA1\u6709\u8FD9\u4E2A agent\uFF1A${agentId}`);
|
|
9026
|
+
if (agentId === MAIN_AGENT.id && sub !== true)
|
|
9027
|
+
throw new RpcError(ErrorCode.InvalidParams, "\u52A9\u624B\u7528\u9ED8\u8BA4\u6A21\u578B\uFF1A\u7528 models/setDefault \u8BBE\u7F6E");
|
|
9028
|
+
if (agentId === void 0 && sub !== true)
|
|
9029
|
+
throw new RpcError(ErrorCode.InvalidParams, "\u8981\u8BF4\u660E\u662F\u54EA\u4E2A agent \u7684\u6A21\u578B");
|
|
9030
|
+
await this.agentModels.set(target, model);
|
|
9031
|
+
this.broadcast("models/agentModelsChanged", this.agentModels.state());
|
|
9032
|
+
if (sub !== true && agentId !== void 0)
|
|
9033
|
+
void this.refreshHomes([agentId]);
|
|
9034
|
+
return model === null ? {} : await this.visionWarning(model, target);
|
|
9035
|
+
}
|
|
9036
|
+
}
|
|
9037
|
+
}), "adg-gateway capability agent-models");
|
|
8684
9038
|
ctx.effect(() => this.registry.register({
|
|
8685
9039
|
id: AGENTS_CAPABILITY,
|
|
8686
9040
|
version: 1,
|
|
@@ -8724,7 +9078,9 @@ var AdgGateway = class extends Service {
|
|
|
8724
9078
|
const entry = (await schedule?.catalog())?.find((e) => e.id === id);
|
|
8725
9079
|
if (schedule === void 0 || entry === void 0)
|
|
8726
9080
|
throw new RpcError(ErrorCode.InvalidParams, "\u6CA1\u6709\u8FD9\u4E2A\u63D0\u9192\uFF08\u53EF\u80FD\u5DF2\u7ECF\u5230\u70B9\u6216\u5220\u6389\u4E86\uFF09");
|
|
8727
|
-
await schedule.
|
|
9081
|
+
const result = await schedule.edit({ id, action: "delete" });
|
|
9082
|
+
if (result.deleted !== true && result.code !== "schedule_not_found")
|
|
9083
|
+
throw new RpcError(ErrorCode.InternalError, `\u6CA1\u5220\u6389\u8FD9\u4E2A\u63D0\u9192\uFF08${result.code ?? "\u539F\u56E0\u4E0D\u660E"}\uFF09\uFF0C\u518D\u8BD5\u4E00\u6B21`);
|
|
8728
9084
|
return {};
|
|
8729
9085
|
}
|
|
8730
9086
|
}
|
|
@@ -8749,7 +9105,7 @@ var AdgGateway = class extends Service {
|
|
|
8749
9105
|
}
|
|
8750
9106
|
} catch {
|
|
8751
9107
|
}
|
|
8752
|
-
await new Promise((
|
|
9108
|
+
await new Promise((resolve4) => setTimeout(resolve4, Math.min(3e4, 1e3 * 2 ** attempt)));
|
|
8753
9109
|
}
|
|
8754
9110
|
})();
|
|
8755
9111
|
return () => controller.abort();
|
|
@@ -8791,7 +9147,8 @@ var AdgGateway = class extends Service {
|
|
|
8791
9147
|
const p = params;
|
|
8792
9148
|
const stored = await scoped.attachments.readImage({ attachmentId: p.attachmentId, mediaType: p.mediaType, bytes: p.bytes, width: p.width, height: p.height });
|
|
8793
9149
|
return { mediaType: stored.ref.mediaType, data: Buffer.from(stored.data).toString("base64") };
|
|
8794
|
-
}
|
|
9150
|
+
},
|
|
9151
|
+
"attachments/file": async (params) => readImageFile(params.path, this.workspace)
|
|
8795
9152
|
}
|
|
8796
9153
|
}), "adg-gateway capability attachments");
|
|
8797
9154
|
});
|
|
@@ -9046,7 +9403,7 @@ var AdgGateway = class extends Service {
|
|
|
9046
9403
|
continue;
|
|
9047
9404
|
registered.get(skill.name)?.();
|
|
9048
9405
|
try {
|
|
9049
|
-
registered.set(skill.name, this.skillScope.register({ name: skill.name, description: skill.description, content: skill.content, source: "custom", path: skill.path, resourceBase: { kind: "directory", path:
|
|
9406
|
+
registered.set(skill.name, this.skillScope.register({ name: skill.name, description: skill.description, content: skill.content, source: "custom", path: skill.path, resourceBase: { kind: "directory", path: dirname7(skill.path) }, ...skill.owner === void 0 ? {} : { owner: skill.owner } }));
|
|
9050
9407
|
} catch (error) {
|
|
9051
9408
|
log.warn(`saved skill ${skill.name} not registered: ${error instanceof Error ? error.message : String(error)}`);
|
|
9052
9409
|
}
|
|
@@ -9282,7 +9639,7 @@ Content-Length: 0
|
|
|
9282
9639
|
if (spec.subAgentOf === void 0) {
|
|
9283
9640
|
const persona = this.persona;
|
|
9284
9641
|
const known = (member) => ({ ...member, alias: persona?.of(member.id).name });
|
|
9285
|
-
disposers.push(agent.ctx.systemPrompt.section({ name: "adg:team", order: 10096, interpolate: false, text: () => teamPrompt(spec, known(MAIN_AGENT_MEMBER), this.roles.list().map(known)) }));
|
|
9642
|
+
disposers.push(agent.ctx.systemPrompt.section({ name: "adg:team", order: 10096, interpolate: false, text: () => teamPrompt(spec, known(MAIN_AGENT_MEMBER), this.roles.list().map(known), { browser: this.parts.tools.has("browser_navigate") }) }));
|
|
9286
9643
|
if (persona !== void 0)
|
|
9287
9644
|
disposers.push(agent.ctx.systemPrompt.section({ name: "adg:persona", order: 10100, interpolate: false, text: () => personaPrompt(persona.of(spec.id)) }));
|
|
9288
9645
|
}
|
|
@@ -9406,11 +9763,11 @@ Content-Length: 0
|
|
|
9406
9763
|
*/
|
|
9407
9764
|
async settled(sessionId, signal) {
|
|
9408
9765
|
const subagents = this.ctx.get("subagents");
|
|
9409
|
-
const stopped = new Promise((
|
|
9766
|
+
const stopped = new Promise((resolve4) => {
|
|
9410
9767
|
if (signal.aborted)
|
|
9411
|
-
|
|
9768
|
+
resolve4();
|
|
9412
9769
|
else
|
|
9413
|
-
signal.addEventListener("abort", () =>
|
|
9770
|
+
signal.addEventListener("abort", () => resolve4(), { once: true });
|
|
9414
9771
|
});
|
|
9415
9772
|
for (; ; ) {
|
|
9416
9773
|
if (signal.aborted)
|
|
@@ -9422,7 +9779,7 @@ Content-Length: 0
|
|
|
9422
9779
|
if (signal.aborted)
|
|
9423
9780
|
return;
|
|
9424
9781
|
const before = agent.session.seq;
|
|
9425
|
-
const joined = await Promise.race([subagents?.
|
|
9782
|
+
const joined = await Promise.race([subagents?.waitForTreeWork(agent) ?? false, stopped.then(() => false)]);
|
|
9426
9783
|
await Promise.race([agent.whenIdle?.(), stopped]);
|
|
9427
9784
|
if (!joined && agent.session.seq === before)
|
|
9428
9785
|
return;
|
|
@@ -9433,7 +9790,7 @@ Content-Length: 0
|
|
|
9433
9790
|
const parent = this.agents.get(sessionId)?.session.header?.parentSession;
|
|
9434
9791
|
if (parent === void 0)
|
|
9435
9792
|
return;
|
|
9436
|
-
this.ctx.get("subagents")?.interrupt(sessionId, { kind: "user"
|
|
9793
|
+
this.ctx.get("subagents")?.interrupt(sessionId, { kind: "user" });
|
|
9437
9794
|
}
|
|
9438
9795
|
/** Stop the sub-agents working under this session's agent (a hand-off called off stops them with it). */
|
|
9439
9796
|
stopSubAgents(sessionId) {
|
|
@@ -9456,11 +9813,98 @@ Content-Length: 0
|
|
|
9456
9813
|
const entries = await this.schedule()?.catalog().catch(() => []) ?? [];
|
|
9457
9814
|
return remindersOf(entries, (sessionId) => this.homes.agentOf(sessionId) ?? this.roles.of(sessionId, void 0) ?? MAIN_AGENT.id);
|
|
9458
9815
|
}
|
|
9459
|
-
/** The model
|
|
9460
|
-
|
|
9461
|
-
if (
|
|
9816
|
+
/** The model set for an agent's own conversations; undefined: the default model (助手's always, and any agent not set). */
|
|
9817
|
+
agentModel(agentId) {
|
|
9818
|
+
if (agentId === MAIN_AGENT.id || this.roles.spec(agentId) === void 0)
|
|
9462
9819
|
return void 0;
|
|
9463
|
-
return this.
|
|
9820
|
+
return this.agentModels.of(agentId);
|
|
9821
|
+
}
|
|
9822
|
+
/** The model an agent's sub-agents are given: theirs, else every sub-agent's; undefined: whatever the agent is using. */
|
|
9823
|
+
subAgentModel(agentId) {
|
|
9824
|
+
return this.agentModels.subOf(agentId);
|
|
9825
|
+
}
|
|
9826
|
+
/** The model an agent's own conversations use now: its own, else the default. */
|
|
9827
|
+
effectiveModel(agentId) {
|
|
9828
|
+
return this.agentModel(agentId) ?? this.ctx.get("agentDefaultModel")?.currentSelection();
|
|
9829
|
+
}
|
|
9830
|
+
/** Give a new session of an agent's its model, when that is not the default (which it has already). */
|
|
9831
|
+
async applyAgentModel(sessionId, agentId) {
|
|
9832
|
+
const model = this.agentModel(agentId);
|
|
9833
|
+
if (model === void 0)
|
|
9834
|
+
return;
|
|
9835
|
+
await this.selectSessionModel(sessionId, model).catch((error) => this.log.warn(`giving ${sessionId} the model of ${agentId}: ${error instanceof Error ? error.message : String(error)}`));
|
|
9836
|
+
}
|
|
9837
|
+
/**
|
|
9838
|
+
* Choose a session's model for that session alone. dsh's own choice also
|
|
9839
|
+
* saves it as the default model, which would hand one agent's model (or a
|
|
9840
|
+
* pick in one conversation) to every new session: the default is put back as
|
|
9841
|
+
* it was. One choice at a time, so each finds the default as the person set it.
|
|
9842
|
+
*/
|
|
9843
|
+
selectSessionModel(sessionId, selection) {
|
|
9844
|
+
return this.oneModelChoice(async () => {
|
|
9845
|
+
const defaults = this.ctx.get("agentDefaultModel");
|
|
9846
|
+
const before = defaults?.currentSelection();
|
|
9847
|
+
const { selected } = await this.ctx.sessionController.selectModel({ sessionId, ...selection });
|
|
9848
|
+
if (defaults !== void 0 && before !== void 0 && !sameRoute(before, selected))
|
|
9849
|
+
await defaults.saveSelection(before);
|
|
9850
|
+
return { provider: selected.provider, model: selected.model, ...selected.reasoningEffort === void 0 ? {} : { reasoningEffort: String(selected.reasoningEffort) } };
|
|
9851
|
+
});
|
|
9852
|
+
}
|
|
9853
|
+
oneModelChoice(choose) {
|
|
9854
|
+
const result = this.modelChoices.then(choose);
|
|
9855
|
+
this.modelChoices = result.catch(() => {
|
|
9856
|
+
});
|
|
9857
|
+
return result;
|
|
9858
|
+
}
|
|
9859
|
+
/** After a model setting changed: these agents' one conversations switch at their next request. Never throws. */
|
|
9860
|
+
async refreshHomes(agentIds) {
|
|
9861
|
+
await this.homes.loaded.catch(() => {
|
|
9862
|
+
});
|
|
9863
|
+
for (const agentId of new Set(agentIds)) {
|
|
9864
|
+
const sessionId = this.homes.get(agentId);
|
|
9865
|
+
const model = this.effectiveModel(agentId);
|
|
9866
|
+
if (sessionId === void 0 || this.archived.has(sessionId) || model === void 0)
|
|
9867
|
+
continue;
|
|
9868
|
+
await this.selectSessionModel(sessionId, model).catch((error) => this.log.warn(`switching the model of ${agentId}'s conversation: ${error instanceof Error ? error.message : String(error)}`));
|
|
9869
|
+
}
|
|
9870
|
+
}
|
|
9871
|
+
/**
|
|
9872
|
+
* A sub-agent works with its agent's sub-agent model when one is set
|
|
9873
|
+
* (agent-models.ts); else dsh gives it its parent's. The choice is made as
|
|
9874
|
+
* the sub-agent is created (agent.model, as dsh's own model choice is), so its
|
|
9875
|
+
* steps use that model from the first and its system prompt names it. A model
|
|
9876
|
+
* that cannot be used now (its service gone) leaves it on its parent's rather
|
|
9877
|
+
* than failing the work. Never throws: a throw would fail the sub-agent.
|
|
9878
|
+
*/
|
|
9879
|
+
async routeSubAgent(agent) {
|
|
9880
|
+
if (agent.session.header?.origin !== "subagent" || !this.isOwn(agent.session.id))
|
|
9881
|
+
return;
|
|
9882
|
+
const spec = this.specOf(agent.session.id);
|
|
9883
|
+
if (spec?.subAgentOf === void 0)
|
|
9884
|
+
return;
|
|
9885
|
+
const model = this.subAgentModel(memoryOwnerOf(spec));
|
|
9886
|
+
if (model === void 0 || agent.model === void 0)
|
|
9887
|
+
return;
|
|
9888
|
+
const route = { provider: model.provider, model: model.model, ...model.reasoningEffort === void 0 ? {} : { reasoningEffort: model.reasoningEffort } };
|
|
9889
|
+
const llm = this.ctx.get("llm");
|
|
9890
|
+
if (llm === void 0)
|
|
9891
|
+
return;
|
|
9892
|
+
try {
|
|
9893
|
+
await llm.resolveCallConfig(route, AbortSignal.timeout(1e4));
|
|
9894
|
+
agent.model.select(route);
|
|
9895
|
+
} catch (error) {
|
|
9896
|
+
this.log.warn(`the sub-agent model ${model.provider}/${model.model} cannot be used now, ${agent.session.id} keeps its parent's: ${error instanceof Error ? error.message : String(error)}`);
|
|
9897
|
+
}
|
|
9898
|
+
}
|
|
9899
|
+
/** Why a model chosen for this layer will not do: it cannot see images and the work there looks at screenshots. */
|
|
9900
|
+
async visionWarning(model, target) {
|
|
9901
|
+
const handed = target.sub !== true && target.agentId !== void 0 ? this.roles.spec(target.agentId) : void 0;
|
|
9902
|
+
if (target.sub !== true && handed?.handedImages !== true)
|
|
9903
|
+
return {};
|
|
9904
|
+
const info = await this.ctx.get("llm")?.resolveModelInfo(model.provider, model.model, AbortSignal.timeout(1e4)).catch(() => void 0);
|
|
9905
|
+
if (info === void 0 || info.inputModalities === void 0 || info.inputModalities.includes("image"))
|
|
9906
|
+
return {};
|
|
9907
|
+
return { warning: target.sub === true ? `${model.model} \u4E0D\u80FD\u770B\u56FE\u7247\uFF1A\u5B50 agent \u8981\u622A\u56FE\u770B\u753B\u9762\u65F6\u7528\u4E0D\u4E86\u5B83\uFF08\u5E72\u9884\u3001\u8BFB\u6E38\u620F\u90FD\u8981\uFF09\uFF0C\u6362\u4E00\u4E2A\u80FD\u770B\u56FE\u7684\u6A21\u578B\u3002` : `${model.model} \u4E0D\u80FD\u770B\u56FE\u7247\uFF1A\u4EA4\u7ED9\u300C${handed.name}\u300D\u7684\u4E8B\u5E26\u7740\u622A\u56FE\uFF0C\u6362\u4E00\u4E2A\u80FD\u770B\u56FE\u7684\u6A21\u578B\u3002` };
|
|
9464
9908
|
}
|
|
9465
9909
|
/** Put a session the app opened under a role agent (`role`); `by`: who asked for its work (监控, 定时, 你, …). */
|
|
9466
9910
|
async tagSession(sessionId, role, by) {
|
|
@@ -9503,10 +9947,7 @@ Content-Length: 0
|
|
|
9503
9947
|
await this.homes.set(agentId, sessionId);
|
|
9504
9948
|
if (role !== void 0) {
|
|
9505
9949
|
await this.tagSession(sessionId, role.id);
|
|
9506
|
-
|
|
9507
|
-
if (model !== void 0)
|
|
9508
|
-
await sessions.selectModel({ sessionId: created.sessionId, provider: model.provider, model: model.model, ...model.reasoningEffort === void 0 ? {} : { reasoningEffort: model.reasoningEffort } }).catch(() => {
|
|
9509
|
-
});
|
|
9950
|
+
await this.applyAgentModel(sessionId, role.id);
|
|
9510
9951
|
}
|
|
9511
9952
|
await sessions.rename({ sessionId: created.sessionId, title: role?.name ?? MAIN_AGENT.name }).catch(() => {
|
|
9512
9953
|
});
|
|
@@ -9601,6 +10042,15 @@ Content-Length: 0
|
|
|
9601
10042
|
}
|
|
9602
10043
|
/** Send one notification to every initialized client. */
|
|
9603
10044
|
/** Where sessions work when they do not say (the agent's own folder, never the app's). */
|
|
10045
|
+
/**
|
|
10046
|
+
* For this app's tools that wait (new-input.ts): a signal that aborts once
|
|
10047
|
+
* the calling agent has new input at its next step — the user's message
|
|
10048
|
+
* sent into the running turn above all — so the wait gives way to it, as
|
|
10049
|
+
* dsh's wait_agent does. Dispose it when the wait is over.
|
|
10050
|
+
*/
|
|
10051
|
+
watchInput(exec) {
|
|
10052
|
+
return this.newInput.watch(exec);
|
|
10053
|
+
}
|
|
9604
10054
|
/**
|
|
9605
10055
|
* Called by this app's tools before they act (most of them never ask for
|
|
9606
10056
|
* approval on their own): an area set to 不允许 refuses, one set to 先问我
|
|
@@ -9655,19 +10105,26 @@ Content-Length: 0
|
|
|
9655
10105
|
for await (const frame of this.ctx.sessionController.control(signal)) {
|
|
9656
10106
|
if (frame.type !== "projection" || !this.isOwn(frame.sessionId))
|
|
9657
10107
|
continue;
|
|
9658
|
-
|
|
9659
|
-
|
|
10108
|
+
const changed = new Map(frame.changes.map((change) => [change.key, change.val]));
|
|
10109
|
+
if (changed.has("title")) {
|
|
10110
|
+
const value = changed.get("title");
|
|
10111
|
+
const title = typeof value === "string" ? value : null;
|
|
9660
10112
|
this.broadcast("session/title", { sessionId: frame.sessionId, title });
|
|
9661
10113
|
const role = this.roles.of(frame.sessionId, title);
|
|
9662
10114
|
const home = this.homes.agentOf(frame.sessionId);
|
|
9663
10115
|
this.broadcast("sessions/changed", { kind: "upsert", item: { id: frame.sessionId, title, ...role === void 0 ? {} : { role }, ...home === void 0 ? {} : { home } } });
|
|
9664
|
-
}
|
|
9665
|
-
|
|
9666
|
-
|
|
9667
|
-
|
|
9668
|
-
|
|
10116
|
+
}
|
|
10117
|
+
if (changed.has("modelSelection"))
|
|
10118
|
+
this.broadcast("session/model", { sessionId: frame.sessionId, ...toSessionModel(changed.get("modelSelection")) });
|
|
10119
|
+
if (changed.has("inbox"))
|
|
10120
|
+
this.broadcast("session/queue", { sessionId: frame.sessionId, items: toQueue(changed.get("inbox")) });
|
|
10121
|
+
if (changed.has("contextPressure") || changed.has("contextBreakdown")) {
|
|
9669
10122
|
const known = this.contexts.get(frame.sessionId) ?? {};
|
|
9670
|
-
const next =
|
|
10123
|
+
const next = {
|
|
10124
|
+
...known,
|
|
10125
|
+
...changed.has("contextPressure") ? { pressure: changed.get("contextPressure") } : {},
|
|
10126
|
+
...changed.has("contextBreakdown") ? { breakdown: changed.get("contextBreakdown") } : {}
|
|
10127
|
+
};
|
|
9671
10128
|
this.contexts.set(frame.sessionId, next);
|
|
9672
10129
|
this.broadcast("session/context", { sessionId: frame.sessionId, context: toContext(next.pressure, next.breakdown) ?? null });
|
|
9673
10130
|
}
|
|
@@ -9677,7 +10134,7 @@ Content-Length: 0
|
|
|
9677
10134
|
return;
|
|
9678
10135
|
log.warn(`title feed interrupted: ${error instanceof Error ? error.message : String(error)}`);
|
|
9679
10136
|
}
|
|
9680
|
-
await new Promise((
|
|
10137
|
+
await new Promise((resolve4) => setTimeout(resolve4, 1e3));
|
|
9681
10138
|
}
|
|
9682
10139
|
}
|
|
9683
10140
|
};
|
|
@@ -9691,7 +10148,7 @@ export {
|
|
|
9691
10148
|
convertRecords,
|
|
9692
10149
|
convertLiveFrame,
|
|
9693
10150
|
SessionRoles,
|
|
9694
|
-
|
|
10151
|
+
AgentModels,
|
|
9695
10152
|
PRESET,
|
|
9696
10153
|
Permissions,
|
|
9697
10154
|
require_permessage_deflate,
|
|
@@ -9707,6 +10164,7 @@ export {
|
|
|
9707
10164
|
clashes,
|
|
9708
10165
|
Instances,
|
|
9709
10166
|
AGENT_PRESET,
|
|
10167
|
+
NEW_INPUT,
|
|
9710
10168
|
AdgGateway,
|
|
9711
10169
|
lib_default
|
|
9712
10170
|
};
|