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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * playkit-sdk v1.4.0-beta.2
2
+ * playkit-sdk v1.4.0-beta.3
3
3
  * PlayKit SDK for JavaScript
4
4
  * @license SEE LICENSE IN LICENSE
5
5
  */
@@ -1177,7 +1177,7 @@
1177
1177
  }
1178
1178
 
1179
1179
  const SDK_TYPE = 'Javascript';
1180
- const SDK_VERSION = '"1.4.0-beta.2"';
1180
+ const SDK_VERSION = '"1.4.0-beta.3"';
1181
1181
  function getSDKHeaders() {
1182
1182
  return {
1183
1183
  'X-SDK-Type': SDK_TYPE,
@@ -4277,6 +4277,9 @@
4277
4277
  stop: chatConfig.stop || null,
4278
4278
  top_p: chatConfig.topP || null,
4279
4279
  };
4280
+ if (chatConfig.thinking) {
4281
+ requestBody.thinking = chatConfig.thinking;
4282
+ }
4280
4283
  try {
4281
4284
  const response = await fetch(`${this.baseURL}${endpoint}`, {
4282
4285
  method: 'POST',
@@ -4334,6 +4337,9 @@
4334
4337
  stop: chatConfig.stop || null,
4335
4338
  top_p: chatConfig.topP || null,
4336
4339
  };
4340
+ if (chatConfig.thinking) {
4341
+ requestBody.thinking = chatConfig.thinking;
4342
+ }
4337
4343
  try {
4338
4344
  const response = await fetch(`${this.baseURL}${endpoint}`, {
4339
4345
  method: 'POST',
@@ -4398,6 +4404,9 @@
4398
4404
  if (chatConfig.tool_choice) {
4399
4405
  requestBody.tool_choice = chatConfig.tool_choice;
4400
4406
  }
4407
+ if (chatConfig.thinking) {
4408
+ requestBody.thinking = chatConfig.thinking;
4409
+ }
4401
4410
  try {
4402
4411
  const response = await fetch(`${this.baseURL}${endpoint}`, {
4403
4412
  method: 'POST',
@@ -4456,6 +4465,9 @@
4456
4465
  if (chatConfig.tool_choice) {
4457
4466
  requestBody.tool_choice = chatConfig.tool_choice;
4458
4467
  }
4468
+ if (chatConfig.thinking) {
4469
+ requestBody.thinking = chatConfig.thinking;
4470
+ }
4459
4471
  try {
4460
4472
  const response = await fetch(`${this.baseURL}${endpoint}`, {
4461
4473
  method: 'POST',
@@ -5003,6 +5015,7 @@
5003
5015
  class StreamParser {
5004
5016
  /**
5005
5017
  * Parse SSE stream using ReadableStream
5018
+ * Yields typed parts so callers can separate text from reasoning.
5006
5019
  */
5007
5020
  static parseStream(reader) {
5008
5021
  return __asyncGenerator(this, arguments, function* parseStream_1() {
@@ -5033,9 +5046,9 @@
5033
5046
  const data = trimmed.substring(6); // Remove 'data: ' prefix
5034
5047
  try {
5035
5048
  const parsed = JSON.parse(data);
5036
- const text = this.extractTextFromChunk(parsed);
5037
- if (text) {
5038
- yield yield __await(text);
5049
+ const part = this.extractPartFromChunk(parsed);
5050
+ if (part) {
5051
+ yield yield __await(part);
5039
5052
  }
5040
5053
  // Stream termination events
5041
5054
  if (parsed.type === 'done' || parsed.type === 'finish' || parsed.finish_reason) {
@@ -5052,7 +5065,7 @@
5052
5065
  }
5053
5066
  catch (error) {
5054
5067
  // If JSON parse fails, treat as plain text
5055
- yield yield __await(data);
5068
+ yield yield __await({ kind: 'text', delta: data });
5056
5069
  }
5057
5070
  }
5058
5071
  }
@@ -5064,22 +5077,33 @@
5064
5077
  });
5065
5078
  }
5066
5079
  /**
5067
- * Extract text from a stream chunk
5068
- * Supports multiple formats (UI Message Stream and OpenAI)
5080
+ * Extract a typed part (text or reasoning) from a stream chunk
5081
+ * Supports multiple formats (UI Message Stream and OpenAI).
5082
+ * Reasoning is detected before the generic text fallback so thinking
5083
+ * deltas never leak into the text stream.
5069
5084
  */
5070
- static extractTextFromChunk(chunk) {
5071
- var _a, _b;
5072
- // UI Message Stream format: { type: "text-delta", delta: "..." }
5085
+ static extractPartFromChunk(chunk) {
5086
+ var _a, _b, _c, _d;
5087
+ // UI Message Stream reasoning: { type: "reasoning-delta", delta: "..." }
5088
+ if (chunk.type === 'reasoning-delta' && chunk.delta) {
5089
+ return { kind: 'reasoning', delta: chunk.delta };
5090
+ }
5091
+ // UI Message Stream text: { type: "text-delta", delta: "..." }
5073
5092
  if (chunk.type === 'text-delta' && chunk.delta) {
5074
- return chunk.delta;
5093
+ return { kind: 'text', delta: chunk.delta };
5075
5094
  }
5076
- // OpenAI format: { choices: [{ delta: { content: "..." } }] }
5077
- if (chunk.choices && ((_b = (_a = chunk.choices[0]) === null || _a === void 0 ? void 0 : _a.delta) === null || _b === void 0 ? void 0 : _b.content)) {
5078
- return chunk.choices[0].delta.content;
5095
+ // OpenAI reasoning (defensive): { choices: [{ delta: { reasoning_content: "..." } }] }
5096
+ 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)) {
5097
+ return { kind: 'reasoning', delta: chunk.choices[0].delta.reasoning_content };
5079
5098
  }
5080
- // Direct delta format
5099
+ // OpenAI text: { choices: [{ delta: { content: "..." } }] }
5100
+ if (chunk.choices && ((_d = (_c = chunk.choices[0]) === null || _c === void 0 ? void 0 : _c.delta) === null || _d === void 0 ? void 0 : _d.content)) {
5101
+ return { kind: 'text', delta: chunk.choices[0].delta.content };
5102
+ }
5103
+ // Direct delta format (text)
5081
5104
  if (chunk.delta) {
5082
- return typeof chunk.delta === 'string' ? chunk.delta : chunk.delta.content || null;
5105
+ const text = typeof chunk.delta === 'string' ? chunk.delta : chunk.delta.content || null;
5106
+ return text ? { kind: 'text', delta: text } : null;
5083
5107
  }
5084
5108
  return null;
5085
5109
  }
@@ -5093,8 +5117,10 @@
5093
5117
  for (var _d = true, _e = __asyncValues(this.parseStream(reader)), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
5094
5118
  _c = _f.value;
5095
5119
  _d = false;
5096
- const chunk = _c;
5097
- fullText += chunk;
5120
+ const part = _c;
5121
+ if (part.kind === 'text') {
5122
+ fullText += part.delta;
5123
+ }
5098
5124
  }
5099
5125
  }
5100
5126
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -5108,8 +5134,9 @@
5108
5134
  }
5109
5135
  /**
5110
5136
  * Stream with callbacks
5137
+ * Text deltas go to onChunk; reasoning (thinking) deltas go to onReasoning.
5111
5138
  */
5112
- static async streamWithCallbacks(reader, onChunk, onComplete, onError) {
5139
+ static async streamWithCallbacks(reader, onChunk, onComplete, onError, onReasoning) {
5113
5140
  var _a, e_2, _b, _c;
5114
5141
  let fullText = '';
5115
5142
  try {
@@ -5117,9 +5144,15 @@
5117
5144
  for (var _d = true, _e = __asyncValues(this.parseStream(reader)), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
5118
5145
  _c = _f.value;
5119
5146
  _d = false;
5120
- const chunk = _c;
5121
- fullText += chunk;
5122
- onChunk(chunk);
5147
+ const part = _c;
5148
+ if (part.kind === 'reasoning') {
5149
+ if (onReasoning) {
5150
+ onReasoning(part.delta);
5151
+ }
5152
+ continue;
5153
+ }
5154
+ fullText += part.delta;
5155
+ onChunk(part.delta);
5123
5156
  }
5124
5157
  }
5125
5158
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
@@ -5220,6 +5253,7 @@
5220
5253
  : undefined,
5221
5254
  id: response.id,
5222
5255
  created: response.created,
5256
+ reasoning: choice.message.reasoning_content,
5223
5257
  };
5224
5258
  }
5225
5259
  /**
@@ -5228,7 +5262,7 @@
5228
5262
  async textGenerationStream(config) {
5229
5263
  const chatConfig = Object.assign(Object.assign({}, config), { model: config.model || this.model });
5230
5264
  const reader = await this.provider.chatCompletionStream(chatConfig);
5231
- await StreamParser.streamWithCallbacks(reader, config.onChunk, config.onComplete, config.onError);
5265
+ await StreamParser.streamWithCallbacks(reader, config.onChunk, config.onComplete, config.onError, config.onReasoning);
5232
5266
  }
5233
5267
  // ===== Structured Output Generation =====
5234
5268
  /**
@@ -5386,6 +5420,7 @@
5386
5420
  id: response.id,
5387
5421
  created: response.created,
5388
5422
  tool_calls: choice.message.tool_calls,
5423
+ reasoning: choice.message.reasoning_content,
5389
5424
  };
5390
5425
  }
5391
5426
  /**
@@ -5396,6 +5431,7 @@
5396
5431
  const chatConfig = Object.assign(Object.assign({}, config), { model: config.model || this.model });
5397
5432
  const reader = await this.provider.chatCompletionWithToolsStream(chatConfig);
5398
5433
  let fullContent = '';
5434
+ let fullReasoning = '';
5399
5435
  let toolCalls = [];
5400
5436
  await StreamParser.streamWithCallbacks(reader, (chunk) => {
5401
5437
  fullContent += chunk;
@@ -5408,9 +5444,14 @@
5408
5444
  model: chatConfig.model || this.model,
5409
5445
  finishReason: toolCalls.length > 0 ? 'tool_calls' : 'stop',
5410
5446
  tool_calls: toolCalls.length > 0 ? toolCalls : undefined,
5447
+ reasoning: fullReasoning || undefined,
5411
5448
  });
5412
5449
  }
5413
- }, config.onError);
5450
+ }, config.onError, (chunk) => {
5451
+ var _a;
5452
+ fullReasoning += chunk;
5453
+ (_a = config.onReasoning) === null || _a === void 0 ? void 0 : _a.call(config, chunk);
5454
+ });
5414
5455
  }
5415
5456
  }
5416
5457