@anthonyhaussman/opencode-agy-auth 1.3.5-alpha.1 → 1.3.5

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/index.js CHANGED
@@ -2098,35 +2098,6 @@ function getLatestSignature(sessionId) {
2098
2098
  }
2099
2099
  return void 0;
2100
2100
  }
2101
- function getSignatureForText(sessionId, text) {
2102
- if (!sessionId || !text) return void 0;
2103
- const textHash = hashText(text);
2104
- const sessionMemCache = signatureCache.get(sessionId);
2105
- if (sessionMemCache) {
2106
- const entry = sessionMemCache.get(textHash);
2107
- if (entry) {
2108
- if (Date.now() - entry.timestamp <= SIGNATURE_CACHE_TTL_MS) {
2109
- return entry.signature;
2110
- }
2111
- sessionMemCache.delete(textHash);
2112
- }
2113
- }
2114
- if (diskCache) {
2115
- const diskKey = makeDiskKey(sessionId, textHash);
2116
- const diskValue = diskCache.retrieve(diskKey);
2117
- if (diskValue) {
2118
- if (!sessionMemCache) {
2119
- const newMemCache = /* @__PURE__ */ new Map();
2120
- signatureCache.set(sessionId, newMemCache);
2121
- newMemCache.set(textHash, { signature: diskValue, timestamp: Date.now() });
2122
- } else {
2123
- sessionMemCache.set(textHash, { signature: diskValue, timestamp: Date.now() });
2124
- }
2125
- return diskValue;
2126
- }
2127
- }
2128
- return void 0;
2129
- }
2130
2101
 
2131
2102
  // src/sdk/request/turn-state-tracker.ts
2132
2103
  import { existsSync as existsSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync4, writeFileSync as writeFileSync4, renameSync as renameSync3, unlinkSync as unlinkSync3 } from "fs";
@@ -2165,7 +2136,7 @@ function hashString(str) {
2165
2136
  }
2166
2137
  function isThinkingPart(part) {
2167
2138
  if (!part || typeof part !== "object") return false;
2168
- return part.thought === true || part.type === "thinking" || part.type === "redacted_thinking" || part.type === "reasoning";
2139
+ return part.thought === true || part.type === "thinking" || part.type === "redacted_thinking";
2169
2140
  }
2170
2141
  function isFunctionResponsePart(part) {
2171
2142
  return part && typeof part === "object" && "functionResponse" in part;
@@ -2185,7 +2156,7 @@ function messageHasThinking(msg) {
2185
2156
  }
2186
2157
  if (Array.isArray(msg.content)) {
2187
2158
  return msg.content.some(
2188
- (block) => block?.type === "thinking" || block?.type === "redacted_thinking" || block?.type === "reasoning"
2159
+ (block) => block?.type === "thinking" || block?.type === "redacted_thinking"
2189
2160
  );
2190
2161
  }
2191
2162
  return false;
@@ -2292,7 +2263,7 @@ function deduplicateThinkingText(response, sentBuffer, displayedThinkingHashes)
2292
2263
  if (!Array.isArray(content.parts)) return candidate;
2293
2264
  const newParts = content.parts.map((part) => {
2294
2265
  const p = part;
2295
- if (p.thought === true || p.type === "thinking" || p.type === "reasoning") {
2266
+ if (p.thought === true || p.type === "thinking") {
2296
2267
  const fullText = p.text || p.thinking || "";
2297
2268
  if (displayedThinkingHashes) {
2298
2269
  const hash2 = hashString(fullText);
@@ -2328,7 +2299,7 @@ function deduplicateThinkingText(response, sentBuffer, displayedThinkingHashes)
2328
2299
  let thinkingIndex = 0;
2329
2300
  const newContent = resp.content.map((block) => {
2330
2301
  const b = block;
2331
- if (b?.type === "thinking" || b?.type === "reasoning") {
2302
+ if (b?.type === "thinking") {
2332
2303
  const fullText = b.thinking || b.text || "";
2333
2304
  if (displayedThinkingHashes) {
2334
2305
  const hash2 = hashString(fullText);
@@ -2374,18 +2345,17 @@ function cacheThinkingSignaturesFromResponse(response, signatureSessionKey, sign
2374
2345
  if (!Array.isArray(content.parts)) return;
2375
2346
  content.parts.forEach((part) => {
2376
2347
  const p = part;
2377
- if (p.thought === true || p.type === "thinking" || p.type === "reasoning") {
2348
+ if (p.thought === true || p.type === "thinking") {
2378
2349
  const text = p.text || p.thinking || "";
2379
2350
  if (text) {
2380
2351
  const current = thoughtBuffer.get(index) ?? "";
2381
2352
  thoughtBuffer.set(index, current + text);
2382
2353
  }
2383
2354
  }
2384
- const partSignature = p.thoughtSignature || p.state?.thoughtSignature || p.signature;
2385
- if (partSignature) {
2355
+ if (p.thoughtSignature) {
2386
2356
  const fullText = thoughtBuffer.get(index) ?? "";
2387
2357
  if (fullText) {
2388
- const signature = partSignature;
2358
+ const signature = p.thoughtSignature;
2389
2359
  onCacheSignature?.(signatureSessionKey, fullText, signature);
2390
2360
  signatureStore.set(signatureSessionKey, { text: fullText, signature });
2391
2361
  }
@@ -2397,18 +2367,17 @@ function cacheThinkingSignaturesFromResponse(response, signatureSessionKey, sign
2397
2367
  const CLAUDE_BUFFER_KEY = 0;
2398
2368
  resp.content.forEach((block) => {
2399
2369
  const b = block;
2400
- if (b?.type === "thinking" || b?.type === "reasoning") {
2370
+ if (b?.type === "thinking") {
2401
2371
  const text = b.thinking || b.text || "";
2402
2372
  if (text) {
2403
2373
  const current = thoughtBuffer.get(CLAUDE_BUFFER_KEY) ?? "";
2404
2374
  thoughtBuffer.set(CLAUDE_BUFFER_KEY, current + text);
2405
2375
  }
2406
2376
  }
2407
- const blockSignature = b?.signature || b?.thoughtSignature || b?.state?.thoughtSignature;
2408
- if (blockSignature) {
2377
+ if (b?.signature) {
2409
2378
  const fullText = thoughtBuffer.get(CLAUDE_BUFFER_KEY) ?? "";
2410
2379
  if (fullText) {
2411
- const signature = blockSignature;
2380
+ const signature = b.signature;
2412
2381
  onCacheSignature?.(signatureSessionKey, fullText, signature);
2413
2382
  signatureStore.set(signatureSessionKey, { text: fullText, signature });
2414
2383
  }
@@ -2484,7 +2453,7 @@ function createStreamingTransformer(signatureStore, callbacks, options = {}) {
2484
2453
  hasSeenUsageMetadata = true;
2485
2454
  }
2486
2455
  if (!streamHasThinking) {
2487
- streamHasThinking = event.includes('"thought":true') || event.includes('"type":"thinking"') || event.includes('"type":"reasoning"');
2456
+ streamHasThinking = event.includes('"thought":true') || event.includes('"type":"thinking"');
2488
2457
  }
2489
2458
  if (!streamHasToolCalls) {
2490
2459
  streamHasToolCalls = event.includes('"functionCall"');
@@ -2508,7 +2477,7 @@ function createStreamingTransformer(signatureStore, callbacks, options = {}) {
2508
2477
  hasSeenUsageMetadata = true;
2509
2478
  }
2510
2479
  if (!streamHasThinking) {
2511
- streamHasThinking = buffer.includes('"thought":true') || buffer.includes('"type":"thinking"') || buffer.includes('"type":"reasoning"');
2480
+ streamHasThinking = buffer.includes('"thought":true') || buffer.includes('"type":"thinking"');
2512
2481
  }
2513
2482
  if (!streamHasToolCalls) {
2514
2483
  streamHasToolCalls = buffer.includes('"functionCall"');
@@ -18934,7 +18903,7 @@ function getModelEnum(modelName) {
18934
18903
  function isClaudeModel(model) {
18935
18904
  return model.toLowerCase().includes("claude");
18936
18905
  }
18937
- function sanitizeClaudeThinkingParts(contents, model, sessionId) {
18906
+ function sanitizeClaudeThinkingParts(contents, model) {
18938
18907
  if (!isClaudeModel(model) || !Array.isArray(contents)) {
18939
18908
  return;
18940
18909
  }
@@ -18944,49 +18913,12 @@ function sanitizeClaudeThinkingParts(contents, model, sessionId) {
18944
18913
  if (!Array.isArray(turn.parts)) continue;
18945
18914
  const filteredParts = turn.parts.filter((part) => {
18946
18915
  if (!part || typeof part !== "object") return true;
18947
- const isThinking = part.thought === true || part.type === "thinking" || part.type === "reasoning" || typeof part.thinking === "string";
18916
+ const isThinking = part.thought === true || part.type === "thinking" || typeof part.thinking === "string";
18948
18917
  if (!isThinking) {
18949
18918
  return true;
18950
18919
  }
18951
- let sig = typeof part.signature === "string" ? part.signature : typeof part.thoughtSignature === "string" ? part.thoughtSignature : typeof part.state?.thoughtSignature === "string" ? part.state.thoughtSignature : void 0;
18952
- let recovered = false;
18953
- if ((!sig || sig === "skip_thought_signature_validator") && sessionId) {
18954
- const text = typeof part.text === "string" ? part.text : typeof part.thinking === "string" ? part.thinking : void 0;
18955
- if (text) {
18956
- const recoveredSig = getSignatureForText(sessionId, text);
18957
- if (recoveredSig) {
18958
- sig = recoveredSig;
18959
- recovered = true;
18960
- }
18961
- }
18962
- if (!sig) {
18963
- const latest = getLatestSignature(sessionId);
18964
- if (latest) {
18965
- sig = latest;
18966
- recovered = true;
18967
- }
18968
- }
18969
- }
18920
+ const sig = typeof part.signature === "string" ? part.signature : typeof part.thoughtSignature === "string" ? part.thoughtSignature : void 0;
18970
18921
  const isValidSig = typeof sig === "string" && sig.length > 0 && sig !== "skip_thought_signature_validator";
18971
- if (isValidSig) {
18972
- if (part.type === "reasoning") {
18973
- part.thoughtSignature = sig;
18974
- part.signature = sig;
18975
- if (part.state) {
18976
- part.state.thoughtSignature = sig;
18977
- }
18978
- } else if (recovered) {
18979
- if (typeof part.thoughtSignature === "string" || part.thought) {
18980
- part.thoughtSignature = sig;
18981
- }
18982
- if (part.type === "thinking" || typeof part.thinking === "string") {
18983
- part.signature = sig;
18984
- }
18985
- if (!part.thoughtSignature && !part.signature) {
18986
- part.signature = sig;
18987
- }
18988
- }
18989
- }
18990
18922
  return isValidSig;
18991
18923
  });
18992
18924
  if (filteredParts.length === 0) {
@@ -19057,7 +18989,7 @@ function transformRequestBody(body, projectId, effectiveModel, requestedModel, t
19057
18989
  contents2 = ensureTrailingUserTurn(contents2);
19058
18990
  const latestSig = getLatestSignature(sessionId2);
19059
18991
  applyLatestSignature(contents2, latestSig);
19060
- sanitizeClaudeThinkingParts(contents2, effectiveModel || requestedModel, sessionId2);
18992
+ sanitizeClaudeThinkingParts(contents2, effectiveModel || requestedModel);
19061
18993
  requestPayloadInside.contents = contents2;
19062
18994
  }
19063
18995
  return { body: JSON.stringify(wrappedBody2), userPromptId: userPromptId2, sessionId: sessionId2 };
@@ -19099,7 +19031,7 @@ function transformRequestBody(body, projectId, effectiveModel, requestedModel, t
19099
19031
  contents = ensureTrailingUserTurn(contents);
19100
19032
  const latestSig = getLatestSignature(sessionId);
19101
19033
  applyLatestSignature(contents, latestSig);
19102
- sanitizeClaudeThinkingParts(contents, effectiveModel || requestedModel, sessionId);
19034
+ sanitizeClaudeThinkingParts(contents, effectiveModel || requestedModel);
19103
19035
  requestPayload.contents = contents;
19104
19036
  }
19105
19037
  if ("model" in requestPayload) {
@@ -20537,26 +20469,6 @@ function createV2HttpRequestHook(state = {}) {
20537
20469
  }
20538
20470
  } catch {
20539
20471
  }
20540
- let bodyPayload = event.body;
20541
- if (bodyPayload === void 0 && event.request) {
20542
- if (typeof event.request.clone === "function") {
20543
- try {
20544
- bodyPayload = await event.request.clone().text();
20545
- } catch {
20546
- }
20547
- } else if (event.request.body !== void 0) {
20548
- bodyPayload = event.request.body;
20549
- }
20550
- }
20551
- if (bodyPayload) {
20552
- try {
20553
- const parsed2 = typeof bodyPayload === "string" ? JSON.parse(bodyPayload) : bodyPayload;
20554
- if (parsed2 && typeof parsed2 === "object" && typeof parsed2.sessionId === "string") {
20555
- state.lastSessionId = parsed2.sessionId;
20556
- }
20557
- } catch {
20558
- }
20559
- }
20560
20472
  if (authRecord && authRecord.access) {
20561
20473
  let projectContext;
20562
20474
  try {
@@ -20583,6 +20495,17 @@ function createV2HttpRequestHook(state = {}) {
20583
20495
  modifiedUrl = modifiedUrl.replace(`models/${originalBase}`, `models/${resolvedBase}`);
20584
20496
  }
20585
20497
  }
20498
+ let bodyPayload = event.body;
20499
+ if (bodyPayload === void 0 && event.request) {
20500
+ if (typeof event.request.clone === "function") {
20501
+ try {
20502
+ bodyPayload = await event.request.clone().text();
20503
+ } catch {
20504
+ }
20505
+ } else if (event.request.body !== void 0) {
20506
+ bodyPayload = event.request.body;
20507
+ }
20508
+ }
20586
20509
  let preExistingUserAgent;
20587
20510
  if (typeof event.headers?.get === "function") {
20588
20511
  preExistingUserAgent = event.headers.get("user-agent") || event.headers.get("User-Agent") || void 0;
@@ -20606,9 +20529,6 @@ function createV2HttpRequestHook(state = {}) {
20606
20529
  authRecord.access,
20607
20530
  projectContext.effectiveProjectId
20608
20531
  );
20609
- if (transformed.sessionId) {
20610
- state.lastSessionId = transformed.sessionId;
20611
- }
20612
20532
  const targetUrl = toUrlString(transformed.request);
20613
20533
  if (typeof event.url === "string") {
20614
20534
  event.url = targetUrl;
@@ -20725,7 +20645,7 @@ function createV2HttpResponseHook(state = {}) {
20725
20645
  !!isStreaming,
20726
20646
  null,
20727
20647
  parsedModel,
20728
- state.lastSessionId,
20648
+ void 0,
20729
20649
  void 0
20730
20650
  );
20731
20651
  event.response = transformed;
@@ -20767,26 +20687,6 @@ function registerV2SessionHooks(ctx) {
20767
20687
 
20768
20688
  // src/plugin/v2.ts
20769
20689
  async function setupOpenCodeV2(ctx) {
20770
- try {
20771
- initDiskSignatureCache({
20772
- enabled: true,
20773
- memory_ttl_seconds: 3600,
20774
- disk_ttl_seconds: 86400,
20775
- write_interval_seconds: 30
20776
- });
20777
- } catch (e) {
20778
- console.warn(`[Agy Auth] initDiskSignatureCache failed, running without signature disk cache: ${e instanceof Error ? e.message : e}`);
20779
- }
20780
- try {
20781
- initTurnStateTracker();
20782
- } catch (e) {
20783
- console.warn(`[Agy Auth] initTurnStateTracker failed, running without turn-state tracking: ${e instanceof Error ? e.message : e}`);
20784
- }
20785
- try {
20786
- initCooldownPersistence();
20787
- } catch (e) {
20788
- console.warn(`[Agy Auth] initCooldownPersistence failed, running without cooldown disk persistence: ${e instanceof Error ? e.message : e}`);
20789
- }
20790
20690
  const resolveVariants = (modelId) => {
20791
20691
  const mapping = TIER_MAPPING[modelId];
20792
20692
  if (!mapping) return void 0;