graphlit-client 1.0.20260626004 ā 1.0.20260626005
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/client.js +24 -5
- package/dist/streaming/providers.js +6 -1
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -21,7 +21,7 @@ class StreamingLoopPartialError extends Error {
|
|
|
21
21
|
import { StuckDetector } from "./helpers/stuck-detector.js";
|
|
22
22
|
import { TurnEvaluator } from "./helpers/turn-evaluator.js";
|
|
23
23
|
import { TokenBudgetTracker, truncateToolResult, windowToolRounds, estimateTokens, DEFAULT_CONTEXT_STRATEGY, } from "./helpers/context-management.js";
|
|
24
|
-
import { assertRequiredToolChoiceConfig, deriveProviderToolChoicePolicy, normalizeToolVisibilityResult, toAnthropicToolChoice, toGoogleToolConfig, toOpenAIChatToolChoice, toOpenAIResponsesToolChoice, validateRequiredToolChoice, } from "./helpers/tool-visibility.js";
|
|
24
|
+
import { assertRequiredToolChoiceConfig, deriveProviderToolChoicePolicy, normalizeToolVisibilityResult, RequiredToolChoiceError, toAnthropicToolChoice, toGoogleToolConfig, toOpenAIChatToolChoice, toOpenAIResponsesToolChoice, validateRequiredToolChoice, } from "./helpers/tool-visibility.js";
|
|
25
25
|
import { isRetryableGraphQLTransportError, ProviderError, } from "./types/internal.js";
|
|
26
26
|
import { UIEventAdapter } from "./streaming/ui-event-adapter.js";
|
|
27
27
|
import { formatMessagesForOpenAI, formatMessagesForOpenAIResponsesInitialRound, extractInstructionsForOpenAIResponses, extractSystemInstructionParts, buildResponsesFunctionCallOutputItems, formatToolsForOpenAIResponses, formatMessagesForAnthropic, formatMessagesForGoogle, formatMessagesForMistral, formatMessagesForBedrock, } from "./streaming/llm-formatters.js";
|
|
@@ -143,6 +143,15 @@ function normalizeToolCallForExecution(toolCall) {
|
|
|
143
143
|
firstStatusAt: toolCall.firstStatusAt ?? undefined,
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
|
+
function cloneOpenAIResponsesInvocationState(state) {
|
|
147
|
+
if (!state)
|
|
148
|
+
return undefined;
|
|
149
|
+
return {
|
|
150
|
+
instructions: state.instructions,
|
|
151
|
+
initialInput: [...state.initialInput],
|
|
152
|
+
continuationItems: [...state.continuationItems],
|
|
153
|
+
};
|
|
154
|
+
}
|
|
146
155
|
// Default eligible OpenAI GPT-5.4+ models to Responses. Explicit
|
|
147
156
|
// `useResponsesApi: false` still forces legacy Chat Completions.
|
|
148
157
|
const OPENAI_RESPONSES_AUTO_ROUTING_ENABLED = true;
|
|
@@ -6678,6 +6687,7 @@ class Graphlit {
|
|
|
6678
6687
|
roundMessage = "";
|
|
6679
6688
|
roundReasoning = undefined;
|
|
6680
6689
|
roundUsage = undefined;
|
|
6690
|
+
const preAttemptOpenAIResponsesState = cloneOpenAIResponsesInvocationState(openAIResponsesState);
|
|
6681
6691
|
try {
|
|
6682
6692
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
|
6683
6693
|
console.log(`\nš [Streaming Decision] Service: ${serviceType}, Round: ${currentRound}${providerAttempt > 0 ? `, Retry: ${providerAttempt}` : ""}`);
|
|
@@ -6701,10 +6711,7 @@ class Graphlit {
|
|
|
6701
6711
|
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING_MESSAGES) {
|
|
6702
6712
|
console.log(`š [OpenAI Responses] Sending ${openAIResponsesState.initialInput.length} initial items and ${openAIResponsesState.continuationItems.length} continuation items`);
|
|
6703
6713
|
}
|
|
6704
|
-
const responsesResult = await this.streamWithOpenAIResponses(specification, messages, openAIResponsesPendingToolMessages, visibleToolsForCurrentRound, uiAdapter, abortSignal, openAIResponsesState, toOpenAIResponsesToolChoice(providerToolChoicePolicy)
|
|
6705
|
-
(currentRound === 0 && visibleToolsForCurrentRound?.length
|
|
6706
|
-
? "required"
|
|
6707
|
-
: undefined));
|
|
6714
|
+
const responsesResult = await this.streamWithOpenAIResponses(specification, messages, openAIResponsesPendingToolMessages, visibleToolsForCurrentRound, uiAdapter, abortSignal, openAIResponsesState, toOpenAIResponsesToolChoice(providerToolChoicePolicy));
|
|
6708
6715
|
roundMessage = responsesResult.message;
|
|
6709
6716
|
toolCalls = responsesResult.toolCalls;
|
|
6710
6717
|
openAIResponsesState = responsesResult.state;
|
|
@@ -6981,6 +6988,17 @@ class Graphlit {
|
|
|
6981
6988
|
catch (retryError) {
|
|
6982
6989
|
if (abortSignal?.aborted)
|
|
6983
6990
|
throw retryError;
|
|
6991
|
+
if (retryError instanceof RequiredToolChoiceError) {
|
|
6992
|
+
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
|
6993
|
+
console.log(`\nš [Required Tool] ${retryError.message} Re-asking round ${currentRound} with the same visibility policy (attempt ${providerAttempt + 1}/${DEFAULT_PROVIDER_RETRIES + 1}).`);
|
|
6994
|
+
}
|
|
6995
|
+
uiAdapter.resetForRetry(preRoundMessage);
|
|
6996
|
+
openAIResponsesState = cloneOpenAIResponsesInvocationState(preAttemptOpenAIResponsesState);
|
|
6997
|
+
if (providerAttempt >= DEFAULT_PROVIDER_RETRIES) {
|
|
6998
|
+
throwWithPartialResult(retryError);
|
|
6999
|
+
}
|
|
7000
|
+
continue;
|
|
7001
|
+
}
|
|
6984
7002
|
const isRetryable = retryError instanceof ProviderError && retryError.retryable;
|
|
6985
7003
|
if (isRetryable &&
|
|
6986
7004
|
providerAttempt >= DEFAULT_PROVIDER_RETRIES &&
|
|
@@ -7002,6 +7020,7 @@ class Graphlit {
|
|
|
7002
7020
|
}
|
|
7003
7021
|
// Reset adapter to pre-round state so partial tokens are cleared
|
|
7004
7022
|
uiAdapter.resetForRetry(preRoundMessage);
|
|
7023
|
+
openAIResponsesState = cloneOpenAIResponsesInvocationState(preAttemptOpenAIResponsesState);
|
|
7005
7024
|
await new Promise((resolve) => setTimeout(resolve, totalDelay));
|
|
7006
7025
|
}
|
|
7007
7026
|
} // end retry for-loop
|
|
@@ -545,7 +545,12 @@ onEvent, onComplete, abortSignal, thinkingConfig, toolChoice) {
|
|
|
545
545
|
...streamConfig.tools[streamConfig.tools.length - 1],
|
|
546
546
|
cache_control: { type: "ephemeral" },
|
|
547
547
|
};
|
|
548
|
-
if (toolChoice) {
|
|
548
|
+
if (toolChoice && thinkingConfig) {
|
|
549
|
+
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
|
550
|
+
console.log("š§ [Anthropic] Skipping native tool_choice because thinking is enabled; required tool policy will be validated after the response.");
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
else if (toolChoice) {
|
|
549
554
|
streamConfig.tool_choice = toolChoice;
|
|
550
555
|
}
|
|
551
556
|
}
|