mirror of
https://github.com/garrytan/gbrain.git
synced 2026-08-14 17:02:19 +00:00
Compare commits
1
Commits
master
...
reland/2407
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1cce0b69f1 |
@@ -32,6 +32,7 @@ import { mkdirSync, appendFileSync } from 'node:fs';
|
||||
import { dirname } from 'node:path';
|
||||
import { gbrainPath } from '../config.ts';
|
||||
import { ANTHROPIC_PRICING, type ModelPricing } from '../anthropic-pricing.ts';
|
||||
import { canonicalLookup } from '../model-pricing.ts';
|
||||
import { EMBEDDING_PRICING, lookupEmbeddingPrice } from '../embedding-pricing.ts';
|
||||
import { splitProviderModelId } from '../model-id.ts';
|
||||
import { isoWeekFilename, resolveAuditDir } from '../audit-week-file.ts';
|
||||
@@ -213,6 +214,12 @@ function lookupPricing(modelId: string, kind: BudgetKind): ModelPricing | null {
|
||||
if (kind === 'rerank' && providerId && FREE_LOCAL_RERANK_PROVIDERS.has(providerId)) {
|
||||
return { input: 0, output: 0 };
|
||||
}
|
||||
// Fall back to the full canonical pricing table so non-Anthropic chat
|
||||
// models with a known price (openai:*, google:*, deepseek:*) resolve under
|
||||
// --max-cost instead of TX2 no_pricing hard-failing at $0. ANTHROPIC_PRICING
|
||||
// above is only the bare-keyed Claude view.
|
||||
const canon = canonicalLookup(modelId);
|
||||
if (canon) return canon;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -6007,6 +6007,9 @@ export class PGLiteEngine implements BrainEngine {
|
||||
);
|
||||
}
|
||||
|
||||
// Exclude dream/synthesize-generated pages (parity with postgres-engine).
|
||||
where.push(`(p.frontmatter ->> 'dream_generated') IS DISTINCT FROM 'true'`);
|
||||
|
||||
const orderKey = ENRICH_ORDER_SQL[opts.order] ? opts.order : 'inbound-links';
|
||||
const orderBy = ENRICH_ORDER_SQL[orderKey];
|
||||
|
||||
|
||||
@@ -6293,6 +6293,12 @@ export class PostgresEngine implements BrainEngine {
|
||||
)`
|
||||
: sql``;
|
||||
|
||||
// Exclude dream/synthesize-generated pages (reflections, originals, cycle
|
||||
// logs carrying frontmatter dream_generated:true). enrich develops ENTITY
|
||||
// stubs; running it on a generated essay/log creates circular self-citation
|
||||
// and drops the H1. IS DISTINCT FROM 'true' keeps NULL/'false' rows.
|
||||
const dreamCondition = sql`AND (p.frontmatter ->> 'dream_generated') IS DISTINCT FROM 'true'`;
|
||||
|
||||
// Whitelisted ORDER BY (no injection — enum maps to a literal fragment).
|
||||
const orderKey = ENRICH_ORDER_SQL[opts.order] ? opts.order : 'inbound-links';
|
||||
const orderBy = sql.unsafe(ENRICH_ORDER_SQL[orderKey]);
|
||||
@@ -6316,6 +6322,7 @@ export class PostgresEngine implements BrainEngine {
|
||||
AND (char_length(p.compiled_truth) + char_length(COALESCE(p.timeline, ''))) < ${threshold}
|
||||
${sourceCondition}
|
||||
${recencyCondition}
|
||||
${dreamCondition}
|
||||
ORDER BY ${orderBy}
|
||||
LIMIT ${limit}
|
||||
`;
|
||||
|
||||
@@ -174,7 +174,11 @@ export async function writePageThrough(
|
||||
}
|
||||
}
|
||||
|
||||
mkdirSync(dirname(filePath), { recursive: true });
|
||||
// On Bun + Windows, mkdirSync(dir, { recursive: true }) can still throw
|
||||
// EEXIST when the directory already exists (POSIX no-ops it). That aborts
|
||||
// the put_page / enrich / capture write-through whenever the prefix dir
|
||||
// already exists, silently leaving the DB and the .md file plane out of sync.
|
||||
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
||||
|
||||
// Atomic write: unique temp sibling + rename. Unique name (pid + random)
|
||||
// so two concurrent saves to the same target can't clobber each other's
|
||||
|
||||
Reference in New Issue
Block a user