@north-light/plugin 0.3.524 → 0.3.526

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,35 +1,35 @@
1
- var E=Object.defineProperty;var a=(e,n)=>E(e,"name",{value:n,configurable:!0});import{createHash as N}from"node:crypto";import{validateCommandManifest as J}from"@north-light/api/command-manifest";const K=3,_=">=0.3.0 <1",A=/^[a-z0-9][a-z0-9_-]*$/,C=new Set(["break","case","catch","class","const","continue","debugger","default","delete","do","else","enum","export","extends","false","finally","for","function","if","import","in","instanceof","new","null","return","super","switch","this","throw","true","try","typeof","var","void","while","with","yield","let","static","implements","interface","package","private","protected","public","await","then","constructor","prototype","__proto__"]),q=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function W(e){const{providerId:n,major:t,version:r}=e;if(!A.test(n))throw new Error(`providerId ${JSON.stringify(n)} is not a valid npm package name part`);if(!Number.isInteger(t)||t<1)throw new Error(`major must be a positive integer, got ${t}`);if(!new RegExp(`^${t}\\.\\d+\\.\\d+$`).test(r))throw new Error(`version ${JSON.stringify(r)} is not ${t}.<minor>.<patch>`);const s=[...new Set(e.ownGroups)].sort(),o=new Set(s),i=N("sha256").update(b({commands:e.commands,ownGroups:s})).digest("hex"),c=k(D(e.commands),[],o),p=w(d(n.split(/[-_]+/).filter(f=>f!=="").join("-")));if(p==="scopes")throw new Error('a provider id may not be "scopes"');const u=[...new Set($(c).flatMap(f=>f.group===void 0?[]:[`${n}:${f.group}`]))].sort(),y=`// @northlight-providers/${n} ${r} (provider ${n}, major ${t}, inputDigest ${i})
1
+ var E=Object.defineProperty;var c=(e,n)=>E(e,"name",{value:n,configurable:!0});import{createHash as N}from"node:crypto";import{validateCommandManifest as J}from"@north-light/api/command-manifest";const K=3,_=">=0.3.0 <1",q=/^[a-z0-9][a-z0-9_-]*$/,A=new Set(["break","case","catch","class","const","continue","debugger","default","delete","do","else","enum","export","extends","false","finally","for","function","if","import","in","instanceof","new","null","return","super","switch","this","throw","true","try","typeof","var","void","while","with","yield","let","static","implements","interface","package","private","protected","public","await","then","constructor","prototype","__proto__"]),C=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function W(e){const{providerId:n,major:r,version:t}=e;if(!q.test(n))throw new Error(`providerId ${JSON.stringify(n)} is not a valid npm package name part`);if(!Number.isInteger(r)||r<1)throw new Error(`major must be a positive integer, got ${r}`);if(!new RegExp(`^${r}\\.\\d+\\.\\d+$`).test(t))throw new Error(`version ${JSON.stringify(t)} is not ${r}.<minor>.<patch>`);const o=[...new Set(e.ownGroups)].sort(),s=new Set(o),i=N("sha256").update(b({commands:e.commands,ownGroups:o})).digest("hex"),a=w(D(e.commands),[],s),p=v(m(n.split(/[-_]+/).filter(d=>d!=="").join("-")));if(p==="scopes")throw new Error('a provider id may not be "scopes"');const u=[...new Set($(a).flatMap(d=>d.group===void 0?[]:[`${n}:${d.group}`]))].sort(),k=`// @northlight-providers/${n} ${t} (provider ${n}, major ${r}, inputDigest ${i})
2
2
  // Generated; do not edit.
3
- `,R={name:`@northlight-providers/${n}`,version:r,type:"module",main:"index.js",types:"index.d.ts",exports:{".":{types:"./index.d.ts",import:"./index.js"}},sideEffects:!1,peerDependencies:{"@north-light/sdk":_}};return{files:{"package.json":`${JSON.stringify(R,null,2)}
4
- `,"index.js":G(y,n,t,p,u,c),"index.d.ts":z(y,n,p,u,c)},inputDigest:i}}a(W,"generateClient");function D(e){const n=J(e,{transport:"http",reservedCoreNames:new Set});if(n.manifest===void 0)throw new Error(`the commands manifest is not valid: ${n.issues.map(s=>`${s.path??""} ${s.message} (${s.received})`.trim()).join("; ")}`);const t=n.manifest.roots,r=t[0];return t.length===1&&r?.kind==="branch"?r.children:t}a(D,"treeRoots");function k(e,n,t){const r=[],s=new Set;for(const o of e){const i=w(d(o.name)),c=[...n,o.name];let p;if(o.kind==="branch"){const u=k(o.children,c,t);u.length>0&&(p={kind:"branch",key:i,node:o,children:u})}else!(o.group!==void 0&&t.has(o.group))&&!o.params.some(u=>u.kind==="context-file"&&u.required)&&(p={kind:"leaf",key:i,segments:c,group:o.group,node:o,params:I(o.params)});if(p!==void 0){if(s.has(i))throw new Error(`commands ${c.join(" ")} and a sibling both generate the name ${i}`);s.add(i),r.push(p)}}return r}a(k,"collect");function $(e){return e.flatMap(n=>n.kind==="leaf"?[n]:$(n.children))}a($,"leaves");function I(e){const n=[],t=new Set;for(const r of e){if(r.kind==="context-file")continue;const s=d(r.name);if(t.has(s))throw new Error(`parameters of one command collide on the name ${s}`);t.add(s);const o=r.kind!=="stdin"&&r.repeatable===!0;let i,c=!1;r.kind==="stdin"||r.kind==="positional"?i="string":r.type==="int"?i="number":r.type==="bool"?i="boolean":r.type==="enum"?i=(r.choices??[]).map(u=>JSON.stringify(u)).join(" | ")||"never":r.type==="json"?i=l(r.shape,""):r.type==="path"&&r.encoding==="base64"?(c=!0,i="Uint8Array"):i="string";const p=o&&/[|]/.test(i)?`(${i})`:i;n.push({key:s,type:o?`${p}[]`:i,required:r.required,constraint:r.constraint,base64:c,repeatable:o})}return n}a(I,"paramModels");function d(e){return e.replace(/-([a-z0-9])/g,(n,t)=>t.toUpperCase())}a(d,"camel");function w(e){const n=/^[0-9]/.test(e)?`_${e}`:e;return C.has(n)?`${n}_`:n}a(w,"safeName");function g(e){const n=d(e);return`${n[0].toUpperCase()}${n.slice(1)}`}a(g,"pascal");function v(e){return e.segments.map(g).join("_")}a(v,"typeBase");function j(e){return e.endsWith(" | null")?{base:e.slice(0,-7),nullable:!0}:{base:e,nullable:!1}}a(j,"nullable");function h(e){return q.test(e)?e:JSON.stringify(e)}a(h,"propertyKey");function l(e,n){const{base:t,nullable:r}=j(e.type);let s;switch(t){case"object":s=e.children===void 0?"Record<string, unknown>":e.children.length===0?"Record<string, never>":x(e.children,n);break;case"array":{if(e.items===void 0){s="unknown[]";break}const o=l(e.items,n);s=P(e.items)?`(${o})[]`:`${o}[]`;break}case"map":s=`Record<string, ${e.items===void 0?"unknown":l(e.items,n)}>`;break;case"union":s=(e.variants??[]).map(o=>l(o,n)).join(" | ")||"never";break;case"enum":s=(e.values??[]).map(o=>JSON.stringify(o)).join(" | ")||"never";break;case"int":case"number":s="number";break;case"bool":s="boolean";break;case"string":case"path":case"markdown":case"file":s="string";break;default:s="unknown"}return r?`${s} | null`:s}a(l,"shapeType");function P(e){const{base:n,nullable:t}=j(e.type);return t||n==="union"||n==="enum"}a(P,"needsParens");function x(e,n){if(e.length===0)return"{}";const t=`${n} `;return`{
5
- ${e.map(s=>`${m(s.constraint,t)}${t}${h(s.name)}${s.required?"":"?"}: ${l(s,t)};`).join(`
3
+ `,R={name:`@northlight-providers/${n}`,version:t,type:"module",main:"index.js",types:"index.d.ts",exports:{".":{types:"./index.d.ts",import:"./index.js"}},sideEffects:!1,peerDependencies:{"@north-light/sdk":_}};return{files:{"package.json":`${JSON.stringify(R,null,2)}
4
+ `,"index.js":G(k,n,r,p,u,a),"index.d.ts":z(k,n,p,u,a)},inputDigest:i}}c(W,"generateClient");function D(e){const n=J(e,{transport:"http",reservedCoreNames:new Set});if(n.manifest===void 0)throw new Error(`the commands manifest is not valid: ${n.issues.map(o=>`${o.path??""} ${o.message} (${o.received})`.trim()).join("; ")}`);const r=n.manifest.roots,t=r[0];return r.length===1&&t?.kind==="branch"?t.children:r}c(D,"treeRoots");function w(e,n,r){const t=[],o=new Set;for(const s of e){const i=v(m(s.name)),a=[...n,s.name];let p;if(s.kind==="branch"){const u=w(s.children,a,r);u.length>0&&(p={kind:"branch",key:i,node:s,children:u})}else!(s.group!==void 0&&r.has(s.group))&&!s.params.some(u=>u.kind==="context-file"&&u.required)&&(p={kind:"leaf",key:i,segments:a,group:s.group,node:s,params:I(s.params)});if(p!==void 0){if(o.has(i))throw new Error(`commands ${a.join(" ")} and a sibling both generate the name ${i}`);o.add(i),t.push(p)}}return t}c(w,"collect");function $(e){return e.flatMap(n=>n.kind==="leaf"?[n]:$(n.children))}c($,"leaves");function I(e){const n=[],r=new Set;for(const t of e){if(t.kind==="context-file")continue;const o=m(t.name);if(r.has(o))throw new Error(`parameters of one command collide on the name ${o}`);r.add(o);const s=t.kind!=="stdin"&&t.repeatable===!0;let i,a=!1;t.kind==="stdin"||t.kind==="positional"?i="string":t.type==="int"?i="number":t.type==="bool"?i="boolean":t.type==="enum"?i=(t.choices??[]).map(u=>JSON.stringify(u)).join(" | ")||"never":t.type==="json"?i=l(t.shape,""):t.type==="path"&&t.encoding==="base64"?(a=!0,i="Uint8Array"):i="string";const p=s&&/[|]/.test(i)?`(${i})`:i;n.push({key:o,type:s?`${p}[]`:i,required:t.required,constraint:t.constraint,base64:a,repeatable:s})}return n}c(I,"paramModels");function m(e){return e.replace(/-([a-z0-9])/g,(n,r)=>r.toUpperCase())}c(m,"camel");function v(e){const n=/^[0-9]/.test(e)?`_${e}`:e;return A.has(n)?`${n}_`:n}c(v,"safeName");function g(e){const n=m(e);return`${n[0].toUpperCase()}${n.slice(1)}`}c(g,"pascal");function j(e){return e.segments.map(g).join("_")}c(j,"typeBase");function h(e){return e.endsWith(" | null")?{base:e.slice(0,-7),nullable:!0}:{base:e,nullable:!1}}c(h,"nullable");function y(e){return C.test(e)?e:JSON.stringify(e)}c(y,"propertyKey");function l(e,n){const{base:r,nullable:t}=h(e.type);let o;switch(r){case"object":o=e.children===void 0?"Record<string, unknown>":e.children.length===0&&e.extra===void 0?"Record<string, never>":x(e.children,n,e.extra);break;case"array":{if(e.items===void 0){o="unknown[]";break}const s=l(e.items,n);o=P(e.items)?`(${s})[]`:`${s}[]`;break}case"map":o=`Record<string, ${e.items===void 0?"unknown":l(e.items,n)}>`;break;case"union":o=(e.variants??[]).map(s=>l(s,n)).join(" | ")||"never";break;case"enum":o=(e.values??[]).map(s=>JSON.stringify(s)).join(" | ")||"never";break;case"int":case"number":o="number";break;case"bool":o="boolean";break;case"string":case"path":case"markdown":case"file":o="string";break;default:o="unknown"}return t?`${o} | null`:o}c(l,"shapeType");function P(e){const{base:n,nullable:r}=h(e.type);return r||n==="union"||n==="enum"}c(P,"needsParens");function x(e,n,r){if(e.length===0&&r===void 0)return"{}";const t=`${n} `,o=e.map(s=>`${f(s.constraint,t)}${t}${y(s.name)}${s.required?"":"?"}: ${l(s,t)};`);if(r!==void 0){const s=[l(r,t),...e.map(a=>l(a,t)),...e.some(a=>!a.required)?["undefined"]:[]],i=h(r.type).base==="unknown"?"unknown":[...new Set(s)].join(" | ");o.push(`${f(r.constraint,t)}${t}[key: string]: ${i};`)}return`{
5
+ ${o.join(`
6
6
  `)}
7
- ${n}}`}a(x,"objectType");function m(e,n,t=[]){const r=[e,...t].flatMap(s=>s.split(`
8
- `)).map(s=>s.replace(/\*\//g,"*\\/").trimEnd());for(;r.length>0&&r[r.length-1]==="";)r.pop();return r.length===0?"":`${n}/**
9
- ${r.map(s=>`${n} *${s===""?"":` ${s}`}`).join(`
7
+ ${n}}`}c(x,"objectType");function f(e,n,r=[]){const t=[e,...r].flatMap(o=>o.split(`
8
+ `)).map(o=>o.replace(/\*\//g,"*\\/").trimEnd());for(;t.length>0&&t[t.length-1]==="";)t.pop();return t.length===0?"":`${n}/**
9
+ ${t.map(o=>`${n} *${o===""?"":` ${o}`}`).join(`
10
10
  `)}
11
11
  ${n} */
12
- `}a(m,"doc");function T(e,n){const{node:t}=e;return[t.description,"",`When to use: ${t.whenToUse}`,"",`Effects: ${t.effects.join(" ")}`,...e.group!==void 0?["",`Scope: ${n}:${e.group}`]:[]]}a(T,"leafDoc");function z(e,n,t,r,s){const o=[e,`import type { RequestOptions } from '@north-light/sdk';
12
+ `}c(f,"doc");function T(e,n){const{node:r}=e;return[r.description,"",`When to use: ${r.whenToUse}`,"",`Effects: ${r.effects.join(" ")}`,...e.group!==void 0?["",`Scope: ${n}:${e.group}`]:[]]}c(T,"leafDoc");function z(e,n,r,t,o){const s=[e,`import type { RequestOptions } from '@north-light/sdk';
13
13
  `,"export interface ProviderRuntime {"," providers: {"," call(input: { provider: string; tool: string; arguments: Record<string, unknown>; version?: number; approval?: string; machine?: string }, options?: RequestOptions): Promise<unknown>;"," };",`}
14
14
  `,`export type CallOptions = RequestOptions & { approval?: string; machine?: string };
15
- `,`export declare const scopes: readonly [${r.map(i=>JSON.stringify(i)).join(", ")}];
16
- `];for(const i of $(s)){const c=v(i);if(i.params.length>0){const p=i.params.map(u=>`${m(u.constraint," ")} ${u.key}${u.required?"":"?"}: ${u.type};`);o.push(`export interface ${c}Args {
15
+ `,`export declare const scopes: readonly [${t.map(i=>JSON.stringify(i)).join(", ")}];
16
+ `];for(const i of $(o)){const a=j(i);if(i.params.length>0){const p=i.params.map(u=>`${f(u.constraint," ")} ${u.key}${u.required?"":"?"}: ${u.type};`);s.push(`export interface ${a}Args {
17
17
  ${p.join(`
18
18
  `)}
19
19
  }
20
- `)}o.push(`export interface ${c}Result ${x(i.node.output,"")}
21
- `)}return o.push(`export interface ${g(t)}Client ${O(s,"",n)}
22
- `),o.push(`export declare function ${t}(runtime: ProviderRuntime): ${g(t)}Client;
23
- `),o.push(`export default ${t};
24
- `),o.join(`
25
- `)}a(z,"renderDts");function O(e,n,t){const r=`${n} `;return`{
26
- ${e.map(o=>{if(o.kind==="branch")return`${m(o.node.description,r)}${r}${h(o.key)}: ${O(o.children,r,t)};`;const i=v(o),c=o.params.length>0?`args: ${i}Args`:"args?: Record<string, never>",[p,...u]=T(o,t);return`${m(p,r,u)}${r}${h(o.key)}(${c}, options?: CallOptions): Promise<${i}Result>;`}).join(`
20
+ `)}s.push(`export interface ${a}Result ${x(i.node.output,"")}
21
+ `)}return s.push(`export interface ${g(r)}Client ${O(o,"",n)}
22
+ `),s.push(`export declare function ${r}(runtime: ProviderRuntime): ${g(r)}Client;
23
+ `),s.push(`export default ${r};
24
+ `),s.join(`
25
+ `)}c(z,"renderDts");function O(e,n,r){const t=`${n} `;return`{
26
+ ${e.map(s=>{if(s.kind==="branch")return`${f(s.node.description,t)}${t}${y(s.key)}: ${O(s.children,t,r)};`;const i=j(s),a=s.params.length>0?`args: ${i}Args`:"args?: Record<string, never>",[p,...u]=T(s,r);return`${f(p,t,u)}${t}${y(s.key)}(${a}, options?: CallOptions): Promise<${i}Result>;`}).join(`
27
27
  `)}
28
- ${n}}`}a(O,"clientType");function G(e,n,t,r,s,o){return`${e}
28
+ ${n}}`}c(O,"clientType");function G(e,n,r,t,o,s){return`${e}
29
29
  const $provider = ${JSON.stringify(n)};
30
- const $major = ${t};
30
+ const $major = ${r};
31
31
 
32
- export const scopes = ${JSON.stringify(s)};
32
+ export const scopes = ${JSON.stringify(o)};
33
33
 
34
34
  function $base64(bytes) {
35
35
  let text = '';
@@ -59,12 +59,12 @@ function $call(runtime, tool, args, spec, options) {
59
59
  }, requestOptions);
60
60
  }
61
61
 
62
- export function ${r}(runtime) {
63
- return ${S(o," ")};
62
+ export function ${t}(runtime) {
63
+ return ${S(s," ")};
64
64
  }
65
65
 
66
- export default ${r};
67
- `}a(G,"renderJs");function S(e,n){const t=`${n} `;return`{
68
- ${e.map(s=>{const o=JSON.stringify(s.key);if(s.kind==="branch")return`${t}${o}: ${S(s.children,t)},`;const i=JSON.stringify(s.params.map(c=>[c.key,c.base64?1:0]));return`${t}${o}: (args, options) => $call(runtime, ${JSON.stringify(s.segments.join(" "))}, args, ${i}, options),`}).join(`
66
+ export default ${t};
67
+ `}c(G,"renderJs");function S(e,n){const r=`${n} `;return`{
68
+ ${e.map(o=>{const s=JSON.stringify(o.key);if(o.kind==="branch")return`${r}${s}: ${S(o.children,r)},`;const i=JSON.stringify(o.params.map(a=>[a.key,a.base64?1:0]));return`${r}${s}: (args, options) => $call(runtime, ${JSON.stringify(o.segments.join(" "))}, args, ${i}, options),`}).join(`
69
69
  `)}
70
- ${n}}`}a(S,"clientJs");function b(e){return Array.isArray(e)?`[${e.map(n=>b(n===void 0?null:n)).join(",")}]`:e!==null&&typeof e=="object"?`{${Object.entries(e).filter(([,t])=>t!==void 0).sort(([t],[r])=>t<r?-1:t>r?1:0).map(([t,r])=>`${JSON.stringify(t)}:${b(r)}`).join(",")}}`:JSON.stringify(e)}a(b,"canonicalJson");export{K as GENERATOR_REVISION,W as generateClient};
70
+ ${n}}`}c(S,"clientJs");function b(e){return Array.isArray(e)?`[${e.map(n=>b(n===void 0?null:n)).join(",")}]`:e!==null&&typeof e=="object"?`{${Object.entries(e).filter(([,r])=>r!==void 0).sort(([r],[t])=>r<t?-1:r>t?1:0).map(([r,t])=>`${JSON.stringify(r)}:${b(t)}`).join(",")}}`:JSON.stringify(e)}c(b,"canonicalJson");export{K as GENERATOR_REVISION,W as generateClient};
package/dist/compare.js CHANGED
@@ -1 +1 @@
1
- var x=Object.defineProperty;var p=(e,o)=>x(e,"name",{value:o,configurable:!0});function z(e,o){const r=k(e),t=k(o),a=[];for(const[s,u]of r){const i=t.get(s);if(!i){a.push({leaf:s,rule:"tool removed or renamed; bump the major"});continue}u.group!==i.group&&a.push({leaf:s,rule:"tool group changed; bump the major"}),B(u,i,s,a),F(u,i,s,a),L(u,i,s,a),P(u.output,i.output,s,a)}return a}p(z,"compareManifests");function B(e,o,r,t){const a=new Map(o.params.map(n=>[n.name,n]));for(const n of e.params){const f=a.get(n.name);if(!f){t.push({leaf:r,rule:`parameter ${n.name} removed; bump the major`});continue}if(S(n)!==S(f)){t.push({leaf:r,rule:`parameter ${n.name} type changed; bump the major`});continue}if(n.kind==="flag"&&f.kind==="flag"&&n.type==="json"&&f.type==="json"&&n.shape&&f.shape)for(const c of N(n.shape,f.shape,"input",`--${n.name}`))t.push({leaf:r,rule:`${c}; bump the major`});if(!n.required&&f.required&&t.push({leaf:r,rule:`parameter ${n.name} became required; bump the major`}),n.kind==="flag"&&f.kind==="flag"){for(const w of n.choices??[])f.choices?.includes(w)||t.push({leaf:r,rule:`parameter ${n.name} enum value ${w} removed; bump the major`});const c=$(n),m=$(f);c!==void 0&&m!==void 0&&m!==c&&t.push({leaf:r,rule:`parameter ${n.name} default changed (${c} -> ${m}), so a caller that omits it gets a different page; bump the major`})}(n.kind==="flag"||n.kind==="positional")&&(f.kind==="flag"||f.kind==="positional")&&n.defaultFromEnv!==f.defaultFromEnv&&t.push({leaf:r,rule:`parameter ${n.name} environment default changed (${n.defaultFromEnv??"none"} -> ${f.defaultFromEnv??"none"}); bump the major`})}const s=new Set(e.params.map(n=>n.name));for(const n of o.params)!s.has(n.name)&&n.required&&t.push({leaf:r,rule:`required parameter ${n.name} added; bump the major`});const u=e.params.filter(n=>n.kind==="positional").map(n=>n.name),i=o.params.filter(n=>n.kind==="positional").map(n=>n.name),d=u.findIndex((n,f)=>a.has(n)&&i[f]!==n);d>=0&&t.push({leaf:r,rule:`positional parameter ${u[d]} moved from position ${d+1}; bump the major`})}p(B,"compareParams");const h=p(e=>e.toLowerCase().replace(/[^a-z0-9]/g,""),"normalize"),A=new Set(["limit","pagesize","perpage","maxresults","take"]),E=new Set(["cursor","page","pagetoken","offset"]),M=new Set(["nextcursor","nextpage","nextpagetoken","hasmore","truncated"]);function $(e){if(e.type!=="int"||!A.has(h(e.name)))return;const o=/\bdefaults?(?: of| to| is)?\s+(\d+)/i.exec(e.constraint);return o?Number(o[1]):void 0}p($,"statedLimit");function F(e,o,r,t){const a=p(m=>m.kind==="flag"&&$(m)!==void 0,"limited"),s=p(m=>m.kind==="flag"&&E.has(h(m.name)),"cursored");if(e.params.some(a)||e.params.some(s)&&e.output.some(m=>M.has(h(m.name))))return;const u=new Set(e.params.map(m=>m.name)),i=new Set(e.output.map(m=>m.name)),d=o.params.filter(m=>!u.has(m.name)&&a(m)).map(m=>`--${m.name} defaulting to ${$(m)}`),n=o.params.filter(m=>!u.has(m.name)&&s(m)).map(m=>`--${m.name}`),f=o.output.filter(m=>!i.has(m.name)&&M.has(h(m.name))).map(m=>`output ${m.name}`),c=n.length>0&&f.length>0;(d.length||c)&&t.push({leaf:r,rule:`gained paging (${[...d,...c?[...n,...f]:[]].join(", ")}) where it returned everything, so callers that do not page now get a partial answer; bump the major`})}p(F,"comparePaging");function L(e,o,r,t){const a=[],s=p(u=>u.replace(/\/v\d+(?=\/|$)/g,"/v*"),"route");e.rest.method!==o.rest.method&&a.push("method"),s(e.rest.path)!==s(o.rest.path)&&a.push("path"),!!e.rest.streaming!=!!o.rest.streaming&&a.push("streaming"),e.rest.bodyRoot!==o.rest.bodyRoot&&a.push("body root"),JSON.stringify(q(e.rest.body))!==JSON.stringify(q(o.rest.body))&&a.push("constant body fields");for(const[u,i]of Object.entries(e.rest.params)){const d=o.rest.params[u];d&&(i.in!==d.in||(i.as??u)!==(d.as??u))&&a.push(`parameter ${u} placement`)}a.length&&t.push({leaf:r,rule:`request mapping changed (${a.join(", ")}); bump the major`})}p(L,"compareRequest");function q(e){return Object.entries(e??{}).sort(([o],[r])=>o<r?-1:1)}p(q,"sorted");function k(e){const o=new Map;function r(t,a){const s=[...a,t.name];if(t.kind==="leaf")o.set(s.join(" "),t);else for(const u of t.children)r(u,s)}p(r,"visit");for(const t of e.mounts)r(t.node,t.parent);return o}p(k,"leaves");function S(e){return e.kind==="flag"?`${e.kind}:${e.type}:${!!e.repeatable}:${e.type==="path"?e.encoding:""}`:e.kind==="positional"?`${e.kind}:${e.type??"string"}:${!!e.repeatable}:${e.type==="path"?e.encoding:""}`:e.kind}p(S,"parameterType");function P(e,o,r,t){const a=new Map(o.map(u=>[u.name,u])),s=new Set(e.map(u=>u.name));for(const u of o)!s.has(u.name)&&b(u.type)==="file"&&t.push({leaf:r,rule:`file output field ${u.name} added; bump the major`});for(const u of e){const i=a.get(u.name);if(!i){t.push({leaf:r,rule:`output field ${u.name} removed; bump the major`});continue}u.required&&!i.required&&t.push({leaf:r,rule:`output field ${u.name} became optional; bump the major`});for(const d of N(u,i,"output",u.name))t.push({leaf:r,rule:`${d}; bump the major`})}}p(P,"compareFields");function b(e){return e.endsWith(" | null")?e.slice(0,-7):e}p(b,"baseType");function N(e,o,r,t){return r==="input"?g(e,o,r,t):g(o,e,r,t)}p(N,"compatible");function g(e,o,r,t){const a=r==="input";if(v(e)&&!v(o))return[`${r==="input"?"parameter":"output field"} ${t} ${a?"| null removed":"| null added"}`];if(l(e)!=="union"&&l(o)!=="union")return l(e)==="null"?[]:O(y(e),y(o),r,t);const s=j(o);return j(e).some(i=>!s.some(d=>O(i,d,r,t).length===0))?[`${r==="input"?"parameter":"output field"} ${t} ${a?"union variant removed":"union variant added"}`]:[]}p(g,"fits");function v(e){return R(e.type)||l(e)==="null"||l(e)==="union"&&(e.variants??[]).some(v)}p(v,"nullableDeep");function y(e){return R(e.type)?{...e,type:b(e.type)}:e}p(y,"withoutNull");function j(e){const o=l(e);if(o==="null")return[];if(o==="union")return(e.variants??[]).flatMap(j);const r=y(e);return o==="enum"&&e.values!==void 0?e.values.map(t=>({...r,values:[t]})):[r]}p(j,"atoms");function O(e,o,r,t){const a=r==="input"?"parameter":"output field",s=p((n,f)=>[`${a} ${n} ${f}`],"fail"),u=r==="input",i=l(e),d=l(o);return d==="unknown"?[]:i==="unknown"||i!==d&&!(i==="int"&&d==="number")?s(t,"type changed"):i==="enum"?o.values===void 0?[]:e.values===void 0||e.values.some(n=>!o.values.includes(n))?s(t,u?"enum value removed":"enum value added"):[]:i==="array"||i==="map"?o.items===void 0?[]:e.items===void 0?s(t,u?"items added":"type changed"):g(e.items,o.items,r,`${t}${i==="array"?"[]":"[*]"}`):i==="object"?T(e,o,r,t):[]}p(O,"fitsAtom");function T(e,o,r,t){const a=r==="input"?"parameter":"output field",s=r==="input";if(o.children===void 0)return[];if(e.children===void 0)return[`${a} ${t} ${s?"object closed":"object opened"}`];const u=[],i=new Map(e.children.map(n=>[n.name,n])),d=new Map(o.children.map(n=>[n.name,n]));for(const[n,f]of i){const c=d.get(n);if(c===void 0){s&&u.push(`${a} ${t}.${n} removed`);continue}!f.required&&c.required&&u.push(`${a} ${t}.${n} ${s?"became required":"became optional"}`),u.push(...g(f,c,r,`${t}.${n}`))}for(const[n,f]of d)i.has(n)||(s?f.required&&u.push(`${a} ${t}.${n} required member added`):u.push(`${a} ${t}.${n} removed`));return u}p(T,"fitMembers");function R(e){return e.endsWith(" | null")}p(R,"isNullable");function l(e){return b(e.type).toLowerCase()}p(l,"shapeBase");export{z as compareManifests,N as compatible};
1
+ var R=Object.defineProperty;var p=(e,o)=>R(e,"name",{value:o,configurable:!0});function _(e,o){const u=q(e),n=q(o),a=[];for(const[i,r]of u){const f=n.get(i);if(!f){a.push({leaf:i,rule:"tool removed or renamed; bump the major"});continue}r.group!==f.group&&a.push({leaf:i,rule:"tool group changed; bump the major"}),A(r,f,i,a),F(r,f,i,a),P(r,f,i,a),T(r.output,f.output,i,a)}return a}p(_,"compareManifests");function A(e,o,u,n){const a=new Map(o.params.map(t=>[t.name,t]));for(const t of e.params){const m=a.get(t.name);if(!m){n.push({leaf:u,rule:`parameter ${t.name} removed; bump the major`});continue}if(S(t)!==S(m)){n.push({leaf:u,rule:`parameter ${t.name} type changed; bump the major`});continue}if(t.kind==="flag"&&m.kind==="flag"&&t.type==="json"&&m.type==="json"&&t.shape&&m.shape)for(const d of x(t.shape,m.shape,"input",`--${t.name}`))n.push({leaf:u,rule:`${d}; bump the major`});if(!t.required&&m.required&&n.push({leaf:u,rule:`parameter ${t.name} became required; bump the major`}),t.kind==="flag"&&m.kind==="flag"){for(const $ of t.choices??[])m.choices?.includes($)||n.push({leaf:u,rule:`parameter ${t.name} enum value ${$} removed; bump the major`});const d=b(t),s=b(m);d!==void 0&&s!==void 0&&s!==d&&n.push({leaf:u,rule:`parameter ${t.name} default changed (${d} -> ${s}), so a caller that omits it gets a different page; bump the major`})}(t.kind==="flag"||t.kind==="positional")&&(m.kind==="flag"||m.kind==="positional")&&t.defaultFromEnv!==m.defaultFromEnv&&n.push({leaf:u,rule:`parameter ${t.name} environment default changed (${t.defaultFromEnv??"none"} -> ${m.defaultFromEnv??"none"}); bump the major`})}const i=new Set(e.params.map(t=>t.name));for(const t of o.params)!i.has(t.name)&&t.required&&n.push({leaf:u,rule:`required parameter ${t.name} added; bump the major`});const r=e.params.filter(t=>t.kind==="positional").map(t=>t.name),f=o.params.filter(t=>t.kind==="positional").map(t=>t.name),c=r.findIndex((t,m)=>a.has(t)&&f[m]!==t);c>=0&&n.push({leaf:u,rule:`positional parameter ${r[c]} moved from position ${c+1}; bump the major`})}p(A,"compareParams");const g=p(e=>e.toLowerCase().replace(/[^a-z0-9]/g,""),"normalize"),B=new Set(["limit","pagesize","perpage","maxresults","take"]),L=new Set(["cursor","page","pagetoken","offset"]),M=new Set(["nextcursor","nextpage","nextpagetoken","hasmore","truncated"]);function b(e){if(e.type!=="int"||!B.has(g(e.name)))return;const o=/\bdefaults?(?: of| to| is)?\s+(\d+)/i.exec(e.constraint);return o?Number(o[1]):void 0}p(b,"statedLimit");function F(e,o,u,n){const a=p(s=>s.kind==="flag"&&b(s)!==void 0,"limited"),i=p(s=>s.kind==="flag"&&L.has(g(s.name)),"cursored");if(e.params.some(a)||e.params.some(i)&&e.output.some(s=>M.has(g(s.name))))return;const r=new Set(e.params.map(s=>s.name)),f=new Set(e.output.map(s=>s.name)),c=o.params.filter(s=>!r.has(s.name)&&a(s)).map(s=>`--${s.name} defaulting to ${b(s)}`),t=o.params.filter(s=>!r.has(s.name)&&i(s)).map(s=>`--${s.name}`),m=o.output.filter(s=>!f.has(s.name)&&M.has(g(s.name))).map(s=>`output ${s.name}`),d=t.length>0&&m.length>0;(c.length||d)&&n.push({leaf:u,rule:`gained paging (${[...c,...d?[...t,...m]:[]].join(", ")}) where it returned everything, so callers that do not page now get a partial answer; bump the major`})}p(F,"comparePaging");function P(e,o,u,n){const a=[],i=p(r=>r.replace(/\/v\d+(?=\/|$)/g,"/v*"),"route");e.rest.method!==o.rest.method&&a.push("method"),i(e.rest.path)!==i(o.rest.path)&&a.push("path"),!!e.rest.streaming!=!!o.rest.streaming&&a.push("streaming"),e.rest.bodyRoot!==o.rest.bodyRoot&&a.push("body root"),JSON.stringify(k(e.rest.body))!==JSON.stringify(k(o.rest.body))&&a.push("constant body fields");for(const[r,f]of Object.entries(e.rest.params)){const c=o.rest.params[r];c&&(f.in!==c.in||(f.as??r)!==(c.as??r))&&a.push(`parameter ${r} placement`)}a.length&&n.push({leaf:u,rule:`request mapping changed (${a.join(", ")}); bump the major`})}p(P,"compareRequest");function k(e){return Object.entries(e??{}).sort(([o],[u])=>o<u?-1:1)}p(k,"sorted");function q(e){const o=new Map;function u(n,a){const i=[...a,n.name];if(n.kind==="leaf")o.set(i.join(" "),n);else for(const r of n.children)u(r,i)}p(u,"visit");for(const n of e.mounts)u(n.node,n.parent);return o}p(q,"leaves");function S(e){return e.kind==="flag"?`${e.kind}:${e.type}:${!!e.repeatable}:${e.type==="path"?e.encoding:""}`:e.kind==="positional"?`${e.kind}:${e.type??"string"}:${!!e.repeatable}:${e.type==="path"?e.encoding:""}`:e.kind}p(S,"parameterType");function T(e,o,u,n){const a=new Map(o.map(r=>[r.name,r])),i=new Set(e.map(r=>r.name));for(const r of o)!i.has(r.name)&&v(r.type)==="file"&&n.push({leaf:u,rule:`file output field ${r.name} added; bump the major`});for(const r of e){const f=a.get(r.name);if(!f){n.push({leaf:u,rule:`output field ${r.name} removed; bump the major`});continue}r.required&&!f.required&&n.push({leaf:u,rule:`output field ${r.name} became optional; bump the major`});for(const c of x(r,f,"output",r.name))n.push({leaf:u,rule:`${c}; bump the major`})}}p(T,"compareFields");function v(e){return e.endsWith(" | null")?e.slice(0,-7):e}p(v,"baseType");function x(e,o,u,n){return u==="input"?h(e,o,u,n):h(o,e,u,n)}p(x,"compatible");function h(e,o,u,n){const a=u==="input";if(y(e)&&!y(o))return[`${u==="input"?"parameter":"output field"} ${n} ${a?"| null removed":"| null added"}`];if(l(e)!=="union"&&l(o)!=="union")return l(e)==="null"?[]:N(j(e),j(o),u,n);const i=w(o);return w(e).some(f=>!i.some(c=>N(f,c,u,n).length===0))?[`${u==="input"?"parameter":"output field"} ${n} ${a?"union variant removed":"union variant added"}`]:[]}p(h,"fits");function y(e){return O(e.type)||l(e)==="null"||l(e)==="union"&&(e.variants??[]).some(y)}p(y,"nullableDeep");function j(e){return O(e.type)?{...e,type:v(e.type)}:e}p(j,"withoutNull");function w(e){const o=l(e);if(o==="null")return[];if(o==="union")return(e.variants??[]).flatMap(w);const u=j(e);return o==="enum"&&e.values!==void 0?e.values.map(n=>({...u,values:[n]})):[u]}p(w,"atoms");function N(e,o,u,n){const a=u==="input"?"parameter":"output field",i=p((t,m)=>[`${a} ${t} ${m}`],"fail"),r=u==="input",f=l(e),c=l(o);return c==="unknown"?[]:f==="unknown"||f!==c&&!(f==="int"&&c==="number")?i(n,"type changed"):f==="enum"?o.values===void 0?[]:e.values===void 0||e.values.some(t=>!o.values.includes(t))?i(n,r?"enum value removed":"enum value added"):[]:f==="array"||f==="map"?o.items===void 0?[]:e.items===void 0?i(n,r?"items added":"type changed"):h(e.items,o.items,u,`${n}${f==="array"?"[]":"[*]"}`):f==="object"?C(e,o,u,n):[]}p(N,"fitsAtom");const E={type:"unknown",constraint:""};function C(e,o,u,n){const a=u==="input"?"parameter":"output field",i=u==="input",r=new Map((e.children??[]).map(d=>[d.name,d])),f=new Map((o.children??[]).map(d=>[d.name,d])),c=e.children===void 0?E:e.extra,t=o.children===void 0?E:o.extra,m=[];for(const[d,s]of r){const $=f.get(d);if($===void 0){t!==void 0?m.push(...h(s,t,u,`${n}.${d}`)):i&&m.push(`${a} ${n}.${d} removed`);continue}!s.required&&$.required&&m.push(`${a} ${n}.${d} ${i?"became required":"became optional"}`),m.push(...h(s,$,u,`${n}.${d}`))}for(const[d,s]of f)r.has(d)||(i?s.required?m.push(`${a} ${n}.${d} required member added`):c!==void 0&&m.push(...h(c,s,u,`${n}.${d}`)):m.push(`${a} ${n}.${d} removed`));return c!==void 0&&(t===void 0?m.push(`${a} ${n} ${i?"object closed":"object opened"}`):m.push(...h(c,t,u,`${n}.*`))),m}p(C,"fitMembers");function O(e){return e.endsWith(" | null")}p(O,"isNullable");function l(e){return v(e.type).toLowerCase()}p(l,"shapeBase");export{_ as compareManifests,x as compatible};
package/dist/define.js CHANGED
@@ -1 +1 @@
1
- var T=Object.defineProperty;var s=(e,t)=>T(e,"name",{value:t,configurable:!0});import{LOCAL as U,mentionsFile as L,objectBlocksShapeReasons as K,objectKindReadReasons as R,outputBaseType as g}from"@north-light/api/command-manifest";class f extends Error{static{s(this,"PluginDefinitionError")}constructor(t){super(t),this.name="PluginDefinitionError"}}function Q(e){return{kind:"leaf",description:e.description,whenToUse:e.whenToUse,summary:e.summary,...e.tier!==void 0?{tier:e.tier}:{},...e.group!==void 0?{group:e.group}:{},...e.sideEffect!==void 0?{sideEffect:e.sideEffect}:{},params:e.params??{},output:e.output,effects:e.effects,streaming:!1,run:s((t,n)=>Promise.resolve(e.handler(t,n)),"run")}}s(Q,"defineLeaf");function X(e){return{kind:"leaf",description:e.description,whenToUse:e.whenToUse,summary:e.summary,...e.tier!==void 0?{tier:e.tier}:{},...e.group!==void 0?{group:e.group}:{},...e.sideEffect!==void 0?{sideEffect:e.sideEffect}:{},params:e.params??{},output:e.output,effects:e.effects,streaming:!0,run:s((t,n)=>Promise.resolve(e.handler(t,n)),"run")}}s(X,"defineStreamingLeaf");function ee(e){return{kind:"branch",...e}}s(ee,"defineBranch");function te(e){if(B(e.name,"plugin name"),d(e.description,"plugin description"),d(e.whenToUse,"plugin whenToUse"),d(e.summary,"plugin summary"),d(e.rootEntry?.concept,"plugin rootEntry.concept"),d(e.rootEntry?.description,"plugin rootEntry.description"),d(e.rootEntry?.whenToUse,"plugin rootEntry.whenToUse"),Z(e.timeouts),e.version!==void 0&&(typeof e.version!="number"||!Number.isInteger(e.version)||e.version<1))throw new f("plugin version must be an integer of at least 1");if(e.provider!==void 0&&typeof e.provider!="boolean")throw new f("plugin provider must be a boolean");if(e.provider===!0&&e.version===void 0)throw new f("a provider plugin must declare its major version");for(const[t,n]of Object.entries(e.commands))v(n,[e.name,t]);if(e.provider===!0){const t=_(e.commands,[e.name]);t!==void 0&&r(t,"needs a group because the plugin is a provider")}if(e.groups!==void 0){if(e.provider!==!0)throw new f("groups can only be declared by a provider plugin; set provider: true");S(e.groups,e.commands,e.name)}for(const t of e.memory??[])J(t);return e.objectKinds!==void 0&&F(e.objectKinds,e.name,e.commands),Object.freeze({name:e.name,description:e.description,whenToUse:e.whenToUse,summary:e.summary,rootEntry:Object.freeze({...e.rootEntry}),commands:p(e.commands),memory:Object.freeze((e.memory??[]).map(W)),...e.timeouts!==void 0?{timeouts:Object.freeze({...e.timeouts})}:{},...e.version!==void 0?{version:e.version}:{},...e.provider!==void 0?{provider:e.provider}:{},...e.objectKinds!==void 0?{objectKinds:M(e.objectKinds)}:{},...e.groups!==void 0?{groups:x(e.groups)}:{}})}s(te,"definePlugin");function S(e,t,n){if(!u(e))throw new f("groups must be an object keyed by group id");for(const[i,o]of Object.entries(e)){if(!z.test(i))throw new f(`group ${JSON.stringify(i)} must match [A-Za-z0-9_-]{1,64}`);if(!u(o))throw new f(`group "${i}" must be an object with consentLine`);const l=Object.keys(o).filter(c=>c!=="consentLine"&&c!=="who"&&c!=="allowlist");if(l.length>0)throw new f(`group "${i}" has unknown keys: ${l.join(", ")}`);if(d(o.consentLine,`group "${i}" consentLine`),o.who!==void 0&&o.who!=="own"&&o.who!=="user"&&o.who!=="allowlist"&&o.who!=="any")throw new f(`group "${i}" who must be own, user, allowlist, or any`);if(o.who==="allowlist"){if(!Array.isArray(o.allowlist)||o.allowlist.length===0||!o.allowlist.every(c=>typeof c=="string"&&/^app:.+/.test(c)))throw new f(`group "${i}" allowlist must be a non-empty array of app principals ("app:<id>") when who is allowlist`)}else if(o.allowlist!==void 0)throw new f(`group "${i}" allowlist is only allowed with who: "allowlist"`)}const a=new Set;for(const[i,o]of y(t,[n]))o.group!==void 0&&(Object.hasOwn(e,o.group)||r(i,`names group "${o.group}", which definePlugin groups does not declare`),a.add(o.group));for(const i of Object.keys(e))if(!a.has(i))throw new f(`group "${i}" is declared but no leaf uses it`)}s(S,"validateGroups");function x(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,Object.freeze({consentLine:n.consentLine,...n.who!==void 0?{who:n.who}:{},...n.allowlist!==void 0?{allowlist:Object.freeze([...n.allowlist])}:{}})])))}s(x,"snapshotGroups");function F(e,t,n){if(!u(e))throw new f("objectKinds must be an object keyed by relative kind name");const a={};for(const[o,l]of Object.entries(e)){if(!U.test(o))throw new f(`object kind ${JSON.stringify(o)} must be a lowercase relative name without a "."; the bundle prefixes it with the provider id`);a[`${t}.${o}`]=l}const i=K({object_kinds:a});if(i.length===0){const{leafPaths:o,streamingLeafPaths:l}=N(n);for(const[c,P]of Object.entries(a))i.push(...R(c,P,t,o,l))}if(i.length>0)throw new f(i.join("; "))}s(F,"validateObjectKinds");function N(e){const t=new Set,n=new Set;for(const[a,i]of y(e,[])){const o=a.map(A).join(" ");t.add(o),i.streaming&&n.add(o)}return{leafPaths:t,streamingLeafPaths:n}}s(N,"leafPathsOf");function M(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,Object.freeze({description:n.description,events:Object.freeze(Object.fromEntries(Object.entries(n.events).map(([a,i])=>[a,Object.freeze({...i})]))),...n.read!==void 0?{read:Object.freeze({command:Object.freeze([...n.read.command])})}:{}})])))}s(M,"snapshotObjectKinds");function _(e,t){for(const[n,a]of y(e,t))if(a.group===void 0)return n}s(_,"firstLeafWithoutGroup");function*y(e,t){for(const[n,a]of Object.entries(e)){const i=[...t,n];a.kind==="leaf"?yield[i,a]:yield*y(a.children,i)}}s(y,"leavesOf");function p(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,C(n)])))}s(p,"snapshotCommands");function C(e){return e.kind==="branch"?Object.freeze({kind:"branch",description:e.description,whenToUse:e.whenToUse,summary:e.summary,...e.tier!==void 0?{tier:e.tier}:{},children:p(e.children)}):Object.freeze({kind:"leaf",description:e.description,whenToUse:e.whenToUse,summary:e.summary,...e.tier!==void 0?{tier:e.tier}:{},params:q(e.params),output:j(e.output),effects:Object.freeze([...e.effects]),streaming:e.streaming,...e.group!==void 0?{group:e.group}:{},...e.sideEffect!==void 0?{sideEffect:e.sideEffect}:{},run:e.run})}s(C,"snapshotNode");function q(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,D(n)])))}s(q,"snapshotParams");function D(e){return e.kind==="flag"&&e.type==="enum"?Object.freeze({...e,choices:Object.freeze([...e.choices])}):e.kind==="flag"&&e.type==="json"?Object.freeze({...e,shape:h(e.shape)}):Object.freeze({...e})}s(D,"snapshotParam");function j(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,h(n)])))}s(j,"snapshotOutput");function h(e){return Object.freeze({...e,...e.children!==void 0?{children:j(e.children)}:{},...e.items!==void 0?{items:h(e.items)}:{},...e.variants!==void 0?{variants:Object.freeze(e.variants.map(h))}:{},...e.values!==void 0?{values:Object.freeze([...e.values])}:{}})}s(h,"snapshotField");function v(e,t){(!u(e)||e.kind!=="branch"&&e.kind!=="leaf")&&r(t,"must be a branch or leaf defined by this package"),d(e.description,`${m(t)} description`),d(e.whenToUse,`${m(t)} whenToUse`),d(e.summary,`${m(t)} summary`),e.tier!==void 0&&e.tier!=="hidden"&&e.tier!=="normal"&&e.tier!=="common"&&e.tier!=="important"&&r(t,"tier must be hidden, normal, common, or important");const n=t.at(-1);if(n===void 0&&r(t,"has no command name"),E(n,`${m(t)} command key`),e.kind==="branch"){u(e.children)||r(t,"branch children must be an object");for(const[i,o]of Object.entries(e.children))v(o,[...t,i]);return}e.group!==void 0&&(typeof e.group!="string"||!z.test(e.group))&&r(t,`group ${JSON.stringify(e.group)} must match [A-Za-z0-9_-]{1,64}`),e.sideEffect!==void 0&&typeof e.sideEffect!="boolean"&&r(t,"sideEffect must be a boolean"),u(e.params)||r(t,"leaf params must be an object");for(const[i,o]of Object.entries(e.params))E(i,`${m(t)} parameter key`),I(o,[...t,`parameter ${i}`]);Object.values(e.params).filter(i=>u(i)&&i.kind==="positional").length>1&&r(t,"a leaf may have at most one positional parameter"),u(e.output)||r(t,"leaf output must be an object");let a;for(const[i,o]of Object.entries(e.output))i.length===0&&r(t,"output field names must not be empty"),b(o,[...t,`output ${i}`],!0),g(o.type)==="file"&&(a!==void 0&&r(t,`declares file outputs ${a} and ${i}; a leaf may declare at most one file output`),a=i);(!Array.isArray(e.effects)||e.effects.length===0||!e.effects.every(i=>typeof i=="string"))&&r(t,"leaf effects must be a non-empty array of strings"),typeof e.streaming!="boolean"&&r(t,"leaf streaming must be a boolean"),typeof e.run!="function"&&r(t,"leaf handler must be a function")}s(v,"validateNode");function I(e,t){if((!u(e)||e.kind!=="flag"&&e.kind!=="positional"&&e.kind!=="stdin")&&r(t,"must be a parameter descriptor produced by param.*"),d(e.constraint,`${m(t)} constraint`),(typeof e.required!="boolean"||typeof e.repeatable!="boolean")&&r(t,"required and repeatable must be booleans"),e.kind==="stdin"){e.repeatable&&r(t,"stdin cannot be repeatable"),Object.hasOwn(e,"default")&&r(t,"stdin parameters cannot have a default");return}if(e.kind==="positional"){e.type!=="string"&&r(t,"positional parameters must have type string"),Object.hasOwn(e,"default")&&r(t,"positional parameters cannot have a default");return}if(e.type==="enum"?(!Array.isArray(e.choices)||e.choices.length===0||!e.choices.every(a=>typeof a=="string"))&&r(t,"enum parameters need at least one string choice"):e.type!=="string"&&e.type!=="int"&&e.type!=="bool"&&e.type!=="path"&&e.type!=="file"&&e.type!=="json"&&r(t,"flag parameters must have a supported type"),(e.type==="bool"||e.type==="path"||e.type==="file"||e.type==="json")&&e.repeatable&&r(t,`${e.type} parameters cannot be repeatable`),e.type==="path"&&e.encoding!=="text"&&e.encoding!=="base64"&&r(t,"path parameters must have text or base64 encoding"),e.type==="json"?b(e.shape,[...t,"shape"],!1):e.shape!==void 0&&r(t,"shape is only valid on json parameters"),e.type!=="path"&&e.encoding!==void 0&&r(t,"encoding is only valid on path parameters"),e.repeatable&&Object.hasOwn(e,"default")&&r(t,"repeatable parameters cannot have a default"),!Object.hasOwn(e,"default"))return;const n=e.default;e.type==="string"&&typeof n!="string"&&r(t,"string parameter defaults must be strings"),e.type==="int"&&(typeof n!="number"||!Number.isInteger(n))&&r(t,"int parameter defaults must be integers"),e.type==="bool"&&typeof n!="boolean"&&r(t,"bool parameter defaults must be booleans"),e.type==="enum"&&(typeof n!="string"||!Array.isArray(e.choices)||!e.choices.includes(n))&&r(t,"enum parameter defaults must be one of their choices"),(e.type==="path"||e.type==="file"||e.type==="json")&&r(t,`${e.type} parameters cannot have a default`)}s(I,"validateParam");function b(e,t,n){(!u(e)||typeof e.type!="string"||e.type.length===0||typeof e.constraint!="string"||typeof e.required!="boolean")&&r(t,"must be an output field descriptor produced by field.*");const a=g(e.type);if(e.kind!==void 0&&a!=="file"&&r(t,"is a parameter descriptor; declare output fields with field.*"),L(e.type)&&a!=="file"&&r(t,`has type ${e.type}; a file output is one file, declared file or file | null`),a==="file"&&!n&&r(t,"is a file, which is only valid as a top-level output field"),e.children!==void 0){a!=="object"&&r(t,"children are only valid on an object field"),u(e.children)||r(t,"children must be an object of output fields");for(const[i,o]of Object.entries(e.children))i.length===0&&r(t,"member names must not be empty"),b(o,[...t,`member ${i}`],!1)}e.items!==void 0&&(a!=="array"&&a!=="map"&&r(t,"items are only valid on an array or map field"),b(e.items,[...t,"items"],!1)),a==="map"&&e.items===void 0&&r(t,"a map field needs the shape of its values"),e.variants!==void 0&&a!=="union"&&r(t,"variants are only valid on a union field"),a==="union"&&((!Array.isArray(e.variants)||e.variants.length<2)&&r(t,"a union field needs two or more variants"),e.variants.forEach((i,o)=>b(i,[...t,`variant ${o}`],!1))),e.values!==void 0&&(a!=="enum"&&r(t,"values are only valid on an enum field"),(!Array.isArray(e.values)||e.values.length===0||!e.values.every(i=>typeof i=="string"&&i.length>0))&&r(t,"enum values must be a non-empty array of non-empty strings"),new Set(e.values).size!==e.values.length&&r(t,"enum values must be unique"))}s(b,"validateField");function J(e){if(!u(e)||typeof e.name!="string"||!Y(e.name))throw new f("memory document name must be a safe relative path");if(e.kind!=="knowledge"&&e.kind!=="preference")throw new f(`memory document ${e.name} has an invalid kind`);if(d(e.whenAndWhyToRead,`memory document ${e.name} whenAndWhyToRead`),typeof e.body!="string")throw new f(`memory document ${e.name} body must be a string`);if(e.unlisted!==void 0&&typeof e.unlisted!="boolean")throw new f(`memory document ${e.name} unlisted must be a boolean`);if(e.rules!==void 0){if(!Array.isArray(e.rules))throw new f(`memory document ${e.name} rules must be an array`);e.rules.forEach((t,n)=>G(t,`memory document ${e.name} rules[${n}]`))}}s(J,"validateMemoryDoc");const O=["boot","file-read","document-read","command","pre-command"],$=["on","deliver","match","matchFrontmatter","if"];function G(e,t){if(!u(e))throw new f(`${t} must be an object`);for(const n of Object.keys(e))if(!$.includes(n))throw new f(`${t} has unknown key ${n}; a rule carries only ${$.join(", ")}`);if(typeof e.on!="string"||!O.includes(e.on))throw new f(`${t} on must be one of ${O.join(", ")}`);if(e.deliver!=="name"&&e.deliver!=="preview"&&e.deliver!=="content")throw new f(`${t} deliver must be name, preview or content`);if(e.match!==void 0){if(e.on==="boot")throw new f(`${t} match is meaningless on boot; drop it`);if(!Array.isArray(e.match)||e.match.length===0||!e.match.every(n=>typeof n=="string"&&n.trim().length>0))throw new f(`${t} match must be a non-empty array of non-empty globs`)}if(e.matchFrontmatter!==void 0){if(e.on!=="file-read")throw new f(`${t} matchFrontmatter applies only to file-read`);k(e.matchFrontmatter,`${t} matchFrontmatter`)}if(e.on!=="boot"&&e.match===void 0&&e.matchFrontmatter===void 0)throw new f(`${t} needs match${e.on==="file-read"?" or matchFrontmatter":""} on ${e.on}`);e.if!==void 0&&k(e.if,`${t} if`)}s(G,"validateMemoryRule");function k(e,t){if(!u(e))throw new f(`${t} must be a field\u2192matcher object`);if(!w(e,0))throw new f(`${t} must hold only strings, finite numbers, booleans, null, arrays and plain objects`)}s(k,"assertCondition");function w(e,t){return t>32?!1:e===null||typeof e=="string"||typeof e=="boolean"?!0:typeof e=="number"?Number.isFinite(e):Array.isArray(e)?e.every(n=>w(n,t+1)):!u(e)||Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null?!1:Object.values(e).every(n=>w(n,t+1))}s(w,"isPlainJson");function W(e){const{rules:t,...n}=e;return Object.freeze({...n,...t!==void 0?{rules:Object.freeze(t.map(a=>structuredClone(a)))}:{}})}s(W,"freezeMemoryDoc");function Z(e){if(e!==void 0){if(!u(e))throw new f("timeouts must be an object");for(const t of["connectMs","requestMs","streamIdleMs"]){const n=e[t];if(n!==void 0&&(typeof n!="number"||!Number.isInteger(n)||n<=0))throw new f(`timeouts.${t} must be a positive integer`)}}}s(Z,"assertTimeouts");const z=/^[A-Za-z0-9_-]{1,64}$/;function E(e,t){if(A(e).replace(/-([a-z])/g,(a,i)=>i.toUpperCase())!==e)throw new f(`${t} must round-trip between camelCase and kebab-case`)}s(E,"assertKey");function B(e,t){if(!/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(e))throw new f(`${t} must be lowercase kebab-case`)}s(B,"assertKebabName");function A(e){const t=e.replace(/[A-Z]/g,n=>`-${n.toLowerCase()}`);if(!/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(t))throw new f(`invalid key ${JSON.stringify(e)}; use camelCase keys that convert to lowercase kebab-case`);return t}s(A,"kebab");function d(e,t){if(typeof e!="string"||e.length===0)throw new f(`${t} must be a non-empty string`)}s(d,"assertText");function Y(e){return e.length>0&&!e.startsWith("/")&&!e.includes("\\")&&e.split("/").every(t=>t.length>0&&t!=="."&&t!=="..")}s(Y,"isSafeRelativePath");function u(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}s(u,"isRecord");function r(e,t){throw new f(`${m(e)} ${t}`)}s(r,"fail");function m(e){return e.join(" ")}s(m,"formatPath");export{f as PluginDefinitionError,ee as defineBranch,Q as defineLeaf,te as definePlugin,X as defineStreamingLeaf,A as kebab};
1
+ var T=Object.defineProperty;var s=(e,t)=>T(e,"name",{value:t,configurable:!0});import{LOCAL as U,mentionsFile as x,objectBlocksShapeReasons as L,objectKindReadReasons as K,outputBaseType as g}from"@north-light/api/command-manifest";class a extends Error{static{s(this,"PluginDefinitionError")}constructor(t){super(t),this.name="PluginDefinitionError"}}function Q(e){return{kind:"leaf",description:e.description,whenToUse:e.whenToUse,summary:e.summary,...e.tier!==void 0?{tier:e.tier}:{},...e.group!==void 0?{group:e.group}:{},...e.sideEffect!==void 0?{sideEffect:e.sideEffect}:{},params:e.params??{},output:e.output,effects:e.effects,streaming:!1,run:s((t,n)=>Promise.resolve(e.handler(t,n)),"run")}}s(Q,"defineLeaf");function X(e){return{kind:"leaf",description:e.description,whenToUse:e.whenToUse,summary:e.summary,...e.tier!==void 0?{tier:e.tier}:{},...e.group!==void 0?{group:e.group}:{},...e.sideEffect!==void 0?{sideEffect:e.sideEffect}:{},params:e.params??{},output:e.output,effects:e.effects,streaming:!0,run:s((t,n)=>Promise.resolve(e.handler(t,n)),"run")}}s(X,"defineStreamingLeaf");function ee(e){return{kind:"branch",...e}}s(ee,"defineBranch");function te(e){if(B(e.name,"plugin name"),d(e.description,"plugin description"),d(e.whenToUse,"plugin whenToUse"),d(e.summary,"plugin summary"),d(e.rootEntry?.concept,"plugin rootEntry.concept"),d(e.rootEntry?.description,"plugin rootEntry.description"),d(e.rootEntry?.whenToUse,"plugin rootEntry.whenToUse"),Z(e.timeouts),e.version!==void 0&&(typeof e.version!="number"||!Number.isInteger(e.version)||e.version<1))throw new a("plugin version must be an integer of at least 1");if(e.provider!==void 0&&typeof e.provider!="boolean")throw new a("plugin provider must be a boolean");if(e.provider===!0&&e.version===void 0)throw new a("a provider plugin must declare its major version");for(const[t,n]of Object.entries(e.commands))v(n,[e.name,t]);if(e.provider===!0){const t=_(e.commands,[e.name]);t!==void 0&&r(t,"needs a group because the plugin is a provider")}if(e.groups!==void 0){if(e.provider!==!0)throw new a("groups can only be declared by a provider plugin; set provider: true");R(e.groups,e.commands,e.name)}for(const t of e.memory??[])J(t);return e.objectKinds!==void 0&&F(e.objectKinds,e.name,e.commands),Object.freeze({name:e.name,description:e.description,whenToUse:e.whenToUse,summary:e.summary,rootEntry:Object.freeze({...e.rootEntry}),commands:p(e.commands),memory:Object.freeze((e.memory??[]).map(W)),...e.timeouts!==void 0?{timeouts:Object.freeze({...e.timeouts})}:{},...e.version!==void 0?{version:e.version}:{},...e.provider!==void 0?{provider:e.provider}:{},...e.objectKinds!==void 0?{objectKinds:M(e.objectKinds)}:{},...e.groups!==void 0?{groups:S(e.groups)}:{}})}s(te,"definePlugin");function R(e,t,n){if(!u(e))throw new a("groups must be an object keyed by group id");for(const[i,o]of Object.entries(e)){if(!z.test(i))throw new a(`group ${JSON.stringify(i)} must match [A-Za-z0-9_-]{1,64}`);if(!u(o))throw new a(`group "${i}" must be an object with consentLine`);const l=Object.keys(o).filter(c=>c!=="consentLine"&&c!=="who"&&c!=="allowlist");if(l.length>0)throw new a(`group "${i}" has unknown keys: ${l.join(", ")}`);if(d(o.consentLine,`group "${i}" consentLine`),o.who!==void 0&&o.who!=="own"&&o.who!=="user"&&o.who!=="allowlist"&&o.who!=="any")throw new a(`group "${i}" who must be own, user, allowlist, or any`);if(o.who==="allowlist"){if(!Array.isArray(o.allowlist)||o.allowlist.length===0||!o.allowlist.every(c=>typeof c=="string"&&/^app:.+/.test(c)))throw new a(`group "${i}" allowlist must be a non-empty array of app principals ("app:<id>") when who is allowlist`)}else if(o.allowlist!==void 0)throw new a(`group "${i}" allowlist is only allowed with who: "allowlist"`)}const f=new Set;for(const[i,o]of h(t,[n]))o.group!==void 0&&(Object.hasOwn(e,o.group)||r(i,`names group "${o.group}", which definePlugin groups does not declare`),f.add(o.group));for(const i of Object.keys(e))if(!f.has(i))throw new a(`group "${i}" is declared but no leaf uses it`)}s(R,"validateGroups");function S(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,Object.freeze({consentLine:n.consentLine,...n.who!==void 0?{who:n.who}:{},...n.allowlist!==void 0?{allowlist:Object.freeze([...n.allowlist])}:{}})])))}s(S,"snapshotGroups");function F(e,t,n){if(!u(e))throw new a("objectKinds must be an object keyed by relative kind name");const f={};for(const[o,l]of Object.entries(e)){if(!U.test(o))throw new a(`object kind ${JSON.stringify(o)} must be a lowercase relative name without a "."; the bundle prefixes it with the provider id`);f[`${t}.${o}`]=l}const i=L({object_kinds:f});if(i.length===0){const{leafPaths:o,streamingLeafPaths:l}=N(n);for(const[c,P]of Object.entries(f))i.push(...K(c,P,t,o,l))}if(i.length>0)throw new a(i.join("; "))}s(F,"validateObjectKinds");function N(e){const t=new Set,n=new Set;for(const[f,i]of h(e,[])){const o=f.map(A).join(" ");t.add(o),i.streaming&&n.add(o)}return{leafPaths:t,streamingLeafPaths:n}}s(N,"leafPathsOf");function M(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,Object.freeze({description:n.description,events:Object.freeze(Object.fromEntries(Object.entries(n.events).map(([f,i])=>[f,Object.freeze({...i})]))),...n.read!==void 0?{read:Object.freeze({command:Object.freeze([...n.read.command])})}:{}})])))}s(M,"snapshotObjectKinds");function _(e,t){for(const[n,f]of h(e,t))if(f.group===void 0)return n}s(_,"firstLeafWithoutGroup");function*h(e,t){for(const[n,f]of Object.entries(e)){const i=[...t,n];f.kind==="leaf"?yield[i,f]:yield*h(f.children,i)}}s(h,"leavesOf");function p(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,C(n)])))}s(p,"snapshotCommands");function C(e){return e.kind==="branch"?Object.freeze({kind:"branch",description:e.description,whenToUse:e.whenToUse,summary:e.summary,...e.tier!==void 0?{tier:e.tier}:{},children:p(e.children)}):Object.freeze({kind:"leaf",description:e.description,whenToUse:e.whenToUse,summary:e.summary,...e.tier!==void 0?{tier:e.tier}:{},params:q(e.params),output:j(e.output),effects:Object.freeze([...e.effects]),streaming:e.streaming,...e.group!==void 0?{group:e.group}:{},...e.sideEffect!==void 0?{sideEffect:e.sideEffect}:{},run:e.run})}s(C,"snapshotNode");function q(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,D(n)])))}s(q,"snapshotParams");function D(e){return e.kind==="flag"&&e.type==="enum"?Object.freeze({...e,choices:Object.freeze([...e.choices])}):e.kind==="flag"&&e.type==="json"?Object.freeze({...e,shape:y(e.shape)}):Object.freeze({...e})}s(D,"snapshotParam");function j(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,y(n)])))}s(j,"snapshotOutput");function y(e){return Object.freeze({...e,...e.children!==void 0?{children:j(e.children)}:{},...e.extra!==void 0?{extra:y(e.extra)}:{},...e.items!==void 0?{items:y(e.items)}:{},...e.variants!==void 0?{variants:Object.freeze(e.variants.map(y))}:{},...e.values!==void 0?{values:Object.freeze([...e.values])}:{}})}s(y,"snapshotField");function v(e,t){(!u(e)||e.kind!=="branch"&&e.kind!=="leaf")&&r(t,"must be a branch or leaf defined by this package"),d(e.description,`${m(t)} description`),d(e.whenToUse,`${m(t)} whenToUse`),d(e.summary,`${m(t)} summary`),e.tier!==void 0&&e.tier!=="hidden"&&e.tier!=="normal"&&e.tier!=="common"&&e.tier!=="important"&&r(t,"tier must be hidden, normal, common, or important");const n=t.at(-1);if(n===void 0&&r(t,"has no command name"),E(n,`${m(t)} command key`),e.kind==="branch"){u(e.children)||r(t,"branch children must be an object");for(const[i,o]of Object.entries(e.children))v(o,[...t,i]);return}e.group!==void 0&&(typeof e.group!="string"||!z.test(e.group))&&r(t,`group ${JSON.stringify(e.group)} must match [A-Za-z0-9_-]{1,64}`),e.sideEffect!==void 0&&typeof e.sideEffect!="boolean"&&r(t,"sideEffect must be a boolean"),u(e.params)||r(t,"leaf params must be an object");for(const[i,o]of Object.entries(e.params))E(i,`${m(t)} parameter key`),I(o,[...t,`parameter ${i}`]);Object.values(e.params).filter(i=>u(i)&&i.kind==="positional").length>1&&r(t,"a leaf may have at most one positional parameter"),u(e.output)||r(t,"leaf output must be an object");let f;for(const[i,o]of Object.entries(e.output))i.length===0&&r(t,"output field names must not be empty"),b(o,[...t,`output ${i}`],!0),g(o.type)==="file"&&(f!==void 0&&r(t,`declares file outputs ${f} and ${i}; a leaf may declare at most one file output`),f=i);(!Array.isArray(e.effects)||e.effects.length===0||!e.effects.every(i=>typeof i=="string"))&&r(t,"leaf effects must be a non-empty array of strings"),typeof e.streaming!="boolean"&&r(t,"leaf streaming must be a boolean"),typeof e.run!="function"&&r(t,"leaf handler must be a function")}s(v,"validateNode");function I(e,t){if((!u(e)||e.kind!=="flag"&&e.kind!=="positional"&&e.kind!=="stdin")&&r(t,"must be a parameter descriptor produced by param.*"),d(e.constraint,`${m(t)} constraint`),(typeof e.required!="boolean"||typeof e.repeatable!="boolean")&&r(t,"required and repeatable must be booleans"),e.kind==="stdin"){e.repeatable&&r(t,"stdin cannot be repeatable"),Object.hasOwn(e,"default")&&r(t,"stdin parameters cannot have a default");return}if(e.kind==="positional"){e.type!=="string"&&r(t,"positional parameters must have type string"),Object.hasOwn(e,"default")&&r(t,"positional parameters cannot have a default");return}if(e.type==="enum"?(!Array.isArray(e.choices)||e.choices.length===0||!e.choices.every(f=>typeof f=="string"))&&r(t,"enum parameters need at least one string choice"):e.type!=="string"&&e.type!=="int"&&e.type!=="bool"&&e.type!=="path"&&e.type!=="file"&&e.type!=="json"&&r(t,"flag parameters must have a supported type"),(e.type==="bool"||e.type==="path"||e.type==="file"||e.type==="json")&&e.repeatable&&r(t,`${e.type} parameters cannot be repeatable`),e.type==="path"&&e.encoding!=="text"&&e.encoding!=="base64"&&r(t,"path parameters must have text or base64 encoding"),e.type==="json"?b(e.shape,[...t,"shape"],!1):e.shape!==void 0&&r(t,"shape is only valid on json parameters"),e.type!=="path"&&e.encoding!==void 0&&r(t,"encoding is only valid on path parameters"),e.repeatable&&Object.hasOwn(e,"default")&&r(t,"repeatable parameters cannot have a default"),!Object.hasOwn(e,"default"))return;const n=e.default;e.type==="string"&&typeof n!="string"&&r(t,"string parameter defaults must be strings"),e.type==="int"&&(typeof n!="number"||!Number.isInteger(n))&&r(t,"int parameter defaults must be integers"),e.type==="bool"&&typeof n!="boolean"&&r(t,"bool parameter defaults must be booleans"),e.type==="enum"&&(typeof n!="string"||!Array.isArray(e.choices)||!e.choices.includes(n))&&r(t,"enum parameter defaults must be one of their choices"),(e.type==="path"||e.type==="file"||e.type==="json")&&r(t,`${e.type} parameters cannot have a default`)}s(I,"validateParam");function b(e,t,n){(!u(e)||typeof e.type!="string"||e.type.length===0||typeof e.constraint!="string"||typeof e.required!="boolean")&&r(t,"must be an output field descriptor produced by field.*");const f=g(e.type);if(e.kind!==void 0&&f!=="file"&&r(t,"is a parameter descriptor; declare output fields with field.*"),x(e.type)&&f!=="file"&&r(t,`has type ${e.type}; a file output is one file, declared file or file | null`),f==="file"&&!n&&r(t,"is a file, which is only valid as a top-level output field"),e.children!==void 0){f!=="object"&&r(t,"children are only valid on an object field"),u(e.children)||r(t,"children must be an object of output fields");for(const[i,o]of Object.entries(e.children))i.length===0&&r(t,"member names must not be empty"),b(o,[...t,`member ${i}`],!1)}e.extra!==void 0&&((f!=="object"||e.children===void 0)&&r(t,"extra is only valid on an object field with children"),b(e.extra,[...t,"extra"],!1)),e.items!==void 0&&(f!=="array"&&f!=="map"&&r(t,"items are only valid on an array or map field"),b(e.items,[...t,"items"],!1)),f==="map"&&e.items===void 0&&r(t,"a map field needs the shape of its values"),e.variants!==void 0&&f!=="union"&&r(t,"variants are only valid on a union field"),f==="union"&&((!Array.isArray(e.variants)||e.variants.length<2)&&r(t,"a union field needs two or more variants"),e.variants.forEach((i,o)=>b(i,[...t,`variant ${o}`],!1))),e.values!==void 0&&(f!=="enum"&&r(t,"values are only valid on an enum field"),(!Array.isArray(e.values)||e.values.length===0||!e.values.every(i=>typeof i=="string"&&i.length>0))&&r(t,"enum values must be a non-empty array of non-empty strings"),new Set(e.values).size!==e.values.length&&r(t,"enum values must be unique"))}s(b,"validateField");function J(e){if(!u(e)||typeof e.name!="string"||!Y(e.name))throw new a("memory document name must be a safe relative path");if(e.kind!=="knowledge"&&e.kind!=="preference")throw new a(`memory document ${e.name} has an invalid kind`);if(d(e.whenAndWhyToRead,`memory document ${e.name} whenAndWhyToRead`),typeof e.body!="string")throw new a(`memory document ${e.name} body must be a string`);if(e.unlisted!==void 0&&typeof e.unlisted!="boolean")throw new a(`memory document ${e.name} unlisted must be a boolean`);if(e.rules!==void 0){if(!Array.isArray(e.rules))throw new a(`memory document ${e.name} rules must be an array`);e.rules.forEach((t,n)=>G(t,`memory document ${e.name} rules[${n}]`))}}s(J,"validateMemoryDoc");const O=["boot","file-read","document-read","command","pre-command"],$=["on","deliver","match","matchFrontmatter","if"];function G(e,t){if(!u(e))throw new a(`${t} must be an object`);for(const n of Object.keys(e))if(!$.includes(n))throw new a(`${t} has unknown key ${n}; a rule carries only ${$.join(", ")}`);if(typeof e.on!="string"||!O.includes(e.on))throw new a(`${t} on must be one of ${O.join(", ")}`);if(e.deliver!=="name"&&e.deliver!=="preview"&&e.deliver!=="content")throw new a(`${t} deliver must be name, preview or content`);if(e.match!==void 0){if(e.on==="boot")throw new a(`${t} match is meaningless on boot; drop it`);if(!Array.isArray(e.match)||e.match.length===0||!e.match.every(n=>typeof n=="string"&&n.trim().length>0))throw new a(`${t} match must be a non-empty array of non-empty globs`)}if(e.matchFrontmatter!==void 0){if(e.on!=="file-read")throw new a(`${t} matchFrontmatter applies only to file-read`);k(e.matchFrontmatter,`${t} matchFrontmatter`)}if(e.on!=="boot"&&e.match===void 0&&e.matchFrontmatter===void 0)throw new a(`${t} needs match${e.on==="file-read"?" or matchFrontmatter":""} on ${e.on}`);e.if!==void 0&&k(e.if,`${t} if`)}s(G,"validateMemoryRule");function k(e,t){if(!u(e))throw new a(`${t} must be a field\u2192matcher object`);if(!w(e,0))throw new a(`${t} must hold only strings, finite numbers, booleans, null, arrays and plain objects`)}s(k,"assertCondition");function w(e,t){return t>32?!1:e===null||typeof e=="string"||typeof e=="boolean"?!0:typeof e=="number"?Number.isFinite(e):Array.isArray(e)?e.every(n=>w(n,t+1)):!u(e)||Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null?!1:Object.values(e).every(n=>w(n,t+1))}s(w,"isPlainJson");function W(e){const{rules:t,...n}=e;return Object.freeze({...n,...t!==void 0?{rules:Object.freeze(t.map(f=>structuredClone(f)))}:{}})}s(W,"freezeMemoryDoc");function Z(e){if(e!==void 0){if(!u(e))throw new a("timeouts must be an object");for(const t of["connectMs","requestMs","streamIdleMs"]){const n=e[t];if(n!==void 0&&(typeof n!="number"||!Number.isInteger(n)||n<=0))throw new a(`timeouts.${t} must be a positive integer`)}}}s(Z,"assertTimeouts");const z=/^[A-Za-z0-9_-]{1,64}$/;function E(e,t){if(A(e).replace(/-([a-z])/g,(f,i)=>i.toUpperCase())!==e)throw new a(`${t} must round-trip between camelCase and kebab-case`)}s(E,"assertKey");function B(e,t){if(!/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(e))throw new a(`${t} must be lowercase kebab-case`)}s(B,"assertKebabName");function A(e){const t=e.replace(/[A-Z]/g,n=>`-${n.toLowerCase()}`);if(!/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(t))throw new a(`invalid key ${JSON.stringify(e)}; use camelCase keys that convert to lowercase kebab-case`);return t}s(A,"kebab");function d(e,t){if(typeof e!="string"||e.length===0)throw new a(`${t} must be a non-empty string`)}s(d,"assertText");function Y(e){return e.length>0&&!e.startsWith("/")&&!e.includes("\\")&&e.split("/").every(t=>t.length>0&&t!=="."&&t!=="..")}s(Y,"isSafeRelativePath");function u(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}s(u,"isRecord");function r(e,t){throw new a(`${m(e)} ${t}`)}s(r,"fail");function m(e){return e.join(" ")}s(m,"formatPath");export{a as PluginDefinitionError,ee as defineBranch,Q as defineLeaf,te as definePlugin,X as defineStreamingLeaf,A as kebab};
package/dist/fields.d.ts CHANGED
@@ -8,6 +8,8 @@ export interface OutField<T extends string, Req extends boolean> {
8
8
  readonly required: Req;
9
9
  /** An object field's members by name, set by `field.object({ … })`. */
10
10
  readonly children?: Readonly<Record<string, OutField<string, boolean>>>;
11
+ /** The shape of every member an object field does not name in `children`, set by `field.object(children, c, { extra })`. Without it the object is closed. */
12
+ readonly extra?: OutField<string, boolean>;
11
13
  /** An array field's element shape or a map field's value shape, set by `field.array(field.…)` or `field.map(field.…)`. */
12
14
  readonly items?: OutField<string, boolean>;
13
15
  /** A union field's alternatives, set by `field.union([…])`. */
@@ -24,9 +26,11 @@ type FieldShape = {
24
26
  readonly type: string;
25
27
  };
26
28
  /** An object field with typed members, as returned by `field.object({ … })`. */
27
- export type ObjectField<C extends Record<string, FieldShape>, Req extends boolean> = Omit<OutField<'object', Req>, 'children'> & {
29
+ export type ObjectField<C extends Record<string, FieldShape>, Req extends boolean, X extends FieldShape | undefined = undefined> = Omit<OutField<'object', Req>, 'children' | 'extra'> & {
28
30
  readonly children: C;
29
- };
31
+ } & (X extends FieldShape ? {
32
+ readonly extra: X;
33
+ } : unknown);
30
34
  /** An array field with a typed element, as returned by `field.array(field.…)`. */
31
35
  export type ArrayField<I extends FieldShape, Req extends boolean> = Omit<OutField<'array', Req>, 'items'> & {
32
36
  readonly items: I;
@@ -73,6 +77,12 @@ export type FieldValue<F> = F extends {
73
77
  } ? FileOutputValue : F extends {
74
78
  type: 'object';
75
79
  children: infer C;
80
+ extra: FieldShape;
81
+ } ? Output<C> & {
82
+ readonly [key: string]: unknown;
83
+ } : F extends {
84
+ type: 'object';
85
+ children: infer C;
76
86
  } ? Output<C> : F extends {
77
87
  type: 'object';
78
88
  } ? Record<string, unknown> : F extends {
@@ -113,8 +123,11 @@ export type Output<O> = {
113
123
  type FieldOptions<Req extends boolean> = {
114
124
  required?: Req;
115
125
  };
126
+ type ObjectOptions<Req extends boolean, X extends FieldShape | undefined> = FieldOptions<Req> & {
127
+ extra?: X;
128
+ };
116
129
  /** A field holding an object: pass its members to type them, or only a constraint for an untyped object. */
117
- declare function object<const C extends Record<string, FieldShape>, Req extends boolean = true>(children: C, constraint?: string, opts?: FieldOptions<Req>): ObjectField<C, Req>;
130
+ declare function object<const C extends Record<string, FieldShape>, Req extends boolean = true, const X extends FieldShape | undefined = undefined>(children: C, constraint?: string, opts?: ObjectOptions<Req, X>): ObjectField<C, Req, X>;
118
131
  declare function object<Req extends boolean = true>(constraint: string, opts?: FieldOptions<Req>): OutField<'object', Req>;
119
132
  /**
120
133
  * A field holding an array: pass the element's field to type it (its `required` is ignored),
package/dist/fields.js CHANGED
@@ -1 +1 @@
1
- var i=Object.defineProperty;var u=(r,n)=>i(r,"name",{value:n,configurable:!0});function e(r,n,t={}){return{type:r,constraint:n,required:t.required??!0}}u(e,"defineField");function o(r,n,t){return typeof r=="string"?e("object",r,n??{}):{...e("object",n??"",t),children:r}}u(o,"object");function a(r,n,t){return typeof r=="string"?e("array",r,n??{}):{...e("array",n??r.constraint,t),items:r}}u(a,"array");const p={string(r,n={}){return e("string",r,n)},int(r,n={}){return e("int",r,n)},number(r,n={}){return e("number",r,n)},bool(r,n={}){return e("bool",r,n)},object:o,array:a,map(r,n,t={}){return{...e("map",n??r.constraint,t),items:r}},union(r,n,t={}){return{...e("union",n,t),variants:r}},unknown(r,n={}){return e("unknown",r,n)},enum(r,n,t={}){return{...e("enum",n,t),values:r}},file(r,n={}){return{kind:"flag",type:"file",constraint:r,required:n.required??!1,repeatable:!1}},markdown(r,n={}){return e("markdown",r,n)},path(r,n={}){return e("path",r,n)},of(r,n,t={}){return e(r,n,t)},nullable(r){return{...r,type:`${r.type} | null`}}};export{p as field};
1
+ var a=Object.defineProperty;var u=(r,e)=>a(r,"name",{value:e,configurable:!0});function t(r,e,n={}){return{type:r,constraint:e,required:n.required??!0}}u(t,"defineField");function i(r,e,n){return typeof r=="string"?t("object",r,e??{}):{...t("object",e??"",n),children:r,...n?.extra!==void 0?{extra:n.extra}:{}}}u(i,"object");function o(r,e,n){return typeof r=="string"?t("array",r,e??{}):{...t("array",e??r.constraint,n),items:r}}u(o,"array");const f={string(r,e={}){return t("string",r,e)},int(r,e={}){return t("int",r,e)},number(r,e={}){return t("number",r,e)},bool(r,e={}){return t("bool",r,e)},object:i,array:o,map(r,e,n={}){return{...t("map",e??r.constraint,n),items:r}},union(r,e,n={}){return{...t("union",e,n),variants:r}},unknown(r,e={}){return t("unknown",r,e)},enum(r,e,n={}){return{...t("enum",e,n),values:r}},file(r,e={}){return{kind:"flag",type:"file",constraint:r,required:e.required??!1,repeatable:!1}},markdown(r,e={}){return t("markdown",r,e)},path(r,e={}){return t("path",r,e)},of(r,e,n={}){return t(r,e,n)},nullable(r){return{...r,type:`${r.type} | null`}}};export{f as field};
package/dist/manifest.js CHANGED
@@ -1 +1 @@
1
- var y=Object.defineProperty;var i=(e,t)=>y(e,"name",{value:t,configurable:!0});import{validateCommandManifest as w}from"@north-light/api/command-manifest";import{kebab as f}from"./define.js";class h extends Error{static{i(this,"ManifestInvalidError")}issues;constructor(t){super(`Generated command manifest is invalid: ${t.map(r=>r.message).join("; ")}`),this.name="ManifestInvalidError",this.issues=t}}function E(e,t){const r=j(t.mountPath),a={schemaVersion:1,...e.version!==void 0?{version:e.version}:{},...t.baseUrl!==void 0?{baseUrl:t.baseUrl}:{},...e.timeouts!==void 0?{timeouts:e.timeouts}:{},mounts:[{parent:[],node:{...v(e.name,e.description,e.whenToUse,e.summary,void 0),rootEntry:e.rootEntry,children:Object.entries(e.commands).map(([c,m])=>p(c,m,[e.name],r))}}]},s=w(a,{transport:"http",reservedCoreNames:new Set});if(s.issues.length>0)throw new h(s.issues);return a}i(E,"buildCommandManifest");function p(e,t,r,a){const s=f(e),c=[...r,s];if(t.kind==="branch")return{...v(s,t.description,t.whenToUse,t.summary,t.tier),children:Object.entries(t.children).map(([o,n])=>p(o,n,c,a))};const m=Object.entries(t.params).map(([o,n])=>{const d=f(o);return n.kind==="stdin"?{kind:n.kind,name:d,required:n.required,constraint:n.constraint}:n.kind==="flag"&&n.type==="json"?{name:d,...n,shape:u(n.shape)}:{name:d,...n}}),l=Object.fromEntries(m.map(o=>[o.name,{in:"body"}]));return{kind:"leaf",name:s,description:t.description,whenToUse:t.whenToUse,...t.tier!==void 0?{tier:t.tier}:{},summary:t.summary,...t.group!==void 0?{group:t.group}:{},params:m,output:b(t.output),effects:t.effects,rest:{method:"POST",path:`${a}/${c.join("/")}`,...t.streaming?{streaming:!0}:{},params:l}}}i(p,"toManifestNode");function b(e){return Object.entries(e).map(([t,r])=>({name:t,...u(r),required:r.required}))}i(b,"toManifestFields");function u(e){return{type:e.type,constraint:e.constraint,...e.children!==void 0?{children:b(e.children)}:{},...e.items!==void 0?{items:u(e.items)}:{},...e.variants!==void 0?{variants:e.variants.map(u)}:{},...e.values!==void 0?{values:[...e.values]}:{}}}i(u,"toManifestShape");function v(e,t,r,a,s){return{kind:"branch",name:e,description:t,whenToUse:r,...s!==void 0?{tier:s}:{},summary:a}}i(v,"branch");function j(e){if(e===""||e==="/")return"";if(!e.startsWith("/")||e.includes("?")||e.includes("#"))throw new h([{code:"command_rest_invalid",message:"mountPath must be an absolute pathname",received:e,expected:"an absolute pathname",next:"Pass the handler mount path, such as /crtr."}]);return e.replace(/\/+$/,"")}i(j,"normalizeMountPath");export{h as ManifestInvalidError,E as buildCommandManifest};
1
+ var l=Object.defineProperty;var i=(e,t)=>l(e,"name",{value:t,configurable:!0});import{validateCommandManifest as w}from"@north-light/api/command-manifest";import{kebab as f}from"./define.js";class h extends Error{static{i(this,"ManifestInvalidError")}issues;constructor(t){super(`Generated command manifest is invalid: ${t.map(r=>r.message).join("; ")}`),this.name="ManifestInvalidError",this.issues=t}}function U(e,t){const r=j(t.mountPath),a={schemaVersion:1,...e.version!==void 0?{version:e.version}:{},...t.baseUrl!==void 0?{baseUrl:t.baseUrl}:{},...e.timeouts!==void 0?{timeouts:e.timeouts}:{},mounts:[{parent:[],node:{...v(e.name,e.description,e.whenToUse,e.summary,void 0),rootEntry:e.rootEntry,children:Object.entries(e.commands).map(([u,m])=>p(u,m,[e.name],r))}}]},s=w(a,{transport:"http",reservedCoreNames:new Set});if(s.issues.length>0)throw new h(s.issues);return a}i(U,"buildCommandManifest");function p(e,t,r,a){const s=f(e),u=[...r,s];if(t.kind==="branch")return{...v(s,t.description,t.whenToUse,t.summary,t.tier),children:Object.entries(t.children).map(([o,n])=>p(o,n,u,a))};const m=Object.entries(t.params).map(([o,n])=>{const d=f(o);return n.kind==="stdin"?{kind:n.kind,name:d,required:n.required,constraint:n.constraint}:n.kind==="flag"&&n.type==="json"?{name:d,...n,shape:c(n.shape)}:{name:d,...n}}),y=Object.fromEntries(m.map(o=>[o.name,{in:"body"}]));return{kind:"leaf",name:s,description:t.description,whenToUse:t.whenToUse,...t.tier!==void 0?{tier:t.tier}:{},summary:t.summary,...t.group!==void 0?{group:t.group}:{},params:m,output:b(t.output),effects:t.effects,rest:{method:"POST",path:`${a}/${u.join("/")}`,...t.streaming?{streaming:!0}:{},params:y}}}i(p,"toManifestNode");function b(e){return Object.entries(e).map(([t,r])=>({name:t,...c(r),required:r.required}))}i(b,"toManifestFields");function c(e){return{type:e.type,constraint:e.constraint,...e.children!==void 0?{children:b(e.children)}:{},...e.extra!==void 0?{extra:c(e.extra)}:{},...e.items!==void 0?{items:c(e.items)}:{},...e.variants!==void 0?{variants:e.variants.map(c)}:{},...e.values!==void 0?{values:[...e.values]}:{}}}i(c,"toManifestShape");function v(e,t,r,a,s){return{kind:"branch",name:e,description:t,whenToUse:r,...s!==void 0?{tier:s}:{},summary:a}}i(v,"branch");function j(e){if(e===""||e==="/")return"";if(!e.startsWith("/")||e.includes("?")||e.includes("#"))throw new h([{code:"command_rest_invalid",message:"mountPath must be an absolute pathname",received:e,expected:"an absolute pathname",next:"Pass the handler mount path, such as /crtr."}]);return e.replace(/\/+$/,"")}i(j,"normalizeMountPath");export{h as ManifestInvalidError,U as buildCommandManifest};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/plugin",
3
- "version": "0.3.524",
3
+ "version": "0.3.526",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -27,8 +27,8 @@
27
27
  "postpack": "node ../../scripts/pack-minify.mjs postpack packages/crouter-plugin"
28
28
  },
29
29
  "dependencies": {
30
- "@north-light/api": "0.3.524",
31
- "@north-light/identity": "0.3.524"
30
+ "@north-light/api": "0.3.526",
31
+ "@north-light/identity": "0.3.526"
32
32
  },
33
33
  "license": "UNLICENSED",
34
34
  "publishConfig": {