@likelz/pi-gpt 0.1.1 → 0.1.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.
- package/README.md +7 -2
- package/dist/index.mjs +6 -3
- package/package.json +1 -1
- package/src/state.ts +6 -4
package/README.md
CHANGED
|
@@ -34,14 +34,19 @@ Edit `~/.pi/agent/extensions/pi-gpt.json` (under `PI_CODING_AGENT_DIR` when over
|
|
|
34
34
|
```json
|
|
35
35
|
{
|
|
36
36
|
"enabled": false,
|
|
37
|
-
"models": ["
|
|
37
|
+
"models": ["gpt-6-astra"]
|
|
38
38
|
}
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
Entries
|
|
41
|
+
Entries support three forms, which can be mixed in the same list. Any matching rule enables fast mode when `enabled` is true:
|
|
42
|
+
|
|
43
|
+
- **Model name** without `/`: case-sensitive, exact match against the final segment of the model identifier. `gpt-6-astra` matches across providers, including `magpie/codex/gpt-6-astra`, and excludes `gpt-6-astra-pro`.
|
|
44
|
+
- **Full identifier** containing `/`: exact match against `provider/model`, including any additional model path segments.
|
|
45
|
+
- **Regex** wrapped in `/.../` (without flags): JavaScript regular expression against the complete identifier. Existing regex rules keep their behavior. They use normal regex search semantics; add `^` and `$` where you need boundaries.
|
|
42
46
|
|
|
43
47
|
| Rule | Matches |
|
|
44
48
|
| ------------------- | -------------------------------------------------------------------------------- |
|
|
49
|
+
| `gpt-6-astra` | The exact final model name under any provider or path prefix |
|
|
45
50
|
| `/[/]gpt-6-astra$/` | `openai/gpt-6-astra`, `openai-codex/gpt-6-astra`, and `magpie/codex/gpt-6-astra` |
|
|
46
51
|
| `/^openai[/]gpt-/` | GPT model IDs under the `openai` provider |
|
|
47
52
|
| `openai/gpt-5.4` | Only this exact identifier |
|
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
|
5
5
|
//#region src/state.ts
|
|
6
6
|
const isRegex = (rule) => rule.startsWith("/");
|
|
7
7
|
const isValidRule = (rule) => {
|
|
8
|
-
if (!isRegex(rule)) return /^[^/\s]
|
|
8
|
+
if (!isRegex(rule)) return /^[^/\s]+(?:\/[^\s]+)?$/.test(rule);
|
|
9
9
|
if (rule.length < 3 || !rule.endsWith("/")) return false;
|
|
10
10
|
try {
|
|
11
11
|
new RegExp(rule.slice(1, -1));
|
|
@@ -16,7 +16,7 @@ const isValidRule = (rule) => {
|
|
|
16
16
|
};
|
|
17
17
|
const FastModeState = Schema.Struct({
|
|
18
18
|
enabled: Schema.Boolean,
|
|
19
|
-
models: Schema.Array(Schema.String.pipe(Schema.filter(isValidRule, { message: () => "Expected a provider/model identifier or
|
|
19
|
+
models: Schema.Array(Schema.String.pipe(Schema.filter(isValidRule, { message: () => "Expected a model name, provider/model identifier, or valid /regex/ rule." })))
|
|
20
20
|
});
|
|
21
21
|
const emptyState = () => ({
|
|
22
22
|
enabled: false,
|
|
@@ -24,7 +24,10 @@ const emptyState = () => ({
|
|
|
24
24
|
});
|
|
25
25
|
const decodeState = Schema.decodeUnknownSync(Schema.parseJson(FastModeState));
|
|
26
26
|
const modelKey = (model) => model ? `${model.provider}/${model.id}` : void 0;
|
|
27
|
-
const matchesModel = (rule, key) =>
|
|
27
|
+
const matchesModel = (rule, key) => {
|
|
28
|
+
if (isRegex(rule)) return new RegExp(rule.slice(1, -1)).test(key);
|
|
29
|
+
return rule === (rule.includes("/") ? key : key.slice(key.lastIndexOf("/") + 1));
|
|
30
|
+
};
|
|
28
31
|
const isActive = (state, model) => {
|
|
29
32
|
const key = modelKey(model);
|
|
30
33
|
return state.enabled && key !== void 0 && state.models.some((pattern) => matchesModel(pattern, key));
|
package/package.json
CHANGED
package/src/state.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Schema } from "effect";
|
|
|
3
3
|
const isRegex = (rule: string): boolean => rule.startsWith("/");
|
|
4
4
|
|
|
5
5
|
const isValidRule = (rule: string): boolean => {
|
|
6
|
-
if (!isRegex(rule)) return /^[^/\s]
|
|
6
|
+
if (!isRegex(rule)) return /^[^/\s]+(?:\/[^\s]+)?$/.test(rule);
|
|
7
7
|
if (rule.length < 3 || !rule.endsWith("/")) return false;
|
|
8
8
|
try {
|
|
9
9
|
new RegExp(rule.slice(1, -1));
|
|
@@ -18,7 +18,7 @@ export const FastModeState = Schema.Struct({
|
|
|
18
18
|
models: Schema.Array(
|
|
19
19
|
Schema.String.pipe(
|
|
20
20
|
Schema.filter(isValidRule, {
|
|
21
|
-
message: () => "Expected a provider/model identifier or
|
|
21
|
+
message: () => "Expected a model name, provider/model identifier, or valid /regex/ rule.",
|
|
22
22
|
}),
|
|
23
23
|
),
|
|
24
24
|
),
|
|
@@ -31,8 +31,10 @@ type Model = { readonly provider: string; readonly id: string } | undefined;
|
|
|
31
31
|
export const modelKey = (model: Model): string | undefined =>
|
|
32
32
|
model ? `${model.provider}/${model.id}` : undefined;
|
|
33
33
|
|
|
34
|
-
const matchesModel = (rule: string, key: string): boolean =>
|
|
35
|
-
isRegex(rule)
|
|
34
|
+
const matchesModel = (rule: string, key: string): boolean => {
|
|
35
|
+
if (isRegex(rule)) return new RegExp(rule.slice(1, -1)).test(key);
|
|
36
|
+
return rule === (rule.includes("/") ? key : key.slice(key.lastIndexOf("/") + 1));
|
|
37
|
+
};
|
|
36
38
|
|
|
37
39
|
export const isActive = (state: FastModeState, model: Model): boolean => {
|
|
38
40
|
const key = modelKey(model);
|