@lmzhen/dsh-evolution-adapter 0.0.0 → 0.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/lib/index.js +12 -0
- package/lib/llm-9Y3qyl1T.js +304 -0
- package/lib/ports.js +2 -0
- package/lib/review-child.js +117 -0
- package/lib/service.js +50 -0
- package/lib/types/agents.d.ts +9 -0
- package/lib/types/agents.js +26 -0
- package/lib/types/commands.d.ts +9 -0
- package/lib/types/commands.js +9 -0
- package/lib/types/connection.d.ts +9 -0
- package/lib/types/connection.js +27 -0
- package/lib/types/index.d.ts +18 -0
- package/lib/types/index.js +10 -0
- package/lib/types/llm.d.ts +12 -0
- package/lib/types/llm.js +67 -0
- package/lib/types/platformView.d.ts +10 -0
- package/lib/types/platformView.js +29 -0
- package/lib/types/ports.d.ts +40 -0
- package/lib/types/ports.js +24 -0
- package/lib/types/presets.d.ts +9 -0
- package/lib/types/presets.js +31 -0
- package/lib/types/profileContext.d.ts +9 -0
- package/lib/types/profileContext.js +14 -0
- package/lib/types/projections.d.ts +9 -0
- package/lib/types/projections.js +34 -0
- package/lib/types/review-child.d.ts +45 -0
- package/lib/types/review-child.js +117 -0
- package/lib/types/service.d.ts +24 -0
- package/lib/types/service.js +63 -0
- package/lib/types/settings.d.ts +9 -0
- package/lib/types/settings.js +14 -0
- package/lib/types/skills.d.ts +9 -0
- package/lib/types/skills.js +9 -0
- package/lib/types/storageDomain.d.ts +9 -0
- package/lib/types/storageDomain.js +9 -0
- package/lib/types/subagents.d.ts +9 -0
- package/lib/types/subagents.js +17 -0
- package/lib/types/systemPrompt.d.ts +9 -0
- package/lib/types/systemPrompt.js +13 -0
- package/lib/types/tools.d.ts +15 -0
- package/lib/types/tools.js +24 -0
- package/lib/types/userQuestions.d.ts +9 -0
- package/lib/types/userQuestions.js +9 -0
- package/lib/types/values.d.ts +25 -0
- package/lib/types/values.js +15 -0
- package/lib/types/workingDirectory.d.ts +9 -0
- package/lib/types/workingDirectory.js +9 -0
- package/lib/values.js +8 -0
- package/locale/de.json +6 -0
- package/locale/en.json +6 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +59 -3
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# `@lmzhen/dsh-evolution-adapter`
|
|
2
|
+
|
|
3
|
+
The only host-facing package in the dsh-evolution family.
|
|
4
|
+
|
|
5
|
+
It owns:
|
|
6
|
+
|
|
7
|
+
- the platform port implementations (`agents`, `tools`, `llm`, `settings`,
|
|
8
|
+
`storageDomain`, `projections`, `connection`, `presets`, and the rest);
|
|
9
|
+
- the `evolutionPlatform` service, which exposes one live port table;
|
|
10
|
+
- the platform runtime helper values (`defineTool`, `createUserMessage`,
|
|
11
|
+
`escapeText`, `SessionId`, `withFileLock`, ...).
|
|
12
|
+
|
|
13
|
+
Feature packages must not import `@deepseek-ai/dsh-*`; they import contract
|
|
14
|
+
types and adapter helpers. The adapter is also the place where a real host API
|
|
15
|
+
shape difference is normalized; business code never branches on a DSH version.
|
|
16
|
+
|
|
17
|
+
## Detached review child
|
|
18
|
+
|
|
19
|
+
`@lmzhen/dsh-evolution-adapter/review-child` exports `createReviewChildAgent(parent, taskId, options)`. It creates a live child `Session` through the public Session store, makes the child object the scope key of a real `createScope` context, and assigns that context to the child. When PTC is requested it probes the platform's optional `@deepseek-ai/dsh-tool-executor-ptc` package by export shape and mounts that executor in the child scope; a missing/incompatible package fails with `PTC_UNAVAILABLE`, never a version guess. The child stays detached from the parent lineage, so PTC nested `tool/ptc-dispatch*` frames land on the child and never touch the parent Session. The PTC package is not a family dependency: the platform base bundle ships it disabled and the PTC preset enables it.
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { _ as pluginManagerPort, a as toolsPort, b as commandsPort, c as userQuestionsPort, d as connectionPort, f as storageDomainPort, g as pluginInventoryPort, h as configEditorPort, i as registerEvolutionTool, l as subagentsPort, m as workingDirectoryPort, n as llmPort, o as projectionPort, p as skillsPort, r as modelRoute, s as presetsPort, t as EvolutionLlmError, u as systemPromptPort, v as profileContextPort, x as agentsPort, y as settingsPort } from "./llm-9Y3qyl1T.js";
|
|
2
|
+
import { EvolutionPlatform } from "./service.js";
|
|
3
|
+
import "./ports.js";
|
|
4
|
+
import { BlockAssembler, DomainError, SessionId, createToolResultMessage, createUserMessage, defineDomain, defineTool, domainTable, escapeText, scopeOf, withFileLock } from "./values.js";
|
|
5
|
+
//#region lib/types/index.js
|
|
6
|
+
const name = "evolution-adapter";
|
|
7
|
+
/** Mount the one host platform service; bundle row order places this before core/runtime. */
|
|
8
|
+
async function apply(ctx) {
|
|
9
|
+
await ctx.plugin(EvolutionPlatform);
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { BlockAssembler, DomainError, EvolutionLlmError, EvolutionPlatform, SessionId, agentsPort, apply, commandsPort, configEditorPort, connectionPort, createToolResultMessage, createUserMessage, defineDomain, defineTool, domainTable, escapeText, llmPort, modelRoute, name, pluginInventoryPort, pluginManagerPort, presetsPort, profileContextPort, projectionPort, registerEvolutionTool, scopeOf, settingsPort, skillsPort, storageDomainPort, subagentsPort, systemPromptPort, toolsPort, userQuestionsPort, withFileLock, workingDirectoryPort };
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { EvolutionLlmError, EvolutionLlmError as EvolutionLlmError$1 } from "@lmzhen/dsh-evolution-platform-contract";
|
|
2
|
+
import { err, ok } from "@lmzhen/dsh-evolution-platform-contract/result";
|
|
3
|
+
//#region lib/types/agents.js
|
|
4
|
+
const asIdentity = (value) => {
|
|
5
|
+
if (value === null || typeof value !== "object") return void 0;
|
|
6
|
+
return typeof value.id === "string" ? value : void 0;
|
|
7
|
+
};
|
|
8
|
+
/** Resolve the agents port; undefined means the host has no agents service. */
|
|
9
|
+
function agentsPort(ctx) {
|
|
10
|
+
const agents = ctx.get("agents");
|
|
11
|
+
if (agents === void 0) return void 0;
|
|
12
|
+
if (typeof agents.get !== "function" && typeof agents.list !== "function") return void 0;
|
|
13
|
+
const get = typeof agents.get === "function" ? agents.get.bind(agents) : void 0;
|
|
14
|
+
const list = typeof agents.list === "function" ? agents.list.bind(agents) : void 0;
|
|
15
|
+
return {
|
|
16
|
+
get: (id) => get === void 0 ? void 0 : asIdentity(get(id)),
|
|
17
|
+
list: () => list === void 0 ? [] : list().map(asIdentity).filter((agent) => agent !== void 0),
|
|
18
|
+
isRoot: (agent) => {
|
|
19
|
+
const live = get === void 0 ? void 0 : asIdentity(get(agent.id));
|
|
20
|
+
return live !== void 0 && live === agent && live.session?.header?.origin !== "subagent";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region lib/types/commands.js
|
|
26
|
+
/** Resolve the commands port; undefined means the host has no commands service. */
|
|
27
|
+
function commandsPort(ctx) {
|
|
28
|
+
const service = ctx.get("commands");
|
|
29
|
+
if (service === void 0 || typeof service.register !== "function") return void 0;
|
|
30
|
+
return { register: (definition) => service.register(definition) };
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region lib/types/settings.js
|
|
34
|
+
/** Resolve the settings port; undefined means the host has no settings service. */
|
|
35
|
+
function settingsPort(ctx) {
|
|
36
|
+
const service = ctx.get("settings");
|
|
37
|
+
if (service === void 0) return void 0;
|
|
38
|
+
if (typeof service.configure !== "function" && typeof service.describe !== "function") return void 0;
|
|
39
|
+
return {
|
|
40
|
+
...typeof service.configure === "function" ? { configure: (options, owner) => service.configure(options, owner) } : {},
|
|
41
|
+
...typeof service.describe === "function" ? { describe: (options) => service.describe(options) } : {}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region lib/types/profileContext.js
|
|
46
|
+
/** Resolve the profile-context port; undefined means no profile is mounted. */
|
|
47
|
+
function profileContextPort(ctx) {
|
|
48
|
+
const service = ctx.get("profileContext");
|
|
49
|
+
if (service === void 0 || typeof service.dir !== "string" || service.dir === "") return void 0;
|
|
50
|
+
return {
|
|
51
|
+
name: typeof service.name === "string" ? service.name : "",
|
|
52
|
+
dir: service.dir,
|
|
53
|
+
...typeof service.patchPath === "string" && service.patchPath !== "" ? { patchPath: service.patchPath } : {},
|
|
54
|
+
...Array.isArray(service.startedBundles) ? { startedBundles: service.startedBundles } : {}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region lib/types/platformView.js
|
|
59
|
+
function pluginManagerPort(ctx) {
|
|
60
|
+
const service = ctx.get("pluginManager");
|
|
61
|
+
if (service === void 0) return void 0;
|
|
62
|
+
return {
|
|
63
|
+
...typeof service.listBundles === "function" ? { listBundles: () => service.listBundles() } : {},
|
|
64
|
+
...typeof service.listPlugins === "function" ? { listPlugins: () => service.listPlugins() } : {}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function pluginInventoryPort(ctx) {
|
|
68
|
+
const service = ctx.get("pluginInventory");
|
|
69
|
+
if (service === void 0) return void 0;
|
|
70
|
+
return { ...typeof service.list === "function" ? { list: () => service.list() } : {} };
|
|
71
|
+
}
|
|
72
|
+
function configEditorPort(ctx) {
|
|
73
|
+
const service = ctx.get("configEditor");
|
|
74
|
+
if (service === void 0) return void 0;
|
|
75
|
+
return { ...typeof service.configuration === "function" ? { configuration: () => service.configuration() } : {} };
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region lib/types/workingDirectory.js
|
|
79
|
+
/** Resolve the working-directory port; undefined means the host has no such service. */
|
|
80
|
+
function workingDirectoryPort(ctx) {
|
|
81
|
+
const service = ctx.get("workingDirectory");
|
|
82
|
+
if (service === void 0 || typeof service.ensure !== "function") return void 0;
|
|
83
|
+
return { ensure: (agent, signal) => service.ensure(agent, signal) };
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region lib/types/skills.js
|
|
87
|
+
/** Resolve the skills port; undefined means the host has no skills service. */
|
|
88
|
+
function skillsPort(ctx) {
|
|
89
|
+
const service = ctx.get("skills");
|
|
90
|
+
if (service === void 0 || typeof service.list !== "function") return void 0;
|
|
91
|
+
return { list: (options) => service.list(options) };
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region lib/types/storageDomain.js
|
|
95
|
+
/** Resolve the storage-domain port; undefined means the host has no provider. */
|
|
96
|
+
function storageDomainPort(ctx) {
|
|
97
|
+
const service = ctx.get("storageDomain");
|
|
98
|
+
if (service === void 0 || typeof service.open !== "function") return void 0;
|
|
99
|
+
return { open: (spec) => service.open(spec) };
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region lib/types/connection.js
|
|
103
|
+
const REGISTER_REQUIRED = "connection.fetch.register() is required to register family host routes (platform >= 0.2.2-rc.1); no fallback admission path exists";
|
|
104
|
+
/** Resolve the connection port; undefined means the host has no connection service. */
|
|
105
|
+
function connectionPort(ctx) {
|
|
106
|
+
const connection = ctx.get("connection");
|
|
107
|
+
if (connection === void 0) return void 0;
|
|
108
|
+
const register = (route) => {
|
|
109
|
+
if (connection.fetch === void 0 || typeof connection.fetch.register !== "function") throw new Error(REGISTER_REQUIRED);
|
|
110
|
+
return connection.fetch.register.call(connection.fetch, route);
|
|
111
|
+
};
|
|
112
|
+
return {
|
|
113
|
+
allowsRemoteAuthorities: connection.allowsRemoteAuthorities === true,
|
|
114
|
+
register,
|
|
115
|
+
tryRegister: (route) => {
|
|
116
|
+
try {
|
|
117
|
+
return ok(register(route));
|
|
118
|
+
} catch (error) {
|
|
119
|
+
return err({
|
|
120
|
+
code: "E-325",
|
|
121
|
+
message: error instanceof Error ? error.message : String(error)
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region lib/types/systemPrompt.js
|
|
129
|
+
/** Resolve the system-prompt port; undefined means the host has no such service. */
|
|
130
|
+
function systemPromptPort(ctx) {
|
|
131
|
+
const service = ctx.get("systemPrompt");
|
|
132
|
+
if (service === void 0 || typeof service.section !== "function" || typeof service.variable !== "function") return void 0;
|
|
133
|
+
return {
|
|
134
|
+
section: (section) => service.section(section),
|
|
135
|
+
variable: (name, provider) => service.variable(name, provider),
|
|
136
|
+
...typeof service.context === "function" ? { context: (context) => service.context(context) } : {}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region lib/types/subagents.js
|
|
141
|
+
/** Resolve the subagents port; undefined means the host has no subagents service. */
|
|
142
|
+
function subagentsPort(ctx) {
|
|
143
|
+
const subagents = ctx.get("subagents");
|
|
144
|
+
if (subagents === void 0 || typeof subagents.getProvider !== "function" || typeof subagents.startActivation !== "function") return void 0;
|
|
145
|
+
return {
|
|
146
|
+
getProvider: (name) => subagents.getProvider(name),
|
|
147
|
+
start: (spec) => subagents.startActivation(spec),
|
|
148
|
+
...typeof subagents.sendMessage === "function" ? { sendMessage: (sender, targetId, content, options) => subagents.sendMessage(sender, targetId, content, options) } : {}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region lib/types/userQuestions.js
|
|
153
|
+
/** Resolve the user-questions port; undefined means the host has no such service. */
|
|
154
|
+
function userQuestionsPort(ctx) {
|
|
155
|
+
const service = ctx.get("userQuestions");
|
|
156
|
+
if (service === void 0 || typeof service.ask !== "function") return void 0;
|
|
157
|
+
return { ask: (request) => service.ask(request) };
|
|
158
|
+
}
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region lib/types/presets.js
|
|
161
|
+
/** Resolve the preset registry facade; undefined when the host has no agentPresets service. */
|
|
162
|
+
function presetsPort(ctx) {
|
|
163
|
+
const registry = ctx.get("agentPresets");
|
|
164
|
+
if (registry === void 0) return void 0;
|
|
165
|
+
return {
|
|
166
|
+
readDocument: (id) => {
|
|
167
|
+
if (registry.readDocument === void 0) throw new Error("agentPresets service has no readDocument()");
|
|
168
|
+
return registry.readDocument(id);
|
|
169
|
+
},
|
|
170
|
+
register: (definition) => {
|
|
171
|
+
if (registry.register === void 0) throw new Error("agentPresets service has no register()");
|
|
172
|
+
return registry.register(definition);
|
|
173
|
+
},
|
|
174
|
+
resolve: (id) => {
|
|
175
|
+
if (registry.resolve === void 0) throw new Error("agentPresets service has no resolve()");
|
|
176
|
+
return registry.resolve(id);
|
|
177
|
+
},
|
|
178
|
+
mount: (target, id) => {
|
|
179
|
+
if (registry.mount === void 0) throw new Error("agentPresets service has no mount()");
|
|
180
|
+
return registry.mount(target, id);
|
|
181
|
+
},
|
|
182
|
+
composedPreset: (target) => registry.composedPreset?.(target)
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region lib/types/projections.js
|
|
187
|
+
const isHandle = (value) => value !== null && typeof value === "object" && typeof value.stateOf === "function" && typeof value.dispose === "function";
|
|
188
|
+
/** Resolve the projection port; undefined means the host has no projection registry. */
|
|
189
|
+
function projectionPort(ctx) {
|
|
190
|
+
const registry = ctx.get("sessionProjections");
|
|
191
|
+
if (registry === void 0) return void 0;
|
|
192
|
+
let shape = "unrecognised";
|
|
193
|
+
let reason = "sessionProjections.register has not answered yet";
|
|
194
|
+
return {
|
|
195
|
+
get shape() {
|
|
196
|
+
return shape;
|
|
197
|
+
},
|
|
198
|
+
get reason() {
|
|
199
|
+
return shape === "unrecognised" ? reason : void 0;
|
|
200
|
+
},
|
|
201
|
+
async register(definition) {
|
|
202
|
+
const resolved = await registry.register(definition);
|
|
203
|
+
if (isHandle(resolved)) {
|
|
204
|
+
shape = "handle";
|
|
205
|
+
reason = void 0;
|
|
206
|
+
return {
|
|
207
|
+
stateOf: (session) => resolved.stateOf(session),
|
|
208
|
+
dispose: () => resolved.dispose()
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
shape = "unrecognised";
|
|
212
|
+
reason = "sessionProjections.register returned " + (resolved === null ? "null" : typeof resolved) + " without a projection handle";
|
|
213
|
+
return {
|
|
214
|
+
stateOf: () => void 0,
|
|
215
|
+
dispose: async () => {}
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region lib/types/tools.js
|
|
222
|
+
/**
|
|
223
|
+
* Resolve the tools port from a context; undefined means the host has no tools service.
|
|
224
|
+
* platform-declaration anchor: tools is declared in core PLATFORM_SERVICE_PROBES.
|
|
225
|
+
*/
|
|
226
|
+
function toolsPort(ctx) {
|
|
227
|
+
const tools = ctx.get("tools");
|
|
228
|
+
if (tools === void 0) return void 0;
|
|
229
|
+
return {
|
|
230
|
+
register: (definition, options) => tools.register(definition, options),
|
|
231
|
+
guard: (guard) => tools.guard(guard),
|
|
232
|
+
restrict: (filter) => tools.restrict(filter),
|
|
233
|
+
get: (name, scope) => tools.get(name, scope),
|
|
234
|
+
...typeof tools.resolve === "function" ? { resolve: (context) => tools.resolve(context) } : {},
|
|
235
|
+
...typeof tools.execute === "function" ? { execute: (input) => tools.execute(input) } : {}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
/** Register one family tool through the port; a missing service yields a no-op disposer. */
|
|
239
|
+
function registerEvolutionTool(ctx, definition) {
|
|
240
|
+
return toolsPort(ctx)?.register(definition) ?? (() => {});
|
|
241
|
+
}
|
|
242
|
+
//#endregion
|
|
243
|
+
//#region lib/types/llm.js
|
|
244
|
+
function toOptions(request) {
|
|
245
|
+
return {
|
|
246
|
+
provider: request.provider,
|
|
247
|
+
model: request.model,
|
|
248
|
+
messages: request.messages,
|
|
249
|
+
...request.maxTokens === void 0 ? {} : { maxTokens: request.maxTokens },
|
|
250
|
+
...request.temperature === void 0 ? {} : { temperature: request.temperature },
|
|
251
|
+
...request.signal === void 0 ? {} : { signal: request.signal },
|
|
252
|
+
purpose: request.purpose
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
/** Resolve the LLM port; undefined means the host has no llm service. */
|
|
256
|
+
function llmPort(ctx) {
|
|
257
|
+
const llm = ctx.get("llm");
|
|
258
|
+
if (llm === void 0) return void 0;
|
|
259
|
+
const port = {
|
|
260
|
+
async *stream(request) {
|
|
261
|
+
const options = toOptions(request);
|
|
262
|
+
if (llm.stream === void 0) throw new EvolutionLlmError("transport", "llm service has no stream()");
|
|
263
|
+
yield* llm.stream(options);
|
|
264
|
+
},
|
|
265
|
+
...llm.stream === void 0 ? {} : { streamRaw: (options) => llm.stream(options) },
|
|
266
|
+
async completeText(request) {
|
|
267
|
+
let text = "";
|
|
268
|
+
for await (const chunk of port.stream(request)) {
|
|
269
|
+
const frame = chunk;
|
|
270
|
+
if (frame.type === "text-delta" || frame.type === "text") text += typeof frame.text === "string" ? frame.text : "";
|
|
271
|
+
if (frame.type === "finish" && frame.reason?.kind === "error") {
|
|
272
|
+
const failure = frame.reason.failure;
|
|
273
|
+
const message = failure?.message;
|
|
274
|
+
throw new EvolutionLlmError(failure?.code === "CONTENT_REFUSED" ? "content-refused" : "transport", "model call failed: " + (typeof message === "string" ? message : "unknown"));
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return text;
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
return port;
|
|
281
|
+
}
|
|
282
|
+
/** Resolve the model route: agent-owned selection first, deployment default second. */
|
|
283
|
+
function modelRoute(ctx, agent, session) {
|
|
284
|
+
const owned = agent?.model?.current?.();
|
|
285
|
+
if (owned !== void 0) return {
|
|
286
|
+
provider: owned.provider,
|
|
287
|
+
model: owned.model
|
|
288
|
+
};
|
|
289
|
+
if (session !== void 0) {
|
|
290
|
+
const value = ctx.get("sessionProjections")?.snapshot?.(session, ["modelSelection"])?.values?.modelSelection;
|
|
291
|
+
const chosen = value?.next ?? value?.lastUsed;
|
|
292
|
+
if (chosen !== void 0 && chosen !== null) return {
|
|
293
|
+
provider: chosen.provider,
|
|
294
|
+
model: chosen.model
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
const fallback = ctx.get("agentDefaultModel")?.currentSelection?.();
|
|
298
|
+
return fallback === void 0 ? void 0 : {
|
|
299
|
+
provider: fallback.provider,
|
|
300
|
+
model: fallback.model
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
//#endregion
|
|
304
|
+
export { pluginManagerPort as _, toolsPort as a, commandsPort as b, userQuestionsPort as c, connectionPort as d, storageDomainPort as f, pluginInventoryPort as g, configEditorPort as h, registerEvolutionTool as i, subagentsPort as l, workingDirectoryPort as m, llmPort as n, projectionPort as o, skillsPort as p, modelRoute as r, presetsPort as s, EvolutionLlmError$1 as t, systemPromptPort as u, profileContextPort as v, agentsPort as x, settingsPort as y };
|
package/lib/ports.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { _ as pluginManagerPort, a as toolsPort, b as commandsPort, c as userQuestionsPort, d as connectionPort, f as storageDomainPort, g as pluginInventoryPort, h as configEditorPort, i as registerEvolutionTool, l as subagentsPort, m as workingDirectoryPort, n as llmPort, o as projectionPort, p as skillsPort, r as modelRoute, s as presetsPort, t as EvolutionLlmError, u as systemPromptPort, v as profileContextPort, x as agentsPort, y as settingsPort } from "./llm-9Y3qyl1T.js";
|
|
2
|
+
export { EvolutionLlmError, agentsPort, commandsPort, configEditorPort, connectionPort, llmPort, modelRoute, pluginInventoryPort, pluginManagerPort, presetsPort, profileContextPort, projectionPort, registerEvolutionTool, settingsPort, skillsPort, storageDomainPort, subagentsPort, systemPromptPort, toolsPort, userQuestionsPort, workingDirectoryPort };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { createScope } from "@deepseek-ai/dsh-scope";
|
|
2
|
+
import { Session, SessionId } from "@deepseek-ai/dsh-session";
|
|
3
|
+
//#region lib/types/review-child.js
|
|
4
|
+
/**
|
|
5
|
+
* Detached review child agent.
|
|
6
|
+
*
|
|
7
|
+
* PTC's `run_code` appends its nested `tool/ptc-dispatch*` frames to
|
|
8
|
+
* `exec.agent.session`. A background review must never write those frames to the
|
|
9
|
+
* parent Session, so the review executor calls the model with a child agent whose
|
|
10
|
+
* `session` is a real, live Session created through the public Session store. The
|
|
11
|
+
* child object is also the scope key of a real scoped context, so the platform's
|
|
12
|
+
* executor selection can attach a PTC executor to this child without touching the
|
|
13
|
+
* parent. This Session is detached from the parent lineage, but is live in the
|
|
14
|
+
* SessionStore so platform tools can resolve its working directory and approval
|
|
15
|
+
* context; the parent Session's seq is therefore untouched.
|
|
16
|
+
*
|
|
17
|
+
* The PTC executor is a platform-provided optional capability, not a family
|
|
18
|
+
* dependency. It is loaded through a runtime probe, never through a declared
|
|
19
|
+
* peer, so one family artifact can remain valid across the declared cohort while
|
|
20
|
+
* a host without PTC mode fails with an explicit unavailable error.
|
|
21
|
+
*
|
|
22
|
+
* @module @lmzhen/dsh-evolution-adapter/review-child
|
|
23
|
+
*/
|
|
24
|
+
var __rewriteRelativeImportExtension = function(path, preserveJsx) {
|
|
25
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function(m, tsx, d, ext, cm) {
|
|
26
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : d + ext + "." + cm.toLowerCase() + "js";
|
|
27
|
+
});
|
|
28
|
+
return path;
|
|
29
|
+
};
|
|
30
|
+
/** The platform PTC executor is absent or not compatible with this host. */
|
|
31
|
+
var PtcExecutorUnavailableError = class extends Error {
|
|
32
|
+
code = "PTC_UNAVAILABLE";
|
|
33
|
+
constructor(reason) {
|
|
34
|
+
super("PTC executor unavailable: " + reason);
|
|
35
|
+
this.name = "PtcExecutorUnavailableError";
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
let nextChild = 0;
|
|
39
|
+
/**
|
|
40
|
+
* Probe the platform's optional PTC executor without declaring a family peer.
|
|
41
|
+
* Shape checks fail closed: a host may ship an older/newer package, but an
|
|
42
|
+
* incompatible export must surface as PTC_UNAVAILABLE, not as a generic startup
|
|
43
|
+
* crash. The version is intentionally not inferred from the package name.
|
|
44
|
+
*/
|
|
45
|
+
async function loadPtcExecutor() {
|
|
46
|
+
const specifier = "@deepseek-ai/dsh-tool-executor-ptc";
|
|
47
|
+
let module;
|
|
48
|
+
try {
|
|
49
|
+
module = await import(__rewriteRelativeImportExtension(
|
|
50
|
+
/* @vite-ignore */
|
|
51
|
+
specifier
|
|
52
|
+
));
|
|
53
|
+
} catch {
|
|
54
|
+
throw new PtcExecutorUnavailableError("platform package @deepseek-ai/dsh-tool-executor-ptc is not installed");
|
|
55
|
+
}
|
|
56
|
+
if (typeof module.apply !== "function") throw new PtcExecutorUnavailableError("@deepseek-ai/dsh-tool-executor-ptc has no apply() export");
|
|
57
|
+
if (module.inject !== void 0 && (!Array.isArray(module.inject) || !module.inject.every((item) => typeof item === "string"))) throw new PtcExecutorUnavailableError("@deepseek-ai/dsh-tool-executor-ptc has an incompatible inject export");
|
|
58
|
+
return module;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Create a detached review child agent.
|
|
62
|
+
* @param parent - the live parent agent; only its `session` is replaced.
|
|
63
|
+
* @param taskId - review task identity used in the child Session id.
|
|
64
|
+
*/
|
|
65
|
+
async function createReviewChildAgent(parent, taskId, options = {}) {
|
|
66
|
+
const childId = SessionId(`review-child:${taskId.replace(/[^A-Za-z0-9_.:-]/g, "_")}:${nextChild++}`);
|
|
67
|
+
const parentSession = parent.session;
|
|
68
|
+
const parentCtx = parent.ctx;
|
|
69
|
+
const cwd = typeof parentSession?.header?.cwd === "string" ? parentSession.header.cwd : void 0;
|
|
70
|
+
const agent = Object.create(parent);
|
|
71
|
+
let scope;
|
|
72
|
+
let child;
|
|
73
|
+
try {
|
|
74
|
+
if (parentCtx !== void 0 && typeof parentCtx.plugin === "function") {
|
|
75
|
+
scope = createScope(parentCtx, agent, { parent });
|
|
76
|
+
Object.defineProperty(agent, "ctx", {
|
|
77
|
+
value: scope.ctx,
|
|
78
|
+
enumerable: true,
|
|
79
|
+
configurable: false
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (scope !== void 0) {
|
|
83
|
+
const capture = Object.assign((inner) => {
|
|
84
|
+
child = inner.sessions.create(childId, cwd === void 0 ? void 0 : { meta: { cwd } });
|
|
85
|
+
}, { inject: ["sessions"] });
|
|
86
|
+
await scope.ctx.plugin(capture, {});
|
|
87
|
+
} else child = parentCtx?.sessions?.create(childId, cwd === void 0 ? void 0 : { meta: { cwd } }) ?? Session.create(childId);
|
|
88
|
+
if (child === void 0) throw new PtcExecutorUnavailableError("the platform has no session store for the child scope");
|
|
89
|
+
Object.defineProperty(agent, "session", {
|
|
90
|
+
value: child,
|
|
91
|
+
enumerable: true,
|
|
92
|
+
configurable: false
|
|
93
|
+
});
|
|
94
|
+
Object.defineProperty(agent, "id", {
|
|
95
|
+
value: child.id,
|
|
96
|
+
enumerable: true,
|
|
97
|
+
configurable: false
|
|
98
|
+
});
|
|
99
|
+
if (options.ptc === true) {
|
|
100
|
+
if (scope === void 0) throw new PtcExecutorUnavailableError("the parent has no scoped context");
|
|
101
|
+
const plugin = await loadPtcExecutor();
|
|
102
|
+
await scope.ctx.plugin(plugin, {});
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
agent,
|
|
106
|
+
session: child,
|
|
107
|
+
async dispose() {
|
|
108
|
+
await scope?.dispose();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
} catch (error) {
|
|
112
|
+
await scope?.dispose().catch(() => {});
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
export { PtcExecutorUnavailableError, createReviewChildAgent };
|
package/lib/service.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { _ as pluginManagerPort, a as toolsPort, b as commandsPort, c as userQuestionsPort, d as connectionPort, f as storageDomainPort, g as pluginInventoryPort, h as configEditorPort, l as subagentsPort, m as workingDirectoryPort, n as llmPort, o as projectionPort, p as skillsPort, s as presetsPort, u as systemPromptPort, v as profileContextPort, x as agentsPort, y as settingsPort } from "./llm-9Y3qyl1T.js";
|
|
2
|
+
import { Service } from "@deepseek-ai/cordis";
|
|
3
|
+
import { CONTRACT } from "@lmzhen/dsh-evolution-platform-contract";
|
|
4
|
+
//#region lib/types/service.js
|
|
5
|
+
/**
|
|
6
|
+
* The family's host capability service: one place that resolves the platform
|
|
7
|
+
* ports and reports which halves are available.
|
|
8
|
+
*/
|
|
9
|
+
/** Domain service owning the host port table. */
|
|
10
|
+
var EvolutionPlatform = class extends Service {
|
|
11
|
+
static inject = [];
|
|
12
|
+
/** The family-facing contract generation this adapter implements. */
|
|
13
|
+
contract = CONTRACT;
|
|
14
|
+
constructor(ctx) {
|
|
15
|
+
super(ctx, "evolutionPlatform");
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Resolve the host ports now. Consumers read this one table; they never fall
|
|
19
|
+
* back to a direct platform import (the second resolution D7 removed).
|
|
20
|
+
* Deliberately uncached: `ctx.get` is the capability lifecycle.
|
|
21
|
+
*/
|
|
22
|
+
get ports() {
|
|
23
|
+
return {
|
|
24
|
+
agents: agentsPort(this.ctx),
|
|
25
|
+
connection: connectionPort(this.ctx),
|
|
26
|
+
settings: settingsPort(this.ctx),
|
|
27
|
+
storageDomain: storageDomainPort(this.ctx),
|
|
28
|
+
workingDirectory: workingDirectoryPort(this.ctx),
|
|
29
|
+
pluginManager: pluginManagerPort(this.ctx),
|
|
30
|
+
pluginInventory: pluginInventoryPort(this.ctx),
|
|
31
|
+
configEditor: configEditorPort(this.ctx),
|
|
32
|
+
profileContext: profileContextPort(this.ctx),
|
|
33
|
+
skills: skillsPort(this.ctx),
|
|
34
|
+
commands: commandsPort(this.ctx),
|
|
35
|
+
systemPrompt: systemPromptPort(this.ctx),
|
|
36
|
+
subagents: subagentsPort(this.ctx),
|
|
37
|
+
userQuestions: userQuestionsPort(this.ctx),
|
|
38
|
+
projections: projectionPort(this.ctx),
|
|
39
|
+
llm: llmPort(this.ctx),
|
|
40
|
+
tools: toolsPort(this.ctx),
|
|
41
|
+
presets: presetsPort(this.ctx)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** Whether an exact live root agent is available for this id. */
|
|
45
|
+
isRootAgent(agent) {
|
|
46
|
+
return this.ports.agents?.isRoot(agent) === true;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
//#endregion
|
|
50
|
+
export { EvolutionPlatform };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agents implementation half of the family's platform boundary.
|
|
3
|
+
*/
|
|
4
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
5
|
+
import type { AgentsPort } from '@lmzhen/dsh-evolution-platform-contract';
|
|
6
|
+
export type { AgentIdentity, AgentsPort } from '@lmzhen/dsh-evolution-platform-contract';
|
|
7
|
+
/** Resolve the agents port; undefined means the host has no agents service. */
|
|
8
|
+
export declare function agentsPort(ctx: Context): AgentsPort | undefined;
|
|
9
|
+
//# sourceMappingURL=agents.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const asIdentity = (value) => {
|
|
2
|
+
if (value === null || typeof value !== 'object')
|
|
3
|
+
return undefined;
|
|
4
|
+
const id = value.id;
|
|
5
|
+
return typeof id === 'string' ? value : undefined;
|
|
6
|
+
};
|
|
7
|
+
/** Resolve the agents port; undefined means the host has no agents service. */
|
|
8
|
+
export function agentsPort(ctx) {
|
|
9
|
+
// platform-declaration anchor: agents is declared in core PLATFORM_SERVICE_PROBES.
|
|
10
|
+
const agents = ctx.get('agents');
|
|
11
|
+
if (agents === undefined)
|
|
12
|
+
return undefined;
|
|
13
|
+
if (typeof agents.get !== 'function' && typeof agents.list !== 'function')
|
|
14
|
+
return undefined;
|
|
15
|
+
const get = typeof agents.get === 'function' ? agents.get.bind(agents) : undefined;
|
|
16
|
+
const list = typeof agents.list === 'function' ? agents.list.bind(agents) : undefined;
|
|
17
|
+
return {
|
|
18
|
+
get: (id) => get === undefined ? undefined : asIdentity(get(id)),
|
|
19
|
+
list: () => list === undefined ? [] : list().map(asIdentity).filter((agent) => agent !== undefined),
|
|
20
|
+
isRoot: (agent) => {
|
|
21
|
+
const live = get === undefined ? undefined : asIdentity(get(agent.id));
|
|
22
|
+
return live !== undefined && live === agent && live.session?.header?.origin !== 'subagent';
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=agents.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The commands implementation half of the family's platform boundary.
|
|
3
|
+
*/
|
|
4
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
5
|
+
import type { CommandsPort } from '@lmzhen/dsh-evolution-platform-contract';
|
|
6
|
+
export type { CommandsPort } from '@lmzhen/dsh-evolution-platform-contract';
|
|
7
|
+
/** Resolve the commands port; undefined means the host has no commands service. */
|
|
8
|
+
export declare function commandsPort(ctx: Context): CommandsPort | undefined;
|
|
9
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Resolve the commands port; undefined means the host has no commands service. */
|
|
2
|
+
export function commandsPort(ctx) {
|
|
3
|
+
// platform-declaration anchor: commands is declared in core PLATFORM_SERVICE_PROBES.
|
|
4
|
+
const service = ctx.get('commands');
|
|
5
|
+
if (service === undefined || typeof service.register !== 'function')
|
|
6
|
+
return undefined;
|
|
7
|
+
return { register: (definition) => service.register(definition) };
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The connection implementation half of the family's platform boundary.
|
|
3
|
+
*/
|
|
4
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
5
|
+
import type { ConnectionPort } from '@lmzhen/dsh-evolution-platform-contract';
|
|
6
|
+
export type { ConnectionPort, ConnectionRegisterResult, ConnectionRoute } from '@lmzhen/dsh-evolution-platform-contract';
|
|
7
|
+
/** Resolve the connection port; undefined means the host has no connection service. */
|
|
8
|
+
export declare function connectionPort(ctx: Context): ConnectionPort | undefined;
|
|
9
|
+
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { err, ok } from '@lmzhen/dsh-evolution-platform-contract/result';
|
|
2
|
+
const REGISTER_REQUIRED = 'connection.fetch.register() is required to register family host routes (platform >= 0.2.2-rc.1); no fallback admission path exists';
|
|
3
|
+
/** Resolve the connection port; undefined means the host has no connection service. */
|
|
4
|
+
export function connectionPort(ctx) {
|
|
5
|
+
// platform-declaration anchor: connection is declared in core PLATFORM_SERVICE_PROBES.
|
|
6
|
+
const connection = ctx.get('connection');
|
|
7
|
+
if (connection === undefined)
|
|
8
|
+
return undefined;
|
|
9
|
+
const register = (route) => {
|
|
10
|
+
if (connection.fetch === undefined || typeof connection.fetch.register !== 'function')
|
|
11
|
+
throw new Error(REGISTER_REQUIRED);
|
|
12
|
+
return connection.fetch.register.call(connection.fetch, route);
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
allowsRemoteAuthorities: connection.allowsRemoteAuthorities === true,
|
|
16
|
+
register,
|
|
17
|
+
tryRegister: (route) => {
|
|
18
|
+
try {
|
|
19
|
+
return ok(register(route));
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
return err({ code: 'E-325', message: error instanceof Error ? error.message : String(error) });
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Full adapter entry.
|
|
3
|
+
*
|
|
4
|
+
* - `./ports` is the composition-safe port surface.
|
|
5
|
+
* - `./values` carries host-provided runtime helper values.
|
|
6
|
+
* - `./service` is the Cordis `evolutionPlatform` service.
|
|
7
|
+
*
|
|
8
|
+
* Feature packages should use the narrow entries (`./ports`, `./values`) and
|
|
9
|
+
* not this umbrella unless they need the service.
|
|
10
|
+
*/
|
|
11
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
12
|
+
export * from './ports.ts';
|
|
13
|
+
export * from './values.ts';
|
|
14
|
+
export * from './service.ts';
|
|
15
|
+
export declare const name = "evolution-adapter";
|
|
16
|
+
/** Mount the one host platform service; bundle row order places this before core/runtime. */
|
|
17
|
+
export declare function apply(ctx: Context): Promise<void>;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EvolutionPlatform } from "./service.js";
|
|
2
|
+
export * from "./ports.js";
|
|
3
|
+
export * from "./values.js";
|
|
4
|
+
export * from "./service.js";
|
|
5
|
+
export const name = 'evolution-adapter';
|
|
6
|
+
/** Mount the one host platform service; bundle row order places this before core/runtime. */
|
|
7
|
+
export async function apply(ctx) {
|
|
8
|
+
await ctx.plugin(EvolutionPlatform);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The LLM implementation half of the family's platform boundary.
|
|
3
|
+
*/
|
|
4
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
5
|
+
import type { LlmPort, ModelRoute } from '@lmzhen/dsh-evolution-platform-contract';
|
|
6
|
+
export { EvolutionLlmError } from '@lmzhen/dsh-evolution-platform-contract';
|
|
7
|
+
export type { EvolutionLlmFailureKind, EvolutionLlmPurpose, EvolutionLlmRequest, LlmPort, ModelRoute, } from '@lmzhen/dsh-evolution-platform-contract';
|
|
8
|
+
/** Resolve the LLM port; undefined means the host has no llm service. */
|
|
9
|
+
export declare function llmPort(ctx: Context): LlmPort | undefined;
|
|
10
|
+
/** Resolve the model route: agent-owned selection first, deployment default second. */
|
|
11
|
+
export declare function modelRoute(ctx: Context, agent?: unknown, session?: unknown): ModelRoute | undefined;
|
|
12
|
+
//# sourceMappingURL=llm.d.ts.map
|