@vicoa/opencode 0.1.0 → 0.1.2

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.
@@ -1,259 +0,0 @@
1
- /**
2
- * Vicoa API client for OpenCode plugin
3
- *
4
- * This client uses Vicoa's existing REST APIs to communicate with the dashboard.
5
- * It mimics the Python VicoaClient functionality but runs in TypeScript/Node.js.
6
- */
7
- export class VicoaClient {
8
- config;
9
- lastMessageId = null;
10
- log;
11
- constructor(config) {
12
- this.config = config;
13
- this.log = config.logFunc || ((level, msg) => console.log(`[${level}] ${msg}`));
14
- }
15
- /**
16
- * Register agent instance with Vicoa backend
17
- */
18
- async registerAgentInstance(project, homeDir) {
19
- const response = await fetch(`${this.config.baseUrl}/api/v1/agent-instances`, {
20
- method: 'POST',
21
- headers: {
22
- 'Authorization': `Bearer ${this.config.apiKey}`,
23
- 'Content-Type': 'application/json',
24
- },
25
- body: JSON.stringify({
26
- agent_type: this.config.agentType,
27
- transport: 'local',
28
- agent_instance_id: this.config.agentInstanceId,
29
- name: this.config.agentType,
30
- project,
31
- home_dir: homeDir,
32
- }),
33
- });
34
- if (!response.ok) {
35
- const error = await response.text();
36
- throw new Error(`Failed to register agent instance: ${response.statusText} - ${error}`);
37
- }
38
- return (await response.json());
39
- }
40
- /**
41
- * Sync custom slash commands to Vicoa backend
42
- */
43
- async syncCommands(agentType, commands) {
44
- try {
45
- const response = await fetch(`${this.config.baseUrl}/api/v1/commands/sync`, {
46
- method: 'POST',
47
- headers: {
48
- 'Authorization': `Bearer ${this.config.apiKey}`,
49
- 'Content-Type': 'application/json',
50
- },
51
- body: JSON.stringify({
52
- agent_type: agentType,
53
- commands,
54
- }),
55
- });
56
- if (!response.ok) {
57
- const error = await response.text();
58
- this.log('warn', `Failed to sync slash commands: ${response.statusText} - ${error}`);
59
- }
60
- }
61
- catch (error) {
62
- this.log('warn', `Error syncing slash commands: ${error}`);
63
- }
64
- }
65
- /**
66
- * Send agent message to Vicoa dashboard
67
- */
68
- async sendMessage(content, requiresUserInput = false) {
69
- try {
70
- const response = await fetch(`${this.config.baseUrl}/api/v1/messages/agent`, {
71
- method: 'POST',
72
- headers: {
73
- 'Authorization': `Bearer ${this.config.apiKey}`,
74
- 'Content-Type': 'application/json',
75
- },
76
- body: JSON.stringify({
77
- content,
78
- agent_type: this.config.agentType,
79
- agent_instance_id: this.config.agentInstanceId,
80
- requires_user_input: requiresUserInput,
81
- }),
82
- });
83
- if (!response.ok) {
84
- const error = await response.text();
85
- this.log('warn', `Failed to send message: ${response.statusText} - ${error}`);
86
- return null;
87
- }
88
- const result = (await response.json());
89
- // Update last message ID for polling
90
- if (result.message_id) {
91
- this.lastMessageId = result.message_id;
92
- }
93
- return result.message_id;
94
- }
95
- catch (error) {
96
- this.log('warn', `Error sending message: ${error}`);
97
- return null;
98
- }
99
- }
100
- /**
101
- * Send user message from terminal to Vicoa dashboard
102
- * This is used when the user types a message directly in the OpenCode terminal
103
- */
104
- async sendUserMessage(content) {
105
- try {
106
- const response = await fetch(`${this.config.baseUrl}/api/v1/messages/user`, {
107
- method: 'POST',
108
- headers: {
109
- 'Authorization': `Bearer ${this.config.apiKey}`,
110
- 'Content-Type': 'application/json',
111
- },
112
- body: JSON.stringify({
113
- content,
114
- agent_instance_id: this.config.agentInstanceId,
115
- }),
116
- });
117
- if (!response.ok) {
118
- const error = await response.text();
119
- this.log('warn', `Failed to send user message: ${response.statusText} - ${error}`);
120
- return null;
121
- }
122
- const result = (await response.json());
123
- // Update last message ID
124
- if (result.message_id) {
125
- this.lastMessageId = result.message_id;
126
- }
127
- return result.message_id;
128
- }
129
- catch (error) {
130
- this.log('warn', `Error sending user message: ${error}`);
131
- return null;
132
- }
133
- }
134
- /**
135
- * Poll for pending user messages from Vicoa dashboard
136
- */
137
- async getPendingMessages() {
138
- try {
139
- const url = new URL(`${this.config.baseUrl}/api/v1/messages/pending`);
140
- url.searchParams.set('agent_instance_id', this.config.agentInstanceId);
141
- if (this.lastMessageId) {
142
- url.searchParams.set('last_read_message_id', this.lastMessageId);
143
- }
144
- const response = await fetch(url.toString(), {
145
- method: 'GET',
146
- headers: {
147
- 'Authorization': `Bearer ${this.config.apiKey}`,
148
- },
149
- });
150
- if (!response.ok) {
151
- // Polling errors are non-fatal
152
- this.log('debug', `Failed to poll messages: ${response.statusText}`);
153
- return [];
154
- }
155
- const result = (await response.json());
156
- // Check if the response is stale
157
- if (result.status === 'stale') {
158
- this.log('debug', 'Message polling returned stale status');
159
- return [];
160
- }
161
- const messages = result.messages || [];
162
- // Update last message ID
163
- if (messages.length > 0) {
164
- const lastMsg = messages[messages.length - 1];
165
- this.lastMessageId = lastMsg.id;
166
- }
167
- return messages;
168
- }
169
- catch (error) {
170
- this.log('debug', `Error polling messages: ${error}`);
171
- return [];
172
- }
173
- }
174
- /**
175
- * Request user input (equivalent to Claude wrapper's request_user_input)
176
- */
177
- async requestUserInput(messageId) {
178
- try {
179
- const response = await fetch(`${this.config.baseUrl}/api/v1/messages/${messageId}/request-input`, {
180
- method: 'PATCH',
181
- headers: {
182
- 'Authorization': `Bearer ${this.config.apiKey}`,
183
- },
184
- });
185
- if (!response.ok) {
186
- this.log('warn', `Failed to request user input: ${response.statusText}`);
187
- }
188
- }
189
- catch (error) {
190
- this.log('warn', `Error requesting user input: ${error}`);
191
- }
192
- }
193
- /**
194
- * Update agent instance status
195
- */
196
- async updateStatus(status) {
197
- try {
198
- const response = await fetch(`${this.config.baseUrl}/api/v1/agent-instances/${this.config.agentInstanceId}/status`, {
199
- method: 'PUT',
200
- headers: {
201
- 'Authorization': `Bearer ${this.config.apiKey}`,
202
- 'Content-Type': 'application/json',
203
- },
204
- body: JSON.stringify({ status }),
205
- });
206
- if (!response.ok) {
207
- this.log('warn', `Failed to update status: ${response.statusText}`);
208
- }
209
- }
210
- catch (error) {
211
- this.log('warn', `Error updating status: ${error}`);
212
- }
213
- }
214
- /**
215
- * Update agent instance title/name
216
- */
217
- async updateAgentInstanceName(name) {
218
- try {
219
- const response = await fetch(`${this.config.baseUrl}/api/v1/agent-instances/${this.config.agentInstanceId}`, {
220
- method: 'PATCH',
221
- headers: {
222
- 'Authorization': `Bearer ${this.config.apiKey}`,
223
- 'Content-Type': 'application/json',
224
- },
225
- body: JSON.stringify({ name }),
226
- });
227
- if (!response.ok) {
228
- this.log('warn', `Failed to update agent instance name: ${response.statusText}`);
229
- }
230
- }
231
- catch (error) {
232
- this.log('warn', `Error updating agent instance name: ${error}`);
233
- }
234
- }
235
- /**
236
- * End session
237
- */
238
- async endSession() {
239
- await this.updateStatus('COMPLETED');
240
- try {
241
- const response = await fetch(`${this.config.baseUrl}/api/v1/sessions/end`, {
242
- method: 'POST',
243
- headers: {
244
- 'Authorization': `Bearer ${this.config.apiKey}`,
245
- 'Content-Type': 'application/json',
246
- },
247
- body: JSON.stringify({
248
- agent_instance_id: this.config.agentInstanceId,
249
- }),
250
- });
251
- if (!response.ok) {
252
- this.log('warn', `Failed to end session: ${response.statusText}`);
253
- }
254
- }
255
- catch (error) {
256
- this.log('warn', `Error ending session: ${error}`);
257
- }
258
- }
259
- }