@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
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public visitor session.
|
|
3
|
+
*
|
|
4
|
+
* ```text
|
|
5
|
+
* SDK + workKey + Origin -> POST /public/v1/work-sessions
|
|
6
|
+
* -> short-lived capability token -> public capability calls
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* The token lives in memory only (never localStorage/cookies), is bound to the
|
|
10
|
+
* Work, Origin, capability set, and expiry by the server, and is dropped on
|
|
11
|
+
* `destroy()`. `workKey` locates the Work — it is never an authorization
|
|
12
|
+
* credential.
|
|
13
|
+
*/
|
|
14
|
+
import type { Transport } from '../transport/transport.ts';
|
|
15
|
+
import type { components } from '../generated/public-contract.ts';
|
|
16
|
+
export type CreateWorkSessionRequestDto = components['schemas']['CreateWorkSessionRequest'];
|
|
17
|
+
export interface WorkDescriptor {
|
|
18
|
+
key: string;
|
|
19
|
+
/** Capability names enabled for this work. */
|
|
20
|
+
capabilities: string[];
|
|
21
|
+
}
|
|
22
|
+
export interface WorkSessionSnapshot {
|
|
23
|
+
work: WorkDescriptor;
|
|
24
|
+
/** Opaque short-lived capability token; memory-only. */
|
|
25
|
+
token?: string;
|
|
26
|
+
/** Epoch milliseconds when the token expires, when provided by the server. */
|
|
27
|
+
expiresAt?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface SessionManagerOptions {
|
|
30
|
+
workKey: string;
|
|
31
|
+
transport: Transport;
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
timeoutMs?: number;
|
|
34
|
+
/** Injectable clock for tests. */
|
|
35
|
+
now?: () => number;
|
|
36
|
+
}
|
|
37
|
+
export declare class SessionManager {
|
|
38
|
+
#private;
|
|
39
|
+
constructor(options: SessionManagerOptions);
|
|
40
|
+
get snapshot(): WorkSessionSnapshot | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Establish (or return the established) public session.
|
|
43
|
+
*
|
|
44
|
+
* A cached snapshot is reused only while it is unexpired; an expired
|
|
45
|
+
* snapshot is dropped and re-authenticated. Concurrent callers share one
|
|
46
|
+
* in-flight request (single flight).
|
|
47
|
+
*/
|
|
48
|
+
establish(): Promise<WorkSessionSnapshot>;
|
|
49
|
+
/** Drop the token; next `establish()` re-authenticates. */
|
|
50
|
+
invalidate(): void;
|
|
51
|
+
/** Hard cleanup: forget the token and pending work. */
|
|
52
|
+
destroy(): void;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAQlE,MAAM,MAAM,2BAA2B,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,0BAA0B,CAAC,CAAC;AAE5F,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,8CAA8C;IAC9C,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,cAAc,CAAC;IACrB,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8EAA8E;IAC9E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AA4CD,qBAAa,cAAc;;gBAMb,OAAO,EAAE,qBAAqB;IAK1C,IAAI,QAAQ,IAAI,mBAAmB,GAAG,SAAS,CAE9C;IAQD;;;;;;OAMG;IACH,SAAS,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAwBzC,2DAA2D;IAC3D,UAAU,IAAI,IAAI;IAIlB,uDAAuD;IACvD,OAAO,IAAI,IAAI;CAIhB"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@viceme-ai/sdk/testing` — explicit test adapter.
|
|
3
|
+
*
|
|
4
|
+
* Deterministic fixture helpers for SDK consumers and capability authors.
|
|
5
|
+
* This code must never be imported from production core, loader, or capability
|
|
6
|
+
* bundles; it is excluded from them at build time and only exported via the
|
|
7
|
+
* `./testing` subpath.
|
|
8
|
+
*
|
|
9
|
+
* The test client runs the exact same config, lifecycle, error, and contract
|
|
10
|
+
* validation as production `createViceMe()` — it is not a bypass mock.
|
|
11
|
+
*/
|
|
12
|
+
import type { ViceMeClient } from '../core/client.ts';
|
|
13
|
+
import type { ViceMeRegion } from '../core/config.ts';
|
|
14
|
+
import type { Transport, TransportRequest } from '../transport/transport.ts';
|
|
15
|
+
export interface MemoryTransportWorkFixture {
|
|
16
|
+
key: string;
|
|
17
|
+
capabilities: string[];
|
|
18
|
+
token?: string;
|
|
19
|
+
expiresAt?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface MemoryTransportOptions {
|
|
22
|
+
/** Work descriptor served for `POST /public/v1/work-sessions`. */
|
|
23
|
+
work: MemoryTransportWorkFixture;
|
|
24
|
+
/** Artificial response latency in milliseconds (default 0). */
|
|
25
|
+
latencyMs?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Queue of failures thrown before the fixture response is served; each
|
|
28
|
+
* entry is consumed by one session request. Use for retry/timeout tests.
|
|
29
|
+
*/
|
|
30
|
+
sessionFailures?: Array<Error | {
|
|
31
|
+
status: number;
|
|
32
|
+
code: string;
|
|
33
|
+
message?: string;
|
|
34
|
+
}>;
|
|
35
|
+
}
|
|
36
|
+
export interface MemoryTransport extends Transport {
|
|
37
|
+
/** Every request seen so far, for assertions. */
|
|
38
|
+
readonly requests: TransportRequest[];
|
|
39
|
+
}
|
|
40
|
+
export declare function createMemoryTransport(options: MemoryTransportOptions): MemoryTransport;
|
|
41
|
+
export interface CreateTestViceMeOptions {
|
|
42
|
+
workKey: string;
|
|
43
|
+
region: ViceMeRegion;
|
|
44
|
+
/** Mock transport serving the fixture contract. */
|
|
45
|
+
transport: Transport;
|
|
46
|
+
signal?: AbortSignal;
|
|
47
|
+
/** Stable virtual clock for deterministic time-based assertions. */
|
|
48
|
+
now?: () => number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Create a client backed by an injected transport. Runs identical validation
|
|
52
|
+
* and lifecycle logic to `createViceMe()`.
|
|
53
|
+
*/
|
|
54
|
+
export declare function createTestViceMe(options: CreateTestViceMeOptions): ViceMeClient;
|
|
55
|
+
/** Standard fixture work used across repo tests and examples. */
|
|
56
|
+
export declare const FIXTURE_WORK: MemoryTransportWorkFixture;
|
|
57
|
+
//# sourceMappingURL=test-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-adapter.d.ts","sourceRoot":"","sources":["../../src/testing/test-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAqB,MAAM,2BAA2B,CAAC;AAEhG,MAAM,WAAW,0BAA0B;IACzC,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,sBAAsB;IACrC,kEAAkE;IAClE,IAAI,EAAE,0BAA0B,CAAC;IACjC,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,eAAe,CAAC,EAAE,KAAK,CAAC,KAAK,GAAG;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACrF;AAED,MAAM,WAAW,eAAgB,SAAQ,SAAS;IAChD,iDAAiD;IACjD,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,EAAE,CAAC;CACvC;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,GAAG,eAAe,CAoDtF;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,YAAY,CAAC;IACrB,mDAAmD;IACnD,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,oEAAoE;IACpE,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,YAAY,CAe/E;AAED,iEAAiE;AACjE,eAAO,MAAM,YAAY,EAAE,0BAI1B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@viceme-ai/sdk/testing` subpath entry (test adapter only).
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the deterministic mock transport and test client so the emitted
|
|
5
|
+
* declaration lands at `dist/testing.d.ts`, matching the package exports map.
|
|
6
|
+
*/
|
|
7
|
+
export { createTestViceMe, createMemoryTransport, FIXTURE_WORK } from './testing/test-adapter.ts';
|
|
8
|
+
export type { MemoryTransport, MemoryTransportOptions, MemoryTransportWorkFixture, CreateTestViceMeOptions, } from './testing/test-adapter.ts';
|
|
9
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAClG,YAAY,EACV,eAAe,EACf,sBAAsB,EACtB,0BAA0B,EAC1B,uBAAuB,GACxB,MAAM,2BAA2B,CAAC"}
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { b as w, c as s, d as u, a as d } from "./chunks/client-CGU3qeew.js";
|
|
2
|
+
function f(e) {
|
|
3
|
+
const i = [], o = [...e.sessionFailures ?? []], a = e.latencyMs ?? 0;
|
|
4
|
+
return {
|
|
5
|
+
requests: i,
|
|
6
|
+
async request(t) {
|
|
7
|
+
if (t.signal?.aborted)
|
|
8
|
+
throw new DOMException("Aborted", "AbortError");
|
|
9
|
+
if (i.push(t), await new Promise((r, n) => {
|
|
10
|
+
const c = t.signal, l = setTimeout(() => r(), a);
|
|
11
|
+
c?.addEventListener(
|
|
12
|
+
"abort",
|
|
13
|
+
() => {
|
|
14
|
+
clearTimeout(l), n(new DOMException("Aborted", "AbortError"));
|
|
15
|
+
},
|
|
16
|
+
{ once: !0 }
|
|
17
|
+
);
|
|
18
|
+
}), t.path === "/public/v1/work-sessions" && t.method === "POST") {
|
|
19
|
+
const r = o.shift();
|
|
20
|
+
if (r) {
|
|
21
|
+
if (r instanceof Error) throw r;
|
|
22
|
+
return {
|
|
23
|
+
status: r.status,
|
|
24
|
+
body: {
|
|
25
|
+
error: { code: r.code, message: r.message ?? "Simulated failure." }
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
status: 201,
|
|
31
|
+
body: {
|
|
32
|
+
work: { key: e.work.key, capabilities: [...e.work.capabilities] },
|
|
33
|
+
...e.work.token !== void 0 ? { token: e.work.token } : {},
|
|
34
|
+
...e.work.expiresAt !== void 0 ? { expiresAt: e.work.expiresAt } : {}
|
|
35
|
+
},
|
|
36
|
+
requestId: `test-${i.length}`
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
status: 404,
|
|
41
|
+
body: { error: { code: "CONFIG_INVALID", message: `No fixture for ${t.path}.` } }
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function g(e) {
|
|
47
|
+
if (!w(e.workKey))
|
|
48
|
+
throw s('Test client requires a valid workKey ("wrk_…").');
|
|
49
|
+
if (!u(e.region))
|
|
50
|
+
throw s('Test client requires region "cn" or "global".');
|
|
51
|
+
if (typeof e.transport?.request != "function")
|
|
52
|
+
throw s("Test client requires a transport with a request() method.");
|
|
53
|
+
return new d({
|
|
54
|
+
config: { workKey: e.workKey, region: e.region, signal: e.signal },
|
|
55
|
+
transport: e.transport,
|
|
56
|
+
...e.now !== void 0 ? { now: e.now } : {}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const y = {
|
|
60
|
+
key: "wrk_test",
|
|
61
|
+
capabilities: ["fixture"],
|
|
62
|
+
token: "test-session-token"
|
|
63
|
+
};
|
|
64
|
+
export {
|
|
65
|
+
y as FIXTURE_WORK,
|
|
66
|
+
f as createMemoryTransport,
|
|
67
|
+
g as createTestViceMe
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.js","sources":["../src/testing/test-adapter.ts"],"sourcesContent":["/**\n * `@viceme-ai/sdk/testing` — explicit test adapter.\n *\n * Deterministic fixture helpers for SDK consumers and capability authors.\n * This code must never be imported from production core, loader, or capability\n * bundles; it is excluded from them at build time and only exported via the\n * `./testing` subpath.\n *\n * The test client runs the exact same config, lifecycle, error, and contract\n * validation as production `createViceMe()` — it is not a bypass mock.\n */\n\nimport { configInvalid } from '../core/errors.ts';\nimport { isValidWorkKey, isValidRegion } from '../core/config.ts';\nimport { ViceMeClientImpl } from '../core/client.ts';\nimport type { ViceMeClient } from '../core/client.ts';\nimport type { ViceMeRegion } from '../core/config.ts';\nimport type { Transport, TransportRequest, TransportResponse } from '../transport/transport.ts';\n\nexport interface MemoryTransportWorkFixture {\n key: string;\n capabilities: string[];\n token?: string;\n expiresAt?: number;\n}\n\nexport interface MemoryTransportOptions {\n /** Work descriptor served for `POST /public/v1/work-sessions`. */\n work: MemoryTransportWorkFixture;\n /** Artificial response latency in milliseconds (default 0). */\n latencyMs?: number;\n /**\n * Queue of failures thrown before the fixture response is served; each\n * entry is consumed by one session request. Use for retry/timeout tests.\n */\n sessionFailures?: Array<Error | { status: number; code: string; message?: string }>;\n}\n\nexport interface MemoryTransport extends Transport {\n /** Every request seen so far, for assertions. */\n readonly requests: TransportRequest[];\n}\n\nexport function createMemoryTransport(options: MemoryTransportOptions): MemoryTransport {\n const requests: TransportRequest[] = [];\n const failures = [...(options.sessionFailures ?? [])];\n const latencyMs = options.latencyMs ?? 0;\n\n return {\n requests,\n async request(request: TransportRequest): Promise<TransportResponse> {\n // A pre-aborted signal never counts as an issued request.\n if (request.signal?.aborted) {\n throw new DOMException('Aborted', 'AbortError');\n }\n requests.push(request);\n await new Promise<void>((resolve, reject) => {\n const signal = request.signal;\n const timer = setTimeout(() => resolve(), latencyMs);\n signal?.addEventListener(\n 'abort',\n () => {\n clearTimeout(timer);\n reject(new DOMException('Aborted', 'AbortError'));\n },\n { once: true },\n );\n });\n if (request.path === '/public/v1/work-sessions' && request.method === 'POST') {\n const failure = failures.shift();\n if (failure) {\n if (failure instanceof Error) throw failure;\n return {\n status: failure.status,\n body: {\n error: { code: failure.code, message: failure.message ?? 'Simulated failure.' },\n },\n };\n }\n return {\n status: 201,\n body: {\n work: { key: options.work.key, capabilities: [...options.work.capabilities] },\n ...(options.work.token !== undefined ? { token: options.work.token } : {}),\n ...(options.work.expiresAt !== undefined ? { expiresAt: options.work.expiresAt } : {}),\n },\n requestId: `test-${requests.length}`,\n };\n }\n return {\n status: 404,\n body: { error: { code: 'CONFIG_INVALID', message: `No fixture for ${request.path}.` } },\n };\n },\n };\n}\n\nexport interface CreateTestViceMeOptions {\n workKey: string;\n region: ViceMeRegion;\n /** Mock transport serving the fixture contract. */\n transport: Transport;\n signal?: AbortSignal;\n /** Stable virtual clock for deterministic time-based assertions. */\n now?: () => number;\n}\n\n/**\n * Create a client backed by an injected transport. Runs identical validation\n * and lifecycle logic to `createViceMe()`.\n */\nexport function createTestViceMe(options: CreateTestViceMeOptions): ViceMeClient {\n if (!isValidWorkKey(options.workKey)) {\n throw configInvalid('Test client requires a valid workKey (\"wrk_…\").');\n }\n if (!isValidRegion(options.region)) {\n throw configInvalid('Test client requires region \"cn\" or \"global\".');\n }\n if (typeof options.transport?.request !== 'function') {\n throw configInvalid('Test client requires a transport with a request() method.');\n }\n return new ViceMeClientImpl({\n config: { workKey: options.workKey, region: options.region, signal: options.signal },\n transport: options.transport,\n ...(options.now !== undefined ? { now: options.now } : {}),\n });\n}\n\n/** Standard fixture work used across repo tests and examples. */\nexport const FIXTURE_WORK: MemoryTransportWorkFixture = {\n key: 'wrk_test',\n capabilities: ['fixture'],\n token: 'test-session-token',\n};\n"],"names":["createMemoryTransport","options","requests","failures","latencyMs","request","resolve","reject","signal","timer","failure","createTestViceMe","isValidWorkKey","configInvalid","isValidRegion","ViceMeClientImpl","FIXTURE_WORK"],"mappings":";AA2CO,SAASA,EAAsBC,GAAkD;AACtF,QAAMC,IAA+B,CAAA,GAC/BC,IAAW,CAAC,GAAIF,EAAQ,mBAAmB,CAAA,CAAG,GAC9CG,IAAYH,EAAQ,aAAa;AAEvC,SAAO;AAAA,IACL,UAAAC;AAAA,IACA,MAAM,QAAQG,GAAuD;AAEnE,UAAIA,EAAQ,QAAQ;AAClB,cAAM,IAAI,aAAa,WAAW,YAAY;AAehD,UAbAH,EAAS,KAAK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AACjC,UAAMY,EAAc,iDAAiD;AAEvE,MAAI,CAACC,EAAcb,EAAQ,MAAM;AAC/B,UAAMY,EAAc,+CAA+C;AAErE,MAAI,OAAOZ,EAAQ,WAAW,WAAY;AACxC,UAAMY,EAAc,2DAA2D;AAEjF,SAAO,IAAIE,EAAiB;AAAA,IAC1B,QAAQ,EAAE,SAASd,EAAQ,SAAS,QAAQA,EAAQ,QAAQ,QAAQA,EAAQ,OAAA;AAAA,IAC5E,WAAWA,EAAQ;AAAA,IACnB,GAAIA,EAAQ,QAAQ,SAAY,EAAE,KAAKA,EAAQ,QAAQ,CAAA;AAAA,EAAC,CACzD;AACH;AAGO,MAAMe,IAA2C;AAAA,EACtD,KAAK;AAAA,EACL,cAAc,CAAC,SAAS;AAAA,EACxB,OAAO;AACT;"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP transport for the public API.
|
|
3
|
+
*
|
|
4
|
+
* Responsibilities: request execution with timeout, abort, client request ids,
|
|
5
|
+
* and normalization of every failure into the public `ViceMeError` model.
|
|
6
|
+
* Capabilities and the loader never build their own `fetch` calls — they go
|
|
7
|
+
* through a Transport so tests can swap in `createMemoryTransport`.
|
|
8
|
+
*/
|
|
9
|
+
export interface TransportRequest {
|
|
10
|
+
method: 'GET' | 'POST';
|
|
11
|
+
/** Absolute path under the public API base, e.g. `/public/v1/work-sessions`. */
|
|
12
|
+
path: string;
|
|
13
|
+
/** JSON-serializable request body. */
|
|
14
|
+
body?: unknown;
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
/** Per-request timeout; defaults to the transport default. */
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface TransportResponse {
|
|
20
|
+
status: number;
|
|
21
|
+
body?: unknown;
|
|
22
|
+
/** Echoed server request id, when provided. */
|
|
23
|
+
requestId?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface Transport {
|
|
26
|
+
request(request: TransportRequest): Promise<TransportResponse>;
|
|
27
|
+
}
|
|
28
|
+
export interface FetchTransportOptions {
|
|
29
|
+
apiBaseUrl: string;
|
|
30
|
+
/** Injectable for tests; defaults to global `fetch`. */
|
|
31
|
+
fetchImpl?: typeof fetch;
|
|
32
|
+
defaultTimeoutMs?: number;
|
|
33
|
+
/** Injectable id generator (default: `crypto.randomUUID`). */
|
|
34
|
+
generateRequestId?: () => string;
|
|
35
|
+
}
|
|
36
|
+
export declare class FetchTransport implements Transport {
|
|
37
|
+
#private;
|
|
38
|
+
constructor(options: FetchTransportOptions);
|
|
39
|
+
request(request: TransportRequest): Promise<TransportResponse>;
|
|
40
|
+
}
|
|
41
|
+
export declare function createFetchTransport(options: FetchTransportOptions): Transport;
|
|
42
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/transport/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,gFAAgF;IAChF,IAAI,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,8DAA8D;IAC9D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAChE;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,wDAAwD;IACxD,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,8DAA8D;IAC9D,iBAAiB,CAAC,EAAE,MAAM,MAAM,CAAC;CAClC;AAiED,qBAAa,cAAe,YAAW,SAAS;;gBAMlC,OAAO,EAAE,qBAAqB;IAOpC,OAAO,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAoGrE;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,SAAS,CAE9E"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for the SDK runtime version.
|
|
3
|
+
*
|
|
4
|
+
* Kept in sync with `packages/sdk/package.json#version`; a unit test enforces
|
|
5
|
+
* the match so the loader, release manifest, and npm metadata can never drift.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SDK_VERSION = "0.1.2";
|
|
8
|
+
/** Public API major carried by this build (loader namespace `v1`). */
|
|
9
|
+
export declare const API_MAJOR = 1;
|
|
10
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,WAAW,UAAU,CAAC;AAEnC,sEAAsE;AACtE,eAAO,MAAM,SAAS,IAAI,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
(function(){"use strict";const _=new Set(["RATE_LIMITED","NETWORK_TIMEOUT","CHECKOUT_UNAVAILABLE","INTERNAL_ERROR"]);class h extends Error{code;retryable;requestId;capability;constructor(e){super(e.message),this.name="ViceMeError",this.code=e.code,this.retryable=e.retryable??_.has(e.code),this.requestId=e.requestId,this.capability=e.capability}toJSON(){const e={code:this.code,retryable:this.retryable};return this.requestId!==void 0&&(e.requestId=this.requestId),this.capability!==void 0&&(e.capability=this.capability),e}}function Q(t){return t instanceof h}function s(t){return new h({code:"CONFIG_INVALID",message:t,retryable:!1})}function ee(){return new h({code:"CLIENT_DESTROYED",message:"ViceMe client has been destroyed.",retryable:!1})}const O=new Set(["cn","global"]),C={cn:"https://api.viceme.cn",global:"https://api.viceme.ai"};function te(t){return C[t]}function I(t){return typeof t=="string"&&/^wrk_[A-Za-z0-9_-]{4,124}$/.test(t)}function A(t){return typeof t=="string"&&O.has(t)}function re(t){if(typeof t!="object"||t===null)throw s("createViceMe expects a configuration object.");const e=t,r=new Set(["workKey","region","signal"]);for(const n of Object.keys(e))if(!r.has(n))throw s(`Unknown configuration field "${n}".`);if(!I(e.workKey))throw s('Configuration field "workKey" must be a public work key ("wrk_…").');if(!A(e.region))throw s('Configuration field "region" must be "cn" or "global".');if(e.signal!==void 0&&!(e.signal instanceof AbortSignal))throw s('Configuration field "signal" must be an AbortSignal.');return{workKey:e.workKey,region:e.region,signal:e.signal}}const M=new Set(["data-viceme-work","data-viceme-region","data-viceme-features","data-viceme-target","data-viceme-theme","data-viceme-loader"]),N=/^[a-z][a-z0-9-]{1,31}$/,$=new Set(["light","dark","auto"]);function D(t){for(const o of t.getAttributeNames())if(o.startsWith("data-viceme-")&&!M.has(o))throw s(`Unknown loader attribute "${o}".`);const e=t.getAttribute("data-viceme-work");if(!I(e))throw s('Loader attribute "data-viceme-work" must be a public work key ("wrk_…").');const r=t.getAttribute("data-viceme-region");if(!A(r))throw s('Loader attribute "data-viceme-region" must be "cn" or "global".');const n=t.getAttribute("data-viceme-features");if(n===null||n.trim()==="")throw s('Loader attribute "data-viceme-features" is required.');const u=[];for(const o of n.split(",")){const l=o.trim();if(l!==""){if(!N.test(l))throw s(`Loader feature name "${l}" is not a valid capability name.`);u.includes(l)||u.push(l)}}if(u.length===0)throw s('Loader attribute "data-viceme-features" must list at least one feature.');const c=t.getAttribute("data-viceme-target");if(c==="")throw s('Loader attribute "data-viceme-target" must be a CSS selector.');if(c===null)throw s('Loader attribute "data-viceme-target" is required when features are declared.');const i=t.getAttribute("data-viceme-theme");if(i!==null&&!$.has(i))throw s('Loader attribute "data-viceme-theme" must be "light", "dark", or "auto".');return{workKey:e,region:r,features:u,target:c,theme:i??"auto"}}function w(t,e,r){return`v${t}+${e}+${r}`}class U{#r=new Map;#e=new Map;#t=new Map;#n=0;getClient(e){return this.#r.get(e)}registerClient(e){this.#r.set(e.clientKey,e)}unregisterClient(e){this.#r.delete(e)}getInstance(e){return this.#e.get(e)}findInstance(e,r,n){return this.#t.get(`${e}::${r}`)?.get(n)}registerInstance(e,r,n,u){const c=`${e}::${r}`;let i=this.#t.get(c);i===void 0&&(i=new WeakMap,this.#t.set(c,i));const o=i.get(n);if(o)return o;this.#n+=1;const l={instanceKey:`${e}::${r}::el${this.#n}`,clientKey:e,capability:r,host:n,raw:u,destroyed:!1};return this.#e.set(l.instanceKey,l),i.set(n,l),l}removeInstance(e){const r=this.#e.get(e);if(r)return this.#e.delete(e),this.#t.get(`${r.clientKey}::${r.capability}`)?.delete(r.host),r}instancesForClient(e){return[...this.#e.values()].filter(r=>r.clientKey===e)}}const j=new Map([["viceme:ready",new Set(["clientKey","workKey","capabilities","version"])],["viceme:capability-ready",new Set(["clientKey","instanceKey","capability","version"])],["viceme:error",new Set(["clientKey","instanceKey","capability","code","retryable","requestId"])],["viceme:destroyed",new Set(["clientKey","instanceKey","capability"])]]);function q(t,e){const r=j.get(t),n={};for(const[u,c]of Object.entries(e))r.has(u)&&c!==void 0&&(n[u]=c);return n}function m(t,e,r){const n=new CustomEvent(e,{detail:q(e,r),bubbles:!0,composed:!0,cancelable:!1});t.dispatchEvent(n)}const ne="0.1.2",y=1,V=8e3,k=Symbol.for("viceme.loader.state.v1");function d(){const e=globalThis[k];if(e)return e;const r={registry:new U,queue:{current:Promise.resolve()}};return Object.defineProperty(globalThis,k,{value:r,writable:!0,configurable:!0,enumerable:!1}),r}function p(t){if(!t.destroyed){t.destroyed=!0,d().registry.removeInstance(t.instanceKey);try{t.raw.destroy()}finally{m(t.host,"viceme:destroyed",{clientKey:t.clientKey,instanceKey:t.instanceKey,capability:t.capability})}}}function P(t){return{instanceKey:t.instanceKey,capability:t.capability,destroy:()=>p(t)}}function v(t,e,r){Object.defineProperty(t,e,{value:r,writable:!0,configurable:!0,enumerable:!1})}function B(t){let r=globalThis.ViceMe;r||(r={},v(globalThis,"ViceMe",r));let n=r.versions;n||(n={},v(r,"versions",n));const u=n[`v${y}`];if(u)return u;const c={version:t,whenReady(i){const o=d().registry.getClient(i);return o?o.ready.then(()=>o.client):Promise.reject(s(`Unknown clientKey "${i}".`))},getInstance(i){const o=d().registry.getInstance(i);return o?P(o):void 0},destroyInstance(i){const o=d().registry.getInstance(i);o&&p(o)},destroyClient(i){for(const l of d().registry.instancesForClient(i))p(l);const o=d().registry.getClient(i);d().registry.unregisterClient(i),o?.client.destroy()}};return v(n,`v${y}`,c),c}function x(){return document.readyState!=="loading"?Promise.resolve():new Promise(t=>{document.addEventListener("DOMContentLoaded",()=>t(),{once:!0})})}async function W(t){let e;try{e=await E(t)}catch{e={ok:!1,status:0}}if(!e.ok){const r=await F(t);if(r!==void 0){const n=new URL(`/viceme-sdk/${r}/manifest.json`,t);return{manifest:await L(await E(n)),baseUrl:n}}}return{manifest:await L(e),baseUrl:t}}function E(t){const e=typeof AbortSignal<"u"&&typeof AbortSignal.timeout=="function"?AbortSignal.timeout(V):void 0;return fetch(t,{credentials:"omit",signal:e})}async function F(t){if(!(!/\/viceme-sdk\/[^/]+\/manifest\.json$/.test(t.pathname)||t.pathname.split("/viceme-sdk/")[1]?.split("/")[0]!==`v${y}`))try{const r=await E(new URL("/viceme-sdk/-/aliases/v1",t));if(!r.ok)return;const n=(await r.text()).trim();return/^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/.test(n)?n:void 0}catch{return}}async function L(t){if(!t.ok)throw s(`Release manifest is not available (HTTP ${t.status}).`);const e=await t.json();if(typeof e!="object"||e===null||typeof e.version!="string"||typeof e.apiMajor!="number"||typeof e.features!="object"||e.features===null)throw s("Release manifest is malformed.");const r=e;if(r.apiMajor!==y)throw s("Release manifest major version does not match this loader.");return r}async function Y(t){const r=await import(new URL("index.js",t).href);if(typeof r.createViceMe!="function")throw s("SDK core chunk does not export createViceMe().");return r}const H=new Set(["CONFIG_INVALID","WORK_NOT_FOUND","ORIGIN_NOT_ALLOWED","CAPABILITY_DISABLED","CLIENT_DESTROYED","SESSION_EXPIRED","RATE_LIMITED","NETWORK_TIMEOUT","CHECKOUT_UNAVAILABLE","INTERNAL_ERROR"]);function z(t){if(typeof t=="object"&&t!==null){const e=t;if(typeof e.code=="string"&&H.has(e.code)&&typeof e.retryable=="boolean"){const r={code:e.code,retryable:e.retryable};return typeof e.requestId=="string"&&(r.requestId=e.requestId),typeof e.capability=="string"&&(r.capability=e.capability),r}}return{code:"INTERNAL_ERROR",retryable:!0}}function f(t,e,r={}){m(t,"viceme:error",{...z(e),...r})}async function G(t){let e;try{e=D(t)}catch(a){f(document,a);return}if(!t.src){f(document,s("Loader script requires a src URL."));return}const r=new URL("manifest.json",t.src);let n,u;try{({manifest:n,baseUrl:u}=await W(r))}catch(a){f(document,a,{clientKey:w(y,e.region,e.workKey)});return}await x();let c;try{const a=document.querySelectorAll(e.target);if(a.length===0)throw s(`Loader target "${e.target}" matched no element; no node was created.`);if(a.length>1)throw s(`Loader target "${e.target}" matched ${a.length} elements; exactly one is required.`);c=a[0]}catch(a){f(document,a,{clientKey:w(n.apiMajor,e.region,e.workKey)});return}const i=w(n.apiMajor,e.region,e.workKey);B(n.version);let o=d().registry.getClient(i),l;if(o)l=o.client;else{let a;try{a=await Y(u)}catch(b){f(c,b,{clientKey:i});return}l=a.createViceMe({workKey:e.workKey,region:e.region});const g=l.ready();g.catch(()=>{}),o={clientKey:i,client:l,ready:g},d().registry.registerClient(o)}try{await o.ready}catch(a){d().registry.unregisterClient(i),l.destroy(),f(c,a,{clientKey:i});return}let K=!1;const T=[];for(const a of e.features){if(d().registry.findInstance(i,a,c))continue;const g=n.features[a];if(typeof g!="string"){l.markDegraded(),f(c,new h({code:"CAPABILITY_DISABLED",message:`Capability "${a}" is not part of this release.`,retryable:!1,capability:a}),{clientKey:i,capability:a});continue}try{const S=await import(new URL(g,u).href);if(typeof S.mount!="function")throw s(`Capability chunk "${a}" does not export mount().`);const Z=await S.mount(l,{target:c,theme:e.theme}),X=d().registry.registerInstance(i,a,c,Z);K=!0,T.push(a),m(c,"viceme:capability-ready",{clientKey:i,instanceKey:X.instanceKey,capability:a,version:n.version})}catch(b){l.markDegraded(),f(c,b,{clientKey:i,capability:a})}}K&&m(c,"viceme:ready",{clientKey:i,workKey:e.workKey,capabilities:T,version:n.version})}function J(t){const{queue:e}=d(),r=e.current.then(()=>G(t));return e.current=r.catch(()=>{}),r}function R(){if(typeof document>"u")return;let t=document.currentScript instanceof HTMLScriptElement?document.currentScript:null;if(!t){const e=document.querySelectorAll("script[data-viceme-loader]");e.length===1&&(t=e[0]??null)}t&&J(t).catch(e=>{f(document,e)})}R();const ie=R})();
|
|
2
|
+
//# sourceMappingURL=viceme.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"viceme.min.js","sources":["../src/core/errors.ts","../src/core/config.ts","../src/loader/attributes.ts","../src/loader/registry.ts","../src/loader/events.ts","../src/version.ts","../src/loader/auto-loader.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 * `data-viceme-*` attribute parsing for the CDN auto-loader.\n *\n * The attribute set is fixed; unknown `data-viceme-*` attributes are rejected\n * so pages can never smuggle endpoints, tokens, secrets, prices, or payment\n * state through the loader. Parse failures never guess defaults for work,\n * region, or target.\n */\n\nimport { configInvalid } from '../core/errors.ts';\nimport type { ViceMeRegion } from '../core/config.ts';\nimport { isValidRegion, isValidWorkKey } from '../core/config.ts';\n\nexport type ViceMeTheme = 'light' | 'dark' | 'auto';\n\nexport interface LoaderAttributes {\n workKey: string;\n region: ViceMeRegion;\n /** Deduplicated feature names in declared order. */\n features: string[];\n /** CSS selector; required whenever features are declared. */\n target?: string;\n theme: ViceMeTheme;\n}\n\nconst KNOWN_ATTRIBUTES: ReadonlySet<string> = new Set([\n 'data-viceme-work',\n 'data-viceme-region',\n 'data-viceme-features',\n 'data-viceme-target',\n 'data-viceme-theme',\n // Marker for explicit opt-in when document.currentScript is unavailable.\n 'data-viceme-loader',\n]);\n\nconst FEATURE_NAME_PATTERN = /^[a-z][a-z0-9-]{1,31}$/;\nconst THEMES: ReadonlySet<string> = new Set(['light', 'dark', 'auto']);\n\nexport function parseLoaderAttributes(element: Element): LoaderAttributes {\n for (const name of element.getAttributeNames()) {\n if (name.startsWith('data-viceme-') && !KNOWN_ATTRIBUTES.has(name)) {\n throw configInvalid(`Unknown loader attribute \"${name}\".`);\n }\n }\n\n const workKey = element.getAttribute('data-viceme-work');\n if (!isValidWorkKey(workKey)) {\n throw configInvalid('Loader attribute \"data-viceme-work\" must be a public work key (\"wrk_…\").');\n }\n\n const region = element.getAttribute('data-viceme-region');\n if (!isValidRegion(region)) {\n throw configInvalid('Loader attribute \"data-viceme-region\" must be \"cn\" or \"global\".');\n }\n\n const rawFeatures = element.getAttribute('data-viceme-features');\n if (rawFeatures === null || rawFeatures.trim() === '') {\n throw configInvalid('Loader attribute \"data-viceme-features\" is required.');\n }\n const features: string[] = [];\n for (const part of rawFeatures.split(',')) {\n const feature = part.trim();\n if (feature === '') continue;\n if (!FEATURE_NAME_PATTERN.test(feature)) {\n throw configInvalid(`Loader feature name \"${feature}\" is not a valid capability name.`);\n }\n if (!features.includes(feature)) features.push(feature);\n }\n if (features.length === 0) {\n throw configInvalid('Loader attribute \"data-viceme-features\" must list at least one feature.');\n }\n\n const target = element.getAttribute('data-viceme-target');\n if (target === '') {\n throw configInvalid('Loader attribute \"data-viceme-target\" must be a CSS selector.');\n }\n // Loader-mounted features are visual capabilities, so a target is required.\n if (target === null) {\n throw configInvalid(\n 'Loader attribute \"data-viceme-target\" is required when features are declared.',\n );\n }\n\n const rawTheme = element.getAttribute('data-viceme-theme');\n if (rawTheme !== null && !THEMES.has(rawTheme)) {\n throw configInvalid('Loader attribute \"data-viceme-theme\" must be \"light\", \"dark\", or \"auto\".');\n }\n\n return {\n workKey,\n region,\n features,\n target,\n theme: (rawTheme ?? 'auto') as ViceMeTheme,\n };\n}\n","/**\n * Loader registry.\n *\n * Only the CDN loader maintains this registry (explicit `createViceMe()`\n * instances never register). Core clients are shared by\n * `major + region + workKey`; capability mounts are deduplicated by\n * `clientKey + capability + target Element identity`.\n *\n * The registry itself is never exposed on `window` — only the fixed\n * `ViceMe.versions.v1` diagnostics/destroy namespace is. It stores raw\n * capability handles; the loader wraps them into the public\n * `ViceMeMountedInstance` and owns destroy/event deduplication.\n */\n\nimport type { ViceMeClient } from '../core/client.ts';\nimport type { CapabilityMountHandle } from './mount-handle.ts';\n\nexport interface RegisteredClient {\n clientKey: string;\n client: ViceMeClient;\n ready: Promise<void>;\n}\n\nexport interface RegisteredInstance {\n instanceKey: string;\n clientKey: string;\n capability: string;\n host: Element;\n raw: CapabilityMountHandle;\n destroyed: boolean;\n}\n\nexport function clientKeyOf(majorVersion: number, region: string, workKey: string): string {\n return `v${majorVersion}+${region}+${workKey}`;\n}\n\nexport class LoaderRegistry {\n readonly #clients = new Map<string, RegisteredClient>();\n readonly #instances = new Map<string, RegisteredInstance>();\n /** (clientKey, capability) -> mounted host element -> instance. */\n readonly #elements = new Map<string, WeakMap<Element, RegisteredInstance>>();\n #elementCounter = 0;\n\n getClient(clientKey: string): RegisteredClient | undefined {\n return this.#clients.get(clientKey);\n }\n\n registerClient(entry: RegisteredClient): void {\n this.#clients.set(entry.clientKey, entry);\n }\n\n unregisterClient(clientKey: string): void {\n this.#clients.delete(clientKey);\n }\n\n getInstance(instanceKey: string): RegisteredInstance | undefined {\n return this.#instances.get(instanceKey);\n }\n\n /** Existing mount for the same client+capability+element, if any. */\n findInstance(\n clientKey: string,\n capability: string,\n element: Element,\n ): RegisteredInstance | undefined {\n return this.#elements.get(`${clientKey}::${capability}`)?.get(element);\n }\n\n registerInstance(\n clientKey: string,\n capability: string,\n element: Element,\n raw: CapabilityMountHandle,\n ): RegisteredInstance {\n const compositeKey = `${clientKey}::${capability}`;\n let byElement = this.#elements.get(compositeKey);\n if (byElement === undefined) {\n byElement = new WeakMap();\n this.#elements.set(compositeKey, byElement);\n }\n const existing = byElement.get(element);\n if (existing) return existing;\n\n this.#elementCounter += 1;\n const instance: RegisteredInstance = {\n instanceKey: `${clientKey}::${capability}::el${this.#elementCounter}`,\n clientKey,\n capability,\n host: element,\n raw,\n destroyed: false,\n };\n this.#instances.set(instance.instanceKey, instance);\n byElement.set(element, instance);\n return instance;\n }\n\n removeInstance(instanceKey: string): RegisteredInstance | undefined {\n const instance = this.#instances.get(instanceKey);\n if (!instance) return undefined;\n this.#instances.delete(instanceKey);\n this.#elements.get(`${instance.clientKey}::${instance.capability}`)?.delete(instance.host);\n return instance;\n }\n\n instancesForClient(clientKey: string): RegisteredInstance[] {\n return [...this.#instances.values()].filter((i) => i.clientKey === clientKey);\n }\n}\n","/**\n * Stable `viceme:*` DOM events.\n *\n * Dispatch target is the mount host element; configuration errors that happen\n * before a host exists are dispatched on `document`. Event details carry an\n * allowlisted field set only — never tokens, cookies, provider payloads, or\n * internal stacks.\n */\n\nimport type { ViceMeErrorCode } from '../core/errors.ts';\n\nexport interface VicemeReadyDetail {\n clientKey: string;\n workKey: string;\n capabilities: string[];\n version: string;\n}\n\nexport interface VicemeCapabilityReadyDetail {\n clientKey: string;\n instanceKey: string;\n capability: string;\n version: string;\n}\n\nexport interface VicemeErrorDetail {\n clientKey?: string;\n instanceKey?: string;\n capability?: string;\n code: ViceMeErrorCode;\n retryable: boolean;\n requestId?: string;\n}\n\nexport interface VicemeDestroyedDetail {\n clientKey: string;\n instanceKey: string;\n capability: string;\n}\n\nexport type VicemeEventType =\n 'viceme:ready' | 'viceme:capability-ready' | 'viceme:error' | 'viceme:destroyed';\n\nexport type VicemeEventDetailMap = {\n 'viceme:ready': VicemeReadyDetail;\n 'viceme:capability-ready': VicemeCapabilityReadyDetail;\n 'viceme:error': VicemeErrorDetail;\n 'viceme:destroyed': VicemeDestroyedDetail;\n};\n\nconst ALLOWED_KEYS: ReadonlyMap<VicemeEventType, ReadonlySet<string>> = new Map([\n ['viceme:ready', new Set(['clientKey', 'workKey', 'capabilities', 'version'])],\n ['viceme:capability-ready', new Set(['clientKey', 'instanceKey', 'capability', 'version'])],\n [\n 'viceme:error',\n new Set(['clientKey', 'instanceKey', 'capability', 'code', 'retryable', 'requestId']),\n ],\n ['viceme:destroyed', new Set(['clientKey', 'instanceKey', 'capability'])],\n]);\n\n/** Strip anything outside the documented allowlist before dispatch. */\nexport function sanitizeDetail(\n type: VicemeEventType,\n detail: VicemeEventDetailMap[VicemeEventType],\n): VicemeEventDetailMap[VicemeEventType] {\n const allowed = ALLOWED_KEYS.get(type)!;\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(detail)) {\n if (allowed.has(key) && value !== undefined) result[key] = value;\n }\n return result as unknown as VicemeEventDetailMap[VicemeEventType];\n}\n\nexport function dispatchViceMeEvent<K extends VicemeEventType>(\n target: EventTarget,\n type: K,\n detail: VicemeEventDetailMap[K],\n): void {\n const event = new CustomEvent(type, {\n detail: sanitizeDetail(type, detail),\n bubbles: true,\n composed: true,\n cancelable: false,\n });\n target.dispatchEvent(event);\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 * CDN auto-loader (`viceme.min.js`, IIFE).\n *\n * Deterministic algorithm (fixed baseline):\n *\n * 1. Read `document.currentScript`; when unavailable, accept exactly one\n * explicit `script[data-viceme-loader]`.\n * 2. Parse and validate `data-viceme-*`; build `clientKey` and per-feature\n * `instanceKey`s.\n * 3. Wait for DOM ready; a missing/ambiguous target emits `CONFIG_INVALID`\n * and never creates phantom nodes.\n * 4. Read `manifest.json` from the loader's own directory (exact release\n * version; URLs are never assembled from page parameters).\n * 5. Load the same-version core, then each declared feature chunk in order.\n * 6. Create the client, then mount; handles land in an internal registry.\n * 7. Re-running the same instance key returns the original handle — no\n * duplicate sessions, subscriptions, or DOM.\n * 8. A failing capability destroys only its own partial state; the rest of\n * the page and other capabilities keep working.\n * 9. `pagehide` never auto-destroys (bfcache); cleanup happens on explicit\n * `destroy()` only.\n *\n * The loader never writes localStorage, cookies, global CSS, or globals other\n * than the fixed `window.ViceMe.versions.vN` namespace.\n */\n\nimport { parseLoaderAttributes, type LoaderAttributes } from './attributes.ts';\nimport { LoaderRegistry, clientKeyOf, type RegisteredInstance } from './registry.ts';\nimport type { CapabilityMountHandle, CapabilityMountFunction } from './mount-handle.ts';\nimport { dispatchViceMeEvent, type VicemeErrorDetail } from './events.ts';\nimport { configInvalid, ViceMeError } from '../core/errors.ts';\nimport type { ViceMeClient, ViceMeMountedInstance } from '../core/client.ts';\nimport { API_MAJOR } from '../version.ts';\n\nexport interface ReleaseManifest {\n version: string;\n apiMajor: number;\n loader: string;\n features: Record<string, string>;\n}\n\ninterface CoreModule {\n createViceMe: (config: unknown) => ViceMeClient;\n}\n\n/** Internal surface the core implementation provides to the loader. */\ninterface InternalCoreClient extends ViceMeClient {\n markDegraded(): void;\n}\n\nexport interface ViceMeLoaderNamespaceV1 {\n readonly version: string;\n whenReady(clientKey: string): Promise<ViceMeClient>;\n getInstance(instanceKey: string): ViceMeMountedInstance | undefined;\n destroyInstance(instanceKey: string): void;\n destroyClient(clientKey: string): void;\n}\n\nexport interface ViceMeBrowserGlobal {\n versions: {\n // Other majors coexist; they are never overwritten by this loader.\n [major: string]: ViceMeLoaderNamespaceV1 | undefined;\n };\n}\n\nconst MANIFEST_TIMEOUT_MS = 8_000;\n\ninterface LoaderSharedState {\n registry: LoaderRegistry;\n /** Serialized run queue shared across every execution of this loader. */\n queue: { current: Promise<void> };\n}\n\nconst STATE_KEY = Symbol.for('viceme.loader.state.v1');\n\n/**\n * Loader state must survive multiple executions of the same (or an identical)\n * loader `<script>`: browsers execute each script tag as an independent IIFE,\n * so the registry and run queue live on a hidden, symbol-keyed, non-enumerable\n * global — never an undeclared string-named global.\n */\nfunction sharedState(): LoaderSharedState {\n const holder = globalThis as Record<symbol, unknown>;\n const existing = holder[STATE_KEY] as LoaderSharedState | undefined;\n if (existing) return existing;\n const state: LoaderSharedState = {\n registry: new LoaderRegistry(),\n queue: { current: Promise.resolve() },\n };\n Object.defineProperty(globalThis, STATE_KEY, {\n value: state,\n writable: true,\n configurable: true,\n enumerable: false,\n });\n return state;\n}\n\n/* ------------------------------------------------------------------ */\n/* Instance wrapper + destroy */\n/* ------------------------------------------------------------------ */\n\nfunction destroyInstanceInternal(instance: RegisteredInstance): void {\n if (instance.destroyed) return;\n instance.destroyed = true;\n sharedState().registry.removeInstance(instance.instanceKey);\n try {\n instance.raw.destroy();\n } finally {\n dispatchViceMeEvent(instance.host, 'viceme:destroyed', {\n clientKey: instance.clientKey,\n instanceKey: instance.instanceKey,\n capability: instance.capability,\n });\n }\n}\n\nfunction wrapInstance(instance: RegisteredInstance): ViceMeMountedInstance {\n return {\n instanceKey: instance.instanceKey,\n capability: instance.capability,\n destroy: () => destroyInstanceInternal(instance),\n };\n}\n\n/* ------------------------------------------------------------------ */\n/* Namespace installation */\n/* ------------------------------------------------------------------ */\n\nfunction defineHidden(target: object, key: string, value: unknown): void {\n Object.defineProperty(target, key, {\n value,\n writable: true,\n configurable: true,\n enumerable: false,\n });\n}\n\nexport function ensureNamespace(version: string): ViceMeLoaderNamespaceV1 {\n const holder = globalThis as { ViceMe?: ViceMeBrowserGlobal };\n let global = holder.ViceMe;\n if (!global) {\n global = {} as ViceMeBrowserGlobal;\n defineHidden(globalThis, 'ViceMe', global);\n }\n let versions = global.versions;\n if (!versions) {\n versions = {} as ViceMeBrowserGlobal['versions'];\n defineHidden(global, 'versions', versions);\n }\n const existing = versions[`v${API_MAJOR}`];\n if (existing) return existing;\n\n const namespace: ViceMeLoaderNamespaceV1 = {\n version,\n whenReady(clientKey: string): Promise<ViceMeClient> {\n const entry = sharedState().registry.getClient(clientKey);\n if (!entry) {\n return Promise.reject(configInvalid(`Unknown clientKey \"${clientKey}\".`));\n }\n return entry.ready.then(() => entry.client);\n },\n getInstance(instanceKey: string): ViceMeMountedInstance | undefined {\n const instance = sharedState().registry.getInstance(instanceKey);\n return instance ? wrapInstance(instance) : undefined;\n },\n destroyInstance(instanceKey: string): void {\n const instance = sharedState().registry.getInstance(instanceKey);\n if (instance) destroyInstanceInternal(instance);\n },\n destroyClient(clientKey: string): void {\n for (const instance of sharedState().registry.instancesForClient(clientKey)) {\n destroyInstanceInternal(instance);\n }\n const entry = sharedState().registry.getClient(clientKey);\n sharedState().registry.unregisterClient(clientKey);\n entry?.client.destroy();\n },\n };\n defineHidden(versions, `v${API_MAJOR}`, namespace);\n return namespace;\n}\n\n/* ------------------------------------------------------------------ */\n/* Loader algorithm */\n/* ------------------------------------------------------------------ */\n\nfunction whenDomReady(): Promise<void> {\n if (document.readyState !== 'loading') return Promise.resolve();\n return new Promise((resolve) => {\n document.addEventListener('DOMContentLoaded', () => resolve(), { once: true });\n });\n}\n\nasync function fetchReleaseManifest(\n manifestUrl: URL,\n): Promise<{ manifest: ReleaseManifest; baseUrl: URL }> {\n let response: Response;\n try {\n response = await fetchWithTimeout(manifestUrl);\n } catch {\n response = { ok: false, status: 0 } as Response;\n }\n // Alias path (e.g. /sdk/v1/) holds no manifest on the S3 topology: it\n // carries only the loader object plus the version POINTER. Resolve the\n // pointer and load the exact version beside it.\n if (!response.ok) {\n const aliasVersion = await resolveAliasPointer(manifestUrl);\n if (aliasVersion !== undefined) {\n const aliasUrl = new URL(`/viceme-sdk/${aliasVersion}/manifest.json`, manifestUrl);\n return { manifest: await parseManifest(await fetchWithTimeout(aliasUrl)), baseUrl: aliasUrl };\n }\n }\n return { manifest: await parseManifest(response), baseUrl: manifestUrl };\n}\n\nfunction fetchWithTimeout(url: URL): Promise<Response> {\n const signal =\n typeof AbortSignal !== 'undefined' && typeof AbortSignal.timeout === 'function'\n ? AbortSignal.timeout(MANIFEST_TIMEOUT_MS)\n : undefined;\n return fetch(url, { credentials: 'omit', signal });\n}\n\n/** Read /sdk/-/aliases/v1 when the loader itself sits under /sdk/v1/. */\nasync function resolveAliasPointer(manifestUrl: URL): Promise<string | undefined> {\n if (!/\\/viceme-sdk\\/[^/]+\\/manifest\\.json$/.test(manifestUrl.pathname)) return undefined;\n const segment = manifestUrl.pathname.split('/viceme-sdk/')[1]?.split('/')[0];\n if (segment !== `v${API_MAJOR}`) return undefined;\n try {\n const response = await fetchWithTimeout(new URL('/viceme-sdk/-/aliases/v1', manifestUrl));\n if (!response.ok) return undefined;\n const version = (await response.text()).trim();\n return /^\\d+\\.\\d+\\.\\d+(-[0-9A-Za-z.-]+)?$/.test(version) ? version : undefined;\n } catch {\n return undefined;\n }\n}\n\nasync function parseManifest(response: Response): Promise<ReleaseManifest> {\n if (!response.ok) {\n throw configInvalid(`Release manifest is not available (HTTP ${response.status}).`);\n }\n const body: unknown = await response.json();\n if (\n typeof body !== 'object' ||\n body === null ||\n typeof (body as ReleaseManifest).version !== 'string' ||\n typeof (body as ReleaseManifest).apiMajor !== 'number' ||\n typeof (body as ReleaseManifest).features !== 'object' ||\n (body as ReleaseManifest).features === null\n ) {\n throw configInvalid('Release manifest is malformed.');\n }\n const manifest = body as ReleaseManifest;\n if (manifest.apiMajor !== API_MAJOR) {\n throw configInvalid('Release manifest major version does not match this loader.');\n }\n return manifest;\n}\n\nasync function loadCore(baseUrl: URL): Promise<CoreModule> {\n const coreUrl = new URL('index.js', baseUrl);\n const core = (await import(/* @vite-ignore */ coreUrl.href)) as Partial<CoreModule>;\n if (typeof core.createViceMe !== 'function') {\n throw configInvalid('SDK core chunk does not export createViceMe().');\n }\n return core as CoreModule;\n}\n\nconst KNOWN_ERROR_CODES: ReadonlySet<string> = new Set([\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]);\n\n/**\n * Normalize any thrown value into an event detail. Uses structural checks,\n * not `instanceof`: the loader IIFE and the core ESM chunk are separate\n * builds, so their `ViceMeError` classes are distinct at runtime.\n */\nfunction toErrorDetail(error: unknown): VicemeErrorDetail {\n if (typeof error === 'object' && error !== null) {\n const candidate = error as Record<string, unknown>;\n if (\n typeof candidate.code === 'string' &&\n KNOWN_ERROR_CODES.has(candidate.code) &&\n typeof candidate.retryable === 'boolean'\n ) {\n const detail: VicemeErrorDetail = {\n code: candidate.code as VicemeErrorDetail['code'],\n retryable: candidate.retryable,\n };\n if (typeof candidate.requestId === 'string') detail.requestId = candidate.requestId;\n if (typeof candidate.capability === 'string') detail.capability = candidate.capability;\n return detail;\n }\n }\n return { code: 'INTERNAL_ERROR', retryable: true };\n}\n\nfunction emitError(\n target: EventTarget,\n error: unknown,\n extra: Partial<Pick<VicemeErrorDetail, 'clientKey' | 'instanceKey' | 'capability'>> = {},\n): void {\n dispatchViceMeEvent(target, 'viceme:error', { ...toErrorDetail(error), ...extra });\n}\n\nexport async function runAutoLoader(script: HTMLScriptElement): Promise<void> {\n let attributes: LoaderAttributes;\n try {\n attributes = parseLoaderAttributes(script);\n } catch (error) {\n // Configuration errors before any host exists go to `document`.\n emitError(document, error);\n return;\n }\n\n if (!script.src) {\n emitError(document, configInvalid('Loader script requires a src URL.'));\n return;\n }\n const manifestUrl = new URL('manifest.json', script.src);\n\n let manifest: ReleaseManifest;\n let releaseBase: URL;\n try {\n ({ manifest, baseUrl: releaseBase } = await fetchReleaseManifest(manifestUrl));\n } catch (error) {\n emitError(document, error, {\n clientKey: clientKeyOf(API_MAJOR, attributes.region, attributes.workKey),\n });\n return;\n }\n\n await whenDomReady();\n\n let host: Element;\n try {\n const matches = document.querySelectorAll(attributes.target!);\n if (matches.length === 0) {\n throw configInvalid(\n `Loader target \"${attributes.target}\" matched no element; no node was created.`,\n );\n }\n if (matches.length > 1) {\n throw configInvalid(\n `Loader target \"${attributes.target}\" matched ${matches.length} elements; exactly one is required.`,\n );\n }\n host = matches[0]!;\n } catch (error) {\n emitError(document, error, {\n clientKey: clientKeyOf(manifest.apiMajor, attributes.region, attributes.workKey),\n });\n return;\n }\n\n const clientKey = clientKeyOf(manifest.apiMajor, attributes.region, attributes.workKey);\n ensureNamespace(manifest.version);\n\n // Shared core client per (major, region, workKey).\n let entry = sharedState().registry.getClient(clientKey);\n let client: ViceMeClient;\n if (entry) {\n client = entry.client;\n } else {\n let core: CoreModule;\n try {\n core = await loadCore(releaseBase);\n } catch (error) {\n emitError(host, error, { clientKey });\n return;\n }\n client = core.createViceMe({\n workKey: attributes.workKey,\n region: attributes.region,\n });\n const ready = client.ready();\n // Keep an unhandled-rejection-free copy on the registry entry; failures\n // are reported through this loader run and via whenReady().\n void ready.catch(() => {});\n entry = { clientKey, client, ready };\n sharedState().registry.registerClient(entry);\n }\n\n try {\n await entry.ready;\n } catch (error) {\n sharedState().registry.unregisterClient(clientKey);\n client.destroy();\n emitError(host, error, { clientKey });\n return;\n }\n\n let mountedAny = false;\n const mounted: string[] = [];\n for (const capability of attributes.features) {\n // Same client + capability + element: reuse the original handle.\n if (sharedState().registry.findInstance(clientKey, capability, host)) continue;\n\n const fileName = manifest.features[capability];\n if (typeof fileName !== 'string') {\n (client as InternalCoreClient).markDegraded();\n emitError(\n host,\n new ViceMeError({\n code: 'CAPABILITY_DISABLED',\n message: `Capability \"${capability}\" is not part of this release.`,\n retryable: false,\n capability,\n }),\n { clientKey, capability },\n );\n continue;\n }\n\n try {\n const chunkUrl = new URL(fileName, releaseBase);\n const module = (await import(/* @vite-ignore */ chunkUrl.href)) as {\n mount?: unknown;\n };\n if (typeof module.mount !== 'function') {\n throw configInvalid(`Capability chunk \"${capability}\" does not export mount().`);\n }\n const raw = (await (module.mount as CapabilityMountFunction)(client, {\n target: host,\n theme: attributes.theme,\n })) as CapabilityMountHandle;\n const instance = sharedState().registry.registerInstance(clientKey, capability, host, raw);\n mountedAny = true;\n mounted.push(capability);\n dispatchViceMeEvent(host, 'viceme:capability-ready', {\n clientKey,\n instanceKey: instance.instanceKey,\n capability,\n version: manifest.version,\n });\n } catch (error) {\n // Only this capability's partial state is discarded; everything else\n // (including the host page) keeps working.\n (client as InternalCoreClient).markDegraded();\n emitError(host, error, { clientKey, capability });\n }\n }\n\n if (mountedAny) {\n dispatchViceMeEvent(host, 'viceme:ready', {\n clientKey,\n workKey: attributes.workKey,\n capabilities: mounted,\n version: manifest.version,\n });\n }\n}\n\n/* ------------------------------------------------------------------ */\n/* IIFE bootstrap */\n/* ------------------------------------------------------------------ */\n\n/**\n * Loader runs are serialized so identical scripts (duplicate tags, re-runs,\n * same work with different targets) observe registry state deterministically\n * and never create duplicate sessions or DOM.\n */\nfunction enqueueRun(script: HTMLScriptElement): Promise<void> {\n const { queue } = sharedState();\n const run = queue.current.then(() => runAutoLoader(script));\n queue.current = run.catch(() => {});\n return run;\n}\n\nfunction bootstrap(): void {\n if (typeof document === 'undefined') return;\n let script: HTMLScriptElement | null =\n document.currentScript instanceof HTMLScriptElement ? document.currentScript : null;\n if (!script) {\n const explicit = document.querySelectorAll<HTMLScriptElement>('script[data-viceme-loader]');\n if (explicit.length === 1) script = explicit[0] ?? null;\n }\n if (!script) return;\n void enqueueRun(script).catch((error: unknown) => {\n emitError(document, error);\n });\n}\n\nbootstrap();\n\n// Test-only handle for re-running the bootstrap in controlled environments.\nexport const __bootstrapForTests = bootstrap;\nexport type { RegisteredInstance };\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","KNOWN_ATTRIBUTES","FEATURE_NAME_PATTERN","THEMES","parseLoaderAttributes","element","name","workKey","rawFeatures","features","part","feature","target","rawTheme","clientKeyOf","majorVersion","LoaderRegistry","#clients","#instances","#elements","#elementCounter","clientKey","entry","instanceKey","capability","compositeKey","byElement","existing","instance","i","ALLOWED_KEYS","sanitizeDetail","type","detail","allowed","result","dispatchViceMeEvent","event","SDK_VERSION","API_MAJOR","MANIFEST_TIMEOUT_MS","STATE_KEY","sharedState","state","destroyInstanceInternal","wrapInstance","defineHidden","ensureNamespace","version","global","versions","namespace","whenDomReady","resolve","fetchReleaseManifest","manifestUrl","response","fetchWithTimeout","aliasVersion","resolveAliasPointer","aliasUrl","parseManifest","url","signal","body","manifest","loadCore","baseUrl","core","KNOWN_ERROR_CODES","toErrorDetail","error","candidate","emitError","extra","runAutoLoader","script","attributes","releaseBase","host","matches","client","ready","mountedAny","mounted","fileName","module","enqueueRun","queue","run","bootstrap","explicit","__bootstrapForTests"],"mappings":"yBA8BA,MAAMA,MAAyD,IAAI,CACjE,eACA,kBACA,uBACA,gBACF,CAAC,EAEM,MAAMC,UAAoB,KAAM,CAC5B,KACA,UACA,UACA,WAET,YAAYC,EAAuB,CACjC,MAAMA,EAAK,OAAO,EAClB,KAAK,KAAO,cACZ,KAAK,KAAOA,EAAK,KACjB,KAAK,UAAYA,EAAK,W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+C,EAAMD,EAAM,QAAQ,KAAK,IAAMb,EAAcC,CAAM,CAAC,EAC1D,OAAAY,EAAM,QAAUC,EAAI,MAAM,IAAM,CAAC,CAAC,EAC3BA,CACT,CAEA,SAASC,GAAkB,CACzB,GAAI,OAAO,SAAa,IAAa,OACrC,IAAId,EACF,SAAS,yBAAyB,kBAAoB,SAAS,cAAgB,KACjF,GAAI,CAACA,EAAQ,CACX,MAAMe,EAAW,SAAS,iBAAoC,4BAA4B,EACtFA,EAAS,SAAW,IAAGf,EAASe,EAAS,CAAC,GAAK,KACrD,CACKf,GACAW,EAAWX,CAAM,EAAE,MAAOL,GAAmB,CAChDE,EAAU,SAAUF,CAAK,CAC3B,CAAC,CACH,CAEAmB,EAAA,EAGO,MAAME,GAAsBF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@viceme-ai/sdk",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "ViceMe browser SDK: headless core, public session, and capability subpaths for static HTML, ESM, React, and Agent-generated sites.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/ViceMe-AI/sdk.git",
|
|
9
|
+
"directory": "packages/sdk"
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./testing": {
|
|
19
|
+
"types": "./dist/testing.d.ts",
|
|
20
|
+
"import": "./dist/testing.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"README.md",
|
|
26
|
+
"LICENSE"
|
|
27
|
+
],
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=20"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"clean": "node ../../scripts/rmrf.mjs dist test-fixtures-dist",
|
|
37
|
+
"build": "pnpm clean && pnpm build:esm && pnpm build:loader && pnpm build:bootstrap && pnpm build:types && pnpm build:fixture && pnpm build:manifest && pnpm build:license",
|
|
38
|
+
"build:esm": "vite build --config vite.config.esm.ts",
|
|
39
|
+
"build:loader": "vite build --config vite.config.loader.ts",
|
|
40
|
+
"build:bootstrap": "vite build --config vite.config.bootstrap.ts",
|
|
41
|
+
"build:types": "tsc -p tsconfig.build.json",
|
|
42
|
+
"build:fixture": "vite build --config vite.config.fixture.ts",
|
|
43
|
+
"build:manifest": "node ../../scripts/build-manifest.mjs",
|
|
44
|
+
"build:license": "node ../../scripts/sync-package-license.mjs",
|
|
45
|
+
"lint": "eslint .",
|
|
46
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"test:browser": "playwright test",
|
|
49
|
+
"pack:check": "node ../../scripts/inspect-tarball.mjs && node ../../scripts/verify-public-surface.mjs && node ../../scripts/check-size-budget.mjs"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@playwright/test": "^1.55.0",
|
|
53
|
+
"@types/node": "^24.3.0",
|
|
54
|
+
"happy-dom": "^18.0.1",
|
|
55
|
+
"typescript": "^5.9.2",
|
|
56
|
+
"vite": "^7.1.2",
|
|
57
|
+
"vitest": "^3.2.4"
|
|
58
|
+
}
|
|
59
|
+
}
|