@hugex/artifact 0.8.0 → 0.9.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.
@@ -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
- remove(slug: string): Promise<void>;
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 that ignores a row whose `revision` is less than or equal to the one already stored.
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`: ignore when `revision <=` stored.
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\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";
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): Promise<{
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;
@@ -0,0 +1,8 @@
1
+ import type { McpRequestContext } from '../context';
2
+ import type { ToolTextResult } from '../tools';
3
+ import type { McpDomain } from './artifacts';
4
+ type Row = Record<string, unknown>;
5
+ export declare const MAX_RESPONSE_BYTES = 262144;
6
+ export declare const workerSessionsDomain: McpDomain;
7
+ export declare function executeWorkerSessionTool(name: string, args: Row, context: McpRequestContext): Promise<ToolTextResult>;
8
+ export {};
@@ -511,7 +511,10 @@ export interface ArtifactRpc {
511
511
  /** RPC surface of ArtifactIndexDO (stub = env.ARTIFACT_INDEX.get(env.ARTIFACT_INDEX.idFromName('index'))). */
512
512
  export interface ArtifactIndexRpc {
513
513
  put(entry: ArtifactIndexEntry): Promise<void>;
514
- remove(slug: string): Promise<void>;
514
+ remove(slug: string, tombstone?: {
515
+ uuid: string;
516
+ revision: number;
517
+ }): Promise<void>;
515
518
  get(slug: string): Promise<ArtifactIndexEntry | null>;
516
519
  list(opts?: {
517
520
  owner?: string;