Skip to content

Commit

Permalink
Address some PR comments, naming and comment updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nichochar committed Jul 19, 2024
1 parent b56aab5 commit bc42118
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 24 deletions.
9 changes: 3 additions & 6 deletions packages/api/ai/generate.mts
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,9 @@ export async function generateCells(
}

// Parse the result into cells
const text = result.text;

// TODO figure out logging here. It's incredibly valuable to see the data going to and from the LLM
// for debugging, but there are considerations around privacy and log size to think about.
const decodeResult = decodeCells(text);
// TODO: figure out logging.
// Data is incredibly valuable for product improvements, but privacy needs to be considered.
const decodeResult = decodeCells(result.text);

if (decodeResult.error) {
return { error: true, errors: decodeResult.errors };
Expand All @@ -167,6 +165,5 @@ export async function generateCellEdit(query: string, session: SessionType, cell
prompt: userPrompt,
});

// TODO: PARSING
return result.text;
}
12 changes: 6 additions & 6 deletions packages/api/server/ws.mts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import type {
CellRenamePayloadType,
CellErrorType,
CellCreatePayloadType,
CellAiGeneratePayloadType,
AiGenerateCellPayloadType,
} from '@srcbook/shared';
import {
CellErrorPayloadSchema,
Expand All @@ -40,8 +40,8 @@ import {
CellDeletePayloadSchema,
CellExecPayloadSchema,
CellStopPayloadSchema,
CellAiGeneratePayloadSchema,
CellAiGeneratedPayloadSchema,
AiGenerateCellPayloadSchema,
AiGeneratedCellPayloadSchema,
DepsInstallPayloadSchema,
DepsValidatePayloadSchema,
CellOutputPayloadSchema,
Expand Down Expand Up @@ -351,7 +351,7 @@ function reopenFileInTsServer(
tsserver.open({ file: openFilePath, fileContent: file.source });
}

async function cellGenerate(payload: CellAiGeneratePayloadType) {
async function cellGenerate(payload: AiGenerateCellPayloadType) {
const session = await findSession(payload.sessionId);
const cell = session.cells.find((cell) => cell.id === payload.cellId) as CodeCellType;

Expand Down Expand Up @@ -584,15 +584,15 @@ wss
.incoming('cell:update', CellUpdatePayloadSchema, cellUpdate)
.incoming('cell:rename', CellRenamePayloadSchema, cellRename)
.incoming('cell:delete', CellDeletePayloadSchema, cellDelete)
.incoming('ai:generate', CellAiGeneratePayloadSchema, cellGenerate)
.incoming('ai:generate', AiGenerateCellPayloadSchema, cellGenerate)
.incoming('deps:install', DepsInstallPayloadSchema, depsInstall)
.incoming('deps:validate', DepsValidatePayloadSchema, depsValidate)
.incoming('tsserver:start', TsServerStartPayloadSchema, tsserverStart)
.incoming('tsserver:stop', TsServerStopPayloadSchema, tsserverStop)
.outgoing('cell:updated', CellUpdatedPayloadSchema)
.outgoing('cell:error', CellErrorPayloadSchema)
.outgoing('cell:output', CellOutputPayloadSchema)
.outgoing('ai:generated', CellAiGeneratedPayloadSchema)
.outgoing('ai:generated', AiGeneratedCellPayloadSchema)
.outgoing('deps:validate:response', DepsValidateResponsePayloadSchema)
.outgoing('tsserver:cell:diagnostics', TsServerCellDiagnosticsPayloadSchema);

Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/schemas/websockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const CellUpdatePayloadSchema = z.object({
updates: CellUpdateAttrsSchema,
});

export const CellAiGeneratePayloadSchema = z.object({
export const AiGenerateCellPayloadSchema = z.object({
sessionId: z.string(),
cellId: z.string(),
prompt: z.string(),
Expand Down Expand Up @@ -56,7 +56,7 @@ export const CellUpdatedPayloadSchema = z.object({
cell: CellSchema,
});

export const CellAiGeneratedPayloadSchema = z.object({
export const AiGeneratedCellPayloadSchema = z.object({
cellId: z.string(),
output: z.string(),
});
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/src/types/websockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
CellUpdatedPayloadSchema,
CellRenamePayloadSchema,
CellDeletePayloadSchema,
CellAiGeneratePayloadSchema,
CellAiGeneratedPayloadSchema,
AiGenerateCellPayloadSchema,
AiGeneratedCellPayloadSchema,
CellOutputPayloadSchema,
DepsInstallPayloadSchema,
DepsValidateResponsePayloadSchema,
Expand All @@ -28,8 +28,8 @@ export type CellUpdatedPayloadType = z.infer<typeof CellUpdatedPayloadSchema>;
export type CellRenamePayloadType = z.infer<typeof CellRenamePayloadSchema>;
export type CellDeletePayloadType = z.infer<typeof CellDeletePayloadSchema>;
export type CellOutputPayloadType = z.infer<typeof CellOutputPayloadSchema>;
export type CellAiGeneratePayloadType = z.infer<typeof CellAiGeneratePayloadSchema>;
export type CellAiGeneratedPayloadType = z.infer<typeof CellAiGeneratedPayloadSchema>;
export type AiGenerateCellPayloadType = z.infer<typeof AiGenerateCellPayloadSchema>;
export type AiGeneratedCellPayloadType = z.infer<typeof AiGeneratedCellPayloadSchema>;

export type DepsInstallPayloadType = z.infer<typeof DepsInstallPayloadSchema>;
export type DepsValidateResponsePayloadType = z.infer<typeof DepsValidateResponsePayloadSchema>;
Expand Down
8 changes: 4 additions & 4 deletions packages/web/src/clients/websocket/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
CellOutputPayloadSchema,
CellCreatePayloadSchema,
CellAiGeneratePayloadSchema,
CellAiGeneratedPayloadSchema,
AiGenerateCellPayloadSchema,
AiGeneratedCellPayloadSchema,
CellUpdatedPayloadSchema,
DepsValidateResponsePayloadSchema,
CellExecPayloadSchema,
Expand Down Expand Up @@ -31,7 +31,7 @@ const IncomingSessionEvents = {
'cell:updated': CellUpdatedPayloadSchema,
'deps:validate:response': DepsValidateResponsePayloadSchema,
'tsserver:cell:diagnostics': TsServerCellDiagnosticsPayloadSchema,
'ai:generated': CellAiGeneratedPayloadSchema,
'ai:generated': AiGeneratedCellPayloadSchema,
};

const OutgoingSessionEvents = {
Expand All @@ -41,7 +41,7 @@ const OutgoingSessionEvents = {
'cell:update': CellUpdatePayloadSchema,
'cell:rename': CellRenamePayloadSchema,
'cell:delete': CellDeletePayloadSchema,
'ai:generate': CellAiGeneratePayloadSchema,
'ai:generate': AiGenerateCellPayloadSchema,
'deps:install': DepsInstallPayloadSchema,
'deps:validate': DepsValidatePayloadSchema,
'tsserver:start': TsServerStartPayloadSchema,
Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/components/cells/code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
CodeCellType,
CodeCellUpdateAttrsType,
CellErrorPayloadType,
CellAiGeneratedPayloadType,
AiGeneratedCellPayloadType,
} from '@srcbook/shared';
import { cn } from '@/lib/utils';
import { SessionType } from '@/types';
Expand Down Expand Up @@ -87,7 +87,7 @@ export default function CodeCell(props: {
}

useEffect(() => {
function callback(payload: CellAiGeneratedPayloadType) {
function callback(payload: AiGeneratedCellPayloadType) {
if (payload.cellId !== cell.id) return;
// We move to the "review" stage of the generation process:
setNewSource(payload.output);
Expand Down

0 comments on commit bc42118

Please sign in to comment.