Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/content/docs/javascript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ Returning `undefined`, a function, a symbol, or a circular value fails with

<CodeSnippet file="examples/js-sdk-overview/src/index.ts" />

Inline JavaScript defaults to ES modules, including static and dynamic imports,
`export` declarations, and top-level `await`. Node-compatible
`data:text/javascript` imports work too, including base64 payloads with unique
URL fragments. You do not need to write an `.mjs` file to use these features.

`execute()` does not return the module namespace. Use `evaluate()` for a
JSON-serializable host result, or assign to `globalThis` when another call in the
same context needs the value.

Executions are ephemeral, so capture stdio only when you want it — `"stderr"` for
diagnostics, `"all"` for both streams. `onStdout`/`onStderr` stream live and work
independently of capture.
Expand Down
5 changes: 4 additions & 1 deletion examples/js-sdk-overview/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ const runtime = await AgentOs.create();

try {
const result = await runtime.javascript.execute(
`console.log("hello from agentOS")`,
`
export const message = await Promise.resolve("hello from agentOS");
console.log(message);
`,
{ output: { capture: "all" } },
);
console.log(result.outcome === "succeeded" ? result.stdout : result.error); // "hello from agentOS\n"
Expand Down