bc39ffa265
- Introduce `@oh-my-pi/omptype` as a new ArkType-compatible schema validation package featuring a lazy JIT runtime, JSON Schema emission, and compatibility adapters. - Replace `arktype` across workspace packages and test utilities with `@oh-my-pi/omptype`. - Add benchmark suites, tests, and documentation for the new validation engine and adapters. - Update workspace build, test runner, and release configurations to include the new package.
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import { type } from "@oh-my-pi/omptype";
|
|
import type { AgentTool, AgentToolResult } from "@oh-my-pi/pi-agent-core/types";
|
|
|
|
export interface CalculateResult extends AgentToolResult<undefined> {
|
|
content: Array<{ type: "text"; text: string }>;
|
|
details: undefined;
|
|
}
|
|
|
|
export function calculate(expression: string): CalculateResult {
|
|
try {
|
|
const result = new Function(`return ${expression}`)();
|
|
return { content: [{ type: "text", text: `${expression} = ${result}` }], details: undefined };
|
|
} catch (e: any) {
|
|
throw new Error(e.message || String(e));
|
|
}
|
|
}
|
|
|
|
const calculateSchema = type({
|
|
expression: "string = 'The mathematical expression to evaluate'",
|
|
});
|
|
|
|
type CalculateParams = typeof calculateSchema.infer;
|
|
|
|
export const calculateTool: AgentTool<typeof calculateSchema, undefined> = {
|
|
label: "Calculator",
|
|
name: "calculate",
|
|
description: "Evaluate mathematical expressions",
|
|
parameters: calculateSchema,
|
|
execute: async (_toolCallId: string, args: CalculateParams) => {
|
|
return calculate(args.expression);
|
|
},
|
|
};
|