pantheon-opencode 1.6.2-beta.3 → 1.6.2-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -0
- package/README.md +209 -1
- package/bin/pantheon-init.mjs +22 -0
- package/package.json +9 -3
- package/plugin.json +1 -1
- package/pyproject.toml +1 -1
- package/scripts/decision-router-budget.mjs +781 -0
- package/scripts/decision-router-v2-budget.mjs +218 -0
- package/scripts/decision-router-v2-egress.mjs +272 -0
- package/scripts/decision-router.mjs +519 -0
- package/scripts/docs-check-changelog.mjs +5 -3
- package/scripts/install/decision-layer-preview.mjs +376 -0
- package/scripts/install/decision-router-config.mjs +579 -0
- package/scripts/install/interactive.mjs +76 -5
- package/scripts/install/opencode.mjs +12 -0
- package/scripts/install/state.mjs +5 -0
- package/scripts/install/strings.mjs +4 -0
- package/scripts/mcp_resources.py +11 -9
- package/scripts/release-notes.mjs +30 -7
- package/scripts/versioning.mjs +41 -5
- package/src/agents/zeus.md +12 -0
- package/src/mcp/eval_store.py +11 -4
- package/src/mcp/mcp_resources.py +11 -9
- package/src/mcp/memory_mcp.py +293 -150
- package/src/pantheon/local-decision-agents.ts +170 -0
- package/src/pantheon/local-decision-budget.ts +1043 -0
- package/src/pantheon/local-decision-egress-gate.ts +264 -0
- package/src/pantheon/local-decision-prompt.ts +268 -0
- package/src/pantheon/local-decision-provider-matrix.ts +92 -0
- package/src/pantheon/local-decision-provider-protocol.ts +335 -0
- package/src/pantheon/local-decision-provider.internal.ts +260 -0
- package/src/pantheon/local-decision-router.ts +225 -0
- package/src/pantheon/local-decision-skills.ts +281 -0
- package/src/pantheon/local-decision-tool.ts +160 -0
- package/src/pantheon/local-decision-turn.ts +338 -0
- package/src/pantheon/local-decision-usage-evidence.internal.ts +207 -0
- package/src/pantheon/local-orchestration.ts +322 -0
- package/src/pantheon/pantheon-decision-catalog.ts +101 -0
- package/src/pantheon/v2-decision-budget.ts +456 -0
- package/src/pantheon/v2-decision-contracts.ts +300 -0
- package/src/pantheon/v2-decision-egress.ts +203 -0
- package/src/pantheon/v2-decision-events.ts +180 -0
- package/src/pantheon/v2-decision-heuristic.ts +121 -0
- package/src/pantheon/v2-decision-points/p1-agent.ts +91 -0
- package/src/pantheon/v2-decision-points/p10-claims.ts +243 -0
- package/src/pantheon/v2-decision-points/p11-catalog.ts +220 -0
- package/src/pantheon/v2-decision-points/p2-skill.ts +83 -0
- package/src/pantheon/v2-decision-points/p3-complexity.ts +108 -0
- package/src/pantheon/v2-decision-points/p4-memory.ts +137 -0
- package/src/pantheon/v2-decision-points/p5-themis-verify.ts +190 -0
- package/src/pantheon/v2-decision-points/p6-council.ts +161 -0
- package/src/pantheon/v2-decision-points/p7-loop.ts +263 -0
- package/src/pantheon/v2-decision-points/p8-guardrail.ts +366 -0
- package/src/pantheon/v2-decision-points/p9-memory-compaction.ts +304 -0
- package/src/pantheon/v2-decision-points.ts +242 -0
- package/src/pantheon/v2-decision-policy.ts +166 -0
- package/src/pantheon/v2-decision-premises.ts +146 -0
- package/src/pantheon/v2-decision-prompt-surface.ts +115 -0
- package/src/pantheon/v2-decision-rank.ts +91 -0
- package/src/pantheon/v2-decision-registry.ts +391 -0
- package/src/pantheon/v2-decision-resource-ids.ts +127 -0
- package/src/pantheon/v2-decision-shadow.ts +123 -0
- package/src/pantheon/v2-decision-telemetry.ts +214 -0
- package/src/pantheon/v2-decision-verify.ts +51 -0
- package/src/pantheon/v2-tools.ts +35 -15
- package/src/plugin-v2.ts +357 -22
- package/src/plugin.ts +4 -0
- package/src/plugins/tui/dist/tui-v2.js +3 -3
- package/src/plugins/tui/dist/tui.js +1 -1
- package/src/plugins/tui/package-lock.json +2 -2
- package/src/plugins/tui/package.json +1 -1
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// Generated by scripts/build-decision-router.mjs. The published CLI cannot
|
|
2
|
+
// import TypeScript from node_modules, so it imports this prebuilt ESM bundle
|
|
3
|
+
// instead. Do not edit: run `npm run build:decision-router`.
|
|
4
|
+
|
|
5
|
+
// src/pantheon/v2-decision-budget.ts
|
|
6
|
+
import { lstatSync } from "node:fs";
|
|
7
|
+
import { DatabaseSync } from "node:sqlite";
|
|
8
|
+
function isPositiveCaps(value) {
|
|
9
|
+
return value !== void 0 && Number.isSafeInteger(value.monthlyCapMicros) && Number.isSafeInteger(value.perDecisionCapMicros) && value.monthlyCapMicros > 0 && value.perDecisionCapMicros > 0;
|
|
10
|
+
}
|
|
11
|
+
function evaluateCapGate(input) {
|
|
12
|
+
const { user, provider, model } = input;
|
|
13
|
+
for (const caps of [user, provider, model]) {
|
|
14
|
+
if (caps === void 0) continue;
|
|
15
|
+
if (!Number.isSafeInteger(caps.monthlyCapMicros) || !Number.isSafeInteger(caps.perDecisionCapMicros) || caps.monthlyCapMicros < 0 || caps.perDecisionCapMicros < 0) {
|
|
16
|
+
return { concern: "cap", ok: false, reason: "invalid-caps" };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (!isPositiveCaps(user) || !isPositiveCaps(provider) || !isPositiveCaps(model)) {
|
|
20
|
+
return { concern: "cap", ok: false, reason: "no-cap" };
|
|
21
|
+
}
|
|
22
|
+
const reservedMicros = model.perDecisionCapMicros;
|
|
23
|
+
if (reservedMicros > user.perDecisionCapMicros || reservedMicros > provider.perDecisionCapMicros) {
|
|
24
|
+
return { concern: "cap", ok: false, reason: "per-decision-cap" };
|
|
25
|
+
}
|
|
26
|
+
return { concern: "cap", ok: true, reservedMicros };
|
|
27
|
+
}
|
|
28
|
+
var PERIOD_PATTERN = /^\d{4}-(0[1-9]|1[0-2])$/;
|
|
29
|
+
function utcPeriodOf(instantMs) {
|
|
30
|
+
if (!Number.isSafeInteger(instantMs) || instantMs < 0) return null;
|
|
31
|
+
const period = new Date(instantMs).toISOString().slice(0, 7);
|
|
32
|
+
return PERIOD_PATTERN.test(period) ? period : null;
|
|
33
|
+
}
|
|
34
|
+
function evaluatePeriodGate(input) {
|
|
35
|
+
if (input.wallPeriod === null || !PERIOD_PATTERN.test(input.wallPeriod)) {
|
|
36
|
+
return { concern: "period", ok: false, reason: "invalid-period" };
|
|
37
|
+
}
|
|
38
|
+
if (input.activePeriod === null) {
|
|
39
|
+
return { concern: "period", ok: false, reason: "period-unconfirmed" };
|
|
40
|
+
}
|
|
41
|
+
if (!PERIOD_PATTERN.test(input.activePeriod)) {
|
|
42
|
+
return { concern: "period", ok: false, reason: "invalid-period" };
|
|
43
|
+
}
|
|
44
|
+
if (input.activePeriod !== input.wallPeriod) {
|
|
45
|
+
return { concern: "period", ok: false, reason: "period-mismatch" };
|
|
46
|
+
}
|
|
47
|
+
return { concern: "period", ok: true, period: input.activePeriod };
|
|
48
|
+
}
|
|
49
|
+
function evaluateLedgerGate(input) {
|
|
50
|
+
if (!input.present) return { concern: "ledger", ok: false, reason: "ledger-missing" };
|
|
51
|
+
if (input.frozen) return { concern: "ledger", ok: false, reason: "frozen" };
|
|
52
|
+
const additional = input.reservedMicros;
|
|
53
|
+
const exceeds = (committed, cap) => committed > cap || additional > cap - committed;
|
|
54
|
+
if (exceeds(input.userCommittedMicros, input.userMonthlyCapMicros) || exceeds(input.providerCommittedMicros, input.providerMonthlyCapMicros) || exceeds(input.modelCommittedMicros, input.modelMonthlyCapMicros)) {
|
|
55
|
+
return { concern: "ledger", ok: false, reason: "monthly-cap" };
|
|
56
|
+
}
|
|
57
|
+
return { concern: "ledger", ok: true };
|
|
58
|
+
}
|
|
59
|
+
function evaluateDecisionBudgetAdmission(input) {
|
|
60
|
+
const cap = evaluateCapGate(input.caps);
|
|
61
|
+
if (!cap.ok) return { admitted: false, concern: cap.concern, reason: cap.reason };
|
|
62
|
+
const period = evaluatePeriodGate(input.period);
|
|
63
|
+
if (!period.ok) return { admitted: false, concern: period.concern, reason: period.reason };
|
|
64
|
+
const ledger = evaluateLedgerGate({
|
|
65
|
+
...input.ledger,
|
|
66
|
+
present: true,
|
|
67
|
+
reservedMicros: cap.reservedMicros
|
|
68
|
+
});
|
|
69
|
+
if (!ledger.ok) return { admitted: false, concern: ledger.concern, reason: ledger.reason };
|
|
70
|
+
return { admitted: true, period: period.period, reservedMicros: cap.reservedMicros };
|
|
71
|
+
}
|
|
72
|
+
var EXPECTED_APPLICATION_ID = 1346522161;
|
|
73
|
+
function classifyDbPath(dbPath) {
|
|
74
|
+
try {
|
|
75
|
+
const stat = lstatSync(dbPath);
|
|
76
|
+
return stat.isFile() && !stat.isSymbolicLink() ? "regular" : "unsafe";
|
|
77
|
+
} catch {
|
|
78
|
+
return "missing";
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function readCapsRow(db, sql) {
|
|
82
|
+
const row = db.prepare(sql).get();
|
|
83
|
+
if (!row) return null;
|
|
84
|
+
return {
|
|
85
|
+
monthly: Number(row.monthly_cap_micros),
|
|
86
|
+
perDecision: Number(row.per_decision_cap_micros)
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function readDecisionBudgetLedgerFacts(dbPath) {
|
|
90
|
+
const kind = classifyDbPath(dbPath);
|
|
91
|
+
if (kind === "missing") return { present: false };
|
|
92
|
+
if (kind === "unsafe") {
|
|
93
|
+
return { present: true, readable: false, reason: "not-a-regular-file" };
|
|
94
|
+
}
|
|
95
|
+
let db;
|
|
96
|
+
try {
|
|
97
|
+
db = new DatabaseSync(dbPath, { readOnly: true });
|
|
98
|
+
} catch {
|
|
99
|
+
return { present: true, readable: false, reason: "unsupported-schema" };
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const version = db.prepare("PRAGMA user_version").get().user_version;
|
|
103
|
+
const applicationId = db.prepare("PRAGMA application_id").get().application_id;
|
|
104
|
+
if (applicationId !== EXPECTED_APPLICATION_ID || version !== 3) {
|
|
105
|
+
return { present: true, readable: false, reason: "unsupported-schema" };
|
|
106
|
+
}
|
|
107
|
+
const activeRow = db.prepare("SELECT active_period_utc FROM ledger_state WHERE id = 1").get();
|
|
108
|
+
const counts = db.prepare(
|
|
109
|
+
`SELECT
|
|
110
|
+
COUNT(*) AS reservations,
|
|
111
|
+
COALESCE(SUM(CASE WHEN state IN ('pending', 'uncertain') THEN 1 ELSE 0 END), 0) AS holds
|
|
112
|
+
FROM reservations`
|
|
113
|
+
).get();
|
|
114
|
+
const freezes = db.prepare("SELECT COUNT(*) AS total FROM budget_freezes").get();
|
|
115
|
+
return {
|
|
116
|
+
present: true,
|
|
117
|
+
readable: true,
|
|
118
|
+
schemaVersion: version,
|
|
119
|
+
applicationId,
|
|
120
|
+
activePeriod: activeRow?.active_period_utc ?? null,
|
|
121
|
+
reservations: Number(counts.reservations),
|
|
122
|
+
holds: Number(counts.holds),
|
|
123
|
+
freezes: Number(freezes.total)
|
|
124
|
+
};
|
|
125
|
+
} catch {
|
|
126
|
+
return { present: true, readable: false, reason: "unsupported-schema" };
|
|
127
|
+
} finally {
|
|
128
|
+
db.close();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function readDecisionCapFacts(dbPath) {
|
|
132
|
+
if (classifyDbPath(dbPath) !== "regular") return null;
|
|
133
|
+
let db;
|
|
134
|
+
try {
|
|
135
|
+
db = new DatabaseSync(dbPath, { readOnly: true });
|
|
136
|
+
} catch {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
const user = readCapsRow(
|
|
141
|
+
db,
|
|
142
|
+
"SELECT monthly_cap_micros, per_decision_cap_micros FROM user_caps WHERE id = 1"
|
|
143
|
+
);
|
|
144
|
+
const providers = {};
|
|
145
|
+
for (const row of db.prepare("SELECT provider, monthly_cap_micros, per_decision_cap_micros FROM provider_caps").all()) {
|
|
146
|
+
providers[row.provider] = {
|
|
147
|
+
monthlyCapMicros: Number(row.monthly_cap_micros),
|
|
148
|
+
perDecisionCapMicros: Number(row.per_decision_cap_micros)
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const models = {};
|
|
152
|
+
for (const row of db.prepare(
|
|
153
|
+
"SELECT provider, model, monthly_cap_micros, per_decision_cap_micros FROM model_caps"
|
|
154
|
+
).all()) {
|
|
155
|
+
models[`${row.provider}/${row.model}`] = {
|
|
156
|
+
monthlyCapMicros: Number(row.monthly_cap_micros),
|
|
157
|
+
perDecisionCapMicros: Number(row.per_decision_cap_micros)
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
user: user === null ? null : { monthlyCapMicros: user.monthly, perDecisionCapMicros: user.perDecision },
|
|
162
|
+
providers,
|
|
163
|
+
models
|
|
164
|
+
};
|
|
165
|
+
} catch {
|
|
166
|
+
return null;
|
|
167
|
+
} finally {
|
|
168
|
+
db.close();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function inspectDecisionBudget(dbPath) {
|
|
172
|
+
const ledger = readDecisionBudgetLedgerFacts(dbPath);
|
|
173
|
+
const caps = readDecisionCapFacts(dbPath);
|
|
174
|
+
const activePeriod = ledger.present && ledger.readable ? ledger.activePeriod : null;
|
|
175
|
+
return { ledger, caps, period: { activePeriod } };
|
|
176
|
+
}
|
|
177
|
+
function listDecisionHoldsReadOnly(dbPath) {
|
|
178
|
+
if (classifyDbPath(dbPath) !== "regular") return null;
|
|
179
|
+
let db;
|
|
180
|
+
try {
|
|
181
|
+
db = new DatabaseSync(dbPath, { readOnly: true });
|
|
182
|
+
} catch {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
const applicationId = db.prepare("PRAGMA application_id").get().application_id;
|
|
187
|
+
const version = db.prepare("PRAGMA user_version").get().user_version;
|
|
188
|
+
if (applicationId !== EXPECTED_APPLICATION_ID || version !== 3) return null;
|
|
189
|
+
const rows = db.prepare(
|
|
190
|
+
`SELECT id, provider, model, period_utc, reserved_micros, state
|
|
191
|
+
FROM reservations WHERE state IN ('pending', 'uncertain')
|
|
192
|
+
ORDER BY created_at_ms, id`
|
|
193
|
+
).all();
|
|
194
|
+
return rows.map((row) => ({
|
|
195
|
+
reservationId: row.id,
|
|
196
|
+
provider: row.provider,
|
|
197
|
+
model: row.model,
|
|
198
|
+
period: row.period_utc,
|
|
199
|
+
reservedMicros: Number(row.reserved_micros),
|
|
200
|
+
state: row.state
|
|
201
|
+
}));
|
|
202
|
+
} catch {
|
|
203
|
+
return null;
|
|
204
|
+
} finally {
|
|
205
|
+
db.close();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
export {
|
|
209
|
+
evaluateCapGate,
|
|
210
|
+
evaluateDecisionBudgetAdmission,
|
|
211
|
+
evaluateLedgerGate,
|
|
212
|
+
evaluatePeriodGate,
|
|
213
|
+
inspectDecisionBudget,
|
|
214
|
+
listDecisionHoldsReadOnly,
|
|
215
|
+
readDecisionBudgetLedgerFacts,
|
|
216
|
+
readDecisionCapFacts,
|
|
217
|
+
utcPeriodOf
|
|
218
|
+
};
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
// Generated by scripts/build-decision-router.mjs. The published CLI cannot
|
|
2
|
+
// import TypeScript from node_modules, so it imports this prebuilt ESM bundle
|
|
3
|
+
// instead. Do not edit: run `npm run build:decision-router`.
|
|
4
|
+
|
|
5
|
+
// scripts/install/decision-router-config.mjs
|
|
6
|
+
var DECISION_ROUTER_CONFIG_SCHEMA_VERSION = 1;
|
|
7
|
+
var DECISION_ROUTER_PROVIDERS = Object.freeze(["local", "openai-decisions", "jev", "auto"]);
|
|
8
|
+
var DEFAULT_DECISION_ROUTER_CONFIG = Object.freeze({
|
|
9
|
+
schema_version: DECISION_ROUTER_CONFIG_SCHEMA_VERSION,
|
|
10
|
+
provider: "local",
|
|
11
|
+
egress_consent: false
|
|
12
|
+
});
|
|
13
|
+
var DECISION_ROUTER_MODELS = Object.freeze({
|
|
14
|
+
"openai-decisions": Object.freeze(["gpt-6-luna"]),
|
|
15
|
+
"typesafe-jev": Object.freeze(["jev-1.14.0"]),
|
|
16
|
+
"opencode-console-jev": Object.freeze(["jev-1.13"]),
|
|
17
|
+
"opencode-console-jev-free": Object.freeze(["jev-1.13-free"])
|
|
18
|
+
});
|
|
19
|
+
var DECISION_PROVIDER_BUDGET_MAPPING = Object.freeze({
|
|
20
|
+
"openai-decisions": "openai-decisions",
|
|
21
|
+
"typesafe-jev": "typesafe-jev",
|
|
22
|
+
"opencode-console-jev": "opencode-console",
|
|
23
|
+
"opencode-console-jev-free": "jev-free"
|
|
24
|
+
});
|
|
25
|
+
var REMOTELY_ELIGIBLE_DECISION_PROVIDERS = Object.freeze([
|
|
26
|
+
"openai-decisions",
|
|
27
|
+
"typesafe-jev"
|
|
28
|
+
]);
|
|
29
|
+
var USER_DECISION_ROUTER_CONFIG_SCHEMA_VERSION = 2;
|
|
30
|
+
var DEFAULT_USER_DECISION_ROUTER_CONFIG = Object.freeze({
|
|
31
|
+
schema_version: USER_DECISION_ROUTER_CONFIG_SCHEMA_VERSION,
|
|
32
|
+
enabled: false,
|
|
33
|
+
selection: Object.freeze({ mode: "local" }),
|
|
34
|
+
egress_consent: false,
|
|
35
|
+
enabled_candidates: Object.freeze([])
|
|
36
|
+
});
|
|
37
|
+
var LEGACY_PROVIDER_ALIASES = Object.freeze({ jev: "typesafe-jev" });
|
|
38
|
+
var userCandidateProviders = new Set(Object.keys(DECISION_ROUTER_MODELS));
|
|
39
|
+
var remotelyEligibleProviders = new Set(REMOTELY_ELIGIBLE_DECISION_PROVIDERS);
|
|
40
|
+
var USER_CONFIG_KEYS = [
|
|
41
|
+
"egress_consent",
|
|
42
|
+
"enabled",
|
|
43
|
+
"enabled_candidates",
|
|
44
|
+
"schema_version",
|
|
45
|
+
"selection"
|
|
46
|
+
];
|
|
47
|
+
var LEGACY_USER_CONFIG_KEYS = [
|
|
48
|
+
"egress_consent",
|
|
49
|
+
"enabled_candidates",
|
|
50
|
+
"schema_version",
|
|
51
|
+
"selection"
|
|
52
|
+
];
|
|
53
|
+
var ACCEPTED_INSTALL_STATE_PROVIDERS = /* @__PURE__ */ new Set([...DECISION_ROUTER_PROVIDERS, "typesafe-jev"]);
|
|
54
|
+
function normalizeDecisionProviderId(provider) {
|
|
55
|
+
if (typeof provider !== "string") return provider;
|
|
56
|
+
return LEGACY_PROVIDER_ALIASES[provider] ?? provider;
|
|
57
|
+
}
|
|
58
|
+
function migrateUserDecisionRouterConfig(value) {
|
|
59
|
+
if (!isPlainObject(value)) return cloneDefaultUserConfig();
|
|
60
|
+
if (value.schema_version === 1) return migrateLegacyUserConfig(value);
|
|
61
|
+
if (value.schema_version !== USER_DECISION_ROUTER_CONFIG_SCHEMA_VERSION) {
|
|
62
|
+
return cloneDefaultUserConfig();
|
|
63
|
+
}
|
|
64
|
+
if (!hasExactKeys(value, USER_CONFIG_KEYS) || typeof value.egress_consent !== "boolean" || typeof value.enabled !== "boolean" || !Array.isArray(value.enabled_candidates)) {
|
|
65
|
+
return cloneDefaultUserConfig();
|
|
66
|
+
}
|
|
67
|
+
const selection = normalizeSelection(value.selection);
|
|
68
|
+
const candidates = normalizeEnabledCandidates(value.enabled_candidates);
|
|
69
|
+
if (selection === null || candidates === null) return cloneDefaultUserConfig();
|
|
70
|
+
return {
|
|
71
|
+
schema_version: USER_DECISION_ROUTER_CONFIG_SCHEMA_VERSION,
|
|
72
|
+
enabled: value.enabled,
|
|
73
|
+
selection,
|
|
74
|
+
egress_consent: selection.mode === "local" ? false : value.egress_consent,
|
|
75
|
+
enabled_candidates: candidates
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function migrateLegacyUserConfig(value) {
|
|
79
|
+
if (!hasExactKeys(value, LEGACY_USER_CONFIG_KEYS) || typeof value.egress_consent !== "boolean" || !Array.isArray(value.enabled_candidates)) {
|
|
80
|
+
return cloneDefaultUserConfig();
|
|
81
|
+
}
|
|
82
|
+
const selection = normalizeSelection(value.selection);
|
|
83
|
+
const candidates = normalizeEnabledCandidates(value.enabled_candidates);
|
|
84
|
+
if (selection === null || candidates === null) return cloneDefaultUserConfig();
|
|
85
|
+
const egressConsent = selection.mode === "local" ? false : value.egress_consent;
|
|
86
|
+
return {
|
|
87
|
+
schema_version: USER_DECISION_ROUTER_CONFIG_SCHEMA_VERSION,
|
|
88
|
+
enabled: selection.mode !== "local" && egressConsent && candidates.length > 0,
|
|
89
|
+
selection,
|
|
90
|
+
egress_consent: egressConsent,
|
|
91
|
+
enabled_candidates: candidates
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function eligibleAutoCandidates(preference, capValidCandidates) {
|
|
95
|
+
const validKeys = new Set(
|
|
96
|
+
capValidCandidates.filter(isKnownCandidate).map(({ provider, model }) => candidateKey(normalizeDecisionProviderId(provider), model))
|
|
97
|
+
);
|
|
98
|
+
return preference.enabled_candidates.filter(
|
|
99
|
+
(candidate) => remotelyEligibleProviders.has(candidate.provider) && validKeys.has(candidateKey(candidate.provider, candidate.model))
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
function explainUserDecisionRouterAutoSelection(config, capValidCandidates = []) {
|
|
103
|
+
const preference = migrateUserDecisionRouterConfig(config);
|
|
104
|
+
if (!preference.enabled) return { outcome: "ineligible", reason: "DISABLED" };
|
|
105
|
+
if (!preference.egress_consent) return { outcome: "ineligible", reason: "CONSENT_MISSING" };
|
|
106
|
+
if (preference.selection.mode !== "auto") return { outcome: "ineligible", reason: "NOT_AUTO" };
|
|
107
|
+
const eligible = eligibleAutoCandidates(preference, capValidCandidates);
|
|
108
|
+
if (eligible.length === 0) {
|
|
109
|
+
return { outcome: "none", reason: "NO_ELIGIBLE_CANDIDATE", count: 0 };
|
|
110
|
+
}
|
|
111
|
+
if (eligible.length > 1) {
|
|
112
|
+
return {
|
|
113
|
+
outcome: "ambiguous",
|
|
114
|
+
reason: "MULTIPLE_ELIGIBLE_CANDIDATES",
|
|
115
|
+
count: eligible.length
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
outcome: "single",
|
|
120
|
+
reason: "SINGLE_ELIGIBLE_CANDIDATE",
|
|
121
|
+
count: 1,
|
|
122
|
+
candidate: eligible[0]
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function normalizeSelection(value) {
|
|
126
|
+
if (!isPlainObject(value) || typeof value.mode !== "string") return null;
|
|
127
|
+
if (value.mode === "local" || value.mode === "auto") {
|
|
128
|
+
return Object.keys(value).length === 1 ? { mode: value.mode } : null;
|
|
129
|
+
}
|
|
130
|
+
if (value.mode !== "explicit" || Object.keys(value).length !== 3 || !isKnownCandidate({ provider: value.provider, model: value.model })) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
mode: "explicit",
|
|
135
|
+
provider: normalizeDecisionProviderId(value.provider),
|
|
136
|
+
model: value.model
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function normalizeEnabledCandidates(value) {
|
|
140
|
+
const seen = /* @__PURE__ */ new Set();
|
|
141
|
+
const result = [];
|
|
142
|
+
for (const item of value) {
|
|
143
|
+
if (!isKnownCandidate(item) || Object.keys(item).length !== 2) return null;
|
|
144
|
+
const provider = normalizeDecisionProviderId(item.provider);
|
|
145
|
+
const key = candidateKey(provider, item.model);
|
|
146
|
+
if (seen.has(key)) return null;
|
|
147
|
+
seen.add(key);
|
|
148
|
+
result.push({ provider, model: item.model });
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
function isKnownCandidate(value) {
|
|
153
|
+
if (!isPlainObject(value) || typeof value.provider !== "string" || typeof value.model !== "string") {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
const provider = normalizeDecisionProviderId(value.provider);
|
|
157
|
+
return userCandidateProviders.has(provider) && DECISION_ROUTER_MODELS[provider].includes(value.model);
|
|
158
|
+
}
|
|
159
|
+
function candidateKey(provider, model) {
|
|
160
|
+
return `${provider}/${model}`;
|
|
161
|
+
}
|
|
162
|
+
function isPlainObject(value) {
|
|
163
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
164
|
+
const prototype = Object.getPrototypeOf(value);
|
|
165
|
+
return prototype === Object.prototype || prototype === null;
|
|
166
|
+
}
|
|
167
|
+
function hasExactKeys(value, keys) {
|
|
168
|
+
const actual = Object.keys(value).sort();
|
|
169
|
+
const expected = [...keys].sort();
|
|
170
|
+
return actual.length === expected.length && actual.every((key, index) => key === expected[index]);
|
|
171
|
+
}
|
|
172
|
+
function cloneDefaultUserConfig() {
|
|
173
|
+
return {
|
|
174
|
+
schema_version: DEFAULT_USER_DECISION_ROUTER_CONFIG.schema_version,
|
|
175
|
+
enabled: false,
|
|
176
|
+
selection: { mode: "local" },
|
|
177
|
+
egress_consent: false,
|
|
178
|
+
enabled_candidates: []
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// src/pantheon/v2-decision-egress.ts
|
|
183
|
+
var V2_DECISION_EGRESS_DEFAULT = "off";
|
|
184
|
+
var DECLARED_EGRESS_ENDPOINTS = Object.freeze([
|
|
185
|
+
{ url: "https://api.openai.com/v1/decisions", wireStatus: "unwired" },
|
|
186
|
+
{ url: "https://api.typesafe.ai/v1/systemone", wireStatus: "unwired" },
|
|
187
|
+
{ url: "https://opencode.ai/inference/systemone/v1/systemone", wireStatus: "unwired" }
|
|
188
|
+
]);
|
|
189
|
+
var V2_DECISION_EGRESS_EXERCISED_PATHS = Object.freeze([]);
|
|
190
|
+
var V2_DECISION_EGRESS_ENDPOINT_WIRE_STATUS = Object.freeze(
|
|
191
|
+
Object.fromEntries(DECLARED_EGRESS_ENDPOINTS.map(({ url, wireStatus }) => [url, wireStatus]))
|
|
192
|
+
);
|
|
193
|
+
function findUnverifiedEgressEndpoints(endpoints, endpointWireStatus, exercisedPaths = V2_DECISION_EGRESS_EXERCISED_PATHS) {
|
|
194
|
+
const exercised = new Set(exercisedPaths);
|
|
195
|
+
return Object.freeze(
|
|
196
|
+
endpoints.filter((endpoint) => {
|
|
197
|
+
const status = endpointWireStatus[endpoint];
|
|
198
|
+
if (status === "unwired") return false;
|
|
199
|
+
if (status === "wired") return !exercised.has(endpoint);
|
|
200
|
+
return true;
|
|
201
|
+
})
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
var V2_DECISION_EGRESS_TRANSPORT = Object.freeze({
|
|
205
|
+
wireStatus: "unwired",
|
|
206
|
+
wired: false,
|
|
207
|
+
note: "Endpoints are retained inert (UNWIRED) in this surface. No transport, retry or fallback exists here, and this module never claims the transport was removed. Verification covers only the paths a probe exercised \u2014 none \u2014 and every declared endpoint carries an explicit wire status so an unverified endpoint fails a test instead of passing silently.",
|
|
208
|
+
endpoints: Object.freeze(DECLARED_EGRESS_ENDPOINTS.map(({ url }) => url)),
|
|
209
|
+
endpointWireStatus: V2_DECISION_EGRESS_ENDPOINT_WIRE_STATUS
|
|
210
|
+
});
|
|
211
|
+
function resolveV2DecisionEgress(config, capEligibleCandidates = []) {
|
|
212
|
+
const preference = migrateUserDecisionRouterConfig(config);
|
|
213
|
+
const candidates = preference.enabled_candidates.length;
|
|
214
|
+
if (!preference.enabled) {
|
|
215
|
+
return { mode: "off", reason: "DISABLED", candidates };
|
|
216
|
+
}
|
|
217
|
+
if (preference.selection.mode === "local") {
|
|
218
|
+
return { mode: "off", reason: "LOCAL_SELECTION", candidates };
|
|
219
|
+
}
|
|
220
|
+
if (!preference.egress_consent) {
|
|
221
|
+
return { mode: "off", reason: "CONSENT_MISSING", candidates };
|
|
222
|
+
}
|
|
223
|
+
if (preference.selection.mode === "auto") {
|
|
224
|
+
const explained = explainUserDecisionRouterAutoSelection(
|
|
225
|
+
preference,
|
|
226
|
+
capEligibleCandidates
|
|
227
|
+
);
|
|
228
|
+
if (explained.outcome === "ambiguous") {
|
|
229
|
+
return { mode: "off", reason: "AMBIGUOUS_CANDIDATES", candidates: explained.count };
|
|
230
|
+
}
|
|
231
|
+
if (explained.outcome !== "single") {
|
|
232
|
+
return { mode: "off", reason: "NO_ELIGIBLE_CANDIDATE", candidates: 0 };
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
mode: "opt-in",
|
|
236
|
+
reason: "EXPLICIT_OPT_IN",
|
|
237
|
+
provider: explained.candidate.provider,
|
|
238
|
+
candidate: explained.candidate
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
const selected = preference.selection;
|
|
242
|
+
const match = capEligibleCandidates.find(
|
|
243
|
+
(candidate) => candidate.provider === selected.provider && candidate.model === selected.model
|
|
244
|
+
);
|
|
245
|
+
if (match === void 0) {
|
|
246
|
+
return { mode: "off", reason: "NO_ELIGIBLE_CANDIDATE", candidates };
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
mode: "opt-in",
|
|
250
|
+
reason: "EXPLICIT_OPT_IN",
|
|
251
|
+
provider: selected.provider,
|
|
252
|
+
candidate: match
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function v2DecisionEgressMaySend(state) {
|
|
256
|
+
return state.mode === "opt-in" && state.reason === "EXPLICIT_OPT_IN";
|
|
257
|
+
}
|
|
258
|
+
function assertV2DecisionEgressOptIn(state) {
|
|
259
|
+
if (!v2DecisionEgressMaySend(state)) {
|
|
260
|
+
throw new Error(`Decision egress is off (${state.mode === "off" ? state.reason : "unknown"})`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
export {
|
|
264
|
+
V2_DECISION_EGRESS_DEFAULT,
|
|
265
|
+
V2_DECISION_EGRESS_ENDPOINT_WIRE_STATUS,
|
|
266
|
+
V2_DECISION_EGRESS_EXERCISED_PATHS,
|
|
267
|
+
V2_DECISION_EGRESS_TRANSPORT,
|
|
268
|
+
assertV2DecisionEgressOptIn,
|
|
269
|
+
findUnverifiedEgressEndpoints,
|
|
270
|
+
resolveV2DecisionEgress,
|
|
271
|
+
v2DecisionEgressMaySend
|
|
272
|
+
};
|