@devvibex/aiflow 1.0.1 → 1.0.3

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.
Files changed (3) hide show
  1. package/README.md +49 -49
  2. package/package.json +1 -1
  3. package/src/index.js +15 -2
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @vibexnpm/aiflow
1
+ # @devvibex/aiflow
2
2
 
3
3
  First-party LLM gateway SDK for apps generated on the VibeX platform.
4
4
  No third-party API key is needed in the browser — every request is routed
@@ -8,11 +8,11 @@ and bills the project owner's credit balance.
8
8
  ## Install
9
9
 
10
10
  ```bash
11
- npm install @vibexnpm/aiflow
11
+ npm install @devvibex/aiflow
12
12
  # or
13
- yarn add @vibexnpm/aiflow
13
+ yarn add @devvibex/aiflow
14
14
  # or
15
- pnpm add @vibexnpm/aiflow
15
+ pnpm add @devvibex/aiflow
16
16
  ```
17
17
 
18
18
  Requires Node.js **18+** (or any modern browser) — uses the native `fetch`
@@ -21,14 +21,14 @@ and `ReadableStream` APIs.
21
21
  ## Quick start
22
22
 
23
23
  ```js
24
- import AIFlowClient from '@vibexnpm/aiflow';
24
+ import AIFlowClient from '@devvibex/aiflow';
25
25
 
26
26
  // No model defaults needed — the SDK fetches them from the server on
27
27
  // first use (cached for the life of the client). Override only if you
28
28
  // want to pin a specific model.
29
29
  const aiflow = new AIFlowClient({
30
30
  appId: 'YOUR_APP_ID', // injected by the platform gateway
31
- baseUrl: 'https://api.vibe-x.io/aiflow',
31
+ baseUrl: 'https://api.vibe-x.app/aiflow',
32
32
  });
33
33
 
34
34
  // Optional — inspect / pre-warm the server config
@@ -67,16 +67,16 @@ console.log(emb.data[0].embedding.length);
67
67
 
68
68
  ### `new AIFlowClient(options)`
69
69
 
70
- | Option | Type | Default | Notes |
71
- | ------------------- | --------------- | ------------------ | ----------------------------------------------- |
72
- | `appId` | `string` | **required** | Public project app id. |
73
- | `baseUrl` | `string` | **required** | Gateway URL, e.g. `https://api.vibe-x.io/aiflow`. |
74
- | `defaultModel` | `string` | from `GET /config` | Override — wins over server config. |
75
- | `defaultImageModel` | `string` | from `GET /config` | Override. |
76
- | `defaultEmbedModel` | `string` | from `GET /config` | Override. |
77
- | `timeout` | `number` | `60000` | Per-request timeout (ms). |
78
- | `maxRetries` | `number` | `2` | Retries on 429 / 5xx / network errors. |
79
- | `fetch` | `typeof fetch` | `globalThis.fetch` | Custom fetch (Node <18, testing). |
70
+ | Option | Type | Default | Notes |
71
+ | ------------------- | -------------- | ------------------ | ------------------------------------------------- |
72
+ | `appId` | `string` | **required** | Public project app id. |
73
+ | `baseUrl` | `string` | **required** | Gateway URL, e.g. `https://api.vibe-x.io/aiflow`. |
74
+ | `defaultModel` | `string` | from `GET /config` | Override — wins over server config. |
75
+ | `defaultImageModel` | `string` | from `GET /config` | Override. |
76
+ | `defaultEmbedModel` | `string` | from `GET /config` | Override. |
77
+ | `timeout` | `number` | `60000` | Per-request timeout (ms). |
78
+ | `maxRetries` | `number` | `2` | Retries on 429 / 5xx / network errors. |
79
+ | `fetch` | `typeof fetch` | `globalThis.fetch` | Custom fetch (Node <18, testing). |
80
80
 
81
81
  When you don't pass a `defaultModel`, the SDK calls `GET /config` on the
82
82
  first `chat` / `chatStream` / `generateImage` / `embed` and caches the
@@ -101,14 +101,14 @@ to invalidate the cache.
101
101
  }
102
102
  ```
103
103
 
104
- ### `aiflow.chat({ messages, model?, system?, maxTokens?, temperature?, tools?, signal? })`
104
+ ### `aiflow.chat({ messages, model?, system?, maxTokens?, temperature?, signal? })`
105
105
 
106
106
  Returns `Promise<{ id, model, content, usage: { inputTokens, outputTokens, creditsUsed } }>`.
107
107
 
108
108
  ### `aiflow.chatStream({ ... })`
109
109
 
110
110
  Async iterable of `{ delta: string, done: boolean }` chunks. The final chunk
111
- has `done: true`.
111
+ has `done: true` and carries the cumulative `usage` object.
112
112
 
113
113
  ### `aiflow.generateImage({ prompt, model?, size?, n?, signal? })`
114
114
 
@@ -124,7 +124,7 @@ Returns `{ data: [{ embedding: number[], index }], usage: { creditsUsed } }`.
124
124
  All failures throw `AIFlowError` with `.status`, `.code`, and `.requestId`.
125
125
 
126
126
  ```js
127
- import { AIFlowError } from '@vibexnpm/aiflow';
127
+ import { AIFlowError } from '@devvibex/aiflow';
128
128
 
129
129
  try {
130
130
  await aiflow.chat({ messages });
@@ -137,12 +137,12 @@ try {
137
137
  }
138
138
  ```
139
139
 
140
- | Status | Meaning | Retry? |
141
- | ------ | ------------------------ | ---------------------------------- |
142
- | 401 | Invalid / revoked appId | No — surface as a config error. |
143
- | 402 | Credits exhausted | **No** — never retry. |
144
- | 429 | Rate limited | Yes, auto (exponential backoff). |
145
- | 5xx | Transient server error | Yes, auto (exponential backoff). |
140
+ | Status | Meaning | Retry? |
141
+ | ------ | ----------------------- | -------------------------------- |
142
+ | 401 | Invalid / revoked appId | No — surface as a config error. |
143
+ | 402 | Credits exhausted | **No** — never retry. |
144
+ | 429 | Rate limited | Yes, auto (exponential backoff). |
145
+ | 5xx | Transient server error | Yes, auto (exponential backoff). |
146
146
 
147
147
  ## Cancellation
148
148
 
@@ -156,12 +156,12 @@ await aiflow.chat({ messages, signal: ctrl.signal });
156
156
 
157
157
  ## Publishing to npmjs
158
158
 
159
- > Owned by the `@vibexnpm` org. You must be a member to publish.
159
+ > Owned by the `@devvibex` org. You must be a member to publish.
160
160
 
161
161
  ### 1. One-off setup
162
162
 
163
163
  ```bash
164
- # Log in with an account that has access to the @vibexnpm org
164
+ # Log in with an account that has access to the @devvibex org
165
165
  npm login
166
166
  ```
167
167
 
@@ -201,24 +201,24 @@ npm publish --access public
201
201
  ```
202
202
 
203
203
  npm will prompt for a 2FA code. On success the package appears at
204
- <https://www.npmjs.com/package/@vibexnpm/aiflow>.
204
+ <https://www.npmjs.com/package/@devvibex/aiflow>.
205
205
 
206
206
  ### 5. Verify
207
207
 
208
208
  ```bash
209
209
  # From any scratch dir
210
- npm info @vibexnpm/aiflow
211
- npm install @vibexnpm/aiflow@latest
210
+ npm info @devvibex/aiflow
211
+ npm install @devvibex/aiflow@latest
212
212
  ```
213
213
 
214
214
  ### 6. Deprecate / unpublish (if needed)
215
215
 
216
216
  ```bash
217
217
  # Soft-deprecate a bad version
218
- npm deprecate @vibexnpm/aiflow@1.0.1 'bug in streaming parser — use 1.0.2+'
218
+ npm deprecate @devvibex/aiflow@1.0.1 'bug in streaming parser — use 1.0.2+'
219
219
 
220
220
  # Hard unpublish (only within 72h of publishing)
221
- npm unpublish @vibexnpm/aiflow@1.0.1
221
+ npm unpublish @devvibex/aiflow@1.0.1
222
222
  ```
223
223
 
224
224
  ### CI publishing (optional)
@@ -227,26 +227,26 @@ Add an `NPM_TOKEN` (automation token) secret to the GitHub repo, then:
227
227
 
228
228
  ```yaml
229
229
  # .github/workflows/publish-aiflow.yml
230
- name: Publish @vibexnpm/aiflow
230
+ name: Publish @devvibex/aiflow
231
231
  on:
232
- push:
233
- tags: ['aiflow-v*']
232
+ push:
233
+ tags: ['aiflow-v*']
234
234
 
235
235
  jobs:
236
- publish:
237
- runs-on: ubuntu-latest
238
- defaults:
239
- run:
240
- working-directory: sdk/aiflow
241
- steps:
242
- - uses: actions/checkout@v4
243
- - uses: actions/setup-node@v4
244
- with:
245
- node-version: '20'
246
- registry-url: 'https://registry.npmjs.org'
247
- - run: npm publish --access public
248
- env:
249
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
236
+ publish:
237
+ runs-on: ubuntu-latest
238
+ defaults:
239
+ run:
240
+ working-directory: sdk/aiflow
241
+ steps:
242
+ - uses: actions/checkout@v4
243
+ - uses: actions/setup-node@v4
244
+ with:
245
+ node-version: '20'
246
+ registry-url: 'https://registry.npmjs.org'
247
+ - run: npm publish --access public
248
+ env:
249
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
250
250
  ```
251
251
 
252
252
  Trigger a release by pushing `git tag aiflow-v1.0.1 && git push --tags`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devvibex/aiflow",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "First-party LLM gateway SDK for apps generated on the VibeX platform — chat, streaming, image generation and embeddings without shipping any third-party API key.",
5
5
  "keywords": [
6
6
  "ai",
package/src/index.js CHANGED
@@ -124,6 +124,17 @@ export class AIFlowClient {
124
124
  return cfg.defaults[kind];
125
125
  }
126
126
 
127
+ /**
128
+ * Resolve the system prompt: user-provided > server config > null.
129
+ * If user provides a system prompt, it always wins.
130
+ * If not, use the systemPrompt from the server config.
131
+ */
132
+ async _resolveSystemPrompt(userSystem) {
133
+ if (userSystem) return userSystem;
134
+ const cfg = await this.getConfig();
135
+ return cfg.systemPrompt || null;
136
+ }
137
+
127
138
  /**
128
139
  * Non-streaming chat completion.
129
140
  * @returns {Promise<{id:string, model:string, content:string, usage:{inputTokens:number,outputTokens:number,creditsUsed:number}}>}
@@ -141,11 +152,12 @@ export class AIFlowClient {
141
152
  throw new AIFlowError('messages must be a non-empty array');
142
153
  }
143
154
  const resolvedModel = model || (await this._resolveDefaultModel('chat'));
155
+ const resolvedSystem = await this._resolveSystemPrompt(system);
144
156
  const res = await this._request(
145
157
  '/chat',
146
158
  {
147
159
  model: resolvedModel,
148
- system,
160
+ system: resolvedSystem,
149
161
  messages,
150
162
  maxTokens,
151
163
  temperature,
@@ -173,11 +185,12 @@ export class AIFlowClient {
173
185
  throw new AIFlowError('messages must be a non-empty array');
174
186
  }
175
187
  const resolvedModel = model || (await this._resolveDefaultModel('chat'));
188
+ const resolvedSystem = await this._resolveSystemPrompt(system);
176
189
  const res = await this._request(
177
190
  '/chat/stream',
178
191
  {
179
192
  model: resolvedModel,
180
- system,
193
+ system: resolvedSystem,
181
194
  messages,
182
195
  maxTokens,
183
196
  temperature,