Status

  • Not available yet SDK import methods. The JavaScript SDK has no import methods.
  • Needs an IntelliNix workspace with the genome flags on fetch against the workspace import routes. Node 18 or newer. Same flags and administrator rule as the IntelliNix import.

The JavaScript SDK has no import methods

client.genome has registerAgent, get, compile, finalize, recordOutcome, export, erase, quality, geneEffects and engineQuality. There are no importPreview, importConsent or importUndo methods yet. Use fetch against the import routes, as below.

Prerequisites

  • Node 18 or newer (for built-in fetch), running the script as an ES module.
  • An IntelliNix workspace with agent_genome and genome_format on, and an administrator account.
  • Your API address as [YOUR-INTELLINIX-API] and a key as [YOUR-API-KEY].
  • For the SDK calls: the package named in the SDK source, @intellinix/sdk (not checked against the npm registry), the genome_public_api flag, and a key with the genome:read scope.
  • The file checked first, with the commands or the checker on the install page.

Import with preview and consent

The script sends the file to the workspace preview route and prints what would happen. It applies nothing. The two lines at the end are comments: remove the comment marks only after you have read the preview. It uses the same routes as the REST guide.

Import with fetch (works with the flags on) JavaScript
import { readFile } from "node:fs/promises";

const base = "[YOUR-INTELLINIX-API]";
const apiKey = "[YOUR-API-KEY]";

async function post(path, body) {
  const response = await fetch(base + path, {
    method: "POST",
    headers: { "X-API-Key": apiKey, "Content-Type": "application/json" },
    body,
  });
  if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
  return response.json();
}

const file = await readFile("my-genome.agf.json");
const preview = await post("/genome/workspace/import/preview", file);
console.log(preview.status, preview.counts);
console.log("skipped:", preview.skipped);
console.log("rejected:", preview.rejected);

// Nothing is applied yet. Read the preview, then apply:
// const done = await post(`/genome/transfers/${preview.id}/consent`);
// And to undo it:
// await post(`/genome/transfers/${preview.id}/undo`, JSON.stringify({ confirm_later_changes: false }));

Read a genome from your own code

This part of the SDK works today, for an agent of your workspace, through the public API. It reads or compiles the genome that is already there. Check the result of get after an import to see whether your genes show for that agent.

Read and compile a genome with the SDK JavaScript
import Intellinix from "@intellinix/sdk";

const client = new Intellinix({ apiKey: "[YOUR-API-KEY]", baseUrl: "[YOUR-INTELLINIX-API]" });

const view = await client.genome.get("[YOUR-AGENT-SLUG]");
console.log(view.version, view.genes.length);

const compiled = await client.genome.compile("[YOUR-AGENT-SLUG]", { task: "Draft a polite payment reminder" });
console.log(compiled.compile_id);
console.log(compiled.section);

Expected results

  • Import script: the transfer's status (previewed) and counts, then the skipped and rejected lists. After the consent line, applied; after the undo line, undone.
  • get: an object with version and genes. compile: compile_id and section, the text to add to your prompt.

Troubleshooting

  • ScopeError (403) from the SDK. The key lacks the genome scope, or it is an older key without scopes. Create a new key.
  • NotFoundError (404) from the SDK. The genome_public_api or agent_genome flag is off for the key's workspace, or the agent is not in it.
  • The script throws “HTTP 404”, “HTTP 403” and so on. Read the status in the table below.
HTTP answers from the import routes
AnswerWhat it meansWhat to do
401 The credentials were not accepted. Check the key or token. A suspended or deleted account is refused with 403.
404 Not found. The same answer is used when a feature flag is off, when the agent or transfer id does not exist, and when it belongs to another workspace. Ask a workspace administrator to turn on agent_genome and genome_format. Check the agent id or transfer id.
403 You are not allowed. The import routes need the settings update permission (an administrator). Applying a preview that holds personal-layer genes is allowed only for the administrator who made it. Use an administrator account, and apply with the same account that made the preview.
422 The file was rejected, or nothing in it can be imported. The message starts with a code such as too_large, invalid_json, invalid_agf_version, unsupported_agf_major, invalid_document, forbidden_reference or digest_mismatch. Nothing is stored for a rejected file. See the common problems table on the install page, then fix the file and preview again.
409 The step cannot happen now: the memory changed since the preview (stale), the preview is older than 7 days (expired), the transfer is not in a state that allows the step (invalid_transition, for example applying twice), or the memory changed while applying (conflict, and none of the import is kept). Preview the file again, then apply.
409 on undo Lists changed after the import. The answer has code later_changes and a count, and nothing is written. Read the warning. To undo anyway, send the undo again with confirm_later_changes set to true.