poke-gate 0.0.6 → 0.0.8
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/LICENSE +21 -0
- package/bin/poke-gate.js +22 -7
- package/clients/Poke macOS Gate/Poke macOS Gate/GateService.swift +78 -3
- package/clients/Poke macOS Gate/Poke macOS Gate/SettingsView.swift +67 -13
- package/clients/Poke macOS Gate/Poke macOS Gate.xcodeproj/project.pbxproj +2 -2
- package/clients/Poke macOS Gate/Poke macOS Gate.xcodeproj/project.xcworkspace/xcuserdata/fka.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/package.json +1 -1
- package/src/app.js +5 -0
- package/src/tunnel.js +41 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fatih Kadir Akın
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/bin/poke-gate.js
CHANGED
|
@@ -21,10 +21,20 @@ function saveConfig(config) {
|
|
|
21
21
|
writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
function loadPokeCredentials() {
|
|
25
|
+
try {
|
|
26
|
+
const creds = JSON.parse(readFileSync(join(CONFIG_DIR, "poke", "credentials.json"), "utf-8"));
|
|
27
|
+
if (creds.token) return creds.token;
|
|
28
|
+
} catch {}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
24
32
|
function resolveToken() {
|
|
25
33
|
if (process.env.POKE_API_KEY) return process.env.POKE_API_KEY;
|
|
26
34
|
const config = loadConfig();
|
|
27
35
|
if (config.apiKey) return config.apiKey;
|
|
36
|
+
const pokeCreds = loadPokeCredentials();
|
|
37
|
+
if (pokeCreds) return pokeCreds;
|
|
28
38
|
return null;
|
|
29
39
|
}
|
|
30
40
|
|
|
@@ -47,19 +57,24 @@ async function onboarding() {
|
|
|
47
57
|
console.log();
|
|
48
58
|
console.log(" ⚠ This grants full shell access. Only run on trusted networks.");
|
|
49
59
|
console.log();
|
|
50
|
-
console.log(" To get started,
|
|
60
|
+
console.log(" To get started, either:");
|
|
51
61
|
console.log();
|
|
52
|
-
console.log(" 1
|
|
53
|
-
console.log(" 2
|
|
54
|
-
console.log(" 3. Paste it below");
|
|
62
|
+
console.log(" Option 1: Run 'npx poke login' (recommended)");
|
|
63
|
+
console.log(" Option 2: Paste an API key from https://poke.com/kitchen/api-keys");
|
|
55
64
|
console.log();
|
|
56
65
|
|
|
57
|
-
const key = await ask(" API key: ");
|
|
66
|
+
const key = await ask(" API key (or press Enter if you ran poke login): ");
|
|
58
67
|
|
|
59
68
|
if (!key) {
|
|
69
|
+
const pokeCreds = loadPokeCredentials();
|
|
70
|
+
if (pokeCreds) {
|
|
71
|
+
console.log();
|
|
72
|
+
console.log(" Found poke login credentials! Starting...");
|
|
73
|
+
console.log();
|
|
74
|
+
return pokeCreds;
|
|
75
|
+
}
|
|
60
76
|
console.log();
|
|
61
|
-
console.log(" No
|
|
62
|
-
console.log(" export POKE_API_KEY=your_key_here");
|
|
77
|
+
console.log(" No credentials found. Run: npx poke login");
|
|
63
78
|
console.log();
|
|
64
79
|
process.exit(1);
|
|
65
80
|
}
|
|
@@ -27,8 +27,7 @@ class GateService: ObservableObject {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
var hasAPIKey: Bool {
|
|
30
|
-
|
|
31
|
-
return key != nil && !key!.isEmpty
|
|
30
|
+
resolveToken() != nil
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
func autoStartIfNeeded() {
|
|
@@ -111,7 +110,7 @@ class GateService: ObservableObject {
|
|
|
111
110
|
proc.arguments = ["-c", "npx -y poke-gate --verbose"]
|
|
112
111
|
proc.environment = ProcessInfo.processInfo.environment.merging(
|
|
113
112
|
[
|
|
114
|
-
"POKE_API_KEY":
|
|
113
|
+
"POKE_API_KEY": resolveToken() ?? "",
|
|
115
114
|
"PATH": fullPath,
|
|
116
115
|
],
|
|
117
116
|
uniquingKeysWith: { _, new in new }
|
|
@@ -226,4 +225,80 @@ class GateService: ObservableObject {
|
|
|
226
225
|
}
|
|
227
226
|
objectWillChange.send()
|
|
228
227
|
}
|
|
228
|
+
|
|
229
|
+
// MARK: - Poke Login Credentials
|
|
230
|
+
|
|
231
|
+
private var pokeCredentialsURL: URL {
|
|
232
|
+
let configDir: URL
|
|
233
|
+
if let xdg = ProcessInfo.processInfo.environment["XDG_CONFIG_HOME"] {
|
|
234
|
+
configDir = URL(fileURLWithPath: xdg)
|
|
235
|
+
} else {
|
|
236
|
+
configDir = FileManager.default.homeDirectoryForCurrentUser
|
|
237
|
+
.appendingPathComponent(".config")
|
|
238
|
+
}
|
|
239
|
+
return configDir
|
|
240
|
+
.appendingPathComponent("poke")
|
|
241
|
+
.appendingPathComponent("credentials.json")
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
var hasPokeLoginCredentials: Bool {
|
|
245
|
+
loadPokeLoginToken() != nil
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
func loadPokeLoginToken() -> String? {
|
|
249
|
+
guard let data = try? Data(contentsOf: pokeCredentialsURL),
|
|
250
|
+
let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
|
|
251
|
+
let token = json["token"] as? String else {
|
|
252
|
+
return nil
|
|
253
|
+
}
|
|
254
|
+
return token
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
var authSource: AuthSource {
|
|
258
|
+
get {
|
|
259
|
+
let config = (try? Data(contentsOf: configURL))
|
|
260
|
+
.flatMap { try? JSONSerialization.jsonObject(with: $0) as? [String: Any] }
|
|
261
|
+
if let source = config?["authSource"] as? String, source == "pokeLogin" {
|
|
262
|
+
return .pokeLogin
|
|
263
|
+
}
|
|
264
|
+
if loadAPIKey() != nil {
|
|
265
|
+
return .apiKey
|
|
266
|
+
}
|
|
267
|
+
if hasPokeLoginCredentials {
|
|
268
|
+
return .pokeLogin
|
|
269
|
+
}
|
|
270
|
+
return .none
|
|
271
|
+
}
|
|
272
|
+
set {
|
|
273
|
+
let dir = configURL.deletingLastPathComponent()
|
|
274
|
+
try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
|
|
275
|
+
var json: [String: Any] = [:]
|
|
276
|
+
if let data = try? Data(contentsOf: configURL),
|
|
277
|
+
let existing = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
|
|
278
|
+
json = existing
|
|
279
|
+
}
|
|
280
|
+
json["authSource"] = newValue == .pokeLogin ? "pokeLogin" : "apiKey"
|
|
281
|
+
if let data = try? JSONSerialization.data(withJSONObject: json, options: [.prettyPrinted]) {
|
|
282
|
+
try? data.write(to: configURL)
|
|
283
|
+
}
|
|
284
|
+
objectWillChange.send()
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
func resolveToken() -> String? {
|
|
289
|
+
switch authSource {
|
|
290
|
+
case .pokeLogin:
|
|
291
|
+
return loadPokeLoginToken()
|
|
292
|
+
case .apiKey:
|
|
293
|
+
return loadAPIKey()
|
|
294
|
+
case .none:
|
|
295
|
+
return loadAPIKey() ?? loadPokeLoginToken()
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
enum AuthSource {
|
|
300
|
+
case pokeLogin
|
|
301
|
+
case apiKey
|
|
302
|
+
case none
|
|
303
|
+
}
|
|
229
304
|
}
|
|
@@ -3,6 +3,7 @@ import SwiftUI
|
|
|
3
3
|
struct SettingsView: View {
|
|
4
4
|
@ObservedObject var service: GateService
|
|
5
5
|
@State private var apiKeyInput: String = ""
|
|
6
|
+
@State private var usePokeLogin: Bool = true
|
|
6
7
|
@Environment(\.dismiss) private var dismiss
|
|
7
8
|
|
|
8
9
|
var body: some View {
|
|
@@ -10,18 +11,64 @@ struct SettingsView: View {
|
|
|
10
11
|
Text("Poke Gate Settings")
|
|
11
12
|
.font(.headline)
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
Text("
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
Picker("Authentication", selection: $usePokeLogin) {
|
|
15
|
+
Text("Use poke login").tag(true)
|
|
16
|
+
Text("Use API key").tag(false)
|
|
17
|
+
}
|
|
18
|
+
.pickerStyle(.segmented)
|
|
19
|
+
|
|
20
|
+
if usePokeLogin {
|
|
21
|
+
VStack(alignment: .leading, spacing: 8) {
|
|
22
|
+
if service.hasPokeLoginCredentials {
|
|
23
|
+
Label("poke login credentials found", systemImage: "checkmark.circle.fill")
|
|
24
|
+
.foregroundStyle(.green)
|
|
25
|
+
.font(.subheadline)
|
|
26
|
+
} else {
|
|
27
|
+
Label("No credentials found", systemImage: "xmark.circle")
|
|
28
|
+
.foregroundStyle(.red)
|
|
29
|
+
.font(.subheadline)
|
|
30
|
+
|
|
31
|
+
Text("Run this in your terminal:")
|
|
32
|
+
.font(.caption)
|
|
33
|
+
.foregroundStyle(.secondary)
|
|
34
|
+
|
|
35
|
+
HStack {
|
|
36
|
+
Text("npx poke login")
|
|
37
|
+
.font(.system(.caption, design: .monospaced))
|
|
38
|
+
.padding(.horizontal, 8)
|
|
39
|
+
.padding(.vertical, 4)
|
|
40
|
+
.background(.quaternary)
|
|
41
|
+
.cornerRadius(4)
|
|
17
42
|
|
|
18
|
-
|
|
19
|
-
|
|
43
|
+
Button {
|
|
44
|
+
NSPasteboard.general.clearContents()
|
|
45
|
+
NSPasteboard.general.setString("npx poke login", forType: .string)
|
|
46
|
+
} label: {
|
|
47
|
+
Image(systemName: "doc.on.doc")
|
|
48
|
+
}
|
|
49
|
+
.buttonStyle(.plain)
|
|
50
|
+
}
|
|
20
51
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
52
|
+
Text("Then come back here and click Save.")
|
|
53
|
+
.font(.caption)
|
|
54
|
+
.foregroundStyle(.secondary)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
.frame(maxWidth: .infinity, alignment: .leading)
|
|
58
|
+
} else {
|
|
59
|
+
VStack(alignment: .leading, spacing: 8) {
|
|
60
|
+
Text("API Key")
|
|
61
|
+
.font(.subheadline)
|
|
62
|
+
.foregroundStyle(.secondary)
|
|
63
|
+
|
|
64
|
+
SecureField("Paste your API key", text: $apiKeyInput)
|
|
65
|
+
.textFieldStyle(.roundedBorder)
|
|
66
|
+
|
|
67
|
+
Link("Get your key at poke.com/kitchen/api-keys",
|
|
68
|
+
destination: URL(string: "https://poke.com/kitchen/api-keys")!)
|
|
69
|
+
.font(.caption)
|
|
70
|
+
.foregroundStyle(.blue)
|
|
71
|
+
}
|
|
25
72
|
}
|
|
26
73
|
|
|
27
74
|
HStack {
|
|
@@ -33,17 +80,24 @@ struct SettingsView: View {
|
|
|
33
80
|
Spacer()
|
|
34
81
|
|
|
35
82
|
Button("Save") {
|
|
36
|
-
|
|
83
|
+
if usePokeLogin {
|
|
84
|
+
service.authSource = .pokeLogin
|
|
85
|
+
} else {
|
|
86
|
+
service.apiKey = apiKeyInput
|
|
87
|
+
service.authSource = .apiKey
|
|
88
|
+
}
|
|
37
89
|
dismiss()
|
|
38
90
|
service.restart()
|
|
39
91
|
}
|
|
40
92
|
.keyboardShortcut(.defaultAction)
|
|
41
|
-
.disabled(apiKeyInput.isEmpty)
|
|
93
|
+
.disabled(!usePokeLogin && apiKeyInput.isEmpty)
|
|
94
|
+
.disabled(usePokeLogin && !service.hasPokeLoginCredentials)
|
|
42
95
|
}
|
|
43
96
|
}
|
|
44
97
|
.padding(20)
|
|
45
|
-
.frame(width:
|
|
98
|
+
.frame(width: 380)
|
|
46
99
|
.onAppear {
|
|
100
|
+
usePokeLogin = service.authSource != .apiKey
|
|
47
101
|
apiKeyInput = service.apiKey
|
|
48
102
|
}
|
|
49
103
|
}
|
|
@@ -264,7 +264,7 @@
|
|
|
264
264
|
"$(inherited)",
|
|
265
265
|
"@executable_path/../Frameworks",
|
|
266
266
|
);
|
|
267
|
-
MARKETING_VERSION = 0.0.
|
|
267
|
+
MARKETING_VERSION = 0.0.7;
|
|
268
268
|
PRODUCT_BUNDLE_IDENTIFIER = "dev.fka.Poke-macOS-Gate";
|
|
269
269
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
|
270
270
|
REGISTER_APP_GROUPS = YES;
|
|
@@ -296,7 +296,7 @@
|
|
|
296
296
|
"$(inherited)",
|
|
297
297
|
"@executable_path/../Frameworks",
|
|
298
298
|
);
|
|
299
|
-
MARKETING_VERSION = 0.0.
|
|
299
|
+
MARKETING_VERSION = 0.0.7;
|
|
300
300
|
PRODUCT_BUNDLE_IDENTIFIER = "dev.fka.Poke-macOS-Gate";
|
|
301
301
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
|
302
302
|
REGISTER_APP_GROUPS = YES;
|
|
Binary file
|
package/package.json
CHANGED
package/src/app.js
CHANGED
|
@@ -18,6 +18,11 @@ function resolveToken() {
|
|
|
18
18
|
if (cfg.apiKey) return cfg.apiKey;
|
|
19
19
|
} catch {}
|
|
20
20
|
|
|
21
|
+
try {
|
|
22
|
+
const creds = JSON.parse(readFileSync(join(configDir, "poke", "credentials.json"), "utf-8"));
|
|
23
|
+
if (creds.token) return creds.token;
|
|
24
|
+
} catch {}
|
|
25
|
+
|
|
21
26
|
return null;
|
|
22
27
|
}
|
|
23
28
|
|
package/src/tunnel.js
CHANGED
|
@@ -1,15 +1,55 @@
|
|
|
1
1
|
import { PokeTunnel, getToken } from "poke";
|
|
2
|
+
import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
|
|
6
|
+
const CONFIG_DIR = process.env.XDG_CONFIG_HOME || join(homedir(), ".config");
|
|
7
|
+
const STATE_PATH = join(CONFIG_DIR, "poke-gate", "state.json");
|
|
8
|
+
|
|
9
|
+
function loadState() {
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(readFileSync(STATE_PATH, "utf-8"));
|
|
12
|
+
} catch {
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function saveState(state) {
|
|
18
|
+
mkdirSync(join(CONFIG_DIR, "poke-gate"), { recursive: true });
|
|
19
|
+
writeFileSync(STATE_PATH, JSON.stringify(state, null, 2));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function cleanupOldConnection(apiKey) {
|
|
23
|
+
const state = loadState();
|
|
24
|
+
if (!state.connectionId) return;
|
|
25
|
+
|
|
26
|
+
const token = getToken() || apiKey;
|
|
27
|
+
const base = process.env.POKE_API ?? "https://poke.com/api/v1";
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
await fetch(`${base}/mcp/connections/${state.connectionId}`, {
|
|
31
|
+
method: "DELETE",
|
|
32
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
33
|
+
});
|
|
34
|
+
} catch {}
|
|
35
|
+
}
|
|
2
36
|
|
|
3
37
|
export async function startTunnel({ apiKey, mcpUrl, onEvent }) {
|
|
38
|
+
await cleanupOldConnection(apiKey);
|
|
39
|
+
|
|
4
40
|
const token = getToken();
|
|
5
41
|
|
|
6
42
|
const tunnel = new PokeTunnel({
|
|
7
43
|
url: mcpUrl,
|
|
8
44
|
name: "poke-gate",
|
|
9
45
|
token: token || apiKey,
|
|
46
|
+
cleanupOnStop: false,
|
|
10
47
|
});
|
|
11
48
|
|
|
12
|
-
tunnel.on("connected", (info) =>
|
|
49
|
+
tunnel.on("connected", (info) => {
|
|
50
|
+
saveState({ connectionId: info.connectionId });
|
|
51
|
+
onEvent("connected", info);
|
|
52
|
+
});
|
|
13
53
|
tunnel.on("disconnected", () => onEvent("disconnected"));
|
|
14
54
|
tunnel.on("error", (err) => onEvent("error", err.message));
|
|
15
55
|
tunnel.on("toolsSynced", ({ toolCount }) => onEvent("tools-synced", toolCount));
|