mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-20 04:02:35 +00:00
mom: Slack bot with abort support, streaming console output, removed sandbox
This commit is contained in:
parent
a7423b954e
commit
aa9e058249
22 changed files with 2741 additions and 58 deletions
46
packages/mom/src/tools/attach.ts
Normal file
46
packages/mom/src/tools/attach.ts
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import type { AgentTool } from "@mariozechner/pi-ai";
|
||||
import { Type } from "@sinclair/typebox";
|
||||
import { basename, resolve as resolvePath } from "path";
|
||||
|
||||
// This will be set by the agent before running
|
||||
let uploadFn: ((filePath: string, title?: string) => Promise<void>) | null = null;
|
||||
|
||||
export function setUploadFunction(fn: (filePath: string, title?: string) => Promise<void>): void {
|
||||
uploadFn = fn;
|
||||
}
|
||||
|
||||
const attachSchema = Type.Object({
|
||||
label: Type.String({ description: "Brief description of what you're sharing (shown to user)" }),
|
||||
path: Type.String({ description: "Path to the file to attach" }),
|
||||
title: Type.Optional(Type.String({ description: "Title for the file (defaults to filename)" })),
|
||||
});
|
||||
|
||||
export const attachTool: AgentTool<typeof attachSchema> = {
|
||||
name: "attach",
|
||||
label: "attach",
|
||||
description: "Attach a file to your response. Use this to share files, images, or documents with the user.",
|
||||
parameters: attachSchema,
|
||||
execute: async (
|
||||
_toolCallId: string,
|
||||
{ path, title }: { label: string; path: string; title?: string },
|
||||
signal?: AbortSignal,
|
||||
) => {
|
||||
if (!uploadFn) {
|
||||
throw new Error("Upload function not configured");
|
||||
}
|
||||
|
||||
if (signal?.aborted) {
|
||||
throw new Error("Operation aborted");
|
||||
}
|
||||
|
||||
const absolutePath = resolvePath(path);
|
||||
const fileName = title || basename(absolutePath);
|
||||
|
||||
await uploadFn(absolutePath, fileName);
|
||||
|
||||
return {
|
||||
content: [{ type: "text" as const, text: `Attached file: ${fileName}` }],
|
||||
details: undefined,
|
||||
};
|
||||
},
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue