feat(foundation): Wave 3 integrity/persistence/build fixes
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* src/clients/aud0-client.ts
|
||||
* ===========================
|
||||
* 0pt's thin client for emitting append-only events + lineage edges to AUD0
|
||||
* (the SIAX Cloud system of record). Two methods:
|
||||
* - ingestEvent -> POST {baseUrl}/v1/aud0/events
|
||||
* - ingestLineageEvent -> POST {baseUrl}/v1/aud0/lineage/events
|
||||
*
|
||||
* Convention (identical to cl0ud-client.ts / n0d-client.ts / st0re-client.ts
|
||||
* / st0re-lakehouse-client.ts): when no base URL is configured the client is
|
||||
* a NO-OP — it does not attempt any network call. AUD0 is a best-effort,
|
||||
* out-of-band audit sink for 0pt; a missing AUD0_URL (unit tests, local dev)
|
||||
* must not turn every capability call into a failed fetch to `undefined`.
|
||||
* When a base URL IS configured, events are POSTed as-is (the event object is
|
||||
* the wire body) with `Content-Type: application/json`.
|
||||
*/
|
||||
|
||||
export interface Aud0Event {
|
||||
event_id: string;
|
||||
event_type: string;
|
||||
tenant_id: string;
|
||||
project_id: string;
|
||||
actor_id: string;
|
||||
app_id: string;
|
||||
capability_id: string;
|
||||
resource_type: string;
|
||||
resource_id: string;
|
||||
/** Risk level L0–L5 per the SIAX Cloud risk taxonomy. */
|
||||
risk_level: string;
|
||||
payload: Record<string, unknown>;
|
||||
created_at: string;
|
||||
correlation_id?: string;
|
||||
}
|
||||
|
||||
export interface Aud0LineageEvent {
|
||||
lineage_event_id: string;
|
||||
tenant_id: string;
|
||||
project_id: string;
|
||||
app_id: string;
|
||||
capability_id: string;
|
||||
source_type: string;
|
||||
source_id: string;
|
||||
target_type: string;
|
||||
target_id: string;
|
||||
/** e.g. "produced" | "derived_from" | "stored_as". */
|
||||
lineage_type: string;
|
||||
metadata: Record<string, unknown>;
|
||||
created_at: string;
|
||||
correlation_id?: string;
|
||||
}
|
||||
|
||||
export interface Aud0Client {
|
||||
ingestEvent(event: Aud0Event): Promise<void>;
|
||||
ingestLineageEvent(event: Aud0LineageEvent): Promise<void>;
|
||||
}
|
||||
|
||||
export function createAud0Client(baseUrl?: string): Aud0Client {
|
||||
if (!baseUrl) return new NoopAud0Client();
|
||||
return new HttpAud0Client(baseUrl);
|
||||
}
|
||||
|
||||
/** No AUD0_URL configured: audit emission is a no-op (see module doc comment). */
|
||||
class NoopAud0Client implements Aud0Client {
|
||||
async ingestEvent(_event: Aud0Event): Promise<void> {
|
||||
/* intentional no-op */
|
||||
}
|
||||
async ingestLineageEvent(_event: Aud0LineageEvent): Promise<void> {
|
||||
/* intentional no-op */
|
||||
}
|
||||
}
|
||||
|
||||
class HttpAud0Client implements Aud0Client {
|
||||
private readonly baseUrl: string;
|
||||
|
||||
constructor(baseUrl: string) {
|
||||
// Normalize so `${baseUrl}/v1/...` never produces a double slash.
|
||||
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
||||
}
|
||||
|
||||
async ingestEvent(event: Aud0Event): Promise<void> {
|
||||
await this.post("/v1/aud0/events", event);
|
||||
}
|
||||
|
||||
async ingestLineageEvent(event: Aud0LineageEvent): Promise<void> {
|
||||
await this.post("/v1/aud0/lineage/events", event);
|
||||
}
|
||||
|
||||
private async post(path: string, body: unknown): Promise<void> {
|
||||
const res = await fetch(`${this.baseUrl}${path}`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
if (!res.ok) {
|
||||
throw new Error(`AUD0 ${path} error: ${res.status} ${await res.text().catch(() => "")}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* src/clients/cl0ud-client.ts
|
||||
* ============================
|
||||
* 0pt's client for the CL0UD control-plane policy decision point:
|
||||
* evaluatePolicy -> POST {baseUrl}/v1/cl0ud/policies/evaluate
|
||||
*
|
||||
* Every side-effecting 0pt capability re-consults CL0UD before acting (per
|
||||
* docs/PRODUCT_PLAN.md §4.1), so this is the single choke point for that.
|
||||
*
|
||||
* Convention (identical to aud0-client.ts / n0d-client.ts / st0re-client.ts):
|
||||
* when no base URL is configured the client runs in LOCAL PASS-THROUGH mode —
|
||||
* it returns a deterministic `allow` decision WITHOUT any network call, so
|
||||
* unit tests and local dev are hermetic. This is a dev-mode default only; any
|
||||
* real deployment MUST set CL0UD_URL so decisions come from the real policy
|
||||
* engine. The pass-through never invents a `deny`/`approval_required` — it
|
||||
* only ever allows, and it stamps a clearly local-looking decision id.
|
||||
*/
|
||||
import crypto from "crypto";
|
||||
|
||||
export type PolicyDecision = "allow" | "deny" | "approval_required";
|
||||
|
||||
export interface EvaluatePolicyInput {
|
||||
tenant_id: string;
|
||||
project_id: string;
|
||||
actor_id: string;
|
||||
capability_id: string;
|
||||
resource_type: string;
|
||||
resource_id: string;
|
||||
/** Risk level L0–L5 per the SIAX Cloud risk taxonomy. */
|
||||
risk_level: string;
|
||||
correlation_id?: string;
|
||||
}
|
||||
|
||||
export interface PolicyResult {
|
||||
decision: PolicyDecision;
|
||||
decision_id: string;
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
export interface Cl0udClient {
|
||||
evaluatePolicy(input: EvaluatePolicyInput): Promise<PolicyResult>;
|
||||
}
|
||||
|
||||
export function createCl0udClient(baseUrl?: string): Cl0udClient {
|
||||
if (!baseUrl) return new LocalAllowCl0udClient();
|
||||
return new HttpCl0udClient(baseUrl);
|
||||
}
|
||||
|
||||
/** No CL0UD_URL configured: allow-only local pass-through (see module doc comment). */
|
||||
class LocalAllowCl0udClient implements Cl0udClient {
|
||||
async evaluatePolicy(_input: EvaluatePolicyInput): Promise<PolicyResult> {
|
||||
return { decision: "allow", decision_id: `pdec_local_${crypto.randomUUID()}` };
|
||||
}
|
||||
}
|
||||
|
||||
class HttpCl0udClient implements Cl0udClient {
|
||||
private readonly baseUrl: string;
|
||||
|
||||
constructor(baseUrl: string) {
|
||||
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
||||
}
|
||||
|
||||
async evaluatePolicy(input: EvaluatePolicyInput): Promise<PolicyResult> {
|
||||
const res = await fetch(`${this.baseUrl}/v1/cl0ud/policies/evaluate`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
if (!res.ok) {
|
||||
throw new Error(`CL0UD policy evaluate error: ${res.status} ${await res.text().catch(() => "")}`);
|
||||
}
|
||||
const body = (await res.json()) as Partial<PolicyResult>;
|
||||
return {
|
||||
decision: (body.decision ?? "deny") as PolicyDecision,
|
||||
decision_id: body.decision_id ?? `pdec_${crypto.randomUUID()}`,
|
||||
reason: body.reason,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* src/clients/n0d-client.ts
|
||||
* ==========================
|
||||
* 0pt's client for REQUESTING heavy compute jobs from N0D (the Compute OS).
|
||||
* 0pt never executes heavy work in-process — it submits an N0D job and holds
|
||||
* only the returned `job_id` (docs/11-lakehouse-write-plan.md item 7,
|
||||
* docs/P0_QUERY_SOURCE_FLOW.md):
|
||||
* createJob -> POST {baseUrl}/v1/n0d/jobs
|
||||
*
|
||||
* Convention (identical to aud0-client.ts / cl0ud-client.ts / st0re-client.ts
|
||||
* / st0re-lakehouse-client.ts): when no base URL is configured the client
|
||||
* returns a deterministic in-memory MOCK job (id prefixed "mock_job_") with
|
||||
* NO network call, so unit tests stay hermetic. A real deployment sets
|
||||
* N0D_URL to submit against the live scheduler.
|
||||
*/
|
||||
import crypto from "crypto";
|
||||
|
||||
export interface CreateJobInput {
|
||||
tenant_id: string;
|
||||
project_id: string;
|
||||
job_type: string;
|
||||
capability_id: string;
|
||||
requested_by_app_id: string;
|
||||
requested_by_actor_id: string;
|
||||
input_artifact_ids?: string[];
|
||||
input_dataset_ids?: string[];
|
||||
output_artifact_type: string;
|
||||
requires_backbone: boolean;
|
||||
requires_gpu: boolean;
|
||||
required_node_roles: string[];
|
||||
resource_profile: string;
|
||||
/** Risk level L0–L5 per the SIAX Cloud risk taxonomy. */
|
||||
risk_level: string;
|
||||
correlation_id?: string;
|
||||
}
|
||||
|
||||
export type N0dJobState = "queued" | "running" | "succeeded" | "failed" | "cancelled";
|
||||
|
||||
export interface N0dJob extends CreateJobInput {
|
||||
job_id: string;
|
||||
state: N0dJobState;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface N0dClient {
|
||||
createJob(input: CreateJobInput): Promise<N0dJob>;
|
||||
}
|
||||
|
||||
export function createN0dClient(baseUrl?: string): N0dClient {
|
||||
if (!baseUrl) return new MockN0dClient();
|
||||
return new HttpN0dClient(baseUrl);
|
||||
}
|
||||
|
||||
/** No N0D_URL configured: returns a deterministic mock job (see module doc comment). */
|
||||
class MockN0dClient implements N0dClient {
|
||||
async createJob(input: CreateJobInput): Promise<N0dJob> {
|
||||
return {
|
||||
...input,
|
||||
job_id: `mock_job_${crypto.randomUUID()}`,
|
||||
state: "queued",
|
||||
created_at: new Date().toISOString(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class HttpN0dClient implements N0dClient {
|
||||
private readonly baseUrl: string;
|
||||
|
||||
constructor(baseUrl: string) {
|
||||
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
||||
}
|
||||
|
||||
async createJob(input: CreateJobInput): Promise<N0dJob> {
|
||||
const res = await fetch(`${this.baseUrl}/v1/n0d/jobs`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
if (!res.ok) {
|
||||
throw new Error(`N0D create-job error: ${res.status} ${await res.text().catch(() => "")}`);
|
||||
}
|
||||
return (await res.json()) as N0dJob;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* src/clients/st0re-client.ts
|
||||
* ============================
|
||||
* 0pt's client for the generic ST0RE Artifact registry (snake_case wire
|
||||
* shape), distinct from `./st0re-lakehouse-client.ts` (the camelCase
|
||||
* /v1/st0re/lakehouse/* table registry). This one registers an artifact's
|
||||
* METADATA — a pointer to where the bytes live (provider/bucket/key/region)
|
||||
* plus content-type/size/checksum/retention/PII/residency:
|
||||
* createArtifact -> POST {baseUrl}/v1/st0re/artifacts
|
||||
*
|
||||
* KNOWN GAP (documented in src/adapters/local-blob-store.ts): ST0RE does not
|
||||
* yet expose a raw-bytes upload endpoint for 0pt to call, so the actual bytes
|
||||
* are persisted by LocalBlobStore (interim) and only the resulting location
|
||||
* is registered here as metadata.
|
||||
*
|
||||
* Convention (identical to aud0-client.ts / cl0ud-client.ts / n0d-client.ts /
|
||||
* st0re-lakehouse-client.ts): when no base URL is configured the client
|
||||
* returns a deterministic in-memory MOCK artifact (id prefixed
|
||||
* "mock_artifact_") with NO network call, so unit tests stay hermetic. A real
|
||||
* deployment sets ST0RE_URL to register against the live artifact registry.
|
||||
*/
|
||||
import crypto from "crypto";
|
||||
|
||||
export interface St0reObjectLocation {
|
||||
provider: string;
|
||||
bucket: string;
|
||||
key: string;
|
||||
region?: string;
|
||||
}
|
||||
|
||||
export interface CreateArtifactInput {
|
||||
tenant_id: string;
|
||||
project_id: string;
|
||||
artifact_type: string;
|
||||
app_id: string;
|
||||
produced_by: string;
|
||||
object_location: St0reObjectLocation;
|
||||
content_type: string;
|
||||
size_bytes: number;
|
||||
checksum_sha256: string;
|
||||
/** "none" | "low" | "medium" | "high" — kept as string to stay tolerant of ST0RE's own vocabulary. */
|
||||
pii_level: string;
|
||||
retention_policy: string;
|
||||
data_residency: string;
|
||||
/** Risk level L0–L5 per the SIAX Cloud risk taxonomy. */
|
||||
risk_level: string;
|
||||
correlation_id?: string;
|
||||
}
|
||||
|
||||
export interface St0reArtifact extends CreateArtifactInput {
|
||||
artifact_id: string;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface St0reClient {
|
||||
createArtifact(input: CreateArtifactInput): Promise<St0reArtifact>;
|
||||
}
|
||||
|
||||
export function createSt0reClient(baseUrl?: string): St0reClient {
|
||||
if (!baseUrl) return new MockSt0reClient();
|
||||
return new HttpSt0reClient(baseUrl);
|
||||
}
|
||||
|
||||
/** No ST0RE_URL configured: returns a deterministic mock artifact (see module doc comment). */
|
||||
class MockSt0reClient implements St0reClient {
|
||||
async createArtifact(input: CreateArtifactInput): Promise<St0reArtifact> {
|
||||
return {
|
||||
...input,
|
||||
artifact_id: `mock_artifact_${crypto.randomUUID()}`,
|
||||
created_at: new Date().toISOString(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class HttpSt0reClient implements St0reClient {
|
||||
private readonly baseUrl: string;
|
||||
|
||||
constructor(baseUrl: string) {
|
||||
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
||||
}
|
||||
|
||||
async createArtifact(input: CreateArtifactInput): Promise<St0reArtifact> {
|
||||
const res = await fetch(`${this.baseUrl}/v1/st0re/artifacts`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
if (!res.ok) {
|
||||
throw new Error(`ST0RE create-artifact error: ${res.status} ${await res.text().catch(() => "")}`);
|
||||
}
|
||||
return (await res.json()) as St0reArtifact;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user