From a007f35c0bddb61e15ce8843f59706aae9b00cd1 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 18 May 2025 20:17:26 +0400 Subject: [PATCH] Add support for 'appwrite' action type in Synapse and chat components - Extended SynapseMessageType to include 'appwrite'. - Introduced SynapseMessageAppwriteOperations for handling appwrite operations. - Updated chat message handling to process 'appwrite' actions. - Modified StreamParser to include service and operation attributes for appwrite actions. - Changed preview URL to localhost for development purposes. --- src/lib/components/studio/chat/message.svelte | 24 +++++++++++++++++++ src/lib/components/studio/chat/parser.ts | 10 +++++--- src/lib/components/studio/synapse.svelte.ts | 18 ++++++++++---- .../studio/artifact-[artifact]/+page.svelte | 2 +- 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/lib/components/studio/chat/message.svelte b/src/lib/components/studio/chat/message.svelte index dc6297c29f..86cbdd9b29 100644 --- a/src/lib/components/studio/chat/message.svelte +++ b/src/lib/components/studio/chat/message.svelte @@ -42,6 +42,7 @@ try { const action = item.data; + console.log(item) switch (action.type) { case 'file': await synapse.dispatch('fs', { @@ -68,6 +69,18 @@ } ); break; + case 'appwrite': + await synapse.dispatch( + 'appwrite', + { + operation: action.operation, + params: { + service: action.service, + payload: JSON.parse(action.content) ?? {} + } + } + ); + break; } if (message.group) { @@ -172,6 +185,17 @@ Finished {/if} + {:else if action.type === 'appwrite'} + {action.type} - {action.service} - {action.operation} + + {#if actionInQueue.status === 'waiting'} + Waiting + {:else if actionInQueue.status === 'processing'} + Running + {:else if actionInQueue.status === 'done'} + Finished + {/if} + {/if} {/if} diff --git a/src/lib/components/studio/chat/parser.ts b/src/lib/components/studio/chat/parser.ts index ef84aebdfd..c8cbf07472 100644 --- a/src/lib/components/studio/chat/parser.ts +++ b/src/lib/components/studio/chat/parser.ts @@ -1,6 +1,6 @@ import { writable, type Readable } from 'svelte/store'; -export type ActionType = 'file' | 'shell'; +export type ActionType = 'file' | 'shell' | 'appwrite'; interface Base { id: symbol; @@ -13,6 +13,8 @@ interface Base { export interface Action extends Base { type: ActionType; src?: string; + service?: string; + operation?: string; } export interface TextChunk extends Base {} @@ -23,7 +25,7 @@ export interface ActionsContainer extends Base { } export function isActionType(type: string): type is ActionType { - return ['file', 'shell'].includes(type); + return ['file', 'shell', 'appwrite'].includes(type); } type ParserEvents = 'complete' | 'chunk'; @@ -242,7 +244,9 @@ export class StreamParser { type, src: attributes.src, content: '', - complete: false + complete: false, + service: attributes.service, + operation: attributes.method }; this.isFirstActionContent = true; diff --git a/src/lib/components/studio/synapse.svelte.ts b/src/lib/components/studio/synapse.svelte.ts index 50d180bfcc..bca4e4fa02 100644 --- a/src/lib/components/studio/synapse.svelte.ts +++ b/src/lib/components/studio/synapse.svelte.ts @@ -2,7 +2,7 @@ import { page } from '$app/state'; import { SvelteURL } from 'svelte/reactivity'; type WebSocketEvent = 'connect' | 'disconnect' | 'reconnect'; -type SynapseMessageType = 'terminal' | 'fs' | 'synapse'; +type SynapseMessageType = 'terminal' | 'fs' | 'synapse' | 'appwrite'; type SynapseMessageOperations = { operation: 'updateWorkDir'; params: { workDir: string }; @@ -32,6 +32,16 @@ type SynapseMessageOperationTerminal = | { operation: 'updateSize'; params: { cols: number; rows: number } } | { operation: 'createCommand'; params: { command: string } }; +type SynapseMessageAppwriteOperations = { + operation: string; + params: { + service: string; + payload: { + [key: string]: string; + }; + }; +}; + type Events = WebSocketEvent | SynapseMessageType; type BaseMessage = { success: boolean; @@ -126,6 +136,7 @@ export class Synapse { synapse: SynapseMessageOperations; fs: SynapseMessageOperationFileSystem; terminal: SynapseMessageOperationTerminal; + appwrite: SynapseMessageAppwriteOperations; }[T], options?: { timeout?: number; @@ -133,13 +144,12 @@ export class Synapse { } ): Promise { const requestId = String(Date.now().toString() + ++this.requestCounter); - const message = { type, operation: payload.operation, params: payload.params, requestId - }; + }; const response = new Promise((resolve, reject) => { const noReturn = options?.noReturn === true; const timeout = setTimeout(() => { @@ -192,7 +202,7 @@ export class Synapse { } } -export const endpoint = 'wss://terminal.appwrite.torsten.work'; +export const endpoint = 'ws://localhost:3000'; export function createSynapse(endpoint: string, artifact?: string) { const url = new SvelteURL(endpoint); diff --git a/src/routes/(console)/project-[project]/studio/artifact-[artifact]/+page.svelte b/src/routes/(console)/project-[project]/studio/artifact-[artifact]/+page.svelte index 0f76a707b1..cc69d7bf2e 100644 --- a/src/routes/(console)/project-[project]/studio/artifact-[artifact]/+page.svelte +++ b/src/routes/(console)/project-[project]/studio/artifact-[artifact]/+page.svelte @@ -10,7 +10,7 @@ import { SvelteURL } from 'svelte/reactivity'; import type { EventHandler } from 'svelte/elements'; - let previewUrl = new SvelteURL('https://preview.torsten.work'); + let previewUrl = new SvelteURL('http://localhost:1234'); let iframeRef: HTMLIFrameElement | null = $state(null); $effect(() => {