pi-freerouter 0.1.0
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 +79 -0
- package/dist/discovery.d.ts +2 -0
- package/dist/discovery.js +47 -0
- package/dist/discovery.js.map +1 -0
- package/dist/discovery.test.d.ts +1 -0
- package/dist/discovery.test.js +68 -0
- package/dist/discovery.test.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +321 -0
- package/dist/index.js.map +1 -0
- package/dist/router.d.ts +12 -0
- package/dist/router.js +53 -0
- package/dist/router.js.map +1 -0
- package/dist/router.test.d.ts +1 -0
- package/dist/router.test.js +74 -0
- package/dist/router.test.js.map +1 -0
- package/dist/stream.d.ts +11 -0
- package/dist/stream.js +292 -0
- package/dist/stream.js.map +1 -0
- package/dist/stream.test.d.ts +1 -0
- package/dist/stream.test.js +129 -0
- package/dist/stream.test.js.map +1 -0
- package/dist/types.d.ts +186 -0
- package/dist/types.js +88 -0
- package/dist/types.js.map +1 -0
- package/package.json +23 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type re-exports for pi-freerouter.
|
|
3
|
+
*
|
|
4
|
+
* All extension types come from @earendil-works/pi-coding-agent.
|
|
5
|
+
* The AI-layer types (AssistantMessageEventStream, Context, Model, etc.) are
|
|
6
|
+
* NOT re-exported by the top-level pi-coding-agent package — they live in the
|
|
7
|
+
* bundled @earendil-works/pi-ai sub-package. We declare them here as local
|
|
8
|
+
* types that are structurally compatible, derived from the published .d.ts
|
|
9
|
+
* files inspected at /node_modules/.../pi-ai/dist/utils/event-stream.d.ts and
|
|
10
|
+
* /node_modules/.../pi-ai/dist/types.d.ts.
|
|
11
|
+
*/
|
|
12
|
+
export type { ExtensionAPI, ExtensionFactory, ExtensionContext, ProviderConfig, ProviderModelConfig, SessionStartEvent, } from "@earendil-works/pi-coding-agent";
|
|
13
|
+
/** Supported input types for a message. */
|
|
14
|
+
export interface TextContent {
|
|
15
|
+
type: "text";
|
|
16
|
+
text: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ImageContent {
|
|
19
|
+
type: "image";
|
|
20
|
+
data: string;
|
|
21
|
+
mimeType: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ToolCall {
|
|
24
|
+
type: "toolCall";
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
arguments: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
export interface ThinkingContent {
|
|
30
|
+
type: "thinking";
|
|
31
|
+
thinking: string;
|
|
32
|
+
}
|
|
33
|
+
export interface Usage {
|
|
34
|
+
input: number;
|
|
35
|
+
output: number;
|
|
36
|
+
cacheRead: number;
|
|
37
|
+
cacheWrite: number;
|
|
38
|
+
totalTokens: number;
|
|
39
|
+
cost: {
|
|
40
|
+
input: number;
|
|
41
|
+
output: number;
|
|
42
|
+
cacheRead: number;
|
|
43
|
+
cacheWrite: number;
|
|
44
|
+
total: number;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export type StopReason = "stop" | "length" | "toolUse" | "error" | "aborted";
|
|
48
|
+
export interface UserMessage {
|
|
49
|
+
role: "user";
|
|
50
|
+
content: string | (TextContent | ImageContent)[];
|
|
51
|
+
timestamp: number;
|
|
52
|
+
}
|
|
53
|
+
export interface AssistantMessage {
|
|
54
|
+
role: "assistant";
|
|
55
|
+
content: (TextContent | ThinkingContent | ToolCall)[];
|
|
56
|
+
api: string;
|
|
57
|
+
provider: string;
|
|
58
|
+
model: string;
|
|
59
|
+
usage: Usage;
|
|
60
|
+
stopReason: StopReason;
|
|
61
|
+
timestamp: number;
|
|
62
|
+
errorMessage?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface ToolResultMessage {
|
|
65
|
+
role: "toolResult";
|
|
66
|
+
toolCallId: string;
|
|
67
|
+
toolName: string;
|
|
68
|
+
content: (TextContent | ImageContent)[];
|
|
69
|
+
isError: boolean;
|
|
70
|
+
timestamp: number;
|
|
71
|
+
}
|
|
72
|
+
export type Message = UserMessage | AssistantMessage | ToolResultMessage;
|
|
73
|
+
/** Context passed to streamSimple (and the ProviderConfig.streamSimple callback). */
|
|
74
|
+
export interface Context {
|
|
75
|
+
systemPrompt?: string;
|
|
76
|
+
messages: Message[];
|
|
77
|
+
tools?: Array<{
|
|
78
|
+
name: string;
|
|
79
|
+
description: string;
|
|
80
|
+
parameters: unknown;
|
|
81
|
+
}>;
|
|
82
|
+
}
|
|
83
|
+
/** Minimal Model shape used by streamSimple. */
|
|
84
|
+
export interface Model {
|
|
85
|
+
id: string;
|
|
86
|
+
name: string;
|
|
87
|
+
api: string;
|
|
88
|
+
provider: string;
|
|
89
|
+
baseUrl: string;
|
|
90
|
+
reasoning: boolean;
|
|
91
|
+
input: ("text" | "image")[];
|
|
92
|
+
cost: {
|
|
93
|
+
input: number;
|
|
94
|
+
output: number;
|
|
95
|
+
cacheRead: number;
|
|
96
|
+
cacheWrite: number;
|
|
97
|
+
};
|
|
98
|
+
contextWindow: number;
|
|
99
|
+
maxTokens: number;
|
|
100
|
+
headers?: Record<string, string>;
|
|
101
|
+
}
|
|
102
|
+
export type ThinkingLevel = "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
103
|
+
/** Options passed to ProviderConfig.streamSimple. */
|
|
104
|
+
export interface SimpleStreamOptions {
|
|
105
|
+
temperature?: number;
|
|
106
|
+
maxTokens?: number;
|
|
107
|
+
signal?: AbortSignal;
|
|
108
|
+
apiKey?: string;
|
|
109
|
+
reasoning?: ThinkingLevel;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Async-iterable event stream returned by ProviderConfig.streamSimple.
|
|
113
|
+
* Structurally compatible with AssistantMessageEventStream from pi-ai.
|
|
114
|
+
*/
|
|
115
|
+
export type AssistantMessageEvent = {
|
|
116
|
+
type: "start";
|
|
117
|
+
partial: AssistantMessage;
|
|
118
|
+
} | {
|
|
119
|
+
type: "text_start";
|
|
120
|
+
contentIndex: number;
|
|
121
|
+
partial: AssistantMessage;
|
|
122
|
+
} | {
|
|
123
|
+
type: "text_delta";
|
|
124
|
+
contentIndex: number;
|
|
125
|
+
delta: string;
|
|
126
|
+
partial: AssistantMessage;
|
|
127
|
+
} | {
|
|
128
|
+
type: "text_end";
|
|
129
|
+
contentIndex: number;
|
|
130
|
+
content: string;
|
|
131
|
+
partial: AssistantMessage;
|
|
132
|
+
} | {
|
|
133
|
+
type: "thinking_start";
|
|
134
|
+
contentIndex: number;
|
|
135
|
+
partial: AssistantMessage;
|
|
136
|
+
} | {
|
|
137
|
+
type: "thinking_delta";
|
|
138
|
+
contentIndex: number;
|
|
139
|
+
delta: string;
|
|
140
|
+
partial: AssistantMessage;
|
|
141
|
+
} | {
|
|
142
|
+
type: "thinking_end";
|
|
143
|
+
contentIndex: number;
|
|
144
|
+
content: string;
|
|
145
|
+
partial: AssistantMessage;
|
|
146
|
+
} | {
|
|
147
|
+
type: "toolcall_start";
|
|
148
|
+
contentIndex: number;
|
|
149
|
+
partial: AssistantMessage;
|
|
150
|
+
} | {
|
|
151
|
+
type: "toolcall_delta";
|
|
152
|
+
contentIndex: number;
|
|
153
|
+
delta: string;
|
|
154
|
+
partial: AssistantMessage;
|
|
155
|
+
} | {
|
|
156
|
+
type: "toolcall_end";
|
|
157
|
+
contentIndex: number;
|
|
158
|
+
toolCall: ToolCall;
|
|
159
|
+
partial: AssistantMessage;
|
|
160
|
+
} | {
|
|
161
|
+
type: "done";
|
|
162
|
+
reason: "stop" | "length" | "toolUse";
|
|
163
|
+
message: AssistantMessage;
|
|
164
|
+
} | {
|
|
165
|
+
type: "error";
|
|
166
|
+
reason: "aborted" | "error";
|
|
167
|
+
error: AssistantMessage;
|
|
168
|
+
};
|
|
169
|
+
export interface AssistantMessageEventStream extends AsyncIterable<AssistantMessageEvent> {
|
|
170
|
+
push(event: AssistantMessageEvent): void;
|
|
171
|
+
end(result?: AssistantMessage): void;
|
|
172
|
+
result(): Promise<AssistantMessage>;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Factory function for AssistantMessageEventStream.
|
|
176
|
+
*
|
|
177
|
+
* NOTE: The real implementation lives in @earendil-works/pi-ai, which is a
|
|
178
|
+
* bundled sub-dependency not directly importable from extension code. Pi
|
|
179
|
+
* injects its own stream factory through the ProviderConfig.streamSimple
|
|
180
|
+
* callback signature — extensions never need to instantiate the stream
|
|
181
|
+
* themselves. If you do need a concrete implementation for testing, create
|
|
182
|
+
* one that satisfies the AsyncIterable interface above.
|
|
183
|
+
*
|
|
184
|
+
* @internal — for testing only. Pi runtime provides the real factory via streamSimple context.
|
|
185
|
+
*/
|
|
186
|
+
export declare function createAssistantMessageEventStream(): AssistantMessageEventStream;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type re-exports for pi-freerouter.
|
|
3
|
+
*
|
|
4
|
+
* All extension types come from @earendil-works/pi-coding-agent.
|
|
5
|
+
* The AI-layer types (AssistantMessageEventStream, Context, Model, etc.) are
|
|
6
|
+
* NOT re-exported by the top-level pi-coding-agent package — they live in the
|
|
7
|
+
* bundled @earendil-works/pi-ai sub-package. We declare them here as local
|
|
8
|
+
* types that are structurally compatible, derived from the published .d.ts
|
|
9
|
+
* files inspected at /node_modules/.../pi-ai/dist/utils/event-stream.d.ts and
|
|
10
|
+
* /node_modules/.../pi-ai/dist/types.d.ts.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Factory function for AssistantMessageEventStream.
|
|
14
|
+
*
|
|
15
|
+
* NOTE: The real implementation lives in @earendil-works/pi-ai, which is a
|
|
16
|
+
* bundled sub-dependency not directly importable from extension code. Pi
|
|
17
|
+
* injects its own stream factory through the ProviderConfig.streamSimple
|
|
18
|
+
* callback signature — extensions never need to instantiate the stream
|
|
19
|
+
* themselves. If you do need a concrete implementation for testing, create
|
|
20
|
+
* one that satisfies the AsyncIterable interface above.
|
|
21
|
+
*
|
|
22
|
+
* @internal — for testing only. Pi runtime provides the real factory via streamSimple context.
|
|
23
|
+
*/
|
|
24
|
+
export function createAssistantMessageEventStream() {
|
|
25
|
+
const queue = [];
|
|
26
|
+
const waiters = [];
|
|
27
|
+
let isDone = false;
|
|
28
|
+
let finalResult;
|
|
29
|
+
let resolveResult;
|
|
30
|
+
const resultPromise = new Promise((r) => (resolveResult = r));
|
|
31
|
+
const stream = {
|
|
32
|
+
push(event) {
|
|
33
|
+
if (isDone)
|
|
34
|
+
return;
|
|
35
|
+
if (waiters.length > 0) {
|
|
36
|
+
waiters.shift()({ value: event, done: false });
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
queue.push(event);
|
|
40
|
+
}
|
|
41
|
+
if (event.type === "done") {
|
|
42
|
+
finalResult = event.message;
|
|
43
|
+
resolveResult(event.message);
|
|
44
|
+
isDone = true;
|
|
45
|
+
while (waiters.length > 0) {
|
|
46
|
+
waiters.shift()({ value: undefined, done: true });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else if (event.type === "error") {
|
|
50
|
+
finalResult = event.error;
|
|
51
|
+
resolveResult(event.error);
|
|
52
|
+
isDone = true;
|
|
53
|
+
while (waiters.length > 0) {
|
|
54
|
+
waiters.shift()({ value: undefined, done: true });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
end(result) {
|
|
59
|
+
isDone = true;
|
|
60
|
+
if (result && !finalResult)
|
|
61
|
+
resolveResult(result);
|
|
62
|
+
while (waiters.length > 0) {
|
|
63
|
+
waiters.shift()({ value: undefined, done: true });
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
result() {
|
|
67
|
+
return resultPromise;
|
|
68
|
+
},
|
|
69
|
+
[Symbol.asyncIterator]() {
|
|
70
|
+
return {
|
|
71
|
+
next() {
|
|
72
|
+
if (queue.length > 0) {
|
|
73
|
+
return Promise.resolve({ value: queue.shift(), done: false });
|
|
74
|
+
}
|
|
75
|
+
if (isDone) {
|
|
76
|
+
return Promise.resolve({
|
|
77
|
+
value: undefined,
|
|
78
|
+
done: true,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return new Promise((resolve) => waiters.push(resolve));
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
return stream;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAwIH;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iCAAiC;IAC/C,MAAM,KAAK,GAA4B,EAAE,CAAC;IAC1C,MAAM,OAAO,GAA8D,EAAE,CAAC;IAC9E,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,WAAyC,CAAC;IAC9C,IAAI,aAA6C,CAAC;IAClD,MAAM,aAAa,GAAG,IAAI,OAAO,CAAmB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC;IAEhF,MAAM,MAAM,GAAgC;QAC1C,IAAI,CAAC,KAA4B;YAC/B,IAAI,MAAM;gBAAE,OAAO;YACnB,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACvB,OAAO,CAAC,KAAK,EAAG,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;YAClD,CAAC;iBAAM,CAAC;gBACN,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC;YACD,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;gBAC1B,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC;gBAC5B,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBAC7B,MAAM,GAAG,IAAI,CAAC;gBACd,OAAO,OAAO,CAAC,MA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4BACpD,IAAI,EAAE,IAAI;yBACX,CAAC,CAAC;oBACL,CAAC;oBACD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;gBACzD,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pi-freerouter",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Pi coding agent extension — auto-routes to free OpenRouter models",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": ["dist"],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"typecheck": "tsc --noEmit",
|
|
12
|
+
"test": "tsc && node --test dist/**/*.test.js"
|
|
13
|
+
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"@earendil-works/pi-coding-agent": ">=1.0.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@earendil-works/pi-coding-agent": "latest",
|
|
19
|
+
"typescript": "^5.0.0"
|
|
20
|
+
},
|
|
21
|
+
"keywords": ["pi", "pi-coding-agent", "openrouter"],
|
|
22
|
+
"license": "MIT"
|
|
23
|
+
}
|