@reopt-ai/brandapp-sdk 3.1.0 → 3.4.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/CHANGELOG.md +147 -0
- package/README.md +39 -14
- package/dist/abort--nOBFN4M.js +50 -0
- package/dist/ai/index.d.ts +2 -314
- package/dist/ai/index.js +3 -7
- package/dist/ai-provider/index.d.ts +79 -163
- package/dist/ai-provider/index.js +752 -671
- package/dist/auth/index.d.ts +27 -27
- package/dist/auth/index.js +41 -33
- package/dist/better-auth/client.d.ts +6 -5
- package/dist/better-auth/client.js +28 -5
- package/dist/better-auth/index.d.ts +19 -17
- package/dist/better-auth/index.js +180 -133
- package/dist/client-B1q5P8rv.js +83 -0
- package/dist/client-B9QHVhdM.js +77 -0
- package/dist/client-BGGd_cpV.d.ts +103 -0
- package/dist/client-BJcy1V1a.js +140 -0
- package/dist/client-Beivhucf.js +55 -0
- package/dist/client-BruP5_nU.d.ts +147 -0
- package/dist/client-D-yNxNfk.js +28 -0
- package/dist/client-D0eBxh8j.d.ts +284 -0
- package/dist/client-D3RHHUUW.d.ts +207 -0
- package/dist/client-D6gs61w8.d.ts +53 -0
- package/dist/client-DBnK7ooQ.js +86 -0
- package/dist/client-DDw5yz_h.d.ts +53 -0
- package/dist/client-DPmoKuR9.js +305 -0
- package/dist/client-DsdakibF.js +503 -0
- package/dist/client-Dxg8_DIH.d.ts +71 -0
- package/dist/client-EbhUIhHq.js +53 -0
- package/dist/client-lk6wBu_0.d.ts +48 -0
- package/dist/client-p49ol9pg.d.ts +124 -0
- package/dist/cms/index.d.ts +52 -108
- package/dist/cms/index.js +105 -84
- package/dist/config-CRytOPPl.d.ts +394 -0
- package/dist/config-Cw0a3-C8.js +487 -0
- package/dist/dev/index.d.ts +2 -509
- package/dist/dev/index.js +2740 -2873
- package/dist/eav/coerce.d.ts +3 -1
- package/dist/eav/coerce.js +72 -46
- package/dist/eav/index.d.ts +72 -100
- package/dist/eav/index.js +158 -125
- package/dist/eav/migrate.d.ts +112 -109
- package/dist/eav/migrate.js +230 -196
- package/dist/eav/schema.d.ts +111 -150
- package/dist/eav/schema.js +624 -603
- package/dist/encoding-Bwfm3iaE.js +21 -0
- package/dist/{errors-DIAS8Rsl.d.ts → errors-CRCcErNC.d.ts} +55 -53
- package/dist/feedback/index.d.ts +2 -132
- package/dist/feedback/index.js +3 -5
- package/dist/files/index.d.ts +14 -14
- package/dist/files/index.js +41 -24
- package/dist/http-client-QKUvvirs.js +386 -0
- package/dist/index-DrVaKfhs.d.ts +456 -0
- package/dist/index-Z6OGcurJ.d.ts +169 -0
- package/dist/index.d.ts +6 -221
- package/dist/index.js +119 -70
- package/dist/logout/index.d.ts +109 -0
- package/dist/logout/index.js +264 -0
- package/dist/plans/index.d.ts +2 -236
- package/dist/plans/index.js +3 -5
- package/dist/push/index.d.ts +2 -79
- package/dist/push/index.js +3 -5
- package/dist/query-BvbCiGWb.js +35 -0
- package/dist/react/hooks.d.ts +97 -95
- package/dist/react/hooks.js +742 -356
- package/dist/sse-parser-FMjxM7sY.js +86 -0
- package/dist/terms/index.d.ts +3 -79
- package/dist/terms/index.js +3 -5
- package/dist/testing/index.d.ts +52 -104
- package/dist/testing/index.js +94 -72
- package/dist/types-B-SMkH6s.d.ts +26 -0
- package/dist/types-BXDcoJHG.d.ts +131 -0
- package/dist/types-BrghN2rJ.d.ts +105 -0
- package/dist/types-DjDRszNj.js +11 -0
- package/dist/webhooks/index.d.ts +77 -47
- package/dist/webhooks/index.js +150 -127
- package/docs/api-reference.md +179 -2
- package/docs/dev-server.md +19 -18
- package/docs/errors.md +72 -15
- package/docs/logout.md +166 -0
- package/package.json +10 -5
- package/dist/chunk-2Q654O63.js +0 -350
- package/dist/chunk-F7BXBTZI.js +0 -54
- package/dist/chunk-IJOXTBIE.js +0 -599
- package/dist/chunk-JWXUVQRC.js +0 -157
- package/dist/chunk-L4DHB36G.js +0 -75
- package/dist/chunk-MRQY45U5.js +0 -465
- package/dist/chunk-N5JVE4WX.js +0 -449
- package/dist/chunk-O3PUWIDJ.js +0 -105
- package/dist/chunk-POLKEOYH.js +0 -63
- package/dist/chunk-R5CCGDUH.js +0 -49
- package/dist/chunk-RBHP7IZF.js +0 -96
- package/dist/chunk-REIKXSMY.js +0 -7
- package/dist/chunk-T7YTITRJ.js +0 -112
- package/dist/chunk-V73GORO3.js +0 -81
- package/dist/chunk-VRNBYSWU.js +0 -32
- package/dist/client-BkcO-0C2.d.ts +0 -216
- package/dist/client-CN5_tNOC.d.ts +0 -147
- package/dist/client-DttyeM_h.d.ts +0 -102
- package/dist/config-CtxyJsDR.d.ts +0 -397
- package/dist/typed-client-BxOVIiMU.d.ts +0 -40
- package/dist/types-6E3ZLL9X.d.ts +0 -24
- package/dist/types-DskYLVb8.d.ts +0 -104
- package/dist/types-ckmDDW3N.d.ts +0 -129
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { A as mapHttpStatusToError, n as SDK_VERSION, o as validateConfig, x as ReoptSDKError } from "./config-Cw0a3-C8.js";
|
|
2
|
+
import { t as createManagedAbort } from "./abort--nOBFN4M.js";
|
|
3
|
+
import { t as BaseHttpClient } from "./http-client-QKUvvirs.js";
|
|
4
|
+
import { n as parseSSEStream } from "./sse-parser-FMjxM7sY.js";
|
|
5
|
+
|
|
6
|
+
//#region src/ai/client.ts
|
|
7
|
+
var ReoptAiClient = class {
|
|
8
|
+
http;
|
|
9
|
+
/**
|
|
10
|
+
* Idle (inactivity) timeout for streaming, in ms — the maximum gap allowed
|
|
11
|
+
* *between* SSE chunks, not a deadline on the whole generation. A long but
|
|
12
|
+
* healthy generation keeps resetting this; only a genuine stall aborts.
|
|
13
|
+
*/
|
|
14
|
+
streamIdleTimeout;
|
|
15
|
+
constructor(config) {
|
|
16
|
+
validateConfig(config);
|
|
17
|
+
const pathPrefix = `/api/v1/brandapp/${config.brandappId}/ai`;
|
|
18
|
+
this.http = new BaseHttpClient(config, pathPrefix);
|
|
19
|
+
this.streamIdleTimeout = config.timeout ?? 6e4;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* AI 텍스트 생성 (non-streaming)
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const result = await sdk.ai.complete({
|
|
27
|
+
* messages: [{ role: "user", content: "Hello" }],
|
|
28
|
+
* model: "anthropic/claude-haiku-4.5",
|
|
29
|
+
* maxTokens: 1024,
|
|
30
|
+
* });
|
|
31
|
+
* console.log(result.message.content);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
async complete(options) {
|
|
35
|
+
return (await this.http.fetch("POST", "/chat/completions", {
|
|
36
|
+
model: options.model,
|
|
37
|
+
agentId: options.agentId,
|
|
38
|
+
messages: options.messages,
|
|
39
|
+
maxTokens: options.maxTokens,
|
|
40
|
+
temperature: options.temperature,
|
|
41
|
+
stream: false,
|
|
42
|
+
customerId: options.customerId
|
|
43
|
+
})).data;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* AI 텍스트 생성 (SSE 스트리밍)
|
|
47
|
+
*
|
|
48
|
+
* async generator로 텍스트 청크를 반환합니다.
|
|
49
|
+
* 사용량 메타데이터가 필요하면 `streamWithMetadata()`를 사용하세요.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* for await (const chunk of sdk.ai.stream({
|
|
54
|
+
* messages: [{ role: "user", content: "Hello" }],
|
|
55
|
+
* })) {
|
|
56
|
+
* process.stdout.write(chunk);
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
async *stream(options) {
|
|
61
|
+
const { response, managed, requestId } = await this.fetchSSE(options);
|
|
62
|
+
if (!response.body) {
|
|
63
|
+
managed.cleanup();
|
|
64
|
+
throw new ReoptSDKError("No response body", 0, "STREAM_ERROR");
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
for await (const { event, data } of parseSSEStream(response.body)) {
|
|
68
|
+
managed.kick();
|
|
69
|
+
if (event === "text-delta") yield data;
|
|
70
|
+
else if (event === "error") {
|
|
71
|
+
const ctx = { requestId };
|
|
72
|
+
try {
|
|
73
|
+
const err = JSON.parse(data);
|
|
74
|
+
if (typeof err.status === "number") throw mapHttpStatusToError(err.status, err.code, err.message, ctx);
|
|
75
|
+
throw new ReoptSDKError(err.message ?? "Stream error", 0, err.code ?? "STREAM_ERROR", ctx);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
if (e instanceof ReoptSDKError) throw e;
|
|
78
|
+
throw new ReoptSDKError(data, 0, "STREAM_ERROR", ctx);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
} catch (e) {
|
|
83
|
+
throw mapStreamError(e, managed);
|
|
84
|
+
} finally {
|
|
85
|
+
managed.cleanup();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* AI 텍스트 생성 (SSE 스트리밍 + 메타데이터)
|
|
90
|
+
*
|
|
91
|
+
* 텍스트 청크와 함께 최종 사용량/크레딧 메타데이터를 반환합니다.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* const { textStream, metadata } = sdk.ai.streamWithMetadata({
|
|
96
|
+
* messages: [{ role: "user", content: "Hello" }],
|
|
97
|
+
* });
|
|
98
|
+
*
|
|
99
|
+
* let text = "";
|
|
100
|
+
* for await (const chunk of textStream) {
|
|
101
|
+
* text += chunk;
|
|
102
|
+
* }
|
|
103
|
+
*
|
|
104
|
+
* const meta = await metadata;
|
|
105
|
+
* console.log(`사용 크레딧: ${meta?.usage.creditCost}`);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
streamWithMetadata(options) {
|
|
109
|
+
let resolveMeta;
|
|
110
|
+
const metadata = new Promise((r) => {
|
|
111
|
+
resolveMeta = r;
|
|
112
|
+
});
|
|
113
|
+
let settled = false;
|
|
114
|
+
const settle = (v) => {
|
|
115
|
+
if (settled) return;
|
|
116
|
+
settled = true;
|
|
117
|
+
resolveMeta(v);
|
|
118
|
+
};
|
|
119
|
+
const self = this;
|
|
120
|
+
async function* gen() {
|
|
121
|
+
const { response, managed, requestId } = await self.fetchSSE(options);
|
|
122
|
+
if (!response.body) {
|
|
123
|
+
managed.cleanup();
|
|
124
|
+
settle(null);
|
|
125
|
+
throw new ReoptSDKError("No response body", 0, "STREAM_ERROR");
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
for await (const { event, data } of parseSSEStream(response.body)) {
|
|
129
|
+
managed.kick();
|
|
130
|
+
if (event === "text-delta") yield data;
|
|
131
|
+
else if (event === "done") try {
|
|
132
|
+
settle(JSON.parse(data));
|
|
133
|
+
} catch {
|
|
134
|
+
settle(null);
|
|
135
|
+
}
|
|
136
|
+
else if (event === "error") {
|
|
137
|
+
const ctx = { requestId };
|
|
138
|
+
try {
|
|
139
|
+
const err = JSON.parse(data);
|
|
140
|
+
if (typeof err.status === "number") throw mapHttpStatusToError(err.status, err.code, err.message, ctx);
|
|
141
|
+
throw new ReoptSDKError(err.message ?? "Stream error", 0, err.code ?? "STREAM_ERROR", ctx);
|
|
142
|
+
} catch (e) {
|
|
143
|
+
if (e instanceof ReoptSDKError) throw e;
|
|
144
|
+
throw new ReoptSDKError(data, 0, "STREAM_ERROR", ctx);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
} catch (e) {
|
|
149
|
+
throw mapStreamError(e, managed);
|
|
150
|
+
} finally {
|
|
151
|
+
settle(null);
|
|
152
|
+
managed.cleanup();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
textStream: gen(),
|
|
157
|
+
metadata
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* 이미지 생성
|
|
162
|
+
*
|
|
163
|
+
* BrandApp의 AI 크레딧으로 이미지를 생성합니다.
|
|
164
|
+
* 생성된 이미지는 자동으로 Vercel Blob에 저장되고 URL이 반환됩니다.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* const image = await sdk.ai.generateImage({
|
|
169
|
+
* prompt: "브랜드 배너 이미지",
|
|
170
|
+
* style: "minimalist",
|
|
171
|
+
* aspectRatio: "16:9",
|
|
172
|
+
* });
|
|
173
|
+
* console.log(image.url); // https://...blob.vercel-storage.com/...
|
|
174
|
+
* console.log(image.size); // 12345 (bytes)
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
async generateImage(options) {
|
|
178
|
+
return (await this.http.fetch("POST", "/images/generate", {
|
|
179
|
+
prompt: options.prompt,
|
|
180
|
+
negativePrompt: options.negativePrompt,
|
|
181
|
+
style: options.style,
|
|
182
|
+
aspectRatio: options.aspectRatio ?? "1:1",
|
|
183
|
+
model: options.model,
|
|
184
|
+
customerId: options.customerId
|
|
185
|
+
})).data;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* 크레딧 잔액 조회
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* const credits = await sdk.ai.credits();
|
|
193
|
+
* console.log(`${credits.balance} / ${credits.limit} (${credits.status})`);
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
async credits() {
|
|
197
|
+
return (await this.http.fetch("GET", "/credits")).data;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* 사용 가능 모델 목록 조회
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```ts
|
|
204
|
+
* const models = await sdk.ai.models();
|
|
205
|
+
* models.forEach(m => console.log(`${m.id} (${m.tierLabel})`));
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
async models() {
|
|
209
|
+
return (await this.http.fetch("GET", "/models")).data;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* 사용 가능한 커스텀 에이전트 목록 조회
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* const agents = await sdk.ai.agents();
|
|
217
|
+
* for (const agent of agents) {
|
|
218
|
+
* console.log(`${agent.name}: ${agent.description}`);
|
|
219
|
+
* }
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
async agents() {
|
|
223
|
+
return (await this.http.fetch("GET", "/agents")).data;
|
|
224
|
+
}
|
|
225
|
+
async fetchSSE(options) {
|
|
226
|
+
const url = `${this.http.requestBaseUrl}/chat/completions`;
|
|
227
|
+
const requestId = globalThis.crypto?.randomUUID?.() ?? `sdk-${"3.4.0"}-${url.length}`;
|
|
228
|
+
const ctx = {
|
|
229
|
+
method: "POST",
|
|
230
|
+
url,
|
|
231
|
+
requestId
|
|
232
|
+
};
|
|
233
|
+
const maxConnectAttempts = 2;
|
|
234
|
+
let lastConnectError;
|
|
235
|
+
for (let attempt = 0; attempt < maxConnectAttempts; attempt++) {
|
|
236
|
+
const managed = createManagedAbort({
|
|
237
|
+
timeoutMs: this.streamIdleTimeout,
|
|
238
|
+
external: options.signal,
|
|
239
|
+
idle: true
|
|
240
|
+
});
|
|
241
|
+
try {
|
|
242
|
+
const response = await globalThis.fetch(url, {
|
|
243
|
+
method: "POST",
|
|
244
|
+
headers: {
|
|
245
|
+
Authorization: this.http.authorizationHeader,
|
|
246
|
+
"Content-Type": "application/json",
|
|
247
|
+
Accept: "text/event-stream",
|
|
248
|
+
"X-SDK-Version": `brandapp-sdk/${SDK_VERSION}`,
|
|
249
|
+
"X-Request-Id": requestId,
|
|
250
|
+
"Idempotency-Key": requestId
|
|
251
|
+
},
|
|
252
|
+
body: JSON.stringify({
|
|
253
|
+
model: options.model,
|
|
254
|
+
agentId: options.agentId,
|
|
255
|
+
messages: options.messages,
|
|
256
|
+
maxTokens: options.maxTokens,
|
|
257
|
+
temperature: options.temperature,
|
|
258
|
+
stream: true,
|
|
259
|
+
customerId: options.customerId
|
|
260
|
+
}),
|
|
261
|
+
signal: managed.signal
|
|
262
|
+
});
|
|
263
|
+
if (!response.ok) {
|
|
264
|
+
const err = (await response.json().catch(() => ({})))?.error ?? {};
|
|
265
|
+
managed.cleanup();
|
|
266
|
+
throw mapHttpStatusToError(response.status, err.code, err.message ?? `HTTP ${response.status}`, ctx);
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
response,
|
|
270
|
+
managed,
|
|
271
|
+
requestId
|
|
272
|
+
};
|
|
273
|
+
} catch (e) {
|
|
274
|
+
managed.cleanup();
|
|
275
|
+
if (e instanceof ReoptSDKError) throw e;
|
|
276
|
+
if (managed.timedOut || options.signal?.aborted) throw mapStreamError(e, managed);
|
|
277
|
+
lastConnectError = e;
|
|
278
|
+
if (attempt < maxConnectAttempts - 1) continue;
|
|
279
|
+
throw mapStreamError(e, managed);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
throw mapStreamError(lastConnectError, void 0);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* Map a raw streaming error to a `ReoptSDKError`. An abort is disambiguated via
|
|
287
|
+
* `managed.timedOut`: our idle timeout → `TIMEOUT` (408); a caller-initiated
|
|
288
|
+
* cancel (external signal) → `CANCELLED` (0). Other errors pass through so the
|
|
289
|
+
* caller sees the same structured shape as the rest of the SDK.
|
|
290
|
+
*/
|
|
291
|
+
function mapStreamError(e, managed) {
|
|
292
|
+
if (e instanceof ReoptSDKError) return e;
|
|
293
|
+
if (e instanceof Error && e.name === "AbortError") {
|
|
294
|
+
if (managed?.timedOut) return new ReoptSDKError("Stream request timed out", 408, "TIMEOUT");
|
|
295
|
+
return new ReoptSDKError("Stream cancelled by caller", 0, "CANCELLED");
|
|
296
|
+
}
|
|
297
|
+
return e;
|
|
298
|
+
}
|
|
299
|
+
function createReoptAiClient(config) {
|
|
300
|
+
return new ReoptAiClient(config);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
//#endregion
|
|
304
|
+
export { createReoptAiClient as n, ReoptAiClient as t };
|
|
305
|
+
//# sourceMappingURL=client-DPmoKuR9.js.map
|