@qmediat.io/gemini-code-context-mcp 1.0.2 → 1.2.0
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/CHANGELOG.md +87 -0
- package/dist/auth/credentials-store.d.ts.map +1 -1
- package/dist/auth/credentials-store.js +8 -2
- package/dist/auth/credentials-store.js.map +1 -1
- package/dist/cache/cache-manager.d.ts +31 -0
- package/dist/cache/cache-manager.d.ts.map +1 -1
- package/dist/cache/cache-manager.js +105 -0
- package/dist/cache/cache-manager.js.map +1 -1
- package/dist/cache/ttl-watcher.d.ts +2 -0
- package/dist/cache/ttl-watcher.d.ts.map +1 -1
- package/dist/cache/ttl-watcher.js +60 -25
- package/dist/cache/ttl-watcher.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +5 -1
- package/dist/config.js.map +1 -1
- package/dist/gemini/models.d.ts.map +1 -1
- package/dist/gemini/models.js +34 -25
- package/dist/gemini/models.js.map +1 -1
- package/dist/indexer/globs.d.ts +24 -1
- package/dist/indexer/globs.d.ts.map +1 -1
- package/dist/indexer/globs.js +70 -4
- package/dist/indexer/globs.js.map +1 -1
- package/dist/indexer/workspace-validation.d.ts +54 -0
- package/dist/indexer/workspace-validation.d.ts.map +1 -0
- package/dist/indexer/workspace-validation.js +206 -0
- package/dist/indexer/workspace-validation.js.map +1 -0
- package/dist/manifest/db.d.ts +50 -0
- package/dist/manifest/db.d.ts.map +1 -1
- package/dist/manifest/db.js +74 -1
- package/dist/manifest/db.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +7 -0
- package/dist/server.js.map +1 -1
- package/dist/tools/ask.tool.d.ts +25 -1
- package/dist/tools/ask.tool.d.ts.map +1 -1
- package/dist/tools/ask.tool.js +267 -27
- package/dist/tools/ask.tool.js.map +1 -1
- package/dist/tools/code.tool.d.ts +24 -1
- package/dist/tools/code.tool.d.ts.map +1 -1
- package/dist/tools/code.tool.js +188 -31
- package/dist/tools/code.tool.js.map +1 -1
- package/dist/tools/registry.d.ts +37 -6
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/tools/registry.js +30 -6
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/reindex.tool.d.ts.map +1 -1
- package/dist/tools/reindex.tool.js +10 -0
- package/dist/tools/reindex.tool.js.map +1 -1
- package/dist/tools/shared/thinking.d.ts +63 -0
- package/dist/tools/shared/thinking.d.ts.map +1 -0
- package/dist/tools/shared/thinking.js +62 -0
- package/dist/tools/shared/thinking.js.map +1 -0
- package/dist/utils/cost-estimator.d.ts +21 -0
- package/dist/utils/cost-estimator.d.ts.map +1 -1
- package/dist/utils/cost-estimator.js +43 -6
- package/dist/utils/cost-estimator.js.map +1 -1
- package/package.json +3 -3
|
@@ -9,6 +9,7 @@ import { z } from 'zod';
|
|
|
9
9
|
import { invalidateWorkspaceCache } from '../cache/cache-manager.js';
|
|
10
10
|
import { invalidateModelCache } from '../gemini/model-registry.js';
|
|
11
11
|
import { scanWorkspace } from '../indexer/workspace-scanner.js';
|
|
12
|
+
import { WorkspaceValidationError, validateWorkspacePath, } from '../indexer/workspace-validation.js';
|
|
12
13
|
import { createProgressEmitter } from '../utils/progress.js';
|
|
13
14
|
import { errorResult, textResult } from './registry.js';
|
|
14
15
|
export const reindexInputSchema = z.object({
|
|
@@ -27,6 +28,15 @@ export const reindexTool = {
|
|
|
27
28
|
const emitter = createProgressEmitter(ctx.server, ctx.progressToken);
|
|
28
29
|
try {
|
|
29
30
|
const workspaceRoot = resolve(input.workspace ?? process.cwd());
|
|
31
|
+
try {
|
|
32
|
+
validateWorkspacePath(workspaceRoot);
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
if (err instanceof WorkspaceValidationError) {
|
|
36
|
+
return errorResult(`reindex: ${err.message}`);
|
|
37
|
+
}
|
|
38
|
+
throw err;
|
|
39
|
+
}
|
|
30
40
|
emitter.emit('invalidating cache…');
|
|
31
41
|
await invalidateWorkspaceCache({
|
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,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC5F,CAAC;gBAAS,CAAC;YACT,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-tool constants for Gemini's thinking-mode configuration.
|
|
3
|
+
*
|
|
4
|
+
* Both `ask` and `code` tools expose the same two knobs (`thinkingBudget`
|
|
5
|
+
* and `thinkingLevel`) with identical semantics and identical mutual-exclusion
|
|
6
|
+
* rules. Keeping the schema literal list and cost-estimate reserve table
|
|
7
|
+
* here avoids drift between the tools — when Google publishes per-tier
|
|
8
|
+
* token budgets or ships a new level, one edit here propagates to both
|
|
9
|
+
* call sites (and any future reasoning-capable tool we add).
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Accepted values for `thinkingLevel` on both `ask` and `code`. Uppercased
|
|
13
|
+
* to match `ThinkingLevel` enum members in `@google/genai` — we pass the
|
|
14
|
+
* literal string through to Gemini as `ThinkingLevel` via a type cast
|
|
15
|
+
* (no runtime enum lookup, so SDK member renames surface as Gemini 400s
|
|
16
|
+
* rather than silent `undefined`).
|
|
17
|
+
*
|
|
18
|
+
* `THINKING_LEVEL_UNSPECIFIED` is deliberately excluded: it's the SDK's
|
|
19
|
+
* "no value set" sentinel, and passing it is semantically equivalent to
|
|
20
|
+
* omitting the field. Callers who want model-native behaviour should just
|
|
21
|
+
* omit `thinkingLevel` entirely.
|
|
22
|
+
*
|
|
23
|
+
* Per Google's Gemini 3 guide (ai.google.dev/gemini-api/docs/gemini-3):
|
|
24
|
+
* - Gemini 3 Pro supports LOW / MEDIUM / HIGH (not MINIMAL); default HIGH.
|
|
25
|
+
* - Gemini 3 Flash supports all four; Flash-Lite defaults to MINIMAL.
|
|
26
|
+
* - Gemini 2.5 family does NOT support `thinkingLevel` — use `thinkingBudget`.
|
|
27
|
+
* Both tools accept all four values at the schema boundary and let Gemini
|
|
28
|
+
* reject unsupported combinations at request time, so the MCP surface stays
|
|
29
|
+
* stable across model rollouts.
|
|
30
|
+
*/
|
|
31
|
+
export declare const THINKING_LEVELS: readonly ["MINIMAL", "LOW", "MEDIUM", "HIGH"];
|
|
32
|
+
/**
|
|
33
|
+
* Literal-union type matching the schema's accepted `thinkingLevel` values.
|
|
34
|
+
* Sourced from `THINKING_LEVELS` so adding a new level means editing exactly
|
|
35
|
+
* one place.
|
|
36
|
+
*/
|
|
37
|
+
export type ThinkingLevelLiteral = (typeof THINKING_LEVELS)[number];
|
|
38
|
+
/**
|
|
39
|
+
* Conservative per-tier thinking-token reservations for cost estimation.
|
|
40
|
+
*
|
|
41
|
+
* Google does not publish the exact per-tier token budgets Gemini consumes
|
|
42
|
+
* for each `thinkingLevel`. These numbers are heuristic upper bounds based
|
|
43
|
+
* on Google's documented "MINIMAL ≈ near-zero", "HIGH ≈ up to model's
|
|
44
|
+
* thinking limit" guidance (ai.google.dev/gemini-api/docs/thinking). Using
|
|
45
|
+
* tier-aware values (rather than always-worst-case) prevents
|
|
46
|
+
* `GEMINI_DAILY_BUDGET_USD` from false-rejecting a long sequence of
|
|
47
|
+
* `MINIMAL` calls where the real spend is ≤1% of a worst-case reservation.
|
|
48
|
+
*
|
|
49
|
+
* If Gemini actually consumes MORE than we reserved, the tool's
|
|
50
|
+
* `finalizeBudgetReservation` writes the measured cost over the estimate —
|
|
51
|
+
* the cap remains a true upper bound across *completed* calls; tiered
|
|
52
|
+
* reservations only affect preflight acceptance. A call that genuinely
|
|
53
|
+
* exceeds the tier's reserve will succeed (Gemini honours whatever it
|
|
54
|
+
* decides to spend); a subsequent call will see the larger measured cost
|
|
55
|
+
* in the budget ledger.
|
|
56
|
+
*
|
|
57
|
+
* HIGH intentionally maps to `null` → call sites substitute
|
|
58
|
+
* `maxOutputTokens - 1024` so the value tracks each tool's actual output
|
|
59
|
+
* cap (8_192 for `ask`, 32_768 for `code`) rather than a hard-coded
|
|
60
|
+
* duplicate.
|
|
61
|
+
*/
|
|
62
|
+
export declare const THINKING_LEVEL_RESERVE: Record<ThinkingLevelLiteral, number | null>;
|
|
63
|
+
//# sourceMappingURL=thinking.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thinking.d.ts","sourceRoot":"","sources":["../../../src/tools/shared/thinking.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,eAAe,+CAAgD,CAAC;AAE7E;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAK9E,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-tool constants for Gemini's thinking-mode configuration.
|
|
3
|
+
*
|
|
4
|
+
* Both `ask` and `code` tools expose the same two knobs (`thinkingBudget`
|
|
5
|
+
* and `thinkingLevel`) with identical semantics and identical mutual-exclusion
|
|
6
|
+
* rules. Keeping the schema literal list and cost-estimate reserve table
|
|
7
|
+
* here avoids drift between the tools — when Google publishes per-tier
|
|
8
|
+
* token budgets or ships a new level, one edit here propagates to both
|
|
9
|
+
* call sites (and any future reasoning-capable tool we add).
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Accepted values for `thinkingLevel` on both `ask` and `code`. Uppercased
|
|
13
|
+
* to match `ThinkingLevel` enum members in `@google/genai` — we pass the
|
|
14
|
+
* literal string through to Gemini as `ThinkingLevel` via a type cast
|
|
15
|
+
* (no runtime enum lookup, so SDK member renames surface as Gemini 400s
|
|
16
|
+
* rather than silent `undefined`).
|
|
17
|
+
*
|
|
18
|
+
* `THINKING_LEVEL_UNSPECIFIED` is deliberately excluded: it's the SDK's
|
|
19
|
+
* "no value set" sentinel, and passing it is semantically equivalent to
|
|
20
|
+
* omitting the field. Callers who want model-native behaviour should just
|
|
21
|
+
* omit `thinkingLevel` entirely.
|
|
22
|
+
*
|
|
23
|
+
* Per Google's Gemini 3 guide (ai.google.dev/gemini-api/docs/gemini-3):
|
|
24
|
+
* - Gemini 3 Pro supports LOW / MEDIUM / HIGH (not MINIMAL); default HIGH.
|
|
25
|
+
* - Gemini 3 Flash supports all four; Flash-Lite defaults to MINIMAL.
|
|
26
|
+
* - Gemini 2.5 family does NOT support `thinkingLevel` — use `thinkingBudget`.
|
|
27
|
+
* Both tools accept all four values at the schema boundary and let Gemini
|
|
28
|
+
* reject unsupported combinations at request time, so the MCP surface stays
|
|
29
|
+
* stable across model rollouts.
|
|
30
|
+
*/
|
|
31
|
+
export const THINKING_LEVELS = ['MINIMAL', 'LOW', 'MEDIUM', 'HIGH'];
|
|
32
|
+
/**
|
|
33
|
+
* Conservative per-tier thinking-token reservations for cost estimation.
|
|
34
|
+
*
|
|
35
|
+
* Google does not publish the exact per-tier token budgets Gemini consumes
|
|
36
|
+
* for each `thinkingLevel`. These numbers are heuristic upper bounds based
|
|
37
|
+
* on Google's documented "MINIMAL ≈ near-zero", "HIGH ≈ up to model's
|
|
38
|
+
* thinking limit" guidance (ai.google.dev/gemini-api/docs/thinking). Using
|
|
39
|
+
* tier-aware values (rather than always-worst-case) prevents
|
|
40
|
+
* `GEMINI_DAILY_BUDGET_USD` from false-rejecting a long sequence of
|
|
41
|
+
* `MINIMAL` calls where the real spend is ≤1% of a worst-case reservation.
|
|
42
|
+
*
|
|
43
|
+
* If Gemini actually consumes MORE than we reserved, the tool's
|
|
44
|
+
* `finalizeBudgetReservation` writes the measured cost over the estimate —
|
|
45
|
+
* the cap remains a true upper bound across *completed* calls; tiered
|
|
46
|
+
* reservations only affect preflight acceptance. A call that genuinely
|
|
47
|
+
* exceeds the tier's reserve will succeed (Gemini honours whatever it
|
|
48
|
+
* decides to spend); a subsequent call will see the larger measured cost
|
|
49
|
+
* in the budget ledger.
|
|
50
|
+
*
|
|
51
|
+
* HIGH intentionally maps to `null` → call sites substitute
|
|
52
|
+
* `maxOutputTokens - 1024` so the value tracks each tool's actual output
|
|
53
|
+
* cap (8_192 for `ask`, 32_768 for `code`) rather than a hard-coded
|
|
54
|
+
* duplicate.
|
|
55
|
+
*/
|
|
56
|
+
export const THINKING_LEVEL_RESERVE = {
|
|
57
|
+
MINIMAL: 512,
|
|
58
|
+
LOW: 2_048,
|
|
59
|
+
MEDIUM: 4_096,
|
|
60
|
+
HIGH: null,
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=thinking.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thinking.js","sourceRoot":"","sources":["../../../src/tools/shared/thinking.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAU,CAAC;AAS7E;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAgD;IACjF,OAAO,EAAE,GAAG;IACZ,GAAG,EAAE,KAAK;IACV,MAAM,EAAE,KAAK;IACb,IAAI,EAAE,IAAI;CACX,CAAC"}
|
|
@@ -21,6 +21,27 @@ export interface CostInputs {
|
|
|
21
21
|
/** Estimated cost in USD (float). Multiply by 1e6 for micros before storing. */
|
|
22
22
|
export declare function estimateCostUsd(input: CostInputs): number;
|
|
23
23
|
export declare function toMicrosUsd(dollars: number): number;
|
|
24
|
+
export interface PreCallEstimateInputs {
|
|
25
|
+
model: string;
|
|
26
|
+
/** Sum of file sizes in bytes — the workspace content that will be sent. */
|
|
27
|
+
workspaceBytes: number;
|
|
28
|
+
/** Length of the user prompt in chars — tokenised at ~4 bytes/token. */
|
|
29
|
+
promptChars: number;
|
|
30
|
+
/** Upper bound on output tokens (tool-specific default). */
|
|
31
|
+
expectedOutputTokens: number;
|
|
32
|
+
/** Thinking budget, passed through as extra output tokens. */
|
|
33
|
+
thinkingTokens?: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Pre-call cost estimate used by the budget-reservation path. Charges
|
|
37
|
+
* the workspace content at the UNCACHED rate on purpose — on the first
|
|
38
|
+
* call a cache doesn't exist yet and the reservation must cover that
|
|
39
|
+
* cost; on subsequent calls the cache makes the ACTUAL cost cheaper and
|
|
40
|
+
* the `finalizeBudgetReservation` pass records the lower real value.
|
|
41
|
+
* Over-estimating here = user sees a clear "budget would be exceeded"
|
|
42
|
+
* message instead of a silent cap overshoot.
|
|
43
|
+
*/
|
|
44
|
+
export declare function estimatePreCallCostUsd(input: PreCallEstimateInputs): number;
|
|
24
45
|
/**
|
|
25
46
|
* Raw conversion: `micros → dollars` as a full-precision float. Sub-cent values
|
|
26
47
|
* survive, so `usageMetrics` tracking of e.g. $0.0043 calls remains visible.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cost-estimator.d.ts","sourceRoot":"","sources":["../../src/utils/cost-estimator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,YAAY;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,wFAAwF;IACxF,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;
|
|
1
|
+
{"version":3,"file":"cost-estimator.d.ts","sourceRoot":"","sources":["../../src/utils/cost-estimator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,YAAY;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,wFAAwF;IACxF,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AA+DD,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,mBAAmB,EAAE,MAAM,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,gFAAgF;AAChF,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAWzD;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,cAAc,EAAE,MAAM,CAAC;IACvB,wEAAwE;IACxE,WAAW,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,oBAAoB,EAAE,MAAM,CAAC;IAC7B,8DAA8D;IAC9D,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,qBAAqB,GAAG,MAAM,CAU3E;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,2DAA2D;AAC3D,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE5D"}
|
|
@@ -39,18 +39,35 @@ function loadOverrides() {
|
|
|
39
39
|
}
|
|
40
40
|
return overrides;
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Conservative defaults for models we've never seen — one for each tier we
|
|
44
|
+
* recognise by name, plus an "unknown premium" fallback that assumes the
|
|
45
|
+
* highest rate we know of. The goal is to over-estimate cost for a brand-new
|
|
46
|
+
* model so a budget-capped user gets blocked at the cap instead of silently
|
|
47
|
+
* overshooting it while we wait for a pricing-table update.
|
|
48
|
+
*/
|
|
49
|
+
const UNKNOWN_PREMIUM_RATE = { inputPerMillion: 10.5, outputPerMillion: 30 };
|
|
50
|
+
const UNKNOWN_PRO_RATE = { inputPerMillion: 3.5, outputPerMillion: 10.5 };
|
|
51
|
+
const UNKNOWN_FLASH_RATE = { inputPerMillion: 0.3, outputPerMillion: 2.5 };
|
|
52
|
+
const UNKNOWN_LITE_RATE = { inputPerMillion: 0.1, outputPerMillion: 0.4 };
|
|
42
53
|
function pricingFor(model) {
|
|
43
54
|
const ov = loadOverrides();
|
|
44
55
|
if (ov?.[model])
|
|
45
56
|
return ov[model];
|
|
46
57
|
if (DEFAULT_PRICING[model])
|
|
47
58
|
return DEFAULT_PRICING[model];
|
|
48
|
-
// Fallback heuristic
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
// Fallback heuristic — name-based classification, conservative defaults.
|
|
60
|
+
// When the model name gives no useful signal we assume premium-tier rates
|
|
61
|
+
// rather than flash: better to block an over-budget user than let a
|
|
62
|
+
// never-seen model silently undercharge and blow past the cap.
|
|
63
|
+
const lower = model.toLowerCase();
|
|
64
|
+
if (lower.includes('lite'))
|
|
65
|
+
return UNKNOWN_LITE_RATE;
|
|
66
|
+
if (lower.includes('flash'))
|
|
67
|
+
return UNKNOWN_FLASH_RATE;
|
|
68
|
+
if (lower.includes('pro'))
|
|
69
|
+
return UNKNOWN_PRO_RATE;
|
|
70
|
+
return UNKNOWN_PREMIUM_RATE;
|
|
54
71
|
}
|
|
55
72
|
/** Estimated cost in USD (float). Multiply by 1e6 for micros before storing. */
|
|
56
73
|
export function estimateCostUsd(input) {
|
|
@@ -68,6 +85,26 @@ export function estimateCostUsd(input) {
|
|
|
68
85
|
export function toMicrosUsd(dollars) {
|
|
69
86
|
return Math.round(dollars * 1_000_000);
|
|
70
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Pre-call cost estimate used by the budget-reservation path. Charges
|
|
90
|
+
* the workspace content at the UNCACHED rate on purpose — on the first
|
|
91
|
+
* call a cache doesn't exist yet and the reservation must cover that
|
|
92
|
+
* cost; on subsequent calls the cache makes the ACTUAL cost cheaper and
|
|
93
|
+
* the `finalizeBudgetReservation` pass records the lower real value.
|
|
94
|
+
* Over-estimating here = user sees a clear "budget would be exceeded"
|
|
95
|
+
* message instead of a silent cap overshoot.
|
|
96
|
+
*/
|
|
97
|
+
export function estimatePreCallCostUsd(input) {
|
|
98
|
+
const workspaceTokens = Math.ceil(Math.max(0, input.workspaceBytes) / 4);
|
|
99
|
+
const promptTokens = Math.ceil(Math.max(0, input.promptChars) / 4);
|
|
100
|
+
return estimateCostUsd({
|
|
101
|
+
model: input.model,
|
|
102
|
+
uncachedInputTokens: workspaceTokens + promptTokens,
|
|
103
|
+
cachedInputTokens: 0,
|
|
104
|
+
outputTokens: Math.max(0, input.expectedOutputTokens),
|
|
105
|
+
...(input.thinkingTokens !== undefined ? { thinkingTokens: input.thinkingTokens } : {}),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
71
108
|
/**
|
|
72
109
|
* Raw conversion: `micros → dollars` as a full-precision float. Sub-cent values
|
|
73
110
|
* survive, so `usageMetrics` tracking of e.g. $0.0043 calls remains visible.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cost-estimator.js","sourceRoot":"","sources":["../../src/utils/cost-estimator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AASH,MAAM,eAAe,GAAiC;IACpD,sFAAsF;IACtF,sBAAsB,EAAE,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE;IACxE,wBAAwB,EAAE,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE;IAC1E,wBAAwB,EAAE,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE;IACzE,gCAAgC,EAAE,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE;IACjF,+BAA+B,EAAE,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE;IAChF,gBAAgB,EAA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E,cAAc,EAAE,KAAK,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACxF,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,OAAO,MAAM,GAAG,SAAS,CAAC;AAC5B,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,oBAAoB,CAAC,OAAe;IAClD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AACzC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qmediat.io/gemini-code-context-mcp",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "MCP server that gives Claude Code persistent memory of your codebase, backed by Gemini's 2M-token context. Drop-in upgrade over the abandoned gemini-mcp-tool.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@google/genai": "^1.0.0",
|
|
60
60
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
61
|
-
"better-sqlite3": "^
|
|
61
|
+
"better-sqlite3": "^12.9.0",
|
|
62
62
|
"zod": "^3.23.0",
|
|
63
63
|
"zod-to-json-schema": "^3.24.0"
|
|
64
64
|
},
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"@types/node": "^22.0.0",
|
|
70
70
|
"@vitest/coverage-v8": "^4.1.0",
|
|
71
71
|
"tsx": "^4.19.0",
|
|
72
|
-
"typescript": "^
|
|
72
|
+
"typescript": "^6.0.3",
|
|
73
73
|
"vitest": "^4.1.0"
|
|
74
74
|
},
|
|
75
75
|
"publishConfig": {
|