@leviyuan/lodestar 0.22.3 → 0.23.1
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/dsh-bridge.js +2 -468
- package/dist/lodestar-agent.js +3 -42
- package/dist/lodestar-claude.js +3 -23
- package/dist/lodestar-setup.js +3 -49
- package/dist/lodestar-stop.js +2 -3
- package/dist/lodestar-update.js +3 -41
- package/dist/lodestar-version.js +3 -17
- package/dist/lodestar.js +3 -666
- package/docs/models.md +2 -2
- package/docs/release.md +1 -0
- package/docs/usage.md +6 -4
- package/package.json +5 -3
package/dist/dsh-bridge.js
CHANGED
|
@@ -1,468 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { createInterface } from "node:readline";
|
|
3
|
-
import { randomUUID } from "node:crypto";
|
|
4
|
-
import { createRequire } from "node:module";
|
|
5
|
-
import { readFileSync } from "node:fs";
|
|
6
|
-
import { realpath } from "node:fs/promises";
|
|
7
|
-
import { createUserMessage, ReasoningEffortId } from "@deepseek-ai/dsh-llm";
|
|
8
|
-
import { SessionLogOffset } from "@deepseek-ai/dsh-session";
|
|
9
|
-
|
|
10
|
-
// src/dsh-protocol.ts
|
|
11
|
-
var DSH_PROTOCOL_VERSION = 1;
|
|
12
|
-
|
|
13
|
-
// src/dsh-bridge.ts
|
|
14
|
-
var name = "lodestar-bridge";
|
|
15
|
-
var inject = ["agents", "llm", "agentDefaultModel", "sessionPersistence", "tools", "systemPrompt", "userQuestions", "compaction", "shellEnv", "attachments", "sdkAppStartup"];
|
|
16
|
-
var PROVIDER = process.env.LODESTAR_DSH_PROVIDER ?? "deepseek-official";
|
|
17
|
-
if (!["deepseek-official", "zai-coding-cn", "zai", "openai-relay"].includes(PROVIDER))
|
|
18
|
-
throw new Error(`Unsupported DSH provider: ${PROVIDER}`);
|
|
19
|
-
function nativeErrorMessage(error, depth = 0) {
|
|
20
|
-
if (!(error instanceof Error))
|
|
21
|
-
return String(error);
|
|
22
|
-
return error.cause && depth < 4 ? `${error.message}: ${nativeErrorMessage(error.cause, depth + 1)}` : error.message;
|
|
23
|
-
}
|
|
24
|
-
function apply(ctx) {
|
|
25
|
-
let root;
|
|
26
|
-
let rootId;
|
|
27
|
-
let initialized = false;
|
|
28
|
-
let closing = false;
|
|
29
|
-
const lifecycle = new AbortController;
|
|
30
|
-
let opening;
|
|
31
|
-
let selected;
|
|
32
|
-
let turnRoute;
|
|
33
|
-
let lastEnd;
|
|
34
|
-
let activeTurn = 0;
|
|
35
|
-
let turnFailure;
|
|
36
|
-
let settledSeq = -1;
|
|
37
|
-
let settling;
|
|
38
|
-
let inputGeneration = 0;
|
|
39
|
-
const steeringInputs = new Map;
|
|
40
|
-
const questions = new Map;
|
|
41
|
-
const notify = (method, params) => {
|
|
42
|
-
process.stdout.write(JSON.stringify({ jsonrpc: "2.0", method, params }) + `
|
|
43
|
-
`);
|
|
44
|
-
};
|
|
45
|
-
const fail = (error) => {
|
|
46
|
-
const message = nativeErrorMessage(error);
|
|
47
|
-
process.stderr.write(`lodestar-dsh: runtime failure
|
|
48
|
-
`);
|
|
49
|
-
notify("failure", { message });
|
|
50
|
-
};
|
|
51
|
-
const live = () => {
|
|
52
|
-
if (!root || closing)
|
|
53
|
-
throw new Error("DSH session is not open");
|
|
54
|
-
return root.agent;
|
|
55
|
-
};
|
|
56
|
-
const delegationContext = process.env.DSH_LODESTAR_AGENT_CONTEXT;
|
|
57
|
-
delete process.env.DSH_LODESTAR_AGENT_CONTEXT;
|
|
58
|
-
ctx.shellEnv.register({
|
|
59
|
-
name: "lodestar-agent",
|
|
60
|
-
variables: { DSH_LODESTAR_AGENT_CONTEXT: { description: "Inherited Lodestar task context for this agent and its native descendants." } },
|
|
61
|
-
resolve: () => delegationContext ? { DSH_LODESTAR_AGENT_CONTEXT: delegationContext } : {}
|
|
62
|
-
});
|
|
63
|
-
const settle = () => {
|
|
64
|
-
if (root?.agent.status === "idle" && turnFailure && lastEnd?.data.turn !== activeTurn) {
|
|
65
|
-
const message = turnFailure;
|
|
66
|
-
turnFailure = undefined;
|
|
67
|
-
fail(new Error(`DSH turn could not be committed: ${message}`));
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (settling || !lastEnd || !root || root.agent.status !== "idle" || lastEnd.seq <= settledSeq)
|
|
71
|
-
return;
|
|
72
|
-
const end = lastEnd;
|
|
73
|
-
for (const messageId of steeringInputs.keys())
|
|
74
|
-
root.agent.inbox.remove(messageId);
|
|
75
|
-
steeringInputs.clear();
|
|
76
|
-
settling = ctx.sessionPersistence.flush().then(() => {
|
|
77
|
-
settledSeq = end.seq;
|
|
78
|
-
if (root?.agent.status !== "idle" || lastEnd !== end || activeTurn !== end.data.turn)
|
|
79
|
-
return;
|
|
80
|
-
notify("settled", { sessionId: rootId, event: end });
|
|
81
|
-
}).catch((error) => {
|
|
82
|
-
settledSeq = end.seq;
|
|
83
|
-
fail(error);
|
|
84
|
-
}).finally(() => {
|
|
85
|
-
settling = undefined;
|
|
86
|
-
settle();
|
|
87
|
-
});
|
|
88
|
-
};
|
|
89
|
-
ctx.on("session/event", (session, event) => {
|
|
90
|
-
const inputId = session.id === rootId && event.type === "user/message" ? steeringInputs.get(event.data.id) : undefined;
|
|
91
|
-
if (inputId && event.type === "user/message")
|
|
92
|
-
steeringInputs.delete(event.data.id);
|
|
93
|
-
notify("session.event", { sessionId: session.id, event, ...inputId ? { inputId } : {} });
|
|
94
|
-
if (session.id === rootId && event.type === "turn/start") {
|
|
95
|
-
turnRoute = selected;
|
|
96
|
-
if (root)
|
|
97
|
-
Object.assign(root.agent.options, selected);
|
|
98
|
-
activeTurn = event.data.turn;
|
|
99
|
-
turnFailure = undefined;
|
|
100
|
-
}
|
|
101
|
-
if (session.id === rootId && event.type === "turn/end") {
|
|
102
|
-
lastEnd = event;
|
|
103
|
-
queueMicrotask(settle);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
ctx.on("agent/assistant-stream", ({ agent, frame }) => {
|
|
107
|
-
notify("assistant.frame", { sessionId: agent.session.id, frame });
|
|
108
|
-
});
|
|
109
|
-
ctx.on("agent/status", ({ agent, status }) => {
|
|
110
|
-
notify("session.status", { sessionId: agent.session.id, status });
|
|
111
|
-
if (agent.session.id === rootId && status === "idle")
|
|
112
|
-
settle();
|
|
113
|
-
});
|
|
114
|
-
ctx.on("agent/error", ({ agent, error }) => {
|
|
115
|
-
const message = nativeErrorMessage(error);
|
|
116
|
-
process.stderr.write(`lodestar-dsh: agent failure
|
|
117
|
-
`);
|
|
118
|
-
if (agent.session.id === rootId)
|
|
119
|
-
turnFailure = message;
|
|
120
|
-
notify("agent.error", { sessionId: agent.session.id, message });
|
|
121
|
-
});
|
|
122
|
-
ctx.on("agent/created", ({ agent }) => {
|
|
123
|
-
if (agent.session.id === rootId)
|
|
124
|
-
return;
|
|
125
|
-
notify("subagent.started", { sessionId: agent.session.id, parentSessionId: agent.session.header.parentSession });
|
|
126
|
-
});
|
|
127
|
-
ctx.on("agent/disposed", ({ agent }) => {
|
|
128
|
-
if (agent.session.id !== rootId)
|
|
129
|
-
notify("subagent.disposed", { sessionId: agent.session.id });
|
|
130
|
-
});
|
|
131
|
-
ctx.on("approval/request", async () => "allowed-once");
|
|
132
|
-
ctx.on("user-questions/request", (request) => {
|
|
133
|
-
if (request.agent !== root?.agent || closing)
|
|
134
|
-
throw new Error("DSH question is not owned by this session");
|
|
135
|
-
const id = randomUUID();
|
|
136
|
-
return new Promise((resolve, reject) => {
|
|
137
|
-
const abort = () => {
|
|
138
|
-
questions.delete(id);
|
|
139
|
-
notify("question.cancelled", { id });
|
|
140
|
-
reject(new Error("DSH question cancelled"));
|
|
141
|
-
};
|
|
142
|
-
if (request.signal?.aborted)
|
|
143
|
-
return abort();
|
|
144
|
-
questions.set(id, {
|
|
145
|
-
resolve: (answer) => {
|
|
146
|
-
request.signal?.removeEventListener("abort", abort);
|
|
147
|
-
resolve(answer);
|
|
148
|
-
},
|
|
149
|
-
reject: (error) => {
|
|
150
|
-
request.signal?.removeEventListener("abort", abort);
|
|
151
|
-
reject(error);
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
request.signal?.addEventListener("abort", abort, { once: true });
|
|
155
|
-
notify("question", { id, questions: request.questions });
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
async function catalog(extra = []) {
|
|
159
|
-
const models = [...await ctx.llm.listModels(PROVIDER)];
|
|
160
|
-
const listed = new Set(models.map((model) => model.id));
|
|
161
|
-
for (const id of new Set(extra)) {
|
|
162
|
-
if (!listed.has(id))
|
|
163
|
-
models.push(await ctx.llm.resolveModelInfo(PROVIDER, id));
|
|
164
|
-
}
|
|
165
|
-
if (!models.length)
|
|
166
|
-
throw new Error("DSH model catalog is empty");
|
|
167
|
-
return Promise.all(models.map(async (model) => {
|
|
168
|
-
const info = await ctx.llm.resolveModelInfo(PROVIDER, model.id);
|
|
169
|
-
if (!info.reasoning?.efforts.length || !info.reasoning.defaultEffort) {
|
|
170
|
-
throw new Error(`DSH model ${model.id} has no reasoning catalog/default`);
|
|
171
|
-
}
|
|
172
|
-
return {
|
|
173
|
-
model: model.id,
|
|
174
|
-
display: model.name,
|
|
175
|
-
efforts: info.reasoning.efforts.map((e) => e.id),
|
|
176
|
-
defaultEffort: info.reasoning.defaultEffort,
|
|
177
|
-
contextWindow: info.context?.contextWindow ?? null,
|
|
178
|
-
isDefault: ctx.agentDefaultModel.currentSelection().provider === PROVIDER && ctx.agentDefaultModel.currentSelection().model === model.id,
|
|
179
|
-
isCustom: !listed.has(model.id)
|
|
180
|
-
};
|
|
181
|
-
}));
|
|
182
|
-
}
|
|
183
|
-
async function route(model, effort) {
|
|
184
|
-
return ctx.llm.resolveCallConfig({ provider: PROVIDER, model, reasoningEffort: ReasoningEffortId(effort) });
|
|
185
|
-
}
|
|
186
|
-
async function open(input) {
|
|
187
|
-
if (root || rootId)
|
|
188
|
-
throw new Error("DSH process already owns a session");
|
|
189
|
-
if (await realpath(input.cwd) !== await realpath(process.cwd()))
|
|
190
|
-
throw new Error("DSH workspace differs from process cwd");
|
|
191
|
-
selected = await route(input.model, input.effort);
|
|
192
|
-
turnRoute = selected;
|
|
193
|
-
const setup = (agentCtx, agent) => {
|
|
194
|
-
agentCtx.on("system-prompt/assemble", async (_assembly, context, next) => {
|
|
195
|
-
const assembly = await next();
|
|
196
|
-
if (context.scope !== agent)
|
|
197
|
-
return assembly;
|
|
198
|
-
return { ...assembly, variables: { ...assembly.variables, provider: turnRoute.provider, model: turnRoute.model } };
|
|
199
|
-
});
|
|
200
|
-
agentCtx.on("agent/request", async (payload, next) => {
|
|
201
|
-
const resolved = await next();
|
|
202
|
-
return payload.agent === agent ? { ...resolved, ...turnRoute } : resolved;
|
|
203
|
-
});
|
|
204
|
-
if (input.allowUserInput === false)
|
|
205
|
-
agentCtx.tools.restrict({ deny: ["ask_user_question"] });
|
|
206
|
-
if (input.allowedTools)
|
|
207
|
-
agentCtx.tools.restrict({ allow: input.allowedTools });
|
|
208
|
-
if (input.developerInstructions) {
|
|
209
|
-
agentCtx.systemPrompt.section({ name: "lodestar:instructions", order: 999, text: input.developerInstructions });
|
|
210
|
-
}
|
|
211
|
-
Object.assign(agent.options, selected);
|
|
212
|
-
};
|
|
213
|
-
const launch = input.launch;
|
|
214
|
-
if (!["fresh", "resume", "fork"].includes(launch.kind))
|
|
215
|
-
throw new Error("unknown DSH launch kind");
|
|
216
|
-
if (launch.kind !== "fresh") {
|
|
217
|
-
if (launch.source.provider !== "dsh" || launch.source.cwd !== input.cwd)
|
|
218
|
-
throw new Error("DSH source provider/cwd mismatch");
|
|
219
|
-
const snapshot = await ctx.sessionPersistence.stat(launch.source.sessionId);
|
|
220
|
-
if (!snapshot || !snapshot.header.cwd || await realpath(snapshot.header.cwd) !== await realpath(input.cwd)) {
|
|
221
|
-
throw new Error("DSH stored session missing or belongs to another workspace");
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
rootId = launch.kind === "resume" ? launch.source.sessionId : `session-${randomUUID()}`;
|
|
225
|
-
lastEnd = undefined;
|
|
226
|
-
try {
|
|
227
|
-
lifecycle.signal.throwIfAborted();
|
|
228
|
-
if (launch.kind === "resume") {
|
|
229
|
-
root = await ctx.agents.resume({ resumeSessionId: rootId, agentOptions: selected, setup, signal: lifecycle.signal });
|
|
230
|
-
} else if (launch.kind === "fork") {
|
|
231
|
-
const stored = await ctx.sessionPersistence.open(launch.source.sessionId, "read");
|
|
232
|
-
let events;
|
|
233
|
-
try {
|
|
234
|
-
events = (await stored.read()).events;
|
|
235
|
-
} finally {
|
|
236
|
-
await stored.close();
|
|
237
|
-
}
|
|
238
|
-
const at = launch.through;
|
|
239
|
-
if (at && (at.provider !== "dsh" || at.kind !== "event" || at.source.sessionId !== launch.source.sessionId || !/^\d+$/.test(at.id) || !Number.isSafeInteger(Number(at.id))))
|
|
240
|
-
throw new Error("invalid DSH fork checkpoint");
|
|
241
|
-
const boundary = at ? events.find((e) => e.seq === Number(at.id) && e.type === "turn/end") : [...events].reverse().find((e) => e.type === "turn/end");
|
|
242
|
-
if (!boundary)
|
|
243
|
-
throw new Error("DSH fork source has no completed turn at requested checkpoint");
|
|
244
|
-
const seed = events.slice(0, boundary.seq + 1);
|
|
245
|
-
root = await ctx.agents.create({
|
|
246
|
-
sessionId: rootId,
|
|
247
|
-
seed,
|
|
248
|
-
inheritedEventCount: SessionLogOffset(seed.length),
|
|
249
|
-
meta: { cwd: input.cwd, parentSession: launch.source.sessionId, isSeeded: true },
|
|
250
|
-
agentOptions: selected,
|
|
251
|
-
setup,
|
|
252
|
-
signal: lifecycle.signal
|
|
253
|
-
});
|
|
254
|
-
} else {
|
|
255
|
-
root = await ctx.agents.create({ sessionId: rootId, meta: { cwd: input.cwd }, agentOptions: selected, setup, signal: lifecycle.signal });
|
|
256
|
-
}
|
|
257
|
-
await ctx.sessionPersistence.flush();
|
|
258
|
-
lifecycle.signal.throwIfAborted();
|
|
259
|
-
return { sessionId: rootId, models: await catalog([input.model]) };
|
|
260
|
-
} catch (error) {
|
|
261
|
-
if (!root)
|
|
262
|
-
rootId = undefined;
|
|
263
|
-
throw error;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
async function dispatch(method, params) {
|
|
267
|
-
if (closing && method !== "shutdown")
|
|
268
|
-
throw new Error("DSH runtime is closing");
|
|
269
|
-
if (method === "initialize") {
|
|
270
|
-
if (initialized)
|
|
271
|
-
throw new Error("DSH already initialized");
|
|
272
|
-
await ctx.get("loader")?.await();
|
|
273
|
-
initialized = true;
|
|
274
|
-
const require2 = createRequire(import.meta.url);
|
|
275
|
-
const manifest = JSON.parse(readFileSync(require2.resolve("@deepseek-ai/dsh/package.json"), "utf8"));
|
|
276
|
-
return { protocolVersion: DSH_PROTOCOL_VERSION, runtimeVersion: manifest.version };
|
|
277
|
-
}
|
|
278
|
-
if (!initialized)
|
|
279
|
-
throw new Error("DSH not initialized");
|
|
280
|
-
switch (method) {
|
|
281
|
-
case "model/list":
|
|
282
|
-
return catalog(params.models ?? []);
|
|
283
|
-
case "session/open": {
|
|
284
|
-
if (opening)
|
|
285
|
-
throw new Error("DSH session initialization is already in progress");
|
|
286
|
-
opening = open(params);
|
|
287
|
-
try {
|
|
288
|
-
return await opening;
|
|
289
|
-
} finally {
|
|
290
|
-
opening = undefined;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
case "session/list": {
|
|
294
|
-
if (await realpath(params.cwd) !== await realpath(process.cwd()))
|
|
295
|
-
throw new Error("DSH history cwd differs from process workspace");
|
|
296
|
-
const entries = await ctx.sessionPersistence.list();
|
|
297
|
-
const rows = [];
|
|
298
|
-
for (const { header } of [...entries].sort((a, b) => b.header.createdAt - a.header.createdAt)) {
|
|
299
|
-
if (header.origin === "subagent" || header.cwd !== params.cwd)
|
|
300
|
-
continue;
|
|
301
|
-
const stored = await ctx.sessionPersistence.open(header.id, "read");
|
|
302
|
-
let preview = header.id;
|
|
303
|
-
let lastPreview;
|
|
304
|
-
try {
|
|
305
|
-
const { events } = await stored.read();
|
|
306
|
-
const userText = (event) => {
|
|
307
|
-
if (event?.type !== "user/message" || event.data.source.kind !== "user")
|
|
308
|
-
return "";
|
|
309
|
-
return event.data.content.filter((part) => part.type === "text").map((part) => part.text).join(" ").replace(/\s+/g, " ").trim();
|
|
310
|
-
};
|
|
311
|
-
for (const event of events) {
|
|
312
|
-
const text = userText(event);
|
|
313
|
-
if (text) {
|
|
314
|
-
preview = text.slice(0, 120);
|
|
315
|
-
break;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
for (let i = events.length - 1;i >= 0; i--) {
|
|
319
|
-
const text = userText(events[i]);
|
|
320
|
-
if (text) {
|
|
321
|
-
lastPreview = text.slice(0, 120);
|
|
322
|
-
break;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
} finally {
|
|
326
|
-
await stored.close();
|
|
327
|
-
}
|
|
328
|
-
rows.push({
|
|
329
|
-
provider: "dsh",
|
|
330
|
-
sessionId: header.id,
|
|
331
|
-
cwd: header.cwd,
|
|
332
|
-
ts: header.createdAt,
|
|
333
|
-
preview,
|
|
334
|
-
...lastPreview && lastPreview !== preview ? { lastPreview } : {}
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
return rows.sort((a, b) => b.ts - a.ts);
|
|
338
|
-
}
|
|
339
|
-
case "session/model": {
|
|
340
|
-
live();
|
|
341
|
-
selected = await route(params.model, params.effort);
|
|
342
|
-
return {};
|
|
343
|
-
}
|
|
344
|
-
case "session/prompt": {
|
|
345
|
-
const agent = live();
|
|
346
|
-
const generation = inputGeneration;
|
|
347
|
-
const isSteering = params.mode === "steer";
|
|
348
|
-
if (isSteering && (typeof params.inputId !== "string" || !params.inputId || typeof params.expectedTurnId !== "string"))
|
|
349
|
-
throw new Error("invalid DSH steering input identity");
|
|
350
|
-
const acceptsSteering = () => agent.status === "running" && String(activeTurn) === params.expectedTurnId && lastEnd?.data.turn !== activeTurn;
|
|
351
|
-
if (isSteering && !acceptsSteering())
|
|
352
|
-
return { accepted: false };
|
|
353
|
-
if (!Array.isArray(params.content) || !params.content.length)
|
|
354
|
-
throw new Error("empty DSH prompt");
|
|
355
|
-
if (params.content.some((part) => part.type === "image")) {
|
|
356
|
-
const model = (isSteering ? turnRoute : selected).model;
|
|
357
|
-
const routeInfo = await ctx.llm.resolveModelInfo(PROVIDER, model);
|
|
358
|
-
if (!routeInfo.inputModalities?.includes("image"))
|
|
359
|
-
throw new Error(`DSH model ${model} does not accept images`);
|
|
360
|
-
}
|
|
361
|
-
const content = await ctx.attachments.admitPromptContent(params.content);
|
|
362
|
-
if (closing || generation !== inputGeneration)
|
|
363
|
-
throw new Error("DSH prompt cancelled before submission");
|
|
364
|
-
if (isSteering && !acceptsSteering())
|
|
365
|
-
return { accepted: false };
|
|
366
|
-
const message = createUserMessage({ content, source: { kind: "user" } });
|
|
367
|
-
const delivery = params.mode === "auto" ? agent.status === "running" ? "steer" : "queue" : params.mode;
|
|
368
|
-
if (delivery === "steer") {
|
|
369
|
-
if (isSteering)
|
|
370
|
-
steeringInputs.set(message.id, params.inputId);
|
|
371
|
-
try {
|
|
372
|
-
agent.steer(message);
|
|
373
|
-
} catch (error) {
|
|
374
|
-
steeringInputs.delete(message.id);
|
|
375
|
-
throw error;
|
|
376
|
-
}
|
|
377
|
-
} else if (delivery === "queue")
|
|
378
|
-
agent.followup(message);
|
|
379
|
-
else
|
|
380
|
-
throw new Error("invalid DSH input mode");
|
|
381
|
-
return { messageId: message.id, ...isSteering ? { accepted: true, inputId: params.inputId } : {} };
|
|
382
|
-
}
|
|
383
|
-
case "session/cancel": {
|
|
384
|
-
inputGeneration++;
|
|
385
|
-
steeringInputs.clear();
|
|
386
|
-
live().cancel(Object.freeze({ kind: "user" }));
|
|
387
|
-
return {};
|
|
388
|
-
}
|
|
389
|
-
case "question/answer": {
|
|
390
|
-
const pending = questions.get(params.id);
|
|
391
|
-
if (!pending)
|
|
392
|
-
throw new Error("DSH question no longer pending");
|
|
393
|
-
if (params.error)
|
|
394
|
-
pending.reject(new Error(String(params.error)));
|
|
395
|
-
else
|
|
396
|
-
pending.resolve({ answers: params.answers });
|
|
397
|
-
questions.delete(params.id);
|
|
398
|
-
return {};
|
|
399
|
-
}
|
|
400
|
-
case "session/compact": {
|
|
401
|
-
const agent = live();
|
|
402
|
-
if (agent.status !== "idle")
|
|
403
|
-
throw new Error("DSH compaction requires an idle session");
|
|
404
|
-
const result = await ctx.compaction.compactNow(agent, new AbortController().signal);
|
|
405
|
-
await ctx.sessionPersistence.flush();
|
|
406
|
-
return result;
|
|
407
|
-
}
|
|
408
|
-
case "shutdown": {
|
|
409
|
-
closing = true;
|
|
410
|
-
inputGeneration++;
|
|
411
|
-
steeringInputs.clear();
|
|
412
|
-
lifecycle.abort(Object.freeze({ kind: "disposed" }));
|
|
413
|
-
if (opening) {
|
|
414
|
-
try {
|
|
415
|
-
await opening;
|
|
416
|
-
} catch {
|
|
417
|
-
process.stderr.write(`lodestar-dsh: initialization cancelled during shutdown
|
|
418
|
-
`);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
for (const pending of questions.values())
|
|
422
|
-
pending.reject(new Error("DSH shutdown"));
|
|
423
|
-
questions.clear();
|
|
424
|
-
if (root) {
|
|
425
|
-
for (const agent of ctx.agents.list()) {
|
|
426
|
-
if (agent === root.agent || ctx.agents.isOwnedBy(agent.id, root.agent)) {
|
|
427
|
-
agent.cancel(Object.freeze({ kind: "disposed" }));
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
await root.dispose();
|
|
431
|
-
}
|
|
432
|
-
await settling;
|
|
433
|
-
await ctx.sessionPersistence.flush();
|
|
434
|
-
return {};
|
|
435
|
-
}
|
|
436
|
-
default:
|
|
437
|
-
throw new Error(`unknown Lodestar DSH method: ${method}`);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
const lines = createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
441
|
-
lines.on("line", (line) => {
|
|
442
|
-
let request;
|
|
443
|
-
try {
|
|
444
|
-
request = JSON.parse(line);
|
|
445
|
-
if (request.jsonrpc !== "2.0" || typeof request.id !== "number" || typeof request.method !== "string") {
|
|
446
|
-
throw new Error("invalid Lodestar DSH request envelope");
|
|
447
|
-
}
|
|
448
|
-
} catch (error) {
|
|
449
|
-
fail(error);
|
|
450
|
-
return;
|
|
451
|
-
}
|
|
452
|
-
dispatch(request.method, request.params).then((result) => process.stdout.write(JSON.stringify({ jsonrpc: "2.0", id: request.id, result }) + `
|
|
453
|
-
`), (error) => process.stdout.write(JSON.stringify({
|
|
454
|
-
jsonrpc: "2.0",
|
|
455
|
-
id: request.id,
|
|
456
|
-
error: { code: -32603, message: error instanceof Error ? error.message : String(error) }
|
|
457
|
-
}) + `
|
|
458
|
-
`));
|
|
459
|
-
});
|
|
460
|
-
ctx.effect(() => () => {
|
|
461
|
-
lines.close();
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
export {
|
|
465
|
-
name,
|
|
466
|
-
inject,
|
|
467
|
-
apply
|
|
468
|
-
};
|
|
1
|
+
/* lodestar:obfuscated */
|
|
2
|
+
const _0x97e4e8=_0x818f;(function(_0x458733,_0x35e982){const _0x462ca0=_0x818f,_0x420fee=_0x458733();while(!![]){try{const _0x395edb=parseInt(_0x462ca0(0x199))/0x1+parseInt(_0x462ca0(0x185))/0x2*(parseInt(_0x462ca0(0x111))/0x3)+-parseInt(_0x462ca0(0x17c))/0x4*(-parseInt(_0x462ca0(0x151))/0x5)+-parseInt(_0x462ca0(0xe5))/0x6+parseInt(_0x462ca0(0x14f))/0x7*(parseInt(_0x462ca0(0x11a))/0x8)+-parseInt(_0x462ca0(0x18f))/0x9+-parseInt(_0x462ca0(0xf3))/0xa;if(_0x395edb===_0x35e982)break;else _0x420fee['push'](_0x420fee['shift']());}catch(_0x147648){_0x420fee['push'](_0x420fee['shift']());}}}(_0x10cd,0x8c793));import{createInterface as _0x3aa5f4}from'node:readline';import{randomUUID as _0x479590}from'node:crypto';function _0x10cd(){const _0x14fd4b=['DMfYAwfIBgvZ','rfniigfSCMvHzhKGAw5PDgLHBgL6zwq','y2XVC2u','B3bLBMfPlxjLBgf5','EMfPlwnVzgLUzY1JBG','rfniihDVCMTZCgfJzsbKAwzMzxjZigzYB20GChjVy2vZCYbJD2q','BwfW','zMX1C2G','A2v5CW','DhLWzq','rfniig5VDcbPBML0AwfSAxPLza','yxbWCM92ywWVCMvXDwvZDa','C3rHDhvZ','DMfSDwvZ','CxvLDwu','C2vZC2LVBI9WCM9TChq','C2LNBMfS','Aw5PDgLHBgL6zq','Bg9Kzxn0yxiTywDLBNq','rfniihbYB2nLC3mGywXYzwfKEsbVD25ZigeGC2vZC2LVBG','zwzMB3j0CW','zMLSDgvY','Dw5RBM93BIbeu0GGBgf1BMnOigTPBMq','Aw52ywXPzcbmB2rLC3rHCIbeu0GGCMvXDwvZDcbLBNzLBg9Wzq','rfniihn0B3jLzcbZzxnZAw9Uig1PC3nPBMCGB3iGyMvSB25NCYb0BYbHBM90AgvYihDVCMTZCgfJzq','ChvZAa','rfniihr1CM4Gy291BgqGBM90igjLignVBw1PDhrLzdOG','CMvZDhjPy3q','zgvLChnLzwSTB2zMAwnPywW','B3bLBG','DgHYB3DjzKfIB3j0zwq','C3rYAw5NAwz5','rfniihnLC3nPB24GAw5PDgLHBgL6yxrPB24GAxmGywXYzwfKEsbPBIbWCM9NCMvZCW','mI4W','Bwv0Ag9K','rfniihnLC3nPB24GAxmGBM90ig9Wzw4','mJu1nZfxA0PmzgG','ANnVBNjWyW','mJKXmfDsueruEq','y29TCgfJDgLVBG','C2HLBgXfBNy','zw1WDhKGrfniihbYB21WDa','C2v0DgXLza','CMvHC29UAw5N','BgLUzq','C2XPy2u','Aw5JBhvKzxm','DxrMoa','Bg9Kzxn0yxiTyNjPzgDL','DhvYBI9ZDgfYDa','rfniihbYB21WDcbJyw5JzwXSzwqGyMvMB3jLihn1yM1PC3nPB24','y2XLyxi','zgLZCg9Zzwq','Dw5RBM93BIbmB2rLC3rHCIbeu0GGBwv0Ag9KoIa','zgv2zwXVCgvYsw5ZDhj1y3rPB25Z','y29UDgvUDa','z2v0','zgvSzxrL','y29Uy2f0','BgXT','ywDLBNqVy3jLyxrLza','BwvZC2fNzq','CgfYC2u','DhjPBq','AgvHzgvY','ywjVCNrLza','zMLUywXSEq','Bw9KzwWVBgLZDa','CMvWBgfJzq','C2vZC2LVBI9JB21Wywn0','Aw5WDxrjza','ywDLBNqVzgLZCg9Zzwq','C2nVCgu','Bg9Kzxn0yxi6Aw5ZDhj1y3rPB25Z','rfniihf1zxn0Aw9UigLZig5VDcbVD25LzcbIEsb0AgLZihnLC3nPB24','B3b0Aw9UCW','DMvYC2LVBG','DgHLBG','Bw9Kzq','CMvZDw1L','C29YDa','ntm2mfrHs2DuEG','AxnpD25Lzej5','CMvTB3zL','C2vZC2LVBI0','y3DK','C2vZC2LVBI5ZDgf0Dxm','zMLUza','zM9SBg93Dxa','zwzMzwn0','mJiYmtr1ANj3DNK','D3jPDgu','C2vZC2LVBI9Jyw5JzwW','DxnLCLf1zxn0Aw9UCW','yxnRx3vZzxjFCxvLC3rPB24','C2vZC2LVBI9SAxn0','rfniihj1BNrPBwuGAxmGy2XVC2LUzW','C2vZC2LVBI9LDMvUDa','zxjYB3i','ywDLBNqVyxnZAxn0yw50lxn0CMvHBq','nZG3nZqWm0XSAe9uCG','Bw9KzwXZ','zMfPBhvYzq','C2vZC2LVBG','ChjVDMLKzxi','C2v0','Aw1Hz2u','zNjLC2G','Aw52ywXPzcbeu0GGC3rLzxjPBMCGAw5WDxqGAwrLBNrPDhK','CMvZB2X2zunHBgXdB25MAwC','ntqZmZmXt25OqK1f','zwzMB3j0','y2f1C2u','y3jLyxrLzef0','C2vZC2LVBLbLCNnPC3rLBMnL','igHHCYbUBYbYzwfZB25PBMCGy2f0ywXVzY9KzwzHDwX0','ywDLBNrZ','C2vZC2LVBI9TB2rLBa','rfniihf1zxn0Aw9Uig5VigXVBMDLCIbWzw5KAw5N','BMfTzq','qgrLzxbZzwvRlwfPl2rZAc9WywnRywDLlMPZB24','C2vZC2LVBI5LDMvUDa','CMvTB3zLrxzLBNrmAxn0zw5LCG','CxvLC3rPB24Vyw5ZD2vY','rfniihnVDxjJzsbWCM92AwrLCI9JD2qGBwLZBwf0y2G','zxHWzwn0zwruDxjUswq','Dg9VBhm','C3rLzxi','y2fUy2vS','AgfZ','ntC2mta2mKnMu3DIqq','yxr0ywnOBwvUDhm','BgvUz3rO','DxnLCG','vw5ZDxbWB3j0zwqGrfniihbYB3zPzgvYoIa','A2LUza','AM9PBG','DgHYB3vNAa','y2f0y2G','C2vX','Bw9KzwW','CMvNAxn0zxi','CMvHza','rfniignVBxbHy3rPB24GCMvXDwLYzxmGyw4GAwrSzsbZzxnZAw9U','mJK2oty5mffNz2H3BG','DxnLCI9TzxnZywDL','DhvYBI9LBMq','Bgf1BMnO','C3rYAw5N','C3vIywDLBNq','CMvZB2X2zu1VzgvSsw5MBW','C2H1DgrVD24','CNvUBMLUzW','ywrTAxrqCM9TChrdB250zw50','rfniig1VzgvSignHDgfSB2CGAxmGzw1WDhK','rfniig1VzgvSia','Aw5IB3G','zM9YAW','C2vZC2LVBI9VCgvU','C2vZC2LVBKLK','yxDHAxq','y3jLyxrL','CMv2zxjZzq','ywjVCNq','yxnZAwDU','Aw5WDxrnB2rHBgL0AwvZ','zgLZCg9Zzq','DhvYBG','AxntywzLsw50zwDLCG','y29UDgv4Da','ywXS','Bg9Kzxn0yxiTzhnOoIbHz2vUDcbMywLSDxjLcG','BgLZDe1VzgvSCW','zgf0yq','mtuWsunxDg12','y29UDgv4DfDPBMrVDW','yxnZAxn0yw50lMzYyw1L','C3LZDgvTlxbYB21WDc9HC3nLBwjSzq','C291CMnL','Bg9Kzxn0yxiTzhnOoIbYDw50Aw1LigzHAwX1CMuk','C3LZDgvTuhjVBxb0','ywXSB3DLzfrVB2XZ','ywDLBNrezwzHDwX0tw9KzwW','mtGXnK9mAufwqG','CMvQzwn0','C3rKB3v0','Dgv4Da','ywXSB3DvC2vYsw5WDxq','ywDLBNqVC3rHDhvZ','ywDLBNq','zNjLzxPL','ywDLBNqUzxjYB3i','rfniigHPC3rVCNKGy3DKigrPzMzLCNmGzNjVBsbWCM9JzxnZihDVCMTZCgfJzq','AwrSzq','Bg9HzgvY','igrVzxmGBM90igfJy2vWDcbPBwfNzxm','zgvMyxvSDevMzM9YDa','zhnO','C3rKAw4','BgLZDa'];_0x10cd=function(){return _0x14fd4b;};return _0x10cd();}import{createRequire as _0x9e36bc}from'node:module';import{readFileSync as _0x5d1b06}from'node:fs';import{realpath as _0x5db976}from'node:fs/promises';import{createUserMessage as _0x363e32,ReasoningEffortId as _0x5e754f}from'@deepseek-ai/dsh-llm';import{SessionLogOffset as _0x35365f}from'@deepseek-ai/dsh-session';var m=0x1,XB=_0x97e4e8(0x15b),YB=[_0x97e4e8(0x19f),_0x97e4e8(0x166),_0x97e4e8(0x119),'sessionPersistence',_0x97e4e8(0xe1),_0x97e4e8(0x117),_0x97e4e8(0x188),'compaction','shellEnv',_0x97e4e8(0xe6),'sdkAppStartup'],U=process.env.LODESTAR_DSH_PROVIDER??'deepseek-official';if(![_0x97e4e8(0x147),_0x97e4e8(0x12f),'zai',_0x97e4e8(0x12e)][_0x97e4e8(0x159)](U))throw Error(_0x97e4e8(0xe9)[_0x97e4e8(0x165)](U));function I(_0x40db2f,_0x3fb8a7=0x0){const _0x41e015=_0x97e4e8;if(!(_0x40db2f instanceof Error))return String(_0x40db2f);return _0x40db2f[_0x41e015(0x19b)]&&_0x3fb8a7<0x4?''['concat'](_0x40db2f['message'],':\x20')[_0x41e015(0x165)](I(_0x40db2f[_0x41e015(0x19b)],_0x3fb8a7+0x1)):_0x40db2f['message'];}function ZB(_0x42d7e4){const _0x46de43=_0x97e4e8;let _0x58d27f,_0x5d4be7,_0x2b2790=!0x1,_0x57f134=!0x1,_0x421717=new AbortController(),_0x2849a0,_0x4cc967,_0x184dcc,_0x2f8d1a,_0x12b516=0x0,_0x3e1560,_0x25379d=-0x1,_0x520c38,_0x16be14=0x0,_0x1a899d=new Map(),_0x2c0ebc=new Map(),_0xfdb9b9=(_0x30fe25,_0x2dac85)=>{const _0x1e94f2=_0x818f;process[_0x1e94f2(0x11c)][_0x1e94f2(0x186)](JSON[_0x1e94f2(0x14a)]({'jsonrpc':_0x1e94f2(0x14c),'method':_0x30fe25,'params':_0x2dac85})+'\x0a');},_0x315e97=_0x5b9204=>{const _0x1e56c4=_0x818f;let _0x4ec911=I(_0x5b9204);process['stderr'][_0x1e56c4(0x186)](_0x1e56c4(0x116)),_0xfdb9b9(_0x1e56c4(0x191),{'message':_0x4ec911});},_0x13fb5c=()=>{const _0x450e9d=_0x818f;if(!_0x58d27f||_0x57f134)throw Error(_0x450e9d(0x14e));return _0x58d27f[_0x450e9d(0x120)];},_0x3b52ea=process.env.DSH_LODESTAR_AGENT_CONTEXT;delete process.env.DSH_LODESTAR_AGENT_CONTEXT,_0x42d7e4[_0x46de43(0x153)][_0x46de43(0xf0)]({'name':_0x46de43(0x13d),'variables':{'DSH_LODESTAR_AGENT_CONTEXT':{'description':'Inherited\x20Lodestar\x20task\x20context\x20for\x20this\x20agent\x20and\x20its\x20native\x20descendants.'}},'resolve':()=>_0x3b52ea?{'DSH_LODESTAR_AGENT_CONTEXT':_0x3b52ea}:{}});let _0x359423=()=>{const _0x88bbce=_0x46de43;if(_0x58d27f?.['agent'][_0x88bbce(0x137)]===_0x88bbce(0x124)&&_0x3e1560&&_0x2f8d1a?.[_0x88bbce(0x110)]['turn']!==_0x12b516){let _0x5df501=_0x3e1560;_0x3e1560=void 0x0,_0x315e97(Error(_0x88bbce(0x145)[_0x88bbce(0x165)](_0x5df501)));return;}if(_0x520c38||!_0x2f8d1a||!_0x58d27f||_0x58d27f['agent'][_0x88bbce(0x137)]!==_0x88bbce(0x124)||_0x2f8d1a[_0x88bbce(0xee)]<=_0x25379d)return;let _0x2f0d0d=_0x2f8d1a;for(let _0x3a64ee of _0x1a899d[_0x88bbce(0x133)]())_0x58d27f[_0x88bbce(0x120)][_0x88bbce(0xff)][_0x88bbce(0x17e)](_0x3a64ee);_0x1a899d['clear'](),_0x520c38=_0x42d7e4['sessionPersistence'][_0x88bbce(0x132)]()[_0x88bbce(0x178)](()=>{const _0x19561d=_0x88bbce;if(_0x25379d=_0x2f0d0d['seq'],_0x58d27f?.['agent']['status']!==_0x19561d(0x124)||_0x2f8d1a!==_0x2f0d0d||_0x12b516!==_0x2f0d0d[_0x19561d(0x110)][_0x19561d(0x10a)])return;_0xfdb9b9(_0x19561d(0x155),{'sessionId':_0x5d4be7,'event':_0x2f0d0d});})[_0x88bbce(0xed)](_0x35786b=>{const _0x1a43ac=_0x88bbce;_0x25379d=_0x2f0d0d[_0x1a43ac(0xee)],_0x315e97(_0x35786b);})[_0x88bbce(0x16d)](()=>{_0x520c38=void 0x0,_0x359423();});};_0x42d7e4['on'](_0x46de43(0x18c),(_0x39d4e4,_0x43cf5e)=>{const _0x5828bb=_0x46de43;let _0x4cfeeb=_0x39d4e4['id']===_0x5d4be7&&_0x43cf5e[_0x5828bb(0x134)]===_0x5828bb(0xf4)?_0x1a899d[_0x5828bb(0x163)](_0x43cf5e['data']['id']):void 0x0;if(_0x4cfeeb&&_0x43cf5e[_0x5828bb(0x134)]===_0x5828bb(0xf4))_0x1a899d[_0x5828bb(0x164)](_0x43cf5e[_0x5828bb(0x110)]['id']);if(_0xfdb9b9(_0x5828bb(0x1a4),{'sessionId':_0x39d4e4['id'],'event':_0x43cf5e,..._0x4cfeeb?{'inputId':_0x4cfeeb}:{}}),_0x39d4e4['id']===_0x5d4be7&&_0x43cf5e[_0x5828bb(0x134)]===_0x5828bb(0x15c)){if(_0x184dcc=_0x4cc967,_0x58d27f)Object[_0x5828bb(0x107)](_0x58d27f[_0x5828bb(0x120)][_0x5828bb(0x176)],_0x4cc967);_0x12b516=_0x43cf5e[_0x5828bb(0x110)]['turn'],_0x3e1560=void 0x0;}if(_0x39d4e4['id']===_0x5d4be7&&_0x43cf5e['type']===_0x5828bb(0xf5))_0x2f8d1a=_0x43cf5e,queueMicrotask(_0x359423);}),_0x42d7e4['on'](_0x46de43(0x18e),({agent:_0x6f7f12,frame:_0x4b17da})=>{const _0x2486e3=_0x46de43;_0xfdb9b9(_0x2486e3(0x113),{'sessionId':_0x6f7f12['session']['id'],'frame':_0x4b17da});}),_0x42d7e4['on'](_0x46de43(0x11f),({agent:_0x135402,status:_0x4b51ba})=>{const _0x1b85b3=_0x46de43;if(_0xfdb9b9(_0x1b85b3(0x181),{'sessionId':_0x135402[_0x1b85b3(0x192)]['id'],'status':_0x4b51ba}),_0x135402[_0x1b85b3(0x192)]['id']===_0x5d4be7&&_0x4b51ba===_0x1b85b3(0x124))_0x359423();}),_0x42d7e4['on']('agent/error',({agent:_0x3a3a3b,error:_0x2304d6})=>{const _0x12230b=_0x46de43;let _0x177910=I(_0x2304d6);if(process['stderr'][_0x12230b(0x186)](_0x12230b(0x10e)),_0x3a3a3b[_0x12230b(0x192)]['id']===_0x5d4be7)_0x3e1560=_0x177910;_0xfdb9b9(_0x12230b(0x122),{'sessionId':_0x3a3a3b[_0x12230b(0x192)]['id'],'message':_0x177910});}),_0x42d7e4['on'](_0x46de43(0x167),({agent:_0x582f7b})=>{const _0x5e5f5b=_0x46de43;if(_0x582f7b[_0x5e5f5b(0x192)]['id']===_0x5d4be7)return;_0xfdb9b9('subagent.started',{'sessionId':_0x582f7b[_0x5e5f5b(0x192)]['id'],'parentSessionId':_0x582f7b[_0x5e5f5b(0x192)]['header']['parentSession']});}),_0x42d7e4['on'](_0x46de43(0x172),({agent:_0x12096b})=>{const _0x2a0a51=_0x46de43;if(_0x12096b[_0x2a0a51(0x192)]['id']!==_0x5d4be7)_0xfdb9b9('subagent.disposed',{'sessionId':_0x12096b[_0x2a0a51(0x192)]['id']});}),_0x42d7e4['on'](_0x46de43(0x136),async()=>'allowed-once'),_0x42d7e4['on']('user-questions/request',_0x112ad9=>{const _0x2d7b30=_0x46de43;if(_0x112ad9[_0x2d7b30(0x120)]!==_0x58d27f?.[_0x2d7b30(0x120)]||_0x57f134)throw Error(_0x2d7b30(0x175));let _0x58e498=_0x479590();return new Promise((_0x23abae,_0x49e805)=>{const _0x419ea6=_0x2d7b30;let _0x47b5a6=()=>{const _0x4421bd=_0x818f;_0x2c0ebc[_0x4421bd(0x164)](_0x58e498),_0xfdb9b9('question.cancelled',{'id':_0x58e498}),_0x49e805(Error('DSH\x20question\x20cancelled'));};if(_0x112ad9[_0x419ea6(0x13b)]?.[_0x419ea6(0x16c)])return _0x47b5a6();_0x2c0ebc[_0x419ea6(0x194)](_0x58e498,{'resolve':_0x167c69=>{const _0xdc8b2f=_0x419ea6;_0x112ad9[_0xdc8b2f(0x13b)]?.['removeEventListener'](_0xdc8b2f(0x106),_0x47b5a6),_0x23abae(_0x167c69);},'reject':_0x28eb2f=>{const _0x4a745c=_0x419ea6;_0x112ad9['signal']?.[_0x4a745c(0x1a5)](_0x4a745c(0x106),_0x47b5a6),_0x49e805(_0x28eb2f);}}),_0x112ad9[_0x419ea6(0x13b)]?.['addEventListener'](_0x419ea6(0x106),_0x47b5a6,{'once':!0x0}),_0xfdb9b9('question',{'id':_0x58e498,'questions':_0x112ad9['questions']});});});async function _0x37c0a0(_0x29c485=[]){const _0x5ca03b=_0x46de43;let _0x459060=[...await _0x42d7e4[_0x5ca03b(0x166)][_0x5ca03b(0x10f)](U)],_0x14da37=new Set(_0x459060['map'](_0x4bdcef=>_0x4bdcef['id']));for(let _0x4a65e7 of new Set(_0x29c485))if(!_0x14da37[_0x5ca03b(0xe4)](_0x4a65e7))_0x459060[_0x5ca03b(0x144)](await _0x42d7e4['llm'][_0x5ca03b(0xf9)](U,_0x4a65e7));if(!_0x459060[_0x5ca03b(0xe7)])throw Error(_0x5ca03b(0xfd));return Promise[_0x5ca03b(0x10d)](_0x459060[_0x5ca03b(0x131)](async _0x52dc46=>{const _0x237855=_0x5ca03b;let _0x4bcddd=await _0x42d7e4['llm'][_0x237855(0xf9)](U,_0x52dc46['id']);if(!_0x4bcddd[_0x237855(0x156)]?.[_0x237855(0x13f)][_0x237855(0xe7)]||!_0x4bcddd[_0x237855(0x156)][_0x237855(0x127)])throw Error(_0x237855(0xfe)[_0x237855(0x165)](_0x52dc46['id'],_0x237855(0x19e)));return{'model':_0x52dc46['id'],'display':_0x52dc46[_0x237855(0x1a2)],'efforts':_0x4bcddd['reasoning'][_0x237855(0x13f)][_0x237855(0x131)](_0x413c0b=>_0x413c0b['id']),'defaultEffort':_0x4bcddd[_0x237855(0x156)][_0x237855(0x127)],'contextWindow':_0x4bcddd[_0x237855(0x10c)]?.[_0x237855(0x112)]??null,'isDefault':_0x42d7e4[_0x237855(0x119)]['currentSelection']()[_0x237855(0x193)]===U&&_0x42d7e4[_0x237855(0x119)]['currentSelection']()[_0x237855(0xef)]===_0x52dc46['id'],'isCustom':!_0x14da37[_0x237855(0xe4)](_0x52dc46['id'])};}));}async function _0x2ed077(_0x2bd19c,_0x3483ba){const _0x49cca9=_0x46de43;return _0x42d7e4['llm'][_0x49cca9(0x198)]({'provider':U,'model':_0x2bd19c,'reasoningEffort':_0x5e754f(_0x3483ba)});}async function _0x5ed84f(_0xff732){const _0x373733=_0x46de43;if(_0x58d27f||_0x5d4be7)throw Error(_0x373733(0x13e));if(await _0x5db976(_0xff732['cwd'])!==await _0x5db976(process[_0x373733(0x180)]()))throw Error(_0x373733(0x130));_0x4cc967=await _0x2ed077(_0xff732['model'],_0xff732[_0x373733(0x19a)]),_0x184dcc=_0x4cc967;let _0x3ace9e=(_0x25bd40,_0x275f7c)=>{const _0x274894=_0x373733;if(_0x25bd40['on'](_0x274894(0x114),async(_0x5326c6,_0x35389c,_0x526813)=>{const _0x149878=_0x274894;let _0x50c10f=await _0x526813();if(_0x35389c[_0x149878(0x173)]!==_0x275f7c)return _0x50c10f;return{..._0x50c10f,'variables':{..._0x50c10f[_0x149878(0x12b)],'provider':_0x184dcc['provider'],'model':_0x184dcc[_0x149878(0xef)]}};}),_0x25bd40['on']('agent/request',async(_0x10d4a1,_0x4e37c4)=>{let _0x20df26=await _0x4e37c4();return _0x10d4a1['agent']===_0x275f7c?{..._0x20df26,..._0x184dcc}:_0x20df26;}),_0xff732[_0x274894(0x11e)]===!0x1)_0x25bd40['tools']['restrict']({'deny':[_0x274894(0x189)]});if(_0xff732['allowedTools'])_0x25bd40[_0x274894(0xe1)][_0x274894(0x146)]({'allow':_0xff732[_0x274894(0x118)]});if(_0xff732['developerInstructions'])_0x25bd40[_0x274894(0x117)]['section']({'name':_0x274894(0x174),'order':0x3e7,'text':_0xff732[_0x274894(0x161)]});Object['assign'](_0x275f7c[_0x274894(0x176)],_0x4cc967);},_0x2dfebe=_0xff732[_0x373733(0xf6)];if(![_0x373733(0x196),_0x373733(0x17a),_0x373733(0x100)]['includes'](_0x2dfebe['kind']))throw Error(_0x373733(0x141));if(_0x2dfebe[_0x373733(0xea)]!==_0x373733(0x196)){if(_0x2dfebe[_0x373733(0x115)][_0x373733(0x193)]!==_0x373733(0x128)||_0x2dfebe['source'][_0x373733(0x180)]!==_0xff732['cwd'])throw Error(_0x373733(0xdf));let _0x1d127d=await _0x42d7e4[_0x373733(0x19d)]['stat'](_0x2dfebe[_0x373733(0x115)][_0x373733(0x102)]);if(!_0x1d127d||!_0x1d127d[_0x373733(0x16b)][_0x373733(0x180)]||await _0x5db976(_0x1d127d[_0x373733(0x16b)][_0x373733(0x180)])!==await _0x5db976(_0xff732['cwd']))throw Error(_0x373733(0x143));}_0x5d4be7=_0x2dfebe[_0x373733(0xea)]===_0x373733(0x17a)?_0x2dfebe[_0x373733(0x115)][_0x373733(0x102)]:_0x373733(0x17f)[_0x373733(0x165)](_0x479590()),_0x2f8d1a=void 0x0;try{if(_0x421717[_0x373733(0x13b)][_0x373733(0x149)](),_0x2dfebe[_0x373733(0xea)]===_0x373733(0x17a))_0x58d27f=await _0x42d7e4[_0x373733(0x19f)][_0x373733(0x17a)]({'resumeSessionId':_0x5d4be7,'agentOptions':_0x4cc967,'setup':_0x3ace9e,'signal':_0x421717[_0x373733(0x13b)]});else{if(_0x2dfebe[_0x373733(0xea)]===_0x373733(0x100)){let _0x330036=await _0x42d7e4[_0x373733(0x19d)][_0x373733(0x148)](_0x2dfebe['source'][_0x373733(0x102)],_0x373733(0xf1)),_0x499e77;try{_0x499e77=(await _0x330036[_0x373733(0xf1)]())['events'];}finally{await _0x330036['close']();}let _0x150822=_0x2dfebe[_0x373733(0xec)];if(_0x150822&&(_0x150822[_0x373733(0x193)]!==_0x373733(0x128)||_0x150822[_0x373733(0xea)]!=='event'||_0x150822[_0x373733(0x115)]['sessionId']!==_0x2dfebe['source']['sessionId']||!/^\d+$/['test'](_0x150822['id'])||!Number[_0x373733(0x10b)](Number(_0x150822['id']))))throw Error('invalid\x20DSH\x20fork\x20checkpoint');let _0x3a0a6a=_0x150822?_0x499e77[_0x373733(0x182)](_0xb838f5=>_0xb838f5['seq']===Number(_0x150822['id'])&&_0xb838f5[_0x373733(0x134)]===_0x373733(0xf5)):[..._0x499e77][_0x373733(0x105)]()['find'](_0x2249c9=>_0x2249c9[_0x373733(0x134)]==='turn/end');if(!_0x3a0a6a)throw Error('DSH\x20fork\x20source\x20has\x20no\x20completed\x20turn\x20at\x20requested\x20checkpoint');let _0x493527=_0x499e77[_0x373733(0x158)](0x0,_0x3a0a6a[_0x373733(0xee)]+0x1);_0x58d27f=await _0x42d7e4[_0x373733(0x19f)][_0x373733(0x104)]({'sessionId':_0x5d4be7,'seed':_0x493527,'inheritedEventCount':_0x35365f(_0x493527[_0x373733(0xe7)]),'meta':{'cwd':_0xff732[_0x373733(0x180)],'parentSession':_0x2dfebe[_0x373733(0x115)][_0x373733(0x102)],'isSeeded':!0x0},'agentOptions':_0x4cc967,'setup':_0x3ace9e,'signal':_0x421717['signal']});}else _0x58d27f=await _0x42d7e4[_0x373733(0x19f)][_0x373733(0x104)]({'sessionId':_0x5d4be7,'meta':{'cwd':_0xff732['cwd']},'agentOptions':_0x4cc967,'setup':_0x3ace9e,'signal':_0x421717[_0x373733(0x13b)]});}return await _0x42d7e4[_0x373733(0x19d)][_0x373733(0x132)](),_0x421717[_0x373733(0x13b)][_0x373733(0x149)](),{'sessionId':_0x5d4be7,'models':await _0x37c0a0([_0xff732[_0x373733(0xef)]])};}catch(_0x5582da){if(!_0x58d27f)_0x5d4be7=void 0x0;throw _0x5582da;}}async function _0x2b0303(_0xeadf2e,_0x5ab622){const _0xa28226=_0x46de43;if(_0x57f134&&_0xeadf2e!==_0xa28226(0xfa))throw Error(_0xa28226(0x18b));if(_0xeadf2e===_0xa28226(0x13c)){if(_0x2b2790)throw Error(_0xa28226(0x12c));await _0x42d7e4[_0xa28226(0x163)](_0xa28226(0x125))?.[_0xa28226(0x103)](),_0x2b2790=!0x0;let _0x2e1a8c=_0x9e36bc(import.meta.url),_0x13b440=JSON[_0xa28226(0x169)](_0x5d1b06(_0x2e1a8c['resolve'](_0xa28226(0x1a3)),_0xa28226(0x15a)));return{'protocolVersion':m,'runtimeVersion':_0x13b440[_0xa28226(0x177)]};}if(!_0x2b2790)throw Error(_0xa28226(0x135));switch(_0xeadf2e){case _0xa28226(0x16e):return _0x37c0a0(_0x5ab622[_0xa28226(0x190)]??[]);case _0xa28226(0x101):{if(_0x2849a0)throw Error(_0xa28226(0x14b));_0x2849a0=_0x5ed84f(_0x5ab622);try{return await _0x2849a0;}finally{_0x2849a0=void 0x0;}}case _0xa28226(0x18a):{if(await _0x5db976(_0x5ab622['cwd'])!==await _0x5db976(process[_0xa28226(0x180)]()))throw Error(_0xa28226(0x123));let _0x2b0cf6=await _0x42d7e4[_0xa28226(0x19d)][_0xa28226(0x12a)](),_0x267a9f=[];for(let {header:_0x4c5809}of[..._0x2b0cf6][_0xa28226(0x17b)]((_0x56301b,_0x4a6e32)=>_0x4a6e32[_0xa28226(0x16b)][_0xa28226(0x19c)]-_0x56301b[_0xa28226(0x16b)][_0xa28226(0x19c)])){if(_0x4c5809['origin']===_0xa28226(0xf8)||_0x4c5809[_0xa28226(0x180)]!==_0x5ab622[_0xa28226(0x180)])continue;let _0x504621=await _0x42d7e4['sessionPersistence'][_0xa28226(0x148)](_0x4c5809['id'],_0xa28226(0xf1)),_0x4eea03=_0x4c5809['id'],_0x1fc7eb;try{let {events:_0x55a041}=await _0x504621[_0xa28226(0xf1)](),_0x4a23cb=_0x559212=>{const _0x25631b=_0xa28226;if(_0x559212?.[_0x25631b(0x134)]!==_0x25631b(0xf4)||_0x559212[_0x25631b(0x110)][_0x25631b(0x115)]['kind']!==_0x25631b(0xe8))return'';return _0x559212['data'][_0x25631b(0x162)][_0x25631b(0x140)](_0x1b048c=>_0x1b048c[_0x25631b(0x134)]===_0x25631b(0x11d))['map'](_0x46bb9f=>_0x46bb9f[_0x25631b(0x11d)])[_0x25631b(0xeb)]('\x20')[_0x25631b(0x16f)](/\s+/g,'\x20')[_0x25631b(0x16a)]();};for(let _0x483c2d of _0x55a041){let _0x21423a=_0x4a23cb(_0x483c2d);if(_0x21423a){_0x4eea03=_0x21423a[_0xa28226(0x158)](0x0,0x78);break;}}for(let _0x40e4f7=_0x55a041[_0xa28226(0xe7)]-0x1;_0x40e4f7>=0x0;_0x40e4f7--){let _0x46549f=_0x4a23cb(_0x55a041[_0x40e4f7]);if(_0x46549f){_0x1fc7eb=_0x46549f[_0xa28226(0x158)](0x0,0x78);break;}}}finally{await _0x504621['close']();}_0x267a9f[_0xa28226(0x144)]({'provider':'dsh','sessionId':_0x4c5809['id'],'cwd':_0x4c5809[_0xa28226(0x180)],'ts':_0x4c5809['createdAt'],'preview':_0x4eea03,..._0x1fc7eb&&_0x1fc7eb!==_0x4eea03?{'lastPreview':_0x1fc7eb}:{}});}return _0x267a9f['sort']((_0x415493,_0x3091fd)=>_0x3091fd['ts']-_0x415493['ts']);}case _0xa28226(0x1a0):return _0x13fb5c(),_0x4cc967=await _0x2ed077(_0x5ab622[_0xa28226(0xef)],_0x5ab622[_0xa28226(0x19a)]),{};case _0xa28226(0x13a):{let _0x139f67=_0x13fb5c(),_0x36af54=_0x16be14,_0x22dd1=_0x5ab622['mode']===_0xa28226(0xe2);if(_0x22dd1&&(typeof _0x5ab622[_0xa28226(0x171)]!==_0xa28226(0xf7)||!_0x5ab622['inputId']||typeof _0x5ab622[_0xa28226(0xe0)]!==_0xa28226(0xf7)))throw Error(_0xa28226(0x197));let _0x7943=()=>_0x139f67['status']===_0xa28226(0xfb)&&String(_0x12b516)===_0x5ab622['expectedTurnId']&&_0x2f8d1a?.[_0xa28226(0x110)][_0xa28226(0x10a)]!==_0x12b516;if(_0x22dd1&&!_0x7943())return{'accepted':!0x1};if(!Array['isArray'](_0x5ab622[_0xa28226(0x162)])||!_0x5ab622[_0xa28226(0x162)][_0xa28226(0xe7)])throw Error(_0xa28226(0x154));if(_0x5ab622[_0xa28226(0x162)]['some'](_0x3dce66=>_0x3dce66[_0xa28226(0x134)]===_0xa28226(0x195))){let _0x553e10=(_0x22dd1?_0x184dcc:_0x4cc967)[_0xa28226(0xef)];if(!(await _0x42d7e4[_0xa28226(0x166)][_0xa28226(0xf9)](U,_0x553e10))[_0xa28226(0x108)]?.[_0xa28226(0x159)](_0xa28226(0x195)))throw Error(_0xa28226(0xfe)['concat'](_0x553e10,_0xa28226(0x126)));}let _0xefed22=await _0x42d7e4[_0xa28226(0xe6)][_0xa28226(0xfc)](_0x5ab622[_0xa28226(0x162)]);if(_0x57f134||_0x36af54!==_0x16be14)throw Error(_0xa28226(0x15d));if(_0x22dd1&&!_0x7943())return{'accepted':!0x1};let _0xdb6571=_0x363e32({'content':_0xefed22,'source':{'kind':'user'}}),_0x356533=_0x5ab622[_0xa28226(0x179)]==='auto'?_0x139f67[_0xa28226(0x137)]===_0xa28226(0xfb)?_0xa28226(0xe2):_0xa28226(0x139):_0x5ab622['mode'];if(_0x356533==='steer'){if(_0x22dd1)_0x1a899d[_0xa28226(0x194)](_0xdb6571['id'],_0x5ab622['inputId']);try{_0x139f67['steer'](_0xdb6571);}catch(_0x49834f){throw _0x1a899d[_0xa28226(0x164)](_0xdb6571['id']),_0x49834f;}}else{if(_0x356533===_0xa28226(0x139))_0x139f67[_0xa28226(0x183)](_0xdb6571);else throw Error('invalid\x20DSH\x20input\x20mode');}return{'messageId':_0xdb6571['id'],..._0x22dd1?{'accepted':!0x0,'inputId':_0x5ab622['inputId']}:{}};}case _0xa28226(0x187):return _0x16be14++,_0x1a899d[_0xa28226(0x15e)](),_0x13fb5c()[_0xa28226(0xe3)](Object[_0xa28226(0x121)]({'kind':_0xa28226(0xe8)})),{};case _0xa28226(0x1a6):{let _0xd561b9=_0x2c0ebc[_0xa28226(0x163)](_0x5ab622['id']);if(!_0xd561b9)throw Error(_0xa28226(0x1a1));if(_0x5ab622[_0xa28226(0x18d)])_0xd561b9[_0xa28226(0x11b)](Error(String(_0x5ab622['error'])));else _0xd561b9['resolve']({'answers':_0x5ab622['answers']});return _0x2c0ebc[_0xa28226(0x164)](_0x5ab622['id']),{};}case _0xa28226(0x170):{let _0x2b8842=_0x13fb5c();if(_0x2b8842[_0xa28226(0x137)]!==_0xa28226(0x124))throw Error(_0xa28226(0xf2));let _0x28d2cf=await _0x42d7e4[_0xa28226(0x152)]['compactNow'](_0x2b8842,new AbortController()[_0xa28226(0x13b)]);return await _0x42d7e4[_0xa28226(0x19d)][_0xa28226(0x132)](),_0x28d2cf;}case'shutdown':{if(_0x57f134=!0x0,_0x16be14++,_0x1a899d['clear'](),_0x421717['abort'](Object[_0xa28226(0x121)]({'kind':_0xa28226(0x15f)})),_0x2849a0)try{await _0x2849a0;}catch{process['stderr']['write']('lodestar-dsh:\x20initialization\x20cancelled\x20during\x20shutdown\x0a');}for(let _0x1fefdb of _0x2c0ebc[_0xa28226(0x138)]())_0x1fefdb[_0xa28226(0x11b)](Error('DSH\x20shutdown'));if(_0x2c0ebc[_0xa28226(0x15e)](),_0x58d27f){for(let _0x569343 of _0x42d7e4[_0xa28226(0x19f)][_0xa28226(0x12a)]())if(_0x569343===_0x58d27f[_0xa28226(0x120)]||_0x42d7e4[_0xa28226(0x19f)][_0xa28226(0x17d)](_0x569343['id'],_0x58d27f[_0xa28226(0x120)]))_0x569343['cancel'](Object['freeze']({'kind':_0xa28226(0x15f)}));await _0x58d27f[_0xa28226(0x109)]();}return await _0x520c38,await _0x42d7e4[_0xa28226(0x19d)][_0xa28226(0x132)](),{};}default:throw Error(_0xa28226(0x160)[_0xa28226(0x165)](_0xeadf2e));}}let _0x454527=_0x3aa5f4({'input':process[_0x46de43(0x129)],'crlfDelay':0x1/0x0});_0x454527['on'](_0x46de43(0x157),_0x541e21=>{const _0x298750=_0x46de43;let _0x1c9928;try{if(_0x1c9928=JSON[_0x298750(0x169)](_0x541e21),_0x1c9928[_0x298750(0x150)]!==_0x298750(0x14c)||typeof _0x1c9928['id']!=='number'||typeof _0x1c9928[_0x298750(0x14d)]!=='string')throw Error(_0x298750(0x142));}catch(_0x5367d3){_0x315e97(_0x5367d3);return;}_0x2b0303(_0x1c9928[_0x298750(0x14d)],_0x1c9928['params'])[_0x298750(0x178)](_0x247cbb=>process['stdout'][_0x298750(0x186)](JSON['stringify']({'jsonrpc':_0x298750(0x14c),'id':_0x1c9928['id'],'result':_0x247cbb})+'\x0a'),_0x5f4bd5=>process[_0x298750(0x11c)][_0x298750(0x186)](JSON[_0x298750(0x14a)]({'jsonrpc':_0x298750(0x14c),'id':_0x1c9928['id'],'error':{'code':-0x7f5b,'message':_0x5f4bd5 instanceof Error?_0x5f4bd5[_0x298750(0x168)]:String(_0x5f4bd5)}})+'\x0a'));}),_0x42d7e4[_0x46de43(0x184)](()=>()=>{const _0x56f07c=_0x46de43;_0x454527[_0x56f07c(0x12d)]();});}function _0x818f(_0x6cdd53,_0x4559c5){_0x6cdd53=_0x6cdd53-0xdf;const _0x10cdeb=_0x10cd();let _0x818fd9=_0x10cdeb[_0x6cdd53];if(_0x818f['WzCXsK']===undefined){var _0x5a4c99=function(_0x49d1b5){const _0xc8a9e1='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x3bfe72='',_0x3aa5f4='';for(let _0x479590=0x0,_0x9e36bc,_0x5d1b06,_0x5db976=0x0;_0x5d1b06=_0x49d1b5['charAt'](_0x5db976++);~_0x5d1b06&&(_0x9e36bc=_0x479590%0x4?_0x9e36bc*0x40+_0x5d1b06:_0x5d1b06,_0x479590++%0x4)?_0x3bfe72+=String['fromCharCode'](0xff&_0x9e36bc>>(-0x2*_0x479590&0x6)):0x0){_0x5d1b06=_0xc8a9e1['indexOf'](_0x5d1b06);}for(let _0x363e32=0x0,_0x5e754f=_0x3bfe72['length'];_0x363e32<_0x5e754f;_0x363e32++){_0x3aa5f4+='%'+('00'+_0x3bfe72['charCodeAt'](_0x363e32)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x3aa5f4);};_0x818f['tRcXli']=_0x5a4c99,_0x818f['svxDFM']={},_0x818f['WzCXsK']=!![];}const _0x26d1d0=_0x10cdeb[0x0];_0x818f['yMIurm']!==_0x26d1d0&&(_0x818f['svxDFM']={},_0x818f['yMIurm']=_0x26d1d0);const _0x107480=_0x818f['svxDFM'][_0x6cdd53];return _0x107480===undefined?(_0x818fd9=_0x818f['tRcXli'](_0x818fd9),_0x818f['svxDFM'][_0x6cdd53]=_0x818fd9):_0x818fd9=_0x107480,_0x818fd9;}export{XB as name,YB as inject,ZB as apply};
|