MCPcopy
hub / github.com/anomalyco/opencode / publish

Method publish

packages/function/src/api.ts:45–66  ·  view source on GitHub ↗
(key: string, content: any)

Source from the content-addressed store, hash-verified

43 }
44
45 async publish(key: string, content: any) {
46 const sessionID = await this.getSessionID()
47 if (
48 !key.startsWith(`session/info/${sessionID}`) &&
49 !key.startsWith(`session/message/${sessionID}/`) &&
50 !key.startsWith(`session/part/${sessionID}/`)
51 )
52 return new Response("Error: Invalid key", { status: 400 })
53
54 // store message
55 await this.env.Bucket.put(`share/${key}.json`, JSON.stringify(content), {
56 httpMetadata: {
57 contentType: "application/json",
58 },
59 })
60 await this.ctx.storage.put(key, content)
61 const clients = this.ctx.getWebSockets()
62 console.log("SyncServer publish", key, "to", clients.length, "subscribers")
63 for (const client of clients) {
64 client.send(JSON.stringify({ key, content }))
65 }
66 }
67
68 public async share(sessionID: string) {
69 let secret = await this.getSecret()

Callers 1

api.tsFile · 0.45

Calls 3

getSessionIDMethod · 0.95
logMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected