@north-light/plugin 0.3.855 → 0.3.856
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/bundle.js +5 -5
- package/dist/define.d.ts +4 -0
- package/dist/define.js +1 -1
- package/dist/kind-spec.d.ts +2 -0
- package/dist/kind-spec.js +1 -0
- package/package.json +3 -3
package/dist/bundle.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var y=Object.defineProperty;var r=(n,t)=>y(n,"name",{value:t,configurable:!0});import{objectBlocksShapeReasons as w}from"@north-light/api/command-manifest";import{PluginDefinitionError as i}from"./define.js";import{buildCommandManifest as
|
|
2
|
-
`,s=
|
|
3
|
-
`,f=
|
|
1
|
+
var y=Object.defineProperty;var r=(n,t)=>y(n,"name",{value:t,configurable:!0});import{objectBlocksShapeReasons as w}from"@north-light/api/command-manifest";import{manifestKindSpec as p}from"./kind-spec.js";import{PluginDefinitionError as i}from"./define.js";import{buildCommandManifest as $}from"./manifest.js";const c=512,S=100,u=new TextEncoder;async function D(n,t){const e=$(n,{...t,mountPath:t.mountPath===""?"/":t.mountPath}),o=`${JSON.stringify(e,null,2)}
|
|
2
|
+
`,s=j(n,t.providerId??n.name),a=`${JSON.stringify({bundleVersion:1,...n.version!==void 0?{version:n.version}:{},...n.groups!==void 0?{groups:g(n.groups)}:{},...s!==void 0?{object_kinds:s}:{},...n.memoryExtensions!==void 0?{memory_extensions:n.memoryExtensions}:{}})}
|
|
3
|
+
`,f=k(n.memory),l=[{path:"bundle.json",contents:a},{path:"commands.json",contents:o},...f],h=U(l),b=await N(h);return{commandsJson:o,bundleJson:a,memory:f,tar:h,etag:b}}r(D,"buildBundle");function g(n){return Object.fromEntries(Object.entries(n).map(([t,e])=>[t,{consent_line:e.consentLine,...e.who!==void 0?{who:e.who}:{},...e.allowlist!==void 0?{allowlist:e.allowlist}:{}}]))}r(g,"groupsBlock");function j(n,t){if(n.objectKinds===void 0)return;const e=Object.fromEntries(Object.entries(n.objectKinds).map(([s,a])=>[`${t}.${s}`,p(a)])),o=w({object_kinds:e});if(o.length>0)throw new i(o.join("; "));return e}r(j,"objectKindsBlock");function k(n){const t=new Set;return n.map(e=>{const o=E(e);if(t.has(o))throw new i(`memory document "${e.name}" produces a duplicate tar member path ${o}`);return t.add(o),{path:o,contents:x(e)}})}r(k,"buildMemoryMembers");function E(n){if(n.name.includes("\0"))throw new i(`memory document "${n.name}" must not contain a NUL character`);const t=`memory/${n.name}.md`;if(u.encode(t).length>S)throw new i(`memory document "${n.name}" produces a tar member path longer than 100 bytes (${t}); shorten its name`);return t}r(E,"memoryMemberPath");function x(n){const t=[`kind: ${n.kind}`,`when-and-why-to-read: ${B(n.whenAndWhyToRead)}`];return n.unlisted===!0&&t.push("unlisted: true"),n.rules!==void 0&&n.rules.length>0&&t.push(`surfaces: ${JSON.stringify(n.rules.map(O))}`),`---
|
|
4
4
|
${t.join(`
|
|
5
5
|
`)}
|
|
6
6
|
---
|
|
7
|
-
${n.body}`}r(
|
|
8
|
-
`:t+="\\n";break;case" ":t+="\\t";break;case"\r":t+="\\r";break;default:t+=e.charCodeAt(0)<=31||e==="\x7F"?`\\x${e.charCodeAt(0).toString(16).padStart(2,"0")}`:e}return`${t}"`}r(
|
|
7
|
+
${n.body}`}r(x,"renderMemoryDoc");const A={boot:"boot","file-read":"read","document-read":"memory-read",command:"command","pre-command":"pre-command"};function O(n){return{on:A[n.on],at:n.deliver,...n.match!==void 0?{match:n.match}:{},...n.matchFrontmatter!==void 0?{"match-frontmatter":n.matchFrontmatter}:{},...n.if!==void 0?{gate:n.if}:{}}}r(O,"surfaceEntry");function B(n){let t='"';for(const e of n)switch(e){case"\\":t+="\\\\";break;case'"':t+='\\"';break;case`
|
|
8
|
+
`:t+="\\n";break;case" ":t+="\\t";break;case"\r":t+="\\r";break;default:t+=e.charCodeAt(0)<=31||e==="\x7F"?`\\x${e.charCodeAt(0).toString(16).padStart(2,"0")}`:e}return`${t}"`}r(B,"yamlDoubleQuoted");function U(n){const t=[];for(const e of n){const o=u.encode(e.contents);t.push(C(e.path,o.length)),t.push(o);const s=_(o.length);s>0&&t.push(new Uint8Array(s))}return t.push(new Uint8Array(c)),t.push(new Uint8Array(c)),M(t)}r(U,"writeTar");function _(n){const t=n%c;return t===0?0:c-t}r(_,"padLength");function C(n,t){const e=new Uint8Array(c);return m(e,0,n),d(e,100,8,420),d(e,108,8,0),d(e,116,8,0),d(e,124,12,t),d(e,136,12,0),e.fill(32,148,156),e[156]=48,m(e,257,"ustar\0"),m(e,263,"00"),F(e,148,K(e)),e}r(C,"ustarHeader");function m(n,t,e){n.set(u.encode(e),t)}r(m,"writeAscii");function d(n,t,e,o){const s=e-1,a=o.toString(8).padStart(s,"0");if(a.length>s)throw new i(`tar header field at offset ${t} cannot hold value ${o} in ${s} octal digits`);m(n,t,a)}r(d,"writeOctalField");function F(n,t,e){m(n,t,e.toString(8).padStart(6,"0")),n[t+6]=0,n[t+7]=32}r(F,"writeChecksumField");function K(n){let t=0;for(const e of n)t+=e;return t}r(K,"sumBytes");function M(n){const t=n.reduce((s,a)=>s+a.length,0),e=new Uint8Array(t);let o=0;for(const s of n)e.set(s,o),o+=s.length;return e}r(M,"concatBytes");async function N(n){const t=new Uint8Array(await crypto.subtle.digest("SHA-256",n));return`"${Array.from(t,o=>o.toString(16).padStart(2,"0")).join("")}"`}r(N,"sha256Etag");export{D as buildBundle};
|
package/dist/define.d.ts
CHANGED
|
@@ -192,6 +192,10 @@ export interface ObjectKindSpec {
|
|
|
192
192
|
readonly read?: {
|
|
193
193
|
readonly command: readonly string[];
|
|
194
194
|
};
|
|
195
|
+
/** The leaf the runtime calls, as the object's person, when the object's last watcher leaves: a non-streaming leaf of this plugin. */
|
|
196
|
+
readonly onUnwatched?: {
|
|
197
|
+
readonly command: readonly string[];
|
|
198
|
+
};
|
|
195
199
|
}
|
|
196
200
|
/** A validated, frozen plugin, as returned by `definePlugin`. */
|
|
197
201
|
export interface PluginDefinition {
|
package/dist/define.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var P=Object.defineProperty;var s=(e,t)=>P(e,"name",{value:t,configurable:!0});import{LOCAL as T,mentionsFile as U,objectBlocksShapeReasons as L,validateMemoryExtensionDeclarations as R,objectKindReadReasons as S,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 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:!1,run:s((t,n)=>Promise.resolve(e.handler(t,n)),"run")}}s(te,"defineLeaf");function ne(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(ne,"defineStreamingLeaf");function ie(e){return{kind:"branch",...e}}s(ie,"defineBranch");function re(e){if(V(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"),B(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=C(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??[])I(t);if(e.objectKinds!==void 0&&M(e.objectKinds,e.name,e.commands),e.memoryExtensions!==void 0){if(e.provider===!0)throw new f("memoryExtensions cannot be declared by a provider plugin: the runtime refuses a provider bundle that carries memory_extensions, so the directory would never serve it");try{R(e.memoryExtensions)}catch(t){throw new f(t instanceof Error?t.message:String(t))}}return 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(Z)),...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:N(e.objectKinds)}:{},...e.groups!==void 0?{groups:_(e.groups)}:{},...e.memoryExtensions!==void 0?{memoryExtensions:structuredClone(e.memoryExtensions)}:{}})}s(re,"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(m=>m!=="consentLine"&&m!=="who"&&m!=="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"&&(Y.has(i.who)||H.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(m=>typeof m=="string"&&/^app:.+/.test(m)))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 b(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 _(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(_,"snapshotGroups");function M(e,t,n){if(!u(e))throw new f("objectKinds must be an object keyed by relative kind name");const o={};for(const[a,m]of Object.entries(e)){if(!T.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}`]=m}const i=L({object_kinds:o});if(i.length===0){const{leafPaths:a,streamingLeafPaths:m}=F(n);for(const[A,x]of Object.entries(o))i.push(...S(A,x,t,a,m))}if(i.length>0)throw new f(i.join("; "))}s(M,"validateObjectKinds");function F(e){const t=new Set,n=new Set;for(const[o,i]of b(e,[])){const a=o.map(z).join(" ");t.add(a),i.streaming&&n.add(a)}return{leafPaths:t,streamingLeafPaths:n}}s(F,"leafPathsOf");function N(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(N,"snapshotObjectKinds");function C(e,t){for(const[n,o]of b(e,t))if(o.group===void 0)return n}s(C,"firstLeafWithoutGroup");function*b(e,t){for(const[n,o]of Object.entries(e)){const i=[...t,n];o.kind==="leaf"?yield[i,o]:yield*b(o.children,i)}}s(b,"leavesOf");function g(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,D(n)])))}s(g,"snapshotCommands");function D(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(D,"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:y(e.shape)}):Object.freeze({...e})}s(q,"snapshotParam");function p(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,y(n)])))}s(p,"snapshotOutput");function y(e){return Object.freeze({...e,...e.children!==void 0?{children:p(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 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,`${c(t)} description`),d(e.whenToUse,`${c(t)} whenToUse`),d(e.summary,`${c(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,`${c(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))E(i,`${c(t)} parameter key`),G(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 G(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,`${c(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(G,"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.*"),U(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 I(e){if(!u(e)||typeof e.name!="string"||!Q(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)=>J(t,`memory document ${e.name} rules[${n}]`))}}s(I,"validateMemoryDoc");const v=["boot","file-read","document-read","command","pre-command"],O=["on","deliver","match","matchFrontmatter","if"];function J(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(J,"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 Z(e){const{rules:t,...n}=e;return Object.freeze({...n,...t!==void 0?{rules:Object.freeze(t.map(o=>structuredClone(o)))}:{}})}s(Z,"freezeMemoryDoc");function B(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(B,"assertTimeouts");const k=/^[A-Za-z0-9_-]{1,64}$/,Y=new Set(["own","user","allowlist","any"]),H=/^team:[a-z0-9]+$/;function E(e,t){if(z(e).replace(/-([a-z])/g,(o,i)=>i.toUpperCase())!==e)throw new f(`${t} must round-trip between camelCase and kebab-case`)}s(E,"assertKey");function V(e,t){if(!/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(e))throw new f(`${t} must be lowercase kebab-case`)}s(V,"assertKebabName");function z(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(z,"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 Q(e){return e.length>0&&!e.startsWith("/")&&!e.includes("\\")&&e.split("/").every(t=>t.length>0&&t!=="."&&t!=="..")}s(Q,"isSafeRelativePath");function u(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}s(u,"isRecord");function r(e,t){throw new f(`${c(e)} ${t}`)}s(r,"fail");function c(e){return e.join(" ")}s(c,"formatPath");export{f as PluginDefinitionError,ie as defineBranch,te as defineLeaf,re as definePlugin,ne as defineStreamingLeaf,z as kebab};
|
|
1
|
+
var P=Object.defineProperty;var s=(e,t)=>P(e,"name",{value:t,configurable:!0});import{LOCAL as U,mentionsFile as T,objectBlocksShapeReasons as L,validateMemoryExtensionDeclarations as S,objectKindReadReasons as K,outputBaseType as w}from"@north-light/api/command-manifest";import{manifestKindSpec as R}from"./kind-spec.js";class f extends Error{static{s(this,"PluginDefinitionError")}constructor(t){super(t),this.name="PluginDefinitionError"}}function ie(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(ie,"defineLeaf");function re(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(re,"defineStreamingLeaf");function oe(e){return{kind:"branch",...e}}s(oe,"defineBranch");function se(e){if(Q(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"),Y(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=D(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");_(e.groups,e.commands,e.name)}for(const t of e.memory??[])J(t);if(e.objectKinds!==void 0&&F(e.objectKinds,e.name,e.commands),e.memoryExtensions!==void 0){if(e.provider===!0)throw new f("memoryExtensions cannot be declared by a provider plugin: the runtime refuses a provider bundle that carries memory_extensions, so the directory would never serve it");try{S(e.memoryExtensions)}catch(t){throw new f(t instanceof Error?t.message:String(t))}}return 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(B)),...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:C(e.objectKinds)}:{},...e.groups!==void 0?{groups:M(e.groups)}:{},...e.memoryExtensions!==void 0?{memoryExtensions:structuredClone(e.memoryExtensions)}:{}})}s(se,"definePlugin");function _(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(m=>m!=="consentLine"&&m!=="who"&&m!=="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"&&(H.has(i.who)||V.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(m=>typeof m=="string"&&/^app:.+/.test(m)))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 b(t,[n]))i.group!==void 0&&!Object.hasOwn(e,i.group)&&r(o,`names group "${i.group}", which definePlugin groups does not declare`)}s(_,"validateGroups");function M(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(M,"snapshotGroups");function F(e,t,n){if(!u(e))throw new f("objectKinds must be an object keyed by relative kind name");const o={};for(const[a,m]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}`]=R(m)}const i=L({object_kinds:o});if(i.length===0){const{leafPaths:a,streamingLeafPaths:m}=N(n);for(const[A,x]of Object.entries(o))i.push(...K(A,x,t,a,m))}if(i.length>0)throw new f(i.join("; "))}s(F,"validateObjectKinds");function N(e){const t=new Set,n=new Set;for(const[o,i]of b(e,[])){const a=o.map(z).join(" ");t.add(a),i.streaming&&n.add(a)}return{leafPaths:t,streamingLeafPaths:n}}s(N,"leafPathsOf");function C(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])})}:{},...n.onUnwatched!==void 0?{onUnwatched:Object.freeze({command:Object.freeze([...n.onUnwatched.command])})}:{}})])))}s(C,"snapshotObjectKinds");function D(e,t){for(const[n,o]of b(e,t))if(o.group===void 0)return n}s(D,"firstLeafWithoutGroup");function*b(e,t){for(const[n,o]of Object.entries(e)){const i=[...t,n];o.kind==="leaf"?yield[i,o]:yield*b(o.children,i)}}s(b,"leavesOf");function g(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,W(n)])))}s(g,"snapshotCommands");function W(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:q(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(W,"snapshotNode");function q(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,G(n)])))}s(q,"snapshotParams");function G(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(G,"snapshotParam");function p(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([t,n])=>[t,y(n)])))}s(p,"snapshotOutput");function y(e){return Object.freeze({...e,...e.children!==void 0?{children:p(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 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,`${c(t)} description`),d(e.whenToUse,`${c(t)} whenToUse`),d(e.summary,`${c(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,`${c(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))E(i,`${c(t)} parameter key`),I(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 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,`${c(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(I,"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.*"),T(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 J(e){if(!u(e)||typeof e.name!="string"||!X(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)=>Z(t,`memory document ${e.name} rules[${n}]`))}}s(J,"validateMemoryDoc");const v=["boot","file-read","document-read","command","pre-command"],O=["on","deliver","match","matchFrontmatter","if"];function Z(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(Z,"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 B(e){const{rules:t,...n}=e;return Object.freeze({...n,...t!==void 0?{rules:Object.freeze(t.map(o=>structuredClone(o)))}:{}})}s(B,"freezeMemoryDoc");function Y(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(Y,"assertTimeouts");const k=/^[A-Za-z0-9_-]{1,64}$/,H=new Set(["own","user","allowlist","any"]),V=/^team:[a-z0-9]+$/;function E(e,t){if(z(e).replace(/-([a-z])/g,(o,i)=>i.toUpperCase())!==e)throw new f(`${t} must round-trip between camelCase and kebab-case`)}s(E,"assertKey");function Q(e,t){if(!/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(e))throw new f(`${t} must be lowercase kebab-case`)}s(Q,"assertKebabName");function z(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(z,"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 X(e){return e.length>0&&!e.startsWith("/")&&!e.includes("\\")&&e.split("/").every(t=>t.length>0&&t!=="."&&t!=="..")}s(X,"isSafeRelativePath");function u(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}s(u,"isRecord");function r(e,t){throw new f(`${c(e)} ${t}`)}s(r,"fail");function c(e){return e.join(" ")}s(c,"formatPath");export{f as PluginDefinitionError,oe as defineBranch,ie as defineLeaf,se as definePlugin,re as defineStreamingLeaf,z as kebab};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var o=Object.defineProperty;var r=(n,t)=>o(n,"name",{value:t,configurable:!0});function u(n){if(typeof n!="object"||n===null||Array.isArray(n))return n;const{onUnwatched:t,...e}=n;return t===void 0?n:{...e,on_unwatched:t}}r(u,"manifestKindSpec");export{u as manifestKindSpec};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/plugin",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.856",
|
|
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.856",
|
|
31
|
+
"@north-light/identity": "0.3.856"
|
|
32
32
|
},
|
|
33
33
|
"license": "UNLICENSED",
|
|
34
34
|
"publishConfig": {
|