@north-light/cli 0.3.619 → 0.3.621
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/api/contract.d.ts +1 -1
- package/dist/api/contract.js +1 -1
- package/dist/api/dto/imports.d.ts +2 -0
- package/dist/core/events/run-event-chunks.d.ts +6 -0
- package/dist/core/events/run-event-chunks.js +5 -5
- package/dist/core/import/load/catalog.d.ts +5 -0
- package/dist/core/import/load/catalog.js +4 -4
- package/dist/core/import/load/rollback.js +6 -6
- package/dist/core/import/load/verify.js +9 -10
- package/dist/core/llm/app-rungs.d.ts +4 -1
- package/dist/core/llm/app-rungs.js +1 -1
- package/package.json +2 -2
- package/packages/crouter-identity/package.json +1 -1
- package/runtime.lock.json +13 -13
package/dist/api/contract.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** The contract level this build serves and requires. Written by `scripts/contract.mjs release`; never edit by hand. */
|
|
2
|
-
export declare const CONTRACT_LEVEL = "1.
|
|
2
|
+
export declare const CONTRACT_LEVEL = "1.48";
|
|
3
3
|
/** Request header naming the one contract level the caller needs, e.g. `1.3`. Optional: absent means no check. */
|
|
4
4
|
export declare const REQUIRED_CONTRACT_HEADER = "Crouter-Required-Contract";
|
|
5
5
|
/** Response header listing the contract levels the server serves, comma-separated, one per major, e.g. `1.3`. */
|
package/dist/api/contract.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var c=Object.defineProperty;var e=(r,t)=>c(r,"name",{value:t,configurable:!0});const f="1.
|
|
1
|
+
var c=Object.defineProperty;var e=(r,t)=>c(r,"name",{value:t,configurable:!0});const f="1.48",i="Crouter-Required-Contract",p="Crouter-Contract";function l(r){const t=/^(\d+)\.(\d+)$/.exec(r.trim());return t===null?null:{major:Number(t[1]),minor:Number(t[2])}}e(l,"parseContractLevel");function a(r){return r==null?[]:r.split(",").map(t=>l(t)).filter(t=>t!==null)}e(a,"parseServedContracts");function s(r,t){const n=l(r);return n===null?!1:(typeof t=="string"||t===null||t===void 0?a(t):t).some(u=>u.major===n.major&&u.minor>=n.minor)}e(s,"contractSatisfies");function C(r,t,n={}){if(r===void 0)return null;if(l(r)===null)return{status:400,code:"invalid_request",param:i,message:`${i} must be a contract level like 1.0.`};if(s(r,t))return null;const o=r.trim();return{status:426,code:"runtime_version_unsupported",message:t===null||a(t).length===0?`The runtime did not name its contract level; the caller requires contract ${o} or later. Roll the runtime forward.`:`The runtime serves contract ${t}; the caller requires contract ${o} or later within the same major. Roll the runtime forward, or pin an SDK whose crouterContract the runtime serves.`,details:{sdk_version:(n.legacyMinimum??"").trim(),runtime_version:n.runtimeVersion??null,required_contract:o,runtime_contract:t}}}e(C,"contractRefusal");export{p as CONTRACT_HEADER,f as CONTRACT_LEVEL,i as REQUIRED_CONTRACT_HEADER,C as contractRefusal,s as contractSatisfies,l as parseContractLevel,a as parseServedContracts};
|
|
@@ -40,6 +40,8 @@ export interface ImportVerifyDTO {
|
|
|
40
40
|
count: number;
|
|
41
41
|
keys: string[];
|
|
42
42
|
}>;
|
|
43
|
+
/** Per table: manifest rows the target no longer holds because it archived them after the copy (run events older than the archive cutoff); their staged row is not compared. */
|
|
44
|
+
archived?: Record<string, number>;
|
|
43
45
|
invariants: Record<string, boolean>;
|
|
44
46
|
}
|
|
45
47
|
export interface ImportFailureDTO {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RunEvent } from '../../api/dto/run-events.js';
|
|
2
2
|
import type { BlobStore } from '../blobs/index.js';
|
|
3
|
+
export declare const BODY_TYPES: string[];
|
|
3
4
|
/** One fixed 128-sequence range of a run's archived events and the immutable objects that hold it. Passes that archive
|
|
4
5
|
* different rows of one range write different objects; the range's events are their union. */
|
|
5
6
|
export interface RunEventChunk {
|
|
@@ -12,6 +13,11 @@ export declare function listRunEventChunks(store: BlobStore, runId: string): Pro
|
|
|
12
13
|
/** Read a range's events, each sequence once, ordered by sequence. An event body never changes after it is written,
|
|
13
14
|
* so a sequence held by more than one object (a retried or concurrent pass) has the same body in each. A missing object is an error. */
|
|
14
15
|
export declare function readRunEventChunk(store: BlobStore, chunk: RunEventChunk): Promise<RunEvent[]>;
|
|
16
|
+
/** The `ts` before which a run event is archived: body types at the first, every type at the second (the archiver's rule, and import verify's for rows it no longer finds). */
|
|
17
|
+
export declare function archiveCutoffs(now: number): {
|
|
18
|
+
bodyCutoff: string;
|
|
19
|
+
controlCutoff: string;
|
|
20
|
+
};
|
|
15
21
|
/**
|
|
16
22
|
* Archive the same 14-day payload/30-day control events formerly deleted by expireRunEvents.
|
|
17
23
|
* No transaction, connection or lock is held across compression or blob I/O: the rows are read, each range's
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var g=Object.defineProperty;var
|
|
2
|
-
`)){const
|
|
3
|
-
WHERE ts < ? AND (ts < ? OR type IN (${
|
|
4
|
-
${
|
|
5
|
-
`),y=v("sha256").update(
|
|
1
|
+
var g=Object.defineProperty;var i=(e,s)=>g(e,"name",{value:s,configurable:!0});import{createHash as v}from"node:crypto";import{promisify as _}from"node:util";import{zstdCompress as k,zstdDecompress as x}from"node:zlib";import{openDb as N,withCanvasWrite as S}from"../canvas/db.js";const C=_(k),$=_(x),l=128,q=16,w=["node.tool_call.completed","node.tool_call.started","node.system_prompt.set","node.thinking.done","node.output_text.done"],h=i(e=>`events/${e}/`,"prefix"),b=i(e=>String(e).padStart(q,"0"),"pad"),D=i(e=>{const s=Math.floor((e-1)/l)*l+1;return{first:s,last:s+l-1}},"range"),R=i((e,s,n,t)=>`${h(e)}${b(s)}-${b(n)}-${t}.jsonl.zst`,"chunkKey");async function H(e,s){const n=new Map;for(const t of await e.list(h(s))){const o=/\/(\d{16})-(\d{16})-[0-9a-f]{32}\.jsonl\.zst$/.exec(t);if(!o)throw new Error(`not a run-event chunk key: ${t}`);const a=Number(o[1]),f=n.get(a);f?f.keys.push(t):n.set(a,{first:a,last:Number(o[2]),keys:[t]})}return[...n.values()].sort((t,o)=>t.first-o.first)}i(H,"listRunEventChunks");async function A(e,s){const n=new Map;for(const t of s.keys){const o=await e.get(t);if(o===null)throw new Error(`run-event chunk missing: ${t}`);const a=(await $(o)).toString("utf8");for(const f of a===""?[]:a.split(`
|
|
2
|
+
`)){const p=JSON.parse(f);n.has(p.sequence_number)||n.set(p.sequence_number,p)}}return[...n.values()].sort((t,o)=>t.sequence_number-o.sequence_number)}i(A,"readRunEventChunk");function I(e){return{bodyCutoff:new Date(e-336*60*6e4).toISOString(),controlCutoff:new Date(e-720*60*6e4).toISOString()}}i(I,"archiveCutoffs");async function B(e,s,n=128){if(!Number.isSafeInteger(n)||n<0)throw new TypeError("limit must be a nonnegative safe integer");if(n===0)return 0;const{bodyCutoff:t,controlCutoff:o}=I(s),a=w.map(()=>"?").join(", "),f=await(await N()).prepare(`SELECT run_id, sequence_number, body_json FROM run_events
|
|
3
|
+
WHERE ts < ? AND (ts < ? OR type IN (${a})) ORDER BY ts LIMIT ?`).all(t,o,...w,n),p=new Map;for(const u of f){const{first:d,last:m}=D(Number(u.sequence_number)),r=`${u.run_id}
|
|
4
|
+
${d}`,c=p.get(r);c?c.rows.push(u):p.set(r,{runId:u.run_id,first:d,last:m,rows:[u]})}for(const{runId:u,first:d,last:m,rows:r}of p.values()){const c=r.map(E=>E.body_json).join(`
|
|
5
|
+
`),y=v("sha256").update(c).digest("hex").slice(0,32);await e.put(R(u,d,m,y),await C(Buffer.from(c,"utf8")))}return await S(async u=>{const d=u.prepare("DELETE FROM run_events WHERE run_id = ? AND sequence_number = ?");let m=0;f.sort((r,c)=>r.run_id<c.run_id?-1:r.run_id>c.run_id?1:Number(r.sequence_number)-Number(c.sequence_number));for(const r of f)m+=Number((await d.run(r.run_id,r.sequence_number)).changes);return m})}i(B,"archiveExpiredRunEvents");export{w as BODY_TYPES,I as archiveCutoffs,B as archiveExpiredRunEvents,H as listRunEventChunks,A as readRunEventChunk};
|
|
@@ -13,9 +13,11 @@ export interface UniqueKey {
|
|
|
13
13
|
}
|
|
14
14
|
/** The columns that identify a row of `info`: its primary key, or every column in order for a table with none (`memory_reads`). */
|
|
15
15
|
export declare const rowKey: (info: TableInfo) => string[];
|
|
16
|
+
/** `types` maps a column to its type name (`udt_name`), so a manifest key (the row key's columns as text) can be cast back and compared through the column's index. */
|
|
16
17
|
export interface TableInfo {
|
|
17
18
|
name: string;
|
|
18
19
|
columns: string[];
|
|
20
|
+
types: Record<string, string>;
|
|
19
21
|
primaryKey: string[];
|
|
20
22
|
identity: string[];
|
|
21
23
|
}
|
|
@@ -26,6 +28,9 @@ export interface Catalog {
|
|
|
26
28
|
uniqueKeys: UniqueKey[];
|
|
27
29
|
}
|
|
28
30
|
export declare const q: (name: string) => string;
|
|
31
|
+
/** True when `alias`'s `columns` equal the manifest key held in `keyColumn` (a jsonb array of the key's columns as text, `m.k`). Each column is compared as itself against the key's
|
|
32
|
+
* element cast to the column's type, so the table's index on the key serves the join; building the key from the table's rows instead would defeat every index. */
|
|
33
|
+
export declare const keyMatch: (info: TableInfo, columns: readonly string[], alias: string, keyColumn: string) => string;
|
|
29
34
|
/** Read the catalog of `schema` for `tables`. */
|
|
30
35
|
export declare function readCatalog(db: CanvasDb, schema: string, tables: readonly string[]): Promise<Catalog>;
|
|
31
36
|
/** Parents before children. Cycles (none in the schema today) are broken by the table list's order. */
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var g=Object.defineProperty;var r=(a
|
|
2
|
-
WHERE table_schema = ? AND table_name = ANY(?::text[]) ORDER BY table_name, ordinal_position`).all(
|
|
1
|
+
var g=Object.defineProperty;var r=(n,a)=>g(n,"name",{value:a,configurable:!0});const _=r(n=>n.primaryKey.length>0?n.primaryKey:n.columns,"rowKey"),u=r(n=>`"${n.replace(/"/g,'""')}"`,"q"),f=r((n,a,l,c)=>a.map((s,o)=>`${l}.${u(s)} = (${c} ->> ${o})::${u(n.types[s])}`).join(" AND "),"keyMatch");async function N(n,a,l){const c=[...l],s=await n.prepareUncached(`SELECT table_name, column_name, is_identity, udt_name FROM information_schema.columns
|
|
2
|
+
WHERE table_schema = ? AND table_name = ANY(?::text[]) ORDER BY table_name, ordinal_position`).all(a,`{${c.map(e=>`"${e}"`).join(",")}}`),o=new Map;for(const e of c)o.set(e,{name:e,columns:[],types:{},primaryKey:[],identity:[]});for(const e of s){const i=o.get(e.table_name);i.columns.push(e.column_name),i.types[e.column_name]=e.udt_name,e.is_identity==="YES"&&i.identity.push(e.column_name)}const d=await n.prepareUncached(`SELECT c.conrelid::regclass::text AS tbl, c.contype, c.conname,
|
|
3
3
|
(SELECT array_agg(a.attname::text ORDER BY k.ord) FROM unnest(c.conkey) WITH ORDINALITY k(attnum, ord) JOIN pg_attribute a ON a.attrelid = c.conrelid AND a.attnum = k.attnum) AS cols,
|
|
4
4
|
c.confrelid::regclass::text AS ptbl,
|
|
5
5
|
(SELECT array_agg(a.attname::text ORDER BY k.ord) FROM unnest(c.confkey) WITH ORDINALITY k(attnum, ord) JOIN pg_attribute a ON a.attrelid = c.confrelid AND a.attnum = k.attnum) AS pcols
|
|
6
|
-
FROM pg_constraint c WHERE c.connamespace = ?::regnamespace AND c.contype IN ('p', 'f')`).all(
|
|
6
|
+
FROM pg_constraint c WHERE c.connamespace = ?::regnamespace AND c.contype IN ('p', 'f')`).all(a),p=r(e=>e.replace(/^.*\./,"").replace(/"/g,""),"bare"),t=[];for(const e of d){const i=p(e.tbl);o.has(i)&&(e.contype==="p"?o.get(i).primaryKey=e.cols:o.has(p(e.ptbl))&&t.push({table:i,columns:e.cols,parent:p(e.ptbl),parentColumns:e.pcols}))}const y=(await n.prepareUncached(`SELECT t.relname AS tbl, i.relname AS name, pg_get_expr(x.indpred, x.indrelid) AS predicate, x.indexprs IS NOT NULL AS has_expr,
|
|
7
7
|
(SELECT array_agg(a.attname::text ORDER BY k.ord) FROM unnest(x.indkey::int2[]) WITH ORDINALITY k(attnum, ord) JOIN pg_attribute a ON a.attrelid = x.indrelid AND a.attnum = k.attnum) AS cols
|
|
8
8
|
FROM pg_index x JOIN pg_class t ON t.oid = x.indrelid JOIN pg_class i ON i.oid = x.indexrelid
|
|
9
|
-
WHERE t.relnamespace = ?::regnamespace AND x.indisunique AND NOT x.indisprimary`).all(
|
|
9
|
+
WHERE t.relnamespace = ?::regnamespace AND x.indisunique AND NOT x.indisprimary`).all(a)).filter(e=>o.has(e.tbl)&&!e.has_expr).map(e=>({table:e.tbl,name:e.name,columns:e.cols,predicate:e.predicate}));return{schema:a,tables:o,foreignKeys:t,uniqueKeys:y}}r(N,"readCatalog");function O(n,a){const l=new Set(a),c=new Map(a.map(t=>[t,new Set]));for(const t of n.foreignKeys)l.has(t.table)&&l.has(t.parent)&&t.table!==t.parent&&c.get(t.table).add(t.parent);const s=[],o=new Set,d=new Set,p=r(t=>{if(!(o.has(t)||d.has(t))){d.add(t);for(const m of[...c.get(t)].sort())p(m);d.delete(t),o.add(t),s.push(t)}},"visit");for(const t of a)p(t);return s}r(O,"topologicalOrder");export{f as keyMatch,u as q,N as readCatalog,_ as rowKey,O as topologicalOrder};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
AND
|
|
3
|
-
AND NOT EXISTS (SELECT 1 FROM _rb o WHERE o.tbl = 'objects' AND o.k =
|
|
4
|
-
heads_key = COALESCE((SELECT string_agg(r.rev_id, ',' ORDER BY r.rev_id) FROM ${
|
|
5
|
-
revision = COALESCE((SELECT max(r.number) FROM ${
|
|
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 =
|
|
1
|
+
var A=Object.defineProperty;var R=(n,d)=>A(n,"name",{value:d,configurable:!0});import{openDb as C,withCanvasWrite as D}from"../../canvas/db.js";import{bundleKeys as h}from"../bundle/layout.js";import{keyMatch as m,q as a,readCatalog as M,rowKey as u,topologicalOrder as y}from"./catalog.js";import{decodeKeys as F}from"./copy.js";import{OBJECT_ID_COLUMNS as W}from"./rewrite.js";import{targetSchema as $}from"./stage.js";class O extends Error{static{R(this,"Refused")}}async function B(n,d){const _=await C(),s=await _.prepare("SELECT source_install_id, source_kind, state, created_at FROM import_runs WHERE run_id = ?").get(n);if(s===void 0)throw new Error(`no import run ${n}`);if(s.state!=="done"&&s.state!=="committed"&&s.state!=="failed")throw new Error(`import run ${n} is ${s.state}, not rollbackable`);const N=(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:{}};try{await D(async t=>{const i=await $(t),L=(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 M(t,i,L);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 S=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 S){const r=F(o);for(let c=0;c<r.length;c+=5e3)await t.prepare("INSERT INTO _rb SELECT ?, e FROM jsonb_array_elements(?::jsonb) e").run(e,JSON.stringify(r.slice(c,c+5e3)))}const b=new Set(S.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 c=b.has(e.table)?`AND NOT EXISTS (SELECT 1 FROM _rb o WHERE o.tbl = '${e.table}' AND ${m(r,u(r),"c","o.k")})`:"",p=Number((await t.prepareUncached(`SELECT count(*) AS n FROM ${a(i)}.${a(e.table)} c WHERE ${e.columns.map(w=>`c.${a(w)} 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")}) ${c}`).get()).n);p>0&&(E.dependents[e.table]=(E.dependents[e.table]??0)+p)}for(const[e,o]of W){const r=l.tables.get(e);if(r===void 0||!r.columns.includes(o)||r.primaryKey.length===0)continue;const c=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') ${c}`).get()).n);p>0&&(E.dependents[`${e}.${o}`]=p)}const T=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(s.source_install_id,n,s.created_at)).n);T>0&&(E.dependents.import_runs=T);const f=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(f>0&&(E.dependents.import_id_map=f),Object.keys(E.dependents).length>0)throw new O;const k=(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 y(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,u(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,u(o),"t","k.k")})`).run();E.deleted[e]=r.changes}for(const e of k)await t.prepareUncached(`UPDATE ${a(i)}.documents d SET
|
|
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
|
+
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(s.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 H(t,s)})}catch(t){if(t instanceof O)return E;throw t}await d.delete(h.manifest(n));for(const t of N)await d.delete(t);return E.rolled_back=!0,E}R(B,"rollbackRun");async function H(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)}R(H,"revokeFor");export{B as rollbackRun};
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
var
|
|
2
|
-
JOIN ${
|
|
3
|
-
|
|
4
|
-
WHERE m.tbl = '
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
WHERE m.tbl = 'revisions' AND encode(sha256(convert_to(b.text, 'UTF8')), 'hex') <> b.hash LIMIT 1`).get()===void 0;const C=await r.prepare(`SELECT 1 AS found FROM (
|
|
1
|
+
var J=Object.defineProperty;var l=(r,d)=>J(r,"name",{value:d,configurable:!0});import{KEY_MAPPED_TABLES as D}from"../bundle/layout.js";import{keyMatch as C,q as o,rowKey as j}from"./catalog.js";import{archiveCutoffs as H,BODY_TYPES as W}from"../../events/run-event-chunks.js";import{decodeKeys as x}from"./copy.js";const a=l((r,d)=>`${o(r)}.${o(d)}`,"sq"),B={messages:["seq"]},q=["claimed_by","lease_expires_at"];async function Z(r,d,t,O,$,h){const _={},m={},{bodyCutoff:g,controlCutoff:M}=H(Date.now()),p=await r.prepare("SELECT table_name, inserted_keys FROM import_manifest WHERE run_id = ?").all(d);await r.exec(`DROP TABLE IF EXISTS ${o(t)}._m; CREATE TABLE ${o(t)}._m (tbl text NOT NULL, k jsonb NOT NULL)`);for(const{table_name:e,inserted_keys:i}of p){const s=$.tables.get(e);if(s===void 0)continue;const E=x(i);if(E.length===0)continue;await r.prepare(`DELETE FROM ${o(t)}._m WHERE tbl = ?`).run(e);for(let n=0;n<E.length;n+=5e3)await r.prepare(`INSERT INTO ${o(t)}._m SELECT ?, e FROM jsonb_array_elements(?::jsonb) e`).run(e,JSON.stringify(E.slice(n,n+5e3)));await r.exec(`ANALYZE ${o(t)}._m`);const R=[...s.identity,...B[e]??[],...q].map(n=>`'${n.replace(/'/g,"''")}'`).join(", ")||"''",T=l(n=>`to_jsonb(${n}) - ARRAY[${R}]::text[]`,"strip"),c=j(s);let S;if(e in D){const n=D[e];S=`JOIN import_key_map km ON km.source_install_id = '${h.replace(/'/g,"''")}' AND km.table_name = '${e}' AND km.target_key = m.k ->> 0
|
|
2
|
+
JOIN ${a(t,e)} s ON s.${o(n)}::text = km.source_key`}else S=`JOIN ${a(t,e)} s ON ${c.map((n,u)=>`s.${o(n)}::text = m.k ->> ${u}`).join(" AND ")}`;const w=e==="revisions"?` AND m.k ->> 0 NOT IN (SELECT rev_id FROM ${a(t,"_arr_revisions")})`:e==="revision_parents"?` AND NOT EXISTS (SELECT 1 FROM ${a(t,"_arr_parents")} a WHERE a.child = m.k ->> 0 AND a.parent = m.k ->> 1)`:"",b=e==="run_events"?`(s.ts < '${M}' OR (s.ts < '${g}' AND s.type IN (${W.map(n=>`'${n}'`).join(", ")})))`:"false",y=`FROM ${a(t,"_m")} m LEFT JOIN ${a(O,e)} t ON ${C(s,c,"t","m.k")} ${S.replace("JOIN","LEFT JOIN")} WHERE m.tbl = '${e}'${w}`,k=`${y} AND ((t.${o(c[0])} IS NULL AND NOT (s.${o(c[0])} IS NOT NULL AND ${b})) OR s.${o(c[0])} IS NULL OR (${T("t")}) <> (${T("s")}))`;if(e==="run_events"){const n=Number((await r.prepareUncached(`SELECT count(*) AS n ${y} AND t.${o(c[0])} IS NULL AND s.${o(c[0])} IS NOT NULL AND ${b}`).get()).n);n>0&&(m[e]=n)}const v=Number((await r.prepareUncached(`SELECT count(*) AS n ${k}`).get()).n);if(v>0){const n=await r.prepareUncached(`SELECT m.k::text AS k ${k} LIMIT 10`).all();_[e]={count:v,keys:n.map(u=>u.k)}}}for(const[e,i]of[["revisions",`FROM ${a(t,"_m")} m JOIN ${a(t,"_arr_revisions")} a ON a.rev_id = m.k ->> 0 LEFT JOIN revisions t ON t.rev_id = a.rev_id
|
|
3
|
+
WHERE m.tbl = 'revisions' AND (t.rev_id IS NULL OR t.document <> a.document OR t.body_hash <> a.body_hash OR t.rationale IS DISTINCT FROM a.rationale OR t.created_at <> a.created_at)`],["revision_parents",`FROM ${a(t,"_m")} m JOIN ${a(t,"_arr_parents")} a ON a.child = m.k ->> 0 AND a.parent = m.k ->> 1 LEFT JOIN revision_parents t ON t.child = a.child AND t.parent = a.parent
|
|
4
|
+
WHERE m.tbl = 'revision_parents' AND t.child IS NULL`]]){const s=Number((await r.prepareUncached(`SELECT count(*) AS n ${i}`).get()).n);s>0&&(_[`${e}.arrived`]={count:s,keys:[]})}const N={},f=`SELECT source AS key FROM ${a(t,"_idmap")} WHERE kind = 'object'`,F=l(e=>e==="messages"?`(${f})`:`(${f} UNION SELECT key FROM ${a(t,"_dropped")} WHERE tbl = 'objects')`,"droppedFor");let L=!1;for(const{table_name:e}of p){const i=$.tables.get(e);if(i===void 0||L||i.primaryKey.length===0)continue;const s=await r.prepareUncached("SELECT column_name FROM information_schema.columns WHERE table_schema = ? AND table_name = ? AND data_type = 'text'").all(O,e);for(const{column_name:E}of s){if(i.primaryKey.includes(E)&&e==="objects")continue;if(await r.prepareUncached(`SELECT 1 AS found FROM ${a(t,"_m")} m JOIN ${a(O,e)} t ON ${C(i,i.primaryKey,"t","m.k")}
|
|
5
|
+
WHERE m.tbl = ? AND t.${o(E)} IN ${F(e)} LIMIT 1`).get(e)!==void 0){L=!0,_[`${e}.${E}`]={count:1,keys:["holds a dropped object id"]};break}}}N.no_dropped_id=!L;const A=p.find(e=>e.table_name==="revisions");let I=!0;A!==void 0&&(I=await r.prepare(`SELECT 1 AS missing FROM ${a(t,"_m")} m JOIN revisions r ON r.rev_id = m.k ->> 0 WHERE m.tbl = 'revisions'
|
|
6
|
+
AND NOT EXISTS (SELECT 1 FROM bodies b WHERE b.hash = r.body_hash) LIMIT 1`).get()===void 0),N.revision_bodies_readable=I,N.revision_bodies_canonical=A===void 0||await r.prepare(`SELECT 1 AS wrong FROM ${a(t,"_m")} m JOIN revisions r ON r.rev_id = m.k ->> 0 JOIN bodies b ON b.hash = r.body_hash
|
|
7
|
+
WHERE m.tbl = 'revisions' AND encode(sha256(convert_to(b.text, 'UTF8')), 'hex') <> b.hash LIMIT 1`).get()===void 0;const U=await r.prepare(`SELECT 1 AS found FROM (
|
|
9
8
|
SELECT month, payer, funding, COALESCE(sub, '') AS sub, grantee, COALESCE(provider, '') AS provider, COALESCE(SUM(usd), 0) AS usd, COALESCE(SUM(billed_usd), 0) AS billed
|
|
10
|
-
FROM charges WHERE refused IS NULL AND kind <> 'take' AND (month, payer) IN (SELECT DISTINCT month, payer FROM ${
|
|
9
|
+
FROM charges WHERE refused IS NULL AND kind <> 'take' AND (month, payer) IN (SELECT DISTINCT month, payer FROM ${a(t,"charges")}) GROUP BY 1, 2, 3, 4, 5, 6) c
|
|
11
10
|
FULL JOIN charge_totals t ON t.month = c.month AND t.payer = c.payer AND t.funding = c.funding AND t.sub = c.sub AND t.grantee = c.grantee AND t.provider = c.provider
|
|
12
|
-
WHERE (COALESCE(t.month, c.month), COALESCE(t.payer, c.payer)) IN (SELECT DISTINCT month, payer FROM ${
|
|
11
|
+
WHERE (COALESCE(t.month, c.month), COALESCE(t.payer, c.payer)) IN (SELECT DISTINCT month, payer FROM ${a(t,"charges")}) AND (c.month IS NULL OR t.month IS NULL OR c.usd <> t.usd OR c.billed <> t.billed_usd) LIMIT 1`).get();return N.charge_totals_equal_recompute=U===void 0,{ok:Object.keys(_).length===0&&Object.values(N).every(Boolean),differences:_,...Object.keys(m).length>0?{archived:m}:{},invariants:N}}l(Z,"verifyRun");export{Z as verifyRun};
|
|
@@ -12,5 +12,8 @@ export declare function resolveAppRung(endpoint: InferenceEndpoint, requested: s
|
|
|
12
12
|
/** Every rung in the order `llm` tries them: the requested rung first, then the declared rungs by distance. */
|
|
13
13
|
export declare function appCandidates(endpoint: InferenceEndpoint, requested: string | undefined, exact?: boolean): AppRung[];
|
|
14
14
|
/** The rung an app-paid grant's node runs on for `requested` (RT-RTE-24), or null when the grant is user-paid or
|
|
15
|
-
* absent. Every path that chooses a node's model (spawn, `node config --model`) resolves through here.
|
|
15
|
+
* absent. Every path that chooses a node's model (spawn, `node config --model`) resolves through here.
|
|
16
|
+
* The recipe's model carries a thinking level only when an exact request named it: the broker sends that level as
|
|
17
|
+
* `reasoning_effort`, a requirement on every rung. A strength request records the bare model, so the daemon applies
|
|
18
|
+
* each rung's own level. */
|
|
16
19
|
export declare function appRungForGrant(grantId: string | null | undefined, requested: string | undefined, exact?: boolean): Promise<AppRung | null>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var h=Object.defineProperty;var s=(e,r)=>h(e,"name",{value:r,configurable:!0});import{defaultModelLaddersConfig as b}from"../../types.js";import{MODEL_STRENGTHS as w,stripThinkingSuffix as u}from"../runtime/model-selection.js";import{modelTokenStrength as O}from"../runtime/launch.js";import{RunError as d}from"../runs/operations.js";import{grantRecord as x}from"../grants/mirror.js";const o=w;function p(e,r){const t=o.indexOf(r);return o.filter(n=>e.rungs[n]!==void 0).sort((n,i)=>Math.abs(o.indexOf(n)-t)-Math.abs(o.indexOf(i)-t)||o.indexOf(n)-o.indexOf(i)).map(n=>({strength:n,model:e.rungs[n]}))}s(p,"rungsByDistance");function l(e,r){const t=p(e,r)[0];if(t===void 0)throw new d(404,"model_unavailable","the app's inference endpoint declares no rung");return t}s(l,"rungAt");function g(e,r,t=!1){if(r===void 0||r==="")return l(e,"strong");const n=O(r)??void 0;if(n!==void 0)return l(e,n);const i=u(r),f=o.find(a=>e.rungs[a]===i);if(f!==void 0)return{strength:f,model:`${e.rungs[f]}${t?r.slice(i.length):""}`};if(t)throw new d(400,"substitution_refused",`model '${r}' is not one of this app's inference rungs`);const c=b(),m=[...Object.entries(c.anthropic),...Object.entries(c.openai)].find(([,a])=>u(a)===i);return l(e,m?.[0]??"strong")}s(g,"resolveAppRung");function $(e,r,t=!1){const n=g(e,r,t);if(t)return[n];const i=p(e,n.strength).filter(f=>f.strength!==n.strength);return[n,...i]}s($,"appCandidates");async function v(e,r,t=!1){const n=e?await x(e):null;if(n?.payer!=="app")return null;if(!n.inference_endpoint)throw new d(404,"model_unavailable",`${n.grantee} is app-paid but its grant carries no inference endpoint`);const i=g(n.inference_endpoint,r,t);return t?i:{...i,model:u(i.model)}}s(v,"appRungForGrant");export{$ as appCandidates,v as appRungForGrant,g as resolveAppRung,l as rungAt};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.621",
|
|
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.621",
|
|
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.621",
|
|
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.621",
|
|
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.621",
|
|
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.621",
|
|
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.621",
|
|
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.621",
|
|
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.621",
|
|
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.621",
|
|
11981
|
+
"@north-light/identity": "0.3.621"
|
|
11982
11982
|
}
|
|
11983
11983
|
},
|
|
11984
11984
|
"packages/crouter-sdk": {
|
|
11985
11985
|
"name": "@north-light/sdk",
|
|
11986
|
-
"version": "0.3.
|
|
11986
|
+
"version": "0.3.621",
|
|
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.621",
|
|
11990
|
+
"@north-light/identity": "0.3.621",
|
|
11991
|
+
"@north-light/plugin": "0.3.621",
|
|
11992
11992
|
"jose": "^6.2.1"
|
|
11993
11993
|
},
|
|
11994
11994
|
"bin": {
|