@north-light/plugin 0.3.541 → 0.3.543
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/define.js +1 -1
- package/package.json +3 -3
package/dist/define.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var T=Object.defineProperty;var o=(e,t)=>T(e,"name",{value:t,configurable:!0});import{LOCAL as U,mentionsFile as x,objectBlocksShapeReasons as L,objectKindReadReasons as R,outputBaseType as g}from"@north-light/api/command-manifest";class a extends Error{static{o(this,"PluginDefinitionError")}constructor(t){super(t),this.name="PluginDefinitionError"}}function ee(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:o((t,n)=>Promise.resolve(e.handler(t,n)),"run")}}o(ee,"defineLeaf");function te(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:o((t,n)=>Promise.resolve(e.handler(t,n)),"run")}}o(te,"defineStreamingLeaf");function ne(e){return{kind:"branch",...e}}o(ne,"defineBranch");function ie(e){if(H(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))O(n,[e.name,t]);if(e.provider===!0){const t=N(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");S(e.groups,e.commands,e.name)}for(const t of e.memory??[])G(t);return e.objectKinds!==void 0&&_(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(J)),...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:K(e.groups)}:{}})}o(ie,"definePlugin");function S(e,t,n){if(!u(e))throw new a("groups must be an object keyed by group id");for(const[i,f]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(f))throw new a(`group "${i}" must be an object with consentLine`);const l=Object.keys(f).filter(c=>c!=="consentLine"&&c!=="who"&&c!=="allowlist");if(l.length>0)throw new a(`group "${i}" has unknown keys: ${l.join(", ")}`);if(d(f.consentLine,`group "${i}" consentLine`),f.who!==void 0&&!(typeof f.who=="string"&&(B.has(f.who)||Y.test(f.who))))throw new a(`group "${i}" who must be own, user, allowlist, any, or team:<id>`);if(f.who==="allowlist"){if(!Array.isArray(f.allowlist)||f.allowlist.length===0||!f.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(f.allowlist!==void 0)throw new a(`group "${i}" allowlist is only allowed with who: "allowlist"`)}const s=new Set;for(const[i,f]of h(t,[n]))f.group!==void 0&&(Object.hasOwn(e,f.group)||r(i,`names group "${f.group}", which definePlugin groups does not declare`),s.add(f.group));for(const i of Object.keys(e))if(!s.has(i))throw new a(`group "${i}" is declared but no leaf uses it`)}o(S,"validateGroups");function K(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])}:{}})])))}o(K,"snapshotGroups");function _(e,t,n){if(!u(e))throw new a("objectKinds must be an object keyed by relative kind name");const s={};for(const[f,l]of Object.entries(e)){if(!U.test(f))throw new a(`object kind ${JSON.stringify(f)} must be a lowercase relative name without a "."; the bundle prefixes it with the provider id`);s[`${t}.${f}`]=l}const i=L({object_kinds:s});if(i.length===0){const{leafPaths:f,streamingLeafPaths:l}=F(n);for(const[c,P]of Object.entries(s))i.push(...R(c,P,t,f,l))}if(i.length>0)throw new a(i.join("; "))}o(_,"validateObjectKinds");function F(e){const t=new Set,n=new Set;for(const[s,i]of h(e,[])){const f=s.map(A).join(" ");t.add(f),i.streaming&&n.add(f)}return{leafPaths:t,streamingLeafPaths:n}}o(F,"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(([s,i])=>[s,Object.freeze({...i})]))),...n.read!==void 0?{read:Object.freeze({command:Object.freeze([...n.read.command])})}:{}})])))}o(M,"snapshotObjectKinds");function N(e,t){for(const[n,s]of h(e,t))if(s.group===void 0)return n}o(N,"firstLeafWithoutGroup");function*h(e,t){for(const[n,s]of Object.entries(e)){const i=[...t,n];s.kind==="leaf"?yield[i,s]:yield*h(s.children,i)}}o(h,"leavesOf");function p(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,C(n)])))}o(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:W(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})}o(C,"snapshotNode");function W(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,q(n)])))}o(W,"snapshotParams");function q(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})}o(q,"snapshotParam");function j(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,y(n)])))}o(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])}:{}})}o(y,"snapshotField");function O(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,f]of Object.entries(e.children))O(f,[...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,f]of Object.entries(e.params))E(i,`${m(t)} parameter key`),D(f,[...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 s;for(const[i,f]of Object.entries(e.output))i.length===0&&r(t,"output field names must not be empty"),b(f,[...t,`output ${i}`],!0),g(f.type)==="file"&&(s!==void 0&&r(t,`declares file outputs ${s} and ${i}; a leaf may declare at most one file output`),s=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")}o(O,"validateNode");function D(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(s=>typeof s=="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`)}o(D,"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 s=g(e.type);if(e.kind!==void 0&&s!=="file"&&r(t,"is a parameter descriptor; declare output fields with field.*"),x(e.type)&&s!=="file"&&r(t,`has type ${e.type}; a file output is one file, declared file or file | null`),s==="file"&&!n&&r(t,"is a file, which is only valid as a top-level output field"),e.children!==void 0){s!=="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,f]of Object.entries(e.children))i.length===0&&r(t,"member names must not be empty"),b(f,[...t,`member ${i}`],!1)}e.extra!==void 0&&((s!=="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&&(s!=="array"&&s!=="map"&&r(t,"items are only valid on an array or map field"),b(e.items,[...t,"items"],!1)),s==="map"&&e.items===void 0&&r(t,"a map field needs the shape of its values"),e.variants!==void 0&&s!=="union"&&r(t,"variants are only valid on a union field"),s==="union"&&((!Array.isArray(e.variants)||e.variants.length<2)&&r(t,"a union field needs two or more variants"),e.variants.forEach((i,f)=>b(i,[...t,`variant ${f}`],!1))),e.values!==void 0&&(s!=="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"))}o(b,"validateField");function G(e){if(!u(e)||typeof e.name!="string"||!V(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)=>I(t,`memory document ${e.name} rules[${n}]`))}}o(G,"validateMemoryDoc");const v=["boot","file-read","document-read","command","pre-command"],$=["on","deliver","match","matchFrontmatter","if"];function I(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"||!v.includes(e.on))throw new a(`${t} on must be one of ${v.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`)}o(I,"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`)}o(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))}o(w,"isPlainJson");function J(e){const{rules:t,...n}=e;return Object.freeze({...n,...t!==void 0?{rules:Object.freeze(t.map(s=>structuredClone(s)))}:{}})}o(J,"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`)}}}o(Z,"assertTimeouts");const z=/^[A-Za-z0-9_-]{1,64}$/,B=new Set(["own","user","allowlist","any"]),Y=/^team:[a-z0-9]+$/;function E(e,t){if(A(e).replace(/-([a-z])/g,(s,i)=>i.toUpperCase())!==e)throw new a(`${t} must round-trip between camelCase and kebab-case`)}o(E,"assertKey");function H(e,t){if(!/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(e))throw new a(`${t} must be lowercase kebab-case`)}o(H,"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}o(A,"kebab");function d(e,t){if(typeof e!="string"||e.length===0)throw new a(`${t} must be a non-empty string`)}o(d,"assertText");function V(e){return e.length>0&&!e.startsWith("/")&&!e.includes("\\")&&e.split("/").every(t=>t.length>0&&t!=="."&&t!=="..")}o(V,"isSafeRelativePath");function u(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}o(u,"isRecord");function r(e,t){throw new a(`${m(e)} ${t}`)}o(r,"fail");function m(e){return e.join(" ")}o(m,"formatPath");export{a as PluginDefinitionError,ne as defineBranch,ee as defineLeaf,ie as definePlugin,te 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 R,outputBaseType as w}from"@north-light/api/command-manifest";class f extends Error{static{s(this,"PluginDefinitionError")}constructor(t){super(t),this.name="PluginDefinitionError"}}function ee(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(ee,"defineLeaf");function te(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(te,"defineStreamingLeaf");function ne(e){return{kind:"branch",...e}}s(ne,"defineBranch");function ie(e){if(H(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))j(n,[e.name,t]);if(e.provider===!0){const t=N(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");K(e.groups,e.commands,e.name)}for(const t of e.memory??[])G(t);return e.objectKinds!==void 0&&_(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:g(e.commands),memory:Object.freeze((e.memory??[]).map(J)),...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(ie,"definePlugin");function K(e,t,n){if(!u(e))throw new f("groups must be an object keyed by group id");for(const[o,i]of Object.entries(e)){if(!k.test(o))throw new f(`group ${JSON.stringify(o)} must match [A-Za-z0-9_-]{1,64}`);if(!u(i))throw new f(`group "${o}" must be an object with consentLine`);const a=Object.keys(i).filter(c=>c!=="consentLine"&&c!=="who"&&c!=="allowlist");if(a.length>0)throw new f(`group "${o}" has unknown keys: ${a.join(", ")}`);if(d(i.consentLine,`group "${o}" consentLine`),i.who!==void 0&&!(typeof i.who=="string"&&(B.has(i.who)||Y.test(i.who))))throw new f(`group "${o}" who must be own, user, allowlist, any, or team:<id>`);if(i.who==="allowlist"){if(!Array.isArray(i.allowlist)||i.allowlist.length===0||!i.allowlist.every(c=>typeof c=="string"&&/^app:.+/.test(c)))throw new f(`group "${o}" allowlist must be a non-empty array of app principals ("app:<id>") when who is allowlist`)}else if(i.allowlist!==void 0)throw new f(`group "${o}" allowlist is only allowed with who: "allowlist"`)}for(const[o,i]of y(t,[n]))i.group!==void 0&&!Object.hasOwn(e,i.group)&&r(o,`names group "${i.group}", which definePlugin groups does not declare`)}s(K,"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 _(e,t,n){if(!u(e))throw new f("objectKinds must be an object keyed by relative kind name");const o={};for(const[a,c]of Object.entries(e)){if(!U.test(a))throw new f(`object kind ${JSON.stringify(a)} must be a lowercase relative name without a "."; the bundle prefixes it with the provider id`);o[`${t}.${a}`]=c}const i=L({object_kinds:o});if(i.length===0){const{leafPaths:a,streamingLeafPaths:c}=F(n);for(const[A,P]of Object.entries(o))i.push(...R(A,P,t,a,c))}if(i.length>0)throw new f(i.join("; "))}s(_,"validateObjectKinds");function F(e){const t=new Set,n=new Set;for(const[o,i]of y(e,[])){const a=o.map(E).join(" ");t.add(a),i.streaming&&n.add(a)}return{leafPaths:t,streamingLeafPaths:n}}s(F,"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(([o,i])=>[o,Object.freeze({...i})]))),...n.read!==void 0?{read:Object.freeze({command:Object.freeze([...n.read.command])})}:{}})])))}s(M,"snapshotObjectKinds");function N(e,t){for(const[n,o]of y(e,t))if(o.group===void 0)return n}s(N,"firstLeafWithoutGroup");function*y(e,t){for(const[n,o]of Object.entries(e)){const i=[...t,n];o.kind==="leaf"?yield[i,o]:yield*y(o.children,i)}}s(y,"leavesOf");function g(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,C(n)])))}s(g,"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:g(e.children)}):Object.freeze({kind:"leaf",description:e.description,whenToUse:e.whenToUse,summary:e.summary,...e.tier!==void 0?{tier:e.tier}:{},params:W(e.params),output:p(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 W(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,q(n)])))}s(W,"snapshotParams");function q(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:b(e.shape)}):Object.freeze({...e})}s(q,"snapshotParam");function p(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,b(n)])))}s(p,"snapshotOutput");function b(e){return Object.freeze({...e,...e.children!==void 0?{children:p(e.children)}:{},...e.extra!==void 0?{extra:b(e.extra)}:{},...e.items!==void 0?{items:b(e.items)}:{},...e.variants!==void 0?{variants:Object.freeze(e.variants.map(b))}:{},...e.values!==void 0?{values:Object.freeze([...e.values])}:{}})}s(b,"snapshotField");function j(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"),z(n,`${m(t)} command key`),e.kind==="branch"){u(e.children)||r(t,"branch children must be an object");for(const[i,a]of Object.entries(e.children))j(a,[...t,i]);return}e.group!==void 0&&(typeof e.group!="string"||!k.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,a]of Object.entries(e.params))z(i,`${m(t)} parameter key`),D(a,[...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 o;for(const[i,a]of Object.entries(e.output))i.length===0&&r(t,"output field names must not be empty"),l(a,[...t,`output ${i}`],!0),w(a.type)==="file"&&(o!==void 0&&r(t,`declares file outputs ${o} and ${i}; a leaf may declare at most one file output`),o=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(j,"validateNode");function D(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(o=>typeof o=="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"?l(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(D,"validateParam");function l(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 o=w(e.type);if(e.kind!==void 0&&o!=="file"&&r(t,"is a parameter descriptor; declare output fields with field.*"),x(e.type)&&o!=="file"&&r(t,`has type ${e.type}; a file output is one file, declared file or file | null`),o==="file"&&!n&&r(t,"is a file, which is only valid as a top-level output field"),e.children!==void 0){o!=="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,a]of Object.entries(e.children))i.length===0&&r(t,"member names must not be empty"),l(a,[...t,`member ${i}`],!1)}e.extra!==void 0&&((o!=="object"||e.children===void 0)&&r(t,"extra is only valid on an object field with children"),l(e.extra,[...t,"extra"],!1)),e.items!==void 0&&(o!=="array"&&o!=="map"&&r(t,"items are only valid on an array or map field"),l(e.items,[...t,"items"],!1)),o==="map"&&e.items===void 0&&r(t,"a map field needs the shape of its values"),e.variants!==void 0&&o!=="union"&&r(t,"variants are only valid on a union field"),o==="union"&&((!Array.isArray(e.variants)||e.variants.length<2)&&r(t,"a union field needs two or more variants"),e.variants.forEach((i,a)=>l(i,[...t,`variant ${a}`],!1))),e.values!==void 0&&(o!=="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(l,"validateField");function G(e){if(!u(e)||typeof e.name!="string"||!V(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)=>I(t,`memory document ${e.name} rules[${n}]`))}}s(G,"validateMemoryDoc");const v=["boot","file-read","document-read","command","pre-command"],O=["on","deliver","match","matchFrontmatter","if"];function I(e,t){if(!u(e))throw new f(`${t} must be an object`);for(const n of Object.keys(e))if(!O.includes(n))throw new f(`${t} has unknown key ${n}; a rule carries only ${O.join(", ")}`);if(typeof e.on!="string"||!v.includes(e.on))throw new f(`${t} on must be one of ${v.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`);$(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&&$(e.if,`${t} if`)}s(I,"validateMemoryRule");function $(e,t){if(!u(e))throw new f(`${t} must be a field\u2192matcher object`);if(!h(e,0))throw new f(`${t} must hold only strings, finite numbers, booleans, null, arrays and plain objects`)}s($,"assertCondition");function h(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=>h(n,t+1)):!u(e)||Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null?!1:Object.values(e).every(n=>h(n,t+1))}s(h,"isPlainJson");function J(e){const{rules:t,...n}=e;return Object.freeze({...n,...t!==void 0?{rules:Object.freeze(t.map(o=>structuredClone(o)))}:{}})}s(J,"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 k=/^[A-Za-z0-9_-]{1,64}$/,B=new Set(["own","user","allowlist","any"]),Y=/^team:[a-z0-9]+$/;function z(e,t){if(E(e).replace(/-([a-z])/g,(o,i)=>i.toUpperCase())!==e)throw new f(`${t} must round-trip between camelCase and kebab-case`)}s(z,"assertKey");function H(e,t){if(!/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(e))throw new f(`${t} must be lowercase kebab-case`)}s(H,"assertKebabName");function E(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(E,"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 V(e){return e.length>0&&!e.startsWith("/")&&!e.includes("\\")&&e.split("/").every(t=>t.length>0&&t!=="."&&t!=="..")}s(V,"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,ne as defineBranch,ee as defineLeaf,ie as definePlugin,te as defineStreamingLeaf,E as kebab};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/plugin",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.543",
|
|
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.
|
|
31
|
-
"@north-light/identity": "0.3.
|
|
30
|
+
"@north-light/api": "0.3.543",
|
|
31
|
+
"@north-light/identity": "0.3.543"
|
|
32
32
|
},
|
|
33
33
|
"license": "UNLICENSED",
|
|
34
34
|
"publishConfig": {
|