@yourgpt/llm-sdk 2.1.8 → 2.1.10-alpha.0
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/adapters/index.d.mts +38 -4
- package/dist/adapters/index.d.ts +38 -4
- package/dist/adapters/index.js +318 -8
- package/dist/adapters/index.mjs +318 -8
- package/dist/{base-iGi9Va6Z.d.ts → base-DN1EfKnE.d.mts} +2 -1
- package/dist/{base-D-U61JaB.d.mts → base-DuUNxtVg.d.ts} +2 -1
- package/dist/fallback/index.d.mts +4 -4
- package/dist/fallback/index.d.ts +4 -4
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +43 -23
- package/dist/index.mjs +43 -23
- package/dist/providers/anthropic/index.d.mts +3 -3
- package/dist/providers/anthropic/index.d.ts +3 -3
- package/dist/providers/anthropic/index.js +17 -0
- package/dist/providers/anthropic/index.mjs +17 -0
- package/dist/providers/azure/index.d.mts +3 -3
- package/dist/providers/azure/index.d.ts +3 -3
- package/dist/providers/fireworks/index.d.mts +1 -1
- package/dist/providers/fireworks/index.d.ts +1 -1
- package/dist/providers/google/index.d.mts +3 -3
- package/dist/providers/google/index.d.ts +3 -3
- package/dist/providers/google/index.js +311 -8
- package/dist/providers/google/index.mjs +311 -8
- package/dist/providers/ollama/index.d.mts +4 -4
- package/dist/providers/ollama/index.d.ts +4 -4
- package/dist/providers/openai/index.d.mts +3 -3
- package/dist/providers/openai/index.d.ts +3 -3
- package/dist/providers/openai/index.js +321 -8
- package/dist/providers/openai/index.mjs +321 -8
- package/dist/providers/openrouter/index.d.mts +7 -3
- package/dist/providers/openrouter/index.d.ts +7 -3
- package/dist/providers/openrouter/index.js +601 -11
- package/dist/providers/openrouter/index.mjs +601 -11
- package/dist/providers/togetherai/index.d.mts +61 -2
- package/dist/providers/togetherai/index.d.ts +61 -2
- package/dist/providers/togetherai/index.js +1030 -2
- package/dist/providers/togetherai/index.mjs +1029 -2
- package/dist/providers/xai/index.d.mts +3 -3
- package/dist/providers/xai/index.d.ts +3 -3
- package/dist/providers/xai/index.js +311 -8
- package/dist/providers/xai/index.mjs +311 -8
- package/dist/{types-D4YfrQJR.d.mts → types-BNCmlJMs.d.mts} +1 -1
- package/dist/{types-DRqxMIjF.d.mts → types-CMMQ8s2O.d.mts} +1 -1
- package/dist/{types-CR8mi9I0.d.ts → types-CMvvDo-E.d.mts} +12 -1
- package/dist/{types-CR8mi9I0.d.mts → types-CMvvDo-E.d.ts} +12 -1
- package/dist/{types-BctsnC3g.d.ts → types-DhktekQ3.d.ts} +1 -1
- package/dist/{types-38yolWJn.d.ts → types-Pj-vpmoT.d.ts} +1 -1
- package/dist/yourgpt/index.d.mts +1 -1
- package/dist/yourgpt/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/adapters/index.mjs
CHANGED
|
@@ -380,6 +380,7 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
380
380
|
if (baseUrl.includes("generativelanguage.googleapis.com")) return "google";
|
|
381
381
|
if (baseUrl.includes("x.ai")) return "xai";
|
|
382
382
|
if (baseUrl.includes("azure")) return "azure";
|
|
383
|
+
if (baseUrl.includes("openrouter.ai")) return "openrouter";
|
|
383
384
|
return "openai";
|
|
384
385
|
}
|
|
385
386
|
async getClient() {
|
|
@@ -479,6 +480,256 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
479
480
|
rawResponse: response
|
|
480
481
|
};
|
|
481
482
|
}
|
|
483
|
+
/**
|
|
484
|
+
* OpenAI reasoning models on OpenRouter (o1/o3/o4/gpt-5 family) hide their
|
|
485
|
+
* reasoning content on the chat-completions endpoint. To surface reasoning
|
|
486
|
+
* SUMMARIES (not raw CoT, which OpenAI never exposes) we have to use the
|
|
487
|
+
* Responses API, which streams `response.reasoning_summary_text.delta` events.
|
|
488
|
+
*
|
|
489
|
+
* Match by prefix on the OpenRouter model id. Excludes openai/gpt-4o,
|
|
490
|
+
* openai/gpt-4.1, openai/chatgpt-* — those continue on chat-completions.
|
|
491
|
+
*/
|
|
492
|
+
isOpenAIReasoningModelOnOpenRouter(activeModel) {
|
|
493
|
+
if (this.provider !== "openrouter") return false;
|
|
494
|
+
return activeModel.startsWith("openai/o1") || activeModel.startsWith("openai/o3") || activeModel.startsWith("openai/o4") || activeModel.startsWith("openai/gpt-5");
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Convert ActionDefinition[] (the chat-completions tool shape used by the
|
|
498
|
+
* adapter) to the Responses API tool shape.
|
|
499
|
+
*/
|
|
500
|
+
buildResponsesToolsFromActions(actions) {
|
|
501
|
+
if (!actions || actions.length === 0) return void 0;
|
|
502
|
+
const formatted = formatTools(actions);
|
|
503
|
+
return formatted.map((t) => ({
|
|
504
|
+
type: "function",
|
|
505
|
+
name: t.function.name,
|
|
506
|
+
description: t.function.description,
|
|
507
|
+
parameters: t.function.parameters
|
|
508
|
+
}));
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Streaming Responses API path for OpenAI reasoning models on OpenRouter.
|
|
512
|
+
*
|
|
513
|
+
* Maps Responses API SSE events back to the same StreamEvent shapes the
|
|
514
|
+
* chat-completions path emits, so downstream consumers (processChunk.ts,
|
|
515
|
+
* frontend tool handlers, plan approval, specialist delegations) see
|
|
516
|
+
* identical events regardless of which path produced them.
|
|
517
|
+
*
|
|
518
|
+
* response.reasoning_summary_text.delta → thinking:start (once) + thinking:delta
|
|
519
|
+
* response.output_text.delta → message:delta
|
|
520
|
+
* response.output_item.added (function_call) → action:start (queued buffer)
|
|
521
|
+
* response.function_call_arguments.delta → action:args (progressive)
|
|
522
|
+
* response.output_item.done (function_call) → final action:args + action:end
|
|
523
|
+
* response.completed → message:end + done(usage)
|
|
524
|
+
* response.error → error
|
|
525
|
+
*/
|
|
526
|
+
async *streamWithResponsesAPI(request, activeModel, messageId) {
|
|
527
|
+
const client = await this.getClient();
|
|
528
|
+
const maxTokensValue = request.config?.maxTokens ?? this.config.maxTokens;
|
|
529
|
+
const payload = {
|
|
530
|
+
model: activeModel,
|
|
531
|
+
input: this.buildResponsesInput(request),
|
|
532
|
+
stream: true,
|
|
533
|
+
reasoning: {
|
|
534
|
+
effort: request.config?.reasoningEffort ?? "medium",
|
|
535
|
+
summary: "auto"
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
if (request.systemPrompt) payload.instructions = request.systemPrompt;
|
|
539
|
+
if (typeof maxTokensValue === "number")
|
|
540
|
+
payload.max_output_tokens = maxTokensValue;
|
|
541
|
+
const tools = this.buildResponsesToolsFromActions(request.actions);
|
|
542
|
+
if (tools && tools.length > 0) payload.tools = tools;
|
|
543
|
+
logProviderPayload(
|
|
544
|
+
"openai",
|
|
545
|
+
"responses-api request payload",
|
|
546
|
+
payload,
|
|
547
|
+
request.debug
|
|
548
|
+
);
|
|
549
|
+
let stream;
|
|
550
|
+
try {
|
|
551
|
+
stream = await client.responses.create(payload);
|
|
552
|
+
} catch (error) {
|
|
553
|
+
yield {
|
|
554
|
+
type: "error",
|
|
555
|
+
message: error instanceof Error ? error.message : "Unknown error",
|
|
556
|
+
code: "OPENAI_RESPONSES_ERROR"
|
|
557
|
+
};
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
const toolBuffers = /* @__PURE__ */ new Map();
|
|
561
|
+
const itemIdToCallId = /* @__PURE__ */ new Map();
|
|
562
|
+
let usage;
|
|
563
|
+
let reasoningStarted = false;
|
|
564
|
+
let textStarted = false;
|
|
565
|
+
let finishEmitted = false;
|
|
566
|
+
const resolveCallId = (evt) => {
|
|
567
|
+
if (evt?.call_id) return evt.call_id;
|
|
568
|
+
if (evt?.item_id) return itemIdToCallId.get(evt.item_id) ?? evt.item_id;
|
|
569
|
+
if (evt?.item?.call_id) return evt.item.call_id;
|
|
570
|
+
if (evt?.item?.id) return evt.item.id;
|
|
571
|
+
return "";
|
|
572
|
+
};
|
|
573
|
+
try {
|
|
574
|
+
for await (const evt of stream) {
|
|
575
|
+
logProviderPayload(
|
|
576
|
+
"openai",
|
|
577
|
+
"responses-api stream chunk",
|
|
578
|
+
evt,
|
|
579
|
+
request.debug
|
|
580
|
+
);
|
|
581
|
+
if (request.signal?.aborted) break;
|
|
582
|
+
const t = evt?.type ?? "";
|
|
583
|
+
if (t === "response.reasoning_summary_text.delta") {
|
|
584
|
+
const delta = evt.delta ?? "";
|
|
585
|
+
if (!delta) continue;
|
|
586
|
+
if (!reasoningStarted) {
|
|
587
|
+
yield { type: "thinking:start" };
|
|
588
|
+
reasoningStarted = true;
|
|
589
|
+
}
|
|
590
|
+
yield { type: "thinking:delta", content: delta };
|
|
591
|
+
continue;
|
|
592
|
+
}
|
|
593
|
+
if (t === "response.reasoning_summary_text.done" || t === "response.reasoning.done") {
|
|
594
|
+
continue;
|
|
595
|
+
}
|
|
596
|
+
if (t === "response.output_text.delta") {
|
|
597
|
+
const text = evt.delta ?? "";
|
|
598
|
+
if (!text) continue;
|
|
599
|
+
if (reasoningStarted && !textStarted) {
|
|
600
|
+
yield { type: "thinking:end" };
|
|
601
|
+
textStarted = true;
|
|
602
|
+
}
|
|
603
|
+
yield { type: "message:delta", content: text };
|
|
604
|
+
continue;
|
|
605
|
+
}
|
|
606
|
+
if (t === "response.output_item.added") {
|
|
607
|
+
const item = evt.item;
|
|
608
|
+
if (item?.type === "function_call") {
|
|
609
|
+
const callId = item.call_id ?? item.id ?? "";
|
|
610
|
+
const itemId = item.id ?? callId;
|
|
611
|
+
if (callId) {
|
|
612
|
+
if (itemId && itemId !== callId) {
|
|
613
|
+
itemIdToCallId.set(itemId, callId);
|
|
614
|
+
}
|
|
615
|
+
if (!toolBuffers.has(callId)) {
|
|
616
|
+
toolBuffers.set(callId, {
|
|
617
|
+
id: callId,
|
|
618
|
+
name: item.name ?? "",
|
|
619
|
+
arguments: item.arguments ?? "",
|
|
620
|
+
emittedStart: false
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
const buf = toolBuffers.get(callId);
|
|
624
|
+
if (buf.name && !buf.emittedStart) {
|
|
625
|
+
yield { type: "action:start", id: buf.id, name: buf.name };
|
|
626
|
+
buf.emittedStart = true;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
continue;
|
|
631
|
+
}
|
|
632
|
+
if (t === "response.function_call_arguments.delta") {
|
|
633
|
+
const callId = resolveCallId(evt);
|
|
634
|
+
const delta = evt.delta ?? "";
|
|
635
|
+
if (!callId || !delta) continue;
|
|
636
|
+
let buf = toolBuffers.get(callId);
|
|
637
|
+
if (!buf) {
|
|
638
|
+
buf = { id: callId, name: "", arguments: "", emittedStart: false };
|
|
639
|
+
toolBuffers.set(callId, buf);
|
|
640
|
+
}
|
|
641
|
+
buf.arguments += delta;
|
|
642
|
+
if (buf.emittedStart) {
|
|
643
|
+
yield {
|
|
644
|
+
type: "action:args",
|
|
645
|
+
id: buf.id,
|
|
646
|
+
args: buf.arguments
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
continue;
|
|
650
|
+
}
|
|
651
|
+
if (t === "response.output_item.done") {
|
|
652
|
+
const item = evt.item;
|
|
653
|
+
if (item?.type === "function_call") {
|
|
654
|
+
const callId = item.call_id ?? item.id ?? "";
|
|
655
|
+
const buf = toolBuffers.get(callId);
|
|
656
|
+
const name = buf?.name || item.name || "";
|
|
657
|
+
const argsStr = buf?.arguments || item.arguments || "{}";
|
|
658
|
+
if (callId && name) {
|
|
659
|
+
if (!buf?.emittedStart) {
|
|
660
|
+
yield { type: "action:start", id: callId, name };
|
|
661
|
+
}
|
|
662
|
+
yield {
|
|
663
|
+
type: "action:args",
|
|
664
|
+
id: callId,
|
|
665
|
+
args: argsStr
|
|
666
|
+
};
|
|
667
|
+
yield {
|
|
668
|
+
type: "action:end",
|
|
669
|
+
id: callId,
|
|
670
|
+
name
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
toolBuffers.delete(callId);
|
|
674
|
+
}
|
|
675
|
+
continue;
|
|
676
|
+
}
|
|
677
|
+
if (t === "response.completed") {
|
|
678
|
+
const u = evt.response?.usage;
|
|
679
|
+
if (u) {
|
|
680
|
+
usage = {
|
|
681
|
+
prompt_tokens: u.input_tokens ?? 0,
|
|
682
|
+
completion_tokens: u.output_tokens ?? 0,
|
|
683
|
+
total_tokens: u.total_tokens ?? (u.input_tokens ?? 0) + (u.output_tokens ?? 0)
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
for (const buf of toolBuffers.values()) {
|
|
687
|
+
if (!buf.id || !buf.name) continue;
|
|
688
|
+
if (!buf.emittedStart) {
|
|
689
|
+
yield { type: "action:start", id: buf.id, name: buf.name };
|
|
690
|
+
}
|
|
691
|
+
yield {
|
|
692
|
+
type: "action:args",
|
|
693
|
+
id: buf.id,
|
|
694
|
+
args: buf.arguments || "{}"
|
|
695
|
+
};
|
|
696
|
+
yield { type: "action:end", id: buf.id, name: buf.name };
|
|
697
|
+
}
|
|
698
|
+
toolBuffers.clear();
|
|
699
|
+
if (reasoningStarted && !textStarted) {
|
|
700
|
+
yield { type: "thinking:end" };
|
|
701
|
+
}
|
|
702
|
+
yield { type: "message:end" };
|
|
703
|
+
yield { type: "done", usage };
|
|
704
|
+
finishEmitted = true;
|
|
705
|
+
continue;
|
|
706
|
+
}
|
|
707
|
+
if (t === "response.error" || t === "error") {
|
|
708
|
+
const msg = evt.error?.message || evt.message || "Responses API error";
|
|
709
|
+
yield {
|
|
710
|
+
type: "error",
|
|
711
|
+
message: msg,
|
|
712
|
+
code: "OPENAI_RESPONSES_ERROR"
|
|
713
|
+
};
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
} catch (error) {
|
|
718
|
+
yield {
|
|
719
|
+
type: "error",
|
|
720
|
+
message: error instanceof Error ? error.message : "Unknown error",
|
|
721
|
+
code: "OPENAI_RESPONSES_ERROR"
|
|
722
|
+
};
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
if (!finishEmitted) {
|
|
726
|
+
if (reasoningStarted && !textStarted) {
|
|
727
|
+
yield { type: "thinking:end" };
|
|
728
|
+
}
|
|
729
|
+
yield { type: "message:end" };
|
|
730
|
+
yield { type: "done", usage };
|
|
731
|
+
}
|
|
732
|
+
}
|
|
482
733
|
async completeWithResponses(request) {
|
|
483
734
|
const client = await this.getClient();
|
|
484
735
|
const openaiToolOptions = request.providerToolOptions?.openai;
|
|
@@ -612,16 +863,37 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
612
863
|
name: openaiToolOptions.toolChoice.name
|
|
613
864
|
}
|
|
614
865
|
} : openaiToolOptions?.toolChoice;
|
|
866
|
+
const isOpenRouter = this.provider === "openrouter";
|
|
867
|
+
const activeModel = request.config?.model || this.model;
|
|
868
|
+
const modelSlug = activeModel.replace("openai/", "");
|
|
869
|
+
const isOSeries = /^o[1-9]/.test(modelSlug);
|
|
870
|
+
const isOpenAIOnOpenRouter = isOpenRouter && activeModel.startsWith("openai/");
|
|
871
|
+
if (!this.config.disableThinking && this.isOpenAIReasoningModelOnOpenRouter(activeModel)) {
|
|
872
|
+
yield* this.streamWithResponsesAPI(request, activeModel, messageId);
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
875
|
+
const maxTokensValue = request.config?.maxTokens ?? this.config.maxTokens;
|
|
615
876
|
const payload = {
|
|
616
|
-
model:
|
|
877
|
+
model: activeModel,
|
|
617
878
|
messages,
|
|
618
879
|
tools: tools.length > 0 ? tools : void 0,
|
|
619
880
|
tool_choice: tools.length > 0 ? toolChoice : void 0,
|
|
620
881
|
parallel_tool_calls: tools.length > 0 ? openaiToolOptions?.parallelToolCalls : void 0,
|
|
621
|
-
temperature: request.config?.temperature ?? this.config.temperature,
|
|
622
|
-
max_tokens: request.config?.maxTokens ?? this.config.maxTokens,
|
|
623
882
|
stream: true,
|
|
624
|
-
stream_options: { include_usage: true }
|
|
883
|
+
stream_options: { include_usage: true },
|
|
884
|
+
// o-series: use max_completion_tokens + reasoning_effort, no temperature
|
|
885
|
+
// regular models: use max_tokens + temperature
|
|
886
|
+
...isOSeries ? {
|
|
887
|
+
max_completion_tokens: maxTokensValue,
|
|
888
|
+
reasoning_effort: request.config?.reasoningEffort ?? "medium"
|
|
889
|
+
} : {
|
|
890
|
+
temperature: request.config?.temperature ?? this.config.temperature,
|
|
891
|
+
max_tokens: maxTokensValue
|
|
892
|
+
},
|
|
893
|
+
// Non-OpenAI OpenRouter models support OR's reasoning/include_reasoning params.
|
|
894
|
+
// When disableThinking=true we must explicitly send include_reasoning:false because
|
|
895
|
+
// models like Qwen3 and DeepSeek-R1 reason by default even without the reasoning param.
|
|
896
|
+
...isOpenRouter && !isOpenAIOnOpenRouter ? this.config.disableThinking ? { include_reasoning: false } : { reasoning: { max_tokens: 8e3 }, include_reasoning: true } : {}
|
|
625
897
|
};
|
|
626
898
|
logProviderPayload("openai", "request payload", payload, request.debug);
|
|
627
899
|
const stream = await client.chat.completions.create(payload);
|
|
@@ -629,6 +901,7 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
629
901
|
const collectedCitations = [];
|
|
630
902
|
let citationIndex = 0;
|
|
631
903
|
let usage;
|
|
904
|
+
let adapterReasoningStarted = false;
|
|
632
905
|
for await (const chunk of stream) {
|
|
633
906
|
logProviderPayload("openai", "stream chunk", chunk, request.debug);
|
|
634
907
|
if (request.signal?.aborted) {
|
|
@@ -639,6 +912,22 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
639
912
|
if (delta?.content) {
|
|
640
913
|
yield { type: "message:delta", content: delta.content };
|
|
641
914
|
}
|
|
915
|
+
if (isOpenRouter) {
|
|
916
|
+
const rc = delta?.reasoning_content ?? delta?.reasoning ?? null;
|
|
917
|
+
if (rc) {
|
|
918
|
+
const rcText = typeof rc === "string" ? rc : Array.isArray(rc) && rc[0]?.text ? rc[0].text : "";
|
|
919
|
+
if (rcText) {
|
|
920
|
+
if (!adapterReasoningStarted) {
|
|
921
|
+
yield { type: "thinking:start" };
|
|
922
|
+
adapterReasoningStarted = true;
|
|
923
|
+
}
|
|
924
|
+
yield { type: "thinking:delta", content: rcText };
|
|
925
|
+
}
|
|
926
|
+
} else if (adapterReasoningStarted && (delta?.content || choice?.finish_reason)) {
|
|
927
|
+
yield { type: "thinking:end" };
|
|
928
|
+
adapterReasoningStarted = false;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
642
931
|
const annotations = delta?.annotations;
|
|
643
932
|
if (annotations && annotations.length > 0) {
|
|
644
933
|
for (const annotation of annotations) {
|
|
@@ -686,6 +975,11 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
686
975
|
};
|
|
687
976
|
} else if (currentToolCall && toolCall.function?.arguments) {
|
|
688
977
|
currentToolCall.arguments += toolCall.function.arguments;
|
|
978
|
+
yield {
|
|
979
|
+
type: "action:args",
|
|
980
|
+
id: currentToolCall.id,
|
|
981
|
+
args: currentToolCall.arguments
|
|
982
|
+
};
|
|
689
983
|
}
|
|
690
984
|
}
|
|
691
985
|
}
|
|
@@ -761,15 +1055,24 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
761
1055
|
name: openaiToolOptions.toolChoice.name
|
|
762
1056
|
}
|
|
763
1057
|
} : openaiToolOptions?.toolChoice;
|
|
1058
|
+
const activeModel2 = request.config?.model || this.model;
|
|
1059
|
+
const modelSlug2 = activeModel2.replace("openai/", "");
|
|
1060
|
+
const isOSeries2 = /^o[1-9]/.test(modelSlug2);
|
|
1061
|
+
const maxTokensValue2 = request.config?.maxTokens ?? this.config.maxTokens;
|
|
764
1062
|
const payload = {
|
|
765
|
-
model:
|
|
1063
|
+
model: activeModel2,
|
|
766
1064
|
messages,
|
|
767
1065
|
tools: tools.length > 0 ? tools : void 0,
|
|
768
1066
|
tool_choice: tools.length > 0 ? toolChoice : void 0,
|
|
769
1067
|
parallel_tool_calls: tools.length > 0 ? openaiToolOptions?.parallelToolCalls : void 0,
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
1068
|
+
stream: false,
|
|
1069
|
+
...isOSeries2 ? {
|
|
1070
|
+
max_completion_tokens: maxTokensValue2,
|
|
1071
|
+
reasoning_effort: request.config?.reasoningEffort ?? "medium"
|
|
1072
|
+
} : {
|
|
1073
|
+
temperature: request.config?.temperature ?? this.config.temperature,
|
|
1074
|
+
max_tokens: maxTokensValue2
|
|
1075
|
+
}
|
|
773
1076
|
};
|
|
774
1077
|
logProviderPayload("openai", "request payload", payload, request.debug);
|
|
775
1078
|
const response = await client.chat.completions.create(payload);
|
|
@@ -1279,6 +1582,13 @@ var AnthropicAdapter = class {
|
|
|
1279
1582
|
yield { type: "thinking:delta", content: event.delta.thinking };
|
|
1280
1583
|
} else if (event.delta.type === "input_json_delta" && currentToolUse) {
|
|
1281
1584
|
currentToolUse.input += event.delta.partial_json;
|
|
1585
|
+
if (currentToolUse.name !== "web_search") {
|
|
1586
|
+
yield {
|
|
1587
|
+
type: "action:args",
|
|
1588
|
+
id: currentToolUse.id,
|
|
1589
|
+
args: currentToolUse.input
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1282
1592
|
}
|
|
1283
1593
|
break;
|
|
1284
1594
|
case "content_block_stop":
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as TokenUsage } from './types-
|
|
1
|
+
import { t as TokenUsage } from './types-CMvvDo-E.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Stream event types for llm-sdk
|
|
@@ -537,6 +537,7 @@ interface RequestLLMConfig {
|
|
|
537
537
|
model?: string;
|
|
538
538
|
temperature?: number;
|
|
539
539
|
maxTokens?: number;
|
|
540
|
+
reasoningEffort?: "low" | "medium" | "high";
|
|
540
541
|
}
|
|
541
542
|
/**
|
|
542
543
|
* Chat completion request
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as TokenUsage } from './types-
|
|
1
|
+
import { t as TokenUsage } from './types-CMvvDo-E.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Stream event types for llm-sdk
|
|
@@ -537,6 +537,7 @@ interface RequestLLMConfig {
|
|
|
537
537
|
model?: string;
|
|
538
538
|
temperature?: number;
|
|
539
539
|
maxTokens?: number;
|
|
540
|
+
reasoningEffort?: "low" | "medium" | "high";
|
|
540
541
|
}
|
|
541
542
|
/**
|
|
542
543
|
* Chat completion request
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { L as LLMAdapter } from '../base-
|
|
2
|
-
import { F as FallbackChainConfig, c as FallbackFailure, R as RoutingStore } from '../types-
|
|
3
|
-
export { d as FallbackInfo, b as RetryBackoff, e as RetryInfo, a as RoutingStrategy } from '../types-
|
|
4
|
-
import '../types-
|
|
1
|
+
import { L as LLMAdapter } from '../base-DN1EfKnE.mjs';
|
|
2
|
+
import { F as FallbackChainConfig, c as FallbackFailure, R as RoutingStore } from '../types-BNCmlJMs.mjs';
|
|
3
|
+
export { d as FallbackInfo, b as RetryBackoff, e as RetryInfo, a as RoutingStrategy } from '../types-BNCmlJMs.mjs';
|
|
4
|
+
import '../types-CMvvDo-E.mjs';
|
|
5
5
|
import 'zod';
|
|
6
6
|
|
|
7
7
|
/**
|
package/dist/fallback/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { L as LLMAdapter } from '../base-
|
|
2
|
-
import { F as FallbackChainConfig, c as FallbackFailure, R as RoutingStore } from '../types-
|
|
3
|
-
export { d as FallbackInfo, b as RetryBackoff, e as RetryInfo, a as RoutingStrategy } from '../types-
|
|
4
|
-
import '../types-
|
|
1
|
+
import { L as LLMAdapter } from '../base-DuUNxtVg.js';
|
|
2
|
+
import { F as FallbackChainConfig, c as FallbackFailure, R as RoutingStore } from '../types-Pj-vpmoT.js';
|
|
3
|
+
export { d as FallbackInfo, b as RetryBackoff, e as RetryInfo, a as RoutingStrategy } from '../types-Pj-vpmoT.js';
|
|
4
|
+
import '../types-CMvvDo-E.js';
|
|
5
5
|
import 'zod';
|
|
6
6
|
|
|
7
7
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { G as GenerateTextParams, a as GenerateTextResult, S as StreamTextParams, b as StreamTextResult, T as ToolContext, c as Tool, d as StorageAdapter, e as StorageMessage } from './types-
|
|
2
|
-
export { A as AssistantMessage, C as CoreMessage, w as DEFAULT_CAPABILITIES, D as DoGenerateParams, f as DoGenerateResult, E as ErrorChunk, F as FilePart, s as FinishChunk, u as FinishReason, m as GenerateStep, I as ImagePart, L as LanguageModel, M as ModelCapabilities, R as ResponseOptions, v as StorageFile, o as StreamChunk, n as StreamPart, g as SystemMessage, p as TextDeltaChunk, j as TextPart, t as TokenUsage, k as ToolCall, q as ToolCallChunk, h as ToolMessage, l as ToolResult, r as ToolResultChunk, i as UserContentPart, U as UserMessage } from './types-
|
|
1
|
+
import { G as GenerateTextParams, a as GenerateTextResult, S as StreamTextParams, b as StreamTextResult, T as ToolContext, c as Tool, d as StorageAdapter, e as StorageMessage } from './types-CMvvDo-E.mjs';
|
|
2
|
+
export { A as AssistantMessage, C as CoreMessage, w as DEFAULT_CAPABILITIES, D as DoGenerateParams, f as DoGenerateResult, E as ErrorChunk, F as FilePart, s as FinishChunk, u as FinishReason, m as GenerateStep, I as ImagePart, L as LanguageModel, M as ModelCapabilities, R as ResponseOptions, v as StorageFile, o as StreamChunk, n as StreamPart, g as SystemMessage, p as TextDeltaChunk, j as TextPart, t as TokenUsage, k as ToolCall, q as ToolCallChunk, h as ToolMessage, l as ToolResult, r as ToolResultChunk, i as UserContentPart, U as UserMessage } from './types-CMvvDo-E.mjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { A as ActionDefinition, T as ToolDefinition, a as ToolProfile, K as KnowledgeBaseConfig, W as WebSearchConfig, L as LLMAdapter, D as DoneEventMessage, S as StreamEvent, b as ToolCallInfo, c as TokenUsageRaw, P as ProviderToolRuntimeOptions, M as Message, d as ToolResponse } from './base-
|
|
5
|
-
export { e as AdapterFactory, m as AnthropicProviderToolOptions, j as AnthropicToolSelectionHints, C as ChatCompletionRequest, n as Citation, f as LLMConfig, l as OpenAIProviderToolOptions, O as OpenAIToolSelectionHints, i as ToolExecution, g as ToolLocation, k as ToolNativeProviderHints, U as UnifiedToolCall, h as UnifiedToolResult } from './base-
|
|
6
|
-
import { A as AIProvider } from './types-
|
|
7
|
-
export { a as AnthropicProviderConfig, f as AnthropicTool, h as AnthropicToolResult, g as AnthropicToolUse, b as AzureProviderConfig, B as BaseProviderConfig, m as GeminiFunctionCall, l as GeminiFunctionDeclaration, n as GeminiFunctionResponse, G as GoogleProviderConfig, d as OllamaModelOptions, c as OllamaProviderConfig, O as OpenAIProviderConfig, i as OpenAITool, j as OpenAIToolCall, k as OpenAIToolResult, P as ProviderCapabilities, e as ProviderFormatter, X as XAIProviderConfig } from './types-
|
|
4
|
+
import { A as ActionDefinition, T as ToolDefinition, a as ToolProfile, K as KnowledgeBaseConfig, W as WebSearchConfig, L as LLMAdapter, D as DoneEventMessage, S as StreamEvent, b as ToolCallInfo, c as TokenUsageRaw, P as ProviderToolRuntimeOptions, M as Message, d as ToolResponse } from './base-DN1EfKnE.mjs';
|
|
5
|
+
export { e as AdapterFactory, m as AnthropicProviderToolOptions, j as AnthropicToolSelectionHints, C as ChatCompletionRequest, n as Citation, f as LLMConfig, l as OpenAIProviderToolOptions, O as OpenAIToolSelectionHints, i as ToolExecution, g as ToolLocation, k as ToolNativeProviderHints, U as UnifiedToolCall, h as UnifiedToolResult } from './base-DN1EfKnE.mjs';
|
|
6
|
+
import { A as AIProvider } from './types-CMMQ8s2O.mjs';
|
|
7
|
+
export { a as AnthropicProviderConfig, f as AnthropicTool, h as AnthropicToolResult, g as AnthropicToolUse, b as AzureProviderConfig, B as BaseProviderConfig, m as GeminiFunctionCall, l as GeminiFunctionDeclaration, n as GeminiFunctionResponse, G as GoogleProviderConfig, d as OllamaModelOptions, c as OllamaProviderConfig, O as OpenAIProviderConfig, i as OpenAITool, j as OpenAIToolCall, k as OpenAIToolResult, P as ProviderCapabilities, e as ProviderFormatter, X as XAIProviderConfig } from './types-CMMQ8s2O.mjs';
|
|
8
8
|
import * as hono from 'hono';
|
|
9
9
|
import { Hono } from 'hono';
|
|
10
|
-
export { F as FallbackChainConfig, c as FallbackFailure, d as FallbackInfo, b as RetryBackoff, e as RetryInfo, R as RoutingStore, a as RoutingStrategy } from './types-
|
|
10
|
+
export { F as FallbackChainConfig, c as FallbackFailure, d as FallbackInfo, b as RetryBackoff, e as RetryInfo, R as RoutingStore, a as RoutingStrategy } from './types-BNCmlJMs.mjs';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* generateText - Generate text using a language model
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { G as GenerateTextParams, a as GenerateTextResult, S as StreamTextParams, b as StreamTextResult, T as ToolContext, c as Tool, d as StorageAdapter, e as StorageMessage } from './types-
|
|
2
|
-
export { A as AssistantMessage, C as CoreMessage, w as DEFAULT_CAPABILITIES, D as DoGenerateParams, f as DoGenerateResult, E as ErrorChunk, F as FilePart, s as FinishChunk, u as FinishReason, m as GenerateStep, I as ImagePart, L as LanguageModel, M as ModelCapabilities, R as ResponseOptions, v as StorageFile, o as StreamChunk, n as StreamPart, g as SystemMessage, p as TextDeltaChunk, j as TextPart, t as TokenUsage, k as ToolCall, q as ToolCallChunk, h as ToolMessage, l as ToolResult, r as ToolResultChunk, i as UserContentPart, U as UserMessage } from './types-
|
|
1
|
+
import { G as GenerateTextParams, a as GenerateTextResult, S as StreamTextParams, b as StreamTextResult, T as ToolContext, c as Tool, d as StorageAdapter, e as StorageMessage } from './types-CMvvDo-E.js';
|
|
2
|
+
export { A as AssistantMessage, C as CoreMessage, w as DEFAULT_CAPABILITIES, D as DoGenerateParams, f as DoGenerateResult, E as ErrorChunk, F as FilePart, s as FinishChunk, u as FinishReason, m as GenerateStep, I as ImagePart, L as LanguageModel, M as ModelCapabilities, R as ResponseOptions, v as StorageFile, o as StreamChunk, n as StreamPart, g as SystemMessage, p as TextDeltaChunk, j as TextPart, t as TokenUsage, k as ToolCall, q as ToolCallChunk, h as ToolMessage, l as ToolResult, r as ToolResultChunk, i as UserContentPart, U as UserMessage } from './types-CMvvDo-E.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { A as ActionDefinition, T as ToolDefinition, a as ToolProfile, K as KnowledgeBaseConfig, W as WebSearchConfig, L as LLMAdapter, D as DoneEventMessage, S as StreamEvent, b as ToolCallInfo, c as TokenUsageRaw, P as ProviderToolRuntimeOptions, M as Message, d as ToolResponse } from './base-
|
|
5
|
-
export { e as AdapterFactory, m as AnthropicProviderToolOptions, j as AnthropicToolSelectionHints, C as ChatCompletionRequest, n as Citation, f as LLMConfig, l as OpenAIProviderToolOptions, O as OpenAIToolSelectionHints, i as ToolExecution, g as ToolLocation, k as ToolNativeProviderHints, U as UnifiedToolCall, h as UnifiedToolResult } from './base-
|
|
6
|
-
import { A as AIProvider } from './types-
|
|
7
|
-
export { a as AnthropicProviderConfig, f as AnthropicTool, h as AnthropicToolResult, g as AnthropicToolUse, b as AzureProviderConfig, B as BaseProviderConfig, m as GeminiFunctionCall, l as GeminiFunctionDeclaration, n as GeminiFunctionResponse, G as GoogleProviderConfig, d as OllamaModelOptions, c as OllamaProviderConfig, O as OpenAIProviderConfig, i as OpenAITool, j as OpenAIToolCall, k as OpenAIToolResult, P as ProviderCapabilities, e as ProviderFormatter, X as XAIProviderConfig } from './types-
|
|
4
|
+
import { A as ActionDefinition, T as ToolDefinition, a as ToolProfile, K as KnowledgeBaseConfig, W as WebSearchConfig, L as LLMAdapter, D as DoneEventMessage, S as StreamEvent, b as ToolCallInfo, c as TokenUsageRaw, P as ProviderToolRuntimeOptions, M as Message, d as ToolResponse } from './base-DuUNxtVg.js';
|
|
5
|
+
export { e as AdapterFactory, m as AnthropicProviderToolOptions, j as AnthropicToolSelectionHints, C as ChatCompletionRequest, n as Citation, f as LLMConfig, l as OpenAIProviderToolOptions, O as OpenAIToolSelectionHints, i as ToolExecution, g as ToolLocation, k as ToolNativeProviderHints, U as UnifiedToolCall, h as UnifiedToolResult } from './base-DuUNxtVg.js';
|
|
6
|
+
import { A as AIProvider } from './types-DhktekQ3.js';
|
|
7
|
+
export { a as AnthropicProviderConfig, f as AnthropicTool, h as AnthropicToolResult, g as AnthropicToolUse, b as AzureProviderConfig, B as BaseProviderConfig, m as GeminiFunctionCall, l as GeminiFunctionDeclaration, n as GeminiFunctionResponse, G as GoogleProviderConfig, d as OllamaModelOptions, c as OllamaProviderConfig, O as OpenAIProviderConfig, i as OpenAITool, j as OpenAIToolCall, k as OpenAIToolResult, P as ProviderCapabilities, e as ProviderFormatter, X as XAIProviderConfig } from './types-DhktekQ3.js';
|
|
8
8
|
import * as hono from 'hono';
|
|
9
9
|
import { Hono } from 'hono';
|
|
10
|
-
export { F as FallbackChainConfig, c as FallbackFailure, d as FallbackInfo, b as RetryBackoff, e as RetryInfo, R as RoutingStore, a as RoutingStrategy } from './types-
|
|
10
|
+
export { F as FallbackChainConfig, c as FallbackFailure, d as FallbackInfo, b as RetryBackoff, e as RetryInfo, R as RoutingStore, a as RoutingStrategy } from './types-Pj-vpmoT.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* generateText - Generate text using a language model
|
package/dist/index.js
CHANGED
|
@@ -299,6 +299,20 @@ async function streamText(params) {
|
|
|
299
299
|
fullText += chunk.text;
|
|
300
300
|
yield { type: "text-delta", text: chunk.text };
|
|
301
301
|
break;
|
|
302
|
+
case "tool-call-start":
|
|
303
|
+
yield {
|
|
304
|
+
type: "tool-call-start",
|
|
305
|
+
toolCallId: chunk.toolCallId,
|
|
306
|
+
toolName: chunk.toolName
|
|
307
|
+
};
|
|
308
|
+
break;
|
|
309
|
+
case "tool-call-delta":
|
|
310
|
+
yield {
|
|
311
|
+
type: "tool-call-delta",
|
|
312
|
+
toolCallId: chunk.toolCallId,
|
|
313
|
+
argsText: chunk.argsText
|
|
314
|
+
};
|
|
315
|
+
break;
|
|
302
316
|
case "tool-call":
|
|
303
317
|
toolCalls.push(chunk.toolCall);
|
|
304
318
|
yield {
|
|
@@ -1597,7 +1611,7 @@ var Runtime = class {
|
|
|
1597
1611
|
const completionRequest = {
|
|
1598
1612
|
messages,
|
|
1599
1613
|
actions: allActions.length > 0 ? allActions : void 0,
|
|
1600
|
-
systemPrompt:
|
|
1614
|
+
systemPrompt: this.config.systemPrompt ?? request.systemPrompt,
|
|
1601
1615
|
config: request.config,
|
|
1602
1616
|
signal,
|
|
1603
1617
|
webSearch: this.getWebSearchConfig(),
|
|
@@ -2161,7 +2175,7 @@ var Runtime = class {
|
|
|
2161
2175
|
}
|
|
2162
2176
|
}
|
|
2163
2177
|
}
|
|
2164
|
-
const systemPrompt =
|
|
2178
|
+
const systemPrompt = this.config.systemPrompt ?? request.systemPrompt ?? "";
|
|
2165
2179
|
let accumulatedText = "";
|
|
2166
2180
|
const toolCalls = [];
|
|
2167
2181
|
let currentToolCall = null;
|
|
@@ -2208,38 +2222,44 @@ var Runtime = class {
|
|
|
2208
2222
|
break;
|
|
2209
2223
|
case "action:args":
|
|
2210
2224
|
if (currentToolCall) {
|
|
2225
|
+
currentToolCall.args = event.args || currentToolCall.args;
|
|
2211
2226
|
try {
|
|
2212
|
-
const parsedArgs = JSON.parse(
|
|
2227
|
+
const parsedArgs = JSON.parse(currentToolCall.args || "{}");
|
|
2228
|
+
const existingIdx = toolCalls.findIndex(
|
|
2229
|
+
(t) => t.id === currentToolCall.id
|
|
2230
|
+
);
|
|
2231
|
+
const entry = {
|
|
2232
|
+
id: currentToolCall.id,
|
|
2233
|
+
name: currentToolCall.name,
|
|
2234
|
+
args: parsedArgs,
|
|
2235
|
+
...currentToolCall.extra_content ? { extra_content: currentToolCall.extra_content } : {}
|
|
2236
|
+
};
|
|
2237
|
+
if (existingIdx >= 0) {
|
|
2238
|
+
toolCalls[existingIdx] = entry;
|
|
2239
|
+
} else {
|
|
2240
|
+
toolCalls.push(entry);
|
|
2241
|
+
}
|
|
2213
2242
|
if (debug) {
|
|
2214
2243
|
console.log(
|
|
2215
2244
|
`[Copilot SDK] Tool args for ${currentToolCall.name}:`,
|
|
2216
2245
|
parsedArgs
|
|
2217
2246
|
);
|
|
2218
2247
|
}
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
event.args,
|
|
2229
|
-
e
|
|
2230
|
-
);
|
|
2231
|
-
toolCalls.push({
|
|
2232
|
-
id: currentToolCall.id,
|
|
2233
|
-
name: currentToolCall.name,
|
|
2234
|
-
args: {},
|
|
2235
|
-
...currentToolCall.extra_content ? { extra_content: currentToolCall.extra_content } : {}
|
|
2236
|
-
});
|
|
2248
|
+
} catch {
|
|
2249
|
+
if (!toolCalls.find((t) => t.id === currentToolCall.id)) {
|
|
2250
|
+
toolCalls.push({
|
|
2251
|
+
id: currentToolCall.id,
|
|
2252
|
+
name: currentToolCall.name,
|
|
2253
|
+
args: {},
|
|
2254
|
+
...currentToolCall.extra_content ? { extra_content: currentToolCall.extra_content } : {}
|
|
2255
|
+
});
|
|
2256
|
+
}
|
|
2237
2257
|
}
|
|
2238
|
-
currentToolCall = null;
|
|
2239
2258
|
}
|
|
2240
2259
|
yield event;
|
|
2241
2260
|
break;
|
|
2242
2261
|
case "action:end": {
|
|
2262
|
+
currentToolCall = null;
|
|
2243
2263
|
const toolName = event.name;
|
|
2244
2264
|
const tool2 = toolName ? selectedToolMap.get(toolName) : void 0;
|
|
2245
2265
|
if (tool2?.location === "server" && tool2.handler) {
|
|
@@ -2449,7 +2469,7 @@ var Runtime = class {
|
|
|
2449
2469
|
const allTools = this.collectToolsForRequest(request);
|
|
2450
2470
|
const nativeToolSearch = this.resolveNativeToolSearchForRequest(request);
|
|
2451
2471
|
let toolSearchState = _toolSearchState;
|
|
2452
|
-
const systemPrompt =
|
|
2472
|
+
const systemPrompt = this.config.systemPrompt ?? request.systemPrompt ?? "";
|
|
2453
2473
|
let iteration = 0;
|
|
2454
2474
|
let conversationMessages = request.messages;
|
|
2455
2475
|
while (iteration < maxIterations) {
|