@launchdarkly/server-sdk-ai 0.10.1 → 0.11.2
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/CHANGELOG.md +27 -0
- package/__tests__/LDAIClientImpl.test.ts +235 -1
- package/__tests__/LDAIConfigTrackerImpl.test.ts +94 -136
- package/dist/LDAIClientImpl.d.ts +7 -0
- package/dist/LDAIClientImpl.d.ts.map +1 -1
- package/dist/LDAIClientImpl.js +60 -11
- package/dist/LDAIClientImpl.js.map +1 -1
- package/dist/LDAIConfigTrackerImpl.d.ts +3 -1
- package/dist/LDAIConfigTrackerImpl.d.ts.map +1 -1
- package/dist/LDAIConfigTrackerImpl.js +5 -3
- package/dist/LDAIConfigTrackerImpl.js.map +1 -1
- package/dist/api/LDAIClient.d.ts +70 -0
- package/dist/api/LDAIClient.d.ts.map +1 -1
- package/dist/api/agents/LDAIAgent.d.ts +32 -0
- package/dist/api/agents/LDAIAgent.d.ts.map +1 -0
- package/dist/api/agents/LDAIAgent.js +3 -0
- package/dist/api/agents/LDAIAgent.js.map +1 -0
- package/dist/api/agents/index.d.ts +2 -0
- package/dist/api/agents/index.d.ts.map +1 -0
- package/dist/api/agents/index.js +18 -0
- package/dist/api/agents/index.js.map +1 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1 -0
- package/dist/api/index.js.map +1 -1
- package/docs/assets/highlight.css +15 -8
- package/docs/assets/search.js +1 -1
- package/docs/enums/LDFeedbackKind.html +11 -8
- package/docs/functions/createBedrockTokenUsage.html +9 -6
- package/docs/functions/createOpenAiUsage.html +9 -6
- package/docs/functions/createVercelAISDKTokenUsage.html +9 -6
- package/docs/functions/initAi.html +9 -6
- package/docs/index.html +12 -6
- package/docs/interfaces/LDAIAgent.html +137 -0
- package/docs/interfaces/LDAIAgentConfig.html +111 -0
- package/docs/interfaces/LDAIClient.html +96 -10
- package/docs/interfaces/LDAIConfig.html +15 -12
- package/docs/interfaces/LDAIConfigTracker.html +21 -18
- package/docs/interfaces/LDMessage.html +11 -8
- package/docs/interfaces/LDModelConfig.html +12 -9
- package/docs/interfaces/LDProviderConfig.html +10 -7
- package/docs/interfaces/LDTokenUsage.html +12 -9
- package/docs/interfaces/VercelAISDKConfig.html +19 -16
- package/docs/interfaces/VercelAISDKMapOptions.html +10 -7
- package/docs/types/LDAIAgentDefaults.html +63 -0
- package/docs/types/LDAIDefaults.html +9 -6
- package/docs/types/VercelAISDKProvider.html +9 -6
- package/package.json +1 -1
- package/src/LDAIClientImpl.ts +141 -12
- package/src/LDAIConfigTrackerImpl.ts +11 -3
- package/src/api/LDAIClient.ts +80 -0
- package/src/api/agents/LDAIAgent.ts +36 -0
- package/src/api/agents/index.ts +1 -0
- package/src/api/index.ts +1 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>LDAIDefaults | @launchdarkly/server-sdk-ai - v0.
|
|
1
|
+
<!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>LDAIDefaults | @launchdarkly/server-sdk-ai - v0.11.2</title><meta name="description" content="Documentation for @launchdarkly/server-sdk-ai"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/search.js" id="tsd-search-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"</script><header class="tsd-page-toolbar">
|
|
2
2
|
<div class="tsd-toolbar-contents container">
|
|
3
3
|
<div class="table-cell" id="tsd-search" data-base="..">
|
|
4
4
|
<div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M15.7824 13.833L12.6666 10.7177C12.5259 10.5771 12.3353 10.499 12.1353 10.499H11.6259C12.4884 9.39596 13.001 8.00859 13.001 6.49937C13.001 2.90909 10.0914 0 6.50048 0C2.90959 0 0 2.90909 0 6.49937C0 10.0896 2.90959 12.9987 6.50048 12.9987C8.00996 12.9987 9.39756 12.4863 10.5008 11.6239V12.1332C10.5008 12.3332 10.5789 12.5238 10.7195 12.6644L13.8354 15.7797C14.1292 16.0734 14.6042 16.0734 14.8948 15.7797L15.7793 14.8954C16.0731 14.6017 16.0731 14.1267 15.7824 13.833ZM6.50048 10.499C4.29094 10.499 2.50018 8.71165 2.50018 6.49937C2.50018 4.29021 4.28781 2.49976 6.50048 2.49976C8.71001 2.49976 10.5008 4.28708 10.5008 6.49937C10.5008 8.70852 8.71314 10.499 6.50048 10.499Z" fill="var(--color-text)"></path></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div>
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<div id="tsd-toolbar-links"></div></div>
|
|
7
7
|
<ul class="results">
|
|
8
8
|
<li class="state loading">Preparing search index...</li>
|
|
9
|
-
<li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@launchdarkly/server-sdk-ai - v0.
|
|
9
|
+
<li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@launchdarkly/server-sdk-ai - v0.11.2</a></div>
|
|
10
10
|
<div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><rect x="1" y="3" width="14" height="2" fill="var(--color-text)"></rect><rect x="1" y="7" width="14" height="2" fill="var(--color-text)"></rect><rect x="1" y="11" width="14" height="2" fill="var(--color-text)"></rect></svg></a></div></div></header>
|
|
11
11
|
<div class="container container-main">
|
|
12
12
|
<div class="col-content">
|
|
@@ -30,7 +30,7 @@ a tracker or mapper, and <code>enabled</code> is optional.</p>
|
|
|
30
30
|
<div class="tsd-comment tsd-typography"></div></li></ul></div>
|
|
31
31
|
<div class="tsd-comment tsd-typography"></div><aside class="tsd-sources">
|
|
32
32
|
<ul>
|
|
33
|
-
<li>Defined in <a href="https://github.com/launchdarkly/js-core/blob/
|
|
33
|
+
<li>Defined in <a href="https://github.com/launchdarkly/js-core/blob/de783b9/packages/sdk/server-ai/src/api/config/LDAIConfig.ts#L94">api/config/LDAIConfig.ts:94</a></li></ul></aside></div>
|
|
34
34
|
<div class="col-sidebar">
|
|
35
35
|
<div class="page-menu">
|
|
36
36
|
<div class="tsd-navigation settings">
|
|
@@ -47,10 +47,12 @@ a tracker or mapper, and <code>enabled</code> is optional.</p>
|
|
|
47
47
|
<div class="tsd-theme-toggle">
|
|
48
48
|
<h4 class="uppercase">Theme</h4><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div>
|
|
49
49
|
<div class="site-menu">
|
|
50
|
-
<nav class="tsd-navigation"><a href="../index.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-4"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-namespace)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.33 16V7.24H10.77L13.446 14.74C13.43 14.54 13.41 14.296 13.386 14.008C13.37 13.712 13.354 13.404 13.338 13.084C13.33 12.756 13.326 12.448 13.326 12.16V7.24H14.37V16H12.93L10.266 8.5C10.282 8.692 10.298 8.936 10.314 9.232C10.33 9.52 10.342 9.828 10.35 10.156C10.366 10.476 10.374 10.784 10.374 11.08V16H9.33Z" fill="var(--color-text)"></path></g></svg><span>@launchdarkly/server-<wbr/>sdk-<wbr/>ai -<wbr/> v0.
|
|
50
|
+
<nav class="tsd-navigation"><a href="../index.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-4"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-namespace)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.33 16V7.24H10.77L13.446 14.74C13.43 14.54 13.41 14.296 13.386 14.008C13.37 13.712 13.354 13.404 13.338 13.084C13.33 12.756 13.326 12.448 13.326 12.16V7.24H14.37V16H12.93L10.266 8.5C10.282 8.692 10.298 8.936 10.314 9.232C10.33 9.52 10.342 9.828 10.35 10.156C10.366 10.476 10.374 10.784 10.374 11.08V16H9.33Z" fill="var(--color-text)"></path></g></svg><span>@launchdarkly/server-<wbr/>sdk-<wbr/>ai -<wbr/> v0.11.2</span></a>
|
|
51
51
|
<ul class="tsd-small-nested-navigation">
|
|
52
52
|
<li><a href="../enums/LDFeedbackKind.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-8"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-enum)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.45 16V7.24H14.49V8.224H10.518V10.936H14.07V11.908H10.518V15.016H14.49V16H9.45Z" fill="var(--color-text)"></path></g></svg><span>LDFeedback<wbr/>Kind</span></a></li>
|
|
53
|
-
<li><a href="../interfaces/
|
|
53
|
+
<li><a href="../interfaces/LDAIAgent.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-256"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-interface)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.51 16V15.016H11.298V8.224H9.51V7.24H14.19V8.224H12.402V15.016H14.19V16H9.51Z" fill="var(--color-text)"></path></g></svg><span>LDAIAgent</span></a></li>
|
|
54
|
+
<li><a href="../interfaces/LDAIAgentConfig.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>LDAIAgent<wbr/>Config</span></a></li>
|
|
55
|
+
<li><a href="../interfaces/LDAIClient.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>LDAIClient</span></a></li>
|
|
54
56
|
<li><a href="../interfaces/LDAIConfig.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>LDAIConfig</span></a></li>
|
|
55
57
|
<li><a href="../interfaces/LDAIConfigTracker.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>LDAIConfig<wbr/>Tracker</span></a></li>
|
|
56
58
|
<li><a href="../interfaces/LDMessage.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>LDMessage</span></a></li>
|
|
@@ -59,7 +61,8 @@ a tracker or mapper, and <code>enabled</code> is optional.</p>
|
|
|
59
61
|
<li><a href="../interfaces/LDTokenUsage.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>LDToken<wbr/>Usage</span></a></li>
|
|
60
62
|
<li><a href="../interfaces/VercelAISDKConfig.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>VercelAISDKConfig</span></a></li>
|
|
61
63
|
<li><a href="../interfaces/VercelAISDKMapOptions.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>VercelAISDKMap<wbr/>Options</span></a></li>
|
|
62
|
-
<li><a href="
|
|
64
|
+
<li><a href="LDAIAgentDefaults.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-2097152"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-type-alias)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M11.31 16V8.224H8.91V7.24H14.79V8.224H12.39V16H11.31Z" fill="var(--color-text)"></path></g></svg><span>LDAIAgent<wbr/>Defaults</span></a></li>
|
|
65
|
+
<li><a href="LDAIDefaults.html" class="current"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-2097152"></use></svg><span>LDAIDefaults</span></a></li>
|
|
63
66
|
<li><a href="VercelAISDKProvider.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-2097152"></use></svg><span>VercelAISDKProvider</span></a></li>
|
|
64
67
|
<li><a href="../functions/createBedrockTokenUsage.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-64"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-function)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.39 16V7.24H14.55V8.224H10.446V11.128H14.238V12.112H10.47V16H9.39Z" fill="var(--color-text)"></path></g></svg><span>create<wbr/>Bedrock<wbr/>Token<wbr/>Usage</span></a></li>
|
|
65
68
|
<li><a href="../functions/createOpenAiUsage.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>create<wbr/>Open<wbr/>Ai<wbr/>Usage</span></a></li>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>VercelAISDKProvider | @launchdarkly/server-sdk-ai - v0.
|
|
1
|
+
<!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>VercelAISDKProvider | @launchdarkly/server-sdk-ai - v0.11.2</title><meta name="description" content="Documentation for @launchdarkly/server-sdk-ai"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/search.js" id="tsd-search-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"</script><header class="tsd-page-toolbar">
|
|
2
2
|
<div class="tsd-toolbar-contents container">
|
|
3
3
|
<div class="table-cell" id="tsd-search" data-base="..">
|
|
4
4
|
<div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M15.7824 13.833L12.6666 10.7177C12.5259 10.5771 12.3353 10.499 12.1353 10.499H11.6259C12.4884 9.39596 13.001 8.00859 13.001 6.49937C13.001 2.90909 10.0914 0 6.50048 0C2.90959 0 0 2.90909 0 6.49937C0 10.0896 2.90959 12.9987 6.50048 12.9987C8.00996 12.9987 9.39756 12.4863 10.5008 11.6239V12.1332C10.5008 12.3332 10.5789 12.5238 10.7195 12.6644L13.8354 15.7797C14.1292 16.0734 14.6042 16.0734 14.8948 15.7797L15.7793 14.8954C16.0731 14.6017 16.0731 14.1267 15.7824 13.833ZM6.50048 10.499C4.29094 10.499 2.50018 8.71165 2.50018 6.49937C2.50018 4.29021 4.28781 2.49976 6.50048 2.49976C8.71001 2.49976 10.5008 4.28708 10.5008 6.49937C10.5008 8.70852 8.71314 10.499 6.50048 10.499Z" fill="var(--color-text)"></path></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div>
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<div id="tsd-toolbar-links"></div></div>
|
|
7
7
|
<ul class="results">
|
|
8
8
|
<li class="state loading">Preparing search index...</li>
|
|
9
|
-
<li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@launchdarkly/server-sdk-ai - v0.
|
|
9
|
+
<li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@launchdarkly/server-sdk-ai - v0.11.2</a></div>
|
|
10
10
|
<div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><rect x="1" y="3" width="14" height="2" fill="var(--color-text)"></rect><rect x="1" y="7" width="14" height="2" fill="var(--color-text)"></rect><rect x="1" y="11" width="14" height="2" fill="var(--color-text)"></rect></svg></a></div></div></header>
|
|
11
11
|
<div class="container container-main">
|
|
12
12
|
<div class="col-content">
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
<h5><span class="tsd-kind-parameter">modelName</span>: <span class="tsd-signature-type">string</span></h5></li></ul></div>
|
|
36
36
|
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type tsd-kind-type-parameter">TMod</span></h4></li></ul></li></ul></div><aside class="tsd-sources">
|
|
37
37
|
<ul>
|
|
38
|
-
<li>Defined in <a href="https://github.com/launchdarkly/js-core/blob/
|
|
38
|
+
<li>Defined in <a href="https://github.com/launchdarkly/js-core/blob/de783b9/packages/sdk/server-ai/src/api/config/VercelAISDK.ts#L3">api/config/VercelAISDK.ts:3</a></li></ul></aside></div>
|
|
39
39
|
<div class="col-sidebar">
|
|
40
40
|
<div class="page-menu">
|
|
41
41
|
<div class="tsd-navigation settings">
|
|
@@ -52,10 +52,12 @@
|
|
|
52
52
|
<div class="tsd-theme-toggle">
|
|
53
53
|
<h4 class="uppercase">Theme</h4><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div>
|
|
54
54
|
<div class="site-menu">
|
|
55
|
-
<nav class="tsd-navigation"><a href="../index.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-4"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-namespace)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.33 16V7.24H10.77L13.446 14.74C13.43 14.54 13.41 14.296 13.386 14.008C13.37 13.712 13.354 13.404 13.338 13.084C13.33 12.756 13.326 12.448 13.326 12.16V7.24H14.37V16H12.93L10.266 8.5C10.282 8.692 10.298 8.936 10.314 9.232C10.33 9.52 10.342 9.828 10.35 10.156C10.366 10.476 10.374 10.784 10.374 11.08V16H9.33Z" fill="var(--color-text)"></path></g></svg><span>@launchdarkly/server-<wbr/>sdk-<wbr/>ai -<wbr/> v0.
|
|
55
|
+
<nav class="tsd-navigation"><a href="../index.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-4"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-namespace)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.33 16V7.24H10.77L13.446 14.74C13.43 14.54 13.41 14.296 13.386 14.008C13.37 13.712 13.354 13.404 13.338 13.084C13.33 12.756 13.326 12.448 13.326 12.16V7.24H14.37V16H12.93L10.266 8.5C10.282 8.692 10.298 8.936 10.314 9.232C10.33 9.52 10.342 9.828 10.35 10.156C10.366 10.476 10.374 10.784 10.374 11.08V16H9.33Z" fill="var(--color-text)"></path></g></svg><span>@launchdarkly/server-<wbr/>sdk-<wbr/>ai -<wbr/> v0.11.2</span></a>
|
|
56
56
|
<ul class="tsd-small-nested-navigation">
|
|
57
57
|
<li><a href="../enums/LDFeedbackKind.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-8"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-enum)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.45 16V7.24H14.49V8.224H10.518V10.936H14.07V11.908H10.518V15.016H14.49V16H9.45Z" fill="var(--color-text)"></path></g></svg><span>LDFeedback<wbr/>Kind</span></a></li>
|
|
58
|
-
<li><a href="../interfaces/
|
|
58
|
+
<li><a href="../interfaces/LDAIAgent.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-256"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-interface)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.51 16V15.016H11.298V8.224H9.51V7.24H14.19V8.224H12.402V15.016H14.19V16H9.51Z" fill="var(--color-text)"></path></g></svg><span>LDAIAgent</span></a></li>
|
|
59
|
+
<li><a href="../interfaces/LDAIAgentConfig.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>LDAIAgent<wbr/>Config</span></a></li>
|
|
60
|
+
<li><a href="../interfaces/LDAIClient.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>LDAIClient</span></a></li>
|
|
59
61
|
<li><a href="../interfaces/LDAIConfig.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>LDAIConfig</span></a></li>
|
|
60
62
|
<li><a href="../interfaces/LDAIConfigTracker.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>LDAIConfig<wbr/>Tracker</span></a></li>
|
|
61
63
|
<li><a href="../interfaces/LDMessage.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>LDMessage</span></a></li>
|
|
@@ -64,7 +66,8 @@
|
|
|
64
66
|
<li><a href="../interfaces/LDTokenUsage.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>LDToken<wbr/>Usage</span></a></li>
|
|
65
67
|
<li><a href="../interfaces/VercelAISDKConfig.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>VercelAISDKConfig</span></a></li>
|
|
66
68
|
<li><a href="../interfaces/VercelAISDKMapOptions.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>VercelAISDKMap<wbr/>Options</span></a></li>
|
|
67
|
-
<li><a href="
|
|
69
|
+
<li><a href="LDAIAgentDefaults.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-2097152"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-type-alias)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M11.31 16V8.224H8.91V7.24H14.79V8.224H12.39V16H11.31Z" fill="var(--color-text)"></path></g></svg><span>LDAIAgent<wbr/>Defaults</span></a></li>
|
|
70
|
+
<li><a href="LDAIDefaults.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-2097152"></use></svg><span>LDAIDefaults</span></a></li>
|
|
68
71
|
<li><a href="VercelAISDKProvider.html" class="current"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-2097152"></use></svg><span>VercelAISDKProvider</span></a></li>
|
|
69
72
|
<li><a href="../functions/createBedrockTokenUsage.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-64"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-function)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.39 16V7.24H14.55V8.224H10.446V11.128H14.238V12.112H10.47V16H9.39Z" fill="var(--color-text)"></path></g></svg><span>create<wbr/>Bedrock<wbr/>Token<wbr/>Usage</span></a></li>
|
|
70
73
|
<li><a href="../functions/createOpenAiUsage.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>create<wbr/>Open<wbr/>Ai<wbr/>Usage</span></a></li>
|
package/package.json
CHANGED
package/src/LDAIClientImpl.ts
CHANGED
|
@@ -2,8 +2,10 @@ import * as Mustache from 'mustache';
|
|
|
2
2
|
|
|
3
3
|
import { LDContext } from '@launchdarkly/js-server-sdk-common';
|
|
4
4
|
|
|
5
|
+
import { LDAIAgent, LDAIAgentConfig, LDAIAgentDefaults } from './api/agents';
|
|
5
6
|
import {
|
|
6
7
|
LDAIConfig,
|
|
8
|
+
LDAIConfigTracker,
|
|
7
9
|
LDAIDefaults,
|
|
8
10
|
LDMessage,
|
|
9
11
|
LDModelConfig,
|
|
@@ -17,13 +19,16 @@ import { LDAIConfigMapper } from './LDAIConfigMapper';
|
|
|
17
19
|
import { LDAIConfigTrackerImpl } from './LDAIConfigTrackerImpl';
|
|
18
20
|
import { LDClientMin } from './LDClientMin';
|
|
19
21
|
|
|
22
|
+
type Mode = 'completion' | 'agent';
|
|
23
|
+
|
|
20
24
|
/**
|
|
21
|
-
* Metadata
|
|
25
|
+
* Metadata associated with a model configuration variation.
|
|
22
26
|
*/
|
|
23
27
|
interface LDMeta {
|
|
24
28
|
variationKey: string;
|
|
25
29
|
enabled: boolean;
|
|
26
30
|
version?: number;
|
|
31
|
+
mode?: Mode;
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
/**
|
|
@@ -33,10 +38,24 @@ interface LDMeta {
|
|
|
33
38
|
interface VariationContent {
|
|
34
39
|
model?: LDModelConfig;
|
|
35
40
|
messages?: LDMessage[];
|
|
41
|
+
instructions?: string;
|
|
36
42
|
provider?: LDProviderConfig;
|
|
37
43
|
_ldMeta?: LDMeta;
|
|
38
44
|
}
|
|
39
45
|
|
|
46
|
+
/**
|
|
47
|
+
* The result of evaluating a configuration.
|
|
48
|
+
*/
|
|
49
|
+
interface EvaluationResult {
|
|
50
|
+
tracker: LDAIConfigTracker;
|
|
51
|
+
enabled: boolean;
|
|
52
|
+
model?: LDModelConfig;
|
|
53
|
+
provider?: LDProviderConfig;
|
|
54
|
+
messages?: LDMessage[];
|
|
55
|
+
instructions?: string;
|
|
56
|
+
mode?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
40
59
|
export class LDAIClientImpl implements LDAIClient {
|
|
41
60
|
constructor(private _ldClient: LDClientMin) {}
|
|
42
61
|
|
|
@@ -44,13 +63,13 @@ export class LDAIClientImpl implements LDAIClient {
|
|
|
44
63
|
return Mustache.render(template, variables, undefined, { escape: (item: any) => item });
|
|
45
64
|
}
|
|
46
65
|
|
|
47
|
-
async
|
|
66
|
+
private async _evaluate(
|
|
48
67
|
key: string,
|
|
49
68
|
context: LDContext,
|
|
50
69
|
defaultValue: LDAIDefaults,
|
|
51
|
-
|
|
52
|
-
): Promise<LDAIConfig> {
|
|
70
|
+
): Promise<EvaluationResult> {
|
|
53
71
|
const value: VariationContent = await this._ldClient.variation(key, context, defaultValue);
|
|
72
|
+
|
|
54
73
|
const tracker = new LDAIConfigTrackerImpl(
|
|
55
74
|
this._ldClient,
|
|
56
75
|
key,
|
|
@@ -58,26 +77,95 @@ export class LDAIClientImpl implements LDAIClient {
|
|
|
58
77
|
value._ldMeta?.variationKey ?? '',
|
|
59
78
|
// eslint-disable-next-line no-underscore-dangle
|
|
60
79
|
value._ldMeta?.version ?? 1,
|
|
80
|
+
value.model?.name ?? '',
|
|
81
|
+
value.provider?.name ?? '',
|
|
61
82
|
context,
|
|
62
83
|
);
|
|
84
|
+
|
|
63
85
|
// eslint-disable-next-line no-underscore-dangle
|
|
64
86
|
const enabled = !!value._ldMeta?.enabled;
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
tracker,
|
|
90
|
+
enabled,
|
|
91
|
+
model: value.model,
|
|
92
|
+
provider: value.provider,
|
|
93
|
+
messages: value.messages,
|
|
94
|
+
instructions: value.instructions,
|
|
95
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
96
|
+
mode: value._ldMeta?.mode ?? 'completion',
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private async _evaluateAgent(
|
|
101
|
+
key: string,
|
|
102
|
+
context: LDContext,
|
|
103
|
+
defaultValue: LDAIAgentDefaults,
|
|
104
|
+
variables?: Record<string, unknown>,
|
|
105
|
+
): Promise<LDAIAgent> {
|
|
106
|
+
const { tracker, enabled, model, provider, instructions } = await this._evaluate(
|
|
107
|
+
key,
|
|
108
|
+
context,
|
|
109
|
+
defaultValue,
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const agent: LDAIAgent = {
|
|
113
|
+
tracker,
|
|
114
|
+
enabled,
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// We are going to modify the contents before returning them, so we make a copy.
|
|
118
|
+
// This isn't a deep copy and the application developer should not modify the returned content.
|
|
119
|
+
if (model) {
|
|
120
|
+
agent.model = { ...model };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (provider) {
|
|
124
|
+
agent.provider = { ...provider };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const allVariables = { ...variables, ldctx: context };
|
|
128
|
+
|
|
129
|
+
if (instructions) {
|
|
130
|
+
agent.instructions = this._interpolateTemplate(instructions, allVariables);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return agent;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async config(
|
|
137
|
+
key: string,
|
|
138
|
+
context: LDContext,
|
|
139
|
+
defaultValue: LDAIDefaults,
|
|
140
|
+
variables?: Record<string, unknown>,
|
|
141
|
+
): Promise<LDAIConfig> {
|
|
142
|
+
this._ldClient.track('$ld:ai:config:function:single', context, key, 1);
|
|
143
|
+
|
|
144
|
+
const {
|
|
145
|
+
tracker,
|
|
146
|
+
enabled,
|
|
147
|
+
model,
|
|
148
|
+
provider: configProvider,
|
|
149
|
+
messages,
|
|
150
|
+
} = await this._evaluate(key, context, defaultValue);
|
|
151
|
+
|
|
65
152
|
const config: Omit<LDAIConfig, 'toVercelAISDK'> = {
|
|
66
153
|
tracker,
|
|
67
154
|
enabled,
|
|
68
155
|
};
|
|
156
|
+
|
|
69
157
|
// We are going to modify the contents before returning them, so we make a copy.
|
|
70
158
|
// This isn't a deep copy and the application developer should not modify the returned content.
|
|
71
|
-
if (
|
|
72
|
-
config.model = { ...
|
|
159
|
+
if (model) {
|
|
160
|
+
config.model = { ...model };
|
|
73
161
|
}
|
|
74
|
-
if (
|
|
75
|
-
config.provider = { ...
|
|
162
|
+
if (configProvider) {
|
|
163
|
+
config.provider = { ...configProvider };
|
|
76
164
|
}
|
|
77
165
|
const allVariables = { ...variables, ldctx: context };
|
|
78
166
|
|
|
79
|
-
if (
|
|
80
|
-
config.messages =
|
|
167
|
+
if (messages) {
|
|
168
|
+
config.messages = messages.map((entry: any) => ({
|
|
81
169
|
...entry,
|
|
82
170
|
content: this._interpolateTemplate(entry.content, allVariables),
|
|
83
171
|
}));
|
|
@@ -88,9 +176,50 @@ export class LDAIClientImpl implements LDAIClient {
|
|
|
88
176
|
return {
|
|
89
177
|
...config,
|
|
90
178
|
toVercelAISDK: <TMod>(
|
|
91
|
-
|
|
179
|
+
sdkProvider: VercelAISDKProvider<TMod> | Record<string, VercelAISDKProvider<TMod>>,
|
|
92
180
|
options?: VercelAISDKMapOptions | undefined,
|
|
93
|
-
): VercelAISDKConfig<TMod> => mapper.toVercelAISDK(
|
|
181
|
+
): VercelAISDKConfig<TMod> => mapper.toVercelAISDK(sdkProvider, options),
|
|
94
182
|
};
|
|
95
183
|
}
|
|
184
|
+
|
|
185
|
+
async agent(
|
|
186
|
+
key: string,
|
|
187
|
+
context: LDContext,
|
|
188
|
+
defaultValue: LDAIAgentDefaults,
|
|
189
|
+
variables?: Record<string, unknown>,
|
|
190
|
+
): Promise<LDAIAgent> {
|
|
191
|
+
// Track agent usage
|
|
192
|
+
this._ldClient.track('$ld:ai:agent:function:single', context, key, 1);
|
|
193
|
+
|
|
194
|
+
return this._evaluateAgent(key, context, defaultValue, variables);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async agents<const T extends readonly (LDAIAgentConfig & { defaultValue: LDAIAgentDefaults })[]>(
|
|
198
|
+
agentConfigs: T,
|
|
199
|
+
context: LDContext,
|
|
200
|
+
): Promise<Record<T[number]['key'], LDAIAgent>> {
|
|
201
|
+
// Track multiple agents usage
|
|
202
|
+
this._ldClient.track(
|
|
203
|
+
'$ld:ai:agent:function:multiple',
|
|
204
|
+
context,
|
|
205
|
+
agentConfigs.length,
|
|
206
|
+
agentConfigs.length,
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
const agents = {} as Record<T[number]['key'], LDAIAgent>;
|
|
210
|
+
|
|
211
|
+
await Promise.all(
|
|
212
|
+
agentConfigs.map(async (config) => {
|
|
213
|
+
const agent = await this._evaluateAgent(
|
|
214
|
+
config.key,
|
|
215
|
+
context,
|
|
216
|
+
config.defaultValue,
|
|
217
|
+
config.variables,
|
|
218
|
+
);
|
|
219
|
+
agents[config.key as T[number]['key']] = agent;
|
|
220
|
+
}),
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
return agents;
|
|
224
|
+
}
|
|
96
225
|
}
|
|
@@ -19,14 +19,24 @@ export class LDAIConfigTrackerImpl implements LDAIConfigTracker {
|
|
|
19
19
|
private _configKey: string,
|
|
20
20
|
private _variationKey: string,
|
|
21
21
|
private _version: number,
|
|
22
|
+
private _modelName: string,
|
|
23
|
+
private _providerName: string,
|
|
22
24
|
private _context: LDContext,
|
|
23
25
|
) {}
|
|
24
26
|
|
|
25
|
-
private _getTrackData(): {
|
|
27
|
+
private _getTrackData(): {
|
|
28
|
+
variationKey: string;
|
|
29
|
+
configKey: string;
|
|
30
|
+
version: number;
|
|
31
|
+
modelName: string;
|
|
32
|
+
providerName: string;
|
|
33
|
+
} {
|
|
26
34
|
return {
|
|
27
35
|
variationKey: this._variationKey,
|
|
28
36
|
configKey: this._configKey,
|
|
29
37
|
version: this._version,
|
|
38
|
+
modelName: this._modelName,
|
|
39
|
+
providerName: this._providerName,
|
|
30
40
|
};
|
|
31
41
|
}
|
|
32
42
|
|
|
@@ -69,13 +79,11 @@ export class LDAIConfigTrackerImpl implements LDAIConfigTracker {
|
|
|
69
79
|
|
|
70
80
|
trackSuccess(): void {
|
|
71
81
|
this._trackedMetrics.success = true;
|
|
72
|
-
this._ldClient.track('$ld:ai:generation', this._context, this._getTrackData(), 1);
|
|
73
82
|
this._ldClient.track('$ld:ai:generation:success', this._context, this._getTrackData(), 1);
|
|
74
83
|
}
|
|
75
84
|
|
|
76
85
|
trackError(): void {
|
|
77
86
|
this._trackedMetrics.success = false;
|
|
78
|
-
this._ldClient.track('$ld:ai:generation', this._context, this._getTrackData(), 1);
|
|
79
87
|
this._ldClient.track('$ld:ai:generation:error', this._context, this._getTrackData(), 1);
|
|
80
88
|
}
|
|
81
89
|
|
package/src/api/LDAIClient.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { LDContext } from '@launchdarkly/js-server-sdk-common';
|
|
2
2
|
|
|
3
|
+
import { LDAIAgent, LDAIAgentConfig, LDAIAgentDefaults } from './agents';
|
|
3
4
|
import { LDAIConfig, LDAIDefaults } from './config/LDAIConfig';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -63,4 +64,83 @@ export interface LDAIClient {
|
|
|
63
64
|
defaultValue: LDAIDefaults,
|
|
64
65
|
variables?: Record<string, unknown>,
|
|
65
66
|
): Promise<LDAIConfig>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Retrieves and processes a single AI Config agent based on the provided key, LaunchDarkly context,
|
|
70
|
+
* and variables. This includes the model configuration and the customized instructions.
|
|
71
|
+
*
|
|
72
|
+
* @param key The key of the AI Config agent.
|
|
73
|
+
* @param context The LaunchDarkly context object that contains relevant information about the
|
|
74
|
+
* current environment, user, or session. This context may influence how the configuration is
|
|
75
|
+
* processed or personalized.
|
|
76
|
+
* @param defaultValue A fallback value containing model configuration and instructions.
|
|
77
|
+
* @param variables A map of key-value pairs representing dynamic variables to be injected into
|
|
78
|
+
* the instructions. The keys correspond to placeholders within the template, and the values
|
|
79
|
+
* are the corresponding replacements.
|
|
80
|
+
*
|
|
81
|
+
* @returns An AI agent with customized `instructions` and a `tracker`. If the configuration
|
|
82
|
+
* cannot be accessed from LaunchDarkly, then the return value will include information from the
|
|
83
|
+
* `defaultValue`. The returned `tracker` can be used to track AI operation metrics (latency, token usage, etc.).
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```
|
|
87
|
+
* const key = "research_agent";
|
|
88
|
+
* const context = {...};
|
|
89
|
+
* const variables = { topic: 'climate change' };
|
|
90
|
+
* const agent = await client.agent(key, context, {
|
|
91
|
+
* enabled: true,
|
|
92
|
+
* instructions: 'You are a research assistant.',
|
|
93
|
+
* }, variables);
|
|
94
|
+
*
|
|
95
|
+
* const researchResult = agent.instructions; // Interpolated instructions
|
|
96
|
+
* agent.tracker.trackSuccess();
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
agent(
|
|
100
|
+
key: string,
|
|
101
|
+
context: LDContext,
|
|
102
|
+
defaultValue: LDAIAgentDefaults,
|
|
103
|
+
variables?: Record<string, unknown>,
|
|
104
|
+
): Promise<LDAIAgent>;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Retrieves and processes multiple AI Config agents based on the provided agent configurations
|
|
108
|
+
* and LaunchDarkly context. This includes the model configuration and the customized instructions.
|
|
109
|
+
*
|
|
110
|
+
* @param agentConfigs An array of agent configurations, each containing the agent key, default configuration,
|
|
111
|
+
* and variables for instructions interpolation.
|
|
112
|
+
* @param context The LaunchDarkly context object that contains relevant information about the
|
|
113
|
+
* current environment, user, or session. This context may influence how the configuration is
|
|
114
|
+
* processed or personalized.
|
|
115
|
+
*
|
|
116
|
+
* @returns A map of agent keys to their respective AI agents with customized `instructions` and `tracker`.
|
|
117
|
+
* If a configuration cannot be accessed from LaunchDarkly, then the return value will include information
|
|
118
|
+
* from the respective `defaultValue`. The returned `tracker` can be used to track AI operation metrics
|
|
119
|
+
* (latency, token usage, etc.).
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```
|
|
123
|
+
* const agentConfigs = [
|
|
124
|
+
* {
|
|
125
|
+
* key: 'research_agent',
|
|
126
|
+
* defaultValue: { enabled: true, instructions: 'You are a research assistant.' },
|
|
127
|
+
* variables: { topic: 'climate change' }
|
|
128
|
+
* },
|
|
129
|
+
* {
|
|
130
|
+
* key: 'writing_agent',
|
|
131
|
+
* defaultValue: { enabled: true, instructions: 'You are a writing assistant.' },
|
|
132
|
+
* variables: { style: 'academic' }
|
|
133
|
+
* }
|
|
134
|
+
* ] as const;
|
|
135
|
+
* const context = {...};
|
|
136
|
+
*
|
|
137
|
+
* const agents = await client.agents(agentConfigs, context);
|
|
138
|
+
* const researchResult = agents["research_agent"].instructions; // Interpolated instructions
|
|
139
|
+
* agents["research_agent"].tracker.trackSuccess();
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
agents<const T extends readonly LDAIAgentConfig[]>(
|
|
143
|
+
agentConfigs: T,
|
|
144
|
+
context: LDContext,
|
|
145
|
+
): Promise<Record<T[number]['key'], LDAIAgent>>;
|
|
66
146
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { LDAIConfig } from '../config';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* AI Config agent and tracker.
|
|
5
|
+
*/
|
|
6
|
+
export interface LDAIAgent extends Omit<LDAIConfig, 'messages' | 'toVercelAISDK'> {
|
|
7
|
+
/**
|
|
8
|
+
* Instructions for the agent.
|
|
9
|
+
*/
|
|
10
|
+
instructions?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Configuration for a single agent request.
|
|
15
|
+
*/
|
|
16
|
+
export interface LDAIAgentConfig {
|
|
17
|
+
/**
|
|
18
|
+
* The agent key to retrieve.
|
|
19
|
+
*/
|
|
20
|
+
key: string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Default configuration for the agent.
|
|
24
|
+
*/
|
|
25
|
+
defaultValue: LDAIAgentDefaults;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Variables for instructions interpolation.
|
|
29
|
+
*/
|
|
30
|
+
variables?: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Default values for an agent.
|
|
35
|
+
*/
|
|
36
|
+
export type LDAIAgentDefaults = Omit<LDAIAgent, 'tracker'>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './LDAIAgent';
|
package/src/api/index.ts
CHANGED