@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runappsai/sdk",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "JavaScript / TypeScript client for the RunApps AI Gateway",
5
5
  "license": "MIT",
6
6
  "author": "RunApps",
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
- /** Static gateway API key (typically prefixed `gw-` / `rj_` / `rrt_`).
36
- * Required unless `apiKeyResolver` or `authProvider: "runapps"` is supplied. */
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 — defaults to `"static"`. Pass `"runapps"` to
47
- * activate the built-in browser auth flow against runapps.ai;
48
- * baseURL defaults to `https://www.runapps.ai` in that mode.
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.Client({ authProvider: "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
- const provider = options.authProvider ?? "static";
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 either `apiKey`, `apiKeyResolver`, or `authProvider: \"runapps\"`",
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({