Skip to content

Commit

Permalink
Fix variable usage at build time and in client
Browse files Browse the repository at this point in the history
  • Loading branch information
tdraier committed Jan 16, 2025
1 parent b60a0ce commit b3924c4
Show file tree
Hide file tree
Showing 31 changed files with 143 additions and 173 deletions.
6 changes: 3 additions & 3 deletions front/admin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
internalSubscribeWorkspaceToFreeNoPlan,
internalSubscribeWorkspaceToFreePlan,
} from "@app/lib/plans/subscription";
import { DustProdActionRegistry } from "@app/lib/registry";
import { getDustProdActionRegistry } from "@app/lib/registry";
import { DataSourceResource } from "@app/lib/resources/data_source_resource";
import { GroupResource } from "@app/lib/resources/group_resource";
import { LabsTranscriptsConfigurationResource } from "@app/lib/resources/labs_transcripts_resource";
Expand Down Expand Up @@ -445,7 +445,7 @@ const transcripts = async (command: string, args: parseArgs.ParsedArgs) => {
const registry = async (command: string) => {
switch (command) {
case "dump": {
console.log(JSON.stringify(DustProdActionRegistry));
console.log(JSON.stringify(getDustProdActionRegistry()));
return;
}

Expand Down Expand Up @@ -507,7 +507,7 @@ const productionCheck = async (command: string, args: parseArgs.ParsedArgs) => {
args.url
);

const actions = Object.values(DustProdActionRegistry);
const actions = Object.values(getDustProdActionRegistry());

const res = await api.checkApps(
{
Expand Down
6 changes: 3 additions & 3 deletions front/lib/actions/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import apiConfig from "@app/lib/api/config";
import type { Authenticator } from "@app/lib/auth";
import { prodAPICredentialsForOwner } from "@app/lib/auth";
import type { DustRegistryActionName } from "@app/lib/registry";
import { DustProdActionRegistry } from "@app/lib/registry";
import { getDustProdAction } from "@app/lib/registry";
import logger from "@app/logger/logger";
import { statsDClient } from "@app/logger/withlogging";

Expand Down Expand Up @@ -60,7 +60,7 @@ export async function runActionStreamed(
});
}

const action = DustProdActionRegistry[actionName];
const action = getDustProdAction(actionName);

const loggerArgs = {
workspace: {
Expand Down Expand Up @@ -177,7 +177,7 @@ export async function runAction(
});
}

const action = DustProdActionRegistry[actionName];
const action = getDustProdAction(actionName);

const loggerArgs = {
workspace: {
Expand Down
4 changes: 2 additions & 2 deletions front/lib/api/assistant/actions/browse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { BaseActionRunParams } from "@app/lib/api/assistant/actions/types";
import { BaseActionConfigurationServerRunner } from "@app/lib/api/assistant/actions/types";
import type { Authenticator } from "@app/lib/auth";
import { AgentBrowseAction } from "@app/lib/models/assistant/actions/browse";
import { cloneBaseConfig, DustProdActionRegistry } from "@app/lib/registry";
import { cloneBaseConfig, getDustProdAction } from "@app/lib/registry";
import logger from "@app/logger/logger";

interface BrowseActionBlob {
Expand Down Expand Up @@ -188,7 +188,7 @@ export class BrowseConfigurationServerRunner extends BaseActionConfigurationServ
};

const config = cloneBaseConfig(
DustProdActionRegistry["assistant-v2-browse"].config
getDustProdAction("assistant-v2-browse").config
);

// Execute the browse action.
Expand Down
4 changes: 2 additions & 2 deletions front/lib/api/assistant/actions/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { constructPromptMultiActions } from "@app/lib/api/assistant/generation";
import { getSupportedModelConfig } from "@app/lib/assistant";
import type { Authenticator } from "@app/lib/auth";
import { AgentProcessAction } from "@app/lib/models/assistant/actions/process";
import { cloneBaseConfig, DustProdActionRegistry } from "@app/lib/registry";
import { cloneBaseConfig, getDustProdAction } from "@app/lib/registry";
import { DataSourceViewResource } from "@app/lib/resources/data_source_view_resource";
import logger from "@app/logger/logger";

Expand Down Expand Up @@ -250,7 +250,7 @@ export class ProcessConfigurationServerRunner extends BaseActionConfigurationSer
);

const config = cloneBaseConfig(
DustProdActionRegistry["assistant-v2-process"].config
getDustProdAction("assistant-v2-process").config
);

// Set the process action model configuration to the assistant model configuration.
Expand Down
4 changes: 2 additions & 2 deletions front/lib/api/assistant/actions/retrieval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { getRefs } from "@app/lib/api/assistant/citations";
import type { Authenticator } from "@app/lib/auth";
import { getDataSourceNameFromView } from "@app/lib/data_sources";
import { AgentRetrievalAction } from "@app/lib/models/assistant/actions/retrieval";
import { cloneBaseConfig, DustProdActionRegistry } from "@app/lib/registry";
import { cloneBaseConfig, getDustProdAction } from "@app/lib/registry";
import { DataSourceViewResource } from "@app/lib/resources/data_source_view_resource";
import type { RetrievalDocumentBlob } from "@app/lib/resources/retrieval_document_resource";
import { RetrievalDocumentResource } from "@app/lib/resources/retrieval_document_resource";
Expand Down Expand Up @@ -392,7 +392,7 @@ export class RetrievalConfigurationServerRunner extends BaseActionConfigurationS

// "assistant-v2-retrieval" has no model interaction.
const config = cloneBaseConfig(
DustProdActionRegistry["assistant-v2-retrieval"].config
getDustProdAction("assistant-v2-retrieval").config
);

// Handle data sources list and parents/tags filtering.
Expand Down
4 changes: 2 additions & 2 deletions front/lib/api/assistant/actions/tables_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { internalCreateToolOutputCsvFile } from "@app/lib/api/files/tool_output"
import { getSupportedModelConfig } from "@app/lib/assistant";
import type { Authenticator } from "@app/lib/auth";
import { AgentTablesQueryAction } from "@app/lib/models/assistant/actions/tables_query";
import { cloneBaseConfig, DustProdActionRegistry } from "@app/lib/registry";
import { cloneBaseConfig, getDustProdAction } from "@app/lib/registry";
import { FileResource } from "@app/lib/resources/file_resource";
import { FileModel } from "@app/lib/resources/storage/models/files";
import { sanitizeJSONOutput } from "@app/lib/utils";
Expand Down Expand Up @@ -381,7 +381,7 @@ export class TablesQueryConfigurationServerRunner extends BaseActionConfiguratio

// Generating configuration
const config = cloneBaseConfig(
DustProdActionRegistry["assistant-v2-query-tables"].config
getDustProdAction("assistant-v2-query-tables").config
);
const tables = actionConfiguration.tables.map((t) => ({
workspace_id: t.workspaceId,
Expand Down
4 changes: 2 additions & 2 deletions front/lib/api/assistant/actions/websearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
import { getRefs } from "@app/lib/api/assistant/citations";
import type { Authenticator } from "@app/lib/auth";
import { AgentWebsearchAction } from "@app/lib/models/assistant/actions/websearch";
import { cloneBaseConfig, DustProdActionRegistry } from "@app/lib/registry";
import { cloneBaseConfig, getDustProdAction } from "@app/lib/registry";
import logger from "@app/logger/logger";

interface WebsearchActionBlob {
Expand Down Expand Up @@ -211,7 +211,7 @@ export class WebsearchConfigurationServerRunner extends BaseActionConfigurationS

// "assitsant-v2-websearch" has no model interaction.
const config = cloneBaseConfig(
DustProdActionRegistry["assistant-v2-websearch"].config
getDustProdAction("assistant-v2-websearch").config
);

config.SEARCH.num = numResults;
Expand Down
4 changes: 2 additions & 2 deletions front/lib/api/assistant/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import { getRedisClient } from "@app/lib/api/redis";
import type { Authenticator } from "@app/lib/auth";
import { AgentConfiguration } from "@app/lib/models/assistant/agent";
import { AgentMessageContent } from "@app/lib/models/assistant/agent_message_content";
import { cloneBaseConfig, DustProdActionRegistry } from "@app/lib/registry";
import { cloneBaseConfig, getDustProdAction } from "@app/lib/registry";
import logger from "@app/logger/logger";

const CANCELLATION_CHECK_INTERVAL = 500;
Expand Down Expand Up @@ -481,7 +481,7 @@ async function* runMultiActionsAgent(
}

const config = cloneBaseConfig(
DustProdActionRegistry["assistant-v2-multi-actions-agent"].config
getDustProdAction("assistant-v2-multi-actions-agent").config
);
if (isLegacyAgent) {
config.MODEL.function_call =
Expand Down
4 changes: 2 additions & 2 deletions front/lib/api/assistant/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import {
UserMessage,
} from "@app/lib/models/assistant/conversation";
import { countActiveSeatsInWorkspaceCached } from "@app/lib/plans/usage/seats";
import { cloneBaseConfig, DustProdActionRegistry } from "@app/lib/registry";
import { cloneBaseConfig, getDustProdAction } from "@app/lib/registry";
import { ContentFragmentResource } from "@app/lib/resources/content_fragment_resource";
import { MembershipResource } from "@app/lib/resources/membership_resource";
import { frontSequelize } from "@app/lib/resources/storage";
Expand Down Expand Up @@ -512,7 +512,7 @@ export async function generateConversationTitle(
// `assistant-v2-title-generator` app.

const config = cloneBaseConfig(
DustProdActionRegistry["assistant-v2-title-generator"].config
getDustProdAction("assistant-v2-title-generator").config
);
config.MODEL.provider_id = model.providerId;
config.MODEL.model_id = model.modelId;
Expand Down
4 changes: 2 additions & 2 deletions front/lib/api/files/upsert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import config from "@app/lib/api/config";
import { upsertDocument, upsertTable } from "@app/lib/api/data_sources";
import type { Authenticator } from "@app/lib/auth";
import type { DustError } from "@app/lib/error";
import { cloneBaseConfig, DustProdActionRegistry } from "@app/lib/registry";
import { cloneBaseConfig, getDustProdAction } from "@app/lib/registry";
import type { DataSourceResource } from "@app/lib/resources/data_source_resource";
import type { FileResource } from "@app/lib/resources/file_resource";
import logger from "@app/logger/logger";
Expand Down Expand Up @@ -96,7 +96,7 @@ async function generateSnippet(
}

const appConfig = cloneBaseConfig(
DustProdActionRegistry["conversation-file-summarizer"].config
getDustProdAction("conversation-file-summarizer").config
);
appConfig.MODEL.provider_id = model.providerId;
appConfig.MODEL.model_id = model.modelId;
Expand Down
4 changes: 2 additions & 2 deletions front/lib/api/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { DateTime } from "luxon";
import { callAction } from "@app/lib/actions/helpers";
import config from "@app/lib/api/config";
import type { Authenticator } from "@app/lib/auth";
import { cloneBaseConfig, DustProdActionRegistry } from "@app/lib/registry";
import { cloneBaseConfig, getDustProdAction } from "@app/lib/registry";
import logger from "@app/logger/logger";

import type { DataSourceResource } from "../resources/data_source_resource";
Expand Down Expand Up @@ -589,7 +589,7 @@ async function detectHeaders(
}
headParser.destroy();

const action = DustProdActionRegistry["table-header-detection"];
const action = getDustProdAction("table-header-detection");

const model = getSmallWhitelistedModel(auth.getNonNullableWorkspace());
if (!model) {
Expand Down
12 changes: 5 additions & 7 deletions front/lib/api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Workspace } from "@app/lib/models/workspace";
import { ExtensionConfigurationResource } from "@app/lib/resources/extension";
import { UserMetadataModel } from "@app/lib/resources/storage/models/user";
import { UserResource } from "@app/lib/resources/user_resource";
import { renderLightWorkspaceType } from "@app/lib/workspace";
import logger from "@app/logger/logger";

import { MembershipResource } from "../resources/membership_resource";
Expand Down Expand Up @@ -166,13 +167,10 @@ export async function getUserWithWorkspaces<T extends boolean>(
...user.toJSON(),
workspaces: workspaces.map((w) => {
return {
id: w.id,
sId: w.sId,
name: w.name,
role: memberships.find((m) => m.workspaceId === w.id)?.role ?? "none",
segmentation: w.segmentation || null,
whiteListedProviders: w.whiteListedProviders,
defaultEmbeddingProvider: w.defaultEmbeddingProvider,
...renderLightWorkspaceType({
workspace: w,
role: memberships.find((m) => m.workspaceId === w.id)?.role ?? "none",
}),
...(populateExtensionConfig && {
blacklistedDomains:
configs.find((c) => c.workspaceId === w.id)?.blacklistedDomains ??
Expand Down
21 changes: 3 additions & 18 deletions front/lib/api/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,7 @@ export async function getWorkspaceInfos(
return null;
}

return {
id: workspace.id,
sId: workspace.sId,
name: workspace.name,
role: "none",
segmentation: workspace.segmentation,
whiteListedProviders: workspace.whiteListedProviders,
defaultEmbeddingProvider: workspace.defaultEmbeddingProvider,
};
return renderLightWorkspaceType({ workspace });
}

export async function getWorkspaceVerifiedDomain(
Expand Down Expand Up @@ -109,15 +101,8 @@ export async function setInternalWorkspaceSegmentation(
await workspace.update({
segmentation,
});
return {
id: workspace.id,
sId: workspace.sId,
name: workspace.name,
role: "none",
segmentation: workspace.segmentation,
whiteListedProviders: workspace.whiteListedProviders,
defaultEmbeddingProvider: workspace.defaultEmbeddingProvider,
};

return renderLightWorkspaceType({ workspace });
}

/**
Expand Down
11 changes: 4 additions & 7 deletions front/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,14 +660,11 @@ export class Authenticator {
workspace(): WorkspaceType | null {
return this._workspace
? {
id: this._workspace.id,
sId: this._workspace.sId,
name: this._workspace.name,
role: this._role,
segmentation: this._workspace.segmentation || null,
...renderLightWorkspaceType({
workspace: this._workspace,
role: this._role,
}),
ssoEnforced: this._workspace.ssoEnforced,
whiteListedProviders: this._workspace.whiteListedProviders,
defaultEmbeddingProvider: this._workspace.defaultEmbeddingProvider,
}
: null;
}
Expand Down
11 changes: 1 addition & 10 deletions front/lib/development.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import type { LightWorkspaceType, UserType } from "@dust-tt/types";
import { Err, isDevelopment, Ok } from "@dust-tt/types";

import config from "@app/lib/api/config";

function isADustProdWorkspace(owner: LightWorkspaceType) {
return (
owner.sId === config.getDustWorkspaceId() ||
owner.sId === config.getDustAppsWorkspaceId()
);
}

export function showDebugTools(owner: LightWorkspaceType) {
return isDevelopment() || isADustProdWorkspace(owner);
return owner.isADustWorkspace || isDevelopment();
}

export async function forceUserRole(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import _ from "lodash";

import { callAction } from "@app/lib/actions/helpers";
import type { Authenticator } from "@app/lib/auth";
import { cloneBaseConfig, DustProdActionRegistry } from "@app/lib/registry";
import { cloneBaseConfig, getDustProdAction } from "@app/lib/registry";
import type { TrackerMaintainedScopeType } from "@app/lib/resources/tracker_resource";

export async function callDocTrackerRetrievalAction(
Expand Down Expand Up @@ -34,7 +34,7 @@ export async function callDocTrackerRetrievalAction(
throw new Error("Duplicate data source ids in maintained scope");
}

const action = DustProdActionRegistry["doc-tracker-retrieval"];
const action = getDustProdAction("doc-tracker-retrieval");
const config = cloneBaseConfig(action.config);

config.SEMANTIC_SEARCH.data_sources = maintainedScope.map((view) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as t from "io-ts";

import { callAction } from "@app/lib/actions/helpers";
import type { Authenticator } from "@app/lib/auth";
import { cloneBaseConfig, DustProdActionRegistry } from "@app/lib/registry";
import { cloneBaseConfig, getDustProdAction } from "@app/lib/registry";

export async function callDocTrackerScoreDocsAction(
auth: Authenticator,
Expand All @@ -26,7 +26,7 @@ export async function callDocTrackerScoreDocsAction(
modelId: string;
}
): Promise<DocTrackerScoreDocsActionResult> {
const action = DustProdActionRegistry["doc-tracker-score-docs"];
const action = getDustProdAction("doc-tracker-score-docs");

const config = cloneBaseConfig(action.config);
config.MODEL.provider_id = providerId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as t from "io-ts";

import { callAction } from "@app/lib/actions/helpers";
import type { Authenticator } from "@app/lib/auth";
import { cloneBaseConfig, DustProdActionRegistry } from "@app/lib/registry";
import { cloneBaseConfig, getDustProdAction } from "@app/lib/registry";

// Part of the new doc tracker pipeline, suggest changes based on a "source_document" (new incoming doc)
// and a "target_document" (the tracked doc)
Expand All @@ -24,7 +24,7 @@ export async function callDocTrackerSuggestChangesAction(
modelId: string;
}
): Promise<DocTrackerSuggestChangesActionResult> {
const action = DustProdActionRegistry["doc-tracker-suggest-changes"];
const action = getDustProdAction("doc-tracker-suggest-changes");

const config = cloneBaseConfig(action.config);
config.SUGGEST_CHANGES.provider_id = providerId;
Expand Down
Loading

0 comments on commit b3924c4

Please sign in to comment.