@pencil-agent/nano-pencil 2.0.0-beta.2 → 2.0.0-beta.3

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 (179) hide show
  1. package/dist/build-meta.json +3 -3
  2. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-continuations.d.ts +17 -0
  3. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-continuations.js +60 -0
  4. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-stream-events.d.ts +19 -0
  5. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-stream-events.js +55 -0
  6. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-results.d.ts +10 -0
  7. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-results.js +137 -0
  8. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-summaries.d.ts +22 -0
  9. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-summaries.js +64 -0
  10. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop.d.ts +26 -0
  11. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop.js +913 -0
  12. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-run-result.d.ts +9 -0
  13. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-run-result.js +32 -0
  14. package/dist/node_modules/@pencil-agent/agent-core/dist/agent.d.ts +215 -0
  15. package/dist/node_modules/@pencil-agent/agent-core/dist/agent.js +522 -0
  16. package/dist/node_modules/@pencil-agent/agent-core/dist/errors.d.ts +62 -0
  17. package/dist/node_modules/@pencil-agent/agent-core/dist/errors.js +146 -0
  18. package/dist/node_modules/@pencil-agent/agent-core/dist/index.d.ts +14 -0
  19. package/dist/node_modules/@pencil-agent/agent-core/dist/index.js +19 -0
  20. package/dist/node_modules/@pencil-agent/agent-core/dist/proxy.d.ts +91 -0
  21. package/dist/node_modules/@pencil-agent/agent-core/dist/proxy.js +279 -0
  22. package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-agent-loop.d.ts +15 -0
  23. package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-agent-loop.js +625 -0
  24. package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-streaming-tool-executor.d.ts +33 -0
  25. package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-streaming-tool-executor.js +189 -0
  26. package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-tool-orchestration.d.ts +35 -0
  27. package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-tool-orchestration.js +319 -0
  28. package/dist/node_modules/@pencil-agent/agent-core/dist/types.d.ts +417 -0
  29. package/dist/node_modules/@pencil-agent/agent-core/dist/types.js +13 -0
  30. package/dist/node_modules/@pencil-agent/agent-core/package.json +28 -0
  31. package/dist/node_modules/@pencil-agent/ai/dist/api-registry.d.ts +27 -0
  32. package/dist/node_modules/@pencil-agent/ai/dist/api-registry.js +152 -0
  33. package/dist/node_modules/@pencil-agent/ai/dist/cli.d.ts +2 -0
  34. package/dist/node_modules/@pencil-agent/ai/dist/cli.js +121 -0
  35. package/dist/node_modules/@pencil-agent/ai/dist/config-path.d.ts +1 -0
  36. package/dist/node_modules/@pencil-agent/ai/dist/config-path.js +17 -0
  37. package/dist/node_modules/@pencil-agent/ai/dist/debug-logger.d.ts +94 -0
  38. package/dist/node_modules/@pencil-agent/ai/dist/debug-logger.js +218 -0
  39. package/dist/node_modules/@pencil-agent/ai/dist/env-api-keys.d.ts +8 -0
  40. package/dist/node_modules/@pencil-agent/ai/dist/env-api-keys.js +107 -0
  41. package/dist/node_modules/@pencil-agent/ai/dist/env.d.ts +7 -0
  42. package/dist/node_modules/@pencil-agent/ai/dist/env.js +7 -0
  43. package/dist/node_modules/@pencil-agent/ai/dist/events.d.ts +8 -0
  44. package/dist/node_modules/@pencil-agent/ai/dist/events.js +7 -0
  45. package/dist/node_modules/@pencil-agent/ai/dist/index.d.ts +27 -0
  46. package/dist/node_modules/@pencil-agent/ai/dist/index.js +20 -0
  47. package/dist/node_modules/@pencil-agent/ai/dist/json.d.ts +7 -0
  48. package/dist/node_modules/@pencil-agent/ai/dist/json.js +7 -0
  49. package/dist/node_modules/@pencil-agent/ai/dist/models.d.ts +31 -0
  50. package/dist/node_modules/@pencil-agent/ai/dist/models.generated.d.ts +15159 -0
  51. package/dist/node_modules/@pencil-agent/ai/dist/models.generated.js +14928 -0
  52. package/dist/node_modules/@pencil-agent/ai/dist/models.js +60 -0
  53. package/dist/node_modules/@pencil-agent/ai/dist/overflow.d.ts +7 -0
  54. package/dist/node_modules/@pencil-agent/ai/dist/overflow.js +7 -0
  55. package/dist/node_modules/@pencil-agent/ai/dist/providers/amazon-bedrock.d.ts +20 -0
  56. package/dist/node_modules/@pencil-agent/ai/dist/providers/amazon-bedrock.js +606 -0
  57. package/dist/node_modules/@pencil-agent/ai/dist/providers/anthropic.d.ts +38 -0
  58. package/dist/node_modules/@pencil-agent/ai/dist/providers/anthropic.js +737 -0
  59. package/dist/node_modules/@pencil-agent/ai/dist/providers/azure-openai-responses.d.ts +21 -0
  60. package/dist/node_modules/@pencil-agent/ai/dist/providers/azure-openai-responses.js +193 -0
  61. package/dist/node_modules/@pencil-agent/ai/dist/providers/github-copilot-headers.d.ts +13 -0
  62. package/dist/node_modules/@pencil-agent/ai/dist/providers/github-copilot-headers.js +34 -0
  63. package/dist/node_modules/@pencil-agent/ai/dist/providers/google-gemini-cli.d.ts +79 -0
  64. package/dist/node_modules/@pencil-agent/ai/dist/providers/google-gemini-cli.js +753 -0
  65. package/dist/node_modules/@pencil-agent/ai/dist/providers/google-shared.d.ts +70 -0
  66. package/dist/node_modules/@pencil-agent/ai/dist/providers/google-shared.js +311 -0
  67. package/dist/node_modules/@pencil-agent/ai/dist/providers/google-vertex.d.ts +20 -0
  68. package/dist/node_modules/@pencil-agent/ai/dist/providers/google-vertex.js +380 -0
  69. package/dist/node_modules/@pencil-agent/ai/dist/providers/google.d.ts +18 -0
  70. package/dist/node_modules/@pencil-agent/ai/dist/providers/google.js +360 -0
  71. package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-codex-responses.d.ts +8 -0
  72. package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-codex-responses.js +704 -0
  73. package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-completions.d.ts +20 -0
  74. package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-completions.js +870 -0
  75. package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses-shared.d.ts +22 -0
  76. package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses-shared.js +432 -0
  77. package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses.d.ts +19 -0
  78. package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses.js +207 -0
  79. package/dist/node_modules/@pencil-agent/ai/dist/providers/register-builtins.d.ts +8 -0
  80. package/dist/node_modules/@pencil-agent/ai/dist/providers/register-builtins.js +86 -0
  81. package/dist/node_modules/@pencil-agent/ai/dist/providers/simple-options.d.ts +13 -0
  82. package/dist/node_modules/@pencil-agent/ai/dist/providers/simple-options.js +40 -0
  83. package/dist/node_modules/@pencil-agent/ai/dist/providers/transform-messages.d.ts +13 -0
  84. package/dist/node_modules/@pencil-agent/ai/dist/providers/transform-messages.js +175 -0
  85. package/dist/node_modules/@pencil-agent/ai/dist/registry.d.ts +8 -0
  86. package/dist/node_modules/@pencil-agent/ai/dist/registry.js +8 -0
  87. package/dist/node_modules/@pencil-agent/ai/dist/schema.d.ts +10 -0
  88. package/dist/node_modules/@pencil-agent/ai/dist/schema.js +9 -0
  89. package/dist/node_modules/@pencil-agent/ai/dist/stream.d.ts +25 -0
  90. package/dist/node_modules/@pencil-agent/ai/dist/stream.js +324 -0
  91. package/dist/node_modules/@pencil-agent/ai/dist/types.d.ts +306 -0
  92. package/dist/node_modules/@pencil-agent/ai/dist/types.js +7 -0
  93. package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream-types.d.ts +12 -0
  94. package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream-types.js +7 -0
  95. package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream.d.ts +31 -0
  96. package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream.js +98 -0
  97. package/dist/node_modules/@pencil-agent/ai/dist/utils/http-proxy.d.ts +13 -0
  98. package/dist/node_modules/@pencil-agent/ai/dist/utils/http-proxy.js +20 -0
  99. package/dist/node_modules/@pencil-agent/ai/dist/utils/json-parse.d.ts +14 -0
  100. package/dist/node_modules/@pencil-agent/ai/dist/utils/json-parse.js +34 -0
  101. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/anthropic.d.ts +22 -0
  102. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/anthropic.js +109 -0
  103. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/decode-credential.d.ts +12 -0
  104. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/decode-credential.js +25 -0
  105. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/github-copilot.d.ts +35 -0
  106. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/github-copilot.js +286 -0
  107. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-antigravity.d.ts +31 -0
  108. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-antigravity.js +378 -0
  109. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-gemini-cli.d.ts +31 -0
  110. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-gemini-cli.js +483 -0
  111. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/index.d.ts +60 -0
  112. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/index.js +131 -0
  113. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/openai-codex.d.ts +39 -0
  114. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/openai-codex.js +385 -0
  115. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/pkce.d.ts +18 -0
  116. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/pkce.js +36 -0
  117. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/types.d.ts +52 -0
  118. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/types.js +7 -0
  119. package/dist/node_modules/@pencil-agent/ai/dist/utils/overflow.d.ts +57 -0
  120. package/dist/node_modules/@pencil-agent/ai/dist/utils/overflow.js +120 -0
  121. package/dist/node_modules/@pencil-agent/ai/dist/utils/sanitize-unicode.d.ts +16 -0
  122. package/dist/node_modules/@pencil-agent/ai/dist/utils/sanitize-unicode.js +20 -0
  123. package/dist/node_modules/@pencil-agent/ai/dist/utils/typebox-helpers.d.ts +22 -0
  124. package/dist/node_modules/@pencil-agent/ai/dist/utils/typebox-helpers.js +26 -0
  125. package/dist/node_modules/@pencil-agent/ai/dist/utils/validation.d.ts +23 -0
  126. package/dist/node_modules/@pencil-agent/ai/dist/utils/validation.js +78 -0
  127. package/dist/node_modules/@pencil-agent/ai/package.json +94 -0
  128. package/dist/node_modules/@pencil-agent/tui/dist/autocomplete.d.ts +62 -0
  129. package/dist/node_modules/@pencil-agent/tui/dist/autocomplete.js +624 -0
  130. package/dist/node_modules/@pencil-agent/tui/dist/components/box.d.ts +27 -0
  131. package/dist/node_modules/@pencil-agent/tui/dist/components/box.js +109 -0
  132. package/dist/node_modules/@pencil-agent/tui/dist/components/cancellable-loader.d.ts +27 -0
  133. package/dist/node_modules/@pencil-agent/tui/dist/components/cancellable-loader.js +40 -0
  134. package/dist/node_modules/@pencil-agent/tui/dist/components/editor.d.ts +218 -0
  135. package/dist/node_modules/@pencil-agent/tui/dist/components/editor.js +1697 -0
  136. package/dist/node_modules/@pencil-agent/tui/dist/components/image.d.ts +33 -0
  137. package/dist/node_modules/@pencil-agent/tui/dist/components/image.js +74 -0
  138. package/dist/node_modules/@pencil-agent/tui/dist/components/input.d.ts +42 -0
  139. package/dist/node_modules/@pencil-agent/tui/dist/components/input.js +438 -0
  140. package/dist/node_modules/@pencil-agent/tui/dist/components/loader.d.ts +26 -0
  141. package/dist/node_modules/@pencil-agent/tui/dist/components/loader.js +54 -0
  142. package/dist/node_modules/@pencil-agent/tui/dist/components/markdown.d.ts +100 -0
  143. package/dist/node_modules/@pencil-agent/tui/dist/components/markdown.js +634 -0
  144. package/dist/node_modules/@pencil-agent/tui/dist/components/select-list.d.ts +37 -0
  145. package/dist/node_modules/@pencil-agent/tui/dist/components/select-list.js +157 -0
  146. package/dist/node_modules/@pencil-agent/tui/dist/components/settings-list.d.ts +55 -0
  147. package/dist/node_modules/@pencil-agent/tui/dist/components/settings-list.js +190 -0
  148. package/dist/node_modules/@pencil-agent/tui/dist/components/spacer.d.ts +17 -0
  149. package/dist/node_modules/@pencil-agent/tui/dist/components/spacer.js +28 -0
  150. package/dist/node_modules/@pencil-agent/tui/dist/components/text.d.ts +24 -0
  151. package/dist/node_modules/@pencil-agent/tui/dist/components/text.js +94 -0
  152. package/dist/node_modules/@pencil-agent/tui/dist/components/truncated-text.d.ts +18 -0
  153. package/dist/node_modules/@pencil-agent/tui/dist/components/truncated-text.js +56 -0
  154. package/dist/node_modules/@pencil-agent/tui/dist/editor-component.d.ts +51 -0
  155. package/dist/node_modules/@pencil-agent/tui/dist/editor-component.js +7 -0
  156. package/dist/node_modules/@pencil-agent/tui/dist/fuzzy.d.ts +32 -0
  157. package/dist/node_modules/@pencil-agent/tui/dist/fuzzy.js +152 -0
  158. package/dist/node_modules/@pencil-agent/tui/dist/index.d.ts +28 -0
  159. package/dist/node_modules/@pencil-agent/tui/dist/index.js +37 -0
  160. package/dist/node_modules/@pencil-agent/tui/dist/keybindings.d.ts +44 -0
  161. package/dist/node_modules/@pencil-agent/tui/dist/keybindings.js +119 -0
  162. package/dist/node_modules/@pencil-agent/tui/dist/keys.d.ts +149 -0
  163. package/dist/node_modules/@pencil-agent/tui/dist/keys.js +948 -0
  164. package/dist/node_modules/@pencil-agent/tui/dist/kill-ring.d.ts +33 -0
  165. package/dist/node_modules/@pencil-agent/tui/dist/kill-ring.js +49 -0
  166. package/dist/node_modules/@pencil-agent/tui/dist/stdin-buffer.d.ts +38 -0
  167. package/dist/node_modules/@pencil-agent/tui/dist/stdin-buffer.js +307 -0
  168. package/dist/node_modules/@pencil-agent/tui/dist/terminal-image.d.ts +73 -0
  169. package/dist/node_modules/@pencil-agent/tui/dist/terminal-image.js +287 -0
  170. package/dist/node_modules/@pencil-agent/tui/dist/terminal.d.ts +86 -0
  171. package/dist/node_modules/@pencil-agent/tui/dist/terminal.js +266 -0
  172. package/dist/node_modules/@pencil-agent/tui/dist/tui.d.ts +219 -0
  173. package/dist/node_modules/@pencil-agent/tui/dist/tui.js +1001 -0
  174. package/dist/node_modules/@pencil-agent/tui/dist/undo-stack.d.ts +22 -0
  175. package/dist/node_modules/@pencil-agent/tui/dist/undo-stack.js +30 -0
  176. package/dist/node_modules/@pencil-agent/tui/dist/utils.d.ts +83 -0
  177. package/dist/node_modules/@pencil-agent/tui/dist/utils.js +811 -0
  178. package/dist/node_modules/@pencil-agent/tui/package.json +37 -0
  179. package/package.json +3 -2
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Antigravity OAuth flow (Gemini 3, Claude, GPT-OSS via Google Cloud)
3
+ * Uses different OAuth credentials than google-gemini-cli for access to additional models.
4
+ *
5
+ * NOTE: This module uses Node.js http.createServer for the OAuth callback.
6
+ * It is only intended for CLI use, not browser environments.
7
+ */
8
+ /**
9
+ * [WHO]: antigravityOAuthProvider
10
+ * [FROM]: Depends on ./pkce.js
11
+ * [TO]: Consumed by core/lib/ai/src/index.ts
12
+ * [HERE]: core/lib/ai/src/utils/oauth/google-antigravity.ts -
13
+ */
14
+ import type { OAuthCredentials, OAuthProviderInterface } from "./types.js";
15
+ /**
16
+ * Refresh Antigravity token
17
+ */
18
+ export declare function refreshAntigravityToken(refreshToken: string, projectId: string): Promise<OAuthCredentials>;
19
+ /**
20
+ * Login with Antigravity OAuth
21
+ *
22
+ * @param onAuth - Callback with URL and optional instructions
23
+ * @param onProgress - Optional progress callback
24
+ * @param onManualCodeInput - Optional promise that resolves with user-pasted redirect URL.
25
+ * Races with browser callback - whichever completes first wins.
26
+ */
27
+ export declare function loginAntigravity(onAuth: (info: {
28
+ url: string;
29
+ instructions?: string;
30
+ }) => void, onProgress?: (message: string) => void, onManualCodeInput?: () => Promise<string>): Promise<OAuthCredentials>;
31
+ export declare const antigravityOAuthProvider: OAuthProviderInterface;
@@ -0,0 +1,378 @@
1
+ /**
2
+ * Antigravity OAuth flow (Gemini 3, Claude, GPT-OSS via Google Cloud)
3
+ * Uses different OAuth credentials than google-gemini-cli for access to additional models.
4
+ *
5
+ * NOTE: This module uses Node.js http.createServer for the OAuth callback.
6
+ * It is only intended for CLI use, not browser environments.
7
+ */
8
+ /**
9
+ * [WHO]: antigravityOAuthProvider
10
+ * [FROM]: Depends on ./pkce.js
11
+ * [TO]: Consumed by core/lib/ai/src/index.ts
12
+ * [HERE]: core/lib/ai/src/utils/oauth/google-antigravity.ts -
13
+ */
14
+ import { decodeOAuthCredentialSegment } from "./decode-credential.js";
15
+ import { generatePKCE } from "./pkce.js";
16
+ let _createServer = null;
17
+ let _httpImportPromise = null;
18
+ if (typeof process !== "undefined" && (process.versions?.node || process.versions?.bun)) {
19
+ _httpImportPromise = import("node:http").then((m) => {
20
+ _createServer = m.createServer;
21
+ });
22
+ }
23
+ // Antigravity OAuth credentials (different from Gemini CLI)
24
+ const CLIENT_ID = decodeOAuthCredentialSegment("YOUR_CLIENT_ID_HERE");
25
+ const CLIENT_SECRET = decodeOAuthCredentialSegment("YOUR_CLIENT_SECRET_HERE");
26
+ const REDIRECT_URI = "http://localhost:51121/oauth-callback";
27
+ // Antigravity requires additional scopes
28
+ const SCOPES = [
29
+ "https://www.googleapis.com/auth/cloud-platform",
30
+ "https://www.googleapis.com/auth/userinfo.email",
31
+ "https://www.googleapis.com/auth/userinfo.profile",
32
+ "https://www.googleapis.com/auth/cclog",
33
+ "https://www.googleapis.com/auth/experimentsandconfigs",
34
+ ];
35
+ const AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
36
+ const TOKEN_URL = "https://oauth2.googleapis.com/token";
37
+ // Fallback project ID when discovery fails
38
+ const DEFAULT_PROJECT_ID = "rising-fact-p41fc";
39
+ /**
40
+ * Start a local HTTP server to receive the OAuth callback
41
+ */
42
+ async function getNodeCreateServer() {
43
+ if (_createServer)
44
+ return _createServer;
45
+ if (_httpImportPromise) {
46
+ await _httpImportPromise;
47
+ }
48
+ if (_createServer)
49
+ return _createServer;
50
+ throw new Error("Antigravity OAuth is only available in Node.js environments");
51
+ }
52
+ async function startCallbackServer() {
53
+ const createServer = await getNodeCreateServer();
54
+ return new Promise((resolve, reject) => {
55
+ let result = null;
56
+ let cancelled = false;
57
+ const server = createServer((req, res) => {
58
+ const url = new URL(req.url || "", `http://localhost:51121`);
59
+ if (url.pathname === "/oauth-callback") {
60
+ const code = url.searchParams.get("code");
61
+ const state = url.searchParams.get("state");
62
+ const error = url.searchParams.get("error");
63
+ if (error) {
64
+ res.writeHead(400, { "Content-Type": "text/html" });
65
+ res.end(`<html><body><h1>Authentication Failed</h1><p>Error: ${error}</p><p>You can close this window.</p></body></html>`);
66
+ return;
67
+ }
68
+ if (code && state) {
69
+ res.writeHead(200, { "Content-Type": "text/html" });
70
+ res.end(`<html><body><h1>Authentication Successful</h1><p>You can close this window and return to the terminal.</p></body></html>`);
71
+ result = { code, state };
72
+ }
73
+ else {
74
+ res.writeHead(400, { "Content-Type": "text/html" });
75
+ res.end(`<html><body><h1>Authentication Failed</h1><p>Missing code or state parameter.</p></body></html>`);
76
+ }
77
+ }
78
+ else {
79
+ res.writeHead(404);
80
+ res.end();
81
+ }
82
+ });
83
+ server.on("error", (err) => {
84
+ reject(err);
85
+ });
86
+ server.listen(51121, "127.0.0.1", () => {
87
+ resolve({
88
+ server,
89
+ cancelWait: () => {
90
+ cancelled = true;
91
+ },
92
+ waitForCode: async () => {
93
+ const sleep = () => new Promise((r) => setTimeout(r, 100));
94
+ while (!result && !cancelled) {
95
+ await sleep();
96
+ }
97
+ return result;
98
+ },
99
+ });
100
+ });
101
+ });
102
+ }
103
+ /**
104
+ * Parse redirect URL to extract code and state
105
+ */
106
+ function parseRedirectUrl(input) {
107
+ const value = input.trim();
108
+ if (!value)
109
+ return {};
110
+ try {
111
+ const url = new URL(value);
112
+ return {
113
+ code: url.searchParams.get("code") ?? undefined,
114
+ state: url.searchParams.get("state") ?? undefined,
115
+ };
116
+ }
117
+ catch {
118
+ // Not a URL, return empty
119
+ return {};
120
+ }
121
+ }
122
+ /**
123
+ * Discover or provision a project for the user
124
+ */
125
+ async function discoverProject(accessToken, onProgress) {
126
+ const headers = {
127
+ Authorization: `Bearer ${accessToken}`,
128
+ "Content-Type": "application/json",
129
+ "User-Agent": "google-api-nodejs-client/9.15.1",
130
+ "X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1",
131
+ "Client-Metadata": JSON.stringify({
132
+ ideType: "IDE_UNSPECIFIED",
133
+ platform: "PLATFORM_UNSPECIFIED",
134
+ pluginType: "GEMINI",
135
+ }),
136
+ };
137
+ // Try endpoints in order: prod first, then sandbox
138
+ const endpoints = ["https://cloudcode-pa.googleapis.com", "https://daily-cloudcode-pa.sandbox.googleapis.com"];
139
+ onProgress?.("Checking for existing project...");
140
+ for (const endpoint of endpoints) {
141
+ try {
142
+ const loadResponse = await fetch(`${endpoint}/v1internal:loadCodeAssist`, {
143
+ method: "POST",
144
+ headers,
145
+ body: JSON.stringify({
146
+ metadata: {
147
+ ideType: "IDE_UNSPECIFIED",
148
+ platform: "PLATFORM_UNSPECIFIED",
149
+ pluginType: "GEMINI",
150
+ },
151
+ }),
152
+ });
153
+ if (loadResponse.ok) {
154
+ const data = (await loadResponse.json());
155
+ // Handle both string and object formats
156
+ if (typeof data.cloudaicompanionProject === "string" && data.cloudaicompanionProject) {
157
+ return data.cloudaicompanionProject;
158
+ }
159
+ if (data.cloudaicompanionProject &&
160
+ typeof data.cloudaicompanionProject === "object" &&
161
+ data.cloudaicompanionProject.id) {
162
+ return data.cloudaicompanionProject.id;
163
+ }
164
+ }
165
+ }
166
+ catch {
167
+ // Try next endpoint
168
+ }
169
+ }
170
+ // Use fallback project ID
171
+ onProgress?.("Using default project...");
172
+ return DEFAULT_PROJECT_ID;
173
+ }
174
+ /**
175
+ * Get user email from the access token
176
+ */
177
+ async function getUserEmail(accessToken) {
178
+ try {
179
+ const response = await fetch("https://www.googleapis.com/oauth2/v1/userinfo?alt=json", {
180
+ headers: {
181
+ Authorization: `Bearer ${accessToken}`,
182
+ },
183
+ });
184
+ if (response.ok) {
185
+ const data = (await response.json());
186
+ return data.email;
187
+ }
188
+ }
189
+ catch {
190
+ // Ignore errors, email is optional
191
+ }
192
+ return undefined;
193
+ }
194
+ /**
195
+ * Refresh Antigravity token
196
+ */
197
+ export async function refreshAntigravityToken(refreshToken, projectId) {
198
+ const response = await fetch(TOKEN_URL, {
199
+ method: "POST",
200
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
201
+ body: new URLSearchParams({
202
+ client_id: CLIENT_ID,
203
+ client_secret: CLIENT_SECRET,
204
+ refresh_token: refreshToken,
205
+ grant_type: "refresh_token",
206
+ }),
207
+ });
208
+ if (!response.ok) {
209
+ const error = await response.text();
210
+ throw new Error(`Antigravity token refresh failed: ${error}`);
211
+ }
212
+ const data = (await response.json());
213
+ return {
214
+ refresh: data.refresh_token || refreshToken,
215
+ access: data.access_token,
216
+ expires: Date.now() + data.expires_in * 1000 - 5 * 60 * 1000,
217
+ projectId,
218
+ };
219
+ }
220
+ /**
221
+ * Login with Antigravity OAuth
222
+ *
223
+ * @param onAuth - Callback with URL and optional instructions
224
+ * @param onProgress - Optional progress callback
225
+ * @param onManualCodeInput - Optional promise that resolves with user-pasted redirect URL.
226
+ * Races with browser callback - whichever completes first wins.
227
+ */
228
+ export async function loginAntigravity(onAuth, onProgress, onManualCodeInput) {
229
+ const { verifier, challenge } = await generatePKCE();
230
+ // Start local server for callback
231
+ onProgress?.("Starting local server for OAuth callback...");
232
+ const server = await startCallbackServer();
233
+ let code;
234
+ try {
235
+ // Build authorization URL
236
+ const authParams = new URLSearchParams({
237
+ client_id: CLIENT_ID,
238
+ response_type: "code",
239
+ redirect_uri: REDIRECT_URI,
240
+ scope: SCOPES.join(" "),
241
+ code_challenge: challenge,
242
+ code_challenge_method: "S256",
243
+ state: verifier,
244
+ access_type: "offline",
245
+ prompt: "consent",
246
+ });
247
+ const authUrl = `${AUTH_URL}?${authParams.toString()}`;
248
+ // Notify caller with URL to open
249
+ onAuth({
250
+ url: authUrl,
251
+ instructions: "Complete the sign-in in your browser.",
252
+ });
253
+ // Wait for the callback, racing with manual input if provided
254
+ onProgress?.("Waiting for OAuth callback...");
255
+ if (onManualCodeInput) {
256
+ // Race between browser callback and manual input
257
+ let manualInput;
258
+ let manualError;
259
+ const manualPromise = onManualCodeInput()
260
+ .then((input) => {
261
+ manualInput = input;
262
+ server.cancelWait();
263
+ })
264
+ .catch((err) => {
265
+ manualError = err instanceof Error ? err : new Error(String(err));
266
+ server.cancelWait();
267
+ });
268
+ const result = await server.waitForCode();
269
+ // If manual input was cancelled, throw that error
270
+ if (manualError) {
271
+ throw manualError;
272
+ }
273
+ if (result?.code) {
274
+ // Browser callback won - verify state
275
+ if (result.state !== verifier) {
276
+ throw new Error("OAuth state mismatch - possible CSRF attack");
277
+ }
278
+ code = result.code;
279
+ }
280
+ else if (manualInput) {
281
+ // Manual input won
282
+ const parsed = parseRedirectUrl(manualInput);
283
+ if (parsed.state && parsed.state !== verifier) {
284
+ throw new Error("OAuth state mismatch - possible CSRF attack");
285
+ }
286
+ code = parsed.code;
287
+ }
288
+ // If still no code, wait for manual promise and try that
289
+ if (!code) {
290
+ await manualPromise;
291
+ if (manualError) {
292
+ throw manualError;
293
+ }
294
+ if (manualInput) {
295
+ const parsed = parseRedirectUrl(manualInput);
296
+ if (parsed.state && parsed.state !== verifier) {
297
+ throw new Error("OAuth state mismatch - possible CSRF attack");
298
+ }
299
+ code = parsed.code;
300
+ }
301
+ }
302
+ }
303
+ else {
304
+ // Original flow: just wait for callback
305
+ const result = await server.waitForCode();
306
+ if (result?.code) {
307
+ if (result.state !== verifier) {
308
+ throw new Error("OAuth state mismatch - possible CSRF attack");
309
+ }
310
+ code = result.code;
311
+ }
312
+ }
313
+ if (!code) {
314
+ throw new Error("No authorization code received");
315
+ }
316
+ // Exchange code for tokens
317
+ onProgress?.("Exchanging authorization code for tokens...");
318
+ const tokenResponse = await fetch(TOKEN_URL, {
319
+ method: "POST",
320
+ headers: {
321
+ "Content-Type": "application/x-www-form-urlencoded",
322
+ },
323
+ body: new URLSearchParams({
324
+ client_id: CLIENT_ID,
325
+ client_secret: CLIENT_SECRET,
326
+ code,
327
+ grant_type: "authorization_code",
328
+ redirect_uri: REDIRECT_URI,
329
+ code_verifier: verifier,
330
+ }),
331
+ });
332
+ if (!tokenResponse.ok) {
333
+ const error = await tokenResponse.text();
334
+ throw new Error(`Token exchange failed: ${error}`);
335
+ }
336
+ const tokenData = (await tokenResponse.json());
337
+ if (!tokenData.refresh_token) {
338
+ throw new Error("No refresh token received. Please try again.");
339
+ }
340
+ // Get user email
341
+ onProgress?.("Getting user info...");
342
+ const email = await getUserEmail(tokenData.access_token);
343
+ // Discover project
344
+ const projectId = await discoverProject(tokenData.access_token, onProgress);
345
+ // Calculate expiry time (current time + expires_in seconds - 5 min buffer)
346
+ const expiresAt = Date.now() + tokenData.expires_in * 1000 - 5 * 60 * 1000;
347
+ const credentials = {
348
+ refresh: tokenData.refresh_token,
349
+ access: tokenData.access_token,
350
+ expires: expiresAt,
351
+ projectId,
352
+ email,
353
+ };
354
+ return credentials;
355
+ }
356
+ finally {
357
+ server.server.close();
358
+ }
359
+ }
360
+ export const antigravityOAuthProvider = {
361
+ id: "google-antigravity",
362
+ name: "Antigravity (Gemini 3, Claude, GPT-OSS)",
363
+ usesCallbackServer: true,
364
+ async login(callbacks) {
365
+ return loginAntigravity(callbacks.onAuth, callbacks.onProgress, callbacks.onManualCodeInput);
366
+ },
367
+ async refreshToken(credentials) {
368
+ const creds = credentials;
369
+ if (!creds.projectId) {
370
+ throw new Error("Antigravity credentials missing projectId");
371
+ }
372
+ return refreshAntigravityToken(creds.refresh, creds.projectId);
373
+ },
374
+ getApiKey(credentials) {
375
+ const creds = credentials;
376
+ return JSON.stringify({ token: creds.access, projectId: creds.projectId });
377
+ },
378
+ };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Gemini CLI OAuth flow (Google Cloud Code Assist)
3
+ * Standard Gemini models only (gemini-2.0-flash, gemini-2.5-*)
4
+ *
5
+ * NOTE: This module uses Node.js http.createServer for the OAuth callback.
6
+ * It is only intended for CLI use, not browser environments.
7
+ */
8
+ /**
9
+ * [WHO]: geminiCliOAuthProvider
10
+ * [FROM]: Depends on ./pkce.js
11
+ * [TO]: Consumed by core/lib/ai/src/index.ts
12
+ * [HERE]: core/lib/ai/src/utils/oauth/google-gemini-cli.ts -
13
+ */
14
+ import type { OAuthCredentials, OAuthProviderInterface } from "./types.js";
15
+ /**
16
+ * Refresh Google Cloud Code Assist token
17
+ */
18
+ export declare function refreshGoogleCloudToken(refreshToken: string, projectId: string): Promise<OAuthCredentials>;
19
+ /**
20
+ * Login with Gemini CLI (Google Cloud Code Assist) OAuth
21
+ *
22
+ * @param onAuth - Callback with URL and optional instructions
23
+ * @param onProgress - Optional progress callback
24
+ * @param onManualCodeInput - Optional promise that resolves with user-pasted redirect URL.
25
+ * Races with browser callback - whichever completes first wins.
26
+ */
27
+ export declare function loginGeminiCli(onAuth: (info: {
28
+ url: string;
29
+ instructions?: string;
30
+ }) => void, onProgress?: (message: string) => void, onManualCodeInput?: () => Promise<string>): Promise<OAuthCredentials>;
31
+ export declare const geminiCliOAuthProvider: OAuthProviderInterface;