@posthog/ai 7.10.0 → 7.11.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/anthropic/index.cjs +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/gemini/index.cjs +1 -1
- package/dist/gemini/index.mjs +1 -1
- package/dist/index.cjs +31 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.mjs +31 -21
- package/dist/index.mjs.map +1 -1
- package/dist/langchain/index.cjs +1 -1
- package/dist/langchain/index.mjs +1 -1
- package/dist/openai/index.cjs +1 -1
- package/dist/openai/index.mjs +1 -1
- package/dist/otel/index.cjs +1 -1
- package/dist/otel/index.mjs +1 -1
- package/dist/vercel/index.cjs +1 -1
- package/dist/vercel/index.mjs +1 -1
- package/package.json +1 -1
package/dist/anthropic/index.cjs
CHANGED
|
@@ -10,7 +10,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
10
10
|
|
|
11
11
|
var AnthropicOriginal__default = /*#__PURE__*/_interopDefault(AnthropicOriginal);
|
|
12
12
|
|
|
13
|
-
var version = "7.
|
|
13
|
+
var version = "7.11.0";
|
|
14
14
|
|
|
15
15
|
// Type guards for safer type checking
|
|
16
16
|
|
package/dist/anthropic/index.mjs
CHANGED
package/dist/gemini/index.cjs
CHANGED
package/dist/gemini/index.mjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -29,7 +29,7 @@ function _interopNamespace(e) {
|
|
|
29
29
|
var uuid__namespace = /*#__PURE__*/_interopNamespace(uuid);
|
|
30
30
|
var AnthropicOriginal__default = /*#__PURE__*/_interopDefault(AnthropicOriginal);
|
|
31
31
|
|
|
32
|
-
var version = "7.
|
|
32
|
+
var version = "7.11.0";
|
|
33
33
|
|
|
34
34
|
// Type guards for safer type checking
|
|
35
35
|
const isString = value => {
|
|
@@ -5213,8 +5213,17 @@ class Prompts {
|
|
|
5213
5213
|
this.host = options.host ?? 'https://us.posthog.com';
|
|
5214
5214
|
}
|
|
5215
5215
|
}
|
|
5216
|
-
|
|
5217
|
-
return
|
|
5216
|
+
getPromptCache(name) {
|
|
5217
|
+
return this.cache.get(name);
|
|
5218
|
+
}
|
|
5219
|
+
getOrCreatePromptCache(name) {
|
|
5220
|
+
const cachedPromptVersions = this.cache.get(name);
|
|
5221
|
+
if (cachedPromptVersions) {
|
|
5222
|
+
return cachedPromptVersions;
|
|
5223
|
+
}
|
|
5224
|
+
const promptVersions = new Map();
|
|
5225
|
+
this.cache.set(name, promptVersions);
|
|
5226
|
+
return promptVersions;
|
|
5218
5227
|
}
|
|
5219
5228
|
getPromptLabel(name, version) {
|
|
5220
5229
|
return version === undefined ? `"${name}"` : `"${name}" version ${version}`;
|
|
@@ -5231,10 +5240,9 @@ class Prompts {
|
|
|
5231
5240
|
const cacheTtlSeconds = options?.cacheTtlSeconds ?? this.defaultCacheTtlSeconds;
|
|
5232
5241
|
const fallback = options?.fallback;
|
|
5233
5242
|
const version = options?.version;
|
|
5234
|
-
const cacheKey = this.getCacheKey(name, version);
|
|
5235
5243
|
const promptLabel = this.getPromptLabel(name, version);
|
|
5236
5244
|
// Check cache first
|
|
5237
|
-
const cached = this.
|
|
5245
|
+
const cached = this.getPromptCache(name)?.get(version);
|
|
5238
5246
|
const now = Date.now();
|
|
5239
5247
|
if (cached) {
|
|
5240
5248
|
const isFresh = now - cached.fetchedAt < cacheTtlSeconds * 1000;
|
|
@@ -5247,7 +5255,7 @@ class Prompts {
|
|
|
5247
5255
|
const prompt = await this.fetchPromptFromApi(name, version);
|
|
5248
5256
|
const fetchedAt = Date.now();
|
|
5249
5257
|
// Update cache
|
|
5250
|
-
this.
|
|
5258
|
+
this.getOrCreatePromptCache(name).set(version, {
|
|
5251
5259
|
prompt,
|
|
5252
5260
|
fetchedAt
|
|
5253
5261
|
});
|
|
@@ -5289,23 +5297,25 @@ class Prompts {
|
|
|
5289
5297
|
/**
|
|
5290
5298
|
* Clear the cache for a specific prompt or all prompts
|
|
5291
5299
|
*
|
|
5292
|
-
* @param name - Optional prompt name to clear. If provided, clears all cached versions for that prompt.
|
|
5300
|
+
* @param name - Optional prompt name to clear. If provided, clears all cached versions for that prompt unless a version is also provided.
|
|
5301
|
+
* @param version - Optional prompt version to clear. Requires a prompt name.
|
|
5293
5302
|
*/
|
|
5294
|
-
clearCache(name) {
|
|
5295
|
-
if (
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
|
|
5299
|
-
if (key === latestKey) {
|
|
5300
|
-
this.cache.delete(key);
|
|
5301
|
-
continue;
|
|
5302
|
-
}
|
|
5303
|
-
if (key.startsWith(versionPrefix) && /^\d+$/.test(key.slice(versionPrefix.length))) {
|
|
5304
|
-
this.cache.delete(key);
|
|
5305
|
-
}
|
|
5306
|
-
}
|
|
5307
|
-
} else {
|
|
5303
|
+
clearCache(name, version) {
|
|
5304
|
+
if (version !== undefined && name === undefined) {
|
|
5305
|
+
throw new Error("'version' requires 'name' to be provided");
|
|
5306
|
+
}
|
|
5307
|
+
if (name === undefined) {
|
|
5308
5308
|
this.cache.clear();
|
|
5309
|
+
return;
|
|
5310
|
+
}
|
|
5311
|
+
if (version === undefined) {
|
|
5312
|
+
this.cache.delete(name);
|
|
5313
|
+
return;
|
|
5314
|
+
}
|
|
5315
|
+
const promptVersions = this.getPromptCache(name);
|
|
5316
|
+
promptVersions?.delete(version);
|
|
5317
|
+
if (promptVersions?.size === 0) {
|
|
5318
|
+
this.cache.delete(name);
|
|
5309
5319
|
}
|
|
5310
5320
|
}
|
|
5311
5321
|
async fetchPromptFromApi(name, version) {
|