@polka-codes/core 0.4.1 → 0.4.3
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/index.js +1238 -480
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var __export = (target, all) => {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
// ../../node_modules/@anthropic-ai/sdk/version.mjs
|
|
13
|
-
var VERSION = "0.
|
|
13
|
+
var VERSION = "0.36.2";
|
|
14
14
|
|
|
15
15
|
// ../../node_modules/@anthropic-ai/sdk/_shims/registry.mjs
|
|
16
16
|
var auto = false;
|
|
@@ -295,6 +295,35 @@ LineDecoder.NEWLINE_CHARS = new Set([`
|
|
|
295
295
|
`, "\r"]);
|
|
296
296
|
LineDecoder.NEWLINE_REGEXP = /\r\n|[\n\r]/g;
|
|
297
297
|
|
|
298
|
+
// ../../node_modules/@anthropic-ai/sdk/internal/stream-utils.mjs
|
|
299
|
+
function ReadableStreamToAsyncIterable(stream) {
|
|
300
|
+
if (stream[Symbol.asyncIterator])
|
|
301
|
+
return stream;
|
|
302
|
+
const reader = stream.getReader();
|
|
303
|
+
return {
|
|
304
|
+
async next() {
|
|
305
|
+
try {
|
|
306
|
+
const result = await reader.read();
|
|
307
|
+
if (result?.done)
|
|
308
|
+
reader.releaseLock();
|
|
309
|
+
return result;
|
|
310
|
+
} catch (e) {
|
|
311
|
+
reader.releaseLock();
|
|
312
|
+
throw e;
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
async return() {
|
|
316
|
+
const cancelPromise = reader.cancel();
|
|
317
|
+
reader.releaseLock();
|
|
318
|
+
await cancelPromise;
|
|
319
|
+
return { done: true, value: undefined };
|
|
320
|
+
},
|
|
321
|
+
[Symbol.asyncIterator]() {
|
|
322
|
+
return this;
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
|
|
298
327
|
// ../../node_modules/@anthropic-ai/sdk/streaming.mjs
|
|
299
328
|
class Stream {
|
|
300
329
|
constructor(iterator, controller) {
|
|
@@ -352,7 +381,7 @@ class Stream {
|
|
|
352
381
|
let consumed = false;
|
|
353
382
|
async function* iterLines() {
|
|
354
383
|
const lineDecoder = new LineDecoder;
|
|
355
|
-
const iter =
|
|
384
|
+
const iter = ReadableStreamToAsyncIterable(readableStream);
|
|
356
385
|
for await (const chunk of iter) {
|
|
357
386
|
for (const line of lineDecoder.decode(chunk)) {
|
|
358
387
|
yield line;
|
|
@@ -444,7 +473,7 @@ async function* _iterSSEMessages(response, controller) {
|
|
|
444
473
|
}
|
|
445
474
|
const sseDecoder = new SSEDecoder;
|
|
446
475
|
const lineDecoder = new LineDecoder;
|
|
447
|
-
const iter =
|
|
476
|
+
const iter = ReadableStreamToAsyncIterable(response.body);
|
|
448
477
|
for await (const sseChunk of iterSSEChunks(iter)) {
|
|
449
478
|
for (const line of lineDecoder.decode(sseChunk)) {
|
|
450
479
|
const sse = sseDecoder.decode(line);
|
|
@@ -543,33 +572,6 @@ function partition(str, delimiter) {
|
|
|
543
572
|
}
|
|
544
573
|
return [str, "", ""];
|
|
545
574
|
}
|
|
546
|
-
function readableStreamAsyncIterable(stream) {
|
|
547
|
-
if (stream[Symbol.asyncIterator])
|
|
548
|
-
return stream;
|
|
549
|
-
const reader = stream.getReader();
|
|
550
|
-
return {
|
|
551
|
-
async next() {
|
|
552
|
-
try {
|
|
553
|
-
const result = await reader.read();
|
|
554
|
-
if (result?.done)
|
|
555
|
-
reader.releaseLock();
|
|
556
|
-
return result;
|
|
557
|
-
} catch (e) {
|
|
558
|
-
reader.releaseLock();
|
|
559
|
-
throw e;
|
|
560
|
-
}
|
|
561
|
-
},
|
|
562
|
-
async return() {
|
|
563
|
-
const cancelPromise = reader.cancel();
|
|
564
|
-
reader.releaseLock();
|
|
565
|
-
await cancelPromise;
|
|
566
|
-
return { done: true, value: undefined };
|
|
567
|
-
},
|
|
568
|
-
[Symbol.asyncIterator]() {
|
|
569
|
-
return this;
|
|
570
|
-
}
|
|
571
|
-
};
|
|
572
|
-
}
|
|
573
575
|
|
|
574
576
|
// ../../node_modules/@anthropic-ai/sdk/uploads.mjs
|
|
575
577
|
var isResponseLike = (value) => value != null && typeof value === "object" && typeof value.url === "string" && typeof value.blob === "function";
|
|
@@ -920,7 +922,14 @@ class APIClient {
|
|
|
920
922
|
if (signal)
|
|
921
923
|
signal.addEventListener("abort", () => controller.abort());
|
|
922
924
|
const timeout = setTimeout(() => controller.abort(), ms);
|
|
923
|
-
|
|
925
|
+
const fetchOptions = {
|
|
926
|
+
signal: controller.signal,
|
|
927
|
+
...options
|
|
928
|
+
};
|
|
929
|
+
if (fetchOptions.method) {
|
|
930
|
+
fetchOptions.method = fetchOptions.method.toUpperCase();
|
|
931
|
+
}
|
|
932
|
+
return this.fetch.call(undefined, url, fetchOptions).finally(() => {
|
|
924
933
|
clearTimeout(timeout);
|
|
925
934
|
});
|
|
926
935
|
}
|
|
@@ -1380,7 +1389,7 @@ class JSONLDecoder {
|
|
|
1380
1389
|
controller.abort();
|
|
1381
1390
|
throw new AnthropicError(`Attempted to iterate over a response with no body`);
|
|
1382
1391
|
}
|
|
1383
|
-
return new JSONLDecoder(
|
|
1392
|
+
return new JSONLDecoder(ReadableStreamToAsyncIterable(response.body), controller);
|
|
1384
1393
|
}
|
|
1385
1394
|
}
|
|
1386
1395
|
|
|
@@ -1424,6 +1433,19 @@ class Batches extends APIResource {
|
|
|
1424
1433
|
}
|
|
1425
1434
|
});
|
|
1426
1435
|
}
|
|
1436
|
+
delete(messageBatchId, params = {}, options) {
|
|
1437
|
+
if (isRequestOptions(params)) {
|
|
1438
|
+
return this.delete(messageBatchId, {}, params);
|
|
1439
|
+
}
|
|
1440
|
+
const { betas } = params;
|
|
1441
|
+
return this._client.delete(`/v1/messages/batches/${messageBatchId}?beta=true`, {
|
|
1442
|
+
...options,
|
|
1443
|
+
headers: {
|
|
1444
|
+
"anthropic-beta": [...betas ?? [], "message-batches-2024-09-24"].toString(),
|
|
1445
|
+
...options?.headers
|
|
1446
|
+
}
|
|
1447
|
+
});
|
|
1448
|
+
}
|
|
1427
1449
|
cancel(messageBatchId, params = {}, options) {
|
|
1428
1450
|
if (isRequestOptions(params)) {
|
|
1429
1451
|
return this.cancel(messageBatchId, {}, params);
|
|
@@ -1450,6 +1472,7 @@ class Batches extends APIResource {
|
|
|
1450
1472
|
...options,
|
|
1451
1473
|
headers: {
|
|
1452
1474
|
"anthropic-beta": [...betas ?? [], "message-batches-2024-09-24"].toString(),
|
|
1475
|
+
Accept: "application/binary",
|
|
1453
1476
|
...options?.headers
|
|
1454
1477
|
},
|
|
1455
1478
|
__binaryResponse: true
|
|
@@ -1461,92 +1484,6 @@ class BetaMessageBatchesPage extends Page {
|
|
|
1461
1484
|
}
|
|
1462
1485
|
Batches.BetaMessageBatchesPage = BetaMessageBatchesPage;
|
|
1463
1486
|
|
|
1464
|
-
// ../../node_modules/@anthropic-ai/sdk/resources/beta/messages/messages.mjs
|
|
1465
|
-
class Messages extends APIResource {
|
|
1466
|
-
constructor() {
|
|
1467
|
-
super(...arguments);
|
|
1468
|
-
this.batches = new Batches(this._client);
|
|
1469
|
-
}
|
|
1470
|
-
create(params, options) {
|
|
1471
|
-
const { betas, ...body } = params;
|
|
1472
|
-
return this._client.post("/v1/messages?beta=true", {
|
|
1473
|
-
body,
|
|
1474
|
-
timeout: this._client._options.timeout ?? 600000,
|
|
1475
|
-
...options,
|
|
1476
|
-
headers: {
|
|
1477
|
-
...betas?.toString() != null ? { "anthropic-beta": betas?.toString() } : undefined,
|
|
1478
|
-
...options?.headers
|
|
1479
|
-
},
|
|
1480
|
-
stream: params.stream ?? false
|
|
1481
|
-
});
|
|
1482
|
-
}
|
|
1483
|
-
countTokens(params, options) {
|
|
1484
|
-
const { betas, ...body } = params;
|
|
1485
|
-
return this._client.post("/v1/messages/count_tokens?beta=true", {
|
|
1486
|
-
body,
|
|
1487
|
-
...options,
|
|
1488
|
-
headers: {
|
|
1489
|
-
"anthropic-beta": [...betas ?? [], "token-counting-2024-11-01"].toString(),
|
|
1490
|
-
...options?.headers
|
|
1491
|
-
}
|
|
1492
|
-
});
|
|
1493
|
-
}
|
|
1494
|
-
}
|
|
1495
|
-
Messages.Batches = Batches;
|
|
1496
|
-
Messages.BetaMessageBatchesPage = BetaMessageBatchesPage;
|
|
1497
|
-
|
|
1498
|
-
// ../../node_modules/@anthropic-ai/sdk/resources/beta/beta.mjs
|
|
1499
|
-
class Beta extends APIResource {
|
|
1500
|
-
constructor() {
|
|
1501
|
-
super(...arguments);
|
|
1502
|
-
this.models = new Models(this._client);
|
|
1503
|
-
this.messages = new Messages(this._client);
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
Beta.Models = Models;
|
|
1507
|
-
Beta.BetaModelInfosPage = BetaModelInfosPage;
|
|
1508
|
-
Beta.Messages = Messages;
|
|
1509
|
-
// ../../node_modules/@anthropic-ai/sdk/resources/completions.mjs
|
|
1510
|
-
class Completions extends APIResource {
|
|
1511
|
-
create(body, options) {
|
|
1512
|
-
return this._client.post("/v1/complete", {
|
|
1513
|
-
body,
|
|
1514
|
-
timeout: this._client._options.timeout ?? 600000,
|
|
1515
|
-
...options,
|
|
1516
|
-
stream: body.stream ?? false
|
|
1517
|
-
});
|
|
1518
|
-
}
|
|
1519
|
-
}
|
|
1520
|
-
// ../../node_modules/@anthropic-ai/sdk/resources/messages/batches.mjs
|
|
1521
|
-
class Batches2 extends APIResource {
|
|
1522
|
-
create(body, options) {
|
|
1523
|
-
return this._client.post("/v1/messages/batches", { body, ...options });
|
|
1524
|
-
}
|
|
1525
|
-
retrieve(messageBatchId, options) {
|
|
1526
|
-
return this._client.get(`/v1/messages/batches/${messageBatchId}`, options);
|
|
1527
|
-
}
|
|
1528
|
-
list(query = {}, options) {
|
|
1529
|
-
if (isRequestOptions(query)) {
|
|
1530
|
-
return this.list({}, query);
|
|
1531
|
-
}
|
|
1532
|
-
return this._client.getAPIList("/v1/messages/batches", MessageBatchesPage, { query, ...options });
|
|
1533
|
-
}
|
|
1534
|
-
cancel(messageBatchId, options) {
|
|
1535
|
-
return this._client.post(`/v1/messages/batches/${messageBatchId}/cancel`, options);
|
|
1536
|
-
}
|
|
1537
|
-
async results(messageBatchId, options) {
|
|
1538
|
-
const batch = await this.retrieve(messageBatchId);
|
|
1539
|
-
if (!batch.results_url) {
|
|
1540
|
-
throw new AnthropicError(`No batch \`results_url\`; Has it finished processing? ${batch.processing_status} - ${batch.id}`);
|
|
1541
|
-
}
|
|
1542
|
-
return this._client.get(batch.results_url, { ...options, __binaryResponse: true })._thenUnwrap((_, props) => JSONLDecoder.fromResponse(props.response, props.controller));
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
|
|
1546
|
-
class MessageBatchesPage extends Page {
|
|
1547
|
-
}
|
|
1548
|
-
Batches2.MessageBatchesPage = MessageBatchesPage;
|
|
1549
|
-
|
|
1550
1487
|
// ../../node_modules/@anthropic-ai/sdk/_vendor/partial-json-parser/parser.mjs
|
|
1551
1488
|
var tokenize = (input) => {
|
|
1552
1489
|
let current = 0;
|
|
@@ -1681,94 +1618,647 @@ var tokenize = (input) => {
|
|
|
1681
1618
|
}
|
|
1682
1619
|
current++;
|
|
1683
1620
|
}
|
|
1684
|
-
return tokens;
|
|
1685
|
-
};
|
|
1686
|
-
var strip = (tokens) => {
|
|
1687
|
-
if (tokens.length === 0) {
|
|
1688
|
-
return tokens;
|
|
1621
|
+
return tokens;
|
|
1622
|
+
};
|
|
1623
|
+
var strip = (tokens) => {
|
|
1624
|
+
if (tokens.length === 0) {
|
|
1625
|
+
return tokens;
|
|
1626
|
+
}
|
|
1627
|
+
let lastToken = tokens[tokens.length - 1];
|
|
1628
|
+
switch (lastToken.type) {
|
|
1629
|
+
case "separator":
|
|
1630
|
+
tokens = tokens.slice(0, tokens.length - 1);
|
|
1631
|
+
return strip(tokens);
|
|
1632
|
+
break;
|
|
1633
|
+
case "number":
|
|
1634
|
+
let lastCharacterOfLastToken = lastToken.value[lastToken.value.length - 1];
|
|
1635
|
+
if (lastCharacterOfLastToken === "." || lastCharacterOfLastToken === "-") {
|
|
1636
|
+
tokens = tokens.slice(0, tokens.length - 1);
|
|
1637
|
+
return strip(tokens);
|
|
1638
|
+
}
|
|
1639
|
+
case "string":
|
|
1640
|
+
let tokenBeforeTheLastToken = tokens[tokens.length - 2];
|
|
1641
|
+
if (tokenBeforeTheLastToken?.type === "delimiter") {
|
|
1642
|
+
tokens = tokens.slice(0, tokens.length - 1);
|
|
1643
|
+
return strip(tokens);
|
|
1644
|
+
} else if (tokenBeforeTheLastToken?.type === "brace" && tokenBeforeTheLastToken.value === "{") {
|
|
1645
|
+
tokens = tokens.slice(0, tokens.length - 1);
|
|
1646
|
+
return strip(tokens);
|
|
1647
|
+
}
|
|
1648
|
+
break;
|
|
1649
|
+
case "delimiter":
|
|
1650
|
+
tokens = tokens.slice(0, tokens.length - 1);
|
|
1651
|
+
return strip(tokens);
|
|
1652
|
+
break;
|
|
1653
|
+
}
|
|
1654
|
+
return tokens;
|
|
1655
|
+
};
|
|
1656
|
+
var unstrip = (tokens) => {
|
|
1657
|
+
let tail = [];
|
|
1658
|
+
tokens.map((token) => {
|
|
1659
|
+
if (token.type === "brace") {
|
|
1660
|
+
if (token.value === "{") {
|
|
1661
|
+
tail.push("}");
|
|
1662
|
+
} else {
|
|
1663
|
+
tail.splice(tail.lastIndexOf("}"), 1);
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
if (token.type === "paren") {
|
|
1667
|
+
if (token.value === "[") {
|
|
1668
|
+
tail.push("]");
|
|
1669
|
+
} else {
|
|
1670
|
+
tail.splice(tail.lastIndexOf("]"), 1);
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
});
|
|
1674
|
+
if (tail.length > 0) {
|
|
1675
|
+
tail.reverse().map((item) => {
|
|
1676
|
+
if (item === "}") {
|
|
1677
|
+
tokens.push({
|
|
1678
|
+
type: "brace",
|
|
1679
|
+
value: "}"
|
|
1680
|
+
});
|
|
1681
|
+
} else if (item === "]") {
|
|
1682
|
+
tokens.push({
|
|
1683
|
+
type: "paren",
|
|
1684
|
+
value: "]"
|
|
1685
|
+
});
|
|
1686
|
+
}
|
|
1687
|
+
});
|
|
1688
|
+
}
|
|
1689
|
+
return tokens;
|
|
1690
|
+
};
|
|
1691
|
+
var generate = (tokens) => {
|
|
1692
|
+
let output = "";
|
|
1693
|
+
tokens.map((token) => {
|
|
1694
|
+
switch (token.type) {
|
|
1695
|
+
case "string":
|
|
1696
|
+
output += '"' + token.value + '"';
|
|
1697
|
+
break;
|
|
1698
|
+
default:
|
|
1699
|
+
output += token.value;
|
|
1700
|
+
break;
|
|
1701
|
+
}
|
|
1702
|
+
});
|
|
1703
|
+
return output;
|
|
1704
|
+
};
|
|
1705
|
+
var partialParse = (input) => JSON.parse(generate(unstrip(strip(tokenize(input)))));
|
|
1706
|
+
|
|
1707
|
+
// ../../node_modules/@anthropic-ai/sdk/lib/BetaMessageStream.mjs
|
|
1708
|
+
var __classPrivateFieldSet2 = function(receiver, state, value, kind2, f) {
|
|
1709
|
+
if (kind2 === "m")
|
|
1710
|
+
throw new TypeError("Private method is not writable");
|
|
1711
|
+
if (kind2 === "a" && !f)
|
|
1712
|
+
throw new TypeError("Private accessor was defined without a setter");
|
|
1713
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
1714
|
+
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
1715
|
+
return kind2 === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
1716
|
+
};
|
|
1717
|
+
var __classPrivateFieldGet2 = function(receiver, state, kind2, f) {
|
|
1718
|
+
if (kind2 === "a" && !f)
|
|
1719
|
+
throw new TypeError("Private accessor was defined without a getter");
|
|
1720
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
1721
|
+
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
1722
|
+
return kind2 === "m" ? f : kind2 === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
1723
|
+
};
|
|
1724
|
+
var _BetaMessageStream_instances;
|
|
1725
|
+
var _BetaMessageStream_currentMessageSnapshot;
|
|
1726
|
+
var _BetaMessageStream_connectedPromise;
|
|
1727
|
+
var _BetaMessageStream_resolveConnectedPromise;
|
|
1728
|
+
var _BetaMessageStream_rejectConnectedPromise;
|
|
1729
|
+
var _BetaMessageStream_endPromise;
|
|
1730
|
+
var _BetaMessageStream_resolveEndPromise;
|
|
1731
|
+
var _BetaMessageStream_rejectEndPromise;
|
|
1732
|
+
var _BetaMessageStream_listeners;
|
|
1733
|
+
var _BetaMessageStream_ended;
|
|
1734
|
+
var _BetaMessageStream_errored;
|
|
1735
|
+
var _BetaMessageStream_aborted;
|
|
1736
|
+
var _BetaMessageStream_catchingPromiseCreated;
|
|
1737
|
+
var _BetaMessageStream_response;
|
|
1738
|
+
var _BetaMessageStream_request_id;
|
|
1739
|
+
var _BetaMessageStream_getFinalMessage;
|
|
1740
|
+
var _BetaMessageStream_getFinalText;
|
|
1741
|
+
var _BetaMessageStream_handleError;
|
|
1742
|
+
var _BetaMessageStream_beginRequest;
|
|
1743
|
+
var _BetaMessageStream_addStreamEvent;
|
|
1744
|
+
var _BetaMessageStream_endRequest;
|
|
1745
|
+
var _BetaMessageStream_accumulateMessage;
|
|
1746
|
+
var JSON_BUF_PROPERTY = "__json_buf";
|
|
1747
|
+
|
|
1748
|
+
class BetaMessageStream {
|
|
1749
|
+
constructor() {
|
|
1750
|
+
_BetaMessageStream_instances.add(this);
|
|
1751
|
+
this.messages = [];
|
|
1752
|
+
this.receivedMessages = [];
|
|
1753
|
+
_BetaMessageStream_currentMessageSnapshot.set(this, undefined);
|
|
1754
|
+
this.controller = new AbortController;
|
|
1755
|
+
_BetaMessageStream_connectedPromise.set(this, undefined);
|
|
1756
|
+
_BetaMessageStream_resolveConnectedPromise.set(this, () => {
|
|
1757
|
+
});
|
|
1758
|
+
_BetaMessageStream_rejectConnectedPromise.set(this, () => {
|
|
1759
|
+
});
|
|
1760
|
+
_BetaMessageStream_endPromise.set(this, undefined);
|
|
1761
|
+
_BetaMessageStream_resolveEndPromise.set(this, () => {
|
|
1762
|
+
});
|
|
1763
|
+
_BetaMessageStream_rejectEndPromise.set(this, () => {
|
|
1764
|
+
});
|
|
1765
|
+
_BetaMessageStream_listeners.set(this, {});
|
|
1766
|
+
_BetaMessageStream_ended.set(this, false);
|
|
1767
|
+
_BetaMessageStream_errored.set(this, false);
|
|
1768
|
+
_BetaMessageStream_aborted.set(this, false);
|
|
1769
|
+
_BetaMessageStream_catchingPromiseCreated.set(this, false);
|
|
1770
|
+
_BetaMessageStream_response.set(this, undefined);
|
|
1771
|
+
_BetaMessageStream_request_id.set(this, undefined);
|
|
1772
|
+
_BetaMessageStream_handleError.set(this, (error) => {
|
|
1773
|
+
__classPrivateFieldSet2(this, _BetaMessageStream_errored, true, "f");
|
|
1774
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
1775
|
+
error = new APIUserAbortError;
|
|
1776
|
+
}
|
|
1777
|
+
if (error instanceof APIUserAbortError) {
|
|
1778
|
+
__classPrivateFieldSet2(this, _BetaMessageStream_aborted, true, "f");
|
|
1779
|
+
return this._emit("abort", error);
|
|
1780
|
+
}
|
|
1781
|
+
if (error instanceof AnthropicError) {
|
|
1782
|
+
return this._emit("error", error);
|
|
1783
|
+
}
|
|
1784
|
+
if (error instanceof Error) {
|
|
1785
|
+
const anthropicError = new AnthropicError(error.message);
|
|
1786
|
+
anthropicError.cause = error;
|
|
1787
|
+
return this._emit("error", anthropicError);
|
|
1788
|
+
}
|
|
1789
|
+
return this._emit("error", new AnthropicError(String(error)));
|
|
1790
|
+
});
|
|
1791
|
+
__classPrivateFieldSet2(this, _BetaMessageStream_connectedPromise, new Promise((resolve, reject) => {
|
|
1792
|
+
__classPrivateFieldSet2(this, _BetaMessageStream_resolveConnectedPromise, resolve, "f");
|
|
1793
|
+
__classPrivateFieldSet2(this, _BetaMessageStream_rejectConnectedPromise, reject, "f");
|
|
1794
|
+
}), "f");
|
|
1795
|
+
__classPrivateFieldSet2(this, _BetaMessageStream_endPromise, new Promise((resolve, reject) => {
|
|
1796
|
+
__classPrivateFieldSet2(this, _BetaMessageStream_resolveEndPromise, resolve, "f");
|
|
1797
|
+
__classPrivateFieldSet2(this, _BetaMessageStream_rejectEndPromise, reject, "f");
|
|
1798
|
+
}), "f");
|
|
1799
|
+
__classPrivateFieldGet2(this, _BetaMessageStream_connectedPromise, "f").catch(() => {
|
|
1800
|
+
});
|
|
1801
|
+
__classPrivateFieldGet2(this, _BetaMessageStream_endPromise, "f").catch(() => {
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
get response() {
|
|
1805
|
+
return __classPrivateFieldGet2(this, _BetaMessageStream_response, "f");
|
|
1806
|
+
}
|
|
1807
|
+
get request_id() {
|
|
1808
|
+
return __classPrivateFieldGet2(this, _BetaMessageStream_request_id, "f");
|
|
1809
|
+
}
|
|
1810
|
+
async withResponse() {
|
|
1811
|
+
const response = await __classPrivateFieldGet2(this, _BetaMessageStream_connectedPromise, "f");
|
|
1812
|
+
if (!response) {
|
|
1813
|
+
throw new Error("Could not resolve a `Response` object");
|
|
1814
|
+
}
|
|
1815
|
+
return {
|
|
1816
|
+
data: this,
|
|
1817
|
+
response,
|
|
1818
|
+
request_id: response.headers.get("request-id")
|
|
1819
|
+
};
|
|
1820
|
+
}
|
|
1821
|
+
static fromReadableStream(stream) {
|
|
1822
|
+
const runner = new BetaMessageStream;
|
|
1823
|
+
runner._run(() => runner._fromReadableStream(stream));
|
|
1824
|
+
return runner;
|
|
1825
|
+
}
|
|
1826
|
+
static createMessage(messages, params, options) {
|
|
1827
|
+
const runner = new BetaMessageStream;
|
|
1828
|
+
for (const message of params.messages) {
|
|
1829
|
+
runner._addMessageParam(message);
|
|
1830
|
+
}
|
|
1831
|
+
runner._run(() => runner._createMessage(messages, { ...params, stream: true }, { ...options, headers: { ...options?.headers, "X-Stainless-Helper-Method": "stream" } }));
|
|
1832
|
+
return runner;
|
|
1833
|
+
}
|
|
1834
|
+
_run(executor) {
|
|
1835
|
+
executor().then(() => {
|
|
1836
|
+
this._emitFinal();
|
|
1837
|
+
this._emit("end");
|
|
1838
|
+
}, __classPrivateFieldGet2(this, _BetaMessageStream_handleError, "f"));
|
|
1839
|
+
}
|
|
1840
|
+
_addMessageParam(message) {
|
|
1841
|
+
this.messages.push(message);
|
|
1842
|
+
}
|
|
1843
|
+
_addMessage(message, emit = true) {
|
|
1844
|
+
this.receivedMessages.push(message);
|
|
1845
|
+
if (emit) {
|
|
1846
|
+
this._emit("message", message);
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
async _createMessage(messages, params, options) {
|
|
1850
|
+
const signal = options?.signal;
|
|
1851
|
+
if (signal) {
|
|
1852
|
+
if (signal.aborted)
|
|
1853
|
+
this.controller.abort();
|
|
1854
|
+
signal.addEventListener("abort", () => this.controller.abort());
|
|
1855
|
+
}
|
|
1856
|
+
__classPrivateFieldGet2(this, _BetaMessageStream_instances, "m", _BetaMessageStream_beginRequest).call(this);
|
|
1857
|
+
const { response, data: stream } = await messages.create({ ...params, stream: true }, { ...options, signal: this.controller.signal }).withResponse();
|
|
1858
|
+
this._connected(response);
|
|
1859
|
+
for await (const event of stream) {
|
|
1860
|
+
__classPrivateFieldGet2(this, _BetaMessageStream_instances, "m", _BetaMessageStream_addStreamEvent).call(this, event);
|
|
1861
|
+
}
|
|
1862
|
+
if (stream.controller.signal?.aborted) {
|
|
1863
|
+
throw new APIUserAbortError;
|
|
1864
|
+
}
|
|
1865
|
+
__classPrivateFieldGet2(this, _BetaMessageStream_instances, "m", _BetaMessageStream_endRequest).call(this);
|
|
1866
|
+
}
|
|
1867
|
+
_connected(response) {
|
|
1868
|
+
if (this.ended)
|
|
1869
|
+
return;
|
|
1870
|
+
__classPrivateFieldSet2(this, _BetaMessageStream_response, response, "f");
|
|
1871
|
+
__classPrivateFieldSet2(this, _BetaMessageStream_request_id, response?.headers.get("request-id"), "f");
|
|
1872
|
+
__classPrivateFieldGet2(this, _BetaMessageStream_resolveConnectedPromise, "f").call(this, response);
|
|
1873
|
+
this._emit("connect");
|
|
1874
|
+
}
|
|
1875
|
+
get ended() {
|
|
1876
|
+
return __classPrivateFieldGet2(this, _BetaMessageStream_ended, "f");
|
|
1877
|
+
}
|
|
1878
|
+
get errored() {
|
|
1879
|
+
return __classPrivateFieldGet2(this, _BetaMessageStream_errored, "f");
|
|
1880
|
+
}
|
|
1881
|
+
get aborted() {
|
|
1882
|
+
return __classPrivateFieldGet2(this, _BetaMessageStream_aborted, "f");
|
|
1883
|
+
}
|
|
1884
|
+
abort() {
|
|
1885
|
+
this.controller.abort();
|
|
1886
|
+
}
|
|
1887
|
+
on(event, listener) {
|
|
1888
|
+
const listeners = __classPrivateFieldGet2(this, _BetaMessageStream_listeners, "f")[event] || (__classPrivateFieldGet2(this, _BetaMessageStream_listeners, "f")[event] = []);
|
|
1889
|
+
listeners.push({ listener });
|
|
1890
|
+
return this;
|
|
1891
|
+
}
|
|
1892
|
+
off(event, listener) {
|
|
1893
|
+
const listeners = __classPrivateFieldGet2(this, _BetaMessageStream_listeners, "f")[event];
|
|
1894
|
+
if (!listeners)
|
|
1895
|
+
return this;
|
|
1896
|
+
const index = listeners.findIndex((l) => l.listener === listener);
|
|
1897
|
+
if (index >= 0)
|
|
1898
|
+
listeners.splice(index, 1);
|
|
1899
|
+
return this;
|
|
1900
|
+
}
|
|
1901
|
+
once(event, listener) {
|
|
1902
|
+
const listeners = __classPrivateFieldGet2(this, _BetaMessageStream_listeners, "f")[event] || (__classPrivateFieldGet2(this, _BetaMessageStream_listeners, "f")[event] = []);
|
|
1903
|
+
listeners.push({ listener, once: true });
|
|
1904
|
+
return this;
|
|
1905
|
+
}
|
|
1906
|
+
emitted(event) {
|
|
1907
|
+
return new Promise((resolve, reject) => {
|
|
1908
|
+
__classPrivateFieldSet2(this, _BetaMessageStream_catchingPromiseCreated, true, "f");
|
|
1909
|
+
if (event !== "error")
|
|
1910
|
+
this.once("error", reject);
|
|
1911
|
+
this.once(event, resolve);
|
|
1912
|
+
});
|
|
1913
|
+
}
|
|
1914
|
+
async done() {
|
|
1915
|
+
__classPrivateFieldSet2(this, _BetaMessageStream_catchingPromiseCreated, true, "f");
|
|
1916
|
+
await __classPrivateFieldGet2(this, _BetaMessageStream_endPromise, "f");
|
|
1917
|
+
}
|
|
1918
|
+
get currentMessage() {
|
|
1919
|
+
return __classPrivateFieldGet2(this, _BetaMessageStream_currentMessageSnapshot, "f");
|
|
1920
|
+
}
|
|
1921
|
+
async finalMessage() {
|
|
1922
|
+
await this.done();
|
|
1923
|
+
return __classPrivateFieldGet2(this, _BetaMessageStream_instances, "m", _BetaMessageStream_getFinalMessage).call(this);
|
|
1924
|
+
}
|
|
1925
|
+
async finalText() {
|
|
1926
|
+
await this.done();
|
|
1927
|
+
return __classPrivateFieldGet2(this, _BetaMessageStream_instances, "m", _BetaMessageStream_getFinalText).call(this);
|
|
1928
|
+
}
|
|
1929
|
+
_emit(event, ...args) {
|
|
1930
|
+
if (__classPrivateFieldGet2(this, _BetaMessageStream_ended, "f"))
|
|
1931
|
+
return;
|
|
1932
|
+
if (event === "end") {
|
|
1933
|
+
__classPrivateFieldSet2(this, _BetaMessageStream_ended, true, "f");
|
|
1934
|
+
__classPrivateFieldGet2(this, _BetaMessageStream_resolveEndPromise, "f").call(this);
|
|
1935
|
+
}
|
|
1936
|
+
const listeners = __classPrivateFieldGet2(this, _BetaMessageStream_listeners, "f")[event];
|
|
1937
|
+
if (listeners) {
|
|
1938
|
+
__classPrivateFieldGet2(this, _BetaMessageStream_listeners, "f")[event] = listeners.filter((l) => !l.once);
|
|
1939
|
+
listeners.forEach(({ listener }) => listener(...args));
|
|
1940
|
+
}
|
|
1941
|
+
if (event === "abort") {
|
|
1942
|
+
const error = args[0];
|
|
1943
|
+
if (!__classPrivateFieldGet2(this, _BetaMessageStream_catchingPromiseCreated, "f") && !listeners?.length) {
|
|
1944
|
+
Promise.reject(error);
|
|
1945
|
+
}
|
|
1946
|
+
__classPrivateFieldGet2(this, _BetaMessageStream_rejectConnectedPromise, "f").call(this, error);
|
|
1947
|
+
__classPrivateFieldGet2(this, _BetaMessageStream_rejectEndPromise, "f").call(this, error);
|
|
1948
|
+
this._emit("end");
|
|
1949
|
+
return;
|
|
1950
|
+
}
|
|
1951
|
+
if (event === "error") {
|
|
1952
|
+
const error = args[0];
|
|
1953
|
+
if (!__classPrivateFieldGet2(this, _BetaMessageStream_catchingPromiseCreated, "f") && !listeners?.length) {
|
|
1954
|
+
Promise.reject(error);
|
|
1955
|
+
}
|
|
1956
|
+
__classPrivateFieldGet2(this, _BetaMessageStream_rejectConnectedPromise, "f").call(this, error);
|
|
1957
|
+
__classPrivateFieldGet2(this, _BetaMessageStream_rejectEndPromise, "f").call(this, error);
|
|
1958
|
+
this._emit("end");
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
_emitFinal() {
|
|
1962
|
+
const finalMessage = this.receivedMessages.at(-1);
|
|
1963
|
+
if (finalMessage) {
|
|
1964
|
+
this._emit("finalMessage", __classPrivateFieldGet2(this, _BetaMessageStream_instances, "m", _BetaMessageStream_getFinalMessage).call(this));
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
async _fromReadableStream(readableStream, options) {
|
|
1968
|
+
const signal = options?.signal;
|
|
1969
|
+
if (signal) {
|
|
1970
|
+
if (signal.aborted)
|
|
1971
|
+
this.controller.abort();
|
|
1972
|
+
signal.addEventListener("abort", () => this.controller.abort());
|
|
1973
|
+
}
|
|
1974
|
+
__classPrivateFieldGet2(this, _BetaMessageStream_instances, "m", _BetaMessageStream_beginRequest).call(this);
|
|
1975
|
+
this._connected(null);
|
|
1976
|
+
const stream = Stream.fromReadableStream(readableStream, this.controller);
|
|
1977
|
+
for await (const event of stream) {
|
|
1978
|
+
__classPrivateFieldGet2(this, _BetaMessageStream_instances, "m", _BetaMessageStream_addStreamEvent).call(this, event);
|
|
1979
|
+
}
|
|
1980
|
+
if (stream.controller.signal?.aborted) {
|
|
1981
|
+
throw new APIUserAbortError;
|
|
1982
|
+
}
|
|
1983
|
+
__classPrivateFieldGet2(this, _BetaMessageStream_instances, "m", _BetaMessageStream_endRequest).call(this);
|
|
1984
|
+
}
|
|
1985
|
+
[(_BetaMessageStream_currentMessageSnapshot = new WeakMap, _BetaMessageStream_connectedPromise = new WeakMap, _BetaMessageStream_resolveConnectedPromise = new WeakMap, _BetaMessageStream_rejectConnectedPromise = new WeakMap, _BetaMessageStream_endPromise = new WeakMap, _BetaMessageStream_resolveEndPromise = new WeakMap, _BetaMessageStream_rejectEndPromise = new WeakMap, _BetaMessageStream_listeners = new WeakMap, _BetaMessageStream_ended = new WeakMap, _BetaMessageStream_errored = new WeakMap, _BetaMessageStream_aborted = new WeakMap, _BetaMessageStream_catchingPromiseCreated = new WeakMap, _BetaMessageStream_response = new WeakMap, _BetaMessageStream_request_id = new WeakMap, _BetaMessageStream_handleError = new WeakMap, _BetaMessageStream_instances = new WeakSet, _BetaMessageStream_getFinalMessage = function _BetaMessageStream_getFinalMessage() {
|
|
1986
|
+
if (this.receivedMessages.length === 0) {
|
|
1987
|
+
throw new AnthropicError("stream ended without producing a Message with role=assistant");
|
|
1988
|
+
}
|
|
1989
|
+
return this.receivedMessages.at(-1);
|
|
1990
|
+
}, _BetaMessageStream_getFinalText = function _BetaMessageStream_getFinalText() {
|
|
1991
|
+
if (this.receivedMessages.length === 0) {
|
|
1992
|
+
throw new AnthropicError("stream ended without producing a Message with role=assistant");
|
|
1993
|
+
}
|
|
1994
|
+
const textBlocks = this.receivedMessages.at(-1).content.filter((block) => block.type === "text").map((block) => block.text);
|
|
1995
|
+
if (textBlocks.length === 0) {
|
|
1996
|
+
throw new AnthropicError("stream ended without producing a content block with type=text");
|
|
1997
|
+
}
|
|
1998
|
+
return textBlocks.join(" ");
|
|
1999
|
+
}, _BetaMessageStream_beginRequest = function _BetaMessageStream_beginRequest() {
|
|
2000
|
+
if (this.ended)
|
|
2001
|
+
return;
|
|
2002
|
+
__classPrivateFieldSet2(this, _BetaMessageStream_currentMessageSnapshot, undefined, "f");
|
|
2003
|
+
}, _BetaMessageStream_addStreamEvent = function _BetaMessageStream_addStreamEvent(event) {
|
|
2004
|
+
if (this.ended)
|
|
2005
|
+
return;
|
|
2006
|
+
const messageSnapshot = __classPrivateFieldGet2(this, _BetaMessageStream_instances, "m", _BetaMessageStream_accumulateMessage).call(this, event);
|
|
2007
|
+
this._emit("streamEvent", event, messageSnapshot);
|
|
2008
|
+
switch (event.type) {
|
|
2009
|
+
case "content_block_delta": {
|
|
2010
|
+
const content = messageSnapshot.content.at(-1);
|
|
2011
|
+
if (event.delta.type === "text_delta" && content.type === "text") {
|
|
2012
|
+
this._emit("text", event.delta.text, content.text || "");
|
|
2013
|
+
} else if (event.delta.type === "input_json_delta" && content.type === "tool_use") {
|
|
2014
|
+
if (content.input) {
|
|
2015
|
+
this._emit("inputJson", event.delta.partial_json, content.input);
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
break;
|
|
2019
|
+
}
|
|
2020
|
+
case "message_stop": {
|
|
2021
|
+
this._addMessageParam(messageSnapshot);
|
|
2022
|
+
this._addMessage(messageSnapshot, true);
|
|
2023
|
+
break;
|
|
2024
|
+
}
|
|
2025
|
+
case "content_block_stop": {
|
|
2026
|
+
this._emit("contentBlock", messageSnapshot.content.at(-1));
|
|
2027
|
+
break;
|
|
2028
|
+
}
|
|
2029
|
+
case "message_start": {
|
|
2030
|
+
__classPrivateFieldSet2(this, _BetaMessageStream_currentMessageSnapshot, messageSnapshot, "f");
|
|
2031
|
+
break;
|
|
2032
|
+
}
|
|
2033
|
+
case "content_block_start":
|
|
2034
|
+
case "message_delta":
|
|
2035
|
+
break;
|
|
2036
|
+
}
|
|
2037
|
+
}, _BetaMessageStream_endRequest = function _BetaMessageStream_endRequest() {
|
|
2038
|
+
if (this.ended) {
|
|
2039
|
+
throw new AnthropicError(`stream has ended, this shouldn't happen`);
|
|
2040
|
+
}
|
|
2041
|
+
const snapshot = __classPrivateFieldGet2(this, _BetaMessageStream_currentMessageSnapshot, "f");
|
|
2042
|
+
if (!snapshot) {
|
|
2043
|
+
throw new AnthropicError(`request ended without sending any chunks`);
|
|
2044
|
+
}
|
|
2045
|
+
__classPrivateFieldSet2(this, _BetaMessageStream_currentMessageSnapshot, undefined, "f");
|
|
2046
|
+
return snapshot;
|
|
2047
|
+
}, _BetaMessageStream_accumulateMessage = function _BetaMessageStream_accumulateMessage(event) {
|
|
2048
|
+
let snapshot = __classPrivateFieldGet2(this, _BetaMessageStream_currentMessageSnapshot, "f");
|
|
2049
|
+
if (event.type === "message_start") {
|
|
2050
|
+
if (snapshot) {
|
|
2051
|
+
throw new AnthropicError(`Unexpected event order, got ${event.type} before receiving "message_stop"`);
|
|
2052
|
+
}
|
|
2053
|
+
return event.message;
|
|
2054
|
+
}
|
|
2055
|
+
if (!snapshot) {
|
|
2056
|
+
throw new AnthropicError(`Unexpected event order, got ${event.type} before "message_start"`);
|
|
2057
|
+
}
|
|
2058
|
+
switch (event.type) {
|
|
2059
|
+
case "message_stop":
|
|
2060
|
+
return snapshot;
|
|
2061
|
+
case "message_delta":
|
|
2062
|
+
snapshot.stop_reason = event.delta.stop_reason;
|
|
2063
|
+
snapshot.stop_sequence = event.delta.stop_sequence;
|
|
2064
|
+
snapshot.usage.output_tokens = event.usage.output_tokens;
|
|
2065
|
+
return snapshot;
|
|
2066
|
+
case "content_block_start":
|
|
2067
|
+
snapshot.content.push(event.content_block);
|
|
2068
|
+
return snapshot;
|
|
2069
|
+
case "content_block_delta": {
|
|
2070
|
+
const snapshotContent = snapshot.content.at(event.index);
|
|
2071
|
+
if (snapshotContent?.type === "text" && event.delta.type === "text_delta") {
|
|
2072
|
+
snapshotContent.text += event.delta.text;
|
|
2073
|
+
} else if (snapshotContent?.type === "tool_use" && event.delta.type === "input_json_delta") {
|
|
2074
|
+
let jsonBuf = snapshotContent[JSON_BUF_PROPERTY] || "";
|
|
2075
|
+
jsonBuf += event.delta.partial_json;
|
|
2076
|
+
Object.defineProperty(snapshotContent, JSON_BUF_PROPERTY, {
|
|
2077
|
+
value: jsonBuf,
|
|
2078
|
+
enumerable: false,
|
|
2079
|
+
writable: true
|
|
2080
|
+
});
|
|
2081
|
+
if (jsonBuf) {
|
|
2082
|
+
snapshotContent.input = partialParse(jsonBuf);
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
return snapshot;
|
|
2086
|
+
}
|
|
2087
|
+
case "content_block_stop":
|
|
2088
|
+
return snapshot;
|
|
2089
|
+
}
|
|
2090
|
+
}, Symbol.asyncIterator)]() {
|
|
2091
|
+
const pushQueue = [];
|
|
2092
|
+
const readQueue = [];
|
|
2093
|
+
let done = false;
|
|
2094
|
+
this.on("streamEvent", (event) => {
|
|
2095
|
+
const reader = readQueue.shift();
|
|
2096
|
+
if (reader) {
|
|
2097
|
+
reader.resolve(event);
|
|
2098
|
+
} else {
|
|
2099
|
+
pushQueue.push(event);
|
|
2100
|
+
}
|
|
2101
|
+
});
|
|
2102
|
+
this.on("end", () => {
|
|
2103
|
+
done = true;
|
|
2104
|
+
for (const reader of readQueue) {
|
|
2105
|
+
reader.resolve(undefined);
|
|
2106
|
+
}
|
|
2107
|
+
readQueue.length = 0;
|
|
2108
|
+
});
|
|
2109
|
+
this.on("abort", (err) => {
|
|
2110
|
+
done = true;
|
|
2111
|
+
for (const reader of readQueue) {
|
|
2112
|
+
reader.reject(err);
|
|
2113
|
+
}
|
|
2114
|
+
readQueue.length = 0;
|
|
2115
|
+
});
|
|
2116
|
+
this.on("error", (err) => {
|
|
2117
|
+
done = true;
|
|
2118
|
+
for (const reader of readQueue) {
|
|
2119
|
+
reader.reject(err);
|
|
2120
|
+
}
|
|
2121
|
+
readQueue.length = 0;
|
|
2122
|
+
});
|
|
2123
|
+
return {
|
|
2124
|
+
next: async () => {
|
|
2125
|
+
if (!pushQueue.length) {
|
|
2126
|
+
if (done) {
|
|
2127
|
+
return { value: undefined, done: true };
|
|
2128
|
+
}
|
|
2129
|
+
return new Promise((resolve, reject) => readQueue.push({ resolve, reject })).then((chunk2) => chunk2 ? { value: chunk2, done: false } : { value: undefined, done: true });
|
|
2130
|
+
}
|
|
2131
|
+
const chunk = pushQueue.shift();
|
|
2132
|
+
return { value: chunk, done: false };
|
|
2133
|
+
},
|
|
2134
|
+
return: async () => {
|
|
2135
|
+
this.abort();
|
|
2136
|
+
return { value: undefined, done: true };
|
|
2137
|
+
}
|
|
2138
|
+
};
|
|
2139
|
+
}
|
|
2140
|
+
toReadableStream() {
|
|
2141
|
+
const stream = new Stream(this[Symbol.asyncIterator].bind(this), this.controller);
|
|
2142
|
+
return stream.toReadableStream();
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2146
|
+
// ../../node_modules/@anthropic-ai/sdk/resources/beta/messages/messages.mjs
|
|
2147
|
+
var DEPRECATED_MODELS = {
|
|
2148
|
+
"claude-1.3": "November 6th, 2024",
|
|
2149
|
+
"claude-1.3-100k": "November 6th, 2024",
|
|
2150
|
+
"claude-instant-1.1": "November 6th, 2024",
|
|
2151
|
+
"claude-instant-1.1-100k": "November 6th, 2024",
|
|
2152
|
+
"claude-instant-1.2": "November 6th, 2024",
|
|
2153
|
+
"claude-3-sonnet-20240229": "July 21st, 2025",
|
|
2154
|
+
"claude-2.1": "July 21st, 2025",
|
|
2155
|
+
"claude-2.0": "July 21st, 2025"
|
|
2156
|
+
};
|
|
2157
|
+
|
|
2158
|
+
class Messages extends APIResource {
|
|
2159
|
+
constructor() {
|
|
2160
|
+
super(...arguments);
|
|
2161
|
+
this.batches = new Batches(this._client);
|
|
2162
|
+
}
|
|
2163
|
+
create(params, options) {
|
|
2164
|
+
const { betas, ...body } = params;
|
|
2165
|
+
if (body.model in DEPRECATED_MODELS) {
|
|
2166
|
+
console.warn(`The model '${body.model}' is deprecated and will reach end-of-life on ${DEPRECATED_MODELS[body.model]}
|
|
2167
|
+
Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`);
|
|
2168
|
+
}
|
|
2169
|
+
return this._client.post("/v1/messages?beta=true", {
|
|
2170
|
+
body,
|
|
2171
|
+
timeout: this._client._options.timeout ?? 600000,
|
|
2172
|
+
...options,
|
|
2173
|
+
headers: {
|
|
2174
|
+
...betas?.toString() != null ? { "anthropic-beta": betas?.toString() } : undefined,
|
|
2175
|
+
...options?.headers
|
|
2176
|
+
},
|
|
2177
|
+
stream: params.stream ?? false
|
|
2178
|
+
});
|
|
2179
|
+
}
|
|
2180
|
+
stream(body, options) {
|
|
2181
|
+
return BetaMessageStream.createMessage(this, body, options);
|
|
2182
|
+
}
|
|
2183
|
+
countTokens(params, options) {
|
|
2184
|
+
const { betas, ...body } = params;
|
|
2185
|
+
return this._client.post("/v1/messages/count_tokens?beta=true", {
|
|
2186
|
+
body,
|
|
2187
|
+
...options,
|
|
2188
|
+
headers: {
|
|
2189
|
+
"anthropic-beta": [...betas ?? [], "token-counting-2024-11-01"].toString(),
|
|
2190
|
+
...options?.headers
|
|
2191
|
+
}
|
|
2192
|
+
});
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
Messages.Batches = Batches;
|
|
2196
|
+
Messages.BetaMessageBatchesPage = BetaMessageBatchesPage;
|
|
2197
|
+
|
|
2198
|
+
// ../../node_modules/@anthropic-ai/sdk/resources/beta/beta.mjs
|
|
2199
|
+
class Beta extends APIResource {
|
|
2200
|
+
constructor() {
|
|
2201
|
+
super(...arguments);
|
|
2202
|
+
this.models = new Models(this._client);
|
|
2203
|
+
this.messages = new Messages(this._client);
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
Beta.Models = Models;
|
|
2207
|
+
Beta.BetaModelInfosPage = BetaModelInfosPage;
|
|
2208
|
+
Beta.Messages = Messages;
|
|
2209
|
+
// ../../node_modules/@anthropic-ai/sdk/resources/completions.mjs
|
|
2210
|
+
class Completions extends APIResource {
|
|
2211
|
+
create(body, options) {
|
|
2212
|
+
return this._client.post("/v1/complete", {
|
|
2213
|
+
body,
|
|
2214
|
+
timeout: this._client._options.timeout ?? 600000,
|
|
2215
|
+
...options,
|
|
2216
|
+
stream: body.stream ?? false
|
|
2217
|
+
});
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
// ../../node_modules/@anthropic-ai/sdk/resources/messages/batches.mjs
|
|
2221
|
+
class Batches2 extends APIResource {
|
|
2222
|
+
create(body, options) {
|
|
2223
|
+
return this._client.post("/v1/messages/batches", { body, ...options });
|
|
2224
|
+
}
|
|
2225
|
+
retrieve(messageBatchId, options) {
|
|
2226
|
+
return this._client.get(`/v1/messages/batches/${messageBatchId}`, options);
|
|
2227
|
+
}
|
|
2228
|
+
list(query = {}, options) {
|
|
2229
|
+
if (isRequestOptions(query)) {
|
|
2230
|
+
return this.list({}, query);
|
|
2231
|
+
}
|
|
2232
|
+
return this._client.getAPIList("/v1/messages/batches", MessageBatchesPage, { query, ...options });
|
|
2233
|
+
}
|
|
2234
|
+
delete(messageBatchId, options) {
|
|
2235
|
+
return this._client.delete(`/v1/messages/batches/${messageBatchId}`, options);
|
|
1689
2236
|
}
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
case "separator":
|
|
1693
|
-
tokens = tokens.slice(0, tokens.length - 1);
|
|
1694
|
-
return strip(tokens);
|
|
1695
|
-
break;
|
|
1696
|
-
case "number":
|
|
1697
|
-
let lastCharacterOfLastToken = lastToken.value[lastToken.value.length - 1];
|
|
1698
|
-
if (lastCharacterOfLastToken === "." || lastCharacterOfLastToken === "-") {
|
|
1699
|
-
tokens = tokens.slice(0, tokens.length - 1);
|
|
1700
|
-
return strip(tokens);
|
|
1701
|
-
}
|
|
1702
|
-
case "string":
|
|
1703
|
-
let tokenBeforeTheLastToken = tokens[tokens.length - 2];
|
|
1704
|
-
if (tokenBeforeTheLastToken?.type === "delimiter") {
|
|
1705
|
-
tokens = tokens.slice(0, tokens.length - 1);
|
|
1706
|
-
return strip(tokens);
|
|
1707
|
-
} else if (tokenBeforeTheLastToken?.type === "brace" && tokenBeforeTheLastToken.value === "{") {
|
|
1708
|
-
tokens = tokens.slice(0, tokens.length - 1);
|
|
1709
|
-
return strip(tokens);
|
|
1710
|
-
}
|
|
1711
|
-
break;
|
|
1712
|
-
case "delimiter":
|
|
1713
|
-
tokens = tokens.slice(0, tokens.length - 1);
|
|
1714
|
-
return strip(tokens);
|
|
1715
|
-
break;
|
|
2237
|
+
cancel(messageBatchId, options) {
|
|
2238
|
+
return this._client.post(`/v1/messages/batches/${messageBatchId}/cancel`, options);
|
|
1716
2239
|
}
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
tokens.map((token) => {
|
|
1722
|
-
if (token.type === "brace") {
|
|
1723
|
-
if (token.value === "{") {
|
|
1724
|
-
tail.push("}");
|
|
1725
|
-
} else {
|
|
1726
|
-
tail.splice(tail.lastIndexOf("}"), 1);
|
|
1727
|
-
}
|
|
1728
|
-
}
|
|
1729
|
-
if (token.type === "paren") {
|
|
1730
|
-
if (token.value === "[") {
|
|
1731
|
-
tail.push("]");
|
|
1732
|
-
} else {
|
|
1733
|
-
tail.splice(tail.lastIndexOf("]"), 1);
|
|
1734
|
-
}
|
|
2240
|
+
async results(messageBatchId, options) {
|
|
2241
|
+
const batch = await this.retrieve(messageBatchId);
|
|
2242
|
+
if (!batch.results_url) {
|
|
2243
|
+
throw new AnthropicError(`No batch \`results_url\`; Has it finished processing? ${batch.processing_status} - ${batch.id}`);
|
|
1735
2244
|
}
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
} else if (item === "]") {
|
|
1745
|
-
tokens.push({
|
|
1746
|
-
type: "paren",
|
|
1747
|
-
value: "]"
|
|
1748
|
-
});
|
|
1749
|
-
}
|
|
1750
|
-
});
|
|
2245
|
+
return this._client.get(batch.results_url, {
|
|
2246
|
+
...options,
|
|
2247
|
+
headers: {
|
|
2248
|
+
Accept: "application/binary",
|
|
2249
|
+
...options?.headers
|
|
2250
|
+
},
|
|
2251
|
+
__binaryResponse: true
|
|
2252
|
+
})._thenUnwrap((_, props) => JSONLDecoder.fromResponse(props.response, props.controller));
|
|
1751
2253
|
}
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
switch (token.type) {
|
|
1758
|
-
case "string":
|
|
1759
|
-
output += '"' + token.value + '"';
|
|
1760
|
-
break;
|
|
1761
|
-
default:
|
|
1762
|
-
output += token.value;
|
|
1763
|
-
break;
|
|
1764
|
-
}
|
|
1765
|
-
});
|
|
1766
|
-
return output;
|
|
1767
|
-
};
|
|
1768
|
-
var partialParse = (input) => JSON.parse(generate(unstrip(strip(tokenize(input)))));
|
|
2254
|
+
}
|
|
2255
|
+
|
|
2256
|
+
class MessageBatchesPage extends Page {
|
|
2257
|
+
}
|
|
2258
|
+
Batches2.MessageBatchesPage = MessageBatchesPage;
|
|
1769
2259
|
|
|
1770
2260
|
// ../../node_modules/@anthropic-ai/sdk/lib/MessageStream.mjs
|
|
1771
|
-
var
|
|
2261
|
+
var __classPrivateFieldSet3 = function(receiver, state, value, kind2, f) {
|
|
1772
2262
|
if (kind2 === "m")
|
|
1773
2263
|
throw new TypeError("Private method is not writable");
|
|
1774
2264
|
if (kind2 === "a" && !f)
|
|
@@ -1777,7 +2267,7 @@ var __classPrivateFieldSet2 = function(receiver, state, value, kind2, f) {
|
|
|
1777
2267
|
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
1778
2268
|
return kind2 === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
1779
2269
|
};
|
|
1780
|
-
var
|
|
2270
|
+
var __classPrivateFieldGet3 = function(receiver, state, kind2, f) {
|
|
1781
2271
|
if (kind2 === "a" && !f)
|
|
1782
2272
|
throw new TypeError("Private accessor was defined without a getter");
|
|
1783
2273
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
@@ -1797,6 +2287,8 @@ var _MessageStream_ended;
|
|
|
1797
2287
|
var _MessageStream_errored;
|
|
1798
2288
|
var _MessageStream_aborted;
|
|
1799
2289
|
var _MessageStream_catchingPromiseCreated;
|
|
2290
|
+
var _MessageStream_response;
|
|
2291
|
+
var _MessageStream_request_id;
|
|
1800
2292
|
var _MessageStream_getFinalMessage;
|
|
1801
2293
|
var _MessageStream_getFinalText;
|
|
1802
2294
|
var _MessageStream_handleError;
|
|
@@ -1804,7 +2296,7 @@ var _MessageStream_beginRequest;
|
|
|
1804
2296
|
var _MessageStream_addStreamEvent;
|
|
1805
2297
|
var _MessageStream_endRequest;
|
|
1806
2298
|
var _MessageStream_accumulateMessage;
|
|
1807
|
-
var
|
|
2299
|
+
var JSON_BUF_PROPERTY2 = "__json_buf";
|
|
1808
2300
|
|
|
1809
2301
|
class MessageStream {
|
|
1810
2302
|
constructor() {
|
|
@@ -1828,13 +2320,15 @@ class MessageStream {
|
|
|
1828
2320
|
_MessageStream_errored.set(this, false);
|
|
1829
2321
|
_MessageStream_aborted.set(this, false);
|
|
1830
2322
|
_MessageStream_catchingPromiseCreated.set(this, false);
|
|
2323
|
+
_MessageStream_response.set(this, undefined);
|
|
2324
|
+
_MessageStream_request_id.set(this, undefined);
|
|
1831
2325
|
_MessageStream_handleError.set(this, (error) => {
|
|
1832
|
-
|
|
2326
|
+
__classPrivateFieldSet3(this, _MessageStream_errored, true, "f");
|
|
1833
2327
|
if (error instanceof Error && error.name === "AbortError") {
|
|
1834
2328
|
error = new APIUserAbortError;
|
|
1835
2329
|
}
|
|
1836
2330
|
if (error instanceof APIUserAbortError) {
|
|
1837
|
-
|
|
2331
|
+
__classPrivateFieldSet3(this, _MessageStream_aborted, true, "f");
|
|
1838
2332
|
return this._emit("abort", error);
|
|
1839
2333
|
}
|
|
1840
2334
|
if (error instanceof AnthropicError) {
|
|
@@ -1847,19 +2341,36 @@ class MessageStream {
|
|
|
1847
2341
|
}
|
|
1848
2342
|
return this._emit("error", new AnthropicError(String(error)));
|
|
1849
2343
|
});
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
2344
|
+
__classPrivateFieldSet3(this, _MessageStream_connectedPromise, new Promise((resolve, reject) => {
|
|
2345
|
+
__classPrivateFieldSet3(this, _MessageStream_resolveConnectedPromise, resolve, "f");
|
|
2346
|
+
__classPrivateFieldSet3(this, _MessageStream_rejectConnectedPromise, reject, "f");
|
|
1853
2347
|
}), "f");
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
2348
|
+
__classPrivateFieldSet3(this, _MessageStream_endPromise, new Promise((resolve, reject) => {
|
|
2349
|
+
__classPrivateFieldSet3(this, _MessageStream_resolveEndPromise, resolve, "f");
|
|
2350
|
+
__classPrivateFieldSet3(this, _MessageStream_rejectEndPromise, reject, "f");
|
|
1857
2351
|
}), "f");
|
|
1858
|
-
|
|
2352
|
+
__classPrivateFieldGet3(this, _MessageStream_connectedPromise, "f").catch(() => {
|
|
1859
2353
|
});
|
|
1860
|
-
|
|
2354
|
+
__classPrivateFieldGet3(this, _MessageStream_endPromise, "f").catch(() => {
|
|
1861
2355
|
});
|
|
1862
2356
|
}
|
|
2357
|
+
get response() {
|
|
2358
|
+
return __classPrivateFieldGet3(this, _MessageStream_response, "f");
|
|
2359
|
+
}
|
|
2360
|
+
get request_id() {
|
|
2361
|
+
return __classPrivateFieldGet3(this, _MessageStream_request_id, "f");
|
|
2362
|
+
}
|
|
2363
|
+
async withResponse() {
|
|
2364
|
+
const response = await __classPrivateFieldGet3(this, _MessageStream_connectedPromise, "f");
|
|
2365
|
+
if (!response) {
|
|
2366
|
+
throw new Error("Could not resolve a `Response` object");
|
|
2367
|
+
}
|
|
2368
|
+
return {
|
|
2369
|
+
data: this,
|
|
2370
|
+
response,
|
|
2371
|
+
request_id: response.headers.get("request-id")
|
|
2372
|
+
};
|
|
2373
|
+
}
|
|
1863
2374
|
static fromReadableStream(stream) {
|
|
1864
2375
|
const runner = new MessageStream;
|
|
1865
2376
|
runner._run(() => runner._fromReadableStream(stream));
|
|
@@ -1877,7 +2388,7 @@ class MessageStream {
|
|
|
1877
2388
|
executor().then(() => {
|
|
1878
2389
|
this._emitFinal();
|
|
1879
2390
|
this._emit("end");
|
|
1880
|
-
},
|
|
2391
|
+
}, __classPrivateFieldGet3(this, _MessageStream_handleError, "f"));
|
|
1881
2392
|
}
|
|
1882
2393
|
_addMessageParam(message) {
|
|
1883
2394
|
this.messages.push(message);
|
|
@@ -1895,42 +2406,44 @@ class MessageStream {
|
|
|
1895
2406
|
this.controller.abort();
|
|
1896
2407
|
signal.addEventListener("abort", () => this.controller.abort());
|
|
1897
2408
|
}
|
|
1898
|
-
|
|
1899
|
-
const stream = await messages.create({ ...params, stream: true }, { ...options, signal: this.controller.signal });
|
|
1900
|
-
this._connected();
|
|
2409
|
+
__classPrivateFieldGet3(this, _MessageStream_instances, "m", _MessageStream_beginRequest).call(this);
|
|
2410
|
+
const { response, data: stream } = await messages.create({ ...params, stream: true }, { ...options, signal: this.controller.signal }).withResponse();
|
|
2411
|
+
this._connected(response);
|
|
1901
2412
|
for await (const event of stream) {
|
|
1902
|
-
|
|
2413
|
+
__classPrivateFieldGet3(this, _MessageStream_instances, "m", _MessageStream_addStreamEvent).call(this, event);
|
|
1903
2414
|
}
|
|
1904
2415
|
if (stream.controller.signal?.aborted) {
|
|
1905
2416
|
throw new APIUserAbortError;
|
|
1906
2417
|
}
|
|
1907
|
-
|
|
2418
|
+
__classPrivateFieldGet3(this, _MessageStream_instances, "m", _MessageStream_endRequest).call(this);
|
|
1908
2419
|
}
|
|
1909
|
-
_connected() {
|
|
2420
|
+
_connected(response) {
|
|
1910
2421
|
if (this.ended)
|
|
1911
2422
|
return;
|
|
1912
|
-
|
|
2423
|
+
__classPrivateFieldSet3(this, _MessageStream_response, response, "f");
|
|
2424
|
+
__classPrivateFieldSet3(this, _MessageStream_request_id, response?.headers.get("request-id"), "f");
|
|
2425
|
+
__classPrivateFieldGet3(this, _MessageStream_resolveConnectedPromise, "f").call(this, response);
|
|
1913
2426
|
this._emit("connect");
|
|
1914
2427
|
}
|
|
1915
2428
|
get ended() {
|
|
1916
|
-
return
|
|
2429
|
+
return __classPrivateFieldGet3(this, _MessageStream_ended, "f");
|
|
1917
2430
|
}
|
|
1918
2431
|
get errored() {
|
|
1919
|
-
return
|
|
2432
|
+
return __classPrivateFieldGet3(this, _MessageStream_errored, "f");
|
|
1920
2433
|
}
|
|
1921
2434
|
get aborted() {
|
|
1922
|
-
return
|
|
2435
|
+
return __classPrivateFieldGet3(this, _MessageStream_aborted, "f");
|
|
1923
2436
|
}
|
|
1924
2437
|
abort() {
|
|
1925
2438
|
this.controller.abort();
|
|
1926
2439
|
}
|
|
1927
2440
|
on(event, listener) {
|
|
1928
|
-
const listeners =
|
|
2441
|
+
const listeners = __classPrivateFieldGet3(this, _MessageStream_listeners, "f")[event] || (__classPrivateFieldGet3(this, _MessageStream_listeners, "f")[event] = []);
|
|
1929
2442
|
listeners.push({ listener });
|
|
1930
2443
|
return this;
|
|
1931
2444
|
}
|
|
1932
2445
|
off(event, listener) {
|
|
1933
|
-
const listeners =
|
|
2446
|
+
const listeners = __classPrivateFieldGet3(this, _MessageStream_listeners, "f")[event];
|
|
1934
2447
|
if (!listeners)
|
|
1935
2448
|
return this;
|
|
1936
2449
|
const index = listeners.findIndex((l) => l.listener === listener);
|
|
@@ -1939,69 +2452,69 @@ class MessageStream {
|
|
|
1939
2452
|
return this;
|
|
1940
2453
|
}
|
|
1941
2454
|
once(event, listener) {
|
|
1942
|
-
const listeners =
|
|
2455
|
+
const listeners = __classPrivateFieldGet3(this, _MessageStream_listeners, "f")[event] || (__classPrivateFieldGet3(this, _MessageStream_listeners, "f")[event] = []);
|
|
1943
2456
|
listeners.push({ listener, once: true });
|
|
1944
2457
|
return this;
|
|
1945
2458
|
}
|
|
1946
2459
|
emitted(event) {
|
|
1947
2460
|
return new Promise((resolve, reject) => {
|
|
1948
|
-
|
|
2461
|
+
__classPrivateFieldSet3(this, _MessageStream_catchingPromiseCreated, true, "f");
|
|
1949
2462
|
if (event !== "error")
|
|
1950
2463
|
this.once("error", reject);
|
|
1951
2464
|
this.once(event, resolve);
|
|
1952
2465
|
});
|
|
1953
2466
|
}
|
|
1954
2467
|
async done() {
|
|
1955
|
-
|
|
1956
|
-
await
|
|
2468
|
+
__classPrivateFieldSet3(this, _MessageStream_catchingPromiseCreated, true, "f");
|
|
2469
|
+
await __classPrivateFieldGet3(this, _MessageStream_endPromise, "f");
|
|
1957
2470
|
}
|
|
1958
2471
|
get currentMessage() {
|
|
1959
|
-
return
|
|
2472
|
+
return __classPrivateFieldGet3(this, _MessageStream_currentMessageSnapshot, "f");
|
|
1960
2473
|
}
|
|
1961
2474
|
async finalMessage() {
|
|
1962
2475
|
await this.done();
|
|
1963
|
-
return
|
|
2476
|
+
return __classPrivateFieldGet3(this, _MessageStream_instances, "m", _MessageStream_getFinalMessage).call(this);
|
|
1964
2477
|
}
|
|
1965
2478
|
async finalText() {
|
|
1966
2479
|
await this.done();
|
|
1967
|
-
return
|
|
2480
|
+
return __classPrivateFieldGet3(this, _MessageStream_instances, "m", _MessageStream_getFinalText).call(this);
|
|
1968
2481
|
}
|
|
1969
2482
|
_emit(event, ...args) {
|
|
1970
|
-
if (
|
|
2483
|
+
if (__classPrivateFieldGet3(this, _MessageStream_ended, "f"))
|
|
1971
2484
|
return;
|
|
1972
2485
|
if (event === "end") {
|
|
1973
|
-
|
|
1974
|
-
|
|
2486
|
+
__classPrivateFieldSet3(this, _MessageStream_ended, true, "f");
|
|
2487
|
+
__classPrivateFieldGet3(this, _MessageStream_resolveEndPromise, "f").call(this);
|
|
1975
2488
|
}
|
|
1976
|
-
const listeners =
|
|
2489
|
+
const listeners = __classPrivateFieldGet3(this, _MessageStream_listeners, "f")[event];
|
|
1977
2490
|
if (listeners) {
|
|
1978
|
-
|
|
2491
|
+
__classPrivateFieldGet3(this, _MessageStream_listeners, "f")[event] = listeners.filter((l) => !l.once);
|
|
1979
2492
|
listeners.forEach(({ listener }) => listener(...args));
|
|
1980
2493
|
}
|
|
1981
2494
|
if (event === "abort") {
|
|
1982
2495
|
const error = args[0];
|
|
1983
|
-
if (!
|
|
2496
|
+
if (!__classPrivateFieldGet3(this, _MessageStream_catchingPromiseCreated, "f") && !listeners?.length) {
|
|
1984
2497
|
Promise.reject(error);
|
|
1985
2498
|
}
|
|
1986
|
-
|
|
1987
|
-
|
|
2499
|
+
__classPrivateFieldGet3(this, _MessageStream_rejectConnectedPromise, "f").call(this, error);
|
|
2500
|
+
__classPrivateFieldGet3(this, _MessageStream_rejectEndPromise, "f").call(this, error);
|
|
1988
2501
|
this._emit("end");
|
|
1989
2502
|
return;
|
|
1990
2503
|
}
|
|
1991
2504
|
if (event === "error") {
|
|
1992
2505
|
const error = args[0];
|
|
1993
|
-
if (!
|
|
2506
|
+
if (!__classPrivateFieldGet3(this, _MessageStream_catchingPromiseCreated, "f") && !listeners?.length) {
|
|
1994
2507
|
Promise.reject(error);
|
|
1995
2508
|
}
|
|
1996
|
-
|
|
1997
|
-
|
|
2509
|
+
__classPrivateFieldGet3(this, _MessageStream_rejectConnectedPromise, "f").call(this, error);
|
|
2510
|
+
__classPrivateFieldGet3(this, _MessageStream_rejectEndPromise, "f").call(this, error);
|
|
1998
2511
|
this._emit("end");
|
|
1999
2512
|
}
|
|
2000
2513
|
}
|
|
2001
2514
|
_emitFinal() {
|
|
2002
2515
|
const finalMessage = this.receivedMessages.at(-1);
|
|
2003
2516
|
if (finalMessage) {
|
|
2004
|
-
this._emit("finalMessage",
|
|
2517
|
+
this._emit("finalMessage", __classPrivateFieldGet3(this, _MessageStream_instances, "m", _MessageStream_getFinalMessage).call(this));
|
|
2005
2518
|
}
|
|
2006
2519
|
}
|
|
2007
2520
|
async _fromReadableStream(readableStream, options) {
|
|
@@ -2011,18 +2524,18 @@ class MessageStream {
|
|
|
2011
2524
|
this.controller.abort();
|
|
2012
2525
|
signal.addEventListener("abort", () => this.controller.abort());
|
|
2013
2526
|
}
|
|
2014
|
-
|
|
2015
|
-
this._connected();
|
|
2527
|
+
__classPrivateFieldGet3(this, _MessageStream_instances, "m", _MessageStream_beginRequest).call(this);
|
|
2528
|
+
this._connected(null);
|
|
2016
2529
|
const stream = Stream.fromReadableStream(readableStream, this.controller);
|
|
2017
2530
|
for await (const event of stream) {
|
|
2018
|
-
|
|
2531
|
+
__classPrivateFieldGet3(this, _MessageStream_instances, "m", _MessageStream_addStreamEvent).call(this, event);
|
|
2019
2532
|
}
|
|
2020
2533
|
if (stream.controller.signal?.aborted) {
|
|
2021
2534
|
throw new APIUserAbortError;
|
|
2022
2535
|
}
|
|
2023
|
-
|
|
2536
|
+
__classPrivateFieldGet3(this, _MessageStream_instances, "m", _MessageStream_endRequest).call(this);
|
|
2024
2537
|
}
|
|
2025
|
-
[(_MessageStream_currentMessageSnapshot = new WeakMap, _MessageStream_connectedPromise = new WeakMap, _MessageStream_resolveConnectedPromise = new WeakMap, _MessageStream_rejectConnectedPromise = new WeakMap, _MessageStream_endPromise = new WeakMap, _MessageStream_resolveEndPromise = new WeakMap, _MessageStream_rejectEndPromise = new WeakMap, _MessageStream_listeners = new WeakMap, _MessageStream_ended = new WeakMap, _MessageStream_errored = new WeakMap, _MessageStream_aborted = new WeakMap, _MessageStream_catchingPromiseCreated = new WeakMap, _MessageStream_handleError = new WeakMap, _MessageStream_instances = new WeakSet, _MessageStream_getFinalMessage = function _MessageStream_getFinalMessage() {
|
|
2538
|
+
[(_MessageStream_currentMessageSnapshot = new WeakMap, _MessageStream_connectedPromise = new WeakMap, _MessageStream_resolveConnectedPromise = new WeakMap, _MessageStream_rejectConnectedPromise = new WeakMap, _MessageStream_endPromise = new WeakMap, _MessageStream_resolveEndPromise = new WeakMap, _MessageStream_rejectEndPromise = new WeakMap, _MessageStream_listeners = new WeakMap, _MessageStream_ended = new WeakMap, _MessageStream_errored = new WeakMap, _MessageStream_aborted = new WeakMap, _MessageStream_catchingPromiseCreated = new WeakMap, _MessageStream_response = new WeakMap, _MessageStream_request_id = new WeakMap, _MessageStream_handleError = new WeakMap, _MessageStream_instances = new WeakSet, _MessageStream_getFinalMessage = function _MessageStream_getFinalMessage() {
|
|
2026
2539
|
if (this.receivedMessages.length === 0) {
|
|
2027
2540
|
throw new AnthropicError("stream ended without producing a Message with role=assistant");
|
|
2028
2541
|
}
|
|
@@ -2039,11 +2552,11 @@ class MessageStream {
|
|
|
2039
2552
|
}, _MessageStream_beginRequest = function _MessageStream_beginRequest() {
|
|
2040
2553
|
if (this.ended)
|
|
2041
2554
|
return;
|
|
2042
|
-
|
|
2555
|
+
__classPrivateFieldSet3(this, _MessageStream_currentMessageSnapshot, undefined, "f");
|
|
2043
2556
|
}, _MessageStream_addStreamEvent = function _MessageStream_addStreamEvent(event) {
|
|
2044
2557
|
if (this.ended)
|
|
2045
2558
|
return;
|
|
2046
|
-
const messageSnapshot =
|
|
2559
|
+
const messageSnapshot = __classPrivateFieldGet3(this, _MessageStream_instances, "m", _MessageStream_accumulateMessage).call(this, event);
|
|
2047
2560
|
this._emit("streamEvent", event, messageSnapshot);
|
|
2048
2561
|
switch (event.type) {
|
|
2049
2562
|
case "content_block_delta": {
|
|
@@ -2067,7 +2580,7 @@ class MessageStream {
|
|
|
2067
2580
|
break;
|
|
2068
2581
|
}
|
|
2069
2582
|
case "message_start": {
|
|
2070
|
-
|
|
2583
|
+
__classPrivateFieldSet3(this, _MessageStream_currentMessageSnapshot, messageSnapshot, "f");
|
|
2071
2584
|
break;
|
|
2072
2585
|
}
|
|
2073
2586
|
case "content_block_start":
|
|
@@ -2078,14 +2591,14 @@ class MessageStream {
|
|
|
2078
2591
|
if (this.ended) {
|
|
2079
2592
|
throw new AnthropicError(`stream has ended, this shouldn't happen`);
|
|
2080
2593
|
}
|
|
2081
|
-
const snapshot =
|
|
2594
|
+
const snapshot = __classPrivateFieldGet3(this, _MessageStream_currentMessageSnapshot, "f");
|
|
2082
2595
|
if (!snapshot) {
|
|
2083
2596
|
throw new AnthropicError(`request ended without sending any chunks`);
|
|
2084
2597
|
}
|
|
2085
|
-
|
|
2598
|
+
__classPrivateFieldSet3(this, _MessageStream_currentMessageSnapshot, undefined, "f");
|
|
2086
2599
|
return snapshot;
|
|
2087
2600
|
}, _MessageStream_accumulateMessage = function _MessageStream_accumulateMessage(event) {
|
|
2088
|
-
let snapshot =
|
|
2601
|
+
let snapshot = __classPrivateFieldGet3(this, _MessageStream_currentMessageSnapshot, "f");
|
|
2089
2602
|
if (event.type === "message_start") {
|
|
2090
2603
|
if (snapshot) {
|
|
2091
2604
|
throw new AnthropicError(`Unexpected event order, got ${event.type} before receiving "message_stop"`);
|
|
@@ -2111,9 +2624,9 @@ class MessageStream {
|
|
|
2111
2624
|
if (snapshotContent?.type === "text" && event.delta.type === "text_delta") {
|
|
2112
2625
|
snapshotContent.text += event.delta.text;
|
|
2113
2626
|
} else if (snapshotContent?.type === "tool_use" && event.delta.type === "input_json_delta") {
|
|
2114
|
-
let jsonBuf = snapshotContent[
|
|
2627
|
+
let jsonBuf = snapshotContent[JSON_BUF_PROPERTY2] || "";
|
|
2115
2628
|
jsonBuf += event.delta.partial_json;
|
|
2116
|
-
Object.defineProperty(snapshotContent,
|
|
2629
|
+
Object.defineProperty(snapshotContent, JSON_BUF_PROPERTY2, {
|
|
2117
2630
|
value: jsonBuf,
|
|
2118
2631
|
enumerable: false,
|
|
2119
2632
|
writable: true
|
|
@@ -2190,8 +2703,8 @@ class Messages2 extends APIResource {
|
|
|
2190
2703
|
this.batches = new Batches2(this._client);
|
|
2191
2704
|
}
|
|
2192
2705
|
create(body, options) {
|
|
2193
|
-
if (body.model in
|
|
2194
|
-
console.warn(`The model '${body.model}' is deprecated and will reach end-of-life on ${
|
|
2706
|
+
if (body.model in DEPRECATED_MODELS2) {
|
|
2707
|
+
console.warn(`The model '${body.model}' is deprecated and will reach end-of-life on ${DEPRECATED_MODELS2[body.model]}
|
|
2195
2708
|
Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`);
|
|
2196
2709
|
}
|
|
2197
2710
|
return this._client.post("/v1/messages", {
|
|
@@ -2208,12 +2721,15 @@ Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resour
|
|
|
2208
2721
|
return this._client.post("/v1/messages/count_tokens", { body, ...options });
|
|
2209
2722
|
}
|
|
2210
2723
|
}
|
|
2211
|
-
var
|
|
2724
|
+
var DEPRECATED_MODELS2 = {
|
|
2212
2725
|
"claude-1.3": "November 6th, 2024",
|
|
2213
2726
|
"claude-1.3-100k": "November 6th, 2024",
|
|
2214
2727
|
"claude-instant-1.1": "November 6th, 2024",
|
|
2215
2728
|
"claude-instant-1.1-100k": "November 6th, 2024",
|
|
2216
|
-
"claude-instant-1.2": "November 6th, 2024"
|
|
2729
|
+
"claude-instant-1.2": "November 6th, 2024",
|
|
2730
|
+
"claude-3-sonnet-20240229": "July 21st, 2025",
|
|
2731
|
+
"claude-2.1": "July 21st, 2025",
|
|
2732
|
+
"claude-2.0": "July 21st, 2025"
|
|
2217
2733
|
};
|
|
2218
2734
|
Messages2.Batches = Batches2;
|
|
2219
2735
|
Messages2.MessageBatchesPage = MessageBatchesPage;
|
|
@@ -2351,6 +2867,35 @@ Anthropic.Beta = Beta;
|
|
|
2351
2867
|
|
|
2352
2868
|
// src/AiService/AiServiceBase.ts
|
|
2353
2869
|
class AiServiceBase {
|
|
2870
|
+
async request(systemPrompt, messages) {
|
|
2871
|
+
const stream = this.send(systemPrompt, messages);
|
|
2872
|
+
const usage = {
|
|
2873
|
+
inputTokens: 0,
|
|
2874
|
+
outputTokens: 0,
|
|
2875
|
+
cacheWriteTokens: 0,
|
|
2876
|
+
cacheReadTokens: 0,
|
|
2877
|
+
totalCost: 0
|
|
2878
|
+
};
|
|
2879
|
+
let resp = "";
|
|
2880
|
+
for await (const chunk of stream) {
|
|
2881
|
+
switch (chunk.type) {
|
|
2882
|
+
case "usage":
|
|
2883
|
+
usage.inputTokens = chunk.inputTokens ?? 0;
|
|
2884
|
+
usage.outputTokens = chunk.outputTokens ?? 0;
|
|
2885
|
+
usage.cacheWriteTokens = chunk.cacheWriteTokens ?? 0;
|
|
2886
|
+
usage.cacheReadTokens = chunk.cacheReadTokens ?? 0;
|
|
2887
|
+
usage.totalCost = chunk.totalCost;
|
|
2888
|
+
break;
|
|
2889
|
+
case "text":
|
|
2890
|
+
resp += chunk.text;
|
|
2891
|
+
break;
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
return {
|
|
2895
|
+
response: resp,
|
|
2896
|
+
usage
|
|
2897
|
+
};
|
|
2898
|
+
}
|
|
2354
2899
|
}
|
|
2355
2900
|
|
|
2356
2901
|
// src/AiService/ModelInfo.ts
|
|
@@ -2417,6 +2962,16 @@ var deepSeekModels = {
|
|
|
2417
2962
|
outputPrice: 0.28,
|
|
2418
2963
|
cacheWritesPrice: 0.14,
|
|
2419
2964
|
cacheReadsPrice: 0.014
|
|
2965
|
+
},
|
|
2966
|
+
"deepseek-reasoner": {
|
|
2967
|
+
maxTokens: 8000,
|
|
2968
|
+
contextWindow: 64000,
|
|
2969
|
+
supportsImages: false,
|
|
2970
|
+
supportsPromptCache: true,
|
|
2971
|
+
inputPrice: 0,
|
|
2972
|
+
outputPrice: 2.19,
|
|
2973
|
+
cacheWritesPrice: 0.55,
|
|
2974
|
+
cacheReadsPrice: 0.14
|
|
2420
2975
|
}
|
|
2421
2976
|
};
|
|
2422
2977
|
|
|
@@ -2432,7 +2987,7 @@ class AnthropicService extends AiServiceBase {
|
|
|
2432
2987
|
apiKey: options.apiKey,
|
|
2433
2988
|
baseURL: options.baseUrl || undefined
|
|
2434
2989
|
});
|
|
2435
|
-
const id = this.#options.
|
|
2990
|
+
const id = this.#options.model ?? anthropicDefaultModelId;
|
|
2436
2991
|
this.model = {
|
|
2437
2992
|
id,
|
|
2438
2993
|
info: anthropicModels[id] ?? anthropicModels[anthropicDefaultModelId]
|
|
@@ -2521,23 +3076,21 @@ class AnthropicService extends AiServiceBase {
|
|
|
2521
3076
|
switch (chunk.type) {
|
|
2522
3077
|
case "message_start": {
|
|
2523
3078
|
const usage = chunk.message.usage;
|
|
2524
|
-
|
|
3079
|
+
yield {
|
|
2525
3080
|
type: "usage",
|
|
2526
|
-
inputTokens: usage.input_tokens
|
|
2527
|
-
outputTokens: usage.output_tokens
|
|
2528
|
-
cacheWriteTokens: usage.cache_creation_input_tokens ||
|
|
2529
|
-
cacheReadTokens: usage.cache_read_input_tokens ||
|
|
3081
|
+
inputTokens: usage.input_tokens,
|
|
3082
|
+
outputTokens: usage.output_tokens,
|
|
3083
|
+
cacheWriteTokens: usage.cache_creation_input_tokens || 0,
|
|
3084
|
+
cacheReadTokens: usage.cache_read_input_tokens || 0
|
|
2530
3085
|
};
|
|
2531
|
-
yield usageInfo;
|
|
2532
3086
|
break;
|
|
2533
3087
|
}
|
|
2534
3088
|
case "message_delta": {
|
|
2535
|
-
|
|
3089
|
+
yield {
|
|
2536
3090
|
type: "usage",
|
|
2537
3091
|
inputTokens: 0,
|
|
2538
|
-
outputTokens: chunk.usage.output_tokens
|
|
3092
|
+
outputTokens: chunk.usage.output_tokens
|
|
2539
3093
|
};
|
|
2540
|
-
yield deltaUsage;
|
|
2541
3094
|
break;
|
|
2542
3095
|
}
|
|
2543
3096
|
case "message_stop":
|
|
@@ -2887,7 +3440,7 @@ function stringify(object, opts = {}) {
|
|
|
2887
3440
|
return joined.length > 0 ? prefix + joined : "";
|
|
2888
3441
|
}
|
|
2889
3442
|
// ../../node_modules/openai/version.mjs
|
|
2890
|
-
var VERSION2 = "4.
|
|
3443
|
+
var VERSION2 = "4.80.0";
|
|
2891
3444
|
|
|
2892
3445
|
// ../../node_modules/openai/_shims/registry.mjs
|
|
2893
3446
|
var auto2 = false;
|
|
@@ -3188,6 +3741,35 @@ LineDecoder2.NEWLINE_CHARS = new Set([`
|
|
|
3188
3741
|
`, "\r"]);
|
|
3189
3742
|
LineDecoder2.NEWLINE_REGEXP = /\r\n|[\n\r]/g;
|
|
3190
3743
|
|
|
3744
|
+
// ../../node_modules/openai/internal/stream-utils.mjs
|
|
3745
|
+
function ReadableStreamToAsyncIterable2(stream) {
|
|
3746
|
+
if (stream[Symbol.asyncIterator])
|
|
3747
|
+
return stream;
|
|
3748
|
+
const reader = stream.getReader();
|
|
3749
|
+
return {
|
|
3750
|
+
async next() {
|
|
3751
|
+
try {
|
|
3752
|
+
const result = await reader.read();
|
|
3753
|
+
if (result?.done)
|
|
3754
|
+
reader.releaseLock();
|
|
3755
|
+
return result;
|
|
3756
|
+
} catch (e) {
|
|
3757
|
+
reader.releaseLock();
|
|
3758
|
+
throw e;
|
|
3759
|
+
}
|
|
3760
|
+
},
|
|
3761
|
+
async return() {
|
|
3762
|
+
const cancelPromise = reader.cancel();
|
|
3763
|
+
reader.releaseLock();
|
|
3764
|
+
await cancelPromise;
|
|
3765
|
+
return { done: true, value: undefined };
|
|
3766
|
+
},
|
|
3767
|
+
[Symbol.asyncIterator]() {
|
|
3768
|
+
return this;
|
|
3769
|
+
}
|
|
3770
|
+
};
|
|
3771
|
+
}
|
|
3772
|
+
|
|
3191
3773
|
// ../../node_modules/openai/streaming.mjs
|
|
3192
3774
|
class Stream2 {
|
|
3193
3775
|
constructor(iterator, controller) {
|
|
@@ -3254,7 +3836,7 @@ class Stream2 {
|
|
|
3254
3836
|
let consumed = false;
|
|
3255
3837
|
async function* iterLines() {
|
|
3256
3838
|
const lineDecoder = new LineDecoder2;
|
|
3257
|
-
const iter =
|
|
3839
|
+
const iter = ReadableStreamToAsyncIterable2(readableStream);
|
|
3258
3840
|
for await (const chunk of iter) {
|
|
3259
3841
|
for (const line of lineDecoder.decode(chunk)) {
|
|
3260
3842
|
yield line;
|
|
@@ -3346,7 +3928,7 @@ async function* _iterSSEMessages2(response, controller) {
|
|
|
3346
3928
|
}
|
|
3347
3929
|
const sseDecoder = new SSEDecoder2;
|
|
3348
3930
|
const lineDecoder = new LineDecoder2;
|
|
3349
|
-
const iter =
|
|
3931
|
+
const iter = ReadableStreamToAsyncIterable2(response.body);
|
|
3350
3932
|
for await (const sseChunk of iterSSEChunks2(iter)) {
|
|
3351
3933
|
for (const line of lineDecoder.decode(sseChunk)) {
|
|
3352
3934
|
const sse = sseDecoder.decode(line);
|
|
@@ -3445,33 +4027,6 @@ function partition2(str, delimiter) {
|
|
|
3445
4027
|
}
|
|
3446
4028
|
return [str, "", ""];
|
|
3447
4029
|
}
|
|
3448
|
-
function readableStreamAsyncIterable2(stream) {
|
|
3449
|
-
if (stream[Symbol.asyncIterator])
|
|
3450
|
-
return stream;
|
|
3451
|
-
const reader = stream.getReader();
|
|
3452
|
-
return {
|
|
3453
|
-
async next() {
|
|
3454
|
-
try {
|
|
3455
|
-
const result = await reader.read();
|
|
3456
|
-
if (result?.done)
|
|
3457
|
-
reader.releaseLock();
|
|
3458
|
-
return result;
|
|
3459
|
-
} catch (e) {
|
|
3460
|
-
reader.releaseLock();
|
|
3461
|
-
throw e;
|
|
3462
|
-
}
|
|
3463
|
-
},
|
|
3464
|
-
async return() {
|
|
3465
|
-
const cancelPromise = reader.cancel();
|
|
3466
|
-
reader.releaseLock();
|
|
3467
|
-
await cancelPromise;
|
|
3468
|
-
return { done: true, value: undefined };
|
|
3469
|
-
},
|
|
3470
|
-
[Symbol.asyncIterator]() {
|
|
3471
|
-
return this;
|
|
3472
|
-
}
|
|
3473
|
-
};
|
|
3474
|
-
}
|
|
3475
4030
|
|
|
3476
4031
|
// ../../node_modules/openai/uploads.mjs
|
|
3477
4032
|
var isResponseLike2 = (value) => value != null && typeof value === "object" && typeof value.url === "string" && typeof value.blob === "function";
|
|
@@ -3562,7 +4117,7 @@ var addFormValue = async (form, key, value) => {
|
|
|
3562
4117
|
};
|
|
3563
4118
|
|
|
3564
4119
|
// ../../node_modules/openai/core.mjs
|
|
3565
|
-
var
|
|
4120
|
+
var __classPrivateFieldSet4 = function(receiver, state, value, kind3, f) {
|
|
3566
4121
|
if (kind3 === "m")
|
|
3567
4122
|
throw new TypeError("Private method is not writable");
|
|
3568
4123
|
if (kind3 === "a" && !f)
|
|
@@ -3571,7 +4126,7 @@ var __classPrivateFieldSet3 = function(receiver, state, value, kind3, f) {
|
|
|
3571
4126
|
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
3572
4127
|
return kind3 === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
3573
4128
|
};
|
|
3574
|
-
var
|
|
4129
|
+
var __classPrivateFieldGet4 = function(receiver, state, kind3, f) {
|
|
3575
4130
|
if (kind3 === "a" && !f)
|
|
3576
4131
|
throw new TypeError("Private accessor was defined without a getter");
|
|
3577
4132
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
@@ -3921,7 +4476,7 @@ class APIClient2 {
|
|
|
3921
4476
|
class AbstractPage2 {
|
|
3922
4477
|
constructor(client, response, body, options) {
|
|
3923
4478
|
_AbstractPage_client2.set(this, undefined);
|
|
3924
|
-
|
|
4479
|
+
__classPrivateFieldSet4(this, _AbstractPage_client2, client, "f");
|
|
3925
4480
|
this.options = options;
|
|
3926
4481
|
this.response = response;
|
|
3927
4482
|
this.body = body;
|
|
@@ -3948,7 +4503,7 @@ class AbstractPage2 {
|
|
|
3948
4503
|
nextOptions.query = undefined;
|
|
3949
4504
|
nextOptions.path = nextInfo.url.toString();
|
|
3950
4505
|
}
|
|
3951
|
-
return await
|
|
4506
|
+
return await __classPrivateFieldGet4(this, _AbstractPage_client2, "f").requestAPIList(this.constructor, nextOptions);
|
|
3952
4507
|
}
|
|
3953
4508
|
async* iterPages() {
|
|
3954
4509
|
let page = this;
|
|
@@ -4182,9 +4737,32 @@ function applyHeadersMut2(targetHeaders, newHeaders) {
|
|
|
4182
4737
|
}
|
|
4183
4738
|
}
|
|
4184
4739
|
}
|
|
4740
|
+
var SENSITIVE_HEADERS = new Set(["authorization", "api-key"]);
|
|
4185
4741
|
function debug2(action, ...args) {
|
|
4186
4742
|
if (typeof process !== "undefined" && process?.env?.["DEBUG"] === "true") {
|
|
4187
|
-
|
|
4743
|
+
const modifiedArgs = args.map((arg) => {
|
|
4744
|
+
if (!arg) {
|
|
4745
|
+
return arg;
|
|
4746
|
+
}
|
|
4747
|
+
if (arg["headers"]) {
|
|
4748
|
+
const modifiedArg2 = { ...arg, headers: { ...arg["headers"] } };
|
|
4749
|
+
for (const header in arg["headers"]) {
|
|
4750
|
+
if (SENSITIVE_HEADERS.has(header.toLowerCase())) {
|
|
4751
|
+
modifiedArg2["headers"][header] = "REDACTED";
|
|
4752
|
+
}
|
|
4753
|
+
}
|
|
4754
|
+
return modifiedArg2;
|
|
4755
|
+
}
|
|
4756
|
+
let modifiedArg = null;
|
|
4757
|
+
for (const header in arg) {
|
|
4758
|
+
if (SENSITIVE_HEADERS.has(header.toLowerCase())) {
|
|
4759
|
+
modifiedArg ?? (modifiedArg = { ...arg });
|
|
4760
|
+
modifiedArg[header] = "REDACTED";
|
|
4761
|
+
}
|
|
4762
|
+
}
|
|
4763
|
+
return modifiedArg ?? arg;
|
|
4764
|
+
});
|
|
4765
|
+
console.log(`OpenAI:DEBUG:${action}`, ...modifiedArgs);
|
|
4188
4766
|
}
|
|
4189
4767
|
}
|
|
4190
4768
|
var uuid42 = () => {
|
|
@@ -4421,7 +4999,7 @@ var isToolMessage = (message) => {
|
|
|
4421
4999
|
};
|
|
4422
5000
|
|
|
4423
5001
|
// ../../node_modules/openai/lib/EventStream.mjs
|
|
4424
|
-
var
|
|
5002
|
+
var __classPrivateFieldSet5 = function(receiver, state, value, kind3, f) {
|
|
4425
5003
|
if (kind3 === "m")
|
|
4426
5004
|
throw new TypeError("Private method is not writable");
|
|
4427
5005
|
if (kind3 === "a" && !f)
|
|
@@ -4430,7 +5008,7 @@ var __classPrivateFieldSet4 = function(receiver, state, value, kind3, f) {
|
|
|
4430
5008
|
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
4431
5009
|
return kind3 === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
4432
5010
|
};
|
|
4433
|
-
var
|
|
5011
|
+
var __classPrivateFieldGet5 = function(receiver, state, kind3, f) {
|
|
4434
5012
|
if (kind3 === "a" && !f)
|
|
4435
5013
|
throw new TypeError("Private accessor was defined without a getter");
|
|
4436
5014
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
@@ -4470,17 +5048,17 @@ class EventStream {
|
|
|
4470
5048
|
_EventStream_errored.set(this, false);
|
|
4471
5049
|
_EventStream_aborted.set(this, false);
|
|
4472
5050
|
_EventStream_catchingPromiseCreated.set(this, false);
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
5051
|
+
__classPrivateFieldSet5(this, _EventStream_connectedPromise, new Promise((resolve, reject) => {
|
|
5052
|
+
__classPrivateFieldSet5(this, _EventStream_resolveConnectedPromise, resolve, "f");
|
|
5053
|
+
__classPrivateFieldSet5(this, _EventStream_rejectConnectedPromise, reject, "f");
|
|
4476
5054
|
}), "f");
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
5055
|
+
__classPrivateFieldSet5(this, _EventStream_endPromise, new Promise((resolve, reject) => {
|
|
5056
|
+
__classPrivateFieldSet5(this, _EventStream_resolveEndPromise, resolve, "f");
|
|
5057
|
+
__classPrivateFieldSet5(this, _EventStream_rejectEndPromise, reject, "f");
|
|
4480
5058
|
}), "f");
|
|
4481
|
-
|
|
5059
|
+
__classPrivateFieldGet5(this, _EventStream_connectedPromise, "f").catch(() => {
|
|
4482
5060
|
});
|
|
4483
|
-
|
|
5061
|
+
__classPrivateFieldGet5(this, _EventStream_endPromise, "f").catch(() => {
|
|
4484
5062
|
});
|
|
4485
5063
|
}
|
|
4486
5064
|
_run(executor) {
|
|
@@ -4488,34 +5066,34 @@ class EventStream {
|
|
|
4488
5066
|
executor().then(() => {
|
|
4489
5067
|
this._emitFinal();
|
|
4490
5068
|
this._emit("end");
|
|
4491
|
-
},
|
|
5069
|
+
}, __classPrivateFieldGet5(this, _EventStream_instances, "m", _EventStream_handleError).bind(this));
|
|
4492
5070
|
}, 0);
|
|
4493
5071
|
}
|
|
4494
5072
|
_connected() {
|
|
4495
5073
|
if (this.ended)
|
|
4496
5074
|
return;
|
|
4497
|
-
|
|
5075
|
+
__classPrivateFieldGet5(this, _EventStream_resolveConnectedPromise, "f").call(this);
|
|
4498
5076
|
this._emit("connect");
|
|
4499
5077
|
}
|
|
4500
5078
|
get ended() {
|
|
4501
|
-
return
|
|
5079
|
+
return __classPrivateFieldGet5(this, _EventStream_ended, "f");
|
|
4502
5080
|
}
|
|
4503
5081
|
get errored() {
|
|
4504
|
-
return
|
|
5082
|
+
return __classPrivateFieldGet5(this, _EventStream_errored, "f");
|
|
4505
5083
|
}
|
|
4506
5084
|
get aborted() {
|
|
4507
|
-
return
|
|
5085
|
+
return __classPrivateFieldGet5(this, _EventStream_aborted, "f");
|
|
4508
5086
|
}
|
|
4509
5087
|
abort() {
|
|
4510
5088
|
this.controller.abort();
|
|
4511
5089
|
}
|
|
4512
5090
|
on(event, listener) {
|
|
4513
|
-
const listeners =
|
|
5091
|
+
const listeners = __classPrivateFieldGet5(this, _EventStream_listeners, "f")[event] || (__classPrivateFieldGet5(this, _EventStream_listeners, "f")[event] = []);
|
|
4514
5092
|
listeners.push({ listener });
|
|
4515
5093
|
return this;
|
|
4516
5094
|
}
|
|
4517
5095
|
off(event, listener) {
|
|
4518
|
-
const listeners =
|
|
5096
|
+
const listeners = __classPrivateFieldGet5(this, _EventStream_listeners, "f")[event];
|
|
4519
5097
|
if (!listeners)
|
|
4520
5098
|
return this;
|
|
4521
5099
|
const index = listeners.findIndex((l) => l.listener === listener);
|
|
@@ -4524,52 +5102,52 @@ class EventStream {
|
|
|
4524
5102
|
return this;
|
|
4525
5103
|
}
|
|
4526
5104
|
once(event, listener) {
|
|
4527
|
-
const listeners =
|
|
5105
|
+
const listeners = __classPrivateFieldGet5(this, _EventStream_listeners, "f")[event] || (__classPrivateFieldGet5(this, _EventStream_listeners, "f")[event] = []);
|
|
4528
5106
|
listeners.push({ listener, once: true });
|
|
4529
5107
|
return this;
|
|
4530
5108
|
}
|
|
4531
5109
|
emitted(event) {
|
|
4532
5110
|
return new Promise((resolve, reject) => {
|
|
4533
|
-
|
|
5111
|
+
__classPrivateFieldSet5(this, _EventStream_catchingPromiseCreated, true, "f");
|
|
4534
5112
|
if (event !== "error")
|
|
4535
5113
|
this.once("error", reject);
|
|
4536
5114
|
this.once(event, resolve);
|
|
4537
5115
|
});
|
|
4538
5116
|
}
|
|
4539
5117
|
async done() {
|
|
4540
|
-
|
|
4541
|
-
await
|
|
5118
|
+
__classPrivateFieldSet5(this, _EventStream_catchingPromiseCreated, true, "f");
|
|
5119
|
+
await __classPrivateFieldGet5(this, _EventStream_endPromise, "f");
|
|
4542
5120
|
}
|
|
4543
5121
|
_emit(event, ...args) {
|
|
4544
|
-
if (
|
|
5122
|
+
if (__classPrivateFieldGet5(this, _EventStream_ended, "f")) {
|
|
4545
5123
|
return;
|
|
4546
5124
|
}
|
|
4547
5125
|
if (event === "end") {
|
|
4548
|
-
|
|
4549
|
-
|
|
5126
|
+
__classPrivateFieldSet5(this, _EventStream_ended, true, "f");
|
|
5127
|
+
__classPrivateFieldGet5(this, _EventStream_resolveEndPromise, "f").call(this);
|
|
4550
5128
|
}
|
|
4551
|
-
const listeners =
|
|
5129
|
+
const listeners = __classPrivateFieldGet5(this, _EventStream_listeners, "f")[event];
|
|
4552
5130
|
if (listeners) {
|
|
4553
|
-
|
|
5131
|
+
__classPrivateFieldGet5(this, _EventStream_listeners, "f")[event] = listeners.filter((l) => !l.once);
|
|
4554
5132
|
listeners.forEach(({ listener }) => listener(...args));
|
|
4555
5133
|
}
|
|
4556
5134
|
if (event === "abort") {
|
|
4557
5135
|
const error = args[0];
|
|
4558
|
-
if (!
|
|
5136
|
+
if (!__classPrivateFieldGet5(this, _EventStream_catchingPromiseCreated, "f") && !listeners?.length) {
|
|
4559
5137
|
Promise.reject(error);
|
|
4560
5138
|
}
|
|
4561
|
-
|
|
4562
|
-
|
|
5139
|
+
__classPrivateFieldGet5(this, _EventStream_rejectConnectedPromise, "f").call(this, error);
|
|
5140
|
+
__classPrivateFieldGet5(this, _EventStream_rejectEndPromise, "f").call(this, error);
|
|
4563
5141
|
this._emit("end");
|
|
4564
5142
|
return;
|
|
4565
5143
|
}
|
|
4566
5144
|
if (event === "error") {
|
|
4567
5145
|
const error = args[0];
|
|
4568
|
-
if (!
|
|
5146
|
+
if (!__classPrivateFieldGet5(this, _EventStream_catchingPromiseCreated, "f") && !listeners?.length) {
|
|
4569
5147
|
Promise.reject(error);
|
|
4570
5148
|
}
|
|
4571
|
-
|
|
4572
|
-
|
|
5149
|
+
__classPrivateFieldGet5(this, _EventStream_rejectConnectedPromise, "f").call(this, error);
|
|
5150
|
+
__classPrivateFieldGet5(this, _EventStream_rejectEndPromise, "f").call(this, error);
|
|
4573
5151
|
this._emit("end");
|
|
4574
5152
|
}
|
|
4575
5153
|
}
|
|
@@ -4577,12 +5155,12 @@ class EventStream {
|
|
|
4577
5155
|
}
|
|
4578
5156
|
}
|
|
4579
5157
|
_EventStream_connectedPromise = new WeakMap, _EventStream_resolveConnectedPromise = new WeakMap, _EventStream_rejectConnectedPromise = new WeakMap, _EventStream_endPromise = new WeakMap, _EventStream_resolveEndPromise = new WeakMap, _EventStream_rejectEndPromise = new WeakMap, _EventStream_listeners = new WeakMap, _EventStream_ended = new WeakMap, _EventStream_errored = new WeakMap, _EventStream_aborted = new WeakMap, _EventStream_catchingPromiseCreated = new WeakMap, _EventStream_instances = new WeakSet, _EventStream_handleError = function _EventStream_handleError2(error) {
|
|
4580
|
-
|
|
5158
|
+
__classPrivateFieldSet5(this, _EventStream_errored, true, "f");
|
|
4581
5159
|
if (error instanceof Error && error.name === "AbortError") {
|
|
4582
5160
|
error = new APIUserAbortError2;
|
|
4583
5161
|
}
|
|
4584
5162
|
if (error instanceof APIUserAbortError2) {
|
|
4585
|
-
|
|
5163
|
+
__classPrivateFieldSet5(this, _EventStream_aborted, true, "f");
|
|
4586
5164
|
return this._emit("abort", error);
|
|
4587
5165
|
}
|
|
4588
5166
|
if (error instanceof OpenAIError) {
|
|
@@ -4682,7 +5260,7 @@ function validateInputTools(tools) {
|
|
|
4682
5260
|
}
|
|
4683
5261
|
|
|
4684
5262
|
// ../../node_modules/openai/lib/AbstractChatCompletionRunner.mjs
|
|
4685
|
-
var
|
|
5263
|
+
var __classPrivateFieldGet6 = function(receiver, state, kind3, f) {
|
|
4686
5264
|
if (kind3 === "a" && !f)
|
|
4687
5265
|
throw new TypeError("Private accessor was defined without a getter");
|
|
4688
5266
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
@@ -4742,23 +5320,23 @@ class AbstractChatCompletionRunner extends EventStream {
|
|
|
4742
5320
|
}
|
|
4743
5321
|
async finalContent() {
|
|
4744
5322
|
await this.done();
|
|
4745
|
-
return
|
|
5323
|
+
return __classPrivateFieldGet6(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalContent).call(this);
|
|
4746
5324
|
}
|
|
4747
5325
|
async finalMessage() {
|
|
4748
5326
|
await this.done();
|
|
4749
|
-
return
|
|
5327
|
+
return __classPrivateFieldGet6(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalMessage).call(this);
|
|
4750
5328
|
}
|
|
4751
5329
|
async finalFunctionCall() {
|
|
4752
5330
|
await this.done();
|
|
4753
|
-
return
|
|
5331
|
+
return __classPrivateFieldGet6(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalFunctionCall).call(this);
|
|
4754
5332
|
}
|
|
4755
5333
|
async finalFunctionCallResult() {
|
|
4756
5334
|
await this.done();
|
|
4757
|
-
return
|
|
5335
|
+
return __classPrivateFieldGet6(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalFunctionCallResult).call(this);
|
|
4758
5336
|
}
|
|
4759
5337
|
async totalUsage() {
|
|
4760
5338
|
await this.done();
|
|
4761
|
-
return
|
|
5339
|
+
return __classPrivateFieldGet6(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_calculateTotalUsage).call(this);
|
|
4762
5340
|
}
|
|
4763
5341
|
allChatCompletions() {
|
|
4764
5342
|
return [...this._chatCompletions];
|
|
@@ -4767,20 +5345,20 @@ class AbstractChatCompletionRunner extends EventStream {
|
|
|
4767
5345
|
const completion = this._chatCompletions[this._chatCompletions.length - 1];
|
|
4768
5346
|
if (completion)
|
|
4769
5347
|
this._emit("finalChatCompletion", completion);
|
|
4770
|
-
const finalMessage =
|
|
5348
|
+
const finalMessage = __classPrivateFieldGet6(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalMessage).call(this);
|
|
4771
5349
|
if (finalMessage)
|
|
4772
5350
|
this._emit("finalMessage", finalMessage);
|
|
4773
|
-
const finalContent =
|
|
5351
|
+
const finalContent = __classPrivateFieldGet6(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalContent).call(this);
|
|
4774
5352
|
if (finalContent)
|
|
4775
5353
|
this._emit("finalContent", finalContent);
|
|
4776
|
-
const finalFunctionCall =
|
|
5354
|
+
const finalFunctionCall = __classPrivateFieldGet6(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalFunctionCall).call(this);
|
|
4777
5355
|
if (finalFunctionCall)
|
|
4778
5356
|
this._emit("finalFunctionCall", finalFunctionCall);
|
|
4779
|
-
const finalFunctionCallResult =
|
|
5357
|
+
const finalFunctionCallResult = __classPrivateFieldGet6(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalFunctionCallResult).call(this);
|
|
4780
5358
|
if (finalFunctionCallResult != null)
|
|
4781
5359
|
this._emit("finalFunctionCallResult", finalFunctionCallResult);
|
|
4782
5360
|
if (this._chatCompletions.some((c) => c.usage)) {
|
|
4783
|
-
this._emit("totalUsage",
|
|
5361
|
+
this._emit("totalUsage", __classPrivateFieldGet6(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_calculateTotalUsage).call(this));
|
|
4784
5362
|
}
|
|
4785
5363
|
}
|
|
4786
5364
|
async _createChatCompletion(client, params, options) {
|
|
@@ -4790,7 +5368,7 @@ class AbstractChatCompletionRunner extends EventStream {
|
|
|
4790
5368
|
this.controller.abort();
|
|
4791
5369
|
signal.addEventListener("abort", () => this.controller.abort());
|
|
4792
5370
|
}
|
|
4793
|
-
|
|
5371
|
+
__classPrivateFieldGet6(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_validateParams).call(this, params);
|
|
4794
5372
|
const chatCompletion = await client.chat.completions.create({ ...params, stream: false }, { ...options, signal: this.controller.signal });
|
|
4795
5373
|
this._connected();
|
|
4796
5374
|
return this._addChatCompletion(parseChatCompletion(chatCompletion, params));
|
|
@@ -4854,7 +5432,7 @@ class AbstractChatCompletionRunner extends EventStream {
|
|
|
4854
5432
|
continue;
|
|
4855
5433
|
}
|
|
4856
5434
|
const rawContent = await fn.function(parsed, this);
|
|
4857
|
-
const content =
|
|
5435
|
+
const content = __classPrivateFieldGet6(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_stringifyFunctionCallResult).call(this, rawContent);
|
|
4858
5436
|
this._addMessage({ role, name, content });
|
|
4859
5437
|
if (singleFunctionToCall)
|
|
4860
5438
|
return;
|
|
@@ -4940,7 +5518,7 @@ class AbstractChatCompletionRunner extends EventStream {
|
|
|
4940
5518
|
continue;
|
|
4941
5519
|
}
|
|
4942
5520
|
const rawContent = await fn.function(parsed, this);
|
|
4943
|
-
const content =
|
|
5521
|
+
const content = __classPrivateFieldGet6(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_stringifyFunctionCallResult).call(this, rawContent);
|
|
4944
5522
|
this._addMessage({ role, tool_call_id, content });
|
|
4945
5523
|
if (singleFunctionToCall) {
|
|
4946
5524
|
return;
|
|
@@ -4951,7 +5529,7 @@ class AbstractChatCompletionRunner extends EventStream {
|
|
|
4951
5529
|
}
|
|
4952
5530
|
}
|
|
4953
5531
|
_AbstractChatCompletionRunner_instances = new WeakSet, _AbstractChatCompletionRunner_getFinalContent = function _AbstractChatCompletionRunner_getFinalContent2() {
|
|
4954
|
-
return
|
|
5532
|
+
return __classPrivateFieldGet6(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_getFinalMessage).call(this).content ?? null;
|
|
4955
5533
|
}, _AbstractChatCompletionRunner_getFinalMessage = function _AbstractChatCompletionRunner_getFinalMessage2() {
|
|
4956
5534
|
let i = this.messages.length;
|
|
4957
5535
|
while (i-- > 0) {
|
|
@@ -5258,7 +5836,7 @@ var _parseJSON = (jsonString, allow) => {
|
|
|
5258
5836
|
var partialParse2 = (input) => parseJSON(input, Allow.ALL ^ Allow.NUM);
|
|
5259
5837
|
|
|
5260
5838
|
// ../../node_modules/openai/lib/ChatCompletionStream.mjs
|
|
5261
|
-
var
|
|
5839
|
+
var __classPrivateFieldSet6 = function(receiver, state, value, kind3, f) {
|
|
5262
5840
|
if (kind3 === "m")
|
|
5263
5841
|
throw new TypeError("Private method is not writable");
|
|
5264
5842
|
if (kind3 === "a" && !f)
|
|
@@ -5267,7 +5845,7 @@ var __classPrivateFieldSet5 = function(receiver, state, value, kind3, f) {
|
|
|
5267
5845
|
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5268
5846
|
return kind3 === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
5269
5847
|
};
|
|
5270
|
-
var
|
|
5848
|
+
var __classPrivateFieldGet7 = function(receiver, state, kind3, f) {
|
|
5271
5849
|
if (kind3 === "a" && !f)
|
|
5272
5850
|
throw new TypeError("Private accessor was defined without a getter");
|
|
5273
5851
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
@@ -5294,11 +5872,11 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
5294
5872
|
_ChatCompletionStream_params.set(this, undefined);
|
|
5295
5873
|
_ChatCompletionStream_choiceEventStates.set(this, undefined);
|
|
5296
5874
|
_ChatCompletionStream_currentChatCompletionSnapshot.set(this, undefined);
|
|
5297
|
-
|
|
5298
|
-
|
|
5875
|
+
__classPrivateFieldSet6(this, _ChatCompletionStream_params, params, "f");
|
|
5876
|
+
__classPrivateFieldSet6(this, _ChatCompletionStream_choiceEventStates, [], "f");
|
|
5299
5877
|
}
|
|
5300
5878
|
get currentChatCompletionSnapshot() {
|
|
5301
|
-
return
|
|
5879
|
+
return __classPrivateFieldGet7(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f");
|
|
5302
5880
|
}
|
|
5303
5881
|
static fromReadableStream(stream) {
|
|
5304
5882
|
const runner = new ChatCompletionStream(null);
|
|
@@ -5318,16 +5896,16 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
5318
5896
|
this.controller.abort();
|
|
5319
5897
|
signal.addEventListener("abort", () => this.controller.abort());
|
|
5320
5898
|
}
|
|
5321
|
-
|
|
5899
|
+
__classPrivateFieldGet7(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_beginRequest).call(this);
|
|
5322
5900
|
const stream = await client.chat.completions.create({ ...params, stream: true }, { ...options, signal: this.controller.signal });
|
|
5323
5901
|
this._connected();
|
|
5324
5902
|
for await (const chunk of stream) {
|
|
5325
|
-
|
|
5903
|
+
__classPrivateFieldGet7(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_addChunk).call(this, chunk);
|
|
5326
5904
|
}
|
|
5327
5905
|
if (stream.controller.signal?.aborted) {
|
|
5328
5906
|
throw new APIUserAbortError2;
|
|
5329
5907
|
}
|
|
5330
|
-
return this._addChatCompletion(
|
|
5908
|
+
return this._addChatCompletion(__classPrivateFieldGet7(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_endRequest).call(this));
|
|
5331
5909
|
}
|
|
5332
5910
|
async _fromReadableStream(readableStream, options) {
|
|
5333
5911
|
const signal = options?.signal;
|
|
@@ -5336,28 +5914,28 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
5336
5914
|
this.controller.abort();
|
|
5337
5915
|
signal.addEventListener("abort", () => this.controller.abort());
|
|
5338
5916
|
}
|
|
5339
|
-
|
|
5917
|
+
__classPrivateFieldGet7(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_beginRequest).call(this);
|
|
5340
5918
|
this._connected();
|
|
5341
5919
|
const stream = Stream2.fromReadableStream(readableStream, this.controller);
|
|
5342
5920
|
let chatId;
|
|
5343
5921
|
for await (const chunk of stream) {
|
|
5344
5922
|
if (chatId && chatId !== chunk.id) {
|
|
5345
|
-
this._addChatCompletion(
|
|
5923
|
+
this._addChatCompletion(__classPrivateFieldGet7(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_endRequest).call(this));
|
|
5346
5924
|
}
|
|
5347
|
-
|
|
5925
|
+
__classPrivateFieldGet7(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_addChunk).call(this, chunk);
|
|
5348
5926
|
chatId = chunk.id;
|
|
5349
5927
|
}
|
|
5350
5928
|
if (stream.controller.signal?.aborted) {
|
|
5351
5929
|
throw new APIUserAbortError2;
|
|
5352
5930
|
}
|
|
5353
|
-
return this._addChatCompletion(
|
|
5931
|
+
return this._addChatCompletion(__classPrivateFieldGet7(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_endRequest).call(this));
|
|
5354
5932
|
}
|
|
5355
5933
|
[(_ChatCompletionStream_params = new WeakMap, _ChatCompletionStream_choiceEventStates = new WeakMap, _ChatCompletionStream_currentChatCompletionSnapshot = new WeakMap, _ChatCompletionStream_instances = new WeakSet, _ChatCompletionStream_beginRequest = function _ChatCompletionStream_beginRequest() {
|
|
5356
5934
|
if (this.ended)
|
|
5357
5935
|
return;
|
|
5358
|
-
|
|
5936
|
+
__classPrivateFieldSet6(this, _ChatCompletionStream_currentChatCompletionSnapshot, undefined, "f");
|
|
5359
5937
|
}, _ChatCompletionStream_getChoiceEventState = function _ChatCompletionStream_getChoiceEventState(choice) {
|
|
5360
|
-
let state =
|
|
5938
|
+
let state = __classPrivateFieldGet7(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index];
|
|
5361
5939
|
if (state) {
|
|
5362
5940
|
return state;
|
|
5363
5941
|
}
|
|
@@ -5369,12 +5947,12 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
5369
5947
|
done_tool_calls: new Set,
|
|
5370
5948
|
current_tool_call_index: null
|
|
5371
5949
|
};
|
|
5372
|
-
|
|
5950
|
+
__classPrivateFieldGet7(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index] = state;
|
|
5373
5951
|
return state;
|
|
5374
5952
|
}, _ChatCompletionStream_addChunk = function _ChatCompletionStream_addChunk(chunk) {
|
|
5375
5953
|
if (this.ended)
|
|
5376
5954
|
return;
|
|
5377
|
-
const completion =
|
|
5955
|
+
const completion = __classPrivateFieldGet7(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_accumulateChatCompletion).call(this, chunk);
|
|
5378
5956
|
this._emit("chunk", chunk, completion);
|
|
5379
5957
|
for (const choice of chunk.choices) {
|
|
5380
5958
|
const choiceSnapshot = completion.choices[choice.index];
|
|
@@ -5404,18 +5982,18 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
5404
5982
|
snapshot: choiceSnapshot.logprobs?.refusal ?? []
|
|
5405
5983
|
});
|
|
5406
5984
|
}
|
|
5407
|
-
const state =
|
|
5985
|
+
const state = __classPrivateFieldGet7(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot);
|
|
5408
5986
|
if (choiceSnapshot.finish_reason) {
|
|
5409
|
-
|
|
5987
|
+
__classPrivateFieldGet7(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitContentDoneEvents).call(this, choiceSnapshot);
|
|
5410
5988
|
if (state.current_tool_call_index != null) {
|
|
5411
|
-
|
|
5989
|
+
__classPrivateFieldGet7(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitToolCallDoneEvent).call(this, choiceSnapshot, state.current_tool_call_index);
|
|
5412
5990
|
}
|
|
5413
5991
|
}
|
|
5414
5992
|
for (const toolCall of choice.delta.tool_calls ?? []) {
|
|
5415
5993
|
if (state.current_tool_call_index !== toolCall.index) {
|
|
5416
|
-
|
|
5994
|
+
__classPrivateFieldGet7(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitContentDoneEvents).call(this, choiceSnapshot);
|
|
5417
5995
|
if (state.current_tool_call_index != null) {
|
|
5418
|
-
|
|
5996
|
+
__classPrivateFieldGet7(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitToolCallDoneEvent).call(this, choiceSnapshot, state.current_tool_call_index);
|
|
5419
5997
|
}
|
|
5420
5998
|
}
|
|
5421
5999
|
state.current_tool_call_index = toolCall.index;
|
|
@@ -5439,7 +6017,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
5439
6017
|
}
|
|
5440
6018
|
}
|
|
5441
6019
|
}, _ChatCompletionStream_emitToolCallDoneEvent = function _ChatCompletionStream_emitToolCallDoneEvent(choiceSnapshot, toolCallIndex) {
|
|
5442
|
-
const state =
|
|
6020
|
+
const state = __classPrivateFieldGet7(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot);
|
|
5443
6021
|
if (state.done_tool_calls.has(toolCallIndex)) {
|
|
5444
6022
|
return;
|
|
5445
6023
|
}
|
|
@@ -5451,7 +6029,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
5451
6029
|
throw new Error("tool call snapshot missing `type`");
|
|
5452
6030
|
}
|
|
5453
6031
|
if (toolCallSnapshot.type === "function") {
|
|
5454
|
-
const inputTool =
|
|
6032
|
+
const inputTool = __classPrivateFieldGet7(this, _ChatCompletionStream_params, "f")?.tools?.find((tool) => tool.type === "function" && tool.function.name === toolCallSnapshot.function.name);
|
|
5455
6033
|
this._emit("tool_calls.function.arguments.done", {
|
|
5456
6034
|
name: toolCallSnapshot.function.name,
|
|
5457
6035
|
index: toolCallIndex,
|
|
@@ -5462,10 +6040,10 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
5462
6040
|
assertNever(toolCallSnapshot.type);
|
|
5463
6041
|
}
|
|
5464
6042
|
}, _ChatCompletionStream_emitContentDoneEvents = function _ChatCompletionStream_emitContentDoneEvents(choiceSnapshot) {
|
|
5465
|
-
const state =
|
|
6043
|
+
const state = __classPrivateFieldGet7(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot);
|
|
5466
6044
|
if (choiceSnapshot.message.content && !state.content_done) {
|
|
5467
6045
|
state.content_done = true;
|
|
5468
|
-
const responseFormat =
|
|
6046
|
+
const responseFormat = __classPrivateFieldGet7(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getAutoParseableResponseFormat).call(this);
|
|
5469
6047
|
this._emit("content.done", {
|
|
5470
6048
|
content: choiceSnapshot.message.content,
|
|
5471
6049
|
parsed: responseFormat ? responseFormat.$parseRaw(choiceSnapshot.message.content) : null
|
|
@@ -5487,25 +6065,25 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
5487
6065
|
if (this.ended) {
|
|
5488
6066
|
throw new OpenAIError(`stream has ended, this shouldn't happen`);
|
|
5489
6067
|
}
|
|
5490
|
-
const snapshot =
|
|
6068
|
+
const snapshot = __classPrivateFieldGet7(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f");
|
|
5491
6069
|
if (!snapshot) {
|
|
5492
6070
|
throw new OpenAIError(`request ended without sending any chunks`);
|
|
5493
6071
|
}
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
return finalizeChatCompletion(snapshot,
|
|
6072
|
+
__classPrivateFieldSet6(this, _ChatCompletionStream_currentChatCompletionSnapshot, undefined, "f");
|
|
6073
|
+
__classPrivateFieldSet6(this, _ChatCompletionStream_choiceEventStates, [], "f");
|
|
6074
|
+
return finalizeChatCompletion(snapshot, __classPrivateFieldGet7(this, _ChatCompletionStream_params, "f"));
|
|
5497
6075
|
}, _ChatCompletionStream_getAutoParseableResponseFormat = function _ChatCompletionStream_getAutoParseableResponseFormat() {
|
|
5498
|
-
const responseFormat =
|
|
6076
|
+
const responseFormat = __classPrivateFieldGet7(this, _ChatCompletionStream_params, "f")?.response_format;
|
|
5499
6077
|
if (isAutoParsableResponseFormat(responseFormat)) {
|
|
5500
6078
|
return responseFormat;
|
|
5501
6079
|
}
|
|
5502
6080
|
return null;
|
|
5503
6081
|
}, _ChatCompletionStream_accumulateChatCompletion = function _ChatCompletionStream_accumulateChatCompletion(chunk) {
|
|
5504
6082
|
var _a2, _b, _c, _d;
|
|
5505
|
-
let snapshot =
|
|
6083
|
+
let snapshot = __classPrivateFieldGet7(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f");
|
|
5506
6084
|
const { choices, ...rest } = chunk;
|
|
5507
6085
|
if (!snapshot) {
|
|
5508
|
-
snapshot =
|
|
6086
|
+
snapshot = __classPrivateFieldSet6(this, _ChatCompletionStream_currentChatCompletionSnapshot, {
|
|
5509
6087
|
...rest,
|
|
5510
6088
|
choices: []
|
|
5511
6089
|
}, "f");
|
|
@@ -5536,7 +6114,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
5536
6114
|
}
|
|
5537
6115
|
if (finish_reason) {
|
|
5538
6116
|
choice.finish_reason = finish_reason;
|
|
5539
|
-
if (
|
|
6117
|
+
if (__classPrivateFieldGet7(this, _ChatCompletionStream_params, "f") && hasAutoParseableInput(__classPrivateFieldGet7(this, _ChatCompletionStream_params, "f"))) {
|
|
5540
6118
|
if (finish_reason === "length") {
|
|
5541
6119
|
throw new LengthFinishReasonError;
|
|
5542
6120
|
}
|
|
@@ -5570,7 +6148,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
5570
6148
|
}
|
|
5571
6149
|
if (content) {
|
|
5572
6150
|
choice.message.content = (choice.message.content || "") + content;
|
|
5573
|
-
if (!choice.message.refusal &&
|
|
6151
|
+
if (!choice.message.refusal && __classPrivateFieldGet7(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getAutoParseableResponseFormat).call(this)) {
|
|
5574
6152
|
choice.message.parsed = partialParse2(choice.message.content);
|
|
5575
6153
|
}
|
|
5576
6154
|
}
|
|
@@ -5590,7 +6168,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
|
|
|
5590
6168
|
tool_call.function.name = fn.name;
|
|
5591
6169
|
if (fn?.arguments) {
|
|
5592
6170
|
tool_call.function.arguments += fn.arguments;
|
|
5593
|
-
if (shouldParseToolCall(
|
|
6171
|
+
if (shouldParseToolCall(__classPrivateFieldGet7(this, _ChatCompletionStream_params, "f"), tool_call)) {
|
|
5594
6172
|
tool_call.function.parsed_arguments = partialParse2(tool_call.function.arguments);
|
|
5595
6173
|
}
|
|
5596
6174
|
}
|
|
@@ -5835,14 +6413,14 @@ class Realtime extends APIResource2 {
|
|
|
5835
6413
|
Realtime.Sessions = Sessions;
|
|
5836
6414
|
|
|
5837
6415
|
// ../../node_modules/openai/lib/AssistantStream.mjs
|
|
5838
|
-
var
|
|
6416
|
+
var __classPrivateFieldGet8 = function(receiver, state, kind3, f) {
|
|
5839
6417
|
if (kind3 === "a" && !f)
|
|
5840
6418
|
throw new TypeError("Private accessor was defined without a getter");
|
|
5841
6419
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
5842
6420
|
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5843
6421
|
return kind3 === "m" ? f : kind3 === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5844
6422
|
};
|
|
5845
|
-
var
|
|
6423
|
+
var __classPrivateFieldSet7 = function(receiver, state, value, kind3, f) {
|
|
5846
6424
|
if (kind3 === "m")
|
|
5847
6425
|
throw new TypeError("Private method is not writable");
|
|
5848
6426
|
if (kind3 === "a" && !f)
|
|
@@ -5956,12 +6534,12 @@ class AssistantStream extends EventStream {
|
|
|
5956
6534
|
this._connected();
|
|
5957
6535
|
const stream = Stream2.fromReadableStream(readableStream, this.controller);
|
|
5958
6536
|
for await (const event of stream) {
|
|
5959
|
-
|
|
6537
|
+
__classPrivateFieldGet8(this, _AssistantStream_instances, "m", _AssistantStream_addEvent).call(this, event);
|
|
5960
6538
|
}
|
|
5961
6539
|
if (stream.controller.signal?.aborted) {
|
|
5962
6540
|
throw new APIUserAbortError2;
|
|
5963
6541
|
}
|
|
5964
|
-
return this._addRun(
|
|
6542
|
+
return this._addRun(__classPrivateFieldGet8(this, _AssistantStream_instances, "m", _AssistantStream_endRequest).call(this));
|
|
5965
6543
|
}
|
|
5966
6544
|
toReadableStream() {
|
|
5967
6545
|
const stream = new Stream2(this[Symbol.asyncIterator].bind(this), this.controller);
|
|
@@ -5989,12 +6567,12 @@ class AssistantStream extends EventStream {
|
|
|
5989
6567
|
});
|
|
5990
6568
|
this._connected();
|
|
5991
6569
|
for await (const event of stream) {
|
|
5992
|
-
|
|
6570
|
+
__classPrivateFieldGet8(this, _AssistantStream_instances, "m", _AssistantStream_addEvent).call(this, event);
|
|
5993
6571
|
}
|
|
5994
6572
|
if (stream.controller.signal?.aborted) {
|
|
5995
6573
|
throw new APIUserAbortError2;
|
|
5996
6574
|
}
|
|
5997
|
-
return this._addRun(
|
|
6575
|
+
return this._addRun(__classPrivateFieldGet8(this, _AssistantStream_instances, "m", _AssistantStream_endRequest).call(this));
|
|
5998
6576
|
}
|
|
5999
6577
|
static createThreadAssistantStream(params, thread, options) {
|
|
6000
6578
|
const runner = new AssistantStream;
|
|
@@ -6013,30 +6591,30 @@ class AssistantStream extends EventStream {
|
|
|
6013
6591
|
return runner;
|
|
6014
6592
|
}
|
|
6015
6593
|
currentEvent() {
|
|
6016
|
-
return
|
|
6594
|
+
return __classPrivateFieldGet8(this, _AssistantStream_currentEvent, "f");
|
|
6017
6595
|
}
|
|
6018
6596
|
currentRun() {
|
|
6019
|
-
return
|
|
6597
|
+
return __classPrivateFieldGet8(this, _AssistantStream_currentRunSnapshot, "f");
|
|
6020
6598
|
}
|
|
6021
6599
|
currentMessageSnapshot() {
|
|
6022
|
-
return
|
|
6600
|
+
return __classPrivateFieldGet8(this, _AssistantStream_messageSnapshot, "f");
|
|
6023
6601
|
}
|
|
6024
6602
|
currentRunStepSnapshot() {
|
|
6025
|
-
return
|
|
6603
|
+
return __classPrivateFieldGet8(this, _AssistantStream_currentRunStepSnapshot, "f");
|
|
6026
6604
|
}
|
|
6027
6605
|
async finalRunSteps() {
|
|
6028
6606
|
await this.done();
|
|
6029
|
-
return Object.values(
|
|
6607
|
+
return Object.values(__classPrivateFieldGet8(this, _AssistantStream_runStepSnapshots, "f"));
|
|
6030
6608
|
}
|
|
6031
6609
|
async finalMessages() {
|
|
6032
6610
|
await this.done();
|
|
6033
|
-
return Object.values(
|
|
6611
|
+
return Object.values(__classPrivateFieldGet8(this, _AssistantStream_messageSnapshots, "f"));
|
|
6034
6612
|
}
|
|
6035
6613
|
async finalRun() {
|
|
6036
6614
|
await this.done();
|
|
6037
|
-
if (!
|
|
6615
|
+
if (!__classPrivateFieldGet8(this, _AssistantStream_finalRun, "f"))
|
|
6038
6616
|
throw Error("Final run was not received.");
|
|
6039
|
-
return
|
|
6617
|
+
return __classPrivateFieldGet8(this, _AssistantStream_finalRun, "f");
|
|
6040
6618
|
}
|
|
6041
6619
|
async _createThreadAssistantStream(thread, params, options) {
|
|
6042
6620
|
const signal = options?.signal;
|
|
@@ -6049,12 +6627,12 @@ class AssistantStream extends EventStream {
|
|
|
6049
6627
|
const stream = await thread.createAndRun(body, { ...options, signal: this.controller.signal });
|
|
6050
6628
|
this._connected();
|
|
6051
6629
|
for await (const event of stream) {
|
|
6052
|
-
|
|
6630
|
+
__classPrivateFieldGet8(this, _AssistantStream_instances, "m", _AssistantStream_addEvent).call(this, event);
|
|
6053
6631
|
}
|
|
6054
6632
|
if (stream.controller.signal?.aborted) {
|
|
6055
6633
|
throw new APIUserAbortError2;
|
|
6056
6634
|
}
|
|
6057
|
-
return this._addRun(
|
|
6635
|
+
return this._addRun(__classPrivateFieldGet8(this, _AssistantStream_instances, "m", _AssistantStream_endRequest).call(this));
|
|
6058
6636
|
}
|
|
6059
6637
|
async _createAssistantStream(run, threadId, params, options) {
|
|
6060
6638
|
const signal = options?.signal;
|
|
@@ -6067,12 +6645,12 @@ class AssistantStream extends EventStream {
|
|
|
6067
6645
|
const stream = await run.create(threadId, body, { ...options, signal: this.controller.signal });
|
|
6068
6646
|
this._connected();
|
|
6069
6647
|
for await (const event of stream) {
|
|
6070
|
-
|
|
6648
|
+
__classPrivateFieldGet8(this, _AssistantStream_instances, "m", _AssistantStream_addEvent).call(this, event);
|
|
6071
6649
|
}
|
|
6072
6650
|
if (stream.controller.signal?.aborted) {
|
|
6073
6651
|
throw new APIUserAbortError2;
|
|
6074
6652
|
}
|
|
6075
|
-
return this._addRun(
|
|
6653
|
+
return this._addRun(__classPrivateFieldGet8(this, _AssistantStream_instances, "m", _AssistantStream_endRequest).call(this));
|
|
6076
6654
|
}
|
|
6077
6655
|
static accumulateDelta(acc, delta) {
|
|
6078
6656
|
for (const [key, deltaValue] of Object.entries(delta)) {
|
|
@@ -6143,8 +6721,8 @@ class AssistantStream extends EventStream {
|
|
|
6143
6721
|
_AssistantStream_addEvent = function _AssistantStream_addEvent2(event) {
|
|
6144
6722
|
if (this.ended)
|
|
6145
6723
|
return;
|
|
6146
|
-
|
|
6147
|
-
|
|
6724
|
+
__classPrivateFieldSet7(this, _AssistantStream_currentEvent, event, "f");
|
|
6725
|
+
__classPrivateFieldGet8(this, _AssistantStream_instances, "m", _AssistantStream_handleEvent).call(this, event);
|
|
6148
6726
|
switch (event.event) {
|
|
6149
6727
|
case "thread.created":
|
|
6150
6728
|
break;
|
|
@@ -6157,7 +6735,7 @@ _AssistantStream_addEvent = function _AssistantStream_addEvent2(event) {
|
|
|
6157
6735
|
case "thread.run.cancelling":
|
|
6158
6736
|
case "thread.run.cancelled":
|
|
6159
6737
|
case "thread.run.expired":
|
|
6160
|
-
|
|
6738
|
+
__classPrivateFieldGet8(this, _AssistantStream_instances, "m", _AssistantStream_handleRun).call(this, event);
|
|
6161
6739
|
break;
|
|
6162
6740
|
case "thread.run.step.created":
|
|
6163
6741
|
case "thread.run.step.in_progress":
|
|
@@ -6166,14 +6744,14 @@ _AssistantStream_addEvent = function _AssistantStream_addEvent2(event) {
|
|
|
6166
6744
|
case "thread.run.step.failed":
|
|
6167
6745
|
case "thread.run.step.cancelled":
|
|
6168
6746
|
case "thread.run.step.expired":
|
|
6169
|
-
|
|
6747
|
+
__classPrivateFieldGet8(this, _AssistantStream_instances, "m", _AssistantStream_handleRunStep).call(this, event);
|
|
6170
6748
|
break;
|
|
6171
6749
|
case "thread.message.created":
|
|
6172
6750
|
case "thread.message.in_progress":
|
|
6173
6751
|
case "thread.message.delta":
|
|
6174
6752
|
case "thread.message.completed":
|
|
6175
6753
|
case "thread.message.incomplete":
|
|
6176
|
-
|
|
6754
|
+
__classPrivateFieldGet8(this, _AssistantStream_instances, "m", _AssistantStream_handleMessage).call(this, event);
|
|
6177
6755
|
break;
|
|
6178
6756
|
case "error":
|
|
6179
6757
|
throw new Error("Encountered an error event in event processing - errors should be processed earlier");
|
|
@@ -6182,13 +6760,13 @@ _AssistantStream_addEvent = function _AssistantStream_addEvent2(event) {
|
|
|
6182
6760
|
if (this.ended) {
|
|
6183
6761
|
throw new OpenAIError(`stream has ended, this shouldn't happen`);
|
|
6184
6762
|
}
|
|
6185
|
-
if (!
|
|
6763
|
+
if (!__classPrivateFieldGet8(this, _AssistantStream_finalRun, "f"))
|
|
6186
6764
|
throw Error("Final run has not been received");
|
|
6187
|
-
return
|
|
6765
|
+
return __classPrivateFieldGet8(this, _AssistantStream_finalRun, "f");
|
|
6188
6766
|
}, _AssistantStream_handleMessage = function _AssistantStream_handleMessage2(event) {
|
|
6189
|
-
const [accumulatedMessage, newContent] =
|
|
6190
|
-
|
|
6191
|
-
|
|
6767
|
+
const [accumulatedMessage, newContent] = __classPrivateFieldGet8(this, _AssistantStream_instances, "m", _AssistantStream_accumulateMessage).call(this, event, __classPrivateFieldGet8(this, _AssistantStream_messageSnapshot, "f"));
|
|
6768
|
+
__classPrivateFieldSet7(this, _AssistantStream_messageSnapshot, accumulatedMessage, "f");
|
|
6769
|
+
__classPrivateFieldGet8(this, _AssistantStream_messageSnapshots, "f")[accumulatedMessage.id] = accumulatedMessage;
|
|
6192
6770
|
for (const content of newContent) {
|
|
6193
6771
|
const snapshotContent = accumulatedMessage.content[content.index];
|
|
6194
6772
|
if (snapshotContent?.type == "text") {
|
|
@@ -6214,46 +6792,46 @@ _AssistantStream_addEvent = function _AssistantStream_addEvent2(event) {
|
|
|
6214
6792
|
throw Error("The snapshot associated with this text delta is not text or missing");
|
|
6215
6793
|
}
|
|
6216
6794
|
}
|
|
6217
|
-
if (content.index !=
|
|
6218
|
-
if (
|
|
6219
|
-
switch (
|
|
6795
|
+
if (content.index != __classPrivateFieldGet8(this, _AssistantStream_currentContentIndex, "f")) {
|
|
6796
|
+
if (__classPrivateFieldGet8(this, _AssistantStream_currentContent, "f")) {
|
|
6797
|
+
switch (__classPrivateFieldGet8(this, _AssistantStream_currentContent, "f").type) {
|
|
6220
6798
|
case "text":
|
|
6221
|
-
this._emit("textDone",
|
|
6799
|
+
this._emit("textDone", __classPrivateFieldGet8(this, _AssistantStream_currentContent, "f").text, __classPrivateFieldGet8(this, _AssistantStream_messageSnapshot, "f"));
|
|
6222
6800
|
break;
|
|
6223
6801
|
case "image_file":
|
|
6224
|
-
this._emit("imageFileDone",
|
|
6802
|
+
this._emit("imageFileDone", __classPrivateFieldGet8(this, _AssistantStream_currentContent, "f").image_file, __classPrivateFieldGet8(this, _AssistantStream_messageSnapshot, "f"));
|
|
6225
6803
|
break;
|
|
6226
6804
|
}
|
|
6227
6805
|
}
|
|
6228
|
-
|
|
6806
|
+
__classPrivateFieldSet7(this, _AssistantStream_currentContentIndex, content.index, "f");
|
|
6229
6807
|
}
|
|
6230
|
-
|
|
6808
|
+
__classPrivateFieldSet7(this, _AssistantStream_currentContent, accumulatedMessage.content[content.index], "f");
|
|
6231
6809
|
}
|
|
6232
6810
|
}
|
|
6233
6811
|
break;
|
|
6234
6812
|
case "thread.message.completed":
|
|
6235
6813
|
case "thread.message.incomplete":
|
|
6236
|
-
if (
|
|
6237
|
-
const currentContent = event.data.content[
|
|
6814
|
+
if (__classPrivateFieldGet8(this, _AssistantStream_currentContentIndex, "f") !== undefined) {
|
|
6815
|
+
const currentContent = event.data.content[__classPrivateFieldGet8(this, _AssistantStream_currentContentIndex, "f")];
|
|
6238
6816
|
if (currentContent) {
|
|
6239
6817
|
switch (currentContent.type) {
|
|
6240
6818
|
case "image_file":
|
|
6241
|
-
this._emit("imageFileDone", currentContent.image_file,
|
|
6819
|
+
this._emit("imageFileDone", currentContent.image_file, __classPrivateFieldGet8(this, _AssistantStream_messageSnapshot, "f"));
|
|
6242
6820
|
break;
|
|
6243
6821
|
case "text":
|
|
6244
|
-
this._emit("textDone", currentContent.text,
|
|
6822
|
+
this._emit("textDone", currentContent.text, __classPrivateFieldGet8(this, _AssistantStream_messageSnapshot, "f"));
|
|
6245
6823
|
break;
|
|
6246
6824
|
}
|
|
6247
6825
|
}
|
|
6248
6826
|
}
|
|
6249
|
-
if (
|
|
6827
|
+
if (__classPrivateFieldGet8(this, _AssistantStream_messageSnapshot, "f")) {
|
|
6250
6828
|
this._emit("messageDone", event.data);
|
|
6251
6829
|
}
|
|
6252
|
-
|
|
6830
|
+
__classPrivateFieldSet7(this, _AssistantStream_messageSnapshot, undefined, "f");
|
|
6253
6831
|
}
|
|
6254
6832
|
}, _AssistantStream_handleRunStep = function _AssistantStream_handleRunStep2(event) {
|
|
6255
|
-
const accumulatedRunStep =
|
|
6256
|
-
|
|
6833
|
+
const accumulatedRunStep = __classPrivateFieldGet8(this, _AssistantStream_instances, "m", _AssistantStream_accumulateRunStep).call(this, event);
|
|
6834
|
+
__classPrivateFieldSet7(this, _AssistantStream_currentRunStepSnapshot, accumulatedRunStep, "f");
|
|
6257
6835
|
switch (event.event) {
|
|
6258
6836
|
case "thread.run.step.created":
|
|
6259
6837
|
this._emit("runStepCreated", event.data);
|
|
@@ -6262,16 +6840,16 @@ _AssistantStream_addEvent = function _AssistantStream_addEvent2(event) {
|
|
|
6262
6840
|
const delta = event.data.delta;
|
|
6263
6841
|
if (delta.step_details && delta.step_details.type == "tool_calls" && delta.step_details.tool_calls && accumulatedRunStep.step_details.type == "tool_calls") {
|
|
6264
6842
|
for (const toolCall of delta.step_details.tool_calls) {
|
|
6265
|
-
if (toolCall.index ==
|
|
6843
|
+
if (toolCall.index == __classPrivateFieldGet8(this, _AssistantStream_currentToolCallIndex, "f")) {
|
|
6266
6844
|
this._emit("toolCallDelta", toolCall, accumulatedRunStep.step_details.tool_calls[toolCall.index]);
|
|
6267
6845
|
} else {
|
|
6268
|
-
if (
|
|
6269
|
-
this._emit("toolCallDone",
|
|
6846
|
+
if (__classPrivateFieldGet8(this, _AssistantStream_currentToolCall, "f")) {
|
|
6847
|
+
this._emit("toolCallDone", __classPrivateFieldGet8(this, _AssistantStream_currentToolCall, "f"));
|
|
6270
6848
|
}
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
if (
|
|
6274
|
-
this._emit("toolCallCreated",
|
|
6849
|
+
__classPrivateFieldSet7(this, _AssistantStream_currentToolCallIndex, toolCall.index, "f");
|
|
6850
|
+
__classPrivateFieldSet7(this, _AssistantStream_currentToolCall, accumulatedRunStep.step_details.tool_calls[toolCall.index], "f");
|
|
6851
|
+
if (__classPrivateFieldGet8(this, _AssistantStream_currentToolCall, "f"))
|
|
6852
|
+
this._emit("toolCallCreated", __classPrivateFieldGet8(this, _AssistantStream_currentToolCall, "f"));
|
|
6275
6853
|
}
|
|
6276
6854
|
}
|
|
6277
6855
|
}
|
|
@@ -6281,12 +6859,12 @@ _AssistantStream_addEvent = function _AssistantStream_addEvent2(event) {
|
|
|
6281
6859
|
case "thread.run.step.failed":
|
|
6282
6860
|
case "thread.run.step.cancelled":
|
|
6283
6861
|
case "thread.run.step.expired":
|
|
6284
|
-
|
|
6862
|
+
__classPrivateFieldSet7(this, _AssistantStream_currentRunStepSnapshot, undefined, "f");
|
|
6285
6863
|
const details = event.data.step_details;
|
|
6286
6864
|
if (details.type == "tool_calls") {
|
|
6287
|
-
if (
|
|
6288
|
-
this._emit("toolCallDone",
|
|
6289
|
-
|
|
6865
|
+
if (__classPrivateFieldGet8(this, _AssistantStream_currentToolCall, "f")) {
|
|
6866
|
+
this._emit("toolCallDone", __classPrivateFieldGet8(this, _AssistantStream_currentToolCall, "f"));
|
|
6867
|
+
__classPrivateFieldSet7(this, _AssistantStream_currentToolCall, undefined, "f");
|
|
6290
6868
|
}
|
|
6291
6869
|
}
|
|
6292
6870
|
this._emit("runStepDone", event.data, accumulatedRunStep);
|
|
@@ -6295,34 +6873,34 @@ _AssistantStream_addEvent = function _AssistantStream_addEvent2(event) {
|
|
|
6295
6873
|
break;
|
|
6296
6874
|
}
|
|
6297
6875
|
}, _AssistantStream_handleEvent = function _AssistantStream_handleEvent2(event) {
|
|
6298
|
-
|
|
6876
|
+
__classPrivateFieldGet8(this, _AssistantStream_events, "f").push(event);
|
|
6299
6877
|
this._emit("event", event);
|
|
6300
6878
|
}, _AssistantStream_accumulateRunStep = function _AssistantStream_accumulateRunStep2(event) {
|
|
6301
6879
|
switch (event.event) {
|
|
6302
6880
|
case "thread.run.step.created":
|
|
6303
|
-
|
|
6881
|
+
__classPrivateFieldGet8(this, _AssistantStream_runStepSnapshots, "f")[event.data.id] = event.data;
|
|
6304
6882
|
return event.data;
|
|
6305
6883
|
case "thread.run.step.delta":
|
|
6306
|
-
let snapshot =
|
|
6884
|
+
let snapshot = __classPrivateFieldGet8(this, _AssistantStream_runStepSnapshots, "f")[event.data.id];
|
|
6307
6885
|
if (!snapshot) {
|
|
6308
6886
|
throw Error("Received a RunStepDelta before creation of a snapshot");
|
|
6309
6887
|
}
|
|
6310
6888
|
let data = event.data;
|
|
6311
6889
|
if (data.delta) {
|
|
6312
6890
|
const accumulated = AssistantStream.accumulateDelta(snapshot, data.delta);
|
|
6313
|
-
|
|
6891
|
+
__classPrivateFieldGet8(this, _AssistantStream_runStepSnapshots, "f")[event.data.id] = accumulated;
|
|
6314
6892
|
}
|
|
6315
|
-
return
|
|
6893
|
+
return __classPrivateFieldGet8(this, _AssistantStream_runStepSnapshots, "f")[event.data.id];
|
|
6316
6894
|
case "thread.run.step.completed":
|
|
6317
6895
|
case "thread.run.step.failed":
|
|
6318
6896
|
case "thread.run.step.cancelled":
|
|
6319
6897
|
case "thread.run.step.expired":
|
|
6320
6898
|
case "thread.run.step.in_progress":
|
|
6321
|
-
|
|
6899
|
+
__classPrivateFieldGet8(this, _AssistantStream_runStepSnapshots, "f")[event.data.id] = event.data;
|
|
6322
6900
|
break;
|
|
6323
6901
|
}
|
|
6324
|
-
if (
|
|
6325
|
-
return
|
|
6902
|
+
if (__classPrivateFieldGet8(this, _AssistantStream_runStepSnapshots, "f")[event.data.id])
|
|
6903
|
+
return __classPrivateFieldGet8(this, _AssistantStream_runStepSnapshots, "f")[event.data.id];
|
|
6326
6904
|
throw new Error("No snapshot available");
|
|
6327
6905
|
}, _AssistantStream_accumulateMessage = function _AssistantStream_accumulateMessage2(event, snapshot) {
|
|
6328
6906
|
let newContent = [];
|
|
@@ -6338,7 +6916,7 @@ _AssistantStream_addEvent = function _AssistantStream_addEvent2(event) {
|
|
|
6338
6916
|
for (const contentElement of data.delta.content) {
|
|
6339
6917
|
if (contentElement.index in snapshot.content) {
|
|
6340
6918
|
let currentContent = snapshot.content[contentElement.index];
|
|
6341
|
-
snapshot.content[contentElement.index] =
|
|
6919
|
+
snapshot.content[contentElement.index] = __classPrivateFieldGet8(this, _AssistantStream_instances, "m", _AssistantStream_accumulateContent).call(this, contentElement, currentContent);
|
|
6342
6920
|
} else {
|
|
6343
6921
|
snapshot.content[contentElement.index] = contentElement;
|
|
6344
6922
|
newContent.push(contentElement);
|
|
@@ -6359,7 +6937,7 @@ _AssistantStream_addEvent = function _AssistantStream_addEvent2(event) {
|
|
|
6359
6937
|
}, _AssistantStream_accumulateContent = function _AssistantStream_accumulateContent2(contentElement, currentContent) {
|
|
6360
6938
|
return AssistantStream.accumulateDelta(currentContent, contentElement);
|
|
6361
6939
|
}, _AssistantStream_handleRun = function _AssistantStream_handleRun2(event) {
|
|
6362
|
-
|
|
6940
|
+
__classPrivateFieldSet7(this, _AssistantStream_currentRunSnapshot, event.data, "f");
|
|
6363
6941
|
switch (event.event) {
|
|
6364
6942
|
case "thread.run.created":
|
|
6365
6943
|
break;
|
|
@@ -6372,10 +6950,10 @@ _AssistantStream_addEvent = function _AssistantStream_addEvent2(event) {
|
|
|
6372
6950
|
case "thread.run.failed":
|
|
6373
6951
|
case "thread.run.completed":
|
|
6374
6952
|
case "thread.run.expired":
|
|
6375
|
-
|
|
6376
|
-
if (
|
|
6377
|
-
this._emit("toolCallDone",
|
|
6378
|
-
|
|
6953
|
+
__classPrivateFieldSet7(this, _AssistantStream_finalRun, event.data, "f");
|
|
6954
|
+
if (__classPrivateFieldGet8(this, _AssistantStream_currentToolCall, "f")) {
|
|
6955
|
+
this._emit("toolCallDone", __classPrivateFieldGet8(this, _AssistantStream_currentToolCall, "f"));
|
|
6956
|
+
__classPrivateFieldSet7(this, _AssistantStream_currentToolCall, undefined, "f");
|
|
6379
6957
|
}
|
|
6380
6958
|
break;
|
|
6381
6959
|
case "thread.run.cancelling":
|
|
@@ -7285,7 +7863,7 @@ class DeepSeekService extends AiServiceBase {
|
|
|
7285
7863
|
baseURL: "https://api.deepseek.com/v1",
|
|
7286
7864
|
apiKey: options.apiKey
|
|
7287
7865
|
});
|
|
7288
|
-
const id = options.
|
|
7866
|
+
const id = options.model || deepSeekDefaultModelId;
|
|
7289
7867
|
this.model = {
|
|
7290
7868
|
id,
|
|
7291
7869
|
info: deepSeekModels[id] ?? deepSeekModels[deepSeekDefaultModelId]
|
|
@@ -7336,7 +7914,7 @@ class OllamaService extends AiServiceBase {
|
|
|
7336
7914
|
apiKey: "ollama"
|
|
7337
7915
|
});
|
|
7338
7916
|
this.model = {
|
|
7339
|
-
id: options.
|
|
7917
|
+
id: options.model || "maryasov/qwen2.5-coder-cline:7b",
|
|
7340
7918
|
info: openAiModelInfoSaneDefaults
|
|
7341
7919
|
};
|
|
7342
7920
|
}
|
|
@@ -7396,11 +7974,14 @@ function parseAssistantMessage(assistantMessage, tools, toolNamePrefix) {
|
|
|
7396
7974
|
const results = [];
|
|
7397
7975
|
const toolTags = tools.map((tool) => `${toolNamePrefix}${tool.name}`);
|
|
7398
7976
|
const toolPattern = toolTags.join("|");
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
|
|
7403
|
-
|
|
7977
|
+
let remainingMessage = assistantMessage;
|
|
7978
|
+
let match;
|
|
7979
|
+
const tagRegex = new RegExp(`<(${toolPattern})>([\\s\\S]*?)<\\/\\1>`, "s");
|
|
7980
|
+
while (true) {
|
|
7981
|
+
match = tagRegex.exec(remainingMessage);
|
|
7982
|
+
if (match === null)
|
|
7983
|
+
break;
|
|
7984
|
+
const beforeTag = remainingMessage.slice(0, match.index).trim();
|
|
7404
7985
|
if (beforeTag) {
|
|
7405
7986
|
results.push({
|
|
7406
7987
|
type: "text",
|
|
@@ -7410,6 +7991,7 @@ function parseAssistantMessage(assistantMessage, tools, toolNamePrefix) {
|
|
|
7410
7991
|
const tagName = match[1];
|
|
7411
7992
|
const toolName = tagName.replace(toolNamePrefix, "");
|
|
7412
7993
|
const tool = tools.find((t) => t.name === toolName);
|
|
7994
|
+
const fullTagContent = match[0];
|
|
7413
7995
|
if (tool) {
|
|
7414
7996
|
const params = {};
|
|
7415
7997
|
for (const param of tool.parameters) {
|
|
@@ -7432,14 +8014,15 @@ function parseAssistantMessage(assistantMessage, tools, toolNamePrefix) {
|
|
|
7432
8014
|
content: fullTagContent
|
|
7433
8015
|
});
|
|
7434
8016
|
}
|
|
7435
|
-
|
|
7436
|
-
|
|
7437
|
-
|
|
7438
|
-
|
|
7439
|
-
|
|
7440
|
-
|
|
7441
|
-
}
|
|
7442
|
-
}
|
|
8017
|
+
remainingMessage = remainingMessage.slice(match.index + fullTagContent.length);
|
|
8018
|
+
}
|
|
8019
|
+
if (remainingMessage.trim()) {
|
|
8020
|
+
results.push({
|
|
8021
|
+
type: "text",
|
|
8022
|
+
content: remainingMessage.trim()
|
|
8023
|
+
});
|
|
8024
|
+
}
|
|
8025
|
+
if (results.length === 0) {
|
|
7443
8026
|
results.push({
|
|
7444
8027
|
type: "text",
|
|
7445
8028
|
content: assistantMessage
|
|
@@ -7622,8 +8205,8 @@ class AgentBase {
|
|
|
7622
8205
|
for await (const chunk of stream) {
|
|
7623
8206
|
switch (chunk.type) {
|
|
7624
8207
|
case "usage":
|
|
7625
|
-
info.inputTokens = chunk.inputTokens;
|
|
7626
|
-
info.outputTokens = chunk.outputTokens;
|
|
8208
|
+
info.inputTokens = chunk.inputTokens ?? 0;
|
|
8209
|
+
info.outputTokens = chunk.outputTokens ?? 0;
|
|
7627
8210
|
info.cacheWriteTokens = chunk.cacheWriteTokens ?? 0;
|
|
7628
8211
|
info.cacheReadTokens = chunk.cacheReadTokens ?? 0;
|
|
7629
8212
|
info.totalCost = chunk.totalCost;
|
|
@@ -8190,7 +8773,12 @@ var handler6 = async (provider, args) => {
|
|
|
8190
8773
|
const resp = [];
|
|
8191
8774
|
for (const path of paths) {
|
|
8192
8775
|
const fileContent = await provider.readFile(path);
|
|
8193
|
-
|
|
8776
|
+
const isEmpty = fileContent.trim().length === 0;
|
|
8777
|
+
if (isEmpty) {
|
|
8778
|
+
resp.push(`<read_file_file_content path="${path}" is_empty="true" />`);
|
|
8779
|
+
} else {
|
|
8780
|
+
resp.push(`<read_file_file_conten path="${path}">${fileContent}</read_file_file_content>`);
|
|
8781
|
+
}
|
|
8194
8782
|
}
|
|
8195
8783
|
return {
|
|
8196
8784
|
type: "Reply" /* Reply */,
|
|
@@ -8590,7 +9178,7 @@ The following additional instructions are provided by the user, and should be fo
|
|
|
8590
9178
|
|
|
8591
9179
|
${joined}`;
|
|
8592
9180
|
};
|
|
8593
|
-
var
|
|
9181
|
+
var customScripts = (commands) => {
|
|
8594
9182
|
const joined = Object.entries(commands).map(([name, command]) => {
|
|
8595
9183
|
if (typeof command === "string") {
|
|
8596
9184
|
return `- ${name}
|
|
@@ -8631,7 +9219,7 @@ NON-INTERACTIVE MODE
|
|
|
8631
9219
|
You are in non-interactive mode. This means you will not be able to ask user questions to gather additional information to complete the task. You should try to use available tools to accomplish the task. If unable to precede further, you may try to end the task and provide a reason.
|
|
8632
9220
|
`;
|
|
8633
9221
|
};
|
|
8634
|
-
var fullSystemPrompt = (info, tools, toolNamePrefix, instructions,
|
|
9222
|
+
var fullSystemPrompt = (info, tools, toolNamePrefix, instructions, scripts, interactive) => `
|
|
8635
9223
|
${basePrompt}
|
|
8636
9224
|
${toolUsePrompt(tools, toolNamePrefix)}
|
|
8637
9225
|
${editingFilesPrompt(toolNamePrefix)}
|
|
@@ -8640,7 +9228,7 @@ ${rules(toolNamePrefix)}
|
|
|
8640
9228
|
${objectives(toolNamePrefix)}
|
|
8641
9229
|
${systemInformation(info)}
|
|
8642
9230
|
${customInstructions(instructions)}
|
|
8643
|
-
${
|
|
9231
|
+
${customScripts(scripts)}
|
|
8644
9232
|
${interactiveMode(interactive)}
|
|
8645
9233
|
`;
|
|
8646
9234
|
|
|
@@ -8652,7 +9240,7 @@ class CoderAgent extends AgentBase {
|
|
|
8652
9240
|
const toolNamePrefix = "tool_";
|
|
8653
9241
|
const systemPrompt = fullSystemPrompt({
|
|
8654
9242
|
os: options.os
|
|
8655
|
-
}, tools, toolNamePrefix, options.customInstructions ?? [], options.
|
|
9243
|
+
}, tools, toolNamePrefix, options.customInstructions ?? [], options.scripts ?? {}, options.interactive);
|
|
8656
9244
|
super(options.ai, {
|
|
8657
9245
|
systemPrompt,
|
|
8658
9246
|
tools,
|
|
@@ -8662,14 +9250,184 @@ class CoderAgent extends AgentBase {
|
|
|
8662
9250
|
});
|
|
8663
9251
|
}
|
|
8664
9252
|
}
|
|
9253
|
+
// src/AiTool/generateGitCommitMessage.ts
|
|
9254
|
+
var prompt = `
|
|
9255
|
+
You are an advanced assistant specialized in creating concise and accurate Git commit messages. When you receive:
|
|
9256
|
+
- A Git diff inside the <tool_input> tag.
|
|
9257
|
+
- Additional user-supplied context inside the <tool_input_context> tag (if any).
|
|
9258
|
+
|
|
9259
|
+
You will produce a single commit message enclosed within <tool_output> tags. The commit message must accurately reflect the changes shown in the diff and should be clear, descriptive, and devoid of unnecessary or repeated information. If a context is provided, it MUST be incorporated into the commit message.
|
|
9260
|
+
|
|
9261
|
+
Here’s an example of the input and the expected output format:
|
|
9262
|
+
|
|
9263
|
+
\`\`\`
|
|
9264
|
+
<tool_input>
|
|
9265
|
+
--- a/example_file.py
|
|
9266
|
+
+++ b/example_file.py
|
|
9267
|
+
@@ -10,7 +10,7 @@ def example_function():
|
|
9268
|
+
- print("Old behavior")
|
|
9269
|
+
+ print("New behavior")
|
|
9270
|
+
</tool_input>
|
|
9271
|
+
<tool_input_context>
|
|
9272
|
+
Changing print statement to update the user-facing message.
|
|
9273
|
+
</tool_input_context>
|
|
9274
|
+
\`\`\`
|
|
9275
|
+
|
|
9276
|
+
Example Output:
|
|
9277
|
+
|
|
9278
|
+
\`\`\`
|
|
9279
|
+
<tool_output>
|
|
9280
|
+
Update print statement for revised user-facing message
|
|
9281
|
+
</tool_output>
|
|
9282
|
+
\`\`\`
|
|
9283
|
+
|
|
9284
|
+
Follow the same structure for any new input. Never repeat questions; focus on generating a concise commit message that captures the essence of the changes.
|
|
9285
|
+
`;
|
|
9286
|
+
var generateGitCommitMessage_default = {
|
|
9287
|
+
name: "generateGitCommitMessage",
|
|
9288
|
+
description: "Generates git commit messages from git diff output",
|
|
9289
|
+
prompt,
|
|
9290
|
+
formatInput: (params) => {
|
|
9291
|
+
let ret = `<tool_input>
|
|
9292
|
+
${params.diff}
|
|
9293
|
+
</tool_input>`;
|
|
9294
|
+
if (params.context) {
|
|
9295
|
+
ret += `
|
|
9296
|
+
<tool_input_context>
|
|
9297
|
+
${params.context}
|
|
9298
|
+
</tool_input_context>`;
|
|
9299
|
+
}
|
|
9300
|
+
return ret;
|
|
9301
|
+
},
|
|
9302
|
+
parseOutput: (output) => {
|
|
9303
|
+
const regex = /<tool_output>([\s\S]*)<\/tool_output>/gm;
|
|
9304
|
+
const match = regex.exec(output);
|
|
9305
|
+
if (match) {
|
|
9306
|
+
return match[1];
|
|
9307
|
+
}
|
|
9308
|
+
throw new Error(`Could not parse output:
|
|
9309
|
+
${output}`);
|
|
9310
|
+
}
|
|
9311
|
+
};
|
|
9312
|
+
|
|
9313
|
+
// src/AiTool/generateGithubPullRequestDetails.ts
|
|
9314
|
+
var prompt2 = `
|
|
9315
|
+
You are given:
|
|
9316
|
+
- A branch name in <tool_input_branch_name>.
|
|
9317
|
+
- An optional context message in <tool_input_context> (which may or may not be present).
|
|
9318
|
+
- All commit messages combined in <tool_input_commit_messages>.
|
|
9319
|
+
- All diffs combined in <tool_input_commit_diff>.
|
|
9320
|
+
|
|
9321
|
+
Your task:
|
|
9322
|
+
1. Consider the optional context (if provided).
|
|
9323
|
+
2. Analyze the combined commit messages and diffs.
|
|
9324
|
+
3. Produce a single GitHub Pull Request title.
|
|
9325
|
+
4. Produce a Pull Request description that explains the changes.
|
|
9326
|
+
|
|
9327
|
+
Output format:
|
|
9328
|
+
<tool_output>
|
|
9329
|
+
<tool_output_pr_title>YOUR PR TITLE HERE</tool_output_pr_title>
|
|
9330
|
+
<tool_output_pr_description>YOUR PR DESCRIPTION HERE</tool_output_pr_description>
|
|
9331
|
+
</tool_output>
|
|
9332
|
+
|
|
9333
|
+
Below is an **example** of the input and output:
|
|
9334
|
+
|
|
9335
|
+
Example Input:
|
|
9336
|
+
<tool_input>
|
|
9337
|
+
<tool_input_branch_name>feature/refactor-logging</tool_input_branch_name>
|
|
9338
|
+
<tool_input_context>Focus on clean code and maintainability</tool_input_context>
|
|
9339
|
+
<tool_input_commit_messages>
|
|
9340
|
+
Remove debug logs
|
|
9341
|
+
Refactor order validation logic
|
|
9342
|
+
</tool_input_commit_messages>
|
|
9343
|
+
<tool_input_commit_diff>
|
|
9344
|
+
diff --git a/user_service.py b/user_service.py
|
|
9345
|
+
- print("Debug info")
|
|
9346
|
+
+ # Removed debug print statements
|
|
9347
|
+
|
|
9348
|
+
diff --git a/order_service.py b/order_service.py
|
|
9349
|
+
- if is_valid_order(order):
|
|
9350
|
+
- process_order(order)
|
|
9351
|
+
+ validate_and_process(order)
|
|
9352
|
+
</tool_input_commit_diff>
|
|
9353
|
+
</tool_input>
|
|
9354
|
+
|
|
9355
|
+
Example Output:
|
|
9356
|
+
<tool_output>
|
|
9357
|
+
<tool_output_pr_title>Refactor Order Validation and Remove Debug Logs</tool_output_pr_title>
|
|
9358
|
+
<tool_output_pr_description>
|
|
9359
|
+
This PR removes unnecessary debug print statements and updates order validation
|
|
9360
|
+
to use the new validate_and_process method for improved maintainability.
|
|
9361
|
+
</tool_output_pr_description>
|
|
9362
|
+
</tool_output>
|
|
9363
|
+
|
|
9364
|
+
---
|
|
9365
|
+
|
|
9366
|
+
Use the above format whenever you receive \`<tool_input>\` that may include a branch name, an optional context, aggregated commit messages in a single tag, and a combined diff in a single tag. Provide your final output strictly in \`<tool_output>\` with \`<tool_output_pr_title>\` and \`<tool_output_pr_description>\`.
|
|
9367
|
+
Only highlight the changed code and avoid including the context around the changes in the description.
|
|
9368
|
+
`;
|
|
9369
|
+
var generateGithubPullRequestDetails_default = {
|
|
9370
|
+
name: "generateGithubPullRequestDetails",
|
|
9371
|
+
description: "Generates a GitHub pull request title and description from git commits",
|
|
9372
|
+
prompt: prompt2,
|
|
9373
|
+
formatInput: (params) => {
|
|
9374
|
+
return `<tool_input>
|
|
9375
|
+
<tool_input_branch_name>${params.branchName}</tool_input_branch_name>${params.context ? `
|
|
9376
|
+
<tool_input_context>${params.context}</tool_input_context>` : ""}
|
|
9377
|
+
<tool_input_commit_messages>${params.commitMessages}</tool_input_commit_messages>
|
|
9378
|
+
<tool_input_commit_diff>${params.commitDiff}</tool_input_commit_diff>
|
|
9379
|
+
</tool_input>`;
|
|
9380
|
+
},
|
|
9381
|
+
parseOutput: (output) => {
|
|
9382
|
+
const regex = /<tool_output>([\s\S]*)<\/tool_output>/gm;
|
|
9383
|
+
const match = regex.exec(output);
|
|
9384
|
+
if (!match) {
|
|
9385
|
+
throw new Error(`Could not parse output:
|
|
9386
|
+
${output}`);
|
|
9387
|
+
}
|
|
9388
|
+
const [, outputContent] = match;
|
|
9389
|
+
const titleRegex = /<tool_output_pr_title>([\s\S]*)<\/tool_output_pr_title>/gm;
|
|
9390
|
+
const titleMatch = titleRegex.exec(outputContent);
|
|
9391
|
+
const descriptionRegex = /<tool_output_pr_description>([\s\S]*)<\/tool_output_pr_description>/gm;
|
|
9392
|
+
const descriptionMatch = descriptionRegex.exec(outputContent);
|
|
9393
|
+
if (titleMatch && descriptionMatch) {
|
|
9394
|
+
return {
|
|
9395
|
+
title: titleMatch[1],
|
|
9396
|
+
description: descriptionMatch[1]
|
|
9397
|
+
};
|
|
9398
|
+
}
|
|
9399
|
+
throw new Error(`Could not parse output:
|
|
9400
|
+
${output}`);
|
|
9401
|
+
}
|
|
9402
|
+
};
|
|
9403
|
+
|
|
9404
|
+
// src/AiTool/index.ts
|
|
9405
|
+
var executeTool = async (definition, ai, params) => {
|
|
9406
|
+
const { response, usage } = await ai.request(definition.prompt, [{ role: "user", content: definition.formatInput(params) }]);
|
|
9407
|
+
return {
|
|
9408
|
+
response: definition.parseOutput(response),
|
|
9409
|
+
usage
|
|
9410
|
+
};
|
|
9411
|
+
};
|
|
9412
|
+
var makeTool = (definition) => {
|
|
9413
|
+
return async (ai, params) => {
|
|
9414
|
+
return executeTool(definition, ai, params);
|
|
9415
|
+
};
|
|
9416
|
+
};
|
|
9417
|
+
var generateGitCommitMessage = makeTool(generateGitCommitMessage_default);
|
|
9418
|
+
var generateGithubPullRequestDetails = makeTool(generateGithubPullRequestDetails_default);
|
|
8665
9419
|
export {
|
|
8666
9420
|
writeToFile_default as writeToFile,
|
|
8667
9421
|
searchFiles_default as searchFiles,
|
|
8668
9422
|
replaceInFile_default as replaceInFile,
|
|
8669
9423
|
readFile_default as readFile,
|
|
8670
9424
|
openAiModelInfoSaneDefaults,
|
|
9425
|
+
makeTool,
|
|
8671
9426
|
listFiles_default as listFiles,
|
|
8672
9427
|
listCodeDefinitionNames_default as listCodeDefinitionNames,
|
|
9428
|
+
generateGithubPullRequestDetails,
|
|
9429
|
+
generateGitCommitMessage,
|
|
9430
|
+
executeTool,
|
|
8673
9431
|
executeCommand_default as executeCommand,
|
|
8674
9432
|
defaultModels,
|
|
8675
9433
|
deepSeekModels,
|