@dudousxd/nestjs-agent-react 0.30.0 → 0.31.0

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/dist/index.d.cts CHANGED
@@ -388,6 +388,9 @@ declare function useAttachments(options?: UseAttachmentsOptions): AttachmentsSta
388
388
  * - `TOOL_CALL_START` / `ARGS` / `END` → `tool-input-start` / `-delta` / `-available`;
389
389
  * `TOOL_CALL_RESULT` → `tool-output` (or `tool-output-error` / `-denied`, from
390
390
  * `metadata['agora.outcome']`);
391
+ * - `ACTIVITY_SNAPSHOT` / `ACTIVITY_DELTA` → a `ui` part named `AgUiActivity`, id
392
+ * `activity:<messageId>`, props `{ activityType, content }` — the whole content each time (the
393
+ * delta's JSON Patch applied here), so a repeat replaces the widget in place;
391
394
  * - `RUN_ERROR` → the stream's `event: error`; `RUN_FINISHED` → `event: done` (a cancelled
392
395
  * outcome writes `cancelled` first; an interrupt outcome writes a `ui` part named
393
396
  * `AgUiInterrupt` carrying the interrupts, for the app to render);
@@ -409,7 +412,35 @@ interface AgUiChatStreamOptions {
409
412
  forwardedProps?: (body: Record<string, unknown>) => unknown;
410
413
  /** Read the refusal of a non-2xx answer. Default: the JSON body's `message`, else the status. */
411
414
  refusal?: (response: Response) => Promise<Error>;
415
+ /**
416
+ * The user message's `content` for the send. Default: the body's `message` as a string. Return
417
+ * a list of AG-UI content parts to send a file with it — `{ type: 'image' | 'document' | …,
418
+ * source: { type: 'data', value: <base64>, mimeType } }` — and the text as a `text` part.
419
+ */
420
+ content?: (body: Record<string, unknown>) => string | AgUiContentPart[];
412
421
  }
422
+ /** One AG-UI content part of a user message (text, or media by inline data, url or file handle). */
423
+ type AgUiContentPart = {
424
+ type: 'text';
425
+ text: string;
426
+ } | {
427
+ type: 'image' | 'audio' | 'video' | 'document';
428
+ source: {
429
+ type: 'data';
430
+ value: string;
431
+ mimeType: string;
432
+ } | {
433
+ type: 'url';
434
+ value: string;
435
+ mimeType?: string;
436
+ } | {
437
+ type: 'file';
438
+ value: string;
439
+ provider?: string;
440
+ mimeType?: string;
441
+ };
442
+ metadata?: Record<string, unknown>;
443
+ };
413
444
  /** Start a turn against an AG-UI producer; the stream comes back in this library's framing. */
414
445
  declare function agUiChatStream(request: ChatStreamRequest, options: AgUiChatStreamOptions): Promise<ChatStreamResponse>;
415
446
  /**
@@ -1975,4 +2006,4 @@ declare class QuotaBlockedError extends Error {
1975
2006
  constructor(block: QuotaBlock);
1976
2007
  }
1977
2008
 
1978
- export { AGENT_RUN_ERROR_CODES, type AgUiChatStreamOptions, AgentBackend, AgentChatTransport, type AgentChatTransportOptions, type AgentConfigState, type AgentMessageMetadata, AgentProvider, type AgentProviderProps, AgentRequestError, type AgentRunErrorCode, type AgentRunFailure, type AgentStreamMeta, type AgentsState, type AggregatedTurnUsage, type AmbientRenderUi, AmbientRenderUiContext, type AnswerInput, AnyToolUIPart, type ApprovalCountdown, type ApproveInput, ApproveOptions, type AttachmentRejection, AttachmentUploadStrategy, type AttachmentsState, type AutocompleteInputProps, type AutocompleteItem, type AutocompleteListboxProps, type AutocompleteOptionProps, type AutocompleteSource, type BackgroundRun, type ChatBackground, ChatInput, type ChatInputProps, type ChatQueue, ChatStatus, ChatStreamRequest, ChatStreamResponse, type ChatTranscript, type ClipboardLikeEvent, type CompletionEdit, type ComposerAutocomplete, DEFAULT_SPEECH_LANG, type DragLikeEvent, type EditSubmitInput, HttpErrorListener, type MessageActionInput, type MessageFeedbackState, type MessageFile, type MessageFileKind, MessageItem, type MessageItemClassNames, type MessageItemProps, MessageItemView, type MessageItemViewProps, MessageList, type MessageListClassNames, type MessageListProps, MessageUsageInfo, type ModelOption, type ModelsState, type QueuedChatMessage, QuotaBlockedError, type QuotaState, RUN_NOT_ACTIVE_CODE, type ReconnectOptions, type RejectInput, type RenderFilesFn, type RenderReasoningFn, type RenderTextFn, type RenderToolGroupFn, type RenderToolPartFn, type RenderUiFn, SPEECH_LANGUAGES, type SendWhileRunning, type SkillSuggestionData, type SkillsSourceOptions, type SkipInput, type SpeechLanguage, type SpeechRecognitionHook, type StagedAttachment, type StagedAttachmentStatus, type StickToBottom, type StickToBottomOptions, type StoredTurnMetadata, type StreamConnectionState, type ThreadsEvent, type ThreadsState, TimestampInfo, ToolCatalog, type ToolCatalogState, type TranscriptActionState, TranscriptBlock, type TranscriptCopyState, type TranscriptEditState, TranscriptFile, type TranscriptItem, type TranscriptItemOptions, type TranscriptQueuedFile, type TranscriptQueuedItem, type TranscriptStopState, TranscriptUiBlock, type TranscriptWindow, type TriggerMatch, type TriggerPosition, UploadAttachmentOptions, UsageSummary, type UseAgentChatOptions, type UseAgentConfigOptions, type UseAgentsOptions, type UseApprovalCountdownOptions, type UseAttachmentsOptions, type UseChatTranscriptOptions, type UseComposerAutocompleteOptions, type UseElapsedOptions, type UseMessageFeedbackOptions, type UseModelsOptions, type UseQuotaOptions, type UseSpeechRecognitionOptions, type UseThreadsOptions, type UseToolCatalogOptions, type UseTranscriptItemOptions, type WhileRunning, acceptsFile, agUiChatStream, applyCompletion, approvalCountdown, attachmentFile, backgroundRunsFromThread, createSkillsSource, dragHasFiles, fileKind, filesFromClipboard, filterAutocompleteItems, findActiveTrigger, formatElapsed, isRunNotActiveError, loadStoredSpeechLang, messageFiles, notifyThreads, onThreadsEvent, persistSpeechLang, readReasoningMs, reframeAgUiStream, storedMessageToUiMessage, storedThreadToUiMessages, useAgentBackend, useAgentChat, useAgentConfig, useAgents, useAmbientRenderUi, useApprovalCountdown, useAttachments, useChatTranscript, useComposerAutocomplete, useElapsed, useMessageFeedback, useModels, useQuota, useSpeechRecognition, useStickToBottom, useThreads, useToolCatalog, useTranscriptItem };
2009
+ export { AGENT_RUN_ERROR_CODES, type AgUiChatStreamOptions, type AgUiContentPart, AgentBackend, AgentChatTransport, type AgentChatTransportOptions, type AgentConfigState, type AgentMessageMetadata, AgentProvider, type AgentProviderProps, AgentRequestError, type AgentRunErrorCode, type AgentRunFailure, type AgentStreamMeta, type AgentsState, type AggregatedTurnUsage, type AmbientRenderUi, AmbientRenderUiContext, type AnswerInput, AnyToolUIPart, type ApprovalCountdown, type ApproveInput, ApproveOptions, type AttachmentRejection, AttachmentUploadStrategy, type AttachmentsState, type AutocompleteInputProps, type AutocompleteItem, type AutocompleteListboxProps, type AutocompleteOptionProps, type AutocompleteSource, type BackgroundRun, type ChatBackground, ChatInput, type ChatInputProps, type ChatQueue, ChatStatus, ChatStreamRequest, ChatStreamResponse, type ChatTranscript, type ClipboardLikeEvent, type CompletionEdit, type ComposerAutocomplete, DEFAULT_SPEECH_LANG, type DragLikeEvent, type EditSubmitInput, HttpErrorListener, type MessageActionInput, type MessageFeedbackState, type MessageFile, type MessageFileKind, MessageItem, type MessageItemClassNames, type MessageItemProps, MessageItemView, type MessageItemViewProps, MessageList, type MessageListClassNames, type MessageListProps, MessageUsageInfo, type ModelOption, type ModelsState, type QueuedChatMessage, QuotaBlockedError, type QuotaState, RUN_NOT_ACTIVE_CODE, type ReconnectOptions, type RejectInput, type RenderFilesFn, type RenderReasoningFn, type RenderTextFn, type RenderToolGroupFn, type RenderToolPartFn, type RenderUiFn, SPEECH_LANGUAGES, type SendWhileRunning, type SkillSuggestionData, type SkillsSourceOptions, type SkipInput, type SpeechLanguage, type SpeechRecognitionHook, type StagedAttachment, type StagedAttachmentStatus, type StickToBottom, type StickToBottomOptions, type StoredTurnMetadata, type StreamConnectionState, type ThreadsEvent, type ThreadsState, TimestampInfo, ToolCatalog, type ToolCatalogState, type TranscriptActionState, TranscriptBlock, type TranscriptCopyState, type TranscriptEditState, TranscriptFile, type TranscriptItem, type TranscriptItemOptions, type TranscriptQueuedFile, type TranscriptQueuedItem, type TranscriptStopState, TranscriptUiBlock, type TranscriptWindow, type TriggerMatch, type TriggerPosition, UploadAttachmentOptions, UsageSummary, type UseAgentChatOptions, type UseAgentConfigOptions, type UseAgentsOptions, type UseApprovalCountdownOptions, type UseAttachmentsOptions, type UseChatTranscriptOptions, type UseComposerAutocompleteOptions, type UseElapsedOptions, type UseMessageFeedbackOptions, type UseModelsOptions, type UseQuotaOptions, type UseSpeechRecognitionOptions, type UseThreadsOptions, type UseToolCatalogOptions, type UseTranscriptItemOptions, type WhileRunning, acceptsFile, agUiChatStream, applyCompletion, approvalCountdown, attachmentFile, backgroundRunsFromThread, createSkillsSource, dragHasFiles, fileKind, filesFromClipboard, filterAutocompleteItems, findActiveTrigger, formatElapsed, isRunNotActiveError, loadStoredSpeechLang, messageFiles, notifyThreads, onThreadsEvent, persistSpeechLang, readReasoningMs, reframeAgUiStream, storedMessageToUiMessage, storedThreadToUiMessages, useAgentBackend, useAgentChat, useAgentConfig, useAgents, useAmbientRenderUi, useApprovalCountdown, useAttachments, useChatTranscript, useComposerAutocomplete, useElapsed, useMessageFeedback, useModels, useQuota, useSpeechRecognition, useStickToBottom, useThreads, useToolCatalog, useTranscriptItem };
package/dist/index.d.ts CHANGED
@@ -388,6 +388,9 @@ declare function useAttachments(options?: UseAttachmentsOptions): AttachmentsSta
388
388
  * - `TOOL_CALL_START` / `ARGS` / `END` → `tool-input-start` / `-delta` / `-available`;
389
389
  * `TOOL_CALL_RESULT` → `tool-output` (or `tool-output-error` / `-denied`, from
390
390
  * `metadata['agora.outcome']`);
391
+ * - `ACTIVITY_SNAPSHOT` / `ACTIVITY_DELTA` → a `ui` part named `AgUiActivity`, id
392
+ * `activity:<messageId>`, props `{ activityType, content }` — the whole content each time (the
393
+ * delta's JSON Patch applied here), so a repeat replaces the widget in place;
391
394
  * - `RUN_ERROR` → the stream's `event: error`; `RUN_FINISHED` → `event: done` (a cancelled
392
395
  * outcome writes `cancelled` first; an interrupt outcome writes a `ui` part named
393
396
  * `AgUiInterrupt` carrying the interrupts, for the app to render);
@@ -409,7 +412,35 @@ interface AgUiChatStreamOptions {
409
412
  forwardedProps?: (body: Record<string, unknown>) => unknown;
410
413
  /** Read the refusal of a non-2xx answer. Default: the JSON body's `message`, else the status. */
411
414
  refusal?: (response: Response) => Promise<Error>;
415
+ /**
416
+ * The user message's `content` for the send. Default: the body's `message` as a string. Return
417
+ * a list of AG-UI content parts to send a file with it — `{ type: 'image' | 'document' | …,
418
+ * source: { type: 'data', value: <base64>, mimeType } }` — and the text as a `text` part.
419
+ */
420
+ content?: (body: Record<string, unknown>) => string | AgUiContentPart[];
412
421
  }
422
+ /** One AG-UI content part of a user message (text, or media by inline data, url or file handle). */
423
+ type AgUiContentPart = {
424
+ type: 'text';
425
+ text: string;
426
+ } | {
427
+ type: 'image' | 'audio' | 'video' | 'document';
428
+ source: {
429
+ type: 'data';
430
+ value: string;
431
+ mimeType: string;
432
+ } | {
433
+ type: 'url';
434
+ value: string;
435
+ mimeType?: string;
436
+ } | {
437
+ type: 'file';
438
+ value: string;
439
+ provider?: string;
440
+ mimeType?: string;
441
+ };
442
+ metadata?: Record<string, unknown>;
443
+ };
413
444
  /** Start a turn against an AG-UI producer; the stream comes back in this library's framing. */
414
445
  declare function agUiChatStream(request: ChatStreamRequest, options: AgUiChatStreamOptions): Promise<ChatStreamResponse>;
415
446
  /**
@@ -1975,4 +2006,4 @@ declare class QuotaBlockedError extends Error {
1975
2006
  constructor(block: QuotaBlock);
1976
2007
  }
1977
2008
 
1978
- export { AGENT_RUN_ERROR_CODES, type AgUiChatStreamOptions, AgentBackend, AgentChatTransport, type AgentChatTransportOptions, type AgentConfigState, type AgentMessageMetadata, AgentProvider, type AgentProviderProps, AgentRequestError, type AgentRunErrorCode, type AgentRunFailure, type AgentStreamMeta, type AgentsState, type AggregatedTurnUsage, type AmbientRenderUi, AmbientRenderUiContext, type AnswerInput, AnyToolUIPart, type ApprovalCountdown, type ApproveInput, ApproveOptions, type AttachmentRejection, AttachmentUploadStrategy, type AttachmentsState, type AutocompleteInputProps, type AutocompleteItem, type AutocompleteListboxProps, type AutocompleteOptionProps, type AutocompleteSource, type BackgroundRun, type ChatBackground, ChatInput, type ChatInputProps, type ChatQueue, ChatStatus, ChatStreamRequest, ChatStreamResponse, type ChatTranscript, type ClipboardLikeEvent, type CompletionEdit, type ComposerAutocomplete, DEFAULT_SPEECH_LANG, type DragLikeEvent, type EditSubmitInput, HttpErrorListener, type MessageActionInput, type MessageFeedbackState, type MessageFile, type MessageFileKind, MessageItem, type MessageItemClassNames, type MessageItemProps, MessageItemView, type MessageItemViewProps, MessageList, type MessageListClassNames, type MessageListProps, MessageUsageInfo, type ModelOption, type ModelsState, type QueuedChatMessage, QuotaBlockedError, type QuotaState, RUN_NOT_ACTIVE_CODE, type ReconnectOptions, type RejectInput, type RenderFilesFn, type RenderReasoningFn, type RenderTextFn, type RenderToolGroupFn, type RenderToolPartFn, type RenderUiFn, SPEECH_LANGUAGES, type SendWhileRunning, type SkillSuggestionData, type SkillsSourceOptions, type SkipInput, type SpeechLanguage, type SpeechRecognitionHook, type StagedAttachment, type StagedAttachmentStatus, type StickToBottom, type StickToBottomOptions, type StoredTurnMetadata, type StreamConnectionState, type ThreadsEvent, type ThreadsState, TimestampInfo, ToolCatalog, type ToolCatalogState, type TranscriptActionState, TranscriptBlock, type TranscriptCopyState, type TranscriptEditState, TranscriptFile, type TranscriptItem, type TranscriptItemOptions, type TranscriptQueuedFile, type TranscriptQueuedItem, type TranscriptStopState, TranscriptUiBlock, type TranscriptWindow, type TriggerMatch, type TriggerPosition, UploadAttachmentOptions, UsageSummary, type UseAgentChatOptions, type UseAgentConfigOptions, type UseAgentsOptions, type UseApprovalCountdownOptions, type UseAttachmentsOptions, type UseChatTranscriptOptions, type UseComposerAutocompleteOptions, type UseElapsedOptions, type UseMessageFeedbackOptions, type UseModelsOptions, type UseQuotaOptions, type UseSpeechRecognitionOptions, type UseThreadsOptions, type UseToolCatalogOptions, type UseTranscriptItemOptions, type WhileRunning, acceptsFile, agUiChatStream, applyCompletion, approvalCountdown, attachmentFile, backgroundRunsFromThread, createSkillsSource, dragHasFiles, fileKind, filesFromClipboard, filterAutocompleteItems, findActiveTrigger, formatElapsed, isRunNotActiveError, loadStoredSpeechLang, messageFiles, notifyThreads, onThreadsEvent, persistSpeechLang, readReasoningMs, reframeAgUiStream, storedMessageToUiMessage, storedThreadToUiMessages, useAgentBackend, useAgentChat, useAgentConfig, useAgents, useAmbientRenderUi, useApprovalCountdown, useAttachments, useChatTranscript, useComposerAutocomplete, useElapsed, useMessageFeedback, useModels, useQuota, useSpeechRecognition, useStickToBottom, useThreads, useToolCatalog, useTranscriptItem };
2009
+ export { AGENT_RUN_ERROR_CODES, type AgUiChatStreamOptions, type AgUiContentPart, AgentBackend, AgentChatTransport, type AgentChatTransportOptions, type AgentConfigState, type AgentMessageMetadata, AgentProvider, type AgentProviderProps, AgentRequestError, type AgentRunErrorCode, type AgentRunFailure, type AgentStreamMeta, type AgentsState, type AggregatedTurnUsage, type AmbientRenderUi, AmbientRenderUiContext, type AnswerInput, AnyToolUIPart, type ApprovalCountdown, type ApproveInput, ApproveOptions, type AttachmentRejection, AttachmentUploadStrategy, type AttachmentsState, type AutocompleteInputProps, type AutocompleteItem, type AutocompleteListboxProps, type AutocompleteOptionProps, type AutocompleteSource, type BackgroundRun, type ChatBackground, ChatInput, type ChatInputProps, type ChatQueue, ChatStatus, ChatStreamRequest, ChatStreamResponse, type ChatTranscript, type ClipboardLikeEvent, type CompletionEdit, type ComposerAutocomplete, DEFAULT_SPEECH_LANG, type DragLikeEvent, type EditSubmitInput, HttpErrorListener, type MessageActionInput, type MessageFeedbackState, type MessageFile, type MessageFileKind, MessageItem, type MessageItemClassNames, type MessageItemProps, MessageItemView, type MessageItemViewProps, MessageList, type MessageListClassNames, type MessageListProps, MessageUsageInfo, type ModelOption, type ModelsState, type QueuedChatMessage, QuotaBlockedError, type QuotaState, RUN_NOT_ACTIVE_CODE, type ReconnectOptions, type RejectInput, type RenderFilesFn, type RenderReasoningFn, type RenderTextFn, type RenderToolGroupFn, type RenderToolPartFn, type RenderUiFn, SPEECH_LANGUAGES, type SendWhileRunning, type SkillSuggestionData, type SkillsSourceOptions, type SkipInput, type SpeechLanguage, type SpeechRecognitionHook, type StagedAttachment, type StagedAttachmentStatus, type StickToBottom, type StickToBottomOptions, type StoredTurnMetadata, type StreamConnectionState, type ThreadsEvent, type ThreadsState, TimestampInfo, ToolCatalog, type ToolCatalogState, type TranscriptActionState, TranscriptBlock, type TranscriptCopyState, type TranscriptEditState, TranscriptFile, type TranscriptItem, type TranscriptItemOptions, type TranscriptQueuedFile, type TranscriptQueuedItem, type TranscriptStopState, TranscriptUiBlock, type TranscriptWindow, type TriggerMatch, type TriggerPosition, UploadAttachmentOptions, UsageSummary, type UseAgentChatOptions, type UseAgentConfigOptions, type UseAgentsOptions, type UseApprovalCountdownOptions, type UseAttachmentsOptions, type UseChatTranscriptOptions, type UseComposerAutocompleteOptions, type UseElapsedOptions, type UseMessageFeedbackOptions, type UseModelsOptions, type UseQuotaOptions, type UseSpeechRecognitionOptions, type UseThreadsOptions, type UseToolCatalogOptions, type UseTranscriptItemOptions, type WhileRunning, acceptsFile, agUiChatStream, applyCompletion, approvalCountdown, attachmentFile, backgroundRunsFromThread, createSkillsSource, dragHasFiles, fileKind, filesFromClipboard, filterAutocompleteItems, findActiveTrigger, formatElapsed, isRunNotActiveError, loadStoredSpeechLang, messageFiles, notifyThreads, onThreadsEvent, persistSpeechLang, readReasoningMs, reframeAgUiStream, storedMessageToUiMessage, storedThreadToUiMessages, useAgentBackend, useAgentChat, useAgentConfig, useAgents, useAmbientRenderUi, useApprovalCountdown, useAttachments, useChatTranscript, useComposerAutocomplete, useElapsed, useMessageFeedback, useModels, useQuota, useSpeechRecognition, useStickToBottom, useThreads, useToolCatalog, useTranscriptItem };
package/dist/index.js CHANGED
@@ -1852,7 +1852,7 @@ async function agUiChatStream(request, options) {
1852
1852
  threadId,
1853
1853
  runId: newId(),
1854
1854
  protocolVersion: "1.0",
1855
- messages: [{ id: newId(), role: "user", content: message }],
1855
+ messages: [{ id: newId(), role: "user", content: options.content?.(body) ?? message }],
1856
1856
  ...forwarded !== void 0 ? { forwardedProps: forwarded } : {}
1857
1857
  };
1858
1858
  const doFetch = options.fetch ?? globalThis.fetch.bind(globalThis);
@@ -1927,6 +1927,7 @@ function reframeAgUiStream(source, ids) {
1927
1927
  });
1928
1928
  }
1929
1929
  function createReframer(threadId) {
1930
+ const activities = /* @__PURE__ */ new Map();
1930
1931
  let seq = 0;
1931
1932
  let metaSent = false;
1932
1933
  const tools = /* @__PURE__ */ new Map();
@@ -2043,6 +2044,30 @@ data: ${JSON.stringify({
2043
2044
  else frame({ kind: "tool-output", id, output: parseJson(content, content) });
2044
2045
  break;
2045
2046
  }
2047
+ case "ACTIVITY_SNAPSHOT":
2048
+ case "ACTIVITY_DELTA": {
2049
+ const messageId = typeof event.messageId === "string" ? event.messageId : "";
2050
+ if (messageId === "") break;
2051
+ const known = activities.get(messageId);
2052
+ const activityType = typeof event.activityType === "string" ? event.activityType : known?.activityType ?? "";
2053
+ let content;
2054
+ if (event.type === "ACTIVITY_SNAPSHOT") {
2055
+ if (known !== void 0 && event.replace === false) break;
2056
+ content = isRecord2(event.content) ? event.content : {};
2057
+ } else {
2058
+ if (known === void 0 || !Array.isArray(event.patch)) break;
2059
+ content = applyPatch(known.content, event.patch);
2060
+ if (content === void 0) break;
2061
+ }
2062
+ activities.set(messageId, { activityType, content });
2063
+ frame({
2064
+ kind: "ui",
2065
+ id: `activity:${messageId}`,
2066
+ component: "AgUiActivity",
2067
+ props: { activityType, content }
2068
+ });
2069
+ break;
2070
+ }
2046
2071
  case "RUN_ERROR":
2047
2072
  state.closed = true;
2048
2073
  out += `event: error
@@ -2096,6 +2121,38 @@ function contentText(content) {
2096
2121
  if (!Array.isArray(content)) return "";
2097
2122
  return content.filter((part) => isRecord2(part) && part.type === "text" && typeof part.text === "string").map((part) => part.text).join("");
2098
2123
  }
2124
+ function applyPatch(target, patch) {
2125
+ const doc = structuredClone(target);
2126
+ for (const operation of patch) {
2127
+ if (!isRecord2(operation) || typeof operation.path !== "string") return void 0;
2128
+ const tokens = operation.path.split("/").slice(1).map((token) => token.replace(/~1/g, "/").replace(/~0/g, "~"));
2129
+ const key = tokens.pop();
2130
+ if (key === void 0) return void 0;
2131
+ let parent = doc;
2132
+ for (const token of tokens) {
2133
+ parent = Array.isArray(parent) ? parent[Number(token)] : isRecord2(parent) ? parent[token] : void 0;
2134
+ if (parent === void 0) return void 0;
2135
+ }
2136
+ if (Array.isArray(parent)) {
2137
+ const index = key === "-" ? parent.length : Number(key);
2138
+ if (!Number.isInteger(index) || index < 0 || index > parent.length) return void 0;
2139
+ if (operation.op === "add") parent.splice(index, 0, operation.value);
2140
+ else if (operation.op === "replace" && index < parent.length) parent[index] = operation.value;
2141
+ else if (operation.op === "remove" && index < parent.length) parent.splice(index, 1);
2142
+ else if (operation.op === "test") {
2143
+ if (JSON.stringify(parent[index]) !== JSON.stringify(operation.value)) return void 0;
2144
+ } else return void 0;
2145
+ } else if (isRecord2(parent)) {
2146
+ if (operation.op === "add" || operation.op === "replace" && key in parent) {
2147
+ parent[key] = operation.value;
2148
+ } else if (operation.op === "remove" && key in parent) delete parent[key];
2149
+ else if (operation.op === "test") {
2150
+ if (JSON.stringify(parent[key]) !== JSON.stringify(operation.value)) return void 0;
2151
+ } else return void 0;
2152
+ } else return void 0;
2153
+ }
2154
+ return doc;
2155
+ }
2099
2156
 
2100
2157
  // src/catalog/use-agents.ts
2101
2158
  import { useMemo as useMemo5 } from "react";