-
Notifications
You must be signed in to change notification settings - Fork 3
fix: add streaming + v2 compat, tsup => bun build #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1.x
Are you sure you want to change the base?
Changes from all commits
053bc53
926bb47
4e1f62e
7c26aa5
7a9bc5b
18a0752
388f6b2
f6a675f
2e3634a
db5fdb3
7fd7803
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,44 @@ | ||
| # Dependencies | ||
| node_modules | ||
| .turbo | ||
|
|
||
| # Build outputs | ||
| dist | ||
| build | ||
| *.tsbuildinfo | ||
| .turbo | ||
| .turbo-tsconfig.json | ||
|
|
||
| # Environment files | ||
| .env | ||
| .eliza** | ||
| .env.local | ||
| .env.production | ||
| .env.bak | ||
|
|
||
| # IDE | ||
| .idea | ||
| .vscode | ||
| .zed | ||
| .DS_Store | ||
|
|
||
| # Test coverage | ||
| coverage | ||
| .nyc_output | ||
|
|
||
| # Logs | ||
| *.log | ||
| logs | ||
|
|
||
| # Cache | ||
| cache | ||
| .cache | ||
| tokencache | ||
|
|
||
| # Temporary files | ||
| *.tmp | ||
| *.temp | ||
| .tmp | ||
|
|
||
| # Bundler artifacts | ||
| tsup.config.bundled_*.mjs | ||
| # prr state file (auto-generated) | ||
| .pr-resolver-state.json |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # PRR Lessons Learned | ||
|
|
||
| > This file is auto-generated by [prr](https://github.com/elizaOS/prr). | ||
| > It contains lessons learned from PR review fixes to help improve future fix attempts. | ||
| > You can edit this file manually or let prr update it. | ||
| > To share lessons across your team, commit this file to your repo. | ||
|
|
||
| ## Global Lessons | ||
|
|
||
| - Fixer attempted disallowed file(s): __tests__/index.test.ts. Only edit the file(s) listed in TARGET FILE(S): src/index.ts, src/index.test.ts. | ||
|
|
||
| ## File-Specific Lessons | ||
|
|
||
| ### src/index.ts | ||
|
|
||
| - Fix for src/index.ts:208 - Need to add unit tests in test/ directory that verify textStream/textStreamDone event ordering and timeout behavior using mocked models |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #!/usr/bin/env bun | ||
| import { $ } from "bun"; | ||
|
|
||
| async function build() { | ||
| const totalStart = Date.now(); | ||
| const pkg = await Bun.file("package.json").json(); | ||
| const externalDeps = [ | ||
| ...Object.keys(pkg.dependencies ?? {}), | ||
| ...Object.keys(pkg.peerDependencies ?? {}), | ||
| ]; | ||
|
|
||
| // Use the clean script from package.json | ||
| if (pkg.scripts?.clean) { | ||
| console.log("🧹 Cleaning..."); | ||
| // Note: always runs clean to ensure a fresh build environment without stale artifacts | ||
| await $`bun run clean`.quiet(); | ||
| } | ||
|
|
||
| const esmStart = Date.now(); | ||
| console.log("🔨 Building @elizaos/plugin-ollama..."); | ||
| const esmResult = await Bun.build({ | ||
| entrypoints: ["src/index.ts"], | ||
| outdir: "dist", | ||
| target: "node", | ||
| format: "esm", | ||
| sourcemap: "external", | ||
| minify: false, | ||
| external: externalDeps, | ||
| }); | ||
| if (!esmResult.success) { | ||
| console.error(esmResult.logs); | ||
| throw new Error("ESM build failed"); | ||
| } | ||
| console.log(`✅ Build complete in ${((Date.now() - esmStart) / 1000).toFixed(2)}s`); | ||
|
|
||
| const dtsStart = Date.now(); | ||
| console.log("📝 Generating TypeScript declarations..."); | ||
| await $`tsc --project tsconfig.build.json`; | ||
| console.log(`✅ Declarations generated in ${((Date.now() - dtsStart) / 1000).toFixed(2)}s`); | ||
|
|
||
| console.log(`🎉 All builds finished in ${((Date.now() - totalStart) / 1000).toFixed(2)}s`); | ||
| } | ||
|
|
||
| build().catch((err) => { | ||
| console.error("Build failed:", err); | ||
| process.exit(1); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -23,22 +23,27 @@ | |||||
| ], | ||||||
| "dependencies": { | ||||||
| "@ai-sdk/ui-utils": "^1.2.8", | ||||||
| "@elizaos/core": "^1.0.0", | ||||||
| "@elizaos/core": "1.7.2", | ||||||
| "ai": "^4.3.9", | ||||||
| "js-tiktoken": "^1.0.18", | ||||||
| "ollama-ai-provider": "^1.2.0", | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Move the line to |
||||||
| "tsup": "8.4.0" | ||||||
| }, | ||||||
| "scripts": { | ||||||
| "build": "tsup", | ||||||
| "dev": "tsup --watch", | ||||||
| "build": "bun run build.ts", | ||||||
| "dev": "bun run build.ts", | ||||||
| "lint": "prettier --write ./src", | ||||||
| "clean": "rm -rf dist .turbo node_modules .turbo-tsconfig.json tsconfig.tsbuildinfo", | ||||||
| "format": "prettier --write ./src", | ||||||
| "format:check": "prettier --check ./src", | ||||||
| "test": "bun test", | ||||||
| "postinstall": "bun scripts/install-ollama.js" | ||||||
| "postinstall": "bun scripts/install-ollama.js", | ||||||
| "prepare-publish": "bun run scripts/rewrite-core-version.ts", | ||||||
| "restore-workspace": "bun run scripts/rewrite-core-version.ts --restore", | ||||||
| "prepublishOnly": "bun run scripts/rewrite-core-version.ts", | ||||||
| "install-git-hooks": "bun run scripts/install-git-hooks.ts" | ||||||
| }, | ||||||
| "publishCoreVersion": "1.7.2", | ||||||
| "publishConfig": { | ||||||
| "access": "public" | ||||||
| }, | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #!/usr/bin/env bash | ||
| # Post-checkout: in a monorepo, set @elizaos/core back to workspace:* so dev uses local core. | ||
| # Skip when this is the standalone repo (no workspace to link). | ||
| set -e | ||
| ROOT="$(git rev-parse --show-toplevel)" | ||
| if [ -f "$ROOT/packages/plugin-ollama/package.json" ] && grep -q '"publishCoreVersion"' "$ROOT/packages/plugin-ollama/package.json" 2>/dev/null; then | ||
| PLUGIN_DIR="$ROOT/packages/plugin-ollama" | ||
| (cd "$PLUGIN_DIR" && bun run scripts/rewrite-core-version.ts --restore) | ||
| fi | ||
| # If repo root has publishCoreVersion (standalone), do not restore — keep committed version for installs. | ||
| exit 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #!/usr/bin/env bash | ||
| # Pre-commit: ensure @elizaos/core is the verified version from publishCoreVersion so we commit the publishable state. | ||
| set -e | ||
| ROOT="$(git rev-parse --show-toplevel)" | ||
| if [ -f "$ROOT/packages/plugin-ollama/package.json" ] && grep -q '"publishCoreVersion"' "$ROOT/packages/plugin-ollama/package.json" 2>/dev/null; then | ||
| PLUGIN_DIR="$ROOT/packages/plugin-ollama" | ||
| else | ||
| [ -f "$ROOT/package.json" ] && grep -q '"publishCoreVersion"' "$ROOT/package.json" 2>/dev/null || exit 0 | ||
| PLUGIN_DIR="$ROOT" | ||
| fi | ||
| (cd "$PLUGIN_DIR" && bun run scripts/rewrite-core-version.ts) | ||
| git add "$PLUGIN_DIR/package.json" | ||
| exit 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #!/usr/bin/env bun | ||
| /** | ||
| * Install git hooks so that: | ||
| * - pre-commit: commit with @elizaos/core = publishCoreVersion (verified for publish) | ||
| * - post-checkout: in monorepo, restore workspace:* for local dev | ||
| * | ||
| * Run from plugin dir: bun run scripts/install-git-hooks.ts | ||
| * Uses git rev-parse to find .git (works when plugin is in monorepo or standalone). | ||
| */ | ||
| import { $ } from "bun"; | ||
| import { mkdir, writeFile } from "fs/promises"; | ||
| import { join } from "path"; | ||
|
|
||
| const pluginDir = join(import.meta.dir, ".."); | ||
| const gitDir = (await $`git -C "${pluginDir}" rev-parse --git-dir`.text()).trim(); | ||
| const hooksDir = join(pluginDir, gitDir, "hooks"); | ||
| const hooksSource = join(pluginDir, "scripts", "git-hooks"); | ||
|
|
||
| await mkdir(hooksDir, { recursive: true }); | ||
|
|
||
| for (const name of ["pre-commit", "post-checkout"]) { | ||
| const src = join(hooksSource, name); | ||
| const dest = join(hooksDir, name); | ||
| const content = await Bun.file(src).text(); | ||
| await writeFile(dest, content, { mode: 0o755 }); | ||
| console.log(`Installed ${name} -> ${dest}`); | ||
| } | ||
| console.log("Git hooks installed. Pre-commit will use publishCoreVersion; post-checkout will restore workspace:* in monorepo."); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #!/usr/bin/env bun | ||
| /** | ||
| * For standalone publish: replace workspace:* with a real @elizaos/core version | ||
| * so installs work outside the monorepo. Run after syncing from monorepo or in | ||
| * prepublishOnly. Use --restore to set back to workspace:* (e.g. after publish). | ||
| * | ||
| * Usage: | ||
| * bun run scripts/rewrite-core-version.ts # set to publish version | ||
| * bun run scripts/rewrite-core-version.ts --restore # set back to workspace:* | ||
| * | ||
| * Version: from package.json "publishCoreVersion" or env CORE_VERSION or "1.7.2" | ||
| */ | ||
|
|
||
| const RESTORE = process.argv.includes("--restore"); | ||
| const pkgPath = new URL("../package.json", import.meta.url); | ||
| const pkg = (await Bun.file(pkgPath).json()) as Record<string, unknown> & { | ||
| dependencies?: Record<string, string>; | ||
| publishCoreVersion?: string; | ||
| }; | ||
| const coreVersion = | ||
| process.env.CORE_VERSION ?? pkg.publishCoreVersion ?? "1.7.2"; | ||
| const deps = pkg.dependencies ?? {}; | ||
| const current = deps["@elizaos/core"]; | ||
|
Comment on lines
+22
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Modifications to If 🐛 Proposed fix-const deps = pkg.dependencies ?? {};
+pkg.dependencies = pkg.dependencies ?? {};
+const deps = pkg.dependencies;🤖 Prompt for AI Agents |
||
|
|
||
| if (RESTORE) { | ||
| if (current !== coreVersion) { | ||
| console.log(`@elizaos/core is "${current}", not "${coreVersion}", skipping restore`); | ||
| process.exit(0); | ||
| } | ||
| deps["@elizaos/core"] = "workspace:*"; | ||
| console.log('Set @elizaos/core to "workspace:*"'); | ||
| } else { | ||
| if (current === coreVersion) { | ||
| console.log(`@elizaos/core already "${coreVersion}"`); | ||
| process.exit(0); | ||
| } | ||
| deps["@elizaos/core"] = coreVersion; | ||
| console.log(`Set @elizaos/core to "${coreVersion}"`); | ||
| } | ||
|
|
||
| await Bun.write(pkgPath, JSON.stringify(pkg, null, 2) + "\n"); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,28 @@ | ||
| import { describe, it, expect } from 'bun:test'; | ||
| import { ollamaPlugin } from './index'; | ||
| import { createOllama } from 'ollama-ai-provider'; | ||
|
|
||
| // Mocked runtime for testing | ||
| const mockRuntime = { | ||
| emit: jest.fn(), | ||
| getSetting: jest.fn().mockReturnValue(null), | ||
| }; | ||
|
|
||
| const mockModel = jest.fn().mockReturnValue({ | ||
| doStream: jest.fn(), | ||
| }); | ||
|
|
||
| const mockStreamText = jest.fn().mockImplementation(() => ({ | ||
| textStream: (async function*() { | ||
| yield 'Hello, '; | ||
| yield 'world!'; | ||
| })(), | ||
| })); | ||
|
|
||
| // Replace actual streamText with mock | ||
| jest.mock('ai', () => ({ | ||
| streamText: mockStreamText, | ||
| })); | ||
|
Comment on lines
+6
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jest APIs used in Bun test file - tests will fail. This file imports from Bun's test framework uses different mocking approaches:
♻️ Example fix using Bun's mocking API-import { describe, it, expect } from 'bun:test';
+import { describe, it, expect, mock, spyOn } from 'bun:test';
import { ollamaPlugin } from './index';
import { createOllama } from 'ollama-ai-provider';
// Mocked runtime for testing
const mockRuntime = {
- emit: jest.fn(),
- getSetting: jest.fn().mockReturnValue(null),
+ emit: mock(() => {}),
+ getSetting: mock(() => null),
};🤖 Prompt for AI Agents |
||
|
|
||
| describe('ollamaPlugin', () => { | ||
| it('should export ollamaPlugin', () => { | ||
|
|
@@ -15,7 +38,27 @@ describe('ollamaPlugin', () => { | |
| expect(typeof ollamaPlugin.init).toBe('function'); | ||
| }); | ||
|
|
||
| it('should have providers array', () => { | ||
| it('should emit text stream events in order', async () => { | ||
| const result = await ollamaPlugin.models[ModelType.TEXT_SMALL](mockRuntime, { | ||
| prompt: 'Test prompt', | ||
| }); | ||
|
|
||
| expect(mockRuntime.emit).toHaveBeenCalledWith('textStream', 'Hello, '); | ||
| expect(mockRuntime.emit).toHaveBeenCalledWith('textStream', 'world!'); | ||
| expect(mockRuntime.emit).toHaveBeenCalledWith('textStreamDone', true); | ||
|
Comment on lines
+41
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The test references import { describe, it, expect } from 'bun:test';
import { ollamaPlugin } from './index';
import { createOllama } from 'ollama-ai-provider';
+import { ModelType } from '@elizaos/core';🤖 Prompt for AI Agents |
||
| }); | ||
|
|
||
| it('should handle timeout behavior correctly', async () => { | ||
| const timeoutModel = createOllama({}); | ||
| const generateOllamaTextSpy = jest.spyOn(timeoutModel, 'doStream'); | ||
|
|
||
| await ollamaPlugin.models[ModelType.TEXT_SMALL](mockRuntime, { | ||
| prompt: 'Test prompt with timeout', | ||
| }); | ||
|
|
||
| expect(generateOllamaTextSpy).toHaveBeenCalled(); | ||
| expect(mockRuntime.emit).toHaveBeenCalledWith('textStreamDone', true); | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Orphaned test code creates syntax error from bad mergeHigh Severity The |
||
| expect(ollamaPlugin.providers).toBeDefined(); | ||
| expect(Array.isArray(ollamaPlugin.providers)).toBe(true); | ||
| }); | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build script deletes node_modules before tsc needs them
High Severity
build.tsunconditionally runsbun run cleanbefore building. Thecleanscript includesrm -rf node_modules, which deletes all installed dependencies. The subsequenttsc --project tsconfig.build.jsonstep (line 38) requiresnode_modulesto resolve type declarations for imports like@elizaos/coreandai. This causestscto fail or produce broken.d.tsfiles with unresolved types.Additional Locations (1)
package.json#L35-L36