@viceme-ai/sdk 0.1.2
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/README.md +48 -0
- package/dist/bootstrap.min.js +2 -0
- package/dist/bootstrap.min.js.map +1 -0
- package/dist/chunks/client-CGU3qeew.js +275 -0
- package/dist/chunks/client-CGU3qeew.js.map +1 -0
- package/dist/core/client.d.ts +55 -0
- package/dist/core/client.d.ts.map +1 -0
- package/dist/core/config.d.ts +32 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/errors.d.ts +37 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/lifecycle.d.ts +25 -0
- package/dist/core/lifecycle.d.ts.map +1 -0
- package/dist/generated/public-contract.d.ts +156 -0
- package/dist/generated/public-contract.d.ts.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +126 -0
- package/dist/index.js.map +1 -0
- package/dist/loader/attributes.d.ts +21 -0
- package/dist/loader/attributes.d.ts.map +1 -0
- package/dist/loader/auto-loader.d.ts +51 -0
- package/dist/loader/auto-loader.d.ts.map +1 -0
- package/dist/loader/bootstrap.d.ts +1 -0
- package/dist/loader/bootstrap.d.ts.map +1 -0
- package/dist/loader/events.d.ts +45 -0
- package/dist/loader/events.d.ts.map +1 -0
- package/dist/loader/main.d.ts +11 -0
- package/dist/loader/main.d.ts.map +1 -0
- package/dist/loader/mount-handle.d.ts +25 -0
- package/dist/loader/mount-handle.d.ts.map +1 -0
- package/dist/loader/registry.d.ts +42 -0
- package/dist/loader/registry.d.ts.map +1 -0
- package/dist/manifest.json +38 -0
- package/dist/session/session.d.ts +54 -0
- package/dist/session/session.d.ts.map +1 -0
- package/dist/testing/test-adapter.d.ts +57 -0
- package/dist/testing/test-adapter.d.ts.map +1 -0
- package/dist/testing.d.ts +9 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +69 -0
- package/dist/testing.js.map +1 -0
- package/dist/transport/transport.d.ts +42 -0
- package/dist/transport/transport.d.ts.map +1 -0
- package/dist/version.d.ts +10 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/viceme.min.js +2 -0
- package/dist/viceme.min.js.map +1 -0
- package/package.json +59 -0
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @viceme-ai/sdk
|
|
2
|
+
|
|
3
|
+
Public ViceMe browser SDK: headless core, public session, and capability
|
|
4
|
+
subpaths for static HTML, browser-native ESM, React/Next.js, and
|
|
5
|
+
Agent-generated sites.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @viceme-ai/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createViceMe } from '@viceme-ai/sdk';
|
|
17
|
+
|
|
18
|
+
const client = createViceMe({ workKey: 'wrk_public_xxx', region: 'cn' });
|
|
19
|
+
await client.ready();
|
|
20
|
+
|
|
21
|
+
if (client.hasCapability('danmaku')) {
|
|
22
|
+
// capability subpath, e.g. '@viceme-ai/sdk/danmaku'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
client.destroy();
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Static HTML sites can use the CDN auto-loader instead — see the
|
|
29
|
+
[repository README](https://github.com/ViceMe-AI/sdk).
|
|
30
|
+
|
|
31
|
+
## Testing your integration
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { createTestViceMe, createMemoryTransport } from '@viceme-ai/sdk/testing';
|
|
35
|
+
|
|
36
|
+
const client = createTestViceMe({
|
|
37
|
+
workKey: 'wrk_test',
|
|
38
|
+
region: 'cn',
|
|
39
|
+
transport: createMemoryTransport({
|
|
40
|
+
work: { key: 'wrk_test', capabilities: ['fixture'] },
|
|
41
|
+
}),
|
|
42
|
+
});
|
|
43
|
+
await client.ready();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Consumers branch on stable `ViceMeError.code` values only — never on error
|
|
47
|
+
messages. Status: `0.x` infrastructure phase; capability subpaths land as
|
|
48
|
+
their public API contracts go live.
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
(function(){"use strict";(()=>{const t=document.currentScript;if(!(t instanceof HTMLScriptElement)||!t.src)return;const c=typeof AbortSignal<"u"&&typeof AbortSignal.timeout=="function"?AbortSignal.timeout(8e3):void 0;fetch(new URL("/viceme-sdk/-/aliases/v1",t.src),{credentials:"omit",signal:c}).then(e=>{if(!e.ok)throw new Error(`pointer HTTP ${e.status}`);return e.text()}).then(e=>{const i=e.trim();if(!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(i))throw new Error("invalid pointer");const r=document.createElement("script");for(const n of t.getAttributeNames())n==="src"||n==="integrity"||r.setAttribute(n,t.getAttribute(n)??"");r.src=new URL(`/viceme-sdk/${i}/viceme.min.js`,t.src).href,(document.head??document.documentElement).append(r)}).catch(()=>{document.dispatchEvent(new CustomEvent("viceme:error",{detail:{code:"CONFIG_INVALID",retryable:!1},bubbles:!0,composed:!0}))})})()})();
|
|
2
|
+
//# sourceMappingURL=bootstrap.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.min.js","sources":["../src/loader/bootstrap.ts"],"sourcesContent":["/**\n * FIXED alias bootstrap — the ONLY object under /viceme-sdk/v1/.\n *\n * Byte-stable for the whole API major (this file must not grow feature\n * logic): it reads the version pointer at /viceme-sdk/-/aliases/v1 and\n * injects the full versioned auto-loader at\n * /viceme-sdk/<version>/viceme.min.js with the same data-viceme-*\n * attributes. The full loader (and every future fix to it) lives in the\n * immutable exact-version directory, so the alias bytes never need to\n * change when releases ship.\n */\n(() => {\n const script = document.currentScript;\n if (!(script instanceof HTMLScriptElement) || !script.src) return;\n\n const signal =\n typeof AbortSignal !== 'undefined' && typeof AbortSignal.timeout === 'function'\n ? AbortSignal.timeout(8_000)\n : undefined;\n\n fetch(new URL('/viceme-sdk/-/aliases/v1', script.src), {\n credentials: 'omit',\n signal,\n })\n .then((response) => {\n if (!response.ok) throw new Error(`pointer HTTP ${response.status}`);\n return response.text();\n })\n .then((text) => {\n const version = text.trim();\n if (!/^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?$/.test(version)) {\n throw new Error('invalid pointer');\n }\n const loader = document.createElement('script');\n for (const name of script.getAttributeNames()) {\n // The loader gets its own src; integrity pins are not transferable.\n if (name === 'src' || name === 'integrity') continue;\n loader.setAttribute(name, script.getAttribute(name) ?? '');\n }\n loader.src = new URL(`/viceme-sdk/${version}/viceme.min.js`, script.src).href;\n (document.head ?? document.documentElement).append(loader);\n })\n .catch(() => {\n document.dispatchEvent(\n new CustomEvent('viceme:error', {\n detail: { code: 'CONFIG_INVALID', retryable: false },\n bubbles: true,\n composed: true,\n }),\n );\n });\n})();\n"],"names":["script","signal","response","text","version","loader","name"],"mappings":"0BAWC,IAAM,CACL,MAAMA,EAAS,SAAS,cACxB,GAAI,EAAEA,aAAkB,oBAAsB,CAACA,EAAO,IAAK,OAE3D,MAAMC,EACJ,OAAO,YAAgB,KAAe,OAAO,YAAY,SAAY,WACjE,YAAY,QAAQ,GAAK,EACzB,OAEN,MAAM,IAAI,IAAI,2BAA4BD,EAAO,GAAG,EAAG,CACrD,YAAa,OACb,OAAAC,CAAA,CACD,EACE,KAAMC,GAAa,CAClB,GAAI,CAACA,EAAS,GAAI,MAAM,IAAI,MAAM,gBAAgBA,EAAS,MAAM,EAAE,EACnE,OAAOA,EAAS,KAAA,CAClB,CAAC,EACA,KAAMC,GAAS,CACd,MAAMC,EAAUD,EAAK,KAAA,EACrB,GAAI,CAAC,sCAAsC,KAAKC,CAAO,EACrD,MAAM,IAAI,MAAM,iBAAiB,EAEnC,MAAMC,EAAS,SAAS,cAAc,QAAQ,EAC9C,UAAWC,KAAQN,EAAO,oBAEpBM,IAAS,OAASA,IAAS,aAC/BD,EAAO,aAAaC,EAAMN,EAAO,aAAaM,CAAI,GAAK,EAAE,EAE3DD,EAAO,IAAM,IAAI,IAAI,eAAeD,CAAO,iBAAkBJ,EAAO,GAAG,EAAE,MACxE,SAAS,MAAQ,SAAS,iBAAiB,OAAOK,CAAM,CAC3D,CAAC,EACA,MAAM,IAAM,CACX,SAAS,cACP,IAAI,YAAY,eAAgB,CAC9B,OAAQ,CAAE,KAAM,iBAAkB,UAAW,EAAA,EAC7C,QAAS,GACT,SAAU,EAAA,CACX,CAAA,CAEL,CAAC,CACL,GAAA"}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
const h = /* @__PURE__ */ new Set([
|
|
2
|
+
"RATE_LIMITED",
|
|
3
|
+
"NETWORK_TIMEOUT",
|
|
4
|
+
"CHECKOUT_UNAVAILABLE",
|
|
5
|
+
"INTERNAL_ERROR"
|
|
6
|
+
]);
|
|
7
|
+
class r extends Error {
|
|
8
|
+
code;
|
|
9
|
+
retryable;
|
|
10
|
+
requestId;
|
|
11
|
+
capability;
|
|
12
|
+
constructor(e) {
|
|
13
|
+
super(e.message), this.name = "ViceMeError", this.code = e.code, this.retryable = e.retryable ?? h.has(e.code), this.requestId = e.requestId, this.capability = e.capability;
|
|
14
|
+
}
|
|
15
|
+
/** Safe, stable-shape serialization for logs and `viceme:error` events. */
|
|
16
|
+
toJSON() {
|
|
17
|
+
const e = { code: this.code, retryable: this.retryable };
|
|
18
|
+
return this.requestId !== void 0 && (e.requestId = this.requestId), this.capability !== void 0 && (e.capability = this.capability), e;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function D(t) {
|
|
22
|
+
return t instanceof r;
|
|
23
|
+
}
|
|
24
|
+
function o(t) {
|
|
25
|
+
return new r({ code: "CONFIG_INVALID", message: t, retryable: !1 });
|
|
26
|
+
}
|
|
27
|
+
function n() {
|
|
28
|
+
return new r({
|
|
29
|
+
code: "CLIENT_DESTROYED",
|
|
30
|
+
message: "ViceMe client has been destroyed.",
|
|
31
|
+
retryable: !1
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const d = /* @__PURE__ */ new Set(["cn", "global"]), f = {
|
|
35
|
+
cn: "https://api.viceme.cn",
|
|
36
|
+
global: "https://api.viceme.ai"
|
|
37
|
+
};
|
|
38
|
+
function R(t) {
|
|
39
|
+
return f[t];
|
|
40
|
+
}
|
|
41
|
+
function y(t) {
|
|
42
|
+
return typeof t == "string" && /^wrk_[A-Za-z0-9_-]{4,124}$/.test(t);
|
|
43
|
+
}
|
|
44
|
+
function u(t) {
|
|
45
|
+
return typeof t == "string" && d.has(t);
|
|
46
|
+
}
|
|
47
|
+
function k(t) {
|
|
48
|
+
if (typeof t != "object" || t === null)
|
|
49
|
+
throw o("createViceMe expects a configuration object.");
|
|
50
|
+
const e = t, s = /* @__PURE__ */ new Set(["workKey", "region", "signal"]);
|
|
51
|
+
for (const i of Object.keys(e))
|
|
52
|
+
if (!s.has(i))
|
|
53
|
+
throw o(`Unknown configuration field "${i}".`);
|
|
54
|
+
if (!y(e.workKey))
|
|
55
|
+
throw o('Configuration field "workKey" must be a public work key ("wrk_…").');
|
|
56
|
+
if (!u(e.region))
|
|
57
|
+
throw o('Configuration field "region" must be "cn" or "global".');
|
|
58
|
+
if (e.signal !== void 0 && !(e.signal instanceof AbortSignal))
|
|
59
|
+
throw o('Configuration field "signal" must be an AbortSignal.');
|
|
60
|
+
return { workKey: e.workKey, region: e.region, signal: e.signal };
|
|
61
|
+
}
|
|
62
|
+
const E = {
|
|
63
|
+
CREATED: ["INITIALIZING", "DESTROYED"],
|
|
64
|
+
INITIALIZING: ["READY", "FAILED", "DESTROYED"],
|
|
65
|
+
READY: ["DEGRADED", "DESTROYED"],
|
|
66
|
+
DEGRADED: ["DESTROYED"],
|
|
67
|
+
FAILED: ["INITIALIZING", "DESTROYED"],
|
|
68
|
+
DESTROYED: []
|
|
69
|
+
};
|
|
70
|
+
class g {
|
|
71
|
+
#e = "CREATED";
|
|
72
|
+
#t = /* @__PURE__ */ new Set();
|
|
73
|
+
get state() {
|
|
74
|
+
return this.#e;
|
|
75
|
+
}
|
|
76
|
+
get destroyed() {
|
|
77
|
+
return this.#e === "DESTROYED";
|
|
78
|
+
}
|
|
79
|
+
transition(e) {
|
|
80
|
+
if (e !== this.#e) {
|
|
81
|
+
if (!E[this.#e].includes(e))
|
|
82
|
+
throw new r({
|
|
83
|
+
code: "INTERNAL_ERROR",
|
|
84
|
+
message: `Illegal lifecycle transition ${this.#e} -> ${e}.`,
|
|
85
|
+
retryable: !1
|
|
86
|
+
});
|
|
87
|
+
this.#e = e;
|
|
88
|
+
for (const s of this.#t) s(e);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** Any operation on a destroyed client must fail closed with this guard. */
|
|
92
|
+
assertAlive() {
|
|
93
|
+
if (this.destroyed) throw n();
|
|
94
|
+
}
|
|
95
|
+
subscribe(e) {
|
|
96
|
+
return this.#t.add(e), () => {
|
|
97
|
+
this.#t.delete(e);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
clearListeners() {
|
|
101
|
+
this.#t.clear();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function w(t, e) {
|
|
105
|
+
if (typeof t != "object" || t === null)
|
|
106
|
+
throw c();
|
|
107
|
+
const s = t, i = s.work;
|
|
108
|
+
if (typeof i != "object" || i === null || typeof i.key != "string" || !Array.isArray(i.capabilities) || !i.capabilities.every((l) => typeof l == "string"))
|
|
109
|
+
throw c();
|
|
110
|
+
if (i.key !== e)
|
|
111
|
+
throw new r({
|
|
112
|
+
code: "WORK_NOT_FOUND",
|
|
113
|
+
message: "Work-session response did not match the requested work key.",
|
|
114
|
+
retryable: !1
|
|
115
|
+
});
|
|
116
|
+
const a = {
|
|
117
|
+
work: {
|
|
118
|
+
key: i.key,
|
|
119
|
+
capabilities: i.capabilities
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
return typeof s.token == "string" && (a.token = s.token), typeof s.expiresAt == "number" && (a.expiresAt = s.expiresAt), a;
|
|
123
|
+
}
|
|
124
|
+
function c() {
|
|
125
|
+
return new r({
|
|
126
|
+
code: "INTERNAL_ERROR",
|
|
127
|
+
message: "Malformed work-session response.",
|
|
128
|
+
retryable: !0
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
class b {
|
|
132
|
+
#e;
|
|
133
|
+
#t;
|
|
134
|
+
#s;
|
|
135
|
+
#i;
|
|
136
|
+
constructor(e) {
|
|
137
|
+
this.#e = e, this.#t = e.now ?? (() => Date.now());
|
|
138
|
+
}
|
|
139
|
+
get snapshot() {
|
|
140
|
+
return this.#s;
|
|
141
|
+
}
|
|
142
|
+
/** True when the cached snapshot's server-provided expiry has passed. */
|
|
143
|
+
#r() {
|
|
144
|
+
const e = this.#s?.expiresAt;
|
|
145
|
+
return e !== void 0 && e <= this.#t();
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Establish (or return the established) public session.
|
|
149
|
+
*
|
|
150
|
+
* A cached snapshot is reused only while it is unexpired; an expired
|
|
151
|
+
* snapshot is dropped and re-authenticated. Concurrent callers share one
|
|
152
|
+
* in-flight request (single flight).
|
|
153
|
+
*/
|
|
154
|
+
establish() {
|
|
155
|
+
if (this.#s) {
|
|
156
|
+
if (!this.#r()) return Promise.resolve(this.#s);
|
|
157
|
+
this.#s = void 0;
|
|
158
|
+
}
|
|
159
|
+
return this.#i ??= this.#e.transport.request({
|
|
160
|
+
method: "POST",
|
|
161
|
+
path: "/public/v1/work-sessions",
|
|
162
|
+
body: { workKey: this.#e.workKey },
|
|
163
|
+
signal: this.#e.signal,
|
|
164
|
+
timeoutMs: this.#e.timeoutMs
|
|
165
|
+
}).then((e) => {
|
|
166
|
+
const s = w(e.body, this.#e.workKey);
|
|
167
|
+
return this.#s = s, s;
|
|
168
|
+
}).finally(() => {
|
|
169
|
+
this.#i = void 0;
|
|
170
|
+
}), this.#i;
|
|
171
|
+
}
|
|
172
|
+
/** Drop the token; next `establish()` re-authenticates. */
|
|
173
|
+
invalidate() {
|
|
174
|
+
this.#s = void 0;
|
|
175
|
+
}
|
|
176
|
+
/** Hard cleanup: forget the token and pending work. */
|
|
177
|
+
destroy() {
|
|
178
|
+
this.invalidate(), this.#i = void 0;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const p = "0.1.2", I = 1;
|
|
182
|
+
class A extends DOMException {
|
|
183
|
+
constructor() {
|
|
184
|
+
super("ViceMe client destroyed.", "AbortError");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
class S {
|
|
188
|
+
#e = new g();
|
|
189
|
+
#t;
|
|
190
|
+
#s;
|
|
191
|
+
#i = new AbortController();
|
|
192
|
+
#r;
|
|
193
|
+
constructor(e) {
|
|
194
|
+
this.#s = e.config, this.#t = new b({
|
|
195
|
+
workKey: e.config.workKey,
|
|
196
|
+
transport: e.transport,
|
|
197
|
+
signal: this.#i.signal,
|
|
198
|
+
...e.now !== void 0 ? { now: e.now } : {}
|
|
199
|
+
});
|
|
200
|
+
const s = e.config.signal;
|
|
201
|
+
if (s) {
|
|
202
|
+
const i = () => {
|
|
203
|
+
this.#i.abort(
|
|
204
|
+
s.reason instanceof Error ? s.reason : new DOMException("Caller signal aborted.", "AbortError")
|
|
205
|
+
);
|
|
206
|
+
};
|
|
207
|
+
s.aborted ? i() : s.addEventListener("abort", i, { once: !0 });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
get version() {
|
|
211
|
+
return p;
|
|
212
|
+
}
|
|
213
|
+
get workKey() {
|
|
214
|
+
return this.#s.workKey;
|
|
215
|
+
}
|
|
216
|
+
get region() {
|
|
217
|
+
return this.#s.region;
|
|
218
|
+
}
|
|
219
|
+
get state() {
|
|
220
|
+
return this.#e.state;
|
|
221
|
+
}
|
|
222
|
+
/** Internal: public API major, used by the loader registry namespace. */
|
|
223
|
+
get apiMajor() {
|
|
224
|
+
return I;
|
|
225
|
+
}
|
|
226
|
+
ready() {
|
|
227
|
+
return this.#e.destroyed ? Promise.reject(n()) : (this.#r ??= this.#o(), this.#r);
|
|
228
|
+
}
|
|
229
|
+
async #o() {
|
|
230
|
+
if (this.#e.destroyed) throw n();
|
|
231
|
+
this.#e.transition("INITIALIZING");
|
|
232
|
+
try {
|
|
233
|
+
if (await this.#t.establish(), this.#e.destroyed) throw n();
|
|
234
|
+
this.#e.transition("READY");
|
|
235
|
+
} catch (e) {
|
|
236
|
+
throw this.#e.destroyed ? n() : (this.#e.transition("FAILED"), this.#r = void 0, this.#t.invalidate(), e);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
hasCapability(e) {
|
|
240
|
+
if (this.#e.destroyed) return !1;
|
|
241
|
+
const s = this.#t.snapshot?.work.capabilities;
|
|
242
|
+
return s !== void 0 && s.includes(e);
|
|
243
|
+
}
|
|
244
|
+
/** Names of capabilities enabled for this work (empty before `ready()`). */
|
|
245
|
+
get capabilities() {
|
|
246
|
+
return this.#t.snapshot?.work.capabilities ?? [];
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Internal: mark one capability unavailable without taking down the client
|
|
250
|
+
* (loader uses this when a feature chunk fails after the core is READY).
|
|
251
|
+
*/
|
|
252
|
+
markDegraded() {
|
|
253
|
+
this.#e.state === "READY" && this.#e.transition("DEGRADED");
|
|
254
|
+
}
|
|
255
|
+
/** Internal: session snapshot access for capability modules. */
|
|
256
|
+
get sessionSnapshot() {
|
|
257
|
+
return this.#t.snapshot;
|
|
258
|
+
}
|
|
259
|
+
destroy() {
|
|
260
|
+
this.#e.destroyed || (this.#e.transition("DESTROYED"), this.#i.abort(new A()), this.#t.destroy(), this.#e.clearListeners(), this.#r = void 0);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
export {
|
|
264
|
+
I as A,
|
|
265
|
+
p as S,
|
|
266
|
+
r as V,
|
|
267
|
+
S as a,
|
|
268
|
+
y as b,
|
|
269
|
+
o as c,
|
|
270
|
+
u as d,
|
|
271
|
+
D as i,
|
|
272
|
+
R as r,
|
|
273
|
+
k as v
|
|
274
|
+
};
|
|
275
|
+
//# sourceMappingURL=client-CGU3qeew.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-CGU3qeew.js","sources":["../../src/core/errors.ts","../../src/core/config.ts","../../src/core/lifecycle.ts","../../src/session/session.ts","../../src/version.ts","../../src/core/client.ts"],"sourcesContent":["/**\n * Public error model.\n *\n * Consumers branch on the stable `code` only — never on `message` text.\n * Error payloads must never contain provider responses, tokens, cookies, or\n * internal stack traces; `toJSON()` exposes the safe diagnostic subset.\n */\n\nexport type ViceMeErrorCode =\n | 'CONFIG_INVALID'\n | 'WORK_NOT_FOUND'\n | 'ORIGIN_NOT_ALLOWED'\n | 'CAPABILITY_DISABLED'\n | 'CLIENT_DESTROYED'\n | 'SESSION_EXPIRED'\n | 'RATE_LIMITED'\n | 'NETWORK_TIMEOUT'\n | 'CHECKOUT_UNAVAILABLE'\n | 'INTERNAL_ERROR';\n\nexport interface ViceMeErrorInit {\n code: ViceMeErrorCode;\n message: string;\n retryable?: boolean;\n /** Server-assigned request id echoed back for support correlation. */\n requestId?: string;\n /** Capability the error belongs to, when scoped to one. */\n capability?: string;\n}\n\nconst RETRYABLE_BY_DEFAULT: ReadonlySet<ViceMeErrorCode> = new Set([\n 'RATE_LIMITED',\n 'NETWORK_TIMEOUT',\n 'CHECKOUT_UNAVAILABLE',\n 'INTERNAL_ERROR',\n]);\n\nexport class ViceMeError extends Error {\n readonly code: ViceMeErrorCode;\n readonly retryable: boolean;\n readonly requestId?: string;\n readonly capability?: string;\n\n constructor(init: ViceMeErrorInit) {\n super(init.message);\n this.name = 'ViceMeError';\n this.code = init.code;\n this.retryable = init.retryable ?? RETRYABLE_BY_DEFAULT.has(init.code);\n this.requestId = init.requestId;\n this.capability = init.capability;\n }\n\n /** Safe, stable-shape serialization for logs and `viceme:error` events. */\n toJSON(): {\n code: ViceMeErrorCode;\n retryable: boolean;\n requestId?: string;\n capability?: string;\n } {\n const json: {\n code: ViceMeErrorCode;\n retryable: boolean;\n requestId?: string;\n capability?: string;\n } = { code: this.code, retryable: this.retryable };\n if (this.requestId !== undefined) json.requestId = this.requestId;\n if (this.capability !== undefined) json.capability = this.capability;\n return json;\n }\n}\n\nexport function isViceMeError(value: unknown): value is ViceMeError {\n return value instanceof ViceMeError;\n}\n\n/** Build a CONFIG_INVALID error with a stable, non-sensitive message. */\nexport function configInvalid(message: string): ViceMeError {\n return new ViceMeError({ code: 'CONFIG_INVALID', message, retryable: false });\n}\n\n/** Build a CLIENT_DESTROYED error for post-destroy calls. */\nexport function clientDestroyed(): ViceMeError {\n return new ViceMeError({\n code: 'CLIENT_DESTROYED',\n message: 'ViceMe client has been destroyed.',\n retryable: false,\n });\n}\n","/**\n * Public client configuration.\n *\n * Production `createViceMe()` accepts exactly `workKey`, `region`, and\n * `signal`. Anything else (transport, clock, request ids, base URLs) is a\n * testing-only concern and lives in `@viceme-ai/sdk/testing`, so Agents can\n * never bake temporary or internal endpoints into user projects.\n */\n\nimport { configInvalid } from './errors.ts';\n\nexport type ViceMeRegion = 'cn' | 'global';\n\nexport interface ViceMeConfig {\n /** Public opaque work key (`wrk_…`). Locates a Work; it is not a secret. */\n workKey: string;\n /** Routes public API and CDN traffic. */\n region: ViceMeRegion;\n /** Optional abort signal owned by the host page. */\n signal?: AbortSignal;\n}\n\nconst REGIONS: ReadonlySet<string> = new Set(['cn', 'global']);\n\n/**\n * Public API origins per region. These are the only production endpoints the\n * SDK may contact; B1 confirms final hostnames and any change happens here in\n * one place (never via a public `apiBaseUrl` option).\n */\nexport const PUBLIC_API_BASE_URLS: Readonly<Record<ViceMeRegion, string>> = {\n cn: 'https://api.viceme.cn',\n global: 'https://api.viceme.ai',\n};\n\nexport function resolveApiBaseUrl(region: ViceMeRegion): string {\n return PUBLIC_API_BASE_URLS[region];\n}\n\nexport function isValidWorkKey(value: unknown): value is string {\n return typeof value === 'string' && /^wrk_[A-Za-z0-9_-]{4,124}$/.test(value);\n}\n\nexport function isValidRegion(value: unknown): value is ViceMeRegion {\n return typeof value === 'string' && REGIONS.has(value);\n}\n\n/**\n * Validate unknown input as a public client config. Throws a CONFIG_INVALID\n * ViceMeError that never echoes values back beyond the offending field name.\n */\nexport function validatePublicConfig(input: unknown): ViceMeConfig {\n if (typeof input !== 'object' || input === null) {\n throw configInvalid('createViceMe expects a configuration object.');\n }\n const raw = input as Record<string, unknown>;\n\n const known = new Set(['workKey', 'region', 'signal']);\n for (const key of Object.keys(raw)) {\n if (!known.has(key)) {\n throw configInvalid(`Unknown configuration field \"${key}\".`);\n }\n }\n if (!isValidWorkKey(raw.workKey)) {\n throw configInvalid('Configuration field \"workKey\" must be a public work key (\"wrk_…\").');\n }\n if (!isValidRegion(raw.region)) {\n throw configInvalid('Configuration field \"region\" must be \"cn\" or \"global\".');\n }\n if (raw.signal !== undefined && !(raw.signal instanceof AbortSignal)) {\n throw configInvalid('Configuration field \"signal\" must be an AbortSignal.');\n }\n return { workKey: raw.workKey, region: raw.region, signal: raw.signal };\n}\n","/**\n * Client lifecycle state machine.\n *\n * ```text\n * CREATED -> INITIALIZING -> READY -> DESTROYED\n * INITIALIZING -> FAILED (retryable: FAILED -> INITIALIZING)\n * READY -> DEGRADED (single capability unavailable; host page keeps working)\n * DEGRADED -> READY (when all capabilities recover is a B1+ concern)\n * ```\n *\n * State is exposed read-only; consumers can never assign it directly.\n */\n\nimport { ViceMeError, clientDestroyed } from './errors.ts';\n\nexport type ViceMeClientState =\n 'CREATED' | 'INITIALIZING' | 'READY' | 'DEGRADED' | 'FAILED' | 'DESTROYED';\n\nconst ALLOWED_TRANSITIONS: Readonly<Record<ViceMeClientState, readonly ViceMeClientState[]>> = {\n CREATED: ['INITIALIZING', 'DESTROYED'],\n INITIALIZING: ['READY', 'FAILED', 'DESTROYED'],\n READY: ['DEGRADED', 'DESTROYED'],\n DEGRADED: ['DESTROYED'],\n FAILED: ['INITIALIZING', 'DESTROYED'],\n DESTROYED: [],\n};\n\nexport type LifecycleListener = (state: ViceMeClientState) => void;\n\nexport class Lifecycle {\n #state: ViceMeClientState = 'CREATED';\n #listeners = new Set<LifecycleListener>();\n\n get state(): ViceMeClientState {\n return this.#state;\n }\n\n get destroyed(): boolean {\n return this.#state === 'DESTROYED';\n }\n\n transition(next: ViceMeClientState): void {\n if (next === this.#state) return;\n if (!ALLOWED_TRANSITIONS[this.#state]!.includes(next)) {\n throw new ViceMeError({\n code: 'INTERNAL_ERROR',\n message: `Illegal lifecycle transition ${this.#state} -> ${next}.`,\n retryable: false,\n });\n }\n this.#state = next;\n for (const listener of this.#listeners) listener(next);\n }\n\n /** Any operation on a destroyed client must fail closed with this guard. */\n assertAlive(): void {\n if (this.destroyed) throw clientDestroyed();\n }\n\n subscribe(listener: LifecycleListener): () => void {\n this.#listeners.add(listener);\n return () => {\n this.#listeners.delete(listener);\n };\n }\n\n clearListeners(): void {\n this.#listeners.clear();\n }\n}\n","/**\n * Public visitor session.\n *\n * ```text\n * SDK + workKey + Origin -> POST /public/v1/work-sessions\n * -> short-lived capability token -> public capability calls\n * ```\n *\n * The token lives in memory only (never localStorage/cookies), is bound to the\n * Work, Origin, capability set, and expiry by the server, and is dropped on\n * `destroy()`. `workKey` locates the Work — it is never an authorization\n * credential.\n */\n\nimport { ViceMeError } from '../core/errors.ts';\nimport type { Transport } from '../transport/transport.ts';\nimport type { components } from '../generated/public-contract.ts';\n\n/**\n * DTO shapes come from the generated public contract snapshot — the SDK never\n * hand-writes a second copy of the server DTOs. The runtime validator below\n * stays intentionally narrow (required fields of the current contract only).\n */\ntype WorkSessionDto = components['schemas']['WorkSession'];\nexport type CreateWorkSessionRequestDto = components['schemas']['CreateWorkSessionRequest'];\n\nexport interface WorkDescriptor {\n key: string;\n /** Capability names enabled for this work. */\n capabilities: string[];\n}\n\nexport interface WorkSessionSnapshot {\n work: WorkDescriptor;\n /** Opaque short-lived capability token; memory-only. */\n token?: string;\n /** Epoch milliseconds when the token expires, when provided by the server. */\n expiresAt?: number;\n}\n\nexport interface SessionManagerOptions {\n workKey: string;\n transport: Transport;\n signal?: AbortSignal;\n timeoutMs?: number;\n /** Injectable clock for tests. */\n now?: () => number;\n}\n\nfunction parseSessionResponse(body: unknown, workKey: string): WorkSessionSnapshot {\n if (typeof body !== 'object' || body === null) {\n throw malformedSessionResponse();\n }\n const raw = body as WorkSessionDto;\n const work = raw.work as { key?: unknown; capabilities?: unknown } | undefined;\n if (\n typeof work !== 'object' ||\n work === null ||\n typeof work.key !== 'string' ||\n !Array.isArray(work.capabilities) ||\n !work.capabilities.every((c) => typeof c === 'string')\n ) {\n throw malformedSessionResponse();\n }\n if (work.key !== workKey) {\n throw new ViceMeError({\n code: 'WORK_NOT_FOUND',\n message: 'Work-session response did not match the requested work key.',\n retryable: false,\n });\n }\n const snapshot: WorkSessionSnapshot = {\n work: {\n key: work.key,\n capabilities: work.capabilities as string[],\n },\n };\n // Unknown extra fields are allowed and ignored (forward compatibility).\n if (typeof raw.token === 'string') snapshot.token = raw.token;\n if (typeof raw.expiresAt === 'number') snapshot.expiresAt = raw.expiresAt;\n return snapshot;\n}\n\nfunction malformedSessionResponse(): ViceMeError {\n return new ViceMeError({\n code: 'INTERNAL_ERROR',\n message: 'Malformed work-session response.',\n retryable: true,\n });\n}\n\nexport class SessionManager {\n readonly #options: SessionManagerOptions;\n readonly #now: () => number;\n #snapshot: WorkSessionSnapshot | undefined;\n #pending: Promise<WorkSessionSnapshot> | undefined;\n\n constructor(options: SessionManagerOptions) {\n this.#options = options;\n this.#now = options.now ?? (() => Date.now());\n }\n\n get snapshot(): WorkSessionSnapshot | undefined {\n return this.#snapshot;\n }\n\n /** True when the cached snapshot's server-provided expiry has passed. */\n #isExpired(): boolean {\n const expiresAt = this.#snapshot?.expiresAt;\n return expiresAt !== undefined && expiresAt <= this.#now();\n }\n\n /**\n * Establish (or return the established) public session.\n *\n * A cached snapshot is reused only while it is unexpired; an expired\n * snapshot is dropped and re-authenticated. Concurrent callers share one\n * in-flight request (single flight).\n */\n establish(): Promise<WorkSessionSnapshot> {\n if (this.#snapshot) {\n if (!this.#isExpired()) return Promise.resolve(this.#snapshot);\n this.#snapshot = undefined;\n }\n this.#pending ??= this.#options.transport\n .request({\n method: 'POST',\n path: '/public/v1/work-sessions',\n body: { workKey: this.#options.workKey } satisfies CreateWorkSessionRequestDto,\n signal: this.#options.signal,\n timeoutMs: this.#options.timeoutMs,\n })\n .then((response) => {\n const snapshot = parseSessionResponse(response.body, this.#options.workKey);\n this.#snapshot = snapshot;\n return snapshot;\n })\n .finally(() => {\n this.#pending = undefined;\n });\n return this.#pending;\n }\n\n /** Drop the token; next `establish()` re-authenticates. */\n invalidate(): void {\n this.#snapshot = undefined;\n }\n\n /** Hard cleanup: forget the token and pending work. */\n destroy(): void {\n this.invalidate();\n this.#pending = undefined;\n }\n}\n","/**\n * Single source of truth for the SDK runtime version.\n *\n * Kept in sync with `packages/sdk/package.json#version`; a unit test enforces\n * the match so the loader, release manifest, and npm metadata can never drift.\n */\nexport const SDK_VERSION = '0.1.2';\n\n/** Public API major carried by this build (loader namespace `v1`). */\nexport const API_MAJOR = 1;\n","/**\n * Headless ViceMe client.\n *\n * The core never touches the DOM: `document`, auto-mount, and UI lifecycle\n * live exclusively in the loader and capability `mount` layers. `ready()` is\n * idempotent per instance (shares one promise), `destroy()` is idempotent and\n * synchronously cancels requests and subscriptions; every business method on a\n * destroyed client fails with `CLIENT_DESTROYED`.\n */\n\nimport { clientDestroyed } from './errors.ts';\nimport { Lifecycle, type ViceMeClientState } from './lifecycle.ts';\nimport type { ViceMeConfig, ViceMeRegion } from './config.ts';\nimport { SessionManager } from '../session/session.ts';\nimport type { Transport } from '../transport/transport.ts';\nimport { API_MAJOR, SDK_VERSION } from '../version.ts';\n\nexport interface ViceMeClient {\n readonly version: string;\n readonly workKey: string;\n readonly region: ViceMeRegion;\n readonly state: ViceMeClientState;\n ready(): Promise<void>;\n hasCapability(name: string): boolean;\n destroy(): void;\n}\n\nexport interface ViceMeMountedInstance {\n readonly instanceKey: string;\n readonly capability: string;\n destroy(): void;\n}\n\n/** Marker so in-flight requests cancelled by `destroy()` map to CLIENT_DESTROYED. */\nclass DestroySignalReason extends DOMException {\n constructor() {\n super('ViceMe client destroyed.', 'AbortError');\n }\n}\n\nexport interface ViceMeClientDeps {\n config: ViceMeConfig;\n transport: Transport;\n /** Injectable clock (testing only). */\n now?: () => number;\n}\n\nexport class ViceMeClientImpl implements ViceMeClient {\n readonly #lifecycle = new Lifecycle();\n readonly #session: SessionManager;\n readonly #config: ViceMeConfig;\n readonly #internalSignal = new AbortController();\n #readyPromise: Promise<void> | undefined;\n\n constructor(deps: ViceMeClientDeps) {\n this.#config = deps.config;\n this.#session = new SessionManager({\n workKey: deps.config.workKey,\n transport: deps.transport,\n signal: this.#internalSignal.signal,\n ...(deps.now !== undefined ? { now: deps.now } : {}),\n });\n const callerSignal = deps.config.signal;\n if (callerSignal) {\n // Propagate the caller's own abort reason when one was set.\n const abortInternal = () => {\n this.#internalSignal.abort(\n callerSignal.reason instanceof Error\n ? callerSignal.reason\n : new DOMException('Caller signal aborted.', 'AbortError'),\n );\n };\n // An already-aborted signal never fires the listener; check\n // synchronously so a pre-cancelled caller cannot issue session\n // requests or reach the network at all.\n if (callerSignal.aborted) abortInternal();\n else callerSignal.addEventListener('abort', abortInternal, { once: true });\n }\n }\n\n get version(): string {\n return SDK_VERSION;\n }\n\n get workKey(): string {\n return this.#config.workKey;\n }\n\n get region(): ViceMeRegion {\n return this.#config.region;\n }\n\n get state(): ViceMeClientState {\n return this.#lifecycle.state;\n }\n\n /** Internal: public API major, used by the loader registry namespace. */\n get apiMajor(): number {\n return API_MAJOR;\n }\n\n ready(): Promise<void> {\n if (this.#lifecycle.destroyed) return Promise.reject(clientDestroyed());\n this.#readyPromise ??= this.#initialize();\n return this.#readyPromise;\n }\n\n async #initialize(): Promise<void> {\n if (this.#lifecycle.destroyed) throw clientDestroyed();\n this.#lifecycle.transition('INITIALIZING');\n try {\n await this.#session.establish();\n if (this.#lifecycle.destroyed) throw clientDestroyed();\n this.#lifecycle.transition('READY');\n } catch (error) {\n // If the client was destroyed mid-flight, report CLIENT_DESTROYED and do\n // not attempt any further lifecycle transitions.\n if (this.#lifecycle.destroyed) throw clientDestroyed();\n this.#lifecycle.transition('FAILED');\n // Allow a later `ready()` retry instead of caching the failure forever.\n this.#readyPromise = undefined;\n this.#session.invalidate();\n throw error;\n }\n }\n\n hasCapability(name: string): boolean {\n if (this.#lifecycle.destroyed) return false;\n const capabilities = this.#session.snapshot?.work.capabilities;\n return capabilities !== undefined && capabilities.includes(name);\n }\n\n /** Names of capabilities enabled for this work (empty before `ready()`). */\n get capabilities(): readonly string[] {\n return this.#session.snapshot?.work.capabilities ?? [];\n }\n\n /**\n * Internal: mark one capability unavailable without taking down the client\n * (loader uses this when a feature chunk fails after the core is READY).\n */\n markDegraded(): void {\n if (this.#lifecycle.state === 'READY') this.#lifecycle.transition('DEGRADED');\n }\n\n /** Internal: session snapshot access for capability modules. */\n get sessionSnapshot() {\n return this.#session.snapshot;\n }\n\n destroy(): void {\n if (this.#lifecycle.destroyed) return;\n this.#lifecycle.transition('DESTROYED');\n this.#internalSignal.abort(new DestroySignalReason());\n this.#session.destroy();\n this.#lifecycle.clearListeners();\n this.#readyPromise = undefined;\n }\n}\n"],"names":["RETRYABLE_BY_DEFAULT","ViceMeError","init","json","isViceMeError","value","configInvalid","message","clientDestroyed","REGIONS","PUBLIC_API_BASE_URLS","resolveApiBaseUrl","region","isValidWorkKey","isValidRegion","validatePublicConfig","input","raw","known","key","ALLOWED_TRANSITIONS","Lifecycle","#state","#listeners","next","listener","parseSessionResponse","body","workKey","malformedSessionResponse","work","c","snapshot","SessionManager","#options","#now","#snapshot","#pending","options","#isExpired","expiresAt","response","SDK_VERSION","API_MAJOR","DestroySignalReason","ViceMeClientImpl","#lifecycle","#session","#config","#internalSignal","#readyPromise","deps","callerSignal","abortInternal","#initialize","error","name","capabilities"],"mappings":"AA8BA,MAAMA,wBAAyD,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,OAAO;AAAA,IACpC,SAASS,GAAO;AAGd,YAAI,KAAKT,GAAW,YAAiBtC,EAAA,KACrC,KAAKsC,GAAW,WAAW,QAAQ,GAEnC,KAAKI,KAAgB,QACrB,KAAKH,GAAS,WAAA,GACRQ;AAAA,IACR;AAAA,EACF;AAAA,EAEA,cAAcC,GAAuB;AACnC,QAAI,KAAKV,GAAW,UAAW,QAAO;AACtC,UAAMW,IAAe,KAAKV,GAAS,UAAU,KAAK;AAClD,WAAOU,MAAiB,UAAaA,EAAa,SAASD,CAAI;AAAA,EACjE;AAAA;AAAA,EAGA,IAAI,eAAkC;AACpC,WAAO,KAAKT,GAAS,UAAU,KAAK,gBAAgB,CAAA;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,eAAqB;AACnB,IAAI,KAAKD,GAAW,UAAU,WAAS,KAAKA,GAAW,WAAW,UAAU;AAAA,EAC9E;AAAA;AAAA,EAGA,IAAI,kBAAkB;AACpB,WAAO,KAAKC,GAAS;AAAA,EACvB;AAAA,EAEA,UAAgB;AACd,IAAI,KAAKD,GAAW,cACpB,KAAKA,GAAW,WAAW,WAAW,GACtC,KAAKG,GAAgB,MAAM,IAAIL,EAAA,CAAqB,GACpD,KAAKG,GAAS,QAAA,GACd,KAAKD,GAAW,eAAA,GAChB,KAAKI,KAAgB;AAAA,EACvB;AACF;"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless ViceMe client.
|
|
3
|
+
*
|
|
4
|
+
* The core never touches the DOM: `document`, auto-mount, and UI lifecycle
|
|
5
|
+
* live exclusively in the loader and capability `mount` layers. `ready()` is
|
|
6
|
+
* idempotent per instance (shares one promise), `destroy()` is idempotent and
|
|
7
|
+
* synchronously cancels requests and subscriptions; every business method on a
|
|
8
|
+
* destroyed client fails with `CLIENT_DESTROYED`.
|
|
9
|
+
*/
|
|
10
|
+
import { type ViceMeClientState } from './lifecycle.ts';
|
|
11
|
+
import type { ViceMeConfig, ViceMeRegion } from './config.ts';
|
|
12
|
+
import type { Transport } from '../transport/transport.ts';
|
|
13
|
+
export interface ViceMeClient {
|
|
14
|
+
readonly version: string;
|
|
15
|
+
readonly workKey: string;
|
|
16
|
+
readonly region: ViceMeRegion;
|
|
17
|
+
readonly state: ViceMeClientState;
|
|
18
|
+
ready(): Promise<void>;
|
|
19
|
+
hasCapability(name: string): boolean;
|
|
20
|
+
destroy(): void;
|
|
21
|
+
}
|
|
22
|
+
export interface ViceMeMountedInstance {
|
|
23
|
+
readonly instanceKey: string;
|
|
24
|
+
readonly capability: string;
|
|
25
|
+
destroy(): void;
|
|
26
|
+
}
|
|
27
|
+
export interface ViceMeClientDeps {
|
|
28
|
+
config: ViceMeConfig;
|
|
29
|
+
transport: Transport;
|
|
30
|
+
/** Injectable clock (testing only). */
|
|
31
|
+
now?: () => number;
|
|
32
|
+
}
|
|
33
|
+
export declare class ViceMeClientImpl implements ViceMeClient {
|
|
34
|
+
#private;
|
|
35
|
+
constructor(deps: ViceMeClientDeps);
|
|
36
|
+
get version(): string;
|
|
37
|
+
get workKey(): string;
|
|
38
|
+
get region(): ViceMeRegion;
|
|
39
|
+
get state(): ViceMeClientState;
|
|
40
|
+
/** Internal: public API major, used by the loader registry namespace. */
|
|
41
|
+
get apiMajor(): number;
|
|
42
|
+
ready(): Promise<void>;
|
|
43
|
+
hasCapability(name: string): boolean;
|
|
44
|
+
/** Names of capabilities enabled for this work (empty before `ready()`). */
|
|
45
|
+
get capabilities(): readonly string[];
|
|
46
|
+
/**
|
|
47
|
+
* Internal: mark one capability unavailable without taking down the client
|
|
48
|
+
* (loader uses this when a feature chunk fails after the core is READY).
|
|
49
|
+
*/
|
|
50
|
+
markDegraded(): void;
|
|
51
|
+
/** Internal: session snapshot access for capability modules. */
|
|
52
|
+
get sessionSnapshot(): import("../session/session.ts").WorkSessionSnapshot | undefined;
|
|
53
|
+
destroy(): void;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=client.d.ts.map
|
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C,IAAI,CAAC;IAyBtB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAMpC,4EAA4E;IAC5E,IAAI,YAAY,IAAI,SAAS,MAAM,EAAE,CAEpC;IAED;;;OAGG;IACH,YAAY,IAAI,IAAI;IAIpB,gEAAgE;IAChE,IAAI,eAAe,oEAElB;IAED,OAAO,IAAI,IAAI;CAQhB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public client configuration.
|
|
3
|
+
*
|
|
4
|
+
* Production `createViceMe()` accepts exactly `workKey`, `region`, and
|
|
5
|
+
* `signal`. Anything else (transport, clock, request ids, base URLs) is a
|
|
6
|
+
* testing-only concern and lives in `@viceme-ai/sdk/testing`, so Agents can
|
|
7
|
+
* never bake temporary or internal endpoints into user projects.
|
|
8
|
+
*/
|
|
9
|
+
export type ViceMeRegion = 'cn' | 'global';
|
|
10
|
+
export interface ViceMeConfig {
|
|
11
|
+
/** Public opaque work key (`wrk_…`). Locates a Work; it is not a secret. */
|
|
12
|
+
workKey: string;
|
|
13
|
+
/** Routes public API and CDN traffic. */
|
|
14
|
+
region: ViceMeRegion;
|
|
15
|
+
/** Optional abort signal owned by the host page. */
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Public API origins per region. These are the only production endpoints the
|
|
20
|
+
* SDK may contact; B1 confirms final hostnames and any change happens here in
|
|
21
|
+
* one place (never via a public `apiBaseUrl` option).
|
|
22
|
+
*/
|
|
23
|
+
export declare const PUBLIC_API_BASE_URLS: Readonly<Record<ViceMeRegion, string>>;
|
|
24
|
+
export declare function resolveApiBaseUrl(region: ViceMeRegion): string;
|
|
25
|
+
export declare function isValidWorkKey(value: unknown): value is string;
|
|
26
|
+
export declare function isValidRegion(value: unknown): value is ViceMeRegion;
|
|
27
|
+
/**
|
|
28
|
+
* Validate unknown input as a public client config. Throws a CONFIG_INVALID
|
|
29
|
+
* ViceMeError that never echoes values back beyond the offending field name.
|
|
30
|
+
*/
|
|
31
|
+
export declare function validatePublicConfig(input: unknown): ViceMeConfig;
|
|
32
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,QAAQ,CAAC;AAE3C,MAAM,WAAW,YAAY;IAC3B,4EAA4E;IAC5E,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,MAAM,EAAE,YAAY,CAAC;IACrB,oDAAoD;IACpD,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAID;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAGvE,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAE9D;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE9D;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEnE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAsBjE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public error model.
|
|
3
|
+
*
|
|
4
|
+
* Consumers branch on the stable `code` only — never on `message` text.
|
|
5
|
+
* Error payloads must never contain provider responses, tokens, cookies, or
|
|
6
|
+
* internal stack traces; `toJSON()` exposes the safe diagnostic subset.
|
|
7
|
+
*/
|
|
8
|
+
export type ViceMeErrorCode = 'CONFIG_INVALID' | 'WORK_NOT_FOUND' | 'ORIGIN_NOT_ALLOWED' | 'CAPABILITY_DISABLED' | 'CLIENT_DESTROYED' | 'SESSION_EXPIRED' | 'RATE_LIMITED' | 'NETWORK_TIMEOUT' | 'CHECKOUT_UNAVAILABLE' | 'INTERNAL_ERROR';
|
|
9
|
+
export interface ViceMeErrorInit {
|
|
10
|
+
code: ViceMeErrorCode;
|
|
11
|
+
message: string;
|
|
12
|
+
retryable?: boolean;
|
|
13
|
+
/** Server-assigned request id echoed back for support correlation. */
|
|
14
|
+
requestId?: string;
|
|
15
|
+
/** Capability the error belongs to, when scoped to one. */
|
|
16
|
+
capability?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare class ViceMeError extends Error {
|
|
19
|
+
readonly code: ViceMeErrorCode;
|
|
20
|
+
readonly retryable: boolean;
|
|
21
|
+
readonly requestId?: string;
|
|
22
|
+
readonly capability?: string;
|
|
23
|
+
constructor(init: ViceMeErrorInit);
|
|
24
|
+
/** Safe, stable-shape serialization for logs and `viceme:error` events. */
|
|
25
|
+
toJSON(): {
|
|
26
|
+
code: ViceMeErrorCode;
|
|
27
|
+
retryable: boolean;
|
|
28
|
+
requestId?: string;
|
|
29
|
+
capability?: string;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export declare function isViceMeError(value: unknown): value is ViceMeError;
|
|
33
|
+
/** Build a CONFIG_INVALID error with a stable, non-sensitive message. */
|
|
34
|
+
export declare function configInvalid(message: string): ViceMeError;
|
|
35
|
+
/** Build a CLIENT_DESTROYED error for post-destroy calls. */
|
|
36
|
+
export declare function clientDestroyed(): ViceMeError;
|
|
37
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,eAAe,GACvB,gBAAgB,GAChB,gBAAgB,GAChB,oBAAoB,GACpB,qBAAqB,GACrB,kBAAkB,GAClB,iBAAiB,GACjB,cAAc,GACd,iBAAiB,GACjB,sBAAsB,GACtB,gBAAgB,CAAC;AAErB,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,eAAe,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AASD,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;gBAEjB,IAAI,EAAE,eAAe;IASjC,2EAA2E;IAC3E,MAAM,IAAI;QACR,IAAI,EAAE,eAAe,CAAC;QACtB,SAAS,EAAE,OAAO,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB;CAWF;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE;AAED,yEAAyE;AACzE,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CAE1D;AAED,6DAA6D;AAC7D,wBAAgB,eAAe,IAAI,WAAW,CAM7C"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client lifecycle state machine.
|
|
3
|
+
*
|
|
4
|
+
* ```text
|
|
5
|
+
* CREATED -> INITIALIZING -> READY -> DESTROYED
|
|
6
|
+
* INITIALIZING -> FAILED (retryable: FAILED -> INITIALIZING)
|
|
7
|
+
* READY -> DEGRADED (single capability unavailable; host page keeps working)
|
|
8
|
+
* DEGRADED -> READY (when all capabilities recover is a B1+ concern)
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* State is exposed read-only; consumers can never assign it directly.
|
|
12
|
+
*/
|
|
13
|
+
export type ViceMeClientState = 'CREATED' | 'INITIALIZING' | 'READY' | 'DEGRADED' | 'FAILED' | 'DESTROYED';
|
|
14
|
+
export type LifecycleListener = (state: ViceMeClientState) => void;
|
|
15
|
+
export declare class Lifecycle {
|
|
16
|
+
#private;
|
|
17
|
+
get state(): ViceMeClientState;
|
|
18
|
+
get destroyed(): boolean;
|
|
19
|
+
transition(next: ViceMeClientState): void;
|
|
20
|
+
/** Any operation on a destroyed client must fail closed with this guard. */
|
|
21
|
+
assertAlive(): void;
|
|
22
|
+
subscribe(listener: LifecycleListener): () => void;
|
|
23
|
+
clearListeners(): void;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/core/lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,MAAM,MAAM,iBAAiB,GAC3B,SAAS,GAAG,cAAc,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,GAAG,WAAW,CAAC;AAW7E,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;AAEnE,qBAAa,SAAS;;IAIpB,IAAI,KAAK,IAAI,iBAAiB,CAE7B;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,UAAU,CAAC,IAAI,EAAE,iBAAiB,GAAG,IAAI;IAazC,4EAA4E;IAC5E,WAAW,IAAI,IAAI;IAInB,SAAS,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM,IAAI;IAOlD,cAAc,IAAI,IAAI;CAGvB"}
|