@posthog/ai 6.3.0 → 6.3.1
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/anthropic/index.cjs +1 -1
- package/dist/anthropic/index.cjs.map +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/gemini/index.cjs +1 -1
- package/dist/gemini/index.cjs.map +1 -1
- package/dist/gemini/index.mjs +1 -1
- package/dist/gemini/index.mjs.map +1 -1
- package/dist/index.cjs +35 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +35 -10
- package/dist/index.mjs.map +1 -1
- package/dist/langchain/index.cjs +1 -1
- package/dist/langchain/index.cjs.map +1 -1
- package/dist/langchain/index.mjs +1 -1
- package/dist/langchain/index.mjs.map +1 -1
- package/dist/openai/index.cjs +1 -1
- package/dist/openai/index.cjs.map +1 -1
- package/dist/openai/index.mjs +1 -1
- package/dist/openai/index.mjs.map +1 -1
- package/dist/vercel/index.cjs +37 -10
- package/dist/vercel/index.cjs.map +1 -1
- package/dist/vercel/index.mjs +37 -10
- package/dist/vercel/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { wrapLanguageModel } from 'ai';
|
|
|
6
6
|
import AnthropicOriginal from '@anthropic-ai/sdk';
|
|
7
7
|
import { GoogleGenAI } from '@google/genai';
|
|
8
8
|
|
|
9
|
-
var version = "6.3.
|
|
9
|
+
var version = "6.3.1";
|
|
10
10
|
|
|
11
11
|
// limit large outputs by truncating to 200kb (approx 200k bytes)
|
|
12
12
|
const MAX_OUTPUT_SIZE = 200000;
|
|
@@ -206,18 +206,43 @@ const mergeSystemPrompt = (params, provider) => {
|
|
|
206
206
|
const withPrivacyMode = (client, privacyMode, input) => {
|
|
207
207
|
return client.privacy_mode || privacyMode ? null : input;
|
|
208
208
|
};
|
|
209
|
-
|
|
209
|
+
function toSafeString(input) {
|
|
210
|
+
if (input === undefined || input === null) {
|
|
211
|
+
return '';
|
|
212
|
+
}
|
|
213
|
+
if (typeof input === 'string') {
|
|
214
|
+
return input;
|
|
215
|
+
}
|
|
210
216
|
try {
|
|
211
|
-
|
|
212
|
-
if (buffer.length <= MAX_OUTPUT_SIZE) {
|
|
213
|
-
return str;
|
|
214
|
-
}
|
|
215
|
-
const truncatedBuffer = buffer.slice(0, MAX_OUTPUT_SIZE);
|
|
216
|
-
return `${truncatedBuffer.toString(STRING_FORMAT)}... [truncated]`;
|
|
217
|
+
return JSON.stringify(input);
|
|
217
218
|
} catch {
|
|
218
|
-
console.
|
|
219
|
-
return
|
|
219
|
+
console.warn('Failed to stringify input', input);
|
|
220
|
+
return '';
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const truncate = input => {
|
|
224
|
+
const str = toSafeString(input);
|
|
225
|
+
if (str === '') {
|
|
226
|
+
return '';
|
|
227
|
+
}
|
|
228
|
+
// Check if we need to truncate and ensure STRING_FORMAT is respected
|
|
229
|
+
const encoder = new TextEncoder();
|
|
230
|
+
const buffer = encoder.encode(str);
|
|
231
|
+
if (buffer.length <= MAX_OUTPUT_SIZE) {
|
|
232
|
+
// Ensure STRING_FORMAT is respected
|
|
233
|
+
return new TextDecoder(STRING_FORMAT).decode(buffer);
|
|
234
|
+
}
|
|
235
|
+
// Truncate the buffer and ensure a valid string is returned
|
|
236
|
+
const truncatedBuffer = buffer.slice(0, MAX_OUTPUT_SIZE);
|
|
237
|
+
// fatal: false means we get U+FFFD at the end if truncation broke the encoding
|
|
238
|
+
const decoder = new TextDecoder(STRING_FORMAT, {
|
|
239
|
+
fatal: false
|
|
240
|
+
});
|
|
241
|
+
let truncatedStr = decoder.decode(truncatedBuffer);
|
|
242
|
+
if (truncatedStr.endsWith('\uFFFD')) {
|
|
243
|
+
truncatedStr = truncatedStr.slice(0, -1);
|
|
220
244
|
}
|
|
245
|
+
return `${truncatedStr}... [truncated]`;
|
|
221
246
|
};
|
|
222
247
|
/**
|
|
223
248
|
* Extract available tool calls from the request parameters.
|