Skip to content

Add support for 'appwrite' action type in Synapse and chat components #1851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: mgn-dv
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/lib/components/studio/chat/message.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

try {
const action = item.data;
console.log(item)
switch (action.type) {
case 'file':
await synapse.dispatch('fs', {
Expand All @@ -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) {
Expand Down Expand Up @@ -172,6 +185,17 @@
Finished
{/if}
</Typography.Code>
{:else if action.type === 'appwrite'}
<Typography.Code size="s">{action.type} - {action.service} - {action.operation}</Typography.Code>
<Typography.Code size="s">
{#if actionInQueue.status === 'waiting'}
Waiting
{:else if actionInQueue.status === 'processing'}
<ShimmerText>Running</ShimmerText>
{:else if actionInQueue.status === 'done'}
Finished
{/if}
</Typography.Code>
{/if}
</Layout.Stack>
{/if}
Expand Down
10 changes: 7 additions & 3 deletions src/lib/components/studio/chat/parser.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,6 +13,8 @@ interface Base {
export interface Action extends Base {
type: ActionType;
src?: string;
service?: string;
operation?: string;
}

export interface TextChunk extends Base {}
Expand All @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 14 additions & 4 deletions src/lib/components/studio/synapse.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -126,20 +136,20 @@ export class Synapse {
synapse: SynapseMessageOperations;
fs: SynapseMessageOperationFileSystem;
terminal: SynapseMessageOperationTerminal;
appwrite: SynapseMessageAppwriteOperations;
}[T],
options?: {
timeout?: number;
noReturn?: boolean;
}
): Promise<BaseMessage> {
const requestId = String(Date.now().toString() + ++this.requestCounter);

const message = {
type,
operation: payload.operation,
params: payload.params,
requestId
};
};
const response = new Promise<BaseMessage>((resolve, reject) => {
const noReturn = options?.noReturn === true;
const timeout = setTimeout(() => {
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down