@opencode/codemode 0.0.0-dev-19439 → 0.0.0-dev-19442

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.
@@ -11,6 +11,7 @@ import { regexpGlobal } from "../stdlib/regexp.js";
11
11
  import { stringGlobal } from "../stdlib/string.js";
12
12
  import { uriGlobal, urlGlobal, urlSearchParamsGlobal } from "../stdlib/url.js";
13
13
  import { coercion, errorConstructors } from "../stdlib/value.js";
14
+ import { atobGlobal, btoaGlobal, cryptoGlobal } from "../stdlib/web.js";
14
15
  import { ToolReference } from "../tool-runtime.js";
15
16
  import { errorGlobal } from "./errors.js";
16
17
  import { HostFunction } from "./host.js";
@@ -55,5 +56,8 @@ export const globals = (host) => [
55
56
  ["encodeURIComponent", uriGlobal("encodeURIComponent")],
56
57
  ["decodeURI", uriGlobal("decodeURI")],
57
58
  ["decodeURIComponent", uriGlobal("decodeURIComponent")],
59
+ ["atob", atobGlobal],
60
+ ["btoa", btoaGlobal],
61
+ ["crypto", cryptoGlobal],
58
62
  ...[...errorConstructors].map((name) => [name, errorGlobal(name, host.runner)]),
59
63
  ];
@@ -0,0 +1,4 @@
1
+ import { HostNamespace } from "../interpreter/host.js";
2
+ export declare const atobGlobal: import("../interpreter/host.js").HostFunction<never>;
3
+ export declare const btoaGlobal: import("../interpreter/host.js").HostFunction<never>;
4
+ export declare const cryptoGlobal: HostNamespace;
@@ -0,0 +1,21 @@
1
+ import { HostNamespace, sync } from "../interpreter/host.js";
2
+ import { InterpreterRuntimeError } from "../interpreter/model.js";
3
+ import { coerceToString } from "./value.js";
4
+ // WebIDL DOMString conversion: a missing argument is a TypeError, anything else stringifies.
5
+ const base64 = (name) => sync(name, (args, node) => {
6
+ if (args.length === 0) {
7
+ throw new InterpreterRuntimeError(`${name} requires 1 argument, but only 0 were provided.`, node).as("TypeError");
8
+ }
9
+ const input = coerceToString(args[0]);
10
+ try {
11
+ return name === "atob" ? atob(input) : btoa(input);
12
+ }
13
+ catch {
14
+ throw new InterpreterRuntimeError("The string contains invalid characters.", node).as("InvalidCharacterError");
15
+ }
16
+ });
17
+ export const atobGlobal = base64("atob");
18
+ export const btoaGlobal = base64("btoa");
19
+ export const cryptoGlobal = new HostNamespace("crypto", {
20
+ randomUUID: sync("crypto.randomUUID", () => crypto.randomUUID()),
21
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@opencode/codemode",
4
- "version": "0.0.0-dev-19439",
4
+ "version": "0.0.0-dev-19442",
5
5
  "description": "Effect-native confined code execution over schema-described tools",
6
6
  "type": "module",
7
7
  "license": "MIT",