@xopcai/xopc 0.0.485 → 0.0.486
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/dist/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/server/chunks.bin +982 -949
- package/dist/gateway/server/chunks.json +1 -1
- package/dist/gateway/static/root/assets/agent-run-error-parser-DsXmcKt-.js +1 -0
- package/dist/gateway/static/root/assets/{api-CGs641OT.js → api-CGrHK9ij.js} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-CH9wENBj.js → apps-page-6xeWvMpF.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-uY_wmZY1.js → automations-page-BLFBqaPX.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-workspace-DyQq55Rh.js → automations-workspace-DiO3Iyuj.js} +2 -2
- package/dist/gateway/static/root/assets/{capabilities-abgigXV1.js → capabilities-CW-vdkz6.js} +1 -1
- package/dist/gateway/static/root/assets/{capabilities-BaKHutgZ.js → capabilities-DZrjA95P.js} +1 -1
- package/dist/gateway/static/root/assets/capabilities-page-DQrfkrBA.js +2 -0
- package/dist/gateway/static/root/assets/{capabilities-settings-panel-BOwbZn9X.js → capabilities-settings-panel-DIT2dvtc.js} +1 -1
- package/dist/gateway/static/root/assets/{channels-DlnXbcOj.js → channels-Dcr5dgqw.js} +1 -1
- package/dist/gateway/static/root/assets/{chat-page-3fVhP77N.js → chat-page-DWZCzxY7.js} +31 -31
- package/dist/gateway/static/root/assets/{chat-terminal-dock-DE8j-K9d.js → chat-terminal-dock-DCUuwiTt.js} +1 -1
- package/dist/gateway/static/root/assets/composer-payload-handoff-a0quQ25p.js +1 -0
- package/dist/gateway/static/root/assets/connected-providers-grid-BJKEp0SE.js +1 -0
- package/dist/gateway/static/root/assets/{connectors-page-BJm1jjct.js → connectors-page-BteRI1XM.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-D3X7SlzG.js → extension-debug-page-4jJ1uVQJ.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-iframe-host-CIAq7PSn.js → extension-iframe-host-CJV5JETm.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-message-router-B2wbucV7.js → extension-message-router-B4I-Y6qs.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-qwY7r1_p.js → extension-page-lc7a84nG.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-provider-DFcRbTHI.js → extension-provider-D8_mIBI0.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-Cpnh9lcZ.js → extension-settings-page-Uw2lfWRh.js} +1 -1
- package/dist/gateway/static/root/assets/{home-page-BusNFHe-.js → home-page-mSRCU81k.js} +4 -4
- package/dist/gateway/static/root/assets/{home-task-actions-C8Fi6GBq.js → home-task-actions-_ZAc57Y7.js} +1 -1
- package/dist/gateway/static/root/assets/{index-790PGhZb.js → index-CJAEAcZV.js} +7 -7
- package/dist/gateway/static/root/assets/{local-app-workbench-page-B9uSL1Mi.js → local-app-workbench-page-C3Lqi8E1.js} +1 -1
- package/dist/gateway/static/root/assets/{note-detail-panel-Bwm_aehq.js → note-detail-panel-uc-5k3a2.js} +3 -3
- package/dist/gateway/static/root/assets/{notes-page-DkZWV3Ds.js → notes-page-RPfvHnl6.js} +1 -1
- package/dist/gateway/static/root/assets/{page-context-capture-button-BXSBeGms.js → page-context-capture-button-CVHz9b6c.js} +1 -1
- package/dist/gateway/static/root/assets/{personal-page-cauym9hr.js → personal-page-Dt1d3tQT.js} +1 -1
- package/dist/gateway/static/root/assets/{personal-profile-settings-TcI0Zfwr.js → personal-profile-settings-XiT1MgTK.js} +1 -1
- package/dist/gateway/static/root/assets/{personal-settings-panel-BJ46T7ZO.js → personal-settings-panel-bcw04REt.js} +1 -1
- package/dist/gateway/static/root/assets/{preview-runtime-C1U57WSM.js → preview-runtime-FtWOW5i4.js} +1 -1
- package/dist/gateway/static/root/assets/{product-automation-feedback-GA_YPLkr.js → product-automation-feedback-DdFoCDzG.js} +1 -1
- package/dist/gateway/static/root/assets/product-preview-content-B3mzl6-f.js +1 -0
- package/dist/gateway/static/root/assets/product-preview-modal-5kTp_7Qk.js +2 -0
- package/dist/gateway/static/root/assets/project-detail-page-DGPfKx5M.js +7 -0
- package/dist/gateway/static/root/assets/{projects-page-BHQxQGTd.js → projects-page-C-9x23LR.js} +1 -1
- package/dist/gateway/static/root/assets/route-preload-CzorjVc9.js +2 -0
- package/dist/gateway/static/root/assets/routine-panel-n4IstC8Y.js +2 -0
- package/dist/gateway/static/root/assets/session-manager-C2MCS4C5.js +28 -0
- package/dist/gateway/static/root/assets/{settings-page-Cd9WZ-Ac.js → settings-page-DsM_f07M.js} +1 -1
- package/dist/gateway/static/root/assets/{share-preview-page-Di5_ukH8.js → share-preview-page-C32Mq-BY.js} +1 -1
- package/dist/gateway/static/root/assets/{shares-settings-CirGM67m.js → shares-settings-BDGbs8wz.js} +1 -1
- package/dist/gateway/static/root/assets/space-page-DwyuUvI3.js +2 -0
- package/dist/gateway/static/root/assets/task-copy-CtcqCQ78.js +1 -0
- package/dist/gateway/static/root/assets/task-detail-page-DdCpNW8K.js +3 -0
- package/dist/gateway/static/root/assets/{task-header-title-qzNctGl5.js → task-header-title-CLt_lmjb.js} +1 -1
- package/dist/gateway/static/root/assets/task-result-presentation-CgvcqEMD.js +1 -0
- package/dist/gateway/static/root/assets/task-run-issue-notice-8FX876PP.js +1 -0
- package/dist/gateway/static/root/assets/tasks-CvOAtEHv.js +1 -0
- package/dist/gateway/static/root/assets/turn-outcome-Dtw6OgwL.js +1 -0
- package/dist/gateway/static/root/assets/{use-composer-attachments-DJsIzJ1c.js → use-composer-attachments-BEuyorVm.js} +1 -1
- package/dist/gateway/static/root/assets/{use-file-preview-expanded-BFF2vXm5.js → use-file-preview-expanded-Cehu0745.js} +1 -1
- package/dist/gateway/static/root/assets/use-personal-work-B25WRGHj.js +1 -0
- package/dist/gateway/static/root/assets/{use-realtime-voice-9OvLwHzk.js → use-realtime-voice-CV3GIt_T.js} +1 -1
- package/dist/gateway/static/root/assets/{use-workspace-tree-LCIT1H-D.js → use-workspace-tree-C0C861cb.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-settings-j8o-hGTm.js → voice-settings-JpPo3BvX.js} +1 -1
- package/dist/gateway/static/root/assets/workspace-api-CQOuWbVv.js +2 -0
- package/dist/gateway/static/root/assets/{workspace-file-preview-dialog-DwVWTehC.js → workspace-file-preview-dialog-CmMueTmW.js} +1 -1
- package/dist/gateway/static/root/index.html +29 -27
- package/dist/package.js +1 -1
- package/dist/packages/gateway-contract/src/index.js +3 -1
- package/dist/packages/gateway-contract/src/notifications.js +1 -8
- package/dist/packages/gateway-contract/src/task-display.js +9 -2
- package/dist/packages/gateway-contract/src/task-lifecycle.js +1 -0
- package/dist/packages/gateway-contract/src/task-research-result.js +2 -1
- package/dist/packages/gateway-contract/src/tasks.js +6 -1
- package/dist/packages/gateway-contract/src/user-message-text.js +64 -0
- package/dist/src/agent/embedded/run-for-session.js +27 -28
- package/dist/src/agent/embedded/session-runner.js +14 -1
- package/dist/src/agent/fallback/candidates.d.ts +1 -0
- package/dist/src/agent/fallback/candidates.js +1 -1
- package/dist/src/agent/image/generation/provider-registry.js +3 -1
- package/dist/src/agent/models/manager.d.ts +1 -1
- package/dist/src/agent/models/manager.js +2 -1
- package/dist/src/agent/models/turn-candidates.d.ts +16 -0
- package/dist/src/agent/models/turn-candidates.js +55 -0
- package/dist/src/agent/service.d.ts +1 -0
- package/dist/src/agent/service.js +12 -0
- package/dist/src/agent/skills/installer.js +2 -2
- package/dist/src/auth/credentials.js +3 -1
- package/dist/src/auth/oauth/index.d.ts +0 -1
- package/dist/src/auth/oauth/index.js +1 -4
- package/dist/src/auth/oauth/registry.js +0 -4
- package/dist/src/auth/oauth/xopc-cloud.js +1 -1
- package/dist/src/cli/command-manifest.js +1 -1
- package/dist/src/cli/commands/auth.js +4 -2
- package/dist/src/cli/commands/models.js +12 -10
- package/dist/src/config/models-json.js +1 -2
- package/dist/src/gateway/agent-reactions/reaction.d.ts +1 -2
- package/dist/src/gateway/agent-reactions/reaction.js +10 -21
- package/dist/src/gateway/custom-image-providers.js +4 -1
- package/dist/src/gateway/hono/oauth.js +3 -0
- package/dist/src/gateway/hono/routes/device-push.js +55 -15
- package/dist/src/gateway/hono/routes/home.js +1 -1
- package/dist/src/gateway/hono/routes/mobile-mcp-setup.js +49 -29
- package/dist/src/gateway/hono/routes/notifications.js +12 -1
- package/dist/src/gateway/hono/routes/sessions.js +1 -13
- package/dist/src/gateway/security/gateway-scopes.js +1 -0
- package/dist/src/gateway/service/run-gateway-agent.js +2 -13
- package/dist/src/gateway/service.js +84 -64
- package/dist/src/home-intelligence/host.js +5 -5
- package/dist/src/local-apps/capabilities/projections.d.ts +5 -5
- package/dist/src/notifications/device-store.d.ts +3 -0
- package/dist/src/notifications/device-store.js +14 -1
- package/dist/src/notifications/platform-push.d.ts +17 -0
- package/dist/src/notifications/platform-push.js +58 -0
- package/dist/src/notifications/service.d.ts +2 -2
- package/dist/src/notifications/service.js +26 -12
- package/dist/src/notifications/store.d.ts +1 -1
- package/dist/src/notifications/store.js +3 -2
- package/dist/src/providers/env-keys.js +0 -1
- package/dist/src/providers/index.js +1 -7
- package/dist/src/providers/model-catalog-sync-service.js +3 -1
- package/dist/src/providers/model-registry.js +6 -2
- package/dist/src/providers/presentation.js +1 -2
- package/dist/src/providers/provider-policy.js +2 -1
- package/dist/src/session/client-history.js +3 -3
- package/dist/src/session/user-message-display.js +3 -2
- package/dist/src/storage/sqlite/agent-reaction-repository.d.ts +2 -4
- package/dist/src/storage/sqlite/agent-reaction-repository.js +18 -13
- package/dist/src/storage/sqlite/device-access-repository.js +2 -1
- package/dist/src/tasks/capabilities/write.d.ts +2 -0
- package/dist/src/tasks/home-query-service.js +2 -1
- package/dist/src/tasks/task-contract-planner.js +1 -0
- package/dist/src/tasks/task-conversation-summary.d.ts +1 -1
- package/dist/src/tasks/task-delivery-checks.d.ts +12 -0
- package/dist/src/tasks/task-delivery-checks.js +91 -0
- package/dist/src/tasks/task-final-reply.d.ts +3 -1
- package/dist/src/tasks/task-final-reply.js +17 -4
- package/dist/src/tasks/task-model-call.js +4 -2
- package/dist/src/tasks/task-origin-repository.d.ts +1 -1
- package/dist/src/tasks/task-read-model-projector.js +24 -7
- package/dist/src/tasks/task-research-result.js +12 -27
- package/dist/src/tasks/task-result-delivery-repository.js +3 -2
- package/dist/src/tasks/task-retry-service.js +2 -1
- package/dist/src/tasks/task-run-coordinator.js +14 -4
- package/dist/src/tasks/task-run-dispatcher.d.ts +1 -0
- package/dist/src/tasks/task-run-dispatcher.js +78 -48
- package/dist/src/tasks/task-run-repository.js +1 -1
- package/package.json +1 -1
- package/dist/gateway/static/root/assets/capabilities-page-WCl7Fdce.js +0 -2
- package/dist/gateway/static/root/assets/composer-payload-handoff-ClWsunJ2.js +0 -1
- package/dist/gateway/static/root/assets/connected-providers-grid-BgW-ioIt.js +0 -1
- package/dist/gateway/static/root/assets/product-preview-content-BOq3gtSJ.js +0 -1
- package/dist/gateway/static/root/assets/product-preview-modal-DIh_CsXp.js +0 -2
- package/dist/gateway/static/root/assets/project-detail-page-D9WKZe3z.js +0 -7
- package/dist/gateway/static/root/assets/route-preload-DF8LOfKW.js +0 -2
- package/dist/gateway/static/root/assets/routine-panel-Bfbiz0IN.js +0 -2
- package/dist/gateway/static/root/assets/session-manager-DUWeBdeG.js +0 -28
- package/dist/gateway/static/root/assets/space-page-DlJB7GT1.js +0 -2
- package/dist/gateway/static/root/assets/task-detail-page-BFa0Px-B.js +0 -3
- package/dist/gateway/static/root/assets/task-run-issue-notice-CGrUMy0s.js +0 -1
- package/dist/gateway/static/root/assets/tasks-CwyNaa-j.js +0 -1
- package/dist/gateway/static/root/assets/turn-outcome-BSbEJx8h.js +0 -1
- package/dist/gateway/static/root/assets/use-personal-work-B1DWeBnm.js +0 -1
- package/dist/gateway/static/root/assets/workspace-api-BuNWyNvA.js +0 -2
- package/dist/src/auth/oauth/google-antigravity.d.ts +0 -4
- package/dist/src/auth/oauth/google-antigravity.js +0 -9
- package/dist/src/auth/oauth/google-oauth/google-antigravity.d.ts +0 -25
- package/dist/src/auth/oauth/google-oauth/google-antigravity.js +0 -309
- package/dist/src/notifications/harmony-push.d.ts +0 -27
- package/dist/src/notifications/harmony-push.js +0 -96
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
import { __esmMin } from "../../../../_virtual/_rolldown/runtime.js";
|
|
2
|
-
import { init_oauth_page, oauthErrorHtml, oauthSuccessHtml } from "./oauth-page.js";
|
|
3
|
-
import { generatePKCE, init_pkce } from "./pkce.js";
|
|
4
|
-
//#region src/auth/oauth/google-oauth/google-antigravity.ts
|
|
5
|
-
/** Desktop OAuth client for this flow — must be set locally (not committed; avoids GitHub push protection). */
|
|
6
|
-
function getAntigravityOAuthClient() {
|
|
7
|
-
const clientId = process.env[ANTIGRAVITY_CLIENT_ID_ENV]?.trim();
|
|
8
|
-
const clientSecret = process.env[ANTIGRAVITY_CLIENT_SECRET_ENV]?.trim();
|
|
9
|
-
if (!clientId || !clientSecret) throw new Error(`Google Antigravity OAuth requires ${ANTIGRAVITY_CLIENT_ID_ENV} and ${ANTIGRAVITY_CLIENT_SECRET_ENV}.`);
|
|
10
|
-
return {
|
|
11
|
-
clientId,
|
|
12
|
-
clientSecret
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Start a local HTTP server to receive the OAuth callback
|
|
17
|
-
*/
|
|
18
|
-
async function getNodeCreateServer() {
|
|
19
|
-
if (_createServer) return _createServer;
|
|
20
|
-
if (_httpImportPromise) await _httpImportPromise;
|
|
21
|
-
if (_createServer) return _createServer;
|
|
22
|
-
throw new Error("Antigravity OAuth is only available in Node.js environments");
|
|
23
|
-
}
|
|
24
|
-
async function startCallbackServer() {
|
|
25
|
-
const createServer = await getNodeCreateServer();
|
|
26
|
-
return new Promise((resolve, reject) => {
|
|
27
|
-
let settleWait;
|
|
28
|
-
const waitForCodePromise = new Promise((resolveWait) => {
|
|
29
|
-
let settled = false;
|
|
30
|
-
settleWait = (value) => {
|
|
31
|
-
if (settled) return;
|
|
32
|
-
settled = true;
|
|
33
|
-
resolveWait(value);
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
const server = createServer((req, res) => {
|
|
37
|
-
const url = new URL(req.url || "", `http://localhost:51121`);
|
|
38
|
-
if (url.pathname === "/oauth-callback") {
|
|
39
|
-
const code = url.searchParams.get("code");
|
|
40
|
-
const state = url.searchParams.get("state");
|
|
41
|
-
const error = url.searchParams.get("error");
|
|
42
|
-
if (error) {
|
|
43
|
-
res.writeHead(400, { "Content-Type": "text/html; charset=utf-8" });
|
|
44
|
-
res.end(oauthErrorHtml("Google authentication did not complete.", `Error: ${error}`));
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (code && state) {
|
|
48
|
-
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
49
|
-
res.end(oauthSuccessHtml("Google authentication completed. You can close this window."));
|
|
50
|
-
settleWait?.({
|
|
51
|
-
code,
|
|
52
|
-
state
|
|
53
|
-
});
|
|
54
|
-
} else {
|
|
55
|
-
res.writeHead(400, { "Content-Type": "text/html; charset=utf-8" });
|
|
56
|
-
res.end(oauthErrorHtml("Missing code or state parameter."));
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
res.writeHead(404, { "Content-Type": "text/html; charset=utf-8" });
|
|
60
|
-
res.end(oauthErrorHtml("Callback route not found."));
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
server.on("error", (err) => {
|
|
64
|
-
reject(err);
|
|
65
|
-
});
|
|
66
|
-
server.listen(51121, () => {
|
|
67
|
-
resolve({
|
|
68
|
-
server,
|
|
69
|
-
cancelWait: () => {
|
|
70
|
-
settleWait?.(null);
|
|
71
|
-
},
|
|
72
|
-
waitForCode: () => waitForCodePromise
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Parse redirect URL to extract code and state
|
|
79
|
-
*/
|
|
80
|
-
function parseRedirectUrl(input) {
|
|
81
|
-
const value = input.trim();
|
|
82
|
-
if (!value) return {};
|
|
83
|
-
try {
|
|
84
|
-
const url = new URL(value);
|
|
85
|
-
return {
|
|
86
|
-
code: url.searchParams.get("code") ?? void 0,
|
|
87
|
-
state: url.searchParams.get("state") ?? void 0
|
|
88
|
-
};
|
|
89
|
-
} catch {
|
|
90
|
-
return {};
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Discover or provision a project for the user
|
|
95
|
-
*/
|
|
96
|
-
async function discoverProject(accessToken, onProgress) {
|
|
97
|
-
const headers = {
|
|
98
|
-
Authorization: `Bearer ${accessToken}`,
|
|
99
|
-
"Content-Type": "application/json",
|
|
100
|
-
"User-Agent": "google-api-nodejs-client/9.15.1",
|
|
101
|
-
"X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1",
|
|
102
|
-
"Client-Metadata": JSON.stringify({
|
|
103
|
-
ideType: "IDE_UNSPECIFIED",
|
|
104
|
-
platform: "PLATFORM_UNSPECIFIED",
|
|
105
|
-
pluginType: "GEMINI"
|
|
106
|
-
})
|
|
107
|
-
};
|
|
108
|
-
const endpoints = ["https://cloudcode-pa.googleapis.com", "https://daily-cloudcode-pa.sandbox.googleapis.com"];
|
|
109
|
-
onProgress?.("Checking for existing project...");
|
|
110
|
-
for (const endpoint of endpoints) try {
|
|
111
|
-
const loadResponse = await fetch(`${endpoint}/v1internal:loadCodeAssist`, {
|
|
112
|
-
method: "POST",
|
|
113
|
-
headers,
|
|
114
|
-
body: JSON.stringify({ metadata: {
|
|
115
|
-
ideType: "IDE_UNSPECIFIED",
|
|
116
|
-
platform: "PLATFORM_UNSPECIFIED",
|
|
117
|
-
pluginType: "GEMINI"
|
|
118
|
-
} })
|
|
119
|
-
});
|
|
120
|
-
if (loadResponse.ok) {
|
|
121
|
-
const data = await loadResponse.json();
|
|
122
|
-
if (typeof data.cloudaicompanionProject === "string" && data.cloudaicompanionProject) return data.cloudaicompanionProject;
|
|
123
|
-
if (data.cloudaicompanionProject && typeof data.cloudaicompanionProject === "object" && data.cloudaicompanionProject.id) return data.cloudaicompanionProject.id;
|
|
124
|
-
}
|
|
125
|
-
} catch {}
|
|
126
|
-
throw new Error("Failed to discover Google Cloud companion project");
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Get user email from the access token
|
|
130
|
-
*/
|
|
131
|
-
async function getUserEmail(accessToken) {
|
|
132
|
-
try {
|
|
133
|
-
const response = await fetch("https://www.googleapis.com/oauth2/v1/userinfo?alt=json", { headers: { Authorization: `Bearer ${accessToken}` } });
|
|
134
|
-
if (response.ok) return (await response.json()).email;
|
|
135
|
-
} catch {}
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Refresh Antigravity token
|
|
139
|
-
*/
|
|
140
|
-
async function refreshAntigravityToken(refreshToken, projectId) {
|
|
141
|
-
const { clientId, clientSecret } = getAntigravityOAuthClient();
|
|
142
|
-
const response = await fetch(TOKEN_URL, {
|
|
143
|
-
method: "POST",
|
|
144
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
145
|
-
body: new URLSearchParams({
|
|
146
|
-
client_id: clientId,
|
|
147
|
-
client_secret: clientSecret,
|
|
148
|
-
refresh_token: refreshToken,
|
|
149
|
-
grant_type: "refresh_token"
|
|
150
|
-
})
|
|
151
|
-
});
|
|
152
|
-
if (!response.ok) {
|
|
153
|
-
const error = await response.text();
|
|
154
|
-
throw new Error(`Antigravity token refresh failed: ${error}`);
|
|
155
|
-
}
|
|
156
|
-
const data = await response.json();
|
|
157
|
-
return {
|
|
158
|
-
refresh: data.refresh_token || refreshToken,
|
|
159
|
-
access: data.access_token,
|
|
160
|
-
expires: Date.now() + data.expires_in * 1e3 - 300 * 1e3,
|
|
161
|
-
projectId
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Login with Antigravity OAuth
|
|
166
|
-
*
|
|
167
|
-
* @param onAuth - Callback with URL and optional instructions
|
|
168
|
-
* @param onProgress - Optional progress callback
|
|
169
|
-
* @param onManualCodeInput - Optional promise that resolves with user-pasted redirect URL.
|
|
170
|
-
* Races with browser callback - whichever completes first wins.
|
|
171
|
-
*/
|
|
172
|
-
async function loginAntigravity(onAuth, onProgress, onManualCodeInput) {
|
|
173
|
-
const { verifier, challenge } = await generatePKCE();
|
|
174
|
-
const { clientId, clientSecret } = getAntigravityOAuthClient();
|
|
175
|
-
onProgress?.("Starting local server for OAuth callback...");
|
|
176
|
-
const server = await startCallbackServer();
|
|
177
|
-
let code;
|
|
178
|
-
try {
|
|
179
|
-
onAuth({
|
|
180
|
-
url: `${AUTH_URL}?${new URLSearchParams({
|
|
181
|
-
client_id: clientId,
|
|
182
|
-
response_type: "code",
|
|
183
|
-
redirect_uri: REDIRECT_URI,
|
|
184
|
-
scope: SCOPES.join(" "),
|
|
185
|
-
code_challenge: challenge,
|
|
186
|
-
code_challenge_method: "S256",
|
|
187
|
-
state: verifier,
|
|
188
|
-
access_type: "offline",
|
|
189
|
-
prompt: "consent"
|
|
190
|
-
}).toString()}`,
|
|
191
|
-
instructions: "Complete the sign-in in your browser."
|
|
192
|
-
});
|
|
193
|
-
onProgress?.("Waiting for OAuth callback...");
|
|
194
|
-
if (onManualCodeInput) {
|
|
195
|
-
let manualInput;
|
|
196
|
-
let manualError;
|
|
197
|
-
const manualPromise = onManualCodeInput().then((input) => {
|
|
198
|
-
manualInput = input;
|
|
199
|
-
server.cancelWait();
|
|
200
|
-
}).catch((err) => {
|
|
201
|
-
manualError = err instanceof Error ? err : new Error(String(err));
|
|
202
|
-
server.cancelWait();
|
|
203
|
-
});
|
|
204
|
-
const result = await server.waitForCode();
|
|
205
|
-
if (manualError) throw manualError;
|
|
206
|
-
if (result?.code) {
|
|
207
|
-
if (result.state !== verifier) throw new Error("OAuth state mismatch - possible CSRF attack");
|
|
208
|
-
code = result.code;
|
|
209
|
-
} else if (manualInput) {
|
|
210
|
-
const parsed = parseRedirectUrl(manualInput);
|
|
211
|
-
if (parsed.state && parsed.state !== verifier) throw new Error("OAuth state mismatch - possible CSRF attack");
|
|
212
|
-
code = parsed.code;
|
|
213
|
-
}
|
|
214
|
-
if (!code) {
|
|
215
|
-
await manualPromise;
|
|
216
|
-
if (manualError) throw manualError;
|
|
217
|
-
if (manualInput) {
|
|
218
|
-
const parsed = parseRedirectUrl(manualInput);
|
|
219
|
-
if (parsed.state && parsed.state !== verifier) throw new Error("OAuth state mismatch - possible CSRF attack");
|
|
220
|
-
code = parsed.code;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
} else {
|
|
224
|
-
const result = await server.waitForCode();
|
|
225
|
-
if (result?.code) {
|
|
226
|
-
if (result.state !== verifier) throw new Error("OAuth state mismatch - possible CSRF attack");
|
|
227
|
-
code = result.code;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
if (!code) throw new Error("No authorization code received");
|
|
231
|
-
onProgress?.("Exchanging authorization code for tokens...");
|
|
232
|
-
const tokenResponse = await fetch(TOKEN_URL, {
|
|
233
|
-
method: "POST",
|
|
234
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
235
|
-
body: new URLSearchParams({
|
|
236
|
-
client_id: clientId,
|
|
237
|
-
client_secret: clientSecret,
|
|
238
|
-
code,
|
|
239
|
-
grant_type: "authorization_code",
|
|
240
|
-
redirect_uri: REDIRECT_URI,
|
|
241
|
-
code_verifier: verifier
|
|
242
|
-
})
|
|
243
|
-
});
|
|
244
|
-
if (!tokenResponse.ok) {
|
|
245
|
-
const error = await tokenResponse.text();
|
|
246
|
-
throw new Error(`Token exchange failed: ${error}`);
|
|
247
|
-
}
|
|
248
|
-
const tokenData = await tokenResponse.json();
|
|
249
|
-
if (!tokenData.refresh_token) throw new Error("No refresh token received. Please try again.");
|
|
250
|
-
onProgress?.("Getting user info...");
|
|
251
|
-
const email = await getUserEmail(tokenData.access_token);
|
|
252
|
-
const projectId = await discoverProject(tokenData.access_token, onProgress);
|
|
253
|
-
const expiresAt = Date.now() + tokenData.expires_in * 1e3 - 300 * 1e3;
|
|
254
|
-
return {
|
|
255
|
-
refresh: tokenData.refresh_token,
|
|
256
|
-
access: tokenData.access_token,
|
|
257
|
-
expires: expiresAt,
|
|
258
|
-
projectId,
|
|
259
|
-
email
|
|
260
|
-
};
|
|
261
|
-
} finally {
|
|
262
|
-
server.server.close();
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
var _createServer, _httpImportPromise, ANTIGRAVITY_CLIENT_ID_ENV, ANTIGRAVITY_CLIENT_SECRET_ENV, REDIRECT_URI, SCOPES, AUTH_URL, TOKEN_URL, antigravityOAuthProvider;
|
|
266
|
-
var init_google_antigravity = __esmMin((() => {
|
|
267
|
-
init_oauth_page();
|
|
268
|
-
init_pkce();
|
|
269
|
-
_createServer = null;
|
|
270
|
-
_httpImportPromise = null;
|
|
271
|
-
if (typeof process !== "undefined" && (process.versions?.node || process.versions?.bun)) _httpImportPromise = import("node:http").then((m) => {
|
|
272
|
-
_createServer = m.createServer;
|
|
273
|
-
});
|
|
274
|
-
ANTIGRAVITY_CLIENT_ID_ENV = "XOPC_GOOGLE_ANTIGRAVITY_OAUTH_CLIENT_ID";
|
|
275
|
-
ANTIGRAVITY_CLIENT_SECRET_ENV = "XOPC_GOOGLE_ANTIGRAVITY_OAUTH_CLIENT_SECRET";
|
|
276
|
-
REDIRECT_URI = "http://localhost:51121/oauth-callback";
|
|
277
|
-
SCOPES = [
|
|
278
|
-
"https://www.googleapis.com/auth/cloud-platform",
|
|
279
|
-
"https://www.googleapis.com/auth/userinfo.email",
|
|
280
|
-
"https://www.googleapis.com/auth/userinfo.profile",
|
|
281
|
-
"https://www.googleapis.com/auth/cclog",
|
|
282
|
-
"https://www.googleapis.com/auth/experimentsandconfigs"
|
|
283
|
-
];
|
|
284
|
-
AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
285
|
-
TOKEN_URL = "https://oauth2.googleapis.com/token";
|
|
286
|
-
antigravityOAuthProvider = {
|
|
287
|
-
id: "google-antigravity",
|
|
288
|
-
name: "Antigravity (Gemini 3, Claude, GPT-OSS)",
|
|
289
|
-
usesCallbackServer: true,
|
|
290
|
-
async login(callbacks) {
|
|
291
|
-
return loginAntigravity(callbacks.onAuth, callbacks.onProgress, callbacks.onManualCodeInput);
|
|
292
|
-
},
|
|
293
|
-
async refreshToken(credentials) {
|
|
294
|
-
const creds = credentials;
|
|
295
|
-
if (!creds.projectId) throw new Error("Antigravity credentials missing projectId");
|
|
296
|
-
return refreshAntigravityToken(creds.refresh, creds.projectId);
|
|
297
|
-
},
|
|
298
|
-
getApiKey(credentials) {
|
|
299
|
-
const creds = credentials;
|
|
300
|
-
return JSON.stringify({
|
|
301
|
-
token: creds.access,
|
|
302
|
-
projectId: creds.projectId
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
};
|
|
306
|
-
}));
|
|
307
|
-
//#endregion
|
|
308
|
-
init_google_antigravity();
|
|
309
|
-
export { antigravityOAuthProvider, init_google_antigravity, loginAntigravity, refreshAntigravityToken };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { NotificationTarget } from '@xopcai/gateway-contract';
|
|
2
|
-
type ServiceAccount = {
|
|
3
|
-
project_id: string;
|
|
4
|
-
key_id: string;
|
|
5
|
-
sub_account: string;
|
|
6
|
-
private_key: string;
|
|
7
|
-
};
|
|
8
|
-
type PushCategory = 'WORK' | 'IM' | 'MARKETING';
|
|
9
|
-
export type HarmonyPushConfig = {
|
|
10
|
-
accountFile: string;
|
|
11
|
-
category: PushCategory;
|
|
12
|
-
testMessage: boolean;
|
|
13
|
-
};
|
|
14
|
-
export type HarmonyNotification = {
|
|
15
|
-
pushToken: string;
|
|
16
|
-
eventId: string;
|
|
17
|
-
title: string;
|
|
18
|
-
body?: string;
|
|
19
|
-
gatewayId?: string;
|
|
20
|
-
target?: NotificationTarget;
|
|
21
|
-
expiresAt?: number;
|
|
22
|
-
};
|
|
23
|
-
export declare function harmonyPushConfig(env?: NodeJS.ProcessEnv): HarmonyPushConfig | undefined;
|
|
24
|
-
export declare function createHarmonyPushJwt(account: ServiceAccount, now?: number): string;
|
|
25
|
-
/** Uses HarmonyOS V3 service-account authentication, not the Android HMS OAuth flow. */
|
|
26
|
-
export declare function sendHarmonyPush(notification: HarmonyNotification, fetchImpl?: typeof fetch, config?: HarmonyPushConfig | undefined): Promise<string>;
|
|
27
|
-
export {};
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { isAbsolute } from "node:path";
|
|
2
|
-
import { constants, createHash, createPrivateKey, sign } from "node:crypto";
|
|
3
|
-
import { readFile } from "node:fs/promises";
|
|
4
|
-
//#region src/notifications/harmony-push.ts
|
|
5
|
-
function harmonyPushConfig(env = process.env) {
|
|
6
|
-
const accountFile = env.XOPC_HARMONY_PUSH_SERVICE_ACCOUNT?.trim();
|
|
7
|
-
const category = env.XOPC_HARMONY_PUSH_CATEGORY;
|
|
8
|
-
if (!accountFile || !isAbsolute(accountFile) || ![
|
|
9
|
-
"WORK",
|
|
10
|
-
"IM",
|
|
11
|
-
"MARKETING"
|
|
12
|
-
].includes(category ?? "")) return void 0;
|
|
13
|
-
return {
|
|
14
|
-
accountFile,
|
|
15
|
-
category,
|
|
16
|
-
testMessage: env.XOPC_HARMONY_PUSH_TEST_MESSAGE === "true"
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
function createHarmonyPushJwt(account, now = Date.now()) {
|
|
20
|
-
if (!/^\d+$/.test(account.project_id) || !account.key_id || !account.sub_account || !account.private_key) throw new Error("Invalid Harmony push service account");
|
|
21
|
-
const key = createPrivateKey(account.private_key);
|
|
22
|
-
if (key.asymmetricKeyType !== "rsa" || (key.asymmetricKeyDetails?.modulusLength ?? 0) < 2048) throw new Error("Harmony push requires an RSA service account key of at least 2048 bits");
|
|
23
|
-
const iat = Math.floor(now / 1e3);
|
|
24
|
-
const input = `${Buffer.from(JSON.stringify({
|
|
25
|
-
alg: "PS256",
|
|
26
|
-
typ: "JWT",
|
|
27
|
-
kid: account.key_id
|
|
28
|
-
})).toString("base64url")}.${Buffer.from(JSON.stringify({
|
|
29
|
-
iss: account.sub_account,
|
|
30
|
-
aud: "https://oauth-login.cloud.huawei.com/oauth2/v3/token",
|
|
31
|
-
iat,
|
|
32
|
-
exp: iat + 3600
|
|
33
|
-
})).toString("base64url")}`;
|
|
34
|
-
return `${input}.${sign("sha256", Buffer.from(input), {
|
|
35
|
-
key,
|
|
36
|
-
padding: constants.RSA_PKCS1_PSS_PADDING,
|
|
37
|
-
saltLength: constants.RSA_PSS_SALTLEN_DIGEST
|
|
38
|
-
}).toString("base64url")}`;
|
|
39
|
-
}
|
|
40
|
-
/** Uses HarmonyOS V3 service-account authentication, not the Android HMS OAuth flow. */
|
|
41
|
-
async function sendHarmonyPush(notification, fetchImpl = fetch, config = harmonyPushConfig()) {
|
|
42
|
-
if (!config) throw new Error("Harmony push is not configured");
|
|
43
|
-
let account;
|
|
44
|
-
let jwt;
|
|
45
|
-
try {
|
|
46
|
-
account = JSON.parse(await readFile(config.accountFile, "utf8"));
|
|
47
|
-
jwt = createHarmonyPushJwt(account);
|
|
48
|
-
} catch {
|
|
49
|
-
throw new Error("Harmony push service account could not be loaded");
|
|
50
|
-
}
|
|
51
|
-
const notifyId = createHash("sha256").update(notification.eventId).digest().readUInt32BE(0) & 2147483647;
|
|
52
|
-
const navigation = notification.gatewayId && notification.target ? Buffer.from(JSON.stringify({
|
|
53
|
-
gatewayId: notification.gatewayId,
|
|
54
|
-
eventId: notification.eventId,
|
|
55
|
-
target: notification.target
|
|
56
|
-
})).toString("base64url") : void 0;
|
|
57
|
-
const ttl = notification.expiresAt === void 0 ? 86400 : Math.min(86400, Math.floor((notification.expiresAt - Date.now()) / 1e3));
|
|
58
|
-
if (ttl <= 0) throw new Error("Notification expired before delivery");
|
|
59
|
-
const response = await fetchImpl(`https://push-api.cloud.huawei.com/v3/${account.project_id}/messages:send`, {
|
|
60
|
-
method: "POST",
|
|
61
|
-
redirect: "error",
|
|
62
|
-
signal: AbortSignal.timeout(1e4),
|
|
63
|
-
headers: {
|
|
64
|
-
"Content-Type": "application/json",
|
|
65
|
-
Authorization: `Bearer ${jwt}`,
|
|
66
|
-
"push-type": "0"
|
|
67
|
-
},
|
|
68
|
-
body: JSON.stringify({
|
|
69
|
-
payload: { notification: {
|
|
70
|
-
category: config.category,
|
|
71
|
-
title: notification.title.slice(0, 100),
|
|
72
|
-
body: (notification.body || notification.title).slice(0, 200),
|
|
73
|
-
clickAction: navigation ? {
|
|
74
|
-
actionType: 1,
|
|
75
|
-
uri: `xopc://notification#p=${navigation}`
|
|
76
|
-
} : { actionType: 0 },
|
|
77
|
-
foregroundShow: false,
|
|
78
|
-
notifyId
|
|
79
|
-
} },
|
|
80
|
-
target: { token: [notification.pushToken] },
|
|
81
|
-
pushOptions: {
|
|
82
|
-
testMessage: config.testMessage,
|
|
83
|
-
ttl
|
|
84
|
-
}
|
|
85
|
-
})
|
|
86
|
-
});
|
|
87
|
-
if (!response.ok) throw new Error(`Harmony push request failed (${response.status})`);
|
|
88
|
-
const result = await response.json();
|
|
89
|
-
if (result.code !== "80000000" || typeof result.requestId !== "string" || !result.requestId) {
|
|
90
|
-
const code = typeof result.code === "string" && /^\d{8}$/.test(result.code) ? result.code : "invalid_response";
|
|
91
|
-
throw new Error(`Harmony push rejected (${code})`);
|
|
92
|
-
}
|
|
93
|
-
return result.requestId;
|
|
94
|
-
}
|
|
95
|
-
//#endregion
|
|
96
|
-
export { createHarmonyPushJwt, harmonyPushConfig, sendHarmonyPush };
|