@chatpanel/events 0.389.0 → 0.392.0
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/apple-notes-source.js +32 -0
- package/backup-records.js +1 -1
- package/default-mcp-servers.js +1 -1
- package/feature-map.js +1 -1
- package/folders.js +1 -0
- package/html-markdown.js +24 -0
- package/index.js +1 -1
- package/library.js +6 -6
- package/link-sync.js +4 -4
- package/mcp-manager.js +1 -1
- package/mcp-registry.js +1 -1
- package/note-merge.js +7 -7
- package/notes-import.js +3 -0
- package/onenote-source.js +1 -0
- package/package.json +11 -1
- package/settings-registry.js +1 -1
package/note-merge.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
const
|
|
1
|
+
const j="<!-- conflict:start -->",C="<!-- conflict:other -->",L="<!-- conflict:end -->",y=/<!-- conflict:start -->\n([\s\S]*?)\n<!-- conflict:other -->\n([\s\S]*?)\n<!-- conflict:end -->/g,K=4e3;function S(t){const c=String(t??"").replace(/\r\n?/g,`
|
|
2
2
|
`).split(`
|
|
3
3
|
`),o=[];let e=[],n=null;const r=()=>{e.length&&(o.push(e.join(`
|
|
4
|
-
`)),e=[])};for(const
|
|
4
|
+
`)),e=[])};for(const l of c){const i=/^\s*(`{3,}|~{3,})/.exec(l);if(n){e.push(l),i&&i[1][0]===n[0]&&i[1].length>=n.length&&(n=null,r());continue}if(i){r(),n=i[1],e.push(l);continue}if(!l.trim()){r();continue}/^\s*(?:[-*+]|\d+[.)])\s+/.test(l)&&e.length&&r(),e.push(l)}return r(),o}const w=/^\s*(?:[-*+]|\d+[.)])\s+/,g=t=>t.reduce((c,o,e)=>e===0?o:`${c}${w.test(o)&&w.test(t[e-1])?`
|
|
5
5
|
`:`
|
|
6
6
|
|
|
7
|
-
`}${o}`,"");function k(t,
|
|
7
|
+
`}${o}`,"");function k(t,c){const o=t.length,e=c.length,n=Array.from({length:o+1},()=>new Uint32Array(e+1));for(let f=o-1;f>=0;f--)for(let d=e-1;d>=0;d--)n[f][d]=t[f]===c[d]?n[f+1][d+1]+1:Math.max(n[f+1][d],n[f][d+1]);const r=[];let l=0,i=0;for(;l<o&&i<e;)t[l]===c[i]?(r.push([l,i]),l++,i++):n[l+1][i]>=n[l][i+1]?l++:i++;return r}const A=(t,c)=>`${j}
|
|
8
8
|
${g(t)}
|
|
9
|
-
${
|
|
10
|
-
${g(
|
|
11
|
-
${
|
|
9
|
+
${C}
|
|
10
|
+
${g(c)}
|
|
11
|
+
${L}`;function N({base:t=null,ours:c="",theirs:o=""}={}){const e=String(c??""),n=String(o??"");if(e===n)return{markdown:e,conflicts:0,clean:!0};if(t!=null&&String(t)===e)return{markdown:n,conflicts:0,clean:!0};if(t!=null&&String(t)===n)return{markdown:e,conflicts:0,clean:!0};const r=S(e),l=S(n);return r.length>4e3||l.length>4e3?{markdown:A(r,l),conflicts:1,clean:!1}:t==null?I(r,l):_(S(t),r,l)}function I(t,c){const o=[];let e=0,n=0,r=0;for(const[l,i]of[...k(t,c),[t.length,c.length]]){const f=t.slice(n,l),d=c.slice(r,i);f.length&&d.length?(o.push(A(f,d)),e++):o.push(...f,...d),l<t.length&&o.push(t[l]),n=l+1,r=i+1}return{markdown:g(o),conflicts:e,clean:e===0}}function M(t,c){const o=[];let e=0,n=0;for(const[r,l]of[...k(t,c),[t.length,c.length]])(r>e||l>n)&&o.push({s:e,e:r,xs:n,xe:l}),e=r+1,n=l+1;return o}function _(t,c,o){const e=[...M(t,c).map(s=>({...s,side:"o"})),...M(t,o).map(s=>({...s,side:"t"}))].sort((s,u)=>s.s-u.s||s.e-u.e||(s.side==="o"?-1:1)),n=[];for(const s of e){const u=n[n.length-1];u&&(s.s<u.e||s.s===u.e&&s.s===s.e&&u.s===u.e)?(u.e=Math.max(u.e,s.e),u[s.side].push(s)):n.push({s:s.s,e:s.e,o:s.side==="o"?[s]:[],t:s.side==="t"?[s]:[]})}const r=(s,u,a,h)=>{const m=[];let x=u;for(const p of s)m.push(...t.slice(x,p.s),...h.slice(p.xs,p.xe)),x=p.e;return m.push(...t.slice(x,a)),m},l=(s,u)=>s.length===u.length&&s.every((a,h)=>a===u[h]),i=[];let f=0,d=0;for(const s of n){i.push(...t.slice(d,s.s));const u=r(s.o,s.s,s.e,c),a=r(s.t,s.s,s.e,o);s.t.length?s.o.length?l(u,a)?i.push(...u):s.s===s.e?i.push(...u,...a.filter(h=>!u.includes(h))):(i.push(A(u,a)),f++):i.push(...a):i.push(...u),d=s.e}return i.push(...t.slice(d)),{markdown:g(i),conflicts:f,clean:f===0}}function $(t,c,o,e){const n=(r,l)=>JSON.stringify(r??null)===JSON.stringify(l??null);return n(c,o)?c:t!==void 0&&n(t,c)?o:t!==void 0&&n(t,o)||e?c:o}function T(t,c,o){const e=Array.isArray(c)?c:[],n=Array.isArray(o)?o:[];if(!Array.isArray(t))return[...new Set([...n,...e])];const r=new Set(t.filter(l=>!e.includes(l)||!n.includes(l)));return[...new Set([...n,...e])].filter(l=>!r.has(l)||!t.includes(l))}function D({base:t=null,ours:c,theirs:o,now:e=0}={}){const n=u=>Number(u?.updatedAt)||0,r=n(c)>n(o),l=r?c:o,i=r?o:c,f=u=>String(u?.body?.markdown??""),d=t?N({base:String(t.markdown??""),ours:f(c),theirs:f(o)}):{markdown:f(l),conflicts:0};return{record:{...i,...l,title:$(t?t.title:void 0,c?.title,o?.title,r),tags:T(t?t.tags:void 0,c?.tags,o?.tags),body:v({...i?.body||{},...l?.body||{},markdown:d.markdown},$(t&&"folder"in t?t.folder??null:void 0,c?.body?.folder??null,o?.body?.folder??null,r)),meta:{...i?.meta||{},...l?.meta||{}},updatedAt:Math.max(n(c),n(o),Number(e)||0)},conflicts:d.conflicts}}function v(t,c){const{folder:o,...e}=t;return c?{...e,folder:c}:e}function E(t){return[...String(t??"").matchAll(y)].map((c,o)=>({index:o,ours:c[1],theirs:c[2]}))}function F(t,c,o="ours"){let e=-1;return String(t??"").replace(y,(n,r,l)=>(e++,e!==c?n:o==="theirs"?l:o==="both"?`${r}
|
|
12
12
|
|
|
13
|
-
${
|
|
13
|
+
${l}`:r))}function J({ours:t=null,theirs:c=null,base:o=null}={}){const e={text:String(t?.text??""),at:Number(t?.updatedAt)||0},n={text:String(c?.text??""),at:Number(c?.updatedAt)||0},r={text:n.text};if(e.text===n.text)return o?.text===n.text?null:{text:e.text,updatedAt:Math.max(e.at,n.at),base:r,conflicts:0};if(o&&typeof o.text=="string"){const l=N({base:o.text,ours:e.text,theirs:n.text});return{text:l.markdown,updatedAt:Math.max(e.at,n.at),base:r,conflicts:l.conflicts}}return n.at>e.at?{text:n.text,updatedAt:n.at,base:r,conflicts:0}:{text:e.text,updatedAt:e.at,base:r,conflicts:0}}export{K as MAX_BLOCKS,E as conflictsIn,N as mergeNote,D as mergeNoteRecords,F as resolveConflict,S as splitBlocks,J as syncNote};
|
package/notes-import.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{makeFolder as V,findSourceFolder as W,MAX_FOLDER_DEPTH as Z}from"./folders.js";import{htmlToMarkdown as v}from"./html-markdown.js";import{contentHash as A}from"./knowledge.js";import{deriveTitle as tt}from"./library.js";import{noteImageRef as et,NOTE_IMAGE_TYPES as nt,MAX_NOTE_IMAGE_BYTES as ot}from"./note-images.js";const rt=Object.freeze({onenote:"OneNote","apple-notes":"Apple Notes"}),L=200,U="import-img:",z=n=>Number.isFinite(Number(n))?Number(n):0,N=n=>n==null?"":String(n),C=(n,r)=>{if(n==null||n==="")return r;const s=typeof n=="number"?n:Date.parse(String(n));return Number.isFinite(s)&&s>0?s:r};function at(n,r){if(!r)return"create";if(z(r.deletedAt))return"deleted";const s=N(r.body?.source?.updatedAt);return s&&s===N(n.updatedAt)?"unchanged":"fetch"}function it(n,r){const s=n.body?.source||{};return A(r)===s.hash?"same":A(String(n.body?.markdown??""))===s.written?"replace":"copy"}function st(n){const r=/^data:([a-z0-9.+/-]+);base64,([a-z0-9+/=\s]+)$/i.exec(n);return r?{mediaType:r[1].toLowerCase(),base64:r[2].replace(/\s+/g,"")}:null}async function mt({adapter:n,store:r,newId:s,now:_=()=>Date.now(),signal:H,onProgress:X,maxDepth:B=Z,batch:G=20,concurrency:Y=3}={}){if(!n?.app||typeof n.children!="function"||typeof n.page!="function")throw new Error("runImport needs an adapter with app, children() and page()");if(typeof s!="function")throw new Error("runImport needs newId()");const w=n.app,S=n.label||rt[w]||w,i={created:0,updated:0,unchanged:0,deleted:0,copies:0,folders:0,images:0,failed:[],aborted:!1},E=(e="")=>X?.({...i,failed:i.failed.length,current:e}),y=()=>(H?.aborted&&(i.aborted=!0),i.aborted),x=[...await r.folders()||[]],j=await r.notesBySource(w)||new Map,T=[],F=(e,d,t)=>{const a=W(x,{app:w,id:e});if(a)return a.id;const o=V({name:String(d||"").trim()||"Untitled",parent:t,source:{app:w,id:e},newId:s,now:_()});return x.push(o),T.push(o),i.folders++,o.id},M=async()=>{T.length&&await r.putFolders(T.splice(0))},q=F("root",S,null),g=[],P=async(e=!1)=>{g.length&&(e||g.length>=G)&&await r.putNotes(g.splice(0))},O=async(e,d,t)=>{let a=d;for(let o=0;o<t.length;o++){const{src:l,info:c}=t[o];let u="";try{const p=st(l)||(n.image?await n.image(l,c):null),k=p?Math.floor(p.base64.length*3/4):0;if(p&&r.putImage&&nt.includes(p.mediaType)&&k<=ot){const h=await r.putImage(e,p);h&&(u=et(h,c.alt||"image"),i.images++)}}catch{}a=a.replace(new RegExp(`!\\[[^\\]\\n]*\\]\\(${U}${o}\\)`),u)}return a.replace(/\n{3,}/g,`
|
|
2
|
+
|
|
3
|
+
`).trim()},J=e=>{const d=[],{markdown:t,title:a}=v(e,{image:(o,l)=>(d.push({src:o,info:l}),`${U}${d.length-1}`)});return{markdown:t,title:a,images:d}},K=async(e,d)=>{if(y())return;const t=j.get(String(e.id))||null,a=at(e,t);if(a==="unchanged"){i.unchanged++;return}if(a==="deleted"){i.deleted++;return}let o;try{o=await n.page(e)}catch(m){i.failed.push({title:String(e.title||e.id),error:String(m?.message||m)});return}if(y())return;const l=_(),c=J(o?.html||""),u=String(e.title||o?.title||c.title||"").replace(/\s+/g," ").trim().slice(0,L),p=C(o?.createdAt??e.createdAt,l),k=C(o?.updatedAt??e.updatedAt,p),h=N(o?.updatedAt??e.updatedAt),D=A(c.markdown);if(t){const m=it(t,c.markdown),f=t.body?.source||{};if(m==="same")g.push({...t,body:{...t.body,source:{...f,updatedAt:h}}}),i.unchanged++;else if(m==="replace"){const b=await O(t.id,c.markdown,c.images),I=t.title===(f.title??t.title)&&u?u:t.title;g.push({...t,title:I,updatedAt:Math.max(k,z(t.updatedAt)),body:{...t.body,markdown:b,source:{...f,updatedAt:h,hash:D,written:A(b),title:u}}}),i.updated++}else{const b=`note:${s()}`,I=await O(b,c.markdown,c.images);g.push({...t,body:{...t.body,source:{...f,updatedAt:h}}},{id:b,kind:"note",title:`${u||t.title} (from ${S})`.slice(0,L),tags:[],createdAt:l,updatedAt:l,deletedAt:0,body:{markdown:I,...t.body?.folder?{folder:t.body.folder}:{}},meta:{origin:"import",copyOf:t.id}}),i.copies++}}else{const m=`note:${s()}`,f=await O(m,c.markdown,c.images);g.push({id:m,kind:"note",title:u||tt(f,"Untitled note"),tags:[],createdAt:p,updatedAt:k,deletedAt:0,body:{markdown:f,folder:d,source:{app:w,id:String(e.id),updatedAt:h,hash:D,written:A(f),title:u}},meta:{origin:"import"}}),i.created++}E(u),await P()},Q=async(e,d)=>{let t=0;const a=async()=>{for(;t<e.length&&!y();)await K(e[t++],d)};await Promise.all(Array.from({length:Math.max(1,Math.min(Y,e.length))},a))},$=new Set,R=async(e,d,t)=>{if(y())return;let a;try{a=await n.children(e)}catch(o){i.failed.push({title:String(e?.name||S),error:String(o?.message||o)});return}E(e?.name||S);for(const o of a?.containers||[]){if(y())return;const l=String(o.id);if($.has(l)||t>=B)continue;$.add(l);const c=F(l,o.name,d);await M(),await R(o,c,t+1)}await Q(a?.pages||[],d)};try{await M(),await R(null,q,0)}finally{await M(),await P(!0)}return E(""),i}export{rt as IMPORT_SOURCES,L as MAX_IMPORT_TITLE,at as decidePage,it as decideUpdate,mt as runImport};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const g=Object.freeze(["notes_list_notebooks","notes_list_section_groups","notes_list_sections","notes_list_pages","notes_get_page_content","notes_get_resource"]),u=8*1024*1024,d=500;function m(s){const e=new Set((s||[]).map(o=>typeof o=="string"?o:o?.name));return g.filter(o=>!e.has(o))}function l(s){let e=s?.structuredContent;if(e&&typeof e=="object"&&"result"in e&&Object.keys(e).length===1&&(e=e.result),e===void 0){const o=(s?.content||[]).filter(c=>c?.type==="text").map(c=>c.text).join("");try{e=JSON.parse(o)}catch{e=o}}if(s?.isError||e&&typeof e=="object"&&!Array.isArray(e)&&typeof e.error=="string"){const o=new Error(String(e?.message||e?.error||(typeof e=="string"?e:"the OneNote server refused")));throw o.code=e?.error||"ERROR",o}return e}function f(s){const e=/\/onenote\/resources\/([^/?#]+)\/\$value(?:[?#]|$)/i.exec(String(s||""));return e?decodeURIComponent(e[1]):""}function h({callTool:s}){if(typeof s!="function")throw new Error("oneNoteSource needs callTool()");const e=async(t,r)=>l(await s(t,r)),o=async(t,r)=>{const n=[];let i="";for(let _=0;_<d;_++){const a=await e(t,{...r,page_token:i}),p=Array.isArray(a)?a:a?.items||[];if(n.push(...p),i=Array.isArray(a)?null:a?.next_page_token,!i)break}return n},c=(t,r)=>({id:`${t}:${r.id}`,graphId:String(r.id),kind:t,name:String(r.name||"")});return{app:"onenote",async children(t){if(!t)return{containers:(await o("notes_list_notebooks",{max_results:100})).map(n=>c("nb",n)),pages:[]};if(t.kind==="nb"||t.kind==="sg"){const n=t.kind==="nb"?{notebook_id:t.graphId}:{section_group_id:t.graphId},i=await o("notes_list_section_groups",n),_=await o("notes_list_sections",n);return{containers:[...i.map(a=>c("sg",a)),..._.map(a=>c("s",a))],pages:[]}}const r=await o("notes_list_pages",{section_id:t.graphId,max_results:100});return{containers:[],pages:r.map(n=>({id:String(n.id),title:String(n.title||""),createdAt:n.created_at||"",updatedAt:n.last_modified||""}))}},async page(t){let r="",n=0;for(;;){const i=await e("notes_get_page_content",{page_id:t.id,offset:n});if(r+=String(i?.content_html||""),r.length>u)throw new Error("this page is larger than a note can hold");if(i?.next_offset==null)break;if(!(Number(i.next_offset)>n))throw new Error("the OneNote server did not move on to the rest of the page");n=Number(i.next_offset)}return{html:r,createdAt:t.createdAt,updatedAt:t.updatedAt}},async image(t){const r=f(t);if(!r)return null;const n=await e("notes_get_resource",{resource_id:r});return n?.content_b64?{mediaType:String(n.mime_type||"").toLowerCase(),base64:String(n.content_b64)}:null}}}export{u as MAX_PAGE_HTML,g as ONENOTE_TOOLS,m as missingOneNoteTools,f as oneNoteResourceId,h as oneNoteSource,l as toolValue};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatpanel/events",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.392.0",
|
|
4
4
|
"description": "The canonical ChatPanel event-log and capability contracts — typed durable facts, clock-free deterministic linearization, schema upcasting, and the invariants the replay harness asserts. Pure, dependency-free ESM shared by the ChatPanel extension, gateway and bridge.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -130,6 +130,11 @@
|
|
|
130
130
|
"./page-guard.js": "./page-guard.js",
|
|
131
131
|
"./stitch.js": "./stitch.js",
|
|
132
132
|
"./note-merge.js": "./note-merge.js",
|
|
133
|
+
"./folders.js": "./folders.js",
|
|
134
|
+
"./html-markdown.js": "./html-markdown.js",
|
|
135
|
+
"./notes-import.js": "./notes-import.js",
|
|
136
|
+
"./onenote-source.js": "./onenote-source.js",
|
|
137
|
+
"./apple-notes-source.js": "./apple-notes-source.js",
|
|
133
138
|
"./link-connect.js": "./link-connect.js",
|
|
134
139
|
"./link-sync.js": "./link-sync.js",
|
|
135
140
|
"./link-routes.js": "./link-routes.js",
|
|
@@ -457,6 +462,11 @@
|
|
|
457
462
|
"page-guard.js",
|
|
458
463
|
"stitch.js",
|
|
459
464
|
"note-merge.js",
|
|
465
|
+
"folders.js",
|
|
466
|
+
"html-markdown.js",
|
|
467
|
+
"notes-import.js",
|
|
468
|
+
"onenote-source.js",
|
|
469
|
+
"apple-notes-source.js",
|
|
460
470
|
"link-connect.js",
|
|
461
471
|
"link-sync.js",
|
|
462
472
|
"link-routes.js",
|