@opengeni/runtime 4.3.0-canary.36844267522001 → 4.3.0
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/dist/assets/codemode-client.json +1 -1
- package/dist/{chunk-XFDVXBB7.js → chunk-22M75RJF.js} +413 -502
- package/dist/chunk-22M75RJF.js.map +1 -0
- package/dist/claude-subscription-usage.d.ts +1 -3
- package/dist/index.d.ts +0 -6
- package/dist/index.js +1 -3
- package/dist/mcp-run-credentials.d.ts +2 -3
- package/dist/model-preparation-diagnostics.d.ts +0 -9
- package/dist/model-request-capture.d.ts +0 -9
- package/dist/replayable-json-body.d.ts +1 -2
- package/dist/workspace-tool-gateway.js +1 -1
- package/package.json +12 -12
- package/src/bundled_default_skills/opengeni-client/SKILL.md +0 -5
- package/src/bundled_default_skills/opengeni-client/references/api-workflows.md +0 -8
- package/src/bundled_default_skills/opengeni-client/references/product-shapes-and-ui.md +3 -16
- package/src/claude-subscription-usage.ts +4 -23
- package/src/index.ts +2 -20
- package/src/lazy-tool-transport.ts +14 -22
- package/src/mcp-run-credentials.ts +3 -18
- package/src/model-preparation-diagnostics.ts +1 -48
- package/src/model-provider-client.ts +1 -5
- package/src/model-request-capture.ts +1 -28
- package/src/replayable-json-body.ts +2 -19
- package/dist/chunk-XFDVXBB7.js.map +0 -1
- package/src/bundled_default_skills/opengeni-client/references/usage-allowances.md +0 -178
|
@@ -9474,161 +9474,273 @@ function isModelCallFetch(input) {
|
|
|
9474
9474
|
// src/replayable-json-body.ts
|
|
9475
9475
|
import OpenAI6 from "openai";
|
|
9476
9476
|
import { types as utilTypes } from "util";
|
|
9477
|
-
|
|
9478
|
-
|
|
9479
|
-
|
|
9480
|
-
|
|
9481
|
-
|
|
9482
|
-
|
|
9483
|
-
var
|
|
9484
|
-
|
|
9485
|
-
|
|
9486
|
-
|
|
9487
|
-
return modelCallLifecycle.run(lifecycle, fn);
|
|
9488
|
-
}
|
|
9489
|
-
async function beforeModelRequest() {
|
|
9490
|
-
await modelCallLifecycle.getStore()?.beforeModelRequest?.();
|
|
9491
|
-
}
|
|
9492
|
-
function modelResponseSettlement(event) {
|
|
9493
|
-
if (event.type !== "response_done") return void 0;
|
|
9494
|
-
return modelCallLifecycle.getStore()?.onModelResponse?.(event);
|
|
9495
|
-
}
|
|
9496
|
-
function nextModelContextCaptureIndex(agent) {
|
|
9497
|
-
const index = (captureIndices.get(agent) ?? 0) + 1;
|
|
9498
|
-
captureIndices.set(agent, index);
|
|
9499
|
-
return index;
|
|
9500
|
-
}
|
|
9501
|
-
function withModelRequestCapture(capture, fn) {
|
|
9502
|
-
return capture ? modelRequestCapture.run(capture, fn) : fn();
|
|
9503
|
-
}
|
|
9504
|
-
function captureProviderRequestBody(provider, input, init) {
|
|
9505
|
-
const context = modelRequestCapture.getStore();
|
|
9506
|
-
const callback = context?.onProviderRequest;
|
|
9507
|
-
if (!callback) return { init, captured: Promise.resolve(), cancel: () => {
|
|
9508
|
-
} };
|
|
9509
|
-
const index = context.nextProviderRequestIndex?.();
|
|
9510
|
-
const observer = (providerId, body2, reason) => callback(providerId, body2, reason, index);
|
|
9511
|
-
let cancel = () => {
|
|
9512
|
-
};
|
|
9513
|
-
let body = init?.body;
|
|
9514
|
-
let nextInit = init;
|
|
9515
|
-
if (body instanceof ReadableStream) {
|
|
9516
|
-
const [sent, inspected] = body.tee();
|
|
9517
|
-
nextInit = { ...init, body: sent };
|
|
9518
|
-
body = inspected;
|
|
9519
|
-
} else if (body == null && input instanceof Request) {
|
|
9520
|
-
body = input.clone().body;
|
|
9477
|
+
var TARGET_CHUNK_CHARS = 64 * 1024;
|
|
9478
|
+
var LARGE_STRING_SOURCE_CHARS = 32 * 1024;
|
|
9479
|
+
var STRING_SLICE_CODE_UNITS = 10 * 1024;
|
|
9480
|
+
var REPLAYABLE_REQUEST_BODY_FACTORY = Symbol.for(
|
|
9481
|
+
"opengeni.replayable-request-body-factory"
|
|
9482
|
+
);
|
|
9483
|
+
var ReplayableJsonBody = class {
|
|
9484
|
+
source;
|
|
9485
|
+
constructor(source) {
|
|
9486
|
+
this.source = source;
|
|
9521
9487
|
}
|
|
9522
|
-
|
|
9523
|
-
const
|
|
9524
|
-
|
|
9525
|
-
|
|
9526
|
-
|
|
9527
|
-
|
|
9528
|
-
|
|
9488
|
+
async *[Symbol.asyncIterator]() {
|
|
9489
|
+
const encoder = new TextEncoder();
|
|
9490
|
+
for (const chunk of jsonTextChunks(this.source)) {
|
|
9491
|
+
yield encoder.encode(chunk);
|
|
9492
|
+
}
|
|
9493
|
+
}
|
|
9494
|
+
createStream() {
|
|
9495
|
+
const iterator = this[Symbol.asyncIterator]();
|
|
9496
|
+
return new ReadableStream({
|
|
9497
|
+
async pull(controller) {
|
|
9498
|
+
try {
|
|
9499
|
+
const next = await iterator.next();
|
|
9500
|
+
if (next.done) controller.close();
|
|
9501
|
+
else controller.enqueue(next.value);
|
|
9502
|
+
} catch (error) {
|
|
9503
|
+
controller.error(error);
|
|
9504
|
+
}
|
|
9505
|
+
},
|
|
9506
|
+
async cancel(reason) {
|
|
9507
|
+
await iterator.return?.(reason).catch(() => void 0);
|
|
9529
9508
|
}
|
|
9530
|
-
|
|
9531
|
-
|
|
9532
|
-
|
|
9533
|
-
|
|
9534
|
-
|
|
9535
|
-
|
|
9536
|
-
|
|
9537
|
-
|
|
9538
|
-
|
|
9539
|
-
|
|
9540
|
-
|
|
9541
|
-
|
|
9542
|
-
|
|
9543
|
-
|
|
9544
|
-
|
|
9545
|
-
|
|
9546
|
-
|
|
9547
|
-
|
|
9548
|
-
|
|
9549
|
-
|
|
9550
|
-
|
|
9551
|
-
|
|
9552
|
-
|
|
9553
|
-
}
|
|
9554
|
-
chunks.push(decoder.decode(chunk.value, { stream: true }));
|
|
9509
|
+
});
|
|
9510
|
+
}
|
|
9511
|
+
};
|
|
9512
|
+
var ReplayableJsonOpenAI = class extends OpenAI6 {
|
|
9513
|
+
modelRequestPolicy;
|
|
9514
|
+
constructor(options, hooks = {}) {
|
|
9515
|
+
super(options);
|
|
9516
|
+
this.modelRequestPolicy = hooks.modelRequestPolicy;
|
|
9517
|
+
}
|
|
9518
|
+
post(path, opts) {
|
|
9519
|
+
if (!isModelRequestPath(path) || opts === void 0) {
|
|
9520
|
+
return super.post(path, opts);
|
|
9521
|
+
}
|
|
9522
|
+
const wrapped = Promise.resolve(opts).then((resolved) => {
|
|
9523
|
+
const body = resolved.body;
|
|
9524
|
+
let prepared = resolved;
|
|
9525
|
+
if (this.modelRequestPolicy && isJsonRecordBody(body)) {
|
|
9526
|
+
const policy = this.modelRequestPolicy({ path, body });
|
|
9527
|
+
if (policy?.body || policy?.headers) {
|
|
9528
|
+
prepared = {
|
|
9529
|
+
...resolved,
|
|
9530
|
+
...policy.body ? { body: policy.body } : {},
|
|
9531
|
+
...policy.headers ? { headers: mergePolicyHeaders(resolved.headers, policy.headers) } : {}
|
|
9532
|
+
};
|
|
9555
9533
|
}
|
|
9556
|
-
if (cancelled) return;
|
|
9557
|
-
chunks.push(decoder.decode());
|
|
9558
|
-
text2 = chunks.join("");
|
|
9559
|
-
} catch {
|
|
9560
|
-
void reader.cancel().catch(() => void 0);
|
|
9561
|
-
if (!cancelled)
|
|
9562
|
-
await observer(provider, null, "The provider body could not be read as UTF-8.");
|
|
9563
|
-
return;
|
|
9564
|
-
} finally {
|
|
9565
|
-
signal?.removeEventListener("abort", cancel);
|
|
9566
|
-
reader.releaseLock();
|
|
9567
|
-
cancel = () => {
|
|
9568
|
-
};
|
|
9569
9534
|
}
|
|
9535
|
+
return wrapJsonRequestOptions(prepared);
|
|
9536
|
+
});
|
|
9537
|
+
return super.post(path, wrapped);
|
|
9538
|
+
}
|
|
9539
|
+
async buildRequest(inputOptions, context) {
|
|
9540
|
+
const replayable = inputOptions.body instanceof ReplayableJsonBody ? inputOptions.body : void 0;
|
|
9541
|
+
const priorStreamingMarker = inputOptions.__metadata?.hasStreamingBody;
|
|
9542
|
+
const built = await super.buildRequest(inputOptions, context);
|
|
9543
|
+
if (!replayable) return built;
|
|
9544
|
+
if (priorStreamingMarker === void 0) {
|
|
9545
|
+
if (inputOptions.__metadata) delete inputOptions.__metadata.hasStreamingBody;
|
|
9570
9546
|
} else {
|
|
9571
|
-
|
|
9572
|
-
|
|
9547
|
+
inputOptions.__metadata = {
|
|
9548
|
+
...inputOptions.__metadata,
|
|
9549
|
+
hasStreamingBody: priorStreamingMarker
|
|
9550
|
+
};
|
|
9573
9551
|
}
|
|
9574
|
-
|
|
9575
|
-
|
|
9576
|
-
|
|
9577
|
-
}
|
|
9578
|
-
async function notifyModelRequestCapture(request) {
|
|
9579
|
-
const capture = modelRequestCapture.getStore();
|
|
9580
|
-
if (!capture) return;
|
|
9581
|
-
try {
|
|
9582
|
-
await capture(snapshotModelRequestPrefix(request));
|
|
9583
|
-
} catch {
|
|
9552
|
+
const request = built.req;
|
|
9553
|
+
request[REPLAYABLE_REQUEST_BODY_FACTORY] = () => replayable.createStream();
|
|
9554
|
+
return built;
|
|
9584
9555
|
}
|
|
9556
|
+
};
|
|
9557
|
+
function isModelRequestPath(path) {
|
|
9558
|
+
const pathname = path.split("?", 1)[0] ?? path;
|
|
9559
|
+
return pathname.endsWith("/responses") || pathname.endsWith("/chat/completions");
|
|
9585
9560
|
}
|
|
9586
|
-
function
|
|
9561
|
+
function wrapJsonRequestOptions(options) {
|
|
9562
|
+
const body = options.body;
|
|
9563
|
+
if (!isJsonObjectBody(body) || body instanceof ReplayableJsonBody) return options;
|
|
9587
9564
|
return {
|
|
9588
|
-
...
|
|
9589
|
-
|
|
9565
|
+
...options,
|
|
9566
|
+
body: new ReplayableJsonBody(body),
|
|
9567
|
+
headers: mergePolicyHeaders(options.headers, { "content-type": "application/json" })
|
|
9590
9568
|
};
|
|
9591
9569
|
}
|
|
9592
|
-
|
|
9593
|
-
|
|
9594
|
-
|
|
9570
|
+
function isJsonObjectBody(value) {
|
|
9571
|
+
if (!value || typeof value !== "object") return false;
|
|
9572
|
+
if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) return false;
|
|
9573
|
+
if (value instanceof Blob || value instanceof FormData || value instanceof URLSearchParams) {
|
|
9574
|
+
return false;
|
|
9575
|
+
}
|
|
9576
|
+
if (value instanceof ReadableStream) return false;
|
|
9577
|
+
return !(Symbol.asyncIterator in value) && !(Symbol.iterator in value);
|
|
9578
|
+
}
|
|
9579
|
+
function isJsonRecordBody(value) {
|
|
9580
|
+
return isJsonObjectBody(value) && !Array.isArray(value);
|
|
9581
|
+
}
|
|
9582
|
+
function mergePolicyHeaders(headers, additions) {
|
|
9583
|
+
const replacedNames = new Set(Object.keys(additions).map((name) => name.toLowerCase()));
|
|
9584
|
+
if (headers instanceof Headers) {
|
|
9585
|
+
const merged2 = new Headers(headers);
|
|
9586
|
+
for (const [name, value] of Object.entries(additions)) merged2.set(name, value);
|
|
9587
|
+
return merged2;
|
|
9588
|
+
}
|
|
9589
|
+
if (headers && typeof headers === "object" && "values" in headers && "nulls" in headers && headers.values instanceof Headers && headers.nulls instanceof Set) {
|
|
9590
|
+
const resolved = headers;
|
|
9591
|
+
const rows = [
|
|
9592
|
+
...resolved.values.entries(),
|
|
9593
|
+
...[...resolved.nulls].map((name) => [name, null])
|
|
9594
|
+
];
|
|
9595
|
+
return mergePolicyHeaders(rows, additions);
|
|
9596
|
+
}
|
|
9597
|
+
if (Array.isArray(headers)) {
|
|
9598
|
+
return [
|
|
9599
|
+
...headers.filter(
|
|
9600
|
+
(row) => !Array.isArray(row) || typeof row[0] !== "string" || !replacedNames.has(row[0].toLowerCase())
|
|
9601
|
+
),
|
|
9602
|
+
...Object.entries(additions)
|
|
9603
|
+
];
|
|
9604
|
+
}
|
|
9605
|
+
const merged = { ...headers ?? {} };
|
|
9606
|
+
for (const name of Object.keys(merged)) {
|
|
9607
|
+
if (replacedNames.has(name.toLowerCase())) delete merged[name];
|
|
9608
|
+
}
|
|
9609
|
+
return { ...merged, ...additions };
|
|
9610
|
+
}
|
|
9611
|
+
function* jsonTextChunks(value) {
|
|
9612
|
+
const fragments = jsonValueFragments(value, "", /* @__PURE__ */ new Set(), 0);
|
|
9613
|
+
if (!fragments) throw new TypeError("Model request body is not JSON serializable");
|
|
9614
|
+
let buffered = "";
|
|
9615
|
+
for (const fragment of fragments) {
|
|
9616
|
+
if (buffered.length > 0 && buffered.length + fragment.length > TARGET_CHUNK_CHARS) {
|
|
9617
|
+
yield buffered;
|
|
9618
|
+
buffered = "";
|
|
9619
|
+
}
|
|
9620
|
+
if (fragment.length >= TARGET_CHUNK_CHARS) yield fragment;
|
|
9621
|
+
else buffered += fragment;
|
|
9622
|
+
}
|
|
9623
|
+
if (buffered.length > 0) yield buffered;
|
|
9624
|
+
}
|
|
9625
|
+
function jsonValueFragments(source, key, ancestors, depth) {
|
|
9626
|
+
if (typeof source === "string" && source.length > LARGE_STRING_SOURCE_CHARS) {
|
|
9627
|
+
return jsonStringFragments(source);
|
|
9628
|
+
}
|
|
9629
|
+
if (depth >= 2 || depth > 0 && !Array.isArray(source)) {
|
|
9630
|
+
return nativeJsonPropertyFragments(source, key);
|
|
9631
|
+
}
|
|
9632
|
+
const value = prepareJsonValue(source, key);
|
|
9633
|
+
if (value === void 0 || typeof value === "function" || typeof value === "symbol") {
|
|
9634
|
+
return null;
|
|
9635
|
+
}
|
|
9636
|
+
if (typeof value === "bigint") {
|
|
9637
|
+
throw new TypeError("Do not know how to serialize a BigInt");
|
|
9638
|
+
}
|
|
9639
|
+
if (typeof value === "string") {
|
|
9640
|
+
return jsonStringFragments(value);
|
|
9641
|
+
}
|
|
9642
|
+
if (value === null || typeof value !== "object") {
|
|
9643
|
+
return [JSON.stringify(value)];
|
|
9644
|
+
}
|
|
9645
|
+
const rawJson = JSON;
|
|
9646
|
+
if (rawJson.isRawJSON?.(value)) return [JSON.stringify(value)];
|
|
9647
|
+
if (ancestors.has(value)) throw new TypeError("cyclic object value");
|
|
9648
|
+
return Array.isArray(value) ? jsonArrayFragments(value, ancestors, depth) : jsonObjectFragments(value, ancestors, depth);
|
|
9649
|
+
}
|
|
9650
|
+
function* jsonArrayFragments(value, ancestors, depth) {
|
|
9651
|
+
ancestors.add(value);
|
|
9652
|
+
try {
|
|
9653
|
+
const length = value.length;
|
|
9654
|
+
yield "[";
|
|
9655
|
+
for (let index = 0; index < length; index += 1) {
|
|
9656
|
+
if (index > 0) yield ",";
|
|
9657
|
+
const child = jsonValueFragments(value[index], String(index), ancestors, depth + 1);
|
|
9658
|
+
if (child) yield* child;
|
|
9659
|
+
else yield "null";
|
|
9660
|
+
}
|
|
9661
|
+
yield "]";
|
|
9662
|
+
} finally {
|
|
9663
|
+
ancestors.delete(value);
|
|
9664
|
+
}
|
|
9665
|
+
}
|
|
9666
|
+
function* jsonObjectFragments(value, ancestors, depth) {
|
|
9667
|
+
ancestors.add(value);
|
|
9668
|
+
try {
|
|
9669
|
+
const keys = Object.keys(value);
|
|
9670
|
+
let emitted = false;
|
|
9671
|
+
yield "{";
|
|
9672
|
+
for (const key of keys) {
|
|
9673
|
+
const child = jsonValueFragments(value[key], key, ancestors, depth + 1);
|
|
9674
|
+
if (!child) continue;
|
|
9675
|
+
if (emitted) yield ",";
|
|
9676
|
+
emitted = true;
|
|
9677
|
+
yield* jsonStringFragments(key);
|
|
9678
|
+
yield ":";
|
|
9679
|
+
yield* child;
|
|
9680
|
+
}
|
|
9681
|
+
yield "}";
|
|
9682
|
+
} finally {
|
|
9683
|
+
ancestors.delete(value);
|
|
9595
9684
|
}
|
|
9596
|
-
|
|
9597
|
-
|
|
9598
|
-
|
|
9599
|
-
|
|
9600
|
-
|
|
9685
|
+
}
|
|
9686
|
+
function nativeJsonPropertyFragments(source, key) {
|
|
9687
|
+
const holder = /* @__PURE__ */ Object.create(null);
|
|
9688
|
+
holder[key] = source;
|
|
9689
|
+
const serialized = JSON.stringify(holder);
|
|
9690
|
+
if (serialized === "{}") return null;
|
|
9691
|
+
const prefix = `{${JSON.stringify(key)}:`;
|
|
9692
|
+
if (!serialized.startsWith(prefix) || !serialized.endsWith("}")) {
|
|
9693
|
+
throw new TypeError("Model request body is not JSON serializable");
|
|
9601
9694
|
}
|
|
9602
|
-
|
|
9603
|
-
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
|
|
9607
|
-
|
|
9608
|
-
|
|
9609
|
-
yield event;
|
|
9695
|
+
return boundedNativeJsonFragments(serialized.slice(prefix.length, -1));
|
|
9696
|
+
}
|
|
9697
|
+
function* boundedNativeJsonFragments(serialized) {
|
|
9698
|
+
for (let start = 0; start < serialized.length; ) {
|
|
9699
|
+
let end = Math.min(serialized.length, start + TARGET_CHUNK_CHARS);
|
|
9700
|
+
if (end < serialized.length && serialized.charCodeAt(end - 1) >= 55296 && serialized.charCodeAt(end - 1) <= 56319 && serialized.charCodeAt(end) >= 56320 && serialized.charCodeAt(end) <= 57343) {
|
|
9701
|
+
end -= 1;
|
|
9610
9702
|
}
|
|
9703
|
+
yield serialized.slice(start, end);
|
|
9704
|
+
start = end;
|
|
9611
9705
|
}
|
|
9612
|
-
|
|
9613
|
-
|
|
9706
|
+
}
|
|
9707
|
+
function prepareJsonValue(source, key) {
|
|
9708
|
+
let value = source;
|
|
9709
|
+
const sourceType = typeof value;
|
|
9710
|
+
if (value !== null && (sourceType === "object" || sourceType === "function" || sourceType === "bigint")) {
|
|
9711
|
+
const toJSON = value.toJSON;
|
|
9712
|
+
if (typeof toJSON === "function") value = toJSON.call(value, key);
|
|
9614
9713
|
}
|
|
9615
|
-
|
|
9616
|
-
|
|
9617
|
-
|
|
9618
|
-
|
|
9714
|
+
if (value !== null && typeof value === "object") {
|
|
9715
|
+
if (utilTypes.isNumberObject(value)) return Number.prototype.valueOf.call(value);
|
|
9716
|
+
if (utilTypes.isStringObject(value)) return String.prototype.valueOf.call(value);
|
|
9717
|
+
if (utilTypes.isBooleanObject(value)) return Boolean.prototype.valueOf.call(value);
|
|
9718
|
+
if (utilTypes.isBigIntObject(value)) return BigInt.prototype.valueOf.call(value);
|
|
9619
9719
|
}
|
|
9620
|
-
|
|
9621
|
-
|
|
9622
|
-
|
|
9623
|
-
|
|
9720
|
+
return value;
|
|
9721
|
+
}
|
|
9722
|
+
function* jsonStringFragments(value) {
|
|
9723
|
+
if (value.length <= LARGE_STRING_SOURCE_CHARS) {
|
|
9724
|
+
yield JSON.stringify(value);
|
|
9725
|
+
return;
|
|
9624
9726
|
}
|
|
9625
|
-
|
|
9727
|
+
yield '"';
|
|
9728
|
+
for (let start = 0; start < value.length; ) {
|
|
9729
|
+
let end = Math.min(value.length, start + STRING_SLICE_CODE_UNITS);
|
|
9730
|
+
if (end < value.length && value.charCodeAt(end - 1) >= 55296 && value.charCodeAt(end - 1) <= 56319 && value.charCodeAt(end) >= 56320 && value.charCodeAt(end) <= 57343) {
|
|
9731
|
+
end -= 1;
|
|
9732
|
+
}
|
|
9733
|
+
const encoded = JSON.stringify(value.slice(start, end));
|
|
9734
|
+
yield encoded.slice(1, -1);
|
|
9735
|
+
start = end;
|
|
9736
|
+
}
|
|
9737
|
+
yield '"';
|
|
9738
|
+
}
|
|
9626
9739
|
|
|
9627
9740
|
// src/model-preparation-diagnostics.ts
|
|
9628
|
-
|
|
9629
|
-
var
|
|
9630
|
-
var
|
|
9631
|
-
var modelTransportRefusals = /* @__PURE__ */ new WeakMap();
|
|
9741
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
9742
|
+
var modelPreparationObserver = new AsyncLocalStorage2();
|
|
9743
|
+
var modelTransportStartedObserver = new AsyncLocalStorage2();
|
|
9632
9744
|
var ModelPreparationTraceProcessor = class {
|
|
9633
9745
|
async onTraceStart(_trace) {
|
|
9634
9746
|
}
|
|
@@ -9669,38 +9781,7 @@ function withModelTransportStartedObserver(observer, callback) {
|
|
|
9669
9781
|
return observer ? modelTransportStartedObserver.run(observer, callback) : callback();
|
|
9670
9782
|
}
|
|
9671
9783
|
async function recordModelTransportStarted() {
|
|
9672
|
-
|
|
9673
|
-
await beforeModelRequest();
|
|
9674
|
-
await modelTransportStartedObserver.getStore()?.();
|
|
9675
|
-
} catch (error) {
|
|
9676
|
-
const admission = modelTransportAdmission.getStore();
|
|
9677
|
-
if (admission) admission.refusal = { error };
|
|
9678
|
-
throw error;
|
|
9679
|
-
}
|
|
9680
|
-
}
|
|
9681
|
-
function sdkModelTransportAdmissionFetch(inner) {
|
|
9682
|
-
return async (input, init) => {
|
|
9683
|
-
const admission = {};
|
|
9684
|
-
return modelTransportAdmission.run(admission, async () => {
|
|
9685
|
-
try {
|
|
9686
|
-
return await inner(input, init);
|
|
9687
|
-
} catch (error) {
|
|
9688
|
-
if (!admission.refusal || admission.refusal.error !== error) throw error;
|
|
9689
|
-
const response = new Response(null, {
|
|
9690
|
-
status: 400,
|
|
9691
|
-
headers: { "x-should-retry": "false" }
|
|
9692
|
-
});
|
|
9693
|
-
modelTransportRefusals.set(response.headers, admission.refusal);
|
|
9694
|
-
return response;
|
|
9695
|
-
}
|
|
9696
|
-
});
|
|
9697
|
-
};
|
|
9698
|
-
}
|
|
9699
|
-
function rethrowModelTransportAdmissionRefusal(headers) {
|
|
9700
|
-
const refusal = modelTransportRefusals.get(headers);
|
|
9701
|
-
if (!refusal) return;
|
|
9702
|
-
modelTransportRefusals.delete(headers);
|
|
9703
|
-
throw refusal.error;
|
|
9784
|
+
await modelTransportStartedObserver.getStore()?.();
|
|
9704
9785
|
}
|
|
9705
9786
|
function markModelPreparationFirstSandboxOperation(durationSeconds) {
|
|
9706
9787
|
try {
|
|
@@ -9865,300 +9946,158 @@ function withModelPreparationClientDiagnostics(client) {
|
|
|
9865
9946
|
durationSeconds: (performance.now() - startedAt) / 1e3
|
|
9866
9947
|
});
|
|
9867
9948
|
}
|
|
9868
|
-
};
|
|
9869
|
-
}
|
|
9870
|
-
});
|
|
9871
|
-
}
|
|
9872
|
-
function recordModelPreparationManifestInventory(phase, manifest) {
|
|
9873
|
-
const startedAt = performance.now();
|
|
9874
|
-
let outcome = "completed";
|
|
9875
|
-
let count = 0;
|
|
9876
|
-
try {
|
|
9877
|
-
if (manifest && typeof manifest === "object" && "iterEntries" in manifest && typeof manifest.iterEntries === "function") {
|
|
9878
|
-
for (const _entry of manifest.iterEntries()) count += 1;
|
|
9879
|
-
}
|
|
9880
|
-
} catch {
|
|
9881
|
-
outcome = "failed";
|
|
9882
|
-
} finally {
|
|
9883
|
-
recordModelPreparationMeasurement({
|
|
9884
|
-
phase,
|
|
9885
|
-
outcome,
|
|
9886
|
-
durationSeconds: (performance.now() - startedAt) / 1e3,
|
|
9887
|
-
count
|
|
9888
|
-
});
|
|
9889
|
-
}
|
|
9890
|
-
}
|
|
9891
|
-
|
|
9892
|
-
// src/replayable-json-body.ts
|
|
9893
|
-
var TARGET_CHUNK_CHARS = 64 * 1024;
|
|
9894
|
-
var LARGE_STRING_SOURCE_CHARS = 32 * 1024;
|
|
9895
|
-
var STRING_SLICE_CODE_UNITS = 10 * 1024;
|
|
9896
|
-
var REPLAYABLE_REQUEST_BODY_FACTORY = Symbol.for(
|
|
9897
|
-
"opengeni.replayable-request-body-factory"
|
|
9898
|
-
);
|
|
9899
|
-
var ReplayableJsonBody = class {
|
|
9900
|
-
source;
|
|
9901
|
-
constructor(source) {
|
|
9902
|
-
this.source = source;
|
|
9903
|
-
}
|
|
9904
|
-
async *[Symbol.asyncIterator]() {
|
|
9905
|
-
const encoder = new TextEncoder();
|
|
9906
|
-
for (const chunk of jsonTextChunks(this.source)) {
|
|
9907
|
-
yield encoder.encode(chunk);
|
|
9908
|
-
}
|
|
9909
|
-
}
|
|
9910
|
-
createStream() {
|
|
9911
|
-
const iterator = this[Symbol.asyncIterator]();
|
|
9912
|
-
return new ReadableStream({
|
|
9913
|
-
async pull(controller) {
|
|
9914
|
-
try {
|
|
9915
|
-
const next = await iterator.next();
|
|
9916
|
-
if (next.done) controller.close();
|
|
9917
|
-
else controller.enqueue(next.value);
|
|
9918
|
-
} catch (error) {
|
|
9919
|
-
controller.error(error);
|
|
9920
|
-
}
|
|
9921
|
-
},
|
|
9922
|
-
async cancel(reason) {
|
|
9923
|
-
await iterator.return?.(reason).catch(() => void 0);
|
|
9924
|
-
}
|
|
9925
|
-
});
|
|
9926
|
-
}
|
|
9927
|
-
};
|
|
9928
|
-
var ReplayableJsonOpenAI = class extends OpenAI6 {
|
|
9929
|
-
modelRequestPolicy;
|
|
9930
|
-
constructor(options, hooks = {}) {
|
|
9931
|
-
super({
|
|
9932
|
-
...options,
|
|
9933
|
-
fetch: sdkModelTransportAdmissionFetch(options?.fetch ?? globalThis.fetch)
|
|
9934
|
-
});
|
|
9935
|
-
this.modelRequestPolicy = hooks.modelRequestPolicy;
|
|
9936
|
-
}
|
|
9937
|
-
makeStatusError(status, error, message, headers) {
|
|
9938
|
-
rethrowModelTransportAdmissionRefusal(headers);
|
|
9939
|
-
return super.makeStatusError(status, error, message, headers);
|
|
9940
|
-
}
|
|
9941
|
-
post(path, opts) {
|
|
9942
|
-
if (!isModelRequestPath(path) || opts === void 0) {
|
|
9943
|
-
return super.post(path, opts);
|
|
9944
|
-
}
|
|
9945
|
-
const wrapped = Promise.resolve(opts).then((resolved) => {
|
|
9946
|
-
const body = resolved.body;
|
|
9947
|
-
let prepared = resolved;
|
|
9948
|
-
if (this.modelRequestPolicy && isJsonRecordBody(body)) {
|
|
9949
|
-
const policy = this.modelRequestPolicy({ path, body });
|
|
9950
|
-
if (policy?.body || policy?.headers) {
|
|
9951
|
-
prepared = {
|
|
9952
|
-
...resolved,
|
|
9953
|
-
...policy.body ? { body: policy.body } : {},
|
|
9954
|
-
...policy.headers ? { headers: mergePolicyHeaders(resolved.headers, policy.headers) } : {}
|
|
9955
|
-
};
|
|
9956
|
-
}
|
|
9957
|
-
}
|
|
9958
|
-
return wrapJsonRequestOptions(prepared);
|
|
9959
|
-
});
|
|
9960
|
-
return super.post(path, wrapped);
|
|
9961
|
-
}
|
|
9962
|
-
async buildRequest(inputOptions, context) {
|
|
9963
|
-
const replayable = inputOptions.body instanceof ReplayableJsonBody ? inputOptions.body : void 0;
|
|
9964
|
-
const priorStreamingMarker = inputOptions.__metadata?.hasStreamingBody;
|
|
9965
|
-
const built = await super.buildRequest(inputOptions, context);
|
|
9966
|
-
if (!replayable) return built;
|
|
9967
|
-
if (priorStreamingMarker === void 0) {
|
|
9968
|
-
if (inputOptions.__metadata) delete inputOptions.__metadata.hasStreamingBody;
|
|
9969
|
-
} else {
|
|
9970
|
-
inputOptions.__metadata = {
|
|
9971
|
-
...inputOptions.__metadata,
|
|
9972
|
-
hasStreamingBody: priorStreamingMarker
|
|
9973
|
-
};
|
|
9974
|
-
}
|
|
9975
|
-
const request = built.req;
|
|
9976
|
-
request[REPLAYABLE_REQUEST_BODY_FACTORY] = () => replayable.createStream();
|
|
9977
|
-
return built;
|
|
9978
|
-
}
|
|
9979
|
-
};
|
|
9980
|
-
function isModelRequestPath(path) {
|
|
9981
|
-
const pathname = path.split("?", 1)[0] ?? path;
|
|
9982
|
-
return pathname.endsWith("/responses") || pathname.endsWith("/chat/completions");
|
|
9983
|
-
}
|
|
9984
|
-
function wrapJsonRequestOptions(options) {
|
|
9985
|
-
const body = options.body;
|
|
9986
|
-
if (!isJsonObjectBody(body) || body instanceof ReplayableJsonBody) return options;
|
|
9987
|
-
return {
|
|
9988
|
-
...options,
|
|
9989
|
-
body: new ReplayableJsonBody(body),
|
|
9990
|
-
headers: mergePolicyHeaders(options.headers, { "content-type": "application/json" })
|
|
9991
|
-
};
|
|
9992
|
-
}
|
|
9993
|
-
function isJsonObjectBody(value) {
|
|
9994
|
-
if (!value || typeof value !== "object") return false;
|
|
9995
|
-
if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) return false;
|
|
9996
|
-
if (value instanceof Blob || value instanceof FormData || value instanceof URLSearchParams) {
|
|
9997
|
-
return false;
|
|
9998
|
-
}
|
|
9999
|
-
if (value instanceof ReadableStream) return false;
|
|
10000
|
-
return !(Symbol.asyncIterator in value) && !(Symbol.iterator in value);
|
|
10001
|
-
}
|
|
10002
|
-
function isJsonRecordBody(value) {
|
|
10003
|
-
return isJsonObjectBody(value) && !Array.isArray(value);
|
|
10004
|
-
}
|
|
10005
|
-
function mergePolicyHeaders(headers, additions) {
|
|
10006
|
-
const replacedNames = new Set(Object.keys(additions).map((name) => name.toLowerCase()));
|
|
10007
|
-
if (headers instanceof Headers) {
|
|
10008
|
-
const merged2 = new Headers(headers);
|
|
10009
|
-
for (const [name, value] of Object.entries(additions)) merged2.set(name, value);
|
|
10010
|
-
return merged2;
|
|
10011
|
-
}
|
|
10012
|
-
if (headers && typeof headers === "object" && "values" in headers && "nulls" in headers && headers.values instanceof Headers && headers.nulls instanceof Set) {
|
|
10013
|
-
const resolved = headers;
|
|
10014
|
-
const rows = [
|
|
10015
|
-
...resolved.values.entries(),
|
|
10016
|
-
...[...resolved.nulls].map((name) => [name, null])
|
|
10017
|
-
];
|
|
10018
|
-
return mergePolicyHeaders(rows, additions);
|
|
10019
|
-
}
|
|
10020
|
-
if (Array.isArray(headers)) {
|
|
10021
|
-
return [
|
|
10022
|
-
...headers.filter(
|
|
10023
|
-
(row) => !Array.isArray(row) || typeof row[0] !== "string" || !replacedNames.has(row[0].toLowerCase())
|
|
10024
|
-
),
|
|
10025
|
-
...Object.entries(additions)
|
|
10026
|
-
];
|
|
10027
|
-
}
|
|
10028
|
-
const merged = { ...headers ?? {} };
|
|
10029
|
-
for (const name of Object.keys(merged)) {
|
|
10030
|
-
if (replacedNames.has(name.toLowerCase())) delete merged[name];
|
|
10031
|
-
}
|
|
10032
|
-
return { ...merged, ...additions };
|
|
10033
|
-
}
|
|
10034
|
-
function* jsonTextChunks(value) {
|
|
10035
|
-
const fragments = jsonValueFragments(value, "", /* @__PURE__ */ new Set(), 0);
|
|
10036
|
-
if (!fragments) throw new TypeError("Model request body is not JSON serializable");
|
|
10037
|
-
let buffered = "";
|
|
10038
|
-
for (const fragment of fragments) {
|
|
10039
|
-
if (buffered.length > 0 && buffered.length + fragment.length > TARGET_CHUNK_CHARS) {
|
|
10040
|
-
yield buffered;
|
|
10041
|
-
buffered = "";
|
|
9949
|
+
};
|
|
10042
9950
|
}
|
|
10043
|
-
|
|
10044
|
-
else buffered += fragment;
|
|
10045
|
-
}
|
|
10046
|
-
if (buffered.length > 0) yield buffered;
|
|
10047
|
-
}
|
|
10048
|
-
function jsonValueFragments(source, key, ancestors, depth) {
|
|
10049
|
-
if (typeof source === "string" && source.length > LARGE_STRING_SOURCE_CHARS) {
|
|
10050
|
-
return jsonStringFragments(source);
|
|
10051
|
-
}
|
|
10052
|
-
if (depth >= 2 || depth > 0 && !Array.isArray(source)) {
|
|
10053
|
-
return nativeJsonPropertyFragments(source, key);
|
|
10054
|
-
}
|
|
10055
|
-
const value = prepareJsonValue(source, key);
|
|
10056
|
-
if (value === void 0 || typeof value === "function" || typeof value === "symbol") {
|
|
10057
|
-
return null;
|
|
10058
|
-
}
|
|
10059
|
-
if (typeof value === "bigint") {
|
|
10060
|
-
throw new TypeError("Do not know how to serialize a BigInt");
|
|
10061
|
-
}
|
|
10062
|
-
if (typeof value === "string") {
|
|
10063
|
-
return jsonStringFragments(value);
|
|
10064
|
-
}
|
|
10065
|
-
if (value === null || typeof value !== "object") {
|
|
10066
|
-
return [JSON.stringify(value)];
|
|
10067
|
-
}
|
|
10068
|
-
const rawJson = JSON;
|
|
10069
|
-
if (rawJson.isRawJSON?.(value)) return [JSON.stringify(value)];
|
|
10070
|
-
if (ancestors.has(value)) throw new TypeError("cyclic object value");
|
|
10071
|
-
return Array.isArray(value) ? jsonArrayFragments(value, ancestors, depth) : jsonObjectFragments(value, ancestors, depth);
|
|
9951
|
+
});
|
|
10072
9952
|
}
|
|
10073
|
-
function
|
|
10074
|
-
|
|
9953
|
+
function recordModelPreparationManifestInventory(phase, manifest) {
|
|
9954
|
+
const startedAt = performance.now();
|
|
9955
|
+
let outcome = "completed";
|
|
9956
|
+
let count = 0;
|
|
10075
9957
|
try {
|
|
10076
|
-
|
|
10077
|
-
|
|
10078
|
-
for (let index = 0; index < length; index += 1) {
|
|
10079
|
-
if (index > 0) yield ",";
|
|
10080
|
-
const child = jsonValueFragments(value[index], String(index), ancestors, depth + 1);
|
|
10081
|
-
if (child) yield* child;
|
|
10082
|
-
else yield "null";
|
|
9958
|
+
if (manifest && typeof manifest === "object" && "iterEntries" in manifest && typeof manifest.iterEntries === "function") {
|
|
9959
|
+
for (const _entry of manifest.iterEntries()) count += 1;
|
|
10083
9960
|
}
|
|
10084
|
-
|
|
9961
|
+
} catch {
|
|
9962
|
+
outcome = "failed";
|
|
10085
9963
|
} finally {
|
|
10086
|
-
|
|
9964
|
+
recordModelPreparationMeasurement({
|
|
9965
|
+
phase,
|
|
9966
|
+
outcome,
|
|
9967
|
+
durationSeconds: (performance.now() - startedAt) / 1e3,
|
|
9968
|
+
count
|
|
9969
|
+
});
|
|
10087
9970
|
}
|
|
10088
9971
|
}
|
|
10089
|
-
|
|
10090
|
-
|
|
10091
|
-
|
|
10092
|
-
|
|
10093
|
-
|
|
10094
|
-
|
|
10095
|
-
|
|
10096
|
-
|
|
10097
|
-
|
|
10098
|
-
if (emitted) yield ",";
|
|
10099
|
-
emitted = true;
|
|
10100
|
-
yield* jsonStringFragments(key);
|
|
10101
|
-
yield ":";
|
|
10102
|
-
yield* child;
|
|
10103
|
-
}
|
|
10104
|
-
yield "}";
|
|
10105
|
-
} finally {
|
|
10106
|
-
ancestors.delete(value);
|
|
10107
|
-
}
|
|
9972
|
+
|
|
9973
|
+
// src/model-request-capture.ts
|
|
9974
|
+
import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
|
|
9975
|
+
var modelRequestCapture = new AsyncLocalStorage3();
|
|
9976
|
+
var captureIndices = /* @__PURE__ */ new WeakMap();
|
|
9977
|
+
function nextModelContextCaptureIndex(agent) {
|
|
9978
|
+
const index = (captureIndices.get(agent) ?? 0) + 1;
|
|
9979
|
+
captureIndices.set(agent, index);
|
|
9980
|
+
return index;
|
|
10108
9981
|
}
|
|
10109
|
-
function
|
|
10110
|
-
|
|
10111
|
-
holder[key] = source;
|
|
10112
|
-
const serialized = JSON.stringify(holder);
|
|
10113
|
-
if (serialized === "{}") return null;
|
|
10114
|
-
const prefix = `{${JSON.stringify(key)}:`;
|
|
10115
|
-
if (!serialized.startsWith(prefix) || !serialized.endsWith("}")) {
|
|
10116
|
-
throw new TypeError("Model request body is not JSON serializable");
|
|
10117
|
-
}
|
|
10118
|
-
return boundedNativeJsonFragments(serialized.slice(prefix.length, -1));
|
|
9982
|
+
function withModelRequestCapture(capture, fn) {
|
|
9983
|
+
return capture ? modelRequestCapture.run(capture, fn) : fn();
|
|
10119
9984
|
}
|
|
10120
|
-
function
|
|
10121
|
-
|
|
10122
|
-
|
|
10123
|
-
|
|
10124
|
-
|
|
9985
|
+
function captureProviderRequestBody(provider, input, init) {
|
|
9986
|
+
const context = modelRequestCapture.getStore();
|
|
9987
|
+
const callback = context?.onProviderRequest;
|
|
9988
|
+
if (!callback) return { init, captured: Promise.resolve(), cancel: () => {
|
|
9989
|
+
} };
|
|
9990
|
+
const index = context.nextProviderRequestIndex?.();
|
|
9991
|
+
const observer = (providerId, body2, reason) => callback(providerId, body2, reason, index);
|
|
9992
|
+
let cancel = () => {
|
|
9993
|
+
};
|
|
9994
|
+
let body = init?.body;
|
|
9995
|
+
let nextInit = init;
|
|
9996
|
+
if (body instanceof ReadableStream) {
|
|
9997
|
+
const [sent, inspected] = body.tee();
|
|
9998
|
+
nextInit = { ...init, body: sent };
|
|
9999
|
+
body = inspected;
|
|
10000
|
+
} else if (body == null && input instanceof Request) {
|
|
10001
|
+
body = input.clone().body;
|
|
10002
|
+
}
|
|
10003
|
+
const captured = (async () => {
|
|
10004
|
+
const limit = 4 * 1024 * 1024;
|
|
10005
|
+
let text2;
|
|
10006
|
+
if (typeof body === "string") {
|
|
10007
|
+
if (Buffer.byteLength(body, "utf8") > limit) {
|
|
10008
|
+
await observer(provider, null, "Request exceeds the 4 MiB capture limit.");
|
|
10009
|
+
return;
|
|
10010
|
+
}
|
|
10011
|
+
text2 = body;
|
|
10012
|
+
} else if (body instanceof ReadableStream) {
|
|
10013
|
+
const reader = body.getReader();
|
|
10014
|
+
let cancelled = false;
|
|
10015
|
+
cancel = () => {
|
|
10016
|
+
cancelled = true;
|
|
10017
|
+
void reader.cancel().catch(() => void 0);
|
|
10018
|
+
};
|
|
10019
|
+
const signal = init?.signal ?? (input instanceof Request ? input.signal : void 0);
|
|
10020
|
+
signal?.addEventListener("abort", cancel, { once: true });
|
|
10021
|
+
if (signal?.aborted) cancel();
|
|
10022
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
10023
|
+
const chunks = [];
|
|
10024
|
+
let bytes = 0;
|
|
10025
|
+
try {
|
|
10026
|
+
while (true) {
|
|
10027
|
+
const chunk = await reader.read();
|
|
10028
|
+
if (chunk.done) break;
|
|
10029
|
+
bytes += chunk.value.byteLength;
|
|
10030
|
+
if (bytes > limit) {
|
|
10031
|
+
void reader.cancel().catch(() => void 0);
|
|
10032
|
+
await observer(provider, null, "Request exceeds the 4 MiB capture limit.");
|
|
10033
|
+
return;
|
|
10034
|
+
}
|
|
10035
|
+
chunks.push(decoder.decode(chunk.value, { stream: true }));
|
|
10036
|
+
}
|
|
10037
|
+
if (cancelled) return;
|
|
10038
|
+
chunks.push(decoder.decode());
|
|
10039
|
+
text2 = chunks.join("");
|
|
10040
|
+
} catch {
|
|
10041
|
+
void reader.cancel().catch(() => void 0);
|
|
10042
|
+
if (!cancelled)
|
|
10043
|
+
await observer(provider, null, "The provider body could not be read as UTF-8.");
|
|
10044
|
+
return;
|
|
10045
|
+
} finally {
|
|
10046
|
+
signal?.removeEventListener("abort", cancel);
|
|
10047
|
+
reader.releaseLock();
|
|
10048
|
+
cancel = () => {
|
|
10049
|
+
};
|
|
10050
|
+
}
|
|
10051
|
+
} else {
|
|
10052
|
+
await observer(provider, null, "This transport body cannot be inspected.");
|
|
10053
|
+
return;
|
|
10125
10054
|
}
|
|
10126
|
-
|
|
10127
|
-
|
|
10055
|
+
await observer(provider, text2);
|
|
10056
|
+
})().catch(() => void 0);
|
|
10057
|
+
return { init: nextInit, captured, cancel: () => cancel() };
|
|
10058
|
+
}
|
|
10059
|
+
async function notifyModelRequestCapture(request) {
|
|
10060
|
+
const capture = modelRequestCapture.getStore();
|
|
10061
|
+
if (!capture) return;
|
|
10062
|
+
try {
|
|
10063
|
+
await capture(snapshotModelRequestPrefix(request));
|
|
10064
|
+
} catch {
|
|
10128
10065
|
}
|
|
10129
10066
|
}
|
|
10130
|
-
function
|
|
10131
|
-
|
|
10132
|
-
|
|
10133
|
-
|
|
10134
|
-
|
|
10135
|
-
|
|
10067
|
+
function snapshotModelRequestPrefix(request) {
|
|
10068
|
+
return {
|
|
10069
|
+
...request,
|
|
10070
|
+
tools: structuredClone(request.tools)
|
|
10071
|
+
};
|
|
10072
|
+
}
|
|
10073
|
+
var ModelRequestCaptureModel = class {
|
|
10074
|
+
constructor(inner) {
|
|
10075
|
+
this.inner = inner;
|
|
10136
10076
|
}
|
|
10137
|
-
|
|
10138
|
-
|
|
10139
|
-
|
|
10140
|
-
|
|
10141
|
-
if (utilTypes.isBigIntObject(value)) return BigInt.prototype.valueOf.call(value);
|
|
10077
|
+
async getResponse(request) {
|
|
10078
|
+
rememberPreparedModelRequest(request);
|
|
10079
|
+
void notifyModelRequestCapture(request);
|
|
10080
|
+
return this.inner.getResponse(request);
|
|
10142
10081
|
}
|
|
10143
|
-
|
|
10144
|
-
|
|
10145
|
-
|
|
10146
|
-
|
|
10147
|
-
yield JSON.stringify(value);
|
|
10148
|
-
return;
|
|
10082
|
+
async *getStreamedResponse(request) {
|
|
10083
|
+
rememberPreparedModelRequest(request);
|
|
10084
|
+
void notifyModelRequestCapture(request);
|
|
10085
|
+
yield* this.inner.getStreamedResponse(request);
|
|
10149
10086
|
}
|
|
10150
|
-
|
|
10151
|
-
|
|
10152
|
-
let end = Math.min(value.length, start + STRING_SLICE_CODE_UNITS);
|
|
10153
|
-
if (end < value.length && value.charCodeAt(end - 1) >= 55296 && value.charCodeAt(end - 1) <= 56319 && value.charCodeAt(end) >= 56320 && value.charCodeAt(end) <= 57343) {
|
|
10154
|
-
end -= 1;
|
|
10155
|
-
}
|
|
10156
|
-
const encoded = JSON.stringify(value.slice(start, end));
|
|
10157
|
-
yield encoded.slice(1, -1);
|
|
10158
|
-
start = end;
|
|
10087
|
+
getRetryAdvice(args) {
|
|
10088
|
+
return this.inner.getRetryAdvice?.(args);
|
|
10159
10089
|
}
|
|
10160
|
-
|
|
10161
|
-
|
|
10090
|
+
};
|
|
10091
|
+
var ModelRequestCaptureProvider = class {
|
|
10092
|
+
constructor(inner) {
|
|
10093
|
+
this.inner = inner;
|
|
10094
|
+
}
|
|
10095
|
+
async getModel(modelName) {
|
|
10096
|
+
const model = await this.inner.getModel(modelName);
|
|
10097
|
+
if (model instanceof ModelRequestCaptureModel) return model;
|
|
10098
|
+
return new ModelRequestCaptureModel(model);
|
|
10099
|
+
}
|
|
10100
|
+
};
|
|
10162
10101
|
|
|
10163
10102
|
// src/provider-quota.ts
|
|
10164
10103
|
import { APIError } from "openai";
|
|
@@ -10410,19 +10349,12 @@ function withoutQuotaExhaustedRetries(inner) {
|
|
|
10410
10349
|
// src/claude-subscription-usage.ts
|
|
10411
10350
|
import { AsyncLocalStorage as AsyncLocalStorage4 } from "async_hooks";
|
|
10412
10351
|
var observers = new AsyncLocalStorage4();
|
|
10413
|
-
function withClaudeUsageObserver(observer, run2
|
|
10414
|
-
return observers.run(
|
|
10415
|
-
}
|
|
10416
|
-
async function prepareClaudeSubscriptionRequest(providerId, input, init) {
|
|
10417
|
-
const prepare = observers.getStore()?.prepare;
|
|
10418
|
-
if (!prepare) return init;
|
|
10419
|
-
const headers = new Headers(input instanceof Request ? input.headers : void 0);
|
|
10420
|
-
new Headers(init?.headers).forEach((value, key) => headers.set(key, value));
|
|
10421
|
-
return { ...init, headers: await prepare(providerId, headers) };
|
|
10352
|
+
function withClaudeUsageObserver(observer, run2) {
|
|
10353
|
+
return observers.run(observer, run2);
|
|
10422
10354
|
}
|
|
10423
10355
|
function observeClaudeUsageResponse(providerId, response) {
|
|
10424
10356
|
try {
|
|
10425
|
-
observers.getStore()?.
|
|
10357
|
+
observers.getStore()?.(providerId, response);
|
|
10426
10358
|
} catch {
|
|
10427
10359
|
}
|
|
10428
10360
|
}
|
|
@@ -10695,7 +10627,6 @@ function instrumentedModelFetch(provider, inner) {
|
|
|
10695
10627
|
if (!isModelCallFetch(input)) {
|
|
10696
10628
|
return await inner(input, init);
|
|
10697
10629
|
}
|
|
10698
|
-
init = await prepareClaudeSubscriptionRequest(provider, input, init);
|
|
10699
10630
|
await recordModelTransportStarted();
|
|
10700
10631
|
const capture = captureProviderRequestBody(provider, input, init);
|
|
10701
10632
|
const started = performance.now();
|
|
@@ -10762,7 +10693,7 @@ var RunMcpCredentials = class {
|
|
|
10762
10693
|
#closed = false;
|
|
10763
10694
|
#onAbort = () => this.close();
|
|
10764
10695
|
constructor(targets, options = {}) {
|
|
10765
|
-
this.#targets = targets.
|
|
10696
|
+
this.#targets = targets.map(({ id, url }) => ({ id, url }));
|
|
10766
10697
|
this.#signal = options.signal;
|
|
10767
10698
|
this.#now = options.now ?? Date.now;
|
|
10768
10699
|
this.#signal?.addEventListener("abort", this.#onAbort, { once: true });
|
|
@@ -10839,11 +10770,11 @@ var RunMcpCredentials = class {
|
|
|
10839
10770
|
replace(material) {
|
|
10840
10771
|
this.prepare(material)();
|
|
10841
10772
|
}
|
|
10842
|
-
/** Refuse credentials for
|
|
10773
|
+
/** Refuse credentials for omitted, local, or rewritten server routes. */
|
|
10843
10774
|
assertRemoteTargets(targets) {
|
|
10844
10775
|
this.#remoteTargets = this.#targets.filter(
|
|
10845
10776
|
(original) => targets.some(
|
|
10846
|
-
(target) =>
|
|
10777
|
+
(target) => target.id === original.id && normalizedUrl(target.url) !== null && normalizedUrl(target.url) === normalizedUrl(original.url)
|
|
10847
10778
|
)
|
|
10848
10779
|
);
|
|
10849
10780
|
this.#dropExcluded();
|
|
@@ -10886,10 +10817,6 @@ var RunMcpCredentials = class {
|
|
|
10886
10817
|
/** Called at the literal fetch boundary, including POST, SSE GET and DELETE. */
|
|
10887
10818
|
requestInit(target, input, init) {
|
|
10888
10819
|
this.#assertOpen();
|
|
10889
|
-
if (target.connectionRef) {
|
|
10890
|
-
this.excludeLocalTarget(target.id);
|
|
10891
|
-
return init;
|
|
10892
|
-
}
|
|
10893
10820
|
this.assertAvailable(target.id);
|
|
10894
10821
|
const entry = this.#entries.get(target.id);
|
|
10895
10822
|
if (!entry) return init;
|
|
@@ -12089,7 +12016,6 @@ var LazyToolModel = class {
|
|
|
12089
12016
|
this.runtime = runtime;
|
|
12090
12017
|
}
|
|
12091
12018
|
async getResponse(request) {
|
|
12092
|
-
await beforeModelRequest();
|
|
12093
12019
|
const prepared = prepareLazyToolRequest(request, this.runtime);
|
|
12094
12020
|
rememberPreparedModelRequest(prepared);
|
|
12095
12021
|
void notifyModelRequestCapture(prepared);
|
|
@@ -12100,7 +12026,6 @@ var LazyToolModel = class {
|
|
|
12100
12026
|
return this.runtime.transport === "generic_dispatch" ? transformGenericDispatchResponse(response, this.runtime) : response;
|
|
12101
12027
|
}
|
|
12102
12028
|
async *getStreamedResponse(request) {
|
|
12103
|
-
await beforeModelRequest();
|
|
12104
12029
|
const prepared = prepareLazyToolRequest(request, this.runtime);
|
|
12105
12030
|
rememberPreparedModelRequest(prepared);
|
|
12106
12031
|
void notifyModelRequestCapture(prepared);
|
|
@@ -12110,18 +12035,19 @@ var LazyToolModel = class {
|
|
|
12110
12035
|
await this.runtime.ensurePrepared();
|
|
12111
12036
|
}
|
|
12112
12037
|
}
|
|
12113
|
-
|
|
12114
|
-
|
|
12115
|
-
|
|
12116
|
-
|
|
12117
|
-
|
|
12118
|
-
|
|
12119
|
-
|
|
12120
|
-
|
|
12121
|
-
|
|
12122
|
-
|
|
12123
|
-
|
|
12124
|
-
|
|
12038
|
+
if (this.runtime.transport === "generic_dispatch" && event.type === "response_done") {
|
|
12039
|
+
yield {
|
|
12040
|
+
...event,
|
|
12041
|
+
response: {
|
|
12042
|
+
...event.response,
|
|
12043
|
+
output: event.response.output.flatMap(
|
|
12044
|
+
(item) => transformGenericDispatchCall(item, this.runtime)
|
|
12045
|
+
)
|
|
12046
|
+
}
|
|
12047
|
+
};
|
|
12048
|
+
} else {
|
|
12049
|
+
yield event;
|
|
12050
|
+
}
|
|
12125
12051
|
}
|
|
12126
12052
|
}
|
|
12127
12053
|
getRetryAdvice(args) {
|
|
@@ -13771,7 +13697,7 @@ import { existsSync, readdirSync } from "fs";
|
|
|
13771
13697
|
// ../sdk/package.json
|
|
13772
13698
|
var package_default = {
|
|
13773
13699
|
name: "@opengeni/sdk",
|
|
13774
|
-
version: "7.4.0
|
|
13700
|
+
version: "7.4.0",
|
|
13775
13701
|
description: "Framework-agnostic TypeScript SDK for the OpenGeni API: typed client, session lifecycle, SSE event streaming with reconnect + replay-by-sequence, and proxy re-streaming helpers.",
|
|
13776
13702
|
license: "Apache-2.0",
|
|
13777
13703
|
repository: {
|
|
@@ -13793,10 +13719,6 @@ var package_default = {
|
|
|
13793
13719
|
module: "./src/index.ts",
|
|
13794
13720
|
types: "./src/index.ts",
|
|
13795
13721
|
exports: {
|
|
13796
|
-
"./allowance-refusal": {
|
|
13797
|
-
types: "./src/allowance-refusal.ts",
|
|
13798
|
-
default: "./src/allowance-refusal.ts"
|
|
13799
|
-
},
|
|
13800
13722
|
".": {
|
|
13801
13723
|
types: "./src/index.ts",
|
|
13802
13724
|
default: "./src/index.ts"
|
|
@@ -13897,10 +13819,6 @@ var package_default = {
|
|
|
13897
13819
|
types: "./src/chat/index.ts",
|
|
13898
13820
|
default: "./src/chat/index.ts"
|
|
13899
13821
|
},
|
|
13900
|
-
"./session-proxy": {
|
|
13901
|
-
types: "./src/session-proxy.ts",
|
|
13902
|
-
default: "./src/session-proxy.ts"
|
|
13903
|
-
},
|
|
13904
13822
|
"./next": {
|
|
13905
13823
|
types: "./src/adapters/next.ts",
|
|
13906
13824
|
default: "./src/adapters/next.ts"
|
|
@@ -13947,7 +13865,7 @@ var package_default = {
|
|
|
13947
13865
|
// ../react/package.json
|
|
13948
13866
|
var package_default2 = {
|
|
13949
13867
|
name: "@opengeni/react",
|
|
13950
|
-
version: "7.4.0
|
|
13868
|
+
version: "7.4.0",
|
|
13951
13869
|
description: "React hooks and styled components for OpenGeni: live session streaming, chat composer, message timeline, session status, and fleet views \u2014 token-themed (CSS variables), dark-first, built on Tailwind v4 + Radix + Motion.",
|
|
13952
13870
|
license: "Apache-2.0",
|
|
13953
13871
|
repository: {
|
|
@@ -14204,7 +14122,7 @@ var package_default2 = {
|
|
|
14204
14122
|
// ../codemode/package.json
|
|
14205
14123
|
var package_default3 = {
|
|
14206
14124
|
name: "@opengeni/codemode",
|
|
14207
|
-
version: "0.6.5
|
|
14125
|
+
version: "0.6.5",
|
|
14208
14126
|
description: "Attempt-frozen programmatic tool catalog and execution authority for OpenGeni.",
|
|
14209
14127
|
license: "Apache-2.0",
|
|
14210
14128
|
repository: {
|
|
@@ -14254,7 +14172,7 @@ var package_default3 = {
|
|
|
14254
14172
|
// ../ogtool/package.json
|
|
14255
14173
|
var package_default4 = {
|
|
14256
14174
|
name: "@opengeni/ogtool",
|
|
14257
|
-
version: "0.3.47
|
|
14175
|
+
version: "0.3.47",
|
|
14258
14176
|
description: "Codemode CLI and typed client entrypoint for an OpenGeni execution attempt.",
|
|
14259
14177
|
license: "Apache-2.0",
|
|
14260
14178
|
repository: {
|
|
@@ -20755,7 +20673,7 @@ async function prepareAgentTools(settings, tools, options = {}) {
|
|
|
20755
20673
|
options = { ...options, sessionAttachedRemoteMcpTargets: identityTargets };
|
|
20756
20674
|
options.runMcpCredentials?.assertRemoteTargets(
|
|
20757
20675
|
settings.mcpServers.filter(
|
|
20758
|
-
(config) => tools.some((tool2) => tool2.id === config.id) && !
|
|
20676
|
+
(config) => tools.some((tool2) => tool2.id === config.id) && !localRegistry.has(config.id) && !isFirstPartyMcpServer(settings, config) && !isCodexAppsMcpServer(config)
|
|
20759
20677
|
)
|
|
20760
20678
|
);
|
|
20761
20679
|
const aggregateToolBudget = new McpAggregateToolListBudget();
|
|
@@ -21226,7 +21144,7 @@ function selectedSessionRemoteMcpTargets(settings, attachments, tools, localServ
|
|
|
21226
21144
|
);
|
|
21227
21145
|
if (configs.length !== 1) return [];
|
|
21228
21146
|
const config = configs[0];
|
|
21229
|
-
if (
|
|
21147
|
+
if (isFirstPartyMcpServer(settings, config) || isCodexAppsMcpServer(config) || BUILT_IN_MCP_BRIDGE_ADAPTERS.some(
|
|
21230
21148
|
(adapter) => adapter.matches({
|
|
21231
21149
|
url: config.url,
|
|
21232
21150
|
...config.connectionRef ? { connectionRef: config.connectionRef } : {}
|
|
@@ -23414,15 +23332,9 @@ async function runAgentStream(agent, input, settings, overrides = {}) {
|
|
|
23414
23332
|
const scope = gate?.beginStream(overrides.signal);
|
|
23415
23333
|
try {
|
|
23416
23334
|
if (scope) agent.toolUseBehavior = scope.toolUseBehavior;
|
|
23417
|
-
const stream = await
|
|
23418
|
-
|
|
23419
|
-
|
|
23420
|
-
...overrides.onModelResponse ? { onModelResponse: overrides.onModelResponse } : {}
|
|
23421
|
-
},
|
|
23422
|
-
() => withPreparedCompactionRequest(
|
|
23423
|
-
agent,
|
|
23424
|
-
() => runAgentStreamInternal(agent, input, settings, overrides, scope)
|
|
23425
|
-
)
|
|
23335
|
+
const stream = await withPreparedCompactionRequest(
|
|
23336
|
+
agent,
|
|
23337
|
+
() => runAgentStreamInternal(agent, input, settings, overrides, scope)
|
|
23426
23338
|
);
|
|
23427
23339
|
if (scope) {
|
|
23428
23340
|
const finish = () => scope.endStream(stream.cancelled);
|
|
@@ -26365,7 +26277,6 @@ export {
|
|
|
26365
26277
|
normalizeVercelGatewayRequestBody,
|
|
26366
26278
|
modelRequestPolicyForProvider,
|
|
26367
26279
|
vercelGatewayRoutingFetch,
|
|
26368
|
-
beforeModelRequest,
|
|
26369
26280
|
markModelPreparationFirstSandboxOperation,
|
|
26370
26281
|
recordModelPreparationMeasurement,
|
|
26371
26282
|
PROVIDER_QUOTA_EXHAUSTED_CODE,
|
|
@@ -26572,4 +26483,4 @@ export {
|
|
|
26572
26483
|
runAzureCliLoginHook,
|
|
26573
26484
|
renderSessionGoalContext2 as renderSessionGoalContext
|
|
26574
26485
|
};
|
|
26575
|
-
//# sourceMappingURL=chunk-
|
|
26486
|
+
//# sourceMappingURL=chunk-22M75RJF.js.map
|