repositories / pi-ext
pi-ext
bugabingas pi extensions
owned by admin
extensions/devdocs/src/types.ts
Rawimport type { FormatId } from "./catalog.ts";
export type Section = { locator: string; heading: string; body: string };
export type Candidate = {
id: string;
target: string;
version: string | null;
origin: string;
title: string;
source: string;
scope: string;
evidence: string | null;
requestedVersion?: string | null;
};
export type Document = {
candidate: Candidate;
sections: Section[];
attribution: string;
validator: string | null;
};
export type Request = {
target: string;
query: string;
version?: string | undefined;
requestedVersion?: string | null;
cwd: string;
signal?: AbortSignal | undefined;
};
export type Adapter = {
id: string;
rank: number;
formatVersion: number;
coverage: "corpus" | "document" | "query";
identity?: string;
discover(request: Request): Promise<Candidate[]>;
retrieve(
candidate: Candidate,
request: Request,
validator?: string | null,
): Promise<Document | "unchanged">;
};
export type RegisteredSource = {
id: string;
target: string;
path: string;
version: string | null;
format: FormatId;
url?: string | null;
private: boolean;
};
export type SearchHit = {
ref: string;
heading: string;
snippet: string;
target: string;
version: string | null;
source: string;
origin: string;
freshness: "fresh" | "stale";
checkedAt: string;
requestedVersion: string | null;
};
export type StoredSection = {
totalLength: number;
revision: string;
ordinal: number;
heading: string;
body: string;
target: string;
version: string | null;
source: string;
origin: string;
checkedAt: string;
attribution: string;
scope: string;
requestedVersion: string | null;
freshness?: "fresh" | "stale";
};
export type SearchResult =
| { status: "ok"; results: SearchHit[]; reasons: string[] }
| { status: "ambiguous"; candidates: Candidate[] }
| { status: "unavailable"; reasons: string[] };
export type ReadSection = {
ref: string;
heading: string;
target: string;
version: string | null;
source: string;
origin: string;
checkedAt: string;
attribution: string;
content: string;
requestedVersion: string | null;
freshness: "fresh" | "stale";
};
export type ReadResult = {
status: "ok";
sections: ReadSection[];
truncated: boolean;
continuation: string[];
};
export type CacheStatus = {
bytes: number;
revisions: number;
refreshing: number;
};
export type StatusResult = {
status: "ok";
tokenizer: "unicode-codepoint-v1";
minimumBudget: number;
sources: { id: string; rank: number; coverage: Adapter["coverage"] }[];
cache: CacheStatus;
offline: boolean;
context7Mode: "anonymous" | "keyed" | "disabled";
};
export type Options = {
databasePath: string;
enabledSources: string[];
sources: RegisteredSource[];
offline: boolean;
cacheBytes: number;
ttlMs: number;
};
export function matchesVersion(
requested: string | undefined,
actual: string | null,
): boolean {
if (!requested) return true;
if (!actual) return false;
const req = requested.replace(/^v/, "");
const got = actual.replace(/^v/, "");
return (
got === req || (/^\d+(?:\.\d+)?$/.test(req) && got.startsWith(req + "."))
);
}