@parhelia/core 0.1.12663 → 0.1.12676

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.
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  import React, { useEffect, useState, useRef, useCallback, useLayoutEffect, useMemo, } from "react";
3
3
  import { flushSync } from "react-dom";
4
4
  import { Send, AlertCircle, Loader2, User, Wand2, Square, Mic, MicOff, ChevronDown, ChevronUp, ListTodo, ArrowLeft, DollarSign, ExternalLink, Settings2, Target, X, Plus, } from "lucide-react";
5
- import { getAgent, startAgent, claimAgentBrowser, cancelAgentDialog, assignAgentSkill, emitAgentDocumentsChanged, persistDraftAgent, updateAgentSettings, updateAgentCostLimit, updateAgentContext, getAgentSkillCatalog, getAgentAvailableTools, getAgentOperationAllowances, getAgentTriggerSubscriptions, cancelAgent, canonicalizeAgentMetadata, getPendingPrompts, releaseAgentBrowser, revokeAgentSkill, } from "../services/agentService";
5
+ import { getAgent, startAgent, claimAgentBrowser, cancelAgentDialog, assignAgentSkill, persistDraftAgent, updateAgentSettings, updateAgentCostLimit, updateAgentContext, getAgentSkillCatalog, getAgentAvailableTools, getAgentOperationAllowances, getAgentTriggerSubscriptions, cancelAgent, canonicalizeAgentMetadata, getPendingPrompts, releaseAgentBrowser, revokeAgentSkill, } from "../services/agentService";
6
6
  import { parseAgentStatus } from "../services/agentStatus";
7
7
  import { useEditContext, useFieldsEditContext } from "../client/editContext";
8
8
  import { localStorageService } from "../services/localStorageService";
@@ -33,52 +33,6 @@ import { Splitter } from "../ui/Splitter";
33
33
  import { ScrollingContentTree } from "../ScrollingContentTree";
34
34
  import { MarkdownDisplay, } from "../../components/MarkdownDisplay";
35
35
  const AGENT_HISTORY_LIMIT = 1000;
36
- function parseToolResultPayload(value) {
37
- if (!value) {
38
- return null;
39
- }
40
- if (typeof value === "object") {
41
- return value;
42
- }
43
- if (typeof value !== "string") {
44
- return null;
45
- }
46
- try {
47
- const parsed = JSON.parse(value);
48
- return parsed && typeof parsed === "object" ? parsed : null;
49
- }
50
- catch {
51
- return null;
52
- }
53
- }
54
- function shouldRefreshDocumentsForToolResult(functionName, data) {
55
- const normalizedName = (functionName || "").trim().toLowerCase();
56
- const hasError = !!(data?.functionError || data?.error);
57
- if (!normalizedName || hasError) {
58
- return false;
59
- }
60
- if (normalizedName === "attach-media-item") {
61
- return true;
62
- }
63
- if (normalizedName === "detach-document") {
64
- const parsed = parseToolResultPayload(data?.functionResult || data?.result);
65
- return parsed?.Removed === true || parsed?.removed === true;
66
- }
67
- if (normalizedName === "extract-pdf-images") {
68
- const parsed = parseToolResultPayload(data?.functionResult || data?.result);
69
- if (!parsed) {
70
- return false;
71
- }
72
- const destination = String(parsed.Destination ?? parsed.destination ?? "");
73
- const discoveryOnly = Boolean(parsed.DiscoveryOnly ?? parsed.discoveryOnly);
74
- const createdImageCount = Number(parsed.CreatedImageCount ?? parsed.createdImageCount ?? 0);
75
- return (!discoveryOnly &&
76
- destination === "agentDocumentStore" &&
77
- Number.isFinite(createdImageCount) &&
78
- createdImageCount > 0);
79
- }
80
- return false;
81
- }
82
36
  function mergeAgentOperationHistory(existing, incoming, limit = AGENT_HISTORY_LIMIT) {
83
37
  const merged = new Map(existing.map((operation) => [operation.id, operation]));
84
38
  for (const operation of incoming) {
@@ -2762,14 +2716,9 @@ export function AgentTerminal({ agentStub, initialMetadata, profiles, isActive =
2762
2716
  appendToolUiEvent("ui:tool-result-applied", `${extractedToolCall.functionName || "unknown"} toolCallId=${resultToolCallId} targetMessageId=${resultMessageId} completed=${matchingToolCall?.isCompleted ? "yes" : "no"} messageToolCalls=${messageWithToolResult?.toolCalls?.length || 0}`);
2763
2717
  return updated;
2764
2718
  });
2765
- const currentAgentId = agentData?.id || agent?.id || agentStub.id;
2766
- if (currentAgentId &&
2767
- shouldRefreshDocumentsForToolResult(extractedToolCall.functionName || "", message.data)) {
2768
- emitAgentDocumentsChanged({
2769
- agentId: currentAgentId,
2770
- reason: extractedToolCall.functionName || "tool-result",
2771
- });
2772
- }
2719
+ // Document-store refresh is now triggered by the backend agent:documents:changed
2720
+ // WebSocket message (fired from AgentDocumentRepository), bridged to the in-process
2721
+ // emitAgentDocumentsChanged event in EditorShell. No per-tool allow-list here.
2773
2722
  }, [agent?.id, agentStub.id, appendToolUiEvent]);
2774
2723
  // Listen for local approval resolution to update UI
2775
2724
  useEffect(() => {
@@ -3616,6 +3565,7 @@ export function AgentTerminal({ agentStub, initialMetadata, profiles, isActive =
3616
3565
  if (normalizedStatus === "idle") {
3617
3566
  clearStopGuard();
3618
3567
  setLastRunStatusReason(null);
3568
+ setError(null);
3619
3569
  // Stop indicators and mark any in-progress streaming messages as completed
3620
3570
  clearHeartbeatMessages();
3621
3571
  setAgent((prev) => (prev ? { ...prev, status: "idle" } : prev));
@@ -3759,6 +3709,7 @@ export function AgentTerminal({ agentStub, initialMetadata, profiles, isActive =
3759
3709
  if (normalizedStatus === "waitingForApproval") {
3760
3710
  clearStopGuard();
3761
3711
  setLastRunStatusReason(null);
3712
+ setError(null);
3762
3713
  setPendingBrowserCaptureDialogType(null);
3763
3714
  setPendingBrowserCaptureCallbackId(null);
3764
3715
  setAgent((prev) => prev ? { ...prev, status: "waitingForApproval" } : prev);
@@ -3771,6 +3722,7 @@ export function AgentTerminal({ agentStub, initialMetadata, profiles, isActive =
3771
3722
  if (normalizedStatus === "waitingForInput") {
3772
3723
  clearStopGuard();
3773
3724
  setLastRunStatusReason(null);
3725
+ setError(null);
3774
3726
  const dialogType = typeof statusData?.dialogType === "string"
3775
3727
  ? statusData.dialogType
3776
3728
  : null;
@@ -3801,6 +3753,7 @@ export function AgentTerminal({ agentStub, initialMetadata, profiles, isActive =
3801
3753
  }
3802
3754
  if (normalizedStatus === "costLimitReached") {
3803
3755
  clearStopGuard();
3756
+ setError(null);
3804
3757
  setPendingBrowserCaptureDialogType(null);
3805
3758
  setPendingBrowserCaptureCallbackId(null);
3806
3759
  const totalCost = Number(statusData.totalCost) || 0;
@@ -3851,6 +3804,7 @@ export function AgentTerminal({ agentStub, initialMetadata, profiles, isActive =
3851
3804
  // Handle "completed" state (fallback for legacy code paths that send status instead of lifecycle event)
3852
3805
  if (normalizedStatus === "completed") {
3853
3806
  clearStopGuard();
3807
+ setError(null);
3854
3808
  // Reset deduplication for the next run
3855
3809
  lastSeqRef.current = 0;
3856
3810
  clearHeartbeatMessages();
@@ -3899,6 +3853,7 @@ export function AgentTerminal({ agentStub, initialMetadata, profiles, isActive =
3899
3853
  return;
3900
3854
  }
3901
3855
  setLastRunStatusReason(null);
3856
+ setError(null);
3902
3857
  // Update agent status to running and clear any previous error statusMessage
3903
3858
  setAgent((prev) => prev
3904
3859
  ? { ...prev, status: "running", statusMessage: undefined }
@@ -3912,8 +3867,11 @@ export function AgentTerminal({ agentStub, initialMetadata, profiles, isActive =
3912
3867
  if (normalizedStatus === "error") {
3913
3868
  clearStopGuard();
3914
3869
  setLastRunStatusReason(null);
3915
- const errorMsg = toUserFacingAgentErrorMessage(statusData?.statusMessage ?? statusData?.error) || "Unknown error";
3870
+ const errorMsg = toUserFacingAgentErrorMessage(statusData?.statusMessage ??
3871
+ statusData?.message ??
3872
+ statusData?.error) || "Unknown error";
3916
3873
  clearHeartbeatMessages();
3874
+ setError(errorMsg);
3917
3875
  setAgent((prev) => prev
3918
3876
  ? { ...prev, status: "error", statusMessage: errorMsg }
3919
3877
  : prev);