Skip to content

implement websocket in TS#3040

Draft
afsalthaj wants to merge 5 commits intoweb_socketfrom
web_socket_ts
Draft

implement websocket in TS#3040
afsalthaj wants to merge 5 commits intoweb_socketfrom
web_socket_ts

Conversation

@afsalthaj
Copy link
Contributor

@afsalthaj afsalthaj commented Mar 20, 2026

This PR raised against: #3039 , which has WIT changes and host implementation

Also this PR requires: golemcloud/wasm-rquickjs#83

TS agent

import { agent, BaseAgent } from "@golemcloud/golem-ts-sdk"; @agent() class WebSocketTest extends BaseAgent { constructor(name: string) { super(); } async echo(url: string, msg: string): Promise<string> { return new Promise((resolve, reject) => { const ws = new WebSocket(url); ws.onopen = () => ws.send(msg); ws.onmessage = (event) => { ws.close(); resolve(event.data); }; ws.onerror = (event) => reject(new Error(event.message)); }); } }

Server

npx wscat --listen 9090 Listening on port 9090 (press CTRL+C to quit) Client connected < hello websocket > hi Disconnected (code: 1000, reason: "")

Test

~/my-ts  ~/my-ts  golem agent invoke 'WebSocketTest("t1")' 'echo' '"ws://localhost:9090"' '"hello websocket"' Using generated idempotency key: dfbf4f8a-84a3-4d48-b4c5-cb52653fa406 Selected app: my-ts, env: local, server: local - builtin (http://localhost:9881) Fuzzy matched pattern echo as echo Invoking agent my:ts/WebSocketTest("t1")/echo [2026-03-20T05:36:25.874Z] [INVOKE ] STARTED golem:agent/guest@1.5.0.{invoke} (dfbf4f8a-84a3-4d48-b4c5-cb52653fa406) [2026-03-20T05:36:38.116Z] [INVOKE ] FINISHED echo (dfbf4f8a-84a3-4d48-b4c5-cb52653fa406) [2026-03-20T05:36:38.118Z] [STREAM ] Stream closed Invocation results in TypeScript syntax: - "hi" ~/my-ts 
wasm-encoder = "0.244.0"
wasm-metadata = { version = "0.244.0", features = ["oci"] }
wasm-rquickjs = "0.0.24"
wasm-rquickjs = { git = "https://github.com/golemcloud/wasm-rquickjs", branch = "web_socket" }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this before merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant