@agentorg/computer 0.0.18 → 0.0.20

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/dist/sdk.js CHANGED
@@ -24595,6 +24595,19 @@ var ComputerError = class extends Error {
24595
24595
  }
24596
24596
  };
24597
24597
  var seconds = (ms) => Math.max(1, Math.ceil(ms / 1e3));
24598
+ function requestOf(opts) {
24599
+ const { access, browser, name, timeoutMs, metadata, apiKey, apiUrl } = opts;
24600
+ return {
24601
+ connection: { ...apiKey ? { apiKey } : {}, ...apiUrl ? { apiUrl } : {} },
24602
+ body: {
24603
+ access,
24604
+ browser: browser ?? false,
24605
+ ...name === void 0 ? {} : { name },
24606
+ ...timeoutMs === void 0 ? {} : { timeout: seconds(timeoutMs) },
24607
+ ...metadata === void 0 ? {} : { metadata }
24608
+ }
24609
+ };
24610
+ }
24598
24611
  function apiOf(opts = {}) {
24599
24612
  const apiKey = opts.apiKey ?? process.env.AGENTCOMPUTER_API_KEY;
24600
24613
  if (!apiKey) throw new ComputerError(401, "Pass apiKey, or set AGENTCOMPUTER_API_KEY.");
@@ -24636,7 +24649,7 @@ var Endpoint = class {
24636
24649
  async #call(name, args) {
24637
24650
  const client = await this.#connected();
24638
24651
  const result = await client.callTool({ name, arguments: args });
24639
- const text = result.content.map((block) => block.text ?? "").join("");
24652
+ const text = result.content[0]?.text ?? "";
24640
24653
  if (result.isError) throw new ComputerError(400, text);
24641
24654
  return { text, structured: result.structuredContent };
24642
24655
  }
@@ -24794,23 +24807,37 @@ var Computer = class _Computer {
24794
24807
  this.files = new Files(this.#computer);
24795
24808
  }
24796
24809
  static async create(opts) {
24797
- const { access, browser, isolation, workspace, name, timeoutMs, metadata, apiKey, apiUrl } = opts;
24798
- const connection = { ...apiKey ? { apiKey } : {}, ...apiUrl ? { apiUrl } : {} };
24810
+ const { isolation, workspace, copyFrom } = opts;
24811
+ const { connection, body } = requestOf(opts);
24799
24812
  const created = answered(
24800
24813
  await apiOf(connection).POST("/v1/computers", {
24801
24814
  body: {
24802
- access,
24803
- browser: browser ?? false,
24815
+ ...body,
24816
+ browser: opts.browser ?? false,
24804
24817
  ...isolation === void 0 ? {} : { isolation },
24805
24818
  ...workspace === void 0 ? {} : { workspace },
24806
- ...name === void 0 ? {} : { name },
24807
- ...timeoutMs === void 0 ? {} : { timeout: seconds(timeoutMs) },
24808
- ...metadata === void 0 ? {} : { metadata }
24819
+ ...copyFrom === void 0 ? {} : { copyFrom }
24809
24820
  }
24810
24821
  })
24811
24822
  );
24812
24823
  return new _Computer(connection, created, created.accessToken);
24813
24824
  }
24825
+ /** This computer, attached whole. Killing it detaches it and removes nothing of the machine's. */
24826
+ static async attach(opts) {
24827
+ const { connection, body } = requestOf(opts);
24828
+ const attached = answered(
24829
+ await apiOf(connection).POST("/v1/computers/attach", {
24830
+ // Only when asked for: a service from before the screen refuses what it doesn't know, so
24831
+ // the body leaves out the default the generated type would have it carry.
24832
+ body: {
24833
+ ...body,
24834
+ workspace: opts.workspace,
24835
+ ...opts.screen ? { screen: true } : {}
24836
+ }
24837
+ })
24838
+ );
24839
+ return new _Computer(connection, attached, attached.accessToken);
24840
+ }
24814
24841
  /** A computer made earlier. Its token was shown when it was made, and only then. */
24815
24842
  static async connect(computerID, opts) {
24816
24843
  const { accessToken, ...connection } = opts;