forked from EduCraft/curriculum-project-hub
fix(hub): send Feishu files explicitly
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import { createSdkMcpServer, tool, type McpSdkServerConfigWithInstance } from "@anthropic-ai/claude-agent-sdk";
|
||||
import { z } from "zod";
|
||||
import { sendFile, type FeishuRuntime } from "./client.js";
|
||||
import { resolveDeliverableFile } from "./fileDelivery.js";
|
||||
|
||||
export interface FileDeliveryToolOptions {
|
||||
readonly rt: FeishuRuntime;
|
||||
readonly chatId: string;
|
||||
readonly workspaceDir: string;
|
||||
readonly onDelivered?: (path: string) => void;
|
||||
}
|
||||
|
||||
export function createFileDeliveryMcpServer(options: FileDeliveryToolOptions): McpSdkServerConfigWithInstance {
|
||||
return createSdkMcpServer({
|
||||
name: "cph_hub",
|
||||
version: "0.0.0",
|
||||
alwaysLoad: true,
|
||||
instructions:
|
||||
"Use send_file when the user asks to receive, resend, download, or attach a file. " +
|
||||
"Do not claim a file was sent unless send_file returns success. " +
|
||||
"If a generated file path is uncertain, list or inspect the workspace first, then call send_file with the actual path.",
|
||||
tools: [
|
||||
tool(
|
||||
"send_file",
|
||||
"Upload an existing project/repository file to the current Feishu chat. The path must point to a concrete file, for example build/student.pdf or README.md.",
|
||||
{
|
||||
path: z.string().describe("Workspace-relative, repository-relative, or absolute path to the existing file."),
|
||||
name: z.string().optional().describe("Optional display filename. Defaults to the file's basename."),
|
||||
},
|
||||
async (args) => {
|
||||
const file = await resolveDeliverableFile(args.path, options.workspaceDir);
|
||||
if (file === null) {
|
||||
return {
|
||||
isError: true,
|
||||
content: [{ type: "text", text: `File not found or not deliverable: ${args.path}` }],
|
||||
};
|
||||
}
|
||||
|
||||
const messageId = await sendFile(options.rt, options.chatId, file.path, args.name ?? file.name);
|
||||
if (messageId === null) {
|
||||
return {
|
||||
isError: true,
|
||||
content: [{ type: "text", text: `Failed to send file: ${file.path}` }],
|
||||
};
|
||||
}
|
||||
|
||||
options.onDelivered?.(file.path);
|
||||
return {
|
||||
content: [{ type: "text", text: `Sent file: ${file.path}` }],
|
||||
};
|
||||
},
|
||||
{ alwaysLoad: true },
|
||||
),
|
||||
],
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user