@lincyaw/dsh 0.2.0-rc.50 → 0.2.0-rc.52
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/build/dist/client.js +162 -162
- package/build/dist/client.json +1 -0
- package/package.json +7 -7
- package/src/node/bindings.ts +3 -0
- package/src/node/policy.ts +2 -1
- package/src/node/tools.ts +39 -4
package/build/dist/client.json
CHANGED
|
@@ -154,6 +154,7 @@
|
|
|
154
154
|
"../workbench/src/document-editor/comment-draft-inspection.ts",
|
|
155
155
|
"../workbench/src/document-editor/comment-draft-actions.ts",
|
|
156
156
|
"../workbench/src/body-draft-actions.ts",
|
|
157
|
+
"../workbench/src/production-draft-actions.ts",
|
|
157
158
|
"../workbench/src/component-draft-inspection.ts",
|
|
158
159
|
"../workbench/src/component-draft-actions.ts",
|
|
159
160
|
"../workbench/src/document-drafts.ts",
|
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.52",
|
|
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/
|
|
89
|
-
"@lincyaw/
|
|
90
|
-
"@lincyaw/
|
|
91
|
-
"@lincyaw/skills": "1.0.0-rc.
|
|
88
|
+
"@lincyaw/cli": "1.0.0-rc.53",
|
|
89
|
+
"@lincyaw/mcp": "1.0.0-rc.53",
|
|
90
|
+
"@lincyaw/kernel": "1.0.0-rc.53",
|
|
91
|
+
"@lincyaw/skills": "1.0.0-rc.53"
|
|
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.53",
|
|
108
|
+
"@lincyaw/workbench": "0.2.0-rc.53"
|
|
109
109
|
},
|
|
110
110
|
"scripts": {}
|
|
111
111
|
}
|
package/src/node/bindings.ts
CHANGED
|
@@ -22,6 +22,8 @@ export interface DocumentBinding {
|
|
|
22
22
|
readonly tools: ListedTool[]
|
|
23
23
|
/** Complete metadata for the currently registered model surface; replaced only at tool installation. */
|
|
24
24
|
registeredTools?: readonly ListedTool[]
|
|
25
|
+
/** Ephemeral fixed inputs between pre-execute approval and this exact invocation. */
|
|
26
|
+
preparedCalls?: Map<symbol, { signature: string, arguments: Record<string, unknown> }>
|
|
25
27
|
toolChanges: BindingTools
|
|
26
28
|
diagnostics: BindingDiagnostics
|
|
27
29
|
}
|
|
@@ -158,6 +160,7 @@ export class BindingDiagnostics {
|
|
|
158
160
|
}
|
|
159
161
|
|
|
160
162
|
async function closeBinding(binding: DocumentBinding): Promise<void> {
|
|
163
|
+
binding.preparedCalls?.clear()
|
|
161
164
|
try {
|
|
162
165
|
await Promise.all([binding.diagnostics.close(), binding.toolChanges.close()])
|
|
163
166
|
} finally {
|
package/src/node/policy.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { CatalogCall } from '@lincyaw/mcp/client'
|
|
|
5
5
|
import { isInside } from '@lincyaw/kernel/node'
|
|
6
6
|
import { describeOperation } from '@lincyaw/mcp/client'
|
|
7
7
|
import type { DshContext, DshPreDecision, DshToolExecution } from './dsh-types.ts'
|
|
8
|
-
import { PREFIX, resolvePresmiumCall } from './tools.ts'
|
|
8
|
+
import { PREFIX, preparePresmiumCall, resolvePresmiumCall } from './tools.ts'
|
|
9
9
|
|
|
10
10
|
export const name = 'presmium-policy'
|
|
11
11
|
export const inject = ['presmium', 'tools']
|
|
@@ -38,6 +38,7 @@ export function apply(ctx: DshContext): void {
|
|
|
38
38
|
const tool = resolved.tool
|
|
39
39
|
if (!binding || !tool) return { kind: 'deny', reason: `Presmium: ${exec.name} is no tool of this session's document` }
|
|
40
40
|
if (tool.kind === 'read') return next()
|
|
41
|
+
try { await preparePresmiumCall(binding, exec, resolved) } catch (error) { return { kind: 'deny', reason: `Presmium: ${errorMessage(error)}` } }
|
|
41
42
|
if (tool.approval === 'allow') return { kind: 'allow' }
|
|
42
43
|
const lang = binding.document.lang
|
|
43
44
|
const title = describeOperation(tool.name, resolved.arguments, lang)
|
package/src/node/tools.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { errorMessage } from '@lincyaw/kernel'
|
|
2
|
-
import { compactToolCatalog, queryToolCatalog, resolveCatalogCall } from '@lincyaw/mcp/client'
|
|
3
|
-
import type { CalledImage, ListedTool } from '@lincyaw/mcp/client'
|
|
1
|
+
import { errorMessage, isRecord } from '@lincyaw/kernel'
|
|
2
|
+
import { compactToolCatalog, isOrdinaryMediaCall, mediaResult, prepareMediaArguments, queryToolCatalog, resolveCatalogCall } from '@lincyaw/mcp/client'
|
|
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
5
|
import type { DocumentBinding } from './bindings.ts'
|
|
6
6
|
|
|
@@ -26,6 +26,31 @@ export async function resolvePresmiumCall(binding: DocumentBinding | undefined,
|
|
|
26
26
|
return target
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
export async function preparePresmiumCall(binding: DocumentBinding, exec: DshToolExecution, target: CatalogCall) {
|
|
30
|
+
if (target.discovery || !isOrdinaryMediaCall(target.tool.name, target.arguments)) return
|
|
31
|
+
if (!isRecord(exec.arguments)) throw new Error('operation-arguments-invalid')
|
|
32
|
+
const preparedCalls = binding.preparedCalls ??= new Map()
|
|
33
|
+
const signature = JSON.stringify([target.tool, target.arguments]), previous = preparedCalls.get(exec.token)
|
|
34
|
+
if (previous) {
|
|
35
|
+
if (previous.signature !== signature) throw new Error('operation-definition-changed')
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
if (preparedCalls.size >= 64) throw new Error('operation-preparation-busy')
|
|
39
|
+
const client = isCandidateTool(target.tool) ? binding.client : binding.authorClient
|
|
40
|
+
const args = await prepareMediaArguments(target.tool.name, target.arguments, async (name, args) => {
|
|
41
|
+
exec.signal.throwIfAborted()
|
|
42
|
+
const result = await client.call(name, args, exec.signal)
|
|
43
|
+
exec.signal.throwIfAborted()
|
|
44
|
+
if (result.isError) throw new Error(result.text)
|
|
45
|
+
return result.structured ?? JSON.parse(result.text)
|
|
46
|
+
})
|
|
47
|
+
// Validate the fixed native request using the same definition; never rewrite logged arguments.
|
|
48
|
+
const prepared = await resolveCatalogCall(binding.tools, target.tool.name, args)
|
|
49
|
+
exec.signal.throwIfAborted()
|
|
50
|
+
if (preparedCalls.size >= 64) throw new Error('operation-preparation-busy')
|
|
51
|
+
preparedCalls.set(exec.token, { signature, arguments: prepared.arguments })
|
|
52
|
+
}
|
|
53
|
+
|
|
29
54
|
const IMAGE_TYPES = new Set<string>(['image/png', 'image/jpeg', 'image/webp', 'image/gif'])
|
|
30
55
|
|
|
31
56
|
/**
|
|
@@ -62,8 +87,17 @@ function definition(ctx: DshContext, binding: DocumentBinding, tool: ListedTool)
|
|
|
62
87
|
if (exec.agent && ctx.presmium.bindings.bindingOf(exec.agent) !== binding) throw new Error('operation-binding-changed')
|
|
63
88
|
const target = await resolvePresmiumCall(binding, { name: PREFIX + tool.name, arguments: args })
|
|
64
89
|
if (target.discovery) return JSON.stringify(queryToolCatalog(binding.registeredTools ?? binding.tools, target.arguments))
|
|
65
|
-
const
|
|
90
|
+
const ordinaryMedia = isOrdinaryMediaCall(target.tool.name, target.arguments)
|
|
91
|
+
let argumentsToSend = target.arguments
|
|
92
|
+
if (ordinaryMedia) {
|
|
93
|
+
const fixed = binding.preparedCalls?.get(exec.token)
|
|
94
|
+
binding.preparedCalls?.delete(exec.token)
|
|
95
|
+
if (!fixed || fixed.signature !== JSON.stringify([target.tool, target.arguments])) throw new Error('operation-not-prepared')
|
|
96
|
+
argumentsToSend = fixed.arguments
|
|
97
|
+
}
|
|
98
|
+
const result = await (isCandidateTool(target.tool) ? binding.client : binding.authorClient).call(target.tool.name, argumentsToSend, exec.signal)
|
|
66
99
|
if (result.isError) throw new Error(result.text)
|
|
100
|
+
if (ordinaryMedia) return JSON.stringify(mediaResult(target.tool.name, result.structured ?? JSON.parse(result.text), target.arguments))
|
|
67
101
|
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)])
|
|
68
102
|
return result.text
|
|
69
103
|
},
|
|
@@ -76,6 +110,7 @@ function definition(ctx: DshContext, binding: DocumentBinding, tool: ListedTool)
|
|
|
76
110
|
}
|
|
77
111
|
|
|
78
112
|
export function apply(ctx: DshContext): void {
|
|
113
|
+
ctx.on('tools/result', (exec: Readonly<DshToolExecution>) => { ctx.presmium.bindings.bindingOf(exec.agent)?.preparedCalls?.delete(exec.token) })
|
|
79
114
|
const live = new WeakSet<DshAgent>()
|
|
80
115
|
const selections = new WeakMap<DshAgent, () => void>()
|
|
81
116
|
const registered = new WeakMap<DshAgent, { binding?: DocumentBinding, tools?: ListedTool[], stop?: () => void, dispose: (() => void)[] }>()
|