//native
// Execute a specific Strale capability by slug.
// Calls a single quality-tested data capability and returns structured results
// with provenance, audit trail, and quality metadata.
//
// Strale is the data layer for AI agents — every data source independently
// quality-tested, scored, and audit-logged. https://strale.dev
type Strale = {
api_key: string;
base_url?: string;
};
export async function main(
strale: Strale,
capability_slug: string,
inputs: Record<string, unknown>,
dry_run: boolean = false,
) {
const baseUrl = strale.base_url ?? "https://api.strale.io";
const body: Record<string, unknown> = {
capability_slug,
inputs,
};
if (dry_run) {
body.dry_run = true;
}
const response = await fetch(`${baseUrl}/v1/do`, {
method: "POST",
headers: {
"Authorization": `Bearer ${strale.api_key}`,
"Content-Type": "application/json",
},
body: JSON.stringify(body),
});
if (!response.ok) {
const error = await response.json().catch(() => ({ message: response.statusText }));
throw new Error(
`Strale API error (${response.status}): ${(error as any).error?.message ?? (error as any).message ?? "Unknown error"}`
);
}
const data = await response.json() as {
transaction_id?: string;
capability_slug: string;
status: string;
output?: Record<string, unknown>;
provenance?: Record<string, unknown>;
quality?: Record<string, unknown>;
cost_cents?: number;
wallet_balance_cents?: number;
dry_run?: boolean;
};
return {
transaction_id: data.transaction_id,
capability: data.capability_slug,
status: data.status,
output: data.output,
provenance: data.provenance,
quality: data.quality,
cost: data.cost_cents != null ? `€${(data.cost_cents / 100).toFixed(2)}` : undefined,
wallet_balance_cents: data.wallet_balance_cents,
dry_run: data.dry_run,
};
}Submitted by hugo989 7 days ago