@tangle-network/agent-app 0.52.8 → 0.52.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{DesignCanvas-H6PVRRLU.js → DesignCanvas-BVBMDXBZ.js} +2 -2
- package/dist/{DesignCanvasEditor-Z6UUPJKS.js → DesignCanvasEditor-3R6KODJG.js} +2 -2
- package/dist/app-auth/index.js +1 -1
- package/dist/chat-routes/index.js +1 -1
- package/dist/{chunk-4S74YVLU.js → chunk-3YVSRH26.js} +3 -3
- package/dist/chunk-YNSPVKMS.js +173 -0
- package/dist/chunk-YNSPVKMS.js.map +1 -0
- package/dist/design-canvas/index.js +1 -1
- package/dist/design-canvas-react/engine.js +1 -1
- package/dist/design-canvas-react/index.js +2 -2
- package/dist/design-canvas-react/lazy.js +1 -1
- package/dist/platform/index.js +1 -1
- package/dist/public-consultation/index.js +1 -1
- package/dist/sequences/index.js +1 -1
- package/dist/web/acquisition.d.ts +16 -0
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js +8 -2
- package/package.json +1 -1
- package/dist/chunk-TZEEGDHS.js +0 -89
- package/dist/chunk-TZEEGDHS.js.map +0 -1
- /package/dist/{DesignCanvas-H6PVRRLU.js.map → DesignCanvas-BVBMDXBZ.js.map} +0 -0
- /package/dist/{DesignCanvasEditor-Z6UUPJKS.js.map → DesignCanvasEditor-3R6KODJG.js.map} +0 -0
- /package/dist/{chunk-4S74YVLU.js.map → chunk-3YVSRH26.js.map} +0 -0
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
} from "./chunk-YJYPXMDL.js";
|
|
4
4
|
import "./chunk-HQ7R6CGM.js";
|
|
5
5
|
import "./chunk-H6XQZFTT.js";
|
|
6
|
-
import "./chunk-
|
|
6
|
+
import "./chunk-YNSPVKMS.js";
|
|
7
7
|
import "./chunk-3NCPXNBZ.js";
|
|
8
8
|
import "./chunk-TXD5HXLE.js";
|
|
9
9
|
export {
|
|
10
10
|
DesignCanvas
|
|
11
11
|
};
|
|
12
|
-
//# sourceMappingURL=DesignCanvas-
|
|
12
|
+
//# sourceMappingURL=DesignCanvas-BVBMDXBZ.js.map
|
|
@@ -6,10 +6,10 @@ import "./chunk-C4V2LIUC.js";
|
|
|
6
6
|
import "./chunk-RRWC77YY.js";
|
|
7
7
|
import "./chunk-HQ7R6CGM.js";
|
|
8
8
|
import "./chunk-H6XQZFTT.js";
|
|
9
|
-
import "./chunk-
|
|
9
|
+
import "./chunk-YNSPVKMS.js";
|
|
10
10
|
import "./chunk-3NCPXNBZ.js";
|
|
11
11
|
import "./chunk-TXD5HXLE.js";
|
|
12
12
|
export {
|
|
13
13
|
DesignCanvasEditor
|
|
14
14
|
};
|
|
15
|
-
//# sourceMappingURL=DesignCanvasEditor-
|
|
15
|
+
//# sourceMappingURL=DesignCanvasEditor-3R6KODJG.js.map
|
package/dist/app-auth/index.js
CHANGED
|
@@ -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-3R6KODJG.js").then((m) => ({ default: m.DesignCanvasEditor }))
|
|
5
5
|
);
|
|
6
6
|
var DesignCanvasChromeLazy = lazy(
|
|
7
|
-
() => import("./DesignCanvas-
|
|
7
|
+
() => import("./DesignCanvas-BVBMDXBZ.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-3YVSRH26.js.map
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readCookieValue,
|
|
3
|
+
serializeCookie
|
|
4
|
+
} from "./chunk-3NCPXNBZ.js";
|
|
5
|
+
|
|
6
|
+
// src/web/message-groups.ts
|
|
7
|
+
function groupConversationMessages(items = []) {
|
|
8
|
+
let speaker = null;
|
|
9
|
+
let conversation;
|
|
10
|
+
let groupId;
|
|
11
|
+
return items.map((item, index) => {
|
|
12
|
+
if (item.conversationId !== void 0 && item.conversationId !== conversation) {
|
|
13
|
+
conversation = item.conversationId;
|
|
14
|
+
speaker = null;
|
|
15
|
+
groupId = void 0;
|
|
16
|
+
}
|
|
17
|
+
const role = item.kind === "thinking" ? "assistant" : !item.kind || item.kind === "message" ? item.role : void 0;
|
|
18
|
+
if (role === "user") {
|
|
19
|
+
speaker = null;
|
|
20
|
+
groupId = void 0;
|
|
21
|
+
return { ...item, isContinuation: false };
|
|
22
|
+
}
|
|
23
|
+
if (role !== "assistant") return item;
|
|
24
|
+
const current = item.speakerId ?? "assistant";
|
|
25
|
+
const isContinuation = speaker === current;
|
|
26
|
+
if (!isContinuation) groupId = String(item.id ?? `assistant-${index}`);
|
|
27
|
+
speaker = current;
|
|
28
|
+
return { ...item, isContinuation, groupId };
|
|
29
|
+
});
|
|
30
|
+
}
|
|
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
|
+
// src/web/acquisition.ts
|
|
91
|
+
var RETENTION_SECONDS = 30 * 24 * 60 * 60;
|
|
92
|
+
var MAX_COOKIE_BYTES = 3600;
|
|
93
|
+
var CAMPAIGN_FIELDS = ["utm_source", "utm_medium", "utm_campaign", "utm_content", "utm_term"];
|
|
94
|
+
var CLICK_FIELDS = ["gclid", "gbraid", "wbraid", "fbclid", "msclkid", "ttclid", "li_fat_id", "twclid"];
|
|
95
|
+
var FIELDS = [...CAMPAIGN_FIELDS, ...CLICK_FIELDS];
|
|
96
|
+
function bounded(value, limit = 160) {
|
|
97
|
+
if (typeof value !== "string") return void 0;
|
|
98
|
+
const text = value.trim().replace(/[\u0000-\u001f\u007f]/g, "").slice(0, limit);
|
|
99
|
+
return text || void 0;
|
|
100
|
+
}
|
|
101
|
+
function origin(value) {
|
|
102
|
+
if (!value) return null;
|
|
103
|
+
try {
|
|
104
|
+
const url = new URL(value);
|
|
105
|
+
return ["https:", "http:"].includes(url.protocol) ? url.origin : null;
|
|
106
|
+
} catch {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function acquisitionFromRequest(request, now = Date.now(), ignoredReferrerOrigins = []) {
|
|
111
|
+
const url = new URL(request.url);
|
|
112
|
+
const parameters = {};
|
|
113
|
+
for (const field of FIELDS) {
|
|
114
|
+
const value = bounded(url.searchParams.get(field));
|
|
115
|
+
if (value) parameters[field] = value;
|
|
116
|
+
}
|
|
117
|
+
const referrer = origin(request.headers.get("referer"));
|
|
118
|
+
const referrerOrigin = referrer === url.origin || referrer !== null && ignoredReferrerOrigins.includes(referrer) ? null : referrer;
|
|
119
|
+
if (!Object.keys(parameters).length && !referrerOrigin) return null;
|
|
120
|
+
return {
|
|
121
|
+
parameters,
|
|
122
|
+
referrerOrigin,
|
|
123
|
+
landingPath: url.pathname.slice(0, 300),
|
|
124
|
+
firstSeenAt: now,
|
|
125
|
+
test: url.searchParams.get("attribution_test") === "1"
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function readFirstTouchAcquisition(request, cookieName, now = Date.now()) {
|
|
129
|
+
const raw = readCookieValue(request.headers.get("cookie"), cookieName);
|
|
130
|
+
if (!raw || encodeURIComponent(raw).length > MAX_COOKIE_BYTES) return null;
|
|
131
|
+
try {
|
|
132
|
+
const value = JSON.parse(raw);
|
|
133
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
134
|
+
const input = value;
|
|
135
|
+
if (typeof input.firstSeenAt !== "number" || !Number.isFinite(input.firstSeenAt) || input.firstSeenAt > now || input.firstSeenAt < now - RETENTION_SECONDS * 1e3) return null;
|
|
136
|
+
if (typeof input.landingPath !== "string" || !input.landingPath.startsWith("/") || input.landingPath.includes("?") || input.landingPath.includes("#")) return null;
|
|
137
|
+
if (!input.parameters || typeof input.parameters !== "object" || Array.isArray(input.parameters)) return null;
|
|
138
|
+
const parameters = {};
|
|
139
|
+
const source = input.parameters;
|
|
140
|
+
for (const field of FIELDS) {
|
|
141
|
+
const value2 = bounded(source[field]);
|
|
142
|
+
if (value2) parameters[field] = value2;
|
|
143
|
+
}
|
|
144
|
+
const referrerOrigin = typeof input.referrerOrigin === "string" ? origin(input.referrerOrigin) : null;
|
|
145
|
+
if (!Object.keys(parameters).length && !referrerOrigin) return null;
|
|
146
|
+
return { parameters, referrerOrigin, landingPath: input.landingPath.slice(0, 300), firstSeenAt: input.firstSeenAt, test: input.test === true };
|
|
147
|
+
} catch {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function firstTouchAcquisitionCookie(request, cookieName, now = Date.now(), ignoredReferrerOrigins = []) {
|
|
152
|
+
if (readFirstTouchAcquisition(request, cookieName, now)) return null;
|
|
153
|
+
const acquisition = acquisitionFromRequest(request, now, ignoredReferrerOrigins);
|
|
154
|
+
if (!acquisition) return null;
|
|
155
|
+
const raw = JSON.stringify(acquisition);
|
|
156
|
+
if (encodeURIComponent(raw).length > MAX_COOKIE_BYTES) return null;
|
|
157
|
+
return serializeCookie(raw, {
|
|
158
|
+
name: cookieName,
|
|
159
|
+
httpOnly: true,
|
|
160
|
+
sameSite: "Lax",
|
|
161
|
+
secure: new URL(request.url).protocol === "https:",
|
|
162
|
+
maxAgeSeconds: RETENTION_SECONDS
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export {
|
|
167
|
+
groupConversationMessages,
|
|
168
|
+
createApiKeyFetch,
|
|
169
|
+
acquisitionFromRequest,
|
|
170
|
+
readFirstTouchAcquisition,
|
|
171
|
+
firstTouchAcquisitionCookie
|
|
172
|
+
};
|
|
173
|
+
//# sourceMappingURL=chunk-YNSPVKMS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/web/message-groups.ts","../src/web/api-key-fetch.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","/** 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","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,gBAAU;AAAA,IACZ;AACA,UAAM,OAAO,KAAK,SAAS,aAAa,cAAe,CAAC,KAAK,QAAQ,KAAK,SAAS,YAAY,KAAK,OAAO;AAC3G,QAAI,SAAS,QAAQ;AAAE,gBAAU;AAAM,gBAAU;AAAW,aAAO,EAAE,GAAG,MAAM,gBAAgB,MAAM;AAAA,IAAE;AACtG,QAAI,SAAS,YAAa,QAAO;AACjC,UAAM,UAAU,KAAK,aAAa;AAClC,UAAM,iBAAiB,YAAY;AACnC,QAAI,CAAC,eAAgB,WAAU,OAAO,KAAK,MAAM,aAAa,KAAK,EAAE;AACrE,cAAU;AACV,WAAO,EAAE,GAAG,MAAM,gBAAgB,QAAQ;AAAA,EAC5C,CAAC;AACH;;;ACxBO,SAAS,kBAAkB,SAA0C;AAC1E,QAAMA,UAAS,IAAI,IAAI,QAAQ,MAAM;AACrC,QAAM,WAAW,CAAC,aAAa,aA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,MAAM,UAAU,EAAG,QAAO;AACzG,UAAM,aAAkD,CAAC;AACzD,UAAM,SAAS,MAAM;AACrB,eAAW,SAAS,QAAQ;AAC1B,YAAMC,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":["origin","value"]}
|
|
@@ -88,13 +88,13 @@ import {
|
|
|
88
88
|
import {
|
|
89
89
|
DesignCanvasChromeLazy,
|
|
90
90
|
DesignCanvasLazy
|
|
91
|
-
} from "../chunk-
|
|
91
|
+
} from "../chunk-3YVSRH26.js";
|
|
92
92
|
import {
|
|
93
93
|
assertSceneMediaSrc,
|
|
94
94
|
bleedAwareExportBounds,
|
|
95
95
|
scaleForPreset
|
|
96
96
|
} from "../chunk-H6XQZFTT.js";
|
|
97
|
-
import "../chunk-
|
|
97
|
+
import "../chunk-YNSPVKMS.js";
|
|
98
98
|
import "../chunk-3NCPXNBZ.js";
|
|
99
99
|
import "../chunk-TXD5HXLE.js";
|
|
100
100
|
|
package/dist/platform/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
streamChatRouteAsSandboxEvents
|
|
4
4
|
} from "../chunk-UII6SBT4.js";
|
|
5
5
|
import "../chunk-TSZIYQAZ.js";
|
|
6
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-YNSPVKMS.js";
|
|
7
7
|
import "../chunk-3NCPXNBZ.js";
|
|
8
8
|
import "../chunk-W3RSC6XB.js";
|
|
9
9
|
import "../chunk-ZVEEWGDK.js";
|
package/dist/sequences/index.js
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare const FIELDS: readonly ["utm_source", "utm_medium", "utm_campaign", "utm_content", "utm_term", "gclid", "gbraid", "wbraid", "fbclid", "msclkid", "ttclid", "li_fat_id", "twclid"];
|
|
2
|
+
/** Untrusted acquisition hints. Never use these fields for identity or authorization. */
|
|
3
|
+
export interface FirstTouchAcquisition {
|
|
4
|
+
parameters: Partial<Record<typeof FIELDS[number], string>>;
|
|
5
|
+
referrerOrigin: string | null;
|
|
6
|
+
landingPath: string;
|
|
7
|
+
firstSeenAt: number;
|
|
8
|
+
test: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** Capture only campaign fields and an external origin, never URL queries or referrer paths. */
|
|
11
|
+
export declare function acquisitionFromRequest(request: Request, now?: number, ignoredReferrerOrigins?: readonly string[]): FirstTouchAcquisition | null;
|
|
12
|
+
/** Reject expired, future, malformed, and oversized hints without affecting authentication. */
|
|
13
|
+
export declare function readFirstTouchAcquisition(request: Request, cookieName: string, now?: number): FirstTouchAcquisition | null;
|
|
14
|
+
/** Host-only HttpOnly cookie survives a top-level sign-in round trip. First valid touch wins. */
|
|
15
|
+
export declare function firstTouchAcquisitionCookie(request: Request, cookieName: string, now?: number, ignoredReferrerOrigins?: readonly string[]): string | null;
|
|
16
|
+
export {};
|
package/dist/web/index.d.ts
CHANGED
package/dist/web/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
+
acquisitionFromRequest,
|
|
2
3
|
createApiKeyFetch,
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
firstTouchAcquisitionCookie,
|
|
5
|
+
groupConversationMessages,
|
|
6
|
+
readFirstTouchAcquisition
|
|
7
|
+
} from "../chunk-YNSPVKMS.js";
|
|
5
8
|
import {
|
|
6
9
|
FREE_ROUTE_BUDGETS,
|
|
7
10
|
FreeRouteLimitError,
|
|
@@ -28,6 +31,7 @@ export {
|
|
|
28
31
|
FreeRouteLimitError,
|
|
29
32
|
STANDARD_SECURITY_HEADERS,
|
|
30
33
|
WORKSPACE_BUDGET_MULTIPLIER,
|
|
34
|
+
acquisitionFromRequest,
|
|
31
35
|
addSecurityHeaders,
|
|
32
36
|
assertMediaUrl,
|
|
33
37
|
checkFreeRouteLimit,
|
|
@@ -35,11 +39,13 @@ export {
|
|
|
35
39
|
clearCookieHeader,
|
|
36
40
|
createApiKeyFetch,
|
|
37
41
|
extractRequestContext,
|
|
42
|
+
firstTouchAcquisitionCookie,
|
|
38
43
|
freeRouteLimitResponse,
|
|
39
44
|
groupConversationMessages,
|
|
40
45
|
isWorkspaceFileExportable,
|
|
41
46
|
parseJsonObjectBody,
|
|
42
47
|
readCookieValue,
|
|
48
|
+
readFirstTouchAcquisition,
|
|
43
49
|
requireString,
|
|
44
50
|
serializeCookie,
|
|
45
51
|
withFreeRouteLimit
|
package/package.json
CHANGED
package/dist/chunk-TZEEGDHS.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
// src/web/message-groups.ts
|
|
2
|
-
function groupConversationMessages(items = []) {
|
|
3
|
-
let speaker = null;
|
|
4
|
-
let conversation;
|
|
5
|
-
let groupId;
|
|
6
|
-
return items.map((item, index) => {
|
|
7
|
-
if (item.conversationId !== void 0 && item.conversationId !== conversation) {
|
|
8
|
-
conversation = item.conversationId;
|
|
9
|
-
speaker = null;
|
|
10
|
-
groupId = void 0;
|
|
11
|
-
}
|
|
12
|
-
const role = item.kind === "thinking" ? "assistant" : !item.kind || item.kind === "message" ? item.role : void 0;
|
|
13
|
-
if (role === "user") {
|
|
14
|
-
speaker = null;
|
|
15
|
-
groupId = void 0;
|
|
16
|
-
return { ...item, isContinuation: false };
|
|
17
|
-
}
|
|
18
|
-
if (role !== "assistant") return item;
|
|
19
|
-
const current = item.speakerId ?? "assistant";
|
|
20
|
-
const isContinuation = speaker === current;
|
|
21
|
-
if (!isContinuation) groupId = String(item.id ?? `assistant-${index}`);
|
|
22
|
-
speaker = current;
|
|
23
|
-
return { ...item, isContinuation, groupId };
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// src/web/api-key-fetch.ts
|
|
28
|
-
function createApiKeyFetch(options) {
|
|
29
|
-
const origin = new URL(options.origin);
|
|
30
|
-
const loopback = ["localhost", "127.0.0.1", "[::1]"].includes(origin.hostname);
|
|
31
|
-
if (origin.username || origin.password || origin.pathname !== "/" || origin.search || origin.hash || origin.protocol !== "https:" && !(origin.protocol === "http:" && loopback && options.allowHttpLoopback)) {
|
|
32
|
-
throw new TypeError("API origin must be HTTPS without credentials, path, query, or fragment");
|
|
33
|
-
}
|
|
34
|
-
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
35
|
-
if (typeof fetchImpl !== "function") throw new TypeError("A fetch implementation is required");
|
|
36
|
-
const getApiKey = options.getApiKey;
|
|
37
|
-
return async (path, init = {}) => {
|
|
38
|
-
if (typeof path !== "string" || !path.startsWith("/") || path.startsWith("//") || /[\\\u0000-\u0020\u007f]/.test(path)) {
|
|
39
|
-
throw new TypeError("API requests require a root-relative path without whitespace or backslashes");
|
|
40
|
-
}
|
|
41
|
-
const target = new URL(path, origin);
|
|
42
|
-
if (target.origin !== origin.origin || target.username || target.password || target.hash) {
|
|
43
|
-
throw new TypeError("API requests must stay on the configured origin without a fragment");
|
|
44
|
-
}
|
|
45
|
-
const headers = new Headers(init.headers);
|
|
46
|
-
if (headers.has("authorization") || headers.has("cookie") || headers.has("proxy-authorization")) {
|
|
47
|
-
throw new TypeError("Authentication headers must come from the configured secret resolver");
|
|
48
|
-
}
|
|
49
|
-
init.signal?.throwIfAborted();
|
|
50
|
-
let apiKey;
|
|
51
|
-
try {
|
|
52
|
-
apiKey = await getApiKey();
|
|
53
|
-
} catch {
|
|
54
|
-
throw new Error("API credential is unavailable");
|
|
55
|
-
}
|
|
56
|
-
if (typeof apiKey !== "string" || !apiKey || /\s|[^\x21-\x7e]/.test(apiKey)) {
|
|
57
|
-
throw new TypeError("API credential must be a nonempty printable token without whitespace");
|
|
58
|
-
}
|
|
59
|
-
init.signal?.throwIfAborted();
|
|
60
|
-
headers.set("Authorization", `Bearer ${apiKey}`);
|
|
61
|
-
let response;
|
|
62
|
-
try {
|
|
63
|
-
response = await fetchImpl(target.href, {
|
|
64
|
-
...init,
|
|
65
|
-
headers,
|
|
66
|
-
credentials: "omit",
|
|
67
|
-
redirect: "manual",
|
|
68
|
-
referrerPolicy: "no-referrer"
|
|
69
|
-
});
|
|
70
|
-
} catch {
|
|
71
|
-
init.signal?.throwIfAborted();
|
|
72
|
-
throw new Error("API transport failed; inspect retained state before retrying a write");
|
|
73
|
-
}
|
|
74
|
-
if (response.type === "opaqueredirect" || response.redirected || response.status >= 300 && response.status < 400 && response.status !== 304) {
|
|
75
|
-
try {
|
|
76
|
-
await response.body?.cancel();
|
|
77
|
-
} catch {
|
|
78
|
-
}
|
|
79
|
-
throw new Error("API redirects are not allowed");
|
|
80
|
-
}
|
|
81
|
-
return response;
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export {
|
|
86
|
-
groupConversationMessages,
|
|
87
|
-
createApiKeyFetch
|
|
88
|
-
};
|
|
89
|
-
//# sourceMappingURL=chunk-TZEEGDHS.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/web/message-groups.ts","../src/web/api-key-fetch.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","/** 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":";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,gBAAU;AAAA,IACZ;AACA,UAAM,OAAO,KAAK,SAAS,aAAa,cAAe,CAAC,KAAK,QAAQ,KAAK,SAAS,YAAY,KAAK,OAAO;AAC3G,QAAI,SAAS,QAAQ;AAAE,gBAAU;AAAM,gBAAU;AAAW,aAAO,EAAE,GAAG,MAAM,gBAAgB,MAAM;AAAA,IAAE;AACtG,QAAI,SAAS,YAAa,QAAO;AACjC,UAAM,UAAU,KAAK,aAAa;AAClC,UAAM,iBAAiB,YAAY;AACnC,QAAI,CAAC,eAAgB,WAAU,OAAO,KAAK,MAAM,aAAa,KAAK,EAAE;AACrE,cAAU;AACV,WAAO,EAAE,GAAG,MAAM,gBAAgB,QAAQ;AAAA,EAC5C,CAAC;AACH;;;ACxBO,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,EAAE,OAAO,aAAa,WAAW,YAAY,QAAQ,oBAAqB;AAC9G,UAAM,IAAI,UAAU,wEAAwE;AAAA,EAC9F;AACA,QAAM,YAAY,QAAQ,aAAa,WAAW;AAClD,MAAI,OAAO,cAAc,WAAY,OAAM,IAAI,UAAU,oCAAoC;AAC7F,QAAM,YAAY,Q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