@deathbeam/pi-mistral 0.0.0-stage → 0.0.1
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/README.md +21 -2
- package/index.ts +96 -0
- package/package.json +26 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tomas Slusny
|
|
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/README.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
#
|
|
1
|
+
# [@deathbeam/pi-mistral](https://www.npmjs.com/package/@deathbeam/pi-mistral)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Mistral models through the built-in `mistral` provider.
|
|
4
|
+
Set `MISTRAL_API_KEY`.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
# Choose one:
|
|
10
|
+
pi install npm:@deathbeam/pi-mistral # this package
|
|
11
|
+
pi install git:github.com/deathbeam/pi-packages # all my packages
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Development
|
|
15
|
+
|
|
16
|
+
From the repo root:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install
|
|
20
|
+
npm test -- packages/pi-mistral
|
|
21
|
+
pi install ./packages/pi-mistral
|
|
22
|
+
```
|
package/index.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { randomBytes, randomUUID } from "node:crypto";
|
|
2
|
+
import { arch, platform, release } from "node:os";
|
|
3
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
|
|
5
|
+
const CLI_NAME = "vibe_rs";
|
|
6
|
+
const CLI_VERSION = "3.1.4";
|
|
7
|
+
const CALL_SOURCE = "vibe_code";
|
|
8
|
+
const HOST_KIND = "local";
|
|
9
|
+
const PLATFORM_IDS: Record<string, string> = {
|
|
10
|
+
win32: "windows",
|
|
11
|
+
darwin: "darwin",
|
|
12
|
+
linux: "linux",
|
|
13
|
+
freebsd: "freebsd",
|
|
14
|
+
openbsd: "openbsd",
|
|
15
|
+
netbsd: "netbsd",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function isObject(value: unknown): value is Record<string, unknown> {
|
|
19
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// HTTP header names are case-insensitive, but a duplicate key would send both values.
|
|
23
|
+
function setHeader(headers: Record<string, string | null>, name: string, value: string): void {
|
|
24
|
+
const lower = name.toLowerCase();
|
|
25
|
+
for (const key of Object.keys(headers)) {
|
|
26
|
+
if (key !== name && key.toLowerCase() === lower) delete headers[key];
|
|
27
|
+
}
|
|
28
|
+
headers[name] = value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function newSessionId(): string {
|
|
32
|
+
const head = randomBytes(10).toString("hex");
|
|
33
|
+
const tail = randomBytes(6).toString("hex");
|
|
34
|
+
return `${head.slice(0, 8)}-${head.slice(8, 12)}-${head.slice(12, 16)}-${head.slice(16, 20)}-${tail}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function machine(): string {
|
|
38
|
+
switch (arch()) {
|
|
39
|
+
case "x64":
|
|
40
|
+
return platform() === "win32" ? "amd64" : "x86_64";
|
|
41
|
+
case "arm64":
|
|
42
|
+
return platform() === "linux" ? "aarch64" : "arm64";
|
|
43
|
+
default:
|
|
44
|
+
return arch();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// shortcut: os_version is the kernel release, use the distro VERSION_ID if it ever matters.
|
|
49
|
+
function requestMetadata(session_id: string): Record<string, string> {
|
|
50
|
+
return {
|
|
51
|
+
os: PLATFORM_IDS[platform()] ?? platform(),
|
|
52
|
+
arch: machine(),
|
|
53
|
+
os_version: release(),
|
|
54
|
+
version: CLI_VERSION,
|
|
55
|
+
session_id,
|
|
56
|
+
message_id: randomUUID(),
|
|
57
|
+
agent_entrypoint: "cli",
|
|
58
|
+
agent_version: CLI_VERSION,
|
|
59
|
+
client_name: CLI_NAME,
|
|
60
|
+
client_version: CLI_VERSION,
|
|
61
|
+
terminal_emulator: "unknown",
|
|
62
|
+
call_type: "main_call",
|
|
63
|
+
call_source: CALL_SOURCE,
|
|
64
|
+
host_kind: HOST_KIND,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default function (pi: ExtensionAPI): void {
|
|
69
|
+
const sessions = new Map<string, string>();
|
|
70
|
+
|
|
71
|
+
const affinity = (ctx: ExtensionContext): string => {
|
|
72
|
+
const piSession = ctx.sessionManager.getSessionId();
|
|
73
|
+
let session = sessions.get(piSession);
|
|
74
|
+
if (!session) {
|
|
75
|
+
session = newSessionId();
|
|
76
|
+
sessions.set(piSession, session);
|
|
77
|
+
}
|
|
78
|
+
return session;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
pi.on("before_provider_headers", (event, ctx) => {
|
|
82
|
+
const model = ctx.model;
|
|
83
|
+
if (!model || model.provider !== "mistral") return;
|
|
84
|
+
|
|
85
|
+
setHeader(event.headers, "User-Agent", `mistral-client-python/Mistral-Vibe/${CLI_VERSION}`);
|
|
86
|
+
setHeader(event.headers, "x-affinity", affinity(ctx));
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
pi.on("before_provider_request", (event, ctx) => {
|
|
90
|
+
const model = ctx.model;
|
|
91
|
+
if (!model || model.provider !== "mistral") return;
|
|
92
|
+
if (!isObject(event.payload)) return;
|
|
93
|
+
|
|
94
|
+
return { ...event.payload, metadata: requestMetadata(affinity(ctx)) };
|
|
95
|
+
});
|
|
96
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deathbeam/pi-mistral",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Mistral models through the built-in mistral provider for Pi",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/deathbeam/pi-packages.git",
|
|
10
|
+
"directory": "packages/pi-mistral"
|
|
11
|
+
},
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=22.19.0"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"index.ts",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"pi": {
|
|
21
|
+
"extensions": [
|
|
22
|
+
"./index.ts"
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
27
|
+
}
|
|
28
|
+
}
|