@reopt-ai/brandapp-sdk 3.3.0 → 3.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/CHANGELOG.md +115 -0
- package/README.md +10 -1
- package/dist/abort--nOBFN4M.js +50 -0
- package/dist/ai/index.d.ts +2 -314
- package/dist/ai/index.js +3 -8
- package/dist/ai-provider/index.d.ts +79 -163
- package/dist/ai-provider/index.js +752 -685
- package/dist/auth/index.d.ts +27 -27
- package/dist/auth/index.js +41 -34
- 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 -144
- package/dist/client-61ldOHMz.js +503 -0
- package/dist/client-7PCoxVhZ.js +28 -0
- package/dist/client-B7rZQ8Zi.d.ts +272 -0
- package/dist/client-BGGd_cpV.d.ts +103 -0
- package/dist/client-BoIuyx4S.js +273 -0
- package/dist/client-BruP5_nU.d.ts +147 -0
- package/dist/client-BxtZt405.js +305 -0
- package/dist/client-ByN3EQdk.js +83 -0
- package/dist/client-CAghoGD_.js +53 -0
- package/dist/client-C_pHsPlj.js +81 -0
- package/dist/client-D0eBxh8j.d.ts +284 -0
- package/dist/client-D6gs61w8.d.ts +53 -0
- package/dist/client-DDw5yz_h.d.ts +53 -0
- package/dist/client-Dxg8_DIH.d.ts +71 -0
- package/dist/client-aMR4CRB8.d.ts +211 -0
- package/dist/client-lk6wBu_0.d.ts +48 -0
- package/dist/client-wEVKLdly.js +55 -0
- package/dist/client-zF1RG2uA.js +86 -0
- package/dist/cms/index.d.ts +52 -108
- package/dist/cms/index.js +103 -86
- package/dist/config-CRytOPPl.d.ts +394 -0
- package/dist/config-aml9oQpX.js +487 -0
- package/dist/dev/index.d.ts +2 -528
- package/dist/dev/index.js +3047 -2967
- 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 -126
- 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-BjDFIyA6.d.ts → errors-CRCcErNC.d.ts} +55 -53
- package/dist/feedback/index.d.ts +2 -132
- package/dist/feedback/index.js +3 -6
- package/dist/files/index.d.ts +14 -14
- package/dist/files/index.js +41 -25
- package/dist/http-client-BZc2mngq.js +386 -0
- package/dist/index-1j_738qk.d.ts +470 -0
- package/dist/index-CeOLGdyL.d.ts +169 -0
- package/dist/index.d.ts +6 -230
- package/dist/index.js +119 -71
- package/dist/logout/index.d.ts +56 -53
- package/dist/logout/index.js +232 -289
- package/dist/plans/index.d.ts +2 -236
- package/dist/plans/index.js +3 -6
- package/dist/push/index.d.ts +2 -79
- package/dist/push/index.js +3 -6
- package/dist/query-xWqtfkvR.js +35 -0
- package/dist/react/hooks.d.ts +157 -100
- package/dist/react/hooks.js +862 -406
- package/dist/sse-parser-FMjxM7sY.js +86 -0
- package/dist/terms/index.d.ts +3 -79
- package/dist/terms/index.js +3 -6
- 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 -50
- package/dist/webhooks/index.js +150 -127
- package/docs/api-reference.md +121 -8
- package/docs/errors.md +19 -0
- package/docs/files.md +165 -7
- package/package.json +7 -6
- package/dist/chunk-2LSCQHAU.js +0 -21
- package/dist/chunk-4U4ZPPL4.js +0 -599
- package/dist/chunk-55KHY5GH.js +0 -96
- package/dist/chunk-C5VTRZWX.js +0 -458
- package/dist/chunk-F7BXBTZI.js +0 -54
- package/dist/chunk-FJUCWXX3.js +0 -350
- package/dist/chunk-H33OTQEN.js +0 -112
- package/dist/chunk-L4DHB36G.js +0 -75
- package/dist/chunk-OG7R3UAR.js +0 -105
- package/dist/chunk-PF24XU54.js +0 -32
- package/dist/chunk-QN3QD67K.js +0 -49
- package/dist/chunk-REIKXSMY.js +0 -7
- package/dist/chunk-UGBBXCZE.js +0 -157
- package/dist/chunk-UVT2E6KD.js +0 -81
- package/dist/chunk-YPLT3RFL.js +0 -63
- package/dist/chunk-YTKSAWV2.js +0 -463
- 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,147 @@
|
|
|
1
|
+
import { n as ReoptSDKConfig } from "./config-CRytOPPl.js";
|
|
2
|
+
//#region src/feedback/types.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Feedback processing status. `reopened` means the customer replied after the
|
|
5
|
+
* staff had answered — the thread is waiting on the workspace again.
|
|
6
|
+
*/
|
|
7
|
+
type FeedbackStatus = "new" | "in_progress" | "responded" | "reopened" | "archived";
|
|
8
|
+
/** Who wrote a message in the feedback thread. */
|
|
9
|
+
type FeedbackReplyAuthor = "staff" | "customer";
|
|
10
|
+
/**
|
|
11
|
+
* A message in the feedback thread — either a workspace staff reply or the
|
|
12
|
+
* customer's own follow-up. Only public fields are exposed — the responding
|
|
13
|
+
* staff identity is never included.
|
|
14
|
+
*/
|
|
15
|
+
type FeedbackReply = {
|
|
16
|
+
id: string;
|
|
17
|
+
content: string;
|
|
18
|
+
author: FeedbackReplyAuthor;
|
|
19
|
+
/**
|
|
20
|
+
* The customer's usefulness rating of a staff reply
|
|
21
|
+
* (true = helpful, false = not helpful, null = not rated / customer message).
|
|
22
|
+
*/
|
|
23
|
+
helpful: boolean | null;
|
|
24
|
+
/** ISO datetime */
|
|
25
|
+
createdAt: string;
|
|
26
|
+
};
|
|
27
|
+
/** A customer feedback item as returned by the Brandapp Feedback API. */
|
|
28
|
+
type Feedback = {
|
|
29
|
+
id: string;
|
|
30
|
+
title: string | null;
|
|
31
|
+
content: string;
|
|
32
|
+
category: string | null;
|
|
33
|
+
/** 1–5, when the feedback carried a rating */
|
|
34
|
+
rating: number | null;
|
|
35
|
+
status: FeedbackStatus;
|
|
36
|
+
/** Linked reopt Customer id (null = anonymous) */
|
|
37
|
+
customerId: string | null;
|
|
38
|
+
/**
|
|
39
|
+
* Number of **staff** replies — the customer's own follow-ups are not counted,
|
|
40
|
+
* so `replyCount > 0` still means "the workspace has answered".
|
|
41
|
+
*/
|
|
42
|
+
replyCount: number;
|
|
43
|
+
/** ISO datetime */
|
|
44
|
+
createdAt: string;
|
|
45
|
+
};
|
|
46
|
+
/** Feedback detail including the reply thread. */
|
|
47
|
+
type FeedbackDetail = Feedback & {
|
|
48
|
+
replies: FeedbackReply[];
|
|
49
|
+
};
|
|
50
|
+
type CreateFeedbackInput = {
|
|
51
|
+
/** Feedback body (1–8000 chars). */
|
|
52
|
+
content: string;
|
|
53
|
+
title?: string;
|
|
54
|
+
category?: string;
|
|
55
|
+
/** 1–5 */
|
|
56
|
+
rating?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Customer id to attribute the feedback to (app-credential path only —
|
|
59
|
+
* the server verifies the customer is linked to this brandapp). Ignored
|
|
60
|
+
* on the `me.*` path where the token's customer is used.
|
|
61
|
+
*/
|
|
62
|
+
customerId?: string;
|
|
63
|
+
/** Free-form metadata (max 4000 chars serialized). */
|
|
64
|
+
metadata?: Record<string, unknown>;
|
|
65
|
+
};
|
|
66
|
+
type ListFeedbackQuery = {
|
|
67
|
+
status?: FeedbackStatus;
|
|
68
|
+
/** Filter by linked Customer id (app-credential path only). */
|
|
69
|
+
customerId?: string;
|
|
70
|
+
/** 1-based page (default 1). */
|
|
71
|
+
page?: number;
|
|
72
|
+
/** Page size 1–100 (default 20). */
|
|
73
|
+
limit?: number;
|
|
74
|
+
};
|
|
75
|
+
type FeedbackListMeta = {
|
|
76
|
+
page: number;
|
|
77
|
+
limit: number;
|
|
78
|
+
total: number;
|
|
79
|
+
};
|
|
80
|
+
type FeedbackListResult = {
|
|
81
|
+
feedbacks: Feedback[];
|
|
82
|
+
meta: FeedbackListMeta;
|
|
83
|
+
};
|
|
84
|
+
type CreateFeedbackResult = {
|
|
85
|
+
id: string;
|
|
86
|
+
};
|
|
87
|
+
type CreateFeedbackReplyResult = {
|
|
88
|
+
id: string;
|
|
89
|
+
/**
|
|
90
|
+
* Feedback status after the reply. Answered threads flip to `reopened`
|
|
91
|
+
* so the workspace sees the customer is still waiting.
|
|
92
|
+
*/
|
|
93
|
+
feedbackStatus: FeedbackStatus;
|
|
94
|
+
/** ISO datetime */
|
|
95
|
+
createdAt: string;
|
|
96
|
+
};
|
|
97
|
+
type RateFeedbackReplyResult = {
|
|
98
|
+
id: string;
|
|
99
|
+
helpful: boolean | null;
|
|
100
|
+
};
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/feedback/client.d.ts
|
|
103
|
+
declare class ReoptFeedbackClient {
|
|
104
|
+
private readonly http;
|
|
105
|
+
constructor(config: ReoptSDKConfig);
|
|
106
|
+
/**
|
|
107
|
+
* Create a feedback with app credentials (server-to-server collection).
|
|
108
|
+
* Pass `customerId` to attribute it to a customer linked to this brandapp.
|
|
109
|
+
*/
|
|
110
|
+
create(input: CreateFeedbackInput): Promise<CreateFeedbackResult>;
|
|
111
|
+
/** List feedback this brandapp collected (app credentials). */
|
|
112
|
+
list(query?: ListFeedbackQuery): Promise<FeedbackListResult>;
|
|
113
|
+
/** Fetch one feedback with its reply thread (app credentials). */
|
|
114
|
+
get(feedbackId: string): Promise<FeedbackDetail>;
|
|
115
|
+
/** End-user surface — requires the signed-in user's OAuth access token. */
|
|
116
|
+
readonly me: {
|
|
117
|
+
/**
|
|
118
|
+
* Create a feedback as the signed-in user. The server resolves the
|
|
119
|
+
* token's linked customer; unlinked users get 403 `LINK_REQUIRED`
|
|
120
|
+
* (call `sdk.auth.linkCurrentUser` first).
|
|
121
|
+
*/
|
|
122
|
+
create: (input: Omit<CreateFeedbackInput, "customerId">, accessToken: string) => Promise<CreateFeedbackResult>;
|
|
123
|
+
/**
|
|
124
|
+
* List the signed-in user's own feedback (all collection sources —
|
|
125
|
+
* brand form submissions included).
|
|
126
|
+
*/
|
|
127
|
+
list: (accessToken: string, query?: Omit<ListFeedbackQuery, "customerId">) => Promise<FeedbackListResult>;
|
|
128
|
+
/** Fetch one of the signed-in user's feedback with its thread. */
|
|
129
|
+
get: (feedbackId: string, accessToken: string) => Promise<FeedbackDetail>;
|
|
130
|
+
/**
|
|
131
|
+
* Reply to a staff answer on the signed-in user's own feedback, continuing
|
|
132
|
+
* the thread instead of filing a new feedback. An already-answered feedback
|
|
133
|
+
* flips back to `reopened` and the workspace is notified.
|
|
134
|
+
*/
|
|
135
|
+
reply: (feedbackId: string, content: string, accessToken: string) => Promise<CreateFeedbackReplyResult>;
|
|
136
|
+
/**
|
|
137
|
+
* Rate a staff reply's usefulness (`true` helpful / `false` not helpful /
|
|
138
|
+
* `null` to clear). Rating alone does not reopen the feedback — send a
|
|
139
|
+
* `reply` when the customer still needs something.
|
|
140
|
+
*/
|
|
141
|
+
rateReply: (feedbackId: string, replyId: string, helpful: boolean | null, accessToken: string) => Promise<RateFeedbackReplyResult>;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
declare function createReoptFeedbackClient(config: ReoptSDKConfig): ReoptFeedbackClient;
|
|
145
|
+
//#endregion
|
|
146
|
+
export { CreateFeedbackResult as a, FeedbackListMeta as c, FeedbackReplyAuthor as d, FeedbackStatus as f, CreateFeedbackReplyResult as i, FeedbackListResult as l, RateFeedbackReplyResult as m, createReoptFeedbackClient as n, Feedback as o, ListFeedbackQuery as p, CreateFeedbackInput as r, FeedbackDetail as s, ReoptFeedbackClient as t, FeedbackReply as u };
|
|
147
|
+
//# sourceMappingURL=client-BruP5_nU.d.ts.map
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { A as mapHttpStatusToError, n as SDK_VERSION, o as validateConfig, x as ReoptSDKError } from "./config-aml9oQpX.js";
|
|
2
|
+
import { t as createManagedAbort } from "./abort--nOBFN4M.js";
|
|
3
|
+
import { t as BaseHttpClient } from "./http-client-BZc2mngq.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.5.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-BxtZt405.js.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { t as BaseHttpClient } from "./http-client-BZc2mngq.js";
|
|
2
|
+
|
|
3
|
+
//#region src/terms/client.ts
|
|
4
|
+
function unwrap(body) {
|
|
5
|
+
if (body && typeof body === "object" && "data" in body) {
|
|
6
|
+
const withData = body;
|
|
7
|
+
if (withData.data !== void 0) return withData.data;
|
|
8
|
+
}
|
|
9
|
+
return body;
|
|
10
|
+
}
|
|
11
|
+
function isListOptions(value) {
|
|
12
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
13
|
+
}
|
|
14
|
+
function buildListQuery(options) {
|
|
15
|
+
const params = new URLSearchParams();
|
|
16
|
+
if (options.country) params.set("country", options.country);
|
|
17
|
+
if (options.locale) params.set("locale", options.locale);
|
|
18
|
+
if (options.jurisdiction) params.set("jurisdiction", options.jurisdiction);
|
|
19
|
+
const qs = params.toString();
|
|
20
|
+
return qs ? `?${qs}` : "";
|
|
21
|
+
}
|
|
22
|
+
var ReoptTermsClient = class {
|
|
23
|
+
http;
|
|
24
|
+
constructor(config) {
|
|
25
|
+
this.http = new BaseHttpClient(config, `/api/v1/brandapp/${config.brandappId}/terms`);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* List active terms for this Brandapp with their currently-published
|
|
29
|
+
* version. Works with either Basic Auth (default) or Bearer Auth — when
|
|
30
|
+
* called from a server handler that has the user's access token, pass
|
|
31
|
+
* `accessToken` to avoid sending app credentials.
|
|
32
|
+
*
|
|
33
|
+
* Accepts either an `accessToken` string (legacy) or an options object
|
|
34
|
+
* (`country`/`locale`/`jurisdiction`/`accessToken`) for jurisdiction-aware
|
|
35
|
+
* matching. When `country` / `locale` are omitted, the server falls back to
|
|
36
|
+
* request headers (`x-vercel-ip-country`, `Accept-Language`).
|
|
37
|
+
*
|
|
38
|
+
* Returns the matched terms array. For matching metadata
|
|
39
|
+
* (jurisdiction, locale, source) use {@link listWithMeta}.
|
|
40
|
+
*/
|
|
41
|
+
async list(optionsOrToken) {
|
|
42
|
+
return (await this.listWithMeta(optionsOrToken)).terms;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Same as {@link list} but returns the full {@link TermsListResponse} including
|
|
46
|
+
* matched jurisdiction, country and locale — useful for displaying "약관이
|
|
47
|
+
* 어떤 국가 기준으로 적용됐는지" hint in the signup UX.
|
|
48
|
+
*/
|
|
49
|
+
async listWithMeta(optionsOrToken) {
|
|
50
|
+
const options = isListOptions(optionsOrToken) ? optionsOrToken : optionsOrToken ? { accessToken: optionsOrToken } : {};
|
|
51
|
+
const path = buildListQuery(options) || "";
|
|
52
|
+
return unwrap(await this.http.fetch("GET", path, void 0, options.accessToken ? { bearerToken: options.accessToken } : void 0));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Fetch the consent history (granted / withdrawn / pendingReConsent) for
|
|
56
|
+
* the OAuth user represented by `accessToken`.
|
|
57
|
+
*/
|
|
58
|
+
async listMyConsents(accessToken) {
|
|
59
|
+
return unwrap(await this.http.fetch("GET", "/me/consents", void 0, { bearerToken: accessToken }));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Record consent for one or more terms versions. The server rejects the
|
|
63
|
+
* call with `REQUIRED_NOT_CONSENTED` (422) if any required term is missing
|
|
64
|
+
* or marked as `consented: false`.
|
|
65
|
+
*/
|
|
66
|
+
async consent(input, accessToken) {
|
|
67
|
+
return unwrap(await this.http.fetch("POST", "/me/consents", input, { bearerToken: accessToken }));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Withdraw a previously-granted consent. The server returns 409 for
|
|
71
|
+
* required terms or already-withdrawn records.
|
|
72
|
+
*/
|
|
73
|
+
async withdraw(consentId, accessToken) {
|
|
74
|
+
return unwrap(await this.http.fetch("DELETE", `/me/consents/${encodeURIComponent(consentId)}`, void 0, { bearerToken: accessToken }));
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
function createReoptTermsClient(config) {
|
|
78
|
+
return new ReoptTermsClient(config);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//#endregion
|
|
82
|
+
export { createReoptTermsClient as n, ReoptTermsClient as t };
|
|
83
|
+
//# sourceMappingURL=client-ByN3EQdk.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { t as BaseHttpClient } from "./http-client-BZc2mngq.js";
|
|
2
|
+
|
|
3
|
+
//#region src/auth/client.ts
|
|
4
|
+
function unwrap(body) {
|
|
5
|
+
if (body && typeof body === "object" && "data" in body) {
|
|
6
|
+
const withData = body;
|
|
7
|
+
if (withData.data !== void 0) return withData.data;
|
|
8
|
+
}
|
|
9
|
+
return body;
|
|
10
|
+
}
|
|
11
|
+
var ReoptAuthClient = class {
|
|
12
|
+
/**
|
|
13
|
+
* Root client for `/api/auth/*` endpoints (OIDC userinfo, etc). Pinned to
|
|
14
|
+
* the id server because Better Auth's handler is only mounted there.
|
|
15
|
+
*/
|
|
16
|
+
rootHttp;
|
|
17
|
+
/** Brandapp-scoped client — prefixed for per-brandapp endpoints. */
|
|
18
|
+
brandappHttp;
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.rootHttp = new BaseHttpClient(config, "", { useIdServer: true });
|
|
21
|
+
this.brandappHttp = new BaseHttpClient(config, `/api/v1/brandapp/${config.brandappId}`);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Upsert the Customer ↔ reoptUser link for the OAuth user represented by
|
|
25
|
+
* the supplied access token.
|
|
26
|
+
*/
|
|
27
|
+
async linkCurrentUser(accessToken) {
|
|
28
|
+
return unwrap(await this.brandappHttp.fetch("POST", "/external-auth", {}, { bearerToken: accessToken }));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Soft-withdraw the current OAuth user from this Brandapp: BrandappCustomer
|
|
32
|
+
* flips to `churned`, the Brand↔Customer junction is removed, all
|
|
33
|
+
* terms-consents move to `withdrawn`, and any Stripe subscription is
|
|
34
|
+
* cancelled. The Customer record itself is retained so re-linking later
|
|
35
|
+
* restores the same customerId (see `linkCurrentUser`).
|
|
36
|
+
*/
|
|
37
|
+
async withdrawCurrentUser(accessToken) {
|
|
38
|
+
return unwrap(await this.brandappHttp.fetch("DELETE", "/external-auth", void 0, { bearerToken: accessToken }));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Fetch the OIDC userinfo claims for the supplied access token.
|
|
42
|
+
*/
|
|
43
|
+
async getUserInfo(accessToken) {
|
|
44
|
+
return this.rootHttp.fetch("GET", "/api/auth/oauth2/userinfo", void 0, { bearerToken: accessToken });
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
function createReoptAuthClient(config) {
|
|
48
|
+
return new ReoptAuthClient(config);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
export { createReoptAuthClient as n, ReoptAuthClient as t };
|
|
53
|
+
//# sourceMappingURL=client-CAghoGD_.js.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { t as BaseHttpClient } from "./http-client-BZc2mngq.js";
|
|
2
|
+
|
|
3
|
+
//#region src/plans/client.ts
|
|
4
|
+
function unwrap(body) {
|
|
5
|
+
if (body && typeof body === "object" && "data" in body) {
|
|
6
|
+
const withData = body;
|
|
7
|
+
if (withData.data !== void 0) return withData.data;
|
|
8
|
+
}
|
|
9
|
+
return body;
|
|
10
|
+
}
|
|
11
|
+
var ReoptPlansClient = class {
|
|
12
|
+
http;
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.http = new BaseHttpClient(config, `/api/v1/brandapp/${config.brandappId}/plans`);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* List active plans for this Brandapp (the customer-facing catalog). Works
|
|
18
|
+
* with either Basic Auth (default) or Bearer Auth — pass `accessToken` when
|
|
19
|
+
* calling from a handler that already has the customer's OAuth token to avoid
|
|
20
|
+
* sending app credentials.
|
|
21
|
+
*/
|
|
22
|
+
async list(accessToken) {
|
|
23
|
+
return unwrap(await this.http.fetch("GET", "", void 0, accessToken ? { bearerToken: accessToken } : void 0));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Fetch the current plan / entitlement for the OAuth customer represented by
|
|
27
|
+
* `accessToken`. Returns `null` when the customer has no active plan.
|
|
28
|
+
*/
|
|
29
|
+
async getMyPlan(accessToken) {
|
|
30
|
+
return unwrap(await this.http.fetch("GET", "/me/plan", void 0, { bearerToken: accessToken }));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Start a hosted checkout to subscribe the current customer (identified by
|
|
34
|
+
* `accessToken`) to `input.planId`, then redirect the browser to the returned
|
|
35
|
+
* `checkoutUrl`. That URL is an order-review page on id.reopt.ai showing the
|
|
36
|
+
* server-truth plan details (price, features, renewal terms) and collecting
|
|
37
|
+
* any required-terms consent **before** payment, then returning to your
|
|
38
|
+
* `successUrl` / `cancelUrl`.
|
|
39
|
+
*
|
|
40
|
+
* Missing required-terms consent no longer fails this call — consent is
|
|
41
|
+
* collected on the hosted order-review page. Pre-collecting via `sdk.terms`
|
|
42
|
+
* still works (the page skips already-consented terms), and
|
|
43
|
+
* `RequiredTermsError` remains for backward compatibility with older
|
|
44
|
+
* servers.
|
|
45
|
+
*
|
|
46
|
+
* @throws {ReoptSDKError} `LIVE_MODE_UNSUPPORTED` (409) when the Brandapp is
|
|
47
|
+
* configured for live **Toss** payments and the plan is priced (use the
|
|
48
|
+
* brandfront checkout). Live Paddle is supported since 3.4.
|
|
49
|
+
*/
|
|
50
|
+
async createCheckout(input, accessToken) {
|
|
51
|
+
return unwrap(await this.http.fetch("POST", "/me/checkout", input, { bearerToken: accessToken }));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Poll a checkout session by id (e.g. on your return page) to read its
|
|
55
|
+
* `status` — `completed` means the subscription is active. `checkoutUrl` is
|
|
56
|
+
* `null` here; use the URL from {@link createCheckout} to re-redirect.
|
|
57
|
+
*/
|
|
58
|
+
async getCheckout(checkoutId, accessToken) {
|
|
59
|
+
return unwrap(await this.http.fetch("GET", `/me/checkout/${encodeURIComponent(checkoutId)}`, void 0, { bearerToken: accessToken }));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Cancel the current customer's active subscription — sandbox and live
|
|
63
|
+
* (Paddle/Toss/IAP) alike since 3.4. Access is kept until the paid period
|
|
64
|
+
* ends (the billing state becomes `canceled`, `accessUntil` says until when).
|
|
65
|
+
*
|
|
66
|
+
* The local subscription is settled first, so the next recurring charge is
|
|
67
|
+
* always stopped; the provider-side cancellation is best-effort and reported
|
|
68
|
+
* through `providerCanceled`. Apple/Google subscriptions are canceled in the
|
|
69
|
+
* store, so no remote call is made for those.
|
|
70
|
+
*/
|
|
71
|
+
async cancel(accessToken) {
|
|
72
|
+
return unwrap(await this.http.fetch("POST", "/me/subscription/cancel", {}, { bearerToken: accessToken }));
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
function createReoptPlansClient(config) {
|
|
76
|
+
return new ReoptPlansClient(config);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
export { createReoptPlansClient as n, ReoptPlansClient as t };
|
|
81
|
+
//# sourceMappingURL=client-C_pHsPlj.js.map
|