Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions js/src/gitutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from "./generated_types";
import { debugLogger } from "./debug-logger";
import { simpleGit } from "simple-git";
import { defaultGitMetadataSettings } from "../util/git_fields";

const COMMON_BASE_BRANCHES = ["main", "master", "develop"];

Expand Down Expand Up @@ -149,17 +150,18 @@ function truncateToByteLimit(s: string, byteLimit: number = 65536): string {
}

export async function getRepoInfo(settings?: GitMetadataSettings) {
if (settings && settings.collect === "none") {
const resolvedSettings = settings ?? defaultGitMetadataSettings();
if (resolvedSettings.collect === "none") {
return undefined;
}

const repo = await repoInfo();
if (!repo || !settings || settings.collect === "all") {
if (!repo || resolvedSettings.collect === "all") {
return repo;
}

let sanitized: RepoInfo = {};
settings.fields?.forEach((field) => {
resolvedSettings.fields?.forEach((field) => {
sanitized = { ...sanitized, [field]: repo[field] };
});

Expand Down
20 changes: 10 additions & 10 deletions js/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
IdField,
IS_MERGE_FIELD,
LogFeedbackFullArgs,
defaultGitMetadataSettings,
mergeDicts,
mergeGitMetadataSettings,
mergeRowBatch,
Expand Down Expand Up @@ -3535,7 +3536,7 @@ type InitializedExperiment<IsOpen extends boolean | undefined> =
* @param options.apiKey The API key to use. If the parameter is not specified, will try to use the `BRAINTRUST_API_KEY` environment variable. If no API key is specified, will prompt the user to login.
* @param options.orgName (Optional) The name of a specific organization to connect to. This is useful if you belong to multiple.
* @param options.metadata (Optional) A dictionary with additional data about the test example, model outputs, or just about anything else that's relevant, that you can use to help find and analyze examples later. For example, you could log the `prompt`, example's `id`, or anything else that would be useful to slice/dice later. The values in `metadata` can be any JSON-serializable type, but its keys must be strings.
* @param options.gitMetadataSettings (Optional) Settings for collecting git metadata. By default, will collect all git metadata fields allowed in org-level settings.
* @param options.gitMetadataSettings (Optional) Settings for collecting git metadata. By default, will collect git metadata fields allowed in org-level settings, excluding diff content unless the org opts in.
* @param setCurrent If true (the default), set the global current-experiment to the newly-created one.
* @param options.open If the experiment already exists, open it in read-only mode. Throws an error if the experiment does not already exist.
* @param options.projectId The id of the project to create the experiment in. This takes precedence over `project` if specified.
Expand Down Expand Up @@ -3689,9 +3690,7 @@ export function init<IsOpen extends boolean = false>(
return repoInfo;
}
let mergedGitMetadataSettings = {
...(state.gitMetadataSettings || {
collect: "all",
}),
...(state.gitMetadataSettings || defaultGitMetadataSettings()),
};
if (gitMetadataSettings) {
mergedGitMetadataSettings = mergeGitMetadataSettings(
Expand Down Expand Up @@ -4263,8 +4262,8 @@ export function initDataset<
legacy,
_internal_btql,
resolvedVersion instanceof LazyValue ||
normalizedEnvironment !== undefined ||
normalizedSnapshotName !== undefined
normalizedEnvironment !== undefined ||
normalizedSnapshotName !== undefined
? {
...(resolvedVersion instanceof LazyValue
? {
Expand Down Expand Up @@ -5699,7 +5698,8 @@ function _saveOrgInfo(
state.orgName = org.name;
state.apiUrl = iso.getEnv("BRAINTRUST_API_URL") ?? org.api_url;
state.proxyUrl = iso.getEnv("BRAINTRUST_PROXY_URL") ?? org.proxy_url;
state.gitMetadataSettings = org.git_metadata || undefined;
state.gitMetadataSettings =
org.git_metadata || defaultGitMetadataSettings();
break;
}
}
Expand Down Expand Up @@ -6041,9 +6041,9 @@ export type WithTransactionId<R> = R & {
export const DEFAULT_FETCH_BATCH_SIZE = 1000;
export const MAX_BTQL_ITERATIONS = 10000;

export class ObjectFetcher<RecordType> implements AsyncIterable<
WithTransactionId<RecordType>
> {
export class ObjectFetcher<RecordType>
implements AsyncIterable<WithTransactionId<RecordType>>
{
private _fetchedData: WithTransactionId<RecordType>[] | undefined = undefined;

constructor(
Expand Down
22 changes: 21 additions & 1 deletion js/util/git_fields.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
import { GitMetadataSettingsType as GitMetadataSettings } from "./generated_types";
import { type GitMetadataSettingsType as GitMetadataSettings } from "./generated_types";

export const DEFAULT_GIT_METADATA_FIELDS: NonNullable<
GitMetadataSettings["fields"]
> = [
"commit",
"branch",
"tag",
"dirty",
"author_name",
"author_email",
"commit_message",
"commit_time",
];

export function defaultGitMetadataSettings(): GitMetadataSettings {
return {
collect: "some",
fields: [...DEFAULT_GIT_METADATA_FIELDS],
};
}

export function mergeGitMetadataSettings(
s1: GitMetadataSettings,
Expand Down
5 changes: 4 additions & 1 deletion js/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ export {
spanTypeAttributeValues,
} from "./span_types";

export { mergeGitMetadataSettings } from "./git_fields";
export {
defaultGitMetadataSettings,
mergeGitMetadataSettings,
} from "./git_fields";

export { loadPrettyXact, prettifyXact } from "./xact-ids";

Expand Down
Loading