dsh-agent-enhancer 0.3.12 → 0.3.13
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/README.en.md +8 -7
- package/README.md +8 -7
- package/lib/client/dsh/settings-about.d.ts +0 -3
- package/lib/client/dsh/settings-about.d.ts.map +1 -1
- package/lib/client/dsh/settings.d.ts +0 -3
- package/lib/client/dsh/settings.d.ts.map +1 -1
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/locales.d.ts +29 -51
- package/lib/client/locales.d.ts.map +1 -1
- package/lib/client/remote.d.ts +0 -7
- package/lib/client/remote.d.ts.map +1 -1
- package/lib/client/web-chat-bridge/preview.d.ts.map +1 -1
- package/lib/client/web-chat-bridge/share-fetch.d.ts +13 -2
- package/lib/client/web-chat-bridge/share-fetch.d.ts.map +1 -1
- package/lib/client.js +1386 -1771
- package/lib/client.js.map +1 -1
- package/lib/host/index.d.ts +0 -4
- package/lib/host/index.d.ts.map +1 -1
- package/lib/host/rpc.d.ts +255 -38
- package/lib/host/rpc.d.ts.map +1 -1
- package/lib/host/web-chat-bridge/convert-conversation.d.ts +38 -0
- package/lib/host/web-chat-bridge/convert-conversation.d.ts.map +1 -0
- package/lib/host/web-chat-bridge/fragments.d.ts +72 -0
- package/lib/host/web-chat-bridge/fragments.d.ts.map +1 -0
- package/lib/host/web-chat-bridge/import-session.d.ts +2 -1
- package/lib/host/web-chat-bridge/import-session.d.ts.map +1 -1
- package/lib/host/web-chat-bridge/share-link.d.ts.map +1 -1
- package/lib/host/web-chat-bridge/types.d.ts +9 -0
- package/lib/host/web-chat-bridge/types.d.ts.map +1 -1
- package/lib/index.js +744 -458
- package/lib/index.js.map +4 -4
- package/package.json +5 -1
- package/lib/client/dsh/settings-update.d.ts +0 -9
- package/lib/client/dsh/settings-update.d.ts.map +0 -1
- package/lib/host/update/check.d.ts +0 -32
- package/lib/host/update/check.d.ts.map +0 -1
- package/lib/host/update/cli.d.ts +0 -41
- package/lib/host/update/cli.d.ts.map +0 -1
- package/lib/host/update/install-kind.d.ts +0 -3
- package/lib/host/update/install-kind.d.ts.map +0 -1
- package/lib/host/update/registry.d.ts +0 -16
- package/lib/host/update/registry.d.ts.map +0 -1
- package/lib/host/update/semver.d.ts +0 -2
- package/lib/host/update/semver.d.ts.map +0 -1
- package/lib/host/update/types.d.ts +0 -17
- package/lib/host/update/types.d.ts.map +0 -1
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/host/index.ts
|
|
2
|
-
import { existsSync as
|
|
3
|
-
import { homedir as
|
|
4
|
-
import { join as
|
|
2
|
+
import { existsSync as existsSync20, mkdirSync as mkdirSync12, readdirSync as readdirSync7, renameSync as renameSync9, rmdirSync } from "node:fs";
|
|
3
|
+
import { homedir as homedir5 } from "node:os";
|
|
4
|
+
import { join as join30 } from "node:path";
|
|
5
5
|
import z5 from "@deepseek-ai/schemastery";
|
|
6
6
|
import { RemoteError as RemoteError2, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
7
7
|
|
|
@@ -6613,7 +6613,7 @@ async function deleteSessionNow(options) {
|
|
|
6613
6613
|
}
|
|
6614
6614
|
|
|
6615
6615
|
// src/host/web-chat-bridge/import-session.ts
|
|
6616
|
-
import { randomUUID as
|
|
6616
|
+
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
6617
6617
|
import { existsSync as existsSync5, mkdirSync as mkdirSync2, statSync } from "node:fs";
|
|
6618
6618
|
import { resolve as resolve2 } from "node:path";
|
|
6619
6619
|
import { RemoteError } from "@deepseek-ai/dsh-typert-protocol";
|
|
@@ -6624,7 +6624,7 @@ import {
|
|
|
6624
6624
|
} from "@deepseek-ai/dsh-llm";
|
|
6625
6625
|
import {
|
|
6626
6626
|
SessionId,
|
|
6627
|
-
SessionSeq as
|
|
6627
|
+
SessionSeq as SessionSeq3
|
|
6628
6628
|
} from "@deepseek-ai/dsh-session";
|
|
6629
6629
|
|
|
6630
6630
|
// src/host/extra-folders/pick.ts
|
|
@@ -6855,6 +6855,413 @@ async function pickFileNow(signal, options = {}) {
|
|
|
6855
6855
|
);
|
|
6856
6856
|
}
|
|
6857
6857
|
|
|
6858
|
+
// src/host/web-chat-bridge/convert-conversation.ts
|
|
6859
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
6860
|
+
import {
|
|
6861
|
+
MessageId as MessageId2,
|
|
6862
|
+
ToolCallId
|
|
6863
|
+
} from "@deepseek-ai/dsh-llm";
|
|
6864
|
+
import { SessionSeq as SessionSeq2 } from "@deepseek-ai/dsh-session";
|
|
6865
|
+
import {
|
|
6866
|
+
fetchMetaFromValue,
|
|
6867
|
+
formatFetchOutput,
|
|
6868
|
+
formatSearchOutput,
|
|
6869
|
+
searchMetaFromValue
|
|
6870
|
+
} from "@deepseek-ai/dsh-tool-web";
|
|
6871
|
+
var WEB_CHAT_IMPORTED_MODEL_SOURCE = {
|
|
6872
|
+
provider: "web-chat-bridge",
|
|
6873
|
+
model: "imported-history"
|
|
6874
|
+
};
|
|
6875
|
+
var FETCH_OUTPUT_CHARS = 4e3;
|
|
6876
|
+
var UNFINISHED_STATUS_CODES = /* @__PURE__ */ new Map([
|
|
6877
|
+
["FAILED", "DEEPSEEK_EXPORT_FAILED"],
|
|
6878
|
+
["TIMEOUT", "DEEPSEEK_EXPORT_TIMEOUT"],
|
|
6879
|
+
["CONTEXT_LENGTH_EXCEEDED", "DEEPSEEK_EXPORT_CONTEXT_LENGTH_EXCEEDED"],
|
|
6880
|
+
["INCOMPLETE", "DEEPSEEK_EXPORT_INCOMPLETE"],
|
|
6881
|
+
["WIP", "DEEPSEEK_EXPORT_WIP"]
|
|
6882
|
+
]);
|
|
6883
|
+
var WebChatConvertError = class extends Error {
|
|
6884
|
+
name = "WebChatConvertError";
|
|
6885
|
+
};
|
|
6886
|
+
function nonEmpty(value) {
|
|
6887
|
+
return value === null || value === void 0 || value.trim().length === 0 ? void 0 : value;
|
|
6888
|
+
}
|
|
6889
|
+
function selectWebChatBranch(messages, currentMessageId) {
|
|
6890
|
+
if (messages.length === 0) {
|
|
6891
|
+
throw new WebChatConvertError("conversation has no messages");
|
|
6892
|
+
}
|
|
6893
|
+
const ids = new Set(messages.map((message) => message.id));
|
|
6894
|
+
const resolved = messages.map((message) => {
|
|
6895
|
+
if (message.parent_id === null || ids.has(message.parent_id)) return message;
|
|
6896
|
+
return { ...message, parent_id: null };
|
|
6897
|
+
});
|
|
6898
|
+
const hasParents = resolved.some((message) => message.parent_id !== null);
|
|
6899
|
+
if (!hasParents) return resolved;
|
|
6900
|
+
const byId = /* @__PURE__ */ new Map();
|
|
6901
|
+
let newest;
|
|
6902
|
+
for (const message of resolved) {
|
|
6903
|
+
if (byId.has(message.id)) {
|
|
6904
|
+
return resolved;
|
|
6905
|
+
}
|
|
6906
|
+
byId.set(message.id, message);
|
|
6907
|
+
if (newest === void 0 || message.id > newest.id) newest = message;
|
|
6908
|
+
}
|
|
6909
|
+
if (newest === void 0) {
|
|
6910
|
+
throw new WebChatConvertError("conversation has no messages");
|
|
6911
|
+
}
|
|
6912
|
+
const selected = currentMessageId === null || currentMessageId === void 0 ? void 0 : byId.get(currentMessageId);
|
|
6913
|
+
const chain = [];
|
|
6914
|
+
for (let message = selected ?? newest; ; ) {
|
|
6915
|
+
if (chain.length === byId.size) {
|
|
6916
|
+
return resolved;
|
|
6917
|
+
}
|
|
6918
|
+
chain.push(message);
|
|
6919
|
+
if (message.parent_id === null) return chain.reverse();
|
|
6920
|
+
const parent = byId.get(message.parent_id);
|
|
6921
|
+
if (parent === void 0) return resolved;
|
|
6922
|
+
message = parent;
|
|
6923
|
+
}
|
|
6924
|
+
}
|
|
6925
|
+
function convertWebChatConversation(input, options = {}) {
|
|
6926
|
+
const createId = options.createId ?? (() => randomUUID6());
|
|
6927
|
+
const chain = selectWebChatBranch(input.messages, input.currentMessageId);
|
|
6928
|
+
const log = new LogBuilder(createId, options.provenancePrefix ?? "");
|
|
6929
|
+
const title = input.title !== null && input.title.trim() !== "" ? input.title.trim() : null;
|
|
6930
|
+
let turn = 0;
|
|
6931
|
+
let withdrawn = 0;
|
|
6932
|
+
for (let index = 0; index < chain.length; index++) {
|
|
6933
|
+
const user = chain[index];
|
|
6934
|
+
if (user.role !== "USER") continue;
|
|
6935
|
+
const next = chain[index + 1];
|
|
6936
|
+
const reply = next?.role === "ASSISTANT" ? next : void 0;
|
|
6937
|
+
if (reply !== void 0) index++;
|
|
6938
|
+
if (reply?.status === "CONTENT_FILTER") {
|
|
6939
|
+
withdrawn++;
|
|
6940
|
+
continue;
|
|
6941
|
+
}
|
|
6942
|
+
turn++;
|
|
6943
|
+
log.turn(turn, user, reply);
|
|
6944
|
+
if (turn === 1 && title !== null) {
|
|
6945
|
+
log.add({
|
|
6946
|
+
type: "session/title",
|
|
6947
|
+
data: { title, messageSeqs: [], source: { kind: "user" } }
|
|
6948
|
+
});
|
|
6949
|
+
}
|
|
6950
|
+
}
|
|
6951
|
+
if (turn === 0) {
|
|
6952
|
+
throw new WebChatConvertError(
|
|
6953
|
+
withdrawn === 0 ? "conversation has no user message" : "every question of the conversation was withdrawn by content filtering"
|
|
6954
|
+
);
|
|
6955
|
+
}
|
|
6956
|
+
return { title, events: log.events };
|
|
6957
|
+
}
|
|
6958
|
+
var LogBuilder = class {
|
|
6959
|
+
constructor(createId, provenancePrefix) {
|
|
6960
|
+
this.createId = createId;
|
|
6961
|
+
this.provenancePrefix = provenancePrefix;
|
|
6962
|
+
}
|
|
6963
|
+
createId;
|
|
6964
|
+
provenancePrefix;
|
|
6965
|
+
events = [];
|
|
6966
|
+
time = Date.now();
|
|
6967
|
+
add(event) {
|
|
6968
|
+
const seq = SessionSeq2(this.events.length);
|
|
6969
|
+
this.events.push({ ...event, seq, time: this.time });
|
|
6970
|
+
return seq;
|
|
6971
|
+
}
|
|
6972
|
+
turn(turn, user, reply) {
|
|
6973
|
+
this.add({ type: "turn/start", data: { turn } });
|
|
6974
|
+
let step = 1;
|
|
6975
|
+
this.add({ type: "step/start", data: { turn, step } });
|
|
6976
|
+
if (turn === 1) {
|
|
6977
|
+
const head = {
|
|
6978
|
+
id: MessageId2(this.id()),
|
|
6979
|
+
role: "system",
|
|
6980
|
+
content: [],
|
|
6981
|
+
source: { kind: "system-prompt" }
|
|
6982
|
+
};
|
|
6983
|
+
this.add({
|
|
6984
|
+
type: "system/message",
|
|
6985
|
+
data: { turn, step, message: head },
|
|
6986
|
+
surfaceOp: "append"
|
|
6987
|
+
});
|
|
6988
|
+
}
|
|
6989
|
+
this.add({
|
|
6990
|
+
type: "user/message",
|
|
6991
|
+
data: this.userMessage(user, turn === 1),
|
|
6992
|
+
surfaceOp: "append"
|
|
6993
|
+
});
|
|
6994
|
+
if (reply === void 0) {
|
|
6995
|
+
this.closeTurn(turn, step, failure(
|
|
6996
|
+
"DEEPSEEK_EXPORT_NO_REPLY",
|
|
6997
|
+
"The export contains no reply to this message."
|
|
6998
|
+
));
|
|
6999
|
+
return;
|
|
7000
|
+
}
|
|
7001
|
+
const { steps, template } = this.replySteps(reply);
|
|
7002
|
+
const excluded = excludedReply(reply, template, steps.length);
|
|
7003
|
+
if (excluded !== void 0) {
|
|
7004
|
+
this.closeTurn(turn, step, { kind: "error", error: excluded });
|
|
7005
|
+
return;
|
|
7006
|
+
}
|
|
7007
|
+
for (const [position, { content, calls, elapsedMs }] of steps.entries()) {
|
|
7008
|
+
if (position > 0) {
|
|
7009
|
+
step++;
|
|
7010
|
+
this.add({ type: "step/start", data: { turn, step } });
|
|
7011
|
+
}
|
|
7012
|
+
this.time += elapsedMs;
|
|
7013
|
+
this.add({
|
|
7014
|
+
type: "assistant/message",
|
|
7015
|
+
data: {
|
|
7016
|
+
turn,
|
|
7017
|
+
step,
|
|
7018
|
+
message: assistantMessage(this.id(), [
|
|
7019
|
+
...content,
|
|
7020
|
+
...calls.map((call) => call.block)
|
|
7021
|
+
]),
|
|
7022
|
+
stream: []
|
|
7023
|
+
},
|
|
7024
|
+
surfaceOp: "append"
|
|
7025
|
+
});
|
|
7026
|
+
const callSeqs = calls.map(({ block }) => this.add({
|
|
7027
|
+
type: "tool/call",
|
|
7028
|
+
data: {
|
|
7029
|
+
turn,
|
|
7030
|
+
step,
|
|
7031
|
+
callId: block.id,
|
|
7032
|
+
name: block.name,
|
|
7033
|
+
arguments: block.arguments
|
|
7034
|
+
}
|
|
7035
|
+
}));
|
|
7036
|
+
for (const [callIndex, call] of calls.entries()) {
|
|
7037
|
+
this.add({
|
|
7038
|
+
type: "tool/result",
|
|
7039
|
+
data: {
|
|
7040
|
+
turn,
|
|
7041
|
+
step,
|
|
7042
|
+
message: toolResult(this.id(), call),
|
|
7043
|
+
...call.meta === void 0 ? {} : { meta: call.meta }
|
|
7044
|
+
},
|
|
7045
|
+
surfaceOp: "append",
|
|
7046
|
+
sourceEventSeqs: [callSeqs[callIndex]]
|
|
7047
|
+
});
|
|
7048
|
+
}
|
|
7049
|
+
if (position < steps.length - 1) {
|
|
7050
|
+
this.add({ type: "step/end", data: { turn, step } });
|
|
7051
|
+
}
|
|
7052
|
+
}
|
|
7053
|
+
this.closeTurn(turn, step, { kind: "completed" });
|
|
7054
|
+
}
|
|
7055
|
+
closeTurn(turn, step, reason) {
|
|
7056
|
+
this.add({ type: "step/end", data: { turn, step } });
|
|
7057
|
+
this.add({ type: "turn/end", data: { turn, reason } });
|
|
7058
|
+
}
|
|
7059
|
+
id() {
|
|
7060
|
+
return this.createId();
|
|
7061
|
+
}
|
|
7062
|
+
userMessage(message, firstTurn) {
|
|
7063
|
+
const lines = [];
|
|
7064
|
+
for (const fragment of message.fragments) {
|
|
7065
|
+
if (fragment.type === "REQUEST") lines.push(fragment.content);
|
|
7066
|
+
}
|
|
7067
|
+
let text3 = lines.join("\n");
|
|
7068
|
+
if (firstTurn && this.provenancePrefix !== "") {
|
|
7069
|
+
text3 = `${this.provenancePrefix}${text3}`;
|
|
7070
|
+
}
|
|
7071
|
+
const content = [{ type: "text", text: text3 }];
|
|
7072
|
+
return {
|
|
7073
|
+
id: MessageId2(this.id()),
|
|
7074
|
+
role: "user",
|
|
7075
|
+
content,
|
|
7076
|
+
source: { kind: "user" }
|
|
7077
|
+
};
|
|
7078
|
+
}
|
|
7079
|
+
replySteps(reply) {
|
|
7080
|
+
const steps = [];
|
|
7081
|
+
let template;
|
|
7082
|
+
let current = emptyStep();
|
|
7083
|
+
const pushStep = () => {
|
|
7084
|
+
if (current.content.length === 0 && current.calls.length === 0) return;
|
|
7085
|
+
steps.push(current);
|
|
7086
|
+
current = emptyStep();
|
|
7087
|
+
};
|
|
7088
|
+
const appendContent = (block) => {
|
|
7089
|
+
if (current.calls.length > 0) pushStep();
|
|
7090
|
+
current.content.push(block);
|
|
7091
|
+
};
|
|
7092
|
+
const appendCall = (call, stage) => {
|
|
7093
|
+
if (stage !== null) {
|
|
7094
|
+
if (current.stage !== null && stage !== current.stage) pushStep();
|
|
7095
|
+
current.stage = stage;
|
|
7096
|
+
}
|
|
7097
|
+
current.calls.push(call);
|
|
7098
|
+
};
|
|
7099
|
+
for (const fragment of reply.fragments) {
|
|
7100
|
+
switch (fragment.type) {
|
|
7101
|
+
case "THINK":
|
|
7102
|
+
if (fragment.content.length > 0) {
|
|
7103
|
+
appendContent({ type: "reasoning", text: fragment.content });
|
|
7104
|
+
}
|
|
7105
|
+
current.elapsedMs += Math.round((fragment.elapsed_secs ?? 0) * 1e3);
|
|
7106
|
+
break;
|
|
7107
|
+
case "RESPONSE":
|
|
7108
|
+
if (fragment.content.length > 0) {
|
|
7109
|
+
appendContent({ type: "text", text: fragment.content });
|
|
7110
|
+
}
|
|
7111
|
+
break;
|
|
7112
|
+
case "TOOL_SEARCH": {
|
|
7113
|
+
if (fragment.status === "WIP") break;
|
|
7114
|
+
const call = searchCall(this.id(), fragment);
|
|
7115
|
+
if (call !== void 0) appendCall(call, fragment.stage_id ?? null);
|
|
7116
|
+
break;
|
|
7117
|
+
}
|
|
7118
|
+
case "TOOL_OPEN": {
|
|
7119
|
+
const url = nonEmpty(fragment.url);
|
|
7120
|
+
if (fragment.status === "WIP" || url === void 0) break;
|
|
7121
|
+
appendCall(openCall(this.id(), fragment, url), fragment.stage_id ?? null);
|
|
7122
|
+
break;
|
|
7123
|
+
}
|
|
7124
|
+
case "READ_LINK": {
|
|
7125
|
+
const text3 = linkLines(fragment.results);
|
|
7126
|
+
if (text3 !== void 0) appendContent({ type: "text", text: text3 });
|
|
7127
|
+
break;
|
|
7128
|
+
}
|
|
7129
|
+
case "TEMPLATE_RESPONSE":
|
|
7130
|
+
template ??= fragment.content;
|
|
7131
|
+
break;
|
|
7132
|
+
case "REQUEST":
|
|
7133
|
+
break;
|
|
7134
|
+
default: {
|
|
7135
|
+
const _exhaustive = fragment;
|
|
7136
|
+
throw new WebChatConvertError(`unexpected fragment ${String(_exhaustive)}`);
|
|
7137
|
+
}
|
|
7138
|
+
}
|
|
7139
|
+
}
|
|
7140
|
+
pushStep();
|
|
7141
|
+
return { steps, template };
|
|
7142
|
+
}
|
|
7143
|
+
};
|
|
7144
|
+
function emptyStep() {
|
|
7145
|
+
return { content: [], calls: [], elapsedMs: 0, stage: null };
|
|
7146
|
+
}
|
|
7147
|
+
function excludedReply(reply, template, stepCount) {
|
|
7148
|
+
if (template !== void 0) {
|
|
7149
|
+
return { code: "DEEPSEEK_EXPORT_TEMPLATE_RESPONSE", message: template };
|
|
7150
|
+
}
|
|
7151
|
+
if (reply.status !== "FINISHED") {
|
|
7152
|
+
return {
|
|
7153
|
+
code: UNFINISHED_STATUS_CODES.get(reply.status) ?? "DEEPSEEK_EXPORT_UNFINISHED_REPLY",
|
|
7154
|
+
message: `The original reply ended with status ${JSON.stringify(reply.status)} and is excluded from the model context.`
|
|
7155
|
+
};
|
|
7156
|
+
}
|
|
7157
|
+
return stepCount === 0 ? {
|
|
7158
|
+
code: "DEEPSEEK_EXPORT_EMPTY_REPLY",
|
|
7159
|
+
message: "The original reply has no importable content."
|
|
7160
|
+
} : void 0;
|
|
7161
|
+
}
|
|
7162
|
+
function failure(code, message) {
|
|
7163
|
+
return { kind: "error", error: { code, message } };
|
|
7164
|
+
}
|
|
7165
|
+
function linkLines(results) {
|
|
7166
|
+
const lines = [];
|
|
7167
|
+
for (const result of results) {
|
|
7168
|
+
const url = nonEmpty(result.url);
|
|
7169
|
+
const title = nonEmpty(result.title);
|
|
7170
|
+
if (url !== void 0) lines.push(`[${title ?? url}](${url})`);
|
|
7171
|
+
else if (title !== void 0) lines.push(title);
|
|
7172
|
+
}
|
|
7173
|
+
return lines.length === 0 ? void 0 : lines.join("\n");
|
|
7174
|
+
}
|
|
7175
|
+
function assistantMessage(id, content) {
|
|
7176
|
+
return {
|
|
7177
|
+
id: MessageId2(id),
|
|
7178
|
+
role: "assistant",
|
|
7179
|
+
content,
|
|
7180
|
+
source: { kind: "model", ...WEB_CHAT_IMPORTED_MODEL_SOURCE }
|
|
7181
|
+
};
|
|
7182
|
+
}
|
|
7183
|
+
function toolResult(id, call) {
|
|
7184
|
+
return {
|
|
7185
|
+
id: MessageId2(id),
|
|
7186
|
+
role: "tool",
|
|
7187
|
+
content: call.result,
|
|
7188
|
+
isError: call.isError,
|
|
7189
|
+
source: { kind: "tool", callId: call.block.id },
|
|
7190
|
+
toolCallId: call.block.id
|
|
7191
|
+
};
|
|
7192
|
+
}
|
|
7193
|
+
function searchCall(id, fragment) {
|
|
7194
|
+
const queries = fragment.queries.filter((query) => query.trim().length > 0);
|
|
7195
|
+
const block = {
|
|
7196
|
+
type: "tool-call",
|
|
7197
|
+
id: ToolCallId(id),
|
|
7198
|
+
name: "web_search",
|
|
7199
|
+
arguments: JSON.stringify({ queries })
|
|
7200
|
+
};
|
|
7201
|
+
if (fragment.status === "FAILED") {
|
|
7202
|
+
return {
|
|
7203
|
+
block,
|
|
7204
|
+
result: [{ type: "text", text: "Error: the export records this search as failed." }],
|
|
7205
|
+
isError: true
|
|
7206
|
+
};
|
|
7207
|
+
}
|
|
7208
|
+
if (queries.length === 0) return void 0;
|
|
7209
|
+
const result = {
|
|
7210
|
+
sources: fragment.results.map((source) => {
|
|
7211
|
+
const title = nonEmpty(source.title);
|
|
7212
|
+
const snippet = nonEmpty(source.snippet);
|
|
7213
|
+
const publishedAt = nonEmpty(source.published_at);
|
|
7214
|
+
return {
|
|
7215
|
+
url: source.url,
|
|
7216
|
+
...title === void 0 ? {} : { title },
|
|
7217
|
+
...snippet === void 0 ? {} : { snippet },
|
|
7218
|
+
...publishedAt === void 0 ? {} : { publishedAt }
|
|
7219
|
+
};
|
|
7220
|
+
}),
|
|
7221
|
+
truncated: false
|
|
7222
|
+
};
|
|
7223
|
+
return {
|
|
7224
|
+
block,
|
|
7225
|
+
result: [{ type: "text", text: formatSearchOutput(result) }],
|
|
7226
|
+
isError: false,
|
|
7227
|
+
meta: searchMetaFromValue(result)
|
|
7228
|
+
};
|
|
7229
|
+
}
|
|
7230
|
+
function openCall(id, fragment, url) {
|
|
7231
|
+
const block = {
|
|
7232
|
+
type: "tool-call",
|
|
7233
|
+
id: ToolCallId(id),
|
|
7234
|
+
name: "web_fetch",
|
|
7235
|
+
arguments: JSON.stringify({ url })
|
|
7236
|
+
};
|
|
7237
|
+
if (fragment.status !== "FINISHED") {
|
|
7238
|
+
return {
|
|
7239
|
+
block,
|
|
7240
|
+
result: [{ type: "text", text: "Error: the page could not be opened." }],
|
|
7241
|
+
isError: true
|
|
7242
|
+
};
|
|
7243
|
+
}
|
|
7244
|
+
const title = nonEmpty(fragment.title);
|
|
7245
|
+
const notice = "The page content is not included in the DeepSeek chat export.";
|
|
7246
|
+
const value = {
|
|
7247
|
+
url,
|
|
7248
|
+
statusCode: 200,
|
|
7249
|
+
truncated: false,
|
|
7250
|
+
body: {
|
|
7251
|
+
kind: "text",
|
|
7252
|
+
content: title === void 0 ? notice : `${title}
|
|
7253
|
+
|
|
7254
|
+
${notice}`
|
|
7255
|
+
}
|
|
7256
|
+
};
|
|
7257
|
+
return {
|
|
7258
|
+
block,
|
|
7259
|
+
result: [{ type: "text", text: formatFetchOutput(value, FETCH_OUTPUT_CHARS) }],
|
|
7260
|
+
isError: false,
|
|
7261
|
+
meta: fetchMetaFromValue(value, FETCH_OUTPUT_CHARS)
|
|
7262
|
+
};
|
|
7263
|
+
}
|
|
7264
|
+
|
|
6858
7265
|
// src/host/web-chat-bridge/limits.ts
|
|
6859
7266
|
var WEB_CHAT_MAX_TEXT_BYTES = 5 * 1024 * 1024;
|
|
6860
7267
|
var WEB_CHAT_MAX_MESSAGES = 5e3;
|
|
@@ -6936,6 +7343,9 @@ function resolveWebChatImportTitle(transcript) {
|
|
|
6936
7343
|
if (raw !== "") return raw;
|
|
6937
7344
|
return "Imported chat";
|
|
6938
7345
|
}
|
|
7346
|
+
function transcriptHasRichMessages(transcript) {
|
|
7347
|
+
return Array.isArray(transcript.messages) && transcript.messages.length > 0;
|
|
7348
|
+
}
|
|
6939
7349
|
function closeOpenTurn(session, turn) {
|
|
6940
7350
|
session.append("turn/end", { turn, reason: { kind: "completed" } });
|
|
6941
7351
|
}
|
|
@@ -6951,7 +7361,7 @@ function appendSessionTitle(session, title, firstUserMessageSeq) {
|
|
|
6951
7361
|
if (trimmed === "") return;
|
|
6952
7362
|
session.append("session/title", {
|
|
6953
7363
|
title: trimmed,
|
|
6954
|
-
messageSeqs: firstUserMessageSeq === void 0 ? [] : [
|
|
7364
|
+
messageSeqs: firstUserMessageSeq === void 0 ? [] : [SessionSeq3(firstUserMessageSeq)],
|
|
6955
7365
|
source: { kind: "fallback" }
|
|
6956
7366
|
});
|
|
6957
7367
|
}
|
|
@@ -6983,6 +7393,12 @@ function appendProtectedSystemHead(session, turn, step) {
|
|
|
6983
7393
|
]);
|
|
6984
7394
|
}
|
|
6985
7395
|
function appendTranscript(session, transcript) {
|
|
7396
|
+
if (transcriptHasRichMessages(transcript)) {
|
|
7397
|
+
throw new WebChatImportError(
|
|
7398
|
+
"import-failed",
|
|
7399
|
+
"Rich web-chat transcripts require seed import"
|
|
7400
|
+
);
|
|
7401
|
+
}
|
|
6986
7402
|
const provenance = importProvenancePrefix(transcript);
|
|
6987
7403
|
const turns = transcript.turns;
|
|
6988
7404
|
let turn = 1;
|
|
@@ -7041,11 +7457,29 @@ function appendTranscript(session, transcript) {
|
|
|
7041
7457
|
appendSessionTitle(session, resolveWebChatImportTitle(transcript), firstUserMessageSeq);
|
|
7042
7458
|
}
|
|
7043
7459
|
function buildWebChatImportSeed(transcript) {
|
|
7460
|
+
if (transcriptHasRichMessages(transcript)) {
|
|
7461
|
+
try {
|
|
7462
|
+
const converted = convertWebChatConversation({
|
|
7463
|
+
title: resolveWebChatImportTitle(transcript),
|
|
7464
|
+
currentMessageId: transcript.currentMessageId,
|
|
7465
|
+
messages: transcript.messages
|
|
7466
|
+
}, {
|
|
7467
|
+
createId: () => randomUUID7(),
|
|
7468
|
+
provenancePrefix: importProvenancePrefix(transcript)
|
|
7469
|
+
});
|
|
7470
|
+
return [...converted.events];
|
|
7471
|
+
} catch (error) {
|
|
7472
|
+
if (error instanceof WebChatConvertError) {
|
|
7473
|
+
throw new WebChatImportError("invalid-transcript", error.message);
|
|
7474
|
+
}
|
|
7475
|
+
throw error;
|
|
7476
|
+
}
|
|
7477
|
+
}
|
|
7044
7478
|
const events = [];
|
|
7045
7479
|
const recordOne = (type, data, intent) => {
|
|
7046
7480
|
const event = {
|
|
7047
7481
|
type,
|
|
7048
|
-
seq:
|
|
7482
|
+
seq: SessionSeq3(events.length),
|
|
7049
7483
|
time: Date.now(),
|
|
7050
7484
|
data,
|
|
7051
7485
|
...intent?.surfaceOp === void 0 ? {} : { surfaceOp: intent.surfaceOp }
|
|
@@ -7088,7 +7522,7 @@ function errorDetail(error) {
|
|
|
7088
7522
|
}
|
|
7089
7523
|
async function openAgentWorkSession(input, cwd) {
|
|
7090
7524
|
const agents = input.agents;
|
|
7091
|
-
if (typeof agents.createSession === "function") {
|
|
7525
|
+
if (typeof agents.createSession === "function" && !transcriptHasRichMessages(input.transcript)) {
|
|
7092
7526
|
let created;
|
|
7093
7527
|
try {
|
|
7094
7528
|
created = await agents.createSession({
|
|
@@ -7118,7 +7552,7 @@ async function openAgentWorkSession(input, cwd) {
|
|
|
7118
7552
|
if (typeof agents.create !== "function") {
|
|
7119
7553
|
throw new WebChatImportError("import-failed", "Agent registry is unavailable");
|
|
7120
7554
|
}
|
|
7121
|
-
const sessionId = SessionId(`session-${
|
|
7555
|
+
const sessionId = SessionId(`session-${randomUUID7()}`);
|
|
7122
7556
|
const seed = buildWebChatImportSeed(input.transcript);
|
|
7123
7557
|
let handle;
|
|
7124
7558
|
try {
|
|
@@ -7695,70 +8129,198 @@ function analyzeWebChatExport(input) {
|
|
|
7695
8129
|
};
|
|
7696
8130
|
}
|
|
7697
8131
|
|
|
7698
|
-
// src/host/web-chat-bridge/
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
|
|
7702
|
-
|
|
7703
|
-
|
|
7704
|
-
|
|
7705
|
-
if (
|
|
7706
|
-
if (
|
|
7707
|
-
return
|
|
8132
|
+
// src/host/web-chat-bridge/fragments.ts
|
|
8133
|
+
function nonEmptyString(value) {
|
|
8134
|
+
if (typeof value !== "string") return void 0;
|
|
8135
|
+
const trimmed = value.trim();
|
|
8136
|
+
return trimmed === "" ? void 0 : trimmed;
|
|
8137
|
+
}
|
|
8138
|
+
function optionalNumber(value) {
|
|
8139
|
+
if (value === null) return null;
|
|
8140
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
8141
|
+
return void 0;
|
|
7708
8142
|
}
|
|
7709
|
-
function
|
|
7710
|
-
return
|
|
8143
|
+
function parseSearchResults(raw) {
|
|
8144
|
+
if (!Array.isArray(raw)) return [];
|
|
8145
|
+
const out = [];
|
|
8146
|
+
for (const row of raw) {
|
|
8147
|
+
if (row === null || typeof row !== "object") continue;
|
|
8148
|
+
const item = row;
|
|
8149
|
+
const url = nonEmptyString(item.url);
|
|
8150
|
+
if (url === void 0) continue;
|
|
8151
|
+
out.push({
|
|
8152
|
+
url,
|
|
8153
|
+
title: typeof item.title === "string" || item.title === null ? item.title : void 0,
|
|
8154
|
+
snippet: typeof item.snippet === "string" || item.snippet === null ? item.snippet : void 0,
|
|
8155
|
+
published_at: typeof item.published_at === "string" || item.published_at === null ? item.published_at : void 0
|
|
8156
|
+
});
|
|
8157
|
+
}
|
|
8158
|
+
return out;
|
|
7711
8159
|
}
|
|
7712
|
-
function
|
|
7713
|
-
|
|
8160
|
+
function parseReadLinkResults(raw) {
|
|
8161
|
+
if (!Array.isArray(raw)) return [];
|
|
8162
|
+
const out = [];
|
|
8163
|
+
for (const row of raw) {
|
|
8164
|
+
if (row === null || typeof row !== "object") continue;
|
|
8165
|
+
const item = row;
|
|
8166
|
+
out.push({
|
|
8167
|
+
url: typeof item.url === "string" || item.url === null ? item.url : void 0,
|
|
8168
|
+
title: typeof item.title === "string" || item.title === null ? item.title : void 0
|
|
8169
|
+
});
|
|
8170
|
+
}
|
|
8171
|
+
return out;
|
|
8172
|
+
}
|
|
8173
|
+
function parseWebChatFragment(raw) {
|
|
8174
|
+
if (raw === null || typeof raw !== "object") return void 0;
|
|
8175
|
+
const item = raw;
|
|
8176
|
+
const type = String(item.type ?? "").toUpperCase();
|
|
8177
|
+
switch (type) {
|
|
8178
|
+
case "REQUEST": {
|
|
8179
|
+
const content = typeof item.content === "string" ? item.content : "";
|
|
8180
|
+
return { type: "REQUEST", content };
|
|
8181
|
+
}
|
|
8182
|
+
case "RESPONSE": {
|
|
8183
|
+
const content = typeof item.content === "string" ? item.content : "";
|
|
8184
|
+
return { type: "RESPONSE", content };
|
|
8185
|
+
}
|
|
8186
|
+
case "THINK": {
|
|
8187
|
+
const content = typeof item.content === "string" ? item.content : "";
|
|
8188
|
+
return {
|
|
8189
|
+
type: "THINK",
|
|
8190
|
+
content,
|
|
8191
|
+
elapsed_secs: optionalNumber(item.elapsed_secs)
|
|
8192
|
+
};
|
|
8193
|
+
}
|
|
8194
|
+
case "TEMPLATE_RESPONSE": {
|
|
8195
|
+
const content = typeof item.content === "string" ? item.content : "";
|
|
8196
|
+
return { type: "TEMPLATE_RESPONSE", content };
|
|
8197
|
+
}
|
|
8198
|
+
case "TOOL_SEARCH": {
|
|
8199
|
+
const queries = Array.isArray(item.queries) ? item.queries.filter((q) => typeof q === "string") : [];
|
|
8200
|
+
return {
|
|
8201
|
+
type: "TOOL_SEARCH",
|
|
8202
|
+
queries,
|
|
8203
|
+
results: parseSearchResults(item.results),
|
|
8204
|
+
status: typeof item.status === "string" ? item.status : void 0,
|
|
8205
|
+
stage_id: optionalNumber(item.stage_id)
|
|
8206
|
+
};
|
|
8207
|
+
}
|
|
8208
|
+
case "TOOL_OPEN": {
|
|
8209
|
+
const url = item.url === null ? null : typeof item.url === "string" ? item.url : null;
|
|
8210
|
+
return {
|
|
8211
|
+
type: "TOOL_OPEN",
|
|
8212
|
+
status: typeof item.status === "string" ? item.status : "FINISHED",
|
|
8213
|
+
url,
|
|
8214
|
+
title: typeof item.title === "string" || item.title === null ? item.title : void 0,
|
|
8215
|
+
stage_id: optionalNumber(item.stage_id)
|
|
8216
|
+
};
|
|
8217
|
+
}
|
|
8218
|
+
case "READ_LINK":
|
|
8219
|
+
return { type: "READ_LINK", results: parseReadLinkResults(item.results) };
|
|
8220
|
+
default:
|
|
8221
|
+
return void 0;
|
|
8222
|
+
}
|
|
7714
8223
|
}
|
|
7715
|
-
function
|
|
8224
|
+
function normalizeExportRole(raw) {
|
|
7716
8225
|
if (typeof raw !== "string") return null;
|
|
7717
|
-
const key = raw.trim().
|
|
7718
|
-
if (key === "
|
|
7719
|
-
if (key === "
|
|
8226
|
+
const key = raw.trim().toUpperCase();
|
|
8227
|
+
if (key === "USER" || key === "HUMAN") return "USER";
|
|
8228
|
+
if (key === "ASSISTANT" || key === "AI" || key === "MODEL") return "ASSISTANT";
|
|
7720
8229
|
return null;
|
|
7721
8230
|
}
|
|
7722
|
-
function
|
|
7723
|
-
|
|
7724
|
-
if (
|
|
7725
|
-
|
|
8231
|
+
function messageTextFallback(item) {
|
|
8232
|
+
const content = item.content ?? item.text ?? item.message;
|
|
8233
|
+
if (typeof content === "string") return content;
|
|
8234
|
+
if (Array.isArray(content)) {
|
|
8235
|
+
return content.map((part) => {
|
|
7726
8236
|
if (typeof part === "string") return part;
|
|
7727
8237
|
if (part && typeof part === "object" && "text" in part) {
|
|
7728
8238
|
const text3 = Reflect.get(part, "text");
|
|
7729
8239
|
return typeof text3 === "string" ? text3 : "";
|
|
7730
8240
|
}
|
|
7731
8241
|
return "";
|
|
7732
|
-
}).filter(Boolean).join("\n")
|
|
8242
|
+
}).filter(Boolean).join("\n");
|
|
7733
8243
|
}
|
|
7734
8244
|
return "";
|
|
7735
8245
|
}
|
|
7736
|
-
function
|
|
7737
|
-
if (
|
|
7738
|
-
|
|
7739
|
-
|
|
7740
|
-
|
|
8246
|
+
function numberId(raw) {
|
|
8247
|
+
if (typeof raw === "number" && Number.isFinite(raw)) return Math.trunc(raw);
|
|
8248
|
+
if (typeof raw === "string" && raw.trim() !== "") {
|
|
8249
|
+
const parsed = Number(raw);
|
|
8250
|
+
if (Number.isFinite(parsed)) return Math.trunc(parsed);
|
|
8251
|
+
}
|
|
8252
|
+
return void 0;
|
|
8253
|
+
}
|
|
8254
|
+
function parseWebChatRichMessage(raw, fallbackId) {
|
|
8255
|
+
if (raw === null || typeof raw !== "object") return null;
|
|
8256
|
+
const item = raw;
|
|
8257
|
+
const role = normalizeExportRole(item.role ?? item.author ?? item.speaker);
|
|
8258
|
+
if (role === null) return null;
|
|
8259
|
+
const id = numberId(item.id) ?? numberId(item.message_id) ?? fallbackId;
|
|
8260
|
+
const parent_id = numberId(item.parent_id) ?? numberId(item.parent_message_id) ?? null;
|
|
8261
|
+
const fragments = [];
|
|
8262
|
+
if (Array.isArray(item.fragments)) {
|
|
8263
|
+
for (const frag of item.fragments) {
|
|
8264
|
+
const parsed = parseWebChatFragment(frag);
|
|
8265
|
+
if (parsed !== void 0) fragments.push(parsed);
|
|
8266
|
+
}
|
|
8267
|
+
}
|
|
8268
|
+
if (fragments.length === 0) {
|
|
8269
|
+
const text3 = messageTextFallback(item);
|
|
8270
|
+
if (role === "USER") fragments.push({ type: "REQUEST", content: text3 });
|
|
8271
|
+
else fragments.push({ type: "RESPONSE", content: text3 });
|
|
8272
|
+
}
|
|
8273
|
+
return {
|
|
8274
|
+
id,
|
|
8275
|
+
parent_id,
|
|
8276
|
+
role,
|
|
8277
|
+
status: typeof item.status === "string" && item.status.trim() !== "" ? item.status.trim() : "FINISHED",
|
|
8278
|
+
inserted_at: typeof item.inserted_at === "string" ? item.inserted_at : void 0,
|
|
8279
|
+
fragments
|
|
8280
|
+
};
|
|
8281
|
+
}
|
|
8282
|
+
function previewTextFromFragments(fragments, role) {
|
|
8283
|
+
const prefer = role === "USER" ? "REQUEST" : "RESPONSE";
|
|
8284
|
+
const preferred = [];
|
|
7741
8285
|
for (const frag of fragments) {
|
|
7742
|
-
if (frag ===
|
|
7743
|
-
|
|
7744
|
-
const content = Reflect.get(frag, "content");
|
|
7745
|
-
if (typeof content !== "string" || content.trim() === "") continue;
|
|
7746
|
-
const text3 = content.trim();
|
|
7747
|
-
if (type === "THINK" || type === "TIP" || type.startsWith("TOOL_")) {
|
|
7748
|
-
if (preferred.size === 0) fallbackParts.push(text3);
|
|
7749
|
-
continue;
|
|
8286
|
+
if (frag.type === prefer && frag.content.trim() !== "") {
|
|
8287
|
+
preferred.push(frag.content.trim());
|
|
7750
8288
|
}
|
|
7751
|
-
if (preferred.size === 0 || preferred.has(type)) preferredParts.push(text3);
|
|
7752
|
-
else fallbackParts.push(text3);
|
|
7753
8289
|
}
|
|
7754
|
-
|
|
7755
|
-
|
|
8290
|
+
return preferred.join("\n\n");
|
|
8291
|
+
}
|
|
8292
|
+
function richMessagesToPreviewTurns(messages) {
|
|
8293
|
+
const turns = [];
|
|
8294
|
+
for (const message of messages) {
|
|
8295
|
+
const text3 = previewTextFromFragments(message.fragments, message.role);
|
|
8296
|
+
if (text3 === "") continue;
|
|
8297
|
+
turns.push({
|
|
8298
|
+
role: message.role === "USER" ? "user" : "assistant",
|
|
8299
|
+
text: text3
|
|
8300
|
+
});
|
|
8301
|
+
}
|
|
8302
|
+
return turns;
|
|
8303
|
+
}
|
|
8304
|
+
|
|
8305
|
+
// src/host/web-chat-bridge/share-link.ts
|
|
8306
|
+
var SHARE_URL_RE = /(?:https?:\/\/chat\.deepseek\.com)?\/share\/([A-Za-z0-9_-]+)/i;
|
|
8307
|
+
var SHARE_ID_RE = /^[A-Za-z0-9_-]{6,}$/;
|
|
8308
|
+
function extractWebChatShareId(raw) {
|
|
8309
|
+
const trimmed = raw.trim();
|
|
8310
|
+
if (trimmed === "") return null;
|
|
8311
|
+
const fromUrl = trimmed.match(SHARE_URL_RE);
|
|
8312
|
+
if (fromUrl?.[1]) return fromUrl[1];
|
|
8313
|
+
if (SHARE_ID_RE.test(trimmed)) return trimmed;
|
|
8314
|
+
return null;
|
|
8315
|
+
}
|
|
8316
|
+
function webChatSharePageUrl(shareId) {
|
|
8317
|
+
return `https://chat.deepseek.com/share/${shareId}`;
|
|
7756
8318
|
}
|
|
7757
|
-
function
|
|
7758
|
-
|
|
7759
|
-
|
|
7760
|
-
|
|
7761
|
-
return
|
|
8319
|
+
function webChatShareContentApiUrl(shareId) {
|
|
8320
|
+
return `https://chat.deepseek.com/api/v0/share/content?share_id=${encodeURIComponent(shareId)}`;
|
|
8321
|
+
}
|
|
8322
|
+
function utf8ByteLength(text3) {
|
|
8323
|
+
return new TextEncoder().encode(text3).length;
|
|
7762
8324
|
}
|
|
7763
8325
|
function assertTurns(turns) {
|
|
7764
8326
|
if (turns.length === 0) {
|
|
@@ -7769,12 +8331,28 @@ function assertTurns(turns) {
|
|
|
7769
8331
|
}
|
|
7770
8332
|
let bytes = 0;
|
|
7771
8333
|
for (const turn of turns) {
|
|
7772
|
-
bytes +=
|
|
8334
|
+
bytes += utf8ByteLength(turn.text);
|
|
7773
8335
|
if (bytes > WEB_CHAT_MAX_TEXT_BYTES) {
|
|
7774
8336
|
throw new Error(`Share content exceeds ${WEB_CHAT_MAX_TEXT_BYTES} byte limit`);
|
|
7775
8337
|
}
|
|
7776
8338
|
}
|
|
7777
8339
|
}
|
|
8340
|
+
function assertRichBudget(messages) {
|
|
8341
|
+
if (messages.length > WEB_CHAT_MAX_MESSAGES) {
|
|
8342
|
+
throw new Error(`Exceeds message limit (${WEB_CHAT_MAX_MESSAGES})`);
|
|
8343
|
+
}
|
|
8344
|
+
let bytes = 0;
|
|
8345
|
+
for (const message of messages) {
|
|
8346
|
+
for (const frag of message.fragments) {
|
|
8347
|
+
if ("content" in frag && typeof frag.content === "string") {
|
|
8348
|
+
bytes += utf8ByteLength(frag.content);
|
|
8349
|
+
}
|
|
8350
|
+
if (bytes > WEB_CHAT_MAX_TEXT_BYTES) {
|
|
8351
|
+
throw new Error(`Share content exceeds ${WEB_CHAT_MAX_TEXT_BYTES} byte limit`);
|
|
8352
|
+
}
|
|
8353
|
+
}
|
|
8354
|
+
}
|
|
8355
|
+
}
|
|
7778
8356
|
function bizRecord(data) {
|
|
7779
8357
|
if (data === null || typeof data !== "object") return null;
|
|
7780
8358
|
const root = data;
|
|
@@ -7789,42 +8367,63 @@ function bizRecord(data) {
|
|
|
7789
8367
|
if (biz !== null && typeof biz === "object") return biz;
|
|
7790
8368
|
return root;
|
|
7791
8369
|
}
|
|
7792
|
-
function
|
|
8370
|
+
function messagesFromBizRecord(record2) {
|
|
7793
8371
|
const rowsRaw = record2.messages ?? record2.chat_messages;
|
|
7794
8372
|
const rows = Array.isArray(rowsRaw) ? rowsRaw : [];
|
|
7795
|
-
const
|
|
7796
|
-
for (
|
|
7797
|
-
|
|
7798
|
-
|
|
7799
|
-
const role = normalizeRole2(item.role ?? item.author ?? item.speaker);
|
|
7800
|
-
if (!role) continue;
|
|
7801
|
-
const text3 = rowText(item, role);
|
|
7802
|
-
if (!text3) continue;
|
|
7803
|
-
turns.push({ role, text: text3 });
|
|
8373
|
+
const messages = [];
|
|
8374
|
+
for (let i = 0; i < rows.length; i++) {
|
|
8375
|
+
const parsed = parseWebChatRichMessage(rows[i], i + 1);
|
|
8376
|
+
if (parsed !== null) messages.push(parsed);
|
|
7804
8377
|
}
|
|
7805
|
-
return
|
|
8378
|
+
return messages;
|
|
7806
8379
|
}
|
|
7807
|
-
function
|
|
7808
|
-
|
|
7809
|
-
if (
|
|
7810
|
-
|
|
8380
|
+
function coerceMessageId(raw) {
|
|
8381
|
+
if (raw === null) return null;
|
|
8382
|
+
if (typeof raw === "number" && Number.isFinite(raw)) return Math.trunc(raw);
|
|
8383
|
+
if (typeof raw === "string" && raw.trim() !== "") {
|
|
8384
|
+
const parsed = Number(raw);
|
|
8385
|
+
if (Number.isFinite(parsed)) return Math.trunc(parsed);
|
|
7811
8386
|
}
|
|
7812
|
-
|
|
7813
|
-
|
|
7814
|
-
|
|
8387
|
+
return void 0;
|
|
8388
|
+
}
|
|
8389
|
+
function currentMessageIdOf(record2) {
|
|
8390
|
+
const fromRoot = coerceMessageId(record2.current_message_id);
|
|
8391
|
+
if (fromRoot !== void 0) return fromRoot;
|
|
8392
|
+
const session = Reflect.get(record2, "chat_session");
|
|
8393
|
+
if (session !== null && typeof session === "object") {
|
|
8394
|
+
return coerceMessageId(Reflect.get(session, "current_message_id"));
|
|
8395
|
+
}
|
|
8396
|
+
return void 0;
|
|
8397
|
+
}
|
|
8398
|
+
function transcriptFromBiz(record2, title, source) {
|
|
8399
|
+
const messages = messagesFromBizRecord(record2);
|
|
8400
|
+
assertRichBudget(messages);
|
|
8401
|
+
const turns = richMessagesToPreviewTurns(messages);
|
|
7815
8402
|
assertTurns(turns);
|
|
8403
|
+
const currentMessageId = currentMessageIdOf(record2);
|
|
7816
8404
|
return {
|
|
7817
8405
|
title,
|
|
7818
8406
|
turns,
|
|
8407
|
+
messages,
|
|
8408
|
+
...currentMessageId === void 0 ? {} : { currentMessageId },
|
|
7819
8409
|
partial: false,
|
|
7820
|
-
source
|
|
7821
|
-
kind: "share-link",
|
|
7822
|
-
url: options.shareUrl,
|
|
7823
|
-
chatSessionId: options.shareId,
|
|
7824
|
-
capturedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
7825
|
-
}
|
|
8410
|
+
source
|
|
7826
8411
|
};
|
|
7827
8412
|
}
|
|
8413
|
+
function parseWebChatShareContent(data, options) {
|
|
8414
|
+
const record2 = bizRecord(data);
|
|
8415
|
+
if (record2 === null) {
|
|
8416
|
+
throw new Error("unrecognized-share: empty response");
|
|
8417
|
+
}
|
|
8418
|
+
const titleRaw = record2.title;
|
|
8419
|
+
const title = typeof titleRaw === "string" && titleRaw.trim() !== "" ? titleRaw.trim() : `Shared chat ${options.shareId}`;
|
|
8420
|
+
return transcriptFromBiz(record2, title, {
|
|
8421
|
+
kind: "share-link",
|
|
8422
|
+
url: options.shareUrl,
|
|
8423
|
+
chatSessionId: options.shareId,
|
|
8424
|
+
capturedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
8425
|
+
});
|
|
8426
|
+
}
|
|
7828
8427
|
async function fetchWebChatShareContent(shareId, signal) {
|
|
7829
8428
|
signal.throwIfAborted();
|
|
7830
8429
|
const response = await fetch(webChatShareContentApiUrl(shareId), {
|
|
@@ -13561,7 +14160,7 @@ function mergeUsageCalls(stored, history) {
|
|
|
13561
14160
|
}
|
|
13562
14161
|
|
|
13563
14162
|
// src/host/usage/ledger.ts
|
|
13564
|
-
import { randomUUID as
|
|
14163
|
+
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
13565
14164
|
import { chmod as chmod4, mkdir as mkdir5, readFile as readFile5, rename as rename4, unlink as unlink5, writeFile as writeFile4 } from "node:fs/promises";
|
|
13566
14165
|
import { basename as basename14, join as join29 } from "node:path";
|
|
13567
14166
|
import { z as z3 } from "zod";
|
|
@@ -13593,7 +14192,7 @@ async function removeIfPresent5(path) {
|
|
|
13593
14192
|
}
|
|
13594
14193
|
}
|
|
13595
14194
|
async function writeAtomic4(path, value) {
|
|
13596
|
-
const temporary = join29(join29(path, ".."), `.${basename14(path)}.${
|
|
14195
|
+
const temporary = join29(join29(path, ".."), `.${basename14(path)}.${randomUUID8()}.tmp`);
|
|
13597
14196
|
try {
|
|
13598
14197
|
await writeFile4(temporary, JSON.stringify(value), { encoding: "utf8", mode: 384, flag: "wx" });
|
|
13599
14198
|
await rename4(temporary, path);
|
|
@@ -13718,11 +14317,6 @@ function installUsageObserver(ctx, recorder) {
|
|
|
13718
14317
|
// src/host/rpc.ts
|
|
13719
14318
|
import { createTypertRemoteInfo } from "@deepseek-ai/dsh-typert-protocol/remote-info";
|
|
13720
14319
|
import { z as z4 } from "zod";
|
|
13721
|
-
|
|
13722
|
-
// src/host/update/types.ts
|
|
13723
|
-
var APPLY_UPDATE_CODES = ["restart", "link", "manual", "none", "failed"];
|
|
13724
|
-
|
|
13725
|
-
// src/host/rpc.ts
|
|
13726
14320
|
var sessionIdSchema3 = z4.string().min(1).transform((value) => value);
|
|
13727
14321
|
var recentExchangeSchema = z4.strictObject({
|
|
13728
14322
|
turn: z4.number().int().nonnegative(),
|
|
@@ -13896,10 +14490,58 @@ var webChatTurnSchema = z4.strictObject({
|
|
|
13896
14490
|
role: z4.enum(["user", "assistant"]),
|
|
13897
14491
|
text: z4.string()
|
|
13898
14492
|
});
|
|
14493
|
+
var webChatSearchResultSchema = z4.strictObject({
|
|
14494
|
+
url: z4.string(),
|
|
14495
|
+
title: z4.string().nullable().optional(),
|
|
14496
|
+
snippet: z4.string().nullable().optional(),
|
|
14497
|
+
published_at: z4.string().nullable().optional()
|
|
14498
|
+
});
|
|
14499
|
+
var webChatFragmentSchema = z4.discriminatedUnion("type", [
|
|
14500
|
+
z4.strictObject({ type: z4.literal("REQUEST"), content: z4.string() }),
|
|
14501
|
+
z4.strictObject({ type: z4.literal("RESPONSE"), content: z4.string() }),
|
|
14502
|
+
z4.strictObject({
|
|
14503
|
+
type: z4.literal("THINK"),
|
|
14504
|
+
content: z4.string(),
|
|
14505
|
+
elapsed_secs: z4.number().nonnegative().nullable().optional()
|
|
14506
|
+
}),
|
|
14507
|
+
z4.strictObject({ type: z4.literal("TEMPLATE_RESPONSE"), content: z4.string() }),
|
|
14508
|
+
z4.strictObject({
|
|
14509
|
+
type: z4.literal("TOOL_SEARCH"),
|
|
14510
|
+
queries: z4.array(z4.string()),
|
|
14511
|
+
results: z4.array(webChatSearchResultSchema),
|
|
14512
|
+
status: z4.string().optional(),
|
|
14513
|
+
stage_id: z4.number().int().nullable().optional()
|
|
14514
|
+
}),
|
|
14515
|
+
z4.strictObject({
|
|
14516
|
+
type: z4.literal("TOOL_OPEN"),
|
|
14517
|
+
status: z4.string(),
|
|
14518
|
+
url: z4.string().nullable(),
|
|
14519
|
+
title: z4.string().nullable().optional(),
|
|
14520
|
+
stage_id: z4.number().int().nullable().optional()
|
|
14521
|
+
}),
|
|
14522
|
+
z4.strictObject({
|
|
14523
|
+
type: z4.literal("READ_LINK"),
|
|
14524
|
+
results: z4.array(z4.strictObject({
|
|
14525
|
+
url: z4.string().nullable().optional(),
|
|
14526
|
+
title: z4.string().nullable().optional()
|
|
14527
|
+
}))
|
|
14528
|
+
})
|
|
14529
|
+
]);
|
|
14530
|
+
var webChatRichMessageSchema = z4.strictObject({
|
|
14531
|
+
id: z4.number().int(),
|
|
14532
|
+
parent_id: z4.number().int().nullable(),
|
|
14533
|
+
role: z4.enum(["USER", "ASSISTANT"]),
|
|
14534
|
+
status: z4.string(),
|
|
14535
|
+
inserted_at: z4.string().optional(),
|
|
14536
|
+
fragments: z4.array(webChatFragmentSchema)
|
|
14537
|
+
});
|
|
13899
14538
|
var webChatTranscriptSchema = z4.strictObject({
|
|
13900
14539
|
title: z4.string(),
|
|
13901
14540
|
partial: z4.boolean(),
|
|
13902
14541
|
turns: z4.array(webChatTurnSchema).min(1),
|
|
14542
|
+
/** Share / history_messages tree for Session seed fidelity (optional for DOM capture). */
|
|
14543
|
+
messages: z4.array(webChatRichMessageSchema).optional(),
|
|
14544
|
+
currentMessageId: z4.number().int().nullable().optional(),
|
|
13903
14545
|
source: z4.strictObject({
|
|
13904
14546
|
kind: z4.enum(["rendered-capture", "official-export", "share-link", "account-history"]),
|
|
13905
14547
|
url: z4.string().optional(),
|
|
@@ -14157,21 +14799,6 @@ var listExtraFolderEntriesResultCodec = codec(
|
|
|
14157
14799
|
"dsh-agent-enhancer#ListExtraFolderEntriesResult",
|
|
14158
14800
|
listExtraFolderEntriesResultSchema
|
|
14159
14801
|
);
|
|
14160
|
-
var updateCheckResultSchema = z4.strictObject({
|
|
14161
|
-
current: z4.string(),
|
|
14162
|
-
latest: z4.string().nullable(),
|
|
14163
|
-
updateAvailable: z4.boolean(),
|
|
14164
|
-
installKind: z4.enum(["npm", "link", "unknown"]),
|
|
14165
|
-
canAutoApply: z4.boolean(),
|
|
14166
|
-
command: z4.string()
|
|
14167
|
-
});
|
|
14168
|
-
var applyUpdateResultSchema = z4.strictObject({
|
|
14169
|
-
ok: z4.boolean(),
|
|
14170
|
-
message: z4.enum(APPLY_UPDATE_CODES),
|
|
14171
|
-
command: z4.string().optional()
|
|
14172
|
-
});
|
|
14173
|
-
var updateCheckResultCodec = codec("dsh-agent-enhancer#UpdateCheckResult", updateCheckResultSchema);
|
|
14174
|
-
var applyUpdateResultCodec = codec("dsh-agent-enhancer#ApplyUpdateResult", applyUpdateResultSchema);
|
|
14175
14802
|
var usageTokenFields = {
|
|
14176
14803
|
inputTokens: z4.number().int().nonnegative(),
|
|
14177
14804
|
outputTokens: z4.number().int().nonnegative(),
|
|
@@ -15076,20 +15703,6 @@ var remoteInfo = createTypertRemoteInfo({
|
|
|
15076
15703
|
cancellation: { parameter: "signal" },
|
|
15077
15704
|
result: listExtraFolderEntriesResultCodec
|
|
15078
15705
|
},
|
|
15079
|
-
"agentEnhancer/checkUpdate": {
|
|
15080
|
-
service: "agentEnhancer",
|
|
15081
|
-
implementation: "checkUpdate",
|
|
15082
|
-
invocation: { kind: "direct" },
|
|
15083
|
-
parameters: [],
|
|
15084
|
-
result: updateCheckResultCodec
|
|
15085
|
-
},
|
|
15086
|
-
"agentEnhancer/applyUpdate": {
|
|
15087
|
-
service: "agentEnhancer",
|
|
15088
|
-
implementation: "applyUpdate",
|
|
15089
|
-
invocation: { kind: "direct" },
|
|
15090
|
-
parameters: [],
|
|
15091
|
-
result: applyUpdateResultCodec
|
|
15092
|
-
},
|
|
15093
15706
|
"agentEnhancer/usageSummary": {
|
|
15094
15707
|
service: "agentEnhancer",
|
|
15095
15708
|
implementation: "usageSummary",
|
|
@@ -15886,319 +16499,6 @@ async function showOsNotificationNow(input) {
|
|
|
15886
16499
|
return { shown: false, channel: "none" };
|
|
15887
16500
|
}
|
|
15888
16501
|
|
|
15889
|
-
// src/host/update/check.ts
|
|
15890
|
-
import { homedir as homedir6 } from "node:os";
|
|
15891
|
-
import { join as join31 } from "node:path";
|
|
15892
|
-
|
|
15893
|
-
// src/host/update/cli.ts
|
|
15894
|
-
import { spawn as nodeSpawn } from "node:child_process";
|
|
15895
|
-
import { existsSync as existsSync20 } from "node:fs";
|
|
15896
|
-
import { homedir as homedir5 } from "node:os";
|
|
15897
|
-
import { posix as pathPosix2 } from "node:path";
|
|
15898
|
-
function defaultSpawn(command, args, options) {
|
|
15899
|
-
return nodeSpawn(command, [...args], options ?? {});
|
|
15900
|
-
}
|
|
15901
|
-
var PROBE_TIMEOUT_MS = 5e3;
|
|
15902
|
-
var RUN_ADD_TIMEOUT_MS = 12e4;
|
|
15903
|
-
var STRICT_SEMVER = /^\d+\.\d+\.\d+$/;
|
|
15904
|
-
function isStrictVersion(value) {
|
|
15905
|
-
return STRICT_SEMVER.test(value);
|
|
15906
|
-
}
|
|
15907
|
-
function dshFromElectronExecPath(execPath) {
|
|
15908
|
-
const normalized = execPath.replace(/\\/g, "/");
|
|
15909
|
-
const marker = "/Contents/MacOS/";
|
|
15910
|
-
const idx = normalized.lastIndexOf(marker);
|
|
15911
|
-
if (idx < 0) return null;
|
|
15912
|
-
const contentsRoot = normalized.slice(0, idx + "/Contents".length);
|
|
15913
|
-
return pathPosix2.join(contentsRoot, "Resources", "runtime", "cli", "bin", "dsh");
|
|
15914
|
-
}
|
|
15915
|
-
function dshExecutableCandidates(options = {}) {
|
|
15916
|
-
const platform = options.platform ?? process.platform;
|
|
15917
|
-
const env = options.env ?? process.env;
|
|
15918
|
-
const home = options.home ?? env.HOME?.trim() ?? homedir5();
|
|
15919
|
-
const execPath = options.execPath ?? process.execPath;
|
|
15920
|
-
const out = [];
|
|
15921
|
-
const push = (value) => {
|
|
15922
|
-
const trimmed = typeof value === "string" ? value.trim() : "";
|
|
15923
|
-
if (trimmed === "" || out.includes(trimmed)) return;
|
|
15924
|
-
out.push(trimmed);
|
|
15925
|
-
};
|
|
15926
|
-
push(env.DSH_CLI);
|
|
15927
|
-
if (platform === "darwin") {
|
|
15928
|
-
push(dshFromElectronExecPath(execPath));
|
|
15929
|
-
push("/Applications/DeepSeek Harness.app/Contents/Resources/runtime/cli/bin/dsh");
|
|
15930
|
-
push(pathPosix2.join(
|
|
15931
|
-
home,
|
|
15932
|
-
"Applications/DeepSeek Harness.app/Contents/Resources/runtime/cli/bin/dsh"
|
|
15933
|
-
));
|
|
15934
|
-
}
|
|
15935
|
-
push("dsh");
|
|
15936
|
-
return out;
|
|
15937
|
-
}
|
|
15938
|
-
function isCommandMissingDetail(detail) {
|
|
15939
|
-
return /ENOENT|not found|spawn .*(ENOENT|not found)/i.test(detail);
|
|
15940
|
-
}
|
|
15941
|
-
function dshSpawnOptions() {
|
|
15942
|
-
const base = { stdio: ["ignore", "pipe", "pipe"] };
|
|
15943
|
-
return process.platform === "win32" ? { ...base, shell: true, windowsHide: true } : base;
|
|
15944
|
-
}
|
|
15945
|
-
function pluginAddArgs(latest) {
|
|
15946
|
-
return ["plugin", "--profile", "desktop", "add", `${PACKAGE_NAME}@${latest}`];
|
|
15947
|
-
}
|
|
15948
|
-
function pluginAddCommand(latest) {
|
|
15949
|
-
return `dsh plugin --profile desktop add ${PACKAGE_NAME}@${latest}`;
|
|
15950
|
-
}
|
|
15951
|
-
function resolveCanAutoApply(input) {
|
|
15952
|
-
return input.installKind === "npm" && input.dshAvailable;
|
|
15953
|
-
}
|
|
15954
|
-
function waitForExit(child, timeoutMs) {
|
|
15955
|
-
return new Promise((resolve17) => {
|
|
15956
|
-
let settled = false;
|
|
15957
|
-
const chunks = [];
|
|
15958
|
-
const finish = (ok, detail) => {
|
|
15959
|
-
if (settled) return;
|
|
15960
|
-
settled = true;
|
|
15961
|
-
clearTimeout(timer);
|
|
15962
|
-
resolve17({ ok, detail });
|
|
15963
|
-
};
|
|
15964
|
-
const timer = setTimeout(() => {
|
|
15965
|
-
child.kill();
|
|
15966
|
-
finish(false, "timeout");
|
|
15967
|
-
}, timeoutMs);
|
|
15968
|
-
child.stdout?.on("data", (chunk) => chunks.push(chunk));
|
|
15969
|
-
child.stderr?.on("data", (chunk) => chunks.push(chunk));
|
|
15970
|
-
child.on("error", (err) => {
|
|
15971
|
-
finish(false, err.message);
|
|
15972
|
-
});
|
|
15973
|
-
child.on("close", (code) => {
|
|
15974
|
-
const detail = Buffer.concat(chunks).toString("utf8").trim();
|
|
15975
|
-
finish(code === 0, detail);
|
|
15976
|
-
});
|
|
15977
|
-
});
|
|
15978
|
-
}
|
|
15979
|
-
async function runDshOnce(command, args, spawnFn, timeoutMs) {
|
|
15980
|
-
let child;
|
|
15981
|
-
try {
|
|
15982
|
-
child = spawnFn(command, args, dshSpawnOptions());
|
|
15983
|
-
} catch (err) {
|
|
15984
|
-
return { ok: false, detail: err instanceof Error ? err.message : String(err) };
|
|
15985
|
-
}
|
|
15986
|
-
return waitForExit(child, timeoutMs);
|
|
15987
|
-
}
|
|
15988
|
-
async function runDsh(args, spawnFn, timeoutMs, options = {}) {
|
|
15989
|
-
const candidates = options.candidates ?? dshExecutableCandidates();
|
|
15990
|
-
const exists = options.exists ?? existsSync20;
|
|
15991
|
-
let last = { ok: false, detail: "dsh not found" };
|
|
15992
|
-
for (const command of candidates) {
|
|
15993
|
-
if (command !== "dsh" && !exists(command)) continue;
|
|
15994
|
-
const result = await runDshOnce(command, args, spawnFn, timeoutMs);
|
|
15995
|
-
if (result.ok) return result;
|
|
15996
|
-
last = result;
|
|
15997
|
-
if (!isCommandMissingDetail(result.detail)) return result;
|
|
15998
|
-
}
|
|
15999
|
-
return last;
|
|
16000
|
-
}
|
|
16001
|
-
async function probeDsh(spawnFn = defaultSpawn, options = {}) {
|
|
16002
|
-
const result = await runDsh(["--version"], spawnFn, PROBE_TIMEOUT_MS, options);
|
|
16003
|
-
return result.ok;
|
|
16004
|
-
}
|
|
16005
|
-
async function runPluginAdd(latest, spawnFn = defaultSpawn, options = {}) {
|
|
16006
|
-
if (!isStrictVersion(latest)) return { ok: false, detail: "invalid version" };
|
|
16007
|
-
return runDsh(pluginAddArgs(latest), spawnFn, RUN_ADD_TIMEOUT_MS, options);
|
|
16008
|
-
}
|
|
16009
|
-
|
|
16010
|
-
// src/host/update/install-kind.ts
|
|
16011
|
-
import { lstatSync as lstatSync5 } from "node:fs";
|
|
16012
|
-
import { join as join30 } from "node:path";
|
|
16013
|
-
function detectInstallKind(profileDir) {
|
|
16014
|
-
const pkgPath = join30(profileDir, "node_modules", PACKAGE_NAME);
|
|
16015
|
-
try {
|
|
16016
|
-
const stat = lstatSync5(pkgPath);
|
|
16017
|
-
if (stat.isSymbolicLink()) return "link";
|
|
16018
|
-
if (stat.isDirectory()) return "npm";
|
|
16019
|
-
return "unknown";
|
|
16020
|
-
} catch {
|
|
16021
|
-
return "unknown";
|
|
16022
|
-
}
|
|
16023
|
-
}
|
|
16024
|
-
|
|
16025
|
-
// src/host/update/registry.ts
|
|
16026
|
-
function defaultSources() {
|
|
16027
|
-
return [
|
|
16028
|
-
{ kind: "npm-dist-tag", baseUrl: "https://registry.npmjs.org" },
|
|
16029
|
-
// CDN package.json is reliable when the npm registry is unreachable.
|
|
16030
|
-
{
|
|
16031
|
-
kind: "package-json",
|
|
16032
|
-
url: `https://cdn.jsdelivr.net/npm/${encodeURIComponent(PACKAGE_NAME)}/package.json`
|
|
16033
|
-
},
|
|
16034
|
-
// Mainland mirror last — some packages publish a misleading `latest` tag there.
|
|
16035
|
-
{ kind: "npm-dist-tag", baseUrl: "https://registry.npmmirror.com" }
|
|
16036
|
-
];
|
|
16037
|
-
}
|
|
16038
|
-
function isUsableReleaseVersion(value) {
|
|
16039
|
-
return /^\d+\.\d+\.\d+$/.test(value);
|
|
16040
|
-
}
|
|
16041
|
-
function abortSignal(timeoutMs) {
|
|
16042
|
-
try {
|
|
16043
|
-
return AbortSignal.timeout(timeoutMs);
|
|
16044
|
-
} catch {
|
|
16045
|
-
return void 0;
|
|
16046
|
-
}
|
|
16047
|
-
}
|
|
16048
|
-
function readDistTagLatest(body) {
|
|
16049
|
-
if (body === null || typeof body !== "object") return null;
|
|
16050
|
-
const distTags = body["dist-tags"];
|
|
16051
|
-
if (distTags === null || typeof distTags !== "object") return null;
|
|
16052
|
-
const latest = distTags.latest;
|
|
16053
|
-
if (typeof latest !== "string" || !isUsableReleaseVersion(latest)) return null;
|
|
16054
|
-
return latest;
|
|
16055
|
-
}
|
|
16056
|
-
function readPackageJsonVersion(body) {
|
|
16057
|
-
if (body === null || typeof body !== "object") return null;
|
|
16058
|
-
const version = body.version;
|
|
16059
|
-
if (typeof version !== "string" || !isUsableReleaseVersion(version)) return null;
|
|
16060
|
-
return version;
|
|
16061
|
-
}
|
|
16062
|
-
async function fetchJson(fetchImpl, url, currentVersion, timeoutMs) {
|
|
16063
|
-
try {
|
|
16064
|
-
const response = await fetchImpl(url, {
|
|
16065
|
-
signal: abortSignal(timeoutMs),
|
|
16066
|
-
headers: {
|
|
16067
|
-
Accept: "application/json",
|
|
16068
|
-
"User-Agent": `dsh-agent-enhancer/${currentVersion}`
|
|
16069
|
-
}
|
|
16070
|
-
});
|
|
16071
|
-
if (!response.ok) {
|
|
16072
|
-
console.error(`agent-enhancer update: registry ${url} returned ${response.status}`);
|
|
16073
|
-
return null;
|
|
16074
|
-
}
|
|
16075
|
-
return await response.json();
|
|
16076
|
-
} catch (error) {
|
|
16077
|
-
console.error(`agent-enhancer update: registry fetch failed for ${url}`, error);
|
|
16078
|
-
return null;
|
|
16079
|
-
}
|
|
16080
|
-
}
|
|
16081
|
-
async function fetchLatestVersion(packageName, opts = {}) {
|
|
16082
|
-
const fetchImpl = opts.fetch ?? globalThis.fetch;
|
|
16083
|
-
const currentVersion = opts.currentVersion ?? PACKAGE_VERSION;
|
|
16084
|
-
const timeoutMs = opts.timeoutMs ?? 12e3;
|
|
16085
|
-
const sources = opts.sources ?? defaultSources();
|
|
16086
|
-
for (const source of sources) {
|
|
16087
|
-
switch (source.kind) {
|
|
16088
|
-
case "npm-dist-tag": {
|
|
16089
|
-
const url = `${source.baseUrl.replace(/\/$/, "")}/${encodeURIComponent(packageName)}`;
|
|
16090
|
-
const body = await fetchJson(fetchImpl, url, currentVersion, timeoutMs);
|
|
16091
|
-
const latest = readDistTagLatest(body);
|
|
16092
|
-
if (latest !== null) return latest;
|
|
16093
|
-
break;
|
|
16094
|
-
}
|
|
16095
|
-
case "package-json": {
|
|
16096
|
-
const body = await fetchJson(fetchImpl, source.url, currentVersion, timeoutMs);
|
|
16097
|
-
const version = readPackageJsonVersion(body);
|
|
16098
|
-
if (version !== null) return version;
|
|
16099
|
-
break;
|
|
16100
|
-
}
|
|
16101
|
-
default: {
|
|
16102
|
-
const _exhaustive = source;
|
|
16103
|
-
return _exhaustive;
|
|
16104
|
-
}
|
|
16105
|
-
}
|
|
16106
|
-
}
|
|
16107
|
-
return null;
|
|
16108
|
-
}
|
|
16109
|
-
|
|
16110
|
-
// src/host/update/semver.ts
|
|
16111
|
-
function parseSemver(version) {
|
|
16112
|
-
const trimmed = version.startsWith("v") ? version.slice(1) : version;
|
|
16113
|
-
const parts = trimmed.split(".");
|
|
16114
|
-
if (parts.length !== 3) {
|
|
16115
|
-
return null;
|
|
16116
|
-
}
|
|
16117
|
-
const nums = [];
|
|
16118
|
-
for (const part of parts) {
|
|
16119
|
-
if (!/^\d+$/.test(part)) {
|
|
16120
|
-
return null;
|
|
16121
|
-
}
|
|
16122
|
-
nums.push(Number(part));
|
|
16123
|
-
}
|
|
16124
|
-
return nums;
|
|
16125
|
-
}
|
|
16126
|
-
function isNewerVersion(latest, current) {
|
|
16127
|
-
const latestParts = parseSemver(latest);
|
|
16128
|
-
const currentParts = parseSemver(current);
|
|
16129
|
-
if (latestParts === null || currentParts === null) {
|
|
16130
|
-
return false;
|
|
16131
|
-
}
|
|
16132
|
-
const [lMajor, lMinor, lPatch] = latestParts;
|
|
16133
|
-
const [cMajor, cMinor, cPatch] = currentParts;
|
|
16134
|
-
if (lMajor !== cMajor) {
|
|
16135
|
-
return lMajor > cMajor;
|
|
16136
|
-
}
|
|
16137
|
-
if (lMinor !== cMinor) {
|
|
16138
|
-
return lMinor > cMinor;
|
|
16139
|
-
}
|
|
16140
|
-
return lPatch > cPatch;
|
|
16141
|
-
}
|
|
16142
|
-
|
|
16143
|
-
// src/host/update/check.ts
|
|
16144
|
-
function resolveDesktopProfileDir(env = process.env, home = homedir6()) {
|
|
16145
|
-
const dshHome2 = env.DSH_HOME ?? join31(home, ".dsh");
|
|
16146
|
-
return join31(dshHome2, "profiles", "desktop");
|
|
16147
|
-
}
|
|
16148
|
-
async function checkPluginUpdate(deps) {
|
|
16149
|
-
const latest = await deps.fetchLatest();
|
|
16150
|
-
const installKind = deps.detectKind(deps.profileDir);
|
|
16151
|
-
const dshAvailable = await deps.dshAvailable().catch(() => false);
|
|
16152
|
-
const updateAvailable = latest !== null && isNewerVersion(latest, deps.currentVersion);
|
|
16153
|
-
const command = pluginAddCommand(latest ?? "latest");
|
|
16154
|
-
const canAutoApply = resolveCanAutoApply({ installKind, dshAvailable });
|
|
16155
|
-
return {
|
|
16156
|
-
current: deps.currentVersion,
|
|
16157
|
-
latest,
|
|
16158
|
-
updateAvailable,
|
|
16159
|
-
installKind,
|
|
16160
|
-
canAutoApply,
|
|
16161
|
-
command
|
|
16162
|
-
};
|
|
16163
|
-
}
|
|
16164
|
-
async function applyPluginUpdate(input) {
|
|
16165
|
-
const { check, runAdd, messages } = input;
|
|
16166
|
-
if (check.latest === null || !check.updateAvailable) {
|
|
16167
|
-
return { ok: false, message: messages.noUpdate, command: check.command };
|
|
16168
|
-
}
|
|
16169
|
-
if (!check.canAutoApply) {
|
|
16170
|
-
const message = check.installKind === "link" ? messages.linkBlocked : messages.manualOnly ?? messages.failed;
|
|
16171
|
-
return { ok: false, message, command: check.command };
|
|
16172
|
-
}
|
|
16173
|
-
const result = await runAdd(check.latest);
|
|
16174
|
-
if (!result.ok) {
|
|
16175
|
-
return { ok: false, message: messages.failed, command: check.command };
|
|
16176
|
-
}
|
|
16177
|
-
return { ok: true, message: messages.success };
|
|
16178
|
-
}
|
|
16179
|
-
function defaultCheckDeps(overrides = {}) {
|
|
16180
|
-
const profileDir = overrides.profileDir ?? resolveDesktopProfileDir();
|
|
16181
|
-
return {
|
|
16182
|
-
currentVersion: PACKAGE_VERSION,
|
|
16183
|
-
fetchLatest: () => fetchLatestVersion(PACKAGE_NAME),
|
|
16184
|
-
detectKind: (dir) => detectInstallKind(dir),
|
|
16185
|
-
dshAvailable: () => probeDsh(),
|
|
16186
|
-
profileDir,
|
|
16187
|
-
...overrides
|
|
16188
|
-
};
|
|
16189
|
-
}
|
|
16190
|
-
async function checkPluginUpdateForHost(overrides) {
|
|
16191
|
-
return checkPluginUpdate(defaultCheckDeps(overrides));
|
|
16192
|
-
}
|
|
16193
|
-
async function applyPluginUpdateForHost(messages, overrides) {
|
|
16194
|
-
const check = await checkPluginUpdate(defaultCheckDeps(overrides));
|
|
16195
|
-
return applyPluginUpdate({
|
|
16196
|
-
check,
|
|
16197
|
-
runAdd: (latest) => runPluginAdd(latest),
|
|
16198
|
-
messages
|
|
16199
|
-
});
|
|
16200
|
-
}
|
|
16201
|
-
|
|
16202
16502
|
// src/host/index.ts
|
|
16203
16503
|
function hostBrowserPreference(value) {
|
|
16204
16504
|
return coerceBrowserAgentBrowserForPlatform(
|
|
@@ -16289,12 +16589,12 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
16289
16589
|
};
|
|
16290
16590
|
}
|
|
16291
16591
|
}, sessionCleanup = new SessionCleanupRegistry(), extraFolders = createExtraFoldersStore(
|
|
16292
|
-
|
|
16592
|
+
join30(homedir5(), ".dsh", "profiles", "desktop", "plugin-data", PACKAGE_NAME, "extra-folders")
|
|
16293
16593
|
), softPause = new SoftPauseGate(), softPauseEnabled = () => true, installLedgerRoot = void 0, mcpHost = null, browserAgent = null, browserAgentSettings = () => ({
|
|
16294
16594
|
enabled: false,
|
|
16295
16595
|
browser: "auto"
|
|
16296
16596
|
}), setBrowserAgentBrowser = () => void 0, browserAgentProfileDir = defaultBrowserAgentProfileDir(
|
|
16297
|
-
|
|
16597
|
+
join30(homedir5(), ".dsh", "profiles", "desktop", "plugin-data", PACKAGE_NAME)
|
|
16298
16598
|
)) {
|
|
16299
16599
|
super(ctx, "agentEnhancer");
|
|
16300
16600
|
this.models = models;
|
|
@@ -16544,7 +16844,7 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
16544
16844
|
}
|
|
16545
16845
|
}
|
|
16546
16846
|
webChatPluginDataRoot() {
|
|
16547
|
-
return this.installLedgerRoot ??
|
|
16847
|
+
return this.installLedgerRoot ?? join30(homedir5(), ".dsh", "profiles", "desktop", "plugin-data", PACKAGE_NAME);
|
|
16548
16848
|
}
|
|
16549
16849
|
/** User-level web chat guest login snapshot (non-HttpOnly storage only). */
|
|
16550
16850
|
async loadWebChatLoginSnapshot(_request, signal) {
|
|
@@ -16696,10 +16996,6 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
16696
16996
|
throw new RemoteError2("agent-enhancer/failed", detail || "Context compaction failed", { code });
|
|
16697
16997
|
}
|
|
16698
16998
|
}
|
|
16699
|
-
/** Read-only version probe — same gate policy as `listCatalog` (settings-safe). */
|
|
16700
|
-
async checkUpdate() {
|
|
16701
|
-
return checkPluginUpdateForHost();
|
|
16702
|
-
}
|
|
16703
16999
|
async usageSummary(range) {
|
|
16704
17000
|
this.assertOwner();
|
|
16705
17001
|
return this.usage.summarize(range);
|
|
@@ -17068,28 +17364,18 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
17068
17364
|
snapshot: await this.browserSnapshotNow()
|
|
17069
17365
|
};
|
|
17070
17366
|
}
|
|
17071
|
-
async applyUpdate() {
|
|
17072
|
-
this.assertOwner();
|
|
17073
|
-
return applyPluginUpdateForHost({
|
|
17074
|
-
linkBlocked: "link",
|
|
17075
|
-
success: "restart",
|
|
17076
|
-
failed: "failed",
|
|
17077
|
-
noUpdate: "none",
|
|
17078
|
-
manualOnly: "manual"
|
|
17079
|
-
});
|
|
17080
|
-
}
|
|
17081
17367
|
};
|
|
17082
17368
|
function resolveCheckpointRoot(dshHome2) {
|
|
17083
|
-
const base =
|
|
17084
|
-
const nextPkg =
|
|
17085
|
-
const next =
|
|
17086
|
-
const prev =
|
|
17087
|
-
if (!
|
|
17369
|
+
const base = join30(dshHome2, "profiles", "desktop", "plugin-data");
|
|
17370
|
+
const nextPkg = join30(base, PACKAGE_NAME);
|
|
17371
|
+
const next = join30(nextPkg, "checkpoint");
|
|
17372
|
+
const prev = join30(base, LEGACY_PACKAGE_NAME, "checkpoint");
|
|
17373
|
+
if (!existsSync20(next) && existsSync20(prev)) {
|
|
17088
17374
|
mkdirSync12(nextPkg, { recursive: true });
|
|
17089
17375
|
renameSync9(prev, next);
|
|
17090
|
-
const prevPkg =
|
|
17376
|
+
const prevPkg = join30(base, LEGACY_PACKAGE_NAME);
|
|
17091
17377
|
try {
|
|
17092
|
-
if (
|
|
17378
|
+
if (existsSync20(prevPkg) && readdirSync7(prevPkg).length === 0) rmdirSync(prevPkg);
|
|
17093
17379
|
} catch {
|
|
17094
17380
|
}
|
|
17095
17381
|
}
|
|
@@ -17192,9 +17478,9 @@ function apply(ctx, config) {
|
|
|
17192
17478
|
const settings = () => readSettings(config);
|
|
17193
17479
|
const models = new AuxiliaryModels(ctx, settings);
|
|
17194
17480
|
installAutoSessionRoute(ctx, { settings });
|
|
17195
|
-
const storageRoot = resolveCheckpointRoot(process.env.DSH_HOME ??
|
|
17196
|
-
const pluginDataPackageRoot =
|
|
17197
|
-
const usage = new UsageLedger(
|
|
17481
|
+
const storageRoot = resolveCheckpointRoot(process.env.DSH_HOME ?? join30(homedir5(), ".dsh"));
|
|
17482
|
+
const pluginDataPackageRoot = join30(storageRoot, "..");
|
|
17483
|
+
const usage = new UsageLedger(join30(storageRoot, "..", "usage"), (message) => {
|
|
17198
17484
|
ctx.logger.warn(message);
|
|
17199
17485
|
});
|
|
17200
17486
|
const balancesFacade = (() => {
|
|
@@ -17224,12 +17510,12 @@ function apply(ctx, config) {
|
|
|
17224
17510
|
})();
|
|
17225
17511
|
installUsageObserver(ctx, usage);
|
|
17226
17512
|
const store = new CheckpointStore(storageRoot);
|
|
17227
|
-
const cutStore = new SessionCutStore(
|
|
17513
|
+
const cutStore = new SessionCutStore(join30(storageRoot, "cuts"));
|
|
17228
17514
|
const cutCache = /* @__PURE__ */ new Map();
|
|
17229
17515
|
const sessionCleanup = new SessionCleanupRegistry();
|
|
17230
17516
|
sessionCleanup.register(createCheckpointCleaner({ store, cutStore, storageRoot }));
|
|
17231
|
-
sessionCleanup.register(createContextExcludeCleaner(
|
|
17232
|
-
const extraFoldersStore = createExtraFoldersStore(
|
|
17517
|
+
sessionCleanup.register(createContextExcludeCleaner(join30(storageRoot, "..")));
|
|
17518
|
+
const extraFoldersStore = createExtraFoldersStore(join30(storageRoot, "..", "extra-folders"));
|
|
17233
17519
|
const softPauseGate = new SoftPauseGate();
|
|
17234
17520
|
const mcpStore = createMcpConnectorsStore(mcpConnectorsRoot(pluginDataPackageRoot));
|
|
17235
17521
|
const mcpRuntime = new McpConnectorRuntime(ctx, mcpStore);
|