@reopt-ai/brandapp-sdk 4.6.0 → 4.7.0-rc.10
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 +275 -1
- package/README.md +194 -72
- package/dist/ai/index.d.ts +52 -2
- package/dist/ai/index.js +32 -2
- package/dist/ai-provider/index.d.ts +58 -6
- package/dist/ai-provider/index.js +456 -119
- package/dist/analytics/index.d.ts +1 -1
- package/dist/analytics/index.js +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.js +1 -1
- package/dist/better-auth/client.d.ts +7 -2
- package/dist/better-auth/client.js +5 -4
- package/dist/better-auth/index.d.ts +39 -7
- package/dist/better-auth/index.js +47 -12
- package/dist/{client-DCqp0Bis.js → client-B281w6RL.js} +2 -2
- package/dist/{client-Bfutv3LK.d.ts → client-BL-Ljwki.d.ts} +2 -2
- package/dist/client-BPcoDnOd.js +194 -0
- package/dist/{client-BSW0Ncjj.d.ts → client-BbmslwWV.d.ts} +2 -2
- package/dist/{client-Ce0gs5Ma.js → client-Brv0KsDM.js} +2 -2
- package/dist/{client-eDd4aWDs.js → client-BxrWT0mi.js} +2 -2
- package/dist/client-C7z5-izC.js +745 -0
- package/dist/{client-IUSZDJio.d.ts → client-CD6uK0dA.d.ts} +87 -6
- package/dist/client-CGy4Z0JO.js +146 -0
- package/dist/{client-7I-mz3Dw.d.ts → client-CJFsLk3_.d.ts} +2 -2
- package/dist/{client-C6OXGMMV.d.ts → client-CJRjPSf7.d.ts} +2 -2
- package/dist/{client-D1AFtJRw.d.ts → client-CP1Jgq4R.d.ts} +139 -13
- package/dist/{client-FM6_YJbr.js → client-CmV48bW0.js} +3 -3
- package/dist/{client-tJq0U_jn.js → client-D8d3xsYm.js} +51 -12
- package/dist/{client-C2xE9HGZ.js → client-D97Ylva1.js} +40 -6
- package/dist/{client-COKDtHO9.d.ts → client-DF-tOyrY.d.ts} +2 -2
- package/dist/client-DlgVNj3w.d.ts +72 -0
- package/dist/{client-BzAgabAs.js → client-Dv7WwJr-.js} +2 -2
- package/dist/{client-yKeRJnIB.d.ts → client-Dwf6UuGH.d.ts} +2 -2
- package/dist/{client-Dmvtr1nS.d.ts → client-NUhpPkl2.d.ts} +2 -2
- package/dist/{client-DjLhTNsZ.js → client-ey80gKM_.js} +11 -5
- package/dist/{client-DeC127BD.js → client-m4e-HwMX.js} +2 -2
- package/dist/client-seu-0lbh.d.ts +654 -0
- package/dist/{client-CniCGdmi.d.ts → client-wNzcgEJu.d.ts} +2 -2
- package/dist/cms/index.d.ts +1 -1
- package/dist/cms/index.js +1 -1
- package/dist/{config-D3SblxWt.d.ts → config-BGT9h1OW.d.ts} +27 -10
- package/dist/{config-BeOelISH.js → config-DaSeKofC.js} +70 -16
- package/dist/dev/index.d.ts +1 -1
- package/dist/dev/index.js +71 -3
- package/dist/eav/index.d.ts +3 -3
- package/dist/eav/index.js +2 -2
- package/dist/eav/migrate.d.ts +2 -2
- package/dist/eav/schema.d.ts +2 -2
- package/dist/{errors-U3TsyWVq.d.ts → errors-D-Va8oeC.d.ts} +5 -2
- package/dist/feedback/index.d.ts +1 -1
- package/dist/feedback/index.js +1 -1
- package/dist/files/index.d.ts +1 -1
- package/dist/files/index.js +1 -1
- package/dist/{http-client-Bl8u1vHN.js → http-client-BCZhLtY5.js} +33 -4
- package/dist/{index-BnAYxnwq.d.ts → index-CaXrNTtU.d.ts} +44 -15
- package/dist/{index-C6fyJTud.d.ts → index-Dh8XMVFF.d.ts} +2 -2
- package/dist/index.d.ts +6 -6
- package/dist/index.js +12 -12
- package/dist/installation/index.d.ts +415 -0
- package/dist/installation/index.js +841 -0
- package/dist/keys-B2pA8EkU.d.ts +44 -0
- package/dist/keys-B_R_lsyF.js +102 -0
- package/dist/logout/index.d.ts +1 -1
- package/dist/logout/index.js +1 -1
- package/dist/machine/index.d.ts +3 -0
- package/dist/machine/index.js +4 -0
- package/dist/machine/keygen-cli.d.ts +7 -0
- package/dist/machine/keygen-cli.js +57 -0
- package/dist/plans/index.d.ts +2 -2
- package/dist/plans/index.js +1 -1
- package/dist/push/index.d.ts +1 -1
- package/dist/push/index.js +1 -1
- package/dist/{query-JPVK_8N5.js → query-B8Hg9bub.js} +2 -2
- package/dist/react/hooks.d.ts +5 -5
- package/dist/resource/index.d.ts +176 -0
- package/dist/resource/index.js +345 -0
- package/dist/social/index.d.ts +284 -0
- package/dist/social/index.js +306 -0
- package/dist/{sse-parser-FMjxM7sY.js → sse-parser-D65dmL4A.js} +15 -18
- package/dist/superadmin/index.d.ts +80 -0
- package/dist/superadmin/index.js +148 -0
- package/dist/terms/index.d.ts +1 -1
- package/dist/terms/index.js +1 -1
- package/dist/testing/index.d.ts +2 -2
- package/dist/types-DGAVaUCc.js +17 -0
- package/dist/{types-MXLudLBP.d.ts → types-FazBnzhg.d.ts} +8 -2
- package/dist/workspace/index.d.ts +2 -624
- package/dist/workspace/index.js +2 -693
- package/docs/api-reference.md +233 -35
- package/docs/dev-server.md +2 -2
- package/docs/environment.md +34 -19
- package/docs/errors.md +54 -0
- package/docs/installation.md +128 -0
- package/docs/machine.md +109 -0
- package/docs/resource.md +75 -0
- package/docs/social.md +92 -0
- package/docs/superadmin.md +55 -0
- package/docs/workspace.md +12 -0
- package/package.json +36 -6
- package/dist/client-CI2Y00Qx.js +0 -81
- package/dist/types-DjDRszNj.js +0 -11
package/README.md
CHANGED
|
@@ -18,22 +18,133 @@ npm install @reopt-ai/brandapp-sdk
|
|
|
18
18
|
|
|
19
19
|
## Quick Start
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
Two kinds of credential (RFC-0034): a **login client** (`purpose: web`) whose
|
|
22
|
+
secret is only used to exchange the login code, and **server credentials**
|
|
23
|
+
(`purpose: machine` for data/AI/files/platform calls, `purpose: adapter` for
|
|
24
|
+
the remote Better Auth adapter) that authenticate with a private key —
|
|
25
|
+
`private_key_jwt` assertions plus DPoP-bound tokens — so Reopt never holds a
|
|
26
|
+
shared secret for server-to-server calls. Login clients are issued in the
|
|
27
|
+
platform console; server credentials are registered by Reopt for now.
|
|
28
|
+
|
|
29
|
+
### Server credentials (4.7+, recommended for every server call)
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
npx --package @reopt-ai/brandapp-sdk reopt-keygen # prints REOPT_CLIENT_PRIVATE_KEY_JWK='{…}'
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
// app/.well-known/reopt-client-jwks.json/route.ts — publish the public key
|
|
37
|
+
import {
|
|
38
|
+
buildClientJwks,
|
|
39
|
+
readClientKeyRing,
|
|
40
|
+
} from "@reopt-ai/brandapp-sdk/machine";
|
|
41
|
+
|
|
42
|
+
export const GET = () => {
|
|
43
|
+
const ring = readClientKeyRing();
|
|
44
|
+
return ring
|
|
45
|
+
? Response.json(buildClientJwks(ring.published))
|
|
46
|
+
: new Response(null, { status: 404 });
|
|
47
|
+
};
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
// lib/reopt.ts — the unified SDK with a machine credential
|
|
52
|
+
import { createReoptSDK } from "@reopt-ai/brandapp-sdk";
|
|
53
|
+
import {
|
|
54
|
+
createMachineClient,
|
|
55
|
+
readClientKeyRing,
|
|
56
|
+
} from "@reopt-ai/brandapp-sdk/machine";
|
|
57
|
+
|
|
58
|
+
const machine = createMachineClient({
|
|
59
|
+
clientId: process.env.BRANDAPP_MACHINE_CLIENT_ID!,
|
|
60
|
+
keyRing: readClientKeyRing()!, // REOPT_CLIENT_PRIVATE_KEY_JWK
|
|
61
|
+
resource: "https://brandapp.reopt.ai", // the token's audience — exactly one
|
|
62
|
+
scopes: ["brandapp:read", "brandapp:write"], // brandapp:write implies eav:*
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export const sdk = createReoptSDK({
|
|
66
|
+
brandappId: process.env.BRANDAPP_ID!,
|
|
67
|
+
clientId: machine.clientId,
|
|
68
|
+
authorization: machine.headers, // Authorization: DPoP … + a DPoP proof per request
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const entities = await sdk.eav.entities.list();
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Register `${origin}/.well-known/reopt-client-jwks.json` as the client's
|
|
75
|
+
`jwksUri`. Rotation, errors and the platform client are in
|
|
76
|
+
[`docs/machine.md`](./docs/machine.md).
|
|
77
|
+
|
|
78
|
+
### Connect to Reopt (installation, 4.7+)
|
|
79
|
+
|
|
80
|
+
A product declares its resources once (`reopt.workspace.ts`), signs the derived
|
|
81
|
+
manifest with the same private key, and asks Reopt to install it. An operator
|
|
82
|
+
approves in the console; the clients, API resources and webhooks are created
|
|
83
|
+
and their `client_id`s come back over the back-channel (or `refresh()`).
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import {
|
|
87
|
+
createInstallationClient,
|
|
88
|
+
createReoptConnection,
|
|
89
|
+
deriveInstallationManifest,
|
|
90
|
+
} from "@reopt-ai/brandapp-sdk/installation";
|
|
91
|
+
|
|
92
|
+
const manifest = deriveInstallationManifest({
|
|
93
|
+
declaration: workspace, // RFC-0030 declaration file
|
|
94
|
+
slug: "my-product",
|
|
95
|
+
name: "My Product",
|
|
96
|
+
workspaceId: process.env.REOPT_WORKSPACE_ID!,
|
|
97
|
+
jwksUri: "https://my-product.example/.well-known/reopt-client-jwks.json",
|
|
98
|
+
clients: [{ purpose: "machine", scopes: ["works:read", "works:write"] }],
|
|
99
|
+
});
|
|
100
|
+
const connection = createReoptConnection({
|
|
101
|
+
client: createInstallationClient({ keyRing: readClientKeyRing()! }),
|
|
102
|
+
manifest,
|
|
103
|
+
store, // one row in your DB holding the installation record
|
|
104
|
+
});
|
|
105
|
+
await connection.requestConnection(); // pending until an operator approves
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
States, the back-channel receiver and key rotation: [`docs/installation.md`](./docs/installation.md).
|
|
109
|
+
|
|
110
|
+
### Better Auth
|
|
111
|
+
|
|
112
|
+
Login goes through the login client; the remote adapter (users and sessions
|
|
113
|
+
stored in Reopt) authenticates as the `adapter` credential with the same key
|
|
114
|
+
ring.
|
|
22
115
|
|
|
23
116
|
```typescript
|
|
24
117
|
// auth.ts
|
|
25
118
|
import { betterAuth } from "better-auth";
|
|
26
|
-
import {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
119
|
+
import {
|
|
120
|
+
createReoptAdapter,
|
|
121
|
+
createReoptOAuth,
|
|
122
|
+
} from "@reopt-ai/brandapp-sdk/better-auth";
|
|
123
|
+
import {
|
|
124
|
+
createMachineClient,
|
|
125
|
+
readClientKeyRing,
|
|
126
|
+
} from "@reopt-ai/brandapp-sdk/machine";
|
|
127
|
+
|
|
128
|
+
const adapter = createMachineClient({
|
|
129
|
+
clientId: process.env.BRANDAPP_ADAPTER_CLIENT_ID!,
|
|
130
|
+
keyRing: readClientKeyRing()!,
|
|
131
|
+
resource: "https://brandapp.reopt.ai",
|
|
132
|
+
scopes: ["brandapp:auth-adapter"],
|
|
32
133
|
});
|
|
33
134
|
|
|
34
135
|
export const auth = betterAuth({
|
|
35
|
-
database:
|
|
36
|
-
|
|
136
|
+
database: createReoptAdapter({
|
|
137
|
+
brandappId: process.env.BRANDAPP_ID!,
|
|
138
|
+
clientId: adapter.clientId,
|
|
139
|
+
authorization: adapter.headers,
|
|
140
|
+
}),
|
|
141
|
+
plugins: [
|
|
142
|
+
createReoptOAuth({
|
|
143
|
+
clientId: process.env.BRANDAPP_CLIENT_ID!, // login client
|
|
144
|
+
clientSecret: process.env.BRANDAPP_CLIENT_SECRET!, // code exchange only
|
|
145
|
+
brandappId: process.env.BRANDAPP_ID!,
|
|
146
|
+
}),
|
|
147
|
+
],
|
|
37
148
|
});
|
|
38
149
|
```
|
|
39
150
|
|
|
@@ -54,19 +165,11 @@ signInWithReopt(authClient, { callbackURL: "/dashboard" });
|
|
|
54
165
|
> registered; if you registered a custom redirect URI, add the new path in the
|
|
55
166
|
> studio before upgrading.
|
|
56
167
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const sdk = createReoptSDK({
|
|
63
|
-
clientId: process.env.BRANDAPP_CLIENT_ID!,
|
|
64
|
-
clientSecret: process.env.BRANDAPP_CLIENT_SECRET!,
|
|
65
|
-
brandappId: process.env.BRANDAPP_ID!,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const entities = await sdk.eav.entities.list();
|
|
69
|
-
```
|
|
168
|
+
> **Shared secret (transitional).** `createReoptSDK({ clientId, clientSecret })`
|
|
169
|
+
> and `createReoptBetterAuth({ clientId, clientSecret })` still work for login
|
|
170
|
+
> clients that keep transitional machine scopes, but those scopes close once an
|
|
171
|
+
> app has moved to a key — new integrations should start with server
|
|
172
|
+
> credentials.
|
|
70
173
|
|
|
71
174
|
### External marketing site (1.8+)
|
|
72
175
|
|
|
@@ -175,9 +278,9 @@ const contacts = defineEntity({
|
|
|
175
278
|
const schema = defineSchema({ entities: { contacts } });
|
|
176
279
|
|
|
177
280
|
const sdk = createReoptSDK({
|
|
178
|
-
clientId: process.env.BRANDAPP_CLIENT_ID!,
|
|
179
|
-
clientSecret: process.env.BRANDAPP_CLIENT_SECRET!,
|
|
180
281
|
brandappId: process.env.BRANDAPP_ID!,
|
|
282
|
+
clientId: machine.clientId, // see "Server credentials"
|
|
283
|
+
authorization: machine.headers,
|
|
181
284
|
schema,
|
|
182
285
|
});
|
|
183
286
|
|
|
@@ -200,9 +303,9 @@ import { createLazySDK } from "@reopt-ai/brandapp-sdk";
|
|
|
200
303
|
import schema from "./eav.schema";
|
|
201
304
|
|
|
202
305
|
export const sdk = createLazySDK(() => ({
|
|
203
|
-
clientId: process.env.BRANDAPP_CLIENT_ID!,
|
|
204
|
-
clientSecret: process.env.BRANDAPP_CLIENT_SECRET!,
|
|
205
306
|
brandappId: process.env.BRANDAPP_ID!,
|
|
307
|
+
clientId: machine.clientId,
|
|
308
|
+
authorization: machine.headers,
|
|
206
309
|
schema,
|
|
207
310
|
}));
|
|
208
311
|
|
|
@@ -216,7 +319,7 @@ Or use the explicit init/get pattern:
|
|
|
216
319
|
import { initReoptSDK, getReoptSDK } from "@reopt-ai/brandapp-sdk";
|
|
217
320
|
|
|
218
321
|
// At app startup
|
|
219
|
-
initReoptSDK({
|
|
322
|
+
initReoptSDK({ brandappId, clientId, authorization: machine.headers, schema });
|
|
220
323
|
|
|
221
324
|
// Anywhere else
|
|
222
325
|
const sdk = getReoptSDK();
|
|
@@ -281,28 +384,32 @@ const meta = asJson<Meta>(record.values.meta); // Meta | undefined
|
|
|
281
384
|
|
|
282
385
|
## Exports
|
|
283
386
|
|
|
284
|
-
| Path | Main Exports
|
|
285
|
-
| ---------------------------- |
|
|
286
|
-
| `"."` | `createReoptSDK`, `createLazySDK`, `initReoptSDK`, `getReoptSDK`, errors
|
|
287
|
-
| `"./better-auth"` | `createReoptBetterAuth`, `createReoptAdapter`, `createReoptOAuth`
|
|
288
|
-
| `"./better-auth/client"` | `signInWithReopt
|
|
289
|
-
| `"./eav"` | `createReoptEavClient`, `collectAll`, EAV types, `TypedEavRecord`, `EntityClient`
|
|
290
|
-
| `"./eav/schema"` | `defineEntity`, `defineSchema`, `syncSchema`, `computeDiff`, schema/sync types
|
|
291
|
-
| `"./eav/coerce"` | `asString`, `asNumber`, `asBoolean`, `asDate`, `asJson`, `asStringArray`
|
|
292
|
-
| `"./eav/migrate"` | `defineMigration`, `runMigrations`, migration types
|
|
293
|
-
| `"./ai"` / `"./ai-provider"` | `ReoptAiClient` / `createBrandappProvider` (Vercel AI SDK)
|
|
294
|
-
| `"./auth"` | `getSessionFromCookies`, `verifySession`, `sdk.auth` client
|
|
295
|
-
| `"./cms"` | `sdk.cms` types + `toMetadata` / `toSitemapItems` / `toRssFeed` / `EditorSpec`
|
|
296
|
-
| `"./files"` | file client types + `optimizeUrl`, `createImageLoader`
|
|
297
|
-
| `"./terms"` | Terms list / consent / withdraw types
|
|
298
|
-
| `"./plans"` | `createReoptPlansClient`, `Plan` / `CheckoutSession` / `CurrentPlan` types
|
|
299
|
-
| `"./push"` | Customer device token register / unregister / list types
|
|
300
|
-
| `"./feedback"` | Customer feedback submission types
|
|
301
|
-
| `"./logout"` | `createBackchannelLogoutHandler`, `verifyBackchannelLogoutToken`, `buildEndSessionUrl`
|
|
302
|
-
| `"./webhooks"` | `createWebhookHandler`, `verifySignature`
|
|
303
|
-
| `"./react/hooks"` | TanStack Query hooks (`useAiCredits`, `useEavRecords`, …)
|
|
304
|
-
| `"./workspace"` | `createPlatformClient` — workspace-scoped platform API (**server-only**)
|
|
305
|
-
| `"./
|
|
387
|
+
| Path | Main Exports | Requires `better-auth` |
|
|
388
|
+
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------ |
|
|
389
|
+
| `"."` | `createReoptSDK`, `createLazySDK`, `initReoptSDK`, `getReoptSDK`, errors | No |
|
|
390
|
+
| `"./better-auth"` | `createReoptBetterAuth`, `createReoptAdapter`, `createReoptOAuth` | Yes |
|
|
391
|
+
| `"./better-auth/client"` | `signInWithReopt` (`{ stepUp }`), `linkReoptAccount`, `REOPT_PROVIDER_ID(S)` | Yes |
|
|
392
|
+
| `"./eav"` | `createReoptEavClient`, `collectAll`, EAV types, `TypedEavRecord`, `EntityClient` | No |
|
|
393
|
+
| `"./eav/schema"` | `defineEntity`, `defineSchema`, `syncSchema`, `computeDiff`, schema/sync types | No |
|
|
394
|
+
| `"./eav/coerce"` | `asString`, `asNumber`, `asBoolean`, `asDate`, `asJson`, `asStringArray` | No |
|
|
395
|
+
| `"./eav/migrate"` | `defineMigration`, `runMigrations`, migration types | No |
|
|
396
|
+
| `"./ai"` / `"./ai-provider"` | `ReoptAiClient` / `createBrandappProvider` (Vercel AI SDK) | No |
|
|
397
|
+
| `"./auth"` | `getSessionFromCookies`, `verifySession`, `sdk.auth` client | No |
|
|
398
|
+
| `"./cms"` | `sdk.cms` types + `toMetadata` / `toSitemapItems` / `toRssFeed` / `EditorSpec` | No |
|
|
399
|
+
| `"./files"` | file client types + `optimizeUrl`, `createImageLoader` | No |
|
|
400
|
+
| `"./terms"` | Terms list / consent / withdraw types | No |
|
|
401
|
+
| `"./plans"` | `createReoptPlansClient`, `Plan` / `CheckoutSession` / `CurrentPlan` types | No |
|
|
402
|
+
| `"./push"` | Customer device token register / unregister / list types | No |
|
|
403
|
+
| `"./feedback"` | Customer feedback submission types | No |
|
|
404
|
+
| `"./logout"` | `createBackchannelLogoutHandler`, `verifyBackchannelLogoutToken`, `buildEndSessionUrl` | No |
|
|
405
|
+
| `"./webhooks"` | `createWebhookHandler`, `verifySignature` | No |
|
|
406
|
+
| `"./react/hooks"` | TanStack Query hooks (`useAiCredits`, `useEavRecords`, …) | No |
|
|
407
|
+
| `"./workspace"` | `createPlatformClient` — workspace-scoped platform API (**server-only**) | No |
|
|
408
|
+
| `"./social"` | `createSocialClient` — social operations platform API: convert · review · submit · propose (**server-only**) | No |
|
|
409
|
+
| `"./machine"` | `createMachineClient`, `readClientKeyRing`, `buildClientJwks` — machine credentials (**server-only**) | No (`@better-auth/core`) |
|
|
410
|
+
| `"./resource"` | `createResourceVerifier`, `createRedisDpopReplayStore` — verify reopt machine tokens on your API (**server-only**) | No (`@better-auth/core`) |
|
|
411
|
+
| `"./superadmin"` | `requireOperator`, `evaluateOperator`, `decodeIdTokenClaims` — operator guard from reopt id-token claims | No |
|
|
412
|
+
| `"./dev"` / `"./testing"` | `createDevServer` / `createTestSDK` (local dev + fixtures) | No |
|
|
306
413
|
|
|
307
414
|
> Full signatures for every sub-path: [`docs/api-reference.md`](./docs/api-reference.md).
|
|
308
415
|
|
|
@@ -318,12 +425,18 @@ const meta = asJson<Meta>(record.values.meta); // Meta | undefined
|
|
|
318
425
|
|
|
319
426
|
```typescript
|
|
320
427
|
{
|
|
321
|
-
clientId: string; // OAuth Client ID (required)
|
|
322
|
-
clientSecret: string; // OAuth Client Secret (required)
|
|
323
428
|
brandappId: string; // Brandapp ID (required)
|
|
429
|
+
clientId: string; // OAuth Client ID (required unless `token`)
|
|
430
|
+
authorization?: (req: { method: string; url: string }) =>
|
|
431
|
+
Promise<Record<string, string>>;
|
|
432
|
+
// Per-request auth headers — pass a machine
|
|
433
|
+
// client's `headers` (private_key_jwt + DPoP).
|
|
434
|
+
// No clientSecret needed.
|
|
435
|
+
clientSecret?: string; // Shared secret (Basic) — transitional; only for
|
|
436
|
+
// login clients that still hold machine scopes
|
|
324
437
|
token?: string; // Short-lived Bearer token (Phase D-2b) —
|
|
325
438
|
// overrides Basic Auth when set
|
|
326
|
-
isProduction?: boolean; // true → brandapp.reopt.ai, false → brand.reopt.
|
|
439
|
+
isProduction?: boolean; // true → brandapp.reopt.ai, false → brand.local.reopt.io
|
|
327
440
|
// default: auto-detect from NODE_ENV
|
|
328
441
|
baseUrl?: string; // Main API host override (REOPT_BASE_URL env equivalent)
|
|
329
442
|
idBaseUrl?: string; // Auth host override (REOPT_ID_BASE_URL env equivalent)
|
|
@@ -347,40 +460,49 @@ const meta = asJson<Meta>(record.values.meta); // Meta | undefined
|
|
|
347
460
|
|
|
348
461
|
### Built-in URLs
|
|
349
462
|
|
|
350
|
-
| `isProduction` | Main API host
|
|
351
|
-
| --------------------- |
|
|
352
|
-
| `false` | `https://brand.reopt.
|
|
353
|
-
| `true` | `https://brandapp.reopt.ai`
|
|
354
|
-
| `undefined` (default) | auto from `NODE_ENV`
|
|
463
|
+
| `isProduction` | Main API host | Auth (id) host |
|
|
464
|
+
| --------------------- | ------------------------------ | --------------------------- |
|
|
465
|
+
| `false` | `https://brand.local.reopt.io` | `https://id.local.reopt.io` |
|
|
466
|
+
| `true` | `https://brandapp.reopt.ai` | `https://id.reopt.ai` |
|
|
467
|
+
| `undefined` (default) | auto from `NODE_ENV` | auto from `NODE_ENV` |
|
|
355
468
|
|
|
356
469
|
## Environment Variables
|
|
357
470
|
|
|
358
|
-
SDK는 `process.env`를 자동으로 읽습니다.
|
|
471
|
+
SDK는 `process.env`를 자동으로 읽습니다. 자격 변수만 설정하면 나머지는
|
|
359
472
|
`NODE_ENV` 기반으로 알아서 분기합니다.
|
|
360
473
|
|
|
361
|
-
|
|
474
|
+
**자격 — 서버 자격(권장)**
|
|
475
|
+
|
|
476
|
+
| 변수 | 용도 |
|
|
477
|
+
| ----------------------------------- | -------------------------------------------------------------------------------------- |
|
|
478
|
+
| `REOPT_CLIENT_PRIVATE_KEY_JWK` | 개인키(JWK) — `reopt-keygen` 출력, 서버 전용. `readClientKeyRing()`이 읽는다 |
|
|
479
|
+
| `REOPT_CLIENT_PRIVATE_KEY_JWK_NEXT` | 회전 중 다음 키 — JWKS에 둘 다 실리고 서명은 NEXT로 옮겨 간다 |
|
|
480
|
+
| `BRANDAPP_MACHINE_CLIENT_ID` | 용도 machine 클라이언트 ID(데이터·AI·파일·플랫폼 API) — 이름은 관례, SDK가 읽지 않는다 |
|
|
481
|
+
| `BRANDAPP_ADAPTER_CLIENT_ID` | 용도 adapter 클라이언트 ID(원격 Better Auth 어댑터) — 위와 같음 |
|
|
482
|
+
| `BRANDAPP_ID` | BrandApp 고유 ID |
|
|
483
|
+
|
|
484
|
+
**자격 — 로그인 클라이언트**
|
|
362
485
|
|
|
363
|
-
| 변수 | 용도
|
|
364
|
-
| ------------------------ |
|
|
365
|
-
| `BRANDAPP_CLIENT_ID` |
|
|
366
|
-
| `BRANDAPP_CLIENT_SECRET` |
|
|
367
|
-
| `BRANDAPP_ID` | BrandApp 고유 ID |
|
|
486
|
+
| 변수 | 용도 |
|
|
487
|
+
| ------------------------ | ------------------------------------------------------------------- |
|
|
488
|
+
| `BRANDAPP_CLIENT_ID` | 로그인(용도 web) Client ID — 플랫폼 콘솔 → 브랜드앱 → 설정에서 발급 |
|
|
489
|
+
| `BRANDAPP_CLIENT_SECRET` | 로그인 Client Secret (1회 노출) — code 교환에만 |
|
|
368
490
|
|
|
369
491
|
**선택 (없으면 `NODE_ENV`로 자동 분기)**
|
|
370
492
|
|
|
371
|
-
| 변수 | 용도 | 기본값
|
|
372
|
-
| ------------------------- | -------------------------------------- |
|
|
373
|
-
| `REOPT_BASE_URL` | 메인 API host (reopt 플랫폼) | prod: `https://brandapp.reopt.ai`, dev: `https://brand.reopt.
|
|
374
|
-
| `REOPT_ID_BASE_URL` | 인증 host (reopt id 서버) | `REOPT_BASE_URL`에서 자동 유도
|
|
375
|
-
| `BRANDAPP_WEBHOOK_SECRET` | webhook HMAC 검증 | — (consumer가 `createWebhookHandler`에 명시 주입)
|
|
376
|
-
| `BRANDAPP_SDK_DEBUG` | 디버그 로그 (`trace` \| `info` \| `1`) | off
|
|
377
|
-
| `BRANDAPP_SDK_LOG_FORMAT` | 로그 포맷 (`json` 시 구조화) | plain
|
|
493
|
+
| 변수 | 용도 | 기본값 |
|
|
494
|
+
| ------------------------- | -------------------------------------- | ---------------------------------------------------------------------- |
|
|
495
|
+
| `REOPT_BASE_URL` | 메인 API host (reopt 플랫폼) | prod: `https://brandapp.reopt.ai`, dev: `https://brand.local.reopt.io` |
|
|
496
|
+
| `REOPT_ID_BASE_URL` | 인증 host (reopt id 서버) | `REOPT_BASE_URL`에서 자동 유도 |
|
|
497
|
+
| `BRANDAPP_WEBHOOK_SECRET` | webhook HMAC 검증 | — (consumer가 `createWebhookHandler`에 명시 주입) |
|
|
498
|
+
| `BRANDAPP_SDK_DEBUG` | 디버그 로그 (`trace` \| `info` \| `1`) | off |
|
|
499
|
+
| `BRANDAPP_SDK_LOG_FORMAT` | 로그 포맷 (`json` 시 구조화) | plain |
|
|
378
500
|
|
|
379
501
|
상세 우선순위·시나리오·트러블슈팅·브라우저(`NEXT_PUBLIC_BRANDAPP_*`)·CI/CD
|
|
380
502
|
패턴은 **[docs/environment.md](./docs/environment.md)**.
|
|
381
503
|
|
|
382
504
|
> **네이밍 원칙** — `BRANDAPP_*`는 consumer 자격/식별자, `REOPT_*`는 reopt 플랫폼
|
|
383
|
-
> 호스트
|
|
505
|
+
> 호스트 정보와 서명 키, `BRANDAPP_SDK_*`는 SDK 자체 동작 제어.
|
|
384
506
|
|
|
385
507
|
## Error Handling
|
|
386
508
|
|
package/dist/ai/index.d.ts
CHANGED
|
@@ -1,2 +1,52 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
|
|
1
|
+
import { C as StreamEvent, S as StreamDoneData, _ as ImageGenerateOptions, a as CompletionContentPart, b as ModelInfo, c as CompletionUsage, d as EvaluateOptions, f as EvaluationAnswer, g as FinishReason, h as EvaluationResult, i as ChatMessage, l as CompletionWarning, m as EvaluationQuestion, n as createReoptAiClient, o as CompletionOptions, p as EvaluationInput, r as AgentInfo, s as CompletionResult, t as ReoptAiClient, u as CreditInfo, v as ImageGenerateResult, x as PartProviderMetadata, y as MessageRole } from "../client-CP1Jgq4R.js";
|
|
2
|
+
//#region src/ai/evaluator.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* json-render `experimental_composeSpec`의 `evaluate`와 같은 모양(0.21 `Experimental_CompositionEvaluator`).
|
|
5
|
+
* json-render를 의존성으로 들이지 않으려고 구조만 같게 적는다 — 호환은 테스트가 실제 `composeSpec`에
|
|
6
|
+
* 꽂아 확인한다.
|
|
7
|
+
*/
|
|
8
|
+
type BrandappCompositionEvaluator = (request: {
|
|
9
|
+
state: Record<string, unknown>;
|
|
10
|
+
questions: Record<string, {
|
|
11
|
+
type: "choice";
|
|
12
|
+
instructions: string;
|
|
13
|
+
criteria: Record<string, string>;
|
|
14
|
+
}>;
|
|
15
|
+
signal: AbortSignal;
|
|
16
|
+
}) => Promise<{
|
|
17
|
+
answers: Record<string, {
|
|
18
|
+
choice: string;
|
|
19
|
+
confidence?: number;
|
|
20
|
+
}>;
|
|
21
|
+
usage?: {
|
|
22
|
+
inputTokens?: number;
|
|
23
|
+
};
|
|
24
|
+
}>;
|
|
25
|
+
type EvaluatorSource = Pick<ReoptAiClient, "evaluate"> | {
|
|
26
|
+
ai: Pick<ReoptAiClient, "evaluate">;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* 브랜드앱 크레딧으로 도는 json-render 평가자(4.7+, RFC-0041).
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* for await (const event of experimental_composeSpec({
|
|
33
|
+
* catalog, candidates, prompt,
|
|
34
|
+
* evaluate: createBrandappEvaluator(sdk, { customerId }),
|
|
35
|
+
* })) { … }
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* 질문은 그대로 보내고 답을 json-render 모양(`{ choice, confidence? }`)으로 옮긴다. 모델이 답을
|
|
39
|
+
* 거부했거나 choice가 아닌 답이 오면 던진다 — json-render는 평가자 오류를 던져 조립을 끝내고
|
|
40
|
+
* 마지막 스냅샷을 남기는 설계다. **서버 전용**(브라우저에서 앱 자격을 쓰지 않는다).
|
|
41
|
+
*/
|
|
42
|
+
type BrandappEvaluatorOptions = Pick<EvaluateOptions, "customerId" | "timeoutMs"> & {
|
|
43
|
+
/**
|
|
44
|
+
* 평가 한 번이 끝날 때마다(성공만) 부른다 — 조립 한 번의 실제 비용을 앱이 셀 자리다. json-render는
|
|
45
|
+
* 입력 토큰만 넘기므로 크레딧은 여기서만 보인다. 합산은 `usage.creditCostMilli`를 더한 뒤 한 번 올림.
|
|
46
|
+
*/
|
|
47
|
+
onEvaluation?: (result: EvaluationResult) => void;
|
|
48
|
+
};
|
|
49
|
+
declare function createBrandappEvaluator(source: EvaluatorSource, options?: BrandappEvaluatorOptions): BrandappCompositionEvaluator;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { type AgentInfo, type BrandappCompositionEvaluator, type BrandappEvaluatorOptions, type ChatMessage, type CompletionContentPart, type CompletionOptions, type CompletionResult, type CompletionUsage, type CompletionWarning, type CreditInfo, type EvaluateOptions, type EvaluationAnswer, type EvaluationInput, type EvaluationQuestion, type EvaluationResult, type FinishReason, type ImageGenerateOptions, type ImageGenerateResult, type MessageRole, type ModelInfo, type PartProviderMetadata, ReoptAiClient, type StreamDoneData, type StreamEvent, createBrandappEvaluator, createReoptAiClient };
|
|
52
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/ai/index.js
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as ReoptSDKError } from "../config-DaSeKofC.js";
|
|
2
|
+
import { n as createReoptAiClient, t as ReoptAiClient } from "../client-D97Ylva1.js";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
//#region src/ai/evaluator.ts
|
|
5
|
+
function createBrandappEvaluator(source, options = {}) {
|
|
6
|
+
const client = "ai" in source ? source.ai : source;
|
|
7
|
+
return async ({ state, questions, signal }) => {
|
|
8
|
+
const result = await client.evaluate({
|
|
9
|
+
state,
|
|
10
|
+
questions,
|
|
11
|
+
...options.timeoutMs != null ? { timeoutMs: options.timeoutMs } : {},
|
|
12
|
+
...options.customerId ? { customerId: options.customerId } : {}
|
|
13
|
+
}, { signal });
|
|
14
|
+
options.onEvaluation?.(result);
|
|
15
|
+
const answers = {};
|
|
16
|
+
for (const id of Object.keys(questions)) {
|
|
17
|
+
const answer = result.answers[id];
|
|
18
|
+
if (!answer || answer.type !== "choice") throw new ReoptSDKError(answer?.type === "refusal" ? `Evaluation model declined to answer "${id}"` : `Evaluation returned no choice for "${id}"`, 502, answer?.type === "refusal" ? "EVALUATION_REFUSED" : "EVALUATION_INVALID_ANSWER");
|
|
19
|
+
answers[id] = {
|
|
20
|
+
choice: answer.choice,
|
|
21
|
+
...answer.confidence != null ? { confidence: answer.confidence } : {}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
answers,
|
|
26
|
+
...result.usage.inputTokens != null ? { usage: { inputTokens: result.usage.inputTokens } } : {}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { ReoptAiClient, createBrandappEvaluator, createReoptAiClient };
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,12 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as ReoptSDKConfig } from "../config-BGT9h1OW.js";
|
|
2
|
+
import { Experimental_DecisionModelV4, Experimental_DecisionModelV4CallOptions, Experimental_DecisionModelV4Result, ImageModelV3, ImageModelV3CallOptions, LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, ProviderV3 } from "@ai-sdk/provider";
|
|
2
3
|
//#region src/ai-provider/brandapp-language-model.d.ts
|
|
3
4
|
type BrandappLanguageModelConfig = {
|
|
4
5
|
/** BrandApp API base URL */
|
|
5
6
|
baseUrl: string;
|
|
6
|
-
/**
|
|
7
|
+
/** 정적 Authorization 헤더 (Basic 또는 Bearer) — `authorization`이 없을 때만 쓴다 */
|
|
7
8
|
authHeader: string;
|
|
8
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* 요청별 인증 헤더 제공자(RFC-0034 기계 클라이언트 DPoP). 있으면 `authHeader` 대신 매 요청
|
|
11
|
+
* 새로 받는다 — DPoP 증명은 메서드·URL에 묶이고 jti를 한 번만 쓸 수 있다.
|
|
12
|
+
*/
|
|
13
|
+
authorization?: (request: {
|
|
14
|
+
method: string;
|
|
15
|
+
url: string;
|
|
16
|
+
}) => Promise<Record<string, string>>;
|
|
17
|
+
/** 요청 타임아웃 (ms) — 스트리밍에서는 청크 사이의 유휴 한도다. */
|
|
9
18
|
timeout: number;
|
|
19
|
+
/**
|
|
20
|
+
* 비스트리밍(`doGenerate`)의 전체 한도(ms) — 응답 본문까지 기다린다. 추론·긴 JSON 응답은
|
|
21
|
+
* 60초를 넘기 쉬워 따로 둔다. 없으면 `timeout`.
|
|
22
|
+
*/
|
|
23
|
+
generateTimeout?: number;
|
|
10
24
|
/** SDK 버전 문자열 */
|
|
11
25
|
sdkVersion: string;
|
|
12
26
|
/** BrandappCustomer ID (사용량 추적) */
|
|
@@ -14,10 +28,14 @@ type BrandappLanguageModelConfig = {
|
|
|
14
28
|
/** 커스텀 fetch 함수 */
|
|
15
29
|
fetch?: typeof globalThis.fetch;
|
|
16
30
|
};
|
|
31
|
+
/** 추론 강도 — 지원 모델에만 전달된다(서버가 판정). */
|
|
32
|
+
type BrandappReasoningEffort = "low" | "medium" | "high";
|
|
17
33
|
/** BrandApp 프로바이더 옵션 (providerOptions.brandapp으로 전달) */
|
|
18
34
|
type BrandappProviderOptions = {
|
|
19
35
|
/** BrandappCustomer ID (사용량 추적) */
|
|
20
36
|
customerId?: string;
|
|
37
|
+
/** 추론 강도. 없으면 `anthropic.effort`·`openai.reasoningEffort`를 읽는다. */
|
|
38
|
+
reasoningEffort?: BrandappReasoningEffort;
|
|
21
39
|
};
|
|
22
40
|
declare class BrandappLanguageModel implements LanguageModelV3 {
|
|
23
41
|
readonly specificationVersion: "v3";
|
|
@@ -35,6 +53,26 @@ declare class BrandappLanguageModel implements LanguageModelV3 {
|
|
|
35
53
|
private createStreamPartTransform;
|
|
36
54
|
}
|
|
37
55
|
//#endregion
|
|
56
|
+
//#region src/ai-provider/brandapp-decision-model.d.ts
|
|
57
|
+
/** 서버가 중계하는 평가 모델 — 지금은 Jev 하나다(서버가 고정 버전으로 부른다). */
|
|
58
|
+
declare const BRANDAPP_DECISION_MODEL_IDS: readonly ["typesafe-ai/jev", "typesafe-ai/jev-1.14.0"];
|
|
59
|
+
type BrandappDecisionModelId = (typeof BRANDAPP_DECISION_MODEL_IDS)[number];
|
|
60
|
+
type BrandappDecisionProviderOptions = {
|
|
61
|
+
/** BrandappCustomer ID (사용량 귀속) */
|
|
62
|
+
customerId?: string;
|
|
63
|
+
/** 서버 상한 1000~10000ms (기본 10000). 넘으면 504 — 과금 없음. */
|
|
64
|
+
timeoutMs?: number;
|
|
65
|
+
};
|
|
66
|
+
declare class BrandappDecisionModel implements Experimental_DecisionModelV4 {
|
|
67
|
+
readonly specificationVersion: "v4";
|
|
68
|
+
readonly provider = "brandapp";
|
|
69
|
+
readonly modelId: string;
|
|
70
|
+
readonly supportedQuestionTypes: readonly ["choice", "score", "boolean"];
|
|
71
|
+
private readonly config;
|
|
72
|
+
constructor(modelId: string, config: BrandappLanguageModelConfig);
|
|
73
|
+
doDecide(options: Experimental_DecisionModelV4CallOptions): Promise<Experimental_DecisionModelV4Result>;
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
38
76
|
//#region src/ai-provider/brandapp-image-model.d.ts
|
|
39
77
|
type BrandappImageProviderOptions = {
|
|
40
78
|
/** BrandappCustomer ID (사용량 추적) */
|
|
@@ -70,16 +108,26 @@ type BrandappProviderConfig = {
|
|
|
70
108
|
brandappId: string;
|
|
71
109
|
/** Short-lived service token minted by `/token/mint`. */
|
|
72
110
|
token?: string;
|
|
111
|
+
/**
|
|
112
|
+
* RFC-0034 per-request auth header provider — pass `machine.headers` from
|
|
113
|
+
* `createMachineClient`. Every request then carries `Authorization: DPoP …`
|
|
114
|
+
* plus a fresh `DPoP` proof, and no clientSecret is needed (same contract as
|
|
115
|
+
* `ReoptSDKConfig.authorization`).
|
|
116
|
+
*/
|
|
117
|
+
authorization?: ReoptSDKConfig["authorization"];
|
|
73
118
|
/**
|
|
74
119
|
* 프로덕션 환경 여부.
|
|
75
120
|
* - `true`: https://brandapp.reopt.ai
|
|
76
|
-
* - `false`: https://brand.reopt.
|
|
121
|
+
* - `false`: https://brand.local.reopt.io (dev)
|
|
77
122
|
* - 미지정 (기본): `NODE_ENV === "production"` 자동 감지
|
|
78
123
|
*/
|
|
79
124
|
isProduction?: boolean;
|
|
80
125
|
/** 커스텀 base URL */
|
|
81
126
|
baseUrl?: string;
|
|
82
|
-
/**
|
|
127
|
+
/**
|
|
128
|
+
* 요청 타임아웃 ms. 스트리밍은 청크 사이 유휴 한도(기본 60000), 비스트리밍(`generateText`)은
|
|
129
|
+
* 응답 전체 한도(기본 300000 — 추론·긴 JSON 응답). 지정하면 둘 다 이 값이다.
|
|
130
|
+
*/
|
|
83
131
|
timeout?: number;
|
|
84
132
|
/** 기본 customerId (모든 요청에 적용) */
|
|
85
133
|
customerId?: string;
|
|
@@ -106,7 +154,11 @@ type BrandappProviderConfig = {
|
|
|
106
154
|
declare function createBrandappProvider(config: BrandappProviderConfig): BrandappProvider;
|
|
107
155
|
type BrandappProvider = ProviderV3 & {
|
|
108
156
|
(modelId: string): LanguageModelV3;
|
|
157
|
+
/** 평가 모델(Jev) — AI SDK `experimental_decide`의 `model`. 생략하면 `typesafe-ai/jev`. */
|
|
158
|
+
decisionModel(modelId?: string): BrandappDecisionModel;
|
|
159
|
+
/** @deprecated `decisionModel`과 같다(AI SDK의 옛 이름). */
|
|
160
|
+
evaluationModel(modelId?: string): BrandappDecisionModel;
|
|
109
161
|
};
|
|
110
162
|
//#endregion
|
|
111
|
-
export { BrandappImageModel, type BrandappImageProviderOptions, BrandappLanguageModel, type BrandappLanguageModelConfig, BrandappProvider, BrandappProviderConfig, type BrandappProviderOptions, createBrandappProvider };
|
|
163
|
+
export { BRANDAPP_DECISION_MODEL_IDS, BrandappDecisionModel, type BrandappDecisionModelId, type BrandappDecisionProviderOptions, BrandappImageModel, type BrandappImageProviderOptions, BrandappLanguageModel, type BrandappLanguageModelConfig, BrandappProvider, BrandappProviderConfig, type BrandappProviderOptions, createBrandappProvider };
|
|
112
164
|
//# sourceMappingURL=index.d.ts.map
|