Fix NodeJS compat

This commit is contained in:
Mario Zechner 2025-09-16 02:19:47 +02:00
parent e2d23a5abb
commit 197259c88a
19 changed files with 110 additions and 99 deletions

12
package-lock.json generated
View file

@ -2813,10 +2813,10 @@
}, },
"packages/agent": { "packages/agent": {
"name": "@mariozechner/pi-agent", "name": "@mariozechner/pi-agent",
"version": "0.5.34", "version": "0.5.39",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@mariozechner/pi-tui": "^0.5.34", "@mariozechner/pi-tui": "^0.5.38",
"@types/glob": "^8.1.0", "@types/glob": "^8.1.0",
"chalk": "^5.5.0", "chalk": "^5.5.0",
"glob": "^11.0.3", "glob": "^11.0.3",
@ -3195,7 +3195,7 @@
}, },
"packages/ai": { "packages/ai": {
"name": "@mariozechner/pi-ai", "name": "@mariozechner/pi-ai",
"version": "0.5.36", "version": "0.5.39",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@anthropic-ai/sdk": "^0.61.0", "@anthropic-ai/sdk": "^0.61.0",
@ -3235,10 +3235,10 @@
}, },
"packages/pods": { "packages/pods": {
"name": "@mariozechner/pi", "name": "@mariozechner/pi",
"version": "0.5.34", "version": "0.5.39",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@mariozechner/pi-agent": "^0.5.34", "@mariozechner/pi-agent": "^0.5.38",
"chalk": "^5.5.0" "chalk": "^5.5.0"
}, },
"bin": { "bin": {
@ -3251,7 +3251,7 @@
}, },
"packages/tui": { "packages/tui": {
"name": "@mariozechner/pi-tui", "name": "@mariozechner/pi-tui",
"version": "0.5.34", "version": "0.5.39",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@types/mime-types": "^2.1.4", "@types/mime-types": "^2.1.4",

View file

@ -1,12 +1,12 @@
{ {
"name": "@mariozechner/pi-agent", "name": "@mariozechner/pi-agent",
"version": "0.5.34", "version": "0.5.39",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@mariozechner/pi-agent", "name": "@mariozechner/pi-agent",
"version": "0.5.34", "version": "0.5.39",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@mariozechner/tui": "^0.1.1", "@mariozechner/tui": "^0.1.1",

View file

@ -1,6 +1,6 @@
{ {
"name": "@mariozechner/pi-agent", "name": "@mariozechner/pi-agent",
"version": "0.5.34", "version": "0.5.39",
"description": "General-purpose agent with tool calling and session persistence", "description": "General-purpose agent with tool calling and session persistence",
"type": "module", "type": "module",
"bin": { "bin": {
@ -18,7 +18,7 @@
"prepublishOnly": "npm run clean && npm run build" "prepublishOnly": "npm run clean && npm run build"
}, },
"dependencies": { "dependencies": {
"@mariozechner/pi-tui": "^0.5.34", "@mariozechner/pi-tui": "^0.5.39",
"@types/glob": "^8.1.0", "@types/glob": "^8.1.0",
"chalk": "^5.5.0", "chalk": "^5.5.0",
"glob": "^11.0.3", "glob": "^11.0.3",

View file

@ -1,6 +1,6 @@
{ {
"name": "@mariozechner/pi-ai", "name": "@mariozechner/pi-ai",
"version": "0.5.36", "version": "0.5.39",
"description": "Unified LLM API with automatic model discovery and provider configuration", "description": "Unified LLM API with automatic model discovery and provider configuration",
"type": "module", "type": "module",
"main": "./dist/index.js", "main": "./dist/index.js",

View file

@ -1,8 +1,8 @@
import { EventStream } from "../event-stream"; import { EventStream } from "../event-stream.js";
import { streamSimple } from "../stream.js"; import { streamSimple } from "../stream.js";
import type { AssistantMessage, Context, Message, ToolResultMessage, UserMessage } from "../types.js"; import type { AssistantMessage, Context, Message, ToolResultMessage, UserMessage } from "../types.js";
import { validateToolArguments } from "../validation.js"; import { validateToolArguments } from "../validation.js";
import type { AgentContext, AgentEvent, AgentTool, AgentToolResult, PromptConfig } from "./types"; import type { AgentContext, AgentEvent, AgentTool, AgentToolResult, PromptConfig } from "./types.js";
// Main prompt function - returns a stream of events // Main prompt function - returns a stream of events
export function prompt( export function prompt(
@ -13,8 +13,8 @@ export function prompt(
streamFn?: typeof streamSimple, streamFn?: typeof streamSimple,
): EventStream<AgentEvent, AgentContext["messages"]> { ): EventStream<AgentEvent, AgentContext["messages"]> {
const stream = new EventStream<AgentEvent, AgentContext["messages"]>( const stream = new EventStream<AgentEvent, AgentContext["messages"]>(
(event) => event.type === "agent_end", (event: AgentEvent) => event.type === "agent_end",
(event) => (event.type === "agent_end" ? event.messages : []), (event: AgentEvent) => (event.type === "agent_end" ? event.messages : []),
); );
// Run the prompt async // Run the prompt async

View file

@ -1,3 +1,3 @@
export { prompt } from "./agent"; export { prompt } from "./agent.js";
export * from "./tools"; export * from "./tools/index.js";
export type { AgentContext, AgentEvent, AgentTool, PromptConfig } from "./types"; export type { AgentContext, AgentEvent, AgentTool, PromptConfig } from "./types.js";

View file

@ -1,5 +1,5 @@
import { type Static, Type } from "@sinclair/typebox"; import { type Static, Type } from "@sinclair/typebox";
import type { AgentTool } from "../../agent"; import type { AgentTool } from "../../agent/types.js";
export interface CalculateResult { export interface CalculateResult {
output: string; output: string;
@ -26,7 +26,7 @@ export const calculateTool: AgentTool<typeof calculateSchema, undefined> = {
name: "calculate", name: "calculate",
description: "Evaluate mathematical expressions", description: "Evaluate mathematical expressions",
parameters: calculateSchema, parameters: calculateSchema,
execute: async (_toolCallId, args) => { execute: async (_toolCallId: string, args: CalculateParams) => {
return calculate(args.expression); return calculate(args.expression);
}, },
}; };

View file

@ -1,6 +1,6 @@
import { type Static, Type } from "@sinclair/typebox"; import { type Static, Type } from "@sinclair/typebox";
import type { AgentTool } from "../../agent"; import type { AgentTool } from "../../agent/index.js";
import type { AgentToolResult } from "../types"; import type { AgentToolResult } from "../types.js";
export interface GetCurrentTimeResult extends AgentToolResult<{ utcTimestamp: number }> {} export interface GetCurrentTimeResult extends AgentToolResult<{ utcTimestamp: number }> {}
@ -39,7 +39,7 @@ export const getCurrentTimeTool: AgentTool<typeof getCurrentTimeSchema, { utcTim
name: "get_current_time", name: "get_current_time",
description: "Get the current date and time", description: "Get the current date and time",
parameters: getCurrentTimeSchema, parameters: getCurrentTimeSchema,
execute: async (_toolCallId, args) => { execute: async (_toolCallId: string, args: GetCurrentTimeParams) => {
return getCurrentTime(args.timezone); return getCurrentTime(args.timezone);
}, },
}; };

View file

@ -1,2 +1,2 @@
export { calculate, calculateTool } from "./calculate"; export { calculate, calculateTool } from "./calculate.js";
export { getCurrentTime, getCurrentTimeTool } from "./get-current-time"; export { getCurrentTime, getCurrentTimeTool } from "./get-current-time.js";

View file

@ -1,4 +1,4 @@
import type { AssistantMessage, AssistantMessageEvent } from "./types"; import type { AssistantMessage, AssistantMessageEvent } from "./types.js";
// Generic event stream class for async iteration // Generic event stream class for async iteration
export class EventStream<T, R = T> implements AsyncIterable<T> { export class EventStream<T, R = T> implements AsyncIterable<T> {

View file

@ -3079,6 +3079,23 @@ export const MODELS = {
contextWindow: 131072, contextWindow: 131072,
maxTokens: 128000, maxTokens: 128000,
} satisfies Model<"openai-completions">, } satisfies Model<"openai-completions">,
"mistralai/mistral-7b-instruct-v0.3": {
id: "mistralai/mistral-7b-instruct-v0.3",
name: "Mistral: Mistral 7B Instruct v0.3",
api: "openai-completions",
provider: "openrouter",
baseUrl: "https://openrouter.ai/api/v1",
reasoning: false,
input: ["text"],
cost: {
input: 0.028,
output: 0.054,
cacheRead: 0,
cacheWrite: 0,
},
contextWindow: 32768,
maxTokens: 16384,
} satisfies Model<"openai-completions">,
"mistralai/mistral-7b-instruct:free": { "mistralai/mistral-7b-instruct:free": {
id: "mistralai/mistral-7b-instruct:free", id: "mistralai/mistral-7b-instruct:free",
name: "Mistral: Mistral 7B Instruct (free)", name: "Mistral: Mistral 7B Instruct (free)",
@ -3113,23 +3130,6 @@ export const MODELS = {
contextWindow: 32768, contextWindow: 32768,
maxTokens: 16384, maxTokens: 16384,
} satisfies Model<"openai-completions">, } satisfies Model<"openai-completions">,
"mistralai/mistral-7b-instruct-v0.3": {
id: "mistralai/mistral-7b-instruct-v0.3",
name: "Mistral: Mistral 7B Instruct v0.3",
api: "openai-completions",
provider: "openrouter",
baseUrl: "https://openrouter.ai/api/v1",
reasoning: false,
input: ["text"],
cost: {
input: 0.028,
output: 0.054,
cacheRead: 0,
cacheWrite: 0,
},
contextWindow: 32768,
maxTokens: 16384,
} satisfies Model<"openai-completions">,
"microsoft/phi-3-mini-128k-instruct": { "microsoft/phi-3-mini-128k-instruct": {
id: "microsoft/phi-3-mini-128k-instruct", id: "microsoft/phi-3-mini-128k-instruct",
name: "Microsoft: Phi-3 Mini 128K Instruct", name: "Microsoft: Phi-3 Mini 128K Instruct",
@ -3164,23 +3164,6 @@ export const MODELS = {
contextWindow: 128000, contextWindow: 128000,
maxTokens: 4096, maxTokens: 4096,
} satisfies Model<"openai-completions">, } satisfies Model<"openai-completions">,
"meta-llama/llama-3-8b-instruct": {
id: "meta-llama/llama-3-8b-instruct",
name: "Meta: Llama 3 8B Instruct",
api: "openai-completions",
provider: "openrouter",
baseUrl: "https://openrouter.ai/api/v1",
reasoning: false,
input: ["text"],
cost: {
input: 0.03,
output: 0.06,
cacheRead: 0,
cacheWrite: 0,
},
contextWindow: 8192,
maxTokens: 16384,
} satisfies Model<"openai-completions">,
"meta-llama/llama-3-70b-instruct": { "meta-llama/llama-3-70b-instruct": {
id: "meta-llama/llama-3-70b-instruct", id: "meta-llama/llama-3-70b-instruct",
name: "Meta: Llama 3 70B Instruct", name: "Meta: Llama 3 70B Instruct",
@ -3198,6 +3181,23 @@ export const MODELS = {
contextWindow: 8192, contextWindow: 8192,
maxTokens: 16384, maxTokens: 16384,
} satisfies Model<"openai-completions">, } satisfies Model<"openai-completions">,
"meta-llama/llama-3-8b-instruct": {
id: "meta-llama/llama-3-8b-instruct",
name: "Meta: Llama 3 8B Instruct",
api: "openai-completions",
provider: "openrouter",
baseUrl: "https://openrouter.ai/api/v1",
reasoning: false,
input: ["text"],
cost: {
input: 0.03,
output: 0.06,
cacheRead: 0,
cacheWrite: 0,
},
contextWindow: 8192,
maxTokens: 16384,
} satisfies Model<"openai-completions">,
"mistralai/mixtral-8x22b-instruct": { "mistralai/mixtral-8x22b-instruct": {
id: "mistralai/mixtral-8x22b-instruct", id: "mistralai/mixtral-8x22b-instruct",
name: "Mistral: Mixtral 8x22B Instruct", name: "Mistral: Mixtral 8x22B Instruct",
@ -3300,23 +3300,6 @@ export const MODELS = {
contextWindow: 128000, contextWindow: 128000,
maxTokens: 4096, maxTokens: 4096,
} satisfies Model<"openai-completions">, } satisfies Model<"openai-completions">,
"mistralai/mistral-small": {
id: "mistralai/mistral-small",
name: "Mistral Small",
api: "openai-completions",
provider: "openrouter",
baseUrl: "https://openrouter.ai/api/v1",
reasoning: false,
input: ["text"],
cost: {
input: 0.19999999999999998,
output: 0.6,
cacheRead: 0,
cacheWrite: 0,
},
contextWindow: 32768,
maxTokens: 4096,
} satisfies Model<"openai-completions">,
"mistralai/mistral-tiny": { "mistralai/mistral-tiny": {
id: "mistralai/mistral-tiny", id: "mistralai/mistral-tiny",
name: "Mistral Tiny", name: "Mistral Tiny",
@ -3334,6 +3317,23 @@ export const MODELS = {
contextWindow: 32768, contextWindow: 32768,
maxTokens: 4096, maxTokens: 4096,
} satisfies Model<"openai-completions">, } satisfies Model<"openai-completions">,
"mistralai/mistral-small": {
id: "mistralai/mistral-small",
name: "Mistral Small",
api: "openai-completions",
provider: "openrouter",
baseUrl: "https://openrouter.ai/api/v1",
reasoning: false,
input: ["text"],
cost: {
input: 0.19999999999999998,
output: 0.6,
cacheRead: 0,
cacheWrite: 0,
},
contextWindow: 32768,
maxTokens: 4096,
} satisfies Model<"openai-completions">,
"mistralai/mixtral-8x7b-instruct": { "mistralai/mixtral-8x7b-instruct": {
id: "mistralai/mixtral-8x7b-instruct", id: "mistralai/mixtral-8x7b-instruct",
name: "Mistral: Mixtral 8x7B Instruct", name: "Mistral: Mixtral 8x7B Instruct",

View file

@ -1,10 +1,10 @@
import type { AssistantMessageEventStream } from "./event-stream"; import type { AssistantMessageEventStream } from "./event-stream.js";
import type { AnthropicOptions } from "./providers/anthropic"; import type { AnthropicOptions } from "./providers/anthropic.js";
import type { GoogleOptions } from "./providers/google"; import type { GoogleOptions } from "./providers/google.js";
import type { OpenAICompletionsOptions } from "./providers/openai-completions"; import type { OpenAICompletionsOptions } from "./providers/openai-completions.js";
import type { OpenAIResponsesOptions } from "./providers/openai-responses"; import type { OpenAIResponsesOptions } from "./providers/openai-responses.js";
export type { AssistantMessageEventStream } from "./event-stream"; export type { AssistantMessageEventStream } from "./event-stream.js";
export type Api = "openai-completions" | "openai-responses" | "anthropic-messages" | "google-generative-ai"; export type Api = "openai-completions" | "openai-responses" | "anthropic-messages" | "google-generative-ai";

View file

@ -1,5 +1,10 @@
import Ajv from "ajv"; import AjvModule from "ajv";
import addFormats from "ajv-formats"; import addFormatsModule from "ajv-formats";
// Handle both default and named exports
const Ajv = (AjvModule as any).default || AjvModule;
const addFormats = (addFormatsModule as any).default || addFormatsModule;
import type { Tool, ToolCall } from "./types.js"; import type { Tool, ToolCall } from "./types.js";
// Create a singleton AJV instance with formats // Create a singleton AJV instance with formats
@ -25,7 +30,7 @@ export function validateToolArguments(tool: Tool, toolCall: ToolCall): any {
// Format validation errors nicely // Format validation errors nicely
const errors = const errors =
validate.errors validate.errors
?.map((err) => { ?.map((err: any) => {
const path = err.instancePath ? err.instancePath.substring(1) : err.params.missingProperty || "root"; const path = err.instancePath ? err.instancePath.substring(1) : err.params.missingProperty || "root";
return ` - ${path}: ${err.message}`; return ` - ${path}: ${err.message}`;
}) })

View file

@ -1,6 +1,11 @@
import { type Static, Type } from "@sinclair/typebox"; import { type Static, Type } from "@sinclair/typebox";
import Ajv from "ajv"; import AjvModule from "ajv";
import addFormats from "ajv-formats"; import addFormatsModule from "ajv-formats";
// Handle both default and named exports
const Ajv = (AjvModule as any).default || AjvModule;
const addFormats = (addFormatsModule as any).default || addFormatsModule;
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "vitest";
import type { AgentTool } from "../src/agent/types.js"; import type { AgentTool } from "../src/agent/types.js";
@ -98,7 +103,7 @@ describe("Tool Validation with TypeBox and AJV", () => {
if (validate.errors) { if (validate.errors) {
const errors = validate.errors const errors = validate.errors
.map((err) => { .map((err: any) => {
const path = err.instancePath ? err.instancePath.substring(1) : err.params.missingProperty || "root"; const path = err.instancePath ? err.instancePath.substring(1) : err.params.missingProperty || "root";
return ` - ${path}: ${err.message}`; return ` - ${path}: ${err.message}`;
}) })

View file

@ -1,12 +1,12 @@
{ {
"name": "@mariozechner/pi", "name": "@mariozechner/pi",
"version": "0.5.34", "version": "0.5.39",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@mariozechner/pi", "name": "@mariozechner/pi",
"version": "0.5.34", "version": "0.5.39",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@ai-sdk/openai": "^2.0.5", "@ai-sdk/openai": "^2.0.5",

View file

@ -1,6 +1,6 @@
{ {
"name": "@mariozechner/pi", "name": "@mariozechner/pi",
"version": "0.5.34", "version": "0.5.39",
"description": "CLI tool for managing vLLM deployments on GPU pods", "description": "CLI tool for managing vLLM deployments on GPU pods",
"type": "module", "type": "module",
"bin": { "bin": {
@ -34,7 +34,7 @@
"node": ">=20.0.0" "node": ">=20.0.0"
}, },
"dependencies": { "dependencies": {
"@mariozechner/pi-agent": "^0.5.34", "@mariozechner/pi-agent": "^0.5.39",
"chalk": "^5.5.0" "chalk": "^5.5.0"
}, },
"devDependencies": {} "devDependencies": {}

View file

@ -1,12 +1,12 @@
{ {
"name": "@mariozechner/tui", "name": "@mariozechner/tui",
"version": "0.5.34", "version": "0.5.39",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@mariozechner/tui", "name": "@mariozechner/tui",
"version": "0.5.34", "version": "0.5.39",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@types/mime-types": "^2.1.4", "@types/mime-types": "^2.1.4",

View file

@ -1,6 +1,6 @@
{ {
"name": "@mariozechner/pi-tui", "name": "@mariozechner/pi-tui",
"version": "0.5.34", "version": "0.5.39",
"description": "Terminal User Interface library with differential rendering for efficient text-based applications", "description": "Terminal User Interface library with differential rendering for efficient text-based applications",
"type": "module", "type": "module",
"main": "dist/index.js", "main": "dist/index.js",

View file

@ -1,7 +1,7 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "esnext", "target": "ES2022",
"module": "esnext", "module": "Node16",
"lib": ["ES2022"], "lib": ["ES2022"],
"strict": true, "strict": true,
"esModuleInterop": true, "esModuleInterop": true,
@ -12,8 +12,9 @@
"sourceMap": true, "sourceMap": true,
"inlineSources": true, "inlineSources": true,
"inlineSourceMap": false, "inlineSourceMap": false,
"moduleResolution": "bundler", "moduleResolution": "Node16",
"resolveJsonModule": true, "resolveJsonModule": true,
"allowImportingTsExtensions": false,
"types": ["node"] "types": ["node"]
} }
} }