@tutti-os/agent-gui 0.0.30 → 0.0.32

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.js CHANGED
@@ -17489,7 +17489,6 @@ var MENTION_PALETTE_MIN_HEIGHT_PX = 280;
17489
17489
  var MENTION_PALETTE_MAX_HEIGHT_PX = 320;
17490
17490
  var MENTION_PALETTE_GAP_PX = 8;
17491
17491
  var MENTION_PALETTE_VIEWPORT_PADDING_PX = 8;
17492
- var promptFileUploadUnsupportedError = "Prompt file uploads are not supported by this agent runtime.";
17493
17492
  var EMPTY_CONTEXT_MENTION_PROVIDERS = [];
17494
17493
  var EMPTY_PROMPT_TIPS = [];
17495
17494
  var EMPTY_PROVIDER_SKILLS = [];
@@ -18493,87 +18492,6 @@ function AgentComposer({
18493
18492
  },
18494
18493
  [onDraftContentChange]
18495
18494
  );
18496
- const addDraftFiles = useCallback9(
18497
- (attachments) => {
18498
- if (attachments.length === 0) {
18499
- return;
18500
- }
18501
- const uploadPromptContent = agentActivityRuntime?.uploadPromptContent;
18502
- const nextFiles = attachments.map((attachment) => ({
18503
- id: `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,
18504
- name: attachment.name,
18505
- mimeType: attachment.mimeType?.trim() || "application/octet-stream",
18506
- hostPath: attachment.hostPath,
18507
- uploading: Boolean(uploadPromptContent),
18508
- ...uploadPromptContent ? {} : { uploadError: promptFileUploadUnsupportedError }
18509
- }));
18510
- const nextDraftFiles = [...draftFilesRef.current, ...nextFiles];
18511
- draftFilesRef.current = nextDraftFiles;
18512
- onDraftContentChange({
18513
- prompt: draftPromptRef.current,
18514
- images: draftImagesRef.current,
18515
- files: nextDraftFiles
18516
- });
18517
- if (!uploadPromptContent) {
18518
- return;
18519
- }
18520
- for (const draftFile of nextFiles) {
18521
- void uploadPromptContent({
18522
- workspaceId,
18523
- content: [
18524
- {
18525
- type: "file",
18526
- mimeType: draftFile.mimeType,
18527
- hostPath: draftFile.hostPath,
18528
- name: draftFile.name,
18529
- kind: "file"
18530
- }
18531
- ]
18532
- }).then((result) => {
18533
- const uploadedFile = result.content.find(
18534
- (block) => block.type === "file"
18535
- );
18536
- const uploadedPath = uploadedFile?.path?.trim() ?? "";
18537
- if (!uploadedPath) {
18538
- throw new Error("Prompt file upload completed without path.");
18539
- }
18540
- const uploadedDraftFiles = draftFilesRef.current.map(
18541
- (file) => file.id === draftFile.id ? {
18542
- id: file.id,
18543
- name: uploadedFile?.name ?? file.name,
18544
- mimeType: uploadedFile?.mimeType ?? file.mimeType,
18545
- path: uploadedPath,
18546
- assetId: uploadedFile?.assetId,
18547
- sizeBytes: uploadedFile?.sizeBytes,
18548
- uploading: false
18549
- } : file
18550
- );
18551
- draftFilesRef.current = uploadedDraftFiles;
18552
- onDraftContentChange({
18553
- prompt: draftPromptRef.current,
18554
- images: draftImagesRef.current,
18555
- files: uploadedDraftFiles
18556
- });
18557
- }).catch((error) => {
18558
- const message = error instanceof Error ? error.message : String(error);
18559
- const failedDraftFiles = draftFilesRef.current.map(
18560
- (file) => file.id === draftFile.id ? {
18561
- ...file,
18562
- uploading: false,
18563
- uploadError: message
18564
- } : file
18565
- );
18566
- draftFilesRef.current = failedDraftFiles;
18567
- onDraftContentChange({
18568
- prompt: draftPromptRef.current,
18569
- images: draftImagesRef.current,
18570
- files: failedDraftFiles
18571
- });
18572
- });
18573
- }
18574
- },
18575
- [agentActivityRuntime, onDraftContentChange, workspaceId]
18576
- );
18577
18495
  const removeDraftFile = useCallback9(
18578
18496
  (id) => {
18579
18497
  const nextDraftFiles = draftFilesRef.current.filter(
@@ -18589,24 +18507,59 @@ function AgentComposer({
18589
18507
  [onDraftContentChange]
18590
18508
  );
18591
18509
  const applyReferencePickResult = useCallback9(
18592
- (result) => {
18510
+ async (result) => {
18593
18511
  if (result.files.length > 0) {
18594
- editorHandleRef.current?.insertWorkspaceReferences(result.files);
18512
+ const uploadPromptContent = agentActivityRuntime?.uploadPromptContent;
18513
+ const uploadedFiles = await Promise.all(
18514
+ result.files.map(async (file) => {
18515
+ const hostPath = file.hostPath?.trim() ?? "";
18516
+ if (!hostPath) {
18517
+ return file;
18518
+ }
18519
+ if (!uploadPromptContent) {
18520
+ throw new Error(
18521
+ "Prompt file uploads are not supported by this agent runtime."
18522
+ );
18523
+ }
18524
+ const uploaded = await uploadPromptContent({
18525
+ workspaceId,
18526
+ content: [
18527
+ {
18528
+ type: "file",
18529
+ hostPath,
18530
+ name: file.displayName,
18531
+ kind: "file"
18532
+ }
18533
+ ]
18534
+ });
18535
+ const uploadedFile = uploaded.content.find(
18536
+ (block) => block.type === "file"
18537
+ );
18538
+ const uploadedPath = uploadedFile?.path?.trim() ?? "";
18539
+ if (!uploadedPath) {
18540
+ throw new Error("Prompt file upload completed without path.");
18541
+ }
18542
+ return {
18543
+ ...file,
18544
+ path: uploadedPath,
18545
+ ...uploadedFile?.name ? { displayName: uploadedFile.name } : file.displayName ? { displayName: file.displayName } : {},
18546
+ ...uploadedFile?.sizeBytes ? { sizeBytes: uploadedFile.sizeBytes } : {}
18547
+ };
18548
+ })
18549
+ );
18550
+ editorHandleRef.current?.insertWorkspaceReferences(uploadedFiles);
18595
18551
  }
18596
18552
  if (result.mentionItems.length > 0) {
18597
18553
  editorHandleRef.current?.insertMentionItems(result.mentionItems);
18598
18554
  }
18599
- if (result.hostAttachments && result.hostAttachments.length > 0) {
18600
- addDraftFiles(result.hostAttachments);
18601
- }
18602
18555
  },
18603
- [addDraftFiles]
18556
+ [agentActivityRuntime, workspaceId]
18604
18557
  );
18605
18558
  const handleWorkspaceReferencePicker = useCallback9(async () => {
18606
18559
  if (!onRequestWorkspaceReferences) {
18607
18560
  return;
18608
18561
  }
18609
- applyReferencePickResult(await onRequestWorkspaceReferences());
18562
+ await applyReferencePickResult(await onRequestWorkspaceReferences());
18610
18563
  }, [applyReferencePickResult, onRequestWorkspaceReferences]);
18611
18564
  const handleOpenReferencesForEntity = useCallback9(
18612
18565
  (entity) => {
@@ -18614,7 +18567,9 @@ function AgentComposer({
18614
18567
  if (!onRequestWorkspaceReferences) {
18615
18568
  return;
18616
18569
  }
18617
- void onRequestWorkspaceReferences(entity).then(applyReferencePickResult);
18570
+ void onRequestWorkspaceReferences(entity).then(
18571
+ (result) => applyReferencePickResult(result)
18572
+ );
18618
18573
  },
18619
18574
  [
18620
18575
  closeFileMentionPalette,
@@ -20138,7 +20093,6 @@ function AgentGUINodeView({
20138
20093
  workspaceAppIcons = EMPTY_WORKSPACE_APP_ICONS3
20139
20094
  }) {
20140
20095
  "use memo";
20141
- const agentHostApi = useAgentHostApi();
20142
20096
  const layoutElementRef = useRef13(null);
20143
20097
  const railResizeInteractionRef = useRef13(null);
20144
20098
  const [isRailResizing, setIsRailResizing] = useState11(false);
@@ -20156,124 +20110,10 @@ function AgentGUINodeView({
20156
20110
  );
20157
20111
  const workspaceReferencePickerResolverRef = useRef13(null);
20158
20112
  const emptyReferencePickResult = useMemo10(
20159
- () => ({ files: [], mentionItems: [], hostAttachments: [] }),
20113
+ () => ({ files: [], mentionItems: [] }),
20160
20114
  []
20161
20115
  );
20162
- const hostLocalFileLabel = uiLanguage === "zh-CN" ? "\u672C\u5730\u6587\u4EF6(\u5BBF\u4E3B\u673A)" : "Local files (Host)";
20163
- const hostLocalFileSelectLabel = uiLanguage === "zh-CN" ? "\u4ECE\u7535\u8111\u9009\u62E9\u2026" : "Choose from computer\u2026";
20164
20116
  const hostLocalFileSourceId = "host-local-file";
20165
- const hostLocalFileActionPath = "host-local-file://select";
20166
- const referenceSourceAggregatorWithHostLocalFile = useMemo10(() => {
20167
- if (!referenceSourceAggregator) {
20168
- return null;
20169
- }
20170
- const sourceId = hostLocalFileSourceId;
20171
- const actionNode = {
20172
- ref: { sourceId, nodeId: "select-files" },
20173
- kind: "file",
20174
- displayName: hostLocalFileSelectLabel
20175
- };
20176
- const rootNode = {
20177
- ref: { sourceId, nodeId: "\0source-root" },
20178
- kind: "folder",
20179
- displayName: hostLocalFileLabel,
20180
- hasChildren: true
20181
- };
20182
- let hostProvidedLocalFileSource = false;
20183
- return {
20184
- ...referenceSourceAggregator,
20185
- async listSources(scope) {
20186
- const sources = await referenceSourceAggregator.listSources(scope);
20187
- hostProvidedLocalFileSource = sources.some(
20188
- (source) => source.sourceId === sourceId
20189
- );
20190
- if (hostProvidedLocalFileSource) {
20191
- return sources;
20192
- }
20193
- return [
20194
- ...sources,
20195
- {
20196
- sourceId,
20197
- label: hostLocalFileLabel,
20198
- icon: "file",
20199
- capabilities: {
20200
- searchable: false,
20201
- previewable: false,
20202
- paginated: false,
20203
- navigable: false,
20204
- filterable: false
20205
- }
20206
- }
20207
- ];
20208
- },
20209
- async listRoot(scope) {
20210
- const root = await referenceSourceAggregator.listRoot(scope);
20211
- if (hostProvidedLocalFileSource) {
20212
- return root;
20213
- }
20214
- return [...root, rootNode];
20215
- },
20216
- async listChildren(scope, node, input) {
20217
- if (node.sourceId === sourceId && !hostProvidedLocalFileSource) {
20218
- return { entries: [actionNode], nextCursor: null };
20219
- }
20220
- return await referenceSourceAggregator.listChildren(scope, node, input);
20221
- },
20222
- async search(scope, currentSourceId, input) {
20223
- if (currentSourceId === sourceId && !hostProvidedLocalFileSource) {
20224
- return { entries: [], nextCursor: null };
20225
- }
20226
- return await referenceSourceAggregator.search(
20227
- scope,
20228
- currentSourceId,
20229
- input
20230
- );
20231
- },
20232
- async open(scope, node) {
20233
- if (node.ref.sourceId === sourceId && !hostProvidedLocalFileSource) {
20234
- return;
20235
- }
20236
- await referenceSourceAggregator.open(scope, node);
20237
- },
20238
- async readPreview(scope, node) {
20239
- if (node.ref.sourceId === sourceId && !hostProvidedLocalFileSource) {
20240
- return null;
20241
- }
20242
- return await referenceSourceAggregator.readPreview(scope, node);
20243
- },
20244
- resolveSelection(node) {
20245
- if (node.ref.sourceId === sourceId && !hostProvidedLocalFileSource) {
20246
- return {
20247
- path: hostLocalFileActionPath,
20248
- kind: "file",
20249
- displayName: actionNode.displayName
20250
- };
20251
- }
20252
- return referenceSourceAggregator.resolveSelection(node);
20253
- },
20254
- async locateTarget(scope, currentSourceId, params) {
20255
- if (currentSourceId === sourceId && !hostProvidedLocalFileSource) {
20256
- return null;
20257
- }
20258
- return await referenceSourceAggregator.locateTarget(
20259
- scope,
20260
- currentSourceId,
20261
- params
20262
- );
20263
- },
20264
- getLoadedSource(currentSourceId) {
20265
- if (currentSourceId === sourceId && !hostProvidedLocalFileSource) {
20266
- return void 0;
20267
- }
20268
- return referenceSourceAggregator.getLoadedSource(currentSourceId);
20269
- }
20270
- };
20271
- }, [
20272
- hostLocalFileLabel,
20273
- hostLocalFileSelectLabel,
20274
- hostLocalFileSourceId,
20275
- referenceSourceAggregator
20276
- ]);
20277
20117
  const isWorkspaceReferencePickerNodeSelectable = useCallback10(
20278
20118
  (node) => node.ref.sourceId !== hostLocalFileSourceId || node.kind === "file",
20279
20119
  [hostLocalFileSourceId]
@@ -20283,10 +20123,10 @@ function AgentGUINodeView({
20283
20123
  if (previewMode) {
20284
20124
  return emptyReferencePickResult;
20285
20125
  }
20286
- if (!workspaceFileReferenceAdapter && !referenceSourceAggregatorWithHostLocalFile || !workspaceFileReferenceCopy) {
20126
+ if (!workspaceFileReferenceAdapter && !referenceSourceAggregator || !workspaceFileReferenceCopy) {
20287
20127
  return emptyReferencePickResult;
20288
20128
  }
20289
- const target = entity && referenceSourceAggregatorWithHostLocalFile ? resolveMentionReferenceTarget?.(entity) ?? null : referenceSourceAggregatorWithHostLocalFile ? resolveWorkspaceReferenceInitialTarget?.({
20129
+ const target = entity && referenceSourceAggregator ? resolveMentionReferenceTarget?.(entity) ?? null : referenceSourceAggregator ? resolveWorkspaceReferenceInitialTarget?.({
20290
20130
  activeConversation: viewModel.activeConversation,
20291
20131
  composerSelectedProjectPath: viewModel.composerSettings.selectedProjectPath ?? null,
20292
20132
  userProjects: viewModel.userProjects
@@ -20300,7 +20140,7 @@ function AgentGUINodeView({
20300
20140
  [
20301
20141
  emptyReferencePickResult,
20302
20142
  previewMode,
20303
- referenceSourceAggregatorWithHostLocalFile,
20143
+ referenceSourceAggregator,
20304
20144
  resolveMentionReferenceTarget,
20305
20145
  resolveWorkspaceReferenceInitialTarget,
20306
20146
  viewModel.activeConversation,
@@ -20329,71 +20169,16 @@ function AgentGUINodeView({
20329
20169
  [onWorkspaceFileReferencesAdded]
20330
20170
  );
20331
20171
  const confirmWorkspaceReferencePicker = useCallback10(
20332
- async (refs) => {
20333
- const wantsHostFiles = refs.some(
20334
- (ref) => ref.path === hostLocalFileActionPath
20335
- );
20336
- const hostSourceRefs = refs.filter(
20337
- (ref) => ref.sourceId === hostLocalFileSourceId && ref.path !== hostLocalFileActionPath
20338
- );
20339
- const hostSourceFileRefs = hostSourceRefs.filter(
20340
- (ref) => ref.kind === "file"
20341
- );
20342
- if (!wantsHostFiles && hostSourceRefs.length === 0) {
20343
- settleReferencePicker(
20344
- { files: refs, mentionItems: [], hostAttachments: [] },
20345
- refs
20346
- );
20347
- return;
20348
- }
20349
- const workspaceRefs = refs.filter(
20350
- (ref) => ref.path !== hostLocalFileActionPath && ref.sourceId !== hostLocalFileSourceId
20351
- );
20352
- const selected = wantsHostFiles ? await agentHostApi.workspace.selectFiles({
20353
- allowDirectories: false
20354
- }) : [];
20355
- const selectedHostAttachments = selected.map((file) => ({
20356
- hostPath: file.path,
20357
- name: file.name || file.path.split("/").pop() || file.path,
20358
- mimeType: null
20359
- }));
20360
- const browsedHostAttachments = hostSourceFileRefs.map((file) => ({
20361
- hostPath: file.path,
20362
- name: file.displayName || file.path.split("/").pop() || file.path,
20363
- mimeType: null
20364
- }));
20365
- settleReferencePicker(
20366
- {
20367
- files: workspaceRefs,
20368
- mentionItems: [],
20369
- hostAttachments: [
20370
- ...selectedHostAttachments,
20371
- ...browsedHostAttachments
20372
- ]
20373
- },
20374
- workspaceRefs
20375
- );
20172
+ (refs) => {
20173
+ settleReferencePicker({ files: refs, mentionItems: [] }, refs);
20376
20174
  },
20377
- [
20378
- agentHostApi.workspace,
20379
- hostLocalFileActionPath,
20380
- hostLocalFileSourceId,
20381
- settleReferencePicker
20382
- ]
20175
+ [settleReferencePicker]
20383
20176
  );
20384
20177
  const confirmWorkspaceReferenceBundles = useCallback10(
20385
20178
  (result) => {
20386
- const hostSourceRefs = result.files.filter(
20387
- (ref) => ref.sourceId === hostLocalFileSourceId && ref.kind === "file"
20388
- );
20389
20179
  const workspaceRefs = result.files.filter(
20390
20180
  (ref) => ref.sourceId !== hostLocalFileSourceId
20391
20181
  );
20392
- const hostAttachments = hostSourceRefs.map((file) => ({
20393
- hostPath: file.path,
20394
- name: file.displayName || file.path.split("/").pop() || file.path,
20395
- mimeType: null
20396
- }));
20397
20182
  const mentionItems = result.bundles.filter((bundle) => bundle.handle != null).map((bundle) => {
20398
20183
  const handle = bundle.handle;
20399
20184
  const bundleIconUrl = bundle.iconUrl ?? void 0;
@@ -20421,7 +20206,7 @@ function AgentGUINodeView({
20421
20206
  };
20422
20207
  });
20423
20208
  settleReferencePicker(
20424
- { files: workspaceRefs, mentionItems, hostAttachments },
20209
+ { files: result.files, mentionItems },
20425
20210
  workspaceRefs
20426
20211
  );
20427
20212
  },
@@ -20767,10 +20552,10 @@ function AgentGUINodeView({
20767
20552
  ]
20768
20553
  }
20769
20554
  ),
20770
- referenceSourceAggregatorWithHostLocalFile ? /* @__PURE__ */ jsx29(
20555
+ referenceSourceAggregator ? /* @__PURE__ */ jsx29(
20771
20556
  ReferenceSourcePicker,
20772
20557
  {
20773
- aggregator: referenceSourceAggregatorWithHostLocalFile,
20558
+ aggregator: referenceSourceAggregator,
20774
20559
  copy: workspaceFileReferenceCopy ?? fallbackWorkspaceFileReferenceCopy,
20775
20560
  initialTarget: workspaceReferencePickerTarget,
20776
20561
  isNodeSelectable: isWorkspaceReferencePickerNodeSelectable,