@agi-cli/sdk 0.1.90 → 0.1.91

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.91",
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,94 @@
1
+ import { existsSync, mkdirSync } from 'node:fs';
2
+ import { dirname, join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { tmpdir } from 'node:os';
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
+ async function readFromEmbedded(
31
+ url: URL,
32
+ targetPath: string,
33
+ ): Promise<string | null> {
34
+ const file = Bun.file(url);
35
+ if (!(await file.exists())) {
36
+ return null;
37
+ }
38
+
39
+ const dir = dirname(targetPath);
40
+ mkdirSync(dir, { recursive: true });
41
+ await Bun.write(targetPath, file);
42
+ process.env.BUN_PTY_LIB = targetPath;
43
+ return targetPath;
44
+ }
45
+
46
+ export async function ensureBunPtyLibrary(): Promise<string | null> {
47
+ const already = tryUseExistingPath(process.env.BUN_PTY_LIB);
48
+ if (already) return already;
49
+
50
+ const filename = resolveLibraryFilename();
51
+ const candidates: string[] = [];
52
+
53
+ let pkgUrl: string | null = null;
54
+ try {
55
+ pkgUrl = await import.meta.resolve('bun-pty/package.json');
56
+ const pkgPath = fileURLToPath(pkgUrl);
57
+ const pkgDir = dirname(pkgPath);
58
+ candidates.push(
59
+ join(pkgDir, 'rust-pty', 'target', 'release', filename),
60
+ join(pkgDir, '..', 'bun-pty', 'rust-pty', 'target', 'release', filename),
61
+ );
62
+ } catch {
63
+ // ignore resolution failures
64
+ }
65
+
66
+ candidates.push(
67
+ join(
68
+ process.cwd(),
69
+ 'node_modules',
70
+ 'bun-pty',
71
+ 'rust-pty',
72
+ 'target',
73
+ 'release',
74
+ filename,
75
+ ),
76
+ );
77
+
78
+ for (const candidate of candidates) {
79
+ const path = tryUseExistingPath(candidate);
80
+ if (path) return path;
81
+ }
82
+
83
+ if (pkgUrl) {
84
+ const embeddedUrl = new URL(
85
+ `./rust-pty/target/release/${filename}`,
86
+ pkgUrl,
87
+ );
88
+ const tmpPath = join(tmpdir(), 'agi-cli', 'bun-pty', filename);
89
+ const fromEmbedded = await readFromEmbedded(embeddedUrl, tmpPath);
90
+ if (fromEmbedded) return fromEmbedded;
91
+ }
92
+
93
+ return null;
94
+ }