@hugex/artifact 0.7.2 → 0.8.1
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 +21 -0
- package/dist/artifact/do/ArtifactDO.d.ts +77 -4
- package/dist/artifact/do/ArtifactIndexDO.d.ts +9 -2
- package/dist/artifact/do/index-upsert.d.ts +14 -3
- package/dist/artifact/do/ora-index.d.ts +8 -1
- package/dist/artifact/host-route.d.ts +1 -1
- package/dist/artifact/inject.d.ts +14 -2
- package/dist/artifact/limits.d.ts +11 -0
- package/dist/artifact/types.d.ts +39 -5
- package/dist/artifact/validate.d.ts +18 -1
- package/dist/artifact/version.d.ts +1 -1
- package/dist/artifact/visit.d.ts +38 -0
- package/dist/common/constants/client-tools.d.ts +137 -0
- package/dist/common/flow-graph/index.d.ts +1 -0
- package/dist/common/flow-graph/schema.d.ts +1 -1
- package/dist/common/flow-graph/validate.d.ts +3 -0
- package/dist/index.js +206 -67
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -162,6 +162,27 @@ require a new OAuth consent. The dedicated Workers consent labels must be integr
|
|
|
162
162
|
owner before release.
|
|
163
163
|
|
|
164
164
|
|
|
165
|
+
## First view
|
|
166
|
+
|
|
167
|
+
`artifact.json` may set `loading`. Without it, the artifact shows the generic overlay (`mode: "auto"`) until `window` `load` or `hx.ready()`, and Tailwind plus the catalog scripts keep the previous blocking order. `defer` is applied only when `loading` is present and its mode is not `none`. An invalid `loading` value on an already published version is ignored; `libs` and `theme` still apply, and that version can be rolled back. A write or publish of new content still rejects invalid `loading`.
|
|
168
|
+
|
|
169
|
+
```json
|
|
170
|
+
{ "title": "Demo", "libs": [], "loading": { "mode": "auto", "page": "loading.html" } }
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
- `auto`: the overlay leaves on `load` (10s cap) or sooner when the page calls `hx.ready()`. SPAs should call `hx.ready()` after the first useful render.
|
|
174
|
+
- `manual`: only `hx.ready()` removes it (15s cap). The cap logs `hx.ready() not called (manual)`.
|
|
175
|
+
- `none`: no overlay.
|
|
176
|
+
- `page` is opt-in. A file named `loading.html` is served as a normal file until the manifest names it. The page must be `.html`, not `index.html`, `server.js`, `artifact.json` or anything under `__hx/`, UTF-8, and at most 32 KiB. It is shown in a sandboxed iframe (`srcdoc`, no scripts, no forms, no same origin). Relative image URLs resolve against the artifact `<base>` without `crossorigin`; `data:` URLs also work.
|
|
177
|
+
- The overlay is mounted from an inline script before the Tailwind CDN script. Colors follow `theme` (`hugex` or `none`) and `prefers-color-scheme`. The status string is chosen from `Accept-Language` (`es` or `en`) on the server.
|
|
178
|
+
|
|
179
|
+
## Usage stats
|
|
180
|
+
|
|
181
|
+
GET document navigations (not HEAD, POST, prefetch, prerender or iframes) record `view`. Bots increment `view_bot` instead, and do not move `view`, `view_key` or `lastViewDay`. From this change onward, days also store dimensions (country, region, device, browser, os, referrer, language; top values plus `other`) and a daily unique count. `uniques` in a range is the sum of those days, not a cross-day dedupe. `series[].coverage` is false for days that predate capture, so a zero is not "no traffic". `dimensionsSince` is the first day with dimensions. A referrer that is an IPv4 or IPv6 literal is stored as `other`.
|
|
182
|
+
|
|
183
|
+
Usage statistics do not store IP or User-Agent. Uniques use a daily identifier derived from them with a salt that rotates at the next UTC midnight. Request headers, including IP and User-Agent, are still forwarded to `server.js`. What the artifact's own code writes to logs is the author's responsibility. The salt and the day's hashes are deleted on the next wake after midnight, including for an idle artifact. Storage stays under 10 MB (90 days, 30 values per dimension, 20 000 visitors per day).
|
|
184
|
+
|
|
185
|
+
|
|
165
186
|
## Package version
|
|
166
187
|
|
|
167
188
|
`runtimeId` includes the package version. The build defines the identifier `__ARTIFACT_PKG_VERSION__` from `ora/scripts/artifact-version.json`. Runtime code should use:
|
|
@@ -10,8 +10,24 @@ import type { AllowsWorkerInput, AllowsWorkerResult, ArtifactEnv, ArtifactFile,
|
|
|
10
10
|
export declare class ArtifactDO extends DurableObject<ArtifactEnv> implements ArtifactRpc {
|
|
11
11
|
/** Bumped when an activation window expires so a late health check cannot publish. */
|
|
12
12
|
private activationGen;
|
|
13
|
+
/** Bumped at the start of every activation or deletion to invalidate in-flight lazy facet starts. */
|
|
14
|
+
private facetEpoch;
|
|
15
|
+
/** Emits `boot failed:` at most once per DO instance for the first failing current boot. */
|
|
16
|
+
private bootFailureLogged;
|
|
17
|
+
/** In-flight coordinated facet startup keyed by `(uuid, activeVersion, facetEpoch)`. */
|
|
18
|
+
private facetStart;
|
|
13
19
|
/** UTC day of the last `daily_stat` prune, so `bump()` prunes at most once per day per instance. */
|
|
14
20
|
private statsPrunedDay;
|
|
21
|
+
/** High-water mark so a replacement salt never reuses an epoch held by an in-flight hash. */
|
|
22
|
+
private saltEpochMem;
|
|
23
|
+
/** After a failed salt purge, the alarm waits until this absolute time. Cleared on a successful purge, a replacement, or a salt that is still valid. */
|
|
24
|
+
private saltPurgeBackoffMs;
|
|
25
|
+
private saltPurgeNotBefore;
|
|
26
|
+
/** Absolute index/ora retry deadlines. Recomputed only when a flush fails or on the first arm after a restart. */
|
|
27
|
+
private indexRetryAt;
|
|
28
|
+
private oraRetryAt;
|
|
29
|
+
/** `expiresAt` of the salt whose alarm was successfully armed. Null means the next view must try again. */
|
|
30
|
+
private saltAlarmExpiresAt;
|
|
15
31
|
constructor(ctx: DurableObjectState, env: ArtifactEnv);
|
|
16
32
|
alarm(): Promise<void>;
|
|
17
33
|
create(input: CreateArtifactInput): Promise<{
|
|
@@ -86,7 +102,7 @@ export declare class ArtifactDO extends DurableObject<ArtifactEnv> implements Ar
|
|
|
86
102
|
blobCount: number;
|
|
87
103
|
versionCount: number;
|
|
88
104
|
} | null>;
|
|
89
|
-
private
|
|
105
|
+
private runFacetDbCall;
|
|
90
106
|
query(sql: string, opts?: QueryOptions): Promise<QueryResult>;
|
|
91
107
|
schema(opts?: SchemaOptions): Promise<SchemaResult>;
|
|
92
108
|
fetch(request: Request): Promise<Response>;
|
|
@@ -123,14 +139,34 @@ export declare class ArtifactDO extends DurableObject<ArtifactEnv> implements Ar
|
|
|
123
139
|
private runtimeId;
|
|
124
140
|
private loadApp;
|
|
125
141
|
private facetOf;
|
|
126
|
-
|
|
127
|
-
private
|
|
142
|
+
private sameFacetKey;
|
|
143
|
+
private facetKeyMatchesCurrent;
|
|
144
|
+
private accessChanged;
|
|
145
|
+
private logBootFailureOnce;
|
|
146
|
+
/**
|
|
147
|
+
* Coordinated lazy facet startup keyed by `(uuid, activeVersion, facetEpoch)`.
|
|
148
|
+
* Never aborts an active facet; discards stale results if an activation or deletion intervenes.
|
|
149
|
+
*/
|
|
150
|
+
private startCurrentFacet;
|
|
128
151
|
/** Replace the facet isolate. Class load happens before abort so a bad module leaves the previous facet up. */
|
|
129
152
|
private swapFacet;
|
|
130
153
|
private abortFacet;
|
|
131
154
|
private allow;
|
|
155
|
+
/**
|
|
156
|
+
* Authorizes `snapshot` and adopts it only when it is still current after `allow`.
|
|
157
|
+
* A newer row is not treated as authorized.
|
|
158
|
+
*/
|
|
159
|
+
private confirmAccess;
|
|
160
|
+
/** One retry for non-API routes. `/api` uses its own budget inside `forwardApi`. */
|
|
161
|
+
private authorizeSnapshot;
|
|
132
162
|
private acceptReload;
|
|
133
163
|
private serveHtml;
|
|
164
|
+
/**
|
|
165
|
+
* Theme and libs always come from a parseable manifest. Invalid `loading` is ignored.
|
|
166
|
+
* Tailwind stays blocking unless the manifest declares a `loading` mode other than `none`.
|
|
167
|
+
*/
|
|
168
|
+
private renderHtml;
|
|
169
|
+
private rejectLoading;
|
|
134
170
|
private serveFile;
|
|
135
171
|
private forwardApi;
|
|
136
172
|
private broadcastReload;
|
|
@@ -139,6 +175,32 @@ export declare class ArtifactDO extends DurableObject<ArtifactEnv> implements Ar
|
|
|
139
175
|
private destroyFacet;
|
|
140
176
|
private browserLogAllowed;
|
|
141
177
|
private writeLog;
|
|
178
|
+
/**
|
|
179
|
+
* Document view: counters and dimensions commit first. A new salt is stored only after
|
|
180
|
+
* `txn.setAlarm` in the same storage transaction. If that fails, the view and dimensions
|
|
181
|
+
* stay and the unique (and its coverage) are omitted. The visitor hash runs after the digest.
|
|
182
|
+
* A failure here must not change the HTML response.
|
|
183
|
+
*/
|
|
184
|
+
private recordDocumentView;
|
|
185
|
+
private finishUnique;
|
|
186
|
+
private resetSaltBackoff;
|
|
187
|
+
private rotateSaltOnAlarm;
|
|
188
|
+
private purgeStaleVisitors;
|
|
189
|
+
/** Bytes for today's salt. A new salt is not written here; `commitSalt` arms the alarm first. */
|
|
190
|
+
private planSalt;
|
|
191
|
+
/**
|
|
192
|
+
* Arm the scheduler minimum (keeping a sooner alarm already set), then persist a new salt.
|
|
193
|
+
* `storage.transaction` commits SQL and `txn.setAlarm` together; a rejection rolls both back.
|
|
194
|
+
* An existing salt still counts its unique when re-arming fails.
|
|
195
|
+
*/
|
|
196
|
+
private commitSalt;
|
|
197
|
+
private readSalt;
|
|
198
|
+
/** One read of the day's named values, then the rows for a single multi-row upsert. */
|
|
199
|
+
private dimensionRows;
|
|
200
|
+
private upsertCounters;
|
|
201
|
+
private upsertDims;
|
|
202
|
+
private markUniquesCapped;
|
|
203
|
+
private sqlWrite;
|
|
142
204
|
/** One daily counter. Like `writeLog`, a counter must never break a response. */
|
|
143
205
|
private bump;
|
|
144
206
|
/** Drops counters older than `LIMITS.statsDays` UTC days (today included). */
|
|
@@ -151,8 +213,19 @@ export declare class ArtifactDO extends DurableObject<ArtifactEnv> implements Ar
|
|
|
151
213
|
private flushIndex;
|
|
152
214
|
private flushLocalIndex;
|
|
153
215
|
private flushOraIndex;
|
|
154
|
-
|
|
216
|
+
private retryDelayMs;
|
|
217
|
+
/** Stores an absolute retry time from the persisted retry count. Does not move an existing future deadline. */
|
|
218
|
+
private noteRetryDeadline;
|
|
219
|
+
/**
|
|
220
|
+
* Shared alarm. Deadlines are absolute: salt expiry, draft expiry, and the retry time captured
|
|
221
|
+
* when a flush failed. A deadline already due (`at <= now`) is scheduled immediately instead of
|
|
222
|
+
* dropped. `preserve` skips deleting the alarm when nothing is due yet, so a flush that has not
|
|
223
|
+
* finished cannot drop the next local wake.
|
|
224
|
+
*/
|
|
155
225
|
private armIndexAlarm;
|
|
226
|
+
/** Minimum wake. A due deadline counts as `now` so a later draft cannot postpone a purge. */
|
|
227
|
+
private earliestDeadline;
|
|
228
|
+
private noteSaltAlarm;
|
|
156
229
|
private indexEntry;
|
|
157
230
|
private readMeta;
|
|
158
231
|
private toPublic;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DurableObject } from "cloudflare:workers";
|
|
2
2
|
import type { ArtifactEnv, ArtifactIndexEntry, ArtifactIndexRpc } from "../types";
|
|
3
3
|
import { type ToolRunAdmitInput, type ToolRunAdmitResult, type ToolRunFinishInput, type ToolRunLogEntry } from "../mcp/toolRunContract";
|
|
4
|
-
export { INDEX_UPSERT_SQL } from "./index-upsert";
|
|
4
|
+
export { INDEX_TOMBSTONE_SQL, INDEX_UPSERT_SQL } from "./index-upsert";
|
|
5
5
|
/**
|
|
6
6
|
* One instance per tenant (`idFromName('index')`).
|
|
7
7
|
* ArtifactDO calls `put` after create, write, rollback, and settings.
|
|
@@ -20,7 +20,14 @@ export declare class ArtifactIndexDO extends DurableObject<ArtifactEnv> implemen
|
|
|
20
20
|
alarm(): Promise<void>;
|
|
21
21
|
private recordDenial;
|
|
22
22
|
put(entry: ArtifactIndexEntry): Promise<void>;
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* With `tombstone`, marks the row deleted instead of erasing it, so a snapshot still in flight
|
|
25
|
+
* cannot bring the artifact back (see INDEX_TOMBSTONE_SQL). Without it (older callers), erases.
|
|
26
|
+
*/
|
|
27
|
+
remove(slug: string, tombstone?: {
|
|
28
|
+
uuid: string;
|
|
29
|
+
revision: number;
|
|
30
|
+
}): Promise<void>;
|
|
24
31
|
get(slug: string): Promise<ArtifactIndexEntry | null>;
|
|
25
32
|
list(opts?: {
|
|
26
33
|
owner?: string;
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Upsert
|
|
2
|
+
* Upsert for the tenant artifact index (one row per slug).
|
|
3
|
+
* - The same artifact (same uuid) is updated only by a strictly higher `revision`, so a late or
|
|
4
|
+
* repeated snapshot never overwrites a newer one.
|
|
5
|
+
* - A different artifact (another uuid) can take the slug only when the stored row is a tombstone,
|
|
6
|
+
* so a late snapshot of an old artifact can neither revive it nor overwrite the artifact that now
|
|
7
|
+
* owns the slug.
|
|
3
8
|
* `updatedAt` is written for display and ordering. It is not the compare key.
|
|
4
|
-
* hx-ora uses the same rule on `PUT /internal/artifacts/:uuid
|
|
9
|
+
* hx-ora uses the same revision rule on `PUT /internal/artifacts/:uuid`.
|
|
5
10
|
*/
|
|
6
|
-
export declare const INDEX_UPSERT_SQL = "INSERT INTO artifact (slug, uuid, title, org, owner, grp, public, active_version, updated_at, revision)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,
|
|
11
|
+
export declare const INDEX_UPSERT_SQL = "INSERT INTO artifact (slug, uuid, title, org, owner, grp, public, active_version, updated_at, revision, deleted)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0)\n ON CONFLICT(slug) DO UPDATE SET\n uuid = excluded.uuid,\n title = excluded.title,\n org = excluded.org,\n owner = excluded.owner,\n grp = excluded.grp,\n public = excluded.public,\n active_version = excluded.active_version,\n updated_at = excluded.updated_at,\n revision = excluded.revision,\n deleted = 0\n WHERE (excluded.uuid = artifact.uuid AND excluded.revision > artifact.revision)\n OR (artifact.deleted = 1 AND excluded.uuid <> artifact.uuid)";
|
|
12
|
+
/**
|
|
13
|
+
* Tombstone written when an artifact is deleted. `revision` is the deleted artifact's last revision
|
|
14
|
+
* plus one, so any snapshot still in flight is ignored. It only marks the row of the same uuid; a
|
|
15
|
+
* slug already owned by another artifact is left alone. Bindings: slug, uuid, updated_at, revision.
|
|
16
|
+
*/
|
|
17
|
+
export declare const INDEX_TOMBSTONE_SQL = "INSERT INTO artifact (slug, uuid, title, org, owner, grp, public, active_version, updated_at, revision, deleted)\n VALUES (?, ?, '', '', '', 'none', 0, NULL, ?, ?, 1)\n ON CONFLICT(slug) DO UPDATE SET\n deleted = 1,\n revision = MAX(artifact.revision, excluded.revision),\n updated_at = excluded.updated_at\n WHERE artifact.uuid = excluded.uuid";
|
|
@@ -6,10 +6,17 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { ArtifactIndexEntry } from "../types";
|
|
8
8
|
export declare const ORA_INDEX_TIMEOUT_MS = 5000;
|
|
9
|
+
/**
|
|
10
|
+
* `tombstone` lets hx-ora record the deletion even when the first snapshot has not arrived yet, so
|
|
11
|
+
* that snapshot cannot create the row afterwards. `revision` is the artifact's last revision plus one.
|
|
12
|
+
*/
|
|
9
13
|
export declare function deleteArtifactOra(env: {
|
|
10
14
|
HX_ORA_URL?: string;
|
|
11
15
|
HX_API_KEY?: string;
|
|
12
|
-
}, uuid: string, fetchImpl?: typeof fetch, timeoutMs?: number
|
|
16
|
+
}, uuid: string, fetchImpl?: typeof fetch, timeoutMs?: number, tombstone?: {
|
|
17
|
+
slug: string;
|
|
18
|
+
revision: number;
|
|
19
|
+
}): Promise<{
|
|
13
20
|
ok: true;
|
|
14
21
|
} | {
|
|
15
22
|
ok: false;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ArtifactLoadingConfig } from "./validate";
|
|
1
2
|
export declare function frameAncestorsDirective(raw: string | undefined): string;
|
|
2
3
|
export declare function artifactCsp(frameAncestors?: string): string;
|
|
3
4
|
/** Default CSP when `ARTIFACT_FRAME_ANCESTORS` is empty: `frame-ancestors 'none'`. */
|
|
@@ -29,6 +30,11 @@ export interface InjectOptions {
|
|
|
29
30
|
tailwindUrl: string;
|
|
30
31
|
tailwindIntegrity: string;
|
|
31
32
|
theme?: "hugex" | "none";
|
|
33
|
+
title?: string;
|
|
34
|
+
lang?: "es" | "en";
|
|
35
|
+
loading?: ArtifactLoadingConfig;
|
|
36
|
+
loadingPageHtml?: string | null;
|
|
37
|
+
deferTailwind?: boolean;
|
|
32
38
|
stylesheets?: {
|
|
33
39
|
url: string;
|
|
34
40
|
integrity: string;
|
|
@@ -39,10 +45,16 @@ export interface InjectOptions {
|
|
|
39
45
|
defer?: boolean;
|
|
40
46
|
}[];
|
|
41
47
|
}
|
|
42
|
-
/** Insert `<base>`, the process shim, the import map, stylesheets, scripts, Tailwind, theme tokens, and the reload client. */
|
|
48
|
+
/** Insert `<base>`, boot overlay, the process shim, the import map, stylesheets, scripts, Tailwind, theme tokens, and the reload client. */
|
|
43
49
|
export declare function injectHtml(html: string, options: InjectOptions): string;
|
|
44
50
|
/** Resolve `libs` and `theme` from artifact.json and inject. Unknown libs are ignored here; write() reports them. */
|
|
45
|
-
export declare function injectArtifactHtml(html: string, baseHref: string, libs: readonly string[], theme?: "hugex" | "none"
|
|
51
|
+
export declare function injectArtifactHtml(html: string, baseHref: string, libs: readonly string[], theme?: "hugex" | "none", extra?: {
|
|
52
|
+
title?: string;
|
|
53
|
+
lang?: "es" | "en";
|
|
54
|
+
loading?: ArtifactLoadingConfig;
|
|
55
|
+
loadingPageHtml?: string | null;
|
|
56
|
+
deferTailwind?: boolean;
|
|
57
|
+
}): string;
|
|
46
58
|
export declare function contentType(path: string): string;
|
|
47
59
|
/** Referrer-Policy, nosniff, no-transform, and the artifact CSP on every response. No Set-Cookie. */
|
|
48
60
|
export declare function applySecurityHeaders(response: Response, frameAncestors?: string): Response;
|
|
@@ -9,6 +9,8 @@ export declare const LIMITS: {
|
|
|
9
9
|
readonly logMessageBytes: 2048;
|
|
10
10
|
readonly browserLogsPerSecond: 20;
|
|
11
11
|
readonly pathMaxChars: 200;
|
|
12
|
+
/** Maximum UTF-8 byte size for a manifest-declared `loading.page` HTML file (32 KiB). */
|
|
13
|
+
readonly loadingPageBytes: 32768;
|
|
12
14
|
/** Shared deadline for facet load, health, and restore. An expired activation cannot publish. */
|
|
13
15
|
readonly healthTimeoutMs: 5000;
|
|
14
16
|
/** Non-active version rows kept by created_at (plus active and log-referenced versions). */
|
|
@@ -17,6 +19,15 @@ export declare const LIMITS: {
|
|
|
17
19
|
readonly statsDays: 90;
|
|
18
20
|
/** Default window for `stats()`. */
|
|
19
21
|
readonly statsDefaultDays: 30;
|
|
22
|
+
/** Named dimension values per day before the rest collapses into "other" (29 + other = 30). */
|
|
23
|
+
readonly statsDimValues: 30;
|
|
24
|
+
/** Distinct visitor hashes kept for the current UTC day. */
|
|
25
|
+
readonly statsVisitorsPerDay: 20000;
|
|
26
|
+
/**
|
|
27
|
+
* Upper bound for stats storage in one DO: 90 days × 7 dims × 30 values,
|
|
28
|
+
* plus at most 20_000 visitor hashes of 16 bytes. Well under 10 MB.
|
|
29
|
+
*/
|
|
30
|
+
readonly statsBudgetBytes: 10000000;
|
|
20
31
|
};
|
|
21
32
|
/**
|
|
22
33
|
* Local caps for `artifact_publish`. Pending bytes are UTF-8 staged content
|
package/dist/artifact/types.d.ts
CHANGED
|
@@ -77,20 +77,45 @@ export interface WorkerGrant {
|
|
|
77
77
|
grantedAt: string;
|
|
78
78
|
}
|
|
79
79
|
/** Daily counters kept by ArtifactDO in `daily_stat` (UTC days, 90 days retained). */
|
|
80
|
-
export type ArtifactStatMetric = 'view' | 'view_key' | 'api' | 'api_error' | 'error' | 'browser_error' | 'worker_browser' | 'worker_server' | 'worker_denied';
|
|
80
|
+
export type ArtifactStatMetric = 'view' | 'view_key' | 'view_bot' | 'api' | 'api_error' | 'error' | 'browser_error' | 'worker_browser' | 'worker_server' | 'worker_denied' | 'uniques';
|
|
81
81
|
export declare const ARTIFACT_STAT_METRICS: readonly ArtifactStatMetric[];
|
|
82
|
+
export declare const ARTIFACT_STAT_DIMS: readonly ['country', 'region', 'device', 'browser', 'os', 'referrer', 'lang'];
|
|
83
|
+
export type ArtifactStatDim = (typeof ARTIFACT_STAT_DIMS)[number];
|
|
84
|
+
export interface ArtifactStatCoverage {
|
|
85
|
+
/** At least one view that day carried a valid visit header. */
|
|
86
|
+
dims: boolean;
|
|
87
|
+
/** At least one non-bot view that day had a usable IP and was counted after the hash. */
|
|
88
|
+
uniques: boolean;
|
|
89
|
+
}
|
|
82
90
|
export interface ArtifactStats {
|
|
83
91
|
days: number;
|
|
84
92
|
/** 'YYYY-MM-DD' UTC, inclusive. */
|
|
85
93
|
from: string;
|
|
86
94
|
/** 'YYYY-MM-DD' UTC (today), inclusive. */
|
|
87
95
|
to: string;
|
|
88
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Ascending, one row per day, zeros included.
|
|
98
|
+
* `view` and `view_key` exclude bots (`view_bot`). `uniques` is that day's distinct visitors.
|
|
99
|
+
* `coverage` is false on days from before capture existed, so zero is not "no traffic".
|
|
100
|
+
*/
|
|
89
101
|
series: Array<{
|
|
90
102
|
day: string;
|
|
91
|
-
} & Record<ArtifactStatMetric, number
|
|
103
|
+
} & Record<ArtifactStatMetric, number> & {
|
|
104
|
+
uniquesCapped: boolean;
|
|
105
|
+
coverage: ArtifactStatCoverage;
|
|
106
|
+
}>;
|
|
107
|
+
/** `uniques` sums daily counts and does not dedupe across days. */
|
|
92
108
|
totals: Record<ArtifactStatMetric, number>;
|
|
93
|
-
/**
|
|
109
|
+
/** True when any day in the requested window hit the visitor cap. */
|
|
110
|
+
uniquesCapped: boolean;
|
|
111
|
+
/** Top 10 values in the window, then `other` for the rest (including daily `other`). */
|
|
112
|
+
dimensions: Record<ArtifactStatDim, Array<{
|
|
113
|
+
value: string;
|
|
114
|
+
n: number;
|
|
115
|
+
}>>;
|
|
116
|
+
/** First UTC day with dimension capture, or null when none exists in retention. */
|
|
117
|
+
dimensionsSince: string | null;
|
|
118
|
+
/** Last day with view > 0 within the 90 retained days. Bots do not move this. */
|
|
94
119
|
lastViewDay: string | null;
|
|
95
120
|
storage: {
|
|
96
121
|
databaseSize: number;
|
|
@@ -329,6 +354,8 @@ export interface SettingsInput {
|
|
|
329
354
|
export interface QueryOptions {
|
|
330
355
|
limit?: number;
|
|
331
356
|
offset?: number;
|
|
357
|
+
/** UUID the caller already authorized. The DO rejects the call when the artifact was recreated. */
|
|
358
|
+
expectUuid?: string;
|
|
332
359
|
}
|
|
333
360
|
export type QueryResult = {
|
|
334
361
|
ok: true;
|
|
@@ -347,6 +374,8 @@ export interface SchemaColumn {
|
|
|
347
374
|
}
|
|
348
375
|
export interface SchemaOptions {
|
|
349
376
|
counts?: boolean;
|
|
377
|
+
/** UUID the caller already authorized. The DO rejects the call when the artifact was recreated. */
|
|
378
|
+
expectUuid?: string;
|
|
350
379
|
}
|
|
351
380
|
export interface SchemaTable {
|
|
352
381
|
name: string;
|
|
@@ -482,7 +511,10 @@ export interface ArtifactRpc {
|
|
|
482
511
|
/** RPC surface of ArtifactIndexDO (stub = env.ARTIFACT_INDEX.get(env.ARTIFACT_INDEX.idFromName('index'))). */
|
|
483
512
|
export interface ArtifactIndexRpc {
|
|
484
513
|
put(entry: ArtifactIndexEntry): Promise<void>;
|
|
485
|
-
remove(slug: string
|
|
514
|
+
remove(slug: string, tombstone?: {
|
|
515
|
+
uuid: string;
|
|
516
|
+
revision: number;
|
|
517
|
+
}): Promise<void>;
|
|
486
518
|
get(slug: string): Promise<ArtifactIndexEntry | null>;
|
|
487
519
|
list(opts?: {
|
|
488
520
|
owner?: string;
|
|
@@ -502,6 +534,8 @@ export interface ArtifactIndexRpc {
|
|
|
502
534
|
* The DO never trusts anything else from the client for access decisions.
|
|
503
535
|
*/
|
|
504
536
|
export declare const HX_HEADER_KEY = "x-hx-artifact-key";
|
|
537
|
+
/** Trusted visit dimensions. The host sets it; the DO strips it before the facet. */
|
|
538
|
+
export declare const HX_HEADER_VISIT = "x-hx-artifact-visit";
|
|
505
539
|
/** Public base path of the artifact including trailing slash, e.g. `/demo/k/abc/` or `/app/demo/`. */
|
|
506
540
|
export declare const HX_HEADER_BASE = "x-hx-artifact-base";
|
|
507
541
|
export {};
|
|
@@ -15,12 +15,29 @@ export declare const WORKER_SESSION_ID_RE: RegExp;
|
|
|
15
15
|
export declare function isWorkerFlowId(value: unknown): value is string;
|
|
16
16
|
export declare function isWorkerSessionId(value: unknown): value is string;
|
|
17
17
|
export type ArtifactTheme = "hugex" | "none";
|
|
18
|
+
export type ArtifactLoadingMode = "auto" | "manual" | "none";
|
|
19
|
+
export interface ArtifactLoadingConfig {
|
|
20
|
+
mode: ArtifactLoadingMode;
|
|
21
|
+
page?: string;
|
|
22
|
+
}
|
|
18
23
|
export type ArtifactManifest = {
|
|
19
24
|
title: string;
|
|
20
25
|
libs: string[];
|
|
21
26
|
theme: ArtifactTheme;
|
|
27
|
+
loading?: ArtifactLoadingConfig;
|
|
22
28
|
};
|
|
23
|
-
|
|
29
|
+
/** Validates `loading.page` path rules (E3): valid relative path, `.html`, not reserved or under `__hx/`. */
|
|
30
|
+
export declare function validateLoadingPagePath(path: string): string | null;
|
|
31
|
+
/** Validates effective `loading.page` existence and 32 KiB UTF-8 size limit. */
|
|
32
|
+
export declare function validateLoadingConfig(manifest: ArtifactManifest, readFile: (path: string) => string | null): {
|
|
33
|
+
ok: true;
|
|
34
|
+
} | {
|
|
35
|
+
ok: false;
|
|
36
|
+
error: string;
|
|
37
|
+
};
|
|
38
|
+
export declare function parseArtifactManifest(text: string, opts?: {
|
|
39
|
+
ignoreInvalidLoading?: boolean;
|
|
40
|
+
}): {
|
|
24
41
|
ok: true;
|
|
25
42
|
manifest: ArtifactManifest;
|
|
26
43
|
} | {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Package version mixed into `runtimeId`. Bump when the Dynamic Worker contract changes. */
|
|
2
|
-
export declare const ARTIFACT_PKG_VERSION = "0.
|
|
2
|
+
export declare const ARTIFACT_PKG_VERSION = "0.8.0";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { HX_HEADER_VISIT, type ArtifactStatDim } from "./types";
|
|
2
|
+
export { HX_HEADER_VISIT };
|
|
3
|
+
export interface ArtifactVisit {
|
|
4
|
+
country: string | null;
|
|
5
|
+
region: string | null;
|
|
6
|
+
device: "mobile" | "tablet" | "desktop" | "bot";
|
|
7
|
+
browser: string;
|
|
8
|
+
os: string;
|
|
9
|
+
referrer: string;
|
|
10
|
+
lang: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Top-level document navigation. Prefetch and prerender are not views.
|
|
14
|
+
* Iframes fail the `Sec-Fetch-Dest: document` check.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isDocumentView(request: Request): boolean;
|
|
17
|
+
export declare function classifyVisit(request: Request): ArtifactVisit;
|
|
18
|
+
/** base64url(JSON), or null when the header would exceed 512 ASCII bytes. */
|
|
19
|
+
export declare function encodeVisit(visit: ArtifactVisit): string | null;
|
|
20
|
+
export declare function buildVisitHeader(request: Request): string | null;
|
|
21
|
+
export declare function decodeVisit(header: string | null): ArtifactVisit | null;
|
|
22
|
+
/** Collapse a dimension value to ASCII ≤ 64 chars, or `other`. */
|
|
23
|
+
export declare function normalizeStatValue(value: string): string;
|
|
24
|
+
export declare function dimensionValue(visit: ArtifactVisit, dim: ArtifactStatDim): string;
|
|
25
|
+
export declare function rankDimensionValues(rows: Array<{
|
|
26
|
+
value: string;
|
|
27
|
+
n: number;
|
|
28
|
+
}>, limit?: number): Array<{
|
|
29
|
+
value: string;
|
|
30
|
+
n: number;
|
|
31
|
+
}>;
|
|
32
|
+
export declare function emptyDimensions(): Record<ArtifactStatDim, Array<{
|
|
33
|
+
value: string;
|
|
34
|
+
n: number;
|
|
35
|
+
}>>;
|
|
36
|
+
/** First 16 bytes of SHA-256(salt ‖ 0x00 ‖ ip ‖ 0x00 ‖ ua). */
|
|
37
|
+
export declare function visitorHash(salt: Uint8Array, ip: string, ua: string): Promise<Uint8Array>;
|
|
38
|
+
export declare function bytesEqual(a: Uint8Array, b: Uint8Array): boolean;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
export type ClientRisk = 'allow' | 'ask';
|
|
2
|
+
export interface ClientToolActionSpec {
|
|
3
|
+
risk: ClientRisk;
|
|
4
|
+
}
|
|
5
|
+
export interface ClientToolSpec {
|
|
6
|
+
sinceVersion: number;
|
|
7
|
+
tokenBudget: number;
|
|
8
|
+
execTimeoutMs?: number;
|
|
9
|
+
description: string;
|
|
10
|
+
actions: Record<string, ClientToolActionSpec>;
|
|
11
|
+
inputSchema: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
export interface ClientToolFamilySpec {
|
|
14
|
+
version: number;
|
|
15
|
+
label: string;
|
|
16
|
+
summary: string;
|
|
17
|
+
tools: Record<string, ClientToolSpec>;
|
|
18
|
+
}
|
|
19
|
+
export declare const CLIENT_TOOL_FAMILIES: {
|
|
20
|
+
readonly system: {
|
|
21
|
+
readonly version: 1;
|
|
22
|
+
readonly label: 'Sistema';
|
|
23
|
+
readonly summary: 'Basic facts about the user computer (OS, local time).';
|
|
24
|
+
readonly tools: {
|
|
25
|
+
readonly desktop_system: {
|
|
26
|
+
readonly sinceVersion: 1;
|
|
27
|
+
readonly tokenBudget: 200;
|
|
28
|
+
readonly description: 'Get basic facts about the user computer: OS, version, local time and time zone.';
|
|
29
|
+
readonly actions: {
|
|
30
|
+
readonly info: {
|
|
31
|
+
readonly risk: 'allow';
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
readonly inputSchema: {
|
|
35
|
+
readonly type: 'object';
|
|
36
|
+
readonly additionalProperties: false;
|
|
37
|
+
readonly properties: {};
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
readonly files: {
|
|
43
|
+
readonly version: 1;
|
|
44
|
+
readonly label: 'Archivos';
|
|
45
|
+
readonly summary: 'List and read files in the folder the user chose.';
|
|
46
|
+
readonly tools: {
|
|
47
|
+
readonly desktop_files: {
|
|
48
|
+
readonly sinceVersion: 1;
|
|
49
|
+
readonly tokenBudget: 300;
|
|
50
|
+
readonly description: string;
|
|
51
|
+
readonly actions: {
|
|
52
|
+
readonly list: {
|
|
53
|
+
readonly risk: 'ask';
|
|
54
|
+
};
|
|
55
|
+
readonly read: {
|
|
56
|
+
readonly risk: 'ask';
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
readonly inputSchema: {
|
|
60
|
+
readonly type: 'object';
|
|
61
|
+
readonly additionalProperties: false;
|
|
62
|
+
readonly required: readonly ["action"];
|
|
63
|
+
readonly properties: {
|
|
64
|
+
readonly action: {
|
|
65
|
+
readonly type: 'string';
|
|
66
|
+
readonly enum: readonly ["list", "read"];
|
|
67
|
+
};
|
|
68
|
+
readonly path: {
|
|
69
|
+
readonly type: 'string';
|
|
70
|
+
readonly maxLength: 512;
|
|
71
|
+
readonly description: 'Relative path. Default "."';
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
readonly code: {
|
|
79
|
+
readonly version: 1;
|
|
80
|
+
readonly label: 'Código';
|
|
81
|
+
readonly summary: 'Run Python or Deno code in a sandboxed local runtime inside the working folder.';
|
|
82
|
+
readonly tools: {
|
|
83
|
+
readonly desktop_code: {
|
|
84
|
+
readonly sinceVersion: 1;
|
|
85
|
+
readonly tokenBudget: 450;
|
|
86
|
+
readonly execTimeoutMs: 130000;
|
|
87
|
+
readonly description: string;
|
|
88
|
+
readonly actions: {
|
|
89
|
+
readonly run: {
|
|
90
|
+
readonly risk: 'ask';
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
readonly inputSchema: {
|
|
94
|
+
readonly type: 'object';
|
|
95
|
+
readonly additionalProperties: false;
|
|
96
|
+
readonly required: readonly ["action", "language", "code"];
|
|
97
|
+
readonly properties: {
|
|
98
|
+
readonly action: {
|
|
99
|
+
readonly type: 'string';
|
|
100
|
+
readonly enum: readonly ["run"];
|
|
101
|
+
};
|
|
102
|
+
readonly language: {
|
|
103
|
+
readonly type: 'string';
|
|
104
|
+
};
|
|
105
|
+
readonly code: {
|
|
106
|
+
readonly type: 'string';
|
|
107
|
+
readonly minLength: 1;
|
|
108
|
+
readonly maxLength: 16384;
|
|
109
|
+
};
|
|
110
|
+
readonly timeoutSec: {
|
|
111
|
+
readonly type: 'number';
|
|
112
|
+
readonly minimum: 1;
|
|
113
|
+
readonly maximum: 120;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
export type ClientToolFamilyId = keyof typeof CLIENT_TOOL_FAMILIES;
|
|
122
|
+
export interface ResolvedClientTool {
|
|
123
|
+
id: string;
|
|
124
|
+
family: ClientToolFamilyId;
|
|
125
|
+
familySpec: ClientToolFamilySpec;
|
|
126
|
+
spec: ClientToolSpec;
|
|
127
|
+
}
|
|
128
|
+
export declare function isClientToolFamily(family: string): family is ClientToolFamilyId;
|
|
129
|
+
export declare function getClientTool(id: string): ResolvedClientTool | undefined;
|
|
130
|
+
export declare function listClientTools(): ResolvedClientTool[];
|
|
131
|
+
export declare const CLIENT_TOOL_ERROR_CODES: ReadonlySet<string>;
|
|
132
|
+
export declare function sanitizeClientToolCode(code: unknown): string;
|
|
133
|
+
export declare function sanitizeClientToolAction(toolName: string, action: unknown): string;
|
|
134
|
+
export declare const CLIENT_TOOL_LANGUAGES: ReadonlySet<string>;
|
|
135
|
+
export declare function sanitizeClientToolLanguage(language: unknown): string;
|
|
136
|
+
export declare function sanitizeFiniteInt(value: unknown): number | undefined;
|
|
137
|
+
export declare function sanitizeDurationMs(value: unknown): number | undefined;
|
|
@@ -9,3 +9,4 @@ export * from './composio';
|
|
|
9
9
|
export * from './classifier';
|
|
10
10
|
export { CLEF_MODELS } from '../constants/clef-models';
|
|
11
11
|
export { TOOL_REGISTRY_SNAPSHOT } from '../constants/tools-registry';
|
|
12
|
+
export { CLIENT_TOOL_FAMILIES, getClientTool, isClientToolFamily, listClientTools, type ClientRisk, type ClientToolActionSpec, type ClientToolFamilyId, type ClientToolFamilySpec, type ClientToolSpec, type ResolvedClientTool, } from '../constants/client-tools';
|
|
@@ -23,7 +23,7 @@ export interface WorkerGraph {
|
|
|
23
23
|
}
|
|
24
24
|
export type IssueSeverity = 'error' | 'warning';
|
|
25
25
|
export type CredentialKind = 'bearer_token' | 'basic_auth' | 'known_token' | 'url_userinfo' | 'url_query' | 'sensitive_key' | 'high_entropy';
|
|
26
|
-
export type IssueCode = 'missing_state' | 'schema_version' | 'var_mapping' | 'classifier_invalid' | 'classifier_edge_missing' | 'out_vars_invalid' | 'start_count' | 'answer_missing' | 'dead_end' | 'unknown_node_type' | 'duplicate_node_id' | 'invalid_node_id' | 'node_id_collides_with_input' | 'edge_unknown_node' | 'edge_bad_handle' | 'edge_duplicate' | 'start_has_input' | 'answer_has_output' | 'multiple_outgoing' | 'field_type' | 'field_required' | 'field_range' | 'field_enum' | 'ref_syntax' | 'ref_unknown_node' | 'ref_out_of_scope' | 'ref_unknown_output' | 'ref_binary_not_allowed' | 'start_input_invalid' | 'answer_mapping_invalid' | 'worker_self_reference' | 'classifier_error_unrouted' | 'classifier_handle_inactive' | 'unreachable_node' | 'graph_cycle' | 'crawl_prompt_literal' | 'model_unknown' | 'param_unsupported' | 'reasoning_effort_unsupported' | 'tool_unavailable' | 'tool_kind_mismatch' | 'skill_unavailable' | 'builtin_unknown' | 'tool_args_invalid' | 'tool_args_unknown' | 'composio_slug_disabled' | 'composio_schema_missing' | 'memo_unavailable' | 'worker_unavailable' | 'worker_child_no_output' | 'worker_inputs_mismatch' | 'worker_child_inactive_forbidden' | 'worker_child_inactive' | 'secret_unknown' | 'secret_check_skipped' | 'personal_memory_inactive' | 'inline_credential' | 'op_invalid' | 'op_unknown_node' | 'already_connected' | 'edge_not_found' | 'edge_ambiguous' | 'cannot_remove_start';
|
|
26
|
+
export type IssueCode = 'missing_state' | 'schema_version' | 'var_mapping' | 'classifier_invalid' | 'classifier_edge_missing' | 'out_vars_invalid' | 'start_count' | 'answer_missing' | 'dead_end' | 'unknown_node_type' | 'duplicate_node_id' | 'invalid_node_id' | 'node_id_collides_with_input' | 'edge_unknown_node' | 'edge_bad_handle' | 'edge_duplicate' | 'start_has_input' | 'answer_has_output' | 'multiple_outgoing' | 'field_type' | 'field_required' | 'field_range' | 'field_enum' | 'ref_syntax' | 'ref_unknown_node' | 'ref_out_of_scope' | 'ref_unknown_output' | 'ref_binary_not_allowed' | 'start_input_invalid' | 'answer_mapping_invalid' | 'worker_self_reference' | 'classifier_error_unrouted' | 'classifier_handle_inactive' | 'unreachable_node' | 'graph_cycle' | 'crawl_prompt_literal' | 'model_unknown' | 'param_unsupported' | 'reasoning_effort_unsupported' | 'tool_unavailable' | 'tool_kind_mismatch' | 'skill_unavailable' | 'builtin_unknown' | 'tool_args_invalid' | 'tool_args_unknown' | 'composio_slug_disabled' | 'composio_schema_missing' | 'memo_unavailable' | 'worker_unavailable' | 'worker_child_no_output' | 'worker_inputs_mismatch' | 'worker_child_inactive_forbidden' | 'worker_child_inactive' | 'secret_unknown' | 'secret_check_skipped' | 'personal_memory_inactive' | 'client_tool_unknown' | 'client_tool_inactive' | 'desktop_tools_unknown_family' | 'inline_credential' | 'op_invalid' | 'op_unknown_node' | 'already_connected' | 'edge_not_found' | 'edge_ambiguous' | 'cannot_remove_start';
|
|
27
27
|
export interface GraphIssue {
|
|
28
28
|
code: IssueCode;
|
|
29
29
|
severity: IssueSeverity;
|
|
@@ -56,6 +56,9 @@ export declare const ISSUE_SEVERITY: {
|
|
|
56
56
|
readonly secret_unknown: 'advisory';
|
|
57
57
|
readonly secret_check_skipped: 'advisory';
|
|
58
58
|
readonly personal_memory_inactive: 'advisory';
|
|
59
|
+
readonly client_tool_unknown: 'advisory';
|
|
60
|
+
readonly client_tool_inactive: 'advisory';
|
|
61
|
+
readonly desktop_tools_unknown_family: 'advisory';
|
|
59
62
|
readonly inline_credential: 'blocking';
|
|
60
63
|
readonly op_invalid: 'blocking';
|
|
61
64
|
readonly op_unknown_node: 'blocking';
|