dsh-plugin-weapp-gateway 0.8.53 → 0.8.55

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/PROTOCOL.md +26 -12
  3. package/README.en.md +410 -0
  4. package/README.md +16 -0
  5. package/README.zh-CN.md +425 -0
  6. package/cordis.patch.yml +2 -0
  7. package/docs/agent-team-app-integration.md +76 -55
  8. package/docs/android-connectors-alignment.md +73 -0
  9. package/docs/dsh-0.2.2-rc.1-mobile-integration.md +269 -0
  10. package/docs/dsh-0.2.2-rc.3-compatibility-audit.md +145 -0
  11. package/docs/file-cards-mobile-integration.md +111 -0
  12. package/docs/file-changes-app-integration.md +277 -0
  13. package/docs/generated-images-mobile-integration.md +125 -0
  14. package/docs/iphone-connector-actions.md +69 -0
  15. package/docs/iphone-map-markers.md +41 -0
  16. package/docs/iphone-maps-connectors.md +56 -0
  17. package/docs/iphone-music-cards.md +28 -0
  18. package/docs/map-app-adapters.md +57 -0
  19. package/docs/phone-connectors-implementation.md +105 -0
  20. package/docs/phone-connectors.md +91 -0
  21. package/docs/readme/README.de.md +404 -0
  22. package/docs/readme/README.es.md +404 -0
  23. package/docs/readme/README.fr.md +404 -0
  24. package/docs/readme/README.ja.md +404 -0
  25. package/docs/readme/README.ko.md +404 -0
  26. package/docs/readme/README.pt-BR.md +404 -0
  27. package/lib/client.js +82 -27
  28. package/lib/cloudflare-tunnel.mjs +6 -2
  29. package/lib/cloudflared-binary.mjs +10 -24
  30. package/lib/device-tool-validation.mjs +173 -0
  31. package/lib/device-tools.mjs +119 -0
  32. package/lib/devices.js +29 -7
  33. package/lib/dsh-host-adapter.mjs +169 -36
  34. package/lib/dsh-runtime-version.mjs +22 -0
  35. package/lib/index.mjs +253 -102
  36. package/lib/logging.mjs +16 -0
  37. package/lib/message-text.mjs +51 -0
  38. package/lib/phone-request-sources.mjs +91 -0
  39. package/lib/phone-tools.mjs +248 -0
  40. package/lib/plugin-management.mjs +24 -0
  41. package/lib/schedule-management.mjs +130 -0
  42. package/lib/session-target.mjs +16 -0
  43. package/lib/tool-images.mjs +32 -0
  44. package/lib/web-restart.mjs +11 -8
  45. package/lib/workspace-changes.mjs +162 -0
  46. package/package.json +8 -3
@@ -1,6 +1,11 @@
1
+ import { createWorkspaceChangesAdapter } from './workspace-changes.mjs'
2
+ import { resolveDshRuntimeVersion } from './dsh-runtime-version.mjs'
1
3
  import crypto from 'node:crypto'
2
4
  import os from 'node:os'
3
5
  import { Readable } from 'node:stream'
6
+ import { sessionAddress, normalizeProjectionValues, normalizeTeamProjection } from './session-target.mjs'
7
+ import { userMessageTextParts } from './message-text.mjs'
8
+ import { toolImages } from './tool-images.mjs'
4
9
 
5
10
  function requireRecord(value, endpoint) {
6
11
  if (value === null || typeof value !== 'object' || Array.isArray(value)) {
@@ -14,6 +19,7 @@ function requireArray(value, endpoint) {
14
19
  return value
15
20
  }
16
21
 
22
+ // 适配基线,用于契约测试和未知宿主的默认接口选择,不作为运行时版本上报。
17
23
  // The current session address, upload and Peer routes are provided by this
18
24
  // Host baseline. Keep the hello value truthful so clients can gate features.
19
25
  export const DSH_VERSION = '0.2.1-rc.2'
@@ -25,7 +31,8 @@ export function readHistoryRecords(records) {
25
31
  if (value.type !== 'event') throw new Error('DSH Session V4 history requires event records')
26
32
  const event = requireRecord(value.event, 'session history event')
27
33
  if (!Number.isSafeInteger(event.seq) || event.seq < 0) throw new Error('invalid history sequence')
28
- return event
34
+ const textParts = event.type === 'user/message' ? userMessageTextParts(event.data?.content) : undefined
35
+ return textParts ? { ...event, data: { ...event.data, textParts } } : event
29
36
  })
30
37
  }
31
38
 
@@ -41,7 +48,11 @@ export function readSessionSnapshot(frame, sessionId) {
41
48
  return {
42
49
  events: readHistoryRecords(frame.records).map(event => ({ event })),
43
50
  hasMore: frame.hasMore === true,
44
- projections: requireRecord(frame.projections, 'session/follow projections'),
51
+ projections: {
52
+ ...requireRecord(frame.projections, 'session/follow projections'),
53
+ ...(Object.hasOwn(frame.projections, 'values')
54
+ ? { values: normalizeProjectionValues(frame.projections.values) } : {}),
55
+ },
45
56
  historyFormatVersion: frame.header.version,
46
57
  cursor: frame.cursor,
47
58
  }
@@ -81,7 +92,7 @@ function sessionListArgs(request) {
81
92
  * descriptors. Its public methods intentionally match weapp-gateway domain
82
93
  * operations, not the upstream transport envelope.
83
94
  */
84
- export function createDshHostAdapter(typertGateway, connection) {
95
+ export function createDshHostAdapter(typertGateway, peer, connection, { runtimeVersion = resolveDshRuntimeVersion() ?? '0.2.2-rc.3' } = {}) {
85
96
  if (!typertGateway || typeof typertGateway.invoke !== 'function' || typeof typertGateway.stream !== 'function') {
86
97
  throw new Error('weapp-gateway requires the DSH Remote Gateway host service')
87
98
  }
@@ -94,17 +105,27 @@ export function createDshHostAdapter(typertGateway, connection) {
94
105
  // 0.2.0-rc.2 ignore the field, so always naming it works on both. The plugin
95
106
  // speaks as the Host itself — an owner Peer living as long as this adapter,
96
107
  // so disposing the plugin ends every stream it opened.
108
+ // 无有效 Peer 时自建 owner Peer(fork 兼容旧调用 createDshHostAdapter(gateway))。
97
109
  const peerLifetime = new AbortController()
98
- const hostPeer = typeof connection?.createPeer === 'function'
99
- ? connection.createPeer({ principal: { kind: 'owner' }, interactions: 'none' })
100
- : {
110
+ // 旧调用形态 createDshHostAdapter(gateway, connection):第二参其实是 connection。
111
+ if (connection === undefined && peer && typeof peer === 'object' && !Array.isArray(peer)
112
+ && typeof peer.createSharedFetchHandler === 'function') {
113
+ connection = peer
114
+ peer = typeof connection.createPeer === 'function'
115
+ ? connection.createPeer({ principal: { kind: 'owner' }, interactions: 'none' })
116
+ : undefined
117
+ }
118
+ if (!peer || !(peer.signal instanceof AbortSignal)) {
119
+ // 无有效 Peer 时自建 owner Peer(fork 兼容旧调用 createDshHostAdapter(gateway))。
120
+ peer = {
101
121
  id: `weapp-gateway:${crypto.randomUUID()}`,
102
122
  principal: Object.freeze({ kind: 'owner' }),
103
123
  interactions: 'none',
104
124
  signal: peerLifetime.signal,
105
125
  dispose: async () => { peerLifetime.abort(new Error('weapp-gateway host adapter disposed')) },
106
126
  }
107
- if (!(hostPeer?.signal instanceof AbortSignal)) throw new Error('DSH Connection.createPeer returned an invalid Peer')
127
+ }
128
+ const usedPeer = peer
108
129
 
109
130
  // Reuse DSH's authenticated in-process route for binary file admission.
110
131
  // Older hosts without this route remain usable; the capability is omitted.
@@ -117,8 +138,22 @@ export function createDshHostAdapter(typertGateway, connection) {
117
138
  method,
118
139
  args,
119
140
  ...(signal === undefined ? {} : { signal }),
120
- peer: hostPeer,
141
+ peer: usedPeer,
121
142
  })
143
+ const stream = (namespace, method, args, signal) => typertGateway.stream({
144
+ namespace, method, args, peer: usedPeer, signal,
145
+ })
146
+ const controlVersion = runtimeVersion ?? DSH_VERSION
147
+ // RC.2 起统一子代理控制接口;旧宿主继续使用原描述符。
148
+ const core = controlVersion.split(/[+-]/)[0].split('.').map(Number)
149
+ const minimum = [0, 2, 2]
150
+ const changed = core.findIndex((part, index) => part !== minimum[index])
151
+ const unifiedSubagents = changed < 0
152
+ ? !controlVersion.includes('-') || Number(controlVersion.match(/-rc\.(\d+)/)?.[1]) >= 2
153
+ : core[changed] > minimum[changed]
154
+ // Dispatch in-process through the official authenticated route; no loopback
155
+ // HTTP listener, browser cookie, or public /api exposure is required.
156
+
122
157
 
123
158
  // 子智能体(subagent)会话必须带持久父地址寻址:host 对裸 sessionId 的
124
159
  // 子会话读历史会直接以 session/agent-busy 拒绝("subagent Sessions require
@@ -140,7 +175,7 @@ export function createDshHostAdapter(typertGateway, connection) {
140
175
  'follow',
141
176
  requestArgs(request),
142
177
  signal,
143
- hostPeer,
178
+ usedPeer,
144
179
  ), 'session/follow')
145
180
  return readSessionSnapshot(frame, addressSessionId(request.address))
146
181
  }
@@ -177,6 +212,34 @@ export function createDshHostAdapter(typertGateway, connection) {
177
212
  'session/modelCatalog',
178
213
  )
179
214
 
215
+ // 新版 Host 接受完整图片引用。旧移动协议仍由会话历史决定可读取的附件。
216
+ const attachment = async (payload, signal) => {
217
+ let beforeSeq
218
+ let throughSeq
219
+ while (true) {
220
+ const page = requireRecord(await invoke('session', 'events', requestArgs({
221
+ address: sessionAddress(payload), maxMessages: 100,
222
+ ...(beforeSeq === undefined ? {} : { beforeSeq, throughSeq }),
223
+ }), signal), 'session/events')
224
+ if (!Number.isSafeInteger(page.cursor) || page.cursor < -1) throw new Error('invalid attachment history cursor')
225
+ throughSeq ??= page.cursor
226
+ const events = readHistoryRecords(page.records)
227
+ for (const event of events) {
228
+ const data = event.data || {}
229
+ const refs = toolImages({ ...data, message: data.message ?? { content: data.content } })
230
+ const ref = refs.find(item => item.attachmentId === payload.attachmentId)
231
+ if (ref) return invoke('session', 'attachment', requestArgs({ sessionId: payload.sessionId, attachment: ref }), signal)
232
+ }
233
+ if (!page.hasMore) break
234
+ const oldest = events[0]?.seq
235
+ if (!Number.isSafeInteger(oldest) || (beforeSeq !== undefined && oldest >= beforeSeq)) {
236
+ throw new Error('attachment history did not advance')
237
+ }
238
+ beforeSeq = oldest
239
+ }
240
+ throw Object.assign(new Error('Image is not referenced by this session'), { code: 'session/attachment-invalid' })
241
+ }
242
+
180
243
  // Control and conversation sockets share this adapter. Admit a prompt only
181
244
  // after an earlier preset switch finishes, and re-check later switches.
182
245
  const sessionOperations = new Map()
@@ -223,6 +286,7 @@ export function createDshHostAdapter(typertGateway, connection) {
223
286
  return { ref: { id: goal.id, revision: goal.revision } }
224
287
  }
225
288
 
289
+ const dshVersion = runtimeVersion
226
290
  const describeHost = async (signal) => {
227
291
  const [sessions, catalog, canOpenPath] = await Promise.all([
228
292
  invoke('session', 'list', sessionListArgs({}), signal),
@@ -245,21 +309,45 @@ export function createDshHostAdapter(typertGateway, connection) {
245
309
  }
246
310
 
247
311
  return {
312
+ agentTeams: {
313
+ available: () => unifiedSubagents,
314
+ async setEnabled({ sessionId, enabled }, signal) {
315
+ if (!unifiedSubagents) throw Object.assign(new Error('Team mode control requires DSH RC.2 or later'), { code: 'unsupported' })
316
+ return serializeSession(sessionId, async () => {
317
+ // 同一个认证 Peer 调用官方根会话接口;由 Host 校验根身份、权限及持久化。
318
+ await invoke('agentTeams', 'setEnabled', { agentId: sessionId, enabled }, signal)
319
+ const snapshot = await invoke('session', 'projections', requestArgs({ sessionId }), signal)
320
+ const team = normalizeTeamProjection(snapshot?.values?.agentTeam)
321
+ if (snapshot?.kind !== 'sequenced' || !Number.isSafeInteger(snapshot.asOfSeq)
322
+ || typeof team?.enabled !== 'boolean') {
323
+ throw Object.assign(new Error('Team mode saved but its current projection is unavailable; refresh before retrying'), { code: 'team-mode-unconfirmed' })
324
+ }
325
+ return { agentTeam: team, asOfSeq: snapshot.asOfSeq, projectionState: 'ready' }
326
+ })
327
+ },
328
+ },
329
+ workspaceChanges: createWorkspaceChangesAdapter(uploadHandler, usedPeer),
248
330
  files: {
331
+ stat: ({ sessionId, path }, signal) => invoke('workspaceFiles', 'stat', {
332
+ workspaceFileScopeId: sessionId, path,
333
+ }, signal),
334
+ readBytes: ({ sessionId, path, offset, length }, signal) => invoke('workspaceFiles', 'readBytes', {
335
+ workspaceFileScopeId: sessionId, path, options: { range: { offset, length } },
336
+ }, signal),
249
337
  available: uploadsAvailable,
250
338
  async upload({ sessionId, name, data }, signal) {
251
339
  if (!uploadsAvailable()) throw Object.assign(new Error('The official file upload service is unavailable'), { code: 'file-upload-unavailable' })
252
340
  const url = new URL(uploadUrl)
253
341
  url.searchParams.set('sessionId', sessionId)
254
342
  url.searchParams.set('name', name)
255
- const uploadSignal = signal ? AbortSignal.any([signal, hostPeer.signal]) : hostPeer.signal
343
+ const uploadSignal = signal ? AbortSignal.any([signal, usedPeer.signal]) : usedPeer.signal
256
344
  uploadSignal.throwIfAborted()
257
345
  const source = Readable.from(data, { objectMode: false })
258
346
  try {
259
347
  const response = await uploadHandler.fetch(new Request(url, {
260
348
  method: 'POST', headers: { 'content-type': 'application/octet-stream' },
261
349
  body: Readable.toWeb(source), duplex: 'half', signal: uploadSignal,
262
- }), hostPeer)
350
+ }), usedPeer)
263
351
  if (!response.ok) throw Object.assign(new Error(`Official file upload returned HTTP ${response.status}`), { code: 'file-upload-unavailable' })
264
352
  const result = await response.json()
265
353
  if (result.ok !== true) throw Object.assign(new Error(result.error?.message || 'Official file upload failed'),
@@ -273,7 +361,7 @@ export function createDshHostAdapter(typertGateway, connection) {
273
361
  },
274
362
  speech: {
275
363
  catalog: (signal) => invoke('speech', 'catalog', {}, signal),
276
- follow: (signal) => typertGateway.stream({ namespace: 'speech', method: 'follow', args: {}, signal, peer: hostPeer }),
364
+ follow: (signal) => typertGateway.stream({ namespace: 'speech', method: 'follow', args: {}, signal, peer }),
277
365
  configure: (patch, signal) => invoke('speech', 'configure', { patch }, signal),
278
366
  prepare: (providerId, options, signal) => invoke('speech', 'prepare', {
279
367
  providerId, ...(options === undefined ? {} : { options }),
@@ -282,6 +370,10 @@ export function createDshHostAdapter(typertGateway, connection) {
282
370
  transcribe: (request, signal) => invoke('speech', 'transcribe', { request }, signal),
283
371
  },
284
372
  sessions: {
373
+ async projections(payload, signal) {
374
+ const snapshot = await invoke('session', 'projections', requestArgs(payload), signal)
375
+ return snapshot === null ? null : { ...snapshot, values: normalizeProjectionValues(snapshot.values) }
376
+ },
285
377
  list: (payload = {}, signal) => invoke('session', 'list', sessionListArgs(payload), signal),
286
378
  projections: (payload, signal) => invoke('session', 'projections', requestArgs(payload), signal),
287
379
  search: (payload, signal) => invoke('session', 'search', requestArgs(payload), signal),
@@ -291,13 +383,12 @@ export function createDshHostAdapter(typertGateway, connection) {
291
383
  if (payload.subagentMode !== 'continuable') {
292
384
  throw Object.assign(new Error('only continuable subagents accept messages'), { code: 'subagent/not-resumable' })
293
385
  }
386
+ // 新接口按 child 授权;先通过历史地址验证移动端声明的直接父子关系。
387
+ if (unifiedSubagents) await sessionSnapshot({ address: sessionAddress(payload), maxMessages: 1 }, signal)
294
388
  return invoke('subagents', 'prompt', requestArgs({
295
389
  requestId: payload.requestId ?? crypto.randomUUID(),
296
- parentSessionId: payload.parentSessionId,
297
- childSessionId: payload.sessionId,
298
- mode: 'continuable',
299
- delivery: payload.mode,
300
- content: payload.content,
390
+ ...(!unifiedSubagents ? { parentSessionId: payload.parentSessionId, mode: 'continuable' } : {}),
391
+ childSessionId: payload.sessionId, delivery: payload.mode, content: payload.content,
301
392
  ...(payload.clientTimeZone === undefined ? {} : { clientTimeZone: payload.clientTimeZone }),
302
393
  }), signal)
303
394
  }
@@ -312,17 +403,21 @@ export function createDshHostAdapter(typertGateway, connection) {
312
403
  throw error
313
404
  }
314
405
  }),
315
- attachment: (payload, signal) => invoke('session', 'attachment', requestArgs(payload), signal),
406
+ attachment,
316
407
  fork: (payload, signal) => invoke('session', 'fork', requestArgs(payload), signal),
317
- cancel: (payload, signal) => payload.parentSessionId === undefined
318
- ? invoke('session', 'cancel', requestArgs(payload), signal)
319
- : payload.subagentMode !== 'continuable'
320
- ? Promise.reject(Object.assign(new Error('only continuable subagents accept interrupts'), { code: 'subagent/not-resumable' }))
321
- : invoke('subagents', 'interruptByParent', {
322
- parentSessionId: payload.parentSessionId,
323
- childSessionId: payload.sessionId,
324
- mode: 'continuable',
325
- }, signal),
408
+ async cancel(payload, signal) {
409
+ if (payload.parentSessionId === undefined) return invoke('session', 'cancel', requestArgs(payload), signal)
410
+ if (payload.subagentMode !== 'continuable') {
411
+ throw Object.assign(new Error('only continuable subagents accept interrupts'), { code: 'subagent/not-resumable' })
412
+ }
413
+ if (unifiedSubagents) {
414
+ await sessionSnapshot({ address: sessionAddress(payload), maxMessages: 1 }, signal)
415
+ return invoke('subagents', 'interruptByUser', { childSessionId: payload.sessionId }, signal)
416
+ }
417
+ return invoke('subagents', 'interruptByParent', {
418
+ parentSessionId: payload.parentSessionId, childSessionId: payload.sessionId, mode: 'continuable',
419
+ }, signal)
420
+ },
326
421
  updateQueue: (payload, signal) => invoke('session', 'updateQueue', requestArgs(payload), signal),
327
422
  rename: (payload, signal) => invoke('session', 'rename', requestArgs(payload), signal),
328
423
  selectModel: (payload, signal) => invoke('session', 'selectModel', requestArgs(payload), signal),
@@ -344,7 +439,7 @@ export function createDshHostAdapter(typertGateway, connection) {
344
439
  },
345
440
  workspace: {
346
441
  async list(_payload = {}, signal) {
347
- const frame = requireRecord(await firstStreamFrame(typertGateway, 'workspace', 'follow', {}, signal, hostPeer), 'workspace/follow')
442
+ const frame = requireRecord(await firstStreamFrame(typertGateway, 'workspace', 'follow', {}, signal, usedPeer), 'workspace/follow')
348
443
  if (frame.type !== 'baseline') throw new Error('workspace/follow returned an invalid opening baseline')
349
444
  return requireRecord(frame.value, 'workspace/follow baseline')
350
445
  },
@@ -379,6 +474,9 @@ export function createDshHostAdapter(typertGateway, connection) {
379
474
  listBundles: (signal) => invoke('pluginManager', 'listBundles', {}, signal),
380
475
  listPlugins: (signal) => invoke('pluginManager', 'listPlugins', {}, signal),
381
476
  registries: (signal) => invoke('pluginManager', 'registries', {}, signal),
477
+ versions: (name, options, signal) => invoke('pluginManager', 'listVersions', { name, options }, signal),
478
+ detail: (name, language, signal) => invoke('pluginManager', 'readBundleDetail', { name, language }, signal),
479
+ update: (name, version, options) => invoke('pluginManager', 'updateBundle', { name, version, options }),
382
480
  inspect: (spec, options, signal) => invoke('pluginManager', 'inspect', {
383
481
  spec, ...(options === undefined ? {} : { options }),
384
482
  }, signal),
@@ -404,11 +502,22 @@ export function createDshHostAdapter(typertGateway, connection) {
404
502
  return { items: requireArray(await invoke('schedule', 'catalog', {}, signal), 'schedule/catalog') }
405
503
  },
406
504
  async list(payload, signal) {
407
- return { items: requireArray(await invoke('schedule', 'list', requestArgs(payload), signal), 'schedule/list') }
505
+ if (payload.sessionId !== undefined) {
506
+ const items = requireArray(await invoke('schedule', 'catalog', {}, signal), 'schedule/catalog')
507
+ .filter(item => item.status === 'active' && (item.target?.sessionId === payload.sessionId
508
+ || item.involvedSessionIds?.includes(payload.sessionId)))
509
+ return { items }
510
+ }
511
+ const result = requireRecord(await invoke('schedule', 'list', requestArgs(payload), signal), 'schedule/list')
512
+ requireArray(result.items, 'schedule/list items')
513
+ return result
408
514
  },
409
515
  history: (payload, signal) => invoke('schedule', 'history', requestArgs(payload), signal),
410
- update: (payload, signal) => invoke('schedule', 'update', requestArgs(payload), signal),
411
- delete: (payload, signal) => invoke('schedule', 'delete', requestArgs(payload), signal),
516
+ view: (payload, signal) => invoke('schedule', 'view', requestArgs(payload), signal),
517
+ create: (payload, signal) => invoke('schedule', 'create', requestArgs(payload), signal),
518
+ edit: (payload, signal) => invoke('schedule', 'edit', requestArgs(payload), signal),
519
+ run: (payload, signal) => invoke('schedule', 'run', requestArgs(payload), signal),
520
+ deleteInactive: (_payload, signal) => invoke('schedule', 'deleteInactive', {}, signal),
412
521
  },
413
522
  skills: {
414
523
  list: (payload, signal) => invoke('skills', 'list', requestArgs(payload), signal),
@@ -480,6 +589,7 @@ export function createDshHostAdapter(typertGateway, connection) {
480
589
  describe: (_payload = {}, signal) => describeHost(signal),
481
590
  },
482
591
  describeHost,
592
+ dshVersion,
483
593
  observeSessionEvent(sessionId, event) {
484
594
  if (event.type === 'turn/start') admittedPrompts.delete(sessionId)
485
595
  },
@@ -496,19 +606,42 @@ export function createDshHostAdapter(typertGateway, connection) {
496
606
  // Bound the opening window at the Host; older records remain available via session.page.
497
607
  args: requestArgs({ address, maxMessages: 12, assistantStream: true }),
498
608
  signal,
499
- peer: hostPeer,
609
+ peer: usedPeer,
500
610
  })
501
611
  },
502
- openControlStream(signal) {
503
- return typertGateway.stream({ namespace: 'session', method: 'control', args: {}, signal, peer: hostPeer })
612
+ async *openControlStream(signal) {
613
+ for await (const frame of await stream('session', 'control', {}, signal)) {
614
+ if (frame.type === 'baseline' && frame.value?.projections) {
615
+ yield { ...frame, value: { ...frame.value, projections: Object.fromEntries(
616
+ Object.entries(frame.value.projections).map(([id, baseline]) => [id,
617
+ { ...baseline, values: normalizeProjectionValues(baseline.values) }]),
618
+ ) } }
619
+ continue
620
+ }
621
+ if (frame.type !== 'projection' || !Object.hasOwn(frame, 'changes')) {
622
+ yield frame.type === 'projection' && frame.key === 'agentTeam'
623
+ ? { ...frame, value: normalizeTeamProjection(frame.value) } : frame
624
+ continue
625
+ }
626
+ const changes = requireArray(frame.changes, 'session/control changes')
627
+ for (const change of changes) {
628
+ if (typeof change?.key !== 'string' || !Object.hasOwn(change, 'val')) {
629
+ throw new Error('session/control returned an invalid projection change')
630
+ }
631
+ }
632
+ for (const { key, val } of changes) {
633
+ yield { type: 'projection', sessionId: frame.sessionId, seq: frame.seq, key,
634
+ value: key === 'agentTeam' ? normalizeTeamProjection(val) : val }
635
+ }
636
+ }
504
637
  },
505
638
  openWorkspaceStream(signal) {
506
- return typertGateway.stream({ namespace: 'workspace', method: 'follow', args: {}, signal, peer: hostPeer })
639
+ return typertGateway.stream({ namespace: 'workspace', method: 'follow', args: {}, signal, peer })
507
640
  },
508
641
  // Ends every stream this adapter opened: the host Peer's signal is joined
509
642
  // into each one by the 0.2.1 Gateway.
510
643
  dispose() {
511
- if (typeof hostPeer.dispose === 'function') return hostPeer.dispose()
644
+ if (typeof usedPeer.dispose === 'function') return usedPeer.dispose()
512
645
  peerLifetime.abort(new Error('weapp-gateway host adapter disposed'))
513
646
  },
514
647
  }
@@ -0,0 +1,22 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+ import { createRequire } from 'node:module'
4
+
5
+ /** 从宿主入口解析启动包,避免误读插件依赖或 PATH 上另一份 DSH 的版本。 */
6
+ export function resolveDshRuntimeVersion(entrypoint = process.argv[1]) {
7
+ if (!entrypoint) return undefined
8
+ try {
9
+ const entry = fs.realpathSync(path.resolve(entrypoint))
10
+ const require = createRequire(entry)
11
+ const filename = require.resolve('@deepseek-ai/dsh-app-boot/package.json')
12
+ const manifest = JSON.parse(fs.readFileSync(filename, 'utf8'))
13
+ const version = manifest.version
14
+ // 探测失败时省略字段,不能把适配基线伪装成实际版本。
15
+ return manifest.name === '@deepseek-ai/dsh-app-boot'
16
+ && typeof version === 'string'
17
+ && /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(version)
18
+ ? version : undefined
19
+ } catch {
20
+ return undefined
21
+ }
22
+ }