opencode-antigravity-auth-mf 1.3.0-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/LICENSE +21 -0
- package/README.md +630 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/src/antigravity/oauth.d.ts +31 -0
- package/dist/src/antigravity/oauth.d.ts.map +1 -0
- package/dist/src/antigravity/oauth.js +168 -0
- package/dist/src/antigravity/oauth.js.map +1 -0
- package/dist/src/constants.d.ts +99 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +135 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/hooks/auto-update-checker/cache.d.ts +3 -0
- package/dist/src/hooks/auto-update-checker/cache.d.ts.map +1 -0
- package/dist/src/hooks/auto-update-checker/cache.js +71 -0
- package/dist/src/hooks/auto-update-checker/cache.js.map +1 -0
- package/dist/src/hooks/auto-update-checker/checker.d.ts +16 -0
- package/dist/src/hooks/auto-update-checker/checker.d.ts.map +1 -0
- package/dist/src/hooks/auto-update-checker/checker.js +237 -0
- package/dist/src/hooks/auto-update-checker/checker.js.map +1 -0
- package/dist/src/hooks/auto-update-checker/constants.d.ts +9 -0
- package/dist/src/hooks/auto-update-checker/constants.d.ts.map +1 -0
- package/dist/src/hooks/auto-update-checker/constants.js +23 -0
- package/dist/src/hooks/auto-update-checker/constants.js.map +1 -0
- package/dist/src/hooks/auto-update-checker/index.d.ts +34 -0
- package/dist/src/hooks/auto-update-checker/index.d.ts.map +1 -0
- package/dist/src/hooks/auto-update-checker/index.js +125 -0
- package/dist/src/hooks/auto-update-checker/index.js.map +1 -0
- package/dist/src/hooks/auto-update-checker/types.d.ts +25 -0
- package/dist/src/hooks/auto-update-checker/types.d.ts.map +1 -0
- package/dist/src/hooks/auto-update-checker/types.js +1 -0
- package/dist/src/hooks/auto-update-checker/types.js.map +1 -0
- package/dist/src/plugin/accounts.d.ts +86 -0
- package/dist/src/plugin/accounts.d.ts.map +1 -0
- package/dist/src/plugin/accounts.js +609 -0
- package/dist/src/plugin/accounts.js.map +1 -0
- package/dist/src/plugin/auth.d.ts +21 -0
- package/dist/src/plugin/auth.d.ts.map +1 -0
- package/dist/src/plugin/auth.js +46 -0
- package/dist/src/plugin/auth.js.map +1 -0
- package/dist/src/plugin/cache/index.d.ts +5 -0
- package/dist/src/plugin/cache/index.d.ts.map +1 -0
- package/dist/src/plugin/cache/index.js +5 -0
- package/dist/src/plugin/cache/index.js.map +1 -0
- package/dist/src/plugin/cache/signature-cache.d.ts +111 -0
- package/dist/src/plugin/cache/signature-cache.d.ts.map +1 -0
- package/dist/src/plugin/cache/signature-cache.js +375 -0
- package/dist/src/plugin/cache/signature-cache.js.map +1 -0
- package/dist/src/plugin/cache.d.ts +44 -0
- package/dist/src/plugin/cache.d.ts.map +1 -0
- package/dist/src/plugin/cache.js +200 -0
- package/dist/src/plugin/cache.js.map +1 -0
- package/dist/src/plugin/cli.d.ts +19 -0
- package/dist/src/plugin/cli.d.ts.map +1 -0
- package/dist/src/plugin/cli.js +59 -0
- package/dist/src/plugin/cli.js.map +1 -0
- package/dist/src/plugin/config/index.d.ts +16 -0
- package/dist/src/plugin/config/index.d.ts.map +1 -0
- package/dist/src/plugin/config/index.js +16 -0
- package/dist/src/plugin/config/index.js.map +1 -0
- package/dist/src/plugin/config/loader.d.ts +37 -0
- package/dist/src/plugin/config/loader.d.ts.map +1 -0
- package/dist/src/plugin/config/loader.js +206 -0
- package/dist/src/plugin/config/loader.js.map +1 -0
- package/dist/src/plugin/config/schema.d.ts +411 -0
- package/dist/src/plugin/config/schema.d.ts.map +1 -0
- package/dist/src/plugin/config/schema.js +339 -0
- package/dist/src/plugin/config/schema.js.map +1 -0
- package/dist/src/plugin/core/streaming/index.d.ts +3 -0
- package/dist/src/plugin/core/streaming/index.d.ts.map +1 -0
- package/dist/src/plugin/core/streaming/index.js +3 -0
- package/dist/src/plugin/core/streaming/index.js.map +1 -0
- package/dist/src/plugin/core/streaming/transformer.d.ts +10 -0
- package/dist/src/plugin/core/streaming/transformer.d.ts.map +1 -0
- package/dist/src/plugin/core/streaming/transformer.js +255 -0
- package/dist/src/plugin/core/streaming/transformer.js.map +1 -0
- package/dist/src/plugin/core/streaming/types.d.ts +35 -0
- package/dist/src/plugin/core/streaming/types.d.ts.map +1 -0
- package/dist/src/plugin/core/streaming/types.js +1 -0
- package/dist/src/plugin/core/streaming/types.js.map +1 -0
- package/dist/src/plugin/debug.d.ts +68 -0
- package/dist/src/plugin/debug.d.ts.map +1 -0
- package/dist/src/plugin/debug.js +325 -0
- package/dist/src/plugin/debug.js.map +1 -0
- package/dist/src/plugin/errors.d.ts +28 -0
- package/dist/src/plugin/errors.d.ts.map +1 -0
- package/dist/src/plugin/errors.js +42 -0
- package/dist/src/plugin/errors.js.map +1 -0
- package/dist/src/plugin/image-saver.d.ts +25 -0
- package/dist/src/plugin/image-saver.d.ts.map +1 -0
- package/dist/src/plugin/image-saver.js +86 -0
- package/dist/src/plugin/image-saver.js.map +1 -0
- package/dist/src/plugin/logger.d.ts +54 -0
- package/dist/src/plugin/logger.d.ts.map +1 -0
- package/dist/src/plugin/logger.js +120 -0
- package/dist/src/plugin/logger.js.map +1 -0
- package/dist/src/plugin/project.d.ts +33 -0
- package/dist/src/plugin/project.d.ts.map +1 -0
- package/dist/src/plugin/project.js +234 -0
- package/dist/src/plugin/project.js.map +1 -0
- package/dist/src/plugin/recovery/constants.d.ts +22 -0
- package/dist/src/plugin/recovery/constants.d.ts.map +1 -0
- package/dist/src/plugin/recovery/constants.js +43 -0
- package/dist/src/plugin/recovery/constants.js.map +1 -0
- package/dist/src/plugin/recovery/index.d.ts +12 -0
- package/dist/src/plugin/recovery/index.d.ts.map +1 -0
- package/dist/src/plugin/recovery/index.js +12 -0
- package/dist/src/plugin/recovery/index.js.map +1 -0
- package/dist/src/plugin/recovery/storage.d.ts +24 -0
- package/dist/src/plugin/recovery/storage.d.ts.map +1 -0
- package/dist/src/plugin/recovery/storage.js +354 -0
- package/dist/src/plugin/recovery/storage.js.map +1 -0
- package/dist/src/plugin/recovery/types.d.ts +116 -0
- package/dist/src/plugin/recovery/types.d.ts.map +1 -0
- package/dist/src/plugin/recovery/types.js +6 -0
- package/dist/src/plugin/recovery/types.js.map +1 -0
- package/dist/src/plugin/recovery.d.ts +61 -0
- package/dist/src/plugin/recovery.d.ts.map +1 -0
- package/dist/src/plugin/recovery.js +376 -0
- package/dist/src/plugin/recovery.js.map +1 -0
- package/dist/src/plugin/refresh-queue.d.ts +101 -0
- package/dist/src/plugin/refresh-queue.d.ts.map +1 -0
- package/dist/src/plugin/refresh-queue.js +244 -0
- package/dist/src/plugin/refresh-queue.js.map +1 -0
- package/dist/src/plugin/request-helpers.d.ts +278 -0
- package/dist/src/plugin/request-helpers.d.ts.map +1 -0
- package/dist/src/plugin/request-helpers.js +2268 -0
- package/dist/src/plugin/request-helpers.js.map +1 -0
- package/dist/src/plugin/request.d.ts +91 -0
- package/dist/src/plugin/request.d.ts.map +1 -0
- package/dist/src/plugin/request.js +1302 -0
- package/dist/src/plugin/request.js.map +1 -0
- package/dist/src/plugin/rotation.d.ts +168 -0
- package/dist/src/plugin/rotation.d.ts.map +1 -0
- package/dist/src/plugin/rotation.js +302 -0
- package/dist/src/plugin/rotation.js.map +1 -0
- package/dist/src/plugin/server.d.ts +23 -0
- package/dist/src/plugin/server.d.ts.map +1 -0
- package/dist/src/plugin/server.js +324 -0
- package/dist/src/plugin/server.js.map +1 -0
- package/dist/src/plugin/storage.d.ts +92 -0
- package/dist/src/plugin/storage.d.ts.map +1 -0
- package/dist/src/plugin/storage.js +417 -0
- package/dist/src/plugin/storage.js.map +1 -0
- package/dist/src/plugin/stores/signature-store.d.ts +5 -0
- package/dist/src/plugin/stores/signature-store.d.ts.map +1 -0
- package/dist/src/plugin/stores/signature-store.js +25 -0
- package/dist/src/plugin/stores/signature-store.js.map +1 -0
- package/dist/src/plugin/thinking-recovery.d.ts +90 -0
- package/dist/src/plugin/thinking-recovery.d.ts.map +1 -0
- package/dist/src/plugin/thinking-recovery.js +316 -0
- package/dist/src/plugin/thinking-recovery.js.map +1 -0
- package/dist/src/plugin/token.d.ts +19 -0
- package/dist/src/plugin/token.d.ts.map +1 -0
- package/dist/src/plugin/token.js +128 -0
- package/dist/src/plugin/token.js.map +1 -0
- package/dist/src/plugin/transform/claude.d.ts +80 -0
- package/dist/src/plugin/transform/claude.d.ts.map +1 -0
- package/dist/src/plugin/transform/claude.js +265 -0
- package/dist/src/plugin/transform/claude.js.map +1 -0
- package/dist/src/plugin/transform/cross-model-sanitizer.d.ts +35 -0
- package/dist/src/plugin/transform/cross-model-sanitizer.d.ts.map +1 -0
- package/dist/src/plugin/transform/cross-model-sanitizer.js +225 -0
- package/dist/src/plugin/transform/cross-model-sanitizer.js.map +1 -0
- package/dist/src/plugin/transform/gemini.d.ts +112 -0
- package/dist/src/plugin/transform/gemini.d.ts.map +1 -0
- package/dist/src/plugin/transform/gemini.js +409 -0
- package/dist/src/plugin/transform/gemini.js.map +1 -0
- package/dist/src/plugin/transform/index.d.ts +15 -0
- package/dist/src/plugin/transform/index.d.ts.map +1 -0
- package/dist/src/plugin/transform/index.js +14 -0
- package/dist/src/plugin/transform/index.js.map +1 -0
- package/dist/src/plugin/transform/model-resolver.d.ts +101 -0
- package/dist/src/plugin/transform/model-resolver.d.ts.map +1 -0
- package/dist/src/plugin/transform/model-resolver.js +356 -0
- package/dist/src/plugin/transform/model-resolver.js.map +1 -0
- package/dist/src/plugin/transform/types.d.ts +106 -0
- package/dist/src/plugin/transform/types.d.ts.map +1 -0
- package/dist/src/plugin/transform/types.js +1 -0
- package/dist/src/plugin/transform/types.js.map +1 -0
- package/dist/src/plugin/types.d.ts +96 -0
- package/dist/src/plugin/types.d.ts.map +1 -0
- package/dist/src/plugin/types.js +1 -0
- package/dist/src/plugin/types.js.map +1 -0
- package/dist/src/plugin/usage-reporter.d.ts +23 -0
- package/dist/src/plugin/usage-reporter.d.ts.map +1 -0
- package/dist/src/plugin/usage-reporter.js +43 -0
- package/dist/src/plugin/usage-reporter.js.map +1 -0
- package/dist/src/plugin.d.ts +8 -0
- package/dist/src/plugin.d.ts.map +1 -0
- package/dist/src/plugin.js +1708 -0
- package/dist/src/plugin.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const ACCESS_TOKEN_EXPIRY_BUFFER_MS = 60 * 1000;
|
|
2
|
+
export function isOAuthAuth(auth) {
|
|
3
|
+
return auth.type === "oauth";
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Splits a packed refresh string into its constituent refresh token and project IDs.
|
|
7
|
+
*/
|
|
8
|
+
export function parseRefreshParts(refresh) {
|
|
9
|
+
const [refreshToken = "", projectId = "", managedProjectId = ""] = (refresh ?? "").split("|");
|
|
10
|
+
return {
|
|
11
|
+
refreshToken,
|
|
12
|
+
projectId: projectId || undefined,
|
|
13
|
+
managedProjectId: managedProjectId || undefined,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Serializes refresh token parts into the stored string format.
|
|
18
|
+
*/
|
|
19
|
+
export function formatRefreshParts(parts) {
|
|
20
|
+
const projectSegment = parts.projectId ?? "";
|
|
21
|
+
const base = `${parts.refreshToken}|${projectSegment}`;
|
|
22
|
+
return parts.managedProjectId ? `${base}|${parts.managedProjectId}` : base;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Determines whether an access token is expired or missing, with buffer for clock skew.
|
|
26
|
+
*/
|
|
27
|
+
export function accessTokenExpired(auth) {
|
|
28
|
+
if (!auth.access || typeof auth.expires !== "number") {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return auth.expires <= Date.now() + ACCESS_TOKEN_EXPIRY_BUFFER_MS;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Calculates absolute expiry timestamp based on a duration.
|
|
35
|
+
* @param requestTimeMs The local time when the request was initiated
|
|
36
|
+
* @param expiresInSeconds The duration returned by the server
|
|
37
|
+
*/
|
|
38
|
+
export function calculateTokenExpiry(requestTimeMs, expiresInSeconds) {
|
|
39
|
+
const seconds = typeof expiresInSeconds === "number" ? expiresInSeconds : 3600;
|
|
40
|
+
// Safety check for bad data - if it's not a positive number, treat as immediately expired
|
|
41
|
+
if (isNaN(seconds) || seconds <= 0) {
|
|
42
|
+
return requestTimeMs;
|
|
43
|
+
}
|
|
44
|
+
return requestTimeMs + seconds * 1000;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/plugin/auth.ts"],"names":[],"mappings":"AAEA,MAAM,6BAA6B,GAAG,EAAE,GAAG,IAAI,CAAC;AAEhD,MAAM,UAAU,WAAW,CAAC,IAAiB;IAC3C,OAAO,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC;AAC/B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,MAAM,CAAC,YAAY,GAAG,EAAE,EAAE,SAAS,GAAG,EAAE,EAAE,gBAAgB,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9F,OAAO;QACL,YAAY;QACZ,SAAS,EAAE,SAAS,IAAI,SAAS;QACjC,gBAAgB,EAAE,gBAAgB,IAAI,SAAS;KAChD,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAmB;IACpD,MAAM,cAAc,GAAG,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC;IAC7C,MAAM,IAAI,GAAG,GAAG,KAAK,CAAC,YAAY,IAAI,cAAc,EAAE,CAAC;IACvD,OAAO,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7E,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAsB;IACvD,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QACrD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,6BAA6B,CAAC;AACpE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,aAAqB,EAAE,gBAAyB;IACnF,MAAM,OAAO,GAAG,OAAO,gBAAgB,KAAK,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC;IAC/E,0FAA0F;IAC1F,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,OAAO,IAAI,CAAC,EAAE,CAAC;QACnC,OAAO,aAAa,CAAC;IACvB,CAAC;IACD,OAAO,aAAa,GAAG,OAAO,GAAG,IAAI,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugin/cache/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,cAAc,EACd,oBAAoB,GACrB,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugin/cache/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,cAAc,EACd,oBAAoB,GACrB,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signature cache for persisting thinking block signatures to disk.
|
|
3
|
+
*
|
|
4
|
+
* Features (based on LLM-API-Key-Proxy's ProviderCache):
|
|
5
|
+
* - Dual-TTL system: short memory TTL, longer disk TTL
|
|
6
|
+
* - Background disk persistence with batched writes
|
|
7
|
+
* - Atomic writes with temp file + move pattern
|
|
8
|
+
* - Automatic cleanup of expired entries
|
|
9
|
+
*
|
|
10
|
+
* Cache key format: `${sessionId}:${modelId}`
|
|
11
|
+
*/
|
|
12
|
+
import type { SignatureCacheConfig } from "../config";
|
|
13
|
+
interface CacheStats {
|
|
14
|
+
memoryHits: number;
|
|
15
|
+
diskHits: number;
|
|
16
|
+
misses: number;
|
|
17
|
+
writes: number;
|
|
18
|
+
memoryEntries: number;
|
|
19
|
+
dirty: boolean;
|
|
20
|
+
diskEnabled: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Full thinking content with signature (for recovery)
|
|
24
|
+
*/
|
|
25
|
+
export interface ThinkingCacheData {
|
|
26
|
+
text: string;
|
|
27
|
+
signature: string;
|
|
28
|
+
toolIds?: string[];
|
|
29
|
+
}
|
|
30
|
+
export declare class SignatureCache {
|
|
31
|
+
private cache;
|
|
32
|
+
private memoryTtlMs;
|
|
33
|
+
private diskTtlMs;
|
|
34
|
+
private writeIntervalMs;
|
|
35
|
+
private cacheFilePath;
|
|
36
|
+
private enabled;
|
|
37
|
+
private dirty;
|
|
38
|
+
private writeTimer;
|
|
39
|
+
private cleanupTimer;
|
|
40
|
+
private stats;
|
|
41
|
+
constructor(config: SignatureCacheConfig);
|
|
42
|
+
/**
|
|
43
|
+
* Generate a cache key from sessionId and modelId.
|
|
44
|
+
*/
|
|
45
|
+
static makeKey(sessionId: string, modelId: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Store a signature in the cache.
|
|
48
|
+
*/
|
|
49
|
+
store(key: string, signature: string): void;
|
|
50
|
+
/**
|
|
51
|
+
* Retrieve a signature from the cache.
|
|
52
|
+
* Returns null if not found or expired.
|
|
53
|
+
*/
|
|
54
|
+
retrieve(key: string): string | null;
|
|
55
|
+
/**
|
|
56
|
+
* Check if a key exists in the cache (without updating stats).
|
|
57
|
+
*/
|
|
58
|
+
has(key: string): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Store full thinking content with signature.
|
|
61
|
+
* This enables recovery even after thinking text is stripped by compaction.
|
|
62
|
+
*
|
|
63
|
+
* Port of LLM-API-Key-Proxy's _cache_thinking()
|
|
64
|
+
*/
|
|
65
|
+
storeThinking(key: string, thinkingText: string, signature: string, toolIds?: string[]): void;
|
|
66
|
+
/**
|
|
67
|
+
* Retrieve full thinking content by key.
|
|
68
|
+
* Returns null if not found or expired.
|
|
69
|
+
*/
|
|
70
|
+
retrieveThinking(key: string): ThinkingCacheData | null;
|
|
71
|
+
/**
|
|
72
|
+
* Check if full thinking content exists for a key.
|
|
73
|
+
*/
|
|
74
|
+
hasThinking(key: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Get cache statistics.
|
|
77
|
+
*/
|
|
78
|
+
getStats(): CacheStats;
|
|
79
|
+
/**
|
|
80
|
+
* Manually trigger a disk save.
|
|
81
|
+
*/
|
|
82
|
+
flush(): Promise<boolean>;
|
|
83
|
+
/**
|
|
84
|
+
* Graceful shutdown: stop timers and flush to disk.
|
|
85
|
+
*/
|
|
86
|
+
shutdown(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Load cache from disk file with TTL validation.
|
|
89
|
+
*/
|
|
90
|
+
private loadFromDisk;
|
|
91
|
+
/**
|
|
92
|
+
* Save cache to disk with atomic write pattern.
|
|
93
|
+
* Merges with existing disk entries that haven't expired.
|
|
94
|
+
*/
|
|
95
|
+
private saveToDisk;
|
|
96
|
+
/**
|
|
97
|
+
* Start background write and cleanup timers.
|
|
98
|
+
*/
|
|
99
|
+
private startBackgroundTasks;
|
|
100
|
+
/**
|
|
101
|
+
* Remove expired entries from memory.
|
|
102
|
+
*/
|
|
103
|
+
private cleanupExpired;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Create a signature cache with the given configuration.
|
|
107
|
+
* Returns null if caching is disabled.
|
|
108
|
+
*/
|
|
109
|
+
export declare function createSignatureCache(config: SignatureCacheConfig | undefined): SignatureCache | null;
|
|
110
|
+
export {};
|
|
111
|
+
//# sourceMappingURL=signature-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature-cache.d.ts","sourceRoot":"","sources":["../../../../src/plugin/cache/signature-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAgCtD,UAAU,UAAU;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAuBD,qBAAa,cAAc;IAEzB,OAAO,CAAC,KAAK,CAAsC;IAGnD,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,OAAO,CAAU;IAGzB,OAAO,CAAC,KAAK,CAAkB;IAC/B,OAAO,CAAC,UAAU,CAA+C;IACjE,OAAO,CAAC,YAAY,CAA+C;IAGnE,OAAO,CAAC,KAAK,CAKX;gBAEU,MAAM,EAAE,oBAAoB;IAiBxC;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM;IAI1D;;OAEG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAU3C;;;OAGG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAkBpC;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAczB;;;;;OAKG;IACH,aAAa,CACX,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,MAAM,EAAE,GACjB,IAAI;IAaP;;;OAGG;IACH,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI;IAoBvD;;OAEG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAUjC;;OAEG;IACH,QAAQ,IAAI,UAAU;IAStB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,OAAO,CAAC;IAK/B;;OAEG;IACH,QAAQ,IAAI,IAAI;IAmBhB;;OAEG;IACH,OAAO,CAAC,YAAY;IAqCpB;;;OAGG;IACH,OAAO,CAAC,UAAU;IAuFlB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAc5B;;OAEG;IACH,OAAO,CAAC,cAAc;CAcvB;AAMD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,oBAAoB,GAAG,SAAS,GAAG,cAAc,GAAG,IAAI,CAMpG"}
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signature cache for persisting thinking block signatures to disk.
|
|
3
|
+
*
|
|
4
|
+
* Features (based on LLM-API-Key-Proxy's ProviderCache):
|
|
5
|
+
* - Dual-TTL system: short memory TTL, longer disk TTL
|
|
6
|
+
* - Background disk persistence with batched writes
|
|
7
|
+
* - Atomic writes with temp file + move pattern
|
|
8
|
+
* - Automatic cleanup of expired entries
|
|
9
|
+
*
|
|
10
|
+
* Cache key format: `${sessionId}:${modelId}`
|
|
11
|
+
*/
|
|
12
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync, unlinkSync } from "node:fs";
|
|
13
|
+
import { join, dirname } from "node:path";
|
|
14
|
+
import { homedir } from "node:os";
|
|
15
|
+
import { tmpdir } from "node:os";
|
|
16
|
+
import { ensureGitignoreSync } from "../storage";
|
|
17
|
+
// =============================================================================
|
|
18
|
+
// Path Utilities
|
|
19
|
+
// =============================================================================
|
|
20
|
+
function getConfigDir() {
|
|
21
|
+
const platform = process.platform;
|
|
22
|
+
if (platform === "win32") {
|
|
23
|
+
return join(process.env.APPDATA || join(homedir(), "AppData", "Roaming"), "opencode");
|
|
24
|
+
}
|
|
25
|
+
const xdgConfig = process.env.XDG_CONFIG_HOME || join(homedir(), ".config");
|
|
26
|
+
return join(xdgConfig, "opencode");
|
|
27
|
+
}
|
|
28
|
+
function getCacheFilePath() {
|
|
29
|
+
return join(getConfigDir(), "antigravity-signature-cache.json");
|
|
30
|
+
}
|
|
31
|
+
// =============================================================================
|
|
32
|
+
// Signature Cache Class
|
|
33
|
+
// =============================================================================
|
|
34
|
+
export class SignatureCache {
|
|
35
|
+
// In-memory cache: key -> entry with signature and optional thinking text
|
|
36
|
+
cache = new Map();
|
|
37
|
+
// Configuration
|
|
38
|
+
memoryTtlMs;
|
|
39
|
+
diskTtlMs;
|
|
40
|
+
writeIntervalMs;
|
|
41
|
+
cacheFilePath;
|
|
42
|
+
enabled;
|
|
43
|
+
// State
|
|
44
|
+
dirty = false;
|
|
45
|
+
writeTimer = null;
|
|
46
|
+
cleanupTimer = null;
|
|
47
|
+
// Statistics
|
|
48
|
+
stats = {
|
|
49
|
+
memoryHits: 0,
|
|
50
|
+
diskHits: 0,
|
|
51
|
+
misses: 0,
|
|
52
|
+
writes: 0,
|
|
53
|
+
};
|
|
54
|
+
constructor(config) {
|
|
55
|
+
this.enabled = config.enabled;
|
|
56
|
+
this.memoryTtlMs = config.memory_ttl_seconds * 1000;
|
|
57
|
+
this.diskTtlMs = config.disk_ttl_seconds * 1000;
|
|
58
|
+
this.writeIntervalMs = config.write_interval_seconds * 1000;
|
|
59
|
+
this.cacheFilePath = getCacheFilePath();
|
|
60
|
+
if (this.enabled) {
|
|
61
|
+
this.loadFromDisk();
|
|
62
|
+
this.startBackgroundTasks();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// ===========================================================================
|
|
66
|
+
// Public API
|
|
67
|
+
// ===========================================================================
|
|
68
|
+
/**
|
|
69
|
+
* Generate a cache key from sessionId and modelId.
|
|
70
|
+
*/
|
|
71
|
+
static makeKey(sessionId, modelId) {
|
|
72
|
+
return `${sessionId}:${modelId}`;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Store a signature in the cache.
|
|
76
|
+
*/
|
|
77
|
+
store(key, signature) {
|
|
78
|
+
if (!this.enabled)
|
|
79
|
+
return;
|
|
80
|
+
this.cache.set(key, {
|
|
81
|
+
value: signature,
|
|
82
|
+
timestamp: Date.now(),
|
|
83
|
+
});
|
|
84
|
+
this.dirty = true;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Retrieve a signature from the cache.
|
|
88
|
+
* Returns null if not found or expired.
|
|
89
|
+
*/
|
|
90
|
+
retrieve(key) {
|
|
91
|
+
if (!this.enabled)
|
|
92
|
+
return null;
|
|
93
|
+
const entry = this.cache.get(key);
|
|
94
|
+
if (entry) {
|
|
95
|
+
const age = Date.now() - entry.timestamp;
|
|
96
|
+
if (age <= this.memoryTtlMs) {
|
|
97
|
+
this.stats.memoryHits++;
|
|
98
|
+
return entry.value;
|
|
99
|
+
}
|
|
100
|
+
// Expired from memory, remove it
|
|
101
|
+
this.cache.delete(key);
|
|
102
|
+
}
|
|
103
|
+
this.stats.misses++;
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Check if a key exists in the cache (without updating stats).
|
|
108
|
+
*/
|
|
109
|
+
has(key) {
|
|
110
|
+
if (!this.enabled)
|
|
111
|
+
return false;
|
|
112
|
+
const entry = this.cache.get(key);
|
|
113
|
+
if (!entry)
|
|
114
|
+
return false;
|
|
115
|
+
const age = Date.now() - entry.timestamp;
|
|
116
|
+
return age <= this.memoryTtlMs;
|
|
117
|
+
}
|
|
118
|
+
// ===========================================================================
|
|
119
|
+
// Full Thinking Cache (ported from LLM-API-Key-Proxy)
|
|
120
|
+
// ===========================================================================
|
|
121
|
+
/**
|
|
122
|
+
* Store full thinking content with signature.
|
|
123
|
+
* This enables recovery even after thinking text is stripped by compaction.
|
|
124
|
+
*
|
|
125
|
+
* Port of LLM-API-Key-Proxy's _cache_thinking()
|
|
126
|
+
*/
|
|
127
|
+
storeThinking(key, thinkingText, signature, toolIds) {
|
|
128
|
+
if (!this.enabled || !thinkingText || !signature)
|
|
129
|
+
return;
|
|
130
|
+
this.cache.set(key, {
|
|
131
|
+
value: signature,
|
|
132
|
+
timestamp: Date.now(),
|
|
133
|
+
thinkingText,
|
|
134
|
+
textPreview: thinkingText.slice(0, 100),
|
|
135
|
+
toolIds,
|
|
136
|
+
});
|
|
137
|
+
this.dirty = true;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Retrieve full thinking content by key.
|
|
141
|
+
* Returns null if not found or expired.
|
|
142
|
+
*/
|
|
143
|
+
retrieveThinking(key) {
|
|
144
|
+
if (!this.enabled)
|
|
145
|
+
return null;
|
|
146
|
+
const entry = this.cache.get(key);
|
|
147
|
+
if (!entry || !entry.thinkingText)
|
|
148
|
+
return null;
|
|
149
|
+
const age = Date.now() - entry.timestamp;
|
|
150
|
+
if (age > this.memoryTtlMs) {
|
|
151
|
+
this.cache.delete(key);
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
this.stats.memoryHits++;
|
|
155
|
+
return {
|
|
156
|
+
text: entry.thinkingText,
|
|
157
|
+
signature: entry.value,
|
|
158
|
+
toolIds: entry.toolIds,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Check if full thinking content exists for a key.
|
|
163
|
+
*/
|
|
164
|
+
hasThinking(key) {
|
|
165
|
+
if (!this.enabled)
|
|
166
|
+
return false;
|
|
167
|
+
const entry = this.cache.get(key);
|
|
168
|
+
if (!entry || !entry.thinkingText)
|
|
169
|
+
return false;
|
|
170
|
+
const age = Date.now() - entry.timestamp;
|
|
171
|
+
return age <= this.memoryTtlMs;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Get cache statistics.
|
|
175
|
+
*/
|
|
176
|
+
getStats() {
|
|
177
|
+
return {
|
|
178
|
+
...this.stats,
|
|
179
|
+
memoryEntries: this.cache.size,
|
|
180
|
+
dirty: this.dirty,
|
|
181
|
+
diskEnabled: this.enabled,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Manually trigger a disk save.
|
|
186
|
+
*/
|
|
187
|
+
async flush() {
|
|
188
|
+
if (!this.enabled)
|
|
189
|
+
return true;
|
|
190
|
+
return this.saveToDisk();
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Graceful shutdown: stop timers and flush to disk.
|
|
194
|
+
*/
|
|
195
|
+
shutdown() {
|
|
196
|
+
if (this.writeTimer) {
|
|
197
|
+
clearInterval(this.writeTimer);
|
|
198
|
+
this.writeTimer = null;
|
|
199
|
+
}
|
|
200
|
+
if (this.cleanupTimer) {
|
|
201
|
+
clearInterval(this.cleanupTimer);
|
|
202
|
+
this.cleanupTimer = null;
|
|
203
|
+
}
|
|
204
|
+
if (this.dirty && this.enabled) {
|
|
205
|
+
this.saveToDisk();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// ===========================================================================
|
|
209
|
+
// Disk Operations
|
|
210
|
+
// ===========================================================================
|
|
211
|
+
/**
|
|
212
|
+
* Load cache from disk file with TTL validation.
|
|
213
|
+
*/
|
|
214
|
+
loadFromDisk() {
|
|
215
|
+
try {
|
|
216
|
+
if (!existsSync(this.cacheFilePath)) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const content = readFileSync(this.cacheFilePath, "utf-8");
|
|
220
|
+
const data = JSON.parse(content);
|
|
221
|
+
if (data.version !== "1.0") {
|
|
222
|
+
// Version mismatch - silently start fresh
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const now = Date.now();
|
|
226
|
+
let loaded = 0;
|
|
227
|
+
let expired = 0;
|
|
228
|
+
for (const [key, entry] of Object.entries(data.entries)) {
|
|
229
|
+
const age = now - entry.timestamp;
|
|
230
|
+
if (age <= this.diskTtlMs) {
|
|
231
|
+
this.cache.set(key, {
|
|
232
|
+
value: entry.value,
|
|
233
|
+
timestamp: entry.timestamp,
|
|
234
|
+
});
|
|
235
|
+
loaded++;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
expired++;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// Silently load - no console output
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
// Silently start fresh on any error (corruption, file not found, etc.)
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Save cache to disk with atomic write pattern.
|
|
249
|
+
* Merges with existing disk entries that haven't expired.
|
|
250
|
+
*/
|
|
251
|
+
saveToDisk() {
|
|
252
|
+
try {
|
|
253
|
+
// Ensure directory exists
|
|
254
|
+
const dir = dirname(this.cacheFilePath);
|
|
255
|
+
if (!existsSync(dir)) {
|
|
256
|
+
mkdirSync(dir, { recursive: true });
|
|
257
|
+
}
|
|
258
|
+
ensureGitignoreSync(dir);
|
|
259
|
+
const now = Date.now();
|
|
260
|
+
// Step 1: Load existing disk entries (if any)
|
|
261
|
+
let existingEntries = {};
|
|
262
|
+
if (existsSync(this.cacheFilePath)) {
|
|
263
|
+
try {
|
|
264
|
+
const content = readFileSync(this.cacheFilePath, "utf-8");
|
|
265
|
+
const data = JSON.parse(content);
|
|
266
|
+
existingEntries = data.entries || {};
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
// Start fresh if corrupted
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
// Step 2: Filter existing disk entries by disk_ttl
|
|
273
|
+
const validDiskEntries = {};
|
|
274
|
+
for (const [key, entry] of Object.entries(existingEntries)) {
|
|
275
|
+
const age = now - entry.timestamp;
|
|
276
|
+
if (age <= this.diskTtlMs) {
|
|
277
|
+
validDiskEntries[key] = entry;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
// Step 3: Merge - memory entries take precedence
|
|
281
|
+
const mergedEntries = { ...validDiskEntries };
|
|
282
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
283
|
+
mergedEntries[key] = {
|
|
284
|
+
value: entry.value,
|
|
285
|
+
timestamp: entry.timestamp,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
// Step 4: Build cache data
|
|
289
|
+
const cacheData = {
|
|
290
|
+
version: "1.0",
|
|
291
|
+
memory_ttl_seconds: this.memoryTtlMs / 1000,
|
|
292
|
+
disk_ttl_seconds: this.diskTtlMs / 1000,
|
|
293
|
+
entries: mergedEntries,
|
|
294
|
+
statistics: {
|
|
295
|
+
memory_hits: this.stats.memoryHits,
|
|
296
|
+
disk_hits: this.stats.diskHits,
|
|
297
|
+
misses: this.stats.misses,
|
|
298
|
+
writes: this.stats.writes + 1,
|
|
299
|
+
last_write: now,
|
|
300
|
+
},
|
|
301
|
+
};
|
|
302
|
+
// Step 5: Atomic write (temp file + rename)
|
|
303
|
+
const tmpPath = join(tmpdir(), `antigravity-cache-${Date.now()}-${Math.random().toString(36).slice(2)}.tmp`);
|
|
304
|
+
writeFileSync(tmpPath, JSON.stringify(cacheData, null, 2), "utf-8");
|
|
305
|
+
try {
|
|
306
|
+
renameSync(tmpPath, this.cacheFilePath);
|
|
307
|
+
}
|
|
308
|
+
catch {
|
|
309
|
+
// On Windows, rename across volumes may fail
|
|
310
|
+
// Fall back to copy + delete
|
|
311
|
+
writeFileSync(this.cacheFilePath, readFileSync(tmpPath));
|
|
312
|
+
try {
|
|
313
|
+
unlinkSync(tmpPath);
|
|
314
|
+
}
|
|
315
|
+
catch {
|
|
316
|
+
// Ignore cleanup errors
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
this.stats.writes++;
|
|
320
|
+
this.dirty = false;
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
catch {
|
|
324
|
+
// Silently fail - disk cache is optional
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
// ===========================================================================
|
|
329
|
+
// Background Tasks
|
|
330
|
+
// ===========================================================================
|
|
331
|
+
/**
|
|
332
|
+
* Start background write and cleanup timers.
|
|
333
|
+
*/
|
|
334
|
+
startBackgroundTasks() {
|
|
335
|
+
// Periodic disk writes
|
|
336
|
+
this.writeTimer = setInterval(() => {
|
|
337
|
+
if (this.dirty) {
|
|
338
|
+
this.saveToDisk();
|
|
339
|
+
}
|
|
340
|
+
}, this.writeIntervalMs);
|
|
341
|
+
// Periodic memory cleanup (every 30 minutes)
|
|
342
|
+
this.cleanupTimer = setInterval(() => {
|
|
343
|
+
this.cleanupExpired();
|
|
344
|
+
}, 30 * 60 * 1000);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Remove expired entries from memory.
|
|
348
|
+
*/
|
|
349
|
+
cleanupExpired() {
|
|
350
|
+
const now = Date.now();
|
|
351
|
+
let cleaned = 0;
|
|
352
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
353
|
+
const age = now - entry.timestamp;
|
|
354
|
+
if (age > this.memoryTtlMs) {
|
|
355
|
+
this.cache.delete(key);
|
|
356
|
+
cleaned++;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
// Silently clean - no console output
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
// =============================================================================
|
|
363
|
+
// Factory Function
|
|
364
|
+
// =============================================================================
|
|
365
|
+
/**
|
|
366
|
+
* Create a signature cache with the given configuration.
|
|
367
|
+
* Returns null if caching is disabled.
|
|
368
|
+
*/
|
|
369
|
+
export function createSignatureCache(config) {
|
|
370
|
+
if (!config || !config.enabled) {
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
return new SignatureCache(config);
|
|
374
|
+
}
|
|
375
|
+
//# sourceMappingURL=signature-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature-cache.js","sourceRoot":"","sources":["../../../../src/plugin/cache/signature-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrG,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAkDjD,gFAAgF;AAChF,iBAAiB;AACjB,gFAAgF;AAEhF,SAAS,YAAY;IACnB,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAClC,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,UAAU,CAAC,CAAC;IACxF,CAAC;IACD,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC;IAC5E,OAAO,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,gBAAgB;IACvB,OAAO,IAAI,CAAC,YAAY,EAAE,EAAE,kCAAkC,CAAC,CAAC;AAClE,CAAC;AAED,gFAAgF;AAChF,wBAAwB;AACxB,gFAAgF;AAEhF,MAAM,O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B,IAAI,CAAC,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE;YACjC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,CAAC;QACH,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QAEzB,6CAA6C;QAC7C,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC,GAAG,EAAE;YACnC,IAAI,CAAC,cAAc,EAAE,CAAC;QACxB,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IACrB,CAAC;IAED;;OAEG;IACK,cAAc;QACpB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,OAAO,GAAG,CAAC,CAAC;QAEhB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YAChD,MAAM,GAAG,GAAG,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC;YAClC,IAAI,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;gBAC3B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBACvB,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;QAED,qCAAqC;IACvC,CAAC;CACF;AAED,gFAAgF;AAChF,mBAAmB;AACnB,gFAAgF;AAEhF;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAwC;IAC3E,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { OAuthAuthDetails } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Returns a cached auth snapshot when available, favoring unexpired tokens.
|
|
4
|
+
*/
|
|
5
|
+
export declare function resolveCachedAuth(auth: OAuthAuthDetails): OAuthAuthDetails;
|
|
6
|
+
/**
|
|
7
|
+
* Stores the latest auth snapshot keyed by refresh token.
|
|
8
|
+
*/
|
|
9
|
+
export declare function storeCachedAuth(auth: OAuthAuthDetails): void;
|
|
10
|
+
/**
|
|
11
|
+
* Clears cached auth globally or for a specific refresh token.
|
|
12
|
+
*/
|
|
13
|
+
export declare function clearCachedAuth(refresh?: string): void;
|
|
14
|
+
import { SignatureCache } from "./cache/signature-cache";
|
|
15
|
+
import type { SignatureCacheConfig } from "./config";
|
|
16
|
+
/**
|
|
17
|
+
* Initialize the disk-based signature cache.
|
|
18
|
+
* Call this from plugin initialization when keep_thinking is enabled.
|
|
19
|
+
*/
|
|
20
|
+
export declare function initDiskSignatureCache(config: SignatureCacheConfig | undefined): SignatureCache | null;
|
|
21
|
+
/**
|
|
22
|
+
* Get the disk cache instance (for testing/debugging).
|
|
23
|
+
*/
|
|
24
|
+
export declare function getDiskSignatureCache(): SignatureCache | null;
|
|
25
|
+
/**
|
|
26
|
+
* Caches a thinking signature for a given session and text.
|
|
27
|
+
* Used for Claude models that require signed thinking blocks in multi-turn conversations.
|
|
28
|
+
* Also writes to disk cache if enabled.
|
|
29
|
+
*/
|
|
30
|
+
export declare function cacheSignature(sessionId: string, text: string, signature: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves a cached signature for a given session and text.
|
|
33
|
+
* Checks memory first, then falls back to disk cache.
|
|
34
|
+
* Returns undefined if not found or expired.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getCachedSignature(sessionId: string, text: string): string | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Clears signature cache for a specific session or all sessions.
|
|
39
|
+
* Also clears from disk cache if enabled.
|
|
40
|
+
*/
|
|
41
|
+
export declare function clearSignatureCache(sessionId?: string): void;
|
|
42
|
+
export { SignatureCache, createSignatureCache } from "./cache/signature-cache";
|
|
43
|
+
export type { SignatureCacheConfig } from "./config";
|
|
44
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../src/plugin/cache.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAahD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,GAAG,gBAAgB,CAuB1E;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAM5D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAStD;AAMD,OAAO,EAAE,cAAc,EAAwB,MAAM,yBAAyB,CAAC;AAC/E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAsBrD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,oBAAoB,GAAG,SAAS,GAAG,cAAc,GAAG,IAAI,CAGtG;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,cAAc,GAAG,IAAI,CAE7D;AAkBD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAsCvF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAoCtF;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAU5D;AAOD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/E,YAAY,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC"}
|