Add snapshot, signature, and drift guard support for Vertex AI, Cloudflare Workers AI, and Perplexity API, backed by a queryable audit table and recent-window view. This commit also wires the audit query layer into daily signal materialization and report generation so structure drift becomes a first-class signal instead of a log-only artifact.
67 lines
2.0 KiB
Go
67 lines
2.0 KiB
Go
//go:build llm_script
|
|
|
|
package main
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type vertexPricingImportConfig struct {
|
|
URL string
|
|
Fixture string
|
|
DryRun bool
|
|
Timeout time.Duration
|
|
SnapshotOnly bool
|
|
SnapshotOut string
|
|
SignatureOut string
|
|
}
|
|
|
|
func runVertexPricingImport(cfg vertexPricingImportConfig, db *sql.DB, out io.Writer) error {
|
|
client := &http.Client{Timeout: cfg.Timeout}
|
|
raw, err := fetchRawPricingPage(cfg.URL, cfg.Fixture, client)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if cfg.SnapshotOnly || strings.TrimSpace(cfg.SnapshotOut) != "" || strings.TrimSpace(cfg.SignatureOut) != "" {
|
|
snapshotPath, signaturePath := resolveVertexPricingSnapshotPaths(cfg.SnapshotOut, cfg.SignatureOut, time.Now())
|
|
signature, err := writeVertexPricingSnapshotArtifacts(raw, cfg.URL, snapshotPath, signaturePath, time.Now())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if cfg.SnapshotOnly {
|
|
_, err = fmt.Fprintf(out,
|
|
"source=vertex-pricing-snapshot snapshot_only=true byte_size=%d sha256=%s structure_sha256=%s snapshot_out=%s signature_out=%s\n",
|
|
signature.ByteSize, signature.SHA256, signature.StructureSHA256, snapshotPath, signaturePath,
|
|
)
|
|
return err
|
|
}
|
|
}
|
|
records, err := parseVertexPricingCatalog(raw)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
records = dedupeOfficialPricingRecords(records)
|
|
if cfg.DryRun {
|
|
_, err = fmt.Fprintf(out, "source=vertex-pricing-import models=%d operator=%s dry_run=true\n", len(records), records[0].OperatorName)
|
|
return err
|
|
}
|
|
if db == nil {
|
|
return fmt.Errorf("db is required when dry-run=false")
|
|
}
|
|
if err := upsertOfficialPricingRecords(db, records, "vertex-pricing-import"); err != nil {
|
|
return err
|
|
}
|
|
|
|
var tableRows int
|
|
if err := db.QueryRow(`SELECT COUNT(*) FROM region_pricing`).Scan(&tableRows); err != nil {
|
|
return fmt.Errorf("count region_pricing: %w", err)
|
|
}
|
|
_, err = fmt.Fprintf(out, "source=vertex-pricing-import models=%d operator=%s table_rows=%d dry_run=false\n", len(records), records[0].OperatorName, tableRows)
|
|
return err
|
|
}
|