@tryvira/opencode 0.1.95 → 0.1.96
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/README.md +9 -3
- package/dist/index.js +82 -21
- package/dist/server.js +82 -21
- package/dist/tui.js +262 -17
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# `@tryvira/opencode` 0.1.
|
|
1
|
+
# `@tryvira/opencode` 0.1.96
|
|
2
2
|
|
|
3
3
|
OpenCode V2 server plugin for Vira host lifecycle governance. The package default
|
|
4
4
|
exports the V2 setup surface plus a compatibility `server()` transport required
|
|
@@ -7,10 +7,10 @@ exported separately as `v1Fallback` and is not the old unconditional-deny path.
|
|
|
7
7
|
|
|
8
8
|
### OpenCode 2.4.x plugin inventory
|
|
9
9
|
|
|
10
|
-
Install with `opencode plugin add @tryvira/opencode@0.1.
|
|
10
|
+
Install with `opencode plugin add @tryvira/opencode@0.1.96`. The
|
|
11
11
|
authoritative fresh-install check is `opencode plugin check` plus
|
|
12
12
|
`opencode debug config` (the latter must contain
|
|
13
|
-
`@tryvira/opencode@0.1.
|
|
13
|
+
`@tryvira/opencode@0.1.96`). OpenCode 2.4.x can still report `No plugins found`
|
|
14
14
|
from `plugin list` immediately after an install because its background plugin
|
|
15
15
|
inventory is populated asynchronously; this is a host inventory race, not
|
|
16
16
|
missing Vira metadata. Do not remove and reinstall the package. Re-run
|
|
@@ -80,3 +80,9 @@ The `./tui` export registers `/vira-result <host-task-run-host-turn:…>` and a
|
|
|
80
80
|
### Commercial wallet readback
|
|
81
81
|
|
|
82
82
|
With an authorized organization-scope owner or Billing Admin identity, the MCP tool `get_ai_credit_wallet` accepts `includeCommercial: true` to request approved agreement summaries. The plugin also exports `readOpenCodeCommercialWallet(client, true)` for explicit host-side reads. Neither runs automatically in model hooks. Department machine keys are not granted organization-wide finance authority. This does not add a native OpenCode financial panel or enable payment collection.
|
|
83
|
+
|
|
84
|
+
Use `/vira-teach-review <teach-run-id>` for a scope-verified, read-only recommendation in an authorized OpenCode TUI session. It never approves or releases behavior.
|
|
85
|
+
|
|
86
|
+
Use `/vira-discovery-status <observation-event-id>` to read the persisted queue state and service scan freshness. `/vira-discovery-queue <observation-event-id>` requires typing `QUEUE` after exact scoped readback and only admits missing work. Both require an authorized actor credential and matching configured department, AI System and connection. The plugin never elevates a machine credential or publishes behavior.
|
|
87
|
+
|
|
88
|
+
Use `/vira-credit-preview <feature>` to read approved token rates and applicable temporary hold for the configured AI System, without reserving credits or invoking a provider. Exact authorized department and current session are required.
|
package/dist/index.js
CHANGED
|
@@ -245,7 +245,7 @@ var ViraClient = class {
|
|
|
245
245
|
...this.defaultHeaders
|
|
246
246
|
};
|
|
247
247
|
if (request.body) headers["content-type"] = "application/json";
|
|
248
|
-
const operatorOperation = /^\/v1\/(?:billing\/legacy-pricing\/(?:inspect|propose|approve)|behavior-policy-bindings\/reconciliation\/(?:inspect|propose|approve|history|remediation-inspect|remediation-propose|remediation-approve|remediation-history)|signals\/subject-consent\/(?:inspect|grant|withdraw)|teach\/subject-evidence\/(?:admit|withdraw|history))$/.test(request.path);
|
|
248
|
+
const operatorOperation = /^\/v1\/(?:billing\/legacy-pricing\/(?:inspect|propose|approve)|behavior-policy-bindings\/reconciliation\/(?:inspect|propose|approve|history|remediation-inspect|remediation-propose|remediation-approve|remediation-history)|signals\/subject-consent\/(?:inspect|grant|withdraw|inventory|history)|connections\/[^/]+\/revoke|teach\/subject-evidence\/(?:admit|withdraw|history))$/.test(request.path);
|
|
249
249
|
if (operatorOperation) {
|
|
250
250
|
if (Object.keys(headers).some((key) => ["authorization", "x-vira-api-key", "x-vira-delegation", "x-vira-taskrun-delegation", "x-vira-optimizer-grant", "cookie"].includes(key.toLowerCase())))
|
|
251
251
|
throw new Error("SDK_OPERATOR_MIXED_AUTHORITY_FORBIDDEN");
|
|
@@ -700,7 +700,7 @@ var ViraClient = class {
|
|
|
700
700
|
if (!listed) throw error62;
|
|
701
701
|
const systems = Array.isArray(listed?.body?.systems) ? listed.body.systems : [];
|
|
702
702
|
const reused = systems.find(
|
|
703
|
-
(system) => String(system.name ?? "") === input2.name && String(system.systemType ?? "") === input2.systemType && String(system.organizationId ?? "") === input2.organizationId && String(system.projectId ?? "") === input2.projectId && String(system.environmentId ?? "") === input2.environmentId
|
|
703
|
+
(system) => system.status === "ACTIVE" && String(system.name ?? "") === input2.name && String(system.systemType ?? "") === input2.systemType && String(system.organizationId ?? "") === input2.organizationId && String(system.projectId ?? "") === input2.projectId && String(system.environmentId ?? "") === input2.environmentId
|
|
704
704
|
);
|
|
705
705
|
if (!reused) throw error62;
|
|
706
706
|
systemResult = { status: listed.status, requestId: listed.requestId, body: { system: reused } };
|
|
@@ -723,11 +723,11 @@ var ViraClient = class {
|
|
|
723
723
|
const listed = await this.listSystemConnections(systemId);
|
|
724
724
|
const connections = Array.isArray(listed?.body?.connections) ? listed.body.connections : [];
|
|
725
725
|
const requested = new Set((input2.capabilities ?? []).map(String));
|
|
726
|
-
const reused = connections.find((connection) => String(connection.adapterType ?? "") === input2.adapterType && requested.size <= new Set(Array.isArray(connection.capabilities) ? connection.capabilities.map(String) : []).size && [...requested].every((capability) => (Array.isArray(connection.capabilities) ? connection.capabilities.map(String) : []).includes(capability)));
|
|
726
|
+
const reused = connections.find((connection) => connection.status === "CONNECTED" && connection.aiSystemId === systemId && String(connection.adapterType ?? "") === input2.adapterType && requested.size <= new Set(Array.isArray(connection.capabilities) ? connection.capabilities.map(String) : []).size && [...requested].every((capability) => (Array.isArray(connection.capabilities) ? connection.capabilities.map(String) : []).includes(capability)));
|
|
727
727
|
if (!reused) throw error62;
|
|
728
728
|
const verified = await this.getConnection(String(reused.id ?? ""));
|
|
729
729
|
const verifiedConnection = verified?.body?.connection && typeof verified.body.connection === "object" ? verified.body.connection : null;
|
|
730
|
-
if (!verifiedConnection || String(verifiedConnection.adapterType ?? "") !== input2.adapterType) throw error62;
|
|
730
|
+
if (!verifiedConnection || verifiedConnection.status !== "CONNECTED" || verifiedConnection.id !== reused.id || verifiedConnection.aiSystemId !== systemId || String(verifiedConnection.adapterType ?? "") !== input2.adapterType) throw error62;
|
|
731
731
|
const verifiedCapabilities = Array.isArray(verifiedConnection.capabilities) ? verifiedConnection.capabilities.map(String) : [];
|
|
732
732
|
if (![...requested].every((capability) => verifiedCapabilities.includes(capability))) throw error62;
|
|
733
733
|
const fromVersion = String(verifiedConnection.adapterVersion ?? "");
|
|
@@ -736,7 +736,8 @@ var ViraClient = class {
|
|
|
736
736
|
}
|
|
737
737
|
if (!connectionResult) return null;
|
|
738
738
|
const connectedId = String(connectionResult.body.connection.id ?? "").trim();
|
|
739
|
-
if (connectedId
|
|
739
|
+
if (!connectedId || connectionResult.body.connection.status !== "CONNECTED" || connectionResult.body.connection.aiSystemId !== systemId) throw Error("SDK_CONNECTION_AUTHORITY_INVALID");
|
|
740
|
+
this.boundConnectionId = connectedId;
|
|
740
741
|
return {
|
|
741
742
|
status: connectionResult.status,
|
|
742
743
|
requestId: connectionResult.requestId,
|
|
@@ -984,6 +985,26 @@ var ViraClient = class {
|
|
|
984
985
|
query: { ...options.reviewState ? { reviewState: options.reviewState } : {}, ...listQuery(normalized) }
|
|
985
986
|
});
|
|
986
987
|
}
|
|
988
|
+
listReusableEvaluationDatasets(systemId, cursor) {
|
|
989
|
+
return this.request({ method: "GET", path: `/v1/ai-systems/${encodeURIComponent(systemId)}/evaluation-datasets`, query: cursor ? { cursor } : {} }, { enforcing: true });
|
|
990
|
+
}
|
|
991
|
+
getReusableEvaluationDataset(systemId, datasetId, datasetDigest) {
|
|
992
|
+
return this.request({ method: "GET", path: `/v1/ai-systems/${encodeURIComponent(systemId)}/evaluation-datasets/${encodeURIComponent(datasetId)}`, query: { datasetDigest } }, { enforcing: true });
|
|
993
|
+
}
|
|
994
|
+
getFeatureCreditPreview(systemId, feature, model) {
|
|
995
|
+
return this.request({ method: "GET", path: `/v1/ai-systems/${encodeURIComponent(systemId)}/ai-credit-preview/${encodeURIComponent(feature)}`, ...model ? { query: { providerId: model.providerId, modelId: model.modelId } } : {} }, { enforcing: true });
|
|
996
|
+
}
|
|
997
|
+
getDiscoveryWorkerHealth() {
|
|
998
|
+
return this.request({ method: "GET", path: "/v1/discovery/worker-health" }, { enforcing: true });
|
|
999
|
+
}
|
|
1000
|
+
getDiscoveryDispatch(eventId) {
|
|
1001
|
+
required(eventId, "SDK_OBSERVATION_EVENT_ID_REQUIRED");
|
|
1002
|
+
return this.request({ method: "GET", path: `/v1/discovery/observations/${encodeURIComponent(eventId)}/dispatch` }, { enforcing: true });
|
|
1003
|
+
}
|
|
1004
|
+
async queueDiscoveryDispatch(eventId, options = {}) {
|
|
1005
|
+
required(eventId, "SDK_OBSERVATION_EVENT_ID_REQUIRED");
|
|
1006
|
+
return this.request({ method: "POST", path: `/v1/discovery/observations/${encodeURIComponent(eventId)}/dispatch`, body: {} }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey("sdk:discovery-dispatch", { eventId }), enforcing: true });
|
|
1007
|
+
}
|
|
987
1008
|
async reviewDiscoveryCandidate(kind, key, input2, options = {}) {
|
|
988
1009
|
required(kind, "SDK_DISCOVERY_CANDIDATE_KIND_REQUIRED");
|
|
989
1010
|
required(key, "SDK_DISCOVERY_CANDIDATE_KEY_REQUIRED");
|
|
@@ -997,6 +1018,15 @@ var ViraClient = class {
|
|
|
997
1018
|
const invocationId = globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
998
1019
|
return this.request({ method: "POST", path, body }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:discovery-review:${kind}:${key}`, { invocationId, body }), enforcing: true });
|
|
999
1020
|
}
|
|
1021
|
+
/** Create a review-only department draft from approved semantic evidence. */
|
|
1022
|
+
async createDepartmentDiscoveryDraft(key, input2, options = {}) {
|
|
1023
|
+
required(key, "SDK_DISCOVERY_CANDIDATE_KEY_REQUIRED");
|
|
1024
|
+
required(input2.candidateId, "SDK_DISCOVERY_CANDIDATE_ID_REQUIRED");
|
|
1025
|
+
required(input2.aiSystemId, "SDK_AI_SYSTEM_ID_REQUIRED");
|
|
1026
|
+
if (!Array.isArray(input2.evidenceIds) || !input2.evidenceIds.length || input2.evidenceIds.length > 200 || input2.evidenceIds.some((id) => typeof id !== "string" || !id.trim()) || new Set(input2.evidenceIds).size !== input2.evidenceIds.length) throw Error("SDK_DISCOVERY_DRAFT_EVIDENCE_INVALID");
|
|
1027
|
+
const body = { candidateId: input2.candidateId, aiSystemId: input2.aiSystemId, evidenceIds: [...input2.evidenceIds] };
|
|
1028
|
+
return this.request({ method: "POST", path: `/v1/discovery/candidates/semantic_task/${encodeURIComponent(key)}/department-draft`, body }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:discovery-draft:${key}`, body), enforcing: true });
|
|
1029
|
+
}
|
|
1000
1030
|
/** Explicit canonical publication; API approval and scope checks still apply. */
|
|
1001
1031
|
publishDiscoveryCandidate(kind, key, input2 = {}, options = {}) {
|
|
1002
1032
|
required(kind, "SDK_DISCOVERY_CANDIDATE_KIND_REQUIRED");
|
|
@@ -1133,7 +1163,8 @@ var ViraClient = class {
|
|
|
1133
1163
|
}
|
|
1134
1164
|
async approvePack(packId, options = {}) {
|
|
1135
1165
|
required(packId, "SDK_PACK_ID_REQUIRED");
|
|
1136
|
-
const
|
|
1166
|
+
const approval = options.manualApproval ? { manualApproval: true, reason: required(options.reason ?? "", "SDK_MANUAL_PACK_APPROVAL_REASON_REQUIRED") } : {};
|
|
1167
|
+
const body = { ...approval, ...options.expectedPackDigest === void 0 ? {} : { expectedPackDigest: options.expectedPackDigest } };
|
|
1137
1168
|
return this.request(
|
|
1138
1169
|
{
|
|
1139
1170
|
method: "POST",
|
|
@@ -1143,15 +1174,16 @@ var ViraClient = class {
|
|
|
1143
1174
|
{ idempotencyKey: await contentIdempotencyKey(`sdk:pack:approve:${packId}`, body) }
|
|
1144
1175
|
);
|
|
1145
1176
|
}
|
|
1146
|
-
async releasePack(packId) {
|
|
1177
|
+
async releasePack(packId, options = {}) {
|
|
1147
1178
|
required(packId, "SDK_PACK_ID_REQUIRED");
|
|
1179
|
+
const body = options.expectedPackDigest === void 0 ? {} : { expectedPackDigest: options.expectedPackDigest };
|
|
1148
1180
|
return this.request(
|
|
1149
1181
|
{
|
|
1150
1182
|
method: "POST",
|
|
1151
1183
|
path: `/v1/packs/${encodeURIComponent(packId)}/release`,
|
|
1152
|
-
body
|
|
1184
|
+
body
|
|
1153
1185
|
},
|
|
1154
|
-
{ idempotencyKey: await contentIdempotencyKey(`sdk:pack:release:${packId}`,
|
|
1186
|
+
{ idempotencyKey: await contentIdempotencyKey(`sdk:pack:release:${packId}`, body) }
|
|
1155
1187
|
);
|
|
1156
1188
|
}
|
|
1157
1189
|
async previewPackUpgrade(packId, incoming) {
|
|
@@ -1268,6 +1300,19 @@ var ViraClient = class {
|
|
|
1268
1300
|
historyLegacyRecordRemediation(input2 = {}) {
|
|
1269
1301
|
return this.request({ method: "POST", path: "/v1/behavior-policy-bindings/reconciliation/remediation-history", body: input2 }, { enforcing: true });
|
|
1270
1302
|
}
|
|
1303
|
+
/** Native operator delegation only; never a machine key or MCP mutation. */
|
|
1304
|
+
revokeConnection(connectionId, input2) {
|
|
1305
|
+
required(connectionId, "SDK_CONNECTION_ID_REQUIRED");
|
|
1306
|
+
required(input2.aiSystemId, "SDK_SYSTEM_ID_REQUIRED");
|
|
1307
|
+
if (input2.confirm !== true) throw Error("SDK_CONNECTION_REVOCATION_CONFIRMATION_REQUIRED");
|
|
1308
|
+
return this.request({ method: "POST", path: `/v1/connections/${encodeURIComponent(connectionId)}/revoke`, body: { aiSystemId: input2.aiSystemId, confirm: true } }, { enforcing: true });
|
|
1309
|
+
}
|
|
1310
|
+
inventorySubjectSignalConsent() {
|
|
1311
|
+
return this.request({ method: "POST", path: "/v1/signals/subject-consent/inventory", body: {} }, { enforcing: true });
|
|
1312
|
+
}
|
|
1313
|
+
historySubjectSignalConsent() {
|
|
1314
|
+
return this.request({ method: "POST", path: "/v1/signals/subject-consent/history", body: {} }, { enforcing: true });
|
|
1315
|
+
}
|
|
1271
1316
|
inspectSubjectSignalConsent(input2) {
|
|
1272
1317
|
return this.request({ method: "POST", path: "/v1/signals/subject-consent/inspect", body: input2 }, { enforcing: true });
|
|
1273
1318
|
}
|
|
@@ -1932,7 +1977,7 @@ var ViraClient = class {
|
|
|
1932
1977
|
return this.request({ method: "POST", path: "/v1/teach/conversations", body: { ...evidence, privacy: evidence.privacy ?? "CONSENTED_TENANT" } }, { idempotencyKey: options.idempotencyKey });
|
|
1933
1978
|
}
|
|
1934
1979
|
listConversationArchive(input2 = {}) {
|
|
1935
|
-
return this.request({ method: "GET", path: "/v1/teach/conversations", query: { ...input2.limit === void 0 ? {} : { limit: String(input2.limit) }, ...input2.cursor ? { cursor: input2.cursor } : {} } });
|
|
1980
|
+
return this.request({ method: "GET", path: "/v1/teach/conversations", query: { ...input2.limit === void 0 ? {} : { limit: String(input2.limit) }, ...input2.cursor ? { cursor: input2.cursor } : {}, ...input2.aiSystemId ? { aiSystemId: input2.aiSystemId } : {} } });
|
|
1936
1981
|
}
|
|
1937
1982
|
importConversationArchive(conversations, options = {}) {
|
|
1938
1983
|
if (!Array.isArray(conversations) || !conversations.length) throw new Error("SDK_CONVERSATION_IMPORT_REQUIRED");
|
|
@@ -1981,10 +2026,12 @@ var ViraClient = class {
|
|
|
1981
2026
|
required(teachRunId, "SDK_TEACH_RUN_ID_REQUIRED");
|
|
1982
2027
|
return this.request({ method: "GET", path: `/v1/teach/runs/${encodeURIComponent(teachRunId)}/recommendation` });
|
|
1983
2028
|
}
|
|
1984
|
-
acceptTeachRecommendation(teachRunId, actorId, options = {}) {
|
|
2029
|
+
async acceptTeachRecommendation(teachRunId, actorId, options = {}) {
|
|
1985
2030
|
required(teachRunId, "SDK_TEACH_RUN_ID_REQUIRED");
|
|
1986
|
-
required(actorId, "SDK_TEACH_RECOMMENDATION_ACTOR_REQUIRED");
|
|
1987
|
-
|
|
2031
|
+
if (actorId !== void 0) required(actorId, "SDK_TEACH_RECOMMENDATION_ACTOR_REQUIRED");
|
|
2032
|
+
if ((options.basePackId !== void 0 || options.basePackDigest !== void 0) && (!options.basePackId?.trim() || !options.basePackDigest || !/^[a-f0-9]{64}$/.test(options.basePackDigest))) throw Error("SDK_TEACH_BASE_PACK_INVALID");
|
|
2033
|
+
const body = { ...actorId === void 0 ? {} : { actorId }, ...options.basePackId === void 0 ? {} : { basePackId: options.basePackId, basePackDigest: options.basePackDigest } };
|
|
2034
|
+
return this.request({ method: "POST", path: `/v1/teach/runs/${encodeURIComponent(teachRunId)}/recommendation/accept`, body }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:teach:recommendation:accept:${teachRunId}`, body) });
|
|
1988
2035
|
}
|
|
1989
2036
|
rejectTeachRecommendation(teachRunId, reason, options = {}) {
|
|
1990
2037
|
required(teachRunId, "SDK_TEACH_RUN_ID_REQUIRED");
|
|
@@ -2013,6 +2060,10 @@ var ViraClient = class {
|
|
|
2013
2060
|
{ idempotencyKey: options.idempotencyKey }
|
|
2014
2061
|
);
|
|
2015
2062
|
}
|
|
2063
|
+
/** Run scoped normal-Pack quality evaluation; does not publish or verify live runtime. */
|
|
2064
|
+
startWholePackQualityEvaluation(input2, options = {}) {
|
|
2065
|
+
return this.startEvaluation({ id: input2.id, aiSystemId: input2.aiSystemId, packId: input2.packId, packDigest: input2.packDigest, dataset: input2.dataset.map((c) => ({ id: c.id, programId: c.programId, input: c.input, rubric: [...c.rubric] })), wholePackEvaluation: true, ...input2.modelSelection ? { modelSelection: input2.modelSelection } : {} }, options);
|
|
2066
|
+
}
|
|
2016
2067
|
/** Request a server-executed OFF/current-ON/candidate-ON comparison.
|
|
2017
2068
|
* The server owns arm execution and receipts; callers cannot submit outputs.
|
|
2018
2069
|
*/
|
|
@@ -2035,7 +2086,7 @@ var ViraClient = class {
|
|
|
2035
2086
|
});
|
|
2036
2087
|
}
|
|
2037
2088
|
listEvaluations(input2 = {}) {
|
|
2038
|
-
return this.request({ method: "GET", path: "/v1/evaluations", query: { ...input2.limit === void 0 ? {} : { limit: String(input2.limit) }, ...input2.cursor ? { cursor: input2.cursor } : {}, ...input2.status ? { status: input2.status } : {} } });
|
|
2089
|
+
return this.request({ method: "GET", path: "/v1/evaluations", query: { ...input2.limit === void 0 ? {} : { limit: String(input2.limit) }, ...input2.cursor ? { cursor: input2.cursor } : {}, ...input2.status ? { status: input2.status } : {}, ...input2.search ? { search: input2.search } : {} } });
|
|
2039
2090
|
}
|
|
2040
2091
|
getEvaluationComparison(evaluationId) {
|
|
2041
2092
|
required(evaluationId, "SDK_EVALUATION_ID_REQUIRED");
|
|
@@ -2087,9 +2138,9 @@ var ViraClient = class {
|
|
|
2087
2138
|
if (!Array.isArray(input2.dataset) || input2.dataset.length === 0) throw new Error("SDK_CANDIDATE_EVALUATION_DATASET_REQUIRED");
|
|
2088
2139
|
return this.request({ method: "POST", path: `/v1/behavior-revision-candidates/${encodeURIComponent(candidateId)}/evaluate`, body: input2 }, { idempotencyKey: options.idempotencyKey ?? `sdk:behavior-candidate:evaluate:${candidateId}` });
|
|
2089
2140
|
}
|
|
2090
|
-
transitionBehaviorRevisionCandidate(candidateId, transition, input2 = {}, options = {}) {
|
|
2141
|
+
async transitionBehaviorRevisionCandidate(candidateId, transition, input2 = {}, options = {}) {
|
|
2091
2142
|
required(candidateId, "SDK_BEHAVIOR_CANDIDATE_ID_REQUIRED");
|
|
2092
|
-
return this.request({ method: "POST", path: `/v1/behavior-revision-candidates/${encodeURIComponent(candidateId)}/${transition}`, body: input2 }, { idempotencyKey: options.idempotencyKey ?? `sdk:behavior-candidate:${transition}:${candidateId}
|
|
2143
|
+
return this.request({ method: "POST", path: `/v1/behavior-revision-candidates/${encodeURIComponent(candidateId)}/${transition}`, body: input2 }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:behavior-candidate:${transition}:${candidateId}`, input2) });
|
|
2093
2144
|
}
|
|
2094
2145
|
createPackRevision(input2, options = {}) {
|
|
2095
2146
|
return this.request({ method: "POST", path: "/v1/pack-revisions", body: input2 }, { idempotencyKey: options.idempotencyKey });
|
|
@@ -2214,6 +2265,9 @@ var ViraClient = class {
|
|
|
2214
2265
|
freezeDepartmentOptimizationDataset(input2) {
|
|
2215
2266
|
return this.request({ method: "POST", path: "/v1/optimization/dataset-freeze", body: input2 }, { enforcing: true });
|
|
2216
2267
|
}
|
|
2268
|
+
inspectDepartmentOptimizationDataset(input2) {
|
|
2269
|
+
return this.request({ method: "POST", path: "/v1/optimization/dataset-inspect", body: input2 }, { enforcing: true });
|
|
2270
|
+
}
|
|
2217
2271
|
listDepartmentOptimizationDatasets(input2) {
|
|
2218
2272
|
return this.request({ method: "POST", path: "/v1/optimization/dataset-options", body: input2 }, { enforcing: true });
|
|
2219
2273
|
}
|
|
@@ -2514,15 +2568,18 @@ function createViraHostRuntime(client, config2) {
|
|
|
2514
2568
|
if (mode === "enforce" && typeof config2.authorizeAction !== "function") throw new Error("SDK_HOST_ACTION_AUTHORIZER_REQUIRED");
|
|
2515
2569
|
let connected = null;
|
|
2516
2570
|
let connectionIdentity = null;
|
|
2571
|
+
let connectionGeneration = 0;
|
|
2517
2572
|
const projections = /* @__PURE__ */ new Map();
|
|
2518
2573
|
const activeToolSessions = /* @__PURE__ */ new Map();
|
|
2519
2574
|
const connectOnce = async (options = {}) => {
|
|
2520
2575
|
if (mode === "off" || !config2.connect) return null;
|
|
2521
2576
|
if (options.force) {
|
|
2577
|
+
++connectionGeneration;
|
|
2522
2578
|
connected = null;
|
|
2523
2579
|
connectionIdentity = null;
|
|
2524
2580
|
}
|
|
2525
2581
|
if (!connected) {
|
|
2582
|
+
const generation = ++connectionGeneration;
|
|
2526
2583
|
const attempt = withTimeout(client.connectOnce(config2.connect), timeoutMs, "SDK_HOST_CONNECT_TIMEOUT").then((result) => {
|
|
2527
2584
|
const body = bodyOf(result);
|
|
2528
2585
|
const system = body.system && typeof body.system === "object" ? body.system : {};
|
|
@@ -2530,13 +2587,16 @@ function createViraHostRuntime(client, config2) {
|
|
|
2530
2587
|
const aiSystemId = typeof system.id === "string" ? system.id.trim() : "";
|
|
2531
2588
|
const connectionId = typeof connection.id === "string" ? connection.id.trim() : "";
|
|
2532
2589
|
if (!aiSystemId || !connectionId) throw new Error("SDK_HOST_CONNECT_IDENTITY_MISSING");
|
|
2590
|
+
if (generation !== connectionGeneration) throw Error("SDK_HOST_CONNECT_SUPERSEDED");
|
|
2533
2591
|
connectionIdentity = { aiSystemId, connectionId };
|
|
2534
2592
|
return result;
|
|
2535
2593
|
});
|
|
2536
2594
|
let cachedAttempt;
|
|
2537
2595
|
cachedAttempt = attempt.catch((error62) => {
|
|
2538
|
-
if (connected === cachedAttempt
|
|
2539
|
-
|
|
2596
|
+
if (connected === cachedAttempt && generation === connectionGeneration) {
|
|
2597
|
+
connected = null;
|
|
2598
|
+
connectionIdentity = null;
|
|
2599
|
+
}
|
|
2540
2600
|
throw error62;
|
|
2541
2601
|
});
|
|
2542
2602
|
connected = cachedAttempt;
|
|
@@ -22940,6 +23000,7 @@ var createV1PromptCache = (ttlMs) => {
|
|
|
22940
23000
|
return { set(sessionId, prompt) {
|
|
22941
23001
|
clear(sessionId);
|
|
22942
23002
|
const timer = setTimeout(() => entries.delete(sessionId), ttl);
|
|
23003
|
+
timer.unref?.();
|
|
22943
23004
|
entries.set(sessionId, { prompt, timer });
|
|
22944
23005
|
}, peek(sessionId) {
|
|
22945
23006
|
return entries.get(sessionId)?.prompt;
|
|
@@ -22988,7 +23049,7 @@ async function resolveOpenCodeCredentialScope(client, options, machine) {
|
|
|
22988
23049
|
async function assertOpenCodeMachineConnection(client, scope, aiSystemId, connectionId) {
|
|
22989
23050
|
if (!aiSystemId || !connectionId) throw Error("VIRA_MACHINE_PREPROVISIONED_CONNECTION_REQUIRED");
|
|
22990
23051
|
const response = await client.getConnection(connectionId);
|
|
22991
|
-
if (response?.body?.systemId !== aiSystemId || response.body.connection?.id !== connectionId || ["organizationId", "projectId", "environmentId", "organizationUnitId"].some((key) => response.body.scope?.[key] !== scope[key]))
|
|
23052
|
+
if (response?.body?.systemId !== aiSystemId || response.body.connection?.id !== connectionId || response.body.connection.status !== "CONNECTED" || response.body.connection.aiSystemId !== aiSystemId || ["organizationId", "projectId", "environmentId", "organizationUnitId"].some((key) => response.body.scope?.[key] !== scope[key]))
|
|
22992
23053
|
throw Error("VIRA_MACHINE_CONNECTION_SCOPE_MISMATCH");
|
|
22993
23054
|
}
|
|
22994
23055
|
var readHostOptions = (rawContext) => {
|
|
@@ -23251,12 +23312,12 @@ var v2Plugin = Plugin.define({
|
|
|
23251
23312
|
try {
|
|
23252
23313
|
const listed = await client.listAISystems();
|
|
23253
23314
|
const systems = Array.isArray(listed?.body?.systems) ? listed.body.systems : [];
|
|
23254
|
-
const system = systems.find((item) => String(item.name ?? "") === "OpenCode" && String(item.systemType ?? "") === "agent" && String(item.organizationId ?? "") === scope.organizationId && String(item.projectId ?? "") === scope.projectId && String(item.environmentId ?? "") === scope.environmentId);
|
|
23315
|
+
const system = systems.find((item) => item.status === "ACTIVE" && String(item.name ?? "") === "OpenCode" && String(item.systemType ?? "") === "agent" && String(item.organizationId ?? "") === scope.organizationId && String(item.projectId ?? "") === scope.projectId && String(item.environmentId ?? "") === scope.environmentId);
|
|
23255
23316
|
if (system?.id) {
|
|
23256
23317
|
const connections = await client.listSystemConnections(String(system.id));
|
|
23257
23318
|
const connectionRows = Array.isArray(connections?.body?.connections) ? connections.body.connections : [];
|
|
23258
23319
|
const requested = new Set(openCodeConnectConfig(scope, options).capabilities);
|
|
23259
|
-
const connection = connectionRows.find((item) => String(item.adapterType ?? "") === "custom-node" && requested.size <= (Array.isArray(item.capabilities) ? item.capabilities.length : 0) && [...requested].every((capability) => Array.isArray(item.capabilities) && item.capabilities.includes(capability)));
|
|
23320
|
+
const connection = connectionRows.find((item) => item.status === "CONNECTED" && item.aiSystemId === system.id && String(item.adapterType ?? "") === "custom-node" && requested.size <= (Array.isArray(item.capabilities) ? item.capabilities.length : 0) && [...requested].every((capability) => Array.isArray(item.capabilities) && item.capabilities.includes(capability)));
|
|
23260
23321
|
if (connection?.id) {
|
|
23261
23322
|
bootstrapAiSystemId = String(system.id);
|
|
23262
23323
|
bootstrapConnectionId = String(connection.id);
|
package/dist/server.js
CHANGED
|
@@ -245,7 +245,7 @@ var ViraClient = class {
|
|
|
245
245
|
...this.defaultHeaders
|
|
246
246
|
};
|
|
247
247
|
if (request.body) headers["content-type"] = "application/json";
|
|
248
|
-
const operatorOperation = /^\/v1\/(?:billing\/legacy-pricing\/(?:inspect|propose|approve)|behavior-policy-bindings\/reconciliation\/(?:inspect|propose|approve|history|remediation-inspect|remediation-propose|remediation-approve|remediation-history)|signals\/subject-consent\/(?:inspect|grant|withdraw)|teach\/subject-evidence\/(?:admit|withdraw|history))$/.test(request.path);
|
|
248
|
+
const operatorOperation = /^\/v1\/(?:billing\/legacy-pricing\/(?:inspect|propose|approve)|behavior-policy-bindings\/reconciliation\/(?:inspect|propose|approve|history|remediation-inspect|remediation-propose|remediation-approve|remediation-history)|signals\/subject-consent\/(?:inspect|grant|withdraw|inventory|history)|connections\/[^/]+\/revoke|teach\/subject-evidence\/(?:admit|withdraw|history))$/.test(request.path);
|
|
249
249
|
if (operatorOperation) {
|
|
250
250
|
if (Object.keys(headers).some((key) => ["authorization", "x-vira-api-key", "x-vira-delegation", "x-vira-taskrun-delegation", "x-vira-optimizer-grant", "cookie"].includes(key.toLowerCase())))
|
|
251
251
|
throw new Error("SDK_OPERATOR_MIXED_AUTHORITY_FORBIDDEN");
|
|
@@ -700,7 +700,7 @@ var ViraClient = class {
|
|
|
700
700
|
if (!listed) throw error62;
|
|
701
701
|
const systems = Array.isArray(listed?.body?.systems) ? listed.body.systems : [];
|
|
702
702
|
const reused = systems.find(
|
|
703
|
-
(system) => String(system.name ?? "") === input2.name && String(system.systemType ?? "") === input2.systemType && String(system.organizationId ?? "") === input2.organizationId && String(system.projectId ?? "") === input2.projectId && String(system.environmentId ?? "") === input2.environmentId
|
|
703
|
+
(system) => system.status === "ACTIVE" && String(system.name ?? "") === input2.name && String(system.systemType ?? "") === input2.systemType && String(system.organizationId ?? "") === input2.organizationId && String(system.projectId ?? "") === input2.projectId && String(system.environmentId ?? "") === input2.environmentId
|
|
704
704
|
);
|
|
705
705
|
if (!reused) throw error62;
|
|
706
706
|
systemResult = { status: listed.status, requestId: listed.requestId, body: { system: reused } };
|
|
@@ -723,11 +723,11 @@ var ViraClient = class {
|
|
|
723
723
|
const listed = await this.listSystemConnections(systemId);
|
|
724
724
|
const connections = Array.isArray(listed?.body?.connections) ? listed.body.connections : [];
|
|
725
725
|
const requested = new Set((input2.capabilities ?? []).map(String));
|
|
726
|
-
const reused = connections.find((connection) => String(connection.adapterType ?? "") === input2.adapterType && requested.size <= new Set(Array.isArray(connection.capabilities) ? connection.capabilities.map(String) : []).size && [...requested].every((capability) => (Array.isArray(connection.capabilities) ? connection.capabilities.map(String) : []).includes(capability)));
|
|
726
|
+
const reused = connections.find((connection) => connection.status === "CONNECTED" && connection.aiSystemId === systemId && String(connection.adapterType ?? "") === input2.adapterType && requested.size <= new Set(Array.isArray(connection.capabilities) ? connection.capabilities.map(String) : []).size && [...requested].every((capability) => (Array.isArray(connection.capabilities) ? connection.capabilities.map(String) : []).includes(capability)));
|
|
727
727
|
if (!reused) throw error62;
|
|
728
728
|
const verified = await this.getConnection(String(reused.id ?? ""));
|
|
729
729
|
const verifiedConnection = verified?.body?.connection && typeof verified.body.connection === "object" ? verified.body.connection : null;
|
|
730
|
-
if (!verifiedConnection || String(verifiedConnection.adapterType ?? "") !== input2.adapterType) throw error62;
|
|
730
|
+
if (!verifiedConnection || verifiedConnection.status !== "CONNECTED" || verifiedConnection.id !== reused.id || verifiedConnection.aiSystemId !== systemId || String(verifiedConnection.adapterType ?? "") !== input2.adapterType) throw error62;
|
|
731
731
|
const verifiedCapabilities = Array.isArray(verifiedConnection.capabilities) ? verifiedConnection.capabilities.map(String) : [];
|
|
732
732
|
if (![...requested].every((capability) => verifiedCapabilities.includes(capability))) throw error62;
|
|
733
733
|
const fromVersion = String(verifiedConnection.adapterVersion ?? "");
|
|
@@ -736,7 +736,8 @@ var ViraClient = class {
|
|
|
736
736
|
}
|
|
737
737
|
if (!connectionResult) return null;
|
|
738
738
|
const connectedId = String(connectionResult.body.connection.id ?? "").trim();
|
|
739
|
-
if (connectedId
|
|
739
|
+
if (!connectedId || connectionResult.body.connection.status !== "CONNECTED" || connectionResult.body.connection.aiSystemId !== systemId) throw Error("SDK_CONNECTION_AUTHORITY_INVALID");
|
|
740
|
+
this.boundConnectionId = connectedId;
|
|
740
741
|
return {
|
|
741
742
|
status: connectionResult.status,
|
|
742
743
|
requestId: connectionResult.requestId,
|
|
@@ -984,6 +985,26 @@ var ViraClient = class {
|
|
|
984
985
|
query: { ...options.reviewState ? { reviewState: options.reviewState } : {}, ...listQuery(normalized) }
|
|
985
986
|
});
|
|
986
987
|
}
|
|
988
|
+
listReusableEvaluationDatasets(systemId, cursor) {
|
|
989
|
+
return this.request({ method: "GET", path: `/v1/ai-systems/${encodeURIComponent(systemId)}/evaluation-datasets`, query: cursor ? { cursor } : {} }, { enforcing: true });
|
|
990
|
+
}
|
|
991
|
+
getReusableEvaluationDataset(systemId, datasetId, datasetDigest) {
|
|
992
|
+
return this.request({ method: "GET", path: `/v1/ai-systems/${encodeURIComponent(systemId)}/evaluation-datasets/${encodeURIComponent(datasetId)}`, query: { datasetDigest } }, { enforcing: true });
|
|
993
|
+
}
|
|
994
|
+
getFeatureCreditPreview(systemId, feature, model) {
|
|
995
|
+
return this.request({ method: "GET", path: `/v1/ai-systems/${encodeURIComponent(systemId)}/ai-credit-preview/${encodeURIComponent(feature)}`, ...model ? { query: { providerId: model.providerId, modelId: model.modelId } } : {} }, { enforcing: true });
|
|
996
|
+
}
|
|
997
|
+
getDiscoveryWorkerHealth() {
|
|
998
|
+
return this.request({ method: "GET", path: "/v1/discovery/worker-health" }, { enforcing: true });
|
|
999
|
+
}
|
|
1000
|
+
getDiscoveryDispatch(eventId) {
|
|
1001
|
+
required(eventId, "SDK_OBSERVATION_EVENT_ID_REQUIRED");
|
|
1002
|
+
return this.request({ method: "GET", path: `/v1/discovery/observations/${encodeURIComponent(eventId)}/dispatch` }, { enforcing: true });
|
|
1003
|
+
}
|
|
1004
|
+
async queueDiscoveryDispatch(eventId, options = {}) {
|
|
1005
|
+
required(eventId, "SDK_OBSERVATION_EVENT_ID_REQUIRED");
|
|
1006
|
+
return this.request({ method: "POST", path: `/v1/discovery/observations/${encodeURIComponent(eventId)}/dispatch`, body: {} }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey("sdk:discovery-dispatch", { eventId }), enforcing: true });
|
|
1007
|
+
}
|
|
987
1008
|
async reviewDiscoveryCandidate(kind, key, input2, options = {}) {
|
|
988
1009
|
required(kind, "SDK_DISCOVERY_CANDIDATE_KIND_REQUIRED");
|
|
989
1010
|
required(key, "SDK_DISCOVERY_CANDIDATE_KEY_REQUIRED");
|
|
@@ -997,6 +1018,15 @@ var ViraClient = class {
|
|
|
997
1018
|
const invocationId = globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
998
1019
|
return this.request({ method: "POST", path, body }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:discovery-review:${kind}:${key}`, { invocationId, body }), enforcing: true });
|
|
999
1020
|
}
|
|
1021
|
+
/** Create a review-only department draft from approved semantic evidence. */
|
|
1022
|
+
async createDepartmentDiscoveryDraft(key, input2, options = {}) {
|
|
1023
|
+
required(key, "SDK_DISCOVERY_CANDIDATE_KEY_REQUIRED");
|
|
1024
|
+
required(input2.candidateId, "SDK_DISCOVERY_CANDIDATE_ID_REQUIRED");
|
|
1025
|
+
required(input2.aiSystemId, "SDK_AI_SYSTEM_ID_REQUIRED");
|
|
1026
|
+
if (!Array.isArray(input2.evidenceIds) || !input2.evidenceIds.length || input2.evidenceIds.length > 200 || input2.evidenceIds.some((id) => typeof id !== "string" || !id.trim()) || new Set(input2.evidenceIds).size !== input2.evidenceIds.length) throw Error("SDK_DISCOVERY_DRAFT_EVIDENCE_INVALID");
|
|
1027
|
+
const body = { candidateId: input2.candidateId, aiSystemId: input2.aiSystemId, evidenceIds: [...input2.evidenceIds] };
|
|
1028
|
+
return this.request({ method: "POST", path: `/v1/discovery/candidates/semantic_task/${encodeURIComponent(key)}/department-draft`, body }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:discovery-draft:${key}`, body), enforcing: true });
|
|
1029
|
+
}
|
|
1000
1030
|
/** Explicit canonical publication; API approval and scope checks still apply. */
|
|
1001
1031
|
publishDiscoveryCandidate(kind, key, input2 = {}, options = {}) {
|
|
1002
1032
|
required(kind, "SDK_DISCOVERY_CANDIDATE_KIND_REQUIRED");
|
|
@@ -1133,7 +1163,8 @@ var ViraClient = class {
|
|
|
1133
1163
|
}
|
|
1134
1164
|
async approvePack(packId, options = {}) {
|
|
1135
1165
|
required(packId, "SDK_PACK_ID_REQUIRED");
|
|
1136
|
-
const
|
|
1166
|
+
const approval = options.manualApproval ? { manualApproval: true, reason: required(options.reason ?? "", "SDK_MANUAL_PACK_APPROVAL_REASON_REQUIRED") } : {};
|
|
1167
|
+
const body = { ...approval, ...options.expectedPackDigest === void 0 ? {} : { expectedPackDigest: options.expectedPackDigest } };
|
|
1137
1168
|
return this.request(
|
|
1138
1169
|
{
|
|
1139
1170
|
method: "POST",
|
|
@@ -1143,15 +1174,16 @@ var ViraClient = class {
|
|
|
1143
1174
|
{ idempotencyKey: await contentIdempotencyKey(`sdk:pack:approve:${packId}`, body) }
|
|
1144
1175
|
);
|
|
1145
1176
|
}
|
|
1146
|
-
async releasePack(packId) {
|
|
1177
|
+
async releasePack(packId, options = {}) {
|
|
1147
1178
|
required(packId, "SDK_PACK_ID_REQUIRED");
|
|
1179
|
+
const body = options.expectedPackDigest === void 0 ? {} : { expectedPackDigest: options.expectedPackDigest };
|
|
1148
1180
|
return this.request(
|
|
1149
1181
|
{
|
|
1150
1182
|
method: "POST",
|
|
1151
1183
|
path: `/v1/packs/${encodeURIComponent(packId)}/release`,
|
|
1152
|
-
body
|
|
1184
|
+
body
|
|
1153
1185
|
},
|
|
1154
|
-
{ idempotencyKey: await contentIdempotencyKey(`sdk:pack:release:${packId}`,
|
|
1186
|
+
{ idempotencyKey: await contentIdempotencyKey(`sdk:pack:release:${packId}`, body) }
|
|
1155
1187
|
);
|
|
1156
1188
|
}
|
|
1157
1189
|
async previewPackUpgrade(packId, incoming) {
|
|
@@ -1268,6 +1300,19 @@ var ViraClient = class {
|
|
|
1268
1300
|
historyLegacyRecordRemediation(input2 = {}) {
|
|
1269
1301
|
return this.request({ method: "POST", path: "/v1/behavior-policy-bindings/reconciliation/remediation-history", body: input2 }, { enforcing: true });
|
|
1270
1302
|
}
|
|
1303
|
+
/** Native operator delegation only; never a machine key or MCP mutation. */
|
|
1304
|
+
revokeConnection(connectionId, input2) {
|
|
1305
|
+
required(connectionId, "SDK_CONNECTION_ID_REQUIRED");
|
|
1306
|
+
required(input2.aiSystemId, "SDK_SYSTEM_ID_REQUIRED");
|
|
1307
|
+
if (input2.confirm !== true) throw Error("SDK_CONNECTION_REVOCATION_CONFIRMATION_REQUIRED");
|
|
1308
|
+
return this.request({ method: "POST", path: `/v1/connections/${encodeURIComponent(connectionId)}/revoke`, body: { aiSystemId: input2.aiSystemId, confirm: true } }, { enforcing: true });
|
|
1309
|
+
}
|
|
1310
|
+
inventorySubjectSignalConsent() {
|
|
1311
|
+
return this.request({ method: "POST", path: "/v1/signals/subject-consent/inventory", body: {} }, { enforcing: true });
|
|
1312
|
+
}
|
|
1313
|
+
historySubjectSignalConsent() {
|
|
1314
|
+
return this.request({ method: "POST", path: "/v1/signals/subject-consent/history", body: {} }, { enforcing: true });
|
|
1315
|
+
}
|
|
1271
1316
|
inspectSubjectSignalConsent(input2) {
|
|
1272
1317
|
return this.request({ method: "POST", path: "/v1/signals/subject-consent/inspect", body: input2 }, { enforcing: true });
|
|
1273
1318
|
}
|
|
@@ -1932,7 +1977,7 @@ var ViraClient = class {
|
|
|
1932
1977
|
return this.request({ method: "POST", path: "/v1/teach/conversations", body: { ...evidence, privacy: evidence.privacy ?? "CONSENTED_TENANT" } }, { idempotencyKey: options.idempotencyKey });
|
|
1933
1978
|
}
|
|
1934
1979
|
listConversationArchive(input2 = {}) {
|
|
1935
|
-
return this.request({ method: "GET", path: "/v1/teach/conversations", query: { ...input2.limit === void 0 ? {} : { limit: String(input2.limit) }, ...input2.cursor ? { cursor: input2.cursor } : {} } });
|
|
1980
|
+
return this.request({ method: "GET", path: "/v1/teach/conversations", query: { ...input2.limit === void 0 ? {} : { limit: String(input2.limit) }, ...input2.cursor ? { cursor: input2.cursor } : {}, ...input2.aiSystemId ? { aiSystemId: input2.aiSystemId } : {} } });
|
|
1936
1981
|
}
|
|
1937
1982
|
importConversationArchive(conversations, options = {}) {
|
|
1938
1983
|
if (!Array.isArray(conversations) || !conversations.length) throw new Error("SDK_CONVERSATION_IMPORT_REQUIRED");
|
|
@@ -1981,10 +2026,12 @@ var ViraClient = class {
|
|
|
1981
2026
|
required(teachRunId, "SDK_TEACH_RUN_ID_REQUIRED");
|
|
1982
2027
|
return this.request({ method: "GET", path: `/v1/teach/runs/${encodeURIComponent(teachRunId)}/recommendation` });
|
|
1983
2028
|
}
|
|
1984
|
-
acceptTeachRecommendation(teachRunId, actorId, options = {}) {
|
|
2029
|
+
async acceptTeachRecommendation(teachRunId, actorId, options = {}) {
|
|
1985
2030
|
required(teachRunId, "SDK_TEACH_RUN_ID_REQUIRED");
|
|
1986
|
-
required(actorId, "SDK_TEACH_RECOMMENDATION_ACTOR_REQUIRED");
|
|
1987
|
-
|
|
2031
|
+
if (actorId !== void 0) required(actorId, "SDK_TEACH_RECOMMENDATION_ACTOR_REQUIRED");
|
|
2032
|
+
if ((options.basePackId !== void 0 || options.basePackDigest !== void 0) && (!options.basePackId?.trim() || !options.basePackDigest || !/^[a-f0-9]{64}$/.test(options.basePackDigest))) throw Error("SDK_TEACH_BASE_PACK_INVALID");
|
|
2033
|
+
const body = { ...actorId === void 0 ? {} : { actorId }, ...options.basePackId === void 0 ? {} : { basePackId: options.basePackId, basePackDigest: options.basePackDigest } };
|
|
2034
|
+
return this.request({ method: "POST", path: `/v1/teach/runs/${encodeURIComponent(teachRunId)}/recommendation/accept`, body }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:teach:recommendation:accept:${teachRunId}`, body) });
|
|
1988
2035
|
}
|
|
1989
2036
|
rejectTeachRecommendation(teachRunId, reason, options = {}) {
|
|
1990
2037
|
required(teachRunId, "SDK_TEACH_RUN_ID_REQUIRED");
|
|
@@ -2013,6 +2060,10 @@ var ViraClient = class {
|
|
|
2013
2060
|
{ idempotencyKey: options.idempotencyKey }
|
|
2014
2061
|
);
|
|
2015
2062
|
}
|
|
2063
|
+
/** Run scoped normal-Pack quality evaluation; does not publish or verify live runtime. */
|
|
2064
|
+
startWholePackQualityEvaluation(input2, options = {}) {
|
|
2065
|
+
return this.startEvaluation({ id: input2.id, aiSystemId: input2.aiSystemId, packId: input2.packId, packDigest: input2.packDigest, dataset: input2.dataset.map((c) => ({ id: c.id, programId: c.programId, input: c.input, rubric: [...c.rubric] })), wholePackEvaluation: true, ...input2.modelSelection ? { modelSelection: input2.modelSelection } : {} }, options);
|
|
2066
|
+
}
|
|
2016
2067
|
/** Request a server-executed OFF/current-ON/candidate-ON comparison.
|
|
2017
2068
|
* The server owns arm execution and receipts; callers cannot submit outputs.
|
|
2018
2069
|
*/
|
|
@@ -2035,7 +2086,7 @@ var ViraClient = class {
|
|
|
2035
2086
|
});
|
|
2036
2087
|
}
|
|
2037
2088
|
listEvaluations(input2 = {}) {
|
|
2038
|
-
return this.request({ method: "GET", path: "/v1/evaluations", query: { ...input2.limit === void 0 ? {} : { limit: String(input2.limit) }, ...input2.cursor ? { cursor: input2.cursor } : {}, ...input2.status ? { status: input2.status } : {} } });
|
|
2089
|
+
return this.request({ method: "GET", path: "/v1/evaluations", query: { ...input2.limit === void 0 ? {} : { limit: String(input2.limit) }, ...input2.cursor ? { cursor: input2.cursor } : {}, ...input2.status ? { status: input2.status } : {}, ...input2.search ? { search: input2.search } : {} } });
|
|
2039
2090
|
}
|
|
2040
2091
|
getEvaluationComparison(evaluationId) {
|
|
2041
2092
|
required(evaluationId, "SDK_EVALUATION_ID_REQUIRED");
|
|
@@ -2087,9 +2138,9 @@ var ViraClient = class {
|
|
|
2087
2138
|
if (!Array.isArray(input2.dataset) || input2.dataset.length === 0) throw new Error("SDK_CANDIDATE_EVALUATION_DATASET_REQUIRED");
|
|
2088
2139
|
return this.request({ method: "POST", path: `/v1/behavior-revision-candidates/${encodeURIComponent(candidateId)}/evaluate`, body: input2 }, { idempotencyKey: options.idempotencyKey ?? `sdk:behavior-candidate:evaluate:${candidateId}` });
|
|
2089
2140
|
}
|
|
2090
|
-
transitionBehaviorRevisionCandidate(candidateId, transition, input2 = {}, options = {}) {
|
|
2141
|
+
async transitionBehaviorRevisionCandidate(candidateId, transition, input2 = {}, options = {}) {
|
|
2091
2142
|
required(candidateId, "SDK_BEHAVIOR_CANDIDATE_ID_REQUIRED");
|
|
2092
|
-
return this.request({ method: "POST", path: `/v1/behavior-revision-candidates/${encodeURIComponent(candidateId)}/${transition}`, body: input2 }, { idempotencyKey: options.idempotencyKey ?? `sdk:behavior-candidate:${transition}:${candidateId}
|
|
2143
|
+
return this.request({ method: "POST", path: `/v1/behavior-revision-candidates/${encodeURIComponent(candidateId)}/${transition}`, body: input2 }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:behavior-candidate:${transition}:${candidateId}`, input2) });
|
|
2093
2144
|
}
|
|
2094
2145
|
createPackRevision(input2, options = {}) {
|
|
2095
2146
|
return this.request({ method: "POST", path: "/v1/pack-revisions", body: input2 }, { idempotencyKey: options.idempotencyKey });
|
|
@@ -2214,6 +2265,9 @@ var ViraClient = class {
|
|
|
2214
2265
|
freezeDepartmentOptimizationDataset(input2) {
|
|
2215
2266
|
return this.request({ method: "POST", path: "/v1/optimization/dataset-freeze", body: input2 }, { enforcing: true });
|
|
2216
2267
|
}
|
|
2268
|
+
inspectDepartmentOptimizationDataset(input2) {
|
|
2269
|
+
return this.request({ method: "POST", path: "/v1/optimization/dataset-inspect", body: input2 }, { enforcing: true });
|
|
2270
|
+
}
|
|
2217
2271
|
listDepartmentOptimizationDatasets(input2) {
|
|
2218
2272
|
return this.request({ method: "POST", path: "/v1/optimization/dataset-options", body: input2 }, { enforcing: true });
|
|
2219
2273
|
}
|
|
@@ -2514,15 +2568,18 @@ function createViraHostRuntime(client, config2) {
|
|
|
2514
2568
|
if (mode === "enforce" && typeof config2.authorizeAction !== "function") throw new Error("SDK_HOST_ACTION_AUTHORIZER_REQUIRED");
|
|
2515
2569
|
let connected = null;
|
|
2516
2570
|
let connectionIdentity = null;
|
|
2571
|
+
let connectionGeneration = 0;
|
|
2517
2572
|
const projections = /* @__PURE__ */ new Map();
|
|
2518
2573
|
const activeToolSessions = /* @__PURE__ */ new Map();
|
|
2519
2574
|
const connectOnce = async (options = {}) => {
|
|
2520
2575
|
if (mode === "off" || !config2.connect) return null;
|
|
2521
2576
|
if (options.force) {
|
|
2577
|
+
++connectionGeneration;
|
|
2522
2578
|
connected = null;
|
|
2523
2579
|
connectionIdentity = null;
|
|
2524
2580
|
}
|
|
2525
2581
|
if (!connected) {
|
|
2582
|
+
const generation = ++connectionGeneration;
|
|
2526
2583
|
const attempt = withTimeout(client.connectOnce(config2.connect), timeoutMs, "SDK_HOST_CONNECT_TIMEOUT").then((result) => {
|
|
2527
2584
|
const body = bodyOf(result);
|
|
2528
2585
|
const system = body.system && typeof body.system === "object" ? body.system : {};
|
|
@@ -2530,13 +2587,16 @@ function createViraHostRuntime(client, config2) {
|
|
|
2530
2587
|
const aiSystemId = typeof system.id === "string" ? system.id.trim() : "";
|
|
2531
2588
|
const connectionId = typeof connection.id === "string" ? connection.id.trim() : "";
|
|
2532
2589
|
if (!aiSystemId || !connectionId) throw new Error("SDK_HOST_CONNECT_IDENTITY_MISSING");
|
|
2590
|
+
if (generation !== connectionGeneration) throw Error("SDK_HOST_CONNECT_SUPERSEDED");
|
|
2533
2591
|
connectionIdentity = { aiSystemId, connectionId };
|
|
2534
2592
|
return result;
|
|
2535
2593
|
});
|
|
2536
2594
|
let cachedAttempt;
|
|
2537
2595
|
cachedAttempt = attempt.catch((error62) => {
|
|
2538
|
-
if (connected === cachedAttempt
|
|
2539
|
-
|
|
2596
|
+
if (connected === cachedAttempt && generation === connectionGeneration) {
|
|
2597
|
+
connected = null;
|
|
2598
|
+
connectionIdentity = null;
|
|
2599
|
+
}
|
|
2540
2600
|
throw error62;
|
|
2541
2601
|
});
|
|
2542
2602
|
connected = cachedAttempt;
|
|
@@ -22940,6 +23000,7 @@ var createV1PromptCache = (ttlMs) => {
|
|
|
22940
23000
|
return { set(sessionId, prompt) {
|
|
22941
23001
|
clear(sessionId);
|
|
22942
23002
|
const timer = setTimeout(() => entries.delete(sessionId), ttl);
|
|
23003
|
+
timer.unref?.();
|
|
22943
23004
|
entries.set(sessionId, { prompt, timer });
|
|
22944
23005
|
}, peek(sessionId) {
|
|
22945
23006
|
return entries.get(sessionId)?.prompt;
|
|
@@ -22988,7 +23049,7 @@ async function resolveOpenCodeCredentialScope(client, options, machine) {
|
|
|
22988
23049
|
async function assertOpenCodeMachineConnection(client, scope, aiSystemId, connectionId) {
|
|
22989
23050
|
if (!aiSystemId || !connectionId) throw Error("VIRA_MACHINE_PREPROVISIONED_CONNECTION_REQUIRED");
|
|
22990
23051
|
const response = await client.getConnection(connectionId);
|
|
22991
|
-
if (response?.body?.systemId !== aiSystemId || response.body.connection?.id !== connectionId || ["organizationId", "projectId", "environmentId", "organizationUnitId"].some((key) => response.body.scope?.[key] !== scope[key]))
|
|
23052
|
+
if (response?.body?.systemId !== aiSystemId || response.body.connection?.id !== connectionId || response.body.connection.status !== "CONNECTED" || response.body.connection.aiSystemId !== aiSystemId || ["organizationId", "projectId", "environmentId", "organizationUnitId"].some((key) => response.body.scope?.[key] !== scope[key]))
|
|
22992
23053
|
throw Error("VIRA_MACHINE_CONNECTION_SCOPE_MISMATCH");
|
|
22993
23054
|
}
|
|
22994
23055
|
var readHostOptions = (rawContext) => {
|
|
@@ -23251,12 +23312,12 @@ var v2Plugin = Plugin.define({
|
|
|
23251
23312
|
try {
|
|
23252
23313
|
const listed = await client.listAISystems();
|
|
23253
23314
|
const systems = Array.isArray(listed?.body?.systems) ? listed.body.systems : [];
|
|
23254
|
-
const system = systems.find((item) => String(item.name ?? "") === "OpenCode" && String(item.systemType ?? "") === "agent" && String(item.organizationId ?? "") === scope.organizationId && String(item.projectId ?? "") === scope.projectId && String(item.environmentId ?? "") === scope.environmentId);
|
|
23315
|
+
const system = systems.find((item) => item.status === "ACTIVE" && String(item.name ?? "") === "OpenCode" && String(item.systemType ?? "") === "agent" && String(item.organizationId ?? "") === scope.organizationId && String(item.projectId ?? "") === scope.projectId && String(item.environmentId ?? "") === scope.environmentId);
|
|
23255
23316
|
if (system?.id) {
|
|
23256
23317
|
const connections = await client.listSystemConnections(String(system.id));
|
|
23257
23318
|
const connectionRows = Array.isArray(connections?.body?.connections) ? connections.body.connections : [];
|
|
23258
23319
|
const requested = new Set(openCodeConnectConfig(scope, options).capabilities);
|
|
23259
|
-
const connection = connectionRows.find((item) => String(item.adapterType ?? "") === "custom-node" && requested.size <= (Array.isArray(item.capabilities) ? item.capabilities.length : 0) && [...requested].every((capability) => Array.isArray(item.capabilities) && item.capabilities.includes(capability)));
|
|
23320
|
+
const connection = connectionRows.find((item) => item.status === "CONNECTED" && item.aiSystemId === system.id && String(item.adapterType ?? "") === "custom-node" && requested.size <= (Array.isArray(item.capabilities) ? item.capabilities.length : 0) && [...requested].every((capability) => Array.isArray(item.capabilities) && item.capabilities.includes(capability)));
|
|
23260
23321
|
if (connection?.id) {
|
|
23261
23322
|
bootstrapAiSystemId = String(system.id);
|
|
23262
23323
|
bootstrapConnectionId = String(connection.id);
|
package/dist/tui.js
CHANGED
|
@@ -215,7 +215,7 @@ var ViraClient = class {
|
|
|
215
215
|
...this.defaultHeaders
|
|
216
216
|
};
|
|
217
217
|
if (request.body) headers["content-type"] = "application/json";
|
|
218
|
-
const operatorOperation = /^\/v1\/(?:billing\/legacy-pricing\/(?:inspect|propose|approve)|behavior-policy-bindings\/reconciliation\/(?:inspect|propose|approve|history|remediation-inspect|remediation-propose|remediation-approve|remediation-history)|signals\/subject-consent\/(?:inspect|grant|withdraw)|teach\/subject-evidence\/(?:admit|withdraw|history))$/.test(request.path);
|
|
218
|
+
const operatorOperation = /^\/v1\/(?:billing\/legacy-pricing\/(?:inspect|propose|approve)|behavior-policy-bindings\/reconciliation\/(?:inspect|propose|approve|history|remediation-inspect|remediation-propose|remediation-approve|remediation-history)|signals\/subject-consent\/(?:inspect|grant|withdraw|inventory|history)|connections\/[^/]+\/revoke|teach\/subject-evidence\/(?:admit|withdraw|history))$/.test(request.path);
|
|
219
219
|
if (operatorOperation) {
|
|
220
220
|
if (Object.keys(headers).some((key) => ["authorization", "x-vira-api-key", "x-vira-delegation", "x-vira-taskrun-delegation", "x-vira-optimizer-grant", "cookie"].includes(key.toLowerCase())))
|
|
221
221
|
throw new Error("SDK_OPERATOR_MIXED_AUTHORITY_FORBIDDEN");
|
|
@@ -670,7 +670,7 @@ var ViraClient = class {
|
|
|
670
670
|
if (!listed) throw error;
|
|
671
671
|
const systems = Array.isArray(listed?.body?.systems) ? listed.body.systems : [];
|
|
672
672
|
const reused = systems.find(
|
|
673
|
-
(system) => String(system.name ?? "") === input.name && String(system.systemType ?? "") === input.systemType && String(system.organizationId ?? "") === input.organizationId && String(system.projectId ?? "") === input.projectId && String(system.environmentId ?? "") === input.environmentId
|
|
673
|
+
(system) => system.status === "ACTIVE" && String(system.name ?? "") === input.name && String(system.systemType ?? "") === input.systemType && String(system.organizationId ?? "") === input.organizationId && String(system.projectId ?? "") === input.projectId && String(system.environmentId ?? "") === input.environmentId
|
|
674
674
|
);
|
|
675
675
|
if (!reused) throw error;
|
|
676
676
|
systemResult = { status: listed.status, requestId: listed.requestId, body: { system: reused } };
|
|
@@ -693,11 +693,11 @@ var ViraClient = class {
|
|
|
693
693
|
const listed = await this.listSystemConnections(systemId);
|
|
694
694
|
const connections = Array.isArray(listed?.body?.connections) ? listed.body.connections : [];
|
|
695
695
|
const requested = new Set((input.capabilities ?? []).map(String));
|
|
696
|
-
const reused = connections.find((connection) => String(connection.adapterType ?? "") === input.adapterType && requested.size <= new Set(Array.isArray(connection.capabilities) ? connection.capabilities.map(String) : []).size && [...requested].every((capability) => (Array.isArray(connection.capabilities) ? connection.capabilities.map(String) : []).includes(capability)));
|
|
696
|
+
const reused = connections.find((connection) => connection.status === "CONNECTED" && connection.aiSystemId === systemId && String(connection.adapterType ?? "") === input.adapterType && requested.size <= new Set(Array.isArray(connection.capabilities) ? connection.capabilities.map(String) : []).size && [...requested].every((capability) => (Array.isArray(connection.capabilities) ? connection.capabilities.map(String) : []).includes(capability)));
|
|
697
697
|
if (!reused) throw error;
|
|
698
698
|
const verified = await this.getConnection(String(reused.id ?? ""));
|
|
699
699
|
const verifiedConnection = verified?.body?.connection && typeof verified.body.connection === "object" ? verified.body.connection : null;
|
|
700
|
-
if (!verifiedConnection || String(verifiedConnection.adapterType ?? "") !== input.adapterType) throw error;
|
|
700
|
+
if (!verifiedConnection || verifiedConnection.status !== "CONNECTED" || verifiedConnection.id !== reused.id || verifiedConnection.aiSystemId !== systemId || String(verifiedConnection.adapterType ?? "") !== input.adapterType) throw error;
|
|
701
701
|
const verifiedCapabilities = Array.isArray(verifiedConnection.capabilities) ? verifiedConnection.capabilities.map(String) : [];
|
|
702
702
|
if (![...requested].every((capability) => verifiedCapabilities.includes(capability))) throw error;
|
|
703
703
|
const fromVersion = String(verifiedConnection.adapterVersion ?? "");
|
|
@@ -706,7 +706,8 @@ var ViraClient = class {
|
|
|
706
706
|
}
|
|
707
707
|
if (!connectionResult) return null;
|
|
708
708
|
const connectedId = String(connectionResult.body.connection.id ?? "").trim();
|
|
709
|
-
if (connectedId
|
|
709
|
+
if (!connectedId || connectionResult.body.connection.status !== "CONNECTED" || connectionResult.body.connection.aiSystemId !== systemId) throw Error("SDK_CONNECTION_AUTHORITY_INVALID");
|
|
710
|
+
this.boundConnectionId = connectedId;
|
|
710
711
|
return {
|
|
711
712
|
status: connectionResult.status,
|
|
712
713
|
requestId: connectionResult.requestId,
|
|
@@ -954,6 +955,26 @@ var ViraClient = class {
|
|
|
954
955
|
query: { ...options.reviewState ? { reviewState: options.reviewState } : {}, ...listQuery(normalized) }
|
|
955
956
|
});
|
|
956
957
|
}
|
|
958
|
+
listReusableEvaluationDatasets(systemId, cursor) {
|
|
959
|
+
return this.request({ method: "GET", path: `/v1/ai-systems/${encodeURIComponent(systemId)}/evaluation-datasets`, query: cursor ? { cursor } : {} }, { enforcing: true });
|
|
960
|
+
}
|
|
961
|
+
getReusableEvaluationDataset(systemId, datasetId, datasetDigest) {
|
|
962
|
+
return this.request({ method: "GET", path: `/v1/ai-systems/${encodeURIComponent(systemId)}/evaluation-datasets/${encodeURIComponent(datasetId)}`, query: { datasetDigest } }, { enforcing: true });
|
|
963
|
+
}
|
|
964
|
+
getFeatureCreditPreview(systemId, feature, model) {
|
|
965
|
+
return this.request({ method: "GET", path: `/v1/ai-systems/${encodeURIComponent(systemId)}/ai-credit-preview/${encodeURIComponent(feature)}`, ...model ? { query: { providerId: model.providerId, modelId: model.modelId } } : {} }, { enforcing: true });
|
|
966
|
+
}
|
|
967
|
+
getDiscoveryWorkerHealth() {
|
|
968
|
+
return this.request({ method: "GET", path: "/v1/discovery/worker-health" }, { enforcing: true });
|
|
969
|
+
}
|
|
970
|
+
getDiscoveryDispatch(eventId) {
|
|
971
|
+
required(eventId, "SDK_OBSERVATION_EVENT_ID_REQUIRED");
|
|
972
|
+
return this.request({ method: "GET", path: `/v1/discovery/observations/${encodeURIComponent(eventId)}/dispatch` }, { enforcing: true });
|
|
973
|
+
}
|
|
974
|
+
async queueDiscoveryDispatch(eventId, options = {}) {
|
|
975
|
+
required(eventId, "SDK_OBSERVATION_EVENT_ID_REQUIRED");
|
|
976
|
+
return this.request({ method: "POST", path: `/v1/discovery/observations/${encodeURIComponent(eventId)}/dispatch`, body: {} }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey("sdk:discovery-dispatch", { eventId }), enforcing: true });
|
|
977
|
+
}
|
|
957
978
|
async reviewDiscoveryCandidate(kind, key, input, options = {}) {
|
|
958
979
|
required(kind, "SDK_DISCOVERY_CANDIDATE_KIND_REQUIRED");
|
|
959
980
|
required(key, "SDK_DISCOVERY_CANDIDATE_KEY_REQUIRED");
|
|
@@ -967,6 +988,15 @@ var ViraClient = class {
|
|
|
967
988
|
const invocationId = globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
968
989
|
return this.request({ method: "POST", path, body }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:discovery-review:${kind}:${key}`, { invocationId, body }), enforcing: true });
|
|
969
990
|
}
|
|
991
|
+
/** Create a review-only department draft from approved semantic evidence. */
|
|
992
|
+
async createDepartmentDiscoveryDraft(key, input, options = {}) {
|
|
993
|
+
required(key, "SDK_DISCOVERY_CANDIDATE_KEY_REQUIRED");
|
|
994
|
+
required(input.candidateId, "SDK_DISCOVERY_CANDIDATE_ID_REQUIRED");
|
|
995
|
+
required(input.aiSystemId, "SDK_AI_SYSTEM_ID_REQUIRED");
|
|
996
|
+
if (!Array.isArray(input.evidenceIds) || !input.evidenceIds.length || input.evidenceIds.length > 200 || input.evidenceIds.some((id) => typeof id !== "string" || !id.trim()) || new Set(input.evidenceIds).size !== input.evidenceIds.length) throw Error("SDK_DISCOVERY_DRAFT_EVIDENCE_INVALID");
|
|
997
|
+
const body = { candidateId: input.candidateId, aiSystemId: input.aiSystemId, evidenceIds: [...input.evidenceIds] };
|
|
998
|
+
return this.request({ method: "POST", path: `/v1/discovery/candidates/semantic_task/${encodeURIComponent(key)}/department-draft`, body }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:discovery-draft:${key}`, body), enforcing: true });
|
|
999
|
+
}
|
|
970
1000
|
/** Explicit canonical publication; API approval and scope checks still apply. */
|
|
971
1001
|
publishDiscoveryCandidate(kind, key, input = {}, options = {}) {
|
|
972
1002
|
required(kind, "SDK_DISCOVERY_CANDIDATE_KIND_REQUIRED");
|
|
@@ -1103,7 +1133,8 @@ var ViraClient = class {
|
|
|
1103
1133
|
}
|
|
1104
1134
|
async approvePack(packId, options = {}) {
|
|
1105
1135
|
required(packId, "SDK_PACK_ID_REQUIRED");
|
|
1106
|
-
const
|
|
1136
|
+
const approval = options.manualApproval ? { manualApproval: true, reason: required(options.reason ?? "", "SDK_MANUAL_PACK_APPROVAL_REASON_REQUIRED") } : {};
|
|
1137
|
+
const body = { ...approval, ...options.expectedPackDigest === void 0 ? {} : { expectedPackDigest: options.expectedPackDigest } };
|
|
1107
1138
|
return this.request(
|
|
1108
1139
|
{
|
|
1109
1140
|
method: "POST",
|
|
@@ -1113,15 +1144,16 @@ var ViraClient = class {
|
|
|
1113
1144
|
{ idempotencyKey: await contentIdempotencyKey(`sdk:pack:approve:${packId}`, body) }
|
|
1114
1145
|
);
|
|
1115
1146
|
}
|
|
1116
|
-
async releasePack(packId) {
|
|
1147
|
+
async releasePack(packId, options = {}) {
|
|
1117
1148
|
required(packId, "SDK_PACK_ID_REQUIRED");
|
|
1149
|
+
const body = options.expectedPackDigest === void 0 ? {} : { expectedPackDigest: options.expectedPackDigest };
|
|
1118
1150
|
return this.request(
|
|
1119
1151
|
{
|
|
1120
1152
|
method: "POST",
|
|
1121
1153
|
path: `/v1/packs/${encodeURIComponent(packId)}/release`,
|
|
1122
|
-
body
|
|
1154
|
+
body
|
|
1123
1155
|
},
|
|
1124
|
-
{ idempotencyKey: await contentIdempotencyKey(`sdk:pack:release:${packId}`,
|
|
1156
|
+
{ idempotencyKey: await contentIdempotencyKey(`sdk:pack:release:${packId}`, body) }
|
|
1125
1157
|
);
|
|
1126
1158
|
}
|
|
1127
1159
|
async previewPackUpgrade(packId, incoming) {
|
|
@@ -1238,6 +1270,19 @@ var ViraClient = class {
|
|
|
1238
1270
|
historyLegacyRecordRemediation(input = {}) {
|
|
1239
1271
|
return this.request({ method: "POST", path: "/v1/behavior-policy-bindings/reconciliation/remediation-history", body: input }, { enforcing: true });
|
|
1240
1272
|
}
|
|
1273
|
+
/** Native operator delegation only; never a machine key or MCP mutation. */
|
|
1274
|
+
revokeConnection(connectionId, input) {
|
|
1275
|
+
required(connectionId, "SDK_CONNECTION_ID_REQUIRED");
|
|
1276
|
+
required(input.aiSystemId, "SDK_SYSTEM_ID_REQUIRED");
|
|
1277
|
+
if (input.confirm !== true) throw Error("SDK_CONNECTION_REVOCATION_CONFIRMATION_REQUIRED");
|
|
1278
|
+
return this.request({ method: "POST", path: `/v1/connections/${encodeURIComponent(connectionId)}/revoke`, body: { aiSystemId: input.aiSystemId, confirm: true } }, { enforcing: true });
|
|
1279
|
+
}
|
|
1280
|
+
inventorySubjectSignalConsent() {
|
|
1281
|
+
return this.request({ method: "POST", path: "/v1/signals/subject-consent/inventory", body: {} }, { enforcing: true });
|
|
1282
|
+
}
|
|
1283
|
+
historySubjectSignalConsent() {
|
|
1284
|
+
return this.request({ method: "POST", path: "/v1/signals/subject-consent/history", body: {} }, { enforcing: true });
|
|
1285
|
+
}
|
|
1241
1286
|
inspectSubjectSignalConsent(input) {
|
|
1242
1287
|
return this.request({ method: "POST", path: "/v1/signals/subject-consent/inspect", body: input }, { enforcing: true });
|
|
1243
1288
|
}
|
|
@@ -1902,7 +1947,7 @@ var ViraClient = class {
|
|
|
1902
1947
|
return this.request({ method: "POST", path: "/v1/teach/conversations", body: { ...evidence, privacy: evidence.privacy ?? "CONSENTED_TENANT" } }, { idempotencyKey: options.idempotencyKey });
|
|
1903
1948
|
}
|
|
1904
1949
|
listConversationArchive(input = {}) {
|
|
1905
|
-
return this.request({ method: "GET", path: "/v1/teach/conversations", query: { ...input.limit === void 0 ? {} : { limit: String(input.limit) }, ...input.cursor ? { cursor: input.cursor } : {} } });
|
|
1950
|
+
return this.request({ method: "GET", path: "/v1/teach/conversations", query: { ...input.limit === void 0 ? {} : { limit: String(input.limit) }, ...input.cursor ? { cursor: input.cursor } : {}, ...input.aiSystemId ? { aiSystemId: input.aiSystemId } : {} } });
|
|
1906
1951
|
}
|
|
1907
1952
|
importConversationArchive(conversations, options = {}) {
|
|
1908
1953
|
if (!Array.isArray(conversations) || !conversations.length) throw new Error("SDK_CONVERSATION_IMPORT_REQUIRED");
|
|
@@ -1951,10 +1996,12 @@ var ViraClient = class {
|
|
|
1951
1996
|
required(teachRunId, "SDK_TEACH_RUN_ID_REQUIRED");
|
|
1952
1997
|
return this.request({ method: "GET", path: `/v1/teach/runs/${encodeURIComponent(teachRunId)}/recommendation` });
|
|
1953
1998
|
}
|
|
1954
|
-
acceptTeachRecommendation(teachRunId, actorId, options = {}) {
|
|
1999
|
+
async acceptTeachRecommendation(teachRunId, actorId, options = {}) {
|
|
1955
2000
|
required(teachRunId, "SDK_TEACH_RUN_ID_REQUIRED");
|
|
1956
|
-
required(actorId, "SDK_TEACH_RECOMMENDATION_ACTOR_REQUIRED");
|
|
1957
|
-
|
|
2001
|
+
if (actorId !== void 0) required(actorId, "SDK_TEACH_RECOMMENDATION_ACTOR_REQUIRED");
|
|
2002
|
+
if ((options.basePackId !== void 0 || options.basePackDigest !== void 0) && (!options.basePackId?.trim() || !options.basePackDigest || !/^[a-f0-9]{64}$/.test(options.basePackDigest))) throw Error("SDK_TEACH_BASE_PACK_INVALID");
|
|
2003
|
+
const body = { ...actorId === void 0 ? {} : { actorId }, ...options.basePackId === void 0 ? {} : { basePackId: options.basePackId, basePackDigest: options.basePackDigest } };
|
|
2004
|
+
return this.request({ method: "POST", path: `/v1/teach/runs/${encodeURIComponent(teachRunId)}/recommendation/accept`, body }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:teach:recommendation:accept:${teachRunId}`, body) });
|
|
1958
2005
|
}
|
|
1959
2006
|
rejectTeachRecommendation(teachRunId, reason, options = {}) {
|
|
1960
2007
|
required(teachRunId, "SDK_TEACH_RUN_ID_REQUIRED");
|
|
@@ -1983,6 +2030,10 @@ var ViraClient = class {
|
|
|
1983
2030
|
{ idempotencyKey: options.idempotencyKey }
|
|
1984
2031
|
);
|
|
1985
2032
|
}
|
|
2033
|
+
/** Run scoped normal-Pack quality evaluation; does not publish or verify live runtime. */
|
|
2034
|
+
startWholePackQualityEvaluation(input, options = {}) {
|
|
2035
|
+
return this.startEvaluation({ id: input.id, aiSystemId: input.aiSystemId, packId: input.packId, packDigest: input.packDigest, dataset: input.dataset.map((c) => ({ id: c.id, programId: c.programId, input: c.input, rubric: [...c.rubric] })), wholePackEvaluation: true, ...input.modelSelection ? { modelSelection: input.modelSelection } : {} }, options);
|
|
2036
|
+
}
|
|
1986
2037
|
/** Request a server-executed OFF/current-ON/candidate-ON comparison.
|
|
1987
2038
|
* The server owns arm execution and receipts; callers cannot submit outputs.
|
|
1988
2039
|
*/
|
|
@@ -2005,7 +2056,7 @@ var ViraClient = class {
|
|
|
2005
2056
|
});
|
|
2006
2057
|
}
|
|
2007
2058
|
listEvaluations(input = {}) {
|
|
2008
|
-
return this.request({ method: "GET", path: "/v1/evaluations", query: { ...input.limit === void 0 ? {} : { limit: String(input.limit) }, ...input.cursor ? { cursor: input.cursor } : {}, ...input.status ? { status: input.status } : {} } });
|
|
2059
|
+
return this.request({ method: "GET", path: "/v1/evaluations", query: { ...input.limit === void 0 ? {} : { limit: String(input.limit) }, ...input.cursor ? { cursor: input.cursor } : {}, ...input.status ? { status: input.status } : {}, ...input.search ? { search: input.search } : {} } });
|
|
2009
2060
|
}
|
|
2010
2061
|
getEvaluationComparison(evaluationId) {
|
|
2011
2062
|
required(evaluationId, "SDK_EVALUATION_ID_REQUIRED");
|
|
@@ -2057,9 +2108,9 @@ var ViraClient = class {
|
|
|
2057
2108
|
if (!Array.isArray(input.dataset) || input.dataset.length === 0) throw new Error("SDK_CANDIDATE_EVALUATION_DATASET_REQUIRED");
|
|
2058
2109
|
return this.request({ method: "POST", path: `/v1/behavior-revision-candidates/${encodeURIComponent(candidateId)}/evaluate`, body: input }, { idempotencyKey: options.idempotencyKey ?? `sdk:behavior-candidate:evaluate:${candidateId}` });
|
|
2059
2110
|
}
|
|
2060
|
-
transitionBehaviorRevisionCandidate(candidateId, transition, input = {}, options = {}) {
|
|
2111
|
+
async transitionBehaviorRevisionCandidate(candidateId, transition, input = {}, options = {}) {
|
|
2061
2112
|
required(candidateId, "SDK_BEHAVIOR_CANDIDATE_ID_REQUIRED");
|
|
2062
|
-
return this.request({ method: "POST", path: `/v1/behavior-revision-candidates/${encodeURIComponent(candidateId)}/${transition}`, body: input }, { idempotencyKey: options.idempotencyKey ?? `sdk:behavior-candidate:${transition}:${candidateId}
|
|
2113
|
+
return this.request({ method: "POST", path: `/v1/behavior-revision-candidates/${encodeURIComponent(candidateId)}/${transition}`, body: input }, { idempotencyKey: options.idempotencyKey ?? await contentIdempotencyKey(`sdk:behavior-candidate:${transition}:${candidateId}`, input) });
|
|
2063
2114
|
}
|
|
2064
2115
|
createPackRevision(input, options = {}) {
|
|
2065
2116
|
return this.request({ method: "POST", path: "/v1/pack-revisions", body: input }, { idempotencyKey: options.idempotencyKey });
|
|
@@ -2184,6 +2235,9 @@ var ViraClient = class {
|
|
|
2184
2235
|
freezeDepartmentOptimizationDataset(input) {
|
|
2185
2236
|
return this.request({ method: "POST", path: "/v1/optimization/dataset-freeze", body: input }, { enforcing: true });
|
|
2186
2237
|
}
|
|
2238
|
+
inspectDepartmentOptimizationDataset(input) {
|
|
2239
|
+
return this.request({ method: "POST", path: "/v1/optimization/dataset-inspect", body: input }, { enforcing: true });
|
|
2240
|
+
}
|
|
2187
2241
|
listDepartmentOptimizationDatasets(input) {
|
|
2188
2242
|
return this.request({ method: "POST", path: "/v1/optimization/dataset-options", body: input }, { enforcing: true });
|
|
2189
2243
|
}
|
|
@@ -2433,6 +2487,112 @@ async function selectSessionTaskRun(client, identity, active) {
|
|
|
2433
2487
|
return selected;
|
|
2434
2488
|
}
|
|
2435
2489
|
|
|
2490
|
+
// src/tui-teach-review.ts
|
|
2491
|
+
var record3 = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
2492
|
+
var clean = (value) => typeof value === "string" && value.length > 0 && value.length <= 1024 && value === value.trim() && !/[\u0000-\u001f\u007f]/.test(value);
|
|
2493
|
+
var validTeachRunId = clean;
|
|
2494
|
+
var scopeKeys = ["organizationId", "projectId", "environmentId", "organizationUnitId"];
|
|
2495
|
+
var matches = (actual, expected) => scopeKeys.every((key) => record3(actual)[key] === expected[key]);
|
|
2496
|
+
async function readOpenCodeTeachReview(client, identity, id, active) {
|
|
2497
|
+
if (!clean(id) || !Object.values(identity).every(clean) || !active()) throw Error("OPENCODE_TEACH_REVIEW_SCOPE_REQUIRED");
|
|
2498
|
+
const { aiSystemId, ...scope } = identity;
|
|
2499
|
+
const confirmed = await client.resolveCredentialScope(scope, { requireDepartment: true });
|
|
2500
|
+
if (!active() || !matches(confirmed, scope)) throw Error("OPENCODE_TEACH_REVIEW_SCOPE_MISMATCH");
|
|
2501
|
+
const response = record3(await client.getTeachRunRecommendation(id)), body = record3(response.body);
|
|
2502
|
+
if (!active() || response.status !== 200 || body.source !== "teach" || body.teachRunId !== id || !matches(body.scope, scope) || !Array.isArray(body.aiSystemIds) || !body.aiSystemIds.includes(aiSystemId) || body.aiSystemIds.some((x) => !clean(x)) || new Set(body.aiSystemIds).size !== body.aiSystemIds.length || typeof body.runDigest !== "string" || !/^[a-f0-9]{64}$/.test(body.runDigest) || body.reviewRequired !== true || body.directPublishAllowed !== false || !body.behaviorSet || typeof body.behaviorSet !== "object" || Array.isArray(body.behaviorSet) || body.accepted === true && body.rejected === true) throw Error("OPENCODE_TEACH_REVIEW_READBACK_MISMATCH");
|
|
2503
|
+
return { id, runDigest: body.runDigest, status: body.accepted === true ? "ACCEPTED" : body.rejected === true ? "REJECTED" : "REVIEW_REQUIRED", basePack: body.basePack ?? null, behaviorSet: body.behaviorSet };
|
|
2504
|
+
}
|
|
2505
|
+
function formatTeachReview(review) {
|
|
2506
|
+
return JSON.stringify(review, null, 2).replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/g, "") + "\n\nRead only. Review or modify through authorized Studio/MCP; no release was created.";
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2509
|
+
// src/tui-discovery.ts
|
|
2510
|
+
var record4 = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
2511
|
+
var clean2 = (v) => typeof v === "string" && v.length > 0 && v.length <= 512 && v === v.trim() && !/[\\/?#%\u0000-\u001f\u007f]/.test(v) && v !== "." && v !== "..";
|
|
2512
|
+
var validDiscoveryEventId = clean2;
|
|
2513
|
+
var scopeKeys2 = ["organizationId", "projectId", "environmentId", "organizationUnitId"];
|
|
2514
|
+
async function authorize(client, identity, active) {
|
|
2515
|
+
if (!Object.values(identity).every(clean2) || !active()) throw Error("OPENCODE_DISCOVERY_SCOPE_REQUIRED");
|
|
2516
|
+
const scope = Object.fromEntries(scopeKeys2.map((k) => [k, identity[k]]));
|
|
2517
|
+
const actual = record4(await client.resolveCredentialScope(scope, { requireDepartment: true }));
|
|
2518
|
+
if (!active() || !scopeKeys2.every((k) => actual[k] === scope[k])) throw Error("OPENCODE_DISCOVERY_SCOPE_MISMATCH");
|
|
2519
|
+
}
|
|
2520
|
+
function readDispatch(response, identity, id, status) {
|
|
2521
|
+
const result = record4(response), body = record4(result.body);
|
|
2522
|
+
if (result.status !== status || body.eventId !== id || body.aiSystemId !== identity.aiSystemId || body.connectionId !== identity.connectionId || typeof body.jobId !== "string" || !/^discovery_[a-f0-9]{24}$/.test(body.jobId) || !["NOT_QUEUED", "QUEUED", "RUNNING", "SUCCEEDED", "FAILED"].includes(String(body.state)) || typeof body.attempts !== "number" || !Number.isSafeInteger(body.attempts) || body.attempts < 0 || !(body.availableAt === null || typeof body.availableAt === "string" && Number.isFinite(Date.parse(body.availableAt)))) throw Error("OPENCODE_DISCOVERY_READBACK_MISMATCH");
|
|
2523
|
+
return { eventId: id, jobId: body.jobId, state: String(body.state), attempts: body.attempts, availableAt: body.availableAt };
|
|
2524
|
+
}
|
|
2525
|
+
async function readOpenCodeDiscovery(client, identity, id, active) {
|
|
2526
|
+
if (!clean2(id)) throw Error("OPENCODE_DISCOVERY_EVENT_REQUIRED");
|
|
2527
|
+
await authorize(client, identity, active);
|
|
2528
|
+
const dispatch = readDispatch(await client.getDiscoveryDispatch(id), identity, id, 200);
|
|
2529
|
+
if (!active()) throw Error("OPENCODE_DISCOVERY_SESSION_CHANGED");
|
|
2530
|
+
let worker = null;
|
|
2531
|
+
try {
|
|
2532
|
+
const result = record4(await client.getDiscoveryWorkerHealth()), body = record4(result.body);
|
|
2533
|
+
if (result.status === 200 && ["RECENT_SCAN", "SCANNING", "STALE", "FAILED", "UNAVAILABLE"].includes(String(body.status)) && (body.lastSuccessfulScanAt === null || typeof body.lastSuccessfulScanAt === "string" && Number.isFinite(Date.parse(body.lastSuccessfulScanAt)))) worker = { status: String(body.status), lastSuccessfulScanAt: body.lastSuccessfulScanAt };
|
|
2534
|
+
} catch {
|
|
2535
|
+
}
|
|
2536
|
+
if (!active()) throw Error("OPENCODE_DISCOVERY_SESSION_CHANGED");
|
|
2537
|
+
return { dispatch, worker };
|
|
2538
|
+
}
|
|
2539
|
+
async function queueOpenCodeDiscovery(client, identity, id, confirm, active) {
|
|
2540
|
+
const prior = await readOpenCodeDiscovery(client, identity, id, active);
|
|
2541
|
+
if (prior.dispatch.state !== "NOT_QUEUED") return { queued: false, dispatch: prior.dispatch };
|
|
2542
|
+
if (!await confirm(prior.dispatch.jobId) || !active()) return { queued: false, dispatch: prior.dispatch };
|
|
2543
|
+
await authorize(client, identity, active);
|
|
2544
|
+
const current = readDispatch(await client.getDiscoveryDispatch(id), identity, id, 200);
|
|
2545
|
+
if (!active() || current.jobId !== prior.dispatch.jobId) throw Error("OPENCODE_DISCOVERY_READBACK_MISMATCH");
|
|
2546
|
+
if (current.state !== "NOT_QUEUED") return { queued: false, dispatch: current };
|
|
2547
|
+
const accepted = readDispatch(await client.queueDiscoveryDispatch(id), identity, id, 202);
|
|
2548
|
+
if (!active() || accepted.jobId !== current.jobId || accepted.state === "NOT_QUEUED") throw Error("OPENCODE_DISCOVERY_READBACK_MISMATCH");
|
|
2549
|
+
return { queued: true, dispatch: accepted };
|
|
2550
|
+
}
|
|
2551
|
+
var formatDiscoveryStatus = (value) => JSON.stringify(value, null, 2).replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/g, "");
|
|
2552
|
+
|
|
2553
|
+
// ../../contracts/credit-display.ts
|
|
2554
|
+
function formatAICredits(microcredits, locale) {
|
|
2555
|
+
if (typeof microcredits !== "number" || !Number.isFinite(microcredits) || microcredits < 0) return null;
|
|
2556
|
+
return (microcredits / 1e6).toLocaleString(locale, { maximumFractionDigits: 6 });
|
|
2557
|
+
}
|
|
2558
|
+
|
|
2559
|
+
// ../../contracts/feature-credit-preview-v1.ts
|
|
2560
|
+
var creditPreviewFeatures = ["teach", "evaluation_generation", "evaluation_judge", "strategy_model", "strategy_decision", "semantic", "authoring", "discovery", "decision", "runtime_verification"];
|
|
2561
|
+
var record5 = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
2562
|
+
var n = (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0;
|
|
2563
|
+
var clean3 = (v) => typeof v === "string" && v.length > 0 && v.length <= 512 && v.trim() === v && !/[\u0000-\u001f\u007f]/.test(v);
|
|
2564
|
+
function isCreditPreviewFeature(value) {
|
|
2565
|
+
return creditPreviewFeatures.some((f) => f === value);
|
|
2566
|
+
}
|
|
2567
|
+
function readFeatureCreditPrice(value, aiSystemId, feature, expectedScope, expectedModel) {
|
|
2568
|
+
const v = record5(value), scope = record5(v.scope);
|
|
2569
|
+
const keys = ["organizationId", "projectId", "environmentId", "organizationUnitId"];
|
|
2570
|
+
if (!clean3(aiSystemId) || v.aiSystemId !== aiSystemId || v.feature !== feature || !keys.every((k) => clean3(expectedScope[k]) && scope[k] === expectedScope[k])) throw Error("OPERATION_CREDIT_PREVIEW_SCOPE_MISMATCH");
|
|
2571
|
+
if (v.status === "UNAVAILABLE") return null;
|
|
2572
|
+
const basis = feature === "teach" ? "TEACH_RUN" : feature === "strategy_model" || feature === "strategy_decision" ? "STRATEGY_EXECUTION" : feature === "runtime_verification" ? "UNSPECIFIED" : "PROVIDER_CALL";
|
|
2573
|
+
if (v.status !== "AVAILABLE" || !clean3(v.providerId) || !clean3(v.modelId) || !clean3(v.pricingVersion) || !n(v.inputTokenMicrocredits) || !n(v.outputTokenMicrocredits) || !(v.reservationMicrocredits === null || n(v.reservationMicrocredits)) || v.reservationBasis !== basis || v.notReserved !== true || v.notFinalCharge !== true || basis === "UNSPECIFIED" && v.reservationMicrocredits !== null || v.reservationMicrocredits === 0 && (basis !== "PROVIDER_CALL" || v.inputTokenMicrocredits !== 0 || v.outputTokenMicrocredits !== 0)) throw Error("OPERATION_CREDIT_PREVIEW_MISMATCH");
|
|
2574
|
+
if (expectedModel && (v.providerId !== expectedModel.providerId || v.modelId !== expectedModel.modelId)) throw Error("OPERATION_CREDIT_PREVIEW_MODEL_MISMATCH");
|
|
2575
|
+
return { providerId: v.providerId, modelId: v.modelId, pricingVersion: v.pricingVersion, inputTokenMicrocredits: v.inputTokenMicrocredits, outputTokenMicrocredits: v.outputTokenMicrocredits, reservationBasis: basis, reservationMicrocredits: v.reservationMicrocredits };
|
|
2576
|
+
}
|
|
2577
|
+
|
|
2578
|
+
// src/tui-credit-preview.ts
|
|
2579
|
+
var record6 = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
2580
|
+
async function readOpenCodeCreditPreview(client, identity, feature, active) {
|
|
2581
|
+
if (!active() || !isCreditPreviewFeature(feature) || Object.values(identity).some((v) => typeof v !== "string" || !v.trim() || v !== v.trim())) throw Error("OPENCODE_CREDIT_PREVIEW_SCOPE_REQUIRED");
|
|
2582
|
+
const { aiSystemId, ...scope } = identity;
|
|
2583
|
+
const confirmed = record6(await client.resolveCredentialScope(scope, { requireDepartment: true }));
|
|
2584
|
+
if (!active() || !Object.entries(scope).every(([k, v]) => confirmed[k] === v)) throw Error("OPENCODE_CREDIT_PREVIEW_SCOPE_MISMATCH");
|
|
2585
|
+
const response = record6(await client.getFeatureCreditPreview(aiSystemId, feature));
|
|
2586
|
+
if (!active() || response.status !== 200) throw Error("OPENCODE_CREDIT_PREVIEW_NOT_CONFIRMED");
|
|
2587
|
+
const price = readFeatureCreditPrice(response.body, aiSystemId, feature, scope);
|
|
2588
|
+
return { feature, aiSystemId, status: price ? "AVAILABLE" : "UNAVAILABLE", price };
|
|
2589
|
+
}
|
|
2590
|
+
function formatOpenCodeCreditPreview(result) {
|
|
2591
|
+
const p = result.price;
|
|
2592
|
+
if (!p) return JSON.stringify({ feature: result.feature, aiSystemId: result.aiSystemId, status: result.status }, null, 2);
|
|
2593
|
+
return JSON.stringify({ feature: result.feature, aiSystemId: result.aiSystemId, status: result.status, providerId: p.providerId, modelId: p.modelId, pricingVersion: p.pricingVersion, inputCreditsPerToken: formatAICredits(p.inputTokenMicrocredits, "en"), outputCreditsPerToken: formatAICredits(p.outputTokenMicrocredits, "en"), reservationBasis: p.reservationBasis, temporaryHoldCredits: formatAICredits(p.reservationMicrocredits, "en"), notReserved: true, notFinalCharge: true }, null, 2);
|
|
2594
|
+
}
|
|
2595
|
+
|
|
2436
2596
|
// src/tui-entry.ts
|
|
2437
2597
|
var val = (value) => typeof value === "string" ? value.trim() : "";
|
|
2438
2598
|
var tui_entry_default = { id: "vira.cli", setup(context) {
|
|
@@ -2478,7 +2638,92 @@ var tui_entry_default = { id: "vira.cli", setup(context) {
|
|
|
2478
2638
|
busy = false;
|
|
2479
2639
|
}
|
|
2480
2640
|
};
|
|
2481
|
-
|
|
2641
|
+
const review = async (argument) => {
|
|
2642
|
+
if (busy || disposed) return;
|
|
2643
|
+
busy = true;
|
|
2644
|
+
const session = context.ui.router.current(), sessionID = session.sessionID;
|
|
2645
|
+
const active = () => {
|
|
2646
|
+
const current = context.ui.router.current();
|
|
2647
|
+
return !disposed && current.type === "session" && current.sessionID === sessionID;
|
|
2648
|
+
};
|
|
2649
|
+
try {
|
|
2650
|
+
if (session.type !== "session" || !sessionID) throw Error("SESSION_REQUIRED");
|
|
2651
|
+
const mode = get("mode", "VIRA_HOST_MODE");
|
|
2652
|
+
if (mode !== "observe" && mode !== "enforce") throw Error("VIRA_HOST_DISABLED");
|
|
2653
|
+
const identity = { organizationId: get("organizationId", "VIRA_ORGANIZATION_ID"), projectId: get("projectId", "VIRA_PROJECT_ID"), environmentId: get("environmentId", "VIRA_ENVIRONMENT_ID"), organizationUnitId: get("organizationUnitId", "VIRA_ORGANIZATION_UNIT_ID"), aiSystemId: get("aiSystemId", "VIRA_AI_SYSTEM_ID") };
|
|
2654
|
+
const baseUrl = get("apiUrl", "VIRA_CONTROL_URL") || val(process.env.VIRA_API_URL), apiKey = get("apiKey", "VIRA_API_KEY");
|
|
2655
|
+
if (!baseUrl || !apiKey || Object.values(identity).some((value) => !value)) throw Error("CONFIGURATION_REQUIRED");
|
|
2656
|
+
let id = val(argument);
|
|
2657
|
+
if (!id) id = val(await context.ui.dialog.prompt({ title: "Vira Teach review \xB7 exact run reference", placeholder: "Teach run ID" }));
|
|
2658
|
+
if (!active() || !id) return;
|
|
2659
|
+
if (!validTeachRunId(id)) throw Error("INVALID_REFERENCE");
|
|
2660
|
+
const client = new ViraClient({ baseUrl, apiKey, organizationUnitId: identity.organizationUnitId, retries: 0, timeoutMs: 15e3 });
|
|
2661
|
+
const recommendation = await readOpenCodeTeachReview(client, identity, id, active);
|
|
2662
|
+
if (!active()) return;
|
|
2663
|
+
const chars = Array.from(formatTeachReview(recommendation)), pageSize = 6e3, pages = Math.max(1, Math.ceil(chars.length / pageSize));
|
|
2664
|
+
for (let i = 0; i < pages && active(); i++) await context.ui.dialog.alert({ title: "Vira Teach review \xB7 read only \xB7 " + (i + 1) + "/" + pages, message: chars.slice(i * pageSize, (i + 1) * pageSize).join("") });
|
|
2665
|
+
} catch {
|
|
2666
|
+
if (active()) await context.ui.dialog.alert({ title: "Vira Teach review unavailable", message: "Check the exact run reference and authorized department / AI System. A credential with current Teach read access is required. No behavior, approval or release was changed." });
|
|
2667
|
+
} finally {
|
|
2668
|
+
busy = false;
|
|
2669
|
+
}
|
|
2670
|
+
};
|
|
2671
|
+
const discovery = async (argument, queue = false) => {
|
|
2672
|
+
if (busy || disposed) return;
|
|
2673
|
+
busy = true;
|
|
2674
|
+
const session = context.ui.router.current(), sessionID = session.sessionID;
|
|
2675
|
+
const active = () => {
|
|
2676
|
+
const current = context.ui.router.current();
|
|
2677
|
+
return !disposed && current.type === "session" && current.sessionID === sessionID;
|
|
2678
|
+
};
|
|
2679
|
+
try {
|
|
2680
|
+
if (session.type !== "session" || !sessionID) throw Error("SESSION_REQUIRED");
|
|
2681
|
+
const mode = get("mode", "VIRA_HOST_MODE");
|
|
2682
|
+
if (mode !== "observe" && mode !== "enforce") throw Error("VIRA_HOST_DISABLED");
|
|
2683
|
+
const identity = { organizationId: get("organizationId", "VIRA_ORGANIZATION_ID"), projectId: get("projectId", "VIRA_PROJECT_ID"), environmentId: get("environmentId", "VIRA_ENVIRONMENT_ID"), organizationUnitId: get("organizationUnitId", "VIRA_ORGANIZATION_UNIT_ID"), aiSystemId: get("aiSystemId", "VIRA_AI_SYSTEM_ID"), connectionId: get("connectionId", "VIRA_CONNECTION_ID") };
|
|
2684
|
+
const baseUrl = get("apiUrl", "VIRA_CONTROL_URL") || val(process.env.VIRA_API_URL), apiKey = get("apiKey", "VIRA_API_KEY");
|
|
2685
|
+
if (!baseUrl || !apiKey || Object.values(identity).some((value) => !value)) throw Error("CONFIGURATION_REQUIRED");
|
|
2686
|
+
let id = val(argument);
|
|
2687
|
+
if (!id) id = val(await context.ui.dialog.prompt({ title: "Vira Discovery \xB7 exact admitted observation", placeholder: "Observation event ID" }));
|
|
2688
|
+
if (!active() || !id) return;
|
|
2689
|
+
if (!validDiscoveryEventId(id)) throw Error("INVALID_REFERENCE");
|
|
2690
|
+
const client = new ViraClient({ baseUrl, apiKey, organizationUnitId: identity.organizationUnitId, retries: 0, timeoutMs: 15e3 });
|
|
2691
|
+
const result = queue ? await queueOpenCodeDiscovery(client, identity, id, async (jobId) => val(await context.ui.dialog.prompt({ title: "Queue missing discovery \xB7 " + jobId, placeholder: "Type QUEUE to authorize" })) === "QUEUE", active) : await readOpenCodeDiscovery(client, identity, id, active);
|
|
2692
|
+
if (active()) await context.ui.dialog.alert({ title: "Vira Discovery \xB7 " + (queue ? "queue admission" : "read only"), message: formatDiscoveryStatus(result) + "\n\nNo release or runtime activation was requested." });
|
|
2693
|
+
} catch {
|
|
2694
|
+
if (active()) await context.ui.dialog.alert({ title: "Vira Discovery unavailable", message: "Check the observation, department, connection and authorized actor credential. Machine credentials cannot gain Studio write authority. If queue admission is uncertain, read status before retrying." });
|
|
2695
|
+
} finally {
|
|
2696
|
+
busy = false;
|
|
2697
|
+
}
|
|
2698
|
+
};
|
|
2699
|
+
const creditPreview = async (argument) => {
|
|
2700
|
+
if (busy || disposed) return;
|
|
2701
|
+
busy = true;
|
|
2702
|
+
const session = context.ui.router.current(), sessionID = session.sessionID;
|
|
2703
|
+
const active = () => {
|
|
2704
|
+
const current = context.ui.router.current();
|
|
2705
|
+
return !disposed && current.type === "session" && current.sessionID === sessionID;
|
|
2706
|
+
};
|
|
2707
|
+
try {
|
|
2708
|
+
if (session.type !== "session" || !sessionID) throw Error("SESSION_REQUIRED");
|
|
2709
|
+
const mode = get("mode", "VIRA_HOST_MODE");
|
|
2710
|
+
if (mode !== "observe" && mode !== "enforce") throw Error("VIRA_HOST_DISABLED");
|
|
2711
|
+
const identity = { organizationId: get("organizationId", "VIRA_ORGANIZATION_ID"), projectId: get("projectId", "VIRA_PROJECT_ID"), environmentId: get("environmentId", "VIRA_ENVIRONMENT_ID"), organizationUnitId: get("organizationUnitId", "VIRA_ORGANIZATION_UNIT_ID"), aiSystemId: get("aiSystemId", "VIRA_AI_SYSTEM_ID") };
|
|
2712
|
+
const baseUrl = get("apiUrl", "VIRA_CONTROL_URL") || val(process.env.VIRA_API_URL), apiKey = get("apiKey", "VIRA_API_KEY");
|
|
2713
|
+
if (!baseUrl || !apiKey || Object.values(identity).some((v) => !v)) throw Error("CONFIGURATION_REQUIRED");
|
|
2714
|
+
const feature = val(argument) || val(await context.ui.dialog.prompt({ title: "Vira AI credit preview", placeholder: "teach, evaluation_judge, strategy_model, discovery\u2026" }));
|
|
2715
|
+
if (!active() || !feature) return;
|
|
2716
|
+
if (!isCreditPreviewFeature(feature)) throw Error("FEATURE_INVALID");
|
|
2717
|
+
const client = new ViraClient({ baseUrl, apiKey, organizationUnitId: identity.organizationUnitId, retries: 0, timeoutMs: 15e3 });
|
|
2718
|
+
const result = await readOpenCodeCreditPreview(client, identity, feature, active);
|
|
2719
|
+
if (active()) await context.ui.dialog.alert({ title: "Vira approved AI credit preview", message: formatOpenCodeCreditPreview(result) + "\n\nRead only. No credit reservation or provider call." });
|
|
2720
|
+
} catch {
|
|
2721
|
+
if (active()) await context.ui.dialog.alert({ title: "Vira credit preview unavailable", message: "Check the feature, configured AI System, active department and authorized credential. No amount has been reserved." });
|
|
2722
|
+
} finally {
|
|
2723
|
+
busy = false;
|
|
2724
|
+
}
|
|
2725
|
+
};
|
|
2726
|
+
context.keymap.layer(() => ({ mode: "global", commands: [{ id: "vira.result", title: "Read verified Vira TaskRun result", group: "Vira", palette: true, slash: { name: "vira-result", arguments: true }, run }, { id: "vira.teach-review", title: "Read persisted Vira Teach recommendation", group: "Vira", palette: true, slash: { name: "vira-teach-review", arguments: true }, run: review }, { id: "vira.discovery-status", title: "Read Vira Discovery status", group: "Vira", palette: true, slash: { name: "vira-discovery-status", arguments: true }, run: (argument) => discovery(argument) }, { id: "vira.discovery-queue", title: "Queue missing Vira Discovery with confirmation", group: "Vira", palette: true, slash: { name: "vira-discovery-queue", arguments: true }, run: (argument) => discovery(argument, true) }, { id: "vira.credit-preview", title: "Read approved Vira AI credit preview", group: "Vira", palette: true, slash: { name: "vira-credit-preview", arguments: true }, run: creditPreview }] }));
|
|
2482
2727
|
return () => {
|
|
2483
2728
|
disposed = true;
|
|
2484
2729
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryvira/opencode",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.96",
|
|
4
4
|
"description": "OpenCode host lifecycle integration for Vira",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"opencode",
|
|
@@ -43,5 +43,6 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@opencode/plugin": "^2.3.2"
|
|
46
|
-
}
|
|
46
|
+
},
|
|
47
|
+
"gitHead": "def3fd5193cedfd38504f231b00727b0fb34dea0"
|
|
47
48
|
}
|