@open-document/core 0.14.2 → 0.15.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.
Files changed (33) hide show
  1. package/dist/{build-I0cgoERP.js → build-CBMroMqd.js} +1 -1
  2. package/dist/{check-Dys96QSL.js → check-C2kIZr3f.js} +3 -3
  3. package/dist/cli/bin.js +9 -9
  4. package/dist/{context-C-osJW5f.js → context-DGp1jwN5.js} +1 -1
  5. package/dist/{dev-CC4PrIOC.js → dev-DmzGncKf.js} +1 -1
  6. package/dist/{diff-DhutD4TJ.js → diff-CMI_PVzz.js} +2 -2
  7. package/dist/{export-KrajVJO7.js → export-BQMUBoBB.js} +3 -3
  8. package/dist/{import-Yv34za3L.js → import-CiSRqZyo.js} +3 -3
  9. package/dist/ops/index.js +2 -2
  10. package/dist/{ops-Dux5HlkH.js → ops-DQbZmYRF.js} +1 -1
  11. package/dist/{preview-7eqn9Wzf.js → preview-CERhZ_FX.js} +1 -1
  12. package/dist/{session-BSbrC5gK.js → session-DdaKKd7_.js} +1022 -10
  13. package/dist/{templates-s-VLTSRc.js → templates-CBeC-v7e.js} +3 -3
  14. package/dist/vite/index.js +1 -1
  15. package/package.json +1 -1
  16. package/src/agent/consent.ts +42 -0
  17. package/src/agent/provider.ts +24 -1
  18. package/src/agent/providers/antigravity-local.ts +193 -0
  19. package/src/agent/providers/antigravity.ts +656 -0
  20. package/src/agent/providers/index.ts +2 -1
  21. package/src/agent/runner.ts +4 -0
  22. package/src/agent/sandbox-sync.ts +178 -0
  23. package/src/agent/status.ts +33 -1
  24. package/src/agent/types.ts +21 -3
  25. package/src/app/components/agent/agent-panel.tsx +180 -42
  26. package/src/app/components/agent/connect-view.tsx +294 -26
  27. package/src/app/components/agent/provider-logo.tsx +4 -0
  28. package/src/app/lib/agent/use-agent.ts +14 -1
  29. package/src/app/lib/i18n-ja/agent-panel.ts +49 -0
  30. package/src/app/lib/i18n-ko/agent-panel.ts +48 -0
  31. package/src/app/lib/i18n-zh-cn/agent-panel.ts +46 -0
  32. package/src/app/lib/i18n-zh-tw/agent-panel.ts +46 -0
  33. package/src/app/lib/use-locale.ts +43 -0
@@ -1,6 +1,6 @@
1
- import { l as createFromTemplate, u as listTemplates } from "./session-BSbrC5gK.js";
2
- import "./ops-Dux5HlkH.js";
3
- import { t as cliContext } from "./context-C-osJW5f.js";
1
+ import { l as createFromTemplate, u as listTemplates } from "./session-DdaKKd7_.js";
2
+ import "./ops-DQbZmYRF.js";
3
+ import { t as cliContext } from "./context-DGp1jwN5.js";
4
4
  import chalk from "chalk";
5
5
  //#region src/cli/templates.ts
6
6
  /**
@@ -1,3 +1,3 @@
1
1
  import { r as openDocPlugin } from "../open-doc-plugin-DnX5usgI.js";
2
- import { r as createViteConfig } from "../session-BSbrC5gK.js";
2
+ import { r as createViteConfig } from "../session-DdaKKd7_.js";
3
3
  export { createViteConfig, openDocPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-document/core",
3
- "version": "0.14.2",
3
+ "version": "0.15.0",
4
4
  "description": "Runtime and CLI for open-doc — write documents in docs/, we handle the pages, print layout, and export.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -0,0 +1,42 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import type { AgentProviderId } from './types.ts';
4
+
5
+ type ConsentRecord = { version: string; acceptedAt: string };
6
+ type ConsentFile = Partial<Record<AgentProviderId, ConsentRecord>>;
7
+
8
+ export function consentFile(userCwd: string): string {
9
+ return path.join(userCwd, 'node_modules', '.open-doc', 'agent-consent.json');
10
+ }
11
+
12
+ async function readAll(userCwd: string): Promise<ConsentFile> {
13
+ try {
14
+ const raw = JSON.parse(await fs.readFile(consentFile(userCwd), 'utf8'));
15
+ return raw && typeof raw === 'object' ? (raw as ConsentFile) : {};
16
+ } catch {
17
+ return {};
18
+ }
19
+ }
20
+
21
+ // Acceptance is kept by the dev server, not the browser, so the provider can
22
+ // refuse a turn itself rather than trusting the panel to have asked.
23
+ export async function hasConsent(
24
+ userCwd: string,
25
+ provider: AgentProviderId,
26
+ version: string,
27
+ ): Promise<boolean> {
28
+ return (await readAll(userCwd))[provider]?.version === version;
29
+ }
30
+
31
+ export async function setConsent(
32
+ userCwd: string,
33
+ provider: AgentProviderId,
34
+ version: string | null,
35
+ ): Promise<void> {
36
+ const all = await readAll(userCwd);
37
+ if (version) all[provider] = { version, acceptedAt: new Date().toISOString() };
38
+ else delete all[provider];
39
+ const file = consentFile(userCwd);
40
+ await fs.mkdir(path.dirname(file), { recursive: true });
41
+ await fs.writeFile(file, `${JSON.stringify(all, null, 2)}\n`);
42
+ }
@@ -1,5 +1,12 @@
1
1
  import path from 'node:path';
2
- import type { AgentEffort, AgentModelOption, AgentProviderId, AgentQuestion } from './types.ts';
2
+ import type {
3
+ AgentEffort,
4
+ AgentModelOption,
5
+ AgentProviderAuth,
6
+ AgentProviderId,
7
+ AgentQuestion,
8
+ AgentRuntime,
9
+ } from './types.ts';
3
10
 
4
11
  export type ProviderEvent =
5
12
  | { type: 'session-id'; id: string }
@@ -20,6 +27,9 @@ export type PermissionRequest = { tool: string; title: string; detail: string |
20
27
 
21
28
  export type ProviderRunOptions = {
22
29
  cwd: string;
30
+ docsDir: string;
31
+ // The open document's folder; null when the turn has no document.
32
+ docDir: string | null;
23
33
  // Directories the agent may write to without asking: the deck and asset
24
34
  // folders. Edits anywhere else (configs, package.json) need approval.
25
35
  writableRoots: string[];
@@ -45,6 +55,19 @@ export interface AgentProvider {
45
55
  // Whether the agent's own commands can start a browser. `open-doc check` and
46
56
  // the page preview both drive Chromium, which Codex's macOS sandbox kills.
47
57
  canOpenBrowser: boolean;
58
+ auth?: AgentProviderAuth;
59
+ preview?: boolean;
60
+ // Set when the user must accept terms before a turn runs; bump it when the
61
+ // terms change so everyone accepts the new text.
62
+ consentVersion?: string;
63
+ // For 'api-key' agents, which have no SDK to resolve.
64
+ hasKey?(cwd: string): Promise<boolean>;
65
+ // Where the agent's tools run, for agents that can run either in the cloud
66
+ // or on this machine once `install` has fetched what that needs.
67
+ runtime?(cwd: string): Promise<AgentRuntime>;
68
+ install?(cwd: string): Promise<void>;
69
+ // Stops anything the provider started that outlives a turn.
70
+ dispose?(): void;
48
71
  models(): Promise<AgentModelOption[]>;
49
72
  run(opts: ProviderRunOptions): Promise<void>;
50
73
  }
@@ -0,0 +1,193 @@
1
+ import { type ChildProcess, spawn } from 'node:child_process';
2
+ import { createHash } from 'node:crypto';
3
+ import fs from 'node:fs/promises';
4
+ import path from 'node:path';
5
+ import { gunzipSync } from 'node:zlib';
6
+ import { readTar } from '../sandbox-sync.ts';
7
+
8
+ // Pinned, with the release's own checksums, so the binary that runs file tools
9
+ // on the user's machine is exactly the one Google published.
10
+ export const GEMINI_API_CLI_VERSION = '0.4.6';
11
+ const RELEASE = `https://github.com/google-gemini/gemini-api-cli/releases/download/v${GEMINI_API_CLI_VERSION}`;
12
+ const CHECKSUMS: Record<string, string> = {
13
+ 'darwin-arm64': 'c80b5ec2d0a6feee0cf18943427cfdaf9aab7183b7f62f50b956cd2431b98018',
14
+ 'darwin-x64': '009a83ea43b1cd25f87375efc01c9418c12fcd7ea779a26a483eb4e875da4a70',
15
+ 'linux-arm64': '6bf48dc0b6479b157d4dc35d074d06286c2c6e2f09ff99236bde9829763576f7',
16
+ 'linux-x64': '78862dde519d9b47a9fb70b1f0340d19fa1245934d65e83f0e2dbc1d17cd2fa6',
17
+ };
18
+ const ASSETS: Record<string, string> = {
19
+ 'darwin-arm64': 'gemini-api_Darwin_arm64.tar.gz',
20
+ 'darwin-x64': 'gemini-api_Darwin_x86_64.tar.gz',
21
+ 'linux-arm64': 'gemini-api_Linux_arm64.tar.gz',
22
+ 'linux-x64': 'gemini-api_Linux_x86_64.tar.gz',
23
+ };
24
+ const API_BASE = 'https://generativelanguage.googleapis.com/v1beta';
25
+ const READY_TIMEOUT_MS = 10_000;
26
+
27
+ function platformKey(): string {
28
+ return `${process.platform}-${process.arch}`;
29
+ }
30
+
31
+ export function localModeSupported(): boolean {
32
+ return platformKey() in ASSETS;
33
+ }
34
+
35
+ function stateDir(cwd: string): string {
36
+ return path.join(cwd, 'node_modules', '.open-doc');
37
+ }
38
+
39
+ export function cliPath(cwd: string): string {
40
+ return path.join(stateDir(cwd), 'bin', 'gemini-api');
41
+ }
42
+
43
+ function versionFile(cwd: string): string {
44
+ return path.join(stateDir(cwd), 'bin', 'gemini-api.version');
45
+ }
46
+
47
+ export async function installedCliVersion(cwd: string): Promise<string | null> {
48
+ try {
49
+ await fs.access(cliPath(cwd));
50
+ return (await fs.readFile(versionFile(cwd), 'utf8')).trim() || null;
51
+ } catch {
52
+ return null;
53
+ }
54
+ }
55
+
56
+ let installing: Promise<void> | null = null;
57
+
58
+ export function installCli(cwd: string): Promise<void> {
59
+ installing ??= (async () => {
60
+ const key = platformKey();
61
+ const asset = ASSETS[key];
62
+ if (!asset) throw new Error(`Local mode is not available on ${key} yet.`);
63
+ const res = await fetch(`${RELEASE}/${asset}`);
64
+ if (!res.ok) throw new Error(`Could not download the gemini-api CLI (${res.status}).`);
65
+ const archive = new Uint8Array(await res.arrayBuffer());
66
+ const digest = createHash('sha256').update(archive).digest('hex');
67
+ if (digest !== CHECKSUMS[key]) {
68
+ throw new Error('The downloaded gemini-api CLI failed its checksum; nothing was installed.');
69
+ }
70
+ const entry = readTar(gunzipSync(archive)).find(
71
+ (e) => path.posix.basename(e.path) === 'gemini-api',
72
+ );
73
+ if (!entry) throw new Error('The gemini-api archive did not contain the CLI.');
74
+ const target = cliPath(cwd);
75
+ await fs.mkdir(path.dirname(target), { recursive: true });
76
+ const partial = `${target}.partial`;
77
+ await fs.writeFile(partial, entry.data, { mode: 0o755 });
78
+ await fs.rename(partial, target);
79
+ await fs.writeFile(versionFile(cwd), `${GEMINI_API_CLI_VERSION}\n`);
80
+ })().finally(() => {
81
+ installing = null;
82
+ });
83
+ return installing;
84
+ }
85
+
86
+ type EnvironmentRecord = { id: string; environment_key: string };
87
+
88
+ function environmentFile(cwd: string): string {
89
+ return path.join(stateDir(cwd), 'antigravity-environment.json');
90
+ }
91
+
92
+ async function readEnvironment(cwd: string): Promise<EnvironmentRecord | null> {
93
+ try {
94
+ const raw = JSON.parse(await fs.readFile(environmentFile(cwd), 'utf8'));
95
+ return typeof raw?.id === 'string' && typeof raw?.environment_key === 'string' ? raw : null;
96
+ } catch {
97
+ return null;
98
+ }
99
+ }
100
+
101
+ // The environment key is shown once, at creation, and lets anyone holding it
102
+ // take this environment's tool calls; it is stored owner-only.
103
+ export async function ensureEnvironment(cwd: string, apiKey: string): Promise<EnvironmentRecord> {
104
+ const existing = await readEnvironment(cwd);
105
+ if (existing) return existing;
106
+ const res = await fetch(`${API_BASE}/environments`, {
107
+ method: 'POST',
108
+ headers: { 'x-goog-api-key': apiKey, 'content-type': 'application/json' },
109
+ body: JSON.stringify({ mode: 'self_hosted' }),
110
+ });
111
+ if (!res.ok) {
112
+ throw new Error(`Could not create a local environment (Gemini API ${res.status}).`);
113
+ }
114
+ const body = (await res.json()) as Partial<EnvironmentRecord>;
115
+ if (!body.id || !body.environment_key) {
116
+ throw new Error('The Gemini API returned an environment without a key.');
117
+ }
118
+ const record = { id: body.id, environment_key: body.environment_key };
119
+ await fs.mkdir(stateDir(cwd), { recursive: true });
120
+ await fs.writeFile(environmentFile(cwd), `${JSON.stringify(record, null, 2)}\n`, {
121
+ mode: 0o600,
122
+ });
123
+ return record;
124
+ }
125
+
126
+ export async function forgetEnvironment(cwd: string): Promise<void> {
127
+ stopWorker();
128
+ await fs.rm(environmentFile(cwd), { force: true });
129
+ }
130
+
131
+ type Worker = { process: ChildProcess; key: string; ready: Promise<void>; log: string[] };
132
+ let worker: Worker | null = null;
133
+
134
+ export function stopWorker(): void {
135
+ worker?.process.kill();
136
+ worker = null;
137
+ }
138
+
139
+ process.once('exit', stopWorker);
140
+
141
+ export function workerLog(): string {
142
+ return worker?.log.slice(-5).join('\n') ?? '';
143
+ }
144
+
145
+ /**
146
+ * One worker per dev server, rooted at the workspace so the agent finds the
147
+ * project skills. `--disable-bash` leaves it only the file tools, which the CLI
148
+ * confines to the root with os.Root, so a model can never run a command here.
149
+ * The project-wide API key is withheld; the worker only needs its environment key.
150
+ */
151
+ export function ensureWorker(cwd: string, env: EnvironmentRecord): Promise<void> {
152
+ if (worker && worker.key === env.environment_key && worker.process.exitCode === null) {
153
+ return worker.ready;
154
+ }
155
+ stopWorker();
156
+ const { GEMINI_API_KEY: _withheld, ...rest } = process.env;
157
+ const child = spawn(
158
+ cliPath(cwd),
159
+ ['environments', 'connect', '--root-dir', cwd, '--workdir', cwd, '--disable-bash'],
160
+ {
161
+ cwd,
162
+ env: { ...rest, GEMINI_ENVIRONMENT_KEY: env.environment_key },
163
+ stdio: ['ignore', 'ignore', 'pipe'],
164
+ },
165
+ );
166
+ const log: string[] = [];
167
+ const ready = new Promise<void>((resolve, reject) => {
168
+ const timer = setTimeout(resolve, READY_TIMEOUT_MS);
169
+ child.stderr?.setEncoding('utf8');
170
+ child.stderr?.on('data', (chunk: string) => {
171
+ for (const line of chunk.split('\n').filter(Boolean)) {
172
+ log.push(line);
173
+ if (log.length > 50) log.shift();
174
+ if (/polling/i.test(line)) {
175
+ clearTimeout(timer);
176
+ resolve();
177
+ }
178
+ }
179
+ });
180
+ child.once('error', (err) => {
181
+ clearTimeout(timer);
182
+ reject(err);
183
+ });
184
+ child.once('exit', (code) => {
185
+ clearTimeout(timer);
186
+ if (worker?.process === child) worker = null;
187
+ reject(new Error(`The local worker stopped (exit ${code}). ${log.slice(-3).join(' ')}`));
188
+ });
189
+ });
190
+ ready.catch(() => {});
191
+ worker = { process: child, key: env.environment_key, ready, log };
192
+ return ready;
193
+ }