@runappsai/sdk 0.4.0 → 0.5.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 +6 -7
- package/dist/client.d.ts +6 -6
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +9 -3
- package/dist/client.js.map +1 -1
- package/dist/sdk.umd.js +2 -2
- package/dist/sdk.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +15 -8
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -32,8 +32,8 @@ const DEFAULT_BASE_URL = "https://www.runapps.ai";
|
|
|
32
32
|
export type AuthProvider = "static" | "runapps" | "runjobs";
|
|
33
33
|
|
|
34
34
|
export interface ClientOptions {
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
35
|
+
/** A personal API key (`rk_…`) or another static key. Leave it out in an
|
|
36
|
+
* app published on RunApps: the browser client then signs the user in. */
|
|
37
37
|
apiKey?: string;
|
|
38
38
|
/**
|
|
39
39
|
* Dynamic API key resolver. See `AuthProvider` for the typical
|
|
@@ -43,9 +43,9 @@ export interface ClientOptions {
|
|
|
43
43
|
*/
|
|
44
44
|
apiKeyResolver?: () => string | Promise<string>;
|
|
45
45
|
/**
|
|
46
|
-
* Auth strategy
|
|
47
|
-
*
|
|
48
|
-
*
|
|
46
|
+
* Auth strategy. Rarely needed: in a browser with no `apiKey` /
|
|
47
|
+
* `apiKeyResolver` the client uses `"runapps"` (the platform sign-in),
|
|
48
|
+
* otherwise `"static"` (the key you pass).
|
|
49
49
|
*/
|
|
50
50
|
authProvider?: AuthProvider;
|
|
51
51
|
/**
|
|
@@ -104,7 +104,7 @@ export interface ClientOptions {
|
|
|
104
104
|
* ```html
|
|
105
105
|
* <script src="https://cdn.jsdelivr.net/npm/@runappsai/sdk/dist/sdk.umd.js"></script>
|
|
106
106
|
* <script>
|
|
107
|
-
* const client = new RunApps
|
|
107
|
+
* const client = new RunApps();
|
|
108
108
|
* const res = await client.chat.create({
|
|
109
109
|
* model: "gpt-4o-mini",
|
|
110
110
|
* messages: [{ role: "user", content: "hello" }],
|
|
@@ -152,7 +152,14 @@ export class RunApps {
|
|
|
152
152
|
readonly events: SDKEvents = new SDKEvents();
|
|
153
153
|
|
|
154
154
|
constructor(options: ClientOptions = {}) {
|
|
155
|
-
|
|
155
|
+
// With no key and no explicit authProvider, a browser client uses the
|
|
156
|
+
// platform sign-in: `new RunApps()` is all an app needs. Elsewhere
|
|
157
|
+
// (Node, workers without a window) there is no one to sign in.
|
|
158
|
+
const provider =
|
|
159
|
+
options.authProvider ??
|
|
160
|
+
(!options.apiKey && !options.apiKeyResolver && typeof window !== "undefined"
|
|
161
|
+
? "runapps"
|
|
162
|
+
: "static");
|
|
156
163
|
let apiKeyResolver = options.apiKeyResolver;
|
|
157
164
|
let baseURL = options.baseURL;
|
|
158
165
|
let onUnauthorized: (() => void) | undefined;
|
|
@@ -197,7 +204,7 @@ export class RunApps {
|
|
|
197
204
|
|
|
198
205
|
if (!options.apiKey && !apiKeyResolver) {
|
|
199
206
|
throw new Error(
|
|
200
|
-
"runapps: pass
|
|
207
|
+
"runapps: pass `apiKey` (or `apiKeyResolver`); outside a browser there is no sign-in to fall back to",
|
|
201
208
|
);
|
|
202
209
|
}
|
|
203
210
|
const transport = new Transport({
|