mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-28 04:03:05 +00:00
* feat(plugins): attach tools to individual agent sessions * feat(plugins): reopen idle agent sessions after hook changes Defer automatic plugin changes until the next idle prompt so running turns keep steering. Expose session reload separately from snapshot refresh in the SDK. * docs(plugins): show how to attach tools to agents * test(agent): update permission follow-up adapter
40 lines
1004 B
TypeScript
40 lines
1004 B
TypeScript
import type { PaseoApi } from "@getpaseo/client";
|
|
import type { z } from "zod";
|
|
import type { PluginHookAgent } from "./lifecycle.js";
|
|
|
|
export interface AgentToolContext {
|
|
agent: PluginHookAgent;
|
|
paseo: PaseoApi;
|
|
signal: AbortSignal;
|
|
}
|
|
|
|
export interface AgentToolResult {
|
|
text?: string;
|
|
structuredContent?: unknown;
|
|
isError?: boolean;
|
|
}
|
|
|
|
export interface AgentToolDefinition {
|
|
name: string;
|
|
title?: string;
|
|
description: string;
|
|
input: z.ZodType;
|
|
execute(input: unknown, context: AgentToolContext): AgentToolResult | Promise<AgentToolResult>;
|
|
}
|
|
|
|
export function defineAgentTool<Input extends z.ZodType>(tool: {
|
|
name: string;
|
|
title?: string;
|
|
description: string;
|
|
input: Input;
|
|
execute(
|
|
input: z.output<Input>,
|
|
context: AgentToolContext,
|
|
): AgentToolResult | Promise<AgentToolResult>;
|
|
}): AgentToolDefinition {
|
|
if (!/^[a-z][a-z0-9_]*$/.test(tool.name) || tool.name.length > 64) {
|
|
throw new Error(`Invalid agent tool name: ${tool.name}`);
|
|
}
|
|
return tool;
|
|
}
|