@voicethere/agent 0.2.8 → 0.2.9

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/README.md CHANGED
@@ -256,7 +256,9 @@ npx @voicethere/agent build
256
256
  # or: npx @voicethere/agent build --entry src/agent.ts --outfile dist/agent.js
257
257
  ```
258
258
 
259
- Defaults: entry `agent.ts`, output `dist/agent.js`. Upload the bundle (or point `AGENT_BUNDLE_PATH` at it locally). Inlining dependencies avoids runtime `node_modules` resolution inside the sandbox.
259
+ Defaults: entry `agent.ts`, output `dist/agent.js`. Upload the bundle (or point `AGENT_BUNDLE_PATH` at it locally). The CLI inlines npm dependencies (e.g. `ioredis`) into one file and wires `createRequire` for Node built-ins (`events`, `net`, `stream`, …) so the sandbox child does not need `node_modules` on disk.
260
+
261
+ After building, run **`npx @voicethere/agent verify-start --no-build --bundle dist/agent.js`** to confirm the bundle loads under production `--permission` flags (catches errors like `Dynamic require of "events" is not supported`).
260
262
 
261
263
  ## Sandbox and security model
262
264
 
package/dist/agent.js CHANGED
@@ -1,3 +1,7 @@
1
+ import { createRequire } from "node:module";
2
+ const require = createRequire(import.meta.url);
3
+
4
+
1
5
  // src/runtime.ts
2
6
  import { AsyncLocalStorage } from "node:async_hooks";
3
7
 
@@ -7,6 +7,12 @@ export interface BuildAgentBundleOptions {
7
7
  /** Working directory for relative paths. Defaults to `process.cwd()`. */
8
8
  cwd?: string;
9
9
  }
10
+ /**
11
+ * Keep Node built-ins external so bundled CJS deps (e.g. ioredis) use runtime
12
+ * `import` / `createRequire` instead of esbuild's broken `__require` shim
13
+ * ("Dynamic require of \"events\" is not supported").
14
+ */
15
+ export declare function nodeBuiltinExternalPlugin(): esbuild.Plugin;
10
16
  /**
11
17
  * Bundle customer agent source into a single ESM file for the sandboxed child.
12
18
  */
@@ -1 +1 @@
1
- {"version":3,"file":"build-bundle.d.ts","sourceRoot":"","sources":["../src/build-bundle.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,MAAM,WAAW,uBAAuB;IACtC,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAoB9B"}
1
+ {"version":3,"file":"build-bundle.d.ts","sourceRoot":"","sources":["../src/build-bundle.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,MAAM,WAAW,uBAAuB;IACtC,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAqCD;;;;GAIG;AACH,wBAAgB,yBAAyB,IAAI,OAAO,CAAC,MAAM,CAY1D;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAsB9B"}
@@ -1,6 +1,55 @@
1
+ import { builtinModules } from "node:module";
1
2
  import { existsSync, mkdirSync } from "node:fs";
2
3
  import { dirname, resolve } from "node:path";
3
4
  import * as esbuild from "esbuild";
5
+ const NODE_BUILTIN_MODULE_IDS = new Set([
6
+ ...builtinModules,
7
+ ...builtinModules.map((name) => `node:${name}`),
8
+ ]);
9
+ /** Lets bundled CJS deps (ioredis) call `require("events")` under ESM output. */
10
+ const AGENT_BUNDLE_BANNER = `import { createRequire } from "node:module";
11
+ const require = createRequire(import.meta.url);
12
+ `;
13
+ function isNodeBuiltinModuleId(path) {
14
+ return NODE_BUILTIN_MODULE_IDS.has(path);
15
+ }
16
+ /** Optional deps that ioredis/debug resolve dynamically; stub so bundles stay self-contained. */
17
+ const BUNDLE_STUB_MODULES = {
18
+ "supports-color": "export default false;",
19
+ };
20
+ function bundleStubPlugin() {
21
+ return {
22
+ name: "agent-bundle-stub",
23
+ setup(build) {
24
+ build.onResolve({ filter: /^supports-color$/ }, () => ({
25
+ path: "supports-color",
26
+ namespace: "agent-bundle-stub",
27
+ }));
28
+ build.onLoad({ filter: /.*/, namespace: "agent-bundle-stub" }, (args) => ({
29
+ contents: BUNDLE_STUB_MODULES[args.path] ?? "export {};",
30
+ loader: "js",
31
+ }));
32
+ },
33
+ };
34
+ }
35
+ /**
36
+ * Keep Node built-ins external so bundled CJS deps (e.g. ioredis) use runtime
37
+ * `import` / `createRequire` instead of esbuild's broken `__require` shim
38
+ * ("Dynamic require of \"events\" is not supported").
39
+ */
40
+ export function nodeBuiltinExternalPlugin() {
41
+ return {
42
+ name: "node-builtin-external",
43
+ setup(build) {
44
+ build.onResolve({ filter: /.*/ }, (args) => {
45
+ if (!isNodeBuiltinModuleId(args.path)) {
46
+ return undefined;
47
+ }
48
+ return { path: args.path, external: true };
49
+ });
50
+ },
51
+ };
52
+ }
4
53
  /**
5
54
  * Bundle customer agent source into a single ESM file for the sandboxed child.
6
55
  */
@@ -20,6 +69,8 @@ export async function buildAgentBundle(options) {
20
69
  outfile,
21
70
  target: "node26",
22
71
  logLevel: "warning",
72
+ banner: { js: AGENT_BUNDLE_BANNER },
73
+ plugins: [nodeBuiltinExternalPlugin(), bundleStubPlugin()],
23
74
  });
24
75
  }
25
76
  //# sourceMappingURL=build-bundle.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build-bundle.js","sourceRoot":"","sources":["../src/build-bundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAWnC;;GAEG;AAC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BAAgB,CACpC,OAAgC;IAEhC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IACzC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAC1C,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAE9C,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,oBAAoB,KAAK,EAAE,CAAC,CAAC;IAC/C,CAAC;IAED,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAEjD,OAAO,OAAO,CAAC,KAAK,CAAC;QACnB,WAAW,EAAE,CAAC,KAAK,CAAC;QACpB,MAAM,EAAE,IAAI;QACZ,QAAQ,EAAE,MAAM;QAChB,MAAM,EAAE,KAAK;QACb,OAAO;QACP,MAAM,EAAE,QAAQ;QAChB,QAAQ,EAAE,SAAS;QACnB,MAAM,EAAE,EAAE,EAAE,EAAE,mBAAmB,EAAE;QACnC,OAAO,EAAE,CAAC,yBAAyB,EAAE,EAAE,gBAAgB,EAAE,CAAC;KAC3D,CAAC,CAAC;AACL,CAAC"}
package/dist/cli.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voicethere/agent",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "VoiceThere customer agent SDK — IPC types and runtime helpers for sandboxed child bundles",
5
5
  "type": "module",
6
6
  "exports": {