@tryvira/opencode 0.1.77 → 0.1.79

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 CHANGED
@@ -1,4 +1,4 @@
1
- # `@tryvira/opencode` 0.1.77
1
+ # `@tryvira/opencode` 0.1.78
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
@@ -17,14 +17,15 @@ events must submit output observations through their normal Vira SDK integration
17
17
 
18
18
  Configuration is supplied through OpenCode plugin options or environment variables: `VIRA_CONTROL_URL`, `VIRA_API_KEY`, `VIRA_ORGANIZATION_ID`, `VIRA_PROJECT_ID`, `VIRA_ENVIRONMENT_ID`, `VIRA_ORGANIZATION_UNIT_ID`, `VIRA_AI_SYSTEM_ID`, `VIRA_CONNECTION_ID`, and `VIRA_HOST_MODE` (`off`, `observe`, `enforce`). `VIRA_HOST_TIMEOUT_MS` controls the bounded host lifecycle timeout (default 30 seconds, maximum 120 seconds) and is applied consistently to the SDK HTTP request and semantic/runtime hook. Use it when a provider-backed semantic decision legitimately takes longer than the default; timeouts still fail closed. `adapterVersion` (or `VIRA_ADAPTER_VERSION`) is the stable Vira adapter protocol version and is intentionally separate from the OpenCode application version; leave it at `1` unless the adapter contract changes. V1 `server()` and V2 `setup()` read the same options, so a fixed connection identity is not recreated with a changing host application version.
19
19
 
20
- An embedding host that can construct plugin options programmatically may supply an
21
- `accessTokenProvider` callback. The SDK calls it for each API request and sends
22
- the returned token only as `Authorization: Bearer`; when provided, it takes
23
- precedence over `apiKey`. Keep token refresh, expiry, storage and revocation in
24
- the host's credential manager. This callback cannot be represented in OpenCode's
25
- JSON configuration and does not provide browser OAuth or native OpenCode OAuth
26
- consent by itself. OpenCode OAuth support remains host-acceptance work; the
27
- existing API-key configuration continues to work.
20
+ An embedding host that constructs plugin options programmatically may supply an
21
+ `apiCredentialProvider` callback returning a Vira customer API key. It is called
22
+ for each request and sends the key in `x-vira-api-key`; Vira derives tenant scope
23
+ from its persisted credential record. Supabase/Better Auth OAuth JWTs are not
24
+ Vira credentials and cannot establish tenant membership. The deprecated
25
+ `accessTokenProvider` option is a compatibility alias with the same key-only
26
+ contract. Keep key rotation and storage in the host's credential manager. This
27
+ callback cannot be represented in OpenCode JSON configuration and does not
28
+ provide OAuth consent or tenant provisioning.
28
29
 
29
30
  In `enforce` mode, V2 uses OpenCode's native `permission.evaluate` hook. Effectful tool calls are changed to `ask`; the customer confirms the exact tool in OpenCode's own permission UI, and only a matching native `permission.asked` followed by `permission.replied` with `reply: once` can create a server-owned one-use approval bound to the exact proposal. The host must supply exact tool-call identity and arguments in the permission metadata; without those or the event stream, approval-required actions remain blocked. An ask, saved/always permission, rejection, mismatched arguments or missing reply is not confirmation. JSON options cannot contain a confirmation callback or a `confirmed` flag. `permissionMode:"deny"` disables the native bridge and therefore fails closed. A denial, expiry, changed argument set, or replay remains blocked. The optional `confirmAction` is retained only as a programmatic embedding seam for tests/host adapters; it is not a JSON-configured approval mechanism. V1 hosts without the native permission hook remain fail-closed for approval-required actions.
30
31
  For an isolated loopback-only test boundary, `VIRA_ALLOW_INSECURE_LOCALHOST=true` may be set; production API URLs must remain HTTPS.
package/dist/index.js CHANGED
@@ -90,7 +90,7 @@ var ViraClient = class {
90
90
  packs;
91
91
  baseUrl;
92
92
  apiKey;
93
- accessTokenProvider;
93
+ apiCredentialProvider;
94
94
  operatorDelegationTokenProvider;
95
95
  fetcher;
96
96
  timeoutMs;
@@ -101,7 +101,7 @@ var ViraClient = class {
101
101
  constructor(options) {
102
102
  this.baseUrl = normalizeBaseUrl(options.baseUrl, options.allowInsecureLocalhost === true);
103
103
  this.apiKey = options.apiKey;
104
- this.accessTokenProvider = options.accessTokenProvider;
104
+ this.apiCredentialProvider = options.apiCredentialProvider ?? options.accessTokenProvider;
105
105
  this.operatorDelegationTokenProvider = options.operatorDelegationTokenProvider;
106
106
  this.fetcher = options.fetcher ?? fetch;
107
107
  this.timeoutMs = Math.max(
@@ -234,10 +234,12 @@ var ViraClient = class {
234
234
  const delegation = (await this.operatorDelegationTokenProvider?.())?.trim();
235
235
  if (!delegation) throw new Error("SDK_OPERATOR_DELEGATION_REQUIRED");
236
236
  headers["x-vira-delegation"] = delegation;
237
- } else if (this.accessTokenProvider) {
238
- const accessToken = (await this.accessTokenProvider())?.trim();
239
- if (!accessToken) throw new Error("SDK_ACCESS_TOKEN_REQUIRED");
240
- headers.authorization = `Bearer ${accessToken}`;
237
+ } else if (this.apiCredentialProvider) {
238
+ const credential = (await this.apiCredentialProvider())?.trim();
239
+ if (!credential) throw new Error("SDK_API_CREDENTIAL_REQUIRED");
240
+ if (/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(credential))
241
+ throw new Error("SDK_OAUTH_IDENTITY_TOKEN_UNSUPPORTED");
242
+ headers["x-vira-api-key"] = credential;
241
243
  } else if (this.apiKey) {
242
244
  if (this.apiKey.startsWith("vira_live_")) headers["x-vira-api-key"] = this.apiKey;
243
245
  else {
@@ -1115,6 +1117,9 @@ var ViraClient = class {
1115
1117
  resolveRuntime(input2) {
1116
1118
  if (!input2.behaviorPoint && !input2.executionBoundary && !input2.semanticContext)
1117
1119
  throw new Error("SDK_RUNTIME_ROUTE_REQUIRED");
1120
+ const idempotencyKey = input2.idempotencyKey ?? `sdk:resolve:${globalThis.crypto.randomUUID()}`;
1121
+ if (!idempotencyKey.trim() || idempotencyKey !== idempotencyKey.trim())
1122
+ throw new Error("SDK_IDEMPOTENCY_KEY_INVALID");
1118
1123
  return this.request(
1119
1124
  {
1120
1125
  method: "POST",
@@ -1127,7 +1132,9 @@ var ViraClient = class {
1127
1132
  }
1128
1133
  },
1129
1134
  {
1130
- idempotencyKey: input2.idempotencyKey ?? `sdk:resolve:${input2.behaviorPoint ?? "boundary"}`,
1135
+ // One key per logical invocation: transport retries reuse this value,
1136
+ // while a later call for the same BehaviorPoint is billed separately.
1137
+ idempotencyKey,
1131
1138
  enforcing: true
1132
1139
  }
1133
1140
  );
@@ -22786,7 +22793,7 @@ var v2Plugin = Plugin.define({
22786
22793
  const apiKey = options.apiKey ?? env("VIRA_API_KEY");
22787
22794
  const machine = isOpenCodeMachineCredential(options, apiKey);
22788
22795
  const allowInsecureLocalhost = options.allowInsecureLocalhost ?? env("VIRA_ALLOW_INSECURE_LOCALHOST") === "true";
22789
- const client = new ViraClient({ baseUrl: required3(apiUrl, "VIRA_HOST_API_URL_REQUIRED"), apiKey, accessTokenProvider: options.accessTokenProvider, allowInsecureLocalhost, organizationUnitId: options.organizationUnitId ?? env("VIRA_ORGANIZATION_UNIT_ID") });
22796
+ const client = new ViraClient({ baseUrl: required3(apiUrl, "VIRA_HOST_API_URL_REQUIRED"), apiKey, apiCredentialProvider: options.apiCredentialProvider ?? options.accessTokenProvider, allowInsecureLocalhost, organizationUnitId: options.organizationUnitId ?? env("VIRA_ORGANIZATION_UNIT_ID") });
22790
22797
  let scope;
22791
22798
  try {
22792
22799
  scope = await resolveOpenCodeCredentialScope(client, options, machine);
@@ -23130,7 +23137,7 @@ var v1Runtime = async (options) => {
23130
23137
  const machine = isOpenCodeMachineCredential(options, options.apiKey ?? env("VIRA_API_KEY"));
23131
23138
  const configuredTimeout = Number(options.timeoutMs ?? env("VIRA_HOST_TIMEOUT_MS") ?? 3e4);
23132
23139
  const timeoutMs = Number.isFinite(configuredTimeout) ? configuredTimeout : 3e4;
23133
- const client = new ViraClient({ baseUrl: required3(options.apiUrl ?? env("VIRA_CONTROL_URL") ?? env("VIRA_API_URL"), "VIRA_HOST_API_URL_REQUIRED"), apiKey: options.apiKey ?? env("VIRA_API_KEY"), accessTokenProvider: options.accessTokenProvider, timeoutMs, allowInsecureLocalhost: options.allowInsecureLocalhost ?? env("VIRA_ALLOW_INSECURE_LOCALHOST") === "true", organizationUnitId: options.organizationUnitId ?? env("VIRA_ORGANIZATION_UNIT_ID") });
23140
+ const client = new ViraClient({ baseUrl: required3(options.apiUrl ?? env("VIRA_CONTROL_URL") ?? env("VIRA_API_URL"), "VIRA_HOST_API_URL_REQUIRED"), apiKey: options.apiKey ?? env("VIRA_API_KEY"), apiCredentialProvider: options.apiCredentialProvider ?? options.accessTokenProvider, timeoutMs, allowInsecureLocalhost: options.allowInsecureLocalhost ?? env("VIRA_ALLOW_INSECURE_LOCALHOST") === "true", organizationUnitId: options.organizationUnitId ?? env("VIRA_ORGANIZATION_UNIT_ID") });
23134
23141
  let scope;
23135
23142
  try {
23136
23143
  scope = await resolveOpenCodeCredentialScope(client, options, machine);
package/dist/server.js CHANGED
@@ -90,7 +90,7 @@ var ViraClient = class {
90
90
  packs;
91
91
  baseUrl;
92
92
  apiKey;
93
- accessTokenProvider;
93
+ apiCredentialProvider;
94
94
  operatorDelegationTokenProvider;
95
95
  fetcher;
96
96
  timeoutMs;
@@ -101,7 +101,7 @@ var ViraClient = class {
101
101
  constructor(options) {
102
102
  this.baseUrl = normalizeBaseUrl(options.baseUrl, options.allowInsecureLocalhost === true);
103
103
  this.apiKey = options.apiKey;
104
- this.accessTokenProvider = options.accessTokenProvider;
104
+ this.apiCredentialProvider = options.apiCredentialProvider ?? options.accessTokenProvider;
105
105
  this.operatorDelegationTokenProvider = options.operatorDelegationTokenProvider;
106
106
  this.fetcher = options.fetcher ?? fetch;
107
107
  this.timeoutMs = Math.max(
@@ -234,10 +234,12 @@ var ViraClient = class {
234
234
  const delegation = (await this.operatorDelegationTokenProvider?.())?.trim();
235
235
  if (!delegation) throw new Error("SDK_OPERATOR_DELEGATION_REQUIRED");
236
236
  headers["x-vira-delegation"] = delegation;
237
- } else if (this.accessTokenProvider) {
238
- const accessToken = (await this.accessTokenProvider())?.trim();
239
- if (!accessToken) throw new Error("SDK_ACCESS_TOKEN_REQUIRED");
240
- headers.authorization = `Bearer ${accessToken}`;
237
+ } else if (this.apiCredentialProvider) {
238
+ const credential = (await this.apiCredentialProvider())?.trim();
239
+ if (!credential) throw new Error("SDK_API_CREDENTIAL_REQUIRED");
240
+ if (/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(credential))
241
+ throw new Error("SDK_OAUTH_IDENTITY_TOKEN_UNSUPPORTED");
242
+ headers["x-vira-api-key"] = credential;
241
243
  } else if (this.apiKey) {
242
244
  if (this.apiKey.startsWith("vira_live_")) headers["x-vira-api-key"] = this.apiKey;
243
245
  else {
@@ -1115,6 +1117,9 @@ var ViraClient = class {
1115
1117
  resolveRuntime(input2) {
1116
1118
  if (!input2.behaviorPoint && !input2.executionBoundary && !input2.semanticContext)
1117
1119
  throw new Error("SDK_RUNTIME_ROUTE_REQUIRED");
1120
+ const idempotencyKey = input2.idempotencyKey ?? `sdk:resolve:${globalThis.crypto.randomUUID()}`;
1121
+ if (!idempotencyKey.trim() || idempotencyKey !== idempotencyKey.trim())
1122
+ throw new Error("SDK_IDEMPOTENCY_KEY_INVALID");
1118
1123
  return this.request(
1119
1124
  {
1120
1125
  method: "POST",
@@ -1127,7 +1132,9 @@ var ViraClient = class {
1127
1132
  }
1128
1133
  },
1129
1134
  {
1130
- idempotencyKey: input2.idempotencyKey ?? `sdk:resolve:${input2.behaviorPoint ?? "boundary"}`,
1135
+ // One key per logical invocation: transport retries reuse this value,
1136
+ // while a later call for the same BehaviorPoint is billed separately.
1137
+ idempotencyKey,
1131
1138
  enforcing: true
1132
1139
  }
1133
1140
  );
@@ -22786,7 +22793,7 @@ var v2Plugin = Plugin.define({
22786
22793
  const apiKey = options.apiKey ?? env("VIRA_API_KEY");
22787
22794
  const machine = isOpenCodeMachineCredential(options, apiKey);
22788
22795
  const allowInsecureLocalhost = options.allowInsecureLocalhost ?? env("VIRA_ALLOW_INSECURE_LOCALHOST") === "true";
22789
- const client = new ViraClient({ baseUrl: required3(apiUrl, "VIRA_HOST_API_URL_REQUIRED"), apiKey, accessTokenProvider: options.accessTokenProvider, allowInsecureLocalhost, organizationUnitId: options.organizationUnitId ?? env("VIRA_ORGANIZATION_UNIT_ID") });
22796
+ const client = new ViraClient({ baseUrl: required3(apiUrl, "VIRA_HOST_API_URL_REQUIRED"), apiKey, apiCredentialProvider: options.apiCredentialProvider ?? options.accessTokenProvider, allowInsecureLocalhost, organizationUnitId: options.organizationUnitId ?? env("VIRA_ORGANIZATION_UNIT_ID") });
22790
22797
  let scope;
22791
22798
  try {
22792
22799
  scope = await resolveOpenCodeCredentialScope(client, options, machine);
@@ -23130,7 +23137,7 @@ var v1Runtime = async (options) => {
23130
23137
  const machine = isOpenCodeMachineCredential(options, options.apiKey ?? env("VIRA_API_KEY"));
23131
23138
  const configuredTimeout = Number(options.timeoutMs ?? env("VIRA_HOST_TIMEOUT_MS") ?? 3e4);
23132
23139
  const timeoutMs = Number.isFinite(configuredTimeout) ? configuredTimeout : 3e4;
23133
- const client = new ViraClient({ baseUrl: required3(options.apiUrl ?? env("VIRA_CONTROL_URL") ?? env("VIRA_API_URL"), "VIRA_HOST_API_URL_REQUIRED"), apiKey: options.apiKey ?? env("VIRA_API_KEY"), accessTokenProvider: options.accessTokenProvider, timeoutMs, allowInsecureLocalhost: options.allowInsecureLocalhost ?? env("VIRA_ALLOW_INSECURE_LOCALHOST") === "true", organizationUnitId: options.organizationUnitId ?? env("VIRA_ORGANIZATION_UNIT_ID") });
23140
+ const client = new ViraClient({ baseUrl: required3(options.apiUrl ?? env("VIRA_CONTROL_URL") ?? env("VIRA_API_URL"), "VIRA_HOST_API_URL_REQUIRED"), apiKey: options.apiKey ?? env("VIRA_API_KEY"), apiCredentialProvider: options.apiCredentialProvider ?? options.accessTokenProvider, timeoutMs, allowInsecureLocalhost: options.allowInsecureLocalhost ?? env("VIRA_ALLOW_INSECURE_LOCALHOST") === "true", organizationUnitId: options.organizationUnitId ?? env("VIRA_ORGANIZATION_UNIT_ID") });
23134
23141
  let scope;
23135
23142
  try {
23136
23143
  scope = await resolveOpenCodeCredentialScope(client, options, machine);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryvira/opencode",
3
- "version": "0.1.77",
3
+ "version": "0.1.79",
4
4
  "description": "OpenCode host lifecycle integration for Vira",
5
5
  "keywords": [
6
6
  "opencode",