Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
76 lines
2.2 KiB
TypeScript
76 lines
2.2 KiB
TypeScript
import type { JSONContent } from "@tiptap/core";
|
|
import type { WorkspaceFileReference } from "@tutti-os/workspace-file-reference/contracts";
|
|
import {
|
|
mentionItemToAttrs,
|
|
type AgentContextMentionItem
|
|
} from "./agentFileMentionExtension";
|
|
import {
|
|
basenameFromPath,
|
|
dirnameFromPath,
|
|
hasPathTrailingSeparator
|
|
} from "./agentMentionMarkdown";
|
|
import { AGENT_RICH_TEXT_CARET_ANCHOR } from "./agentRichTextCaretAnchor";
|
|
|
|
function referenceMentionPath(item: WorkspaceFileReference): string {
|
|
const path = item.path.trim();
|
|
if (
|
|
item.kind === "folder" &&
|
|
path &&
|
|
path !== "/" &&
|
|
!hasPathTrailingSeparator(path)
|
|
) {
|
|
return `${path}/`;
|
|
}
|
|
return path;
|
|
}
|
|
|
|
/**
|
|
* 把任意 mention item(file / workspace-reference / …)建成可插入的节点内容。
|
|
* 每个 item 走 mentionItemToAttrs 归一为节点 attrs;item 之间补空格。
|
|
*/
|
|
export function createAgentMentionContent(
|
|
items: readonly AgentContextMentionItem[],
|
|
options: { prefixCaretAnchor?: boolean } = {}
|
|
): JSONContent[] {
|
|
return items.flatMap((item, index) => [
|
|
...(index === 0 && options.prefixCaretAnchor
|
|
? ([
|
|
{ type: "text", text: AGENT_RICH_TEXT_CARET_ANCHOR }
|
|
] as JSONContent[])
|
|
: index > 0
|
|
? ([{ type: "text", text: " " }] as JSONContent[])
|
|
: []),
|
|
{ type: "agentFileMention", attrs: mentionItemToAttrs(item) },
|
|
{ type: "text", text: " " }
|
|
]);
|
|
}
|
|
|
|
export function createAgentFileMentionContent(
|
|
items: readonly WorkspaceFileReference[],
|
|
options: { prefixCaretAnchor?: boolean } = {}
|
|
): JSONContent[] {
|
|
return items.flatMap((item, index) => {
|
|
const path = referenceMentionPath(item);
|
|
const name = item.displayName?.trim() || basenameFromPath(path);
|
|
return [
|
|
...(index === 0 && options.prefixCaretAnchor
|
|
? ([
|
|
{ type: "text", text: AGENT_RICH_TEXT_CARET_ANCHOR }
|
|
] as JSONContent[])
|
|
: []),
|
|
{
|
|
type: "agentFileMention",
|
|
attrs: {
|
|
kind: "file",
|
|
href: path,
|
|
path,
|
|
name,
|
|
entryKind: item.kind === "folder" ? "directory" : "file",
|
|
directoryPath: dirnameFromPath(path) || (path ? "/" : "")
|
|
}
|
|
},
|
|
{ type: "text", text: " " }
|
|
];
|
|
});
|
|
}
|