Skip to content

Commit

Permalink
update files to follow lint style
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-cho committed Nov 1, 2024
1 parent 84ca500 commit 091eefa
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 49 deletions.
14 changes: 7 additions & 7 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
plugins: [
// Process Tailwind CSS classes
require('tailwindcss'),
// Add vendor prefixes to CSS rules
require('autoprefixer'),
]
};
plugins: [
// Process Tailwind CSS classes
require('tailwindcss'),
// Add vendor prefixes to CSS rules
require('autoprefixer'),
],
};
2 changes: 1 addition & 1 deletion resources/chat-view/chat.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ZenML Chat</title>
<link id="styles" rel="stylesheet" href="${stylesUri}">
<link id="styles" rel="stylesheet" href="${stylesUri}" />
<link
href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;600;700&display=swap"
rel="stylesheet"
Expand Down
15 changes: 11 additions & 4 deletions src/types/ChatTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export interface TreeItem {
}

/**
* Represents a context item in the tree structure.
*/
* Represents a context item in the tree structure.
*/
export interface ContextItem {
/** The name of the context item. */
name: string;
Expand Down Expand Up @@ -97,7 +97,14 @@ export type AIModel =
*/
export interface WebviewMessage {
/** The command to be executed in the webview. */
command: 'sendMessage' | 'clearChat' | 'showInfo' | 'updateProvider' | 'updateModel' | 'prevPage' | 'nextPage';
command:
| 'sendMessage'
| 'clearChat'
| 'showInfo'
| 'updateProvider'
| 'updateModel'
| 'prevPage'
| 'nextPage';
/** The text content of the message (if applicable). */
text?: string;
/** Additional context for the message (if applicable). */
Expand All @@ -106,4 +113,4 @@ export interface WebviewMessage {
provider?: 'openai' | 'anthropic' | 'gemini';
/** The AI model to be used (if applicable). */
model?: AIModel;
}
}
4 changes: 3 additions & 1 deletion src/views/chatView/chatMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ const commandHandlers: Record<string, CommandHandler> = {
} catch (error) {
console.error('Error adding message:', error);
if (error instanceof NetworkError) {
chatDataProvider.showInfoMessage('Network error. Please check your connection and try again.');
chatDataProvider.showInfoMessage(
'Network error. Please check your connection and try again.'
);
} else if (error instanceof ValidationError) {
chatDataProvider.showInfoMessage('Invalid message format. Please try again.');
} else {
Expand Down
49 changes: 32 additions & 17 deletions src/views/chatView/utils/ContextUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ import { getPipelineData } from './PipelineUtils';
import { ComponentDataProvider } from '../../activityBar/componentView/ComponentDataProvider';
import { EnvironmentDataProvider } from '../../activityBar/environmentView/EnvironmentDataProvider';

type ContextType = 'serverContext' | 'environmentContext' | 'pipelineContext' | 'stackContext' | 'stackComponentsContext' | 'logsContext' | 'pipelineRunContext' | string;
type ContextType =
| 'serverContext'
| 'environmentContext'
| 'pipelineContext'
| 'stackContext'
| 'stackComponentsContext'
| 'logsContext'
| 'pipelineRunContext'
| string;

export async function addContext(requestedContext: ContextType[]): Promise<string> {
let systemMessage = 'Context:\n';
Expand Down Expand Up @@ -124,9 +132,7 @@ function getStackData(): string {
let contextString = stackData
.map(item => {
if ('isActive' in item && 'id' in item) {
return `Name: ${item.label || 'N/A'}\n` +
`ID: ${item.id}\n` +
`Active: ${item.isActive}`;
return `Name: ${item.label || 'N/A'}\n` + `ID: ${item.id}\n` + `Active: ${item.isActive}`;
}
return `Name: ${item.label || 'N/A'}`;
})
Expand All @@ -141,7 +147,8 @@ function getStackData(): string {
async function getLogData(): Promise<any[]> {
try {
const lsClient = LSClient.getInstance();
const globalConfig = await lsClient.sendLsClientRequest<ZenmlGlobalConfigResp>('getGlobalConfig');
const globalConfig =
await lsClient.sendLsClientRequest<ZenmlGlobalConfigResp>('getGlobalConfig');
const apiToken = globalConfig.store.api_token;
const dashboardUrl = globalConfig.store.url;

Expand Down Expand Up @@ -208,16 +215,19 @@ async function getPipelineRunLogs(id: string): Promise<any[]> {
const lsClient = LSClient.getInstance();
const dagData = await lsClient.sendLsClientRequest<PipelineRunDag>('getPipelineRunDag', [id]);

const stepData = (await Promise.all(
dagData.nodes.map(async (node: DagArtifact | DagStep) => {
if (node.type === 'step') {
return await lsClient.sendLsClientRequest<Step>('getPipelineRunStep', [node.id]);
}
return null;
})
)).filter((step): step is Step => step !== null);
const stepData = (
await Promise.all(
dagData.nodes.map(async (node: DagArtifact | DagStep) => {
if (node.type === 'step') {
return await lsClient.sendLsClientRequest<Step>('getPipelineRunStep', [node.id]);
}
return null;
})
)
).filter((step): step is Step => step !== null);

const globalConfig = await lsClient.sendLsClientRequest<ZenmlGlobalConfigResp>('getGlobalConfig');
const globalConfig =
await lsClient.sendLsClientRequest<ZenmlGlobalConfigResp>('getGlobalConfig');
const apiToken = globalConfig.store.api_token;
const dashboardUrl = globalConfig.store.url;

Expand All @@ -238,7 +248,10 @@ async function getPipelineRunLogs(id: string): Promise<any[]> {

type NodeType = 'all' | 'step' | 'artifact';

async function getPipelineRunNodes(nodeType: NodeType, pipelineRunId?: string): Promise<JsonObject[][]> {
async function getPipelineRunNodes(
nodeType: NodeType,
pipelineRunId?: string
): Promise<JsonObject[][]> {
try {
const pipelineDataProvider = PipelineDataProvider.getInstance();
const allPipelineRuns = pipelineDataProvider.getPipelineData();
Expand All @@ -249,8 +262,10 @@ async function getPipelineRunNodes(nodeType: NodeType, pipelineRunId?: string):
const lsClient = LSClient.getInstance();

const fetchAndFilterNodes = async (pipelineRun: { id: string }): Promise<JsonObject[]> => {
const dag = await lsClient.sendLsClientRequest<PipelineRunDag>('getPipelineRunDag', [pipelineRun.id]);

const dag = await lsClient.sendLsClientRequest<PipelineRunDag>('getPipelineRunDag', [
pipelineRun.id,
]);

const filteredNodes = await Promise.all(
dag.nodes.map(async (node: DagArtifact | DagStep) => {
if (nodeType === 'all' || node.type === nodeType) {
Expand Down
30 changes: 15 additions & 15 deletions src/views/chatView/utils/CustomErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
// permissions and limitations under the License.

export class NetworkError extends Error {
constructor(message: string) {
super(message);
this.name = 'NetworkError';
}
constructor(message: string) {
super(message);
this.name = 'NetworkError';
}
}

export class ValidationError extends Error {
constructor(message: string) {
super(message);
this.name = 'ValidationError';
}
export class ValidationError extends Error {
constructor(message: string) {
super(message);
this.name = 'ValidationError';
}
}

export class StorageError extends Error {
constructor(message: string) {
super(message);
this.name = 'StorageError';
}
}
export class StorageError extends Error {
constructor(message: string) {
super(message);
this.name = 'StorageError';
}
}
14 changes: 11 additions & 3 deletions src/views/chatView/utils/PipelineUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ import { TreeItem, ContextItem } from '../../../types/ChatTypes';

const CONTEXT_ITEMS: readonly ContextItem[] = [
{ name: 'Server', value: 'serverContext', title: 'Includes all server metadata with message' },
{ name: 'Environment', value: 'environmentContext', title: 'Includes all server metadata with message' },
{
name: 'Environment',
value: 'environmentContext',
title: 'Includes all server metadata with message',
},
{ name: 'Stack', value: 'stackContext', title: 'Includes all stack metadata with message' },
{ name: 'Stack Components', value: 'stackComponentsContext', title: 'Includes all stack component metadata with message' },
{
name: 'Stack Components',
value: 'stackComponentsContext',
title: 'Includes all stack component metadata with message',
},
] as const;

export function getPipelineData(): { contextString: string; treeItems: TreeItem[] } {
Expand Down Expand Up @@ -89,7 +97,7 @@ export function getPaginatedTreeData(): TreeItem[] {

export function getTreeData(): TreeItem[] {
const paginatedItems = getPaginatedTreeData();

return [
...CONTEXT_ITEMS,
{
Expand Down
2 changes: 1 addition & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./resources/chat-view/**/*.{html,js}"],
content: ['./resources/chat-view/**/*.{html,js}'],
theme: {
extend: {},
},
Expand Down

0 comments on commit 091eefa

Please sign in to comment.