@hugex/artifact 0.7.2 → 0.8.0

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 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 startFacetForDb;
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
- /** Attach to the running facet, or start it. Does not abort. */
127
- private ensureFacet;
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
- /** Shared alarm for index retries and the soonest open draft. The earlier deadline wins. */
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;
@@ -45,4 +45,4 @@ export declare function routeArtifactRequest(input: RouteInput): ArtifactRoute;
45
45
  */
46
46
  export declare function buildForwardRequest(request: Request, route: Extract<ArtifactRoute, {
47
47
  kind: "forward";
48
- }>): Request;
48
+ }>, visitHeader?: string | null): Request;
@@ -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"): string;
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
@@ -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
- /** Ascending, one row per day, zeros included. */
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
- /** Last day with view > 0 within the 90 retained days. */
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;
@@ -502,6 +531,8 @@ export interface ArtifactIndexRpc {
502
531
  * The DO never trusts anything else from the client for access decisions.
503
532
  */
504
533
  export declare const HX_HEADER_KEY = "x-hx-artifact-key";
534
+ /** Trusted visit dimensions. The host sets it; the DO strips it before the facet. */
535
+ export declare const HX_HEADER_VISIT = "x-hx-artifact-visit";
505
536
  /** Public base path of the artifact including trailing slash, e.g. `/demo/k/abc/` or `/app/demo/`. */
506
537
  export declare const HX_HEADER_BASE = "x-hx-artifact-base";
507
538
  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
- export declare function parseArtifactManifest(text: string): {
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.1.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';