mom: Slack bot with abort support, streaming console output, removed sandbox

This commit is contained in:
Mario Zechner 2025-11-26 00:27:21 +01:00
parent a7423b954e
commit aa9e058249
22 changed files with 2741 additions and 58 deletions

View 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,
};
},
};