ha-opencode 0.1.1 → 0.2.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.
package/dist/state.js CHANGED
@@ -1,12 +1,15 @@
1
1
  import { hostname } from "os";
2
2
  export class StateTracker {
3
- discovery;
3
+ wsClient;
4
+ instanceToken;
4
5
  state;
5
6
  pendingPermission = null;
6
7
  currentSessionId = null;
7
- deviceNameUpdated = false;
8
- constructor(discovery) {
9
- this.discovery = discovery;
8
+ projectName;
9
+ constructor(wsClient, instanceToken, projectName) {
10
+ this.wsClient = wsClient;
11
+ this.instanceToken = instanceToken;
12
+ this.projectName = projectName;
10
13
  this.state = {
11
14
  state: "idle",
12
15
  previousState: null,
@@ -25,30 +28,64 @@ export class StateTracker {
25
28
  getCurrentSessionId() {
26
29
  return this.currentSessionId;
27
30
  }
31
+ getPendingPermission() {
32
+ return this.pendingPermission;
33
+ }
28
34
  /**
29
- * Check if we have a valid session title for updating the device friendly name.
35
+ * Set the current session ID and optionally publish an update.
36
+ * Used when initializing with an existing session.
30
37
  */
31
- hasValidTitle() {
32
- const title = this.state.sessionTitle;
33
- return !!(title &&
34
- title !== "No active session" &&
35
- title !== "Untitled" &&
36
- title.toLowerCase() !== "unknown");
38
+ async setSessionId(sessionId, publishUpdate = false) {
39
+ this.currentSessionId = sessionId;
40
+ if (publishUpdate) {
41
+ await this.publishUpdate();
42
+ }
37
43
  }
38
44
  /**
39
- * Initialize the state tracker.
40
- * Registers the device with Home Assistant immediately since we have the session ID.
45
+ * Build a session update object for sending to HA.
41
46
  */
42
- async initialize() {
43
- await this.discovery.registerDevice();
44
- await this.discovery.publishDeviceInfo();
45
- await this.discovery.publishAvailable();
46
- await this.publishAll();
47
- await this.publishStateAttributes();
48
- await this.discovery.publishPermission(null);
47
+ buildSessionUpdate() {
48
+ return {
49
+ session_id: this.currentSessionId || "",
50
+ title: this.state.sessionTitle,
51
+ state: this.state.state,
52
+ previous_state: this.state.previousState,
53
+ model: this.state.model,
54
+ current_tool: this.state.currentTool,
55
+ tokens_input: this.state.tokensInput,
56
+ tokens_output: this.state.tokensOutput,
57
+ cost: this.state.cost,
58
+ last_activity: this.state.lastActivity,
59
+ agent: this.state.agent,
60
+ current_agent: this.state.currentAgent,
61
+ hostname: hostname(),
62
+ error_message: this.state.errorMessage,
63
+ permission: this.pendingPermission,
64
+ };
49
65
  }
50
- getPendingPermission() {
51
- return this.pendingPermission;
66
+ /**
67
+ * Send the current session state to Home Assistant.
68
+ */
69
+ async publishUpdate() {
70
+ if (!this.currentSessionId) {
71
+ return;
72
+ }
73
+ try {
74
+ await this.wsClient.sendSessionUpdate(this.instanceToken, this.buildSessionUpdate());
75
+ }
76
+ catch {
77
+ // Silent failure
78
+ }
79
+ }
80
+ /**
81
+ * Get all current sessions for state response.
82
+ * Currently we only track one session at a time.
83
+ */
84
+ getAllSessions() {
85
+ if (!this.currentSessionId) {
86
+ return [];
87
+ }
88
+ return [this.buildSessionUpdate()];
52
89
  }
53
90
  async handleEvent(event) {
54
91
  try {
@@ -80,59 +117,42 @@ export class StateTracker {
80
117
  }
81
118
  }
82
119
  catch (err) {
83
- console.error(`[ha-opencode] Error in handleEvent for '${event.type}':`, err);
84
- console.error(`[ha-opencode] Event properties:`, JSON.stringify(event.properties, null, 2));
85
120
  throw err;
86
121
  }
87
122
  }
88
123
  async onSessionCreated(event) {
89
- this.currentSessionId = event.properties.info.id;
124
+ const newSessionId = event.properties.info.id;
125
+ // If switching sessions, notify HA to remove the old one
126
+ if (this.currentSessionId && this.currentSessionId !== newSessionId) {
127
+ try {
128
+ await this.wsClient.sendSessionRemoved(this.instanceToken, this.currentSessionId);
129
+ }
130
+ catch {
131
+ // Silent failure
132
+ }
133
+ }
134
+ this.currentSessionId = newSessionId;
90
135
  this.state.sessionTitle = event.properties.info.title || "Untitled";
91
136
  this.state.tokensInput = 0;
92
137
  this.state.tokensOutput = 0;
93
138
  this.state.cost = 0;
139
+ this.state.state = "idle";
140
+ this.state.previousState = null;
94
141
  this.updateActivity();
95
- // Check if we got a valid title on creation
96
- await this.maybeUpdateDeviceName();
97
- await this.publish("session_title", this.state.sessionTitle);
98
- await this.updateState("idle");
99
- await this.publish("tokens_input", this.state.tokensInput);
100
- await this.publish("tokens_output", this.state.tokensOutput);
101
- await this.publish("cost", this.state.cost);
102
- await this.publish("last_activity", this.state.lastActivity);
142
+ await this.publishUpdate();
103
143
  }
104
144
  async onSessionUpdated(event) {
105
145
  const title = event.properties.info.title;
106
- const titleChanged = title && title !== this.state.sessionTitle;
107
- if (titleChanged) {
146
+ if (title && title !== this.state.sessionTitle) {
108
147
  this.state.sessionTitle = title;
109
148
  }
110
149
  this.updateActivity();
111
- // Update device friendly name when we get a valid title
112
- await this.maybeUpdateDeviceName();
113
- if (titleChanged) {
114
- await this.publish("session_title", this.state.sessionTitle);
115
- }
116
- await this.publish("last_activity", this.state.lastActivity);
117
- }
118
- /**
119
- * Update the device friendly name in Home Assistant if we have a valid title
120
- * and haven't done so yet.
121
- */
122
- async maybeUpdateDeviceName() {
123
- if (!this.deviceNameUpdated && this.hasValidTitle()) {
124
- await this.discovery.updateDeviceName(this.state.sessionTitle);
125
- // Also update device_id attributes with new device name
126
- await this.discovery.publishDeviceInfo();
127
- this.deviceNameUpdated = true;
128
- }
150
+ await this.publishUpdate();
129
151
  }
130
152
  async onSessionIdle(_event) {
131
153
  this.state.currentTool = "none";
132
154
  this.updateActivity();
133
155
  await this.updateState("idle");
134
- await this.publish("current_tool", this.state.currentTool);
135
- await this.publish("last_activity", this.state.lastActivity);
136
156
  }
137
157
  async onSessionError(event) {
138
158
  this.updateActivity();
@@ -148,7 +168,6 @@ export class StateTracker {
148
168
  this.state.errorMessage = "Unknown error";
149
169
  }
150
170
  await this.updateState("error");
151
- await this.publish("last_activity", this.state.lastActivity);
152
171
  }
153
172
  async onMessageUpdated(event) {
154
173
  const message = event.properties.info;
@@ -158,36 +177,34 @@ export class StateTracker {
158
177
  this.state.agent = message.agent;
159
178
  // Reset current agent when new user message arrives
160
179
  this.state.currentAgent = null;
161
- await this.publishStateAttributes();
162
180
  }
163
181
  }
164
182
  else if (message.role === "assistant") {
165
183
  // Update model info
166
184
  this.state.model = `${message.providerID}/${message.modelID}`;
167
- await this.publish("model", this.state.model);
168
185
  // Update token counts and cost
169
186
  // Note: SDK may return Decimal objects, so convert to primitives
170
187
  this.state.tokensInput = Number(message.tokens.input);
171
188
  this.state.tokensOutput = Number(message.tokens.output);
172
189
  this.state.cost = Number(message.cost);
173
- await this.publish("tokens_input", this.state.tokensInput);
174
- await this.publish("tokens_output", this.state.tokensOutput);
175
- await this.publish("cost", this.state.cost);
176
190
  }
177
191
  this.updateActivity();
178
- await this.publish("last_activity", this.state.lastActivity);
192
+ await this.publishUpdate();
179
193
  }
180
194
  async onMessagePartUpdated(event) {
181
195
  const part = event.properties.part;
196
+ let stateChanged = false;
182
197
  // When receiving text parts with deltas, the model is actively working
183
198
  if (part.type === "text" && event.properties.delta) {
184
- await this.updateState("working");
199
+ if (this.state.state !== "working") {
200
+ await this.updateState("working");
201
+ stateChanged = true;
202
+ }
185
203
  }
186
204
  // Track agent/sub-agent switching
187
205
  if (part.type === "agent") {
188
206
  if (part.name !== this.state.currentAgent) {
189
207
  this.state.currentAgent = part.name;
190
- await this.publishStateAttributes();
191
208
  }
192
209
  }
193
210
  // Track tool execution
@@ -195,44 +212,48 @@ export class StateTracker {
195
212
  const toolState = part.state;
196
213
  if (toolState.status === "running") {
197
214
  this.state.currentTool = part.tool;
198
- await this.updateState("working");
199
- await this.publish("current_tool", this.state.currentTool);
215
+ if (this.state.state !== "working") {
216
+ await this.updateState("working");
217
+ stateChanged = true;
218
+ }
200
219
  }
201
220
  else if (toolState.status === "completed" || toolState.status === "error") {
202
221
  this.state.currentTool = "none";
203
- await this.publish("current_tool", this.state.currentTool);
204
222
  }
205
223
  }
206
224
  this.updateActivity();
207
- await this.publish("last_activity", this.state.lastActivity);
225
+ // Only publish if state didn't change (updateState already publishes)
226
+ if (!stateChanged) {
227
+ await this.publishUpdate();
228
+ }
208
229
  }
209
230
  async onPermissionUpdated(event) {
210
231
  const permission = event.properties;
232
+ // Pattern might be string | string[] from SDK, convert to string
233
+ const pattern = Array.isArray(permission.pattern)
234
+ ? permission.pattern.join(", ")
235
+ : permission.pattern;
211
236
  this.pendingPermission = {
212
237
  id: permission.id,
213
238
  type: permission.type,
214
239
  title: permission.title,
215
- sessionID: permission.sessionID,
216
- messageID: permission.messageID,
217
- callID: permission.callID,
218
- pattern: permission.pattern,
240
+ session_id: permission.sessionID,
241
+ message_id: permission.messageID,
242
+ call_id: permission.callID,
243
+ pattern,
219
244
  metadata: permission.metadata,
220
245
  };
221
246
  this.updateActivity();
222
247
  await this.updateState("waiting_permission");
223
- await this.publish("last_activity", this.state.lastActivity);
224
- await this.discovery.publishPermission(this.pendingPermission);
225
248
  }
226
249
  async onPermissionReplied(_event) {
227
250
  this.pendingPermission = null;
228
251
  this.updateActivity();
229
252
  await this.updateState("working");
230
- await this.publish("last_activity", this.state.lastActivity);
231
- await this.discovery.publishPermission(null);
232
253
  }
233
254
  async clearPermission() {
234
255
  this.pendingPermission = null;
235
- await this.discovery.publishPermission(null);
256
+ await this.publishUpdate();
236
257
  }
237
258
  updateActivity() {
238
259
  this.state.lastActivity = new Date().toISOString();
@@ -245,38 +266,8 @@ export class StateTracker {
245
266
  if (newState !== "error") {
246
267
  this.state.errorMessage = null;
247
268
  }
248
- // IMPORTANT: Publish attributes BEFORE state so that when HA automation
249
- // triggers on state topic, the previous_state attribute is already available
250
- await this.publishStateAttributes();
251
- await this.publish("state", this.state.state);
269
+ await this.publishUpdate();
252
270
  }
253
271
  }
254
- async publishStateAttributes() {
255
- await this.discovery.publishAttributes("state", {
256
- previous_state: this.state.previousState,
257
- agent: this.state.agent,
258
- current_agent: this.state.currentAgent,
259
- hostname: hostname(),
260
- error_message: this.state.errorMessage,
261
- });
262
- }
263
- async publish(key, value) {
264
- try {
265
- await this.discovery.publishState(key, value);
266
- }
267
- catch (err) {
268
- console.error(`[ha-opencode] Failed to publish ${key}:`, err);
269
- }
270
- }
271
- async publishAll() {
272
- await this.publish("state", this.state.state);
273
- await this.publish("session_title", this.state.sessionTitle);
274
- await this.publish("model", this.state.model);
275
- await this.publish("current_tool", this.state.currentTool);
276
- await this.publish("tokens_input", this.state.tokensInput);
277
- await this.publish("tokens_output", this.state.tokensOutput);
278
- await this.publish("cost", this.state.cost);
279
- await this.publish("last_activity", this.state.lastActivity);
280
- }
281
272
  }
282
273
  //# sourceMappingURL=state.js.map
package/dist/state.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAqB9B,MAAM,OAAO,YAAY;IACN,SAAS,CAAY;IAC9B,KAAK,CAAe;IACpB,iBAAiB,GAA0B,IAAI,CAAC;IAChD,gBAAgB,GAAkB,IAAI,CAAC;IACvC,iBAAiB,GAAG,KAAK,CAAC;IAElC,YAAY,SAAoB;QAC9B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG;YACX,KAAK,EAAE,MAAM;YACb,aAAa,EAAE,IAAI;YACnB,YAAY,EAAE,UAAU;YACxB,KAAK,EAAE,SAAS;YAChB,WAAW,EAAE,MAAM;YACnB,WAAW,EAAE,CAAC;YACd,YAAY,EAAE,CAAC;YACf,IAAI,EAAE,CAAC;YACP,YAAY,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACtC,KAAK,EAAE,IAAI;YACX,YAAY,EAAE,IAAI;YAClB,YAAY,EAAE,IAAI;SACnB,CAAC;IACJ,CAAC;IAED,mBAAmB;QACjB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;IAED;;OAEG;IACK,aAAa;QACnB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC;QACtC,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;IAED,KAAK,CAAC,eAAe;QACnB,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAC9B,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;IAC7B,CAAC;IAEO,cAAc;QACpB,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACrD,CAAC;IAEO,KAAK,CAAC,WAAW,CAAC,QAAsB;QAC9C,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YAClC,IAAI,CAAC,KAAK,CAAC,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;YAC5C,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,QAAQ,CAAC;YAE5B,+DAA+D;YAC/D,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;gBACzB,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC;YACjC,CAAC;YAED,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QAC7B,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,113 @@
1
+ export interface HAWebSocketConfig {
2
+ url: string;
3
+ accessToken?: string;
4
+ }
5
+ export type MessageHandler = (message: HAMessage) => void;
6
+ export type CommandHandler = (command: string, sessionId: string, data: Record<string, unknown>) => void;
7
+ export interface HAMessage {
8
+ id?: number;
9
+ type: string;
10
+ [key: string]: unknown;
11
+ }
12
+ export interface HistoryResponseData {
13
+ session_id: string;
14
+ session_title: string;
15
+ messages: HistoryMessageData[];
16
+ fetched_at: string;
17
+ since?: string;
18
+ request_id?: string;
19
+ }
20
+ export interface HistoryMessageData {
21
+ id: string;
22
+ role: "user" | "assistant";
23
+ timestamp: string;
24
+ model?: string;
25
+ provider?: string;
26
+ tokens_input?: number;
27
+ tokens_output?: number;
28
+ cost?: number;
29
+ parts: HistoryPartData[];
30
+ }
31
+ export interface HistoryPartData {
32
+ type: "text" | "tool_call" | "tool_result" | "image" | "other";
33
+ content?: string;
34
+ tool_name?: string;
35
+ tool_id?: string;
36
+ tool_args?: Record<string, unknown>;
37
+ tool_output?: string;
38
+ tool_error?: string;
39
+ }
40
+ export interface AgentData {
41
+ name: string;
42
+ description?: string;
43
+ mode: "subagent" | "primary" | "all";
44
+ }
45
+ export interface AgentsResponseData {
46
+ session_id: string;
47
+ agents: AgentData[];
48
+ request_id?: string;
49
+ }
50
+ export interface HAWebSocketClient {
51
+ connect(): Promise<void>;
52
+ disconnect(): Promise<void>;
53
+ isConnected(): boolean;
54
+ pair(code: string, hostname: string): Promise<PairResult>;
55
+ reconnect(instanceToken: string, hostname: string): Promise<ReconnectResult>;
56
+ sendSessionUpdate(instanceToken: string, session: SessionUpdate): Promise<void>;
57
+ sendSessionRemoved(instanceToken: string, sessionId: string): Promise<void>;
58
+ sendStateResponse(instanceToken: string, sessions: SessionUpdate[]): Promise<void>;
59
+ sendHistoryResponse(instanceToken: string, data: HistoryResponseData): Promise<void>;
60
+ sendAgentsResponse(instanceToken: string, data: AgentsResponseData): Promise<void>;
61
+ onCommand(handler: CommandHandler): void;
62
+ onStateRequest(handler: () => void): void;
63
+ onDisconnect(handler: () => void): void;
64
+ }
65
+ export interface PairResult {
66
+ success: boolean;
67
+ instanceId?: string;
68
+ instanceToken?: string;
69
+ error?: string;
70
+ }
71
+ export interface ReconnectResult {
72
+ success: boolean;
73
+ instanceId?: string;
74
+ error?: string;
75
+ }
76
+ export interface SessionUpdate {
77
+ session_id: string;
78
+ title: string;
79
+ state: string;
80
+ previous_state: string | null;
81
+ model: string;
82
+ current_tool: string;
83
+ tokens_input: number;
84
+ tokens_output: number;
85
+ cost: number;
86
+ last_activity: string;
87
+ agent: string | null;
88
+ current_agent: string | null;
89
+ hostname: string;
90
+ error_message: string | null;
91
+ permission: PermissionInfo | null;
92
+ }
93
+ export interface PermissionInfo {
94
+ id: string;
95
+ type: string;
96
+ title: string;
97
+ session_id: string;
98
+ message_id: string;
99
+ call_id?: string;
100
+ pattern?: string;
101
+ metadata?: Record<string, unknown>;
102
+ }
103
+ export declare function createHAWebSocketClient(config: HAWebSocketConfig): HAWebSocketClient;
104
+ export interface ReconnectingClientCallbacks {
105
+ onReconnected: () => void;
106
+ onDisconnected?: () => void;
107
+ onReconnecting?: () => void;
108
+ }
109
+ /**
110
+ * Create a WebSocket client with automatic reconnection.
111
+ */
112
+ export declare function createReconnectingClient(config: HAWebSocketConfig, instanceToken: string, hostname: string, callbacks: ReconnectingClientCallbacks | (() => void)): HAWebSocketClient;
113
+ //# sourceMappingURL=websocket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../src/websocket.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,SAAS,KAAK,IAAI,CAAC;AAC1D,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;AAEzG,MAAM,WAAW,SAAS;IACxB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,kBAAkB,EAAE,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,GAAG,WAAW,CA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