@gitterm/sdk 0.3.0 → 0.4.0

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/README.md CHANGED
@@ -450,7 +450,10 @@ Three things have to be true before a prompt can be delivered, and the SDK handl
450
450
  The shortest correct sequence is therefore:
451
451
 
452
452
  ```ts
453
- const { workspace } = await client.workspaces.create({ repo, setup: { afterAgent: ["npm ci"] } });
453
+ const { workspace } = await client.workspaces.create({
454
+ repo,
455
+ setup: { afterAgent: ["npm ci"] },
456
+ });
454
457
  const run = await client.runs.create({
455
458
  workspace,
456
459
  idempotencyKey: `review-${sha}`,
@@ -682,10 +685,10 @@ would otherwise change them for other runs on the same runtime.
682
685
 
683
686
  ## OpenCode API versions
684
687
 
685
- Managed workspaces run OpenCode V2 from `@opencode/cli@2` and use `opencodeApi: "v2"`. V2 stores
686
- credentials in SQLite; GitTerm writes a short-lived V1-shaped `auth.json` seed before first startup,
687
- triggers V2's supported credential import, then deletes the seed. Runs, questions, permissions, and
688
- events use GitTerm's V2 runtime adapter.
688
+ Managed workspaces default to OpenCode V1 from `opencode-ai` and use `opencodeApi: "v1"`.
689
+ Credentials are written to OpenCode's `auth.json` before the runtime starts. Runs, questions,
690
+ permissions, and events use GitTerm's V1 runtime adapter. V2 remains selectable only for explicitly
691
+ compatible images.
689
692
 
690
693
  ## Errors
691
694
 
@@ -784,12 +787,17 @@ let workspace = await direct.workspaces.create({
784
787
  repo: "https://github.com/acme/project",
785
788
  lifecycle: "ephemeral",
786
789
  models: {
787
- providers: { anthropic: { source: "apiKey", apiKey: process.env.ANTHROPIC_API_KEY! } },
790
+ providers: {
791
+ anthropic: { source: "apiKey", apiKey: process.env.ANTHROPIC_API_KEY! },
792
+ },
788
793
  },
789
794
  });
790
795
 
791
796
  try {
792
- const run = await direct.runs.create({ workspace, prompt: "Review the open pull request" });
797
+ const run = await direct.runs.create({
798
+ workspace,
799
+ prompt: "Review the open pull request",
800
+ });
793
801
  const completed = await direct.runs.result(run);
794
802
  console.log(completed.finalText);
795
803
  } finally {
@@ -823,12 +823,6 @@ function parseV2Signal(raw) {
823
823
  return null;
824
824
  }
825
825
  }
826
- // ../agent-runtime/src/opencode-credentials.ts
827
- var OPENCODE_V2_IMPORT_CREDENTIALS = String.raw`AUTH_FILE="\${OPENCODE_DATA_DIR:-\${XDG_DATA_HOME:-$HOME/.local/share}/opencode}/auth.json"
828
- if [ -f "$AUTH_FILE" ]; then
829
- opencode auth list >/dev/null
830
- rm -f "$AUTH_FILE"
831
- fi`;
832
826
  // ../agent-runtime/src/derive.ts
833
827
  var MISSING_ASSISTANT_GRACE_MS = 1e4;
834
828
  function deriveRunState(snapshot, context) {
@@ -1617,7 +1611,10 @@ function buildDirectProvisioningPlan(input) {
1617
1611
  throw new GittermError("MODEL_CREDENTIAL_INVALID", "Direct mode cannot inherit dashboard credentials");
1618
1612
  }
1619
1613
  for (const [key, source] of Object.entries(input.models?.providers ?? {})) {
1620
- const credential = { ...source, providerName: key };
1614
+ const credential = {
1615
+ ...source,
1616
+ providerName: key
1617
+ };
1621
1618
  const providerName = key.trim();
1622
1619
  if (!providerName)
1623
1620
  throw new Error("Model credential providerName is required");
@@ -1698,11 +1695,7 @@ function buildDirectProvisioningPlan(input) {
1698
1695
  port: DIRECT_OPENCODE_PORT
1699
1696
  },
1700
1697
  setup: {
1701
- beforeAgent: [
1702
- ...(input.opencode?.api ?? "v2") === "v2" ? [OPENCODE_V2_IMPORT_CREDENTIALS] : [],
1703
- ...github ? [github.setup] : [],
1704
- ...input.setup?.beforeAgent ?? []
1705
- ],
1698
+ beforeAgent: [...github ? [github.setup] : [], ...input.setup?.beforeAgent ?? []],
1706
1699
  afterAgent: input.setup?.afterAgent ?? []
1707
1700
  }
1708
1701
  };
@@ -1727,7 +1720,9 @@ function railwayContainerEnvironment(plan) {
1727
1720
  } : {}
1728
1721
  } : {},
1729
1722
  AGENT_FILES_BASE64: base64(JSON.stringify(plan.agent.files)),
1730
- ...beforeAgent.length ? { WORKSPACE_SETUP_COMMAND_BASE64: base64(setupCommandScript(beforeAgent)) } : {},
1723
+ ...beforeAgent.length ? {
1724
+ WORKSPACE_SETUP_COMMAND_BASE64: base64(setupCommandScript(beforeAgent))
1725
+ } : {},
1731
1726
  GITTERM_DIRECT_PROVIDER: "railway"
1732
1727
  };
1733
1728
  }
@@ -1897,7 +1892,7 @@ function createAsciiDirectProvider(config) {
1897
1892
  });
1898
1893
  await runCommand(handle.boxId, `mkdir -p ${shellQuote(directory)}`);
1899
1894
  for (const command of config.runtimeSetupCommands ?? [
1900
- "npm install -g @opencode/cli@2 --no-audit --fund=false"
1895
+ "npm install -g opencode-ai --no-audit --fund=false"
1901
1896
  ]) {
1902
1897
  await runCommand(handle.boxId, command, undefined, 600);
1903
1898
  }
@@ -2889,7 +2884,7 @@ function createVercelDirectProvider(config) {
2889
2884
  });
2890
2885
  try {
2891
2886
  await run(sandbox, `mkdir -p ${shellQuote(handle.directory)}`);
2892
- for (const command of config.runtimeSetupCommands ?? (config.image ? [] : ["npm install -g @opencode/cli@2 --no-audit --fund=false"])) {
2887
+ for (const command of config.runtimeSetupCommands ?? (config.image ? [] : ["npm install -g opencode-ai --no-audit --fund=false"])) {
2893
2888
  await run(sandbox, command);
2894
2889
  }
2895
2890
  if (plan.repository) {
@@ -147,7 +147,7 @@ export type DirectWorkspaceCreateInput = {
147
147
  /** Trusted integration context appended to the generated global AGENTS.md. */
148
148
  additionalAgentInstructions?: string;
149
149
  opencode?: {
150
- /** Defaults to v2. */
150
+ /** Defaults to v1. v2 requires a compatible provider image/template. */
151
151
  api?: OpencodeApi;
152
152
  config?: Record<string, unknown>;
153
153
  plugins?: string[];
package/dist/types.d.ts CHANGED
@@ -63,7 +63,7 @@ export type RunRef = {
63
63
  workspaceId: string;
64
64
  id: string;
65
65
  };
66
- /** `v1` = OpenCode 1.x (`/event`, `/session/*`); `v2` = OpenCode 2 (`/api/*`) and the default. */
66
+ /** `v1` = OpenCode 1.x (`/event`, `/session/*`) and the default; `v2` = OpenCode 2 (`/api/*`). */
67
67
  export type OpencodeApi = "v1" | "v2";
68
68
  export type WaitOptions = {
69
69
  timeoutMs?: number;
@@ -272,7 +272,8 @@ export type WorkspaceCreateInput = {
272
272
  */
273
273
  config?: Record<string, unknown>;
274
274
  /**
275
- * OpenCode API generation served by the image. Defaults to `v2`.
275
+ * OpenCode API generation served by the image. Defaults to `v1`. Use `v2`
276
+ * only with an explicitly compatible image.
276
277
  */
277
278
  api?: OpencodeApi;
278
279
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitterm/sdk",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "files": [
5
5
  "dist"
6
6
  ],