playkit-sdk 1.4.0-beta.2 → 1.4.0-beta.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/README.md +31 -0
- package/dist/playkit-sdk.cjs.js +66 -25
- package/dist/playkit-sdk.cjs.js.map +1 -1
- package/dist/playkit-sdk.d.ts +32 -7
- package/dist/playkit-sdk.esm.js +66 -25
- package/dist/playkit-sdk.esm.js.map +1 -1
- package/dist/playkit-sdk.umd.js +66 -25
- package/dist/playkit-sdk.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/playkit-sdk.d.ts
CHANGED
|
@@ -586,6 +586,13 @@ interface ChatConfig {
|
|
|
586
586
|
name: string;
|
|
587
587
|
};
|
|
588
588
|
};
|
|
589
|
+
/** Reasoning effort for thinking-capable models */
|
|
590
|
+
thinking?: {
|
|
591
|
+
/** Whether thinking is enabled */
|
|
592
|
+
enabled?: boolean;
|
|
593
|
+
/** Reasoning effort level */
|
|
594
|
+
effort?: 'minimal' | 'low' | 'medium' | 'high' | 'max';
|
|
595
|
+
};
|
|
589
596
|
}
|
|
590
597
|
/**
|
|
591
598
|
* Configuration for streaming text generation
|
|
@@ -593,6 +600,8 @@ interface ChatConfig {
|
|
|
593
600
|
interface ChatStreamConfig extends ChatConfig {
|
|
594
601
|
/** Callback for each chunk of text */
|
|
595
602
|
onChunk: (chunk: string) => void;
|
|
603
|
+
/** Callback for each chunk of reasoning (thinking) text */
|
|
604
|
+
onReasoning?: (chunk: string) => void;
|
|
596
605
|
/** Callback when generation is complete */
|
|
597
606
|
onComplete?: (fullText: string) => void;
|
|
598
607
|
/** Callback for errors during streaming */
|
|
@@ -620,6 +629,8 @@ interface ChatResult {
|
|
|
620
629
|
created?: number;
|
|
621
630
|
/** Tool calls made by the model */
|
|
622
631
|
tool_calls?: ToolCall[];
|
|
632
|
+
/** Model's reasoning (thinking) content, present only when the model produced thinking */
|
|
633
|
+
reasoning?: string;
|
|
623
634
|
}
|
|
624
635
|
/**
|
|
625
636
|
* Configuration for structured output generation
|
|
@@ -646,7 +657,9 @@ interface ChatCompletionResponse {
|
|
|
646
657
|
model: string;
|
|
647
658
|
choices: Array<{
|
|
648
659
|
index: number;
|
|
649
|
-
message: Message
|
|
660
|
+
message: Message & {
|
|
661
|
+
reasoning_content?: string;
|
|
662
|
+
};
|
|
650
663
|
finish_reason: string;
|
|
651
664
|
}>;
|
|
652
665
|
usage?: {
|
|
@@ -659,7 +672,7 @@ interface ChatCompletionResponse {
|
|
|
659
672
|
* Streaming chunk formats
|
|
660
673
|
*/
|
|
661
674
|
interface StreamChunk {
|
|
662
|
-
type: 'text-delta' | 'done' | 'finish' | 'abort' | 'error';
|
|
675
|
+
type: 'text-delta' | 'reasoning-delta' | 'reasoning-start' | 'reasoning-end' | 'done' | 'finish' | 'abort' | 'error';
|
|
663
676
|
id?: string;
|
|
664
677
|
delta?: string;
|
|
665
678
|
error?: string;
|
|
@@ -1741,6 +1754,7 @@ interface ChatWithToolsConfig extends ChatConfig {
|
|
|
1741
1754
|
*/
|
|
1742
1755
|
interface ChatWithToolsStreamConfig extends ChatWithToolsConfig {
|
|
1743
1756
|
onChunk: (chunk: string) => void;
|
|
1757
|
+
onReasoning?: (chunk: string) => void;
|
|
1744
1758
|
onComplete?: (result: ChatResult) => void;
|
|
1745
1759
|
onError?: (error: Error) => void;
|
|
1746
1760
|
}
|
|
@@ -3000,24 +3014,35 @@ declare class AuthFlowManager extends EventEmitter {
|
|
|
3000
3014
|
* Server-Sent Events (SSE) stream parser
|
|
3001
3015
|
* Handles parsing of streaming text responses
|
|
3002
3016
|
*/
|
|
3017
|
+
/**
|
|
3018
|
+
* A parsed part of the stream — either generated text or reasoning (thinking) text.
|
|
3019
|
+
*/
|
|
3020
|
+
interface StreamPart {
|
|
3021
|
+
kind: 'text' | 'reasoning';
|
|
3022
|
+
delta: string;
|
|
3023
|
+
}
|
|
3003
3024
|
declare class StreamParser {
|
|
3004
3025
|
/**
|
|
3005
3026
|
* Parse SSE stream using ReadableStream
|
|
3027
|
+
* Yields typed parts so callers can separate text from reasoning.
|
|
3006
3028
|
*/
|
|
3007
|
-
static parseStream(reader: ReadableStreamDefaultReader<Uint8Array>): AsyncGenerator<
|
|
3029
|
+
static parseStream(reader: ReadableStreamDefaultReader<Uint8Array>): AsyncGenerator<StreamPart, void, unknown>;
|
|
3008
3030
|
/**
|
|
3009
|
-
* Extract text from a stream chunk
|
|
3010
|
-
* Supports multiple formats (UI Message Stream and OpenAI)
|
|
3031
|
+
* Extract a typed part (text or reasoning) from a stream chunk
|
|
3032
|
+
* Supports multiple formats (UI Message Stream and OpenAI).
|
|
3033
|
+
* Reasoning is detected before the generic text fallback so thinking
|
|
3034
|
+
* deltas never leak into the text stream.
|
|
3011
3035
|
*/
|
|
3012
|
-
private static
|
|
3036
|
+
private static extractPartFromChunk;
|
|
3013
3037
|
/**
|
|
3014
3038
|
* Collect all chunks from a stream
|
|
3015
3039
|
*/
|
|
3016
3040
|
static collectFullText(reader: ReadableStreamDefaultReader<Uint8Array>): Promise<string>;
|
|
3017
3041
|
/**
|
|
3018
3042
|
* Stream with callbacks
|
|
3043
|
+
* Text deltas go to onChunk; reasoning (thinking) deltas go to onReasoning.
|
|
3019
3044
|
*/
|
|
3020
|
-
static streamWithCallbacks(reader: ReadableStreamDefaultReader<Uint8Array>, onChunk: (chunk: string) => void, onComplete?: (fullText: string) => void, onError?: (error: Error) => void): Promise<void>;
|
|
3045
|
+
static streamWithCallbacks(reader: ReadableStreamDefaultReader<Uint8Array>, onChunk: (chunk: string) => void, onComplete?: (fullText: string) => void, onError?: (error: Error) => void, onReasoning?: (chunk: string) => void): Promise<void>;
|
|
3021
3046
|
}
|
|
3022
3047
|
|
|
3023
3048
|
/**
|
package/dist/playkit-sdk.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* playkit-sdk v1.4.0-beta.
|
|
2
|
+
* playkit-sdk v1.4.0-beta.3
|
|
3
3
|
* PlayKit SDK for JavaScript
|
|
4
4
|
* @license SEE LICENSE IN LICENSE
|
|
5
5
|
*/
|
|
@@ -826,7 +826,7 @@ class TokenStorage {
|
|
|
826
826
|
}
|
|
827
827
|
|
|
828
828
|
const SDK_TYPE = 'Javascript';
|
|
829
|
-
const SDK_VERSION = '"1.4.0-beta.
|
|
829
|
+
const SDK_VERSION = '"1.4.0-beta.3"';
|
|
830
830
|
function getSDKHeaders() {
|
|
831
831
|
return {
|
|
832
832
|
'X-SDK-Type': SDK_TYPE,
|
|
@@ -3926,6 +3926,9 @@ class ChatProvider {
|
|
|
3926
3926
|
stop: chatConfig.stop || null,
|
|
3927
3927
|
top_p: chatConfig.topP || null,
|
|
3928
3928
|
};
|
|
3929
|
+
if (chatConfig.thinking) {
|
|
3930
|
+
requestBody.thinking = chatConfig.thinking;
|
|
3931
|
+
}
|
|
3929
3932
|
try {
|
|
3930
3933
|
const response = await fetch(`${this.baseURL}${endpoint}`, {
|
|
3931
3934
|
method: 'POST',
|
|
@@ -3983,6 +3986,9 @@ class ChatProvider {
|
|
|
3983
3986
|
stop: chatConfig.stop || null,
|
|
3984
3987
|
top_p: chatConfig.topP || null,
|
|
3985
3988
|
};
|
|
3989
|
+
if (chatConfig.thinking) {
|
|
3990
|
+
requestBody.thinking = chatConfig.thinking;
|
|
3991
|
+
}
|
|
3986
3992
|
try {
|
|
3987
3993
|
const response = await fetch(`${this.baseURL}${endpoint}`, {
|
|
3988
3994
|
method: 'POST',
|
|
@@ -4047,6 +4053,9 @@ class ChatProvider {
|
|
|
4047
4053
|
if (chatConfig.tool_choice) {
|
|
4048
4054
|
requestBody.tool_choice = chatConfig.tool_choice;
|
|
4049
4055
|
}
|
|
4056
|
+
if (chatConfig.thinking) {
|
|
4057
|
+
requestBody.thinking = chatConfig.thinking;
|
|
4058
|
+
}
|
|
4050
4059
|
try {
|
|
4051
4060
|
const response = await fetch(`${this.baseURL}${endpoint}`, {
|
|
4052
4061
|
method: 'POST',
|
|
@@ -4105,6 +4114,9 @@ class ChatProvider {
|
|
|
4105
4114
|
if (chatConfig.tool_choice) {
|
|
4106
4115
|
requestBody.tool_choice = chatConfig.tool_choice;
|
|
4107
4116
|
}
|
|
4117
|
+
if (chatConfig.thinking) {
|
|
4118
|
+
requestBody.thinking = chatConfig.thinking;
|
|
4119
|
+
}
|
|
4108
4120
|
try {
|
|
4109
4121
|
const response = await fetch(`${this.baseURL}${endpoint}`, {
|
|
4110
4122
|
method: 'POST',
|
|
@@ -4652,6 +4664,7 @@ function createDecoder() {
|
|
|
4652
4664
|
class StreamParser {
|
|
4653
4665
|
/**
|
|
4654
4666
|
* Parse SSE stream using ReadableStream
|
|
4667
|
+
* Yields typed parts so callers can separate text from reasoning.
|
|
4655
4668
|
*/
|
|
4656
4669
|
static parseStream(reader) {
|
|
4657
4670
|
return __asyncGenerator(this, arguments, function* parseStream_1() {
|
|
@@ -4682,9 +4695,9 @@ class StreamParser {
|
|
|
4682
4695
|
const data = trimmed.substring(6); // Remove 'data: ' prefix
|
|
4683
4696
|
try {
|
|
4684
4697
|
const parsed = JSON.parse(data);
|
|
4685
|
-
const
|
|
4686
|
-
if (
|
|
4687
|
-
yield yield __await(
|
|
4698
|
+
const part = this.extractPartFromChunk(parsed);
|
|
4699
|
+
if (part) {
|
|
4700
|
+
yield yield __await(part);
|
|
4688
4701
|
}
|
|
4689
4702
|
// Stream termination events
|
|
4690
4703
|
if (parsed.type === 'done' || parsed.type === 'finish' || parsed.finish_reason) {
|
|
@@ -4701,7 +4714,7 @@ class StreamParser {
|
|
|
4701
4714
|
}
|
|
4702
4715
|
catch (error) {
|
|
4703
4716
|
// If JSON parse fails, treat as plain text
|
|
4704
|
-
yield yield __await(data);
|
|
4717
|
+
yield yield __await({ kind: 'text', delta: data });
|
|
4705
4718
|
}
|
|
4706
4719
|
}
|
|
4707
4720
|
}
|
|
@@ -4713,22 +4726,33 @@ class StreamParser {
|
|
|
4713
4726
|
});
|
|
4714
4727
|
}
|
|
4715
4728
|
/**
|
|
4716
|
-
* Extract text from a stream chunk
|
|
4717
|
-
* Supports multiple formats (UI Message Stream and OpenAI)
|
|
4729
|
+
* Extract a typed part (text or reasoning) from a stream chunk
|
|
4730
|
+
* Supports multiple formats (UI Message Stream and OpenAI).
|
|
4731
|
+
* Reasoning is detected before the generic text fallback so thinking
|
|
4732
|
+
* deltas never leak into the text stream.
|
|
4718
4733
|
*/
|
|
4719
|
-
static
|
|
4720
|
-
var _a, _b;
|
|
4721
|
-
// UI Message Stream
|
|
4734
|
+
static extractPartFromChunk(chunk) {
|
|
4735
|
+
var _a, _b, _c, _d;
|
|
4736
|
+
// UI Message Stream reasoning: { type: "reasoning-delta", delta: "..." }
|
|
4737
|
+
if (chunk.type === 'reasoning-delta' && chunk.delta) {
|
|
4738
|
+
return { kind: 'reasoning', delta: chunk.delta };
|
|
4739
|
+
}
|
|
4740
|
+
// UI Message Stream text: { type: "text-delta", delta: "..." }
|
|
4722
4741
|
if (chunk.type === 'text-delta' && chunk.delta) {
|
|
4723
|
-
return chunk.delta;
|
|
4742
|
+
return { kind: 'text', delta: chunk.delta };
|
|
4724
4743
|
}
|
|
4725
|
-
// OpenAI
|
|
4726
|
-
if (chunk.choices && ((_b = (_a = chunk.choices[0]) === null || _a === void 0 ? void 0 : _a.delta) === null || _b === void 0 ? void 0 : _b.
|
|
4727
|
-
return chunk.choices[0].delta.
|
|
4744
|
+
// OpenAI reasoning (defensive): { choices: [{ delta: { reasoning_content: "..." } }] }
|
|
4745
|
+
if (chunk.choices && ((_b = (_a = chunk.choices[0]) === null || _a === void 0 ? void 0 : _a.delta) === null || _b === void 0 ? void 0 : _b.reasoning_content)) {
|
|
4746
|
+
return { kind: 'reasoning', delta: chunk.choices[0].delta.reasoning_content };
|
|
4728
4747
|
}
|
|
4729
|
-
//
|
|
4748
|
+
// OpenAI text: { choices: [{ delta: { content: "..." } }] }
|
|
4749
|
+
if (chunk.choices && ((_d = (_c = chunk.choices[0]) === null || _c === void 0 ? void 0 : _c.delta) === null || _d === void 0 ? void 0 : _d.content)) {
|
|
4750
|
+
return { kind: 'text', delta: chunk.choices[0].delta.content };
|
|
4751
|
+
}
|
|
4752
|
+
// Direct delta format (text)
|
|
4730
4753
|
if (chunk.delta) {
|
|
4731
|
-
|
|
4754
|
+
const text = typeof chunk.delta === 'string' ? chunk.delta : chunk.delta.content || null;
|
|
4755
|
+
return text ? { kind: 'text', delta: text } : null;
|
|
4732
4756
|
}
|
|
4733
4757
|
return null;
|
|
4734
4758
|
}
|
|
@@ -4742,8 +4766,10 @@ class StreamParser {
|
|
|
4742
4766
|
for (var _d = true, _e = __asyncValues(this.parseStream(reader)), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
|
|
4743
4767
|
_c = _f.value;
|
|
4744
4768
|
_d = false;
|
|
4745
|
-
const
|
|
4746
|
-
|
|
4769
|
+
const part = _c;
|
|
4770
|
+
if (part.kind === 'text') {
|
|
4771
|
+
fullText += part.delta;
|
|
4772
|
+
}
|
|
4747
4773
|
}
|
|
4748
4774
|
}
|
|
4749
4775
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -4757,8 +4783,9 @@ class StreamParser {
|
|
|
4757
4783
|
}
|
|
4758
4784
|
/**
|
|
4759
4785
|
* Stream with callbacks
|
|
4786
|
+
* Text deltas go to onChunk; reasoning (thinking) deltas go to onReasoning.
|
|
4760
4787
|
*/
|
|
4761
|
-
static async streamWithCallbacks(reader, onChunk, onComplete, onError) {
|
|
4788
|
+
static async streamWithCallbacks(reader, onChunk, onComplete, onError, onReasoning) {
|
|
4762
4789
|
var _a, e_2, _b, _c;
|
|
4763
4790
|
let fullText = '';
|
|
4764
4791
|
try {
|
|
@@ -4766,9 +4793,15 @@ class StreamParser {
|
|
|
4766
4793
|
for (var _d = true, _e = __asyncValues(this.parseStream(reader)), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
|
|
4767
4794
|
_c = _f.value;
|
|
4768
4795
|
_d = false;
|
|
4769
|
-
const
|
|
4770
|
-
|
|
4771
|
-
|
|
4796
|
+
const part = _c;
|
|
4797
|
+
if (part.kind === 'reasoning') {
|
|
4798
|
+
if (onReasoning) {
|
|
4799
|
+
onReasoning(part.delta);
|
|
4800
|
+
}
|
|
4801
|
+
continue;
|
|
4802
|
+
}
|
|
4803
|
+
fullText += part.delta;
|
|
4804
|
+
onChunk(part.delta);
|
|
4772
4805
|
}
|
|
4773
4806
|
}
|
|
4774
4807
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
@@ -4869,6 +4902,7 @@ class ChatClient {
|
|
|
4869
4902
|
: undefined,
|
|
4870
4903
|
id: response.id,
|
|
4871
4904
|
created: response.created,
|
|
4905
|
+
reasoning: choice.message.reasoning_content,
|
|
4872
4906
|
};
|
|
4873
4907
|
}
|
|
4874
4908
|
/**
|
|
@@ -4877,7 +4911,7 @@ class ChatClient {
|
|
|
4877
4911
|
async textGenerationStream(config) {
|
|
4878
4912
|
const chatConfig = Object.assign(Object.assign({}, config), { model: config.model || this.model });
|
|
4879
4913
|
const reader = await this.provider.chatCompletionStream(chatConfig);
|
|
4880
|
-
await StreamParser.streamWithCallbacks(reader, config.onChunk, config.onComplete, config.onError);
|
|
4914
|
+
await StreamParser.streamWithCallbacks(reader, config.onChunk, config.onComplete, config.onError, config.onReasoning);
|
|
4881
4915
|
}
|
|
4882
4916
|
// ===== Structured Output Generation =====
|
|
4883
4917
|
/**
|
|
@@ -5035,6 +5069,7 @@ class ChatClient {
|
|
|
5035
5069
|
id: response.id,
|
|
5036
5070
|
created: response.created,
|
|
5037
5071
|
tool_calls: choice.message.tool_calls,
|
|
5072
|
+
reasoning: choice.message.reasoning_content,
|
|
5038
5073
|
};
|
|
5039
5074
|
}
|
|
5040
5075
|
/**
|
|
@@ -5045,6 +5080,7 @@ class ChatClient {
|
|
|
5045
5080
|
const chatConfig = Object.assign(Object.assign({}, config), { model: config.model || this.model });
|
|
5046
5081
|
const reader = await this.provider.chatCompletionWithToolsStream(chatConfig);
|
|
5047
5082
|
let fullContent = '';
|
|
5083
|
+
let fullReasoning = '';
|
|
5048
5084
|
let toolCalls = [];
|
|
5049
5085
|
await StreamParser.streamWithCallbacks(reader, (chunk) => {
|
|
5050
5086
|
fullContent += chunk;
|
|
@@ -5057,9 +5093,14 @@ class ChatClient {
|
|
|
5057
5093
|
model: chatConfig.model || this.model,
|
|
5058
5094
|
finishReason: toolCalls.length > 0 ? 'tool_calls' : 'stop',
|
|
5059
5095
|
tool_calls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
5096
|
+
reasoning: fullReasoning || undefined,
|
|
5060
5097
|
});
|
|
5061
5098
|
}
|
|
5062
|
-
}, config.onError)
|
|
5099
|
+
}, config.onError, (chunk) => {
|
|
5100
|
+
var _a;
|
|
5101
|
+
fullReasoning += chunk;
|
|
5102
|
+
(_a = config.onReasoning) === null || _a === void 0 ? void 0 : _a.call(config, chunk);
|
|
5103
|
+
});
|
|
5063
5104
|
}
|
|
5064
5105
|
}
|
|
5065
5106
|
|