@averyyy/pi-coding-agent 1.4.0-piclient.3 → 1.4.0-piclient.5
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/CHANGELOG.md +2 -1
- package/dist/bundle/chunks/{chunk-ONNEWCXN.js → chunk-CZS5NCQL.js} +1 -1
- package/dist/bundle/chunks/{chunk-7Q2A4TEZ.js → chunk-N3WDXTDL.js} +3 -3
- package/dist/bundle/chunks/{virtual-modules-XW2JKHUP.js → virtual-modules-SBB7EAKK.js} +1 -1
- package/dist/bundle/cli-runtime.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/core/pi-server-observer.d.ts +1 -1
- package/dist/core/pi-server-observer.d.ts.map +1 -1
- package/dist/core/pi-server-observer.js +5 -1
- package/dist/core/pi-server-observer.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url);
|
|
2
|
-
import{dist_exports as dist_exports3}from"./chunk-
|
|
2
|
+
import{dist_exports as dist_exports3}from"./chunk-CZS5NCQL.js";import{all_exports,compat_exports,compile_exports,dist_exports as dist_exports2,value_exports}from"./chunk-N3WDXTDL.js";import{build_exports}from"./chunk-BRYV63PL.js";import"./chunk-3EGEEHMN.js";import{dist_exports}from"./chunk-H2UJDH5M.js";import"./chunk-PG7P2LUM.js";import"./chunk-VYYRESZJ.js";import"./chunk-H2AI7MFJ.js";import"./chunk-6QGV3IWD.js";import"./chunk-3LTMO2WY.js";import"./chunk-USJZMAIR.js";import"./chunk-5AGIVGSV.js";import"./chunk-UKVNB6C4.js";import"./chunk-TMTOQ7H7.js";import"./chunk-7DDKXS2Q.js";import"./chunk-3V45WARH.js";import{models_exports}from"./chunk-D3OXAPLU.js";import"./chunk-LPXNMA2W.js";import"./chunk-H76KZMOI.js";import"./chunk-JXWJOIH4.js";var oauth_exports={};var VIRTUAL_MODULES={typebox:build_exports,"typebox/compile":compile_exports,"typebox/value":value_exports,"@sinclair/typebox":build_exports,"@sinclair/typebox/compile":compile_exports,"@sinclair/typebox/value":value_exports,"@earendil-works/pi-agent-core":dist_exports2,"@earendil-works/pi-tui":dist_exports,"@earendil-works/pi-ai":compat_exports,"@earendil-works/pi-ai/compat":compat_exports,"@earendil-works/pi-ai/models":models_exports,"@earendil-works/pi-ai/oauth":oauth_exports,"@earendil-works/pi-ai/providers/all":all_exports,"@earendil-works/pi-coding-agent":dist_exports3,"@mariozechner/pi-agent-core":dist_exports2,"@mariozechner/pi-tui":dist_exports,"@mariozechner/pi-ai":compat_exports,"@mariozechner/pi-ai/compat":compat_exports,"@mariozechner/pi-ai/models":models_exports,"@mariozechner/pi-ai/oauth":oauth_exports,"@mariozechner/pi-ai/providers/all":all_exports,"@mariozechner/pi-coding-agent":dist_exports3};export{VIRTUAL_MODULES};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url);
|
|
3
|
-
import{configureHttpDispatcher,main}from"./chunks/chunk-
|
|
3
|
+
import{configureHttpDispatcher,main}from"./chunks/chunk-N3WDXTDL.js";import"./chunks/chunk-BRYV63PL.js";import"./chunks/chunk-3EGEEHMN.js";import"./chunks/chunk-H2UJDH5M.js";import"./chunks/chunk-PG7P2LUM.js";import"./chunks/chunk-VYYRESZJ.js";import"./chunks/chunk-H2AI7MFJ.js";import"./chunks/chunk-6QGV3IWD.js";import{APP_NAME}from"./chunks/chunk-3LTMO2WY.js";import"./chunks/chunk-USJZMAIR.js";import"./chunks/chunk-5AGIVGSV.js";import"./chunks/chunk-UKVNB6C4.js";import"./chunks/chunk-TMTOQ7H7.js";import"./chunks/chunk-7DDKXS2Q.js";import"./chunks/chunk-3V45WARH.js";import"./chunks/chunk-D3OXAPLU.js";import"./chunks/chunk-LPXNMA2W.js";import"./chunks/chunk-H76KZMOI.js";import"./chunks/chunk-JXWJOIH4.js";function setupCli(){process.title=APP_NAME,process.env.PI_CODING_AGENT="true",process.env.AI_AGENT="pi",process.emitWarning=(()=>{}),configureHttpDispatcher()}setupCli();main(process.argv.slice(2));
|
package/dist/bundle/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url);
|
|
2
|
-
import{ShowImagesSelectorComponent,ThemeSelectorComponent}from"./chunks/chunk-
|
|
2
|
+
import{ShowImagesSelectorComponent,ThemeSelectorComponent}from"./chunks/chunk-CZS5NCQL.js";import{AgentSession,AgentSessionRuntime,AssistantMessageComponent,BashExecutionComponent,BorderedLoader,BranchSummaryMessageComponent,CURRENT_SESSION_VERSION,CompactionSummaryMessageComponent,CredentialSynchronizationError,CustomEditor,CustomMessageComponent,DEFAULT_COMPACTION_SETTINGS,DefaultPackageManager,DefaultResourceLoader,DynamicBorder,ExtensionEditorComponent,ExtensionInputComponent,ExtensionRunner,ExtensionSelectorComponent,FooterComponent,InteractiveMode,LoginDialogComponent,ModelRegistry,ModelRuntime,ModelSelectorComponent,OAuthSelectorComponent,RpcClient,SessionManager,SessionSelectorComponent,SettingsManager,SettingsSelectorComponent,SkillInvocationMessageComponent,ThinkingSelectorComponent,ToolExecutionComponent,TreeSelectorComponent,UserMessageComponent,UserMessageSelectorComponent,VIRTUAL_MODEL_STATE_ENTRY,buildContextEntries,buildSessionContext,buildSessionProjection,calculateContextTokens,collectEntriesForBranchSummary,compact,convertToLlm,convertToPng,copyToClipboard,createAgentSession,createAgentSessionFromServices,createAgentSessionRuntime,createAgentSessionServices,createBashTool,createBashToolDefinition,createCodemodeExtension,createCodingToolDefinitions,createCodingTools,createEditTool,createEditToolDefinition,createEventBus,createExtensionRuntime,createFindTool,createFindToolDefinition,createGrepTool,createGrepToolDefinition,createLocalBashOperations,createLsTool,createLsToolDefinition,createMcpExtension,createReadOnlyToolDefinitions,createReadOnlyTools,createReadTool,createReadToolDefinition,createSyntheticSourceInfo,createToolSearchExtension,createWriteTool,createWriteToolDefinition,defineTool,detectSupportedImageMimeTypeFromFile,discoverAndLoadExtensions,estimateTokens,findCutPoint,findTurnStartIndex,formatDimensionNote,formatSkillsForPrompt,generateBranchSummary,generateDiffString,generateSummary,generateSummaryWithUsage,generateUnifiedPatch,getLastAssistantUsage,getLatestCompactionEntry,isBashToolResult,isEditToolResult,isFindToolResult,isGrepToolResult,isLsToolResult,isReadToolResult,isToolCallEventType,isWriteToolResult,loadProjectContextFiles,loadSkills,loadSkillsFromDir,main,migrateSessionEntries,parseArgs,parseFrontmatter,parseSessionEntries,parseSkillBlock,prepareBranchEntries,renderDiff,resizeImage,resolveCliModel,resolveModelScopeWithDiagnostics,runPrintMode,runRpcMode,serializeConversation,sessionEntryToContextMessages,shouldCompact,stripFrontmatter,withFileMutationQueue,wrapRegisteredTool,wrapRegisteredTools}from"./chunks/chunk-N3WDXTDL.js";import{DEFAULT_MAX_BYTES,DEFAULT_MAX_LINES,formatReadLineRange,formatSize,truncateHead,truncateLine,truncateTail,truncateToVisualLines}from"./chunks/chunk-BRYV63PL.js";import{ArminComponent}from"./chunks/chunk-3EGEEHMN.js";import{Theme,getLanguageFromPath,getMarkdownTheme,getSelectListTheme,getSettingsListTheme,highlightCode,initTheme,keyHint,keyText,rawKeyHint}from"./chunks/chunk-H2UJDH5M.js";import{ProjectTrustStore,hasTrustRequiringProjectResources}from"./chunks/chunk-PG7P2LUM.js";import{readStoredCredential}from"./chunks/chunk-VYYRESZJ.js";import{getShellConfig}from"./chunks/chunk-H2AI7MFJ.js";import"./chunks/chunk-6QGV3IWD.js";import{CONFIG_DIR_NAME,VERSION,getAgentDir,getDocsPath,getExamplesPath,getPackageDir,getReadmePath}from"./chunks/chunk-3LTMO2WY.js";import"./chunks/chunk-USJZMAIR.js";import"./chunks/chunk-5AGIVGSV.js";import"./chunks/chunk-UKVNB6C4.js";import"./chunks/chunk-TMTOQ7H7.js";import"./chunks/chunk-7DDKXS2Q.js";import"./chunks/chunk-3V45WARH.js";import"./chunks/chunk-D3OXAPLU.js";import"./chunks/chunk-LPXNMA2W.js";import"./chunks/chunk-H76KZMOI.js";import"./chunks/chunk-JXWJOIH4.js";export{AgentSession,AgentSessionRuntime,ArminComponent,AssistantMessageComponent,BashExecutionComponent,BorderedLoader,BranchSummaryMessageComponent,CONFIG_DIR_NAME,CURRENT_SESSION_VERSION,CompactionSummaryMessageComponent,CredentialSynchronizationError,CustomEditor,CustomMessageComponent,DEFAULT_COMPACTION_SETTINGS,DEFAULT_MAX_BYTES,DEFAULT_MAX_LINES,DefaultPackageManager,DefaultResourceLoader,DynamicBorder,ExtensionEditorComponent,ExtensionInputComponent,ExtensionRunner,ExtensionSelectorComponent,FooterComponent,InteractiveMode,LoginDialogComponent,ModelRegistry,ModelRuntime,ModelSelectorComponent,OAuthSelectorComponent,ProjectTrustStore,RpcClient,SessionManager,SessionSelectorComponent,SettingsManager,SettingsSelectorComponent,ShowImagesSelectorComponent,SkillInvocationMessageComponent,Theme,ThemeSelectorComponent,ThinkingSelectorComponent,ToolExecutionComponent,TreeSelectorComponent,UserMessageComponent,UserMessageSelectorComponent,VERSION,VIRTUAL_MODEL_STATE_ENTRY,buildContextEntries,buildSessionContext,buildSessionProjection,calculateContextTokens,collectEntriesForBranchSummary,compact,convertToLlm,convertToPng,copyToClipboard,createAgentSession,createAgentSessionFromServices,createAgentSessionRuntime,createAgentSessionServices,createBashTool,createBashToolDefinition,createCodemodeExtension,createCodingToolDefinitions,createCodingTools,createEditTool,createEditToolDefinition,createEventBus,createExtensionRuntime,createFindTool,createFindToolDefinition,createGrepTool,createGrepToolDefinition,createLocalBashOperations,createLsTool,createLsToolDefinition,createMcpExtension,createReadOnlyToolDefinitions,createReadOnlyTools,createReadTool,createReadToolDefinition,createSyntheticSourceInfo,createToolSearchExtension,createWriteTool,createWriteToolDefinition,defineTool,detectSupportedImageMimeTypeFromFile,discoverAndLoadExtensions,estimateTokens,findCutPoint,findTurnStartIndex,formatDimensionNote,formatReadLineRange,formatSize,formatSkillsForPrompt,generateBranchSummary,generateDiffString,generateSummary,generateSummaryWithUsage,generateUnifiedPatch,getAgentDir,getDocsPath,getExamplesPath,getLanguageFromPath,getLastAssistantUsage,getLatestCompactionEntry,getMarkdownTheme,getPackageDir,getReadmePath,getSelectListTheme,getSettingsListTheme,getShellConfig,hasTrustRequiringProjectResources,highlightCode,initTheme,isBashToolResult,isEditToolResult,isFindToolResult,isGrepToolResult,isLsToolResult,isReadToolResult,isToolCallEventType,isWriteToolResult,keyHint,keyText,loadProjectContextFiles,loadSkills,loadSkillsFromDir,main,migrateSessionEntries,parseArgs,parseFrontmatter,parseSessionEntries,parseSkillBlock,prepareBranchEntries,rawKeyHint,readStoredCredential,renderDiff,resizeImage,resolveCliModel,resolveModelScopeWithDiagnostics,runPrintMode,runRpcMode,serializeConversation,sessionEntryToContextMessages,shouldCompact,stripFrontmatter,truncateHead,truncateLine,truncateTail,truncateToVisualLines,withFileMutationQueue,wrapRegisteredTool,wrapRegisteredTools};
|
package/dist/bundle/rpc-entry.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url);
|
|
3
|
-
import{configureHttpDispatcher,main}from"./chunks/chunk-
|
|
3
|
+
import{configureHttpDispatcher,main}from"./chunks/chunk-N3WDXTDL.js";import"./chunks/chunk-BRYV63PL.js";import"./chunks/chunk-3EGEEHMN.js";import"./chunks/chunk-H2UJDH5M.js";import"./chunks/chunk-PG7P2LUM.js";import"./chunks/chunk-VYYRESZJ.js";import"./chunks/chunk-H2AI7MFJ.js";import"./chunks/chunk-6QGV3IWD.js";import{APP_NAME}from"./chunks/chunk-3LTMO2WY.js";import"./chunks/chunk-USJZMAIR.js";import"./chunks/chunk-5AGIVGSV.js";import"./chunks/chunk-UKVNB6C4.js";import"./chunks/chunk-TMTOQ7H7.js";import"./chunks/chunk-7DDKXS2Q.js";import"./chunks/chunk-3V45WARH.js";import"./chunks/chunk-D3OXAPLU.js";import"./chunks/chunk-LPXNMA2W.js";import"./chunks/chunk-H76KZMOI.js";import"./chunks/chunk-JXWJOIH4.js";process.title=`${APP_NAME}-rpc`;process.env.PI_CODING_AGENT="true";process.env.AI_AGENT="pi";process.emitWarning=(()=>{});configureHttpDispatcher();main(["--mode","rpc",...process.argv.slice(2)]);
|
|
@@ -49,7 +49,7 @@ export interface ObserverUpdate {
|
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
export declare function projectObserverEntries(entries: SessionEntry[]): ObserverMessage[];
|
|
52
|
-
/** Publishes
|
|
52
|
+
/** Publishes transcript updates independently of provider requests and durable server trees. */
|
|
53
53
|
export declare class PiServerObserver {
|
|
54
54
|
private readonly session;
|
|
55
55
|
private readonly unsubscribe;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi-server-observer.d.ts","sourceRoot":"","sources":["../../src/core/pi-server-observer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA6B,eAAe,EAA6B,MAAM,uBAAuB,CAAC;AAEnH,OAAO,KAAK,EAAE,YAAY,EAAqB,MAAM,oBAAoB,CAAC;AAG1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIzD,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhF;AAED,KAAK,aAAa,GACf;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC,CAAA;CAAE,GAChE;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACtC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAA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OAAO,CAAC,aAAa,CAAM;IAC3B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmC;IACzD,OAAO,CAAC,YAAY,CAAS;IAE7B,YAAY,OAAO,EAAE,YAAY,EAWhC;IAED,OAAO,CAAC,WAAW;IAmFnB,OAAO,CAAC,QAAQ;IAkBhB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,kBAAkB;IAe1B,OAAO,CAAC,OAAO;YAQD,OAAO;IA+ErB,OAAO,CAAC,KAAK;YAUC,UAAU;IAyExB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAGrB;YAEa,aAAa;IA2B3B,OAAO,IAAI,IAAI,CAOd;CACD"}
|
|
@@ -78,7 +78,7 @@ export function projectObserverEntries(entries) {
|
|
|
78
78
|
}
|
|
79
79
|
return messages;
|
|
80
80
|
}
|
|
81
|
-
/** Publishes
|
|
81
|
+
/** Publishes transcript updates independently of provider requests and durable server trees. */
|
|
82
82
|
export class PiServerObserver {
|
|
83
83
|
session;
|
|
84
84
|
unsubscribe;
|
|
@@ -258,6 +258,10 @@ export class PiServerObserver {
|
|
|
258
258
|
timeout.unref();
|
|
259
259
|
try {
|
|
260
260
|
const response = await this.request(controller.signal).getJson(`/api/observer/connect?sessionId=${encodeURIComponent(sessionId)}`);
|
|
261
|
+
if (response.status === 410) {
|
|
262
|
+
this.stopDeletedSession(sessionId, controller);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
261
265
|
if (!response.ok || !response.headers.get("content-type")?.includes("text/event-stream") || !response.body) {
|
|
262
266
|
throw new Error(`connection failed (HTTP ${response.status})`);
|
|
263
267
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi-server-observer.js","sourceRoot":"","sources":["../../src/core/pi-server-observer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAE,mB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works/pi-agent-core\";\nimport type { ImageContent, TextContent, TextSignatureV1, ThinkingContent, ToolCall } from \"@earendil-works/pi-ai\";\nimport { raceWithAbortSignal } from \"../utils/abort.ts\";\nimport type { AgentSession, AgentSessionEvent } from \"./agent-session.ts\";\nimport { bashExecutionToText } from \"./messages.ts\";\nimport { ChunkRequest } from \"./pi-server-request.ts\";\nimport type { SessionEntry } from \"./session-manager.ts\";\n\nconst observers = new WeakMap<AgentSession, PiServerObserver>();\n\nexport async function closePiServerObserver(session: AgentSession): Promise<void> {\n\tawait observers.get(session)?.close();\n}\n\ntype ViewerContent =\n\t| { type: \"text\"; text: string; phase?: TextSignatureV1[\"phase\"] }\n\t| { type: \"thinking\"; thinking: string }\n\t| { type: \"toolCall\"; id: string; name: string; arguments: unknown }\n\t| { type: \"attachment\"; label: string };\n\nexport interface ObserverMessage {\n\tid: string;\n\trole: string;\n\tcontent: string | ViewerContent[];\n\ttimestamp: number;\n\tstopReason?: string;\n\tphase?: string;\n\terrorMessage?: string;\n}\n\ninterface ObserverTool {\n\tid: string;\n\tname: string;\n\targuments: unknown;\n\tresult?: unknown;\n\tstatus: \"running\" | \"completed\" | \"error\";\n}\n\nexport interface ObserverUpdate {\n\tsessionId: string;\n\tconnectionId: string;\n\tsequence: number;\n\tcwd: string;\n\ttitle: string;\n\treplace?: ObserverMessage[];\n\tappend?: ObserverMessage[];\n\tstatus: \"running\" | \"idle\";\n\tlive: { message: ObserverMessage | null; tools: ObserverTool[] };\n}\n\nfunction textPhase(signature: string | undefined): TextSignatureV1[\"phase\"] {\n\tif (!signature?.startsWith(\"{\")) return undefined;\n\ttry {\n\t\tconst parsed = JSON.parse(signature) as Partial<TextSignatureV1>;\n\t\tif (\n\t\t\tparsed.v === 1 &&\n\t\t\ttypeof parsed.id === \"string\" &&\n\t\t\t(parsed.phase === \"commentary\" || parsed.phase === \"final_answer\")\n\t\t)\n\t\t\treturn parsed.phase;\n\t} catch {\n\t\t// Provider signatures outside TextSignatureV1 have no display phase.\n\t}\n\treturn undefined;\n}\n\nfunction projectContent(\n\tcontent: string | (TextContent | ThinkingContent | ImageContent | ToolCall)[],\n): ObserverMessage[\"content\"] {\n\tif (typeof content === \"string\") return content;\n\treturn content.map((part): ViewerContent => {\n\t\tif (part.type === \"text\") return { type: \"text\", text: part.text, phase: textPhase(part.textSignature) };\n\t\tif (part.type === \"thinking\") return { type: \"thinking\", thinking: part.thinking };\n\t\tif (part.type === \"toolCall\")\n\t\t\treturn { type: \"toolCall\", id: part.id, name: part.name, arguments: part.arguments };\n\t\treturn { type: \"attachment\", label: part.mimeType };\n\t});\n}\n\nfunction projectMessage(id: string, message: AgentMessage): ObserverMessage | undefined {\n\tif (message.role === \"system\" || (message.role === \"custom\" && !message.display)) return undefined;\n\tlet content: ObserverMessage[\"content\"];\n\tif (message.role === \"bashExecution\") content = bashExecutionToText(message);\n\telse if (message.role === \"compactionSummary\" || message.role === \"branchSummary\") content = message.summary;\n\telse content = projectContent(message.content);\n\tconst projected: ObserverMessage = { id, role: message.role, content, timestamp: message.timestamp };\n\tif (message.role === \"assistant\") {\n\t\tprojected.stopReason = message.stopReason;\n\t\tprojected.errorMessage = message.errorMessage;\n\t\tfor (const part of message.content) {\n\t\t\tconst phase = part.type === \"text\" ? textPhase(part.textSignature) : undefined;\n\t\t\tif (phase) projected.phase = phase;\n\t\t}\n\t}\n\treturn projected;\n}\n\nexport function projectObserverEntries(entries: SessionEntry[]): ObserverMessage[] {\n\tconst messages: ObserverMessage[] = [];\n\tfor (const entry of entries) {\n\t\tlet message: ObserverMessage | undefined;\n\t\tif (entry.type === \"message\") message = projectMessage(entry.id, entry.message);\n\t\telse if (entry.type === \"custom_message\" && entry.display) {\n\t\t\tmessage = {\n\t\t\t\tid: entry.id,\n\t\t\t\trole: \"custom\",\n\t\t\t\tcontent: projectContent(entry.content),\n\t\t\t\ttimestamp: Date.parse(entry.timestamp),\n\t\t\t};\n\t\t} else if (entry.type === \"compaction\" || entry.type === \"branch_summary\") {\n\t\t\tmessage = { id: entry.id, role: entry.type, content: entry.summary, timestamp: Date.parse(entry.timestamp) };\n\t\t}\n\t\tif (message) messages.push(message);\n\t}\n\treturn messages;\n}\n\n/** Publishes a read-only transcript independently of provider requests and durable server trees. */\nexport class PiServerObserver {\n\tprivate readonly session: AgentSession;\n\tprivate readonly unsubscribe: () => void;\n\tprivate controller?: AbortController;\n\tprivate timer?: ReturnType<typeof setTimeout>;\n\tprivate reconnectTimer?: ReturnType<typeof setTimeout>;\n\tprivate disposed = false;\n\tprivate closing = false;\n\tprivate closePromise?: Promise<void>;\n\tprivate connectionReady?: Promise<void>;\n\tprivate deletedSessionId?: string;\n\tprivate connectionId?: string;\n\tprivate connectedSessionId?: string;\n\tprivate sequence = 0;\n\tprivate sending = false;\n\tprivate flushPromise?: Promise<void>;\n\tprivate dirty = true;\n\tprivate historyDirty = true;\n\tprivate replace = true;\n\tprivate sentEntryId?: string;\n\tprivate pendingEntries: SessionEntry[] = [];\n\tprivate firstUserTitle = \"\";\n\tprivate liveMessage: AgentMessage | null = null;\n\tprivate liveMessageId = \"\";\n\tprivate readonly tools = new Map<string, ObserverTool>();\n\tprivate disconnected = false;\n\n\tconstructor(session: AgentSession) {\n\t\tthis.session = session;\n\t\tobservers.set(session, this);\n\t\tthis.unsubscribe = session.subscribe((event) => {\n\t\t\ttry {\n\t\t\t\tthis.handleEvent(event);\n\t\t\t} catch (error) {\n\t\t\t\tthis.reportError(error);\n\t\t\t}\n\t\t});\n\t\tvoid this.connect();\n\t}\n\n\tprivate handleEvent(event: AgentSessionEvent): void {\n\t\tswitch (event.type) {\n\t\t\tcase \"session_disposed\":\n\t\t\t\tthis.dispose();\n\t\t\t\treturn;\n\t\t\tcase \"run_state_changed\":\n\t\t\t\tif (!event.running) {\n\t\t\t\t\tthis.liveMessage = null;\n\t\t\t\t\tthis.tools.clear();\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase \"message_start\":\n\t\t\t\tif (event.message.role !== \"assistant\") return;\n\t\t\t\tthis.tools.clear();\n\t\t\t\tthis.liveMessageId = randomUUID();\n\t\t\t\tthis.liveMessage = event.message;\n\t\t\t\tbreak;\n\t\t\tcase \"message_update\":\n\t\t\t\tthis.liveMessage = event.message;\n\t\t\t\tbreak;\n\t\t\tcase \"entry_appended\":\n\t\t\tcase \"message_committed\":\n\t\t\t\tif (this.connectionId && !this.historyDirty) {\n\t\t\t\t\tthis.pendingEntries.push(event.entry);\n\t\t\t\t\tif (this.pendingEntries.length > 64) {\n\t\t\t\t\t\tthis.pendingEntries = [];\n\t\t\t\t\t\tthis.historyDirty = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (event.entry.type === \"message\" && event.entry.message.role === \"assistant\") this.liveMessage = null;\n\t\t\t\tbreak;\n\t\t\tcase \"history_reconciled\":\n\t\t\tcase \"session_tree_changed\":\n\t\t\t\tif (this.deletedSessionId && this.deletedSessionId !== this.session.sessionId) {\n\t\t\t\t\tthis.deletedSessionId = undefined;\n\t\t\t\t\tvoid this.connect();\n\t\t\t\t}\n\t\t\t\tif (this.connectedSessionId && this.connectedSessionId !== this.session.sessionId) {\n\t\t\t\t\tthis.connectionId = undefined;\n\t\t\t\t\tthis.controller?.abort();\n\t\t\t\t}\n\t\t\t\tthis.replace = true;\n\t\t\t\tthis.historyDirty = true;\n\t\t\t\tbreak;\n\t\t\tcase \"compaction_end\":\n\t\t\t\tthis.historyDirty = true;\n\t\t\t\tbreak;\n\t\t\tcase \"compaction_start\":\n\t\t\t\tbreak;\n\t\t\tcase \"session_info_changed\":\n\t\t\t\tbreak;\n\t\t\tcase \"tool_execution_start\":\n\t\t\t\tthis.tools.set(event.toolCallId, {\n\t\t\t\t\tid: event.toolCallId,\n\t\t\t\t\tname: event.toolName,\n\t\t\t\t\targuments: event.args,\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase \"tool_execution_update\": {\n\t\t\t\tconst tool = this.tools.get(event.toolCallId);\n\t\t\t\tif (tool) tool.result = { content: projectContent(event.partialResult.content) };\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"tool_execution_end\": {\n\t\t\t\tconst tool = this.tools.get(event.toolCallId);\n\t\t\t\tif (tool) {\n\t\t\t\t\ttool.result = { content: projectContent(event.result.content), isError: event.isError };\n\t\t\t\t\ttool.status = event.isError ? \"error\" : \"completed\";\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn;\n\t\t}\n\t\tthis.dirty = true;\n\t\tthis.schedule(\n\t\t\tevent.type === \"run_state_changed\" || event.type === \"compaction_start\" || event.type === \"compaction_end\"\n\t\t\t\t? 0\n\t\t\t\t: 80,\n\t\t);\n\t}\n\n\tprivate schedule(delay: number): void {\n\t\tif (\n\t\t\tthis.disposed ||\n\t\t\tthis.closing ||\n\t\t\tthis.deletedSessionId === this.session.sessionId ||\n\t\t\t!this.dirty ||\n\t\t\t!this.connectionId ||\n\t\t\tthis.sending ||\n\t\t\tthis.timer\n\t\t)\n\t\t\treturn;\n\t\tthis.timer = setTimeout(() => {\n\t\t\tthis.timer = undefined;\n\t\t\tvoid this.flush();\n\t\t}, delay);\n\t\tthis.timer.unref();\n\t}\n\n\tprivate reportError(error: unknown): void {\n\t\tif (this.disposed || this.disconnected) return;\n\t\tthis.disconnected = true;\n\t\tconsole.error(`pi-server observer disconnected: ${error instanceof Error ? error.message : String(error)}`);\n\t}\n\n\tprivate stopDeletedSession(sessionId: string, controller: AbortController): void {\n\t\tif (sessionId === this.session.sessionId) {\n\t\t\tthis.deletedSessionId = sessionId;\n\t\t\tthis.connectionId = undefined;\n\t\t\tthis.pendingEntries = [];\n\t\t\tthis.liveMessage = null;\n\t\t\tthis.tools.clear();\n\t\t\tclearTimeout(this.timer);\n\t\t\tthis.timer = undefined;\n\t\t\tclearTimeout(this.reconnectTimer);\n\t\t\tthis.reconnectTimer = undefined;\n\t\t}\n\t\tcontroller.abort();\n\t}\n\n\tprivate request(signal: AbortSignal): ChunkRequest {\n\t\treturn new ChunkRequest({\n\t\t\tserverUrl: process.env.PI_SERVER_URL ?? \"http://127.0.0.1:4217\",\n\t\t\tauthToken: process.env.PI_SERVER_AUTH_TOKEN ?? \"\",\n\t\t\tsignal,\n\t\t});\n\t}\n\n\tprivate async connect(): Promise<void> {\n\t\tif (this.disposed || this.deletedSessionId === this.session.sessionId) return;\n\t\tconst controller = new AbortController();\n\t\tthis.controller = controller;\n\t\tconst sessionId = this.session.sessionId;\n\t\tthis.connectedSessionId = sessionId;\n\t\tlet resolveConnection: (() => void) | undefined;\n\t\tthis.connectionReady = new Promise<void>((resolve) => {\n\t\t\tresolveConnection = resolve;\n\t\t});\n\t\tconst timeout = setTimeout(() => controller.abort(new Error(\"connection timed out\")), 10000);\n\t\ttimeout.unref();\n\t\ttry {\n\t\t\tconst response = await this.request(controller.signal).getJson(\n\t\t\t\t`/api/observer/connect?sessionId=${encodeURIComponent(sessionId)}`,\n\t\t\t);\n\t\t\tif (!response.ok || !response.headers.get(\"content-type\")?.includes(\"text/event-stream\") || !response.body) {\n\t\t\t\tthrow new Error(`connection failed (HTTP ${response.status})`);\n\t\t\t}\n\t\t\tconst reader = response.body.getReader();\n\t\t\tconst decoder = new TextDecoder();\n\t\t\tlet buffer = \"\";\n\t\t\tlet event = \"\";\n\t\t\ttry {\n\t\t\t\twhile (!this.disposed) {\n\t\t\t\t\tconst { done, value } = await reader.read();\n\t\t\t\t\tif (done) throw new Error(\"connection closed\");\n\t\t\t\t\tbuffer += decoder.decode(value, { stream: true });\n\t\t\t\t\tlet newline = buffer.indexOf(\"\\n\");\n\t\t\t\t\twhile (newline !== -1) {\n\t\t\t\t\t\tconst line = buffer.slice(0, newline).replace(/\\r$/, \"\");\n\t\t\t\t\t\tbuffer = buffer.slice(newline + 1);\n\t\t\t\t\t\tif (line.startsWith(\"event:\")) event = line.slice(6).trim();\n\t\t\t\t\t\tif (event === \"deleted\" && line.startsWith(\"data:\")) {\n\t\t\t\t\t\t\tthis.stopDeletedSession(sessionId, controller);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (event === \"connected\" && !this.connectionId && line.startsWith(\"data:\")) {\n\t\t\t\t\t\t\tconst connected = JSON.parse(line.slice(5)) as { connectionId: string };\n\t\t\t\t\t\t\tthis.connectionId = connected.connectionId;\n\t\t\t\t\t\t\tthis.sequence = 0;\n\t\t\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\t\t\tthis.replace = true;\n\t\t\t\t\t\t\tthis.historyDirty = true;\n\t\t\t\t\t\t\tthis.dirty = true;\n\t\t\t\t\t\t\tthis.schedule(0);\n\t\t\t\t\t\t\tresolveConnection?.();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnewline = buffer.indexOf(\"\\n\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tawait reader.cancel();\n\t\t\t\treader.releaseLock();\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (sessionId === this.session.sessionId && this.deletedSessionId !== sessionId) this.reportError(error);\n\t\t} finally {\n\t\t\tresolveConnection?.();\n\t\t\tclearTimeout(timeout);\n\t\t\tcontroller.abort();\n\t\t\tif (this.controller === controller) this.connectionId = undefined;\n\t\t\tif (this.controller === controller && !this.disposed && !this.closing && this.deletedSessionId !== sessionId) {\n\t\t\t\tthis.reconnectTimer = setTimeout(\n\t\t\t\t\t() => {\n\t\t\t\t\t\tthis.reconnectTimer = undefined;\n\t\t\t\t\t\tvoid this.connect();\n\t\t\t\t\t},\n\t\t\t\t\tsessionId === this.session.sessionId ? 2000 : 0,\n\t\t\t\t);\n\t\t\t\tthis.reconnectTimer.unref();\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate flush(): Promise<void> {\n\t\tif (this.flushPromise) return this.flushPromise;\n\t\tconst promise = this.sendUpdate();\n\t\tthis.flushPromise = promise;\n\t\tvoid promise.finally(() => {\n\t\t\tthis.flushPromise = undefined;\n\t\t});\n\t\treturn promise;\n\t}\n\n\tprivate async sendUpdate(): Promise<void> {\n\t\tconst connectionId = this.connectionId;\n\t\tconst sessionId = this.connectedSessionId;\n\t\tconst controller = this.controller;\n\t\tif (\n\t\t\t!connectionId ||\n\t\t\t!sessionId ||\n\t\t\t!controller ||\n\t\t\tthis.disposed ||\n\t\t\tthis.deletedSessionId === sessionId ||\n\t\t\tthis.sending ||\n\t\t\t!this.dirty\n\t\t)\n\t\t\treturn;\n\t\tthis.sending = true;\n\t\tthis.dirty = false;\n\t\ttry {\n\t\t\tconst branch = this.historyDirty ? this.session.sessionManager.getBranch() : undefined;\n\t\t\tconst sentIndex = branch && this.sentEntryId ? branch.findIndex((entry) => entry.id === this.sentEntryId) : -1;\n\t\t\tconst replace = this.replace || (branch !== undefined && this.sentEntryId !== undefined && sentIndex === -1);\n\t\t\tthis.historyDirty = false;\n\t\t\tthis.replace = false;\n\t\t\tconst entries = branch ? (replace ? branch : branch.slice(sentIndex + 1)) : this.pendingEntries;\n\t\t\tthis.pendingEntries = [];\n\t\t\tconst messages = projectObserverEntries(entries);\n\t\t\tif (replace) this.firstUserTitle = \"\";\n\t\t\tif (!this.firstUserTitle) {\n\t\t\t\tconst firstUserContent = messages.find((message) => message.role === \"user\")?.content;\n\t\t\t\tthis.firstUserTitle = (\n\t\t\t\t\ttypeof firstUserContent === \"string\"\n\t\t\t\t\t\t? firstUserContent\n\t\t\t\t\t\t: (firstUserContent\n\t\t\t\t\t\t\t\t?.filter((part) => part.type === \"text\")\n\t\t\t\t\t\t\t\t.map((part) => part.text)\n\t\t\t\t\t\t\t\t.join(\"\") ?? \"\")\n\t\t\t\t).slice(0, 120);\n\t\t\t}\n\t\t\tconst update: ObserverUpdate = {\n\t\t\t\tsessionId,\n\t\t\t\tconnectionId,\n\t\t\t\tsequence: ++this.sequence,\n\t\t\t\tcwd: this.session.sessionManager.getCwd(),\n\t\t\t\ttitle: this.session.sessionManager.getSessionName() ?? this.firstUserTitle,\n\t\t\t\t...(replace ? { replace: messages } : messages.length ? { append: messages } : {}),\n\t\t\t\tstatus: this.session.isIdle ? \"idle\" : \"running\",\n\t\t\t\tlive: {\n\t\t\t\t\tmessage: this.liveMessage ? (projectMessage(this.liveMessageId, this.liveMessage) ?? null) : null,\n\t\t\t\t\ttools: [...this.tools.values()],\n\t\t\t\t},\n\t\t\t};\n\t\t\tconst response = await this.request(controller.signal).postJson(\"/api/observer\", update);\n\t\t\tif (response.status === 410) {\n\t\t\t\tthis.stopDeletedSession(sessionId, controller);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!response.ok) throw new Error(`update failed (HTTP ${response.status})`);\n\t\t\tconst result = (await response.json()) as { accepted: boolean };\n\t\t\tif (!result.accepted) throw new Error(\"update was not accepted\");\n\t\t\tif (entries.length > 0) this.sentEntryId = entries.at(-1)?.id;\n\t\t\telse if (replace) this.sentEntryId = undefined;\n\t\t\tif (this.disconnected) {\n\t\t\t\tthis.disconnected = false;\n\t\t\t\tconsole.error(\"pi-server observer connected\");\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (sessionId === this.session.sessionId && this.deletedSessionId !== sessionId) this.reportError(error);\n\t\t\tcontroller.abort();\n\t\t} finally {\n\t\t\tthis.sending = false;\n\t\t\tthis.schedule(80);\n\t\t}\n\t}\n\n\tclose(): Promise<void> {\n\t\tthis.closePromise ??= this.drainAndClose();\n\t\treturn this.closePromise;\n\t}\n\n\tprivate async drainAndClose(): Promise<void> {\n\t\tif (this.disposed) return;\n\t\tthis.closing = true;\n\t\tclearTimeout(this.timer);\n\t\tthis.timer = undefined;\n\t\tclearTimeout(this.reconnectTimer);\n\t\ttry {\n\t\t\tawait raceWithAbortSignal(\n\t\t\t\t(async () => {\n\t\t\t\t\tif (this.deletedSessionId === this.session.sessionId) return;\n\t\t\t\t\tif (!this.connectionId && this.controller?.signal.aborted) void this.connect();\n\t\t\t\t\tawait this.connectionReady;\n\t\t\t\t\tawait this.flushPromise;\n\t\t\t\t\tif (!this.connectionId) throw new Error(\"final transcript was not delivered: observer is disconnected\");\n\t\t\t\t\twhile (this.dirty && this.connectionId && !this.disposed) await this.flush();\n\t\t\t\t\tif (this.controller?.signal.aborted && this.deletedSessionId !== this.session.sessionId)\n\t\t\t\t\t\tthrow new Error(\"final transcript was not delivered: observer update failed\");\n\t\t\t\t})(),\n\t\t\t\tAbortSignal.timeout(10000),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconsole.error(`pi-server observer shutdown failed: ${error instanceof Error ? error.message : String(error)}`);\n\t\t} finally {\n\t\t\tthis.dispose();\n\t\t}\n\t}\n\n\tdispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.unsubscribe();\n\t\tclearTimeout(this.timer);\n\t\tclearTimeout(this.reconnectTimer);\n\t\tthis.controller?.abort();\n\t\tobservers.delete(this.session);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pi-server-observer.js","sourceRoot":"","sources":["../../src/core/pi-server-observer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAGtD,MAAM,SAAS,GAAG,IAAI,OAAO,EAAkC,CAAC;AAEhE,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,OAAqB;IAChE,MAAM,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC;AACvC,CAAC;AAsCD,SAAS,SAAS,CAAC,SAA6B;IAC/C,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IAClD,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAA6B,CAAC;QACjE,IACC,MAAM,CAAC,CAAC,KAAK,C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,CAAC,UAAU,EAAE,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,gBAAgB,KAAK,IAAI,CAAC,OAAO,CAAC,SAAS;oBACtF,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;YAChF,CAAC,CAAC,EAAE,EACJ,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAC1B,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,CAAC,KAAK,CAAC,uCAAuC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAChH,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,OAAO,EAAE,CAAC;QAChB,CAAC;IACF,CAAC;IAED,OAAO;QACN,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAClC,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC;QACzB,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;CACD","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { ImageContent, TextContent, TextSignatureV1, ThinkingContent, ToolCall } from \"@earendil-works/pi-ai\";\nimport { raceWithAbortSignal } from \"../utils/abort.ts\";\nimport type { AgentSession, AgentSessionEvent } from \"./agent-session.ts\";\nimport { bashExecutionToText } from \"./messages.ts\";\nimport { ChunkRequest } from \"./pi-server-request.ts\";\nimport type { SessionEntry } from \"./session-manager.ts\";\n\nconst observers = new WeakMap<AgentSession, PiServerObserver>();\n\nexport async function closePiServerObserver(session: AgentSession): Promise<void> {\n\tawait observers.get(session)?.close();\n}\n\ntype ViewerContent =\n\t| { type: \"text\"; text: string; phase?: TextSignatureV1[\"phase\"] }\n\t| { type: \"thinking\"; thinking: string }\n\t| { type: \"toolCall\"; id: string; name: string; arguments: unknown }\n\t| { type: \"attachment\"; label: string };\n\nexport interface ObserverMessage {\n\tid: string;\n\trole: string;\n\tcontent: string | ViewerContent[];\n\ttimestamp: number;\n\tstopReason?: string;\n\tphase?: string;\n\terrorMessage?: string;\n}\n\ninterface ObserverTool {\n\tid: string;\n\tname: string;\n\targuments: unknown;\n\tresult?: unknown;\n\tstatus: \"running\" | \"completed\" | \"error\";\n}\n\nexport interface ObserverUpdate {\n\tsessionId: string;\n\tconnectionId: string;\n\tsequence: number;\n\tcwd: string;\n\ttitle: string;\n\treplace?: ObserverMessage[];\n\tappend?: ObserverMessage[];\n\tstatus: \"running\" | \"idle\";\n\tlive: { message: ObserverMessage | null; tools: ObserverTool[] };\n}\n\nfunction textPhase(signature: string | undefined): TextSignatureV1[\"phase\"] {\n\tif (!signature?.startsWith(\"{\")) return undefined;\n\ttry {\n\t\tconst parsed = JSON.parse(signature) as Partial<TextSignatureV1>;\n\t\tif (\n\t\t\tparsed.v === 1 &&\n\t\t\ttypeof parsed.id === \"string\" &&\n\t\t\t(parsed.phase === \"commentary\" || parsed.phase === \"final_answer\")\n\t\t)\n\t\t\treturn parsed.phase;\n\t} catch {\n\t\t// Provider signatures outside TextSignatureV1 have no display phase.\n\t}\n\treturn undefined;\n}\n\nfunction projectContent(\n\tcontent: string | (TextContent | ThinkingContent | ImageContent | ToolCall)[],\n): ObserverMessage[\"content\"] {\n\tif (typeof content === \"string\") return content;\n\treturn content.map((part): ViewerContent => {\n\t\tif (part.type === \"text\") return { type: \"text\", text: part.text, phase: textPhase(part.textSignature) };\n\t\tif (part.type === \"thinking\") return { type: \"thinking\", thinking: part.thinking };\n\t\tif (part.type === \"toolCall\")\n\t\t\treturn { type: \"toolCall\", id: part.id, name: part.name, arguments: part.arguments };\n\t\treturn { type: \"attachment\", label: part.mimeType };\n\t});\n}\n\nfunction projectMessage(id: string, message: AgentMessage): ObserverMessage | undefined {\n\tif (message.role === \"system\" || (message.role === \"custom\" && !message.display)) return undefined;\n\tlet content: ObserverMessage[\"content\"];\n\tif (message.role === \"bashExecution\") content = bashExecutionToText(message);\n\telse if (message.role === \"compactionSummary\" || message.role === \"branchSummary\") content = message.summary;\n\telse content = projectContent(message.content);\n\tconst projected: ObserverMessage = { id, role: message.role, content, timestamp: message.timestamp };\n\tif (message.role === \"assistant\") {\n\t\tprojected.stopReason = message.stopReason;\n\t\tprojected.errorMessage = message.errorMessage;\n\t\tfor (const part of message.content) {\n\t\t\tconst phase = part.type === \"text\" ? textPhase(part.textSignature) : undefined;\n\t\t\tif (phase) projected.phase = phase;\n\t\t}\n\t}\n\treturn projected;\n}\n\nexport function projectObserverEntries(entries: SessionEntry[]): ObserverMessage[] {\n\tconst messages: ObserverMessage[] = [];\n\tfor (const entry of entries) {\n\t\tlet message: ObserverMessage | undefined;\n\t\tif (entry.type === \"message\") message = projectMessage(entry.id, entry.message);\n\t\telse if (entry.type === \"custom_message\" && entry.display) {\n\t\t\tmessage = {\n\t\t\t\tid: entry.id,\n\t\t\t\trole: \"custom\",\n\t\t\t\tcontent: projectContent(entry.content),\n\t\t\t\ttimestamp: Date.parse(entry.timestamp),\n\t\t\t};\n\t\t} else if (entry.type === \"compaction\" || entry.type === \"branch_summary\") {\n\t\t\tmessage = { id: entry.id, role: entry.type, content: entry.summary, timestamp: Date.parse(entry.timestamp) };\n\t\t}\n\t\tif (message) messages.push(message);\n\t}\n\treturn messages;\n}\n\n/** Publishes transcript updates independently of provider requests and durable server trees. */\nexport class PiServerObserver {\n\tprivate readonly session: AgentSession;\n\tprivate readonly unsubscribe: () => void;\n\tprivate controller?: AbortController;\n\tprivate timer?: ReturnType<typeof setTimeout>;\n\tprivate reconnectTimer?: ReturnType<typeof setTimeout>;\n\tprivate disposed = false;\n\tprivate closing = false;\n\tprivate closePromise?: Promise<void>;\n\tprivate connectionReady?: Promise<void>;\n\tprivate deletedSessionId?: string;\n\tprivate connectionId?: string;\n\tprivate connectedSessionId?: string;\n\tprivate sequence = 0;\n\tprivate sending = false;\n\tprivate flushPromise?: Promise<void>;\n\tprivate dirty = true;\n\tprivate historyDirty = true;\n\tprivate replace = true;\n\tprivate sentEntryId?: string;\n\tprivate pendingEntries: SessionEntry[] = [];\n\tprivate firstUserTitle = \"\";\n\tprivate liveMessage: AgentMessage | null = null;\n\tprivate liveMessageId = \"\";\n\tprivate readonly tools = new Map<string, ObserverTool>();\n\tprivate disconnected = false;\n\n\tconstructor(session: AgentSession) {\n\t\tthis.session = session;\n\t\tobservers.set(session, this);\n\t\tthis.unsubscribe = session.subscribe((event) => {\n\t\t\ttry {\n\t\t\t\tthis.handleEvent(event);\n\t\t\t} catch (error) {\n\t\t\t\tthis.reportError(error);\n\t\t\t}\n\t\t});\n\t\tvoid this.connect();\n\t}\n\n\tprivate handleEvent(event: AgentSessionEvent): void {\n\t\tswitch (event.type) {\n\t\t\tcase \"session_disposed\":\n\t\t\t\tthis.dispose();\n\t\t\t\treturn;\n\t\t\tcase \"run_state_changed\":\n\t\t\t\tif (!event.running) {\n\t\t\t\t\tthis.liveMessage = null;\n\t\t\t\t\tthis.tools.clear();\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase \"message_start\":\n\t\t\t\tif (event.message.role !== \"assistant\") return;\n\t\t\t\tthis.tools.clear();\n\t\t\t\tthis.liveMessageId = randomUUID();\n\t\t\t\tthis.liveMessage = event.message;\n\t\t\t\tbreak;\n\t\t\tcase \"message_update\":\n\t\t\t\tthis.liveMessage = event.message;\n\t\t\t\tbreak;\n\t\t\tcase \"entry_appended\":\n\t\t\tcase \"message_committed\":\n\t\t\t\tif (this.connectionId && !this.historyDirty) {\n\t\t\t\t\tthis.pendingEntries.push(event.entry);\n\t\t\t\t\tif (this.pendingEntries.length > 64) {\n\t\t\t\t\t\tthis.pendingEntries = [];\n\t\t\t\t\t\tthis.historyDirty = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (event.entry.type === \"message\" && event.entry.message.role === \"assistant\") this.liveMessage = null;\n\t\t\t\tbreak;\n\t\t\tcase \"history_reconciled\":\n\t\t\tcase \"session_tree_changed\":\n\t\t\t\tif (this.deletedSessionId && this.deletedSessionId !== this.session.sessionId) {\n\t\t\t\t\tthis.deletedSessionId = undefined;\n\t\t\t\t\tvoid this.connect();\n\t\t\t\t}\n\t\t\t\tif (this.connectedSessionId && this.connectedSessionId !== this.session.sessionId) {\n\t\t\t\t\tthis.connectionId = undefined;\n\t\t\t\t\tthis.controller?.abort();\n\t\t\t\t}\n\t\t\t\tthis.replace = true;\n\t\t\t\tthis.historyDirty = true;\n\t\t\t\tbreak;\n\t\t\tcase \"compaction_end\":\n\t\t\t\tthis.historyDirty = true;\n\t\t\t\tbreak;\n\t\t\tcase \"compaction_start\":\n\t\t\t\tbreak;\n\t\t\tcase \"session_info_changed\":\n\t\t\t\tbreak;\n\t\t\tcase \"tool_execution_start\":\n\t\t\t\tthis.tools.set(event.toolCallId, {\n\t\t\t\t\tid: event.toolCallId,\n\t\t\t\t\tname: event.toolName,\n\t\t\t\t\targuments: event.args,\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase \"tool_execution_update\": {\n\t\t\t\tconst tool = this.tools.get(event.toolCallId);\n\t\t\t\tif (tool) tool.result = { content: projectContent(event.partialResult.content) };\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"tool_execution_end\": {\n\t\t\t\tconst tool = this.tools.get(event.toolCallId);\n\t\t\t\tif (tool) {\n\t\t\t\t\ttool.result = { content: projectContent(event.result.content), isError: event.isError };\n\t\t\t\t\ttool.status = event.isError ? \"error\" : \"completed\";\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn;\n\t\t}\n\t\tthis.dirty = true;\n\t\tthis.schedule(\n\t\t\tevent.type === \"run_state_changed\" || event.type === \"compaction_start\" || event.type === \"compaction_end\"\n\t\t\t\t? 0\n\t\t\t\t: 80,\n\t\t);\n\t}\n\n\tprivate schedule(delay: number): void {\n\t\tif (\n\t\t\tthis.disposed ||\n\t\t\tthis.closing ||\n\t\t\tthis.deletedSessionId === this.session.sessionId ||\n\t\t\t!this.dirty ||\n\t\t\t!this.connectionId ||\n\t\t\tthis.sending ||\n\t\t\tthis.timer\n\t\t)\n\t\t\treturn;\n\t\tthis.timer = setTimeout(() => {\n\t\t\tthis.timer = undefined;\n\t\t\tvoid this.flush();\n\t\t}, delay);\n\t\tthis.timer.unref();\n\t}\n\n\tprivate reportError(error: unknown): void {\n\t\tif (this.disposed || this.disconnected) return;\n\t\tthis.disconnected = true;\n\t\tconsole.error(`pi-server observer disconnected: ${error instanceof Error ? error.message : String(error)}`);\n\t}\n\n\tprivate stopDeletedSession(sessionId: string, controller: AbortController): void {\n\t\tif (sessionId === this.session.sessionId) {\n\t\t\tthis.deletedSessionId = sessionId;\n\t\t\tthis.connectionId = undefined;\n\t\t\tthis.pendingEntries = [];\n\t\t\tthis.liveMessage = null;\n\t\t\tthis.tools.clear();\n\t\t\tclearTimeout(this.timer);\n\t\t\tthis.timer = undefined;\n\t\t\tclearTimeout(this.reconnectTimer);\n\t\t\tthis.reconnectTimer = undefined;\n\t\t}\n\t\tcontroller.abort();\n\t}\n\n\tprivate request(signal: AbortSignal): ChunkRequest {\n\t\treturn new ChunkRequest({\n\t\t\tserverUrl: process.env.PI_SERVER_URL ?? \"http://127.0.0.1:4217\",\n\t\t\tauthToken: process.env.PI_SERVER_AUTH_TOKEN ?? \"\",\n\t\t\tsignal,\n\t\t});\n\t}\n\n\tprivate async connect(): Promise<void> {\n\t\tif (this.disposed || this.deletedSessionId === this.session.sessionId) return;\n\t\tconst controller = new AbortController();\n\t\tthis.controller = controller;\n\t\tconst sessionId = this.session.sessionId;\n\t\tthis.connectedSessionId = sessionId;\n\t\tlet resolveConnection: (() => void) | undefined;\n\t\tthis.connectionReady = new Promise<void>((resolve) => {\n\t\t\tresolveConnection = resolve;\n\t\t});\n\t\tconst timeout = setTimeout(() => controller.abort(new Error(\"connection timed out\")), 10000);\n\t\ttimeout.unref();\n\t\ttry {\n\t\t\tconst response = await this.request(controller.signal).getJson(\n\t\t\t\t`/api/observer/connect?sessionId=${encodeURIComponent(sessionId)}`,\n\t\t\t);\n\t\t\tif (response.status === 410) {\n\t\t\t\tthis.stopDeletedSession(sessionId, controller);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!response.ok || !response.headers.get(\"content-type\")?.includes(\"text/event-stream\") || !response.body) {\n\t\t\t\tthrow new Error(`connection failed (HTTP ${response.status})`);\n\t\t\t}\n\t\t\tconst reader = response.body.getReader();\n\t\t\tconst decoder = new TextDecoder();\n\t\t\tlet buffer = \"\";\n\t\t\tlet event = \"\";\n\t\t\ttry {\n\t\t\t\twhile (!this.disposed) {\n\t\t\t\t\tconst { done, value } = await reader.read();\n\t\t\t\t\tif (done) throw new Error(\"connection closed\");\n\t\t\t\t\tbuffer += decoder.decode(value, { stream: true });\n\t\t\t\t\tlet newline = buffer.indexOf(\"\\n\");\n\t\t\t\t\twhile (newline !== -1) {\n\t\t\t\t\t\tconst line = buffer.slice(0, newline).replace(/\\r$/, \"\");\n\t\t\t\t\t\tbuffer = buffer.slice(newline + 1);\n\t\t\t\t\t\tif (line.startsWith(\"event:\")) event = line.slice(6).trim();\n\t\t\t\t\t\tif (event === \"deleted\" && line.startsWith(\"data:\")) {\n\t\t\t\t\t\t\tthis.stopDeletedSession(sessionId, controller);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (event === \"connected\" && !this.connectionId && line.startsWith(\"data:\")) {\n\t\t\t\t\t\t\tconst connected = JSON.parse(line.slice(5)) as { connectionId: string };\n\t\t\t\t\t\t\tthis.connectionId = connected.connectionId;\n\t\t\t\t\t\t\tthis.sequence = 0;\n\t\t\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\t\t\tthis.replace = true;\n\t\t\t\t\t\t\tthis.historyDirty = true;\n\t\t\t\t\t\t\tthis.dirty = true;\n\t\t\t\t\t\t\tthis.schedule(0);\n\t\t\t\t\t\t\tresolveConnection?.();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnewline = buffer.indexOf(\"\\n\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tawait reader.cancel();\n\t\t\t\treader.releaseLock();\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (sessionId === this.session.sessionId && this.deletedSessionId !== sessionId) this.reportError(error);\n\t\t} finally {\n\t\t\tresolveConnection?.();\n\t\t\tclearTimeout(timeout);\n\t\t\tcontroller.abort();\n\t\t\tif (this.controller === controller) this.connectionId = undefined;\n\t\t\tif (this.controller === controller && !this.disposed && !this.closing && this.deletedSessionId !== sessionId) {\n\t\t\t\tthis.reconnectTimer = setTimeout(\n\t\t\t\t\t() => {\n\t\t\t\t\t\tthis.reconnectTimer = undefined;\n\t\t\t\t\t\tvoid this.connect();\n\t\t\t\t\t},\n\t\t\t\t\tsessionId === this.session.sessionId ? 2000 : 0,\n\t\t\t\t);\n\t\t\t\tthis.reconnectTimer.unref();\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate flush(): Promise<void> {\n\t\tif (this.flushPromise) return this.flushPromise;\n\t\tconst promise = this.sendUpdate();\n\t\tthis.flushPromise = promise;\n\t\tvoid promise.finally(() => {\n\t\t\tthis.flushPromise = undefined;\n\t\t});\n\t\treturn promise;\n\t}\n\n\tprivate async sendUpdate(): Promise<void> {\n\t\tconst connectionId = this.connectionId;\n\t\tconst sessionId = this.connectedSessionId;\n\t\tconst controller = this.controller;\n\t\tif (\n\t\t\t!connectionId ||\n\t\t\t!sessionId ||\n\t\t\t!controller ||\n\t\t\tthis.disposed ||\n\t\t\tthis.deletedSessionId === sessionId ||\n\t\t\tthis.sending ||\n\t\t\t!this.dirty\n\t\t)\n\t\t\treturn;\n\t\tthis.sending = true;\n\t\tthis.dirty = false;\n\t\ttry {\n\t\t\tconst branch = this.historyDirty ? this.session.sessionManager.getBranch() : undefined;\n\t\t\tconst sentIndex = branch && this.sentEntryId ? branch.findIndex((entry) => entry.id === this.sentEntryId) : -1;\n\t\t\tconst replace = this.replace || (branch !== undefined && this.sentEntryId !== undefined && sentIndex === -1);\n\t\t\tthis.historyDirty = false;\n\t\t\tthis.replace = false;\n\t\t\tconst entries = branch ? (replace ? branch : branch.slice(sentIndex + 1)) : this.pendingEntries;\n\t\t\tthis.pendingEntries = [];\n\t\t\tconst messages = projectObserverEntries(entries);\n\t\t\tif (replace) this.firstUserTitle = \"\";\n\t\t\tif (!this.firstUserTitle) {\n\t\t\t\tconst firstUserContent = messages.find((message) => message.role === \"user\")?.content;\n\t\t\t\tthis.firstUserTitle = (\n\t\t\t\t\ttypeof firstUserContent === \"string\"\n\t\t\t\t\t\t? firstUserContent\n\t\t\t\t\t\t: (firstUserContent\n\t\t\t\t\t\t\t\t?.filter((part) => part.type === \"text\")\n\t\t\t\t\t\t\t\t.map((part) => part.text)\n\t\t\t\t\t\t\t\t.join(\"\") ?? \"\")\n\t\t\t\t).slice(0, 120);\n\t\t\t}\n\t\t\tconst update: ObserverUpdate = {\n\t\t\t\tsessionId,\n\t\t\t\tconnectionId,\n\t\t\t\tsequence: ++this.sequence,\n\t\t\t\tcwd: this.session.sessionManager.getCwd(),\n\t\t\t\ttitle: this.session.sessionManager.getSessionName() ?? this.firstUserTitle,\n\t\t\t\t...(replace ? { replace: messages } : messages.length ? { append: messages } : {}),\n\t\t\t\tstatus: this.session.isIdle ? \"idle\" : \"running\",\n\t\t\t\tlive: {\n\t\t\t\t\tmessage: this.liveMessage ? (projectMessage(this.liveMessageId, this.liveMessage) ?? null) : null,\n\t\t\t\t\ttools: [...this.tools.values()],\n\t\t\t\t},\n\t\t\t};\n\t\t\tconst response = await this.request(controller.signal).postJson(\"/api/observer\", update);\n\t\t\tif (response.status === 410) {\n\t\t\t\tthis.stopDeletedSession(sessionId, controller);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!response.ok) throw new Error(`update failed (HTTP ${response.status})`);\n\t\t\tconst result = (await response.json()) as { accepted: boolean };\n\t\t\tif (!result.accepted) throw new Error(\"update was not accepted\");\n\t\t\tif (entries.length > 0) this.sentEntryId = entries.at(-1)?.id;\n\t\t\telse if (replace) this.sentEntryId = undefined;\n\t\t\tif (this.disconnected) {\n\t\t\t\tthis.disconnected = false;\n\t\t\t\tconsole.error(\"pi-server observer connected\");\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (sessionId === this.session.sessionId && this.deletedSessionId !== sessionId) this.reportError(error);\n\t\t\tcontroller.abort();\n\t\t} finally {\n\t\t\tthis.sending = false;\n\t\t\tthis.schedule(80);\n\t\t}\n\t}\n\n\tclose(): Promise<void> {\n\t\tthis.closePromise ??= this.drainAndClose();\n\t\treturn this.closePromise;\n\t}\n\n\tprivate async drainAndClose(): Promise<void> {\n\t\tif (this.disposed) return;\n\t\tthis.closing = true;\n\t\tclearTimeout(this.timer);\n\t\tthis.timer = undefined;\n\t\tclearTimeout(this.reconnectTimer);\n\t\ttry {\n\t\t\tawait raceWithAbortSignal(\n\t\t\t\t(async () => {\n\t\t\t\t\tif (this.deletedSessionId === this.session.sessionId) return;\n\t\t\t\t\tif (!this.connectionId && this.controller?.signal.aborted) void this.connect();\n\t\t\t\t\tawait this.connectionReady;\n\t\t\t\t\tawait this.flushPromise;\n\t\t\t\t\tif (!this.connectionId) throw new Error(\"final transcript was not delivered: observer is disconnected\");\n\t\t\t\t\twhile (this.dirty && this.connectionId && !this.disposed) await this.flush();\n\t\t\t\t\tif (this.controller?.signal.aborted && this.deletedSessionId !== this.session.sessionId)\n\t\t\t\t\t\tthrow new Error(\"final transcript was not delivered: observer update failed\");\n\t\t\t\t})(),\n\t\t\t\tAbortSignal.timeout(10000),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconsole.error(`pi-server observer shutdown failed: ${error instanceof Error ? error.message : String(error)}`);\n\t\t} finally {\n\t\t\tthis.dispose();\n\t\t}\n\t}\n\n\tdispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.unsubscribe();\n\t\tclearTimeout(this.timer);\n\t\tclearTimeout(this.reconnectTimer);\n\t\tthis.controller?.abort();\n\t\tobservers.delete(this.session);\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@averyyy/pi-coding-agent",
|
|
3
|
-
"version": "1.4.0-piclient.
|
|
3
|
+
"version": "1.4.0-piclient.5",
|
|
4
4
|
"description": "Coding agent CLI with read, bash, edit, write tools and session management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"piConfig": {
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
"prepublishOnly": "npm run clean && npm run build"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@earendil-works/pi-agent-core": "npm:@averyyy/pi-agent-core@1.4.0-piclient.
|
|
52
|
-
"@earendil-works/pi-ai": "npm:@averyyy/pi-ai@1.4.0-piclient.
|
|
51
|
+
"@earendil-works/pi-agent-core": "npm:@averyyy/pi-agent-core@1.4.0-piclient.5",
|
|
52
|
+
"@earendil-works/pi-ai": "npm:@averyyy/pi-ai@1.4.0-piclient.5",
|
|
53
53
|
"@earendil-works/pi-codemode": "1.4.0",
|
|
54
54
|
"@earendil-works/pi-mcp": "1.4.0",
|
|
55
|
-
"@earendil-works/pi-tui": "npm:@averyyy/pi-tui@1.4.0-piclient.
|
|
55
|
+
"@earendil-works/pi-tui": "npm:@averyyy/pi-tui@1.4.0-piclient.5",
|
|
56
56
|
"@silvia-odwyer/photon-node": "0.3.4",
|
|
57
57
|
"brace-expansion": "5.0.12",
|
|
58
58
|
"chalk": "6.0.0",
|