@anthonyhaussman/opencode-agy-auth 1.5.9 → 1.5.18
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 +49 -17
- package/agy-plugin/agents/opencode.md +14 -0
- package/agy-plugin/bridge-proxy.mjs +92 -0
- package/agy-plugin/mcp_config.json +1 -0
- package/agy-plugin/plugin.json +5 -0
- package/dist/index.d.ts +3 -5
- package/dist/index.js +7591 -6009
- package/dist/index.js.map +1 -1
- package/dist/sdk-placeholder.js +15 -0
- package/dist/sdk-placeholder.js.map +1 -0
- package/dist/src/acp/agy-plugin.d.ts +43 -0
- package/dist/src/acp/binary.d.ts +40 -0
- package/dist/src/acp/constants.d.ts +32 -0
- package/dist/src/acp/debug.d.ts +11 -0
- package/dist/src/acp/errors.d.ts +14 -0
- package/dist/src/acp/language-model.d.ts +35 -0
- package/dist/src/acp/live-session.d.ts +99 -0
- package/dist/src/acp/mcp-bridge.d.ts +66 -0
- package/dist/src/acp/permission.d.ts +9 -0
- package/dist/src/acp/process.d.ts +178 -0
- package/dist/src/acp/register-auth.d.ts +60 -0
- package/dist/src/acp/register-catalog.d.ts +32 -0
- package/dist/src/acp/register.d.ts +34 -0
- package/dist/src/acp/rpc.d.ts +35 -0
- package/dist/src/acp/sdk-placeholder.d.ts +4 -0
- package/dist/src/acp/session-lock.d.ts +16 -0
- package/dist/src/acp/session-sync.d.ts +40 -0
- package/dist/src/acp/stream-map.d.ts +40 -0
- package/dist/src/plugin/tos-warning.d.ts +4 -1
- package/dist/src/plugin/types.d.ts +55 -20
- package/dist/src/sdk/agy-cli-version.d.ts +1 -1
- package/package.json +11 -7
- package/dist/src/plugin.d.ts +0 -8
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/acp/sdk-placeholder.ts
|
|
2
|
+
var MESSAGE = "google-agy-acp models are provided by the opencode-agy-auth plugin. Make sure the plugin is enabled and runs on OpenCode v2.4.0 or newer.";
|
|
3
|
+
function createGoogleAgyAcp() {
|
|
4
|
+
return {
|
|
5
|
+
languageModel() {
|
|
6
|
+
throw new Error(MESSAGE);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
var sdk_placeholder_default = createGoogleAgyAcp;
|
|
11
|
+
export {
|
|
12
|
+
createGoogleAgyAcp,
|
|
13
|
+
sdk_placeholder_default as default
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=sdk-placeholder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/acp/sdk-placeholder.ts"],"sourcesContent":["/**\n * AI SDK package placeholder for the google-agy-acp provider.\n *\n * The provider record points OpenCode at this module (`aisdk:file://...`) so\n * OpenCode never falls back to installing an npm package. The real language\n * model is supplied by the plugin's `aisdk.hook(\"sdk\")` handler; this factory\n * only runs if that hook did not, and then fails with a clear message.\n */\nconst MESSAGE =\n \"google-agy-acp models are provided by the opencode-agy-auth plugin. Make sure the plugin is enabled and runs on OpenCode v2.4.0 or newer.\";\n\nexport function createGoogleAgyAcp(): { languageModel(modelId: string): never } {\n return {\n languageModel(): never {\n throw new Error(MESSAGE);\n },\n };\n}\n\nexport default createGoogleAgyAcp;\n"],"mappings":";AAQA,IAAM,UACJ;AAEK,SAAS,qBAAgE;AAC9E,SAAO;AAAA,IACL,gBAAuB;AACrB,YAAM,IAAI,MAAM,OAAO;AAAA,IACzB;AAAA,EACF;AACF;AAEA,IAAO,0BAAQ;","names":[]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type ExecFn } from "./binary";
|
|
2
|
+
/** Bump whenever any file under agy-plugin/ changes (must equal plugin.json version). */
|
|
3
|
+
export declare const AGY_PLUGIN_VERSION = "1.0.1";
|
|
4
|
+
export declare const AGY_PLUGIN_NOTICE = "google-agy-acp installed the agy plugin \"opencode-bridge\" into agy's global plugins (~/.gemini/config/plugins/) so agy can call OpenCode tools. Remove it with: agy plugin uninstall opencode-bridge";
|
|
5
|
+
export interface AgyPluginStamp {
|
|
6
|
+
version: string;
|
|
7
|
+
nodePath: string;
|
|
8
|
+
dir: string;
|
|
9
|
+
installedAt: number;
|
|
10
|
+
/** Extra env for the bridge process (BUN_BE_BUN under compiled OpenCode). */
|
|
11
|
+
launchEnv?: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Compiled OpenCode is a bun binary: running it with a script path starts
|
|
15
|
+
* OpenCode itself unless BUN_BE_BUN=1 makes it behave as plain bun.
|
|
16
|
+
*/
|
|
17
|
+
export declare function bridgeLaunchEnv(versions?: {
|
|
18
|
+
bun?: string;
|
|
19
|
+
}): Record<string, string> | undefined;
|
|
20
|
+
export type AgyPluginStatus = "installed" | "updated" | "current";
|
|
21
|
+
export declare function agyPluginTemplateDir(): string;
|
|
22
|
+
export declare function materializeAgyPlugin(o: {
|
|
23
|
+
templateDir: string;
|
|
24
|
+
dataDir: string;
|
|
25
|
+
nodePath: string;
|
|
26
|
+
version: string;
|
|
27
|
+
launchEnv?: Record<string, string>;
|
|
28
|
+
}): Promise<string>;
|
|
29
|
+
export declare function ensureAgyPlugin(o: {
|
|
30
|
+
agyPath: string;
|
|
31
|
+
templateDir?: string;
|
|
32
|
+
dataDir?: string;
|
|
33
|
+
nodePath?: string;
|
|
34
|
+
launchEnv?: Record<string, string>;
|
|
35
|
+
exec?: ExecFn;
|
|
36
|
+
}): Promise<{
|
|
37
|
+
status: AgyPluginStatus;
|
|
38
|
+
dir: string;
|
|
39
|
+
version: string;
|
|
40
|
+
}>;
|
|
41
|
+
export declare function createAgyPluginInstaller(o: Parameters<typeof ensureAgyPlugin>[0] & {
|
|
42
|
+
notify: (msg: string) => void;
|
|
43
|
+
}): () => Promise<void>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { AcpModelInfo } from "./process";
|
|
2
|
+
export type ExecFn = (file: string, args: string[], opts?: {
|
|
3
|
+
env?: NodeJS.ProcessEnv;
|
|
4
|
+
}) => Promise<{
|
|
5
|
+
stdout: string;
|
|
6
|
+
stderr: string;
|
|
7
|
+
}>;
|
|
8
|
+
export type AgyProbe = {
|
|
9
|
+
status: "missing";
|
|
10
|
+
} | {
|
|
11
|
+
status: "too_old";
|
|
12
|
+
path: string;
|
|
13
|
+
version: string;
|
|
14
|
+
} | {
|
|
15
|
+
status: "ready";
|
|
16
|
+
path: string;
|
|
17
|
+
version: string;
|
|
18
|
+
} | {
|
|
19
|
+
status: "failed";
|
|
20
|
+
path: string;
|
|
21
|
+
error: string;
|
|
22
|
+
};
|
|
23
|
+
export declare function compareVersions(a: string, b: string): number;
|
|
24
|
+
/**
|
|
25
|
+
* OPENCODE_AGY_PATH wins when set and executable; otherwise `agy` is looked up
|
|
26
|
+
* on PATH. A non-executable override falls back to the PATH lookup.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveAgyPath(env?: NodeJS.ProcessEnv): Promise<string | null>;
|
|
29
|
+
export declare const defaultExec: ExecFn;
|
|
30
|
+
export declare function probeAgy(env?: NodeJS.ProcessEnv, exec?: ExecFn): Promise<AgyProbe>;
|
|
31
|
+
/**
|
|
32
|
+
* Parses `agy --output-format stream-json models` NDJSON output. Returns the
|
|
33
|
+
* models from the first `command_result` line, or undefined when no such
|
|
34
|
+
* line exists (unrecognized output).
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseAgyModelsOutput(stdout: string): AcpModelInfo[] | undefined;
|
|
37
|
+
export declare function listAgyModels(agyPath: string, env: NodeJS.ProcessEnv, exec?: ExecFn): Promise<{
|
|
38
|
+
models: AcpModelInfo[];
|
|
39
|
+
recognized: boolean;
|
|
40
|
+
}>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare const AGY_ACP_PROVIDER_ID = "google-agy-acp";
|
|
2
|
+
export declare const MIN_AGY_VERSION = "1.5.10";
|
|
3
|
+
export declare const STARTUP_TIMEOUT_MS = 30000;
|
|
4
|
+
export declare const IDLE_TIMEOUT_MS = 300000;
|
|
5
|
+
/** How long plugin setup waits for the first `agy models` before returning. */
|
|
6
|
+
export declare const MODELS_STARTUP_WAIT_MS = 10000;
|
|
7
|
+
export declare const BRIDGE_CONNECT_TIMEOUT_MS = 10000;
|
|
8
|
+
/** How long a cancelled agy turn may take to settle before its process is disposed. */
|
|
9
|
+
export declare const CANCEL_SETTLE_TIMEOUT_MS = 10000;
|
|
10
|
+
export declare const MCP_HARD_TIMEOUT_MS = 180000;
|
|
11
|
+
export declare const MCP_SOFT_TIMEOUT_MS = 170000;
|
|
12
|
+
export declare const AGY_PLUGIN_NAME = "opencode-bridge";
|
|
13
|
+
export declare const AGY_AGENT_NAME = "opencode";
|
|
14
|
+
export declare const BRIDGE_SERVER_KEY = "bridge";
|
|
15
|
+
export declare const BRIDGE_SERVER_NAME = "opencode-bridge_bridge";
|
|
16
|
+
export declare const BRIDGE_TOOL_NAME = "call_mcp_tool";
|
|
17
|
+
export declare const ALLOWED_BUILTINS: ReadonlySet<string>;
|
|
18
|
+
export declare const AGY_SPAWN_ARGS: readonly string[];
|
|
19
|
+
export declare const BRIDGE_URL_ENV = "AGY_ACP_BRIDGE_URL";
|
|
20
|
+
export declare const BRIDGE_TOKEN_ENV = "AGY_ACP_BRIDGE_TOKEN";
|
|
21
|
+
export declare const AGY_API_KEY_ENV = "GEMINI_API_KEY";
|
|
22
|
+
export declare const AGY_API_KEY_OVERRIDE_ENV = "GOOGLE_API_KEY";
|
|
23
|
+
export declare const AGY_ADC_ENV = "AGY_ADC_AUTH";
|
|
24
|
+
export declare const THOUGHT_LEVEL_CONFIG_ID = "thought_level";
|
|
25
|
+
export declare const MODE_CONFIG_ID = "mode";
|
|
26
|
+
export type AgyTier = "low" | "medium" | "high";
|
|
27
|
+
export declare const STILL_RUNNING_TEXT = "Still running in OpenCode (waiting on execution or user permission); the result will be sent with the next message.";
|
|
28
|
+
export declare const CANCELLED_TEXT = "Cancelled by user";
|
|
29
|
+
export declare const SESSION_HEADER = "x-opencode-session-id";
|
|
30
|
+
export declare const KIND_HEADER = "x-opencode-request-kind";
|
|
31
|
+
export declare function agyAcpDataDir(env?: NodeJS.ProcessEnv): string;
|
|
32
|
+
export declare function agyMcpSchemaDir(home?: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type AgyDebugLog = (event: string, detail?: string) => void;
|
|
2
|
+
/** Env switch for the opt-in agy ACP debug log. */
|
|
3
|
+
export declare const AGY_ACP_DEBUG_ENV = "AGY_ACP_DEBUG";
|
|
4
|
+
/** Optional override for the debug log path. */
|
|
5
|
+
export declare const AGY_ACP_DEBUG_FILE_ENV = "AGY_ACP_DEBUG_FILE";
|
|
6
|
+
/**
|
|
7
|
+
* Returns a logger that appends timestamped lines to a private file when
|
|
8
|
+
* AGY_ACP_DEBUG=1, or undefined when debugging is off. The logger redacts the
|
|
9
|
+
* given secrets and never throws.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createAgyDebugLog(env?: NodeJS.ProcessEnv, secrets?: (string | undefined)[]): AgyDebugLog | undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type AgyErrorCode = "tos_disabled" | "auth_required" | "missing" | "too_old" | "plugin_install" | "bridge_unreachable" | "crash" | "other";
|
|
2
|
+
export declare const BRIDGE_NOT_CONNECTED_TEXT = "agy did not connect to the OpenCode tool bridge. Check that \"agy plugin list\" shows opencode-bridge, then retry.";
|
|
3
|
+
export declare const TOS_DISABLED_TEXT = "Google disabled Antigravity access for this account for a Terms of Service violation. Submit an appeal to Google, or switch the google-agy-acp provider to the Gemini API key or Vertex (Agent Platform) method.";
|
|
4
|
+
/** Error with a known classification, raised by the provider itself. */
|
|
5
|
+
export declare class AgyAcpError extends Error {
|
|
6
|
+
readonly code: AgyErrorCode;
|
|
7
|
+
constructor(code: AgyErrorCode, message: string);
|
|
8
|
+
}
|
|
9
|
+
export declare function classifyAgyError(e: unknown): {
|
|
10
|
+
code: AgyErrorCode;
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
/** Converts any failure into the Error value carried by an AI SDK `error` stream part. */
|
|
14
|
+
export declare function toAgyError(e: unknown): AgyAcpError;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamPart } from "@ai-sdk/provider";
|
|
2
|
+
import { type AgyAcpDeps } from "./live-session";
|
|
3
|
+
export type { AgyAcpDeps } from "./live-session";
|
|
4
|
+
export { LiveSession, LiveTurn } from "./live-session";
|
|
5
|
+
type Part = LanguageModelV3StreamPart;
|
|
6
|
+
export declare class AgyAcpLanguageModel implements LanguageModelV3 {
|
|
7
|
+
readonly modelId: string;
|
|
8
|
+
private readonly deps;
|
|
9
|
+
readonly specificationVersion: "v3";
|
|
10
|
+
readonly provider = "google-agy-acp";
|
|
11
|
+
readonly supportedUrls: {};
|
|
12
|
+
constructor(modelId: string, deps: AgyAcpDeps);
|
|
13
|
+
doStream(o: LanguageModelV3CallOptions): Promise<{
|
|
14
|
+
stream: ReadableStream<Part>;
|
|
15
|
+
}>;
|
|
16
|
+
doGenerate(o: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
|
|
17
|
+
private sessionParams;
|
|
18
|
+
private run;
|
|
19
|
+
private runSession;
|
|
20
|
+
private runLocked;
|
|
21
|
+
private runThrowaway;
|
|
22
|
+
private resolveToolResults;
|
|
23
|
+
/** Drains the open turn (if any), then sends the next prompt when there is something to send. */
|
|
24
|
+
private step;
|
|
25
|
+
/**
|
|
26
|
+
* Streams one turn until it settles or yields to OpenCode. Returns the prompt
|
|
27
|
+
* result when the turn settled normally; otherwise the step was already ended.
|
|
28
|
+
*/
|
|
29
|
+
private drive;
|
|
30
|
+
private consume;
|
|
31
|
+
private onAbort;
|
|
32
|
+
private writeRecord;
|
|
33
|
+
private markInterrupted;
|
|
34
|
+
private save;
|
|
35
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { LanguageModelV3StreamPart } from "@ai-sdk/provider";
|
|
2
|
+
import { McpBridge, PendingTools, type BridgeToolDef } from "./mcp-bridge";
|
|
3
|
+
import { AgyAcpProcess, type AcpContentBlock, type AcpModelInfo, type AgyAuthMethod, type AgyProcessPool, type NewSessionParams, type PoolEntry, type PromptResult } from "./process";
|
|
4
|
+
import type { SessionRecord, SessionStore } from "./session-sync";
|
|
5
|
+
import { StreamMapper } from "./stream-map";
|
|
6
|
+
/** One resolved credential for a call. `identity` is non-secret (never the raw key). */
|
|
7
|
+
export interface AgyAuth {
|
|
8
|
+
method: AgyAuthMethod;
|
|
9
|
+
apiKey?: string;
|
|
10
|
+
identity: string;
|
|
11
|
+
}
|
|
12
|
+
export interface AgyAcpDeps {
|
|
13
|
+
pool: AgyProcessPool<LiveSession>;
|
|
14
|
+
store: SessionStore;
|
|
15
|
+
agyPath: string;
|
|
16
|
+
cwd: string;
|
|
17
|
+
env: NodeJS.ProcessEnv;
|
|
18
|
+
/** Resolves the active credential once per call. */
|
|
19
|
+
auth: () => Promise<AgyAuth>;
|
|
20
|
+
ensurePlugin: () => Promise<void>;
|
|
21
|
+
onModels?: (models: AcpModelInfo[]) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Reports the auth outcome of starting agy: `undefined` after a successful
|
|
24
|
+
* `authenticate` + `session/new`, else the auth-required message.
|
|
25
|
+
*/
|
|
26
|
+
onAuthStatus?: (failure: string | undefined) => void;
|
|
27
|
+
log: (level: "info" | "warn" | "error", msg: string) => void;
|
|
28
|
+
bridgeConnectTimeoutMs?: number;
|
|
29
|
+
softTimeoutMs?: number;
|
|
30
|
+
cancelSettleTimeoutMs?: number;
|
|
31
|
+
/** agy idle-kill delay (tests); defaults to IDLE_TIMEOUT_MS. */
|
|
32
|
+
idleTimeoutMs?: number;
|
|
33
|
+
}
|
|
34
|
+
export type TurnEvent = {
|
|
35
|
+
kind: "part";
|
|
36
|
+
part: LanguageModelV3StreamPart;
|
|
37
|
+
bridgeCallId?: string;
|
|
38
|
+
} | {
|
|
39
|
+
kind: "violation";
|
|
40
|
+
toolName: string;
|
|
41
|
+
};
|
|
42
|
+
/** Small edge-triggered wake-up primitive. */
|
|
43
|
+
declare class Signal {
|
|
44
|
+
private waiters;
|
|
45
|
+
wait(): Promise<void>;
|
|
46
|
+
fire(): void;
|
|
47
|
+
}
|
|
48
|
+
/** One agy `session/prompt`; it can outlive a single doStream (open across tool calls). */
|
|
49
|
+
export declare class LiveTurn {
|
|
50
|
+
readonly queue: TurnEvent[];
|
|
51
|
+
readonly mapper: StreamMapper;
|
|
52
|
+
readonly parked: Set<string>;
|
|
53
|
+
readonly signal: Signal;
|
|
54
|
+
settled?: {
|
|
55
|
+
result?: PromptResult;
|
|
56
|
+
error?: unknown;
|
|
57
|
+
};
|
|
58
|
+
aborted?: unknown;
|
|
59
|
+
done: Promise<void>;
|
|
60
|
+
detachAbort?: () => void;
|
|
61
|
+
interruptWrite?: Promise<void>;
|
|
62
|
+
setAbortSignal(signal: AbortSignal | undefined, onAbort: (reason: unknown) => void): void;
|
|
63
|
+
}
|
|
64
|
+
export interface LiveSessionConfig {
|
|
65
|
+
key: string | undefined;
|
|
66
|
+
fingerprint: string;
|
|
67
|
+
tools: BridgeToolDef[];
|
|
68
|
+
session: NewSessionParams;
|
|
69
|
+
auth: AgyAuth;
|
|
70
|
+
}
|
|
71
|
+
/** agy process + MCP bridge + agy session for one OpenCode session. */
|
|
72
|
+
export declare class LiveSession implements PoolEntry {
|
|
73
|
+
readonly proc: AgyAcpProcess;
|
|
74
|
+
readonly bridge: McpBridge;
|
|
75
|
+
readonly pending: PendingTools;
|
|
76
|
+
readonly config: LiveSessionConfig;
|
|
77
|
+
private readonly log;
|
|
78
|
+
agySessionId?: string;
|
|
79
|
+
turn?: LiveTurn;
|
|
80
|
+
dead: boolean;
|
|
81
|
+
record?: SessionRecord;
|
|
82
|
+
readonly claimed: Set<string>;
|
|
83
|
+
readonly callOrder: string[];
|
|
84
|
+
private readonly toolCalls;
|
|
85
|
+
private readonly deadListeners;
|
|
86
|
+
private constructor();
|
|
87
|
+
static create(deps: AgyAcpDeps, config: LiveSessionConfig): Promise<LiveSession>;
|
|
88
|
+
/** Runs `listener` once the agy process has exited (immediately if it already has). */
|
|
89
|
+
onDead(listener: () => void): void;
|
|
90
|
+
/** Opens a new agy session (closing the current one, if any). */
|
|
91
|
+
openSession(): Promise<AcpModelInfo[]>;
|
|
92
|
+
private onPermission;
|
|
93
|
+
private markClaimed;
|
|
94
|
+
startTurn(blocks: AcpContentBlock[]): LiveTurn;
|
|
95
|
+
/** Cancels the open turn (if any) and fails every pending bridge call. */
|
|
96
|
+
cancelTurn(): void;
|
|
97
|
+
dispose(): Promise<void>;
|
|
98
|
+
}
|
|
99
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export type JSONSchema7 = Record<string, unknown>;
|
|
2
|
+
export interface BridgeToolDef {
|
|
3
|
+
name: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
inputSchema: JSONSchema7;
|
|
6
|
+
}
|
|
7
|
+
export interface BridgeCall {
|
|
8
|
+
/** ACP toolCallId. */
|
|
9
|
+
callId: string;
|
|
10
|
+
toolName: string;
|
|
11
|
+
input: unknown;
|
|
12
|
+
}
|
|
13
|
+
export type ToolOutcome = {
|
|
14
|
+
text: string;
|
|
15
|
+
isError: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare class PendingTools {
|
|
18
|
+
private readonly opts;
|
|
19
|
+
private readonly entries;
|
|
20
|
+
private late;
|
|
21
|
+
constructor(opts: {
|
|
22
|
+
softTimeoutMs: number | null;
|
|
23
|
+
/** Called when the MCP client claims an expected call (agy's tools/call arrived). */
|
|
24
|
+
onClaim?: (callId: string) => void;
|
|
25
|
+
});
|
|
26
|
+
get size(): number;
|
|
27
|
+
expect(call: BridgeCall): void;
|
|
28
|
+
/** First unclaimed entry for `toolName` with equal input, else the first unclaimed one for `toolName`. */
|
|
29
|
+
private find;
|
|
30
|
+
claim(toolName: string, input: unknown): Promise<ToolOutcome>;
|
|
31
|
+
/**
|
|
32
|
+
* agy's call was refused before reaching OpenCode (invalid input), but OpenCode
|
|
33
|
+
* already saw the tool call and may still run it. Claims the matching entry as
|
|
34
|
+
* soft-timed-out, so OpenCode's result is delivered later as a late result and
|
|
35
|
+
* the entry can never be handed to another call.
|
|
36
|
+
*/
|
|
37
|
+
abandon(toolName: string, input: unknown): void;
|
|
38
|
+
resolve(callId: string, outcome: ToolOutcome): boolean;
|
|
39
|
+
rejectAll(text: string): void;
|
|
40
|
+
takeLateResults(): Array<{
|
|
41
|
+
callId: string;
|
|
42
|
+
outcome: ToolOutcome;
|
|
43
|
+
}>;
|
|
44
|
+
}
|
|
45
|
+
export declare class McpBridge {
|
|
46
|
+
readonly token: string;
|
|
47
|
+
private readonly makePair;
|
|
48
|
+
private readonly log;
|
|
49
|
+
private clientSeen;
|
|
50
|
+
private waiters;
|
|
51
|
+
private closed;
|
|
52
|
+
private current;
|
|
53
|
+
private http;
|
|
54
|
+
url: string;
|
|
55
|
+
private constructor();
|
|
56
|
+
static start(opts: {
|
|
57
|
+
tools: BridgeToolDef[];
|
|
58
|
+
pending: PendingTools;
|
|
59
|
+
log?: (msg: string) => void;
|
|
60
|
+
}): Promise<McpBridge>;
|
|
61
|
+
private readBody;
|
|
62
|
+
private handle;
|
|
63
|
+
private markClient;
|
|
64
|
+
waitForClient(timeoutMs: number): Promise<boolean>;
|
|
65
|
+
close(): Promise<void>;
|
|
66
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AcpPermissionRequest, AcpPermissionResponse } from "./process";
|
|
2
|
+
/**
|
|
3
|
+
* Allows only `call_mcp_tool` aimed at the OpenCode bridge; rejects everything
|
|
4
|
+
* else. Replies `cancelled` only when no option of the needed kind exists.
|
|
5
|
+
*/
|
|
6
|
+
export declare function decidePermission(req: AcpPermissionRequest): {
|
|
7
|
+
response: AcpPermissionResponse;
|
|
8
|
+
allowed: boolean;
|
|
9
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { type AgyTier } from "./constants";
|
|
2
|
+
export type AgyAuthMethod = "oauth-personal" | "oauth-business" | "gemini-api-key" | "agent-platform";
|
|
3
|
+
export type AcpContentBlock = {
|
|
4
|
+
type: "text";
|
|
5
|
+
text: string;
|
|
6
|
+
} | {
|
|
7
|
+
type: "image";
|
|
8
|
+
data: string;
|
|
9
|
+
mimeType: string;
|
|
10
|
+
};
|
|
11
|
+
export interface AcpToolCall {
|
|
12
|
+
toolCallId: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
title?: string;
|
|
15
|
+
kind?: string;
|
|
16
|
+
status?: "pending" | "in_progress" | "completed" | "failed";
|
|
17
|
+
rawInput?: unknown;
|
|
18
|
+
rawOutput?: unknown;
|
|
19
|
+
content?: Array<{
|
|
20
|
+
type: "content";
|
|
21
|
+
content: {
|
|
22
|
+
type: "text";
|
|
23
|
+
text: string;
|
|
24
|
+
};
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
export type AcpSessionUpdate = {
|
|
28
|
+
sessionUpdate: "agent_message_chunk";
|
|
29
|
+
content: {
|
|
30
|
+
type: string;
|
|
31
|
+
text?: string;
|
|
32
|
+
};
|
|
33
|
+
} | {
|
|
34
|
+
sessionUpdate: "agent_thought_chunk";
|
|
35
|
+
content: {
|
|
36
|
+
type: string;
|
|
37
|
+
text?: string;
|
|
38
|
+
};
|
|
39
|
+
} | ({
|
|
40
|
+
sessionUpdate: "tool_call";
|
|
41
|
+
} & AcpToolCall) | ({
|
|
42
|
+
sessionUpdate: "tool_call_update";
|
|
43
|
+
} & AcpToolCall) | {
|
|
44
|
+
sessionUpdate: "usage_update";
|
|
45
|
+
used: number;
|
|
46
|
+
size: number;
|
|
47
|
+
} | {
|
|
48
|
+
sessionUpdate: "session_info_update";
|
|
49
|
+
title?: string;
|
|
50
|
+
} | {
|
|
51
|
+
sessionUpdate: "available_commands_update";
|
|
52
|
+
availableCommands?: unknown[];
|
|
53
|
+
} | {
|
|
54
|
+
sessionUpdate: "current_mode_update";
|
|
55
|
+
currentModeId?: string;
|
|
56
|
+
} | {
|
|
57
|
+
sessionUpdate: "plan";
|
|
58
|
+
entries?: unknown[];
|
|
59
|
+
};
|
|
60
|
+
export interface AcpModelInfo {
|
|
61
|
+
modelId: string;
|
|
62
|
+
name?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface AcpInitializeResult {
|
|
65
|
+
protocolVersion?: number;
|
|
66
|
+
agentCapabilities?: {
|
|
67
|
+
loadSession?: boolean;
|
|
68
|
+
[key: string]: unknown;
|
|
69
|
+
};
|
|
70
|
+
authMethods?: Array<{
|
|
71
|
+
id: string;
|
|
72
|
+
name?: string;
|
|
73
|
+
}>;
|
|
74
|
+
[key: string]: unknown;
|
|
75
|
+
}
|
|
76
|
+
export interface AgyProcessOptions {
|
|
77
|
+
binaryPath: string;
|
|
78
|
+
args?: readonly string[];
|
|
79
|
+
cwd: string;
|
|
80
|
+
env: NodeJS.ProcessEnv;
|
|
81
|
+
startupTimeoutMs?: number;
|
|
82
|
+
idleTimeoutMs?: number;
|
|
83
|
+
authMethod?: AgyAuthMethod;
|
|
84
|
+
}
|
|
85
|
+
export interface NewSessionParams {
|
|
86
|
+
cwd: string;
|
|
87
|
+
systemPromptAppend?: string;
|
|
88
|
+
modelId?: string;
|
|
89
|
+
tier?: AgyTier;
|
|
90
|
+
}
|
|
91
|
+
export interface NewSessionResult {
|
|
92
|
+
sessionId: string;
|
|
93
|
+
models: AcpModelInfo[];
|
|
94
|
+
currentModelId?: string;
|
|
95
|
+
}
|
|
96
|
+
export interface AcpUsage {
|
|
97
|
+
inputTokens?: number;
|
|
98
|
+
outputTokens?: number;
|
|
99
|
+
cachedReadTokens?: number;
|
|
100
|
+
cachedWriteTokens?: number;
|
|
101
|
+
thoughtTokens?: number;
|
|
102
|
+
totalTokens?: number;
|
|
103
|
+
}
|
|
104
|
+
export interface PromptResult {
|
|
105
|
+
stopReason: "end_turn" | "max_tokens" | "max_turn_requests" | "refusal" | "cancelled";
|
|
106
|
+
usage?: AcpUsage;
|
|
107
|
+
}
|
|
108
|
+
export interface AcpPermissionOption {
|
|
109
|
+
optionId: string;
|
|
110
|
+
name?: string;
|
|
111
|
+
kind: "allow_once" | "allow_always" | "reject_once" | "reject_always";
|
|
112
|
+
}
|
|
113
|
+
export interface AcpPermissionRequest {
|
|
114
|
+
sessionId: string;
|
|
115
|
+
toolCall: AcpToolCall;
|
|
116
|
+
options: AcpPermissionOption[];
|
|
117
|
+
}
|
|
118
|
+
export type AcpPermissionResponse = {
|
|
119
|
+
outcome: {
|
|
120
|
+
outcome: "selected";
|
|
121
|
+
optionId: string;
|
|
122
|
+
} | {
|
|
123
|
+
outcome: "cancelled";
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
export interface AgyExit {
|
|
127
|
+
code: number | null;
|
|
128
|
+
signal: string | null;
|
|
129
|
+
stderrTail: string;
|
|
130
|
+
}
|
|
131
|
+
/** Returns a copy of `base` carrying the credential agy should use for `authMethod`. */
|
|
132
|
+
export declare function applyAgyAuthEnv(base: NodeJS.ProcessEnv, o: {
|
|
133
|
+
authMethod: AgyAuthMethod;
|
|
134
|
+
apiKey?: string;
|
|
135
|
+
}): NodeJS.ProcessEnv;
|
|
136
|
+
export declare function buildAgyEnv(base: NodeJS.ProcessEnv, o: {
|
|
137
|
+
bridgeUrl: string;
|
|
138
|
+
bridgeToken: string;
|
|
139
|
+
authMethod: AgyAuthMethod;
|
|
140
|
+
apiKey?: string;
|
|
141
|
+
}): NodeJS.ProcessEnv;
|
|
142
|
+
export declare class AgyAcpProcess {
|
|
143
|
+
private readonly child;
|
|
144
|
+
private readonly conn;
|
|
145
|
+
private readonly idleTimeoutMs;
|
|
146
|
+
initializeResult: AcpInitializeResult;
|
|
147
|
+
readonly exited: Promise<AgyExit>;
|
|
148
|
+
private readonly updateHandlers;
|
|
149
|
+
private permissionHandler?;
|
|
150
|
+
private idleTimer?;
|
|
151
|
+
private inflightPrompts;
|
|
152
|
+
private hasExited;
|
|
153
|
+
private disposePromise?;
|
|
154
|
+
private constructor();
|
|
155
|
+
static start(opts: AgyProcessOptions): Promise<AgyAcpProcess>;
|
|
156
|
+
touch(): void;
|
|
157
|
+
private rpc;
|
|
158
|
+
newSession(p: NewSessionParams): Promise<NewSessionResult>;
|
|
159
|
+
prompt(sessionId: string, blocks: AcpContentBlock[]): Promise<PromptResult>;
|
|
160
|
+
cancel(sessionId: string): void;
|
|
161
|
+
closeSession(sessionId: string): Promise<void>;
|
|
162
|
+
onUpdate(sessionId: string, handler: (u: AcpSessionUpdate) => void): () => void;
|
|
163
|
+
onPermissionRequest(handler: (r: AcpPermissionRequest) => AcpPermissionResponse | Promise<AcpPermissionResponse>): void;
|
|
164
|
+
dispose(): Promise<void>;
|
|
165
|
+
private doDispose;
|
|
166
|
+
}
|
|
167
|
+
export interface PoolEntry {
|
|
168
|
+
dispose(): Promise<void>;
|
|
169
|
+
/** Optional: called once the entry can no longer serve requests; the pool then drops it. */
|
|
170
|
+
onDead?(listener: () => void): void;
|
|
171
|
+
}
|
|
172
|
+
export declare class AgyProcessPool<T extends PoolEntry> {
|
|
173
|
+
private readonly slots;
|
|
174
|
+
acquire(key: string, fingerprint: string, create: () => Promise<T>): Promise<T>;
|
|
175
|
+
get(key: string): T | undefined;
|
|
176
|
+
release(key: string): Promise<void>;
|
|
177
|
+
disposeAll(): Promise<void>;
|
|
178
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { OpenCodeV2PluginContext } from "../plugin/types";
|
|
2
|
+
import type { AgyProbe } from "./binary";
|
|
3
|
+
import type { AgyAuthMethod } from "./process";
|
|
4
|
+
export type AgyAcpStatus = {
|
|
5
|
+
status: "checking";
|
|
6
|
+
} | {
|
|
7
|
+
status: "missing";
|
|
8
|
+
message: string;
|
|
9
|
+
} | {
|
|
10
|
+
status: "failed";
|
|
11
|
+
message: string;
|
|
12
|
+
} | {
|
|
13
|
+
status: "needs_auth";
|
|
14
|
+
message: string;
|
|
15
|
+
} | {
|
|
16
|
+
status: "ready";
|
|
17
|
+
version: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Auth methods, mapped to agy's ACP `authMethods`. Google login methods are
|
|
21
|
+
* external: the user signs in with agy itself and the plugin never touches
|
|
22
|
+
* agy's OAuth tokens. The API key is stored by OpenCode (method type `key`).
|
|
23
|
+
*/
|
|
24
|
+
export declare const AGY_ACP_AUTH_METHODS: ({
|
|
25
|
+
integrationID: string;
|
|
26
|
+
method: {
|
|
27
|
+
id: string;
|
|
28
|
+
type: "external";
|
|
29
|
+
label: string;
|
|
30
|
+
form: {
|
|
31
|
+
key: string;
|
|
32
|
+
type: "boolean";
|
|
33
|
+
title: string;
|
|
34
|
+
description: string;
|
|
35
|
+
default: boolean;
|
|
36
|
+
}[];
|
|
37
|
+
};
|
|
38
|
+
} | {
|
|
39
|
+
integrationID: string;
|
|
40
|
+
method: {
|
|
41
|
+
type: "key";
|
|
42
|
+
label: string;
|
|
43
|
+
};
|
|
44
|
+
})[];
|
|
45
|
+
export declare function registerIntegration(ctx: OpenCodeV2PluginContext): void;
|
|
46
|
+
export interface ResolvedAuth {
|
|
47
|
+
/**
|
|
48
|
+
* Non-secret identity of the active credential; changes on connection or key
|
|
49
|
+
* switch. Holds a truncated SHA-256 of an API key, never the key itself.
|
|
50
|
+
*/
|
|
51
|
+
identity: string;
|
|
52
|
+
connection: unknown;
|
|
53
|
+
method: AgyAuthMethod;
|
|
54
|
+
apiKey?: string;
|
|
55
|
+
}
|
|
56
|
+
/** Reads the active OpenCode connection. No connection means agy's own Google login. */
|
|
57
|
+
export declare function resolveAuth(ctx: OpenCodeV2PluginContext): Promise<ResolvedAuth>;
|
|
58
|
+
export declare function statusFromProbe(probe: AgyProbe): AgyAcpStatus;
|
|
59
|
+
/** Mirrors a status into OpenCode's connection status (only `needs_auth` exists there). */
|
|
60
|
+
export declare function publishStatus(ctx: OpenCodeV2PluginContext, status: AgyAcpStatus): Promise<void>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AcpModelInfo } from "./process";
|
|
2
|
+
export declare const AGY_ACP_PROVIDER_NAME = "Antigravity CLI (ACP)";
|
|
3
|
+
/**
|
|
4
|
+
* `aisdk:` package URL of the placeholder module. The bundle ships it as
|
|
5
|
+
* `dist/sdk-placeholder.js` next to `dist/index.js`; from source (tests) the
|
|
6
|
+
* sibling is `sdk-placeholder.ts`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function placeholderPackage(base?: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* In-memory list of the models agy reports. The catalog transform reads it on
|
|
11
|
+
* every run; `set` asks the host to re-run the transform when the list changes.
|
|
12
|
+
* Nothing is persisted: when agy cannot be asked, the provider has no models.
|
|
13
|
+
*/
|
|
14
|
+
export declare class ModelRegistry {
|
|
15
|
+
private readonly reload;
|
|
16
|
+
private readonly log;
|
|
17
|
+
private models;
|
|
18
|
+
constructor(reload: () => Promise<void> | void, log: (level: "warn", msg: string) => void);
|
|
19
|
+
list(): AcpModelInfo[];
|
|
20
|
+
/** Replaces the list; reloads the catalog only when ids or names changed. Returns whether it changed. */
|
|
21
|
+
set(models: AcpModelInfo[]): Promise<boolean>;
|
|
22
|
+
}
|
|
23
|
+
/** Mutates an OpenCode provider record into the google-agy-acp provider. */
|
|
24
|
+
export declare function applyProviderRecord(p: any, pkg: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Mutates an OpenCode model record. Variant `settings` become AI SDK
|
|
27
|
+
* `providerOptions`, so `providerOptions["google-agy-acp"].tier` reaches the
|
|
28
|
+
* language model. Cost is zero: agy bills the Google account, not OpenCode.
|
|
29
|
+
*/
|
|
30
|
+
export declare function applyModelRecord(m: any, model: AcpModelInfo): void;
|
|
31
|
+
/** Registers the provider and its models with whichever catalog API the host exposes. */
|
|
32
|
+
export declare function registerCatalog(ctx: any, pkg: string, models: () => AcpModelInfo[]): void;
|