@byfriends/kosong 0.2.2 → 0.3.2
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/{anthropic-0CVG5rBE.d.mts → anthropic-BYlmhwZs.d.mts} +6 -14
- package/dist/base-chat-provider-B_Ow8SIj.d.mts +74 -0
- package/dist/base-streamed-message-D738gMHT.d.mts +23 -0
- package/dist/{request-auth-BMXt8jRu.mjs → base-streamed-message-Kok6Drxr.mjs} +111 -2
- package/dist/{google-genai-xKK8lI_R.d.mts → google-genai-CSE4ZD3A.d.mts} +18 -24
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +33 -72
- package/dist/{openai-common-DwkxUSyI.d.mts → openai-common-7D2LXUK2.d.mts} +1 -1
- package/dist/{openai-common-Dl42y_vn.mjs → openai-common-B7Ex3mNh.mjs} +8 -30
- package/dist/{openai-responses-DZ9mQ5RA.d.mts → openai-responses-Bj6eg-S0.d.mts} +11 -26
- package/dist/provider-common-CaxKVTTJ.mjs +151 -0
- package/dist/providers/anthropic.d.mts +1 -1
- package/dist/providers/anthropic.mjs +59 -110
- package/dist/providers/google-genai.d.mts +1 -1
- package/dist/providers/google-genai.mjs +45 -77
- package/dist/providers/openai-common.d.mts +1 -1
- package/dist/providers/openai-common.mjs +1 -1
- package/dist/providers/openai-responses.d.mts +1 -1
- package/dist/providers/openai-responses.mjs +29 -82
- package/package.json +1 -1
- package/dist/errors-WFxxzL1B.mjs +0 -80
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { c as thinkingEffortToReasoningEffort, n as convertOpenAIError, p as extractText, s as reasoningEffortToThinkingEffort } from "../openai-common-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { c as thinkingEffortToReasoningEffort, n as convertOpenAIError, p as extractText, s as reasoningEffortToThinkingEffort } from "../openai-common-B7Ex3mNh.mjs";
|
|
2
|
+
import { l as ChatProviderError, n as extractCacheUsage } from "../provider-common-CaxKVTTJ.mjs";
|
|
3
|
+
import { d as usesOpenAIResponsesDeveloperRole, l as getOpenAIResponsesModelCapability, n as BaseChatProvider, t as BaseStreamedMessage } from "../base-streamed-message-Kok6Drxr.mjs";
|
|
4
4
|
import OpenAI from "openai";
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
6
|
//#region src/providers/openai-responses.ts
|
|
@@ -308,30 +308,17 @@ function convertTool(tool) {
|
|
|
308
308
|
strict: false
|
|
309
309
|
};
|
|
310
310
|
}
|
|
311
|
-
var OpenAIResponsesStreamedMessage = class {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
_finishReason = null;
|
|
315
|
-
_rawFinishReason = null;
|
|
316
|
-
_iter;
|
|
311
|
+
var OpenAIResponsesStreamedMessage = class extends BaseStreamedMessage {
|
|
312
|
+
_response;
|
|
313
|
+
_isStream;
|
|
317
314
|
constructor(response, isStream) {
|
|
318
|
-
|
|
319
|
-
|
|
315
|
+
super();
|
|
316
|
+
this._response = response;
|
|
317
|
+
this._isStream = isStream;
|
|
320
318
|
}
|
|
321
|
-
|
|
322
|
-
return this.
|
|
323
|
-
|
|
324
|
-
get usage() {
|
|
325
|
-
return this._usage;
|
|
326
|
-
}
|
|
327
|
-
get finishReason() {
|
|
328
|
-
return this._finishReason;
|
|
329
|
-
}
|
|
330
|
-
get rawFinishReason() {
|
|
331
|
-
return this._rawFinishReason;
|
|
332
|
-
}
|
|
333
|
-
async *[Symbol.asyncIterator]() {
|
|
334
|
-
yield* this._iter;
|
|
319
|
+
_buildIter() {
|
|
320
|
+
if (this._isStream) return this._convertStreamResponse(this._response);
|
|
321
|
+
return this._convertNonStreamResponse(this._response);
|
|
335
322
|
}
|
|
336
323
|
_captureFinishReasonFromResponse(response) {
|
|
337
324
|
const status = readNullableStringField(response, "status");
|
|
@@ -345,12 +332,7 @@ var OpenAIResponsesStreamedMessage = class {
|
|
|
345
332
|
const outputTokens = readNumberField(usage, "output_tokens") ?? 0;
|
|
346
333
|
const details = readObjectField(usage, "input_tokens_details");
|
|
347
334
|
const cached = details ? readNumberField(details, "cached_tokens") ?? 0 : 0;
|
|
348
|
-
this._usage =
|
|
349
|
-
inputOther: inputTokens - cached,
|
|
350
|
-
output: outputTokens,
|
|
351
|
-
inputCacheRead: cached,
|
|
352
|
-
inputCacheCreation: 0
|
|
353
|
-
};
|
|
335
|
+
this._usage = extractCacheUsage(inputTokens, cached, outputTokens);
|
|
354
336
|
}
|
|
355
337
|
async *_convertNonStreamResponse(response) {
|
|
356
338
|
this._id = readStringField(response, "id") ?? null;
|
|
@@ -513,34 +495,22 @@ var OpenAIResponsesStreamedMessage = class {
|
|
|
513
495
|
}
|
|
514
496
|
}
|
|
515
497
|
};
|
|
516
|
-
var OpenAIResponsesChatProvider = class {
|
|
498
|
+
var OpenAIResponsesChatProvider = class OpenAIResponsesChatProvider extends BaseChatProvider {
|
|
517
499
|
name = "openai-responses";
|
|
518
|
-
_model;
|
|
519
500
|
_stream;
|
|
520
|
-
_apiKey;
|
|
521
|
-
_baseUrl;
|
|
522
|
-
_defaultHeaders;
|
|
523
|
-
_generationKwargs;
|
|
524
501
|
_toolMessageConversion;
|
|
525
|
-
_client;
|
|
526
502
|
_httpClient;
|
|
527
|
-
_clientFactory;
|
|
528
503
|
constructor(options) {
|
|
529
504
|
const apiKey = options.apiKey ?? process.env["OPENAI_API_KEY"];
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
505
|
+
const apiKeyResolved = apiKey === void 0 || apiKey.length === 0 ? void 0 : apiKey;
|
|
506
|
+
const baseUrl = options.baseUrl ?? "https://api.openai.com/v1";
|
|
507
|
+
const generationKwargs = {};
|
|
508
|
+
if (options.maxOutputTokens !== void 0) generationKwargs.max_output_tokens = options.maxOutputTokens;
|
|
509
|
+
const client = apiKeyResolved === void 0 ? void 0 : OpenAIResponsesChatProvider.buildClient(apiKeyResolved, baseUrl, options.defaultHeaders, options.httpClient);
|
|
510
|
+
super(options.model, generationKwargs, apiKeyResolved, baseUrl, options.defaultHeaders, client, options.clientFactory);
|
|
534
511
|
this._stream = true;
|
|
535
|
-
this._generationKwargs = {};
|
|
536
512
|
this._toolMessageConversion = options.toolMessageConversion ?? null;
|
|
537
513
|
this._httpClient = options.httpClient;
|
|
538
|
-
this._clientFactory = options.clientFactory;
|
|
539
|
-
if (options.maxOutputTokens !== void 0) this._generationKwargs.max_output_tokens = options.maxOutputTokens;
|
|
540
|
-
this._client = this._apiKey === void 0 ? void 0 : this._buildClient(this._apiKey);
|
|
541
|
-
}
|
|
542
|
-
get modelName() {
|
|
543
|
-
return this._model;
|
|
544
514
|
}
|
|
545
515
|
get thinkingEffort() {
|
|
546
516
|
return reasoningEffortToThinkingEffort(this._generationKwargs.reasoning_effort);
|
|
@@ -599,41 +569,18 @@ var OpenAIResponsesChatProvider = class {
|
|
|
599
569
|
}
|
|
600
570
|
withThinking(effort) {
|
|
601
571
|
const reasoningEffort = thinkingEffortToReasoningEffort(effort, this._model);
|
|
602
|
-
|
|
603
|
-
clone._generationKwargs = {
|
|
604
|
-
...clone._generationKwargs,
|
|
605
|
-
reasoning_effort: reasoningEffort
|
|
606
|
-
};
|
|
607
|
-
return clone;
|
|
608
|
-
}
|
|
609
|
-
withGenerationKwargs(kwargs) {
|
|
610
|
-
const clone = this._clone();
|
|
611
|
-
clone._generationKwargs = {
|
|
612
|
-
...clone._generationKwargs,
|
|
613
|
-
...kwargs
|
|
614
|
-
};
|
|
615
|
-
return clone;
|
|
572
|
+
return this.withGenerationKwargs({ reasoning_effort: reasoningEffort });
|
|
616
573
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
clone._generationKwargs = { ...this._generationKwargs };
|
|
620
|
-
return clone;
|
|
574
|
+
createRawClient(auth, defaultHeaders) {
|
|
575
|
+
return OpenAIResponsesChatProvider.buildClient(auth.apiKey, this._baseUrl, defaultHeaders, this._httpClient);
|
|
621
576
|
}
|
|
622
|
-
|
|
623
|
-
return
|
|
624
|
-
cachedClient: this._client,
|
|
625
|
-
clientFactory: this._clientFactory
|
|
626
|
-
}, auth, (a) => this._buildClient(requireProviderApiKey("OpenAIResponsesChatProvider", a, this._apiKey), a));
|
|
627
|
-
}
|
|
628
|
-
_buildClient(apiKey, auth) {
|
|
629
|
-
const clientOpts = {
|
|
577
|
+
static buildClient(apiKey, baseURL, defaultHeaders, httpClient) {
|
|
578
|
+
return new OpenAI({
|
|
630
579
|
apiKey,
|
|
631
|
-
baseURL
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
if (this._httpClient !== void 0) clientOpts["httpClient"] = this._httpClient;
|
|
636
|
-
return new OpenAI(clientOpts);
|
|
580
|
+
baseURL,
|
|
581
|
+
...defaultHeaders !== void 0 ? { defaultHeaders } : {},
|
|
582
|
+
...httpClient !== void 0 ? { httpClient } : {}
|
|
583
|
+
});
|
|
637
584
|
}
|
|
638
585
|
};
|
|
639
586
|
//#endregion
|
package/package.json
CHANGED
package/dist/errors-WFxxzL1B.mjs
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
//#region src/errors.ts
|
|
2
|
-
/**
|
|
3
|
-
* Base error for all chat provider errors.
|
|
4
|
-
*/
|
|
5
|
-
var ChatProviderError = class extends Error {
|
|
6
|
-
constructor(message) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.name = "ChatProviderError";
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Network-level connection failure.
|
|
13
|
-
*/
|
|
14
|
-
var APIConnectionError = class extends ChatProviderError {
|
|
15
|
-
constructor(message) {
|
|
16
|
-
super(message);
|
|
17
|
-
this.name = "APIConnectionError";
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Request timed out.
|
|
22
|
-
*/
|
|
23
|
-
var APITimeoutError = class extends ChatProviderError {
|
|
24
|
-
constructor(message) {
|
|
25
|
-
super(message);
|
|
26
|
-
this.name = "APITimeoutError";
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* HTTP status error from the API.
|
|
31
|
-
*/
|
|
32
|
-
var APIStatusError = class extends ChatProviderError {
|
|
33
|
-
statusCode;
|
|
34
|
-
requestId;
|
|
35
|
-
constructor(statusCode, message, requestId) {
|
|
36
|
-
super(message);
|
|
37
|
-
this.name = "APIStatusError";
|
|
38
|
-
this.statusCode = statusCode;
|
|
39
|
-
this.requestId = requestId ?? null;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* HTTP status error that specifically means the request exceeded the model
|
|
44
|
-
* context window.
|
|
45
|
-
*/
|
|
46
|
-
var APIContextOverflowError = class extends APIStatusError {
|
|
47
|
-
constructor(statusCode, message, requestId) {
|
|
48
|
-
super(statusCode, message, requestId);
|
|
49
|
-
this.name = "APIContextOverflowError";
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* The API returned an empty response (no content, no tool calls).
|
|
54
|
-
*/
|
|
55
|
-
var APIEmptyResponseError = class extends ChatProviderError {
|
|
56
|
-
constructor(message) {
|
|
57
|
-
super(message);
|
|
58
|
-
this.name = "APIEmptyResponseError";
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
const CONTEXT_OVERFLOW_MESSAGE_PATTERNS = [
|
|
62
|
-
/context[ _-]?length/,
|
|
63
|
-
/(?:context[ _-]?window.*exceed|exceed.*context[ _-]?window)/,
|
|
64
|
-
/maximum context/,
|
|
65
|
-
/exceed(?:ed|s|ing)?\s+(?:the\s+)?max(?:imum)?\s+tokens?/,
|
|
66
|
-
/(?:too many tokens.*(?:prompt|input|context)|(?:prompt|input|context).*too many tokens)/,
|
|
67
|
-
/prompt is too long.*maximum/,
|
|
68
|
-
/input token count.*exceeds?.*maximum number of tokens/
|
|
69
|
-
];
|
|
70
|
-
function normalizeAPIStatusError(statusCode, message, requestId) {
|
|
71
|
-
if (isContextOverflowStatusError(statusCode, message)) return new APIContextOverflowError(statusCode, message, requestId);
|
|
72
|
-
return new APIStatusError(statusCode, message, requestId);
|
|
73
|
-
}
|
|
74
|
-
function isContextOverflowStatusError(statusCode, message) {
|
|
75
|
-
if (statusCode !== 400 && statusCode !== 413 && statusCode !== 422) return false;
|
|
76
|
-
const lowerMessage = message.toLowerCase();
|
|
77
|
-
return CONTEXT_OVERFLOW_MESSAGE_PATTERNS.some((pattern) => pattern.test(lowerMessage));
|
|
78
|
-
}
|
|
79
|
-
//#endregion
|
|
80
|
-
export { APITimeoutError as a, APIStatusError as i, APIContextOverflowError as n, ChatProviderError as o, APIEmptyResponseError as r, normalizeAPIStatusError as s, APIConnectionError as t };
|