@north-light/plugin 0.3.520 → 0.3.522

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,6 +1,6 @@
1
1
  import type { HttpPluginCommandManifest } from '@north-light/api/plugin-manifest';
2
2
  /** Raised on every change to the emitted bytes, so a caller can tell which stored packages predate the change. */
3
- export declare const GENERATOR_REVISION = 2;
3
+ export declare const GENERATOR_REVISION = 3;
4
4
  export interface ClientGeneratorInput {
5
5
  /** The provider's registration id; also the package name `@northlight-providers/<providerId>`. */
6
6
  readonly providerId: string;
@@ -1,33 +1,33 @@
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=2,_=">=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:r,version:t}=e;if(!A.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 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} ${t} (provider ${n}, major ${r}, inputDigest ${i})
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})
2
2
  // Generated; do not edit.
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(y,n,r,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 r=n.manifest.roots,t=r[0];return r.length===1&&t?.kind==="branch"?t.children:r}a(D,"treeRoots");function k(e,n,r){const t=[],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,r);u.length>0&&(p={kind:"branch",key:i,node:o,children:u})}else!(o.group!==void 0&&r.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),t.push(p)}}return t}a(k,"collect");function $(e){return e.flatMap(n=>n.kind==="leaf"?[n]:$(n.children))}a($,"leaves");function I(e){const n=[],r=new Set;for(const t of e){if(t.kind==="context-file")continue;const s=d(t.name);if(r.has(s))throw new Error(`parameters of one command collide on the name ${s}`);r.add(s);const o=t.kind!=="stdin"&&t.repeatable===!0;let i,c=!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"?(c=!0,i="Uint8Array"):i="string";const p=o&&/[|]/.test(i)?`(${i})`:i;n.push({key:s,wire:t.name,type:o?`${p}[]`:i,required:t.required,constraint:t.constraint,base64:c,repeatable:o})}return n}a(I,"paramModels");function d(e){return e.replace(/-([a-z0-9])/g,(n,r)=>r.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:r,nullable:t}=j(e.type);let s;switch(r){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 t?`${s} | null`:s}a(l,"shapeType");function P(e){const{base:n,nullable:r}=j(e.type);return r||n==="union"||n==="enum"}a(P,"needsParens");function x(e,n){if(e.length===0)return"{}";const r=`${n} `;return`{
5
- ${e.map(s=>`${m(s.constraint,r)}${r}${h(s.name)}${s.required?"":"?"}: ${l(s,r)};`).join(`
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(`
6
6
  `)}
7
- ${n}}`}a(x,"objectType");function m(e,n,r=[]){const t=[e,...r].flatMap(s=>s.split(`
8
- `)).map(s=>s.replace(/\*\//g,"*\\/").trimEnd());for(;t.length>0&&t[t.length-1]==="";)t.pop();return t.length===0?"":`${n}/**
9
- ${t.map(s=>`${n} *${s===""?"":` ${s}`}`).join(`
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(`
10
10
  `)}
11
11
  ${n} */
12
- `}a(m,"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}`]:[]]}a(T,"leafDoc");function z(e,n,r,t,s){const o=[e,`import type { RequestOptions } from '@north-light/sdk';
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';
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 [${t.map(i=>JSON.stringify(i)).join(", ")}];
15
+ `,`export declare const scopes: readonly [${r.map(i=>JSON.stringify(i)).join(", ")}];
16
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 {
17
17
  ${p.join(`
18
18
  `)}
19
19
  }
20
20
  `)}o.push(`export interface ${c}Result ${x(i.node.output,"")}
21
- `)}return o.push(`export interface ${g(r)}Client ${O(s,"",n)}
22
- `),o.push(`export declare function ${r}(runtime: ProviderRuntime): ${g(r)}Client;
23
- `),o.push(`export default ${r};
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
24
  `),o.join(`
25
- `)}a(z,"renderDts");function O(e,n,r){const t=`${n} `;return`{
26
- ${e.map(o=>{if(o.kind==="branch")return`${m(o.node.description,t)}${t}${h(o.key)}: ${O(o.children,t,r)};`;const i=v(o),c=o.params.length>0?`args: ${i}Args`:"args?: Record<string, never>",[p,...u]=T(o,r);return`${m(p,t,u)}${t}${h(o.key)}(${c}, options?: CallOptions): Promise<${i}Result>;`}).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(`
27
27
  `)}
28
- ${n}}`}a(O,"clientType");function G(e,n,r,t,s,o){return`${e}
28
+ ${n}}`}a(O,"clientType");function G(e,n,t,r,s,o){return`${e}
29
29
  const $provider = ${JSON.stringify(n)};
30
- const $major = ${r};
30
+ const $major = ${t};
31
31
 
32
32
  export const scopes = ${JSON.stringify(s)};
33
33
 
@@ -39,10 +39,10 @@ function $base64(bytes) {
39
39
 
40
40
  function $wire(args, spec) {
41
41
  const wire = {};
42
- for (const [key, name, base64] of spec) {
42
+ for (const [key, base64] of spec) {
43
43
  if (args == null || !Object.hasOwn(args, key) || args[key] === undefined) continue;
44
44
  const value = args[key];
45
- wire[name] = base64 === 0 ? value : Array.isArray(value) ? value.map($base64) : $base64(value);
45
+ wire[key] = base64 === 0 ? value : Array.isArray(value) ? value.map($base64) : $base64(value);
46
46
  }
47
47
  return wire;
48
48
  }
@@ -59,12 +59,12 @@ function $call(runtime, tool, args, spec, options) {
59
59
  }, requestOptions);
60
60
  }
61
61
 
62
- export function ${t}(runtime) {
62
+ export function ${r}(runtime) {
63
63
  return ${S(o," ")};
64
64
  }
65
65
 
66
- export default ${t};
67
- `}a(G,"renderJs");function S(e,n){const r=`${n} `;return`{
68
- ${e.map(s=>{const o=JSON.stringify(s.key);if(s.kind==="branch")return`${r}${o}: ${S(s.children,r)},`;const i=JSON.stringify(s.params.map(c=>[c.key,c.wire,c.base64?1:0]));return`${r}${o}: (args, options) => $call(runtime, ${JSON.stringify(s.segments.join(" "))}, args, ${i}, options),`}).join(`
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(`
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(([,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)}a(b,"canonicalJson");export{K as GENERATOR_REVISION,W as generateClient};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/plugin",
3
- "version": "0.3.520",
3
+ "version": "0.3.522",
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.520",
31
- "@north-light/identity": "0.3.520"
30
+ "@north-light/api": "0.3.522",
31
+ "@north-light/identity": "0.3.522"
32
32
  },
33
33
  "license": "UNLICENSED",
34
34
  "publishConfig": {