poke-browser 0.3.0 → 0.4.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.
@@ -34,6 +34,15 @@ let offscreenCreatingPromise = null;
34
34
  /** @type {Array<{ ts: number, direction: "in" | "out", summary: string }>} */
35
35
  let commandLog = [];
36
36
 
37
+ const POKE_TERMINAL_ONLY_INSTRUCTION =
38
+ "[BROWSER EXTENSION SESSION — MANDATORY]\n" +
39
+ "You are in a browser extension initiated terminal-style session.\n" +
40
+ "DO NOT reply via iMessage. DO NOT reply via SMS. DO NOT reply via Telegram.\n" +
41
+ "DO NOT send any normal chat reply text.\n" +
42
+ "Your only allowed behavior is to execute browser tasks and deliver output through the terminal/tool channel.\n" +
43
+ "Be strict: immediately start the browser process and proceed with the requested browser actions.\n" +
44
+ "[END BROWSER EXTENSION SESSION]\n\n";
45
+
37
46
  function logCommand(direction, summary) {
38
47
  commandLog.unshift({ ts: Date.now(), direction, summary });
39
48
  if (commandLog.length > LOG_MAX) commandLog.length = LOG_MAX;
@@ -1954,6 +1963,76 @@ const RUNTIME_HANDLERS = {
1954
1963
  })();
1955
1964
  return true;
1956
1965
  },
1966
+ POKE_GET_API_KEY_STATE: (_message, sendResponse) => {
1967
+ void chrome.storage.local.get("pokeApiKey").then((st) => {
1968
+ const apiKey = st && typeof st.pokeApiKey === "string" ? st.pokeApiKey.trim() : "";
1969
+ sendResponse({ hasApiKey: apiKey.length > 0 });
1970
+ });
1971
+ return true;
1972
+ },
1973
+ POKE_SET_API_KEY: (message, sendResponse) => {
1974
+ const m = /** @type {{ apiKey?: unknown }} */ (message);
1975
+ const apiKey = typeof m.apiKey === "string" ? m.apiKey.trim() : "";
1976
+ void chrome.storage.local.set({ pokeApiKey: apiKey }).then(() => {
1977
+ sendResponse({ ok: true });
1978
+ });
1979
+ return true;
1980
+ },
1981
+ POKE_SEND_MESSAGE: (message, sendResponse) => {
1982
+ const m = /** @type {{ message?: unknown }} */ (message);
1983
+ const userMessage = typeof m.message === "string" ? m.message.trim() : "";
1984
+ if (!userMessage) {
1985
+ sendResponse({ ok: false, error: "Message is required." });
1986
+ return false;
1987
+ }
1988
+ void (async () => {
1989
+ const st = await chrome.storage.local.get(["pokeApiKey"]);
1990
+ const apiKey = st && typeof st.pokeApiKey === "string" ? st.pokeApiKey.trim() : "";
1991
+ if (!apiKey) {
1992
+ sendResponse({ ok: false, error: "Missing API key. Save it in the popup first." });
1993
+ return;
1994
+ }
1995
+ try {
1996
+ const fullMessage = `${POKE_TERMINAL_ONLY_INSTRUCTION}${userMessage}`;
1997
+ const resp = await fetch("https://poke.com/api/v1/inbound/api-message", {
1998
+ method: "POST",
1999
+ headers: {
2000
+ Authorization: `Bearer ${apiKey}`,
2001
+ "Content-Type": "application/json",
2002
+ },
2003
+ body: JSON.stringify({ message: fullMessage }),
2004
+ });
2005
+ if (!resp.ok) {
2006
+ const bodyText = await resp.text();
2007
+ let serverMsg = "";
2008
+ try {
2009
+ const parsed = JSON.parse(bodyText);
2010
+ serverMsg =
2011
+ typeof parsed?.error === "string"
2012
+ ? parsed.error
2013
+ : typeof parsed?.message === "string"
2014
+ ? parsed.message
2015
+ : "";
2016
+ } catch {
2017
+ /* keep raw status */
2018
+ }
2019
+ sendResponse({
2020
+ ok: false,
2021
+ error: serverMsg || `Poke API error (${resp.status}).`,
2022
+ });
2023
+ return;
2024
+ }
2025
+ const data = await resp.json().catch(() => null);
2026
+ sendResponse({ ok: true, data });
2027
+ } catch (err) {
2028
+ sendResponse({
2029
+ ok: false,
2030
+ error: err instanceof Error ? err.message : String(err),
2031
+ });
2032
+ }
2033
+ })();
2034
+ return true;
2035
+ },
1957
2036
  };
1958
2037
 
1959
2038
  chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "poke-browser",
4
- "version": "0.2.9",
4
+ "version": "0.3.0",
5
5
  "description": "Browser automation bridge for MCP agents via WebSocket.",
6
6
  "permissions": [
7
7
  "tabs",
@@ -185,6 +185,81 @@
185
185
  margin-bottom: 14px;
186
186
  }
187
187
 
188
+ .form-card {
189
+ background: var(--surface);
190
+ border: 1px solid var(--border);
191
+ border-radius: 8px;
192
+ padding: 12px 14px;
193
+ margin-bottom: 12px;
194
+ }
195
+
196
+ .form-label {
197
+ display: block;
198
+ font-size: 12px;
199
+ color: var(--text-muted);
200
+ margin-bottom: 6px;
201
+ }
202
+
203
+ .form-input,
204
+ .form-textarea {
205
+ width: 100%;
206
+ padding: 8px 10px;
207
+ font-size: 12px;
208
+ font-family: inherit;
209
+ background: #1a1a1a;
210
+ border: 1px solid #333;
211
+ border-radius: 6px;
212
+ color: var(--text-primary);
213
+ outline: none;
214
+ }
215
+
216
+ .form-input:focus,
217
+ .form-textarea:focus {
218
+ border-color: var(--accent-muted);
219
+ }
220
+
221
+ .form-textarea {
222
+ resize: vertical;
223
+ min-height: 72px;
224
+ max-height: 180px;
225
+ }
226
+
227
+ .actions-row {
228
+ display: flex;
229
+ gap: 8px;
230
+ margin-top: 8px;
231
+ }
232
+
233
+ .btn {
234
+ border: 1px solid #333;
235
+ border-radius: 6px;
236
+ background: #161616;
237
+ color: var(--text-primary);
238
+ font-size: 12px;
239
+ padding: 7px 10px;
240
+ cursor: pointer;
241
+ }
242
+
243
+ .btn:hover {
244
+ background: #1e1e1e;
245
+ }
246
+
247
+ .btn.primary {
248
+ border-color: #5b21b6;
249
+ background: #4c1d95;
250
+ }
251
+
252
+ .btn.primary:hover {
253
+ background: #5b21b6;
254
+ }
255
+
256
+ .mini-status {
257
+ margin-top: 8px;
258
+ font-size: 11px;
259
+ color: var(--text-muted);
260
+ min-height: 14px;
261
+ }
262
+
188
263
  .toggle-label {
189
264
  font-size: 13px;
190
265
  color: var(--text-primary);
@@ -400,6 +475,32 @@
400
475
  </label>
401
476
  </div>
402
477
 
478
+ <section class="form-card">
479
+ <label class="form-label" for="api-key-input">Poke API key (stored locally in this extension)</label>
480
+ <input
481
+ id="api-key-input"
482
+ class="form-input"
483
+ type="password"
484
+ spellcheck="false"
485
+ autocomplete="off"
486
+ placeholder="pk_..."
487
+ />
488
+ <div class="actions-row">
489
+ <button type="button" id="save-api-key-btn" class="btn">Save key</button>
490
+ <button type="button" id="clear-api-key-btn" class="btn">Clear key</button>
491
+ </div>
492
+ <div class="mini-status" id="api-key-status"></div>
493
+ </section>
494
+
495
+ <section class="form-card">
496
+ <label class="form-label" for="poke-message-input">Send message to Poke (strict browser session mode)</label>
497
+ <textarea id="poke-message-input" class="form-textarea" placeholder="Tell Poke what to do in the browser..."></textarea>
498
+ <div class="actions-row">
499
+ <button type="button" id="send-poke-message-btn" class="btn primary">Send</button>
500
+ </div>
501
+ <div class="mini-status" id="poke-send-status"></div>
502
+ </section>
503
+
403
504
  <div class="logs-section" id="logsSection">
404
505
  <button type="button" class="logs-header" id="logsToggle" aria-expanded="false" aria-controls="logsCollapse">
405
506
  <span>Logs</span>
@@ -10,6 +10,13 @@ const versionEl = document.getElementById("version");
10
10
  const logsSection = document.getElementById("logsSection");
11
11
  const logsToggle = document.getElementById("logsToggle");
12
12
  const disconnectedHint = document.getElementById("disconnected-hint");
13
+ const apiKeyInput = document.getElementById("api-key-input");
14
+ const saveApiKeyBtn = document.getElementById("save-api-key-btn");
15
+ const clearApiKeyBtn = document.getElementById("clear-api-key-btn");
16
+ const apiKeyStatus = document.getElementById("api-key-status");
17
+ const pokeMessageInput = document.getElementById("poke-message-input");
18
+ const sendPokeMessageBtn = document.getElementById("send-poke-message-btn");
19
+ const pokeSendStatus = document.getElementById("poke-send-status");
13
20
 
14
21
  const { version } = chrome.runtime.getManifest();
15
22
 
@@ -149,6 +156,76 @@ async function load() {
149
156
  if (mcpEnabled) mcpEnabled.checked = enabled;
150
157
 
151
158
  await syncFromBackgroundStatus();
159
+
160
+ try {
161
+ const keyState = await chrome.runtime.sendMessage({ type: "POKE_GET_API_KEY_STATE" });
162
+ if (keyState?.hasApiKey) {
163
+ if (apiKeyStatus) apiKeyStatus.textContent = "API key saved.";
164
+ if (apiKeyInput) apiKeyInput.placeholder = "Saved (enter a new key to replace)";
165
+ } else if (apiKeyStatus) {
166
+ apiKeyStatus.textContent = "No API key saved.";
167
+ }
168
+ } catch {
169
+ if (apiKeyStatus) apiKeyStatus.textContent = "Could not read API key state.";
170
+ }
171
+ }
172
+
173
+ async function saveApiKey() {
174
+ const key = apiKeyInput?.value?.trim() ?? "";
175
+ if (!key) {
176
+ if (apiKeyStatus) apiKeyStatus.textContent = "Enter an API key first.";
177
+ return;
178
+ }
179
+ if (apiKeyStatus) apiKeyStatus.textContent = "Saving...";
180
+ try {
181
+ const res = await chrome.runtime.sendMessage({ type: "POKE_SET_API_KEY", apiKey: key });
182
+ if (res?.ok) {
183
+ if (apiKeyInput) apiKeyInput.value = "";
184
+ if (apiKeyStatus) apiKeyStatus.textContent = "API key saved.";
185
+ } else if (apiKeyStatus) {
186
+ apiKeyStatus.textContent = "Failed to save API key.";
187
+ }
188
+ } catch {
189
+ if (apiKeyStatus) apiKeyStatus.textContent = "Failed to save API key.";
190
+ }
191
+ }
192
+
193
+ async function clearApiKey() {
194
+ if (apiKeyStatus) apiKeyStatus.textContent = "Clearing...";
195
+ try {
196
+ const res = await chrome.runtime.sendMessage({ type: "POKE_SET_API_KEY", apiKey: "" });
197
+ if (res?.ok) {
198
+ if (apiKeyInput) apiKeyInput.value = "";
199
+ if (apiKeyStatus) apiKeyStatus.textContent = "API key cleared.";
200
+ } else if (apiKeyStatus) {
201
+ apiKeyStatus.textContent = "Failed to clear API key.";
202
+ }
203
+ } catch {
204
+ if (apiKeyStatus) apiKeyStatus.textContent = "Failed to clear API key.";
205
+ }
206
+ }
207
+
208
+ async function sendPokeMessage() {
209
+ const message = pokeMessageInput?.value?.trim() ?? "";
210
+ if (!message) {
211
+ if (pokeSendStatus) pokeSendStatus.textContent = "Enter a message first.";
212
+ return;
213
+ }
214
+ if (pokeSendStatus) pokeSendStatus.textContent = "Sending...";
215
+ if (sendPokeMessageBtn) sendPokeMessageBtn.disabled = true;
216
+ try {
217
+ const res = await chrome.runtime.sendMessage({ type: "POKE_SEND_MESSAGE", message });
218
+ if (res?.ok) {
219
+ if (pokeSendStatus) pokeSendStatus.textContent = "Message sent to Poke.";
220
+ if (pokeMessageInput) pokeMessageInput.value = "";
221
+ } else {
222
+ if (pokeSendStatus) pokeSendStatus.textContent = res?.error ? String(res.error) : "Failed to send message.";
223
+ }
224
+ } catch {
225
+ if (pokeSendStatus) pokeSendStatus.textContent = "Failed to send message.";
226
+ } finally {
227
+ if (sendPokeMessageBtn) sendPokeMessageBtn.disabled = false;
228
+ }
152
229
  }
153
230
 
154
231
  chrome.runtime.onMessage.addListener((msg) => {
@@ -201,5 +278,31 @@ mcpEnabled?.addEventListener("change", async () => {
201
278
  await syncFromBackgroundStatus();
202
279
  });
203
280
 
281
+ saveApiKeyBtn?.addEventListener("click", () => {
282
+ void saveApiKey();
283
+ });
284
+
285
+ clearApiKeyBtn?.addEventListener("click", () => {
286
+ void clearApiKey();
287
+ });
288
+
289
+ apiKeyInput?.addEventListener("keydown", (e) => {
290
+ if (e.key === "Enter") {
291
+ e.preventDefault();
292
+ void saveApiKey();
293
+ }
294
+ });
295
+
296
+ sendPokeMessageBtn?.addEventListener("click", () => {
297
+ void sendPokeMessage();
298
+ });
299
+
300
+ pokeMessageInput?.addEventListener("keydown", (e) => {
301
+ if ((e.metaKey || e.ctrlKey) && e.key === "Enter") {
302
+ e.preventDefault();
303
+ void sendPokeMessage();
304
+ }
305
+ });
306
+
204
307
  checkForUpdates();
205
308
  void load();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poke-browser",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "MCP server + WebSocket bridge for the poke-browser Chrome extension",
5
5
  "type": "module",
6
6
  "engines": {