mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-03 14:34:40 +00:00
refactor(agent)!: migrate to Pi Durable and embed the agent queue (#525)
* refactor(agent)!: migrate sessions to Pi Durable Replace patched AgentHarness storage with per-session SQLite and PostgreSQL commit mirroring. Migrate legacy history automatically and run agent queues with the main server. BREAKING CHANGE: Remove standalone agent workers and return native Pi entry records from chat history APIs. * fix(agent): constrain session log dialog scrolling Keep the header visible and wrap long output while log entries and expanded records scroll within the dialog. Cover desktop and narrow viewports through the dashboard Sessions flow. * fix(agent): hide entry IDs from session log card headers Retain internal entry IDs in expanded raw records for debugging. Verify that card headers omit the IDs while raw JSON preserves them. * test(e2e): handle browser wheel limits in session log checks Verify that a normal wheel event moves the viewport before explicitly scrolling to the final record. Keep the dialog bounds, fixed header, wrapping, and expanded-record assertions. * fix(agent): select model providers without inheriting unrelated auth * fix(webui): prevent resize feedback when toggling agent panel * test(agent): reproduce concurrent comment session races * fix(agent): serialize comment sessions and deduplicate history * docs(changelog): consolidate Pi Durable changes into one entry
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import { BACKGROUND_CONTEXT } from '@earendil-works/chord/context'
|
||||
import { OutputBuffer } from '@earendil-works/chord/output'
|
||||
import type {
|
||||
Harness,
|
||||
JsonObject,
|
||||
ToolExecutionApi,
|
||||
ToolExecutionResult,
|
||||
ToolRegistration,
|
||||
} from '@earendil-works/pi-durable'
|
||||
|
||||
/** Exercise a tool with the native execution API while keeping assertions focused on its result. */
|
||||
export async function invokeTool<T extends ToolRegistration>(
|
||||
tool: T,
|
||||
callId: string,
|
||||
args: Parameters<T['execute']>[0],
|
||||
signal?: AbortSignal,
|
||||
onUpdate?: (update: {
|
||||
content: NonNullable<ToolExecutionResult['output']>
|
||||
details?: unknown
|
||||
}) => void,
|
||||
) {
|
||||
const buffer = new OutputBuffer({
|
||||
maxBytes: tool.outputLimits?.maxBytes ?? 50000,
|
||||
maxLines: tool.outputLimits?.maxLines ?? 2000,
|
||||
retain: tool.outputLimits?.retain ?? 'head',
|
||||
})
|
||||
let details: unknown
|
||||
const notify = () =>
|
||||
onUpdate?.({
|
||||
content: buffer.snapshot().text ? [{ type: 'text', text: buffer.snapshot().text }] : [],
|
||||
details,
|
||||
})
|
||||
const api = {
|
||||
callId,
|
||||
output: (chunk: string | Uint8Array) => {
|
||||
buffer.push(chunk)
|
||||
notify()
|
||||
},
|
||||
details: async (value: unknown) => {
|
||||
details = value
|
||||
notify()
|
||||
},
|
||||
retainedOutput: () => ({ text: buffer.snapshot().text, truncated: false }),
|
||||
diagnostic: () => {},
|
||||
} as unknown as ToolExecutionApi
|
||||
const result = await tool.execute(args, api, { ...BACKGROUND_CONTEXT, abortSignal: signal })
|
||||
return {
|
||||
...result,
|
||||
details: result.details as Awaited<ReturnType<T['execute']>>['details'],
|
||||
content: result.output ?? [{ type: 'text' as const, text: buffer.snapshot().text }],
|
||||
}
|
||||
}
|
||||
|
||||
export async function getAgentTools(harness: Harness) {
|
||||
return (await (await harness.root(BACKGROUND_CONTEXT)).agent(BACKGROUND_CONTEXT)).tools
|
||||
}
|
||||
|
||||
export async function getAgentPrompt(harness: Harness) {
|
||||
return (
|
||||
(await (await harness.root(BACKGROUND_CONTEXT)).agent(BACKGROUND_CONTEXT)).instructions ?? ''
|
||||
)
|
||||
}
|
||||
|
||||
export function jsonData(value: unknown): JsonObject {
|
||||
return JSON.parse(JSON.stringify(value)) as JsonObject
|
||||
}
|
||||
Reference in New Issue
Block a user