@anthonyhaussman/opencode-agy-auth 1.1.19-alpha.0 → 1.1.19-alpha.1
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 +0 -13
- package/dist/index.js +53 -149
- package/dist/index.js.map +1 -1
- package/dist/src/constants.d.ts +2 -2
- package/package.json +1 -1
- package/dist/src/sdk/credentials.d.ts +0 -10
package/README.md
CHANGED
|
@@ -9,16 +9,6 @@ An [OpenCode](https://opencode.ai/) authentication plugin that enables seamless
|
|
|
9
9
|
- **Quota Tracking**: Injects the `agy_quota` tool into OpenCode to check usage limits directly.
|
|
10
10
|
- **Traffic Simulation**: Maintains background heartbeat with `agy` servers.
|
|
11
11
|
|
|
12
|
-
## Prerequisites
|
|
13
|
-
|
|
14
|
-
The plugin dynamically resolves Google OAuth credentials at runtime using one of the following methods:
|
|
15
|
-
|
|
16
|
-
1. **Installed `agy` / `antigravity` CLI binary (recommended)**:
|
|
17
|
-
- Ensure `agy` or `antigravity` is installed and available in your `PATH`.
|
|
18
|
-
- Alternatively, specify the binary path using the `AGY_BIN_PATH` environment variable.
|
|
19
|
-
2. **Environment variables (headless/CI or standalone environments)**:
|
|
20
|
-
- Set `AGY_CLIENT_ID` (or `GOOGLE_AGY_CLIENT_ID`) and `AGY_CLIENT_SECRET` (or `GOOGLE_AGY_CLIENT_SECRET`).
|
|
21
|
-
|
|
22
12
|
## Installation
|
|
23
13
|
|
|
24
14
|
Install the plugin from npm (or directly using local file configurations if developing):
|
|
@@ -52,9 +42,6 @@ You can switch your active OpenCode provider to `agy` or let the plugin inject a
|
|
|
52
42
|
|
|
53
43
|
If you are running OpenCode in environments with specific requirements for Antigravity, you can use the following environment variables:
|
|
54
44
|
|
|
55
|
-
- `AGY_BIN_PATH`: Explicit path to the `agy` / `antigravity` CLI executable.
|
|
56
|
-
- `AGY_CLIENT_ID` / `GOOGLE_AGY_CLIENT_ID`: Override or explicitly provide the Google OAuth Client ID.
|
|
57
|
-
- `AGY_CLIENT_SECRET` / `GOOGLE_AGY_CLIENT_SECRET`: Override or explicitly provide the Google OAuth Client Secret.
|
|
58
45
|
- `OPENCODE_AGY_PROJECT_ID`: Specify your Google Cloud Project ID manually.
|
|
59
46
|
- `OPENCODE_AGY_AUTH_PROXY`: Define a proxy if accessing authentication endpoints behind a corporate firewall.
|
|
60
47
|
- `OPENCODE_AGY_ENDPOINT`: Override the default internal `daily-cloudcode-pa.googleapis.com` API endpoint.
|
package/dist/index.js
CHANGED
|
@@ -102,106 +102,10 @@ function updateStaticModelsWithPricing(staticModels) {
|
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
// src/sdk/credentials.ts
|
|
106
|
-
import { execSync } from "child_process";
|
|
107
|
-
import { existsSync as existsSync2, readFileSync as readFileSync2, realpathSync } from "fs";
|
|
108
|
-
import { homedir } from "os";
|
|
109
|
-
import { join as join2 } from "path";
|
|
110
|
-
var cachedCredentials = null;
|
|
111
|
-
function findAgyBinary() {
|
|
112
|
-
if (process.env.AGY_BIN_PATH && existsSync2(process.env.AGY_BIN_PATH)) {
|
|
113
|
-
try {
|
|
114
|
-
return realpathSync(process.env.AGY_BIN_PATH);
|
|
115
|
-
} catch {
|
|
116
|
-
return process.env.AGY_BIN_PATH;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
try {
|
|
120
|
-
const which = execSync("which agy 2>/dev/null || which antigravity 2>/dev/null", {
|
|
121
|
-
encoding: "utf8",
|
|
122
|
-
stdio: ["pipe", "pipe", "ignore"]
|
|
123
|
-
}).trim();
|
|
124
|
-
if (which && existsSync2(which)) {
|
|
125
|
-
return realpathSync(which);
|
|
126
|
-
}
|
|
127
|
-
} catch {
|
|
128
|
-
}
|
|
129
|
-
const home = homedir();
|
|
130
|
-
const candidatePaths = [
|
|
131
|
-
join2(home, ".local/share/mise/installs/antigravity-cli/latest/agy"),
|
|
132
|
-
join2(home, ".local/share/mise/installs/antigravity-cli/latest/antigravity"),
|
|
133
|
-
join2(home, ".local/bin/agy"),
|
|
134
|
-
join2(home, ".local/bin/antigravity"),
|
|
135
|
-
join2(home, "bin/agy"),
|
|
136
|
-
join2(home, "bin/antigravity"),
|
|
137
|
-
"/usr/local/bin/agy",
|
|
138
|
-
"/usr/local/bin/antigravity",
|
|
139
|
-
"/usr/bin/agy",
|
|
140
|
-
"/usr/bin/antigravity"
|
|
141
|
-
];
|
|
142
|
-
for (const candidate of candidatePaths) {
|
|
143
|
-
if (existsSync2(candidate)) {
|
|
144
|
-
try {
|
|
145
|
-
return realpathSync(candidate);
|
|
146
|
-
} catch {
|
|
147
|
-
return candidate;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
function extractAgyCredentialsFromBinary(binaryPath) {
|
|
154
|
-
try {
|
|
155
|
-
const buffer = readFileSync2(binaryPath);
|
|
156
|
-
const content = buffer.toString("latin1");
|
|
157
|
-
const clientIds = [...new Set(content.match(/[0-9]+-[a-z0-9_]+\.apps\.googleusercontent\.com/g) || [])];
|
|
158
|
-
const clientSecrets = [...new Set(content.match(/GOCSPX-[A-Za-z0-9_-]{28}/g) || [])];
|
|
159
|
-
if (clientIds.length === 0 || clientSecrets.length === 0) {
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
const preferredClientId = clientIds.find((id) => id.startsWith("1071")) || clientIds[clientIds.length - 1];
|
|
163
|
-
const preferredClientSecret = clientSecrets[0];
|
|
164
|
-
if (!preferredClientId || !preferredClientSecret) {
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
return {
|
|
168
|
-
clientId: preferredClientId,
|
|
169
|
-
clientSecret: preferredClientSecret
|
|
170
|
-
};
|
|
171
|
-
} catch {
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
function getAgyCredentials() {
|
|
176
|
-
const envClientId = process.env.AGY_CLIENT_ID || process.env.GOOGLE_AGY_CLIENT_ID;
|
|
177
|
-
const envClientSecret = process.env.AGY_CLIENT_SECRET || process.env.GOOGLE_AGY_CLIENT_SECRET;
|
|
178
|
-
if (envClientId && envClientSecret) {
|
|
179
|
-
return { clientId: envClientId, clientSecret: envClientSecret };
|
|
180
|
-
}
|
|
181
|
-
if (cachedCredentials) {
|
|
182
|
-
return cachedCredentials;
|
|
183
|
-
}
|
|
184
|
-
const binaryPath = findAgyBinary();
|
|
185
|
-
if (binaryPath) {
|
|
186
|
-
const extracted = extractAgyCredentialsFromBinary(binaryPath);
|
|
187
|
-
if (extracted) {
|
|
188
|
-
cachedCredentials = extracted;
|
|
189
|
-
return extracted;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
throw new Error(
|
|
193
|
-
'Antigravity OAuth credentials not found. Ensure the "agy" CLI is installed and in PATH, or set the AGY_CLIENT_ID and AGY_CLIENT_SECRET environment variables.'
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
function getAgyClientId() {
|
|
197
|
-
return getAgyCredentials().clientId;
|
|
198
|
-
}
|
|
199
|
-
function getAgyClientSecret() {
|
|
200
|
-
return getAgyCredentials().clientSecret;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
105
|
// src/constants.ts
|
|
204
106
|
var AGY_PROVIDER_ID = "google-agy";
|
|
107
|
+
var AGY_CLIENT_ID = "1071006060591-tmhssin2h21lcre235vtolojh4g403ep.apps.googleusercontent.com";
|
|
108
|
+
var AGY_CLIENT_SECRET = "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";
|
|
205
109
|
var AGY_SCOPES = [
|
|
206
110
|
"openid",
|
|
207
111
|
"https://www.googleapis.com/auth/cloud-platform",
|
|
@@ -290,7 +194,7 @@ async function authorizeAgy() {
|
|
|
290
194
|
const pkce = await generatePKCE();
|
|
291
195
|
const state = randomBytes(32).toString("hex");
|
|
292
196
|
const url2 = new URL("https://accounts.google.com/o/oauth2/v2/auth");
|
|
293
|
-
url2.searchParams.set("client_id",
|
|
197
|
+
url2.searchParams.set("client_id", AGY_CLIENT_ID);
|
|
294
198
|
url2.searchParams.set("response_type", "code");
|
|
295
199
|
url2.searchParams.set("redirect_uri", AGY_REDIRECT_URI);
|
|
296
200
|
url2.searchParams.set("scope", AGY_SCOPES.join(" "));
|
|
@@ -323,8 +227,8 @@ async function exchangeAgyWithVerifierInternal(code, verifier) {
|
|
|
323
227
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
324
228
|
},
|
|
325
229
|
body: new URLSearchParams({
|
|
326
|
-
client_id:
|
|
327
|
-
client_secret:
|
|
230
|
+
client_id: AGY_CLIENT_ID,
|
|
231
|
+
client_secret: AGY_CLIENT_SECRET,
|
|
328
232
|
code,
|
|
329
233
|
grant_type: "authorization_code",
|
|
330
234
|
redirect_uri: AGY_REDIRECT_URI,
|
|
@@ -816,29 +720,29 @@ function clampDelay(delayMs) {
|
|
|
816
720
|
}
|
|
817
721
|
|
|
818
722
|
// src/sdk/retry/cooldown-store.ts
|
|
819
|
-
import { existsSync as
|
|
820
|
-
import { join as
|
|
821
|
-
import { homedir
|
|
723
|
+
import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, writeFileSync as writeFileSync2, renameSync, unlinkSync } from "fs";
|
|
724
|
+
import { join as join2, dirname } from "path";
|
|
725
|
+
import { homedir, tmpdir as tmpdir2 } from "os";
|
|
822
726
|
var WRITE_THROTTLE_MS = 5e3;
|
|
823
727
|
function getConfigDir() {
|
|
824
728
|
const platform2 = process.platform;
|
|
825
729
|
if (platform2 === "win32") {
|
|
826
|
-
return
|
|
730
|
+
return join2(process.env.APPDATA || join2(homedir(), "AppData", "Roaming"), "opencode");
|
|
827
731
|
}
|
|
828
|
-
const xdgConfig = process.env.XDG_CONFIG_HOME ||
|
|
829
|
-
return
|
|
732
|
+
const xdgConfig = process.env.XDG_CONFIG_HOME || join2(homedir(), ".config");
|
|
733
|
+
return join2(xdgConfig, "opencode");
|
|
830
734
|
}
|
|
831
735
|
function getCooldownFilePath() {
|
|
832
|
-
return
|
|
736
|
+
return join2(getConfigDir(), "antigravity-retry-cooldowns.json");
|
|
833
737
|
}
|
|
834
738
|
function loadCooldowns() {
|
|
835
739
|
const result = /* @__PURE__ */ new Map();
|
|
836
740
|
try {
|
|
837
741
|
const filePath = getCooldownFilePath();
|
|
838
|
-
if (!
|
|
742
|
+
if (!existsSync2(filePath)) {
|
|
839
743
|
return result;
|
|
840
744
|
}
|
|
841
|
-
const content =
|
|
745
|
+
const content = readFileSync2(filePath, "utf-8");
|
|
842
746
|
const data = JSON.parse(content);
|
|
843
747
|
if (data.version !== "1.0") {
|
|
844
748
|
return result;
|
|
@@ -857,7 +761,7 @@ function saveCooldowns(entries) {
|
|
|
857
761
|
try {
|
|
858
762
|
const filePath = getCooldownFilePath();
|
|
859
763
|
const dir = dirname(filePath);
|
|
860
|
-
if (!
|
|
764
|
+
if (!existsSync2(dir)) {
|
|
861
765
|
mkdirSync(dir, { recursive: true });
|
|
862
766
|
}
|
|
863
767
|
const now = Date.now();
|
|
@@ -872,12 +776,12 @@ function saveCooldowns(entries) {
|
|
|
872
776
|
entries: serializable,
|
|
873
777
|
updatedAt: now
|
|
874
778
|
};
|
|
875
|
-
const tmpPath =
|
|
779
|
+
const tmpPath = join2(tmpdir2(), `antigravity-cooldowns-${Date.now()}-${Math.random().toString(36).slice(2)}.tmp`);
|
|
876
780
|
writeFileSync2(tmpPath, JSON.stringify(data), "utf-8");
|
|
877
781
|
try {
|
|
878
782
|
renameSync(tmpPath, filePath);
|
|
879
783
|
} catch {
|
|
880
|
-
writeFileSync2(filePath,
|
|
784
|
+
writeFileSync2(filePath, readFileSync2(tmpPath));
|
|
881
785
|
try {
|
|
882
786
|
unlinkSync(tmpPath);
|
|
883
787
|
} catch {
|
|
@@ -1743,27 +1647,27 @@ function openBrowserUrl(url2) {
|
|
|
1743
1647
|
import { createHash } from "crypto";
|
|
1744
1648
|
|
|
1745
1649
|
// src/sdk/cache/signature-cache.ts
|
|
1746
|
-
import { existsSync as
|
|
1747
|
-
import { join as
|
|
1748
|
-
import { homedir as
|
|
1650
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync3, renameSync as renameSync2, unlinkSync as unlinkSync2, appendFileSync } from "fs";
|
|
1651
|
+
import { join as join3, dirname as dirname2 } from "path";
|
|
1652
|
+
import { homedir as homedir2, tmpdir as tmpdir3 } from "os";
|
|
1749
1653
|
function getConfigDir2() {
|
|
1750
1654
|
const platform2 = process.platform;
|
|
1751
1655
|
if (platform2 === "win32") {
|
|
1752
|
-
return
|
|
1656
|
+
return join3(process.env.APPDATA || join3(homedir2(), "AppData", "Roaming"), "opencode");
|
|
1753
1657
|
}
|
|
1754
|
-
const xdgConfig = process.env.XDG_CONFIG_HOME ||
|
|
1755
|
-
return
|
|
1658
|
+
const xdgConfig = process.env.XDG_CONFIG_HOME || join3(homedir2(), ".config");
|
|
1659
|
+
return join3(xdgConfig, "opencode");
|
|
1756
1660
|
}
|
|
1757
1661
|
function getCacheFilePath() {
|
|
1758
|
-
return
|
|
1662
|
+
return join3(getConfigDir2(), "antigravity-signature-cache.json");
|
|
1759
1663
|
}
|
|
1760
1664
|
function ensureGitignoreSync(configDir) {
|
|
1761
|
-
const gitignorePath =
|
|
1665
|
+
const gitignorePath = join3(configDir, ".gitignore");
|
|
1762
1666
|
const entries = [".gitignore", "antigravity-signature-cache.json"];
|
|
1763
1667
|
try {
|
|
1764
1668
|
let content = "";
|
|
1765
|
-
if (
|
|
1766
|
-
content =
|
|
1669
|
+
if (existsSync3(gitignorePath)) {
|
|
1670
|
+
content = readFileSync3(gitignorePath, "utf-8");
|
|
1767
1671
|
}
|
|
1768
1672
|
const existingLines = content.split("\n").map((line) => line.trim());
|
|
1769
1673
|
const missing = entries.filter((e) => !existingLines.includes(e));
|
|
@@ -1945,10 +1849,10 @@ var SignatureCache = class {
|
|
|
1945
1849
|
*/
|
|
1946
1850
|
loadFromDisk() {
|
|
1947
1851
|
try {
|
|
1948
|
-
if (!
|
|
1852
|
+
if (!existsSync3(this.cacheFilePath)) {
|
|
1949
1853
|
return;
|
|
1950
1854
|
}
|
|
1951
|
-
const content =
|
|
1855
|
+
const content = readFileSync3(this.cacheFilePath, "utf-8");
|
|
1952
1856
|
const data = JSON.parse(content);
|
|
1953
1857
|
if (data.version !== "1.0") {
|
|
1954
1858
|
return;
|
|
@@ -1976,15 +1880,15 @@ var SignatureCache = class {
|
|
|
1976
1880
|
saveToDisk() {
|
|
1977
1881
|
try {
|
|
1978
1882
|
const dir = dirname2(this.cacheFilePath);
|
|
1979
|
-
if (!
|
|
1883
|
+
if (!existsSync3(dir)) {
|
|
1980
1884
|
mkdirSync2(dir, { recursive: true });
|
|
1981
1885
|
}
|
|
1982
1886
|
ensureGitignoreSync(dir);
|
|
1983
1887
|
const now = Date.now();
|
|
1984
1888
|
let existingEntries = {};
|
|
1985
|
-
if (
|
|
1889
|
+
if (existsSync3(this.cacheFilePath)) {
|
|
1986
1890
|
try {
|
|
1987
|
-
const content =
|
|
1891
|
+
const content = readFileSync3(this.cacheFilePath, "utf-8");
|
|
1988
1892
|
const data = JSON.parse(content);
|
|
1989
1893
|
existingEntries = data.entries || {};
|
|
1990
1894
|
} catch {
|
|
@@ -2020,12 +1924,12 @@ var SignatureCache = class {
|
|
|
2020
1924
|
last_write: now
|
|
2021
1925
|
}
|
|
2022
1926
|
};
|
|
2023
|
-
const tmpPath =
|
|
1927
|
+
const tmpPath = join3(tmpdir3(), `antigravity-cache-${Date.now()}-${Math.random().toString(36).slice(2)}.tmp`);
|
|
2024
1928
|
writeFileSync3(tmpPath, JSON.stringify(cacheData, null, 2), "utf-8");
|
|
2025
1929
|
try {
|
|
2026
1930
|
renameSync2(tmpPath, this.cacheFilePath);
|
|
2027
1931
|
} catch {
|
|
2028
|
-
writeFileSync3(this.cacheFilePath,
|
|
1932
|
+
writeFileSync3(this.cacheFilePath, readFileSync3(tmpPath));
|
|
2029
1933
|
try {
|
|
2030
1934
|
unlinkSync2(tmpPath);
|
|
2031
1935
|
} catch {
|
|
@@ -2179,9 +2083,9 @@ function getLatestSignature(sessionId) {
|
|
|
2179
2083
|
}
|
|
2180
2084
|
|
|
2181
2085
|
// src/sdk/request/turn-state-tracker.ts
|
|
2182
|
-
import { existsSync as
|
|
2183
|
-
import { join as
|
|
2184
|
-
import { homedir as
|
|
2086
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync4, writeFileSync as writeFileSync4, renameSync as renameSync3, unlinkSync as unlinkSync3 } from "fs";
|
|
2087
|
+
import { join as join4, dirname as dirname3 } from "path";
|
|
2088
|
+
import { homedir as homedir3, tmpdir as tmpdir4 } from "os";
|
|
2185
2089
|
|
|
2186
2090
|
// src/sdk/request/thinking.ts
|
|
2187
2091
|
import { createHash as createHash2 } from "crypto";
|
|
@@ -2604,22 +2508,22 @@ var WRITE_THROTTLE_MS2 = 5e3;
|
|
|
2604
2508
|
function getConfigDir3() {
|
|
2605
2509
|
const platform2 = process.platform;
|
|
2606
2510
|
if (platform2 === "win32") {
|
|
2607
|
-
return
|
|
2511
|
+
return join4(process.env.APPDATA || join4(homedir3(), "AppData", "Roaming"), "opencode");
|
|
2608
2512
|
}
|
|
2609
|
-
const xdgConfig = process.env.XDG_CONFIG_HOME ||
|
|
2610
|
-
return
|
|
2513
|
+
const xdgConfig = process.env.XDG_CONFIG_HOME || join4(homedir3(), ".config");
|
|
2514
|
+
return join4(xdgConfig, "opencode");
|
|
2611
2515
|
}
|
|
2612
2516
|
function getTurnStateFilePath() {
|
|
2613
|
-
return
|
|
2517
|
+
return join4(getConfigDir3(), "antigravity-turn-states.json");
|
|
2614
2518
|
}
|
|
2615
2519
|
function loadTurnStatesFromDisk() {
|
|
2616
2520
|
const result = /* @__PURE__ */ new Map();
|
|
2617
2521
|
try {
|
|
2618
2522
|
const filePath = getTurnStateFilePath();
|
|
2619
|
-
if (!
|
|
2523
|
+
if (!existsSync4(filePath)) {
|
|
2620
2524
|
return result;
|
|
2621
2525
|
}
|
|
2622
|
-
const content =
|
|
2526
|
+
const content = readFileSync4(filePath, "utf-8");
|
|
2623
2527
|
const data = JSON.parse(content);
|
|
2624
2528
|
if (data.version !== "1.0") {
|
|
2625
2529
|
return result;
|
|
@@ -2639,7 +2543,7 @@ function saveTurnStatesToDisk(entries) {
|
|
|
2639
2543
|
try {
|
|
2640
2544
|
const filePath = getTurnStateFilePath();
|
|
2641
2545
|
const dir = dirname3(filePath);
|
|
2642
|
-
if (!
|
|
2546
|
+
if (!existsSync4(dir)) {
|
|
2643
2547
|
mkdirSync3(dir, { recursive: true });
|
|
2644
2548
|
}
|
|
2645
2549
|
const now = Date.now();
|
|
@@ -2655,12 +2559,12 @@ function saveTurnStatesToDisk(entries) {
|
|
|
2655
2559
|
entries: serializable,
|
|
2656
2560
|
updatedAt: now
|
|
2657
2561
|
};
|
|
2658
|
-
const tmpPath =
|
|
2562
|
+
const tmpPath = join4(tmpdir4(), `antigravity-turn-states-${Date.now()}-${Math.random().toString(36).slice(2)}.tmp`);
|
|
2659
2563
|
writeFileSync4(tmpPath, JSON.stringify(data), "utf-8");
|
|
2660
2564
|
try {
|
|
2661
2565
|
renameSync3(tmpPath, filePath);
|
|
2662
2566
|
} catch {
|
|
2663
|
-
writeFileSync4(filePath,
|
|
2567
|
+
writeFileSync4(filePath, readFileSync4(tmpPath));
|
|
2664
2568
|
try {
|
|
2665
2569
|
unlinkSync3(tmpPath);
|
|
2666
2570
|
} catch {
|
|
@@ -15317,8 +15221,8 @@ async function refreshAccessTokenInternal(auth, client, parts) {
|
|
|
15317
15221
|
}
|
|
15318
15222
|
async function fetchTokenRefresh(refreshToken) {
|
|
15319
15223
|
const tokenUrl = "https://oauth2.googleapis.com/token";
|
|
15320
|
-
const clientId =
|
|
15321
|
-
const clientSecret =
|
|
15224
|
+
const clientId = AGY_CLIENT_ID;
|
|
15225
|
+
const clientSecret = AGY_CLIENT_SECRET;
|
|
15322
15226
|
const init = {
|
|
15323
15227
|
method: "POST",
|
|
15324
15228
|
headers: {
|
|
@@ -19038,20 +18942,20 @@ function transformStreamingPayloadStream(stream, sessionId, chatLogger) {
|
|
|
19038
18942
|
}
|
|
19039
18943
|
|
|
19040
18944
|
// src/sdk/chat-logger.ts
|
|
19041
|
-
import { createWriteStream, existsSync as
|
|
19042
|
-
import { join as
|
|
18945
|
+
import { createWriteStream, existsSync as existsSync5, mkdirSync as mkdirSync4 } from "fs";
|
|
18946
|
+
import { join as join5 } from "path";
|
|
19043
18947
|
import { cwd } from "process";
|
|
19044
18948
|
function createChatLogger() {
|
|
19045
18949
|
if (process.env.AGY_LOG !== "1") {
|
|
19046
18950
|
return null;
|
|
19047
18951
|
}
|
|
19048
18952
|
try {
|
|
19049
|
-
const logDir =
|
|
19050
|
-
if (!
|
|
18953
|
+
const logDir = join5(cwd(), "agy_chat_log");
|
|
18954
|
+
if (!existsSync5(logDir)) {
|
|
19051
18955
|
mkdirSync4(logDir, { recursive: true });
|
|
19052
18956
|
}
|
|
19053
18957
|
const timestamp = Date.now();
|
|
19054
|
-
const logFile =
|
|
18958
|
+
const logFile = join5(logDir, `${timestamp}.log`);
|
|
19055
18959
|
const stream = createWriteStream(logFile, { flags: "w", encoding: "utf8" });
|
|
19056
18960
|
return new ChatLoggerImpl(stream);
|
|
19057
18961
|
} catch (error45) {
|