@yuva-devlab/ai-client 0.3.0 → 0.4.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/index.cjs +69 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +69 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -519,6 +519,10 @@ type LLMResponse = z.infer<typeof LLMResponseSchema>;
|
|
|
519
519
|
interface LLMStreamChunk {
|
|
520
520
|
/** Delta text token */
|
|
521
521
|
delta: string;
|
|
522
|
+
/** Optional reasoning or thinking delta emitted by reasoning-capable models */
|
|
523
|
+
reasoningDelta?: string;
|
|
524
|
+
/** Optional tool invocations emitted during streaming */
|
|
525
|
+
toolCalls?: ToolCall[];
|
|
522
526
|
/** Finish reason if this chunk is the final stream message */
|
|
523
527
|
finishReason?: FinishReason;
|
|
524
528
|
/** Cumulative token usage if supplied by the provider */
|
|
@@ -679,6 +683,7 @@ interface OllamaAdapterConfig {
|
|
|
679
683
|
interface OllamaWireMessage {
|
|
680
684
|
role: string;
|
|
681
685
|
content: string;
|
|
686
|
+
thinking?: string;
|
|
682
687
|
tool_name?: string;
|
|
683
688
|
}
|
|
684
689
|
/**
|
|
@@ -867,6 +872,7 @@ interface GeminiCandidate {
|
|
|
867
872
|
content?: {
|
|
868
873
|
parts?: Array<{
|
|
869
874
|
text?: string;
|
|
875
|
+
thought?: boolean;
|
|
870
876
|
}>;
|
|
871
877
|
};
|
|
872
878
|
finishReason?: string;
|
|
@@ -886,6 +892,13 @@ interface GeminiResponse {
|
|
|
886
892
|
* @returns JSON-serializable Gemini request body.
|
|
887
893
|
*/
|
|
888
894
|
declare function buildGeminiRequestBody(request: LLMRequest): Record<string, unknown>;
|
|
895
|
+
/**
|
|
896
|
+
* Parses a single Google Gemini SSE data payload into a normalized stream chunk.
|
|
897
|
+
*
|
|
898
|
+
* @param jsonStr - Raw JSON payload stripped of the SSE `data:` prefix.
|
|
899
|
+
* @returns Normalized stream chunk when content/reasoning/usage is present, or `null`.
|
|
900
|
+
*/
|
|
901
|
+
declare function parseGeminiSseChunk(jsonStr: string): LLMStreamChunk | null;
|
|
889
902
|
|
|
890
903
|
/**
|
|
891
904
|
* @file packages/ai-client/src/adapters/google/google.adapter.ts
|
|
@@ -1403,4 +1416,4 @@ interface DefaultProviderOptions {
|
|
|
1403
1416
|
*/
|
|
1404
1417
|
declare function createDefaultProvider(options?: DefaultProviderOptions): ILLMProvider;
|
|
1405
1418
|
|
|
1406
|
-
export { type AIMessage, AIMessageSchema, AI_DEFAULT_MODELS, AI_ENDPOINTS, AI_EXECUTION_DEFAULTS, AnthropicAdapter, type AnthropicAdapterConfig, type AnthropicResponse, type CascadeCandidatesConfig, ClineAdapter, type ClineAdapterConfig, type ClineCompletionResponse, type CredentialResolver, type DefaultProviderOptions, type ExtractStructuredOutputOptions, FallbackCascade, type FallbackCascadeOptions, FinishReason, type GeminiCandidate, type GeminiResponse, GoogleAdapter, type GoogleAdapterConfig, GroqAdapter, type GroqAdapterConfig, type GroqCompletionResponse, type ILLMProvider, type LLMRequest, type LLMRequestOptions, LLMRequestOptionsSchema, LLMRequestSchema, type LLMResponse, LLMResponseSchema, type LLMStreamChunk, type LLMUsage, LLMUsageSchema, MessageRole, MissingCredentialError, OllamaAdapter, type OllamaAdapterConfig, type OllamaChatResponseChunk, type OllamaWireMessage, OpenAIAdapter, type OpenAIAdapterConfig, type OpenAiCompletionResponse, type OpenAiWireMessage, type ProviderCredentials, type ProviderType, type ToolCall, ToolCallSchema, buildGeminiRequestBody, createAssistantMessage, createCascadeCandidates, createDefaultProvider, createProvider, createSystemMessage, createToolResultMessage, createUserMessage, extractAnthropicSystemAndMessages, extractClineRetrySuffix, extractClineToolCalls, extractStructuredOutput, mapClineFinishReason, mapClineMessages, mapGroqMessages, mapOllamaMessages, mapOpenAiMessages, resolveEnvCredentials, restoreClineToolName, sanitizeClineToolName };
|
|
1419
|
+
export { type AIMessage, AIMessageSchema, AI_DEFAULT_MODELS, AI_ENDPOINTS, AI_EXECUTION_DEFAULTS, AnthropicAdapter, type AnthropicAdapterConfig, type AnthropicResponse, type CascadeCandidatesConfig, ClineAdapter, type ClineAdapterConfig, type ClineCompletionResponse, type CredentialResolver, type DefaultProviderOptions, type ExtractStructuredOutputOptions, FallbackCascade, type FallbackCascadeOptions, FinishReason, type GeminiCandidate, type GeminiResponse, GoogleAdapter, type GoogleAdapterConfig, GroqAdapter, type GroqAdapterConfig, type GroqCompletionResponse, type ILLMProvider, type LLMRequest, type LLMRequestOptions, LLMRequestOptionsSchema, LLMRequestSchema, type LLMResponse, LLMResponseSchema, type LLMStreamChunk, type LLMUsage, LLMUsageSchema, MessageRole, MissingCredentialError, OllamaAdapter, type OllamaAdapterConfig, type OllamaChatResponseChunk, type OllamaWireMessage, OpenAIAdapter, type OpenAIAdapterConfig, type OpenAiCompletionResponse, type OpenAiWireMessage, type ProviderCredentials, type ProviderType, type ToolCall, ToolCallSchema, buildGeminiRequestBody, createAssistantMessage, createCascadeCandidates, createDefaultProvider, createProvider, createSystemMessage, createToolResultMessage, createUserMessage, extractAnthropicSystemAndMessages, extractClineRetrySuffix, extractClineToolCalls, extractStructuredOutput, mapClineFinishReason, mapClineMessages, mapGroqMessages, mapOllamaMessages, mapOpenAiMessages, parseGeminiSseChunk, resolveEnvCredentials, restoreClineToolName, sanitizeClineToolName };
|
package/dist/index.d.ts
CHANGED
|
@@ -519,6 +519,10 @@ type LLMResponse = z.infer<typeof LLMResponseSchema>;
|
|
|
519
519
|
interface LLMStreamChunk {
|
|
520
520
|
/** Delta text token */
|
|
521
521
|
delta: string;
|
|
522
|
+
/** Optional reasoning or thinking delta emitted by reasoning-capable models */
|
|
523
|
+
reasoningDelta?: string;
|
|
524
|
+
/** Optional tool invocations emitted during streaming */
|
|
525
|
+
toolCalls?: ToolCall[];
|
|
522
526
|
/** Finish reason if this chunk is the final stream message */
|
|
523
527
|
finishReason?: FinishReason;
|
|
524
528
|
/** Cumulative token usage if supplied by the provider */
|
|
@@ -679,6 +683,7 @@ interface OllamaAdapterConfig {
|
|
|
679
683
|
interface OllamaWireMessage {
|
|
680
684
|
role: string;
|
|
681
685
|
content: string;
|
|
686
|
+
thinking?: string;
|
|
682
687
|
tool_name?: string;
|
|
683
688
|
}
|
|
684
689
|
/**
|
|
@@ -867,6 +872,7 @@ interface GeminiCandidate {
|
|
|
867
872
|
content?: {
|
|
868
873
|
parts?: Array<{
|
|
869
874
|
text?: string;
|
|
875
|
+
thought?: boolean;
|
|
870
876
|
}>;
|
|
871
877
|
};
|
|
872
878
|
finishReason?: string;
|
|
@@ -886,6 +892,13 @@ interface GeminiResponse {
|
|
|
886
892
|
* @returns JSON-serializable Gemini request body.
|
|
887
893
|
*/
|
|
888
894
|
declare function buildGeminiRequestBody(request: LLMRequest): Record<string, unknown>;
|
|
895
|
+
/**
|
|
896
|
+
* Parses a single Google Gemini SSE data payload into a normalized stream chunk.
|
|
897
|
+
*
|
|
898
|
+
* @param jsonStr - Raw JSON payload stripped of the SSE `data:` prefix.
|
|
899
|
+
* @returns Normalized stream chunk when content/reasoning/usage is present, or `null`.
|
|
900
|
+
*/
|
|
901
|
+
declare function parseGeminiSseChunk(jsonStr: string): LLMStreamChunk | null;
|
|
889
902
|
|
|
890
903
|
/**
|
|
891
904
|
* @file packages/ai-client/src/adapters/google/google.adapter.ts
|
|
@@ -1403,4 +1416,4 @@ interface DefaultProviderOptions {
|
|
|
1403
1416
|
*/
|
|
1404
1417
|
declare function createDefaultProvider(options?: DefaultProviderOptions): ILLMProvider;
|
|
1405
1418
|
|
|
1406
|
-
export { type AIMessage, AIMessageSchema, AI_DEFAULT_MODELS, AI_ENDPOINTS, AI_EXECUTION_DEFAULTS, AnthropicAdapter, type AnthropicAdapterConfig, type AnthropicResponse, type CascadeCandidatesConfig, ClineAdapter, type ClineAdapterConfig, type ClineCompletionResponse, type CredentialResolver, type DefaultProviderOptions, type ExtractStructuredOutputOptions, FallbackCascade, type FallbackCascadeOptions, FinishReason, type GeminiCandidate, type GeminiResponse, GoogleAdapter, type GoogleAdapterConfig, GroqAdapter, type GroqAdapterConfig, type GroqCompletionResponse, type ILLMProvider, type LLMRequest, type LLMRequestOptions, LLMRequestOptionsSchema, LLMRequestSchema, type LLMResponse, LLMResponseSchema, type LLMStreamChunk, type LLMUsage, LLMUsageSchema, MessageRole, MissingCredentialError, OllamaAdapter, type OllamaAdapterConfig, type OllamaChatResponseChunk, type OllamaWireMessage, OpenAIAdapter, type OpenAIAdapterConfig, type OpenAiCompletionResponse, type OpenAiWireMessage, type ProviderCredentials, type ProviderType, type ToolCall, ToolCallSchema, buildGeminiRequestBody, createAssistantMessage, createCascadeCandidates, createDefaultProvider, createProvider, createSystemMessage, createToolResultMessage, createUserMessage, extractAnthropicSystemAndMessages, extractClineRetrySuffix, extractClineToolCalls, extractStructuredOutput, mapClineFinishReason, mapClineMessages, mapGroqMessages, mapOllamaMessages, mapOpenAiMessages, resolveEnvCredentials, restoreClineToolName, sanitizeClineToolName };
|
|
1419
|
+
export { type AIMessage, AIMessageSchema, AI_DEFAULT_MODELS, AI_ENDPOINTS, AI_EXECUTION_DEFAULTS, AnthropicAdapter, type AnthropicAdapterConfig, type AnthropicResponse, type CascadeCandidatesConfig, ClineAdapter, type ClineAdapterConfig, type ClineCompletionResponse, type CredentialResolver, type DefaultProviderOptions, type ExtractStructuredOutputOptions, FallbackCascade, type FallbackCascadeOptions, FinishReason, type GeminiCandidate, type GeminiResponse, GoogleAdapter, type GoogleAdapterConfig, GroqAdapter, type GroqAdapterConfig, type GroqCompletionResponse, type ILLMProvider, type LLMRequest, type LLMRequestOptions, LLMRequestOptionsSchema, LLMRequestSchema, type LLMResponse, LLMResponseSchema, type LLMStreamChunk, type LLMUsage, LLMUsageSchema, MessageRole, MissingCredentialError, OllamaAdapter, type OllamaAdapterConfig, type OllamaChatResponseChunk, type OllamaWireMessage, OpenAIAdapter, type OpenAIAdapterConfig, type OpenAiCompletionResponse, type OpenAiWireMessage, type ProviderCredentials, type ProviderType, type ToolCall, ToolCallSchema, buildGeminiRequestBody, createAssistantMessage, createCascadeCandidates, createDefaultProvider, createProvider, createSystemMessage, createToolResultMessage, createUserMessage, extractAnthropicSystemAndMessages, extractClineRetrySuffix, extractClineToolCalls, extractStructuredOutput, mapClineFinishReason, mapClineMessages, mapGroqMessages, mapOllamaMessages, mapOpenAiMessages, parseGeminiSseChunk, resolveEnvCredentials, restoreClineToolName, sanitizeClineToolName };
|
package/dist/index.js
CHANGED
|
@@ -363,8 +363,10 @@ var OllamaAdapter = class {
|
|
|
363
363
|
try {
|
|
364
364
|
const chunk = JSON.parse(trimmed);
|
|
365
365
|
const delta = chunk.message?.content ?? "";
|
|
366
|
+
const reasoningDelta = chunk.message?.thinking;
|
|
366
367
|
yield {
|
|
367
368
|
delta,
|
|
369
|
+
...reasoningDelta ? { reasoningDelta } : {},
|
|
368
370
|
finishReason: chunk.done ? FinishReason.STOP : void 0,
|
|
369
371
|
usage: chunk.done ? {
|
|
370
372
|
promptTokens: chunk.prompt_eval_count ?? 0,
|
|
@@ -391,6 +393,35 @@ function mapGroqMessages(messages) {
|
|
|
391
393
|
return { role, content: m.content };
|
|
392
394
|
});
|
|
393
395
|
}
|
|
396
|
+
|
|
397
|
+
// src/adapters/stream-chunk.helpers.ts
|
|
398
|
+
function parseOpenAiCompatStreamChunk(payload) {
|
|
399
|
+
try {
|
|
400
|
+
const parsed = JSON.parse(payload);
|
|
401
|
+
const choice = parsed.choices?.[0];
|
|
402
|
+
const delta = choice?.delta?.content ?? "";
|
|
403
|
+
const reasoningDelta = choice?.delta?.reasoning_content ?? choice?.delta?.reasoning;
|
|
404
|
+
const finishReason = choice?.finish_reason === "length" ? FinishReason.LENGTH : choice?.finish_reason === "tool_calls" ? FinishReason.TOOL_CALLS : choice?.finish_reason ? FinishReason.STOP : void 0;
|
|
405
|
+
const usage = parsed.usage ? {
|
|
406
|
+
promptTokens: parsed.usage.prompt_tokens ?? 0,
|
|
407
|
+
completionTokens: parsed.usage.completion_tokens ?? 0,
|
|
408
|
+
totalTokens: parsed.usage.total_tokens ?? (parsed.usage.prompt_tokens ?? 0) + (parsed.usage.completion_tokens ?? 0)
|
|
409
|
+
} : void 0;
|
|
410
|
+
if (!delta && !reasoningDelta && !finishReason && !usage) {
|
|
411
|
+
return null;
|
|
412
|
+
}
|
|
413
|
+
return {
|
|
414
|
+
delta,
|
|
415
|
+
...reasoningDelta ? { reasoningDelta } : {},
|
|
416
|
+
...finishReason ? { finishReason } : {},
|
|
417
|
+
...usage ? { usage } : {}
|
|
418
|
+
};
|
|
419
|
+
} catch {
|
|
420
|
+
return null;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// src/adapters/groq/groq.adapter.ts
|
|
394
425
|
var logger2 = loggerWithConfig(new Logger("GroqAdapter"));
|
|
395
426
|
var GroqAdapter = class {
|
|
396
427
|
name = "groq";
|
|
@@ -539,13 +570,9 @@ var GroqAdapter = class {
|
|
|
539
570
|
if (!trimmed || !trimmed.startsWith("data:")) continue;
|
|
540
571
|
const payload = trimmed.slice(5).trim();
|
|
541
572
|
if (payload === "[DONE]") break;
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
if (delta) {
|
|
546
|
-
yield { delta };
|
|
547
|
-
}
|
|
548
|
-
} catch {
|
|
573
|
+
const parsedChunk = parseOpenAiCompatStreamChunk(payload);
|
|
574
|
+
if (parsedChunk) {
|
|
575
|
+
yield parsedChunk;
|
|
549
576
|
}
|
|
550
577
|
}
|
|
551
578
|
}
|
|
@@ -581,6 +608,32 @@ function buildGeminiRequestBody(request) {
|
|
|
581
608
|
}
|
|
582
609
|
};
|
|
583
610
|
}
|
|
611
|
+
function parseGeminiSseChunk(jsonStr) {
|
|
612
|
+
try {
|
|
613
|
+
const chunk = JSON.parse(jsonStr);
|
|
614
|
+
const parts = chunk.candidates?.[0]?.content?.parts ?? [];
|
|
615
|
+
let delta = "";
|
|
616
|
+
let reasoningDelta = "";
|
|
617
|
+
for (const part of parts) {
|
|
618
|
+
if (!part.text) continue;
|
|
619
|
+
if (part.thought) reasoningDelta += part.text;
|
|
620
|
+
else delta += part.text;
|
|
621
|
+
}
|
|
622
|
+
const usage = chunk.usageMetadata ? {
|
|
623
|
+
promptTokens: chunk.usageMetadata.promptTokenCount ?? 0,
|
|
624
|
+
completionTokens: chunk.usageMetadata.candidatesTokenCount ?? 0,
|
|
625
|
+
totalTokens: chunk.usageMetadata.totalTokenCount ?? 0
|
|
626
|
+
} : void 0;
|
|
627
|
+
if (!delta && !reasoningDelta && !usage) return null;
|
|
628
|
+
return {
|
|
629
|
+
delta,
|
|
630
|
+
...reasoningDelta ? { reasoningDelta } : {},
|
|
631
|
+
...usage ? { usage } : {}
|
|
632
|
+
};
|
|
633
|
+
} catch {
|
|
634
|
+
return null;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
584
637
|
var logger3 = loggerWithConfig(new Logger("GoogleAdapter"));
|
|
585
638
|
var GoogleAdapter = class {
|
|
586
639
|
name = "google";
|
|
@@ -721,15 +774,8 @@ var GoogleAdapter = class {
|
|
|
721
774
|
for (const line of lines) {
|
|
722
775
|
const trimmed = line.trim();
|
|
723
776
|
if (!trimmed || !trimmed.startsWith("data:")) continue;
|
|
724
|
-
const
|
|
725
|
-
|
|
726
|
-
const chunk = JSON.parse(jsonStr);
|
|
727
|
-
const delta = chunk.candidates?.[0]?.content?.parts?.[0]?.text ?? "";
|
|
728
|
-
if (delta) {
|
|
729
|
-
yield { delta };
|
|
730
|
-
}
|
|
731
|
-
} catch {
|
|
732
|
-
}
|
|
777
|
+
const parsed = parseGeminiSseChunk(trimmed.slice(5).trim());
|
|
778
|
+
if (parsed) yield parsed;
|
|
733
779
|
}
|
|
734
780
|
}
|
|
735
781
|
} finally {
|
|
@@ -890,13 +936,9 @@ var OpenAIAdapter = class {
|
|
|
890
936
|
if (!trimmed || !trimmed.startsWith("data:")) continue;
|
|
891
937
|
const payload = trimmed.slice(5).trim();
|
|
892
938
|
if (payload === "[DONE]") break;
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
if (delta) {
|
|
897
|
-
yield { delta };
|
|
898
|
-
}
|
|
899
|
-
} catch {
|
|
939
|
+
const parsedChunk = parseOpenAiCompatStreamChunk(payload);
|
|
940
|
+
if (parsedChunk) {
|
|
941
|
+
yield parsedChunk;
|
|
900
942
|
}
|
|
901
943
|
}
|
|
902
944
|
}
|
|
@@ -1218,13 +1260,9 @@ var ClineAdapter = class {
|
|
|
1218
1260
|
if (!trimmed || !trimmed.startsWith("data:")) continue;
|
|
1219
1261
|
const payload = trimmed.slice(5).trim();
|
|
1220
1262
|
if (payload === "[DONE]") break;
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
if (delta) {
|
|
1225
|
-
yield { delta };
|
|
1226
|
-
}
|
|
1227
|
-
} catch {
|
|
1263
|
+
const parsedChunk = parseOpenAiCompatStreamChunk(payload);
|
|
1264
|
+
if (parsedChunk) {
|
|
1265
|
+
yield parsedChunk;
|
|
1228
1266
|
}
|
|
1229
1267
|
}
|
|
1230
1268
|
}
|
|
@@ -1437,6 +1475,6 @@ function createDefaultProvider(options = {}) {
|
|
|
1437
1475
|
});
|
|
1438
1476
|
}
|
|
1439
1477
|
|
|
1440
|
-
export { AIMessageSchema, AI_DEFAULT_MODELS, AI_ENDPOINTS, AI_EXECUTION_DEFAULTS, AnthropicAdapter, ClineAdapter, FallbackCascade, FinishReason, GoogleAdapter, GroqAdapter, LLMRequestOptionsSchema, LLMRequestSchema, LLMResponseSchema, LLMUsageSchema, MessageRole, MissingCredentialError, OllamaAdapter, OpenAIAdapter, ToolCallSchema, buildGeminiRequestBody, createAssistantMessage, createCascadeCandidates, createDefaultProvider, createProvider, createSystemMessage, createToolResultMessage, createUserMessage, extractAnthropicSystemAndMessages, extractClineRetrySuffix, extractClineToolCalls, extractStructuredOutput, mapClineFinishReason, mapClineMessages, mapGroqMessages, mapOllamaMessages, mapOpenAiMessages, resolveEnvCredentials, restoreClineToolName, sanitizeClineToolName };
|
|
1478
|
+
export { AIMessageSchema, AI_DEFAULT_MODELS, AI_ENDPOINTS, AI_EXECUTION_DEFAULTS, AnthropicAdapter, ClineAdapter, FallbackCascade, FinishReason, GoogleAdapter, GroqAdapter, LLMRequestOptionsSchema, LLMRequestSchema, LLMResponseSchema, LLMUsageSchema, MessageRole, MissingCredentialError, OllamaAdapter, OpenAIAdapter, ToolCallSchema, buildGeminiRequestBody, createAssistantMessage, createCascadeCandidates, createDefaultProvider, createProvider, createSystemMessage, createToolResultMessage, createUserMessage, extractAnthropicSystemAndMessages, extractClineRetrySuffix, extractClineToolCalls, extractStructuredOutput, mapClineFinishReason, mapClineMessages, mapGroqMessages, mapOllamaMessages, mapOpenAiMessages, parseGeminiSseChunk, resolveEnvCredentials, restoreClineToolName, sanitizeClineToolName };
|
|
1441
1479
|
//# sourceMappingURL=index.js.map
|
|
1442
1480
|
//# sourceMappingURL=index.js.map
|