mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-02 13:22:11 +03:00
* chore(release): open v3.8.18 development cycle * fix(catalog): stop Codex CLI model-catalog refresh from erroring (#3481) Codex's model-catalog refresh (codex_models_manager) does GET /v1/models?client_version=<v> and decodes a JSON object with a TOP-LEVEL `models` array. OmniRoute answers in the OpenAI-standard `{object,data}` shape, so codex fails with "missing field `models`" and logs "failed to refresh available models" on every startup. Detect codex clients via the `originator` / `user-agent` = `codex_*` headers they send and add an EMPTY top-level `models: []` so the decode succeeds. Non-codex OpenAI clients keep the byte-identical `{object,data}` response. The array is intentionally empty: codex replaces its built-in per-model agent prompt (`base_instructions`, ~21k chars) with whatever a populated entry carries for the selected model, so emitting our catalog would drop the agent prompt to nothing and break codex's agent behaviour (verified empirically against codex 0.137). An empty list keeps codex on its built-in model info — same inference as before, minus the error. Validated end-to-end with the real handler against codex 0.137: "failed to refresh available models" → 0 occurrences, instructions preserved (built-in Codex agent prompt, not empty). Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore: ignore quality reports and local prompt artifacts Add generated quality gate reports, metrics files, and local setup prompt artifacts to .gitignore to prevent committing environment-specific or temporary files. * fix(provider): detect Responses API format when body has `input` but … (#3490) Integrated into release/v3.8.18 * fix(sse): normalize numeric provider ids to strings (#3451) Integrated into release/v3.8.18 * feat(browserPool): resolve Playwright proxy from proxy_registry DB (#3492) Integrated into release/v3.8.18 * fix(theoldllm): generate X-Request-Token server-side, drop Playwright (#3491) Integrated into release/v3.8.18 * feat(plugins): add lifecycle hooks and theme-manager plugin (#3473) Integrated into release/v3.8.18 * fix(combo): parallel pre-screen + circuit-breaker fast-exit for priority combos (#3169) Integrated into release/v3.8.18 * feat(ui): unifi active and finished requests into single view #1422 (#3401) Integrated into release/v3.8.18 * docs(changelog): record #3401, #3473, #3492, #3490, #3451, #3491, #3169 under v3.8.18 * feat(docs): add doc accuracy gate + refresh AGENTS.md counts (#3510) Integrated into release/v3.8.18 * fix(sse): drop empty-choices chunks without usage instead of injecting retry text (#3513) PR #3422 ('allow OpenAI usage-only empty choices chunks') reintroduced the assistant-content injection '[OmniRoute] Upstream returned an empty response. Please retry.' for empty `choices: []` chunks that carry no valid usage. Clients (Goose/opencode) feed that text back as a turn and spin in a retry loop -- the exact regression #3400 had fixed by dropping the chunk. Restore the drop behavior for the no-usage case while preserving #3422's standards-compliant forwarding of usage-only `include_usage` final chunks. Realign the mislabeled stream-utils test (it asserted the injection) and add a dedicated regression guard. Reported-by: @mochizzan Refs: #3502, #3388, #3400, #3422 * fix(authz): fall back to URL token when Authorization isn't a usable Bearer (#3504) Integrated into release/v3.8.18 * fix(playground): authenticate via session, test key policy by id (#3503) Integrated into release/v3.8.18 * docs(changelog): record #3510, #3504, #3503 under v3.8.18 * fix: llama base url normalization (#3519) * docs(changelog): reconcile v3.8.18 — add #3519, #3513, #3435-repair, gitignore chore (full commit↔changelog coverage) * fix(opencode-plugin): bound regex quantifiers in normaliseFreeLabel (polynomial-ReDoS) CodeQL js/polynomial-redos: unbounded \s* before an anchored \s*$ allowed O(n²) backtracking on attacker-influenced display names. Bounded to {0,8}/{1,8} (ample for any real label spacing). Plugin builds + 254 tests green. * fix(types): restore clean typecheck:core for v3.8.18 release gate - getPendingRequests() typed to real shape (was widened to object) → fixes unknown 'count' in the unified-requests view (#3401) - streamChunks log payload cast to its declared type (callLogs.ts) - preScreenTargets aligned to canonical IsModelAvailable signature (#3169), Promise.resolve-normalized so .catch never hits a bare boolean All 5 gates green: lint(0 err) + typecheck:core + cycles + docs-all + unit + vitest(146). --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Andrey Borodulin <borodulin@gmail.com> Co-authored-by: Dmitrii Safronov <zimniy@cyberbrain.cc> Co-authored-by: Paijo <14921983+oyi77@users.noreply.github.com> Co-authored-by: PizzaV <103120356+pizzav-xyz@users.noreply.github.com> Co-authored-by: Markus Hartung <mail@hartmark.se> Co-authored-by: Felipe Almeman <4226997+zhiru@users.noreply.github.com>
214 lines
6.8 KiB
TypeScript
214 lines
6.8 KiB
TypeScript
/**
|
|
* Plugin manifest validator — Zod schema for plugin.json files.
|
|
*
|
|
* @module plugins/manifest
|
|
*/
|
|
|
|
import { z } from "zod";
|
|
|
|
// ── Permission enum ──
|
|
|
|
export const PermissionSchema = z.enum(["network", "file-read", "file-write", "env", "exec"]);
|
|
export type Permission = z.infer<typeof PermissionSchema>;
|
|
|
|
// ── Skill definition in manifest ──
|
|
|
|
export const ManifestSkillSchema = z.object({
|
|
name: z.string().min(1).max(100),
|
|
description: z.string().max(500).optional(),
|
|
input: z.record(z.string(), z.unknown()).optional(),
|
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
});
|
|
export type ManifestSkill = z.infer<typeof ManifestSkillSchema>;
|
|
|
|
// ── Config schema field ──
|
|
|
|
export const ConfigFieldSchema = z.object({
|
|
type: z.enum(["string", "number", "boolean", "select"]),
|
|
default: z.unknown().optional(),
|
|
min: z.number().optional(),
|
|
max: z.number().optional(),
|
|
enum: z.array(z.string()).optional(),
|
|
description: z.string().optional(),
|
|
});
|
|
export type ConfigField = z.infer<typeof ConfigFieldSchema>;
|
|
|
|
// ── Hooks ──
|
|
|
|
export const HooksSchema = z.object({
|
|
onRequest: z.boolean().optional(),
|
|
onResponse: z.boolean().optional(),
|
|
onError: z.boolean().optional(),
|
|
onInstall: z.boolean().optional(),
|
|
onActivate: z.boolean().optional(),
|
|
onDeactivate: z.boolean().optional(),
|
|
onUninstall: z.boolean().optional(),
|
|
});
|
|
|
|
// ── Requires ──
|
|
|
|
export const RequiresSchema = z.object({
|
|
omniroute: z.string().optional(),
|
|
permissions: z.array(PermissionSchema).optional(),
|
|
});
|
|
|
|
// ── Full manifest ──
|
|
|
|
export const PluginManifestSchema = z.object({
|
|
name: z
|
|
.string()
|
|
.min(1)
|
|
.max(100)
|
|
.regex(/^[a-z0-9-]+$/, "Name must be kebab-case (lowercase, hyphens only)"),
|
|
version: z.string().regex(/^\d+\.\d+\.\d+$/, "Version must be semver (e.g. 1.0.0)"),
|
|
description: z.string().max(500).optional(),
|
|
author: z.string().max(200).optional(),
|
|
license: z.string().optional(),
|
|
main: z.string().optional(),
|
|
source: z.enum(["local", "marketplace"]).optional(),
|
|
tags: z.array(z.string()).optional(),
|
|
requires: RequiresSchema.optional(),
|
|
hooks: HooksSchema.optional(),
|
|
skills: z.array(ManifestSkillSchema).optional(),
|
|
enabledByDefault: z.boolean().optional(),
|
|
configSchema: z.record(z.string(), ConfigFieldSchema).optional(),
|
|
/**
|
|
* OPT-IN tamper-detection: `sha256-<base64>` of the plugin's entry file.
|
|
*
|
|
* NOT a security boundary — loopback-only routing and exec opt-in are the real
|
|
* boundaries. Local-operator plugins without `integrity` are fully allowed (trust
|
|
* is implicit for locally installed code). When this field IS present, the loader
|
|
* verifies the entry file hash at load time and refuses to activate on mismatch.
|
|
*
|
|
* Format: `sha256-<base64url>` (same as SRI / W3C Subresource Integrity).
|
|
* Generate with: `node -e "const {createHash}=require('crypto'),{readFileSync}=require('fs');
|
|
* console.log('sha256-'+createHash('sha256').update(readFileSync('index.js')).digest('base64'))"`
|
|
*/
|
|
integrity: z.string().optional(),
|
|
});
|
|
|
|
export type PluginManifest = z.infer<typeof PluginManifestSchema>;
|
|
|
|
// ── Defaults applied after parsing ──
|
|
|
|
export interface PluginManifestWithDefaults extends PluginManifest {
|
|
license: string;
|
|
main: string;
|
|
source: "local" | "marketplace";
|
|
tags: string[];
|
|
requires: { omniroute?: string; permissions: Permission[] };
|
|
hooks: {
|
|
onRequest: boolean;
|
|
onResponse: boolean;
|
|
onError: boolean;
|
|
onInstall: boolean;
|
|
onActivate: boolean;
|
|
onDeactivate: boolean;
|
|
onUninstall: boolean;
|
|
};
|
|
skills: ManifestSkill[];
|
|
enabledByDefault: boolean;
|
|
configSchema: Record<string, ConfigField>;
|
|
}
|
|
|
|
export function applyDefaults(manifest: PluginManifest): PluginManifestWithDefaults {
|
|
return {
|
|
...manifest,
|
|
license: manifest.license ?? "MIT",
|
|
main: manifest.main ?? "index.js",
|
|
source: manifest.source ?? "local",
|
|
tags: manifest.tags ?? [],
|
|
requires: {
|
|
omniroute: manifest.requires?.omniroute,
|
|
permissions: manifest.requires?.permissions ?? [],
|
|
},
|
|
hooks: {
|
|
onRequest: manifest.hooks?.onRequest ?? false,
|
|
onResponse: manifest.hooks?.onResponse ?? false,
|
|
onError: manifest.hooks?.onError ?? false,
|
|
onInstall: manifest.hooks?.onInstall ?? false,
|
|
onActivate: manifest.hooks?.onActivate ?? false,
|
|
onDeactivate: manifest.hooks?.onDeactivate ?? false,
|
|
onUninstall: manifest.hooks?.onUninstall ?? false,
|
|
},
|
|
skills: manifest.skills ?? [],
|
|
enabledByDefault: manifest.enabledByDefault ?? false,
|
|
configSchema: manifest.configSchema ?? {},
|
|
};
|
|
}
|
|
|
|
// ── Validation ──
|
|
|
|
export function validateManifest(raw: unknown): PluginManifestWithDefaults {
|
|
const parsed = PluginManifestSchema.parse(raw);
|
|
return applyDefaults(parsed);
|
|
}
|
|
|
|
export function safeValidateManifest(
|
|
raw: unknown
|
|
): { success: true; data: PluginManifestWithDefaults } | { success: false; errors: string[] } {
|
|
const result = PluginManifestSchema.safeParse(raw);
|
|
if (result.success) {
|
|
return { success: true, data: applyDefaults(result.data) };
|
|
}
|
|
return {
|
|
success: false,
|
|
errors: result.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`),
|
|
};
|
|
}
|
|
|
|
// ── Config validation ──
|
|
|
|
export type ValidatePluginConfigResult =
|
|
| { valid: true }
|
|
| { valid: false; errors: string[] };
|
|
|
|
/**
|
|
* Validate a config object against a ConfigField schema map.
|
|
* Only provided keys are validated — missing keys are fine (use defaults).
|
|
*/
|
|
export function validatePluginConfig(
|
|
config: Record<string, unknown>,
|
|
schema: Record<string, ConfigField>
|
|
): ValidatePluginConfigResult {
|
|
const errors: string[] = [];
|
|
|
|
// If schema is empty, allow anything
|
|
const hasSchema = Object.keys(schema).length > 0;
|
|
if (!hasSchema) return { valid: true };
|
|
|
|
for (const [key, value] of Object.entries(config)) {
|
|
const field = schema[key];
|
|
if (!field) {
|
|
errors.push(`Unknown config key: ${key}`);
|
|
continue;
|
|
}
|
|
|
|
switch (field.type) {
|
|
case "string":
|
|
if (typeof value !== "string") errors.push(`${key} must be a string`);
|
|
break;
|
|
case "number":
|
|
if (typeof value !== "number") {
|
|
errors.push(`${key} must be a number`);
|
|
} else {
|
|
if (field.min !== undefined && value < field.min)
|
|
errors.push(`${key} must be >= ${field.min}`);
|
|
if (field.max !== undefined && value > field.max)
|
|
errors.push(`${key} must be <= ${field.max}`);
|
|
}
|
|
break;
|
|
case "boolean":
|
|
if (typeof value !== "boolean") errors.push(`${key} must be a boolean`);
|
|
break;
|
|
case "select":
|
|
if (!field.enum || !field.enum.includes(value as string))
|
|
errors.push(`${key} must be one of: ${(field.enum ?? []).join(", ")}`);
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (errors.length > 0) return { valid: false, errors };
|
|
return { valid: true };
|
|
}
|