@hugex/artifact 0.0.0-stage → 0.1.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/LICENSE +18 -0
- package/README.md +104 -2
- package/dist/catalog.d.ts +49 -0
- package/dist/dev-prefix.d.ts +5 -0
- package/dist/do/ArtifactDO.d.ts +98 -0
- package/dist/do/ArtifactIndexDO.d.ts +18 -0
- package/dist/do/index-upsert.d.ts +6 -0
- package/dist/do/meta-migrate.d.ts +12 -0
- package/dist/do/ora-index.d.ts +17 -0
- package/dist/hash.d.ts +36 -0
- package/dist/host-route.d.ts +40 -0
- package/dist/host.d.ts +9 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +875 -0
- package/dist/inject.d.ts +29 -0
- package/dist/internal.d.ts +10 -0
- package/dist/limits.d.ts +20 -0
- package/dist/mcp/access.d.ts +18 -0
- package/dist/mcp/auth.d.ts +32 -0
- package/dist/mcp/authz.d.ts +50 -0
- package/dist/mcp/index.d.ts +12 -0
- package/dist/mcp/tools.d.ts +43 -0
- package/dist/rpc.d.ts +5 -0
- package/dist/runtime/artifact-app-source.d.ts +7 -0
- package/dist/sql.d.ts +17 -0
- package/dist/templates.d.ts +7 -0
- package/dist/types.d.ts +209 -0
- package/dist/url.d.ts +8 -0
- package/dist/validate.d.ts +21 -0
- package/dist/version.d.ts +2 -0
- package/package.json +26 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
HugeX Proprietary Software License
|
|
2
|
+
|
|
3
|
+
Copyright (c) HugeX. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is granted to HugeX customers and authorized partners to install,
|
|
6
|
+
use, and integrate @hugex packages (@hugex/ai, @hugex/ui, @hugex/shared, and
|
|
7
|
+
related scoped packages) solely in connection with a HugeX or Ora deployment
|
|
8
|
+
you are licensed to operate.
|
|
9
|
+
|
|
10
|
+
You may not copy, modify, merge, publish, distribute, sublicense, or sell
|
|
11
|
+
copies of this software except as expressly permitted by HugeX in writing.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
16
|
+
HUGEX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
17
|
+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
18
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,105 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @hugex/artifact
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
HugeX Artifacts runtime for a tenant Cloudflare Worker. Each `ora-[tenant]` runs its own artifacts. The tenant Worker re-exports the Durable Objects and calls `handleArtifactHost` before any other fetch handler.
|
|
4
|
+
|
|
5
|
+
Source of this package is `ora/lib/artifact/`. This repository is the published build (`../artifact`).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @hugex/artifact
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Runtime dependency: `jose`. There are no peer dependencies.
|
|
14
|
+
|
|
15
|
+
## Mount on a tenant Worker
|
|
16
|
+
|
|
17
|
+
### 1. Re-export the Durable Objects
|
|
18
|
+
|
|
19
|
+
In `workers/app.ts`, export both classes from this package (same pattern as `AgentDO` from `@hugex/ai`) and dispatch the artifact host **before** every other handler:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { handleArtifactHost } from '@hugex/artifact';
|
|
23
|
+
|
|
24
|
+
export default {
|
|
25
|
+
async fetch(request, env, ctx) {
|
|
26
|
+
const artifactResponse = await handleArtifactHost(request, env, ctx);
|
|
27
|
+
if (artifactResponse) return artifactResponse;
|
|
28
|
+
|
|
29
|
+
// existing tenant handlers (agents, auth, React Router, …)
|
|
30
|
+
},
|
|
31
|
+
} satisfies ExportedHandler<Env>;
|
|
32
|
+
|
|
33
|
+
export { AgentDO } from '@hugex/ai';
|
|
34
|
+
export { ArtifactDO, ArtifactIndexDO } from '@hugex/artifact';
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`handleArtifactHost` returns `null` when the request is not for the artifact host, and a `Response` when it is. On the artifact host the response is terminal: `/mcp`, `/<slug>/`, `/<slug>/k/<key>/`, or 404. Do not fall through to login or agent routes.
|
|
38
|
+
|
|
39
|
+
### 2. Bindings
|
|
40
|
+
|
|
41
|
+
`wrangler.jsonc` (do not put `TENANT` here; it is a var in `.dev.vars` / the tenant dashboard):
|
|
42
|
+
|
|
43
|
+
```jsonc
|
|
44
|
+
{
|
|
45
|
+
"durable_objects": {
|
|
46
|
+
"bindings": [
|
|
47
|
+
{ "name": "ARTIFACT", "class_name": "ArtifactDO" },
|
|
48
|
+
{ "name": "ARTIFACT_INDEX", "class_name": "ArtifactIndexDO" }
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
"worker_loaders": [{ "binding": "LOADER" }],
|
|
52
|
+
"vars": {
|
|
53
|
+
"ARTIFACT_HOST": "app-<tenant>.hugex.co"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Secrets and vars:
|
|
59
|
+
|
|
60
|
+
| Name | Where | Required |
|
|
61
|
+
|---|---|---|
|
|
62
|
+
| `TENANT` | var (`.dev.vars` locally, Worker var in production) | yes |
|
|
63
|
+
| `KC_RS256_PK` | secret, same Keycloak RS256 public key ora already uses | yes |
|
|
64
|
+
| `ARTIFACT_HOST` | production var, e.g. `app-vip.hugex.co` | production only |
|
|
65
|
+
| `ARTIFACT_DEV_PATH` | `.dev.vars` only, e.g. `/app` | local only |
|
|
66
|
+
| `LOADER` | `worker_loaders` binding | yes |
|
|
67
|
+
|
|
68
|
+
Leave `ARTIFACT_HOST` unset in local dev. With `ARTIFACT_DEV_PATH=/app` the same Worker serves `/app/mcp` and `/app/<slug>/…` on the main host.
|
|
69
|
+
|
|
70
|
+
### 3. Migration v3
|
|
71
|
+
|
|
72
|
+
Add a **new** migration tag. Do not append the classes to an existing tag:
|
|
73
|
+
|
|
74
|
+
```jsonc
|
|
75
|
+
"migrations": [
|
|
76
|
+
{ "tag": "v2", "new_sqlite_classes": ["AgentDO"] },
|
|
77
|
+
{ "tag": "v3", "new_sqlite_classes": ["ArtifactDO", "ArtifactIndexDO"] }
|
|
78
|
+
]
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`ArtifactDO` is one instance per artifact (`idFromName(slug)`). `ArtifactIndexDO` is a single instance per tenant (`idFromName('index')`).
|
|
82
|
+
|
|
83
|
+
### 4. Local ora
|
|
84
|
+
|
|
85
|
+
From `ora/`:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# .dev.vars (not committed by the package task):
|
|
89
|
+
# TENANT=cx_test
|
|
90
|
+
# ARTIFACT_DEV_PATH=/app
|
|
91
|
+
|
|
92
|
+
pnpm dev
|
|
93
|
+
curl -X GET "http://localhost:5173/app/mcp"
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`GET /app/mcp` is the MCP endpoint and responds **405** (or **401** if a route requires a Bearer token before the method check). It must not be a React Router 404.
|
|
97
|
+
|
|
98
|
+
## Package version
|
|
99
|
+
|
|
100
|
+
`runtimeId` includes the package version. The build defines the identifier `__ARTIFACT_PKG_VERSION__` from `ora/scripts/artifact-version.json`. Runtime code should use:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
declare const __ARTIFACT_PKG_VERSION__: string;
|
|
104
|
+
export const ARTIFACT_PKG_VERSION: string = __ARTIFACT_PKG_VERSION__;
|
|
105
|
+
```
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recommended client libraries. Exact versions, static jsDelivr files (never `+esm`,
|
|
3
|
+
* which is rebuilt and breaks SRI).
|
|
4
|
+
*
|
|
5
|
+
* Regenerate `integrity` after changing a URL (Accept-Encoding: identity):
|
|
6
|
+
* curl -fsSL -H 'Accept-Encoding: identity' '<url>' \
|
|
7
|
+
* | openssl dgst -sha384 -binary | openssl base64 -A
|
|
8
|
+
* Prefix the digest with `sha384-`.
|
|
9
|
+
*
|
|
10
|
+
* react and react-dom are not listed. react@19.2.0 publishes only CJS
|
|
11
|
+
* (`index.js` → `cjs/react.production.js`); there is no stable static ESM
|
|
12
|
+
* browser entry. jsDelivr `+esm` is generated per request and cannot be pinned
|
|
13
|
+
* with SRI. Preact is the catalog's component runtime.
|
|
14
|
+
*
|
|
15
|
+
* `chart.js/auto` is a 147-byte re-export of `../dist/chart.js`. That relative
|
|
16
|
+
* import is resolved by the CDN and is not covered by the import-map integrity
|
|
17
|
+
* entry (same as the Fase 0 spike). `@kurkle/color` is a bare specifier inside
|
|
18
|
+
* `dist/chart.js`, so it is always added with chart.js.
|
|
19
|
+
*/
|
|
20
|
+
export interface CatalogSpecifier {
|
|
21
|
+
url: string;
|
|
22
|
+
integrity: string;
|
|
23
|
+
}
|
|
24
|
+
export interface CatalogEntry {
|
|
25
|
+
/** Name accepted in artifact.json `libs`. */
|
|
26
|
+
name: string;
|
|
27
|
+
version: string;
|
|
28
|
+
/** Primary file URL (also the classic script URL when `kind` is `classic`). */
|
|
29
|
+
url: string;
|
|
30
|
+
integrity: string;
|
|
31
|
+
kind: "module" | "classic";
|
|
32
|
+
/** Import-map specifiers contributed when this entry is selected. */
|
|
33
|
+
specifiers: Record<string, CatalogSpecifier>;
|
|
34
|
+
/** Other catalog names that must be on the import map (bare imports). */
|
|
35
|
+
needs?: string[];
|
|
36
|
+
}
|
|
37
|
+
export declare const CATALOG: readonly CatalogEntry[];
|
|
38
|
+
export declare function catalogEntry(name: string): CatalogEntry | undefined;
|
|
39
|
+
export declare function tailwindBrowser(): {
|
|
40
|
+
url: string;
|
|
41
|
+
integrity: string;
|
|
42
|
+
};
|
|
43
|
+
export interface ResolvedImports {
|
|
44
|
+
imports: Record<string, string>;
|
|
45
|
+
integrity: Record<string, string>;
|
|
46
|
+
warnings: string[];
|
|
47
|
+
}
|
|
48
|
+
/** Unknown names become warnings. Bare deps of a known lib are pulled in without a warning. */
|
|
49
|
+
export declare function resolveImportMap(libs: readonly string[]): ResolvedImports;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { DurableObject } from "cloudflare:workers";
|
|
2
|
+
import type { ArtifactEnv, ArtifactFile, ArtifactLogEntry, ArtifactMeta, ArtifactRpc, ArtifactVersion, CreateArtifactInput, QueryResult, SettingsInput, WriteInput, WriteResult } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* One instance per artifact (`idFromName(slug)`).
|
|
5
|
+
* Supervisor SQLite holds meta, files, versions, and logs.
|
|
6
|
+
* `server.js` runs in a facet named `app`, loaded with `globalOutbound: null` and `env: {}`.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ArtifactDO extends DurableObject<ArtifactEnv> implements ArtifactRpc {
|
|
9
|
+
/** Bumped when an activation window expires so a late health check cannot publish. */
|
|
10
|
+
private activationGen;
|
|
11
|
+
constructor(ctx: DurableObjectState, env: ArtifactEnv);
|
|
12
|
+
alarm(): Promise<void>;
|
|
13
|
+
create(input: CreateArtifactInput): Promise<{
|
|
14
|
+
meta: ArtifactMeta;
|
|
15
|
+
key: string;
|
|
16
|
+
} | null>;
|
|
17
|
+
getMeta(): Promise<ArtifactMeta | null>;
|
|
18
|
+
getAccess(): Promise<{
|
|
19
|
+
public: boolean;
|
|
20
|
+
key: string | null;
|
|
21
|
+
} | null>;
|
|
22
|
+
readFiles(opts?: {
|
|
23
|
+
version?: string;
|
|
24
|
+
path?: string;
|
|
25
|
+
}): Promise<ArtifactFile[] | null>;
|
|
26
|
+
write(input: WriteInput): Promise<WriteResult>;
|
|
27
|
+
rollback(input: {
|
|
28
|
+
version: string;
|
|
29
|
+
author: string;
|
|
30
|
+
}): Promise<WriteResult>;
|
|
31
|
+
settings(input: SettingsInput): Promise<{
|
|
32
|
+
meta: ArtifactMeta;
|
|
33
|
+
key: string | null;
|
|
34
|
+
} | null>;
|
|
35
|
+
versions(opts?: {
|
|
36
|
+
limit?: number;
|
|
37
|
+
}): Promise<ArtifactVersion[] | null>;
|
|
38
|
+
logs(opts?: {
|
|
39
|
+
limit?: number;
|
|
40
|
+
source?: ArtifactLogEntry["source"];
|
|
41
|
+
}): Promise<ArtifactLogEntry[] | null>;
|
|
42
|
+
query(sql: string): Promise<QueryResult>;
|
|
43
|
+
fetch(request: Request): Promise<Response>;
|
|
44
|
+
webSocketMessage(_ws: WebSocket, message: string | ArrayBuffer): Promise<void>;
|
|
45
|
+
webSocketClose(_ws: WebSocket, _code: number, _reason: string, _wasClean: boolean): Promise<void>;
|
|
46
|
+
webSocketError(_ws: WebSocket, _error: unknown): Promise<void>;
|
|
47
|
+
private boot;
|
|
48
|
+
private migrate;
|
|
49
|
+
private recoverProvisional;
|
|
50
|
+
private writeLocked;
|
|
51
|
+
private rollbackLocked;
|
|
52
|
+
private beginActivation;
|
|
53
|
+
private activationLive;
|
|
54
|
+
/** Starts `serverJs`, or stops the facet when the version has no server. Load, health, and restore share `session`. */
|
|
55
|
+
private activateCode;
|
|
56
|
+
/** Version row + files, or nothing. Hashes are already computed. Quota is checked before the inserts. */
|
|
57
|
+
private persistNewVersion;
|
|
58
|
+
private markFailed;
|
|
59
|
+
/** Active/previous/meta move together, and the index is marked dirty in the same transaction. */
|
|
60
|
+
private promote;
|
|
61
|
+
private runtimeId;
|
|
62
|
+
private loadApp;
|
|
63
|
+
private facetOf;
|
|
64
|
+
/** Attach to the running facet, or start it. Does not abort. */
|
|
65
|
+
private ensureFacet;
|
|
66
|
+
/** Replace the facet isolate. Class load happens before abort so a bad module leaves the previous facet up. */
|
|
67
|
+
private swapFacet;
|
|
68
|
+
private abortFacet;
|
|
69
|
+
private allow;
|
|
70
|
+
private acceptReload;
|
|
71
|
+
private serveHtml;
|
|
72
|
+
private serveFile;
|
|
73
|
+
private forwardApi;
|
|
74
|
+
private broadcastReload;
|
|
75
|
+
private closeStaleSockets;
|
|
76
|
+
private browserLogAllowed;
|
|
77
|
+
private writeLog;
|
|
78
|
+
/**
|
|
79
|
+
* Push `meta` to the local index and, when hx-ora is configured, to
|
|
80
|
+
* `PUT /internal/artifacts/:uuid`. The two dirty flags retry independently.
|
|
81
|
+
* Without `HX_ORA_URL` the remote flag is left set and no request is made.
|
|
82
|
+
*/
|
|
83
|
+
private flushIndex;
|
|
84
|
+
private flushLocalIndex;
|
|
85
|
+
private flushOraIndex;
|
|
86
|
+
/** Alarm only for a destination that will actually be retried. */
|
|
87
|
+
private armIndexAlarm;
|
|
88
|
+
private indexEntry;
|
|
89
|
+
private readMeta;
|
|
90
|
+
private toPublic;
|
|
91
|
+
private secure;
|
|
92
|
+
private toVersion;
|
|
93
|
+
private filesFor;
|
|
94
|
+
private readFile;
|
|
95
|
+
private rows;
|
|
96
|
+
private notFound;
|
|
97
|
+
private plain;
|
|
98
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DurableObject } from "cloudflare:workers";
|
|
2
|
+
import type { ArtifactEnv, ArtifactIndexEntry, ArtifactIndexRpc } from "../types";
|
|
3
|
+
export { INDEX_UPSERT_SQL } from "./index-upsert";
|
|
4
|
+
/**
|
|
5
|
+
* One instance per tenant (`idFromName('index')`).
|
|
6
|
+
* ArtifactDO calls `put` after create, write, rollback, and settings.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ArtifactIndexDO extends DurableObject<ArtifactEnv> implements ArtifactIndexRpc {
|
|
9
|
+
constructor(ctx: DurableObjectState, env: ArtifactEnv);
|
|
10
|
+
put(entry: ArtifactIndexEntry): Promise<void>;
|
|
11
|
+
remove(slug: string): Promise<void>;
|
|
12
|
+
get(slug: string): Promise<ArtifactIndexEntry | null>;
|
|
13
|
+
list(opts?: {
|
|
14
|
+
owner?: string;
|
|
15
|
+
}): Promise<ArtifactIndexEntry[]>;
|
|
16
|
+
private rows;
|
|
17
|
+
private toEntry;
|
|
18
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Upsert that ignores a row whose `revision` is less than or equal to the one already stored.
|
|
3
|
+
* `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`: ignore when `revision <=` stored.
|
|
5
|
+
*/
|
|
6
|
+
export declare const INDEX_UPSERT_SQL = "INSERT INTO artifact (slug, uuid, title, org, owner, grp, public, active_version, updated_at, revision)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\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 WHERE excluded.revision > artifact.revision";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Columns added to `meta` after the first ArtifactDO schema.
|
|
3
|
+
* A new column on an existing DO marks both index replicas dirty so the next boot reconciles.
|
|
4
|
+
* Adding `revision` also publishes that row as revision 1, strictly newer than a stored 0.
|
|
5
|
+
*/
|
|
6
|
+
export declare const META_ADDED_COLUMNS: readonly {
|
|
7
|
+
name: string;
|
|
8
|
+
ddl: string;
|
|
9
|
+
}[];
|
|
10
|
+
/** SQL to run after new columns were added, or null when the schema was already current. */
|
|
11
|
+
export declare function metaBackfillSql(addedColumns: readonly string[]): string | null;
|
|
12
|
+
export declare function applyMetaMigration(exec: (sql: string) => void, columnNames: readonly string[]): string[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Push one ArtifactIndexEntry to hx-ora `PUT /internal/artifacts/:uuid`.
|
|
3
|
+
* The JSON body includes `revision`. hx-ora ignores the write when `revision` is less than or
|
|
4
|
+
* equal to the stored revision (including a tombstone). The caller skips this when HX_ORA_URL
|
|
5
|
+
* is unset. A non-2xx response or a transport failure leaves the DO's ora_dirty flag set.
|
|
6
|
+
*/
|
|
7
|
+
import type { ArtifactIndexEntry } from "../types";
|
|
8
|
+
export declare const ORA_INDEX_TIMEOUT_MS = 5000;
|
|
9
|
+
export declare function pushArtifactIndex(env: {
|
|
10
|
+
HX_ORA_URL?: string;
|
|
11
|
+
HX_API_KEY?: string;
|
|
12
|
+
}, entry: ArtifactIndexEntry, fetchImpl?: typeof fetch, timeoutMs?: number): Promise<{
|
|
13
|
+
ok: true;
|
|
14
|
+
} | {
|
|
15
|
+
ok: false;
|
|
16
|
+
error: string;
|
|
17
|
+
}>;
|
package/dist/hash.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare function sha256Hex(text: string): Promise<string>;
|
|
2
|
+
/** Compare two strings without short-circuiting on the first differing byte. */
|
|
3
|
+
export declare function timingSafeEqual(a: string, b: string): boolean;
|
|
4
|
+
export declare function utf8Length(text: string): number;
|
|
5
|
+
/** Replace `/k/<key>/` so a capability URL never lands in a log or error string. */
|
|
6
|
+
export declare function redactArtifactKey(text: string): string;
|
|
7
|
+
export declare function truncateUtf8(text: string, maxBytes: number): string;
|
|
8
|
+
/**
|
|
9
|
+
* sha256(JSON.stringify(sorted [[path, sha256(content)], ...])).
|
|
10
|
+
* Key order does not change the digest. The JSON array is unambiguous:
|
|
11
|
+
* a newline or NUL inside a file cannot alias another path.
|
|
12
|
+
*/
|
|
13
|
+
export declare function hashFileSet(files: ReadonlyMap<string, string> | Record<string, string>): Promise<string>;
|
|
14
|
+
export declare function sameFileSet(a: ReadonlyMap<string, string>, b: ReadonlyMap<string, string>): boolean;
|
|
15
|
+
/** Stable config mixed into runtimeId. `globalOutbound: null` and empty env are part of the contract. */
|
|
16
|
+
export declare function artifactWorkerConfig(compatibilityDate?: string): {
|
|
17
|
+
compatibilityDate: string;
|
|
18
|
+
mainModule: string;
|
|
19
|
+
globalOutbound: null;
|
|
20
|
+
env: Record<string, never>;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* runtimeId = sha256(server modules + package version + compatibilityDate + config).
|
|
24
|
+
* Loader id is `artifact:<uuid>:<runtimeId>`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function runtimeIdOf(parts: {
|
|
27
|
+
appSource: string;
|
|
28
|
+
serverJs: string;
|
|
29
|
+
pkgVersion: string;
|
|
30
|
+
compatibilityDate: string;
|
|
31
|
+
config: unknown;
|
|
32
|
+
}): Promise<string>;
|
|
33
|
+
export declare function randomKey(): string;
|
|
34
|
+
export declare function messageOf(err: unknown): string;
|
|
35
|
+
export declare function isSqliteFull(err: unknown): boolean;
|
|
36
|
+
export declare function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type ArtifactRoute = {
|
|
2
|
+
kind: "passthrough";
|
|
3
|
+
} | {
|
|
4
|
+
kind: "mcp";
|
|
5
|
+
} | {
|
|
6
|
+
kind: "not-found";
|
|
7
|
+
} | {
|
|
8
|
+
kind: "redirect";
|
|
9
|
+
location: string;
|
|
10
|
+
} | {
|
|
11
|
+
kind: "forward";
|
|
12
|
+
slug: string;
|
|
13
|
+
key: string;
|
|
14
|
+
internalPath: string;
|
|
15
|
+
basePath: string;
|
|
16
|
+
};
|
|
17
|
+
export interface RouteInput {
|
|
18
|
+
pathname: string;
|
|
19
|
+
search: string;
|
|
20
|
+
/**
|
|
21
|
+
* When false, only paths under `devPrefix` are artifact routes; anything else is `passthrough`.
|
|
22
|
+
* When true (request hostname is ARTIFACT_HOST), every path is terminal.
|
|
23
|
+
*/
|
|
24
|
+
terminal: boolean;
|
|
25
|
+
devPrefix?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Parse the public URL into an MCP handoff, a redirect, or a forward to ArtifactDO.
|
|
29
|
+
* `internalPath` is the path the DO sees (`/`, `/app.js`, `/api/x`, `/__hx/ws`).
|
|
30
|
+
* `basePath` is the public base with a trailing slash.
|
|
31
|
+
*/
|
|
32
|
+
export declare function routeArtifactRequest(input: RouteInput): ArtifactRoute;
|
|
33
|
+
/**
|
|
34
|
+
* Rebuild the request the DO fetches: internal path plus the two trusted headers.
|
|
35
|
+
* Client copies of those headers are dropped. The original request is the init so a
|
|
36
|
+
* WebSocket upgrade is preserved (`new Request(url, request)`).
|
|
37
|
+
*/
|
|
38
|
+
export declare function buildForwardRequest(request: Request, route: Extract<ArtifactRoute, {
|
|
39
|
+
kind: "forward";
|
|
40
|
+
}>): Request;
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { artifactDevPrefix } from "./dev-prefix";
|
|
2
|
+
import type { ArtifactEnv } from "./types";
|
|
3
|
+
export { artifactDevPrefix };
|
|
4
|
+
/**
|
|
5
|
+
* Terminal on `ARTIFACT_HOST`. On localhost, 127.0.0.1, or [::1], mounts the same
|
|
6
|
+
* routes under `ARTIFACT_DEV_PATH` (for example `/app/...`). Any other hostname
|
|
7
|
+
* ignores that variable. Returns null when the path is unrelated.
|
|
8
|
+
*/
|
|
9
|
+
export declare function handleArtifactHost(request: Request, env: ArtifactEnv, ctx: ExecutionContext): Promise<Response | null>;
|