@tryvira/opencode 0.1.80 → 0.1.82
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 +1 -1
- package/dist/index.js +43 -2
- package/dist/server.js +43 -2
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -84,6 +84,17 @@ var retryAfterMs = (value, now = Date.now()) => {
|
|
|
84
84
|
const date5 = Date.parse(value);
|
|
85
85
|
return Number.isFinite(date5) && date5 > now ? Math.min(date5 - now, 12e4) : 0;
|
|
86
86
|
};
|
|
87
|
+
function notifyTransport(observer, method, status, error62, started, attempt) {
|
|
88
|
+
if (!observer) return;
|
|
89
|
+
try {
|
|
90
|
+
const known = ["GET", "POST", "PUT", "PATCH", "DELETE"];
|
|
91
|
+
const outcome = status === 429 ? "http_429" : status !== void 0 ? status >= 200 && status < 600 ? "http_" + Math.floor(status / 100) + "xx" : "http_other" : error62 instanceof Error && ["AbortError", "TimeoutError"].includes(error62.name) ? "timeout" : "transport_error";
|
|
92
|
+
const event = Object.freeze({ method: known.includes(method) ? method : "OTHER", outcome, durationMs: Math.max(0, performance.now() - started), attempt: attempt + 1 });
|
|
93
|
+
void Promise.resolve(observer(event)).catch(() => {
|
|
94
|
+
});
|
|
95
|
+
} catch {
|
|
96
|
+
}
|
|
97
|
+
}
|
|
87
98
|
var ViraClient = class {
|
|
88
99
|
evaluations;
|
|
89
100
|
teach;
|
|
@@ -93,6 +104,7 @@ var ViraClient = class {
|
|
|
93
104
|
apiCredentialProvider;
|
|
94
105
|
operatorDelegationTokenProvider;
|
|
95
106
|
fetcher;
|
|
107
|
+
transportObserver;
|
|
96
108
|
timeoutMs;
|
|
97
109
|
retries;
|
|
98
110
|
failureMode;
|
|
@@ -104,6 +116,7 @@ var ViraClient = class {
|
|
|
104
116
|
this.apiCredentialProvider = options.apiCredentialProvider ?? options.accessTokenProvider;
|
|
105
117
|
this.operatorDelegationTokenProvider = options.operatorDelegationTokenProvider;
|
|
106
118
|
this.fetcher = options.fetcher ?? fetch;
|
|
119
|
+
this.transportObserver = options.transportObserver;
|
|
107
120
|
this.timeoutMs = Math.max(
|
|
108
121
|
1e3,
|
|
109
122
|
Math.min(options.timeoutMs ?? 15e3, 12e4)
|
|
@@ -173,6 +186,11 @@ var ViraClient = class {
|
|
|
173
186
|
if (options.limit !== void 0 && !Number.isFinite(options.limit)) throw new Error("SDK_NOTIFICATION_LIMIT_INVALID");
|
|
174
187
|
return this.request({ method: "GET", path: "/v1/notifications/inbox", query: { ...limit === void 0 ? {} : { limit: String(limit) }, ...options.cursor ? { cursor: options.cursor } : {}, ...options.search ? { search: options.search } : {} } });
|
|
175
188
|
}
|
|
189
|
+
readNotificationUpdates(options = {}) {
|
|
190
|
+
const count = options.count ?? 32;
|
|
191
|
+
if (!Number.isSafeInteger(count) || count < 1 || count > 100) throw new Error("SDK_NOTIFICATION_UPDATES_COUNT_INVALID");
|
|
192
|
+
return this.request({ method: "GET", path: "/v1/notifications/updates", query: { afterId: options.afterId ?? "latest", count: String(count) } });
|
|
193
|
+
}
|
|
176
194
|
markInboxRead(notificationId, options = {}) {
|
|
177
195
|
if (!notificationId.trim()) throw new Error("SDK_NOTIFICATION_ID_REQUIRED");
|
|
178
196
|
return this.request({ method: "POST", path: `/v1/notifications/${encodeURIComponent(notificationId)}/read`, body: {} }, { idempotencyKey: options.idempotencyKey ?? `sdk:inbox-read:${notificationId}` });
|
|
@@ -255,6 +273,8 @@ var ViraClient = class {
|
|
|
255
273
|
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
256
274
|
const controller = new AbortController();
|
|
257
275
|
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
276
|
+
const started = this.transportObserver ? performance.now() : 0;
|
|
277
|
+
let reported = false;
|
|
258
278
|
try {
|
|
259
279
|
const response = await this.fetcher(url2, {
|
|
260
280
|
method: request.method,
|
|
@@ -264,6 +284,8 @@ var ViraClient = class {
|
|
|
264
284
|
...operatorOperation ? { redirect: "error", credentials: "omit" } : {}
|
|
265
285
|
});
|
|
266
286
|
const raw = await response.text();
|
|
287
|
+
notifyTransport(this.transportObserver, request.method, response.status, void 0, started, attempt);
|
|
288
|
+
reported = true;
|
|
267
289
|
let body = null;
|
|
268
290
|
try {
|
|
269
291
|
body = raw ? JSON.parse(raw) : null;
|
|
@@ -290,6 +312,7 @@ var ViraClient = class {
|
|
|
290
312
|
}
|
|
291
313
|
return { status: response.status, body, requestId };
|
|
292
314
|
} catch (error62) {
|
|
315
|
+
if (!reported) notifyTransport(this.transportObserver, request.method, void 0, error62, started, attempt);
|
|
293
316
|
lastError = error62;
|
|
294
317
|
if (error62 instanceof ViraApiError) throw error62;
|
|
295
318
|
if (attempt + 1 < attempts) {
|
|
@@ -743,6 +766,24 @@ var ViraClient = class {
|
|
|
743
766
|
return response;
|
|
744
767
|
})();
|
|
745
768
|
}
|
|
769
|
+
/** Explicit opt-in upload through the existing scoped observation authority.
|
|
770
|
+
* Do not call automatically from a transport observer (recursive reporting).
|
|
771
|
+
* May be subject to observation quotas and negotiated latency capability.
|
|
772
|
+
*/
|
|
773
|
+
reportTransportLatency(input2, options = {}) {
|
|
774
|
+
if (!Number.isFinite(input2.durationMs) || input2.durationMs < 0 || input2.durationMs > 36e5) throw Error("SDK_TRANSPORT_LATENCY_INVALID");
|
|
775
|
+
return this.observe({
|
|
776
|
+
organizationId: input2.organizationId,
|
|
777
|
+
projectId: input2.projectId,
|
|
778
|
+
environmentId: input2.environmentId,
|
|
779
|
+
...input2.organizationUnitId ? { organizationUnitId: input2.organizationUnitId } : {},
|
|
780
|
+
eventId: input2.eventId,
|
|
781
|
+
eventType: "latency",
|
|
782
|
+
aiSystemId: input2.aiSystemId,
|
|
783
|
+
connectionId: input2.connectionId,
|
|
784
|
+
payload: { latencyMs: input2.durationMs }
|
|
785
|
+
}, options);
|
|
786
|
+
}
|
|
746
787
|
listObservations(input2 = {}) {
|
|
747
788
|
const query = new URLSearchParams();
|
|
748
789
|
if (input2.limit !== void 0) query.set("limit", String(input2.limit));
|
|
@@ -22793,7 +22834,7 @@ var v2Plugin = Plugin.define({
|
|
|
22793
22834
|
const apiKey = options.apiKey ?? env("VIRA_API_KEY");
|
|
22794
22835
|
const machine = isOpenCodeMachineCredential(options, apiKey);
|
|
22795
22836
|
const allowInsecureLocalhost = options.allowInsecureLocalhost ?? env("VIRA_ALLOW_INSECURE_LOCALHOST") === "true";
|
|
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") });
|
|
22837
|
+
const client = new ViraClient({ baseUrl: required3(apiUrl, "VIRA_HOST_API_URL_REQUIRED"), apiKey, apiCredentialProvider: options.apiCredentialProvider ?? options.accessTokenProvider, transportObserver: options.transportObserver, allowInsecureLocalhost, organizationUnitId: options.organizationUnitId ?? env("VIRA_ORGANIZATION_UNIT_ID") });
|
|
22797
22838
|
let scope;
|
|
22798
22839
|
try {
|
|
22799
22840
|
scope = await resolveOpenCodeCredentialScope(client, options, machine);
|
|
@@ -23137,7 +23178,7 @@ var v1Runtime = async (options) => {
|
|
|
23137
23178
|
const machine = isOpenCodeMachineCredential(options, options.apiKey ?? env("VIRA_API_KEY"));
|
|
23138
23179
|
const configuredTimeout = Number(options.timeoutMs ?? env("VIRA_HOST_TIMEOUT_MS") ?? 3e4);
|
|
23139
23180
|
const timeoutMs = Number.isFinite(configuredTimeout) ? configuredTimeout : 3e4;
|
|
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") });
|
|
23181
|
+
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, transportObserver: options.transportObserver, timeoutMs, allowInsecureLocalhost: options.allowInsecureLocalhost ?? env("VIRA_ALLOW_INSECURE_LOCALHOST") === "true", organizationUnitId: options.organizationUnitId ?? env("VIRA_ORGANIZATION_UNIT_ID") });
|
|
23141
23182
|
let scope;
|
|
23142
23183
|
try {
|
|
23143
23184
|
scope = await resolveOpenCodeCredentialScope(client, options, machine);
|
package/dist/server.js
CHANGED
|
@@ -84,6 +84,17 @@ var retryAfterMs = (value, now = Date.now()) => {
|
|
|
84
84
|
const date5 = Date.parse(value);
|
|
85
85
|
return Number.isFinite(date5) && date5 > now ? Math.min(date5 - now, 12e4) : 0;
|
|
86
86
|
};
|
|
87
|
+
function notifyTransport(observer, method, status, error62, started, attempt) {
|
|
88
|
+
if (!observer) return;
|
|
89
|
+
try {
|
|
90
|
+
const known = ["GET", "POST", "PUT", "PATCH", "DELETE"];
|
|
91
|
+
const outcome = status === 429 ? "http_429" : status !== void 0 ? status >= 200 && status < 600 ? "http_" + Math.floor(status / 100) + "xx" : "http_other" : error62 instanceof Error && ["AbortError", "TimeoutError"].includes(error62.name) ? "timeout" : "transport_error";
|
|
92
|
+
const event = Object.freeze({ method: known.includes(method) ? method : "OTHER", outcome, durationMs: Math.max(0, performance.now() - started), attempt: attempt + 1 });
|
|
93
|
+
void Promise.resolve(observer(event)).catch(() => {
|
|
94
|
+
});
|
|
95
|
+
} catch {
|
|
96
|
+
}
|
|
97
|
+
}
|
|
87
98
|
var ViraClient = class {
|
|
88
99
|
evaluations;
|
|
89
100
|
teach;
|
|
@@ -93,6 +104,7 @@ var ViraClient = class {
|
|
|
93
104
|
apiCredentialProvider;
|
|
94
105
|
operatorDelegationTokenProvider;
|
|
95
106
|
fetcher;
|
|
107
|
+
transportObserver;
|
|
96
108
|
timeoutMs;
|
|
97
109
|
retries;
|
|
98
110
|
failureMode;
|
|
@@ -104,6 +116,7 @@ var ViraClient = class {
|
|
|
104
116
|
this.apiCredentialProvider = options.apiCredentialProvider ?? options.accessTokenProvider;
|
|
105
117
|
this.operatorDelegationTokenProvider = options.operatorDelegationTokenProvider;
|
|
106
118
|
this.fetcher = options.fetcher ?? fetch;
|
|
119
|
+
this.transportObserver = options.transportObserver;
|
|
107
120
|
this.timeoutMs = Math.max(
|
|
108
121
|
1e3,
|
|
109
122
|
Math.min(options.timeoutMs ?? 15e3, 12e4)
|
|
@@ -173,6 +186,11 @@ var ViraClient = class {
|
|
|
173
186
|
if (options.limit !== void 0 && !Number.isFinite(options.limit)) throw new Error("SDK_NOTIFICATION_LIMIT_INVALID");
|
|
174
187
|
return this.request({ method: "GET", path: "/v1/notifications/inbox", query: { ...limit === void 0 ? {} : { limit: String(limit) }, ...options.cursor ? { cursor: options.cursor } : {}, ...options.search ? { search: options.search } : {} } });
|
|
175
188
|
}
|
|
189
|
+
readNotificationUpdates(options = {}) {
|
|
190
|
+
const count = options.count ?? 32;
|
|
191
|
+
if (!Number.isSafeInteger(count) || count < 1 || count > 100) throw new Error("SDK_NOTIFICATION_UPDATES_COUNT_INVALID");
|
|
192
|
+
return this.request({ method: "GET", path: "/v1/notifications/updates", query: { afterId: options.afterId ?? "latest", count: String(count) } });
|
|
193
|
+
}
|
|
176
194
|
markInboxRead(notificationId, options = {}) {
|
|
177
195
|
if (!notificationId.trim()) throw new Error("SDK_NOTIFICATION_ID_REQUIRED");
|
|
178
196
|
return this.request({ method: "POST", path: `/v1/notifications/${encodeURIComponent(notificationId)}/read`, body: {} }, { idempotencyKey: options.idempotencyKey ?? `sdk:inbox-read:${notificationId}` });
|
|
@@ -255,6 +273,8 @@ var ViraClient = class {
|
|
|
255
273
|
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
256
274
|
const controller = new AbortController();
|
|
257
275
|
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
276
|
+
const started = this.transportObserver ? performance.now() : 0;
|
|
277
|
+
let reported = false;
|
|
258
278
|
try {
|
|
259
279
|
const response = await this.fetcher(url2, {
|
|
260
280
|
method: request.method,
|
|
@@ -264,6 +284,8 @@ var ViraClient = class {
|
|
|
264
284
|
...operatorOperation ? { redirect: "error", credentials: "omit" } : {}
|
|
265
285
|
});
|
|
266
286
|
const raw = await response.text();
|
|
287
|
+
notifyTransport(this.transportObserver, request.method, response.status, void 0, started, attempt);
|
|
288
|
+
reported = true;
|
|
267
289
|
let body = null;
|
|
268
290
|
try {
|
|
269
291
|
body = raw ? JSON.parse(raw) : null;
|
|
@@ -290,6 +312,7 @@ var ViraClient = class {
|
|
|
290
312
|
}
|
|
291
313
|
return { status: response.status, body, requestId };
|
|
292
314
|
} catch (error62) {
|
|
315
|
+
if (!reported) notifyTransport(this.transportObserver, request.method, void 0, error62, started, attempt);
|
|
293
316
|
lastError = error62;
|
|
294
317
|
if (error62 instanceof ViraApiError) throw error62;
|
|
295
318
|
if (attempt + 1 < attempts) {
|
|
@@ -743,6 +766,24 @@ var ViraClient = class {
|
|
|
743
766
|
return response;
|
|
744
767
|
})();
|
|
745
768
|
}
|
|
769
|
+
/** Explicit opt-in upload through the existing scoped observation authority.
|
|
770
|
+
* Do not call automatically from a transport observer (recursive reporting).
|
|
771
|
+
* May be subject to observation quotas and negotiated latency capability.
|
|
772
|
+
*/
|
|
773
|
+
reportTransportLatency(input2, options = {}) {
|
|
774
|
+
if (!Number.isFinite(input2.durationMs) || input2.durationMs < 0 || input2.durationMs > 36e5) throw Error("SDK_TRANSPORT_LATENCY_INVALID");
|
|
775
|
+
return this.observe({
|
|
776
|
+
organizationId: input2.organizationId,
|
|
777
|
+
projectId: input2.projectId,
|
|
778
|
+
environmentId: input2.environmentId,
|
|
779
|
+
...input2.organizationUnitId ? { organizationUnitId: input2.organizationUnitId } : {},
|
|
780
|
+
eventId: input2.eventId,
|
|
781
|
+
eventType: "latency",
|
|
782
|
+
aiSystemId: input2.aiSystemId,
|
|
783
|
+
connectionId: input2.connectionId,
|
|
784
|
+
payload: { latencyMs: input2.durationMs }
|
|
785
|
+
}, options);
|
|
786
|
+
}
|
|
746
787
|
listObservations(input2 = {}) {
|
|
747
788
|
const query = new URLSearchParams();
|
|
748
789
|
if (input2.limit !== void 0) query.set("limit", String(input2.limit));
|
|
@@ -22793,7 +22834,7 @@ var v2Plugin = Plugin.define({
|
|
|
22793
22834
|
const apiKey = options.apiKey ?? env("VIRA_API_KEY");
|
|
22794
22835
|
const machine = isOpenCodeMachineCredential(options, apiKey);
|
|
22795
22836
|
const allowInsecureLocalhost = options.allowInsecureLocalhost ?? env("VIRA_ALLOW_INSECURE_LOCALHOST") === "true";
|
|
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") });
|
|
22837
|
+
const client = new ViraClient({ baseUrl: required3(apiUrl, "VIRA_HOST_API_URL_REQUIRED"), apiKey, apiCredentialProvider: options.apiCredentialProvider ?? options.accessTokenProvider, transportObserver: options.transportObserver, allowInsecureLocalhost, organizationUnitId: options.organizationUnitId ?? env("VIRA_ORGANIZATION_UNIT_ID") });
|
|
22797
22838
|
let scope;
|
|
22798
22839
|
try {
|
|
22799
22840
|
scope = await resolveOpenCodeCredentialScope(client, options, machine);
|
|
@@ -23137,7 +23178,7 @@ var v1Runtime = async (options) => {
|
|
|
23137
23178
|
const machine = isOpenCodeMachineCredential(options, options.apiKey ?? env("VIRA_API_KEY"));
|
|
23138
23179
|
const configuredTimeout = Number(options.timeoutMs ?? env("VIRA_HOST_TIMEOUT_MS") ?? 3e4);
|
|
23139
23180
|
const timeoutMs = Number.isFinite(configuredTimeout) ? configuredTimeout : 3e4;
|
|
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") });
|
|
23181
|
+
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, transportObserver: options.transportObserver, timeoutMs, allowInsecureLocalhost: options.allowInsecureLocalhost ?? env("VIRA_ALLOW_INSECURE_LOCALHOST") === "true", organizationUnitId: options.organizationUnitId ?? env("VIRA_ORGANIZATION_UNIT_ID") });
|
|
23141
23182
|
let scope;
|
|
23142
23183
|
try {
|
|
23143
23184
|
scope = await resolveOpenCodeCredentialScope(client, options, machine);
|