Skip to content

Commit

Permalink
URLs revamp: DUST_FRONT_API (#2248)
Browse files Browse the repository at this point in the history
  • Loading branch information
lasryaric authored Oct 25, 2023
1 parent ddf65ee commit 8bd2c8c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
10 changes: 5 additions & 5 deletions connectors/src/lib/data_sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import logger from "@connectors/logger/logger";
import { statsDClient } from "@connectors/logger/withlogging";
import { DataSourceConfig } from "@connectors/types/data_source_config";

const { FRONT_API } = process.env;
if (!FRONT_API) {
const { DUST_FRONT_API } = process.env;
if (!DUST_FRONT_API) {
throw new Error("FRONT_API not set");
}

Expand Down Expand Up @@ -95,7 +95,7 @@ async function _upsertToDatasource({
const now = new Date();

const urlSafeName = encodeURIComponent(dataSourceConfig.dataSourceName);
const endpoint = `${FRONT_API}/api/v1/w/${dataSourceConfig.workspaceId}/data_sources/${urlSafeName}/documents/${documentId}`;
const endpoint = `${DUST_FRONT_API}/api/v1/w/${dataSourceConfig.workspaceId}/data_sources/${urlSafeName}/documents/${documentId}`;
const dustRequestPayload = {
text: documentText,
source_url: documentUrl,
Expand Down Expand Up @@ -168,7 +168,7 @@ export async function deleteFromDataSource(
const localLogger = logger.child({ ...loggerArgs, documentId });

const urlSafeName = encodeURIComponent(dataSourceConfig.dataSourceName);
const endpoint = `${FRONT_API}/api/v1/w/${dataSourceConfig.workspaceId}/data_sources/${urlSafeName}/documents/${documentId}`;
const endpoint = `${DUST_FRONT_API}/api/v1/w/${dataSourceConfig.workspaceId}/data_sources/${urlSafeName}/documents/${documentId}`;
const dustRequestConfig: AxiosRequestConfig = {
headers: {
Authorization: `Bearer ${dataSourceConfig.workspaceAPIKey}`,
Expand Down Expand Up @@ -204,7 +204,7 @@ export async function updateDocumentParentsField(
) {
const localLogger = logger.child({ ...loggerArgs, documentId });
const urlSafeName = encodeURIComponent(dataSourceConfig.dataSourceName);
const endpoint = `${FRONT_API}/api/v1/w/${dataSourceConfig.workspaceId}/data_sources/${urlSafeName}/documents/${documentId}/parents`;
const endpoint = `${DUST_FRONT_API}/api/v1/w/${dataSourceConfig.workspaceId}/data_sources/${urlSafeName}/documents/${documentId}/parents`;
const dustRequestConfig: AxiosRequestConfig = {
headers: {
Authorization: `Bearer ${dataSourceConfig.workspaceAPIKey}`,
Expand Down
19 changes: 11 additions & 8 deletions connectors/src/lib/dust_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type DataSourceType = {
connectorProvider?: ConnectorProvider;
};

const { DUST_API = "https://dust.tt" } = process.env;
const { DUST_FRONT_API } = process.env;

type DustAPIErrorResponse = {
type: string;
Expand Down Expand Up @@ -349,6 +349,9 @@ export class DustAPI {
*/
constructor(credentials: DustAPICredentials) {
this._credentials = credentials;
if (!DUST_FRONT_API) {
throw new Error("Missing DUST_FRONT_API env variable.");
}
}

workspaceId(): string {
Expand All @@ -363,7 +366,7 @@ export class DustAPI {
*/
async getDataSources(workspaceId: string) {
const res = await fetch(
`${DUST_API}/api/v1/w/${workspaceId}/data_sources`,
`${DUST_FRONT_API}/api/v1/w/${workspaceId}/data_sources`,
{
method: "GET",
headers: {
Expand Down Expand Up @@ -393,7 +396,7 @@ export class DustAPI {
>
> {
const res = await fetch(
`${DUST_API}/api/v1/w/${this.workspaceId()}/assistant/conversations`,
`${DUST_FRONT_API}/api/v1/w/${this.workspaceId()}/assistant/conversations`,
{
method: "POST",
headers: {
Expand Down Expand Up @@ -427,7 +430,7 @@ export class DustAPI {
message: PostMessagesRequestBodySchema;
}) {
const res = await fetch(
`${DUST_API}/api/v1/w/${this.workspaceId()}/assistant/conversations/${conversationId}/messages`,
`${DUST_FRONT_API}/api/v1/w/${this.workspaceId()}/assistant/conversations/${conversationId}/messages`,
{
method: "POST",
headers: {
Expand Down Expand Up @@ -461,7 +464,7 @@ export class DustAPI {
};

const res = await fetch(
`${DUST_API}/api/v1/w/${this.workspaceId()}/assistant/conversations/${
`${DUST_FRONT_API}/api/v1/w/${this.workspaceId()}/assistant/conversations/${
conversation.sId
}/messages/${message.sId}/events`,
{
Expand Down Expand Up @@ -560,7 +563,7 @@ export class DustAPI {

async getConversation({ conversationId }: { conversationId: string }) {
const res = await fetch(
`${DUST_API}/api/v1/w/${this.workspaceId()}/assistant/conversations/${conversationId}`,
`${DUST_FRONT_API}/api/v1/w/${this.workspaceId()}/assistant/conversations/${conversationId}`,
{
method: "GET",
headers: {
Expand All @@ -580,7 +583,7 @@ export class DustAPI {

async getAgentConfigurations() {
const res = await fetch(
`${DUST_API}/api/v1/w/${this.workspaceId()}/assistant/agent_configurations`,
`${DUST_FRONT_API}/api/v1/w/${this.workspaceId()}/assistant/agent_configurations`,
{
method: "GET",
headers: {
Expand All @@ -606,7 +609,7 @@ export class DustAPI {
contentFragment: PostContentFragmentRequestBody;
}) {
const res = await fetch(
`${DUST_API}/api/v1/w/${this.workspaceId()}/assistant/conversations/${conversationId}/content_fragments`,
`${DUST_FRONT_API}/api/v1/w/${this.workspaceId()}/assistant/conversations/${conversationId}/content_fragments`,
{
method: "POST",
headers: {
Expand Down
2 changes: 1 addition & 1 deletion k8s/deployments/connectors-edge-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ spec:
- name: NODE_OPTIONS
value: "-r dd-trace/init --max-old-space-size=600"

- name: FRONT_API
- name: DUST_FRONT_API
value: http://front-edge-service

- name: DD_AGENT_HOST
Expand Down

0 comments on commit 8bd2c8c

Please sign in to comment.