@tangle-network/agent-app 0.60.6 → 0.60.7
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/dist/{DesignCanvas-OWE67ZX3.js → DesignCanvas-TW45DTK7.js} +3 -2
- package/dist/{DesignCanvasEditor-4FPLJ3YJ.js → DesignCanvasEditor-3DL3PF6P.js} +3 -2
- package/dist/app-auth/index.js +2 -1
- package/dist/app-auth/index.js.map +1 -1
- package/dist/assistant/index.js +1 -1
- package/dist/chat-routes/index.js +2 -1
- package/dist/chat-routes/index.js.map +1 -1
- package/dist/{chunk-DWUSVC3U.js → chunk-CN5HNTU6.js} +3 -3
- package/dist/chunk-MLDKEEFQ.js +48 -0
- package/dist/chunk-MLDKEEFQ.js.map +1 -0
- package/dist/chunk-RN4WPTBH.js +62 -0
- package/dist/chunk-RN4WPTBH.js.map +1 -0
- package/dist/{chunk-YNSPVKMS.js → chunk-UTAIRVOK.js} +1 -60
- package/dist/chunk-UTAIRVOK.js.map +1 -0
- package/dist/design-canvas/index.js +2 -1
- package/dist/design-canvas/index.js.map +1 -1
- package/dist/design-canvas-react/engine.js +2 -1
- package/dist/design-canvas-react/index.js +6 -5
- package/dist/design-canvas-react/index.js.map +1 -1
- package/dist/design-canvas-react/lazy.js +1 -1
- package/dist/operator/client.d.ts +76 -0
- package/dist/operator/contract.d.ts +255 -0
- package/dist/operator/index.d.ts +8 -0
- package/dist/operator/index.js +533 -0
- package/dist/operator/index.js.map +1 -0
- package/dist/operator/server.d.ts +101 -0
- package/dist/platform/index.js +5 -45
- package/dist/platform/index.js.map +1 -1
- package/dist/public-consultation/index.js +2 -1
- package/dist/public-consultation/index.js.map +1 -1
- package/dist/sequences/index.js +2 -1
- package/dist/sequences/index.js.map +1 -1
- package/dist/web/index.js +4 -2
- package/dist/web-react/index.js +4 -4
- package/package.json +6 -1
- package/dist/chunk-YNSPVKMS.js.map +0 -1
- /package/dist/{DesignCanvas-OWE67ZX3.js.map → DesignCanvas-TW45DTK7.js.map} +0 -0
- /package/dist/{DesignCanvasEditor-4FPLJ3YJ.js.map → DesignCanvasEditor-3DL3PF6P.js.map} +0 -0
- /package/dist/{chunk-DWUSVC3U.js.map → chunk-CN5HNTU6.js.map} +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// src/design-canvas-react/lazy.tsx
|
|
2
2
|
import { lazy } from "react";
|
|
3
3
|
var DesignCanvasLazy = lazy(
|
|
4
|
-
() => import("./DesignCanvasEditor-
|
|
4
|
+
() => import("./DesignCanvasEditor-3DL3PF6P.js").then((m) => ({ default: m.DesignCanvasEditor }))
|
|
5
5
|
);
|
|
6
6
|
var DesignCanvasChromeLazy = lazy(
|
|
7
|
-
() => import("./DesignCanvas-
|
|
7
|
+
() => import("./DesignCanvas-TW45DTK7.js").then((m) => ({ default: m.DesignCanvas }))
|
|
8
8
|
);
|
|
9
9
|
|
|
10
10
|
export {
|
|
11
11
|
DesignCanvasLazy,
|
|
12
12
|
DesignCanvasChromeLazy
|
|
13
13
|
};
|
|
14
|
-
//# sourceMappingURL=chunk-
|
|
14
|
+
//# sourceMappingURL=chunk-CN5HNTU6.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// src/platform/api-key-auth.ts
|
|
2
|
+
function createApiKeyRequestAuth(options) {
|
|
3
|
+
return async (request) => {
|
|
4
|
+
const authorization = request.headers.get("Authorization");
|
|
5
|
+
if (authorization === null) return null;
|
|
6
|
+
const bearer = /^Bearer +(\S+)$/i.exec(authorization);
|
|
7
|
+
if (!bearer) {
|
|
8
|
+
throw denied(401, "api_key.invalid", "Invalid API key");
|
|
9
|
+
}
|
|
10
|
+
const requiredScope = options.requiredScope(request);
|
|
11
|
+
const requiredScopes = typeof requiredScope === "string" ? [requiredScope] : Array.from(requiredScope ?? []);
|
|
12
|
+
if (!requiredScopes?.length || !requiredScopes.every((scope) => typeof scope === "string" && scope.trim())) {
|
|
13
|
+
throw denied(403, "api_key.route_denied", "API key access is not enabled for this route");
|
|
14
|
+
}
|
|
15
|
+
const key = await options.verify(`Bearer ${bearer[1]}`);
|
|
16
|
+
if (!key || !key.keyId?.trim() || !key.ownerId?.trim()) {
|
|
17
|
+
throw denied(401, "api_key.invalid", "Invalid API key");
|
|
18
|
+
}
|
|
19
|
+
if (!Number.isSafeInteger(key.expiresAt) || key.expiresAt <= Date.now()) {
|
|
20
|
+
throw denied(401, "api_key.expired", "An unexpired API key with a finite expiry is required");
|
|
21
|
+
}
|
|
22
|
+
if (!Array.isArray(key.scopes) || !requiredScopes.every((scope) => key.scopes.includes(scope))) {
|
|
23
|
+
throw denied(403, "api_key.insufficient_scope", `API key requires scopes: ${requiredScopes.join(", ")}`);
|
|
24
|
+
}
|
|
25
|
+
const identity = await options.resolveIdentity(key);
|
|
26
|
+
if (!identity) throw denied(401, "api_key.invalid_owner", "API key owner is unavailable");
|
|
27
|
+
const claim = await options.claimRequest(key, crypto.randomUUID());
|
|
28
|
+
if (claim.allowed !== true) {
|
|
29
|
+
const headers = new Headers();
|
|
30
|
+
if (Number.isFinite(claim.retryAfterSeconds) && claim.retryAfterSeconds > 0) {
|
|
31
|
+
headers.set("Retry-After", String(Math.ceil(claim.retryAfterSeconds)));
|
|
32
|
+
}
|
|
33
|
+
throw denied(429, "api_key.request_limit_exceeded", "API key request limit exceeded", headers);
|
|
34
|
+
}
|
|
35
|
+
if (key.expiresAt <= Date.now()) {
|
|
36
|
+
throw denied(401, "api_key.expired", "API key expired during authorization");
|
|
37
|
+
}
|
|
38
|
+
return identity;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function denied(status, code, error, headers) {
|
|
42
|
+
return Response.json({ error, code }, { status, headers });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export {
|
|
46
|
+
createApiKeyRequestAuth
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=chunk-MLDKEEFQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/platform/api-key-auth.ts"],"sourcesContent":["/** Verified key fields required to enter a product's private API routes. */\nexport interface RequestApiKey {\n keyId: string\n ownerId: string\n scopes: readonly string[]\n /** Unix epoch milliseconds. Private API credentials must expire. */\n expiresAt: number\n}\n\nexport interface ApiKeyRequestAuthOptions<Key extends RequestApiKey, Identity> {\n /** Verify against the existing key store, including revocation and spending limits. */\n verify(authorization: string): Promise<Key | null>\n /** Return one scope or all required scopes; null or an empty list denies the route. */\n requiredScope(request: Request): string | readonly string[] | null\n /** Load the owner from product storage; retain normal workspace and tenant authorization. */\n resolveIdentity(key: Key): Promise<Identity | null>\n /** Atomically enforce the existing key's request quotas before admitting the request. */\n claimRequest(key: Key, requestId: string): Promise<{ allowed: boolean; retryAfterSeconds?: number }>\n}\n\n/**\n * Adapt existing Bearer keys to private product routes without issuing sessions.\n * Only absent authorization returns null; supplied invalid credentials never\n * fall through to cookie authentication. Callers retain their ordinary RBAC.\n */\nexport function createApiKeyRequestAuth<Key extends RequestApiKey, Identity>(\n options: ApiKeyRequestAuthOptions<Key, Identity>,\n): (request: Request) => Promise<Identity | null> {\n return async (request) => {\n const authorization = request.headers.get('Authorization')\n if (authorization === null) return null\n const bearer = /^Bearer +(\\S+)$/i.exec(authorization)\n if (!bearer) {\n throw denied(401, 'api_key.invalid', 'Invalid API key')\n }\n const requiredScope = options.requiredScope(request)\n const requiredScopes = typeof requiredScope === 'string' ? [requiredScope] : Array.from(requiredScope ?? [])\n if (!requiredScopes?.length || !requiredScopes.every(scope => typeof scope === 'string' && scope.trim())) {\n throw denied(403, 'api_key.route_denied', 'API key access is not enabled for this route')\n }\n const key = await options.verify(`Bearer ${bearer[1]}`)\n if (!key || !key.keyId?.trim() || !key.ownerId?.trim()) {\n throw denied(401, 'api_key.invalid', 'Invalid API key')\n }\n if (!Number.isSafeInteger(key.expiresAt) || key.expiresAt <= Date.now()) {\n throw denied(401, 'api_key.expired', 'An unexpired API key with a finite expiry is required')\n }\n if (!Array.isArray(key.scopes) || !requiredScopes.every(scope => key.scopes.includes(scope))) {\n throw denied(403, 'api_key.insufficient_scope', `API key requires scopes: ${requiredScopes.join(', ')}`)\n }\n const identity = await options.resolveIdentity(key)\n if (!identity) throw denied(401, 'api_key.invalid_owner', 'API key owner is unavailable')\n const claim = await options.claimRequest(key, crypto.randomUUID())\n if (claim.allowed !== true) {\n const headers = new Headers()\n if (Number.isFinite(claim.retryAfterSeconds) && claim.retryAfterSeconds! > 0) {\n headers.set('Retry-After', String(Math.ceil(claim.retryAfterSeconds!)))\n }\n throw denied(429, 'api_key.request_limit_exceeded', 'API key request limit exceeded', headers)\n }\n if (key.expiresAt <= Date.now()) {\n throw denied(401, 'api_key.expired', 'API key expired during authorization')\n }\n return identity\n }\n}\n\nfunction denied(status: number, code: string, error: string, headers?: Headers): Response {\n return Response.json({ error, code }, { status, headers })\n}\n"],"mappings":";AAyBO,SAAS,wBACd,SACgD;AAChD,SAAO,OAAO,YAAY;AACxB,UAAM,gBAAgB,QAAQ,QAAQ,IAAI,eAAe;AACzD,QAAI,kBAAkB,KAAM,QAAO;AACnC,UAAM,SAAS,mBAAmB,KAAK,aAAa;AACpD,QAAI,CAAC,QAAQ;AACX,YAAM,OAAO,KAAK,mBAAmB,iBAAiB;AAAA,IACxD;AACA,UAAM,gBAAgB,QAAQ,cAAc,OAAO;AACnD,UAAM,iBAAiB,OAAO,kBAAkB,WAAW,CAAC,aAAa,IAAI,MAAM,KAAK,iBAAiB,CAAC,CAAC;AAC3G,QAAI,CAAC,gBAAgB,UAAU,CAAC,eAAe,MAAM,WAAS,OAAO,UAAU,YAAY,MAAM,KAAK,CAAC,GAAG;AACxG,YAAM,OAAO,KAAK,wBAAwB,8CAA8C;AAAA,IAC1F;AACA,UAAM,MAAM,MAAM,QAAQ,OAAO,UAAU,OAAO,CAAC,CAAC,EAAE;AACtD,QAAI,CAAC,OAAO,CAAC,IAAI,OAAO,KAAK,KAAK,CAAC,IAAI,SAAS,KAAK,GAAG;AACtD,YAAM,OAAO,KAAK,mBAAmB,iBAAiB;AAAA,IACxD;AACA,QAAI,CAAC,OAAO,cAAc,IAAI,SAAS,KAAK,IAAI,aAAa,KAAK,IAAI,GAAG;AACvE,YAAM,OAAO,KAAK,mBAAmB,uDAAuD;AAAA,IAC9F;AACA,QAAI,CAAC,MAAM,QAAQ,IAAI,MAAM,KAAK,CAAC,eAAe,MAAM,WAAS,IAAI,OAAO,SAAS,KAAK,CAAC,GAAG;AAC5F,YAAM,OAAO,KAAK,8BAA8B,4BAA4B,eAAe,KAAK,IAAI,CAAC,EAAE;AAAA,IACzG;AACA,UAAM,WAAW,MAAM,QAAQ,gBAAgB,GAAG;AAClD,QAAI,CAAC,SAAU,OAAM,OAAO,KAAK,yBAAyB,8BAA8B;AACxF,UAAM,QAAQ,MAAM,QAAQ,aAAa,KAAK,OAAO,WAAW,CAAC;AACjE,QAAI,MAAM,YAAY,MAAM;AAC1B,YAAM,UAAU,IAAI,QAAQ;AAC5B,UAAI,OAAO,SAAS,MAAM,iBAAiB,KAAK,MAAM,oBAAqB,GAAG;AAC5E,gBAAQ,IAAI,eAAe,OAAO,KAAK,KAAK,MAAM,iBAAkB,CAAC,CAAC;AAAA,MACxE;AACA,YAAM,OAAO,KAAK,kCAAkC,kCAAkC,OAAO;AAAA,IAC/F;AACA,QAAI,IAAI,aAAa,KAAK,IAAI,GAAG;AAC/B,YAAM,OAAO,KAAK,mBAAmB,sCAAsC;AAAA,IAC7E;AACA,WAAO;AAAA,EACT;AACF;AAEA,SAAS,OAAO,QAAgB,MAAc,OAAe,SAA6B;AACxF,SAAO,SAAS,KAAK,EAAE,OAAO,KAAK,GAAG,EAAE,QAAQ,QAAQ,CAAC;AAC3D;","names":[]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// src/web/api-key-fetch.ts
|
|
2
|
+
function createApiKeyFetch(options) {
|
|
3
|
+
const origin = new URL(options.origin);
|
|
4
|
+
const loopback = ["localhost", "127.0.0.1", "[::1]"].includes(origin.hostname);
|
|
5
|
+
if (origin.username || origin.password || origin.pathname !== "/" || origin.search || origin.hash || origin.protocol !== "https:" && !(origin.protocol === "http:" && loopback && options.allowHttpLoopback)) {
|
|
6
|
+
throw new TypeError("API origin must be HTTPS without credentials, path, query, or fragment");
|
|
7
|
+
}
|
|
8
|
+
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
9
|
+
if (typeof fetchImpl !== "function") throw new TypeError("A fetch implementation is required");
|
|
10
|
+
const getApiKey = options.getApiKey;
|
|
11
|
+
return async (path, init = {}) => {
|
|
12
|
+
if (typeof path !== "string" || !path.startsWith("/") || path.startsWith("//") || /[\\\u0000-\u0020\u007f]/.test(path)) {
|
|
13
|
+
throw new TypeError("API requests require a root-relative path without whitespace or backslashes");
|
|
14
|
+
}
|
|
15
|
+
const target = new URL(path, origin);
|
|
16
|
+
if (target.origin !== origin.origin || target.username || target.password || target.hash) {
|
|
17
|
+
throw new TypeError("API requests must stay on the configured origin without a fragment");
|
|
18
|
+
}
|
|
19
|
+
const headers = new Headers(init.headers);
|
|
20
|
+
if (headers.has("authorization") || headers.has("cookie") || headers.has("proxy-authorization")) {
|
|
21
|
+
throw new TypeError("Authentication headers must come from the configured secret resolver");
|
|
22
|
+
}
|
|
23
|
+
init.signal?.throwIfAborted();
|
|
24
|
+
let apiKey;
|
|
25
|
+
try {
|
|
26
|
+
apiKey = await getApiKey();
|
|
27
|
+
} catch {
|
|
28
|
+
throw new Error("API credential is unavailable");
|
|
29
|
+
}
|
|
30
|
+
if (typeof apiKey !== "string" || !apiKey || /\s|[^\x21-\x7e]/.test(apiKey)) {
|
|
31
|
+
throw new TypeError("API credential must be a nonempty printable token without whitespace");
|
|
32
|
+
}
|
|
33
|
+
init.signal?.throwIfAborted();
|
|
34
|
+
headers.set("Authorization", `Bearer ${apiKey}`);
|
|
35
|
+
let response;
|
|
36
|
+
try {
|
|
37
|
+
response = await fetchImpl(target.href, {
|
|
38
|
+
...init,
|
|
39
|
+
headers,
|
|
40
|
+
credentials: "omit",
|
|
41
|
+
redirect: "manual",
|
|
42
|
+
referrerPolicy: "no-referrer"
|
|
43
|
+
});
|
|
44
|
+
} catch {
|
|
45
|
+
init.signal?.throwIfAborted();
|
|
46
|
+
throw new Error("API transport failed; inspect retained state before retrying a write");
|
|
47
|
+
}
|
|
48
|
+
if (response.type === "opaqueredirect" || response.redirected || response.status >= 300 && response.status < 400 && response.status !== 304) {
|
|
49
|
+
try {
|
|
50
|
+
await response.body?.cancel();
|
|
51
|
+
} catch {
|
|
52
|
+
}
|
|
53
|
+
throw new Error("API redirects are not allowed");
|
|
54
|
+
}
|
|
55
|
+
return response;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export {
|
|
60
|
+
createApiKeyFetch
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=chunk-RN4WPTBH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/web/api-key-fetch.ts"],"sourcesContent":["/** A credential-bearing client for one application origin, not a web fetch tool. */\nexport interface ApiKeyFetchOptions {\n origin: string\n /** Resolve from trusted client secret storage; never from an agent's arguments. */\n getApiKey(): string | Promise<string>\n fetchImpl?: typeof fetch\n /** Explicit local-development opt-in; never permits remote plaintext origins. */\n allowHttpLoopback?: boolean\n}\n\nexport type ApiKeyFetch = (path: string, init?: RequestInit) => Promise<Response>\n\n/** No redirects, cookie fallback, hidden retries, or model-selected credential destination. */\nexport function createApiKeyFetch(options: ApiKeyFetchOptions): ApiKeyFetch {\n const origin = new URL(options.origin)\n const loopback = ['localhost', '127.0.0.1', '[::1]'].includes(origin.hostname)\n if (origin.username || origin.password || origin.pathname !== '/' || origin.search || origin.hash\n || (origin.protocol !== 'https:' && !(origin.protocol === 'http:' && loopback && options.allowHttpLoopback))) {\n throw new TypeError('API origin must be HTTPS without credentials, path, query, or fragment')\n }\n const fetchImpl = options.fetchImpl ?? globalThis.fetch\n if (typeof fetchImpl !== 'function') throw new TypeError('A fetch implementation is required')\n const getApiKey = options.getApiKey\n\n return async (path, init = {}) => {\n // Reject URL-parser repairs and authority-relative references before resolving secrets.\n if (typeof path !== 'string' || !path.startsWith('/') || path.startsWith('//')\n || /[\\\\\\u0000-\\u0020\\u007f]/.test(path)) {\n throw new TypeError('API requests require a root-relative path without whitespace or backslashes')\n }\n const target = new URL(path, origin)\n if (target.origin !== origin.origin || target.username || target.password || target.hash) {\n throw new TypeError('API requests must stay on the configured origin without a fragment')\n }\n const headers = new Headers(init.headers)\n if (headers.has('authorization') || headers.has('cookie') || headers.has('proxy-authorization')) {\n throw new TypeError('Authentication headers must come from the configured secret resolver')\n }\n init.signal?.throwIfAborted()\n let apiKey: string\n try {\n apiKey = await getApiKey()\n } catch {\n throw new Error('API credential is unavailable')\n }\n if (typeof apiKey !== 'string' || !apiKey || /\\s|[^\\x21-\\x7e]/.test(apiKey)) {\n throw new TypeError('API credential must be a nonempty printable token without whitespace')\n }\n init.signal?.throwIfAborted()\n headers.set('Authorization', `Bearer ${apiKey}`)\n let response: Response\n try {\n response = await fetchImpl(target.href, {\n ...init, headers, credentials: 'omit', redirect: 'manual', referrerPolicy: 'no-referrer',\n })\n } catch {\n // A failed transport does not establish that an external action did not run.\n // Do not forward an adapter's diagnostic, which could include the bearer.\n init.signal?.throwIfAborted()\n throw new Error('API transport failed; inspect retained state before retrying a write')\n }\n if (response.type === 'opaqueredirect' || response.redirected\n || (response.status >= 300 && response.status < 400 && response.status !== 304)) {\n try { await response.body?.cancel() } catch { /* Preserve the redirect refusal. */ }\n throw new Error('API redirects are not allowed')\n }\n return response\n }\n}\n"],"mappings":";AAaO,SAAS,kBAAkB,SAA0C;AAC1E,QAAM,SAAS,IAAI,IAAI,QAAQ,MAAM;AACrC,QAAM,WAAW,CAAC,aAAa,aAAa,OAAO,EAAE,SAAS,OAAO,QAAQ;AAC7E,MAAI,OAAO,YAAY,OAAO,YAAY,OAAO,aAAa,OAAO,OAAO,UAAU,OAAO,QACvF,OAAO,aAAa,YAAY,E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,CAAC;AAAA,IACH,QAAQ;AAGN,WAAK,QAAQ,eAAe;AAC5B,YAAM,IAAI,MAAM,sEAAsE;AAAA,IACxF;AACA,QAAI,SAAS,SAAS,oBAAoB,SAAS,cAC7C,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO,SAAS,WAAW,KAAM;AACjF,UAAI;AAAE,cAAM,SAAS,MAAM,OAAO;AAAA,MAAE,QAAQ;AAAA,MAAuC;AACnF,YAAM,IAAI,MAAM,+BAA+B;AAAA,IACjD;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -29,64 +29,6 @@ function groupConversationMessages(items = []) {
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
// src/web/api-key-fetch.ts
|
|
33
|
-
function createApiKeyFetch(options) {
|
|
34
|
-
const origin2 = new URL(options.origin);
|
|
35
|
-
const loopback = ["localhost", "127.0.0.1", "[::1]"].includes(origin2.hostname);
|
|
36
|
-
if (origin2.username || origin2.password || origin2.pathname !== "/" || origin2.search || origin2.hash || origin2.protocol !== "https:" && !(origin2.protocol === "http:" && loopback && options.allowHttpLoopback)) {
|
|
37
|
-
throw new TypeError("API origin must be HTTPS without credentials, path, query, or fragment");
|
|
38
|
-
}
|
|
39
|
-
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
40
|
-
if (typeof fetchImpl !== "function") throw new TypeError("A fetch implementation is required");
|
|
41
|
-
const getApiKey = options.getApiKey;
|
|
42
|
-
return async (path, init = {}) => {
|
|
43
|
-
if (typeof path !== "string" || !path.startsWith("/") || path.startsWith("//") || /[\\\u0000-\u0020\u007f]/.test(path)) {
|
|
44
|
-
throw new TypeError("API requests require a root-relative path without whitespace or backslashes");
|
|
45
|
-
}
|
|
46
|
-
const target = new URL(path, origin2);
|
|
47
|
-
if (target.origin !== origin2.origin || target.username || target.password || target.hash) {
|
|
48
|
-
throw new TypeError("API requests must stay on the configured origin without a fragment");
|
|
49
|
-
}
|
|
50
|
-
const headers = new Headers(init.headers);
|
|
51
|
-
if (headers.has("authorization") || headers.has("cookie") || headers.has("proxy-authorization")) {
|
|
52
|
-
throw new TypeError("Authentication headers must come from the configured secret resolver");
|
|
53
|
-
}
|
|
54
|
-
init.signal?.throwIfAborted();
|
|
55
|
-
let apiKey;
|
|
56
|
-
try {
|
|
57
|
-
apiKey = await getApiKey();
|
|
58
|
-
} catch {
|
|
59
|
-
throw new Error("API credential is unavailable");
|
|
60
|
-
}
|
|
61
|
-
if (typeof apiKey !== "string" || !apiKey || /\s|[^\x21-\x7e]/.test(apiKey)) {
|
|
62
|
-
throw new TypeError("API credential must be a nonempty printable token without whitespace");
|
|
63
|
-
}
|
|
64
|
-
init.signal?.throwIfAborted();
|
|
65
|
-
headers.set("Authorization", `Bearer ${apiKey}`);
|
|
66
|
-
let response;
|
|
67
|
-
try {
|
|
68
|
-
response = await fetchImpl(target.href, {
|
|
69
|
-
...init,
|
|
70
|
-
headers,
|
|
71
|
-
credentials: "omit",
|
|
72
|
-
redirect: "manual",
|
|
73
|
-
referrerPolicy: "no-referrer"
|
|
74
|
-
});
|
|
75
|
-
} catch {
|
|
76
|
-
init.signal?.throwIfAborted();
|
|
77
|
-
throw new Error("API transport failed; inspect retained state before retrying a write");
|
|
78
|
-
}
|
|
79
|
-
if (response.type === "opaqueredirect" || response.redirected || response.status >= 300 && response.status < 400 && response.status !== 304) {
|
|
80
|
-
try {
|
|
81
|
-
await response.body?.cancel();
|
|
82
|
-
} catch {
|
|
83
|
-
}
|
|
84
|
-
throw new Error("API redirects are not allowed");
|
|
85
|
-
}
|
|
86
|
-
return response;
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
32
|
// src/web/acquisition.ts
|
|
91
33
|
var RETENTION_SECONDS = 30 * 24 * 60 * 60;
|
|
92
34
|
var MAX_COOKIE_BYTES = 3600;
|
|
@@ -165,9 +107,8 @@ function firstTouchAcquisitionCookie(request, cookieName, now = Date.now(), igno
|
|
|
165
107
|
|
|
166
108
|
export {
|
|
167
109
|
groupConversationMessages,
|
|
168
|
-
createApiKeyFetch,
|
|
169
110
|
acquisitionFromRequest,
|
|
170
111
|
readFirstTouchAcquisition,
|
|
171
112
|
firstTouchAcquisitionCookie
|
|
172
113
|
};
|
|
173
|
-
//# sourceMappingURL=chunk-
|
|
114
|
+
//# sourceMappingURL=chunk-UTAIRVOK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/web/message-groups.ts","../src/web/acquisition.ts"],"sourcesContent":["/** Renderer-neutral attribution. Not a transcript merger or an execution state machine. */\nexport interface ConversationGroupItem {\n id?: string | number\n kind?: string\n role?: string\n /** A different assistant/persona must never inherit the previous speaker's label. */\n speakerId?: string\n /** Distinct threads must not be grouped if their rows share a viewport. */\n conversationId?: string\n}\nexport type GroupedConversationItem<T> = T & { isContinuation?: boolean; groupId?: string }\n\n/**\n * Annotate assistant rows until an actual user message, speaker or conversation change.\n * Tool/progress notices do not interrupt the group. The first visible assistant is\n * always labeled, including when a renderer has paged earlier history away.\n * Pass display order; stored content, IDs, timestamps and input objects are untouched.\n */\nexport function groupConversationMessages<T extends ConversationGroupItem>(items: readonly T[] = []): GroupedConversationItem<T>[] {\n let speaker: string | null = null\n let conversation: string | undefined\n let groupId: string | undefined\n return items.map((item, index) => {\n if (item.conversationId !== undefined && item.conversationId !== conversation) {\n conversation = item.conversationId\n speaker = null\n groupId = undefined\n }\n const role = item.kind === 'thinking' ? 'assistant' : (!item.kind || item.kind === 'message' ? item.role : undefined)\n if (role === 'user') { speaker = null; groupId = undefined; return { ...item, isContinuation: false } }\n if (role !== 'assistant') return item\n const current = item.speakerId ?? 'assistant'\n const isContinuation = speaker === current\n if (!isContinuation) groupId = String(item.id ?? `assistant-${index}`)\n speaker = current\n return { ...item, isContinuation, groupId }\n })\n}\n","import { readCookieValue, serializeCookie } from './core'\n\nconst RETENTION_SECONDS = 30 * 24 * 60 * 60\nconst MAX_COOKIE_BYTES = 3600\nconst CAMPAIGN_FIELDS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term'] as const\nconst CLICK_FIELDS = ['gclid', 'gbraid', 'wbraid', 'fbclid', 'msclkid', 'ttclid', 'li_fat_id', 'twclid'] as const\nconst FIELDS = [...CAMPAIGN_FIELDS, ...CLICK_FIELDS] as const\n\n/** Untrusted acquisition hints. Never use these fields for identity or authorization. */\nexport interface FirstTouchAcquisition {\n parameters: Partial<Record<typeof FIELDS[number], string>>\n referrerOrigin: string | null\n landingPath: string\n firstSeenAt: number\n test: boolean\n}\n\nfunction bounded(value: unknown, limit = 160): string | undefined {\n if (typeof value !== 'string') return undefined\n const text = value.trim().replace(/[\\u0000-\\u001f\\u007f]/g, '').slice(0, limit)\n return text || undefined\n}\n\nfunction origin(value: string | null): string | null {\n if (!value) return null\n try {\n const url = new URL(value)\n return ['https:', 'http:'].includes(url.protocol) ? url.origin : null\n } catch { return null }\n}\n\n/** Capture only campaign fields and an external origin, never URL queries or referrer paths. */\nexport function acquisitionFromRequest(request: Request, now = Date.now(), ignoredReferrerOrigins: readonly string[] = []): FirstTouchAcquisition | null {\n const url = new URL(request.url)\n const parameters: FirstTouchAcquisition['parameters'] = {}\n for (const field of FIELDS) {\n const value = bounded(url.searchParams.get(field))\n if (value) parameters[field] = value\n }\n const referrer = origin(request.headers.get('referer'))\n const referrerOrigin = referrer === url.origin || (referrer !== null && ignoredReferrerOrigins.includes(referrer)) ? null : referrer\n if (!Object.keys(parameters).length && !referrerOrigin) return null\n return {\n parameters,\n referrerOrigin,\n landingPath: url.pathname.slice(0, 300),\n firstSeenAt: now,\n test: url.searchParams.get('attribution_test') === '1',\n }\n}\n\n/** Reject expired, future, malformed, and oversized hints without affecting authentication. */\nexport function readFirstTouchAcquisition(request: Request, cookieName: string, now = Date.now()): FirstTouchAcquisition | null {\n const raw = readCookieValue(request.headers.get('cookie'), cookieName)\n if (!raw || encodeURIComponent(raw).length > MAX_COOKIE_BYTES) return null\n try {\n const value: unknown = JSON.parse(raw)\n if (!value || typeof value !== 'object' || Array.isArray(value)) return null\n const input = value as Record<string, unknown>\n if (typeof input.firstSeenAt !== 'number' || !Number.isFinite(input.firstSeenAt)\n || input.firstSeenAt > now || input.firstSeenAt < now - RETENTION_SECONDS * 1000) return null\n if (typeof input.landingPath !== 'string' || !input.landingPath.startsWith('/')\n || input.landingPath.includes('?') || input.landingPath.includes('#')) return null\n if (!input.parameters || typeof input.parameters !== 'object' || Array.isArray(input.parameters)) return null\n const parameters: FirstTouchAcquisition['parameters'] = {}\n const source = input.parameters as Record<string, unknown>\n for (const field of FIELDS) {\n const value = bounded(source[field])\n if (value) parameters[field] = value\n }\n const referrerOrigin = typeof input.referrerOrigin === 'string' ? origin(input.referrerOrigin) : null\n if (!Object.keys(parameters).length && !referrerOrigin) return null\n return { parameters, referrerOrigin, landingPath: input.landingPath.slice(0, 300), firstSeenAt: input.firstSeenAt, test: input.test === true }\n } catch { return null }\n}\n\n/** Host-only HttpOnly cookie survives a top-level sign-in round trip. First valid touch wins. */\nexport function firstTouchAcquisitionCookie(request: Request, cookieName: string, now = Date.now(), ignoredReferrerOrigins: readonly string[] = []): string | null {\n if (readFirstTouchAcquisition(request, cookieName, now)) return null\n const acquisition = acquisitionFromRequest(request, now, ignoredReferrerOrigins)\n if (!acquisition) return null\n const raw = JSON.stringify(acquisition)\n if (encodeURIComponent(raw).length > MAX_COOKIE_BYTES) return null\n return serializeCookie(raw, {\n name: cookieName,\n httpOnly: true,\n sameSite: 'Lax',\n secure: new URL(request.url).protocol === 'https:',\n maxAgeSeconds: RETENTION_SECONDS,\n })\n}\n"],"mappings":";;;;;;AAkBO,SAAS,0BAA2D,QAAsB,CAAC,GAAiC;AACjI,MAAI,UAAyB;AAC7B,MAAI;AACJ,MAAI;AACJ,SAAO,MAAM,IAAI,CAAC,MAAM,UAAU;AAChC,QAAI,KAAK,mBAAmB,UAAa,KAAK,mBAAmB,cAAc;AAC7E,qBAAe,KAAK;AACpB,gBAAU;AACV,gBA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AAM,aAAkD,CAAC;AACzD,UAAM,SAAS,MAAM;AACrB,eAAW,SAAS,QAAQ;AAC1B,YAAMA,SAAQ,QAAQ,OAAO,KAAK,CAAC;AACnC,UAAIA,OAAO,YAAW,KAAK,IAAIA;AAAA,IACjC;AACA,UAAM,iBAAiB,OAAO,MAAM,mBAAmB,WAAW,OAAO,MAAM,cAAc,IAAI;AACjG,QAAI,CAAC,OAAO,KAAK,UAAU,EAAE,UAAU,CAAC,eAAgB,QAAO;AAC/D,WAAO,EAAE,YAAY,gBAAgB,aAAa,MAAM,YAAY,MAAM,GAAG,GAAG,GAAG,aAAa,MAAM,aAAa,MAAM,MAAM,SAAS,KAAK;AAAA,EAC/I,QAAQ;AAAE,WAAO;AAAA,EAAK;AACxB;AAGO,SAAS,4BAA4B,SAAkB,YAAoB,MAAM,KAAK,IAAI,GAAG,yBAA4C,CAAC,GAAkB;AACjK,MAAI,0BAA0B,SAAS,YAAY,GAAG,EAAG,QAAO;AAChE,QAAM,cAAc,uBAAuB,SAAS,KAAK,sBAAsB;AAC/E,MAAI,CAAC,YAAa,QAAO;AACzB,QAAM,MAAM,KAAK,UAAU,WAAW;AACtC,MAAI,mBAAmB,GAAG,EAAE,SAAS,iBAAkB,QAAO;AAC9D,SAAO,gBAAgB,KAAK;AAAA,IAC1B,MAAM;AAAA,IACN,UAAU;AAAA,IACV,UAAU;AAAA,IACV,QAAQ,IAAI,IAAI,QAAQ,GAAG,EAAE,aAAa;AAAA,IAC1C,eAAe;AAAA,EACjB,CAAC;AACH;","names":["value"]}
|
|
@@ -35,7 +35,8 @@ import {
|
|
|
35
35
|
buildScopedMcpServerEntry,
|
|
36
36
|
createMcpToolHandler
|
|
37
37
|
} from "../chunk-6A7MYOUI.js";
|
|
38
|
-
import "../chunk-
|
|
38
|
+
import "../chunk-UTAIRVOK.js";
|
|
39
|
+
import "../chunk-RN4WPTBH.js";
|
|
39
40
|
import "../chunk-3NCPXNBZ.js";
|
|
40
41
|
import "../chunk-TXD5HXLE.js";
|
|
41
42
|
|