Skip to content

implement websocket in TS#3040

Merged
afsalthaj merged 7 commits intoweb_socketfrom
web_socket_ts
Mar 23, 2026
Merged

implement websocket in TS#3040
afsalthaj merged 7 commits intoweb_socketfrom
web_socket_ts

Conversation

@afsalthaj
Copy link
Copy Markdown
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 

Comment thread Cargo.toml
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
Copy Markdown
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!

@afsalthaj afsalthaj marked this pull request as ready for review March 23, 2026 03:15
@afsalthaj afsalthaj merged commit fec8547 into web_socket Mar 23, 2026
26 of 28 checks passed
@afsalthaj afsalthaj deleted the web_socket_ts branch March 23, 2026 03:35
@github-actions github-actions bot locked and limited conversation to collaborators Mar 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant