@try-works/dsh-memory 0.1.7 → 0.1.9
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 +1 -1
- package/src/client/index.js +18 -1
- package/src/tools.js +10 -0
package/package.json
CHANGED
package/src/client/index.js
CHANGED
|
@@ -358,6 +358,11 @@ window.__ModuleLoader__.load({
|
|
|
358
358
|
*/
|
|
359
359
|
const MEMORY_STATE_NONE = { kind: 'none', meta: null, seq: null, time: null }
|
|
360
360
|
const MEMORY_STATE_UNAVAILABLE = { kind: 'unavailable', meta: null, seq: null, time: null }
|
|
361
|
+
// Distinct from NONE on purpose. PTC mode dispatches a tool from inside a run_code program and
|
|
362
|
+
// records tool/ptc-dispatch, which carries the rendered text but NO structured value, so there
|
|
363
|
+
// is genuinely nothing to draw - and telling the reader 'memory_map has not run here' would be
|
|
364
|
+
// false.
|
|
365
|
+
const MEMORY_STATE_NESTED = { kind: 'nested', meta: null, seq: null, time: null }
|
|
361
366
|
|
|
362
367
|
/**
|
|
363
368
|
* Find the newest memory_map result in the window and say what it carried.
|
|
@@ -370,10 +375,13 @@ window.__ModuleLoader__.load({
|
|
|
370
375
|
const entries = window && Array.isArray(window.entries) ? window.entries : null
|
|
371
376
|
if (!entries) return MEMORY_STATE_NONE
|
|
372
377
|
const calls = Object.create(null)
|
|
378
|
+
let nested = false
|
|
373
379
|
for (let i = 0; i < entries.length; i += 1) {
|
|
374
380
|
const entry = entries[i]
|
|
375
381
|
const event = entry && entry.type === 'event' ? entry.event : null
|
|
376
382
|
if (event && event.type === 'tool/call' && event.data && event.data.name === 'memory_map') calls[event.data.callId] = true
|
|
383
|
+
// A nested dispatch is a real call the agent made; it simply has no structured result.
|
|
384
|
+
if (event && event.type === 'tool/ptc-dispatch' && event.data && event.data.name === 'memory_map') nested = true
|
|
377
385
|
}
|
|
378
386
|
// Newest first: the tab describes the session as it stands now, not as it first was.
|
|
379
387
|
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
@@ -392,7 +400,7 @@ window.__ModuleLoader__.load({
|
|
|
392
400
|
if (meta === null || typeof meta !== 'object') return { kind: 'empty', meta: null, seq: event.seq, time: event.time }
|
|
393
401
|
return { kind: 'ready', meta: meta, seq: event.seq, time: event.time }
|
|
394
402
|
}
|
|
395
|
-
return MEMORY_STATE_NONE
|
|
403
|
+
return nested ? MEMORY_STATE_NESTED : MEMORY_STATE_NONE
|
|
396
404
|
}
|
|
397
405
|
|
|
398
406
|
/**
|
|
@@ -493,6 +501,15 @@ window.__ModuleLoader__.load({
|
|
|
493
501
|
],
|
|
494
502
|
}
|
|
495
503
|
}
|
|
504
|
+
if (state.kind === 'nested') {
|
|
505
|
+
return {
|
|
506
|
+
title: 'memory_map ran here, but not as a readable result',
|
|
507
|
+
lines: [
|
|
508
|
+
'This session called memory_map from inside a run_code program. Those calls are recorded as nested dispatches, which keep the rendered text and not the structured value this tab draws.',
|
|
509
|
+
'Calling memory_map directly - scope "session" or "all" - records a result the panels can read.',
|
|
510
|
+
],
|
|
511
|
+
}
|
|
512
|
+
}
|
|
496
513
|
return {
|
|
497
514
|
title: 'No memory_map result in this session yet',
|
|
498
515
|
lines: [
|
package/src/tools.js
CHANGED
|
@@ -321,7 +321,17 @@ export function registerTools(ctx, store, extras = {}) {
|
|
|
321
321
|
session: { type: 'object', additionalProperties: true },
|
|
322
322
|
},
|
|
323
323
|
},
|
|
324
|
+
// The text face, for the agent and for any caller without a UI.
|
|
324
325
|
render: (_args, value) => [{ type: 'text', text: renderMap(value) }],
|
|
326
|
+
// The STRUCTURED face, and the only reason the Memory tab and the inline card can draw
|
|
327
|
+
// anything. A tool result reaches the session event with a `meta` field ONLY when the tool
|
|
328
|
+
// declares presentationMeta (core/tools/src/index.ts:1845-1859), and that field is what
|
|
329
|
+
// ui-chat forwards to a view (conversation-nodes/tool.ts:77: meta: match.event.data.meta).
|
|
330
|
+
// Without this, memory_map rendered its snapshot to prose and threw the value away: the tab
|
|
331
|
+
// showed 'the result carried no snapshot' while the same call displayed 2,197 entries in
|
|
332
|
+
// the conversation. The rendered text is not a substitute - rebuilding panels by parsing it
|
|
333
|
+
// would be a second source of truth.
|
|
334
|
+
presentationMeta: (_args, value) => value,
|
|
325
335
|
},
|
|
326
336
|
async execute(args, exec) {
|
|
327
337
|
const scope = args.scope === 'store' || args.scope === 'session' ? args.scope : 'all'
|