@ai-sdk/provider-utils 3.0.0-canary.0 → 3.0.0-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/index.js +15 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -2
- package/test/dist/index.d.mts +2 -40
- package/test/dist/index.d.ts +2 -40
- package/test/dist/index.js +6 -189
- package/test/dist/index.js.map +1 -1
- package/test/dist/index.mjs +5 -186
- package/test/dist/index.mjs.map +1 -1
package/test/dist/index.mjs
CHANGED
@@ -18445,194 +18445,15 @@ var setupServer = (...handlers) => {
|
|
18445
18445
|
|
18446
18446
|
// src/test/test-server.ts
|
18447
18447
|
var TestServerCall = class {
|
18448
|
-
constructor(request) {
|
18449
|
-
this.request = request;
|
18450
|
-
}
|
18451
|
-
async getRequestBodyJson() {
|
18452
|
-
expect(this.request).toBeDefined();
|
18453
|
-
return JSON.parse(await this.request.text());
|
18454
|
-
}
|
18455
|
-
getRequestCredentials() {
|
18456
|
-
expect(this.request).toBeDefined();
|
18457
|
-
return this.request.credentials;
|
18458
|
-
}
|
18459
|
-
getRequestHeaders() {
|
18460
|
-
expect(this.request).toBeDefined();
|
18461
|
-
const requestHeaders = this.request.headers;
|
18462
|
-
const headersObject = {};
|
18463
|
-
requestHeaders.forEach((value, key) => {
|
18464
|
-
headersObject[key] = value;
|
18465
|
-
});
|
18466
|
-
return headersObject;
|
18467
|
-
}
|
18468
|
-
getRequestUrlSearchParams() {
|
18469
|
-
expect(this.request).toBeDefined();
|
18470
|
-
return new URL(this.request.url).searchParams;
|
18471
|
-
}
|
18472
|
-
};
|
18473
|
-
function createServer({
|
18474
|
-
responses,
|
18475
|
-
pushCall,
|
18476
|
-
pushController
|
18477
|
-
}) {
|
18478
|
-
const responsesArray = Array.isArray(responses) ? responses : [responses];
|
18479
|
-
const responsesByUrl = responsesArray.reduce(
|
18480
|
-
(responsesByUrl2, response) => {
|
18481
|
-
if (!responsesByUrl2[response.url]) {
|
18482
|
-
responsesByUrl2[response.url] = [];
|
18483
|
-
}
|
18484
|
-
responsesByUrl2[response.url].push(response);
|
18485
|
-
return responsesByUrl2;
|
18486
|
-
},
|
18487
|
-
{}
|
18488
|
-
);
|
18489
|
-
const streams = {};
|
18490
|
-
responsesArray.filter(
|
18491
|
-
(response) => response.type === "controlled-stream"
|
18492
|
-
).forEach((response) => {
|
18493
|
-
var _a4, _b2;
|
18494
|
-
let streamController;
|
18495
|
-
const stream = new ReadableStream({
|
18496
|
-
start(controller) {
|
18497
|
-
streamController = controller;
|
18498
|
-
}
|
18499
|
-
});
|
18500
|
-
pushController((_a4 = response.id) != null ? _a4 : "", () => streamController);
|
18501
|
-
streams[(_b2 = response.id) != null ? _b2 : ""] = stream;
|
18502
|
-
});
|
18503
|
-
const urlInvocationCounts = Object.fromEntries(
|
18504
|
-
Object.entries(responsesByUrl).map(([url]) => [url, 0])
|
18505
|
-
);
|
18506
|
-
return setupServer(
|
18507
|
-
...Object.entries(responsesByUrl).map(([url, responses2]) => {
|
18508
|
-
return http.post(url, ({ request }) => {
|
18509
|
-
var _a4, _b2;
|
18510
|
-
pushCall(new TestServerCall(request));
|
18511
|
-
const invocationCount = urlInvocationCounts[url]++;
|
18512
|
-
const response = responses2[
|
18513
|
-
// TODO bug needs to be >=
|
18514
|
-
invocationCount > responses2.length ? responses2.length - 1 : invocationCount
|
18515
|
-
];
|
18516
|
-
switch (response.type) {
|
18517
|
-
case "json-value":
|
18518
|
-
return HttpResponse.json(response.content, {
|
18519
|
-
status: 200,
|
18520
|
-
headers: {
|
18521
|
-
"Content-Type": "application/json",
|
18522
|
-
...response.headers
|
18523
|
-
}
|
18524
|
-
});
|
18525
|
-
case "stream-values":
|
18526
|
-
return new HttpResponse(
|
18527
|
-
convertArrayToReadableStream(response.content).pipeThrough(
|
18528
|
-
new TextEncoderStream()
|
18529
|
-
),
|
18530
|
-
{
|
18531
|
-
status: 200,
|
18532
|
-
headers: {
|
18533
|
-
"Content-Type": "text/event-stream",
|
18534
|
-
"Cache-Control": "no-cache",
|
18535
|
-
Connection: "keep-alive",
|
18536
|
-
...response.headers
|
18537
|
-
}
|
18538
|
-
}
|
18539
|
-
);
|
18540
|
-
case "controlled-stream": {
|
18541
|
-
return new HttpResponse(
|
18542
|
-
streams[(_a4 = response.id) != null ? _a4 : ""].pipeThrough(new TextEncoderStream()),
|
18543
|
-
{
|
18544
|
-
status: 200,
|
18545
|
-
headers: {
|
18546
|
-
"Content-Type": "text/event-stream",
|
18547
|
-
"Cache-Control": "no-cache",
|
18548
|
-
Connection: "keep-alive",
|
18549
|
-
...response.headers
|
18550
|
-
}
|
18551
|
-
}
|
18552
|
-
);
|
18553
|
-
}
|
18554
|
-
case "error":
|
18555
|
-
return HttpResponse.text((_b2 = response.content) != null ? _b2 : "Error", {
|
18556
|
-
status: response.status,
|
18557
|
-
headers: {
|
18558
|
-
...response.headers
|
18559
|
-
}
|
18560
|
-
});
|
18561
|
-
}
|
18562
|
-
});
|
18563
|
-
})
|
18564
|
-
);
|
18565
|
-
}
|
18566
|
-
function withTestServer(responses, testFunction) {
|
18567
|
-
return async () => {
|
18568
|
-
const calls = [];
|
18569
|
-
const controllers = {};
|
18570
|
-
const server = createServer({
|
18571
|
-
responses,
|
18572
|
-
pushCall: (call) => calls.push(call),
|
18573
|
-
pushController: (id, controller) => {
|
18574
|
-
controllers[id] = controller;
|
18575
|
-
}
|
18576
|
-
});
|
18577
|
-
try {
|
18578
|
-
server.listen();
|
18579
|
-
await testFunction({
|
18580
|
-
calls: () => calls,
|
18581
|
-
call: (index) => calls[index],
|
18582
|
-
getStreamController: (id) => {
|
18583
|
-
return controllers[id]();
|
18584
|
-
},
|
18585
|
-
get streamController() {
|
18586
|
-
return controllers[""]();
|
18587
|
-
}
|
18588
|
-
});
|
18589
|
-
} finally {
|
18590
|
-
server.close();
|
18591
|
-
}
|
18592
|
-
};
|
18593
|
-
}
|
18594
|
-
function describeWithTestServer(description, responses, testFunction) {
|
18595
|
-
describe(description, () => {
|
18596
|
-
let calls;
|
18597
|
-
let controllers;
|
18598
|
-
let server;
|
18599
|
-
beforeAll(() => {
|
18600
|
-
server = createServer({
|
18601
|
-
responses,
|
18602
|
-
pushCall: (call) => calls.push(call),
|
18603
|
-
pushController: (id, controller) => {
|
18604
|
-
controllers[id] = controller;
|
18605
|
-
}
|
18606
|
-
});
|
18607
|
-
server.listen();
|
18608
|
-
});
|
18609
|
-
beforeEach(() => {
|
18610
|
-
calls = [];
|
18611
|
-
controllers = {};
|
18612
|
-
server.resetHandlers();
|
18613
|
-
});
|
18614
|
-
afterAll(() => {
|
18615
|
-
server.close();
|
18616
|
-
});
|
18617
|
-
testFunction({
|
18618
|
-
calls: () => calls,
|
18619
|
-
call: (index) => calls[index],
|
18620
|
-
getStreamController: (id) => controllers[id](),
|
18621
|
-
get streamController() {
|
18622
|
-
return controllers[""]();
|
18623
|
-
}
|
18624
|
-
});
|
18625
|
-
});
|
18626
|
-
}
|
18627
|
-
|
18628
|
-
// src/test/unified-test-server.ts
|
18629
|
-
var TestServerCall2 = class {
|
18630
18448
|
constructor(request) {
|
18631
18449
|
this.request = request;
|
18632
18450
|
}
|
18633
18451
|
get requestBody() {
|
18634
18452
|
return this.request.text().then(JSON.parse);
|
18635
18453
|
}
|
18454
|
+
get requestCredentials() {
|
18455
|
+
return this.request.credentials;
|
18456
|
+
}
|
18636
18457
|
get requestHeaders() {
|
18637
18458
|
const requestHeaders = this.request.headers;
|
18638
18459
|
const headersObject = {};
|
@@ -18658,7 +18479,7 @@ function createTestServer(routes) {
|
|
18658
18479
|
return http.all(url, ({ request }) => {
|
18659
18480
|
var _a4, _b2, _c2;
|
18660
18481
|
const callNumber = calls.length;
|
18661
|
-
calls.push(new
|
18482
|
+
calls.push(new TestServerCall(request));
|
18662
18483
|
const response = typeof handler.response === "function" ? handler.response({ callNumber }) : Array.isArray(handler.response) ? handler.response[callNumber] : handler.response;
|
18663
18484
|
if (response === void 0) {
|
18664
18485
|
return HttpResponse.json({ error: "Not Found" }, { status: 404 });
|
@@ -18772,9 +18593,7 @@ export {
|
|
18772
18593
|
convertReadableStreamToArray,
|
18773
18594
|
convertResponseStreamToArray,
|
18774
18595
|
createTestServer,
|
18775
|
-
|
18776
|
-
mockId,
|
18777
|
-
withTestServer
|
18596
|
+
mockId
|
18778
18597
|
};
|
18779
18598
|
/*! Bundled license information:
|
18780
18599
|
|