sliftutils 1.2.3 → 1.2.5
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/index.d.ts +2 -0
- package/misc/apiKeys.d.ts +1 -0
- package/misc/apiKeys.tsx +7 -3
- package/misc/openrouter.d.ts +1 -0
- package/misc/openrouter.ts +3 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ declare module "sliftutils/misc/apiKeys" {
|
|
|
14
14
|
getAllKeys(): string[];
|
|
15
15
|
get(key: string): Promise<string> | undefined;
|
|
16
16
|
};
|
|
17
|
+
export declare function setAPIKey(key: string, value: string): void;
|
|
17
18
|
export declare class ManageAPIKeys extends preact.Component {
|
|
18
19
|
render(): string;
|
|
19
20
|
}
|
|
@@ -228,6 +229,7 @@ declare module "sliftutils/misc/openrouter" {
|
|
|
228
229
|
}[];
|
|
229
230
|
export declare function getTotalCost(): number;
|
|
230
231
|
type OpenRouterOptions = {
|
|
232
|
+
apiKey?: string;
|
|
231
233
|
provider?: {
|
|
232
234
|
sort?: "throughput" | "price" | "latency";
|
|
233
235
|
order?: string[];
|
package/misc/apiKeys.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare const getAPIKey: {
|
|
|
10
10
|
getAllKeys(): string[];
|
|
11
11
|
get(key: string): Promise<string> | undefined;
|
|
12
12
|
};
|
|
13
|
+
export declare function setAPIKey(key: string, value: string): void;
|
|
13
14
|
export declare class ManageAPIKeys extends preact.Component {
|
|
14
15
|
render(): string;
|
|
15
16
|
}
|
package/misc/apiKeys.tsx
CHANGED
|
@@ -128,15 +128,19 @@ export const getAPIKey = cache(async function getAPIKey(key: string): Promise<st
|
|
|
128
128
|
try {
|
|
129
129
|
let value = await promise;
|
|
130
130
|
|
|
131
|
-
|
|
132
|
-
state.keys.push(key);
|
|
133
|
-
getStorage().setItem(getStorageKey("__keys"), JSON.stringify(state.keys));
|
|
131
|
+
setAPIKey(key, value);
|
|
134
132
|
return value;
|
|
135
133
|
} finally {
|
|
136
134
|
obj.close();
|
|
137
135
|
}
|
|
138
136
|
});
|
|
139
137
|
|
|
138
|
+
export function setAPIKey(key: string, value: string) {
|
|
139
|
+
getStorage().setItem(getStorageKey(key), value);
|
|
140
|
+
state.keys.push(key);
|
|
141
|
+
getStorage().setItem(getStorageKey("__keys"), JSON.stringify(state.keys));
|
|
142
|
+
}
|
|
143
|
+
|
|
140
144
|
@observer
|
|
141
145
|
export class ManageAPIKeys extends preact.Component {
|
|
142
146
|
render() {
|
package/misc/openrouter.d.ts
CHANGED
package/misc/openrouter.ts
CHANGED
|
@@ -22,6 +22,8 @@ export function getTotalCost() {
|
|
|
22
22
|
return totalCost;
|
|
23
23
|
}
|
|
24
24
|
type OpenRouterOptions = {
|
|
25
|
+
// If not provided, we'll pop up a modal to ask the user for it, Or, if we're on the server, we'll try to read it from the user folder.
|
|
26
|
+
apiKey?: string;
|
|
25
27
|
provider?: {
|
|
26
28
|
sort?: "throughput" | "price" | "latency",
|
|
27
29
|
// https://openrouter.ai/docs/features/provider-routing#ordering-specific-providers
|
|
@@ -90,7 +92,7 @@ export async function openRouterCallBase(config: {
|
|
|
90
92
|
retries?: number;
|
|
91
93
|
}): Promise<string> {
|
|
92
94
|
let { model, messages, options, onCost } = config;
|
|
93
|
-
let openrouterKey = await getAPIKey("openrouter.json");
|
|
95
|
+
let openrouterKey = options?.apiKey || await getAPIKey("openrouter.json");
|
|
94
96
|
console.log(`Calling ${model} with ${messages.length} messages`);
|
|
95
97
|
let time = Date.now();
|
|
96
98
|
let stillRunning = true;
|