@lincyaw/dsh 0.2.0-rc.11 → 0.2.0-rc.110
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/client.mjs +0 -2
- package/build/dist/client.js +302 -299
- package/build/dist/client.json +76 -41
- package/cordis.patch.yml +20 -0
- package/entries/deltabox-runtime.mjs +3 -0
- package/package.json +12 -9
- package/src/client/RootLayout.tsx +18 -15
- package/src/client/agent-requests.ts +47 -0
- package/src/client/contract.ts +0 -6
- package/src/client/dsh.d.ts +12 -0
- package/src/client/fallback.tsx +6 -4
- package/src/client/frame.css +0 -10
- package/src/client/index.tsx +8 -7
- package/src/client/layout.ts +9 -6
- package/src/client/messages.ts +6 -10
- package/src/client/navigation-shell.tsx +2 -2
- package/src/client/runtime-diagnostics.tsx +1 -1
- package/src/client/settings-launcher.tsx +19 -0
- package/src/client/settings-opener.ts +6 -0
- package/src/client/speech-settings.tsx +2 -1
- package/src/client/startup.css +47 -0
- package/src/client/startup.ts +17 -0
- package/src/client/styles.css +0 -42
- package/src/client/workspace-events.ts +10 -8
- package/src/node/bindings.ts +136 -8
- package/src/node/context.ts +16 -26
- package/src/node/deltabox-runtime.ts +19 -0
- package/src/node/dsh-types.ts +31 -1
- package/src/node/launch.ts +40 -11
- package/src/node/policy.ts +14 -3
- package/src/node/routes.ts +10 -3
- package/src/node/service.ts +7 -1
- package/src/node/startup.ts +73 -0
- package/src/node/tools.ts +121 -8
- package/src/node/turns.ts +23 -8
- package/src/node/workbench.ts +9 -2
- package/src/node/workspace-events.ts +7 -4
- package/src/startup-messages.ts +15 -0
- package/src/workspace-events.ts +3 -2
- package/web.patch.yml +18 -6
- package/src/client/mascot.tsx +0 -37
package/src/node/tools.ts
CHANGED
|
@@ -1,27 +1,137 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
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
|
+
import type { DshAgent, DshAttachments, DshContentBlock, DshContext, DshImageMediaType, DshLlm, DshToolDefinition, DshToolExecution } from './dsh-types.ts'
|
|
5
|
+
import type { DocumentBinding, PreparedBindingCall } from './bindings.ts'
|
|
4
6
|
|
|
5
7
|
export const name = 'presmium-tools'
|
|
6
|
-
export const inject = ['presmium', 'tools']
|
|
8
|
+
export const inject = ['presmium', 'tools', 'deltabox']
|
|
7
9
|
|
|
8
10
|
export const PREFIX = 'presmium__'
|
|
11
|
+
export const CANDIDATE_TOOLS = new Set([
|
|
12
|
+
'get_authoring_capabilities', 'get_document', 'get_document_outline', 'read_document_part',
|
|
13
|
+
'plan_document_change', 'apply_document_change', 'plan_page_change', 'apply_page_change',
|
|
14
|
+
'plan_page_duplication', 'apply_page_duplication', 'plan_authoring_action', 'apply_authoring_action', 'read_authoring_action_impact',
|
|
15
|
+
'check_document', 'get_section', 'get_step', 'list_sections', 'deck_info', 'list_documents',
|
|
16
|
+
'run_code', 'capture_slides', 'capture_reading', 'capture_overview',
|
|
17
|
+
])
|
|
9
18
|
|
|
10
|
-
|
|
19
|
+
/** New tools carry their routing with their schema; the names retain compatibility with older servers. */
|
|
20
|
+
export const isCandidateTool = (tool: ListedTool): boolean => tool.workspace ? tool.workspace === 'candidate' : CANDIDATE_TOOLS.has(tool.name)
|
|
21
|
+
|
|
22
|
+
export async function resolvePresmiumCall(binding: DocumentBinding | undefined, exec: Pick<DshToolExecution, 'name' | 'arguments'>) {
|
|
23
|
+
if (!binding || !exec.name.startsWith(PREFIX)) throw new Error('operation-unavailable')
|
|
24
|
+
const target = await resolveCatalogCall(binding.registeredTools ?? binding.tools, exec.name.slice(PREFIX.length), exec.arguments)
|
|
25
|
+
if (!target.discovery && JSON.stringify(binding.tools.find(tool => tool.name === target.tool.name)) !== JSON.stringify(target.tool)) throw new Error('operation-definition-changed')
|
|
26
|
+
return target
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function preparePresmiumCall(binding: DocumentBinding, exec: DshToolExecution, target: CatalogCall) {
|
|
30
|
+
if (target.discovery || !isOrdinaryMediaCall(target.tool.name, target.arguments) && target.tool.name !== 'clone_voice') 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
|
+
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
|
+
}
|
|
49
|
+
const args = await prepareMediaArguments(target.tool.name, target.arguments, async (name, args) => {
|
|
50
|
+
exec.signal.throwIfAborted()
|
|
51
|
+
const result = await client.call(name, args, exec.signal)
|
|
52
|
+
exec.signal.throwIfAborted()
|
|
53
|
+
if (result.isError) throw new Error(result.text)
|
|
54
|
+
return result.structured ?? JSON.parse(result.text)
|
|
55
|
+
})
|
|
56
|
+
// Validate the fixed native request using the same definition; never rewrite logged arguments.
|
|
57
|
+
const prepared = await resolveCatalogCall(binding.tools, target.tool.name, args)
|
|
58
|
+
exec.signal.throwIfAborted()
|
|
59
|
+
if (preparedCalls.size >= 64) throw new Error('operation-preparation-busy')
|
|
60
|
+
preparedCalls.set(exec.token, { signature, arguments: prepared.arguments })
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const IMAGE_TYPES = new Set<string>(['image/png', 'image/jpeg', 'image/webp', 'image/gif'])
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A tool result's images as dsh's durable image blocks, which reach the model beside the text; only when the model of
|
|
67
|
+
* the session's latest request declares image input, as dsh's own MCP client does. Otherwise, and when the attachment
|
|
68
|
+
* store refuses them, one line says they were left out (the text names their files where the tool has any) and the call
|
|
69
|
+
* still succeeds.
|
|
70
|
+
*/
|
|
71
|
+
async function imageBlocks(ctx: DshContext, tool: string, images: CalledImage[], exec: DshToolExecution): Promise<DshContentBlock[]> {
|
|
72
|
+
const leftOut = (why: string): DshContentBlock[] => [{ type: 'text', text: `[${images.length} image${images.length === 1 ? '' : 's'} not attached: ${why}]` }]
|
|
73
|
+
const attachments = ctx.get('attachments') as DshAttachments | undefined
|
|
74
|
+
const llm = ctx.get('llm') as DshLlm | undefined
|
|
75
|
+
const { provider, model } = exec.agent?.session.requestContext() ?? {}
|
|
76
|
+
if (!attachments || !llm || !provider || !model) return leftOut('this session takes no images')
|
|
77
|
+
const info = await llm.resolveModelInfo(provider, model, exec.signal).catch(() => undefined)
|
|
78
|
+
if (!info?.inputModalities?.includes('image')) return leftOut(`the model ${model} does not take images`)
|
|
79
|
+
if (images.some(image => !IMAGE_TYPES.has(image.mimeType))) return leftOut('not PNG, JPEG, WebP or GIF')
|
|
80
|
+
try {
|
|
81
|
+
const refs = await attachments.saveImages(images.map((image, n) => ({ data: Buffer.from(image.data, 'base64'), mediaType: image.mimeType as DshImageMediaType, name: `${tool}-${n + 1}.${image.mimeType.slice('image/'.length)}` })))
|
|
82
|
+
return refs.map(attachment => ({ type: 'image', attachment }))
|
|
83
|
+
} catch (error) {
|
|
84
|
+
return leftOut(errorMessage(error))
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function definition(ctx: DshContext, binding: DocumentBinding, tool: ListedTool): DshToolDefinition {
|
|
89
|
+
const prepared = new Map<symbol, DshContentBlock[]>()
|
|
11
90
|
return {
|
|
12
91
|
name: `${PREFIX}${tool.name}`,
|
|
13
92
|
description: tool.description,
|
|
14
93
|
parameters: tool.inputSchema,
|
|
15
94
|
output: { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: String(value) }] },
|
|
16
95
|
async execute(args, exec) {
|
|
17
|
-
|
|
96
|
+
if (exec.agent && ctx.presmium.bindings.bindingOf(exec.agent) !== binding) throw new Error('operation-binding-changed')
|
|
97
|
+
const target = await resolvePresmiumCall(binding, { name: PREFIX + tool.name, arguments: args })
|
|
98
|
+
if (target.discovery) return JSON.stringify(queryToolCatalog(binding.registeredTools ?? binding.tools, target.arguments))
|
|
99
|
+
const ordinaryMedia = isOrdinaryMediaCall(target.tool.name, target.arguments)
|
|
100
|
+
const needsPreparation = ordinaryMedia || target.tool.name === 'clone_voice'
|
|
101
|
+
let argumentsToSend = target.arguments
|
|
102
|
+
let fixed: PreparedBindingCall | undefined
|
|
103
|
+
if (needsPreparation) {
|
|
104
|
+
const prepared = binding.preparedCalls?.get(exec.token)
|
|
105
|
+
binding.preparedCalls?.delete(exec.token)
|
|
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
|
|
111
|
+
argumentsToSend = fixed.arguments
|
|
112
|
+
}
|
|
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() }
|
|
18
116
|
if (result.isError) throw new Error(result.text)
|
|
117
|
+
if (ordinaryMedia) return JSON.stringify(mediaResult(target.tool.name, result.structured ?? JSON.parse(result.text), target.arguments))
|
|
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)])
|
|
19
119
|
return result.text
|
|
20
120
|
},
|
|
121
|
+
projectContent(exec, result) {
|
|
122
|
+
const content = prepared.get(exec.token)
|
|
123
|
+
prepared.delete(exec.token)
|
|
124
|
+
return result.isError ? undefined : content
|
|
125
|
+
},
|
|
21
126
|
}
|
|
22
127
|
}
|
|
23
128
|
|
|
24
129
|
export function apply(ctx: DshContext): void {
|
|
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
|
+
})
|
|
25
135
|
const live = new WeakSet<DshAgent>()
|
|
26
136
|
const selections = new WeakMap<DshAgent, () => void>()
|
|
27
137
|
const registered = new WeakMap<DshAgent, { binding?: DocumentBinding, tools?: ListedTool[], stop?: () => void, dispose: (() => void)[] }>()
|
|
@@ -31,10 +141,11 @@ export function apply(ctx: DshContext): void {
|
|
|
31
141
|
if (previous && previous.binding === binding && previous.tools === binding?.tools) return
|
|
32
142
|
previous?.stop?.()
|
|
33
143
|
for (const dispose of previous?.dispose ?? []) dispose()
|
|
144
|
+
if (binding) binding.registeredTools = binding.tools
|
|
34
145
|
registered.set(agent, {
|
|
35
146
|
binding, tools: binding?.tools,
|
|
36
147
|
stop: binding?.toolChanges.watch(() => { if (agent.status === 'idle') install(agent, binding) }),
|
|
37
|
-
dispose: binding
|
|
148
|
+
dispose: binding ? compactToolCatalog(binding.tools).map(tool => agent.ctx.tools.register(definition(ctx, binding, tool))) : [],
|
|
38
149
|
})
|
|
39
150
|
}
|
|
40
151
|
const sync = async (agent: DshAgent) => {
|
|
@@ -48,15 +159,17 @@ export function apply(ctx: DshContext): void {
|
|
|
48
159
|
if (!live.has(agent)) return
|
|
49
160
|
selections.set(agent, ctx.presmium.bindings.watchSelection(agent.session.id, { before: () => agent.whenIdle(), after: () => sync(agent) }))
|
|
50
161
|
})
|
|
51
|
-
ctx.on('agent/disposed', ({ agent }: { agent: DshAgent }) => {
|
|
162
|
+
ctx.on('agent/disposed', async ({ agent }: { agent: DshAgent }) => {
|
|
52
163
|
live.delete(agent)
|
|
53
164
|
selections.get(agent)?.(); selections.delete(agent)
|
|
54
165
|
const previous = registered.get(agent)
|
|
55
166
|
registered.delete(agent)
|
|
56
167
|
previous?.stop?.()
|
|
57
168
|
for (const dispose of previous?.dispose ?? []) dispose()
|
|
169
|
+
await ctx.presmium.bindings.retireCandidate(agent)
|
|
58
170
|
})
|
|
59
171
|
ctx.on('agent/pre-step', async ({ agent }: { agent: DshAgent }, next: () => Promise<unknown>) => {
|
|
172
|
+
await ctx.presmium.bindings.refreshCandidate(agent)
|
|
60
173
|
await sync(agent)
|
|
61
174
|
return next()
|
|
62
175
|
})
|
package/src/node/turns.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { errorMessage } from '@lincyaw/kernel'
|
|
|
3
3
|
import { isInside } from '@lincyaw/kernel/node'
|
|
4
4
|
import type { DshAgent, DshContext, DshToolExecution } from './dsh-types.ts'
|
|
5
5
|
import { WORKSPACE_ROUTES } from './server-routes.ts'
|
|
6
|
+
import { isCandidateTool, PREFIX, resolvePresmiumCall } from './tools.ts'
|
|
7
|
+
import { deltaboxOf, runtimeAgent } from './deltabox-runtime.ts'
|
|
6
8
|
|
|
7
9
|
// What a writing tool answers when the change cannot be recorded. The AI reads it and tells the author in their own
|
|
8
10
|
// language, so it names what the author sees (Version History) and none of the internals behind it.
|
|
@@ -83,7 +85,8 @@ export function apply(ctx: DshContext): void {
|
|
|
83
85
|
if (path === 'open' && response.status === 404) throw new Error(NOT_RECORDED)
|
|
84
86
|
let reason = text
|
|
85
87
|
try {
|
|
86
|
-
|
|
88
|
+
const failure = JSON.parse(text) as { error?: string, next?: string, paths?: string[] }
|
|
89
|
+
reason = [failure.error, failure.paths?.join(', '), failure.next].filter(Boolean).join(' ') || reason
|
|
87
90
|
} catch {
|
|
88
91
|
}
|
|
89
92
|
throw new Error(reason || `the review answered ${response.status}`)
|
|
@@ -100,25 +103,37 @@ export function apply(ctx: DshContext): void {
|
|
|
100
103
|
})
|
|
101
104
|
|
|
102
105
|
ctx.on('tools/execute', async (exec: DshToolExecution, next: () => Promise<unknown>) => {
|
|
103
|
-
if (!
|
|
106
|
+
if (!exec.agent) return next()
|
|
104
107
|
const { root } = await ctx.presmium.server.ready
|
|
105
|
-
if (!isInside(ctx.presmium.bindings.workingDirectoryOf(exec.agent), root)) return next()
|
|
108
|
+
if (!ctx.presmium.bindings.candidateRootOf(exec.agent) && !isInside(ctx.presmium.bindings.workingDirectoryOf(exec.agent), root)) return next()
|
|
109
|
+
await ctx.presmium.bindings.candidateOf(exec.agent)
|
|
110
|
+
const binding = ctx.presmium.bindings.bindingOf(exec.agent)
|
|
111
|
+
const target = exec.name.startsWith(PREFIX) ? await resolvePresmiumCall(binding, exec) : undefined
|
|
112
|
+
const tool = target?.tool
|
|
113
|
+
if (!WRITING_TOOLS.has(exec.name) && (!tool || tool.kind === 'read' || !isCandidateTool(tool))) return next()
|
|
106
114
|
const document = ctx.presmium.bindings.bindingOf(exec.agent)?.document.dir ?? ''
|
|
107
115
|
const agentSessionId = rootAgentSessionOf(exec.agent.session.id)
|
|
108
116
|
const state = turnStateOf(agentSessionId)
|
|
109
117
|
try {
|
|
110
|
-
await postReview(document, agentSessionId, 'open', state.turn !== undefined ? { turn: state.turn } : {})
|
|
118
|
+
await postReview(document, agentSessionId, 'open', { ...state.turn !== undefined ? { turn: state.turn } : {}, ...deltaboxOf(ctx) ? { backend: 'deltabox' } : {} })
|
|
111
119
|
} catch (error) {
|
|
112
120
|
throw new Error(`${errorMessage(error)} ${NOTHING_CHANGED}`)
|
|
113
121
|
}
|
|
114
122
|
state.document = document
|
|
115
123
|
state.wrote = true
|
|
124
|
+
const session = await deltaboxOf(ctx)?.acquireFor(runtimeAgent(exec.agent))
|
|
125
|
+
let result
|
|
116
126
|
try {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
127
|
+
result = session && target ? await session.runMutable(() => next()) : await next()
|
|
128
|
+
if (session?.reviewActive) await session.reviewCommit()
|
|
129
|
+
} catch (error) {
|
|
130
|
+
if (session?.reviewActive) await session.reviewAbort()
|
|
131
|
+
ctx.presmium.bindings.candidateChanged(exec.agent)
|
|
132
|
+
throw error
|
|
121
133
|
}
|
|
134
|
+
ctx.presmium.bindings.candidateChanged(exec.agent)
|
|
135
|
+
await postReview(document, agentSessionId, 'step', { ...state.turn !== undefined ? { turn: state.turn } : {}, label: labelOf(target ? { ...exec, name: PREFIX + target.tool.name, arguments: target.arguments } : exec), tool: target ? PREFIX + target.tool.name : exec.name })
|
|
136
|
+
return result
|
|
122
137
|
})
|
|
123
138
|
|
|
124
139
|
ctx.on('agent/created', ({ agent }: { agent: LiveAgent }) => {
|
package/src/node/workbench.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { startupAssets, startupIndex } from './startup.ts'
|
|
1
2
|
import { LOCAL_AUTHOR } from '@lincyaw/kernel'
|
|
2
3
|
import type { DshContext, DshOtelScalar } from './dsh-types.ts'
|
|
3
4
|
import type { OperationClient, OperationRecord, PresmiumTelemetry } from './telemetry.ts'
|
|
@@ -8,10 +9,10 @@ export const inject = ['presmium', 'connection', 'webServer', 'presmiumTelemetry
|
|
|
8
9
|
const ICON = `data:image/svg+xml,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" rx="7" fill="#0F5F5C"/><path d="M11 8h7.5a6.5 6.5 0 0 1 0 13H15v4h-4zM15 12v5h3.5a2.5 2.5 0 0 0 0-5z" fill="#F7F5F0" fill-rule="evenodd"/></svg>')}`
|
|
9
10
|
|
|
10
11
|
export function brandIndex(html: string): string {
|
|
11
|
-
return html
|
|
12
|
+
return startupIndex(html
|
|
12
13
|
.replace(/<title>[^<]*<\/title>/, '<title>Presmium</title>')
|
|
13
14
|
.replace(/<link rel="(?:icon|manifest)"[^>]*>\s*/g, '')
|
|
14
|
-
.replace('</head>', `<link rel="icon" type="image/svg+xml" href="${ICON}" />\n</head>`)
|
|
15
|
+
.replace('</head>', `<link rel="icon" type="image/svg+xml" href="${ICON}" />\n</head>`))
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
interface WebServer {
|
|
@@ -48,6 +49,12 @@ export function readOperations(body: unknown): { client: OperationClient, record
|
|
|
48
49
|
|
|
49
50
|
export function apply(ctx: DshContext & { webServer: WebServer, presmiumTelemetry: PresmiumTelemetry }): void {
|
|
50
51
|
ctx.effect(() => ctx.webServer.tapIndex(brandIndex))
|
|
52
|
+
ctx.connection.fetch.register({ path: '/api/presmium/startup.js', methods: ['GET'], requestBody: 'buffered', async fetch() {
|
|
53
|
+
return new Response(startupAssets().script, { headers: { 'content-type': 'text/javascript; charset=utf-8', 'cache-control': 'public, max-age=31536000, immutable' } })
|
|
54
|
+
} })
|
|
55
|
+
ctx.connection.fetch.register({ path: '/api/presmium/startup.css', methods: ['GET'], requestBody: 'buffered', async fetch() {
|
|
56
|
+
return new Response(startupAssets().css, { headers: { 'content-type': 'text/css; charset=utf-8', 'cache-control': 'public, max-age=31536000, immutable' } })
|
|
57
|
+
} })
|
|
51
58
|
ctx.connection.fetch.register({
|
|
52
59
|
path: '/api/presmium/context', methods: ['POST'], requestBody: 'buffered',
|
|
53
60
|
async fetch(request) {
|
|
@@ -27,6 +27,7 @@ const ROUTES = {
|
|
|
27
27
|
review: { path: `${WORKSPACE_ROUTES}review`, event: 'review' },
|
|
28
28
|
ir: { path: `${WORKSPACE_ROUTES}ir/events`, event: 'revision' },
|
|
29
29
|
jobs: { path: `${WORKSPACE_ROUTES}jobs/events`, event: 'job' },
|
|
30
|
+
'agent-activity': { path: `${WORKSPACE_ROUTES}agent-activity/events`, event: 'agent-activity' },
|
|
30
31
|
} as const
|
|
31
32
|
const MAX_SUBSCRIPTIONS = 16
|
|
32
33
|
const MAX_BUFFERED_BYTES = 2 << 20
|
|
@@ -94,13 +95,15 @@ export function apply(ctx: EventContext): void {
|
|
|
94
95
|
const current = () => !closed && !controller.signal.aborted && subscriptions.get(command.id) === entry
|
|
95
96
|
void ctx.presmium.server.ready.then(endpoint => {
|
|
96
97
|
if (!current()) return
|
|
97
|
-
if (command.topic === 'authoring-client') {
|
|
98
|
+
if (command.topic === 'authoring-client' || command.topic === 'authoring-window') {
|
|
99
|
+
const resource = command.topic === 'authoring-window' ? 'authoring-windows' : 'authoring-clients'
|
|
100
|
+
const documentQuery: Record<string, string> = command.topic === 'authoring-client' ? { document: command.document } : {}
|
|
98
101
|
// Keep the client credential on the trusted host, off browser messages and MCP reads.
|
|
99
102
|
let lease: AuthoringClientLease | undefined
|
|
100
103
|
let publication: Promise<void> = Promise.resolve()
|
|
101
104
|
let publications = 0
|
|
102
105
|
const post = async (kind: string, value: unknown) => {
|
|
103
|
-
const path = `${WORKSPACE_ROUTES}
|
|
106
|
+
const path = `${WORKSPACE_ROUTES}${resource}/${kind}?${new URLSearchParams(documentQuery)}`
|
|
104
107
|
const response = await ctx.presmium.server.request(path, { method: 'POST', body: value, signal: controller.signal })
|
|
105
108
|
if (!response.ok) throw new Error('client-publication-refused')
|
|
106
109
|
return response.json() as Promise<unknown>
|
|
@@ -120,8 +123,8 @@ export function apply(ctx: EventContext): void {
|
|
|
120
123
|
if (!current()) return
|
|
121
124
|
if (!validateAuthoringClientLease(value)) throw new Error('client-registration-invalid')
|
|
122
125
|
lease = value
|
|
123
|
-
const query = new URLSearchParams({
|
|
124
|
-
const path = `${WORKSPACE_ROUTES}
|
|
126
|
+
const query = new URLSearchParams({ ...documentQuery, clientId: lease.clientId, epoch: lease.epoch, connectionId: lease.connectionId })
|
|
127
|
+
const path = `${WORKSPACE_ROUTES}${resource}/events?${query}`
|
|
125
128
|
source = new EventSource(new URL(path, endpoint.url), {
|
|
126
129
|
fetch: (_address, init) => ctx.presmium.server.request(path, { headers: { ...Object.fromEntries(new Headers(init?.headers)), 'X-Presmium-Authoring-Client': value.credential }, signal: init?.signal ? AbortSignal.any([controller.signal, init.signal]) : controller.signal }),
|
|
127
130
|
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const zh = {
|
|
2
|
+
opening: '正在打开工作区…',
|
|
3
|
+
failed: '无法打开工作区。可以重试,或查看详细信息。',
|
|
4
|
+
slow: '打开工作区所需时间较长,你可以继续等待或重试。',
|
|
5
|
+
retry: '重试', details: '详细信息',
|
|
6
|
+
}
|
|
7
|
+
export const STARTUP_MESSAGES = {
|
|
8
|
+
'zh-CN': zh,
|
|
9
|
+
en: {
|
|
10
|
+
opening: 'Opening your workspace…',
|
|
11
|
+
failed: 'The workspace could not open. Retry or view details.',
|
|
12
|
+
slow: 'Opening the workspace is taking longer than usual. You can keep waiting or retry.',
|
|
13
|
+
retry: 'Retry', details: 'Details',
|
|
14
|
+
} satisfies typeof zh,
|
|
15
|
+
}
|
package/src/workspace-events.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { z } from 'zod'
|
|
|
2
2
|
|
|
3
3
|
/** One authenticated Studio socket carries these existing workspace subscriptions. */
|
|
4
4
|
export const WORKSPACE_EVENTS_PATH = '/api/presmium/events'
|
|
5
|
-
export const WORKSPACE_EVENT_TOPICS = ['document', 'diagnostics', 'review', 'ir', 'jobs'] as const
|
|
5
|
+
export const WORKSPACE_EVENT_TOPICS = ['document', 'diagnostics', 'review', 'ir', 'jobs', 'agent-activity'] as const
|
|
6
6
|
const subscriptionId = z.string().min(1).max(80)
|
|
7
7
|
|
|
8
8
|
const viewerSite = z.strictObject({ type: z.literal('subscribe'), id: subscriptionId, topic: z.literal('viewer-site'), document: z.string().max(1024), app: z.string().max(200), lang: z.string().max(80), form: z.enum(['web', 'slides']) })
|
|
@@ -12,6 +12,7 @@ const approvals = z.strictObject({ type: z.literal('subscribe'), id: subscriptio
|
|
|
12
12
|
|
|
13
13
|
export const workspaceEventCommand = z.union([
|
|
14
14
|
z.strictObject({ type: z.literal('subscribe'), id: subscriptionId, topic: z.literal('authoring-client'), document: z.string().max(1024), clientId: subscriptionId, epoch: subscriptionId, snapshot: z.unknown() }),
|
|
15
|
+
z.strictObject({ type: z.literal('subscribe'), id: subscriptionId, topic: z.literal('authoring-window'), clientId: subscriptionId, epoch: subscriptionId, snapshot: z.unknown() }),
|
|
15
16
|
z.strictObject({ type: z.literal('authoring-client-publish'), id: subscriptionId, connectionId: subscriptionId, sequence: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER), kind: z.enum(['state', 'ack']), value: z.unknown() }),
|
|
16
17
|
viewerSite, viewerControl, approvals,
|
|
17
18
|
z.strictObject({ type: z.literal('subscribe'), id: subscriptionId, topic: z.enum(WORKSPACE_EVENT_TOPICS), document: z.string().max(1024) }),
|
|
@@ -26,6 +27,6 @@ export const workspaceEventMessage = z.discriminatedUnion('type', [
|
|
|
26
27
|
z.strictObject({ type: z.literal('event'), id: subscriptionId, event: z.string().max(40).optional(), data: z.string() }),
|
|
27
28
|
])
|
|
28
29
|
|
|
29
|
-
export type WorkspaceEventTopic = typeof WORKSPACE_EVENT_TOPICS[number] | 'viewer-site' | 'viewer-control' | 'approvals' | 'authoring-client'
|
|
30
|
+
export type WorkspaceEventTopic = typeof WORKSPACE_EVENT_TOPICS[number] | 'viewer-site' | 'viewer-control' | 'approvals' | 'authoring-client' | 'authoring-window'
|
|
30
31
|
export type WorkspaceEventCommand = z.infer<typeof workspaceEventCommand>
|
|
31
32
|
export type WorkspaceEventMessage = z.infer<typeof workspaceEventMessage>
|
package/web.patch.yml
CHANGED
|
@@ -10,6 +10,20 @@
|
|
|
10
10
|
|
|
11
11
|
- id: harness-dev-context
|
|
12
12
|
disabled: true
|
|
13
|
+
- id: agent-preset-registry
|
|
14
|
+
disabled: false
|
|
15
|
+
- id: open-in-app
|
|
16
|
+
disabled: true
|
|
17
|
+
- id: job-controller
|
|
18
|
+
disabled: true
|
|
19
|
+
- id: terminal-controller
|
|
20
|
+
disabled: true
|
|
21
|
+
- id: ui-sidebar-terminal
|
|
22
|
+
disabled: true
|
|
23
|
+
- id: ui-jobs
|
|
24
|
+
disabled: true
|
|
25
|
+
- id: workspace-changes
|
|
26
|
+
disabled: true
|
|
13
27
|
|
|
14
28
|
- insert:
|
|
15
29
|
- id: presmium-workbench
|
|
@@ -79,18 +93,16 @@
|
|
|
79
93
|
name: '@deepseek-ai/dsh-time-context'
|
|
80
94
|
- id: tool-bash
|
|
81
95
|
name: '@deepseek-ai/dsh-tool-bash'
|
|
96
|
+
config:
|
|
97
|
+
enableRunInBackground: false
|
|
82
98
|
disabled: !!js process.platform === 'win32'
|
|
83
99
|
- id: tool-pwsh
|
|
84
100
|
name: '@deepseek-ai/dsh-tool-pwsh'
|
|
101
|
+
config:
|
|
102
|
+
enableRunInBackground: false
|
|
85
103
|
disabled: !!js process.platform !== 'win32'
|
|
86
104
|
- id: tool-fs
|
|
87
105
|
name: '@deepseek-ai/dsh-tool-fs'
|
|
88
|
-
- id: tool-fs-search
|
|
89
|
-
name: '@deepseek-ai/dsh-tool-fs-search'
|
|
90
|
-
config:
|
|
91
|
-
sampleOverCapGlobResults: false
|
|
92
|
-
- id: tool-jobs
|
|
93
|
-
name: '@deepseek-ai/dsh-tool-jobs'
|
|
94
106
|
- id: skill-filesystem
|
|
95
107
|
name: '@deepseek-ai/dsh-skill-filesystem'
|
|
96
108
|
- id: tool-skill
|
package/src/client/mascot.tsx
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { PmMascot, PmSegmented, setMascotEnabled, useAssistantMascot, useMascotEnabled, WorkbenchProvider } from '@lincyaw/workbench'
|
|
2
|
-
import type { Workbench } from '@lincyaw/workbench'
|
|
3
|
-
import { MASCOT_SETTING, MASCOT_SLOT } from './contract.ts'
|
|
4
|
-
import { useClientMessages } from './messages.ts'
|
|
5
|
-
|
|
6
|
-
/** The session header's standard prop: a selector over the bound session's snapshot. */
|
|
7
|
-
type UseSession = <T>(select: (snapshot: { running?: boolean }) => T) => T
|
|
8
|
-
|
|
9
|
-
function Kitten({ running }: { running: boolean }) {
|
|
10
|
-
return <span className="pmw-conversation-mascot"><PmMascot size="small" action={useAssistantMascot(running)} /></span>
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function MascotSetting({ workbench }: { workbench: Workbench }) {
|
|
14
|
-
const t = useClientMessages(workbench)
|
|
15
|
-
const on = useMascotEnabled()
|
|
16
|
-
return (
|
|
17
|
-
<div className="pmw-mascot-setting pm-ui" data-pmw-setting="mascot">
|
|
18
|
-
<div className="pmw-mascot-setting__copy">
|
|
19
|
-
<p className="pmw-mascot-setting__title">{t.mascot}</p>
|
|
20
|
-
<p className="pmw-mascot-setting__hint">{t.mascotHint}</p>
|
|
21
|
-
</div>
|
|
22
|
-
<PmSegmented label={t.mascot} value={on ? 'show' : 'hide'} options={[{ value: 'show', label: t.mascotShow }, { value: 'hide', label: t.mascotHide }]} onChange={value => setMascotEnabled(value === 'show')} />
|
|
23
|
-
</div>
|
|
24
|
-
)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** Puts the kitten in the conversation's header, where it acts out what the assistant is doing, and its switch in
|
|
28
|
-
* Settings → General. */
|
|
29
|
-
export function registerMascot(ctx: DshClientContext, workbench: Workbench): void {
|
|
30
|
-
ctx.effect(() => ctx.slots.inject(MASCOT_SLOT.name, () => ctx.slots.register({ name: MASCOT_SLOT.name, id: MASCOT_SLOT.id, order: -100 }, ({ useSession }: { useSession: UseSession }) => {
|
|
31
|
-
const running = useSession(snapshot => Boolean(snapshot.running))
|
|
32
|
-
return <WorkbenchProvider workbench={workbench}><Kitten running={running} /></WorkbenchProvider>
|
|
33
|
-
})), 'presmium: the kitten beside the conversation')
|
|
34
|
-
ctx.effect(() => ctx.slots.inject(MASCOT_SETTING.name, () => ctx.slots.register({ name: MASCOT_SETTING.name, id: MASCOT_SETTING.id, order: 1000 }, () => (
|
|
35
|
-
<WorkbenchProvider workbench={workbench}><MascotSetting workbench={workbench} /></WorkbenchProvider>
|
|
36
|
-
))), 'presmium: the kitten\'s switch in Settings')
|
|
37
|
-
}
|