@dev-anywhere/proxy 0.3.14 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-JYPJ7PQ3.js → chunk-IFQSVDHB.js} +371 -260
- package/dist/chunk-IFQSVDHB.js.map +1 -0
- package/dist/{chunk-ENA4NCWK.js → chunk-UDLPU2NC.js} +14 -2
- package/dist/chunk-UDLPU2NC.js.map +1 -0
- package/dist/{chunk-LWTSGIOQ.js → chunk-W6275ZRJ.js} +13 -1
- package/dist/chunk-W6275ZRJ.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/serve.js +286 -25
- package/dist/serve.js.map +1 -1
- package/dist/session-worker.js +6 -4
- package/dist/session-worker.js.map +1 -1
- package/dist/{terminal-TKIXG3KL.js → terminal-HB75QUZK.js} +7 -4
- package/dist/terminal-HB75QUZK.js.map +1 -0
- package/package.json +3 -3
- package/dist/chunk-ENA4NCWK.js.map +0 -1
- package/dist/chunk-JYPJ7PQ3.js.map +0 -1
- package/dist/chunk-LWTSGIOQ.js.map +0 -1
- package/dist/terminal-TKIXG3KL.js.map +0 -1
package/dist/serve.js
CHANGED
|
@@ -7,9 +7,10 @@ import {
|
|
|
7
7
|
IGNORED_EVENT_TYPES,
|
|
8
8
|
KnownContentBlockSchema,
|
|
9
9
|
StreamJsonEventSchema,
|
|
10
|
+
createScopedApprovalRequestIdFactory,
|
|
10
11
|
disposeSeqCounter,
|
|
11
12
|
getSeqCounterFor
|
|
12
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-UDLPU2NC.js";
|
|
13
14
|
import {
|
|
14
15
|
appendPtySemanticTextTail,
|
|
15
16
|
decidePtySemanticTransition,
|
|
@@ -17,7 +18,7 @@ import {
|
|
|
17
18
|
extractOscSignals,
|
|
18
19
|
extractTextSignals,
|
|
19
20
|
shouldReleaseTextApprovalOnInput
|
|
20
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-W6275ZRJ.js";
|
|
21
22
|
import {
|
|
22
23
|
spawnScript
|
|
23
24
|
} from "./chunk-IHUQNJF6.js";
|
|
@@ -41,7 +42,7 @@ import {
|
|
|
41
42
|
serializeControl,
|
|
42
43
|
serializeIpc,
|
|
43
44
|
serializeWorkerMsg
|
|
44
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-IFQSVDHB.js";
|
|
45
46
|
import {
|
|
46
47
|
buildProviderEnv,
|
|
47
48
|
loadConfig,
|
|
@@ -162,10 +163,11 @@ var SessionManager = class {
|
|
|
162
163
|
this.onSessionRemoved = options.onSessionRemoved;
|
|
163
164
|
this.load();
|
|
164
165
|
}
|
|
165
|
-
createSession(mode, cwd, pid, name, id, provider = "claude", ptyOwner) {
|
|
166
|
+
createSession(mode, cwd, pid, name, id, provider = "claude", ptyOwner, nameLocked) {
|
|
166
167
|
const now = Date.now();
|
|
167
168
|
const pendingPtyMetadata = mode === "pty" && id !== void 0 ? this.pendingPtyReconnectMetadata.get(id) : void 0;
|
|
168
169
|
const resolvedName = pendingPtyMetadata?.nameLocked && pendingPtyMetadata.name !== void 0 ? pendingPtyMetadata.name : name;
|
|
170
|
+
const resolvedNameLocked = pendingPtyMetadata?.nameLocked ?? (nameLocked ? true : void 0);
|
|
169
171
|
const info = {
|
|
170
172
|
id: id ?? nanoid(),
|
|
171
173
|
mode,
|
|
@@ -177,7 +179,7 @@ var SessionManager = class {
|
|
|
177
179
|
cwd,
|
|
178
180
|
pid,
|
|
179
181
|
...resolvedName !== void 0 ? { name: resolvedName } : {},
|
|
180
|
-
...
|
|
182
|
+
...resolvedNameLocked !== void 0 ? { nameLocked: resolvedNameLocked } : {},
|
|
181
183
|
...pendingPtyMetadata?.claudeSessionId !== void 0 ? { claudeSessionId: pendingPtyMetadata.claudeSessionId } : {}
|
|
182
184
|
};
|
|
183
185
|
this.sessions.set(info.id, info);
|
|
@@ -2297,8 +2299,8 @@ function loadImagePreview(request, options) {
|
|
|
2297
2299
|
}
|
|
2298
2300
|
|
|
2299
2301
|
// src/serve/pty-input.ts
|
|
2300
|
-
function serializeRawPtyInput(sessionId, data) {
|
|
2301
|
-
return serializeIpc({ type: "pty_input", sessionId, data });
|
|
2302
|
+
function serializeRawPtyInput(sessionId, data, traceId) {
|
|
2303
|
+
return serializeIpc({ type: "pty_input", sessionId, data, traceId });
|
|
2302
2304
|
}
|
|
2303
2305
|
|
|
2304
2306
|
// src/serve/relay-input-handlers.ts
|
|
@@ -2347,22 +2349,26 @@ var RelayInputHandlers = class {
|
|
|
2347
2349
|
);
|
|
2348
2350
|
}
|
|
2349
2351
|
onRemoteInputRaw(msg) {
|
|
2350
|
-
const { sessionId, data } = msg;
|
|
2352
|
+
const { sessionId, data, traceId } = msg;
|
|
2351
2353
|
if (!sessionId || data === void 0) return;
|
|
2352
2354
|
const ts = this.deps.terminalSockets.get(sessionId);
|
|
2353
|
-
|
|
2355
|
+
const hostedInputForwarded = !ts?.writable && (traceId ? this.deps.hostedPtyRegistry.write(sessionId, data, traceId) : this.deps.hostedPtyRegistry.write(sessionId, data));
|
|
2356
|
+
if (hostedInputForwarded) {
|
|
2354
2357
|
serviceLogger.info(
|
|
2355
|
-
{ sessionId, bytes: data.length },
|
|
2358
|
+
{ sessionId, traceId, bytes: data.length },
|
|
2356
2359
|
"Raw PTY input forwarded to hosted PTY"
|
|
2357
2360
|
);
|
|
2358
2361
|
return;
|
|
2359
2362
|
}
|
|
2360
2363
|
if (!ts?.writable) {
|
|
2361
|
-
serviceLogger.warn(
|
|
2364
|
+
serviceLogger.warn(
|
|
2365
|
+
{ sessionId, traceId },
|
|
2366
|
+
"Raw PTY input dropped: terminal socket unavailable"
|
|
2367
|
+
);
|
|
2362
2368
|
return;
|
|
2363
2369
|
}
|
|
2364
|
-
ts.write(serializeRawPtyInput(sessionId, data));
|
|
2365
|
-
serviceLogger.info({ sessionId, bytes: data.length }, "Raw PTY input forwarded");
|
|
2370
|
+
ts.write(serializeRawPtyInput(sessionId, data, traceId));
|
|
2371
|
+
serviceLogger.info({ sessionId, traceId, bytes: data.length }, "Raw PTY input forwarded");
|
|
2366
2372
|
}
|
|
2367
2373
|
onClipboardImageUpload(msg) {
|
|
2368
2374
|
const { sessionId, requestId } = msg;
|
|
@@ -2922,11 +2928,15 @@ var HostedPtyRegistry = class {
|
|
|
2922
2928
|
has(sessionId) {
|
|
2923
2929
|
return this.sessions.has(sessionId);
|
|
2924
2930
|
}
|
|
2925
|
-
write(sessionId, data) {
|
|
2931
|
+
write(sessionId, data, traceId) {
|
|
2926
2932
|
const hosted = this.sessions.get(sessionId);
|
|
2927
2933
|
if (!hosted) return false;
|
|
2928
2934
|
this.releaseTextApprovalOnInput(sessionId, hosted, data);
|
|
2929
2935
|
hosted.child.write(data);
|
|
2936
|
+
serviceLogger.debug(
|
|
2937
|
+
{ sessionId, traceId, bytes: data.length },
|
|
2938
|
+
"Raw PTY input written to hosted PTY"
|
|
2939
|
+
);
|
|
2930
2940
|
return true;
|
|
2931
2941
|
}
|
|
2932
2942
|
resize(sessionId, cols, rows) {
|
|
@@ -3106,6 +3116,10 @@ function validateSessionCwd(cwd) {
|
|
|
3106
3116
|
};
|
|
3107
3117
|
}
|
|
3108
3118
|
}
|
|
3119
|
+
function normalizeSessionName(name) {
|
|
3120
|
+
const trimmed = name?.trim();
|
|
3121
|
+
return trimmed ? trimmed : void 0;
|
|
3122
|
+
}
|
|
3109
3123
|
var RelaySessionCreateHandler = class {
|
|
3110
3124
|
constructor(deps) {
|
|
3111
3125
|
this.deps = deps;
|
|
@@ -3159,7 +3173,9 @@ var RelaySessionCreateHandler = class {
|
|
|
3159
3173
|
}
|
|
3160
3174
|
const resumeSessionId = msg.resumeSessionId;
|
|
3161
3175
|
const streamDelta = false;
|
|
3162
|
-
const
|
|
3176
|
+
const requestedName = normalizeSessionName(msg.name);
|
|
3177
|
+
const name = requestedName ?? tildify(sessionCwd);
|
|
3178
|
+
const nameLocked = requestedName !== void 0;
|
|
3163
3179
|
const pendingId = nanoid5();
|
|
3164
3180
|
const hook = this.deps.createHookContext(pendingId, provider);
|
|
3165
3181
|
const workerPid = this.deps.workerRegistry.spawn(pendingId, {
|
|
@@ -3187,7 +3203,9 @@ var RelaySessionCreateHandler = class {
|
|
|
3187
3203
|
workerPid,
|
|
3188
3204
|
name,
|
|
3189
3205
|
pendingId,
|
|
3190
|
-
provider
|
|
3206
|
+
provider,
|
|
3207
|
+
void 0,
|
|
3208
|
+
nameLocked
|
|
3191
3209
|
);
|
|
3192
3210
|
if (resumeSessionId) {
|
|
3193
3211
|
this.deps.sessionManager.setClaudeSessionId(session.id, resumeSessionId);
|
|
@@ -3196,7 +3214,11 @@ var RelaySessionCreateHandler = class {
|
|
|
3196
3214
|
serializeControl({
|
|
3197
3215
|
type: "session_create_response",
|
|
3198
3216
|
requestId,
|
|
3199
|
-
sessionId: session.id
|
|
3217
|
+
sessionId: session.id,
|
|
3218
|
+
name: session.name,
|
|
3219
|
+
nameLocked: session.nameLocked,
|
|
3220
|
+
mode: "json",
|
|
3221
|
+
provider
|
|
3200
3222
|
})
|
|
3201
3223
|
);
|
|
3202
3224
|
if (resumeSessionId) {
|
|
@@ -3254,7 +3276,9 @@ var RelaySessionCreateHandler = class {
|
|
|
3254
3276
|
}
|
|
3255
3277
|
const resumeSessionId = msg.resumeSessionId;
|
|
3256
3278
|
const pendingId = nanoid5();
|
|
3257
|
-
const
|
|
3279
|
+
const requestedName = normalizeSessionName(msg.name);
|
|
3280
|
+
const name = requestedName ?? tildify(cwd);
|
|
3281
|
+
const nameLocked = requestedName !== void 0;
|
|
3258
3282
|
const hook = this.deps.createHookContext(pendingId, provider);
|
|
3259
3283
|
try {
|
|
3260
3284
|
const pid = this.deps.hostedPtyRegistry.start({
|
|
@@ -3272,7 +3296,8 @@ var RelaySessionCreateHandler = class {
|
|
|
3272
3296
|
name,
|
|
3273
3297
|
pendingId,
|
|
3274
3298
|
provider,
|
|
3275
|
-
"proxy-hosted"
|
|
3299
|
+
"proxy-hosted",
|
|
3300
|
+
nameLocked
|
|
3276
3301
|
);
|
|
3277
3302
|
if (resumeSessionId && provider === "claude") {
|
|
3278
3303
|
this.deps.sessionManager.setClaudeSessionId(session.id, resumeSessionId);
|
|
@@ -3282,6 +3307,8 @@ var RelaySessionCreateHandler = class {
|
|
|
3282
3307
|
type: "session_create_response",
|
|
3283
3308
|
requestId: msg.requestId,
|
|
3284
3309
|
sessionId: session.id,
|
|
3310
|
+
name: session.name,
|
|
3311
|
+
nameLocked: session.nameLocked,
|
|
3285
3312
|
mode: "pty",
|
|
3286
3313
|
provider,
|
|
3287
3314
|
ptyOwner: "proxy-hosted"
|
|
@@ -3346,6 +3373,227 @@ var RelaySessionCreateHandler = class {
|
|
|
3346
3373
|
}
|
|
3347
3374
|
};
|
|
3348
3375
|
|
|
3376
|
+
// src/serve/voice-summary-handler.ts
|
|
3377
|
+
import { createHash } from "crypto";
|
|
3378
|
+
import { spawn as spawn2 } from "child_process";
|
|
3379
|
+
|
|
3380
|
+
// src/serve/voice-summary-prompt.ts
|
|
3381
|
+
var reasonLabels = {
|
|
3382
|
+
code: "code block",
|
|
3383
|
+
table: "table",
|
|
3384
|
+
diff: "diff",
|
|
3385
|
+
log: "log output",
|
|
3386
|
+
stack_trace: "stack trace",
|
|
3387
|
+
long_list: "long list",
|
|
3388
|
+
long_text: "long reply",
|
|
3389
|
+
mixed: "mixed structured content",
|
|
3390
|
+
approval: "tool approval request"
|
|
3391
|
+
};
|
|
3392
|
+
function buildVoiceSummaryPrompt({ reason, text }) {
|
|
3393
|
+
const clippedText = text.length > 24e3 ? `${text.slice(0, 24e3)}
|
|
3394
|
+
|
|
3395
|
+
[truncated]` : text;
|
|
3396
|
+
if (reason === "approval") {
|
|
3397
|
+
return [
|
|
3398
|
+
"You are producing speech for a hands-free developer assistant.",
|
|
3399
|
+
"",
|
|
3400
|
+
"The user must decide whether to approve one pending developer tool request.",
|
|
3401
|
+
"Create a concise but useful Chinese spoken approval summary.",
|
|
3402
|
+
"",
|
|
3403
|
+
"Rules:",
|
|
3404
|
+
"- Output one or two Chinese sentences.",
|
|
3405
|
+
"- Keep it under 100 Chinese characters; aim for 60-85.",
|
|
3406
|
+
"- Say what the tool wants to do in plain language and include enough context to decide.",
|
|
3407
|
+
"- Use the parameters to infer the key target, such as the exact search topic, short file name, command purpose, or result count.",
|
|
3408
|
+
"- Prefer concrete names from the request over generic nouns.",
|
|
3409
|
+
"- If a file/path/query/tool target is present, name it with a short basename, short path, or query topic.",
|
|
3410
|
+
"- Do not say generic phrases like \u9879\u76EE\u914D\u7F6E\u6587\u4EF6, \u67D0\u4E2A\u6587\u4EF6, \u76F8\u5173\u8D44\u6599, or \u7F51\u7EDC\u641C\u7D22 when a concrete target is available.",
|
|
3411
|
+
"- For search requests, include the query topic and result count when present.",
|
|
3412
|
+
"- For file requests, include the concrete file name or short path when present.",
|
|
3413
|
+
"- Mention up to two key parameters when they materially clarify the action.",
|
|
3414
|
+
"- Do not evaluate risk or safety; the user will decide from the approval card.",
|
|
3415
|
+
"- Do not read raw JSON, raw shell commands, IDs, or full paths.",
|
|
3416
|
+
"- Do not add greetings, markdown, explanations, or approval instructions.",
|
|
3417
|
+
"",
|
|
3418
|
+
"Good examples:",
|
|
3419
|
+
"- \u8981\u641C\u7D22 Web Speech \u7684\u5B98\u65B9\u8D44\u6599\uFF0C\u6700\u591A\u8FD4\u56DE\u5341\u6761\u7ED3\u679C\u3002",
|
|
3420
|
+
"- \u8981\u8BFB\u53D6 package.json\uFF0C\u7528\u6765\u786E\u8BA4\u6784\u5EFA\u811A\u672C\u548C\u4F9D\u8D56\u914D\u7F6E\u3002",
|
|
3421
|
+
"- \u8981\u8BFB\u53D6 apps/web/package.json\uFF0C\u7528\u6765\u786E\u8BA4 Web \u5E94\u7528\u7684\u811A\u672C\u548C\u4F9D\u8D56\u3002",
|
|
3422
|
+
"- \u8981\u7F16\u8F91 src/app.ts\uFF0C\u628A\u5165\u53E3\u903B\u8F91\u6539\u6210\u65B0\u7684\u521D\u59CB\u5316\u6D41\u7A0B\u3002",
|
|
3423
|
+
"- \u8981\u5220\u9664\u6784\u5EFA\u76EE\u5F55 dist\uFF0C\u6E05\u7406\u65E7\u7684\u4EA7\u7269\u540E\u91CD\u65B0\u751F\u6210\u3002",
|
|
3424
|
+
"",
|
|
3425
|
+
"Tool request:",
|
|
3426
|
+
clippedText
|
|
3427
|
+
].join("\n");
|
|
3428
|
+
}
|
|
3429
|
+
return [
|
|
3430
|
+
"You are producing speech for a hands-free developer assistant.",
|
|
3431
|
+
"",
|
|
3432
|
+
`The assistant response contains ${reasonLabels[reason]} content that should not be read verbatim.`,
|
|
3433
|
+
"Create a concise Chinese speech summary for the user.",
|
|
3434
|
+
"",
|
|
3435
|
+
"Rules:",
|
|
3436
|
+
"- Do not use Markdown tables.",
|
|
3437
|
+
"- Do not include code blocks or raw stack traces.",
|
|
3438
|
+
"- Mention that the structured/code/log content was summarized.",
|
|
3439
|
+
"- Preserve concrete decisions, risks, commands, filenames, and next actions when they matter.",
|
|
3440
|
+
"- Keep it short enough to read aloud naturally, ideally 2-4 sentences.",
|
|
3441
|
+
"",
|
|
3442
|
+
"Assistant response:",
|
|
3443
|
+
clippedText
|
|
3444
|
+
].join("\n");
|
|
3445
|
+
}
|
|
3446
|
+
|
|
3447
|
+
// src/serve/voice-summary-handler.ts
|
|
3448
|
+
var SUMMARY_TIMEOUT_MS = 12e3;
|
|
3449
|
+
function buildClaudeSpeechSummaryCommand({
|
|
3450
|
+
env
|
|
3451
|
+
}) {
|
|
3452
|
+
return {
|
|
3453
|
+
command: env.CLAUDE_BIN || "claude",
|
|
3454
|
+
args: [
|
|
3455
|
+
"-p",
|
|
3456
|
+
"--output-format",
|
|
3457
|
+
"text",
|
|
3458
|
+
"--input-format",
|
|
3459
|
+
"text",
|
|
3460
|
+
"--no-session-persistence",
|
|
3461
|
+
"--permission-mode",
|
|
3462
|
+
"plan",
|
|
3463
|
+
"--tools",
|
|
3464
|
+
"Read,Grep,Glob,LS"
|
|
3465
|
+
]
|
|
3466
|
+
};
|
|
3467
|
+
}
|
|
3468
|
+
var runClaudeSpeechSummary = ({ cwd, prompt, env, timeoutMs }) => {
|
|
3469
|
+
const { command, args } = buildClaudeSpeechSummaryCommand({ env, prompt });
|
|
3470
|
+
return new Promise((resolve3, reject) => {
|
|
3471
|
+
const child = spawn2(command, args, {
|
|
3472
|
+
cwd,
|
|
3473
|
+
env: { ...process.env, ...env },
|
|
3474
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
3475
|
+
});
|
|
3476
|
+
const stdoutChunks = [];
|
|
3477
|
+
const stderrChunks = [];
|
|
3478
|
+
let settled = false;
|
|
3479
|
+
const timer = setTimeout(() => {
|
|
3480
|
+
if (settled) return;
|
|
3481
|
+
settled = true;
|
|
3482
|
+
child.kill("SIGTERM");
|
|
3483
|
+
reject(new Error("Claude speech summary timed out"));
|
|
3484
|
+
}, timeoutMs);
|
|
3485
|
+
child.stdin.on("error", () => {
|
|
3486
|
+
});
|
|
3487
|
+
child.stdin.end(prompt);
|
|
3488
|
+
child.stdout.on("data", (chunk) => stdoutChunks.push(chunk));
|
|
3489
|
+
child.stderr.on("data", (chunk) => stderrChunks.push(chunk));
|
|
3490
|
+
child.on("error", (err) => {
|
|
3491
|
+
if (settled) return;
|
|
3492
|
+
settled = true;
|
|
3493
|
+
clearTimeout(timer);
|
|
3494
|
+
reject(err);
|
|
3495
|
+
});
|
|
3496
|
+
child.on("close", (code) => {
|
|
3497
|
+
if (settled) return;
|
|
3498
|
+
settled = true;
|
|
3499
|
+
clearTimeout(timer);
|
|
3500
|
+
const stdout = Buffer.concat(stdoutChunks).toString("utf8").trim();
|
|
3501
|
+
if (code === 0 && stdout.length > 0) {
|
|
3502
|
+
resolve3(stdout);
|
|
3503
|
+
return;
|
|
3504
|
+
}
|
|
3505
|
+
const stderr = Buffer.concat(stderrChunks).toString("utf8").trim();
|
|
3506
|
+
reject(new Error(stderr || `Claude speech summary exited with code ${code ?? "unknown"}`));
|
|
3507
|
+
});
|
|
3508
|
+
});
|
|
3509
|
+
};
|
|
3510
|
+
var VoiceSummaryHandler = class {
|
|
3511
|
+
constructor(deps) {
|
|
3512
|
+
this.deps = deps;
|
|
3513
|
+
this.runner = deps.runner ?? runClaudeSpeechSummary;
|
|
3514
|
+
}
|
|
3515
|
+
deps;
|
|
3516
|
+
cache = /* @__PURE__ */ new Map();
|
|
3517
|
+
runner;
|
|
3518
|
+
async onVoiceSummaryRequest(msg) {
|
|
3519
|
+
const session = this.deps.sessionManager.getSession(msg.sessionId);
|
|
3520
|
+
if (!session) {
|
|
3521
|
+
this.sendFailure(msg, "Session not found", ControlErrorCode.SESSION_NOT_FOUND);
|
|
3522
|
+
return;
|
|
3523
|
+
}
|
|
3524
|
+
const cacheKey = cacheKeyForSummary(msg.sessionId, msg.messageId, msg.reason, msg.text);
|
|
3525
|
+
const cached = this.cache.get(cacheKey);
|
|
3526
|
+
if (cached) {
|
|
3527
|
+
this.sendSuccess(msg, cached);
|
|
3528
|
+
return;
|
|
3529
|
+
}
|
|
3530
|
+
const prompt = buildVoiceSummaryPrompt({ reason: msg.reason, text: msg.text });
|
|
3531
|
+
try {
|
|
3532
|
+
const summary = sanitizeSummary(
|
|
3533
|
+
await this.runner({
|
|
3534
|
+
cwd: session.cwd,
|
|
3535
|
+
prompt,
|
|
3536
|
+
env: this.deps.getProviderEnv(),
|
|
3537
|
+
timeoutMs: SUMMARY_TIMEOUT_MS
|
|
3538
|
+
}),
|
|
3539
|
+
msg.reason
|
|
3540
|
+
);
|
|
3541
|
+
if (!summary) {
|
|
3542
|
+
this.sendFailure(msg, "Voice summary is empty", ControlErrorCode.UNKNOWN);
|
|
3543
|
+
return;
|
|
3544
|
+
}
|
|
3545
|
+
this.cache.set(cacheKey, summary);
|
|
3546
|
+
this.sendSuccess(msg, summary);
|
|
3547
|
+
} catch (err) {
|
|
3548
|
+
serviceLogger.warn(
|
|
3549
|
+
{ sessionId: msg.sessionId, messageId: msg.messageId, error: String(err) },
|
|
3550
|
+
"Voice summary generation failed"
|
|
3551
|
+
);
|
|
3552
|
+
this.sendFailure(msg, "Voice summary generation failed", ControlErrorCode.UNKNOWN);
|
|
3553
|
+
}
|
|
3554
|
+
}
|
|
3555
|
+
sendSuccess(msg, summary) {
|
|
3556
|
+
this.deps.relaySend(
|
|
3557
|
+
serializeControl({
|
|
3558
|
+
type: "voice_summary_response",
|
|
3559
|
+
requestId: msg.requestId,
|
|
3560
|
+
sessionId: msg.sessionId,
|
|
3561
|
+
messageId: msg.messageId,
|
|
3562
|
+
success: true,
|
|
3563
|
+
summary
|
|
3564
|
+
})
|
|
3565
|
+
);
|
|
3566
|
+
}
|
|
3567
|
+
sendFailure(msg, error, errorCode3) {
|
|
3568
|
+
this.deps.relaySend(
|
|
3569
|
+
serializeControl({
|
|
3570
|
+
type: "voice_summary_response",
|
|
3571
|
+
requestId: msg.requestId,
|
|
3572
|
+
sessionId: msg.sessionId,
|
|
3573
|
+
messageId: msg.messageId,
|
|
3574
|
+
success: false,
|
|
3575
|
+
error,
|
|
3576
|
+
errorCode: errorCode3
|
|
3577
|
+
})
|
|
3578
|
+
);
|
|
3579
|
+
}
|
|
3580
|
+
};
|
|
3581
|
+
function cacheKeyForSummary(sessionId, messageId, reason, text) {
|
|
3582
|
+
return createHash("sha256").update(sessionId).update("\0").update(messageId).update("\0").update(reason).update("\0").update(text).digest("hex");
|
|
3583
|
+
}
|
|
3584
|
+
function sanitizeSummary(value, reason) {
|
|
3585
|
+
const summary = value.replace(/\s+/g, " ").trim().slice(0, 1e3);
|
|
3586
|
+
if (reason === "approval" && containsApprovalRiskEvaluation(summary)) {
|
|
3587
|
+
return "";
|
|
3588
|
+
}
|
|
3589
|
+
return summary;
|
|
3590
|
+
}
|
|
3591
|
+
function containsApprovalRiskEvaluation(summary) {
|
|
3592
|
+
return /(?:风险|危险|高危|中危|低危|谨慎|小心|破坏性|不可逆|安全风险|不安全|建议(?:允许|拒绝|批准))/u.test(
|
|
3593
|
+
summary
|
|
3594
|
+
);
|
|
3595
|
+
}
|
|
3596
|
+
|
|
3349
3597
|
// src/serve/relay-router.ts
|
|
3350
3598
|
var RelayRouter = class {
|
|
3351
3599
|
constructor(deps) {
|
|
@@ -3392,6 +3640,12 @@ var RelayRouter = class {
|
|
|
3392
3640
|
broadcastSessionSync: deps.broadcastSessionSync,
|
|
3393
3641
|
broadcastSessionList: deps.broadcastSessionList
|
|
3394
3642
|
});
|
|
3643
|
+
this.voiceSummaryHandler = new VoiceSummaryHandler({
|
|
3644
|
+
relaySend: deps.relaySend,
|
|
3645
|
+
sessionManager: deps.sessionManager,
|
|
3646
|
+
getProviderEnv: deps.getProviderEnv,
|
|
3647
|
+
runner: deps.voiceSummaryRunner
|
|
3648
|
+
});
|
|
3395
3649
|
}
|
|
3396
3650
|
deps;
|
|
3397
3651
|
historyHandlers;
|
|
@@ -3399,6 +3653,7 @@ var RelayRouter = class {
|
|
|
3399
3653
|
permissionHandlers;
|
|
3400
3654
|
resourceHandlers;
|
|
3401
3655
|
sessionCreateHandler;
|
|
3656
|
+
voiceSummaryHandler;
|
|
3402
3657
|
// shutdown 链路上提供单一 destroy 入口:把 sessionCreateHandler 内部 pending retry timer 清掉
|
|
3403
3658
|
// 并 cleanup 已 spawn 但未 connect 的 worker 子进程,避免在 SIGTERM 之后变成孤儿。
|
|
3404
3659
|
destroy() {
|
|
@@ -3506,6 +3761,9 @@ var RelayRouter = class {
|
|
|
3506
3761
|
case "session_subscribe":
|
|
3507
3762
|
this.onSessionSubscribe(msg);
|
|
3508
3763
|
return;
|
|
3764
|
+
case "voice_summary_request":
|
|
3765
|
+
void this.voiceSummaryHandler.onVoiceSummaryRequest(msg);
|
|
3766
|
+
return;
|
|
3509
3767
|
case "terminal_resize_request":
|
|
3510
3768
|
this.onTerminalResizeRequest(msg);
|
|
3511
3769
|
return;
|
|
@@ -3799,6 +4057,7 @@ var HookEventRouter = class {
|
|
|
3799
4057
|
this.deps = deps;
|
|
3800
4058
|
}
|
|
3801
4059
|
deps;
|
|
4060
|
+
nextFallbackRequestId = createScopedApprovalRequestIdFactory();
|
|
3802
4061
|
handle(event) {
|
|
3803
4062
|
switch (event.event) {
|
|
3804
4063
|
case "SessionStart":
|
|
@@ -3856,7 +4115,7 @@ var HookEventRouter = class {
|
|
|
3856
4115
|
serviceLogger.info({ sessionId, requestId, outcome }, "Hook permission resolved");
|
|
3857
4116
|
}
|
|
3858
4117
|
forwardPermissionRequest(event) {
|
|
3859
|
-
const requestId = event.requestId ??
|
|
4118
|
+
const requestId = event.requestId ?? this.nextFallbackRequestId(event.sessionId);
|
|
3860
4119
|
const toolName = toolNameFromPayload(event.payload);
|
|
3861
4120
|
const input = toolInputFromPayload(event.payload);
|
|
3862
4121
|
this.deps.changeSessionState(event.sessionId, SessionState.WAITING_APPROVAL);
|
|
@@ -4370,7 +4629,7 @@ function handleTerminalConnection(socket, deps) {
|
|
|
4370
4629
|
case "pty_input": {
|
|
4371
4630
|
if (!sessionManager.getSession(msg.sessionId)) break;
|
|
4372
4631
|
const targetSocket = terminalSockets.get(msg.sessionId);
|
|
4373
|
-
if (hostedPtyRegistry.write(msg.sessionId, msg.data)) {
|
|
4632
|
+
if (msg.traceId ? hostedPtyRegistry.write(msg.sessionId, msg.data, msg.traceId) : hostedPtyRegistry.write(msg.sessionId, msg.data)) {
|
|
4374
4633
|
break;
|
|
4375
4634
|
}
|
|
4376
4635
|
if (targetSocket?.writable) {
|
|
@@ -4378,7 +4637,8 @@ function handleTerminalConnection(socket, deps) {
|
|
|
4378
4637
|
serializeIpc({
|
|
4379
4638
|
type: "pty_input",
|
|
4380
4639
|
sessionId: msg.sessionId,
|
|
4381
|
-
data: msg.data
|
|
4640
|
+
data: msg.data,
|
|
4641
|
+
traceId: msg.traceId
|
|
4382
4642
|
})
|
|
4383
4643
|
);
|
|
4384
4644
|
}
|
|
@@ -4468,7 +4728,7 @@ function handleTerminalConnection(socket, deps) {
|
|
|
4468
4728
|
}
|
|
4469
4729
|
|
|
4470
4730
|
// src/serve/hook-registry.ts
|
|
4471
|
-
import { createHash, randomBytes } from "crypto";
|
|
4731
|
+
import { createHash as createHash2, randomBytes } from "crypto";
|
|
4472
4732
|
import { existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync7, renameSync, writeFileSync as writeFileSync3 } from "fs";
|
|
4473
4733
|
import { dirname } from "path";
|
|
4474
4734
|
import { z } from "zod";
|
|
@@ -4485,7 +4745,7 @@ var PersistedHookRegistrySchema = z.object({
|
|
|
4485
4745
|
bindings: z.array(PersistedHookSessionBindingSchema)
|
|
4486
4746
|
});
|
|
4487
4747
|
function hashToken(token) {
|
|
4488
|
-
return
|
|
4748
|
+
return createHash2("sha256").update(token).digest("hex");
|
|
4489
4749
|
}
|
|
4490
4750
|
function randomSecret() {
|
|
4491
4751
|
return randomBytes(32).toString("base64url");
|
|
@@ -4589,6 +4849,7 @@ var HookServer = class {
|
|
|
4589
4849
|
server = null;
|
|
4590
4850
|
host;
|
|
4591
4851
|
maxBodyBytes;
|
|
4852
|
+
nextFallbackRequestId = createScopedApprovalRequestIdFactory();
|
|
4592
4853
|
start() {
|
|
4593
4854
|
if (this.server) return Promise.resolve();
|
|
4594
4855
|
this.server = createServer((req, res) => {
|
|
@@ -4677,7 +4938,7 @@ var HookServer = class {
|
|
|
4677
4938
|
this.writeProviderResponse(res, this.toNeutralProviderResponse(event.provider, event.event));
|
|
4678
4939
|
}
|
|
4679
4940
|
async handlePermissionRequest(event, res) {
|
|
4680
|
-
const requestId = event.requestId ?? (typeof event.payload.tool_use_id === "string" ? event.payload.tool_use_id : void 0) ??
|
|
4941
|
+
const requestId = event.requestId ?? (typeof event.payload.tool_use_id === "string" ? event.payload.tool_use_id : void 0) ?? this.nextFallbackRequestId(event.sessionId);
|
|
4681
4942
|
const toolName = toolNameFromPayload(event.payload);
|
|
4682
4943
|
const input = asRecord(event.payload.input ?? event.payload.tool_input);
|
|
4683
4944
|
this.options.onEvent?.({ ...event, requestId });
|