@devvibex/aiflow 1.5.0 → 1.6.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 +1 -1
- package/src/index.d.ts +81 -0
- package/src/index.js +110 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devvibex/aiflow",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "First-party LLM gateway SDK for apps generated on the VibeX platform — chat, streaming, image, video, music (Lyria), sound effects (ElevenLabs), embeddings and real-time speech translation (Gemini Live) without shipping any third-party API key.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
package/src/index.d.ts
CHANGED
|
@@ -61,16 +61,26 @@ export interface ChatUsage {
|
|
|
61
61
|
creditsUsed: number;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
/** Where the resolved `model` came from. */
|
|
65
|
+
export type ModelSource = 'request' | 'message' | 'default';
|
|
66
|
+
|
|
64
67
|
export interface ChatResponse {
|
|
65
68
|
id: string;
|
|
69
|
+
/** Resolved model id. */
|
|
66
70
|
model: string;
|
|
67
71
|
content: string;
|
|
68
72
|
usage: ChatUsage;
|
|
73
|
+
/** Where the resolved `model` came from. */
|
|
74
|
+
modelSource?: ModelSource;
|
|
69
75
|
}
|
|
70
76
|
|
|
71
77
|
export interface ChatStreamChunk {
|
|
72
78
|
delta: string;
|
|
73
79
|
done: boolean;
|
|
80
|
+
/** Resolved model id (present on the final `done: true` chunk). */
|
|
81
|
+
model?: string;
|
|
82
|
+
/** Where the resolved `model` came from (present on the final `done: true` chunk). */
|
|
83
|
+
modelSource?: ModelSource;
|
|
74
84
|
[key: string]: unknown;
|
|
75
85
|
}
|
|
76
86
|
|
|
@@ -515,6 +525,8 @@ export interface AiflowConfig {
|
|
|
515
525
|
video: string[];
|
|
516
526
|
audio: string[];
|
|
517
527
|
sfx: string[];
|
|
528
|
+
/** Real-time translate models, when configured. */
|
|
529
|
+
translate?: string[];
|
|
518
530
|
};
|
|
519
531
|
defaults: {
|
|
520
532
|
chat: string;
|
|
@@ -523,6 +535,8 @@ export interface AiflowConfig {
|
|
|
523
535
|
video: string;
|
|
524
536
|
audio: string;
|
|
525
537
|
sfx: string;
|
|
538
|
+
/** Default real-time translate model, when configured. */
|
|
539
|
+
translate?: string;
|
|
526
540
|
};
|
|
527
541
|
limits: {
|
|
528
542
|
maxTokens: number;
|
|
@@ -534,6 +548,53 @@ export interface AiflowConfig {
|
|
|
534
548
|
creditValue: number;
|
|
535
549
|
/** Module-configured default system prompt, or null if none. */
|
|
536
550
|
systemPrompt?: string | null;
|
|
551
|
+
/** Whether server-side web search is enabled for chat by default. */
|
|
552
|
+
webSearch?: boolean;
|
|
553
|
+
/** Whether the real-time live-translate feature is enabled. */
|
|
554
|
+
liveTranslate?: boolean;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// ─── Admin (module config) ───────────────────────────────────────────────────
|
|
558
|
+
|
|
559
|
+
/** One AIFlow module in the app's project, as returned by `admin.listModules`. */
|
|
560
|
+
export interface AiflowAdminModule {
|
|
561
|
+
appId: string;
|
|
562
|
+
moduleId: number;
|
|
563
|
+
feature: string | null;
|
|
564
|
+
useCase: string;
|
|
565
|
+
useCaseName: string | null;
|
|
566
|
+
title: string | null;
|
|
567
|
+
systemPrompt: string | null;
|
|
568
|
+
defaults: Record<string, string>;
|
|
569
|
+
models: string[];
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/** Input for `admin.updateConfig`. */
|
|
573
|
+
export interface AiflowAdminUpdateConfigInput {
|
|
574
|
+
/**
|
|
575
|
+
* Target module. Optional — defaults to the module for this client's app_id.
|
|
576
|
+
* When set it must be a sibling module in the same project.
|
|
577
|
+
*/
|
|
578
|
+
moduleId?: number;
|
|
579
|
+
systemPrompt?: string;
|
|
580
|
+
defaults?: Record<string, string>;
|
|
581
|
+
/** Sugar: sets the chat default model (folded into `defaults.chat`). */
|
|
582
|
+
defaultModel?: string;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Admin namespace — manage the app's AIFlow module config. Requires an admin
|
|
587
|
+
* bearer token set via `setAdminToken()`; the gateway rejects non-admins (403).
|
|
588
|
+
*/
|
|
589
|
+
export interface AiflowAdminNamespace {
|
|
590
|
+
/** List every AIFlow module in this app's project. */
|
|
591
|
+
listModules(opts?: {
|
|
592
|
+
signal?: AbortSignal;
|
|
593
|
+
}): Promise<{ modules: AiflowAdminModule[] }>;
|
|
594
|
+
/** Update the target module's system prompt and/or default models. */
|
|
595
|
+
updateConfig(
|
|
596
|
+
input: AiflowAdminUpdateConfigInput,
|
|
597
|
+
): Promise<{ module: AiflowAdminModule }>;
|
|
537
598
|
}
|
|
538
599
|
|
|
539
600
|
export class AIFlowClient {
|
|
@@ -545,6 +606,8 @@ export class AIFlowClient {
|
|
|
545
606
|
endUserId: string | null;
|
|
546
607
|
/** Per-user knowledge base — upload / list / delete the current user's docs. */
|
|
547
608
|
readonly knowledge: KnowledgeNamespace;
|
|
609
|
+
/** Admin namespace — manage the app's AIFlow module config (needs `setAdminToken`). */
|
|
610
|
+
readonly admin: AiflowAdminNamespace;
|
|
548
611
|
|
|
549
612
|
constructor(options: AIFlowClientOptions);
|
|
550
613
|
|
|
@@ -556,6 +619,24 @@ export class AIFlowClient {
|
|
|
556
619
|
*/
|
|
557
620
|
setEndUser(endUserId: string | null): this;
|
|
558
621
|
|
|
622
|
+
/**
|
|
623
|
+
* Set a session-level default model for one generation kind. Wins over the
|
|
624
|
+
* server config default, but a per-call `model` still wins over this. Pass
|
|
625
|
+
* `null` to clear the override. Returns `this` for chaining.
|
|
626
|
+
*/
|
|
627
|
+
setModel(
|
|
628
|
+
kind: 'chat' | 'image' | 'embed' | 'video' | 'audio' | 'sfx',
|
|
629
|
+
model: string | null,
|
|
630
|
+
): this;
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Set (or clear with `null`) the admin bearer token — the generated app's
|
|
634
|
+
* own logged-in admin JWT (the same bearer the app's `vibex` SDK reads from
|
|
635
|
+
* localStorage['access_token']). Required for every `admin.*` call. Returns
|
|
636
|
+
* `this` for chaining.
|
|
637
|
+
*/
|
|
638
|
+
setAdminToken(token: string | null): this;
|
|
639
|
+
|
|
559
640
|
/**
|
|
560
641
|
* Fetch (and cache) the server-side AIFlow config. Pass `{ refresh: true }`
|
|
561
642
|
* to force a reload.
|
package/src/index.js
CHANGED
|
@@ -64,6 +64,9 @@ export class AIFlowClient {
|
|
|
64
64
|
audio: defaultAudioModel,
|
|
65
65
|
sfx: defaultSfxModel,
|
|
66
66
|
};
|
|
67
|
+
// Admin bearer token (the generated app's own logged-in admin JWT).
|
|
68
|
+
// Set via setAdminToken(); required by the /admin/* routes.
|
|
69
|
+
this._adminToken = null;
|
|
67
70
|
this.timeout = timeout;
|
|
68
71
|
this.maxRetries = maxRetries;
|
|
69
72
|
this._fetch =
|
|
@@ -95,6 +98,18 @@ export class AIFlowClient {
|
|
|
95
98
|
/** Delete one of the current user's own knowledge sources by id. */
|
|
96
99
|
deleteMine: (id, opts) => this._knowledgeDelete(id, opts),
|
|
97
100
|
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Admin namespace — manage the app's AIFlow module config (system
|
|
104
|
+
* prompt + per-kind default models). Requires an admin bearer token set
|
|
105
|
+
* via `setAdminToken()`; the gateway rejects non-admin callers (403).
|
|
106
|
+
*/
|
|
107
|
+
this.admin = {
|
|
108
|
+
/** List every AIFlow module in this app's project. */
|
|
109
|
+
listModules: (opts) => this._adminListModules(opts),
|
|
110
|
+
/** Update this app's (or a sibling) module system prompt / defaults. */
|
|
111
|
+
updateConfig: (input) => this._adminUpdateConfig(input),
|
|
112
|
+
};
|
|
98
113
|
}
|
|
99
114
|
|
|
100
115
|
/**
|
|
@@ -109,6 +124,29 @@ export class AIFlowClient {
|
|
|
109
124
|
return this;
|
|
110
125
|
}
|
|
111
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Set a session-level default model for one generation kind. Wins over the
|
|
129
|
+
* server-fetched config default, but a per-call `model` still wins over
|
|
130
|
+
* this. Pass `null` to clear the override and fall back to config.
|
|
131
|
+
* @param {'chat'|'image'|'embed'|'video'|'audio'|'sfx'} kind
|
|
132
|
+
* @param {string|null} model
|
|
133
|
+
*/
|
|
134
|
+
setModel(kind, model) {
|
|
135
|
+
this._userDefaults[kind] = model || null;
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Set (or clear) the admin bearer token. This is the generated app's own
|
|
141
|
+
* logged-in admin JWT (the same bearer the app's `vibex` SDK reads from
|
|
142
|
+
* localStorage['access_token']). Required for every `admin.*` call.
|
|
143
|
+
* @param {string|null} token
|
|
144
|
+
*/
|
|
145
|
+
setAdminToken(token) {
|
|
146
|
+
this._adminToken = token || null;
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
|
|
112
150
|
/**
|
|
113
151
|
* Fetch (and cache) the server-side AIFlow config. Subsequent calls
|
|
114
152
|
* return the cached object; pass `{ refresh: true }` to force a reload.
|
|
@@ -688,6 +726,19 @@ export class AIFlowClient {
|
|
|
688
726
|
return h;
|
|
689
727
|
}
|
|
690
728
|
|
|
729
|
+
/**
|
|
730
|
+
* Auth headers for the admin (`/admin/*`) routes: the standard app/end-user
|
|
731
|
+
* headers PLUS the admin bearer token (when set via `setAdminToken()`).
|
|
732
|
+
*/
|
|
733
|
+
_adminHeaders() {
|
|
734
|
+
return {
|
|
735
|
+
...this._authHeaders(),
|
|
736
|
+
...(this._adminToken
|
|
737
|
+
? { Authorization: 'Bearer ' + this._adminToken }
|
|
738
|
+
: {}),
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
|
|
691
742
|
/** POST a JSON body to the gateway. */
|
|
692
743
|
async _request(path, body, { signal, stream = false, timeout } = {}) {
|
|
693
744
|
const headers = {
|
|
@@ -702,6 +753,29 @@ export class AIFlowClient {
|
|
|
702
753
|
);
|
|
703
754
|
}
|
|
704
755
|
|
|
756
|
+
/**
|
|
757
|
+
* Request an admin (`/admin/*`) route. Mirrors {@link _request} but attaches
|
|
758
|
+
* the admin bearer via {@link _adminHeaders}. Supports GET (no body) and
|
|
759
|
+
* PATCH/POST (JSON body). Reuses the shared timeout/retry + error mapping.
|
|
760
|
+
*/
|
|
761
|
+
async _adminRequest(path, body, { method = 'GET', signal, timeout } = {}) {
|
|
762
|
+
const isBodyMethod = method !== 'GET' && method !== 'HEAD';
|
|
763
|
+
const headers = {
|
|
764
|
+
...this._adminHeaders(),
|
|
765
|
+
Accept: 'application/json',
|
|
766
|
+
};
|
|
767
|
+
if (isBodyMethod) headers['Content-Type'] = 'application/json';
|
|
768
|
+
return this._fetchWithRetry(
|
|
769
|
+
`${this.baseUrl}${path}`,
|
|
770
|
+
{
|
|
771
|
+
method,
|
|
772
|
+
headers,
|
|
773
|
+
...(isBodyMethod ? { body: JSON.stringify(body ?? {}) } : {}),
|
|
774
|
+
},
|
|
775
|
+
{ signal, timeout },
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
|
|
705
779
|
/** GET from the gateway (used by short status polls). */
|
|
706
780
|
async _get(path, { signal, timeout } = {}) {
|
|
707
781
|
return this._fetchWithRetry(
|
|
@@ -837,6 +911,42 @@ export class AIFlowClient {
|
|
|
837
911
|
);
|
|
838
912
|
return await res.json();
|
|
839
913
|
}
|
|
914
|
+
|
|
915
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
916
|
+
// Admin (module config) internals
|
|
917
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
918
|
+
|
|
919
|
+
async _adminListModules({ signal } = {}) {
|
|
920
|
+
const res = await this._adminRequest('/admin/modules', undefined, {
|
|
921
|
+
method: 'GET',
|
|
922
|
+
signal,
|
|
923
|
+
});
|
|
924
|
+
return await res.json();
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
async _adminUpdateConfig({
|
|
928
|
+
moduleId,
|
|
929
|
+
systemPrompt,
|
|
930
|
+
defaults,
|
|
931
|
+
defaultModel,
|
|
932
|
+
signal,
|
|
933
|
+
} = {}) {
|
|
934
|
+
// `defaultModel` is sugar for setting the chat default; fold it into
|
|
935
|
+
// `defaults.chat` without clobbering any explicit `defaults` passed.
|
|
936
|
+
let resolvedDefaults = defaults;
|
|
937
|
+
if (defaultModel != null) {
|
|
938
|
+
resolvedDefaults = { ...(defaults || {}), chat: defaultModel };
|
|
939
|
+
}
|
|
940
|
+
const body = {};
|
|
941
|
+
if (moduleId != null) body.moduleId = moduleId;
|
|
942
|
+
if (systemPrompt !== undefined) body.systemPrompt = systemPrompt;
|
|
943
|
+
if (resolvedDefaults !== undefined) body.defaults = resolvedDefaults;
|
|
944
|
+
const res = await this._adminRequest('/admin/config', body, {
|
|
945
|
+
method: 'PATCH',
|
|
946
|
+
signal,
|
|
947
|
+
});
|
|
948
|
+
return await res.json();
|
|
949
|
+
}
|
|
840
950
|
}
|
|
841
951
|
|
|
842
952
|
// ────────────────────────────────────────────────────────────────────────────
|