Skip to content

Commit

Permalink
Fix/undefined is not json serializable (#1245)
Browse files Browse the repository at this point in the history
* types from apps.ts

* chat related types

* datasource related types

* extract types

* fix chat

* review
  • Loading branch information
fontanierh authored Sep 4, 2023
1 parent a3f8479 commit cb430a1
Show file tree
Hide file tree
Showing 27 changed files with 130 additions and 84 deletions.
9 changes: 9 additions & 0 deletions front/lib/ajv_utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// see here: https://github.com/ajv-validator/ajv/issues/1375#issuecomment-1328076097
// AJV is a little broken in the way it handles nullable types.

export const nullable = <T>(input: T): T => {
return {
...input,
nullable: true,
} as T;
};
16 changes: 8 additions & 8 deletions front/lib/api/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export async function getApp(
id: app.id,
sId: app.sId,
name: app.name,
description: app.description ?? undefined,
description: app.description,
visibility: app.visibility,
savedSpecification: app.savedSpecification ?? undefined,
savedConfig: app.savedConfig ?? undefined,
savedRun: app.savedRun ?? undefined,
savedSpecification: app.savedSpecification,
savedConfig: app.savedConfig,
savedRun: app.savedRun,
dustAPIProjectId: app.dustAPIProjectId,
};
}
Expand Down Expand Up @@ -73,11 +73,11 @@ export async function getApps(auth: Authenticator): Promise<AppType[]> {
id: app.id,
sId: app.sId,
name: app.name,
description: app.description ?? undefined,
description: app.description,
visibility: app.visibility,
savedSpecification: app.savedSpecification ?? undefined,
savedConfig: app.savedConfig ?? undefined,
savedRun: app.savedRun ?? undefined,
savedSpecification: app.savedSpecification,
savedConfig: app.savedConfig,
savedRun: app.savedRun,
dustAPIProjectId: app.dustAPIProjectId,
};
});
Expand Down
23 changes: 20 additions & 3 deletions front/lib/api/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export async function getChatSession(
sId: chatSession.sId,
title: chatSession.title,
visibility: chatSession.visibility,
messages: null,
};
}

Expand Down Expand Up @@ -147,6 +148,7 @@ export async function takeOwnerShipOfChatSession(
sId: chatSession.sId,
title: chatSession.title,
visibility: chatSession.visibility,
messages: null,
};
}

Expand Down Expand Up @@ -220,6 +222,7 @@ export async function upsertChatSession(
sId: chatSession.sId,
title: chatSession.title,
visibility: chatSession.visibility,
messages: null,
};
});
}
Expand Down Expand Up @@ -265,7 +268,7 @@ export async function getChatSessionWithMessages(
messages: messages.map((m) => {
return {
role: m.role,
message: m.message ?? undefined,
message: m.message,
feedback: m.feedback,
sId: m.sId,
retrievals: chatMessagesRetrieval[m.id].map((r) => {
Expand All @@ -279,6 +282,7 @@ export async function getChatSessionWithMessages(
chunks: [],
};
}),
params: null,
};
}),
};
Expand Down Expand Up @@ -328,7 +332,7 @@ export async function getChatMessage(

return {
role: chatMessage.role,
message: chatMessage.message ?? undefined,
message: chatMessage.message,
feedback: chatMessage.feedback,
sId: chatMessage.sId,
retrievals: retrievedDocuments.map((r) => {
Expand All @@ -342,6 +346,7 @@ export async function getChatMessage(
chunks: [],
};
}),
params: null,
};
}

Expand Down Expand Up @@ -570,6 +575,9 @@ export async function* newChat(
sId: new_id(),
role: "user",
message: userMessage,
retrievals: null,
params: null,
feedback: null,
},
];

Expand All @@ -582,6 +590,9 @@ export async function* newChat(
sId: new_id(),
role: "error",
message: errorMessage,
retrievals: null,
params: null,
feedback: null,
});

yield {
Expand Down Expand Up @@ -672,7 +683,10 @@ export async function* newChat(
messages.push({
sId: new_id(),
role: "assistant",
message: m.message,
message: m.message ?? null,
retrievals: null,
params: null,
feedback: null,
});
}

Expand All @@ -685,6 +699,9 @@ export async function* newChat(
sId: new_id(),
role: "retrieval",
params: m.params,
retrievals: null,
feedback: null,
message: null,
});
}
}
Expand Down
16 changes: 8 additions & 8 deletions front/lib/api/data_sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ export async function getDataSource(
return {
id: dataSource.id,
name: dataSource.name,
description: dataSource.description ?? undefined,
description: dataSource.description,
visibility: dataSource.visibility,
config: dataSource.config ?? undefined,
config: dataSource.config,
dustAPIProjectId: dataSource.dustAPIProjectId,
connectorId: dataSource.connectorId ?? undefined,
connectorProvider: dataSource.connectorProvider ?? undefined,
connectorId: dataSource.connectorId,
connectorProvider: dataSource.connectorProvider,
assistantDefaultSelected: dataSource.assistantDefaultSelected,
};
}
Expand Down Expand Up @@ -75,12 +75,12 @@ export async function getDataSources(
return {
id: dataSource.id,
name: dataSource.name,
description: dataSource.description ?? undefined,
description: dataSource.description,
visibility: dataSource.visibility,
config: dataSource.config ?? undefined,
config: dataSource.config,
dustAPIProjectId: dataSource.dustAPIProjectId,
connectorId: dataSource.connectorId ?? undefined,
connectorProvider: dataSource.connectorProvider ?? undefined,
connectorId: dataSource.connectorId,
connectorProvider: dataSource.connectorProvider,
assistantDefaultSelected: dataSource.assistantDefaultSelected,
};
});
Expand Down
8 changes: 5 additions & 3 deletions front/lib/api/datasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export async function getDatasets(

return datasets.map((dataset) => ({
name: dataset.name,
description: dataset.description ?? undefined,
description: dataset.description,
data: null,
}));
}

Expand Down Expand Up @@ -52,7 +53,8 @@ export async function getDataset(

return {
name: dataset.name,
description: dataset.description ?? undefined,
description: dataset.description,
data: null,
};
}

Expand Down Expand Up @@ -110,7 +112,7 @@ export async function getDatasetHash(

return {
name: dataset.name,
description: dataset.description ?? undefined,
description: dataset.description,
data: apiDataset.value.dataset.data,
};
}
2 changes: 1 addition & 1 deletion front/lib/api/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function _getEventSchemaType(schema: EventSchema): EventSchemaType {
id: schema.id,
sId: schema.sId,
marker: schema.marker,
description: schema.description ?? undefined,
description: schema.description,
status: schema.status,
properties: schema.properties,
};
Expand Down
2 changes: 1 addition & 1 deletion front/lib/datasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function areSetsEqual(a: Set<any>, b: Set<any>): boolean {
return true;
}

export function checkDatasetData(data: Array<object> | undefined): string[] {
export function checkDatasetData(data?: Array<object> | null): string[] {
if (!data) {
throw new Error("data must be defined");
}
Expand Down
2 changes: 1 addition & 1 deletion front/lib/extract_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ async function _processExtractEventsForMarker({
auth,
content: contentToProcess,
marker: marker,
schema: { ...schema, description: schema.description ?? undefined },
schema,
});

if (result.length === 0) {
Expand Down
8 changes: 4 additions & 4 deletions front/pages/api/w/[wId]/apps/[aId]/clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ async function handler(
id: cloned.id,
sId: cloned.sId,
name: cloned.name,
description: cloned.description ?? undefined,
description: cloned.description,
visibility: cloned.visibility,
savedSpecification: cloned.savedSpecification ?? undefined,
savedConfig: cloned.savedConfig ?? undefined,
savedRun: cloned.savedRun ?? undefined,
savedSpecification: cloned.savedSpecification,
savedConfig: cloned.savedConfig,
savedRun: cloned.savedRun,
dustAPIProjectId: cloned.dustAPIProjectId,
},
});
Expand Down
6 changes: 4 additions & 2 deletions front/pages/api/w/[wId]/apps/[aId]/datasets/[name]/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ async function handler(

res.status(200).json({
dataset: {
name: req.body.name,
name: typeof req.body.name == "string" ? req.body.name : null,
description,
data: null,
},
});
return;
Expand Down Expand Up @@ -170,7 +171,8 @@ async function handler(
res.status(200).json({
dataset: {
name: dataset.name,
description: dataset.description ?? undefined,
description: dataset.description,
data: null,
},
});
return;
Expand Down
1 change: 1 addition & 0 deletions front/pages/api/w/[wId]/apps/[aId]/datasets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ async function handler(
dataset: {
name: req.body.name,
description,
data: null,
},
});
return;
Expand Down
8 changes: 4 additions & 4 deletions front/pages/api/w/[wId]/apps/[aId]/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ async function handler(
id: app.id,
sId: app.sId,
name: app.name,
description: app.description ?? undefined,
description: app.description,
visibility: app.visibility,
savedSpecification: app.savedSpecification ?? undefined,
savedConfig: app.savedConfig ?? undefined,
savedRun: app.savedRun ?? undefined,
savedSpecification: app.savedSpecification,
savedConfig: app.savedConfig,
savedRun: app.savedRun,
dustAPIProjectId: app.dustAPIProjectId,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ async function handler(
});
}

let runId = req.query.runId;
let runId: string | null =
typeof req.query.runId === "string" ? req.query.runId : null;

if (runId === "saved") {
runId = app.savedRun;
}
Expand All @@ -52,7 +54,7 @@ async function handler(

const run = await CoreAPI.getRunBlock({
projectId: app.dustAPIProjectId,
runId: runId as string,
runId: runId,
blockType: req.query.type as BlockType,
blockName: req.query.name as string,
});
Expand Down
5 changes: 3 additions & 2 deletions front/pages/api/w/[wId]/apps/[aId]/runs/[runId]/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ async function handler(
});
}

let runId = req.query.runId;
let runId: string | null =
typeof req.query.runId === "string" ? req.query.runId : null;
if (runId === "saved") {
runId = app.savedRun;
}
Expand All @@ -46,7 +47,7 @@ async function handler(

const run = await CoreAPI.getRunStatus({
projectId: app.dustAPIProjectId,
runId: runId as string,
runId: runId,
});
if (run.isErr()) {
return apiError(req, res, {
Expand Down
8 changes: 4 additions & 4 deletions front/pages/api/w/[wId]/apps/[aId]/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ async function handler(
id: app.id,
sId: app.sId,
name: app.name,
description: app.description ?? undefined,
description: app.description,
visibility: app.visibility,
savedSpecification: app.savedSpecification ?? undefined,
savedConfig: app.savedConfig ?? undefined,
savedRun: app.savedRun ?? undefined,
savedSpecification: app.savedSpecification,
savedConfig: app.savedConfig,
savedRun: app.savedRun,
dustAPIProjectId: app.dustAPIProjectId,
},
});
Expand Down
8 changes: 4 additions & 4 deletions front/pages/api/w/[wId]/apps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ async function handler(
id: app.id,
sId: app.sId,
name: app.name,
description: app.description ?? undefined,
description: app.description,
visibility: app.visibility,
savedSpecification: app.savedSpecification ?? undefined,
savedConfig: app.savedConfig ?? undefined,
savedRun: app.savedRun ?? undefined,
savedSpecification: app.savedSpecification,
savedConfig: app.savedConfig,
savedRun: app.savedRun,
dustAPIProjectId: app.dustAPIProjectId,
},
});
Expand Down
8 changes: 4 additions & 4 deletions front/pages/api/w/[wId]/data_sources/[name]/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ async function handler(
dataSource: {
id: ds.id,
name: ds.name,
description: ds.description ?? undefined,
description: ds.description,
visibility: ds.visibility,
assistantDefaultSelected: ds.assistantDefaultSelected,
config: ds.config ?? undefined,
config: ds.config,
dustAPIProjectId: ds.dustAPIProjectId,
connectorId: ds.connectorId ?? undefined,
connectorProvider: ds.connectorProvider ?? undefined,
connectorId: ds.connectorId,
connectorProvider: ds.connectorProvider,
},
});

Expand Down
6 changes: 4 additions & 2 deletions front/pages/api/w/[wId]/data_sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,13 @@ async function handler(
dataSource: {
id: ds.id,
name: ds.name,
description: ds.description ?? undefined,
description: ds.description,
visibility: ds.visibility,
config: ds.config ?? undefined,
config: ds.config,
dustAPIProjectId: ds.dustAPIProjectId,
assistantDefaultSelected: ds.assistantDefaultSelected,
connectorId: null,
connectorProvider: null,
},
});
return;
Expand Down
Loading

0 comments on commit cb430a1

Please sign in to comment.