Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
professorice authored Jan 24, 2025
2 parents 5bccb5b + 83f9cb1 commit 1b440a8
Show file tree
Hide file tree
Showing 16 changed files with 152 additions and 20 deletions.
6 changes: 3 additions & 3 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"packages/store/node-server-sdk-dynamodb": "6.2.3",
"packages/store/node-server-sdk-redis": "4.2.3",
"packages/shared/sdk-client": "1.12.2",
"packages/sdk/react-native": "10.9.4",
"packages/sdk/react-native": "10.9.5",
"packages/telemetry/node-server-sdk-otel": "1.1.3",
"packages/sdk/browser": "0.4.0",
"packages/sdk/server-ai": "0.7.1",
"packages/telemetry/browser-telemetry": "0.1.0"
"packages/sdk/server-ai": "0.8.1",
"packages/telemetry/browser-telemetry": "0.2.0"
}
7 changes: 7 additions & 0 deletions packages/sdk/react-native/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [10.9.5](https://github.com/launchdarkly/js-core/compare/react-native-client-sdk-v10.9.4...react-native-client-sdk-v10.9.5) (2025-01-24)


### Bug Fixes

* **react-native:** check for nullability in SettingsManager?.settings ([#758](https://github.com/launchdarkly/js-core/issues/758)) ([3449934](https://github.com/launchdarkly/js-core/commit/3449934027697ac9283aeeeca8df9a76d172fcad))

## [10.9.4](https://github.com/launchdarkly/js-core/compare/react-native-client-sdk-v10.9.3...react-native-client-sdk-v10.9.4) (2025-01-22)


Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/react-native/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@launchdarkly/react-native-client-sdk",
"version": "10.9.4",
"version": "10.9.5",
"description": "React Native LaunchDarkly SDK",
"homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/sdk/react-native",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/react-native/src/platform/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { NativeModules, Platform } from 'react-native';
*/
const locale =
Platform.OS === 'ios'
? NativeModules.SettingsManager?.settings.AppleLocale // iOS
? NativeModules.SettingsManager?.settings?.AppleLocale // iOS
: NativeModules.I18nManager?.localeIdentifier;

export default locale;
14 changes: 14 additions & 0 deletions packages/sdk/server-ai/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## [0.8.1](https://github.com/launchdarkly/js-core/compare/server-sdk-ai-v0.8.0...server-sdk-ai-v0.8.1) (2025-01-24)


### Bug Fixes

* Correct documentation for AI config function. ([#754](https://github.com/launchdarkly/js-core/issues/754)) ([0bdb0be](https://github.com/launchdarkly/js-core/commit/0bdb0be6b0e0213c5139af9008884ea74be197b1))

## [0.8.0](https://github.com/launchdarkly/js-core/compare/server-sdk-ai-v0.7.1...server-sdk-ai-v0.8.0) (2025-01-23)


### Features

* track timeToFirstToken in LDAIConfigTracker ([#749](https://github.com/launchdarkly/js-core/issues/749)) ([c97674f](https://github.com/launchdarkly/js-core/commit/c97674fe521bcfe14dc6e0679bf25e293a2a1ad1))

## [0.7.1](https://github.com/launchdarkly/js-core/compare/server-sdk-ai-v0.7.0...server-sdk-ai-v0.7.1) (2025-01-22)


Expand Down
12 changes: 12 additions & 0 deletions packages/sdk/server-ai/__tests__/LDAIConfigTrackerImpl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ it('tracks duration of async function', async () => {
);
});

it('tracks time to first token', () => {
const tracker = new LDAIConfigTrackerImpl(mockLdClient, configKey, variationKey, testContext);
tracker.trackTimeToFirstToken(1000);

expect(mockTrack).toHaveBeenCalledWith(
'$ld:ai:tokens:ttf',
testContext,
{ configKey, variationKey },
1000,
);
});

it('tracks positive feedback', () => {
const tracker = new LDAIConfigTrackerImpl(mockLdClient, configKey, variationKey, testContext);
tracker.trackFeedback({ kind: LDFeedbackKind.Positive });
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/server-ai/examples/bedrock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"dependencies": {
"@aws-sdk/client-bedrock-runtime": "^3.679.0",
"@launchdarkly/node-server-sdk": "^9.7.1",
"@launchdarkly/server-sdk-ai": "0.7.1"
"@launchdarkly/server-sdk-ai": "0.8.1"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/server-ai/examples/openai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"license": "Apache-2.0",
"dependencies": {
"@launchdarkly/node-server-sdk": "^9.7.1",
"@launchdarkly/server-sdk-ai": "0.7.1",
"@launchdarkly/server-sdk-ai": "0.8.1",
"openai": "^4.58.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/server-ai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@launchdarkly/server-sdk-ai",
"version": "0.7.1",
"version": "0.8.1",
"description": "LaunchDarkly AI SDK for Server-Side JavaScript",
"homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/sdk/server-ai",
"repository": {
Expand Down
10 changes: 10 additions & 0 deletions packages/sdk/server-ai/src/LDAIConfigTrackerImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ export class LDAIConfigTrackerImpl implements LDAIConfigTracker {
}
}

trackTimeToFirstToken(timeToFirstTokenMs: number) {
this._trackedMetrics.timeToFirstTokenMs = timeToFirstTokenMs;
this._ldClient.track(
'$ld:ai:tokens:ttf',
this._context,
this._getTrackData(),
timeToFirstTokenMs,
);
}

trackFeedback(feedback: { kind: LDFeedbackKind }): void {
this._trackedMetrics.feedback = feedback;
if (feedback.kind === LDFeedbackKind.Positive) {
Expand Down
19 changes: 9 additions & 10 deletions packages/sdk/server-ai/src/api/LDAIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@ import { LDAIConfig, LDAIDefaults } from './config/LDAIConfig';
export interface LDAIClient {
/**
* Retrieves and processes an AI configuration based on the provided key, LaunchDarkly context,
* and variables. This includes the model configuration and the processed prompts.
* and variables. This includes the model configuration and the customized messages.
*
* @param key The key of the AI configuration.
* @param context The LaunchDarkly context object that contains relevant information about the
* current environment, user, or session. This context may influence how the configuration is
* processed or personalized.
* @param defaultValue A fallback value containing model configuration and messages. This will
* be used if the configuration is not available from LaunchDarkly.
* @param variables A map of key-value pairs representing dynamic variables to be injected into
* the prompt template. The keys correspond to placeholders within the template, and the values
* the message content. The keys correspond to placeholders within the template, and the values
* are the corresponding replacements.
* @param defaultValue A fallback value containing model configuration and prompts. This will
* be used if the configurationuration is not available from launchdarkly.
*
* @returns The AI configurationuration including a processed prompt after all variables have been
* substituted in the stored prompt template. This will also include a `tracker` used to track
* the state of the AI operation. If the configuration cannot be accessed from LaunchDarkly, then
* the return value will include information from the defaultValue.
* @returns The AI `config`, customized `messages`, and a `tracker`. If the configuration cannot be accessed from
* LaunchDarkly, then the return value will include information from the `defaultValue`. The returned `tracker` can
* be used to track AI operation metrics (latency, token usage, etc.).
*
* @example
* ```
Expand All @@ -34,7 +33,7 @@ export interface LDAIClient {
* enabled: false,
* };
*
* const result = modelConfig(key, context, defaultValue, variables);
* const result = config(key, context, defaultValue, variables);
* // Output:
* {
* enabled: true,
Expand All @@ -44,7 +43,7 @@ export interface LDAIClient {
* maxTokens: 4096,
* userDefinedKey: "myValue",
* },
* prompt: [
* messages: [
* {
* role: "system",
* content: "You are an amazing GPT."
Expand Down
12 changes: 12 additions & 0 deletions packages/sdk/server-ai/src/api/config/LDAIConfigTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export interface LDAIMetricSummary {
* Any sentiment about the generation.
*/
feedback?: { kind: LDFeedbackKind };

/**
* Time to first token for this generation.
*/
timeToFirstTokenMs?: number;
}

/**
Expand Down Expand Up @@ -62,6 +67,13 @@ export interface LDAIConfigTracker {
*/
trackFeedback(feedback: { kind: LDFeedbackKind }): void;

/**
* Track the time to first token for this generation.
*
* @param timeToFirstTokenMs The duration in milliseconds.
*/
trackTimeToFirstToken(timeToFirstTokenMs: number): void;

/**
* Track the duration of execution of the provided function.
*
Expand Down
14 changes: 14 additions & 0 deletions packages/telemetry/browser-telemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## [0.2.0](https://github.com/launchdarkly/js-core/compare/browser-telemetry-v0.1.1...browser-telemetry-v0.2.0) (2025-01-23)


### Features

* Add support for filtering username/password URL authority. ([#751](https://github.com/launchdarkly/js-core/issues/751)) ([62ab9fb](https://github.com/launchdarkly/js-core/commit/62ab9fb774847b5d953041f29b5f997629f86fa7))

## [0.1.1](https://github.com/launchdarkly/js-core/compare/browser-telemetry-v0.1.0...browser-telemetry-v0.1.1) (2025-01-23)


### Bug Fixes

* Fix race condition with client registration. ([#750](https://github.com/launchdarkly/js-core/issues/750)) ([d2ac2e2](https://github.com/launchdarkly/js-core/commit/d2ac2e230118b573b4e90b5781350067c7920fcf))

## [0.1.0](https://github.com/launchdarkly/js-core/compare/browser-telemetry-v0.0.9...browser-telemetry-v0.1.0) (2025-01-22)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,27 @@ it.each([
])('passes through other URLs unfiltered', (url) => {
expect(defaultUrlFilter(url)).toBe(url);
});

it('filters out username and password from URLs', () => {
const urls = [
// Username only
{
input: 'https://[email protected]/',
expected: 'https://[email protected]/',
},
// Password only
{
input: 'https://:[email protected]/',
expected: 'https://:[email protected]/',
},
// Both username and password
{
input: 'https://user:[email protected]/',
expected: 'https://redacted:[email protected]/',
},
];

urls.forEach(({ input, expected }) => {
expect(defaultUrlFilter(input)).toBe(expected);
});
});
2 changes: 1 addition & 1 deletion packages/telemetry/browser-telemetry/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@launchdarkly/browser-telemetry",
"version": "0.1.0",
"version": "0.2.0",
"packageManager": "[email protected]",
"type": "module",
"main": "./dist/index.cjs",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
const pollingRegex = /sdk\/evalx\/[^/]+\/contexts\/(?<context>[^/?]*)\??.*?/;
const streamingREgex = /\/eval\/[^/]+\/(?<context>[^/?]*)\??.*?/;

/**
* Filter which redacts user information (auth) from a URL.
*
* If a username/password is present, then they are replaced with 'redacted'.
* Authority reference: https://developer.mozilla.org/en-US/docs/Web/URI/Authority
*
* @param url URL to filter.
* @returns A filtered URL.
*/
function authorityUrlFilter(url: string): string {
// This will work in browser environments, but in the future we may want to consider an approach
// which doesn't rely on the browser's URL parsing. This is because other environments we may
// want to target, such as ReactNative, may not have as robust URL parsing.
const urlObj = new URL(url);
let hadAuth = false;
if (urlObj.username) {
urlObj.username = 'redacted';
hadAuth = true;
}
if (urlObj.password) {
urlObj.password = 'redacted';
hadAuth = true;
}
if (hadAuth) {
return urlObj.toString();
}
// If there was no auth information, then we don't need to modify the URL.
return url;
}

/**
* Filter which removes context information for browser JavaScript endpoints.
*
* @param url URL to filter.
* @returns A filtered URL.
*/
export default function defaultUrlFilter(url: string): string {
function ldUrlFilter(url: string): string {
// TODO: Maybe we consider a way to identify LD requests so they can be filtered without
// regular expressions.

Expand All @@ -27,3 +57,13 @@ export default function defaultUrlFilter(url: string): string {
}
return url;
}

/**
* Filter which redacts user information and removes context information for browser JavaScript endpoints.
*
* @param url URL to filter.
* @returns A filtered URL.
*/
export default function defaultUrlFilter(url: string): string {
return ldUrlFilter(authorityUrlFilter(url));
}

0 comments on commit 1b440a8

Please sign in to comment.