@alexsun-top/opencode-chat-room 0.3.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +44 -11
  3. package/README.zh-CN.md +40 -10
  4. package/package.json +4 -1
  5. package/plugin.ts +26 -10
  6. package/server/announcement-routes.ts +34 -0
  7. package/server/assets/MERMAID-LICENSE +21 -0
  8. package/server/assets/NOTICE.txt +2 -1
  9. package/server/assets/base.css +43 -27
  10. package/server/assets/chat/announcements.js +119 -0
  11. package/server/assets/chat/events.js +180 -6
  12. package/server/assets/chat/index.js +6 -0
  13. package/server/assets/chat/markdown.js +214 -11
  14. package/server/assets/chat/members.js +4 -1
  15. package/server/assets/chat/messages.js +57 -77
  16. package/server/assets/chat/questions.js +204 -0
  17. package/server/assets/chat/receipts.js +117 -0
  18. package/server/assets/chat/rooms.js +11 -6
  19. package/server/assets/chat/state.js +64 -18
  20. package/server/assets/conversation.css +58 -17
  21. package/server/assets/mermaid-11.12.2.min.js +2811 -0
  22. package/server/assets/responsive.css +47 -23
  23. package/server/chat-server.ts +41 -12
  24. package/server/chat.html +51 -10
  25. package/server/member-routes.ts +3 -0
  26. package/server/newrooms.ts +2 -0
  27. package/server/resource-routes.ts +65 -0
  28. package/server/wake.ts +2 -2
  29. package/skills/chatroom/SKILL.md +92 -0
  30. package/src/agent-receipts.ts +4 -4
  31. package/src/announcement-tool.ts +25 -0
  32. package/src/announcements.ts +16 -0
  33. package/src/center-client.ts +32 -2
  34. package/src/center-inbox.ts +9 -9
  35. package/src/chatroom-skill.ts +15 -0
  36. package/src/plugin-notifications.ts +7 -9
  37. package/src/resource-upload.ts +50 -0
  38. package/src/resources.ts +104 -0
  39. package/src/room-service.ts +5 -0
  40. package/src/sqlite-state.ts +83 -13
  41. package/src/store.ts +4 -11
  42. package/src/v1-plugin.ts +6 -1
  43. package/src/v2-plugin.ts +39 -8
package/src/v1-plugin.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import type { Config, Plugin, PluginInput, ToolDefinition } from "@opencode-ai/plugin";
2
2
  import type { V2Runtime } from "./v2-plugin";
3
3
  import type { QueueTransport } from "./queue-transport";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ const bundledSkillsPath = fileURLToPath(new URL("../skills", import.meta.url));
4
7
 
5
8
  export function createV1Server(deps: {
6
9
  runtime(input: PluginInput, transport: QueueTransport): V2Runtime;
@@ -35,7 +38,9 @@ export function createV1Server(deps: {
35
38
  };
36
39
  return {
37
40
  tool: { room },
38
- config: async (cfg: Config) => {
41
+ config: async (cfg: Config & { skills?: { paths?: string[]; urls?: string[] } }) => {
42
+ cfg.skills ??= {};
43
+ cfg.skills.paths = [...new Set([...(cfg.skills.paths ?? []), bundledSkillsPath])];
39
44
  cfg.command = cfg.command ?? {};
40
45
  cfg.command.room = {
41
46
  description: "Chat room: create/join/leave/list rooms, send and poll messages",
package/src/v2-plugin.ts CHANGED
@@ -1,10 +1,11 @@
1
- import type { Plugin } from "@opencode/plugin";
1
+ import type { Skill, Plugin } from "@opencode/plugin";
2
2
  import { z } from "zod";
3
3
  import type { QueueTransport } from "./center-client";
4
4
  import { backgroundOwnSession, discoverVerifiedHost, verifyHostSession } from "./background";
5
5
  import { receiverOwnerID } from "./receiver-owner";
6
6
  import { attachV2Receiver } from "./v2-receiver";
7
7
  import { observeReceiptContext, receiptDestination } from "./agent-receipts";
8
+ import { chatroomSkill } from "./chatroom-skill";
8
9
 
9
10
  type CenterOptions = { center: string; token: string; directory?: string };
10
11
  export type V2Runtime = {
@@ -18,7 +19,7 @@ export type V2Runtime = {
18
19
  export function createV2Setup(deps: {
19
20
  runtime(directory: string, transport: QueueTransport): V2Runtime;
20
21
  run<T>(runtime: V2Runtime, callback: () => T): T;
21
- execute(args: z.infer<ReturnType<typeof roomSchema>>, sessionID: string): Promise<string>;
22
+ execute(args: z.infer<ReturnType<typeof roomSchema>>, sessionID: string, permissionContext: { directory: string; worktree?: string; ask(input: { permission: string; patterns: string[]; always: string[]; metadata: Record<string, unknown> }): Promise<void> }): Promise<string>;
22
23
  observe(runtime: V2Runtime, sessionID: string): Promise<void>;
23
24
  poll(sessions: ReadonlySet<string>, transport: QueueTransport, center: CenterOptions): Promise<void>;
24
25
  resolveOwner?: () => Promise<string | undefined>;
@@ -45,9 +46,18 @@ export function createV2Setup(deps: {
45
46
  let commandRegistration: { dispose(): Promise<void> } | undefined;
46
47
  let promptRegistration: { dispose(): Promise<void> } | undefined;
47
48
  let contextRegistration: { dispose(): Promise<void> } | undefined;
49
+ let skillRegistration: { dispose(): Promise<void> } | undefined;
48
50
  let releaseReceiver: (() => void) | undefined;
49
51
 
50
52
  try {
53
+ skillRegistration = await context.skill.transform((editor) => {
54
+ if (!editor.get(chatroomSkill.id)) editor.add({
55
+ ...chatroomSkill,
56
+ id: chatroomSkill.id as Skill.ID,
57
+ name: chatroomSkill.name as Skill.Name,
58
+ path: chatroomSkill.path as Skill.Info["path"],
59
+ });
60
+ });
51
61
  promptRegistration = await context.session.hook("prompt", async (input) => {
52
62
  sessions.add(input.sessionID);
53
63
  await deps.run(runtime, () => deps.observe(runtime, input.sessionID));
@@ -67,14 +77,27 @@ export function createV2Setup(deps: {
67
77
  });
68
78
  toolRegistration = await context.tool.transform((editor) => editor.add({
69
79
  name: "room",
70
- description: "Chat room operations: create, join, leave and list rooms; send and poll messages; list members",
80
+ description: "Chat room operations: create, join, leave and list rooms; send and poll messages; list members and announcements; upload files and media",
71
81
  options: { codemode: false },
72
82
  input: roomSchema(),
73
83
  execute: async (args, toolContext) => {
74
84
  sessions.add(toolContext.sessionID);
75
85
  return deps.run(runtime, async () => {
76
86
  await deps.observe(runtime, toolContext.sessionID);
77
- return { content: [{ type: "text", text: await deps.execute(args, toolContext.sessionID) }] };
87
+ const permissionContext = {
88
+ directory: context.location.directory,
89
+ worktree: context.location.directory,
90
+ ask: (input: { permission: string; patterns: string[]; always: string[]; metadata: Record<string, unknown> }) => context.permission.assert({
91
+ sessionID: toolContext.sessionID,
92
+ agent: toolContext.agent,
93
+ action: input.permission,
94
+ resources: input.patterns,
95
+ save: input.always,
96
+ metadata: input.metadata,
97
+ source: { type: "tool", messageID: toolContext.messageID, id: toolContext.id },
98
+ }),
99
+ };
100
+ return { content: [{ type: "text", text: await deps.execute(args, toolContext.sessionID, permissionContext) }] };
78
101
  });
79
102
  },
80
103
  }));
@@ -104,22 +127,30 @@ export function createV2Setup(deps: {
104
127
  });
105
128
  } catch (error) {
106
129
  releaseReceiver?.();
107
- await dispose(toolRegistration, commandRegistration, promptRegistration, contextRegistration);
130
+ await dispose(toolRegistration, commandRegistration, promptRegistration, contextRegistration, skillRegistration);
108
131
  throw error;
109
132
  }
110
133
  return async () => {
111
134
  releaseReceiver?.();
112
- await dispose(toolRegistration, commandRegistration, promptRegistration, contextRegistration);
135
+ await dispose(toolRegistration, commandRegistration, promptRegistration, contextRegistration, skillRegistration);
113
136
  };
114
137
  };
115
138
  }
116
139
 
117
140
  function roomSchema() {
118
141
  return z.object({
119
- action: z.enum(["create", "join", "leave", "list", "send", "poll", "members"]),
120
- name: z.string().max(64).optional(),
142
+ action: z.enum(["create", "join", "leave", "list", "send", "poll", "members", "upload_resource", "announcement_list", "announcement_read", "announcement_write", "announcement_delete"]),
143
+ name: z.string().max(64).optional().describe("For join: your own participant display name, NOT the room name (required). For create: the new room name."),
121
144
  roomId: z.string().optional(),
145
+ filePath: z.string().optional().describe("Local regular file to upload; central mode only; requires host read permission."),
122
146
  text: z.string().max(2000).optional(),
147
+ isQuestion: z.boolean().optional(),
148
+ announcementName: z.string().optional().describe("Name of a room announcement; distinct from participant or room name."),
149
+ content: z.string().optional().describe("Announcement content, at most 5000 Unicode characters."),
150
+ }).superRefine((args, ctx) => {
151
+ if (args.action === "join" && !args.name?.trim()) {
152
+ ctx.addIssue({ code: "custom", path: ["name"], message: "name is required to join a room" });
153
+ }
123
154
  });
124
155
  }
125
156