Files
deer-flow/frontend/src/core/artifacts/loader.ts

46 lines
1.2 KiB
TypeScript
Raw Normal View History

2026-01-19 19:41:46 +08:00
import type { UseStream } from "@langchain/langgraph-sdk/react";
import type { AgentThreadState } from "../threads";
2026-01-17 15:09:44 +08:00
import { urlOfArtifact } from "./utils";
export async function loadArtifactContent({
filepath,
threadId,
}: {
filepath: string;
threadId: string;
}) {
2026-01-31 11:08:27 +08:00
let enhancedFilepath = filepath;
if (filepath.endsWith(".skill")) {
enhancedFilepath = filepath.replace(".md", ".skill/SKILL.md");
}
const url = urlOfArtifact({ filepath: enhancedFilepath, threadId });
2026-01-17 15:09:44 +08:00
const response = await fetch(url);
const text = await response.text();
return text;
}
2026-01-19 19:41:46 +08:00
export function loadArtifactContentFromToolCall({
url: urlString,
thread,
}: {
url: string;
thread: UseStream<AgentThreadState>;
}) {
const url = new URL(urlString);
const toolCallId = url.searchParams.get("tool_call_id");
const messageId = url.searchParams.get("message_id");
if (messageId && toolCallId) {
const message = thread.messages.find((message) => message.id === messageId);
if (message?.type === "ai" && message.tool_calls) {
const toolCall = message.tool_calls.find(
(toolCall) => toolCall.id === toolCallId,
);
if (toolCall) {
return toolCall.args.content;
}
}
}
}