@p-dsh-market/conversation-knowledge-map 0.1.1 → 0.1.2

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.
@@ -258,6 +258,7 @@ export class KnowledgeGenerationOrchestrator {
258
258
  agentDefaultModel,
259
259
  storage,
260
260
  modelRunner,
261
+ sessionEventSource,
261
262
  sourceReader = readSelectedSurfaces,
262
263
  now = () => Date.now(),
263
264
  idFactory = () => randomUUID()
@@ -268,6 +269,7 @@ export class KnowledgeGenerationOrchestrator {
268
269
  this.agentDefaultModel = agentDefaultModel
269
270
  this.storage = storage
270
271
  this.modelRunner = modelRunner
272
+ this.sessionEventSource = sessionEventSource
271
273
  this.sourceReader = sourceReader
272
274
  this.now = now
273
275
  this.idFactory = idFactory
@@ -450,28 +452,42 @@ export class KnowledgeGenerationOrchestrator {
450
452
  const model = String(selection?.model || '').trim()
451
453
  if (!provider || !model) throw new Error('当前没有可用的默认 Provider/Model。')
452
454
  const sessionId = `knowledge-map-${this.idFactory()}`
453
- const handle = await this.agents.create({
454
- sessionId,
455
- meta: { cwd: input.cwd, origin: 'subagent' },
456
- agentOptions: { provider, model, maxTokens: input.kind === 'summary' ? 2500 : 6000 },
457
- signal: input.signal,
458
- setup: async (agentCtx) => {
459
- agentCtx?.systemPrompt?.section?.({
460
- name: 'knowledge-map:protocol',
461
- order: 0,
462
- text: '你是 DSH 知识视图生成器。只输出调用方要求的 JSON;不要调用外部网络、文件写入或其他 Agent 工具。'
455
+ const liveEvents = []
456
+ let unsubscribe
457
+ if (typeof this.sessionEventSource === 'function') {
458
+ try {
459
+ unsubscribe = this.sessionEventSource((session, event) => {
460
+ const eventSessionId = String(session?.id || session?.header?.id || '')
461
+ if (eventSessionId === sessionId && event) liveEvents.push(event)
463
462
  })
464
- try {
465
- agentCtx?.tools?.restrict?.({ deny: ['multi_agent_discuss', 'shell', 'filesystem', 'web_search', 'browser'] })
466
- } catch { /* older runtimes may not expose tool restriction */ }
467
- }
468
- })
463
+ } catch { /* event subscription is an optimization; surface reads remain the fallback */ }
464
+ }
465
+ let handle
469
466
  try {
467
+ handle = await this.agents.create({
468
+ sessionId,
469
+ meta: { cwd: input.cwd, origin: 'subagent' },
470
+ agentOptions: { provider, model, maxTokens: input.kind === 'summary' ? 2500 : 6000 },
471
+ signal: input.signal,
472
+ setup: async (agentCtx) => {
473
+ agentCtx?.systemPrompt?.section?.({
474
+ name: 'knowledge-map:protocol',
475
+ order: 0,
476
+ text: '你是 DSH 知识视图生成器。只输出调用方要求的 JSON;不要调用外部网络、文件写入或其他 Agent 工具。'
477
+ })
478
+ try {
479
+ agentCtx?.tools?.restrict?.({ deny: ['multi_agent_discuss', 'shell', 'filesystem', 'web_search', 'browser'] })
480
+ } catch { /* older runtimes may not expose tool restriction */ }
481
+ }
482
+ })
470
483
  handle.agent.followup(makeUserMessage(input.prompt, `${sessionId}-${input.kind}`))
471
484
  await handle.agent.whenIdle()
485
+ const liveText = extractAgentText({ events: liveEvents })
486
+ if (liveText.trim()) return parseStructuredOutput(liveText)
472
487
  return parseStructuredOutput(await readAgentText(this.sessionQuery, sessionId, input.signal))
473
488
  } finally {
474
- await handle.dispose?.()
489
+ await unsubscribe?.()
490
+ await handle?.dispose?.()
475
491
  }
476
492
  }
477
493
 
package/lib/index.js CHANGED
@@ -111,13 +111,15 @@ export function createHost(options = {}) {
111
111
  const skills = options.skills || getService(ctx, 'skills')
112
112
  const webServer = options.webServer || getService(ctx, 'webServer')
113
113
  const storage = options.storage || new WorkspaceStorage(options.storageOptions)
114
+ const sessionEventSource = options.sessionEventSource || (typeof ctx?.on === 'function' ? (listener) => ctx.on('session/event', listener) : null)
114
115
  const orchestrator = options.orchestrator || new KnowledgeGenerationOrchestrator({
115
116
  sessionQuery,
116
117
  sessions,
117
118
  agents,
118
119
  agentDefaultModel,
119
120
  storage,
120
- modelRunner: options.modelRunner
121
+ modelRunner: options.modelRunner,
122
+ sessionEventSource
121
123
  })
122
124
  const confirmations = new Map()
123
125
  const sseClients = new Set()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@p-dsh-market/conversation-knowledge-map",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "DSH 多对话思维导图与静态知识图谱",
5
5
  "keywords": [
6
6
  "dsh",