feat(ai): add @oh-my-pi/pi-ai package with tool name prefixing

- Port pi-ai from upstream with Bun-first approach (source files, no dist)
- Add cli_ prefix to tool names in OAuth mode to avoid collisions
- Improve beta header handling with proper deduplication
- Convert codex-instructions.md to Bun text embed
- Strip .js extensions from all imports
This commit is contained in:
can1357
2026-01-09 12:10:03 +01:00
parent d934594aed
commit 5a63120dd3
138 changed files with 25016 additions and 474 deletions
@@ -48,7 +48,7 @@ See [docs/custom-tools.md](../../docs/custom-tools.md) for full documentation.
```typescript
import { Type } from "@sinclair/typebox";
import { StringEnum } from "@mariozechner/pi-ai";
import { StringEnum } from "@oh-my-pi/pi-ai";
import { Text } from "@oh-my-pi/pi-tui";
import type { CustomToolFactory } from "@oh-my-pi/pi-coding-agent";
@@ -99,7 +99,7 @@ renderResult(result, { expanded, isPartial }, theme) {
**Use StringEnum for string parameters** (required for Google API compatibility):
```typescript
import { StringEnum } from "@mariozechner/pi-ai";
import { StringEnum } from "@oh-my-pi/pi-ai";
// Good
action: StringEnum(["list", "add"] as const);
@@ -113,7 +113,7 @@ export default function (pi: ExtensionAPI) {
**Use StringEnum for string parameters** (required for Google API compatibility):
```typescript
import { StringEnum } from "@mariozechner/pi-ai";
import { StringEnum } from "@oh-my-pi/pi-ai";
// Good
action: StringEnum(["list", "add"] as const);
@@ -10,7 +10,7 @@
* correct for that point in history.
*/
import { StringEnum } from "@mariozechner/pi-ai";
import { StringEnum } from "@oh-my-pi/pi-ai";
import type { ExtensionAPI, ExtensionContext, Theme } from "@oh-my-pi/pi-coding-agent";
import { matchesKey, Text, truncateToWidth } from "@oh-my-pi/pi-tui";
import { Type } from "@sinclair/typebox";
@@ -263,7 +263,7 @@ export default function (pi: ExtensionAPI) {
return new Text(
`${theme.fg("success", "✓ Added ") + theme.fg("accent", `#${added.id}`)} ${theme.fg("muted", added.text)}`,
0,
0,
0
);
}
@@ -13,7 +13,7 @@
* omp --hook examples/hooks/custom-compaction.ts
*/
import { complete, getModel } from "@mariozechner/pi-ai";
import { complete, getModel } from "@oh-my-pi/pi-ai";
import type { HookAPI } from "@oh-my-pi/pi-coding-agent";
import { convertToLlm, serializeConversation } from "@oh-my-pi/pi-coding-agent";
@@ -42,8 +42,10 @@ export default function (pi: HookAPI) {
const allMessages = [...messagesToSummarize, ...turnPrefixMessages];
ctx.ui.notify(
`Custom compaction: summarizing ${allMessages.length} messages (${tokensBefore.toLocaleString()} tokens) with ${model.id}...`,
"info",
`Custom compaction: summarizing ${allMessages.length} messages (${tokensBefore.toLocaleString()} tokens) with ${
model.id
}...`,
"info"
);
// Convert messages to readable text format
@@ -12,7 +12,7 @@
* The generated prompt appears as a draft in the editor for review/editing.
*/
import { complete, type Message } from "@mariozechner/pi-ai";
import { complete, type Message } from "@oh-my-pi/pi-ai";
import type { HookAPI, SessionEntry } from "@oh-my-pi/pi-coding-agent";
import { BorderedLoader, convertToLlm, serializeConversation } from "@oh-my-pi/pi-coding-agent";
@@ -96,7 +96,7 @@ export default function (pi: HookAPI) {
const response = await complete(
ctx.model!,
{ systemPrompt: SYSTEM_PROMPT, messages: [userMessage] },
{ apiKey, signal: loader.signal },
{ apiKey, signal: loader.signal }
);
if (response.stopReason === "aborted") {
+2 -2
View File
@@ -7,7 +7,7 @@
* 3. Loads the result into the editor for user to fill in answers
*/
import { complete, type UserMessage } from "@mariozechner/pi-ai";
import { complete, type UserMessage } from "@oh-my-pi/pi-ai";
import type { HookAPI } from "@oh-my-pi/pi-coding-agent";
import { BorderedLoader } from "@oh-my-pi/pi-coding-agent";
@@ -87,7 +87,7 @@ export default function (pi: HookAPI) {
const response = await complete(
ctx.model!,
{ systemPrompt: SYSTEM_PROMPT, messages: [userMessage] },
{ apiKey, signal: loader.signal },
{ apiKey, signal: loader.signal }
);
if (response.stopReason === "aborted") {
@@ -4,7 +4,7 @@
* Shows how to select a specific model and thinking level.
*/
import { getModel } from "@mariozechner/pi-ai";
import { getModel } from "@oh-my-pi/pi-ai";
import { createAgentSession, discoverAuthStorage, discoverModels } from "@oh-my-pi/pi-coding-agent";
// Set up auth storage and model registry
@@ -27,7 +27,7 @@ if (customModel) {
const available = modelRegistry.getAvailable();
console.log(
"Available models:",
available.map((m) => `${m.provider}/${m.id}`),
available.map((m) => `${m.provider}/${m.id}`)
);
if (available.length > 0) {
+1 -1
View File
@@ -29,7 +29,7 @@ npx tsx examples/sdk/01-minimal.ts
## Quick Reference
```typescript
import { getModel } from "@mariozechner/pi-ai";
import { getModel } from "@oh-my-pi/pi-ai";
import {
AuthStorage,
createAgentSession,