@north-light/cli 0.3.625 → 0.3.626
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/import/bundle/blob-keys.d.ts +2 -0
- package/dist/core/import/bundle/blob-keys.js +1 -1
- package/dist/core/import/load/blobs.d.ts +2 -0
- package/dist/core/import/load/blobs.js +1 -1
- package/dist/core/import/load/rollback.js +4 -4
- package/package.json +2 -2
- package/packages/crouter-identity/package.json +1 -1
- package/runtime.lock.json +13 -13
|
@@ -6,5 +6,7 @@ export interface ParsedBlobKey {
|
|
|
6
6
|
ownerTable: 'nodes' | 'human_requests';
|
|
7
7
|
owner: string;
|
|
8
8
|
}
|
|
9
|
+
/** Every prefix `<dir>/<owner>/` under which `parseBlobKey` accepts a key of this owner: the prefixes to list to find all of an owner's blobs. */
|
|
10
|
+
export declare const ownerBlobPrefixes: (ownerTable: ParsedBlobKey["ownerTable"], owner: string) => string[];
|
|
9
11
|
/** The key's kind and owner, or null when it is none of the keys cycle 5 reads (or has an empty, `.` or `..` segment). */
|
|
10
12
|
export declare function parseBlobKey(key: string): ParsedBlobKey | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var u=Object.defineProperty;var s=(t,e)=>u(t,"name",{value:e,configurable:!0});const a=s(t=>`imports/${t}/blobs/`,"runBlobPrefix"),l=s((t,e)=>`${a(t)}${e}`,"runBlobKey"),r=[["conversation","conversations",/^conversations\/([^/]+)\/[^/]+\/[^/]+$/],["attachment","attachments",/^attachments\/([^/]+)\/[0-9a-f]{64}$/],["job","jobs",/^jobs\/([^/]+)\/[^/]+\/output(?:\/\d{8})?$/],["event","events",/^events\/([^/]+)\/\d{16}-\d{16}-[0-9a-f]{32}\.jsonl\.zst$/],["request","requests",/^requests\/([^/]+)\/.+$/]],i=s((t,e)=>r.filter(([n])=>n==="request"==(t==="human_requests")).map(([,n])=>`${n}/${e}/`),"ownerBlobPrefixes");function b(t){if(t.split("/").some(e=>e===""||e==="."||e===".."))return null;for(const[e,,n]of r){const o=n.exec(t);if(o!==null)return{kind:e,ownerTable:e==="request"?"human_requests":"nodes",owner:o[1]}}return null}s(b,"parseBlobKey");export{i as ownerBlobPrefixes,b as parseBlobKey,l as runBlobKey,a as runBlobPrefix};
|
|
@@ -8,5 +8,7 @@ export interface MovedBlobs {
|
|
|
8
8
|
export declare function moveRunBlobs(db: CanvasDb, schema: string, target: string, person: string, blobs: BlobStore, runId: string, created: string[]): Promise<MovedBlobs>;
|
|
9
9
|
/** Delete the keys, concurrently. With `bestEffort`, a key that cannot be deleted is skipped and the rest still go; otherwise the first failure is thrown. */
|
|
10
10
|
export declare function deleteBlobs(blobs: BlobStore, keys: readonly string[], bestEffort?: boolean): Promise<void>;
|
|
11
|
+
/** Delete every blob `moveRunBlobs` can have moved for these owners (the keys `parseBlobKey` accepts under each owner's prefixes): one paged listing per owner and kind, then the deletes, with no request per key to check. */
|
|
12
|
+
export declare function deleteOwnedBlobs(blobs: BlobStore, nodes: readonly string[], requests: readonly string[]): Promise<void>;
|
|
11
13
|
/** Delete the run's uploaded copies (after the run is done). */
|
|
12
14
|
export declare function deleteRunBlobs(blobs: BlobStore, runId: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var M=Object.defineProperty;var l=(e,t)=>M(e,"name",{value:t,configurable:!0});import{R2_MAX_CONNECTIONS as T}from"../../blobs/r2.js";import{ownerBlobPrefixes as R,parseBlobKey as O,runBlobPrefix as _}from"../bundle/blob-keys.js";import{q as p}from"./catalog.js";import{ImportLaneError as E}from"./stage.js";const b=T;function v(){const e=process.env.CRTR_IMPORT_BLOB_WORKERS;if(e===void 0||e==="")return b;const t=Number(e);if(!Number.isInteger(t)||t<1||t>1024)throw new Error(`CRTR_IMPORT_BLOB_WORKERS must be an integer from 1 to 1024, got ${JSON.stringify(e)}`);return t}l(v,"workerLimit");async function w(e,t){if(e.length===0)return;let o=0,n;const i=l(async()=>{for(;n===void 0&&o<e.length;)try{await t(e[o++])}catch(a){n??={error:a}}},"worker");if(await Promise.all(Array.from({length:Math.min(v(),e.length)},i)),n!==void 0)throw n.error}l(w,"forEachBounded");async function I(e,t,o,n,i,a,c){const h={nodes:new Set((await e.prepareUncached(`SELECT node_id AS v FROM ${p(t)}.nodes UNION SELECT node_id FROM ${p(o)}.nodes WHERE sub = ?`).all(n)).map(r=>r.v)),human_requests:new Set((await e.prepareUncached(`SELECT request_id AS v FROM ${p(t)}.human_requests`).all()).map(r=>r.v))},f=_(a),u={moved:0,left:0},m=[];for(const r of await i.listObjects(f)){const s=O(r.key.slice(f.length));s===null||!h[s.ownerTable].has(s.owner)?u.left+=1:m.push(r)}const y=new Map,d=new Set(m.map(r=>r.key.slice(f.length)));return await w([...new Set([...d].map(x))],async r=>{for(const s of await i.listObjects(r))d.has(s.key)&&y.set(s.key,s)}),await w(m,async r=>{const s=r.key.slice(f.length),g=y.get(s);if(g===void 0){if(c.push(s),!await i.copy(r.key,s))throw k(r.key)}else if(!await C(i,r,g))throw new E("blobs","unique_conflict",`${s} already exists with other contents; the import does not replace it`,{key:s});u.moved+=1}),u}l(I,"moveRunBlobs");const x=l(e=>e.split("/").slice(0,2).join("/")+"/","ownerPrefix"),k=l(e=>new E("blobs","bundle_invalid",`${e} was listed and is gone`),"gone");async function C(e,t,o){if(t.size!==o.size)return!1;if(t.etag!==null&&o.etag!==null)return t.etag===o.etag;for(let n=0;n<t.size;n+=S){const i={start:n,length:Math.min(S,t.size-n)},[a,c]=await Promise.all([e.get(t.key,i),e.get(o.key,i)]);if(a===null)throw k(t.key);if(c===null||!a.equals(c))return!1}return!0}l(C,"sameObject");const S=256*1024;async function B(e,t,o=!1){await w(t,o?n=>e.delete(n).catch(()=>{}):n=>e.delete(n))}l(B,"deleteBlobs");async function $(e,t,o){const n=[...t.flatMap(a=>R("nodes",a).map(c=>({prefix:c,owner:a,table:"nodes"}))),...o.flatMap(a=>R("human_requests",a).map(c=>({prefix:c,owner:a,table:"human_requests"})))],i=[];await w(n,async({prefix:a,owner:c,table:h})=>{for(const f of await e.list(a)){const u=O(f);u!==null&&u.ownerTable===h&&u.owner===c&&i.push(f)}}),await B(e,i)}l($,"deleteOwnedBlobs");async function j(e,t){await B(e,await e.list(_(t)))}l(j,"deleteRunBlobs");export{B as deleteBlobs,$ as deleteOwnedBlobs,j as deleteRunBlobs,I as moveRunBlobs};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
AND EXISTS (SELECT 1 FROM _rb p WHERE p.tbl = '${e.parent}' AND ${m(r,e.columns,"c","p.k")}) ${
|
|
3
|
-
AND NOT EXISTS (SELECT 1 FROM _rb o WHERE o.tbl = 'objects' AND o.k ->> 0 = r.document)`).all()).map(e=>e.document);for(const e of
|
|
1
|
+
var C=Object.defineProperty;var u=(n,d)=>C(n,"name",{value:d,configurable:!0});import{openDb as D,withCanvasWrite as h}from"../../canvas/db.js";import{bundleKeys as M}from"../bundle/layout.js";import{keyMatch as m,q as a,readCatalog as y,rowKey as S,topologicalOrder as F}from"./catalog.js";import{deleteOwnedBlobs as W}from"./blobs.js";import{decodeKeys as $}from"./copy.js";import{OBJECT_ID_COLUMNS as H}from"./rewrite.js";import{targetSchema as g}from"./stage.js";class N extends Error{static{u(this,"Refused")}}async function Y(n,d){const _=await D(),c=await _.prepare("SELECT source_install_id, source_kind, state, created_at FROM import_runs WHERE run_id = ?").get(n);if(c===void 0)throw new Error(`no import run ${n}`);if(c.state!=="done"&&c.state!=="committed"&&c.state!=="failed")throw new Error(`import run ${n} is ${c.state}, not rollbackable`);const L=(await _.prepare("SELECT blob_key FROM import_node_files WHERE blob_key LIKE ?").all(`imports/${n}/node-files/%`)).map(t=>t.blob_key),E={run_id:n,rolled_back:!1,dependents:{},deleted:{}},R={nodes:[],human_requests:[]};try{await h(async t=>{const i=await g(t),k=(await t.prepareUncached("SELECT table_name FROM information_schema.tables WHERE table_schema = ? AND table_type = 'BASE TABLE'").all(i)).map(e=>e.table_name),l=await y(t,i,k);l.tables.get("env_vars").primaryKey=["person","owner_kind","owner_id","name"],await t.exec("CREATE TEMP TABLE _rb (tbl text NOT NULL, k jsonb NOT NULL) ON COMMIT DROP");const T=await t.prepare("SELECT table_name, inserted_keys FROM import_manifest WHERE run_id = ?").all(n);for(const{table_name:e,inserted_keys:o}of T){const r=$(o);(e==="nodes"||e==="human_requests")&&R[e].push(...r.map(s=>s[0]));for(let s=0;s<r.length;s+=5e3)await t.prepare("INSERT INTO _rb SELECT ?, e FROM jsonb_array_elements(?::jsonb) e").run(e,JSON.stringify(r.slice(s,s+5e3)))}const b=new Set(T.map(e=>e.table_name));await t.exec("ANALYZE _rb");for(const e of l.foreignKeys){const o=l.tables.get(e.parent),r=l.tables.get(e.table);if(e.table==="import_node_files"||!b.has(e.parent)||o===void 0||r===void 0||e.parentColumns.join()!==o.primaryKey.join())continue;const s=b.has(e.table)?`AND NOT EXISTS (SELECT 1 FROM _rb o WHERE o.tbl = '${e.table}' AND ${m(r,S(r),"c","o.k")})`:"",p=Number((await t.prepareUncached(`SELECT count(*) AS n FROM ${a(i)}.${a(e.table)} c WHERE ${e.columns.map(A=>`c.${a(A)} IS NOT NULL`).join(" AND ")}
|
|
2
|
+
AND EXISTS (SELECT 1 FROM _rb p WHERE p.tbl = '${e.parent}' AND ${m(r,e.columns,"c","p.k")}) ${s}`).get()).n);p>0&&(E.dependents[e.table]=(E.dependents[e.table]??0)+p)}for(const[e,o]of H){const r=l.tables.get(e);if(r===void 0||!r.columns.includes(o)||r.primaryKey.length===0)continue;const s=b.has(e)?`AND NOT EXISTS (SELECT 1 FROM _rb o WHERE o.tbl = '${e}' AND ${m(r,r.primaryKey,"c","o.k")})`:"",p=Number((await t.prepareUncached(`SELECT count(*) AS n FROM ${a(i)}.${a(e)} c WHERE c.${a(o)} IN (SELECT k ->> 0 FROM _rb WHERE tbl = 'objects') ${s}`).get()).n);p>0&&(E.dependents[`${e}.${o}`]=p)}const f=Number((await t.prepare("SELECT count(*) AS n FROM import_runs WHERE source_install_id = ? AND run_id <> ? AND created_at > ? AND (state IN ('loading', 'committed', 'done') OR (state = 'failed' AND committed_at IS NOT NULL))").get(c.source_install_id,n,c.created_at)).n);f>0&&(E.dependents.import_runs=f);const O=Number((await t.prepare("SELECT count(*) AS n FROM import_id_map m WHERE m.run_id <> ? AND m.kind = 'object' AND m.target_value IN (SELECT k ->> 0 FROM _rb WHERE tbl = 'objects')").get(n)).n);if(O>0&&(E.dependents.import_id_map=O),Object.keys(E.dependents).length>0)throw new N;const w=(await t.prepareUncached(`SELECT DISTINCT r.document FROM ${a(i)}.revisions r WHERE r.rev_id IN (SELECT k ->> 0 FROM _rb WHERE tbl = 'revisions')
|
|
3
|
+
AND NOT EXISTS (SELECT 1 FROM _rb o WHERE o.tbl = 'objects' AND o.k ->> 0 = r.document)`).all()).map(e=>e.document);for(const e of F(l,[...b]).reverse()){const o=l.tables.get(e);if(o===void 0)continue;e==="run_events"&&await t.prepareUncached(`SELECT 1 FROM ${a(i)}.run_events t WHERE EXISTS (SELECT 1 FROM _rb k WHERE k.tbl = 'run_events' AND ${m(o,S(o),"t","k.k")}) ORDER BY t."run_id" COLLATE "C", t."sequence_number" FOR UPDATE`).all();const r=await t.prepareUncached(`DELETE FROM ${a(i)}.${a(e)} t WHERE EXISTS (SELECT 1 FROM _rb k WHERE k.tbl = '${e}' AND ${m(o,S(o),"t","k.k")})`).run();E.deleted[e]=r.changes}for(const e of w)await t.prepareUncached(`UPDATE ${a(i)}.documents d SET
|
|
4
4
|
heads_key = COALESCE((SELECT string_agg(r.rev_id, ',' ORDER BY r.rev_id) FROM ${a(i)}.revisions r WHERE r.document = d.object AND NOT EXISTS (SELECT 1 FROM ${a(i)}.revision_parents p WHERE p.parent = r.rev_id)), ''),
|
|
5
5
|
revision = COALESCE((SELECT max(r.number) FROM ${a(i)}.revisions r WHERE r.document = d.object AND NOT EXISTS (SELECT 1 FROM ${a(i)}.revision_parents p WHERE p.parent = r.rev_id)), 0)
|
|
6
|
-
WHERE d.object = ?`).run(e);await t.prepareUncached("DELETE FROM import_key_map km WHERE km.source_install_id = ? AND EXISTS (SELECT 1 FROM _rb r WHERE r.tbl = km.table_name AND r.k ->> 0 = km.target_key)").run(
|
|
6
|
+
WHERE d.object = ?`).run(e);await t.prepareUncached("DELETE FROM import_key_map km WHERE km.source_install_id = ? AND EXISTS (SELECT 1 FROM _rb r WHERE r.tbl = km.table_name AND r.k ->> 0 = km.target_key)").run(c.source_install_id),await t.prepare("DELETE FROM import_id_map WHERE run_id = ?").run(n),await t.prepare("DELETE FROM import_manifest WHERE run_id = ?").run(n),await t.prepare("UPDATE import_runs SET state = 'rolled_back', step = 'rolled_back', finished_at = ? WHERE run_id = ?").run(new Date().toISOString(),n),await v(t,c)})}catch(t){if(t instanceof N)return E;throw t}await d.delete(M.manifest(n));for(const t of L)await d.delete(t);return await W(d,R.nodes,R.human_requests),E.rolled_back=!0,E}u(Y,"rollbackRun");async function v(n,d){if(d.source_kind!=="machine")return;const _=await n.prepare("SELECT object FROM environments WHERE machine_id = ? AND kind = 'machine'").get(d.source_install_id);_!==void 0&&await n.prepare("UPDATE machine_credentials SET revoked_at = ? WHERE environment = ? AND revoked_at IS NULL").run(new Date().toISOString(),_.object)}u(v,"revokeFor");export{Y as rollbackRun};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.626",
|
|
4
4
|
"description": "crtr — agent runtime with memory, plugins, and marketplaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
},
|
|
146
146
|
"license": "UNLICENSED",
|
|
147
147
|
"dependencies": {
|
|
148
|
-
"@north-light/identity": "0.3.
|
|
148
|
+
"@north-light/identity": "0.3.626",
|
|
149
149
|
"@earendil-works/chord": "1.1.0",
|
|
150
150
|
"@earendil-works/pi-agent-core": "1.1.0",
|
|
151
151
|
"@earendil-works/pi-ai": "1.1.0",
|
package/runtime.lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.626",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@north-light/cli",
|
|
9
|
-
"version": "0.3.
|
|
9
|
+
"version": "0.3.626",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "UNLICENSED",
|
|
12
12
|
"workspaces": [
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@milkdown/preset-gfm": "^7.22.3",
|
|
29
29
|
"@milkdown/prose": "^7.22.3",
|
|
30
30
|
"@milkdown/utils": "^7.22.3",
|
|
31
|
-
"@north-light/identity": "0.3.
|
|
31
|
+
"@north-light/identity": "0.3.626",
|
|
32
32
|
"cron-parser": "^5.6.0",
|
|
33
33
|
"esbuild": "^0.27.7",
|
|
34
34
|
"jose": "^6.2.12",
|
|
@@ -11956,17 +11956,17 @@
|
|
|
11956
11956
|
},
|
|
11957
11957
|
"packages/crouter-api": {
|
|
11958
11958
|
"name": "@north-light/api",
|
|
11959
|
-
"version": "0.3.
|
|
11959
|
+
"version": "0.3.626",
|
|
11960
11960
|
"license": "UNLICENSED"
|
|
11961
11961
|
},
|
|
11962
11962
|
"packages/crouter-env-docker": {
|
|
11963
11963
|
"name": "@north-light/env-docker",
|
|
11964
|
-
"version": "0.3.
|
|
11964
|
+
"version": "0.3.626",
|
|
11965
11965
|
"license": "UNLICENSED"
|
|
11966
11966
|
},
|
|
11967
11967
|
"packages/crouter-identity": {
|
|
11968
11968
|
"name": "@north-light/identity",
|
|
11969
|
-
"version": "0.3.
|
|
11969
|
+
"version": "0.3.626",
|
|
11970
11970
|
"license": "UNLICENSED",
|
|
11971
11971
|
"dependencies": {
|
|
11972
11972
|
"jose": "^6.2.1"
|
|
@@ -11974,21 +11974,21 @@
|
|
|
11974
11974
|
},
|
|
11975
11975
|
"packages/crouter-plugin": {
|
|
11976
11976
|
"name": "@north-light/plugin",
|
|
11977
|
-
"version": "0.3.
|
|
11977
|
+
"version": "0.3.626",
|
|
11978
11978
|
"license": "UNLICENSED",
|
|
11979
11979
|
"dependencies": {
|
|
11980
|
-
"@north-light/api": "0.3.
|
|
11981
|
-
"@north-light/identity": "0.3.
|
|
11980
|
+
"@north-light/api": "0.3.626",
|
|
11981
|
+
"@north-light/identity": "0.3.626"
|
|
11982
11982
|
}
|
|
11983
11983
|
},
|
|
11984
11984
|
"packages/crouter-sdk": {
|
|
11985
11985
|
"name": "@north-light/sdk",
|
|
11986
|
-
"version": "0.3.
|
|
11986
|
+
"version": "0.3.626",
|
|
11987
11987
|
"license": "UNLICENSED",
|
|
11988
11988
|
"dependencies": {
|
|
11989
|
-
"@north-light/api": "0.3.
|
|
11990
|
-
"@north-light/identity": "0.3.
|
|
11991
|
-
"@north-light/plugin": "0.3.
|
|
11989
|
+
"@north-light/api": "0.3.626",
|
|
11990
|
+
"@north-light/identity": "0.3.626",
|
|
11991
|
+
"@north-light/plugin": "0.3.626",
|
|
11992
11992
|
"jose": "^6.2.1"
|
|
11993
11993
|
},
|
|
11994
11994
|
"bin": {
|