@lincyaw/dsh 0.2.0-rc.60 → 0.2.0-rc.62
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/package.json +7 -7
- package/src/node/bindings.ts +8 -3
- package/src/node/tools.ts +28 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincyaw/dsh",
|
|
3
|
-
"version": "0.2.0-rc.
|
|
3
|
+
"version": "0.2.0-rc.62",
|
|
4
4
|
"description": "Presmium's bundle for DeepSeek Harness: the workbench of presmium studio, its host side (Presmium's tools, approvals, document context, skills and routes) and its client side (the root layout and the workbench's panels, precompiled) (experimental)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -85,10 +85,10 @@
|
|
|
85
85
|
"node-addon-require-builtin": "0.1.9",
|
|
86
86
|
"ws": "8.22.0",
|
|
87
87
|
"zod": "4.4.3",
|
|
88
|
-
"@lincyaw/cli": "1.0.0-rc.
|
|
89
|
-
"@lincyaw/
|
|
90
|
-
"@lincyaw/
|
|
91
|
-
"@lincyaw/
|
|
88
|
+
"@lincyaw/cli": "1.0.0-rc.63",
|
|
89
|
+
"@lincyaw/kernel": "1.0.0-rc.63",
|
|
90
|
+
"@lincyaw/mcp": "1.0.0-rc.63",
|
|
91
|
+
"@lincyaw/skills": "1.0.0-rc.63"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
94
|
"@deepseek-ai/dsh": "0.2.1-alpha.4"
|
|
@@ -104,8 +104,8 @@
|
|
|
104
104
|
"react": "18.3.1",
|
|
105
105
|
"react-dom": "18.3.1",
|
|
106
106
|
"react-resizable-panels": "^4.14.5",
|
|
107
|
-
"@lincyaw/design": "1.0.0-rc.
|
|
108
|
-
"@lincyaw/workbench": "0.2.0-rc.
|
|
107
|
+
"@lincyaw/design": "1.0.0-rc.63",
|
|
108
|
+
"@lincyaw/workbench": "0.2.0-rc.63"
|
|
109
109
|
},
|
|
110
110
|
"scripts": {}
|
|
111
111
|
}
|
package/src/node/bindings.ts
CHANGED
|
@@ -4,13 +4,15 @@ import { isInside } from '@lincyaw/kernel/node'
|
|
|
4
4
|
import { connectPresmiumMcp } from '@lincyaw/mcp/client'
|
|
5
5
|
import { errorMessage, isRecord } from '@lincyaw/kernel'
|
|
6
6
|
import type { DiagnosticSnapshot, DocumentSummary } from '@lincyaw/kernel'
|
|
7
|
-
import type { ListedTool, PresmiumMcpClient } from '@lincyaw/mcp/client'
|
|
7
|
+
import type { ListedTool, PresmiumMcpClient, PreparedMcpCall } from '@lincyaw/mcp/client'
|
|
8
8
|
import type { DshAgent, DshContext, DshLogger } from './dsh-types.ts'
|
|
9
9
|
import { SERVER_ROUTES } from './server-routes.ts'
|
|
10
10
|
import type { WorkspaceServerClient } from './service.ts'
|
|
11
11
|
import { WorkspaceServerClient as CandidateServer } from './service.ts'
|
|
12
12
|
import { WORKSPACE_ROUTES } from './server-routes.ts'
|
|
13
13
|
|
|
14
|
+
/** Fixed inputs owned by one pending invocation, including native resources that need retirement. */
|
|
15
|
+
export interface PreparedBindingCall { signature: string, arguments: Record<string, unknown>, native?: PreparedMcpCall }
|
|
14
16
|
/** The document an agent session works on: an MCP client with a session token for it, its tools and its diagnostics. */
|
|
15
17
|
export interface DocumentBinding {
|
|
16
18
|
agentSessionId: string
|
|
@@ -23,7 +25,7 @@ export interface DocumentBinding {
|
|
|
23
25
|
/** Complete metadata for the currently registered model surface; replaced only at tool installation. */
|
|
24
26
|
registeredTools?: readonly ListedTool[]
|
|
25
27
|
/** Ephemeral fixed inputs between pre-execute approval and this exact invocation. */
|
|
26
|
-
preparedCalls?: Map<symbol,
|
|
28
|
+
preparedCalls?: Map<symbol, PreparedBindingCall>
|
|
27
29
|
toolChanges: BindingTools
|
|
28
30
|
diagnostics: BindingDiagnostics
|
|
29
31
|
}
|
|
@@ -160,9 +162,12 @@ export class BindingDiagnostics {
|
|
|
160
162
|
}
|
|
161
163
|
|
|
162
164
|
async function closeBinding(binding: DocumentBinding): Promise<void> {
|
|
165
|
+
const prepared = [...binding.preparedCalls?.values() ?? []]
|
|
163
166
|
binding.preparedCalls?.clear()
|
|
164
167
|
try {
|
|
165
|
-
await Promise.
|
|
168
|
+
const results = await Promise.allSettled([...prepared.flatMap(value => value.native ? [value.native.close()] : []), binding.diagnostics.close(), binding.toolChanges.close()])
|
|
169
|
+
const failed = results.find(result => result.status === 'rejected')
|
|
170
|
+
if (failed?.status === 'rejected') throw failed.reason
|
|
166
171
|
} finally {
|
|
167
172
|
await Promise.all([binding.client.close(), binding.authorClient.close()])
|
|
168
173
|
}
|
package/src/node/tools.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { errorMessage, isRecord } from '@lincyaw/kernel'
|
|
|
2
2
|
import { compactToolCatalog, isOrdinaryMediaCall, mediaResult, prepareMediaArguments, queryToolCatalog, resolveCatalogCall } from '@lincyaw/mcp/client'
|
|
3
3
|
import type { CalledImage, CatalogCall, ListedTool } from '@lincyaw/mcp/client'
|
|
4
4
|
import type { DshAgent, DshAttachments, DshContentBlock, DshContext, DshImageMediaType, DshLlm, DshToolDefinition, DshToolExecution } from './dsh-types.ts'
|
|
5
|
-
import type { DocumentBinding } from './bindings.ts'
|
|
5
|
+
import type { DocumentBinding, PreparedBindingCall } from './bindings.ts'
|
|
6
6
|
|
|
7
7
|
export const name = 'presmium-tools'
|
|
8
8
|
export const inject = ['presmium', 'tools']
|
|
@@ -27,7 +27,7 @@ export async function resolvePresmiumCall(binding: DocumentBinding | undefined,
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export async function preparePresmiumCall(binding: DocumentBinding, exec: DshToolExecution, target: CatalogCall) {
|
|
30
|
-
if (target.discovery || !isOrdinaryMediaCall(target.tool.name, target.arguments)) return
|
|
30
|
+
if (target.discovery || !isOrdinaryMediaCall(target.tool.name, target.arguments) && target.tool.name !== 'clone_voice') return
|
|
31
31
|
if (!isRecord(exec.arguments)) throw new Error('operation-arguments-invalid')
|
|
32
32
|
const preparedCalls = binding.preparedCalls ??= new Map()
|
|
33
33
|
const signature = JSON.stringify([target.tool, target.arguments]), previous = preparedCalls.get(exec.token)
|
|
@@ -37,6 +37,15 @@ export async function preparePresmiumCall(binding: DocumentBinding, exec: DshToo
|
|
|
37
37
|
}
|
|
38
38
|
if (preparedCalls.size >= 64) throw new Error('operation-preparation-busy')
|
|
39
39
|
const client = isCandidateTool(target.tool) ? binding.client : binding.authorClient
|
|
40
|
+
if (target.tool.name === 'clone_voice') {
|
|
41
|
+
const native = await client.prepareVoiceClone(target.arguments, exec.signal)
|
|
42
|
+
try {
|
|
43
|
+
exec.signal.throwIfAborted()
|
|
44
|
+
if (preparedCalls.size >= 64) throw new Error('operation-preparation-busy')
|
|
45
|
+
preparedCalls.set(exec.token, { signature, arguments: target.arguments, native })
|
|
46
|
+
} catch (error) { await native.close(); throw error }
|
|
47
|
+
return
|
|
48
|
+
}
|
|
40
49
|
const args = await prepareMediaArguments(target.tool.name, target.arguments, async (name, args) => {
|
|
41
50
|
exec.signal.throwIfAborted()
|
|
42
51
|
const result = await client.call(name, args, exec.signal)
|
|
@@ -88,14 +97,22 @@ function definition(ctx: DshContext, binding: DocumentBinding, tool: ListedTool)
|
|
|
88
97
|
const target = await resolvePresmiumCall(binding, { name: PREFIX + tool.name, arguments: args })
|
|
89
98
|
if (target.discovery) return JSON.stringify(queryToolCatalog(binding.registeredTools ?? binding.tools, target.arguments))
|
|
90
99
|
const ordinaryMedia = isOrdinaryMediaCall(target.tool.name, target.arguments)
|
|
100
|
+
const needsPreparation = ordinaryMedia || target.tool.name === 'clone_voice'
|
|
91
101
|
let argumentsToSend = target.arguments
|
|
92
|
-
|
|
93
|
-
|
|
102
|
+
let fixed: PreparedBindingCall | undefined
|
|
103
|
+
if (needsPreparation) {
|
|
104
|
+
const prepared = binding.preparedCalls?.get(exec.token)
|
|
94
105
|
binding.preparedCalls?.delete(exec.token)
|
|
95
|
-
if (!
|
|
106
|
+
if (!prepared || prepared.signature !== JSON.stringify([target.tool, target.arguments]) || target.tool.name === 'clone_voice' && !prepared.native) {
|
|
107
|
+
await prepared?.native?.close()
|
|
108
|
+
throw new Error('operation-not-prepared')
|
|
109
|
+
}
|
|
110
|
+
fixed = prepared
|
|
96
111
|
argumentsToSend = fixed.arguments
|
|
97
112
|
}
|
|
98
|
-
|
|
113
|
+
let result
|
|
114
|
+
try { result = target.tool.name === 'clone_voice' ? await fixed!.native!.call(exec.signal) : await (isCandidateTool(target.tool) ? binding.client : binding.authorClient).call(target.tool.name, argumentsToSend, exec.signal) }
|
|
115
|
+
finally { await fixed?.native?.close() }
|
|
99
116
|
if (result.isError) throw new Error(result.text)
|
|
100
117
|
if (ordinaryMedia) return JSON.stringify(mediaResult(target.tool.name, result.structured ?? JSON.parse(result.text), target.arguments))
|
|
101
118
|
if (result.images.length > 0) prepared.set(exec.token, [...result.text ? [{ type: 'text' as const, text: result.text }] : [], ...await imageBlocks(ctx, tool.name, result.images, exec)])
|
|
@@ -110,7 +127,11 @@ function definition(ctx: DshContext, binding: DocumentBinding, tool: ListedTool)
|
|
|
110
127
|
}
|
|
111
128
|
|
|
112
129
|
export function apply(ctx: DshContext): void {
|
|
113
|
-
ctx.on('tools/result', (exec: Readonly<DshToolExecution>) => {
|
|
130
|
+
ctx.on('tools/result', async (exec: Readonly<DshToolExecution>) => {
|
|
131
|
+
const calls = ctx.presmium.bindings.bindingOf(exec.agent)?.preparedCalls, prepared = calls?.get(exec.token)
|
|
132
|
+
calls?.delete(exec.token)
|
|
133
|
+
await prepared?.native?.close()
|
|
134
|
+
})
|
|
114
135
|
const live = new WeakSet<DshAgent>()
|
|
115
136
|
const selections = new WeakMap<DshAgent, () => void>()
|
|
116
137
|
const registered = new WeakMap<DshAgent, { binding?: DocumentBinding, tools?: ListedTool[], stop?: () => void, dispose: (() => void)[] }>()
|