@neuralnomads/codenomad 0.10.1 → 0.10.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.
@@ -22,6 +22,11 @@ const PreferencesSchema = z.object({
22
22
  showUsageMetrics: z.boolean().default(true),
23
23
  autoCleanupBlankSessions: z.boolean().default(true),
24
24
  listeningMode: z.enum(["local", "all"]).default("local"),
25
+ // OS notifications
26
+ osNotificationsEnabled: z.boolean().default(false),
27
+ osNotificationsAllowWhenVisible: z.boolean().default(false),
28
+ notifyOnNeedsInput: z.boolean().default(true),
29
+ notifyOnIdle: z.boolean().default(true),
25
30
  });
26
31
  const RecentFolderSchema = z.object({
27
32
  path: z.string(),
package/dist/index.js CHANGED
@@ -304,7 +304,11 @@ async function main() {
304
304
  const remoteStart = httpsStart ?? httpStart;
305
305
  const localProtocol = httpStart ? "http" : "https";
306
306
  const remoteProtocol = httpsStart ? "https" : "http";
307
- const localUrl = `${localProtocol}://localhost:${localStart.port}`;
307
+ // Use an explicit IPv4 loopback address for the "local" URL.
308
+ // On macOS, `localhost` often resolves to ::1 first, and it is possible to have
309
+ // another instance bound on IPv6 while this instance binds IPv4 (or vice versa),
310
+ // which can lead clients to talk to the wrong process.
311
+ const localUrl = `${localProtocol}://127.0.0.1:${localStart.port}`;
308
312
  let remoteUrl;
309
313
  if (remoteStart) {
310
314
  const wantsAll = options.host === "0.0.0.0" || !isLoopbackHost(options.host);
@@ -1,3 +1,7 @@
1
+ import http from "http"
2
+ import https from "https"
3
+ import { Readable } from "stream"
4
+
1
5
  export type PluginEvent = {
2
6
  type: string
3
7
  properties?: Record<string, unknown>
@@ -16,7 +20,8 @@ export function getCodeNomadConfig(): CodeNomadConfig {
16
20
  }
17
21
 
18
22
  export function createCodeNomadRequester(config: CodeNomadConfig) {
19
- const baseUrl = config.baseUrl.replace(/\/+$/, "")
23
+ const rawBaseUrl = (config.baseUrl ?? "").trim()
24
+ const baseUrl = rawBaseUrl.replace(/\/+$/, "")
20
25
  const pluginBase = `${baseUrl}/workspaces/${encodeURIComponent(config.instanceId)}/plugin`
21
26
  const authorization = buildInstanceAuthorizationHeader()
22
27
 
@@ -42,10 +47,10 @@ export function createCodeNomadRequester(config: CodeNomadConfig) {
42
47
  const hasBody = init?.body !== undefined
43
48
  const headers = buildHeaders(init?.headers, hasBody)
44
49
 
45
- return fetch(url, {
46
- ...init,
47
- headers,
48
- })
50
+ // The CodeNomad plugin only talks to the local CodeNomad server.
51
+ // Use a single request implementation that tolerates custom/self-signed certs
52
+ // without disabling TLS verification for the whole Node process.
53
+ return nodeFetch(url, { ...init, headers }, { rejectUnauthorized: false })
49
54
  }
50
55
 
51
56
  const requestJson = async <T>(path: string, init?: RequestInit): Promise<T> => {
@@ -87,6 +92,91 @@ export function createCodeNomadRequester(config: CodeNomadConfig) {
87
92
  }
88
93
  }
89
94
 
95
+ async function nodeFetch(
96
+ url: string,
97
+ init: RequestInit & { headers?: Record<string, string> },
98
+ tls: { rejectUnauthorized: boolean },
99
+ ): Promise<Response> {
100
+ const parsed = new URL(url)
101
+ const isHttps = parsed.protocol === "https:"
102
+ const requestFn = isHttps ? https.request : http.request
103
+
104
+ const method = (init.method ?? "GET").toUpperCase()
105
+ const headers = init.headers ?? {}
106
+ const body = init.body
107
+
108
+ return await new Promise<Response>((resolve, reject) => {
109
+ const req = requestFn(
110
+ {
111
+ protocol: parsed.protocol,
112
+ hostname: parsed.hostname,
113
+ port: parsed.port ? Number(parsed.port) : undefined,
114
+ path: `${parsed.pathname}${parsed.search}`,
115
+ method,
116
+ headers,
117
+ ...(isHttps ? { rejectUnauthorized: tls.rejectUnauthorized } : {}),
118
+ },
119
+ (res) => {
120
+ const responseHeaders = new Headers()
121
+ for (const [key, value] of Object.entries(res.headers)) {
122
+ if (value === undefined) continue
123
+ if (Array.isArray(value)) {
124
+ responseHeaders.set(key, value.join(", "))
125
+ } else {
126
+ responseHeaders.set(key, String(value))
127
+ }
128
+ }
129
+
130
+ // Convert Node stream -> Web ReadableStream for Response.
131
+ const webBody = Readable.toWeb(res) as unknown as ReadableStream<Uint8Array>
132
+ resolve(new Response(webBody, { status: res.statusCode ?? 0, headers: responseHeaders }))
133
+ },
134
+ )
135
+
136
+ const signal = init.signal
137
+ const abort = () => {
138
+ const err = new Error("Request aborted")
139
+ ;(err as any).name = "AbortError"
140
+ req.destroy(err)
141
+ reject(err)
142
+ }
143
+
144
+ if (signal) {
145
+ if (signal.aborted) {
146
+ abort()
147
+ return
148
+ }
149
+ signal.addEventListener("abort", abort, { once: true })
150
+ req.once("close", () => signal.removeEventListener("abort", abort))
151
+ }
152
+
153
+ req.once("error", reject)
154
+
155
+ if (body === undefined || body === null) {
156
+ req.end()
157
+ return
158
+ }
159
+
160
+ if (typeof body === "string") {
161
+ req.end(body)
162
+ return
163
+ }
164
+
165
+ if (body instanceof Uint8Array) {
166
+ req.end(Buffer.from(body))
167
+ return
168
+ }
169
+
170
+ if (body instanceof ArrayBuffer) {
171
+ req.end(Buffer.from(new Uint8Array(body)))
172
+ return
173
+ }
174
+
175
+ // Fallback for less common BodyInit types.
176
+ req.end(String(body))
177
+ })
178
+ }
179
+
90
180
  function requireEnv(key: string): string {
91
181
  const value = process.env[key]
92
182
  if (!value || !value.trim()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neuralnomads/codenomad",
3
- "version": "0.10.1",
3
+ "version": "0.10.2",
4
4
  "description": "CodeNomad Server",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -0,0 +1 @@
1
+ function s(n,e,i,t){if(typeof e=="function"?n!==e||!t:!e.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return i==="m"?t:i==="a"?t.call(n):t?t.value:e.get(n)}function o(n,e,i,t,c){if(typeof e=="function"?n!==e||!0:!e.has(n))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(n,i),i}var a,r,h,l;const d="__TAURI_TO_IPC_KEY__";function p(n,e=!1){return window.__TAURI_INTERNALS__.transformCallback(n,e)}class w{constructor(e){a.set(this,void 0),r.set(this,0),h.set(this,[]),l.set(this,void 0),o(this,a,e||(()=>{})),this.id=p(i=>{const t=i.index;if("end"in i){t==s(this,r,"f")?this.cleanupCallback():o(this,l,t);return}const c=i.message;if(t==s(this,r,"f")){for(s(this,a,"f").call(this,c),o(this,r,s(this,r,"f")+1);s(this,r,"f")in s(this,h,"f");){const f=s(this,h,"f")[s(this,r,"f")];s(this,a,"f").call(this,f),delete s(this,h,"f")[s(this,r,"f")],o(this,r,s(this,r,"f")+1)}s(this,r,"f")===s(this,l,"f")&&this.cleanupCallback()}else s(this,h,"f")[t]=c})}cleanupCallback(){window.__TAURI_INTERNALS__.unregisterCallback(this.id)}set onmessage(e){o(this,a,e)}get onmessage(){return s(this,a,"f")}[(a=new WeakMap,r=new WeakMap,h=new WeakMap,l=new WeakMap,d)](){return`__CHANNEL__:${this.id}`}toJSON(){return this[d]()}}class u{constructor(e,i,t){this.plugin=e,this.event=i,this.channelId=t}async unregister(){return _(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}}async function g(n,e,i){const t=new w(i);try{return await _(`plugin:${n}|register_listener`,{event:e,handler:t}),new u(n,e,t.id)}catch{return await _(`plugin:${n}|registerListener`,{event:e,handler:t}),new u(n,e,t.id)}}async function _(n,e={},i){return window.__TAURI_INTERNALS__.invoke(n,e,i)}export{g as a,_ as i};