pi-omlx-picker 0.2.3 → 0.2.4
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/README.md +9 -7
- package/index.ts +3 -0
- package/package.json +1 -1
- package/src/dotenv.ts +49 -0
package/README.md
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
> Seamlessly integrate your local [oMLX](https://github.com/jundot/omlx) models into Pi.
|
|
4
4
|
|
|
5
|
-
This extension discovers models from a local OMLX server and registers them as native Pi providers.
|
|
5
|
+
This extension discovers models from a local OMLX server and registers them as native Pi providers.
|
|
6
|
+
Switch between your local and remote models effortlessly using Pi's built-in `/model` command.
|
|
6
7
|
|
|
7
8
|

|
|
8
9
|
|
|
@@ -14,17 +15,17 @@ This extension discovers models from a local OMLX server and registers them as n
|
|
|
14
15
|
|
|
15
16
|
## 📦 Installation
|
|
16
17
|
|
|
17
|
-
```
|
|
18
|
+
```bash
|
|
18
19
|
pi install npm:pi-omlx-picker
|
|
19
20
|
```
|
|
20
21
|
|
|
21
22
|
## 🛠️ Development
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
* `npm install`
|
|
25
|
+
* `npm run check`
|
|
26
|
+
* `npm run format`
|
|
27
|
+
* `npm test`
|
|
28
|
+
* `npm run test:watch`
|
|
28
29
|
|
|
29
30
|
## 🚀 Quick Start
|
|
30
31
|
|
|
@@ -35,6 +36,7 @@ pi install npm:pi-omlx-picker
|
|
|
35
36
|
|
|
36
37
|
The default base URL is `http://127.0.0.1:8000/v1`. Set `OMLX_BASE_URL` before starting Pi if your OMLX server uses a different URL.
|
|
37
38
|
|
|
39
|
+
|
|
38
40
|
## ⚙️ Configuration
|
|
39
41
|
|
|
40
42
|
Env-var overrides, model metadata overlay, and stream timeout knobs are documented in [docs/CONFIGURATION.md](./docs/CONFIGURATION.md).
|
package/index.ts
CHANGED
|
@@ -6,6 +6,9 @@ import {
|
|
|
6
6
|
} from "@earendil-works/pi-ai";
|
|
7
7
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
8
8
|
import { PROVIDER_KEY } from "./src/auth-storage.ts";
|
|
9
|
+
import { loadDotenvFromExtensionDir } from "./src/dotenv.ts";
|
|
10
|
+
|
|
11
|
+
loadDotenvFromExtensionDir(import.meta.url);
|
|
9
12
|
import {
|
|
10
13
|
fetchModels,
|
|
11
14
|
type OmlxModel,
|
package/package.json
CHANGED
package/src/dotenv.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
export function parseDotenv(content: string): Record<string, string> {
|
|
6
|
+
const result: Record<string, string> = {};
|
|
7
|
+
for (const raw of content.split(/\r?\n/)) {
|
|
8
|
+
const line = raw.trim();
|
|
9
|
+
if (!line || line.startsWith("#")) continue;
|
|
10
|
+
const stripped = line.startsWith("export ") ? line.slice(7).trim() : line;
|
|
11
|
+
const eq = stripped.indexOf("=");
|
|
12
|
+
if (eq === -1) continue;
|
|
13
|
+
const key = stripped.slice(0, eq).trim();
|
|
14
|
+
if (!key) continue;
|
|
15
|
+
let val = stripped.slice(eq + 1).trim();
|
|
16
|
+
if (
|
|
17
|
+
(val.startsWith('"') && val.endsWith('"')) ||
|
|
18
|
+
(val.startsWith("'") && val.endsWith("'"))
|
|
19
|
+
) {
|
|
20
|
+
val = val.slice(1, -1);
|
|
21
|
+
}
|
|
22
|
+
result[key] = val;
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function mergeDotenv(
|
|
28
|
+
parsed: Record<string, string>,
|
|
29
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
30
|
+
): void {
|
|
31
|
+
for (const [key, val] of Object.entries(parsed)) {
|
|
32
|
+
if (env[key] === undefined || env[key] === "") env[key] = val;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function loadDotenvFromExtensionDir(
|
|
37
|
+
importMetaUrl: string,
|
|
38
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
39
|
+
): void {
|
|
40
|
+
try {
|
|
41
|
+
const dir = dirname(fileURLToPath(importMetaUrl));
|
|
42
|
+
const dotenvPath = join(dir, ".env");
|
|
43
|
+
if (!existsSync(dotenvPath)) return;
|
|
44
|
+
const content = readFileSync(dotenvPath, "utf8");
|
|
45
|
+
mergeDotenv(parseDotenv(content), env);
|
|
46
|
+
} catch {
|
|
47
|
+
// non-fatal
|
|
48
|
+
}
|
|
49
|
+
}
|