@gitterm/sdk 0.1.2 → 0.2.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.
@@ -0,0 +1,19 @@
1
+ import { GittermError } from "../errors.js";
2
+ import type { AgentRunReply, RunWatchOptions } from "../types.js";
3
+ import type { DirectRun, DirectRunMessage, DirectWorkspace } from "./types.js";
4
+ export declare function directError(error: unknown): GittermError;
5
+ export declare function directRunOperations(assertWorkspace: (workspace: DirectWorkspace) => void, fetchImpl?: typeof fetch): {
6
+ messages(run: DirectRun): Promise<DirectRunMessage[]>;
7
+ cancel(run: DirectRun): Promise<{
8
+ cancelled: boolean;
9
+ }>;
10
+ events: (ref: DirectRun, options?: RunWatchOptions) => AsyncIterable<import("../types.js").AgentRunEvent<DirectRun>>;
11
+ wait: (ref: DirectRun, options?: import("../types.js").RunWaitOptions) => Promise<DirectRun>;
12
+ result: (ref: DirectRun, options?: import("../types.js").RunResultOptions) => Promise<import("../types.js").AgentRunResult<DirectRun>>;
13
+ get: (run: DirectRun) => Promise<DirectRun>;
14
+ watch: (run: DirectRun, options?: RunWatchOptions) => AsyncGenerator<DirectRun>;
15
+ respond: (run: DirectRun, input: {
16
+ requestId: string;
17
+ reply: AgentRunReply;
18
+ }) => Promise<DirectRun>;
19
+ };
@@ -1,3 +1,4 @@
1
+ import type { AgentRun, AgentRunMessage, OpencodeApi, RunWaitOptions } from "../types.js";
1
2
  export type DirectWorkspaceLifecycle = "ephemeral" | "persistent";
2
3
  export type DirectWorkspaceStatus = "pending" | "running" | "paused" | "failed" | "terminated" | "unknown";
3
4
  export type DirectProviderCapabilities = {
@@ -10,13 +11,13 @@ export type DirectProviderCapabilities = {
10
11
  };
11
12
  export type DirectApiModelCredential = {
12
13
  providerName: string;
13
- type?: "api";
14
+ source: "apiKey";
14
15
  apiKey: string;
15
16
  metadata?: Record<string, string>;
16
17
  };
17
18
  export type DirectOAuthModelCredential = {
18
19
  providerName: string;
19
- type: "oauth";
20
+ source: "oauth";
20
21
  refreshToken: string;
21
22
  /** May be omitted when OpenCode should refresh immediately. */
22
23
  accessToken?: string;
@@ -131,7 +132,11 @@ export type DirectWorkspaceCreateInput = {
131
132
  };
132
133
  lifecycle?: DirectWorkspaceLifecycle;
133
134
  environmentVariables?: Record<string, string>;
134
- modelCredentials?: DirectModelCredential[];
135
+ models?: {
136
+ default?: string;
137
+ inherit?: "none";
138
+ providers?: Record<string, Omit<DirectApiModelCredential, "providerName"> | Omit<DirectOAuthModelCredential, "providerName">>;
139
+ };
135
140
  setup?: DirectWorkspaceSetup;
136
141
  secretFiles?: DirectSecretFile[];
137
142
  /** Provider-specific attachment settings. */
@@ -141,6 +146,8 @@ export type DirectWorkspaceCreateInput = {
141
146
  /** Trusted integration context appended to the generated global AGENTS.md. */
142
147
  additionalAgentInstructions?: string;
143
148
  opencode?: {
149
+ /** Defaults to v1. v2 requires a compatible provider image/template. */
150
+ api?: OpencodeApi;
144
151
  config?: Record<string, unknown>;
145
152
  plugins?: string[];
146
153
  skills?: Array<{
@@ -162,6 +169,7 @@ export type DirectWorkspace = {
162
169
  status: DirectWorkspaceStatus;
163
170
  lifecycle: DirectWorkspaceLifecycle;
164
171
  runtime: DirectWorkspaceRuntime;
172
+ opencodeApi: OpencodeApi;
165
173
  setup: "not_requested" | "before_agent_complete" | "after_agent";
166
174
  createdAt: string;
167
175
  };
@@ -293,27 +301,21 @@ export type DirectRunCreateInput = {
293
301
  title?: string;
294
302
  agent?: string;
295
303
  model?: string;
296
- /** Reuse this native OpenCode session for conversational context. */
297
- sessionId?: string;
304
+ context?: {
305
+ type: "isolated";
306
+ } | {
307
+ type: "continue";
308
+ run: DirectRun;
309
+ };
310
+ waitForSetup?: boolean;
311
+ setupTimeoutMs?: number;
312
+ signal?: AbortSignal;
298
313
  };
299
- export type DirectRun = {
300
- id: string;
301
- workspaceId: string;
314
+ /** Contains runtime credentials. Encrypt when persisting; do not send to an untrusted UI. */
315
+ export type DirectRun = AgentRun & {
316
+ workspace: DirectWorkspace;
302
317
  sessionId: string;
303
318
  messageId: string;
304
- title: string;
305
- status: "running" | "retrying" | "completed" | "failed" | "cancelled";
306
- error: string | null;
307
- finalText: string | null;
308
- submittedAt: string;
309
- };
310
- export type DirectRunMessage = {
311
- id: string;
312
- role: "user" | "assistant";
313
- text: string;
314
- error: string | null;
315
- };
316
- export type DirectRunWaitOptions = {
317
- timeoutMs?: number;
318
- pollIntervalMs?: number;
319
319
  };
320
+ export type DirectRunMessage = AgentRunMessage;
321
+ export type DirectRunWaitOptions = RunWaitOptions;
package/dist/errors.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- export type GittermErrorCode = "NOT_LOGGED_IN" | "UNAUTHORIZED" | "NOT_FOUND" | "FORBIDDEN" | "BAD_REQUEST" | "CONFLICT" | "SERVER_ERROR" | "NETWORK" | CredentialErrorCode | WorkspaceLifecycleErrorCode;
1
+ import type { AgentRun } from "./types.js";
2
+ export type GittermErrorCode = "NOT_LOGGED_IN" | "UNAUTHORIZED" | "NOT_FOUND" | "FORBIDDEN" | "BAD_REQUEST" | "CONFLICT" | "SERVER_ERROR" | "NETWORK" | "ABORTED" | "TIMEOUT" | "INPUT_NOT_PENDING" | "INPUT_REQUIRED" | "RUN_FAILED" | "RUN_CANCELLED" | CredentialErrorCode | WorkspaceLifecycleErrorCode;
2
3
  export type CredentialErrorCode = "MODEL_CREDENTIAL_UNAVAILABLE" | "MODEL_CREDENTIAL_DUPLICATE_PROVIDER" | "MODEL_CREDENTIAL_INVALID" | "MODEL_CREDENTIAL_REQUIRED";
3
- export type WorkspaceLifecycleErrorCode = "WORKSPACE_TERMINATED" | "WORKSPACE_NON_RECOVERABLE" | "WORKSPACE_START_TIMEOUT" | "WORKSPACE_RESTART_FAILED";
4
+ export type WorkspaceLifecycleErrorCode = "WORKSPACE_NOT_RUNNING" | "WORKSPACE_TERMINATED" | "WORKSPACE_NON_RECOVERABLE" | "WORKSPACE_START_TIMEOUT" | "WORKSPACE_RESTART_FAILED";
5
+ export declare const WORKSPACE_LIFECYCLE_ERROR_CODES: readonly WorkspaceLifecycleErrorCode[];
4
6
  export declare class GittermError extends Error {
5
7
  readonly code: GittermErrorCode;
6
8
  readonly cause?: unknown;
@@ -14,3 +16,8 @@ export declare class WorkspaceLifecycleError extends GittermError {
14
16
  cause?: unknown;
15
17
  });
16
18
  }
19
+ /** result() could not produce a successful result. The run remains inspectable. */
20
+ export declare class AgentRunError<T extends AgentRun = AgentRun> extends GittermError {
21
+ readonly run: T;
22
+ constructor(run: T, code: "INPUT_REQUIRED" | "RUN_FAILED" | "RUN_CANCELLED");
23
+ }
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { DEFAULT_GITTERM_SERVER_URL, getConfigPath, loadConfig, loadConfigSync,
3
3
  export type { CliConfig } from "./config.js";
4
4
  export { loginWithDeviceCode } from "./device-login.js";
5
5
  export type { DeviceCodeInfo, LoginWithDeviceCodeOptions } from "./device-login.js";
6
- export { GittermError, WorkspaceLifecycleError } from "./errors.js";
6
+ export { AgentRunError, GittermError, WorkspaceLifecycleError } from "./errors.js";
7
7
  export { createGittermWorkspaceClient, getWorkspaceEnvironment, type GittermWorkspaceClient, type WorkspaceClientOptions, type WorkspaceEnvironment, type WorkspacePort, type WorkspaceSelf, } from "./workspace-client.js";
8
8
  export type { CredentialErrorCode, GittermErrorCode, WorkspaceLifecycleErrorCode, } from "./errors.js";
9
- export type { AgentRun, AgentRunCreateInput, AgentRunMessage, AgentRunStatus, AgentType, AgentKey, AuthStatus, BuiltInAgentKey, CloudProvider, ProviderKey, Workspace, WorkspaceCreateInput, WorkspaceCreateResult, WorkspaceCatalog, WorkspaceEnsureRunningResult, WorkspaceHostingType, WorkspaceListOptions, WorkspaceListResult, WorkspaceRestartResult, WorkspaceRuntimeAccess, WorkspaceStatus, WorkspaceSetupStatus, ModelCredential, ModelProviderInfo, WorkspaceModelCredentialInput, WorkspacePauseResult, WorkspaceTerminateResult, WorkspaceProviderSelection, } from "./types.js";
9
+ export type { AgentPermissionRequest, AgentQuestion, AgentQuestionOption, AgentQuestionRequest, AgentRun, AgentRunCreateInput, AgentRunInputRequest, AgentRunMessage, AgentRunMessagePart, AgentRunReply, AgentRunStatus, AgentRunEvent, AgentRunResult, AgentRunReplyPermission, AgentRunReplyQuestion, RunResultOptions, RunRef, RunWaitOptions, RunWatchOptions, OpencodeApi, AgentType, AgentKey, AuthStatus, BuiltInAgentKey, CloudProvider, ProviderKey, Workspace, WorkspaceCreateInput, WorkspaceCreateResult, WorkspaceCatalog, WorkspaceEnsureRunningResult, WorkspaceHostingType, WorkspaceListOptions, WorkspaceListResult, WorkspaceRestartResult, WorkspaceRuntimeAccess, WorkspaceStatus, WorkspaceSetupStatus, ModelCredential, ModelProviderInfo, ModelInfo, ModelCredentialSource, WorkspaceModelsInput, WorkspaceModelAccess, WorkspacePauseResult, WorkspaceTerminateResult, WorkspaceProviderSelection, } from "./types.js";