Skip to content

An open-source, faster Devin alternative

TypeScript

feat(sdk): add reviewed repository agent imports

Igor Zalutski61d535841842
diff --git a/sdks/typescript/README.md b/sdks/typescript/README.md
index 19243ba5..2ff454ce 100644
--- a/sdks/typescript/README.md
+++ b/sdks/typescript/README.md
@@ -66,6 +66,41 @@ if (delivery.type === "turn.completed") {
}
```
+### Create an agent from a repository
+
+Repository creation is a two-phase review/import so a moving branch cannot change underneath the
+confirmation. Only an exact review is importable; invalid or unrecognized source should be fixed or
+reviewed at another root.
+
+```typescript
+const review = await oc.agents.repository.review({
+ repo: "repo_...",
+ path: "agents/support",
+ productionRef: "main",
+});
+
+if (review.interpretation.disposition !== "exact") {
+ throw new Error(review.interpretation.summary);
+}
+
+const { agent, deployment } = await oc.agents.repository.import({
+ name: "Support triage",
+ credential: "managed",
+ idempotencyKey: crypto.randomUUID(),
+ source: {
+ type: "github",
+ repo: review.repository.id,
+ path: review.root,
+ productionRef: review.productionRef,
+ },
+ review: {
+ sha: review.sha,
+ sourceProfile: review.interpretation.sourceProfile,
+ fingerprint: review.reviewFingerprint,
+ },
+});
+```
+
### Credentials
Sessions run **Managed** (via OpenComputer, billed to your credits — `credential: "managed"`, no key, the default for new orgs) or on **your own** model-provider key (Anthropic for `claude`, OpenAI for `codex`). An inline `key` stores one and attaches it to the agent; manage keys directly to reuse one across agents, set an org default, or rotate/remove:
diff --git a/sdks/typescript/package-lock.json b/sdks/typescript/package-lock.json
index f3cd7de3..c6c0dfd7 100644
--- a/sdks/typescript/package-lock.json
+++ b/sdks/typescript/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "@opencomputer/sdk",
- "version": "0.12.1",
+ "version": "0.12.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@opencomputer/sdk",
- "version": "0.12.1",
+ "version": "0.12.2",
"license": "MIT",
"devDependencies": {
"@types/node": "^25.3.0",
diff --git a/sdks/typescript/package.json b/sdks/typescript/package.json
index 4f797612..77b6583b 100644
--- a/sdks/typescript/package.json
+++ b/sdks/typescript/package.json
@@ -1,6 +1,6 @@
{
"name": "@opencomputer/sdk",
- "version": "0.12.1",
+ "version": "0.12.2",
"description": "TypeScript SDK for OpenComputer - cloud sandbox platform",
"type": "module",
"main": "dist/index.js",
diff --git a/sdks/typescript/src/agents/agents.ts b/sdks/typescript/src/agents/agents.ts
index c45d8372..74873bd2 100644
--- a/sdks/typescript/src/agents/agents.ts
+++ b/sdks/typescript/src/agents/agents.ts
@@ -5,6 +5,7 @@ import {
type Deployment, type InlineSkillFile,
} from "./deployments.js";
import { Schedules } from "./schedules.js";
+import { AgentRepository } from "./repository-agents.js";
export interface CreateAgentParams {
name: string;
@@ -71,6 +72,8 @@ export class Agents {
readonly deploymentSource: DeploymentSourceResource;
/** Cron for agents — schedules that fire a session per slot (015). */
readonly schedules: Schedules;
+ /** Review and import an agent from an existing repository. */
+ readonly repository: AgentRepository;
constructor(private readonly http: Http) {
this.deployments = new Deployments(http);
@@ -79,6 +82,7 @@ export class Agents {
this.skills = new Skills(http);
this.deploymentSource = new DeploymentSourceResource(http);
this.schedules = new Schedules(http);
+ this.repository = new AgentRepository(http);
}
create(params: CreateAgentParams): Promise<Agent> {
diff --git a/sdks/typescript/src/agents/deployments.ts b/sdks/typescript/src/agents/deployments.ts
index df33dd86..75c70943 100644
--- a/sdks/typescript/src/agents/deployments.ts
+++ b/sdks/typescript/src/agents/deployments.ts
@@ -90,9 +90,12 @@ export interface DeploymentSource {
repoId: string;
path: string;
productionRef: string;
- status: string; // active|path_missing|ref_missing|auth_required|repo_not_selected|app_suspended|error
+ status: string; // active|source_profile_changed|path_missing|ref_missing|auth_required|repo_not_selected|app_suspended|error
latestSeenSha?: string | null;
activeDeployedSha?: string | null;
+ sourceProfile?: "flue-app-v1" | null;
+ sourceProfileVersion?: 1 | null;
+ reviewFingerprint?: string | null;
}
export interface LinkParams {
diff --git a/sdks/typescript/src/agents/index.ts b/sdks/typescript/src/agents/index.ts
index 22f6a680..a946dcc7 100644
--- a/sdks/typescript/src/agents/index.ts
+++ b/sdks/typescript/src/agents/index.ts
@@ -12,6 +12,13 @@ export type {
CreateAgentParams, UpdateAgentParams, Page,
SlackManifest, SlackConnection, ConnectSlackParams,
} from "./agents.js";
+export { AgentRepository } from "./repository-agents.js";
+export type {
+ SourceProfileId, RepositoryAgentSource, ReviewRepositoryAgentParams,
+ RepositoryReviewIssue, RepositoryCandidateRoot, FlueSourceProfile,
+ RepositorySourceInterpretation, RepositoryAgentReview, RepositoryReviewReceipt,
+ ImportRepositoryAgentParams, ImportRepositoryAgentResult,
+} from "./repository-agents.js";
export {
Deployments, Revisions, Activations, Skills, DeploymentSourceResource,
} from "./deployments.js";
diff --git a/sdks/typescript/src/agents/normalize.test.ts b/sdks/typescript/src/agents/normalize.test.ts
index bcadbe24..6624232c 100644
--- a/sdks/typescript/src/agents/normalize.test.ts
+++ b/sdks/typescript/src/agents/normalize.test.ts
@@ -31,6 +31,13 @@ describe("normalize (API response → idiomatic TS)", () => {
});
expect(out.refs).toEqual({ pull_number: 42, owner_repo: "acme/widgets", nested: { keep_me: true } });
});
+
+ it("passes manifest vars through verbatim", () => {
+ const out = normalize<{ vars?: Record<string, unknown> }>({
+ vars: { api_url: "https://example.test", nested_value: { keep_me: true } },
+ });
+ expect(out.vars).toEqual({ api_url: "https://example.test", nested_value: { keep_me: true } });
+ });
});
describe("serialize (request body → snake_case)", () => {
@@ -44,4 +51,9 @@ describe("serialize (request body → snake_case)", () => {
const out = serialize({ refs: { pullNumber: 42, owner_repo: "acme/widgets" } }) as Record<string, unknown>;
expect(out.refs).toEqual({ pullNumber: 42, owner_repo: "acme/widgets" });
});
+
+ it("leaves vars opaque on request bodies", () => {
+ const out = serialize({ vars: { apiUrl: "https://example.test", keep_me: true } }) as Record<string, unknown>;
+ expect(out.vars).toEqual({ apiUrl: "https://example.test", keep_me: true });
+ });
});
diff --git a/sdks/typescript/src/agents/normalize.ts b/sdks/typescript/src/agents/normalize.ts
index 23cb8fbb..9a696ad9 100644
--- a/sdks/typescript/src/agents/normalize.ts
+++ b/sdks/typescript/src/agents/normalize.ts
@@ -1,7 +1,7 @@
// Normalize API responses to idiomatic TS: snake_case keys → camelCase, and a known set
// of numeric fields that the API serializes as strings (bigints) → numbers. Opaque
// subtrees are passed through untouched: `raw` (source-specific adapter data),
-// `metadata`, and `refs` (caller-owned routing JSON — must round-trip verbatim,
+// `metadata`, `refs`, and `vars` (caller/source-owned maps — must round-trip verbatim,
// keys included).
const NUMERIC = new Set([
@@ -18,7 +18,7 @@ export function normalize<T = any>(value: unknown): T {
const out: Record<string, unknown> = {};
for (const [k, v] of Object.entries(value as Record<string, unknown>)) {
const ck = camel(k);
- if (ck === "raw" || ck === "metadata" || ck === "refs") { out[ck] = v; continue; } // opaque: verbatim, keys untouched
+ if (ck === "raw" || ck === "metadata" || ck === "refs" || ck === "vars") { out[ck] = v; continue; } // opaque: verbatim, keys untouched
let nv: unknown = normalize(v);
if (NUMERIC.has(ck) && typeof nv === "string" && nv !== "" && !Number.isNaN(Number(nv))) {
nv = Number(nv);
@@ -32,9 +32,9 @@ export function normalize<T = any>(value: unknown): T {
// Inverse of normalize: camelCase keys → snake_case for REQUEST bodies (the API reads
// snake_case). Values are left untouched, and opaque/user-owned subtrees (raw, body,
-// metadata, refs, input) are passed through without key-mangling.
+// metadata, refs, vars, input) are passed through without key-mangling.
const snakeKey = (k: string): string => k.replace(/[A-Z]/g, (c) => "_" + c.toLowerCase());
-const OPAQUE = new Set(["raw", "body", "metadata", "refs", "input"]);
+const OPAQUE = new Set(["raw", "body", "metadata", "refs", "vars", "input"]);
export function serialize(value: unknown): unknown {
if (Array.isArray(value)) return value.map((v) => serialize(v));
diff --git a/sdks/typescript/src/agents/repository-agents.test.ts b/sdks/typescript/src/agents/repository-agents.test.ts
new file mode 100644
index 00000000..ada09497
--- /dev/null
+++ b/sdks/typescript/src/agents/repository-agents.test.ts
@@ -0,0 +1,149 @@
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { OpenComputer } from "./client.js";
+
+const reviewResponse = {
+ repository: {
+ id: "repo_0123456789abcdef01234567",
+ full_name: "example/support-agent",
+ default_branch: "main",
+ },
+ root: "agents/support",
+ production_ref: "main",
+ sha: "a".repeat(40),
+ interpretation: {
+ disposition: "exact",
+ source_profile: "flue-app-v1",
+ source_profile_version: 1,
+ summary: "Flue agent detected",
+ reason_code: "flue_detected",
+ assumptions: [],
+ agent: { runtime: "flue", model: "anthropic/claude-haiku-4-5" },
+ },
+ profile: {
+ source_profile: "flue-app-v1",
+ source_profile_version: 1,
+ manifest: {
+ schema_version: 1,
+ entrypoint: "support-triage",
+ model: "anthropic/claude-haiku-4-5",
+ runtime: { family: "flue", type: "default" },
+ vars: {},
+ },
+ package: {
+ name: "support-agent",
+ node_engine: ">=22.19 <23",
+ flue_cli: "^1.0.0",
+ },
+ lockfile: { version: 3 },
+ builder: { node: "22.19.0" },
+ source: { files: 12, bytes: 4096 },
+ variable_names: [],
+ warnings: [],
+ },
+ review_fingerprint: "sha256:reviewed",
+ candidate_roots: [],
+ candidate_roots_truncated: false,
+};
+
+afterEach(() => {
+ vi.restoreAllMocks();
+});
+
+describe("agent repository review/import", () => {
+ it("normalizes a source-profile review and replays its receipt on import", async () => {
+ const fetchMock = vi
+ .spyOn(globalThis, "fetch")
+ .mockResolvedValueOnce(Response.json(reviewResponse))
+ .mockResolvedValueOnce(
+ Response.json({
+ agent: {
+ id: "agt_imported",
+ name: "Support triage",
+ model: "anthropic/claude-haiku-4-5",
+ runtime: "flue",
+ },
+ source: {
+ agent_id: "agt_imported",
+ repo_id: reviewResponse.repository.id,
+ path: reviewResponse.root,
+ production_ref: reviewResponse.production_ref,
+ status: "active",
+ },
+ deployment: { id: "dep_first", state: "accepted" },
+ }),
+ );
+ const oc = new OpenComputer({
+ apiKey: "oc_test",
+ baseUrl: "https://api.example.test/v3",
+ maxRetries: 0,
+ });
+
+ const review = await oc.agents.repository.review({
+ repo: reviewResponse.repository.id,
+ path: reviewResponse.root,
+ productionRef: reviewResponse.production_ref,
+ });
+ expect(review.interpretation.disposition).toBe("exact");
+ expect(review.interpretation.sourceProfile).toBe("flue-app-v1");
+ expect(review.profile?.manifest.entrypoint).toBe("support-triage");
+
+ if (review.interpretation.disposition !== "exact") {
+ throw new Error("fixture must be importable");
+ }
+ await oc.agents.repository.import({
+ name: "Support triage",
+ credential: "managed",
+ idempotencyKey: "import-command-1",
+ source: {
+ type: "github",
+ repo: review.repository.id,
+ path: review.root,
+ productionRef: review.productionRef,
+ },
+ review: {
+ sha: review.sha,
+ sourceProfile: review.interpretation.sourceProfile,
+ fingerprint: review.reviewFingerprint,
+ },
+ });
+
+ expect(fetchMock).toHaveBeenNthCalledWith(
+ 1,
+ "https://api.example.test/v3/github/deploy-app/inspect",
+ expect.objectContaining({
+ method: "POST",
+ body: JSON.stringify({
+ repo: reviewResponse.repository.id,
+ path: "agents/support",
+ production_ref: "main",
+ }),
+ }),
+ );
+ expect(fetchMock).toHaveBeenNthCalledWith(
+ 2,
+ "https://api.example.test/v3/agents/import",
+ expect.objectContaining({
+ method: "POST",
+ headers: expect.objectContaining({
+ "Idempotency-Key": "import-command-1",
+ }),
+ }),
+ );
+ const importInit = fetchMock.mock.calls[1]?.[1] as RequestInit;
+ expect(JSON.parse(String(importInit.body))).toEqual({
+ name: "Support triage",
+ credential: "managed",
+ source: {
+ type: "github",
+ repo: reviewResponse.repository.id,
+ path: "agents/support",
+ production_ref: "main",
+ },
+ review: {
+ sha: reviewResponse.sha,
+ source_profile: "flue-app-v1",
+ fingerprint: "sha256:reviewed",
+ },
+ });
+ });
+});
diff --git a/sdks/typescript/src/agents/repository-agents.ts b/sdks/typescript/src/agents/repository-agents.ts
new file mode 100644
index 00000000..0b4606de
--- /dev/null
+++ b/sdks/typescript/src/agents/repository-agents.ts
@@ -0,0 +1,181 @@
+// Two-phase repository agent creation. Review is read-only and pins the exact
+// source interpretation the user confirmed; import revalidates that review
+// before creating an agent or deployment.
+
+import type { Http } from "./http.js";
+import type { Agent, CredentialRef } from "./types.js";
+import type { Deployment, DeploymentSource } from "./deployments.js";
+
+export type SourceProfileId = "flue-app-v1";
+
+export interface RepositoryAgentSource {
+ type: "github";
+ /** An owner-scoped `repo_…` id. */
+ repo: string;
+ /** Repository-relative root; use an empty string for the repository root. */
+ path: string;
+ /** The production branch OpenComputer resolves and follows for push-to-deploy. */
+ productionRef: string;
+}
+
+export interface ReviewRepositoryAgentParams {
+ repo: string;
+ path: string;
+ productionRef: string;
+}
+
+export interface RepositoryReviewIssue {
+ code: string;
+ message: string;
+ path?: string;
+}
+
+export interface RepositoryCandidateRoot {
+ path: string;
+ sourceProfile: SourceProfileId | null;
+ summary: string;
+ marker:
+ | "agent.toml"
+ | "flue.config.ts"
+ | "flue.config.js"
+ | "flue.config.mjs"
+ | "flue.config.cjs";
+}
+
+export interface FlueSourceProfile {
+ sourceProfile: "flue-app-v1";
+ sourceProfileVersion: 1;
+ manifest: {
+ schemaVersion: 1;
+ entrypoint: string;
+ model: string;
+ runtime: { family: "flue"; type: string };
+ /** Non-secret manifest variables. */
+ vars: Record<string, string>;
+ };
+ package: {
+ name: string | null;
+ nodeEngine: string;
+ flueCli: string;
+ };
+ lockfile: { version: number };
+ builder: { node: string };
+ source: { files: number; bytes: number };
+ variableNames: string[];
+ warnings: RepositoryReviewIssue[];
+}
+
+export type RepositorySourceInterpretation =
+ | {
+ disposition: "exact";
+ sourceProfile: "flue-app-v1";
+ sourceProfileVersion: 1;
+ summary: string;
+ reasonCode: "flue_detected";
+ assumptions: string[];
+ agent: { runtime: "flue"; model: string };
+ }
+ | {
+ disposition: "invalid";
+ sourceProfile: SourceProfileId | null;
+ sourceProfileVersion: 1 | null;
+ summary: string;
+ reasonCode: string;
+ issues: RepositoryReviewIssue[];
+ }
+ | {
+ disposition: "unrecognized";
+ sourceProfile: null;
+ sourceProfileVersion: null;
+ summary: string;
+ reasonCode: "unrecognized_source";
+ };
+
+interface RepositoryAgentReviewBase {
+ repository: {
+ id: string;
+ fullName: string;
+ defaultBranch: string | null;
+ };
+ root: string;
+ productionRef: string;
+ sha: string;
+ reviewFingerprint: string;
+ candidateRoots: RepositoryCandidateRoot[];
+ candidateRootsTruncated: boolean;
+}
+
+export type RepositoryAgentReview =
+ | (RepositoryAgentReviewBase & {
+ interpretation: Extract<
+ RepositorySourceInterpretation,
+ { disposition: "exact" }
+ >;
+ profile: FlueSourceProfile;
+ })
+ | (RepositoryAgentReviewBase & {
+ interpretation: Extract<
+ RepositorySourceInterpretation,
+ { disposition: "invalid" }
+ >;
+ profile: null;
+ })
+ | (RepositoryAgentReviewBase & {
+ interpretation: Extract<
+ RepositorySourceInterpretation,
+ { disposition: "unrecognized" }
+ >;
+ profile: null;
+ });
+
+export interface RepositoryReviewReceipt {
+ sha: string;
+ sourceProfile: SourceProfileId;
+ fingerprint: string;
+}
+
+export interface ImportRepositoryAgentParams {
+ name: string;
+ source: RepositoryAgentSource;
+ review: RepositoryReviewReceipt;
+ /** Repository imports currently use Managed model access. */
+ credential: Extract<CredentialRef, "managed">;
+ /** Stable for one logical import; conflicting reuse fails safely. */
+ idempotencyKey: string;
+}
+
+export interface ImportRepositoryAgentResult {
+ agent: Agent;
+ source: DeploymentSource;
+ deployment: Deployment;
+}
+
+/** Review and import an agent from a repository (`oc.agents.repository`). */
+export class AgentRepository {
+ constructor(private readonly http: Http) {}
+
+ /**
+ * Resolve one exact commit and interpret its selected root without executing
+ * repository code. Only an `exact` result can be imported.
+ */
+ review(params: ReviewRepositoryAgentParams): Promise<RepositoryAgentReview> {
+ return this.http.request("POST", "/github/deploy-app/inspect", {
+ body: params,
+ });
+ }
+
+ /**
+ * Revalidate a reviewed source plan, then atomically create its agent, source
+ * link, and first deployment. The idempotency key is sent as a header.
+ */
+ import(
+ params: ImportRepositoryAgentParams,
+ ): Promise<ImportRepositoryAgentResult> {
+ const { idempotencyKey, ...body } = params;
+ return this.http.request("POST", "/agents/import", {
+ body,
+ idempotencyKey,
+ idempotent: true,
+ });
+ }
+}