@agi-cli/sdk 0.1.90 → 0.1.92

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agi-cli/sdk",
3
- "version": "0.1.90",
3
+ "version": "0.1.92",
4
4
  "description": "AI agent SDK for building intelligent assistants - tree-shakable and comprehensive",
5
5
  "author": "ntishxyz",
6
6
  "license": "MIT",
@@ -1,2 +1,13 @@
1
- export { spawn } from 'bun-pty';
2
- export type { IPty, IPtyForkOptions as PtyOptions, IExitEvent } from 'bun-pty';
1
+ import { ensureBunPtyLibrary } from './ensure-bun-pty.ts';
2
+
3
+ await ensureBunPtyLibrary();
4
+
5
+ const bunPty = await import('bun-pty');
6
+
7
+ export const spawn = bunPty.spawn;
8
+
9
+ export type {
10
+ IPty,
11
+ IPtyForkOptions as PtyOptions,
12
+ IExitEvent,
13
+ } from 'bun-pty';
@@ -0,0 +1,70 @@
1
+ import { existsSync, mkdirSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { getGlobalConfigDir } from '../../../../src/config/src/paths.ts';
4
+ import { RUST_PTY_LIBS } from './rust-libs.ts';
5
+
6
+ function resolveLibraryFilename(): string {
7
+ const platform = process.platform;
8
+ const arch = process.arch;
9
+
10
+ if (platform === 'darwin') {
11
+ return arch === 'arm64' ? 'librust_pty_arm64.dylib' : 'librust_pty.dylib';
12
+ }
13
+
14
+ if (platform === 'win32') {
15
+ return 'rust_pty.dll';
16
+ }
17
+
18
+ return arch === 'arm64' ? 'librust_pty_arm64.so' : 'librust_pty.so';
19
+ }
20
+
21
+ function tryUseExistingPath(path?: string | null): string | null {
22
+ if (!path) return null;
23
+ if (existsSync(path)) {
24
+ process.env.BUN_PTY_LIB = path;
25
+ return path;
26
+ }
27
+ return null;
28
+ }
29
+
30
+ export async function ensureBunPtyLibrary(): Promise<string | null> {
31
+ const already = tryUseExistingPath(process.env.BUN_PTY_LIB);
32
+ if (already) return already;
33
+
34
+ const filename = resolveLibraryFilename();
35
+ const candidates: string[] = [];
36
+
37
+ candidates.push(
38
+ join(
39
+ process.cwd(),
40
+ 'node_modules',
41
+ 'bun-pty',
42
+ 'rust-pty',
43
+ 'target',
44
+ 'release',
45
+ filename,
46
+ ),
47
+ );
48
+
49
+ for (const candidate of candidates) {
50
+ const path = tryUseExistingPath(candidate);
51
+ if (path) return path;
52
+ }
53
+
54
+ const platformLibs =
55
+ RUST_PTY_LIBS[process.platform as keyof typeof RUST_PTY_LIBS];
56
+ const embeddedPath =
57
+ platformLibs?.[process.arch === 'arm64' ? 'arm64' : 'x64'];
58
+
59
+ if (embeddedPath) {
60
+ const targetDir = join(getGlobalConfigDir(), 'runtime', 'bun-pty');
61
+ mkdirSync(targetDir, { recursive: true });
62
+ const targetPath = join(targetDir, filename);
63
+ const source = Bun.file(embeddedPath);
64
+ await Bun.write(targetPath, source);
65
+ process.env.BUN_PTY_LIB = targetPath;
66
+ return targetPath;
67
+ }
68
+
69
+ return null;
70
+ }
@@ -0,0 +1,30 @@
1
+ import darwinArm64 from 'bun-pty/rust-pty/target/release/librust_pty_arm64.dylib' with {
2
+ type: 'file',
3
+ };
4
+ import darwinX64 from 'bun-pty/rust-pty/target/release/librust_pty.dylib' with {
5
+ type: 'file',
6
+ };
7
+ import linuxArm64 from 'bun-pty/rust-pty/target/release/librust_pty_arm64.so' with {
8
+ type: 'file',
9
+ };
10
+ import linuxX64 from 'bun-pty/rust-pty/target/release/librust_pty.so' with {
11
+ type: 'file',
12
+ };
13
+ import windowsDll from 'bun-pty/rust-pty/target/release/rust_pty.dll' with {
14
+ type: 'file',
15
+ };
16
+
17
+ export const RUST_PTY_LIBS = {
18
+ darwin: {
19
+ arm64: darwinArm64,
20
+ x64: darwinX64,
21
+ },
22
+ linux: {
23
+ arm64: linuxArm64,
24
+ x64: linuxX64,
25
+ },
26
+ win32: {
27
+ arm64: windowsDll,
28
+ x64: windowsDll,
29
+ },
30
+ } as const;