@contentgrowth/llm-service 0.6.9 → 0.6.91

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentgrowth/llm-service",
3
- "version": "0.6.9",
3
+ "version": "0.6.91",
4
4
  "description": "Unified LLM Service for Content Growth",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -135,12 +135,41 @@ export class GeminiProvider extends BaseLLMProvider {
135
135
  tools: tools ? [{ functionDeclarations: tools.map(t => t.function) }] : undefined,
136
136
  });
137
137
 
138
- const response = result.response;
139
- const toolCalls = response.functionCalls?.() || response.functionCalls || null;
138
+ // New SDK returns result directly, not result.response
139
+ // Debug log to understand structure
140
+ console.log('[GeminiProvider] Result structure:', JSON.stringify(Object.keys(result), null, 2));
141
+
142
+ // Handle both old (result.response) and new (direct result) structures
143
+ const response = result.response || result;
144
+
145
+ // Extract function calls - try multiple possible locations
146
+ let toolCalls = null;
147
+ if (typeof response.functionCalls === 'function') {
148
+ toolCalls = response.functionCalls();
149
+ } else if (response.functionCalls) {
150
+ toolCalls = response.functionCalls;
151
+ } else if (response.candidates?.[0]?.content?.parts) {
152
+ // Check parts for function calls
153
+ const functionCallParts = response.candidates[0].content.parts.filter(p => p.functionCall);
154
+ if (functionCallParts.length > 0) {
155
+ toolCalls = functionCallParts.map(p => p.functionCall);
156
+ }
157
+ }
140
158
 
159
+ // Extract text content - try multiple possible locations
141
160
  let textContent = '';
142
161
  try {
143
- textContent = typeof response.text === 'function' ? response.text() : (response.text || '');
162
+ if (typeof response.text === 'function') {
163
+ textContent = response.text();
164
+ } else if (typeof response.text === 'string') {
165
+ textContent = response.text;
166
+ } else if (response.candidates?.[0]?.content?.parts) {
167
+ // Concatenate text from parts
168
+ textContent = response.candidates[0].content.parts
169
+ .filter(p => p.text)
170
+ .map(p => p.text)
171
+ .join('');
172
+ }
144
173
  } catch (e) {
145
174
  // response.text() throws if there is no text content (e.g. only tool calls)
146
175
  // This is expected behavior for tool-only responses
@@ -149,7 +178,7 @@ export class GeminiProvider extends BaseLLMProvider {
149
178
  // Validate that we have EITHER content OR tool calls
150
179
  if (!textContent && (!toolCalls || toolCalls.length === 0)) {
151
180
  console.error('[GeminiProvider] Model returned empty response (no text, no tool calls)');
152
- console.error('[GeminiProvider] Contents:', JSON.stringify(contents, null, 2));
181
+ console.error('[GeminiProvider] Full result:', JSON.stringify(result, null, 2));
153
182
  throw new LLMServiceException(
154
183
  'Model returned empty response. This usually means the prompt or schema is confusing the model.',
155
184
  500