buckyos 0.7.183 → 0.7.185
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/cli/dist/cli.mjs +115 -28
- package/cli/dist/cli.mjs.map +1 -1
- package/cli/modules/aiws.ts +93 -21
- package/cli/modules/aiws_place.ts +3 -1
- package/cli/modules/pikg_protocol.ts +1 -1
- package/cli/version.ts +1 -1
- package/dist/aiworkspace_client.d.ts +19 -5
- package/dist/aiworkspace_client.d.ts.map +1 -1
- package/dist/{aiws_bind-82bace11.js → aiws_bind-0654c24e.js} +2 -2
- package/dist/aiws_bind-0654c24e.js.map +1 -0
- package/dist/{aiws_bind-3b874f77.mjs → aiws_bind-0885ff99.mjs} +7 -5
- package/dist/aiws_bind-0885ff99.mjs.map +1 -0
- package/dist/aiws_ext.cjs +1 -1
- package/dist/aiws_ext.mjs +1 -1
- package/dist/{aiws_write-c2de498e.mjs → aiws_write-675664eb.mjs} +5 -3
- package/dist/{aiws_write-c2de498e.mjs.map → aiws_write-675664eb.mjs.map} +1 -1
- package/dist/{aiws_write-89b5cc2a.js → aiws_write-b0333ca1.js} +3 -3
- package/dist/{aiws_write-89b5cc2a.js.map → aiws_write-b0333ca1.js.map} +1 -1
- package/dist/aiws_write.d.ts +5 -1
- package/dist/aiws_write.d.ts.map +1 -1
- package/dist/browser.cjs +1 -1
- package/dist/browser.mjs +4 -4
- package/dist/{content_objid-dff803ff.js → content_objid-252bd154.js} +2 -2
- package/dist/{content_objid-dff803ff.js.map → content_objid-252bd154.js.map} +1 -1
- package/dist/{content_objid-a2cafba9.mjs → content_objid-39f4f273.mjs} +2 -2
- package/dist/{content_objid-a2cafba9.mjs.map → content_objid-39f4f273.mjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +4 -4
- package/dist/node.cjs +1 -1
- package/dist/node.mjs +3 -3
- package/package.json +1 -1
- package/dist/aiws_bind-3b874f77.mjs.map +0 -1
- package/dist/aiws_bind-82bace11.js.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const e=require("./object_url-8fb5a7bf.js");class t extends Error{constructor(e){super(`${e.code}${e.sub_code?`/${e.sub_code}`:""}: ${e.detail}`),this.name="AiwsFailure",this.code=e.code,this.subCode=e.sub_code,this.data=e.data}}function n(e){return e.startsWith("/")||e.startsWith("~")?{path:e}:{entity_id:e}}const r=6291456,o=33554432,i=5e4,a=new TextEncoder;function s(e){const t=JSON.stringify(e);return t.length+(/[^\x00-\x7f]/.test(t)?a.encode(t).length-t.length:0)}function l(e,t=6291456){const n=[];let r=[],o=2;for(const i of e){const e=s(i)+1;r.length>0&&o+e>t&&(n.push(r),r=[],o=2),r.push(i),o+=e}return(r.length>0||0===n.length)&&n.push(r),n}async function d(e,t,n={}){var o,i;const a=n.method??"doc.commit",s=l(Array.isArray(t.operations)?t.operations:[],n.partBytes??r);if(s.length<=1)return await e(a,t);const{workspace_id:d,epoch:c,idempotency_key:u}=t;for(let r=0;;r++){const l=[];for(let t=0;t<s.length-1;t++){null==(o=n.onPart)||o.call(n,t+1,s.length);const r=await e("doc.stage",{workspace_id:d,epoch:c,idempotency_key:u,part:t,operations:s[t]});if(!r||!1===r.ok||"string"!=typeof r.digest){const e=(null==r?void 0:r.error)??{code:"STORAGE_IO_ERROR",retryable:!0,detail:"doc.stage returned no digest"};return{status:"rejected",code:e.code,retryable:e.retryable,detail:e.detail,...e.sub_code?{sub_code:e.sub_code}:{},errors:[e]}}l.push(r.digest)}null==(i=n.onPart)||i.call(n,s.length,s.length);const y=await e(a,{...t,staged:l,operations:s[s.length-1]});if(0!==r||"rejected"!==(null==y?void 0:y.status)||"STAGED_PARTS_MISSING"!==y.sub_code)return y}}const c=["MO","TU","WE","TH","FR","SA","SU"];class u extends Error{constructor(e){super(e),this.name="RRuleError"}}const y=["DAILY","WEEKLY","MONTHLY","YEARLY"];function p(e,t,n,r,o=!1){if(!/^[+-]?\d{1,3}$/.test(t))throw new u(`${e}: ${t} is not a number`);const i=Number(t);if(i<n||i>r||!o&&0===i)throw new u(`${e}: ${t} is out of range`);return i}function f(e,t,n){const r=t.split(",");if(0===r.length||r.length>n||r.some((e=>""===e)))throw new u(`${e}: at most ${n} comma-separated values`);return r}function h(e){const t=e.startsWith("RRULE:")?e.slice(6):e;if(""===t.trim())throw new u("empty rule");const n=new Set,r={};for(const a of t.split(";")){const e=a.indexOf("=");if(e<=0)throw new u(`${a||"(empty)"}: expected NAME=VALUE`);const t=a.slice(0,e),o=a.slice(e+1);if(t!==t.toUpperCase()||o!==o.toUpperCase())throw new u(`${a}: write the rule in upper case`);if(n.has(t))throw new u(`${t}: given twice`);if(n.add(t),!["FREQ","INTERVAL","COUNT","UNTIL","BYDAY","BYMONTHDAY","BYMONTH","BYSETPOS","WKST"].includes(t))throw new u(`${t}: not supported (supported: FREQ, INTERVAL, COUNT, UNTIL, BYDAY, BYMONTHDAY, BYMONTH, BYSETPOS, WKST)`);if(""===o)throw new u(`${t}: empty value`);r[t]=o}if(!r.FREQ)throw new u("FREQ is required");if(!y.includes(r.FREQ))throw new u(`FREQ: ${r.FREQ} is not supported (DAILY, WEEKLY, MONTHLY, YEARLY)`);const o=r.FREQ,i={freq:o,interval:1,wkst:0};if(void 0!==r.INTERVAL&&(i.interval=p("INTERVAL",r.INTERVAL,1,999)),void 0!==r.COUNT&&void 0!==r.UNTIL)throw new u("COUNT and UNTIL cannot both be given");if(void 0!==r.COUNT&&(i.count=p("COUNT",r.COUNT,1,1e3)),void 0!==r.UNTIL&&(i.until=function(e){let t=/^(\d{4})(\d{2})(\d{2})$/.exec(e);if(t){const n=`${t[1]}-${t[2]}-${t[3]}`;if(!m(n))throw new u(`UNTIL: ${e} is not a date`);return n}if(t=/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z$/.exec(e),t){const n=Date.UTC(+t[1],+t[2]-1,+t[3],+t[4],+t[5],+t[6]);if(!m(`${t[1]}-${t[2]}-${t[3]}`)||+t[4]>23||+t[5]>59||+t[6]>59)throw new u(`UNTIL: ${e} is not a UTC time`);return new Date(n).toISOString()}throw new u(`UNTIL: ${e} must be YYYYMMDD or YYYYMMDDTHHMMSSZ`)}(r.UNTIL)),void 0!==r.BYDAY){i.byDay=f("BYDAY",r.BYDAY,7).map((e=>{const t=/^([+-]?\d)?(MO|TU|WE|TH|FR|SA|SU)$/.exec(e);if(!t)throw new u(`BYDAY: ${e} is not a weekday`);const n=c.indexOf(t[2]);if(void 0===t[1])return{weekday:n};if("MONTHLY"!==o&&"YEARLY"!==o)throw new u(`BYDAY: ${e}: an ordinal needs FREQ=MONTHLY or YEARLY`);return{weekday:n,ordinal:p("BYDAY",t[1],-5,5)}}));const e=i.byDay.map((e=>`${e.ordinal??""}${e.weekday}`));if(new Set(e).size!==e.length)throw new u("BYDAY: repeated day")}if(void 0!==r.BYMONTHDAY){if("MONTHLY"!==o&&"YEARLY"!==o)throw new u("BYMONTHDAY needs FREQ=MONTHLY or YEARLY");if(i.byMonthDay=f("BYMONTHDAY",r.BYMONTHDAY,31).map((e=>p("BYMONTHDAY",e,-1,31))),new Set(i.byMonthDay).size!==i.byMonthDay.length)throw new u("BYMONTHDAY: repeated day")}if(void 0!==r.BYMONTH){if("YEARLY"!==o)throw new u("BYMONTH needs FREQ=YEARLY");if(i.byMonth=f("BYMONTH",r.BYMONTH,12).map((e=>p("BYMONTH",e,1,12))),new Set(i.byMonth).size!==i.byMonth.length)throw new u("BYMONTH: repeated month")}if(void 0!==r.BYSETPOS){if("MONTHLY"!==o||!i.byDay)throw new u("BYSETPOS needs FREQ=MONTHLY and BYDAY");i.bySetPos=p("BYSETPOS",r.BYSETPOS,-5,5)}if(void 0!==r.WKST){const e=c.indexOf(r.WKST);if(e<0)throw new u(`WKST: ${r.WKST} is not a weekday`);i.wkst=e}return i}function _(e){var t,n,r;const o=[`FREQ=${e.freq}`];return e.interval>1&&o.push(`INTERVAL=${e.interval}`),(null==(t=e.byMonth)?void 0:t.length)&&o.push(`BYMONTH=${e.byMonth.join(",")}`),(null==(n=e.byMonthDay)?void 0:n.length)&&o.push(`BYMONTHDAY=${e.byMonthDay.join(",")}`),(null==(r=e.byDay)?void 0:r.length)&&o.push(`BYDAY=${e.byDay.map((e=>`${e.ordinal??""}${c[e.weekday]}`)).join(",")}`),void 0!==e.bySetPos&&o.push(`BYSETPOS=${e.bySetPos}`),void 0!==e.count&&o.push(`COUNT=${e.count}`),void 0!==e.until&&o.push(`UNTIL=${10===e.until.length?e.until.replace(/-/g,""):e.until.replace(/[-:]/g,"").replace(/\.\d{3}/,"")}`),0!==e.wkst&&o.push(`WKST=${c[e.wkst]}`),o.join(";")}function m(e){const t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)return!1;const n=+t[1],r=+t[2],o=+t[3];return n>=1&&r>=1&&r<=12&&o>=1&&o<=g(n,r)}const w=e=>e%4==0&&e%100!=0||e%400==0;function g(e,t){return[31,w(e)?29:28,31,30,31,30,31,31,30,31,30,31][t-1]}const b=(e,t,n)=>Math.floor(Date.UTC(e,t-1,n)/864e5);function D(e){return b(+e.slice(0,4),+e.slice(5,7),+e.slice(8,10))}function v(e){return new Date(864e5*e).toISOString().slice(0,10)}function x(e){const t=new Date(864e5*e);return{y:t.getUTCFullYear(),m:t.getUTCMonth()+1,d:t.getUTCDate()}}const k=e=>((e+3)%7+7)%7,M=new Map;function O(e){let t=M.get(e);return t||(t=new Intl.DateTimeFormat("en-US",{timeZone:e,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}),M.set(e,t)),t}function $(e){try{return O(e),!0}catch{return!1}}function S(e,t){const n={};for(const r of O(t).formatToParts(new Date(e)))"literal"!==r.type&&(n[r.type]=Number(r.value));return{y:n.year,m:n.month,d:n.day,h:24===n.hour?0:n.hour,mi:n.minute,s:n.second}}function T(e,t){const n=S(e,t);return Date.UTC(n.y,n.m-1,n.d,n.h,n.mi,n.s)-1e3*Math.floor(e/1e3)}function E(e,t,n,r){const o=864e5*e+6e4*t+1e3*n,i=o-T(o,r);return o-T(i,r)}function A(e,t){const n=S(e,t);return b(n.y,n.m,n.d)}function Y(e,t,n){const r=x(n),o=[],i=(e,t,n)=>{for(let r=0;r<t;r++)n.some((t=>void 0===t.ordinal&&t.weekday===k(e+r)))&&o.push(e+r)},a=(e,t,n)=>{const r=[];for(let o=0;o<t;o++)k(e+o)===n.weekday&&r.push(e+o);const i=n.ordinal>0?n.ordinal-1:r.length+n.ordinal;i>=0&&i<r.length&&o.push(r[i])},s=(e,t,n)=>{const r=g(e,t);for(const i of n){const n=i>0?i:r+i+1;n>=1&&n<=r&&o.push(b(e,t,n))}};switch(e.freq){case"DAILY":{const r=n+t*e.interval,{m:i,d:a}=x(r);if(e.byMonth&&!e.byMonth.includes(i))break;if(e.byMonthDay&&!e.byMonthDay.some((e=>e>0?e===a:g(x(r).y,i)+e+1===a)))break;if(e.byDay&&!e.byDay.some((e=>e.weekday===k(r))))break;o.push(r);break}case"WEEKLY":if(i(n-(k(n)-e.wkst+7)%7+t*e.interval*7,7,e.byDay??[{weekday:k(n)}]),e.byMonth)return o.filter((t=>e.byMonth.includes(x(t).m))).sort(((e,t)=>e-t));break;case"MONTHLY":{const n=12*r.y+(r.m-1)+t*e.interval,l=Math.floor(n/12),d=n%12+1,c=b(l,d,1),u=g(l,d);if(e.byMonthDay){if(s(l,d,e.byMonthDay),e.byDay){const t=o.filter((t=>e.byDay.some((e=>e.weekday===k(t)))));o.length=0,o.push(...t)}}else if(e.byDay){i(c,u,e.byDay);for(const t of e.byDay)void 0!==t.ordinal&&a(c,u,t)}else r.d<=u&&o.push(b(l,d,r.d));break}case"YEARLY":{const n=r.y+t*e.interval;if(e.byDay&&!e.byMonth&&!e.byMonthDay){const t=b(n,1,1),r=w(n)?366:365;i(t,r,e.byDay);for(const n of e.byDay)void 0!==n.ordinal&&a(t,r,n);break}const l=e.byMonth??[r.m];for(const t of l)if(e.byMonthDay)s(n,t,e.byMonthDay);else if(e.byDay){const r=b(n,t,1),o=g(n,t);i(r,o,e.byDay);for(const t of e.byDay)void 0!==t.ordinal&&a(r,o,t)}else r.d<=g(n,t)&&o.push(b(n,t,r.d));if(e.byMonthDay&&e.byDay){const t=o.filter((t=>e.byDay.some((e=>e.weekday===k(t)))));o.length=0,o.push(...t)}break}}const l=[...new Set(o)].sort(((e,t)=>e-t));if(void 0!==e.bySetPos){const t=e.bySetPos>0?e.bySetPos-1:l.length+e.bySetPos;return t>=0&&t<l.length?[l[t]]:[]}return l}function I(e,t,n){const r=x(n);switch(e.freq){case"DAILY":return n+t*e.interval;case"WEEKLY":return n-(k(n)-e.wkst+7)%7+t*e.interval*7;case"MONTHLY":{const n=12*r.y+(r.m-1)+t*e.interval;return b(Math.floor(n/12),n%12+1,1)}case"YEARLY":return b(r.y+t*e.interval,1,1)}}function N(e,t,n,r={}){var o;const i=r.limit??2e3,a=new Set(r.exdate??[]),s=[];let l,d,c,u=0,y=0,p="UTC";const f=r.viewerTz??"UTC";if("date"===t.kind)l=D(t.date),d=A(n.fromMs,f)-(r.durationDays??0),c=A(n.toMs-1,f);else{p=t.tz;const e=S(Date.parse(t.utc),p);l=b(e.y,e.m,e.d),u=60*e.h+e.mi,y=e.s,d=A(n.fromMs-(r.durationMs??0),p)-1,c=A(n.toMs,p)+1}const h=10===(null==(o=e.until)?void 0:o.length)?D(e.until):void 0,_=e.until&&e.until.length>10?Date.parse(e.until):void 0;let m=0;const w=o=>{if(void 0!==e.count&&m>=e.count)return!1;if(void 0!==h&&o>h)return!1;let i;if("date"===t.kind){if(void 0!==_&&864e5*o>_)return!1;const e=v(o);i={original:e,date:e}}else{const e=E(o,u,y,p);if(void 0!==_&&e>_)return!1;i={original:new Date(e).toISOString(),startMs:e}}return m+=1,a.has(i.original)||("date"===t.kind?o>=d&&o<=c&&s.push(i):i.startMs+(r.durationMs??0)>n.fromMs&&i.startMs<n.toMs&&s.push(i)),!0};if(l>c||!w(l))return s;let g=void 0===e.count?function(e,t,n){const r=x(t),o=x(n);let i;switch(e.freq){case"DAILY":i=Math.floor((n-t)/e.interval);break;case"WEEKLY":i=Math.floor((n-I(e,0,t))/(7*e.interval));break;case"MONTHLY":i=Math.floor((12*o.y+o.m-(12*r.y+r.m))/e.interval);break;case"YEARLY":i=Math.floor((o.y-r.y)/e.interval)}return Math.max(-1,i-1)}(e,l,d)+1:0;for(let b=0;b<2e5&&s.length<i&&!(I(e,g,l)>c);b++,g++)for(const t of Y(e,g,l))if(!(t<=l)){if(t>c)return s;if(!w(t)||s.length>=i)return s}return s}function L(e,t,n="UTC"){return!0===e.all_day?"string"==typeof e.start_date?{kind:"date",date:e.start_date}:null:"string"==typeof e.start?{kind:"datetime",utc:e.start,tz:t&&$(t)?t:n}:null}function R(e,t){return`${e}@${t}`}const C={1:"第一个",2:"第二个",3:"第三个",4:"第四个",5:"第五个",[-1]:"最后一个",[-2]:"倒数第二个",[-3]:"倒数第三个",[-4]:"倒数第四个",[-5]:"倒数第五个"},B={1:"first",2:"second",3:"third",4:"fourth",5:"fifth",[-1]:"last",[-2]:"second to last",[-3]:"third to last",[-4]:"fourth to last",[-5]:"fifth to last"},U=["周一","周二","周三","周四","周五","周六","周日"],j=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],H=["January","February","March","April","May","June","July","August","September","October","November","December"],F=e=>!!e&&5===e.length&&e.every((e=>void 0===e.ordinal))&&[0,1,2,3,4].every((t=>e.some((e=>e.weekday===t))));const q="buckyos.todo@1",P="buckyos.calendar@1",W="schedule",z="todo",K="calendar",Q="schedule-board",V="done",Z={zh:{title:"标题",status:"状态",due:"截止",order:"顺序",done_at:"完成时间",ext:"扩展",todo:"待办",doing:"进行中",done:"已完成",all_day:"全天",start:"开始",end:"结束",start_date:"开始日期",end_date:"结束日期",confirmed:"已确认",tentative:"暂定",cancelled:"已取消",todo_table:"待办",calendar_table:"日程",workspace:"我的日程",board:"日程"},en:{title:"Title",status:"Status",due:"Due",order:"Order",done_at:"Completed",ext:"Extension",todo:"To do",doing:"In progress",done:"Done",all_day:"All day",start:"Start",end:"End",start_date:"Start date",end_date:"End date",confirmed:"Confirmed",tentative:"Tentative",cancelled:"Cancelled",todo_table:"To-do",calendar_table:"Calendar",workspace:"My schedule",board:"Schedule"}};function J(e,t){return Z[e][t]??Z.en[t]??t}function G(e="zh"){const t=t=>J(e,t);return[{field_id:"title",name:t("title"),type:"text",required:!0},{field_id:"status",name:t("status"),type:"select",required:!0,options:["todo","doing","done"].map((e=>({option_id:e,label:t(e)})))},{field_id:"due",name:t("due"),type:"date",nullable:!0},{field_id:"order",name:t("order"),type:"text",nullable:!0},{field_id:"done_at",name:t("done_at"),type:"datetime",nullable:!0},{field_id:"ext",name:t("ext"),type:"json",nullable:!0}]}function X(e="zh"){const t=t=>J(e,t);return[{field_id:"title",name:t("title"),type:"text",required:!0},{field_id:"all_day",name:t("all_day"),type:"boolean",nullable:!0},{field_id:"start",name:t("start"),type:"datetime",nullable:!0},{field_id:"end",name:t("end"),type:"datetime",nullable:!0},{field_id:"start_date",name:t("start_date"),type:"date",nullable:!0},{field_id:"end_date",name:t("end_date"),type:"date",nullable:!0},{field_id:"status",name:t("status"),type:"select",nullable:!0,options:["confirmed","tentative","cancelled"].map((e=>({option_id:e,label:t(e)})))},{field_id:"ext",name:t("ext"),type:"json",nullable:!0}]}function ee(e,t){const n=t.locale??"zh";return{op:"entity.create",entity_id:t.entity_id,type_id:"buckyos.table-source",parent_id:t.parent_id,order_key:t.order_key,schema_id:"todo"===e?q:P,name:t.name??J(n,"todo"===e?"todo_table":"calendar_table"),payload:{title_field_id:"title",fields:"todo"===e?G(n):X(n)}}}const te="0123456789abcdefghijklmnopqrstuvwxyz";function ne(e){return"string"==typeof e&&e.length>0&&e.length<=64&&/^[0-9a-z]+$/.test(e)&&!e.endsWith("0")}function re(e,t){if(null!==t){let n=0;for(;n<t.length&&(e[n]??"0")===t[n];)n++;if(n>0)return t.slice(0,n)+re(e.length>n?e.slice(n):"",t.slice(n))}const n=e.length?te.indexOf(e[0]):0,r=null!==t?te.indexOf(t[0]):36;return r-n>1?te[Math.floor((n+r+1)/2)]:null!==t&&t.length>1?t[0]:te[n]+re(e.length>1?e.slice(1):"",null)}function oe(e,t){const n=e??null,r=t??null;if(null!==n&&null!==r&&n>=r)throw new Error("orderKeyBetween requires a < b");const o=null!==n&&null===r?function(e){const t=e.padEnd(Math.max(e.length,8),"0").split("");let n=t.length-1;for(;n>=0&&"z"===t[n];)n--;if(n>=0){t[n]=te[te.indexOf(t[n])+1];for(let e=n+1;e<t.length;e++)t[e]="0";return"0"===t[t.length-1]&&(t[t.length-1]="1"),t.join("")}if(t.length>=64)throw new Error("order key space exhausted; rebalance");return t.join("").padEnd(Math.min(t.length+8,64),"0").slice(0,-1)+"1"}(n):re(n??"",r);if(!ne(o))throw new Error("order key space exhausted; rebalance");return o}let ie=0;function ae(e="r"){ie=(ie+1)%1296;const t=Math.floor(Math.random()*36**6).toString(36).padStart(6,"0");return`${e}${Date.now().toString(36)}${ie.toString(36).padStart(2,"0")}${t}`}function se(e,t,n){var r;const o=[],i=[];for(const[s,l]of Object.entries(n)){const e={record_id:t.record_id,field_id:s,expect:{rev:(null==(r=t.revs)?void 0:r[s])??0}};null==l?void 0!==t.values[s]&&null!==t.values[s]&&i.push(e):o.push({...e,value:l})}const a=[];return o.length&&a.push({op:"table.set_values",source_id:e,values:o}),i.length&&a.push({op:"table.unset_values",source_id:e,values:i}),a}function le(e,t){return{op:"table.insert_records",source_id:e,records:t.map((e=>({record_id:e.record_id,values:Object.fromEntries(Object.entries(e.values).filter((([,e])=>null!=e)))})))}}function de(e,t){return{op:"table.delete_records",source_id:e,records:t.map((e=>({record_id:e.record_id,expect:{rev:e.rev??0}})))}}function ce(e){if(m(e))return e;const t=Date.parse(e);return Number.isFinite(t)?new Date(t).toISOString():e}const ue=e=>Array.isArray(e)?e.filter((e=>"string"==typeof e)).map(ce):[],ye=e=>{const t=null==e?void 0:e.values.ext;return t&&"object"==typeof t&&!Array.isArray(t)?{...t}:{}};function pe(e){const t=e.values,n="string"==typeof t.status?t.status:"todo";return{record_id:e.record_id,rev:e.rev,revs:e.revs,values:e.values,title:"string"==typeof t.title?t.title:"",status:n,due:"string"==typeof t.due?t.due:null,order:ne(t.order)?t.order:null,done:n===V,done_at:"string"==typeof t.done_at?t.done_at:null,ext:ye(e)}}function fe(e){return[...e].sort(((e,t)=>e.order===t.order?e.record_id.localeCompare(t.record_id):null===e.order?1:null===t.order||e.order<t.order?-1:1))}function he(e,t,n={}){const r=t.record_id??ae("t");let o=t.order??null;if(!o)if(void 0!==n.after||void 0!==n.before)o=oe(n.after??null,n.before??null);else{o=oe((n.items??[]).map((e=>e.order)).filter(ne).sort().pop()??null,null)}const i=t.status??"todo";return{record_id:r,order:o,ops:[le(e,[{record_id:r,values:{title:t.title,status:i,order:o,due:t.due??void 0,ext:t.ext&&Object.keys(t.ext).length?t.ext:void 0,done_at:i===V?t.done_at??(new Date).toISOString():void 0}}])]}}function _e(e,t,n,r={}){return se(e,t,n?{status:V,done_at:r.now??(new Date).toISOString()}:{status:r.reopenStatus??"todo",done_at:null})}function me(e,t,n,r={}){const o={},i="string"==typeof t.values.status?t.values.status:void 0;return void 0!==n.status&&n.status!==i&&(o.status=n.status,n.status===V?o.done_at=r.now??(new Date).toISOString():i===V&&(o.done_at=null)),void 0!==n.order&&n.order!==t.values.order&&(o.order=n.order),Object.keys(o).length?se(e,t,o):[]}function we(e,t,n){const r={};for(const o of["title","status","due","order","done_at"])void 0!==n[o]&&(r[o]=n[o]);if(void 0!==n.ext&&(r.ext=n.ext&&Object.keys(n.ext).length?n.ext:null),n.ext_merge){const e=ye(t);for(const[t,r]of Object.entries(n.ext_merge))null===r?delete e[t]:e[t]=r;r.ext=Object.keys(e).length?e:null}return void 0!==r.status&&r.status!==t.values.status&&void 0===r.done_at&&(r.status===V?r.done_at=(new Date).toISOString():t.values.status===V&&(r.done_at=null)),se(e,t,r)}function ge(e,t){const n=e.map((e=>e.order)),r=t>0?n[t-1]:null,o=t<n.length?n[t]:null;return null===r||ne(r)?null!==o&&ne(o)&&(null===r||r<o)?oe(r,o):oe(r,null):oe(null,null)}function be(e){const t=e.values;if(!0===t.all_day){if("string"!=typeof t.start_date||!m(t.start_date))return null;const e="string"==typeof t.end_date&&m(t.end_date)&&t.end_date>=t.start_date?t.end_date:t.start_date;return{allDay:!0,startDate:t.start_date,endDate:e}}if("string"!=typeof t.start)return null;const n=Date.parse(t.start);if(!Number.isFinite(n))return null;const r="string"==typeof t.end?Date.parse(t.end):NaN;return{allDay:!1,startMs:n,endMs:Number.isFinite(r)&&r>=n?r:n+36e5}}function De(e,t){return v(D(e)+t)}const ve=(e,t)=>D(t)-D(e);function xe(e,t,n){const r=ye(e);return{id:e.record_id,row:e,title:"string"==typeof e.values.title?e.values.title:"",allDay:t.allDay,startMs:t.startMs,endMs:t.endMs,startDate:t.startDate,endDate:t.endDate,status:"string"==typeof e.values.status?e.values.status:null,ext:r,recurring:!1,override:!1,agentWritten:!1,...n}}function ke(e,t,n){if(!e.allDay)return e.startMs<t.toMs&&Math.max(e.endMs,e.startMs+1)>t.fromMs;const r=Me(t.fromMs,n),o=Me(t.toMs-1,n);return e.startDate<=o&&e.endDate>=r}function Me(e,t){return new Intl.DateTimeFormat("en-CA",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit"}).format(new Date(e))}function Oe(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}function $e(e,t,n={}){const r=n.viewerTz??Oe(),o=[],i=new Map;for(const s of e){const e=ye(s).recurrence_id;e&&"object"==typeof e&&!Array.isArray(e)&&"string"==typeof e.master&&"string"==typeof e.original&&i.set(`${e.master}@${ce(e.original)}`,s)}const a=new Map(e.map((e=>[e.record_id,e])));for(const s of e){const e=be(s);if(!e)continue;const l=ye(s),d=l.recurrence_id;if(d&&"object"==typeof d){const n="string"==typeof d.master?a.get(d.master):void 0,i="string"==typeof d.original?ce(d.original):void 0,l=xe(s,e,{id:n&&i?R(n.record_id,i):s.record_id,master:n,original:i,recurring:Boolean(n),override:!0});ke(l,t,r)&&o.push(l);continue}const c=e.allDay?ve(e.startDate,e.endDate):e.endMs-e.startMs,u=t=>{const n=`${s.record_id}@${t.original}`;return i.has(n)?null:e.allDay?xe(s,{allDay:!0,startDate:t.date,endDate:De(t.date,c)},{id:n,master:s,original:t.original,recurring:!0}):xe(s,{allDay:!1,startMs:t.startMs,endMs:t.startMs+c},{id:n,master:s,original:t.original,recurring:!0})};let y=null;if("string"==typeof l.rrule)try{y=h(l.rrule)}catch{y=null}if(y){const i=L(s.values,"string"==typeof l.tz?l.tz:void 0,r);if(!i)continue;const a=N(y,i,t,{exdate:ue(l.exdate),viewerTz:r,durationMs:e.allDay?void 0:c,durationDays:e.allDay?c:void 0,limit:n.limit});for(const e of a){const t=u(e);t&&o.push(t)}continue}if(Array.isArray(l.occurrences)&&l.occurrences.length>0){const n=new Set(ue(l.exdate));for(const i of l.occurrences){if("string"!=typeof i)continue;const a=ce(i);if(n.has(a))continue;const s=e.allDay?{original:a,date:a}:{original:a,startMs:Date.parse(a)};if(!e.allDay&&!Number.isFinite(s.startMs))continue;if(e.allDay&&!m(a))continue;const l=u(s);l&&ke(l,t,r)&&o.push({...l,agentWritten:!0})}continue}const p=xe(s,e,{});ke(p,t,r)&&o.push(p)}return o.sort(((e,t)=>Se(e)-Se(t)||e.id.localeCompare(t.id)))}const Se=e=>e.allDay?Date.parse(`${e.startDate}T00:00:00Z`):e.startMs;function Te(e,t){const n=t.record_id??ae("e"),r={title:t.title,status:t.status??void 0,ext:t.ext&&Object.keys(t.ext).length?t.ext:void 0};return t.all_day?(r.all_day=!0,r.start_date=t.start_date??void 0,r.end_date=t.end_date&&t.end_date!==t.start_date?t.end_date:void 0):(r.start=t.start??void 0,r.end=t.end??void 0),{record_id:n,ops:[le(e,[{record_id:n,values:r}])]}}function Ee(e){return e.allDay?{all_day:!0,start_date:e.startDate,end_date:e.endDate!==e.startDate?e.endDate:null,start:null,end:null}:{all_day:null,start:e.start,end:e.end,start_date:null,end_date:null}}function Ae(e,t){return e.filter((e=>{const n=ye(e).recurrence_id;return n&&"object"==typeof n&&n.master===t}))}function Ye(e,t,n,r){return t?De(e,r):((e,t)=>new Date(Date.parse(e)+t).toISOString())(e,n)}function Ie(e,t,n,r,o){const i=o.newRecordId??(()=>ae("e")),a=e=>{const t={...n.values};if(n.ext_merge){const r=ye(e);for(const[e,t]of Object.entries(n.ext_merge))null===t?delete r[e]:r[e]=t;t.ext=Object.keys(r).length?r:null}return t},s=t.master;if(!s||t.row!==s&&"one"===r){const r=t.row,o={...a(r),...n.times?Ee(n.times):{}};if(void 0!==n.rrule&&!s){const e={...o.ext??ye(r)??{}};null===n.rrule?delete e.rrule:e.rrule=_(h(n.rrule)),null===n.rrule&&delete e.exdate,o.ext=Object.keys(e).length?e:null}return{ops:se(e,r,o),record_id:r.record_id}}const l=t.original,d=be(s),c=ye(s);if("one"===r){const r=i(),o={...c,recurrence_id:{master:s.record_id,original:l}};delete o.rrule,delete o.exdate,delete o.occurrences,delete o.rule_text,delete o.covered_until,delete o.maintenance;const u={title:s.values.title,status:s.values.status,ext:o},y=n.times??(t.allDay?{allDay:!0,startDate:t.startDate,endDate:De(t.startDate,ve(d.startDate,d.endDate))}:{allDay:!1,start:new Date(t.startMs).toISOString(),end:new Date(t.startMs+(d.endMs-d.startMs)).toISOString()}),p={...u,...a({record_id:r,values:{ext:o}}),...Ee(y)};return p.ext||(p.ext=o),{ops:[le(e,[{record_id:r,values:p}])],record_id:r}}let u=0,y=0,p=d.allDay?0:d.endMs-d.startMs,f=d.allDay?ve(d.startDate,d.endDate):0;if(n.times){if(n.times.allDay!==d.allDay)throw new Error("changing a series between all-day and timed: edit the series itself (scope all) with new times");n.times.allDay?(y=ve(l,n.times.startDate),f=ve(n.times.startDate,n.times.endDate)):(u=Date.parse(n.times.start)-Date.parse(l),y=Math.round(u/864e5),p=Date.parse(n.times.end)-Date.parse(n.times.start))}const m="string"==typeof c.rrule?h(c.rrule):null,w=Ae(o.rows,s.record_id),g=ue(c.exdate),b=d.allDay?l===d.startDate:l===new Date(d.startMs).toISOString(),D=(e,t)=>d.allDay?{allDay:!0,startDate:De(t,y),endDate:De(De(t,y),f)}:{allDay:!1,start:new Date(e+u).toISOString(),end:new Date(e+u+p).toISOString()},v=e=>void 0!==n.rrule?null===n.rrule?null:_(h(n.rrule)):e?_(function(e,t){if(!t)return e;const n={...e};if(e.byDay&&e.byDay.every((e=>void 0===e.ordinal))&&("WEEKLY"===e.freq||"DAILY"===e.freq))n.byDay=e.byDay.map((e=>({weekday:((e.weekday+t)%7+7)%7})));else if(e.byDay&&"MONTHLY"===e.freq&&1===e.byDay.length&&void 0===e.bySetPos&&Math.abs(t)<7)n.byDay=[{...e.byDay[0],weekday:((e.byDay[0].weekday+t)%7+7)%7}];else if(e.byMonthDay&&1===e.byMonthDay.length&&e.byMonthDay[0]>0){const r=e.byMonthDay[0]+t;r>=1&&r<=28&&(n.byMonthDay=[r])}return n}(e,y)):null,x=[];if("all"===r||b){const t=D(d.startMs,d.startDate),n={...c},r=v(m);r?n.rrule=r:(delete n.rrule,delete n.exdate),r&&g.length&&(n.exdate=g.map((e=>Ye(e,d.allDay,u,y))));const o=a({record_id:s.record_id,values:{ext:n}}),i=void 0!==o.ext?o.ext:n;x.push(...se(e,s,{...o,...Ee(t),ext:i&&Object.keys(i).length?i:null}));for(const a of w){const t=ye(a),n=t.recurrence_id;r?(u||y)&&x.push(...se(e,a,{ext:{...t,recurrence_id:{...n,original:Ye(String(n.original),d.allDay,u,y)}}})):x.push(de(e,[a]))}return{ops:x,record_id:s.record_id}}if(!m)throw new Error("not a repeating event");const k=i(),M=e=>d.allDay?e<l:Date.parse(e)<Date.parse(l);let O={...m},$={...m};if(void 0!==m.count){const e=N(m,L(s.values,"string"==typeof c.tz?c.tz:void 0),{fromMs:d.allDay?Date.parse(`${d.startDate}T00:00:00Z`)-1728e5:d.startMs,toMs:d.allDay?Date.parse(`${l}T00:00:00Z`):Date.parse(l)},{viewerTz:"UTC"}).filter((e=>M(e.original))).length;O={...m,count:Math.max(1,e)},$={...m,count:Math.max(1,m.count-e)}}else O={...m,until:d.allDay?De(l,-1):new Date(Date.parse(l)-1e3).toISOString().replace(/\.\d{3}Z$/,".000Z")};const S={...c,rrule:_(O)},T=g.filter(M);T.length?S.exdate=T:delete S.exdate,x.push(...se(e,s,{ext:S}));const E={...c},A=v($);A?E.rrule=A:delete E.rrule;const Y=g.filter((e=>!M(e))).map((e=>Ye(e,d.allDay,u,y)));Y.length&&A?E.exdate=Y:delete E.exdate;const I=D(d.allDay?void 0:Date.parse(l),d.allDay?l:void 0),R=a({record_id:k,values:{ext:E}}),C={title:s.values.title,status:s.values.status,...R,...Ee(I)};C.ext=(void 0!==R.ext?R.ext:E)??void 0,x.push(le(e,[{record_id:k,values:C}]));for(const h of w){const t=ye(h),n=t.recurrence_id;M(String(n.original))||(A?x.push(...se(e,h,{ext:{...t,recurrence_id:{master:k,original:Ye(String(n.original),d.allDay,u,y)}}})):x.push(de(e,[h])))}return{ops:x,record_id:k}}function Ne(e,t,n,r){const o=t.master;if(!o)return[de(e,[t.row])];const i=t.original,a=ye(o),s=be(o),l=Ae(r.rows,o.record_id),d=s.allDay?i===s.startDate:i===new Date(s.startMs).toISOString();if("all"===n||"following"===n&&d)return[de(e,[o,...l])];const c=[];if("one"===n){const t=ue(a.exdate);t.includes(i)||c.push(...se(e,o,{ext:{...a,exdate:[...t,i].sort()}}));const n=l.filter((e=>ce(String(ye(e).recurrence_id.original))===i));return n.length&&c.push(de(e,n)),c}const u="string"==typeof a.rrule?h(a.rrule):null;if(!u)return[de(e,[t.row])];const y=e=>s.allDay?e<i:Date.parse(e)<Date.parse(i),p={...u,count:void 0,until:s.allDay?De(i,-1):new Date(Date.parse(i)-1e3).toISOString()},f={...a,rrule:_(p)};if(Array.isArray(a.exdate)){const e=ue(a.exdate).filter(y);e.length?f.exdate=e:delete f.exdate}c.push(...se(e,o,{ext:f}));const m=l.filter((e=>!y(String(ye(e).recurrence_id.original))));return m.length&&c.push(de(e,m)),c}const Le=1e3;function Re(e){var n,r,o,i;const a=null==(n=e.errors)?void 0:n[0];if("conflict"===e.status){const n=null==(r=e.conflicts)?void 0:r[0];return new t({code:e.code??"REVISION_CONFLICT",retryable:!0,detail:"changed meanwhile, read it again"+(n?`: ${JSON.stringify(n.selector??n)}`:"")})}return new t({code:e.code??(null==(o=e.error)?void 0:o.code)??"REJECTED",sub_code:e.sub_code??(null==a?void 0:a.sub_code),retryable:!1,detail:(null==a?void 0:a.detail)??e.detail??(null==(i=e.error)?void 0:i.detail)??"refused"})}function Ce(e,n){const r=n.indexOf("@"),o=r<0?n:n.slice(0,r),i=r<0?null:ce(n.slice(r+1)),a=e.find((e=>e.record_id===o));if(!a)throw new t({code:"NOT_FOUND",retryable:!1,detail:`event ${o} not found`});if(null===i){const n=be(a);if(!n)throw new t({code:"INVALID_OPERATION",retryable:!1,detail:`event ${o} has no time`});const r=ye(a),i=r.recurrence_id,s=i&&"string"==typeof i.master?e.find((e=>e.record_id===i.master)):void 0;return xe(a,n,s?{master:s,original:String(i.original),recurring:!0,override:!0}:{recurring:"string"==typeof r.rrule,master:"string"==typeof r.rrule?a:void 0,original:"string"==typeof r.rrule?n.allDay?n.startDate:new Date(n.startMs).toISOString():void 0})}const s=e.find((e=>{const t=ye(e).recurrence_id;return t&&t.master===o&&"string"==typeof t.original&&ce(t.original)===ce(i)})),l=be(a);if(!l)throw new t({code:"INVALID_OPERATION",retryable:!1,detail:`event ${o} has no time`});if(s)return xe(s,be(s),{id:n,master:a,original:i,recurring:!0,override:!0});const d=l.allDay,c=d?0:l.endMs-l.startMs,u=d?ve(l.startDate,l.endDate):0;return xe(a,d?{allDay:!0,startDate:i,endDate:De(i,u)}:{allDay:!1,startMs:Date.parse(i),endMs:Date.parse(i)+c},{id:n,master:a,original:i,recurring:!0})}function Be(e="zh"){const t=`${Q}-content`,n=J(e,"board");return[{op:"entity.create",entity_id:t,type_id:"buckyos.container",parent_id:"canvas-content",order_key:"u",name:n,payload:{kind:"folder",title:n,system:"surface_content",surface_id:Q}},{op:"entity.create",entity_id:Q,type_id:"buckyos.container",parent_id:"surfaces",order_key:"a",name:n,payload:{kind:"surface",layout:{mode:"free"},title:n,content_folder_id:t}},{op:"entity.create",entity_id:`${Q}-calendar`,type_id:"buckyos.container",parent_id:Q,order_key:"a",placement:{x:40,y:40,w:880,h:640},payload:{kind:"calendar",layout:{mode:"data"},title:J(e,"calendar_table"),bindings:{events:[{entity_id:K}],todo:[{entity_id:z}]},config:{view:"week"}}},{op:"entity.create",entity_id:`${Q}-todo`,type_id:"buckyos.container",parent_id:Q,order_key:"b",placement:{x:960,y:40,w:420,h:640},payload:{kind:"todo",layout:{mode:"data"},title:J(e,"todo_table"),bindings:{items:{entity_id:z}},config:{mode:"list"}}}]}class Ue extends Error{constructor(e,t,n,r){super(e),this.code=t,this.node=n,this.binding=r}}const je=[q,P],He=e=>void 0===e?[]:Array.isArray(e)?e:[e],Fe=(e,t)=>t.title??e;function qe(e,t){return!(e.accepts&&e.accepts.length>0&&!e.accepts.includes(t.type_id))&&(!e.schema_id||t.schema_id===e.schema_id)}const Pe=e=>{var t;return{...(null==(t=e.accepts)?void 0:t.length)?{accepts:e.accepts}:{},...e.schema_id?{schema_id:e.schema_id}:{}}};function We(){const e=e=>{throw new Ue(`needs a choice: ${e}`,"NEEDS_UI")};return{pickOne:async t=>e(t.title),pickMany:async t=>e(t.title),confirm:async t=>e(t.title)}}let ze=0;const Ke=()=>"ref:"+ ++ze;function Qe(e,t,n){const r=e=>{throw new Ue(`on_bind result: ${e}`,"INVALID",n)},o=e=>"object"==typeof e&&null!==e&&!Array.isArray(e);if(!o(e)||!o(e.bindings))return r("{ bindings, create? } (or null to cancel)");const i=void 0===e.create?[]:e.create;if(!Array.isArray(i)||i.length>16)return r("create: a list of at most 16");const a=new Map,s=i.map(((e,t)=>{const n=`create[${t}]`;if(!o(e)||"string"!=typeof e.ref||!e.ref)return r(`${n}: { ref, kind, … }`);if(a.has(e.ref))return r(`${n}: ref ${e.ref} twice`);const i=Ke();a.set(e.ref,i);const s="string"==typeof e.name&&e.name.trim()&&e.name.length<=128?e.name.trim():null;return"standard"===e.kind?"string"!=typeof e.schema_id?r(`${n}: a standard table names its schema_id`):{ref:i,kind:"standard",schema_id:e.schema_id,name:s??e.schema_id}:s?"table"===e.kind?Array.isArray(e.fields)&&0!==e.fields.length?void 0!==e.title_field_id&&"string"!=typeof e.title_field_id?r(`${n}: title_field_id is a field id`):{ref:i,kind:"table",name:s,fields:e.fields,...e.title_field_id?{title_field_id:e.title_field_id}:{}}:r(`${n}: a table lists its fields`):"dir"===e.kind?{ref:i,kind:"dir",name:s}:r(`${n}: kind standard, table or dir`):r(`${n}: a name (at most 128 characters)`)})),l={},d=new Set;for(const[u,y]of Object.entries(e.bindings)){const e=t[u];if(!e)return r(`${u} is not a declared binding`);if(null==y)continue;const n="string"==typeof y?[y]:Array.isArray(y)&&y.every((e=>"string"==typeof e&&e))?y:r(`${u}: an id, or a list of ids`);if(!e.many&&(Array.isArray(y)||1!==n.length))return r(`${u} takes one`);if(n.length>32||new Set(n).size!==n.length)return r(`${u}: at most 32, each once`);const o=n.map((e=>(a.has(e)&&d.add(e),a.get(e)??e)));e.many?o.length>0&&(l[u]=o):l[u]=o[0]}const c=[...a.keys()].filter((e=>!d.has(e)));return c.length>0?r(`created but not bound: ${c.join(", ")}`):{bindings:l,create:s}}const Ve=async e=>{const t={},n=[],r=e.parent?Object.values(e.parent.bound).flatMap(He):[],o=new Map(e.find({}).map((e=>[e.entity_id,e])));for(const[i,a]of Object.entries(e.decls)){const s=(t,n)=>new Ue(t,n,e.node,i);if("rebind"===e.reason){if(void 0!==e.given[i]&&e.no_ui){t[i]=e.given[i];continue}const r=He(e.given[i]);if(a.many){const o=await Je(i,(()=>e.dialogs.pickMany({title:Fe(i,a),query:Pe(a),preselect:r,allow_new:e.canCreate(a)})));if(null===o)return null;t[i]=o.map((t=>{if("string"==typeof t)return t;const r=Ke();return n.push(Ze(r,a,e.title)),r}))}else{const o=await Je(i,(()=>e.dialogs.pickOne({title:Fe(i,a),query:Pe(a),allow_new:e.canCreate(a),current:r[0]??null})));if(null===o)return null;if("string"==typeof o)t[i]=o;else{const r=Ke();n.push(Ze(r,a,e.title)),t[i]=r}}continue}if(void 0!==e.given[i]){t[i]=a.many?He(e.given[i]):He(e.given[i])[0];continue}const l=r.filter((e=>{const t=o.get(e);return void 0!==t&&qe(a,t)}));if(a.many&&l.length>0){t[i]=l;continue}if(!a.many&&1===l.length){t[i]=l[0];continue}const d=e.find(Pe(a)).filter((e=>qe(a,e)));if(0===d.length){if(!a.required)continue;if(!e.canCreate(a))throw s(`no ${Fe(i,a)} in this Workspace yet`,"NO_DATA");const r=Ke();n.push(Ze(r,a,e.title)),t[i]=a.many?[r]:r}else if(a.many)t[i]=d.map((e=>e.entity_id));else if(1===d.length)t[i]=d[0].entity_id;else if(a.required){const r=await Je(i,(()=>e.dialogs.pickOne({title:Fe(i,a),query:Pe(a),allow_new:e.canCreate(a)})));if(null===r)return null;if("string"==typeof r)t[i]=r;else{const r=Ke();n.push(Ze(r,a,e.title)),t[i]=r}}}return{bindings:t,create:n}};function Ze(e,t,n){return{ref:e,kind:"standard",schema_id:t.schema_id,name:n||t.title||"Table"}}async function Je(e,t){try{return await t()}catch(n){if(n instanceof Ue&&"NEEDS_UI"===n.code)throw new Ue(`binding ${e} needs a choice: give it`,"NEEDS_UI",void 0,e);throw n}}function Ge(e){return async t=>{var n;const r={},o=[];for(const a of e){const e=t.decls[a.binding]??{};if(void 0===t.given[a.binding]||"insert"!==t.reason)if("from_parent"in a){const o=null==(n=t.parent)?void 0:n.bound[a.from_parent];void 0!==o&&(r[a.binding]=e.many?He(o):He(o)[0])}else if("pick"in a){const n=Pe(e),i=a.title??Fe(a.binding,e),s=!1!==a.allow_new&&t.canCreate(e),l=He(t.given[a.binding]);if("all"===a.pick)r[a.binding]=t.find(n).filter((t=>qe(e,t))).map((e=>e.entity_id));else if("many"===a.pick){const d=await Je(a.binding,(()=>t.dialogs.pickMany({title:i,query:n,preselect:l.length?l:"none",allow_new:s})));if(null===d)return null;r[a.binding]=d.map((n=>{if("string"==typeof n)return n;const r=Ke();return o.push(Ze(r,e,t.title)),r}))}else{const d=await Je(a.binding,(()=>t.dialogs.pickOne({title:i,query:n,allow_new:s,current:l[0]??null})));if(null===d)return null;if("string"==typeof d)r[a.binding]=e.many?[d]:d;else{const n=Ke();o.push(Ze(n,e,t.title)),r[a.binding]=e.many?[n]:n}}}else{const n=0===t.find(Pe(e)).filter((t=>qe(e,t))).length;if("missing"===(a.when??"missing")&&!n)continue;const i=Ke(),s=a.create;o.push("standard"in s?{ref:i,kind:"standard",schema_id:s.standard,name:Fe(a.binding,e)}:"table"in s?{ref:i,kind:"table",name:s.table.name,title_field_id:s.table.title_field_id,fields:s.table.fields}:{ref:i,kind:"dir",name:s.dir.name}),r[a.binding]=e.many?[i]:i}else r[a.binding]=t.given[a.binding]}const i=Object.fromEntries(Object.entries(t.decls).filter((([e])=>void 0===r[e])));if(Object.keys(i).length>0){const e=await Ve({...t,decls:i});if(null===e)return null;Object.assign(r,e.bindings),o.push(...e.create)}return{bindings:r,create:o}}}const Xe=async e=>{const t=(n=e.decls,r=e.bound,Object.entries(n).filter((([e,t])=>t.required&&0===He(r[e]).length)).map((([e,t])=>Fe(e,t))));var n,r;if(t.length>0)return`${e.title}: ${t.join(", ")} not bound`;const o=e.children.filter((e=>!e.ready));return!(o.length>0)||`not ready: ${o.map((e=>`${e.title} (${e.missing.join(", ")})`)).join("; ")}`};exports.AIWORKSPACE_SERVICE_NAME="aiworkspace",exports.AIWS_COMMIT_MAX_BYTES=o,exports.AIWS_COMMIT_MAX_OPERATIONS=i,exports.AIWS_COMMIT_PART_BYTES=r,exports.AIWS_PROTOCOL_VERSION="1.2",exports.AiWorkspaceClient=class{constructor(e){this.rpcClient=e,this.raw=(e,t)=>this.rpcClient.call(e,t)}async call(e,n){const r=await this.rpcClient.call(e,n);if(r&&"object"==typeof r&&!1===r.ok)throw new t(r.error);return r}create(e,t={}){return this.call("ws.create",{title:e,...t})}ensure(e,t){return this.call("ws.ensure",{name:e,...void 0===t?{}:{title:t}})}time(){return this.call("ws.time",{})}list(){return this.call("ws.list",{})}info(e){return this.call("ws.get_info",{workspace_id:e})}getUserState(e){return this.call("ws.get_user_state",{workspace_id:e})}setUserState(e,t,n){return this.call("ws.set_user_state",{workspace_id:e,entries:t,...n?{expect:n}:{}})}resolve(e,t){return this.call("doc.resolve",{workspace_id:e,reference:t})}resolvePath(e,t){return this.call("doc.resolve",{workspace_id:e,path:t})}read(e,t,r){return this.call("doc.read",{workspace_id:e,...n(t),...r?{selector:r}:{}})}readMeta(e,t){return this.call("doc.read",{workspace_id:e,...n(t),as:"meta"})}readBody(e,t,r={}){return this.call("doc.read",{workspace_id:e,...n(t),as:"body",...r})}listEntities(e,t={}){return this.call("doc.list",{workspace_id:e,...t})}findEntities(e,t={}){return this.call("doc.find",{workspace_id:e,...t})}textQuery(e,t,n={}){return this.call("doc.query",{workspace_id:e,text:t,...n})}sql(e,t,n={}){return this.call("doc.query",{workspace_id:e,sql:t,...n})}sourceQuery(e,t,n){return this.call("doc.source_query",{workspace_id:e,source_id:t,...n})}outline(e){return this.call("doc.outline",{workspace_id:e})}prepare(e,t){return d(this.raw,{workspace_id:e,...t},{method:"doc.prepare"})}commit(e,t,n={}){return d(this.raw,{workspace_id:e,...t},n)}getSubmission(e,t,n){return this.call("doc.get_submission",{workspace_id:e,epoch:t,idempotency_key:n})}getChanges(e,t,n,r={}){return this.call("doc.get_changes",{workspace_id:e,epoch:t,after_seq:n,...r.limit?{limit:r.limit}:{},...r.touchedOnly?{filter:{detail:"touched"}}:{}})}waitChanges(e,t,n={}){return this.call("doc.wait_changes",{workspace_id:e,after_seq:t,...n})}exportDoc(e,t,n,r){return this.call("doc.export",{workspace_id:e,mode:t,self_contained:n,...void 0===r?{}:{include_notes:r}})}assetImportObject(e,t){return this.call("asset.import_object",{workspace_id:e,...t})}controlsList(){return this.call("control.list",{})}controlsDescribe(e){return this.call("control.describe",{kind:e})}controlsImport(e,t){return this.call("control.import",{workspace_id:e,...t})}controlsExport(e,t,n){return this.call("control.export",{workspace_id:e,entity_id:t,...n?{format:n}:{}})}extBuild(e,t){return this.call("ext.build",{workspace_id:e,...t})}extExport(e,t,n="package"){return this.call("ext.export",{workspace_id:e,entity_ids:t,purpose:n})}extInstall(e){return this.call("ext.install",e)}extPack(e,t,n,r){return this.call("ext.pack",{workspace_id:e,entity_ids:t,package:n,...r?{templates:r}:{}})}extUpgrade(e){return this.call("ext.upgrade",{...e})}extExportTemplate(e){return this.call("ext.export_template",{...e})}extCreateFromTemplate(e){return this.call("ext.create_from_template",e)}extListLibrary(){return this.call("ext.list_library",{})}extUninstall(e){return this.call("ext.uninstall",{pkg_id:e})}extLibraryBundle(e,t){return this.call("ext.library_bundle",{pkg_id:e,...t?{idents:t}:{}})}extImport(e,t,n={}){return this.call("ext.import",{workspace_id:e,items:t,...n})}runStart(e,t,n,r){return this.call("proc.start",{workspace_id:e,program:t,params:n,idempotency_key:r})}runGet(e,t,n){return this.call("proc.get",{workspace_id:e,run_id:t,...n?{choices:n}:{}})}runList(e,t,n){return this.call("proc.list",{workspace_id:e,...t?{wish_id:t}:{},...n?{limit:n}:{}})}runClaim(e,t,n,r){return this.call("proc.claim",{workspace_id:e,run_id:t,claim_token:n,...r?{executor:r}:{}})}runHeartbeat(e,t,n,r){return this.call("proc.heartbeat",{workspace_id:e,run_id:t,attempt:n,...r?{progress:r}:{}})}runReport(e,t){return this.call("proc.report",{workspace_id:e,...t})}runApply(e,t,n,r){return this.call("proc.apply",{workspace_id:e,run_id:t,plan_digest:n,...r?{session_id:r}:{}})}runCancel(e,t){return this.call("proc.cancel",{workspace_id:e,run_id:t})}},exports.AiwsFailure=t,exports.BindFailure=Ue,exports.CALENDAR_SCHEMA_ID=P,exports.RRuleError=u,exports.SCHEDULE_CALENDAR_ID=K,exports.SCHEDULE_SURFACE_ID=Q,exports.SCHEDULE_TODO_ID=z,exports.SCHEDULE_WORKSPACE_NAME=W,exports.STANDARD_SCHEMAS=je,exports.ScheduleClient=class{constructor(e,t={}){this.aiws=e,this.handle=null,this.locale=t.locale??"zh"}async ensure(){var e,t,n;if(this.handle)return this.handle;const r=await this.aiws.call("ws.ensure",{name:W,title:J(this.locale,"workspace")}),o={workspace_id:r.workspace_id,epoch:r.epoch,created:r.created,todo:z,calendar:K},i=new Set;for(const l of[z,K,Q])try{(await this.aiws.call("doc.read",{workspace_id:r.workspace_id,entity_id:l})).deleted||i.add(l)}catch(s){const e=null==s?void 0:s.code;if("NOT_FOUND"!==e&&"TARGET_DELETED"!==e)throw s}const a=[];if(i.has(z)||a.push(ee("todo",{entity_id:z,parent_id:"data",order_key:"u",locale:this.locale})),i.has(K)||a.push(ee("calendar",{entity_id:K,parent_id:"data",order_key:"v",locale:this.locale})),i.has(Q)||a.push(...Be(this.locale)),a.length){const r=await this.commitTo(o,a,"create the schedule","system"),i="ID_CONFLICT"===(r.sub_code??(null==(t=null==(e=r.errors)?void 0:e[0])?void 0:t.sub_code)??(null==(n=r.error)?void 0:n.sub_code));if("accepted"!==r.status&&("rejected"!==r.status||!i))throw Re(r)}return this.handle=o,o}async commitTo(e,t,n,r="agent"){var o;const i=`sched-${ae("k")}`,a=o=>({protocol_version:"1.2",workspace_id:e.workspace_id,epoch:o,idempotency_key:i,origin:r,message:n,operations:t});let s=await this.aiws.call("doc.commit",a(e.epoch));if("rejected"===s.status&&"EPOCH_MISMATCH"===(s.code??(null==(o=s.error)?void 0:o.code))){const t=await this.aiws.call("ws.get_info",{workspace_id:e.workspace_id});e.epoch=t.epoch,s=await this.aiws.call("doc.commit",a(e.epoch))}return s}async commit(e,t){const n=await this.ensure(),r=await this.commitTo(n,e,t);if("accepted"!==r.status)throw Re(r);return r}async rows(e){const t=await this.ensure(),n=[];for(let r=0;r<100;r++){const o=await this.aiws.call("doc.query",{workspace_id:t.workspace_id,sql:'SELECT "_record" FROM t ORDER BY "_id" LIMIT ? OFFSET ?',params:[Le,r*Le],tables:{t:e},max_rows:Le});for(const[e]of o.rows)n.push("string"==typeof e?JSON.parse(e):e);if(o.rows.length<Le)break}return n}async row(e,n){const r=await this.ensure(),o=(await this.aiws.call("doc.read",{workspace_id:r.workspace_id,entity_id:e,selector:{kind:"table_record",record_id:n}})).content;if(!(null==o?void 0:o.record_id))throw new t({code:"NOT_FOUND",retryable:!1,detail:`record ${n} not found`});return o}async todos(e={}){const t=fe((await this.rows(z)).map(pe));return e.includeDone?t:t.filter((e=>!e.done))}async addTodo(e,t={}){var n,r,o,i;const a=fe((await this.rows(z)).map(pe)),s=e=>a.find((t=>t.record_id===e));let l={items:a};if(t.after){const e=a.findIndex((e=>e.record_id===t.after));l={after:(null==(n=s(t.after))?void 0:n.order)??null,before:(null==(r=a[e+1])?void 0:r.order)??null}}else if(t.before){const e=a.findIndex((e=>e.record_id===t.before));l={after:(null==(o=a[e-1])?void 0:o.order)??null,before:(null==(i=s(t.before))?void 0:i.order)??null}}const{record_id:d,ops:c}=he(z,e,l);return await this.commit(c,`add to-do: ${e.title}`),pe(await this.row(z,d))}async completeTodo(e,t=!0){const n=await this.row(z,e),r=_e(z,n,t);r.length&&await this.commit(r,`${t?"complete":"reopen"} to-do ${e}`)}async updateTodo(e,t){const n=await this.row(z,e),r=we(z,n,t);r.length&&await this.commit(r,`update to-do ${e}`)}async moveTodo(e,n){const r=fe((await this.rows(z)).map(pe)),o=r.find((t=>t.record_id===e));if(!o)throw new t({code:"NOT_FOUND",retryable:!1,detail:`to-do ${e} not found`});const i=r.filter((t=>t.record_id!==e));let a;if(n.before||n.after){const e=i.findIndex((e=>e.record_id===(n.before??n.after)));if(e<0)throw new t({code:"NOT_FOUND",retryable:!1,detail:`to-do ${n.before??n.after} not found`});a=ge(i,n.before?e:e+1)}const s=me(z,o,{status:n.status,order:a});s.length&&await this.commit(s,`move to-do ${e}`)}async removeTodos(e){const t=await Promise.all(e.map((e=>this.row(z,e))));await this.commit([de(z,t)],`delete to-do ${e.join(", ")}`)}async events(e,t={}){return $e(await this.rows(K),e,t)}async addEvent(e){var t;void 0!==(null==(t=e.ext)?void 0:t.rrule)&&"string"==typeof e.ext.rrule&&(e={...e,ext:{...e.ext,rrule:_(h(e.ext.rrule))}});const{record_id:n,ops:r}=Te(K,e);return await this.commit(r,`add event: ${e.title}`),n}async occurrence(e){const t=await this.rows(K);return{occ:Ce(t,e),rows:t}}async editEvent(e,t,n="one"){const{occ:r,rows:o}=await this.occurrence(e),{ops:i,record_id:a}=Ie(K,r,t,n,{rows:o});return i.length&&await this.commit(i,`edit event ${e} (${n})`),a}async deleteEvent(e,t="one"){const{occ:n,rows:r}=await this.occurrence(e);await this.commit(Ne(K,n,t,{rows:r}),`delete event ${e} (${t})`)}},exports.TODO_DONE=V,exports.TODO_SCHEMA_ID=q,exports.WEEKDAYS=c,exports.aiwsReferenceUrl=function(t,n){const r=t.workspace_id??n;if(!r)throw new Error("reference names no workspace");const o=[];"fixed"===t.mode&&o.push("mode=fixed"),null!=t.selector&&o.push(`selector=${e.encodeObjQueryComponent(e.canonicalJson(t.selector))}`),null!=t.version&&o.push(`version=${e.encodeObjQueryComponent(e.canonicalJson(t.version))}`);const i=e.objServiceUrl("aiworkspace",[r,"entities",t.entity_id]);return e.normalizeObjectUrl(o.length?`${i}?${o.join("&")}`:i)},exports.aiwsTarget=n,exports.bindingAccepts=qe,exports.bindingsPayload=function(e,t,n){var r;const o={};for(const[i,a]of Object.entries(e)){const e=He(a).map((e=>({entity_id:n[e]??e})));(null==(r=t[i])?void 0:r.many)||Array.isArray(a)?e.length>0&&(o[i]=e):e[0]&&(o[i]=e[0])}return o},exports.boundIds=function(e){return null==e?[]:Array.isArray(e)?e:[e]},exports.calendarFields=X,exports.calendarOccurrences=$e,exports.canonicalOriginal=ce,exports.checkBindResult=Qe,exports.checkBindSteps=function(e,t,n,r){var o,i,a,s;const l=[];if(void 0!==e)if(!Array.isArray(e)||e.length>16)l.push("on_bind: at most 16 steps");else for(const[d,c]of e.entries()){const e=c,t=`on_bind[${d}]`;if(!e||"object"!=typeof e||"string"!=typeof e.binding){l.push(`${t}: names a binding`);continue}const r=n[e.binding];if(!r){l.push(`${t}: ${e.binding} is not a declared binding`);continue}if(1===["pick","from_parent","create"].filter((t=>t in e)).length){if("pick"in e&&!["one","many","all"].includes(String(e.pick))&&l.push(`${t}: pick is one, many or all`),"pick"in e&&"one"!==e.pick&&!r.many&&l.push(`${t}: ${e.binding} takes one`),"from_parent"in e&&"string"!=typeof e.from_parent&&l.push(`${t}: from_parent names a binding of the parent`),"create"in e){const n=e.create,r=n&&"object"==typeof n?["standard","table","dir"].filter((e=>e in n)):[];1!==r.length?l.push(`${t}: create one of standard, table, dir`):"standard"!==r[0]||je.includes(String(n.standard))?"table"!==r[0]||Array.isArray(null==(o=n.table)?void 0:o.fields)&&"string"==typeof(null==(i=n.table)?void 0:i.name)?"dir"===r[0]&&"string"!=typeof(null==(a=n.dir)?void 0:a.name)&&l.push(`${t}: create.dir needs name`):l.push(`${t}: create.table needs name and fields`):l.push(`${t}: no standard table ${String(n.standard)}`),void 0!==e.when&&"missing"!==e.when&&"always"!==e.when&&l.push(`${t}: when is missing or always`)}}else l.push(`${t}: one of pick, from_parent, create`)}if(void 0!==t)if(!Array.isArray(t)||t.length>16)l.push("on_init_control: at most 16 steps");else for(const[d,c]of t.entries()){const e=c,t=`on_init_control[${d}]`;if("children"===(null==e?void 0:e.require))continue;const n=null==(s=null==e?void 0:e.then)?void 0:s.action;"string"!=typeof n?l.push(`${t}: { require: "children" } or { then: { action } }`):r.includes(n)||l.push(`${t}: ${n} is not a declared action`)}return l},exports.commitOverLimit=function(e){if(e.length>i)return{limit:"operations",value:e.length,max:i};let t=2;for(const n of e)t+=s(n)+1;return t+4096>o?{limit:"bytes",value:t,max:o}:null},exports.commitWithParts=d,exports.createOps=function(e,t){const n=[],r={};for(const o of e.values())for(const e of o.create){const o=t.newId();r[e.ref]=o;const i={entity_id:o,parent_id:t.folderId,order_key:t.orderKey(),name:t.freeName(e.name)};if("standard"===e.kind){const r=e.schema_id===q?"todo":e.schema_id===P?"calendar":null;if(!r)throw new Ue(`cannot create a table of ${e.schema_id}`,"INVALID");n.push(ee(r,{...i,locale:t.locale}))}else"table"===e.kind?n.push({op:"entity.create",type_id:"buckyos.table-source",...i,payload:{fields:e.fields,...e.title_field_id?{title_field_id:e.title_field_id}:{}}}):n.push({op:"entity.create",type_id:"buckyos.dir",...i,payload:{members:{}}})}return{ops:n,ids:r}},exports.dateOf=v,exports.dayNumber=b,exports.dayOf=D,exports.daysInMonth=g,exports.defaultOnBind=Ve,exports.defaultOnInit=Xe,exports.deleteRecordsOp=de,exports.describeRRule=function(e,t="zh"){var n;const r="zh"===t,o=e.interval,i=e=>e.map((e=>{const t=r?U[e.weekday]:j[e.weekday];return void 0===e.ordinal?t:r?`${C[e.ordinal]}${t}`:`${B[e.ordinal]} ${t}`})),a=e=>r?e.join("、"):e.length>1?`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`:e.join(""),s=e=>r?-1===e?"最后一天":`${e} 日`:-1===e?"the last day":`day ${e}`;let l;switch(e.freq){case"DAILY":l=r?1===o?"每天":`每 ${o} 天`:1===o?"every day":`every ${o} days`;break;case"WEEKLY":if(F(e.byDay)&&1===o)l=r?"每个工作日":"every weekday";else{const t=e.byDay?a(i(e.byDay)):"";l=r?`${1===o?"每周":`每 ${o} 周的`}${t}`:`${1===o?"every week":`every ${o} weeks`}${t?` on ${t}`:""}`}break;case"MONTHLY":{let t="";e.byMonthDay?t=a(e.byMonthDay.map(s)):e.byDay&&void 0!==e.bySetPos?t=F(e.byDay)?r?`${C[e.bySetPos]}工作日`:`the ${B[e.bySetPos]} weekday`:r?`${C[e.bySetPos]}${a(i(e.byDay))}`:`the ${B[e.bySetPos]} of ${a(i(e.byDay))}`:e.byDay&&(t=r?a(i(e.byDay)):`the ${a(i(e.byDay))}`),l=r?`${1===o?"每月":`每 ${o} 个月的`}${t}`:`${1===o?"every month":`every ${o} months`}${t?` on ${t}`:""}`;break}case"YEARLY":{const t=null==(n=e.byMonth)?void 0:n.map((e=>r?`${e} 月`:H[e-1]));let d=t?a(t):"";e.byMonthDay?d+=r?a(e.byMonthDay.map(s)):` ${a(e.byMonthDay.map((e=>-1===e?"last day":String(e))))}`:e.byDay&&(d+=r?a(i(e.byDay)):` on the ${a(i(e.byDay))}`),l=r?`${1===o?"每年":`每 ${o} 年的`}${d}`:`${1===o?"every year":`every ${o} years`}${d.trim()?` in ${d.trim()}`:""}`;break}}return void 0!==e.count&&(l+=r?`,共 ${e.count} 次`:`, ${e.count} times`),void 0!==e.until&&(l+=r?`,到 ${e.until.slice(0,10)} 为止`:`, until ${e.until.slice(0,10)}`),l},exports.eventAddOps=Te,exports.eventDeleteOps=Ne,exports.eventEditOps=Ie,exports.eventPostponeOps=function(e,t,n,r){return Ie(e,t,{times:t.allDay?{allDay:!0,startDate:De(t.startDate,Math.max(1,Math.round(n/1440))),endDate:De(t.endDate,Math.max(1,Math.round(n/1440)))}:{allDay:!1,start:new Date(t.startMs+6e4*n).toISOString(),end:new Date(t.endMs+6e4*n).toISOString()}},"one",r)},exports.eventSkipOps=(e,t,n)=>Ne(e,t,"one",n),exports.expandSeries=N,exports.findOccurrence=Ce,exports.formatRRule=_,exports.insertRecordOp=le,exports.isDate=m,exports.isLeap=w,exports.isOrderKey=ne,exports.isTimeZone=$,exports.localDate=Me,exports.localDay=A,exports.newRecordId=ae,exports.noUiDialogs=We,exports.occurrenceId=R,exports.orderAt=ge,exports.orderKeyBetween=oe,exports.orderKeysBetween=function(e,t,n){const r=[];let o=e;for(let i=0;i<n;i++)o=oe(o,t),r.push(o);return r},exports.originalOf=function(e){return e.date??new Date(e.startMs).toISOString()},exports.parseAiwsReferenceUrl=function(t){const n=e.parseObjectUrl(t),r=e.objectSegments(n);if("obj"!==n.kind||"aiworkspace"!==n.host.name||3!==r.length||"entities"!==r[1])throw new Error(`${t} is not an AI Workspace entity url`);const o={workspace_id:r[0],entity_id:r[2],mode:"fixed"===n.query.mode?"fixed":"live"};return void 0!==n.query.selector&&(o.selector=JSON.parse(n.query.selector)),void 0!==n.query.version&&(o.version=JSON.parse(n.query.version)),o},exports.parseOccurrenceId=function(e){const t=e.indexOf("@");return t<0?{recordId:e,original:null}:{recordId:e.slice(0,t),original:e.slice(t+1)}},exports.parseRRule=h,exports.recurrencePresets=function(e,t="zh"){const n=D(e),{y:r,m:o,d:i}=x(n),a=k(n),s=Math.floor((i-1)/7)+1,l=i+7>g(r,o),d="zh"===t,u=c[a],y=[{id:"none",label:d?"不重复":"Does not repeat",rrule:null},{id:"daily",label:d?"每天":"Daily",rrule:"FREQ=DAILY"},{id:"weekdays",label:d?"每个工作日(周一至周五)":"Every weekday (Monday to Friday)",rrule:"FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR"},{id:"weekly",label:d?`每周的${U[a]}`:`Weekly on ${j[a]}`,rrule:`FREQ=WEEKLY;BYDAY=${u}`},{id:"monthly_day",label:d?`每月 ${i} 日`:`Monthly on day ${i}`,rrule:`FREQ=MONTHLY;BYMONTHDAY=${i}`}];return s<=4&&y.push({id:"monthly_nth",label:d?`每月${C[s]}${U[a]}`:`Monthly on the ${B[s]} ${j[a]}`,rrule:`FREQ=MONTHLY;BYDAY=${s}${u}`}),l&&y.push({id:"monthly_last",label:d?`每月最后一个${U[a]}`:`Monthly on the last ${j[a]}`,rrule:`FREQ=MONTHLY;BYDAY=-1${u}`}),y.push({id:"yearly",label:d?`每年 ${o} 月 ${i} 日`:`Annually on ${H[o-1]} ${i}`,rrule:`FREQ=YEARLY;BYMONTH=${o};BYMONTHDAY=${i}`}),y},exports.resolveBindings=async function(e,t){const n=t.standardSchemas??je,r=t.no_ui?We():t.dialogs,o=new Map,i=[],a=async(e,s)=>{const l={reason:t.reason,no_ui:t.no_ui,node:e.id,title:e.title,decls:e.decls,given:e.given??{},parent:s,find:t.find,canCreate:e=>Boolean(e.schema_id&&n.includes(e.schema_id)),dialogs:r},d="function"==typeof e.onBind?e.onBind:Array.isArray(e.onBind)?Ge(e.onBind):Ve;let c;try{c=await d(l)}catch(h){if(h instanceof Ue)throw new Ue(h.message,h.code,h.node??e.id,h.binding);throw h}if(null===c)throw new Ue(`${e.title}: cancelled`,"CANCELLED",e.id);c=Qe(c,e.decls,e.id),o.set(e.id,c);const u=[];for(const t of e.children)u.push(await a(t,{decls:e.decls,bound:c.bindings}));const y="function"==typeof e.onInit?e.onInit:Xe,p=Array.isArray(e.onInit)?e.onInit:[],f=await y({reason:t.reason,no_ui:t.no_ui,node:e.id,title:e.title,decls:e.decls,bound:c.bindings,children:u,dialogs:r});if(!0!==f)throw new Ue(f,"NOT_READY",e.id);for(const t of p)"then"in t&&i.push({node:e.id,action:t.then.action});return{node:e.id,title:e.title,ready:!0,missing:[]}};try{return await a(e,t.parent??null),{ok:!0,results:o,then:i}}catch(s){if(s instanceof Ue)return{ok:!1,error:s};throw s}},exports.scheduleBoardOps=Be,exports.scheduleLabel=J,exports.seriesStartOf=L,exports.setValuesOps=se,exports.sortTodos=fe,exports.splitCommitOperations=l,exports.standardTableOp=ee,exports.stepsOnBind=Ge,exports.todoAddOps=he,exports.todoCompleteOps=_e,exports.todoFields=G,exports.todoItem=pe,exports.todoMoveOps=me,exports.todoUpdateOps=we,exports.viewerTimeZone=Oe,exports.weekdayOf=k,exports.ymdOf=x,exports.zonedParts=S,exports.zonedToUtc=E;
|
|
2
|
-
//# sourceMappingURL=aiws_bind-
|
|
1
|
+
"use strict";const e=require("./object_url-8fb5a7bf.js");class t extends Error{constructor(e){super(`${e.code}${e.sub_code?`/${e.sub_code}`:""}: ${e.detail}`),this.name="AiwsFailure",this.code=e.code,this.subCode=e.sub_code,this.data=e.data}}function n(e){return e.startsWith("/")||e.startsWith("~")?{path:e}:{entity_id:e}}const r=6291456,o=33554432,i=5e4,a=new TextEncoder;function s(e){const t=JSON.stringify(e);return t.length+(/[^\x00-\x7f]/.test(t)?a.encode(t).length-t.length:0)}function l(e,t=6291456){const n=[];let r=[],o=2;for(const i of e){const e=s(i)+1;r.length>0&&o+e>t&&(n.push(r),r=[],o=2),r.push(i),o+=e}return(r.length>0||0===n.length)&&n.push(r),n}async function d(e,t,n={}){var o,i;const a=n.method??"doc.commit",s=l(Array.isArray(t.operations)?t.operations:[],n.partBytes??r);if(s.length<=1)return await e(a,t);const{workspace_id:d,epoch:c,idempotency_key:u}=t;for(let r=0;;r++){const l=[];for(let t=0;t<s.length-1;t++){null==(o=n.onPart)||o.call(n,t+1,s.length);const r=await e("doc.stage",{workspace_id:d,epoch:c,idempotency_key:u,part:t,operations:s[t]});if(!r||!1===r.ok||"string"!=typeof r.digest){const e=(null==r?void 0:r.error)??{code:"STORAGE_IO_ERROR",retryable:!0,detail:"doc.stage returned no digest"};return{status:"rejected",code:e.code,retryable:e.retryable,detail:e.detail,...e.sub_code?{sub_code:e.sub_code}:{},errors:[e]}}l.push(r.digest)}null==(i=n.onPart)||i.call(n,s.length,s.length);const y=await e(a,{...t,staged:l,operations:s[s.length-1]});if(0!==r||"rejected"!==(null==y?void 0:y.status)||"STAGED_PARTS_MISSING"!==y.sub_code)return y}}const c=["MO","TU","WE","TH","FR","SA","SU"];class u extends Error{constructor(e){super(e),this.name="RRuleError"}}const y=["DAILY","WEEKLY","MONTHLY","YEARLY"];function f(e,t,n,r,o=!1){if(!/^[+-]?\d{1,3}$/.test(t))throw new u(`${e}: ${t} is not a number`);const i=Number(t);if(i<n||i>r||!o&&0===i)throw new u(`${e}: ${t} is out of range`);return i}function p(e,t,n){const r=t.split(",");if(0===r.length||r.length>n||r.some((e=>""===e)))throw new u(`${e}: at most ${n} comma-separated values`);return r}function h(e){const t=e.startsWith("RRULE:")?e.slice(6):e;if(""===t.trim())throw new u("empty rule");const n=new Set,r={};for(const a of t.split(";")){const e=a.indexOf("=");if(e<=0)throw new u(`${a||"(empty)"}: expected NAME=VALUE`);const t=a.slice(0,e),o=a.slice(e+1);if(t!==t.toUpperCase()||o!==o.toUpperCase())throw new u(`${a}: write the rule in upper case`);if(n.has(t))throw new u(`${t}: given twice`);if(n.add(t),!["FREQ","INTERVAL","COUNT","UNTIL","BYDAY","BYMONTHDAY","BYMONTH","BYSETPOS","WKST"].includes(t))throw new u(`${t}: not supported (supported: FREQ, INTERVAL, COUNT, UNTIL, BYDAY, BYMONTHDAY, BYMONTH, BYSETPOS, WKST)`);if(""===o)throw new u(`${t}: empty value`);r[t]=o}if(!r.FREQ)throw new u("FREQ is required");if(!y.includes(r.FREQ))throw new u(`FREQ: ${r.FREQ} is not supported (DAILY, WEEKLY, MONTHLY, YEARLY)`);const o=r.FREQ,i={freq:o,interval:1,wkst:0};if(void 0!==r.INTERVAL&&(i.interval=f("INTERVAL",r.INTERVAL,1,999)),void 0!==r.COUNT&&void 0!==r.UNTIL)throw new u("COUNT and UNTIL cannot both be given");if(void 0!==r.COUNT&&(i.count=f("COUNT",r.COUNT,1,1e3)),void 0!==r.UNTIL&&(i.until=function(e){let t=/^(\d{4})(\d{2})(\d{2})$/.exec(e);if(t){const n=`${t[1]}-${t[2]}-${t[3]}`;if(!m(n))throw new u(`UNTIL: ${e} is not a date`);return n}if(t=/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z$/.exec(e),t){const n=Date.UTC(+t[1],+t[2]-1,+t[3],+t[4],+t[5],+t[6]);if(!m(`${t[1]}-${t[2]}-${t[3]}`)||+t[4]>23||+t[5]>59||+t[6]>59)throw new u(`UNTIL: ${e} is not a UTC time`);return new Date(n).toISOString()}throw new u(`UNTIL: ${e} must be YYYYMMDD or YYYYMMDDTHHMMSSZ`)}(r.UNTIL)),void 0!==r.BYDAY){i.byDay=p("BYDAY",r.BYDAY,7).map((e=>{const t=/^([+-]?\d)?(MO|TU|WE|TH|FR|SA|SU)$/.exec(e);if(!t)throw new u(`BYDAY: ${e} is not a weekday`);const n=c.indexOf(t[2]);if(void 0===t[1])return{weekday:n};if("MONTHLY"!==o&&"YEARLY"!==o)throw new u(`BYDAY: ${e}: an ordinal needs FREQ=MONTHLY or YEARLY`);return{weekday:n,ordinal:f("BYDAY",t[1],-5,5)}}));const e=i.byDay.map((e=>`${e.ordinal??""}${e.weekday}`));if(new Set(e).size!==e.length)throw new u("BYDAY: repeated day")}if(void 0!==r.BYMONTHDAY){if("MONTHLY"!==o&&"YEARLY"!==o)throw new u("BYMONTHDAY needs FREQ=MONTHLY or YEARLY");if(i.byMonthDay=p("BYMONTHDAY",r.BYMONTHDAY,31).map((e=>f("BYMONTHDAY",e,-1,31))),new Set(i.byMonthDay).size!==i.byMonthDay.length)throw new u("BYMONTHDAY: repeated day")}if(void 0!==r.BYMONTH){if("YEARLY"!==o)throw new u("BYMONTH needs FREQ=YEARLY");if(i.byMonth=p("BYMONTH",r.BYMONTH,12).map((e=>f("BYMONTH",e,1,12))),new Set(i.byMonth).size!==i.byMonth.length)throw new u("BYMONTH: repeated month")}if(void 0!==r.BYSETPOS){if("MONTHLY"!==o||!i.byDay)throw new u("BYSETPOS needs FREQ=MONTHLY and BYDAY");i.bySetPos=f("BYSETPOS",r.BYSETPOS,-5,5)}if(void 0!==r.WKST){const e=c.indexOf(r.WKST);if(e<0)throw new u(`WKST: ${r.WKST} is not a weekday`);i.wkst=e}return i}function _(e){var t,n,r;const o=[`FREQ=${e.freq}`];return e.interval>1&&o.push(`INTERVAL=${e.interval}`),(null==(t=e.byMonth)?void 0:t.length)&&o.push(`BYMONTH=${e.byMonth.join(",")}`),(null==(n=e.byMonthDay)?void 0:n.length)&&o.push(`BYMONTHDAY=${e.byMonthDay.join(",")}`),(null==(r=e.byDay)?void 0:r.length)&&o.push(`BYDAY=${e.byDay.map((e=>`${e.ordinal??""}${c[e.weekday]}`)).join(",")}`),void 0!==e.bySetPos&&o.push(`BYSETPOS=${e.bySetPos}`),void 0!==e.count&&o.push(`COUNT=${e.count}`),void 0!==e.until&&o.push(`UNTIL=${10===e.until.length?e.until.replace(/-/g,""):e.until.replace(/[-:]/g,"").replace(/\.\d{3}/,"")}`),0!==e.wkst&&o.push(`WKST=${c[e.wkst]}`),o.join(";")}function m(e){const t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)return!1;const n=+t[1],r=+t[2],o=+t[3];return n>=1&&r>=1&&r<=12&&o>=1&&o<=g(n,r)}const w=e=>e%4==0&&e%100!=0||e%400==0;function g(e,t){return[31,w(e)?29:28,31,30,31,30,31,31,30,31,30,31][t-1]}const b=(e,t,n)=>Math.floor(Date.UTC(e,t-1,n)/864e5);function D(e){return b(+e.slice(0,4),+e.slice(5,7),+e.slice(8,10))}function v(e){return new Date(864e5*e).toISOString().slice(0,10)}function x(e){const t=new Date(864e5*e);return{y:t.getUTCFullYear(),m:t.getUTCMonth()+1,d:t.getUTCDate()}}const k=e=>((e+3)%7+7)%7,M=new Map;function O(e){let t=M.get(e);return t||(t=new Intl.DateTimeFormat("en-US",{timeZone:e,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}),M.set(e,t)),t}function $(e){try{return O(e),!0}catch{return!1}}function S(e,t){const n={};for(const r of O(t).formatToParts(new Date(e)))"literal"!==r.type&&(n[r.type]=Number(r.value));return{y:n.year,m:n.month,d:n.day,h:24===n.hour?0:n.hour,mi:n.minute,s:n.second}}function T(e,t){const n=S(e,t);return Date.UTC(n.y,n.m-1,n.d,n.h,n.mi,n.s)-1e3*Math.floor(e/1e3)}function E(e,t,n,r){const o=864e5*e+6e4*t+1e3*n,i=o-T(o,r);return o-T(i,r)}function A(e,t){const n=S(e,t);return b(n.y,n.m,n.d)}function Y(e,t,n){const r=x(n),o=[],i=(e,t,n)=>{for(let r=0;r<t;r++)n.some((t=>void 0===t.ordinal&&t.weekday===k(e+r)))&&o.push(e+r)},a=(e,t,n)=>{const r=[];for(let o=0;o<t;o++)k(e+o)===n.weekday&&r.push(e+o);const i=n.ordinal>0?n.ordinal-1:r.length+n.ordinal;i>=0&&i<r.length&&o.push(r[i])},s=(e,t,n)=>{const r=g(e,t);for(const i of n){const n=i>0?i:r+i+1;n>=1&&n<=r&&o.push(b(e,t,n))}};switch(e.freq){case"DAILY":{const r=n+t*e.interval,{m:i,d:a}=x(r);if(e.byMonth&&!e.byMonth.includes(i))break;if(e.byMonthDay&&!e.byMonthDay.some((e=>e>0?e===a:g(x(r).y,i)+e+1===a)))break;if(e.byDay&&!e.byDay.some((e=>e.weekday===k(r))))break;o.push(r);break}case"WEEKLY":if(i(n-(k(n)-e.wkst+7)%7+t*e.interval*7,7,e.byDay??[{weekday:k(n)}]),e.byMonth)return o.filter((t=>e.byMonth.includes(x(t).m))).sort(((e,t)=>e-t));break;case"MONTHLY":{const n=12*r.y+(r.m-1)+t*e.interval,l=Math.floor(n/12),d=n%12+1,c=b(l,d,1),u=g(l,d);if(e.byMonthDay){if(s(l,d,e.byMonthDay),e.byDay){const t=o.filter((t=>e.byDay.some((e=>e.weekday===k(t)))));o.length=0,o.push(...t)}}else if(e.byDay){i(c,u,e.byDay);for(const t of e.byDay)void 0!==t.ordinal&&a(c,u,t)}else r.d<=u&&o.push(b(l,d,r.d));break}case"YEARLY":{const n=r.y+t*e.interval;if(e.byDay&&!e.byMonth&&!e.byMonthDay){const t=b(n,1,1),r=w(n)?366:365;i(t,r,e.byDay);for(const n of e.byDay)void 0!==n.ordinal&&a(t,r,n);break}const l=e.byMonth??[r.m];for(const t of l)if(e.byMonthDay)s(n,t,e.byMonthDay);else if(e.byDay){const r=b(n,t,1),o=g(n,t);i(r,o,e.byDay);for(const t of e.byDay)void 0!==t.ordinal&&a(r,o,t)}else r.d<=g(n,t)&&o.push(b(n,t,r.d));if(e.byMonthDay&&e.byDay){const t=o.filter((t=>e.byDay.some((e=>e.weekday===k(t)))));o.length=0,o.push(...t)}break}}const l=[...new Set(o)].sort(((e,t)=>e-t));if(void 0!==e.bySetPos){const t=e.bySetPos>0?e.bySetPos-1:l.length+e.bySetPos;return t>=0&&t<l.length?[l[t]]:[]}return l}function I(e,t,n){const r=x(n);switch(e.freq){case"DAILY":return n+t*e.interval;case"WEEKLY":return n-(k(n)-e.wkst+7)%7+t*e.interval*7;case"MONTHLY":{const n=12*r.y+(r.m-1)+t*e.interval;return b(Math.floor(n/12),n%12+1,1)}case"YEARLY":return b(r.y+t*e.interval,1,1)}}function N(e,t,n,r={}){var o;const i=r.limit??2e3,a=new Set(r.exdate??[]),s=[];let l,d,c,u=0,y=0,f="UTC";const p=r.viewerTz??"UTC";if("date"===t.kind)l=D(t.date),d=A(n.fromMs,p)-(r.durationDays??0),c=A(n.toMs-1,p);else{f=t.tz;const e=S(Date.parse(t.utc),f);l=b(e.y,e.m,e.d),u=60*e.h+e.mi,y=e.s,d=A(n.fromMs-(r.durationMs??0),f)-1,c=A(n.toMs,f)+1}const h=10===(null==(o=e.until)?void 0:o.length)?D(e.until):void 0,_=e.until&&e.until.length>10?Date.parse(e.until):void 0;let m=0;const w=o=>{if(void 0!==e.count&&m>=e.count)return!1;if(void 0!==h&&o>h)return!1;let i;if("date"===t.kind){if(void 0!==_&&864e5*o>_)return!1;const e=v(o);i={original:e,date:e}}else{const e=E(o,u,y,f);if(void 0!==_&&e>_)return!1;i={original:new Date(e).toISOString(),startMs:e}}return m+=1,a.has(i.original)||("date"===t.kind?o>=d&&o<=c&&s.push(i):i.startMs+(r.durationMs??0)>n.fromMs&&i.startMs<n.toMs&&s.push(i)),!0};if(l>c||!w(l))return s;let g=void 0===e.count?function(e,t,n){const r=x(t),o=x(n);let i;switch(e.freq){case"DAILY":i=Math.floor((n-t)/e.interval);break;case"WEEKLY":i=Math.floor((n-I(e,0,t))/(7*e.interval));break;case"MONTHLY":i=Math.floor((12*o.y+o.m-(12*r.y+r.m))/e.interval);break;case"YEARLY":i=Math.floor((o.y-r.y)/e.interval)}return Math.max(-1,i-1)}(e,l,d)+1:0;for(let b=0;b<2e5&&s.length<i&&!(I(e,g,l)>c);b++,g++)for(const t of Y(e,g,l))if(!(t<=l)){if(t>c)return s;if(!w(t)||s.length>=i)return s}return s}function L(e,t,n="UTC"){return!0===e.all_day?"string"==typeof e.start_date?{kind:"date",date:e.start_date}:null:"string"==typeof e.start?{kind:"datetime",utc:e.start,tz:t&&$(t)?t:n}:null}function R(e,t){return`${e}@${t}`}const C={1:"第一个",2:"第二个",3:"第三个",4:"第四个",5:"第五个",[-1]:"最后一个",[-2]:"倒数第二个",[-3]:"倒数第三个",[-4]:"倒数第四个",[-5]:"倒数第五个"},B={1:"first",2:"second",3:"third",4:"fourth",5:"fifth",[-1]:"last",[-2]:"second to last",[-3]:"third to last",[-4]:"fourth to last",[-5]:"fifth to last"},U=["周一","周二","周三","周四","周五","周六","周日"],j=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],H=["January","February","March","April","May","June","July","August","September","October","November","December"],F=e=>!!e&&5===e.length&&e.every((e=>void 0===e.ordinal))&&[0,1,2,3,4].every((t=>e.some((e=>e.weekday===t))));const q="buckyos.todo@1",P="buckyos.calendar@1",W="schedule",z="todo",K="calendar",Q="schedule-board",V="done",Z={zh:{title:"标题",status:"状态",due:"截止",order:"顺序",done_at:"完成时间",ext:"扩展",todo:"待办",doing:"进行中",done:"已完成",all_day:"全天",start:"开始",end:"结束",start_date:"开始日期",end_date:"结束日期",confirmed:"已确认",tentative:"暂定",cancelled:"已取消",todo_table:"待办",calendar_table:"日程",workspace:"我的日程",board:"日程"},en:{title:"Title",status:"Status",due:"Due",order:"Order",done_at:"Completed",ext:"Extension",todo:"To do",doing:"In progress",done:"Done",all_day:"All day",start:"Start",end:"End",start_date:"Start date",end_date:"End date",confirmed:"Confirmed",tentative:"Tentative",cancelled:"Cancelled",todo_table:"To-do",calendar_table:"Calendar",workspace:"My schedule",board:"Schedule"}};function J(e,t){return Z[e][t]??Z.en[t]??t}function G(e="zh"){const t=t=>J(e,t);return[{field_id:"title",name:t("title"),type:"text",required:!0},{field_id:"status",name:t("status"),type:"select",required:!0,options:["todo","doing","done"].map((e=>({option_id:e,label:t(e)})))},{field_id:"due",name:t("due"),type:"date",nullable:!0},{field_id:"order",name:t("order"),type:"text",nullable:!0},{field_id:"done_at",name:t("done_at"),type:"datetime",nullable:!0},{field_id:"ext",name:t("ext"),type:"json",nullable:!0}]}function X(e="zh"){const t=t=>J(e,t);return[{field_id:"title",name:t("title"),type:"text",required:!0},{field_id:"all_day",name:t("all_day"),type:"boolean",nullable:!0},{field_id:"start",name:t("start"),type:"datetime",nullable:!0},{field_id:"end",name:t("end"),type:"datetime",nullable:!0},{field_id:"start_date",name:t("start_date"),type:"date",nullable:!0},{field_id:"end_date",name:t("end_date"),type:"date",nullable:!0},{field_id:"status",name:t("status"),type:"select",nullable:!0,options:["confirmed","tentative","cancelled"].map((e=>({option_id:e,label:t(e)})))},{field_id:"ext",name:t("ext"),type:"json",nullable:!0}]}function ee(e,t){const n=t.locale??"zh";return{op:"entity.create",entity_id:t.entity_id,type_id:"buckyos.table-source",parent_id:t.parent_id,order_key:t.order_key,schema_id:"todo"===e?q:P,name:t.name??J(n,"todo"===e?"todo_table":"calendar_table"),payload:{title_field_id:"title",fields:"todo"===e?G(n):X(n)}}}const te="0123456789abcdefghijklmnopqrstuvwxyz";function ne(e){return"string"==typeof e&&e.length>0&&e.length<=64&&/^[0-9a-z]+$/.test(e)&&!e.endsWith("0")}function re(e,t){if(null!==t){let n=0;for(;n<t.length&&(e[n]??"0")===t[n];)n++;if(n>0)return t.slice(0,n)+re(e.length>n?e.slice(n):"",t.slice(n))}const n=e.length?te.indexOf(e[0]):0,r=null!==t?te.indexOf(t[0]):36;return r-n>1?te[Math.floor((n+r+1)/2)]:null!==t&&t.length>1?t[0]:te[n]+re(e.length>1?e.slice(1):"",null)}function oe(e,t){const n=e??null,r=t??null;if(null!==n&&null!==r&&n>=r)throw new Error("orderKeyBetween requires a < b");const o=null!==n&&null===r?function(e){const t=e.padEnd(Math.max(e.length,8),"0").split("");let n=t.length-1;for(;n>=0&&"z"===t[n];)n--;if(n>=0){t[n]=te[te.indexOf(t[n])+1];for(let e=n+1;e<t.length;e++)t[e]="0";return"0"===t[t.length-1]&&(t[t.length-1]="1"),t.join("")}if(t.length>=64)throw new Error("order key space exhausted; rebalance");return t.join("").padEnd(Math.min(t.length+8,64),"0").slice(0,-1)+"1"}(n):re(n??"",r);if(!ne(o))throw new Error("order key space exhausted; rebalance");return o}let ie=0;function ae(e="r"){ie=(ie+1)%1296;const t=Math.floor(Math.random()*36**6).toString(36).padStart(6,"0");return`${e}${Date.now().toString(36)}${ie.toString(36).padStart(2,"0")}${t}`}function se(e,t,n){var r;const o=[],i=[];for(const[s,l]of Object.entries(n)){const e={record_id:t.record_id,field_id:s,expect:{rev:(null==(r=t.revs)?void 0:r[s])??0}};null==l?void 0!==t.values[s]&&null!==t.values[s]&&i.push(e):o.push({...e,value:l})}const a=[];return o.length&&a.push({op:"table.set_values",source_id:e,values:o}),i.length&&a.push({op:"table.unset_values",source_id:e,values:i}),a}function le(e,t){return{op:"table.insert_records",source_id:e,records:t.map((e=>({record_id:e.record_id,values:Object.fromEntries(Object.entries(e.values).filter((([,e])=>null!=e)))})))}}function de(e,t){return{op:"table.delete_records",source_id:e,records:t.map((e=>({record_id:e.record_id,expect:{rev:e.rev??0}})))}}function ce(e){if(m(e))return e;const t=Date.parse(e);return Number.isFinite(t)?new Date(t).toISOString():e}const ue=e=>Array.isArray(e)?e.filter((e=>"string"==typeof e)).map(ce):[],ye=e=>{const t=null==e?void 0:e.values.ext;return t&&"object"==typeof t&&!Array.isArray(t)?{...t}:{}};function fe(e){const t=e.values,n="string"==typeof t.status?t.status:"todo";return{record_id:e.record_id,rev:e.rev,revs:e.revs,values:e.values,title:"string"==typeof t.title?t.title:"",status:n,due:"string"==typeof t.due?t.due:null,order:ne(t.order)?t.order:null,done:n===V,done_at:"string"==typeof t.done_at?t.done_at:null,ext:ye(e)}}function pe(e){return[...e].sort(((e,t)=>e.order===t.order?e.record_id.localeCompare(t.record_id):null===e.order?1:null===t.order||e.order<t.order?-1:1))}function he(e,t,n={}){const r=t.record_id??ae("t");let o=t.order??null;if(!o)if(void 0!==n.after||void 0!==n.before)o=oe(n.after??null,n.before??null);else{o=oe((n.items??[]).map((e=>e.order)).filter(ne).sort().pop()??null,null)}const i=t.status??"todo";return{record_id:r,order:o,ops:[le(e,[{record_id:r,values:{title:t.title,status:i,order:o,due:t.due??void 0,ext:t.ext&&Object.keys(t.ext).length?t.ext:void 0,done_at:i===V?t.done_at??(new Date).toISOString():void 0}}])]}}function _e(e,t,n,r={}){return se(e,t,n?{status:V,done_at:r.now??(new Date).toISOString()}:{status:r.reopenStatus??"todo",done_at:null})}function me(e,t,n,r={}){const o={},i="string"==typeof t.values.status?t.values.status:void 0;return void 0!==n.status&&n.status!==i&&(o.status=n.status,n.status===V?o.done_at=r.now??(new Date).toISOString():i===V&&(o.done_at=null)),void 0!==n.order&&n.order!==t.values.order&&(o.order=n.order),Object.keys(o).length?se(e,t,o):[]}function we(e,t,n){const r={};for(const o of["title","status","due","order","done_at"])void 0!==n[o]&&(r[o]=n[o]);if(void 0!==n.ext&&(r.ext=n.ext&&Object.keys(n.ext).length?n.ext:null),n.ext_merge){const e=ye(t);for(const[t,r]of Object.entries(n.ext_merge))null===r?delete e[t]:e[t]=r;r.ext=Object.keys(e).length?e:null}return void 0!==r.status&&r.status!==t.values.status&&void 0===r.done_at&&(r.status===V?r.done_at=(new Date).toISOString():t.values.status===V&&(r.done_at=null)),se(e,t,r)}function ge(e,t){const n=e.map((e=>e.order)),r=t>0?n[t-1]:null,o=t<n.length?n[t]:null;return null===r||ne(r)?null!==o&&ne(o)&&(null===r||r<o)?oe(r,o):oe(r,null):oe(null,null)}function be(e){const t=e.values;if(!0===t.all_day){if("string"!=typeof t.start_date||!m(t.start_date))return null;const e="string"==typeof t.end_date&&m(t.end_date)&&t.end_date>=t.start_date?t.end_date:t.start_date;return{allDay:!0,startDate:t.start_date,endDate:e}}if("string"!=typeof t.start)return null;const n=Date.parse(t.start);if(!Number.isFinite(n))return null;const r="string"==typeof t.end?Date.parse(t.end):NaN;return{allDay:!1,startMs:n,endMs:Number.isFinite(r)&&r>=n?r:n+36e5}}function De(e,t){return v(D(e)+t)}const ve=(e,t)=>D(t)-D(e);function xe(e,t,n){const r=ye(e);return{id:e.record_id,row:e,title:"string"==typeof e.values.title?e.values.title:"",allDay:t.allDay,startMs:t.startMs,endMs:t.endMs,startDate:t.startDate,endDate:t.endDate,status:"string"==typeof e.values.status?e.values.status:null,ext:r,recurring:!1,override:!1,agentWritten:!1,...n}}function ke(e,t,n){if(!e.allDay)return e.startMs<t.toMs&&Math.max(e.endMs,e.startMs+1)>t.fromMs;const r=Me(t.fromMs,n),o=Me(t.toMs-1,n);return e.startDate<=o&&e.endDate>=r}function Me(e,t){return new Intl.DateTimeFormat("en-CA",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit"}).format(new Date(e))}function Oe(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}function $e(e,t,n={}){const r=n.viewerTz??Oe(),o=[],i=new Map;for(const s of e){const e=ye(s).recurrence_id;e&&"object"==typeof e&&!Array.isArray(e)&&"string"==typeof e.master&&"string"==typeof e.original&&i.set(`${e.master}@${ce(e.original)}`,s)}const a=new Map(e.map((e=>[e.record_id,e])));for(const s of e){const e=be(s);if(!e)continue;const l=ye(s),d=l.recurrence_id;if(d&&"object"==typeof d){const n="string"==typeof d.master?a.get(d.master):void 0,i="string"==typeof d.original?ce(d.original):void 0,l=xe(s,e,{id:n&&i?R(n.record_id,i):s.record_id,master:n,original:i,recurring:Boolean(n),override:!0});ke(l,t,r)&&o.push(l);continue}const c=e.allDay?ve(e.startDate,e.endDate):e.endMs-e.startMs,u=t=>{const n=`${s.record_id}@${t.original}`;return i.has(n)?null:e.allDay?xe(s,{allDay:!0,startDate:t.date,endDate:De(t.date,c)},{id:n,master:s,original:t.original,recurring:!0}):xe(s,{allDay:!1,startMs:t.startMs,endMs:t.startMs+c},{id:n,master:s,original:t.original,recurring:!0})};let y=null;if("string"==typeof l.rrule)try{y=h(l.rrule)}catch{y=null}if(y){const i=L(s.values,"string"==typeof l.tz?l.tz:void 0,r);if(!i)continue;const a=N(y,i,t,{exdate:ue(l.exdate),viewerTz:r,durationMs:e.allDay?void 0:c,durationDays:e.allDay?c:void 0,limit:n.limit});for(const e of a){const t=u(e);t&&o.push(t)}continue}if(Array.isArray(l.occurrences)&&l.occurrences.length>0){const n=new Set(ue(l.exdate));for(const i of l.occurrences){if("string"!=typeof i)continue;const a=ce(i);if(n.has(a))continue;const s=e.allDay?{original:a,date:a}:{original:a,startMs:Date.parse(a)};if(!e.allDay&&!Number.isFinite(s.startMs))continue;if(e.allDay&&!m(a))continue;const l=u(s);l&&ke(l,t,r)&&o.push({...l,agentWritten:!0})}continue}const f=xe(s,e,{});ke(f,t,r)&&o.push(f)}return o.sort(((e,t)=>Se(e)-Se(t)||e.id.localeCompare(t.id)))}const Se=e=>e.allDay?Date.parse(`${e.startDate}T00:00:00Z`):e.startMs;function Te(e,t){const n=t.record_id??ae("e"),r={title:t.title,status:t.status??void 0,ext:t.ext&&Object.keys(t.ext).length?t.ext:void 0};return t.all_day?(r.all_day=!0,r.start_date=t.start_date??void 0,r.end_date=t.end_date&&t.end_date!==t.start_date?t.end_date:void 0):(r.start=t.start??void 0,r.end=t.end??void 0),{record_id:n,ops:[le(e,[{record_id:n,values:r}])]}}function Ee(e){return e.allDay?{all_day:!0,start_date:e.startDate,end_date:e.endDate!==e.startDate?e.endDate:null,start:null,end:null}:{all_day:null,start:e.start,end:e.end,start_date:null,end_date:null}}function Ae(e,t){return e.filter((e=>{const n=ye(e).recurrence_id;return n&&"object"==typeof n&&n.master===t}))}function Ye(e,t,n,r){return t?De(e,r):((e,t)=>new Date(Date.parse(e)+t).toISOString())(e,n)}function Ie(e,t,n,r,o){const i=o.newRecordId??(()=>ae("e")),a=e=>{const t={...n.values};if(n.ext_merge){const r=ye(e);for(const[e,t]of Object.entries(n.ext_merge))null===t?delete r[e]:r[e]=t;t.ext=Object.keys(r).length?r:null}return t},s=t.master;if(!s||t.row!==s&&"one"===r){const r=t.row,o={...a(r),...n.times?Ee(n.times):{}};if(void 0!==n.rrule&&!s){const e={...o.ext??ye(r)??{}};null===n.rrule?delete e.rrule:e.rrule=_(h(n.rrule)),null===n.rrule&&delete e.exdate,o.ext=Object.keys(e).length?e:null}return{ops:se(e,r,o),record_id:r.record_id}}const l=t.original,d=be(s),c=ye(s);if("one"===r){const r=i(),o={...c,recurrence_id:{master:s.record_id,original:l}};delete o.rrule,delete o.exdate,delete o.occurrences,delete o.rule_text,delete o.covered_until,delete o.maintenance;const u={title:s.values.title,status:s.values.status,ext:o},y=n.times??(t.allDay?{allDay:!0,startDate:t.startDate,endDate:De(t.startDate,ve(d.startDate,d.endDate))}:{allDay:!1,start:new Date(t.startMs).toISOString(),end:new Date(t.startMs+(d.endMs-d.startMs)).toISOString()}),f={...u,...a({record_id:r,values:{ext:o}}),...Ee(y)};return f.ext||(f.ext=o),{ops:[le(e,[{record_id:r,values:f}])],record_id:r}}let u=0,y=0,f=d.allDay?0:d.endMs-d.startMs,p=d.allDay?ve(d.startDate,d.endDate):0;if(n.times){if(n.times.allDay!==d.allDay)throw new Error("changing a series between all-day and timed: edit the series itself (scope all) with new times");n.times.allDay?(y=ve(l,n.times.startDate),p=ve(n.times.startDate,n.times.endDate)):(u=Date.parse(n.times.start)-Date.parse(l),y=Math.round(u/864e5),f=Date.parse(n.times.end)-Date.parse(n.times.start))}const m="string"==typeof c.rrule?h(c.rrule):null,w=Ae(o.rows,s.record_id),g=ue(c.exdate),b=d.allDay?l===d.startDate:l===new Date(d.startMs).toISOString(),D=(e,t)=>d.allDay?{allDay:!0,startDate:De(t,y),endDate:De(De(t,y),p)}:{allDay:!1,start:new Date(e+u).toISOString(),end:new Date(e+u+f).toISOString()},v=e=>void 0!==n.rrule?null===n.rrule?null:_(h(n.rrule)):e?_(function(e,t){if(!t)return e;const n={...e};if(e.byDay&&e.byDay.every((e=>void 0===e.ordinal))&&("WEEKLY"===e.freq||"DAILY"===e.freq))n.byDay=e.byDay.map((e=>({weekday:((e.weekday+t)%7+7)%7})));else if(e.byDay&&"MONTHLY"===e.freq&&1===e.byDay.length&&void 0===e.bySetPos&&Math.abs(t)<7)n.byDay=[{...e.byDay[0],weekday:((e.byDay[0].weekday+t)%7+7)%7}];else if(e.byMonthDay&&1===e.byMonthDay.length&&e.byMonthDay[0]>0){const r=e.byMonthDay[0]+t;r>=1&&r<=28&&(n.byMonthDay=[r])}return n}(e,y)):null,x=[];if("all"===r||b){const t=D(d.startMs,d.startDate),n={...c},r=v(m);r?n.rrule=r:(delete n.rrule,delete n.exdate),r&&g.length&&(n.exdate=g.map((e=>Ye(e,d.allDay,u,y))));const o=a({record_id:s.record_id,values:{ext:n}}),i=void 0!==o.ext?o.ext:n;x.push(...se(e,s,{...o,...Ee(t),ext:i&&Object.keys(i).length?i:null}));for(const a of w){const t=ye(a),n=t.recurrence_id;r?(u||y)&&x.push(...se(e,a,{ext:{...t,recurrence_id:{...n,original:Ye(String(n.original),d.allDay,u,y)}}})):x.push(de(e,[a]))}return{ops:x,record_id:s.record_id}}if(!m)throw new Error("not a repeating event");const k=i(),M=e=>d.allDay?e<l:Date.parse(e)<Date.parse(l);let O={...m},$={...m};if(void 0!==m.count){const e=N(m,L(s.values,"string"==typeof c.tz?c.tz:void 0),{fromMs:d.allDay?Date.parse(`${d.startDate}T00:00:00Z`)-1728e5:d.startMs,toMs:d.allDay?Date.parse(`${l}T00:00:00Z`):Date.parse(l)},{viewerTz:"UTC"}).filter((e=>M(e.original))).length;O={...m,count:Math.max(1,e)},$={...m,count:Math.max(1,m.count-e)}}else O={...m,until:d.allDay?De(l,-1):new Date(Date.parse(l)-1e3).toISOString().replace(/\.\d{3}Z$/,".000Z")};const S={...c,rrule:_(O)},T=g.filter(M);T.length?S.exdate=T:delete S.exdate,x.push(...se(e,s,{ext:S}));const E={...c},A=v($);A?E.rrule=A:delete E.rrule;const Y=g.filter((e=>!M(e))).map((e=>Ye(e,d.allDay,u,y)));Y.length&&A?E.exdate=Y:delete E.exdate;const I=D(d.allDay?void 0:Date.parse(l),d.allDay?l:void 0),R=a({record_id:k,values:{ext:E}}),C={title:s.values.title,status:s.values.status,...R,...Ee(I)};C.ext=(void 0!==R.ext?R.ext:E)??void 0,x.push(le(e,[{record_id:k,values:C}]));for(const h of w){const t=ye(h),n=t.recurrence_id;M(String(n.original))||(A?x.push(...se(e,h,{ext:{...t,recurrence_id:{master:k,original:Ye(String(n.original),d.allDay,u,y)}}})):x.push(de(e,[h])))}return{ops:x,record_id:k}}function Ne(e,t,n,r){const o=t.master;if(!o)return[de(e,[t.row])];const i=t.original,a=ye(o),s=be(o),l=Ae(r.rows,o.record_id),d=s.allDay?i===s.startDate:i===new Date(s.startMs).toISOString();if("all"===n||"following"===n&&d)return[de(e,[o,...l])];const c=[];if("one"===n){const t=ue(a.exdate);t.includes(i)||c.push(...se(e,o,{ext:{...a,exdate:[...t,i].sort()}}));const n=l.filter((e=>ce(String(ye(e).recurrence_id.original))===i));return n.length&&c.push(de(e,n)),c}const u="string"==typeof a.rrule?h(a.rrule):null;if(!u)return[de(e,[t.row])];const y=e=>s.allDay?e<i:Date.parse(e)<Date.parse(i),f={...u,count:void 0,until:s.allDay?De(i,-1):new Date(Date.parse(i)-1e3).toISOString()},p={...a,rrule:_(f)};if(Array.isArray(a.exdate)){const e=ue(a.exdate).filter(y);e.length?p.exdate=e:delete p.exdate}c.push(...se(e,o,{ext:p}));const m=l.filter((e=>!y(String(ye(e).recurrence_id.original))));return m.length&&c.push(de(e,m)),c}const Le=1e3;function Re(e){var n,r,o,i;const a=null==(n=e.errors)?void 0:n[0];if("conflict"===e.status){const n=null==(r=e.conflicts)?void 0:r[0];return new t({code:e.code??"REVISION_CONFLICT",retryable:!0,detail:"changed meanwhile, read it again"+(n?`: ${JSON.stringify(n.selector??n)}`:"")})}return new t({code:e.code??(null==(o=e.error)?void 0:o.code)??"REJECTED",sub_code:e.sub_code??(null==a?void 0:a.sub_code),retryable:!1,detail:(null==a?void 0:a.detail)??e.detail??(null==(i=e.error)?void 0:i.detail)??"refused"})}function Ce(e,n){const r=n.indexOf("@"),o=r<0?n:n.slice(0,r),i=r<0?null:ce(n.slice(r+1)),a=e.find((e=>e.record_id===o));if(!a)throw new t({code:"NOT_FOUND",retryable:!1,detail:`event ${o} not found`});if(null===i){const n=be(a);if(!n)throw new t({code:"INVALID_OPERATION",retryable:!1,detail:`event ${o} has no time`});const r=ye(a),i=r.recurrence_id,s=i&&"string"==typeof i.master?e.find((e=>e.record_id===i.master)):void 0;return xe(a,n,s?{master:s,original:String(i.original),recurring:!0,override:!0}:{recurring:"string"==typeof r.rrule,master:"string"==typeof r.rrule?a:void 0,original:"string"==typeof r.rrule?n.allDay?n.startDate:new Date(n.startMs).toISOString():void 0})}const s=e.find((e=>{const t=ye(e).recurrence_id;return t&&t.master===o&&"string"==typeof t.original&&ce(t.original)===ce(i)})),l=be(a);if(!l)throw new t({code:"INVALID_OPERATION",retryable:!1,detail:`event ${o} has no time`});if(s)return xe(s,be(s),{id:n,master:a,original:i,recurring:!0,override:!0});const d=l.allDay,c=d?0:l.endMs-l.startMs,u=d?ve(l.startDate,l.endDate):0;return xe(a,d?{allDay:!0,startDate:i,endDate:De(i,u)}:{allDay:!1,startMs:Date.parse(i),endMs:Date.parse(i)+c},{id:n,master:a,original:i,recurring:!0})}function Be(e="zh"){const t=`${Q}-content`,n=J(e,"board");return[{op:"entity.create",entity_id:t,type_id:"buckyos.container",parent_id:"canvas-content",order_key:"u",name:n,payload:{kind:"folder",title:n,system:"surface_content",surface_id:Q}},{op:"entity.create",entity_id:Q,type_id:"buckyos.container",parent_id:"surfaces",order_key:"a",name:n,payload:{kind:"surface",layout:{mode:"free"},title:n,content_folder_id:t}},{op:"entity.create",entity_id:`${Q}-calendar`,type_id:"buckyos.container",parent_id:Q,order_key:"a",placement:{x:40,y:40,w:880,h:640},payload:{kind:"calendar",layout:{mode:"data"},title:J(e,"calendar_table"),bindings:{events:[{entity_id:K}],todo:[{entity_id:z}]},config:{view:"week"}}},{op:"entity.create",entity_id:`${Q}-todo`,type_id:"buckyos.container",parent_id:Q,order_key:"b",placement:{x:960,y:40,w:420,h:640},payload:{kind:"todo",layout:{mode:"data"},title:J(e,"todo_table"),bindings:{items:{entity_id:z}},config:{mode:"list"}}}]}class Ue extends Error{constructor(e,t,n,r){super(e),this.code=t,this.node=n,this.binding=r}}const je=[q,P],He=e=>void 0===e?[]:Array.isArray(e)?e:[e],Fe=(e,t)=>t.title??e;function qe(e,t){return!(e.accepts&&e.accepts.length>0&&!e.accepts.includes(t.type_id))&&(!e.schema_id||t.schema_id===e.schema_id)}const Pe=e=>{var t;return{...(null==(t=e.accepts)?void 0:t.length)?{accepts:e.accepts}:{},...e.schema_id?{schema_id:e.schema_id}:{}}};function We(){const e=e=>{throw new Ue(`needs a choice: ${e}`,"NEEDS_UI")};return{pickOne:async t=>e(t.title),pickMany:async t=>e(t.title),confirm:async t=>e(t.title)}}let ze=0;const Ke=()=>"ref:"+ ++ze;function Qe(e,t,n){const r=e=>{throw new Ue(`on_bind result: ${e}`,"INVALID",n)},o=e=>"object"==typeof e&&null!==e&&!Array.isArray(e);if(!o(e)||!o(e.bindings))return r("{ bindings, create? } (or null to cancel)");const i=void 0===e.create?[]:e.create;if(!Array.isArray(i)||i.length>16)return r("create: a list of at most 16");const a=new Map,s=i.map(((e,t)=>{const n=`create[${t}]`;if(!o(e)||"string"!=typeof e.ref||!e.ref)return r(`${n}: { ref, kind, … }`);if(a.has(e.ref))return r(`${n}: ref ${e.ref} twice`);const i=Ke();a.set(e.ref,i);const s="string"==typeof e.name&&e.name.trim()&&e.name.length<=128?e.name.trim():null;return"standard"===e.kind?"string"!=typeof e.schema_id?r(`${n}: a standard table names its schema_id`):{ref:i,kind:"standard",schema_id:e.schema_id,name:s??e.schema_id}:s?"table"===e.kind?Array.isArray(e.fields)&&0!==e.fields.length?void 0!==e.title_field_id&&"string"!=typeof e.title_field_id?r(`${n}: title_field_id is a field id`):{ref:i,kind:"table",name:s,fields:e.fields,...e.title_field_id?{title_field_id:e.title_field_id}:{}}:r(`${n}: a table lists its fields`):"dir"===e.kind?{ref:i,kind:"dir",name:s}:r(`${n}: kind standard, table or dir`):r(`${n}: a name (at most 128 characters)`)})),l={},d=new Set;for(const[u,y]of Object.entries(e.bindings)){const e=t[u];if(!e)return r(`${u} is not a declared binding`);if(null==y)continue;const n="string"==typeof y?[y]:Array.isArray(y)&&y.every((e=>"string"==typeof e&&e))?y:r(`${u}: an id, or a list of ids`);if(!e.many&&(Array.isArray(y)||1!==n.length))return r(`${u} takes one`);if(n.length>32||new Set(n).size!==n.length)return r(`${u}: at most 32, each once`);const o=n.map((e=>(a.has(e)&&d.add(e),a.get(e)??e)));e.many?o.length>0&&(l[u]=o):l[u]=o[0]}const c=[...a.keys()].filter((e=>!d.has(e)));return c.length>0?r(`created but not bound: ${c.join(", ")}`):{bindings:l,create:s}}const Ve=async e=>{const t={},n=[],r=e.parent?Object.values(e.parent.bound).flatMap(He):[],o=new Map(e.find({}).map((e=>[e.entity_id,e])));for(const[i,a]of Object.entries(e.decls)){const s=(t,n)=>new Ue(t,n,e.node,i);if("rebind"===e.reason){if(void 0!==e.given[i]&&e.no_ui){t[i]=e.given[i];continue}const r=He(e.given[i]);if(a.many){const o=await Je(i,(()=>e.dialogs.pickMany({title:Fe(i,a),query:Pe(a),preselect:r,allow_new:e.canCreate(a)})));if(null===o)return null;t[i]=o.map((t=>{if("string"==typeof t)return t;const r=Ke();return n.push(Ze(r,a,e.title)),r}))}else{const o=await Je(i,(()=>e.dialogs.pickOne({title:Fe(i,a),query:Pe(a),allow_new:e.canCreate(a),current:r[0]??null})));if(null===o)return null;if("string"==typeof o)t[i]=o;else{const r=Ke();n.push(Ze(r,a,e.title)),t[i]=r}}continue}if(void 0!==e.given[i]){t[i]=a.many?He(e.given[i]):He(e.given[i])[0];continue}const l=r.filter((e=>{const t=o.get(e);return void 0!==t&&qe(a,t)}));if(a.many&&l.length>0){t[i]=l;continue}if(!a.many&&1===l.length){t[i]=l[0];continue}const d=e.find(Pe(a)).filter((e=>qe(a,e)));if(0===d.length){if(!a.required)continue;if(!e.canCreate(a))throw s(`no ${Fe(i,a)} in this Workspace yet`,"NO_DATA");const r=Ke();n.push(Ze(r,a,e.title)),t[i]=a.many?[r]:r}else if(a.many)t[i]=d.map((e=>e.entity_id));else if(1===d.length)t[i]=d[0].entity_id;else if(a.required){const r=await Je(i,(()=>e.dialogs.pickOne({title:Fe(i,a),query:Pe(a),allow_new:e.canCreate(a)})));if(null===r)return null;if("string"==typeof r)t[i]=r;else{const r=Ke();n.push(Ze(r,a,e.title)),t[i]=r}}}return{bindings:t,create:n}};function Ze(e,t,n){return{ref:e,kind:"standard",schema_id:t.schema_id,name:n||t.title||"Table"}}async function Je(e,t){try{return await t()}catch(n){if(n instanceof Ue&&"NEEDS_UI"===n.code)throw new Ue(`binding ${e} needs a choice: give it`,"NEEDS_UI",void 0,e);throw n}}function Ge(e){return async t=>{var n;const r={},o=[];for(const a of e){const e=t.decls[a.binding]??{};if(void 0===t.given[a.binding]||"insert"!==t.reason)if("from_parent"in a){const o=null==(n=t.parent)?void 0:n.bound[a.from_parent];void 0!==o&&(r[a.binding]=e.many?He(o):He(o)[0])}else if("pick"in a){const n=Pe(e),i=a.title??Fe(a.binding,e),s=!1!==a.allow_new&&t.canCreate(e),l=He(t.given[a.binding]);if("all"===a.pick)r[a.binding]=t.find(n).filter((t=>qe(e,t))).map((e=>e.entity_id));else if("many"===a.pick){const d=await Je(a.binding,(()=>t.dialogs.pickMany({title:i,query:n,preselect:l.length?l:"none",allow_new:s})));if(null===d)return null;r[a.binding]=d.map((n=>{if("string"==typeof n)return n;const r=Ke();return o.push(Ze(r,e,t.title)),r}))}else{const d=await Je(a.binding,(()=>t.dialogs.pickOne({title:i,query:n,allow_new:s,current:l[0]??null})));if(null===d)return null;if("string"==typeof d)r[a.binding]=e.many?[d]:d;else{const n=Ke();o.push(Ze(n,e,t.title)),r[a.binding]=e.many?[n]:n}}}else{const n=0===t.find(Pe(e)).filter((t=>qe(e,t))).length;if("missing"===(a.when??"missing")&&!n)continue;const i=Ke(),s=a.create;o.push("standard"in s?{ref:i,kind:"standard",schema_id:s.standard,name:Fe(a.binding,e)}:"table"in s?{ref:i,kind:"table",name:s.table.name,title_field_id:s.table.title_field_id,fields:s.table.fields}:{ref:i,kind:"dir",name:s.dir.name}),r[a.binding]=e.many?[i]:i}else r[a.binding]=t.given[a.binding]}const i=Object.fromEntries(Object.entries(t.decls).filter((([e])=>void 0===r[e])));if(Object.keys(i).length>0){const e=await Ve({...t,decls:i});if(null===e)return null;Object.assign(r,e.bindings),o.push(...e.create)}return{bindings:r,create:o}}}const Xe=async e=>{const t=(n=e.decls,r=e.bound,Object.entries(n).filter((([e,t])=>t.required&&0===He(r[e]).length)).map((([e,t])=>Fe(e,t))));var n,r;if(t.length>0)return`${e.title}: ${t.join(", ")} not bound`;const o=e.children.filter((e=>!e.ready));return!(o.length>0)||`not ready: ${o.map((e=>`${e.title} (${e.missing.join(", ")})`)).join("; ")}`};exports.AIWORKSPACE_SERVICE_NAME="aiworkspace",exports.AIWS_COMMIT_MAX_BYTES=o,exports.AIWS_COMMIT_MAX_OPERATIONS=i,exports.AIWS_COMMIT_PART_BYTES=r,exports.AIWS_PROTOCOL_VERSION="1.2",exports.AiWorkspaceClient=class{constructor(e){this.rpcClient=e,this.raw=(e,t)=>this.rpcClient.call(e,t)}async call(e,n){const r=await this.rpcClient.call(e,n);if(r&&"object"==typeof r&&!1===r.ok)throw new t(r.error);return r}create(e,t={}){return this.call("ws.create",{title:e,...t})}ensure(e,t){return this.call("ws.ensure",{name:e,...void 0===t?{}:{title:t}})}time(){return this.call("ws.time",{})}list(){return this.call("ws.list",{})}info(e){return this.call("ws.get_info",{workspace_id:e})}getUserState(e){return this.call("ws.get_user_state",{workspace_id:e})}setUserState(e,t,n){return this.call("ws.set_user_state",{workspace_id:e,entries:t,...n?{expect:n}:{}})}resolve(e,t){return this.call("doc.resolve",{workspace_id:e,reference:t})}resolvePath(e,t){return this.call("doc.resolve",{workspace_id:e,path:t})}read(e,t,r){return this.call("doc.read",{workspace_id:e,...n(t),...r?{selector:r}:{}})}readMeta(e,t){return this.call("doc.read",{workspace_id:e,...n(t),as:"meta"})}readBody(e,t,r={}){return this.call("doc.read",{workspace_id:e,...n(t),as:"body",...r})}listEntities(e,t={}){return this.call("doc.list",{workspace_id:e,...t})}findEntities(e,t={}){return this.call("doc.find",{workspace_id:e,...t})}textQuery(e,t,n={}){return this.call("doc.query",{workspace_id:e,text:t,...n})}sql(e,t,n={}){return this.call("doc.query",{workspace_id:e,sql:t,...n})}sourceQuery(e,t,n){return this.call("doc.source_query",{workspace_id:e,source_id:t,...n})}outline(e){return this.call("doc.outline",{workspace_id:e})}prepare(e,t){return d(this.raw,{workspace_id:e,...t},{method:"doc.prepare"})}commit(e,t,n={}){return d(this.raw,{workspace_id:e,...t},n)}getSubmission(e,t,n){return this.call("doc.get_submission",{workspace_id:e,epoch:t,idempotency_key:n})}getChanges(e,t,n,r={}){return this.call("doc.get_changes",{workspace_id:e,epoch:t,after_seq:n,...r.limit?{limit:r.limit}:{},...r.touchedOnly?{filter:{detail:"touched"}}:{}})}waitChanges(e,t,n={}){return this.call("doc.wait_changes",{workspace_id:e,after_seq:t,...n})}exportDoc(e,t,n,r){return this.call("doc.export",{workspace_id:e,mode:t,self_contained:n,...void 0===r?{}:{include_notes:r}})}assetImportObject(e,t){return this.call("asset.import_object",{workspace_id:e,...t})}controlsList(){return this.call("control.list",{})}controlsDescribe(e){return this.call("control.describe",{kind:e})}controlsImport(e,t){return this.call("control.import",{workspace_id:e,...t})}controlsExport(e,t,n){return this.call("control.export",{workspace_id:e,entity_id:t,...n?{format:n}:{}})}extBuild(e,t){return this.call("ext.build",{workspace_id:e,...t})}extExport(e,t,n="package"){return this.call("ext.export",{workspace_id:e,entity_ids:t,purpose:n})}extInstall(e){return this.call("ext.install",e)}extPack(e,t,n,r){return this.call("ext.pack",{workspace_id:e,entity_ids:t,package:n,...r?{templates:r}:{}})}extUpgrade(e){return this.call("ext.upgrade",{...e})}extExportTemplate(e){return this.call("ext.export_template",{...e})}extCreateFromTemplate(e){return this.call("ext.create_from_template",e)}extListLibrary(){return this.call("ext.list_library",{})}extUninstall(e){return this.call("ext.uninstall",{pkg_id:e})}extLibraryBundle(e,t){return this.call("ext.library_bundle",{pkg_id:e,...t?{idents:t}:{}})}extImport(e,t,n={}){return this.call("ext.import",{workspace_id:e,items:t,...n})}runStart(e,t,n,r){return this.call("proc.start",{workspace_id:e,program:t,params:n,idempotency_key:r})}runGet(e,t){return this.call("proc.get",{workspace_id:e,run_id:t})}runList(e,t,n){return this.call("proc.list",{workspace_id:e,...t?{wish_id:t}:{},...n?{limit:n}:{}})}runClaim(e,t,n,r){return this.call("proc.claim",{workspace_id:e,run_id:t,claim_token:n,...r?{executor:r}:{}})}runHeartbeat(e,t,n,r){return this.call("proc.heartbeat",{workspace_id:e,run_id:t,attempt:n,...r?{progress:r}:{}})}runReport(e,t){return this.call("proc.report",{workspace_id:e,...t})}runRollback(e,t,n={}){return this.call("proc.rollback",{workspace_id:e,run_id:t,...n.confirm?{confirm:!0}:{},...n.session_id?{session_id:n.session_id}:{}})}runCancel(e,t){return this.call("proc.cancel",{workspace_id:e,run_id:t})}},exports.AiwsFailure=t,exports.BindFailure=Ue,exports.CALENDAR_SCHEMA_ID=P,exports.RRuleError=u,exports.SCHEDULE_CALENDAR_ID=K,exports.SCHEDULE_SURFACE_ID=Q,exports.SCHEDULE_TODO_ID=z,exports.SCHEDULE_WORKSPACE_NAME=W,exports.STANDARD_SCHEMAS=je,exports.ScheduleClient=class{constructor(e,t={}){this.aiws=e,this.handle=null,this.locale=t.locale??"zh"}async ensure(){var e,t,n;if(this.handle)return this.handle;const r=await this.aiws.call("ws.ensure",{name:W,title:J(this.locale,"workspace")}),o={workspace_id:r.workspace_id,epoch:r.epoch,created:r.created,todo:z,calendar:K},i=new Set;for(const l of[z,K,Q])try{(await this.aiws.call("doc.read",{workspace_id:r.workspace_id,entity_id:l})).deleted||i.add(l)}catch(s){const e=null==s?void 0:s.code;if("NOT_FOUND"!==e&&"TARGET_DELETED"!==e)throw s}const a=[];if(i.has(z)||a.push(ee("todo",{entity_id:z,parent_id:"data",order_key:"u",locale:this.locale})),i.has(K)||a.push(ee("calendar",{entity_id:K,parent_id:"data",order_key:"v",locale:this.locale})),i.has(Q)||a.push(...Be(this.locale)),a.length){const r=await this.commitTo(o,a,"create the schedule","system"),i="ID_CONFLICT"===(r.sub_code??(null==(t=null==(e=r.errors)?void 0:e[0])?void 0:t.sub_code)??(null==(n=r.error)?void 0:n.sub_code));if("accepted"!==r.status&&("rejected"!==r.status||!i))throw Re(r)}return this.handle=o,o}async commitTo(e,t,n,r="agent"){var o;const i=`sched-${ae("k")}`,a=o=>({protocol_version:"1.2",workspace_id:e.workspace_id,epoch:o,idempotency_key:i,origin:r,message:n,operations:t});let s=await this.aiws.call("doc.commit",a(e.epoch));if("rejected"===s.status&&"EPOCH_MISMATCH"===(s.code??(null==(o=s.error)?void 0:o.code))){const t=await this.aiws.call("ws.get_info",{workspace_id:e.workspace_id});e.epoch=t.epoch,s=await this.aiws.call("doc.commit",a(e.epoch))}return s}async commit(e,t){const n=await this.ensure(),r=await this.commitTo(n,e,t);if("accepted"!==r.status)throw Re(r);return r}async rows(e){const t=await this.ensure(),n=[];for(let r=0;r<100;r++){const o=await this.aiws.call("doc.query",{workspace_id:t.workspace_id,sql:'SELECT "_record" FROM t ORDER BY "_id" LIMIT ? OFFSET ?',params:[Le,r*Le],tables:{t:e},max_rows:Le});for(const[e]of o.rows)n.push("string"==typeof e?JSON.parse(e):e);if(o.rows.length<Le)break}return n}async row(e,n){const r=await this.ensure(),o=(await this.aiws.call("doc.read",{workspace_id:r.workspace_id,entity_id:e,selector:{kind:"table_record",record_id:n}})).content;if(!(null==o?void 0:o.record_id))throw new t({code:"NOT_FOUND",retryable:!1,detail:`record ${n} not found`});return o}async todos(e={}){const t=pe((await this.rows(z)).map(fe));return e.includeDone?t:t.filter((e=>!e.done))}async addTodo(e,t={}){var n,r,o,i;const a=pe((await this.rows(z)).map(fe)),s=e=>a.find((t=>t.record_id===e));let l={items:a};if(t.after){const e=a.findIndex((e=>e.record_id===t.after));l={after:(null==(n=s(t.after))?void 0:n.order)??null,before:(null==(r=a[e+1])?void 0:r.order)??null}}else if(t.before){const e=a.findIndex((e=>e.record_id===t.before));l={after:(null==(o=a[e-1])?void 0:o.order)??null,before:(null==(i=s(t.before))?void 0:i.order)??null}}const{record_id:d,ops:c}=he(z,e,l);return await this.commit(c,`add to-do: ${e.title}`),fe(await this.row(z,d))}async completeTodo(e,t=!0){const n=await this.row(z,e),r=_e(z,n,t);r.length&&await this.commit(r,`${t?"complete":"reopen"} to-do ${e}`)}async updateTodo(e,t){const n=await this.row(z,e),r=we(z,n,t);r.length&&await this.commit(r,`update to-do ${e}`)}async moveTodo(e,n){const r=pe((await this.rows(z)).map(fe)),o=r.find((t=>t.record_id===e));if(!o)throw new t({code:"NOT_FOUND",retryable:!1,detail:`to-do ${e} not found`});const i=r.filter((t=>t.record_id!==e));let a;if(n.before||n.after){const e=i.findIndex((e=>e.record_id===(n.before??n.after)));if(e<0)throw new t({code:"NOT_FOUND",retryable:!1,detail:`to-do ${n.before??n.after} not found`});a=ge(i,n.before?e:e+1)}const s=me(z,o,{status:n.status,order:a});s.length&&await this.commit(s,`move to-do ${e}`)}async removeTodos(e){const t=await Promise.all(e.map((e=>this.row(z,e))));await this.commit([de(z,t)],`delete to-do ${e.join(", ")}`)}async events(e,t={}){return $e(await this.rows(K),e,t)}async addEvent(e){var t;void 0!==(null==(t=e.ext)?void 0:t.rrule)&&"string"==typeof e.ext.rrule&&(e={...e,ext:{...e.ext,rrule:_(h(e.ext.rrule))}});const{record_id:n,ops:r}=Te(K,e);return await this.commit(r,`add event: ${e.title}`),n}async occurrence(e){const t=await this.rows(K);return{occ:Ce(t,e),rows:t}}async editEvent(e,t,n="one"){const{occ:r,rows:o}=await this.occurrence(e),{ops:i,record_id:a}=Ie(K,r,t,n,{rows:o});return i.length&&await this.commit(i,`edit event ${e} (${n})`),a}async deleteEvent(e,t="one"){const{occ:n,rows:r}=await this.occurrence(e);await this.commit(Ne(K,n,t,{rows:r}),`delete event ${e} (${t})`)}},exports.TODO_DONE=V,exports.TODO_SCHEMA_ID=q,exports.WEEKDAYS=c,exports.aiwsReferenceUrl=function(t,n){const r=t.workspace_id??n;if(!r)throw new Error("reference names no workspace");const o=[];"fixed"===t.mode&&o.push("mode=fixed"),null!=t.selector&&o.push(`selector=${e.encodeObjQueryComponent(e.canonicalJson(t.selector))}`),null!=t.version&&o.push(`version=${e.encodeObjQueryComponent(e.canonicalJson(t.version))}`);const i=e.objServiceUrl("aiworkspace",[r,"entities",t.entity_id]);return e.normalizeObjectUrl(o.length?`${i}?${o.join("&")}`:i)},exports.aiwsTarget=n,exports.bindingAccepts=qe,exports.bindingsPayload=function(e,t,n){var r;const o={};for(const[i,a]of Object.entries(e)){const e=He(a).map((e=>({entity_id:n[e]??e})));(null==(r=t[i])?void 0:r.many)||Array.isArray(a)?e.length>0&&(o[i]=e):e[0]&&(o[i]=e[0])}return o},exports.boundIds=function(e){return null==e?[]:Array.isArray(e)?e:[e]},exports.calendarFields=X,exports.calendarOccurrences=$e,exports.canonicalOriginal=ce,exports.checkBindResult=Qe,exports.checkBindSteps=function(e,t,n,r){var o,i,a,s;const l=[];if(void 0!==e)if(!Array.isArray(e)||e.length>16)l.push("on_bind: at most 16 steps");else for(const[d,c]of e.entries()){const e=c,t=`on_bind[${d}]`;if(!e||"object"!=typeof e||"string"!=typeof e.binding){l.push(`${t}: names a binding`);continue}const r=n[e.binding];if(!r){l.push(`${t}: ${e.binding} is not a declared binding`);continue}if(1===["pick","from_parent","create"].filter((t=>t in e)).length){if("pick"in e&&!["one","many","all"].includes(String(e.pick))&&l.push(`${t}: pick is one, many or all`),"pick"in e&&"one"!==e.pick&&!r.many&&l.push(`${t}: ${e.binding} takes one`),"from_parent"in e&&"string"!=typeof e.from_parent&&l.push(`${t}: from_parent names a binding of the parent`),"create"in e){const n=e.create,r=n&&"object"==typeof n?["standard","table","dir"].filter((e=>e in n)):[];1!==r.length?l.push(`${t}: create one of standard, table, dir`):"standard"!==r[0]||je.includes(String(n.standard))?"table"!==r[0]||Array.isArray(null==(o=n.table)?void 0:o.fields)&&"string"==typeof(null==(i=n.table)?void 0:i.name)?"dir"===r[0]&&"string"!=typeof(null==(a=n.dir)?void 0:a.name)&&l.push(`${t}: create.dir needs name`):l.push(`${t}: create.table needs name and fields`):l.push(`${t}: no standard table ${String(n.standard)}`),void 0!==e.when&&"missing"!==e.when&&"always"!==e.when&&l.push(`${t}: when is missing or always`)}}else l.push(`${t}: one of pick, from_parent, create`)}if(void 0!==t)if(!Array.isArray(t)||t.length>16)l.push("on_init_control: at most 16 steps");else for(const[d,c]of t.entries()){const e=c,t=`on_init_control[${d}]`;if("children"===(null==e?void 0:e.require))continue;const n=null==(s=null==e?void 0:e.then)?void 0:s.action;"string"!=typeof n?l.push(`${t}: { require: "children" } or { then: { action } }`):r.includes(n)||l.push(`${t}: ${n} is not a declared action`)}return l},exports.commitOverLimit=function(e){if(e.length>i)return{limit:"operations",value:e.length,max:i};let t=2;for(const n of e)t+=s(n)+1;return t+4096>o?{limit:"bytes",value:t,max:o}:null},exports.commitWithParts=d,exports.createOps=function(e,t){const n=[],r={};for(const o of e.values())for(const e of o.create){const o=t.newId();r[e.ref]=o;const i={entity_id:o,parent_id:t.folderId,order_key:t.orderKey(),name:t.freeName(e.name)};if("standard"===e.kind){const r=e.schema_id===q?"todo":e.schema_id===P?"calendar":null;if(!r)throw new Ue(`cannot create a table of ${e.schema_id}`,"INVALID");n.push(ee(r,{...i,locale:t.locale}))}else"table"===e.kind?n.push({op:"entity.create",type_id:"buckyos.table-source",...i,payload:{fields:e.fields,...e.title_field_id?{title_field_id:e.title_field_id}:{}}}):n.push({op:"entity.create",type_id:"buckyos.dir",...i,payload:{members:{}}})}return{ops:n,ids:r}},exports.dateOf=v,exports.dayNumber=b,exports.dayOf=D,exports.daysInMonth=g,exports.defaultOnBind=Ve,exports.defaultOnInit=Xe,exports.deleteRecordsOp=de,exports.describeRRule=function(e,t="zh"){var n;const r="zh"===t,o=e.interval,i=e=>e.map((e=>{const t=r?U[e.weekday]:j[e.weekday];return void 0===e.ordinal?t:r?`${C[e.ordinal]}${t}`:`${B[e.ordinal]} ${t}`})),a=e=>r?e.join("、"):e.length>1?`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`:e.join(""),s=e=>r?-1===e?"最后一天":`${e} 日`:-1===e?"the last day":`day ${e}`;let l;switch(e.freq){case"DAILY":l=r?1===o?"每天":`每 ${o} 天`:1===o?"every day":`every ${o} days`;break;case"WEEKLY":if(F(e.byDay)&&1===o)l=r?"每个工作日":"every weekday";else{const t=e.byDay?a(i(e.byDay)):"";l=r?`${1===o?"每周":`每 ${o} 周的`}${t}`:`${1===o?"every week":`every ${o} weeks`}${t?` on ${t}`:""}`}break;case"MONTHLY":{let t="";e.byMonthDay?t=a(e.byMonthDay.map(s)):e.byDay&&void 0!==e.bySetPos?t=F(e.byDay)?r?`${C[e.bySetPos]}工作日`:`the ${B[e.bySetPos]} weekday`:r?`${C[e.bySetPos]}${a(i(e.byDay))}`:`the ${B[e.bySetPos]} of ${a(i(e.byDay))}`:e.byDay&&(t=r?a(i(e.byDay)):`the ${a(i(e.byDay))}`),l=r?`${1===o?"每月":`每 ${o} 个月的`}${t}`:`${1===o?"every month":`every ${o} months`}${t?` on ${t}`:""}`;break}case"YEARLY":{const t=null==(n=e.byMonth)?void 0:n.map((e=>r?`${e} 月`:H[e-1]));let d=t?a(t):"";e.byMonthDay?d+=r?a(e.byMonthDay.map(s)):` ${a(e.byMonthDay.map((e=>-1===e?"last day":String(e))))}`:e.byDay&&(d+=r?a(i(e.byDay)):` on the ${a(i(e.byDay))}`),l=r?`${1===o?"每年":`每 ${o} 年的`}${d}`:`${1===o?"every year":`every ${o} years`}${d.trim()?` in ${d.trim()}`:""}`;break}}return void 0!==e.count&&(l+=r?`,共 ${e.count} 次`:`, ${e.count} times`),void 0!==e.until&&(l+=r?`,到 ${e.until.slice(0,10)} 为止`:`, until ${e.until.slice(0,10)}`),l},exports.eventAddOps=Te,exports.eventDeleteOps=Ne,exports.eventEditOps=Ie,exports.eventPostponeOps=function(e,t,n,r){return Ie(e,t,{times:t.allDay?{allDay:!0,startDate:De(t.startDate,Math.max(1,Math.round(n/1440))),endDate:De(t.endDate,Math.max(1,Math.round(n/1440)))}:{allDay:!1,start:new Date(t.startMs+6e4*n).toISOString(),end:new Date(t.endMs+6e4*n).toISOString()}},"one",r)},exports.eventSkipOps=(e,t,n)=>Ne(e,t,"one",n),exports.expandSeries=N,exports.findOccurrence=Ce,exports.formatRRule=_,exports.insertRecordOp=le,exports.isDate=m,exports.isLeap=w,exports.isOrderKey=ne,exports.isTimeZone=$,exports.localDate=Me,exports.localDay=A,exports.newRecordId=ae,exports.noUiDialogs=We,exports.occurrenceId=R,exports.orderAt=ge,exports.orderKeyBetween=oe,exports.orderKeysBetween=function(e,t,n){const r=[];let o=e;for(let i=0;i<n;i++)o=oe(o,t),r.push(o);return r},exports.originalOf=function(e){return e.date??new Date(e.startMs).toISOString()},exports.parseAiwsReferenceUrl=function(t){const n=e.parseObjectUrl(t),r=e.objectSegments(n);if("obj"!==n.kind||"aiworkspace"!==n.host.name||3!==r.length||"entities"!==r[1])throw new Error(`${t} is not an AI Workspace entity url`);const o={workspace_id:r[0],entity_id:r[2],mode:"fixed"===n.query.mode?"fixed":"live"};return void 0!==n.query.selector&&(o.selector=JSON.parse(n.query.selector)),void 0!==n.query.version&&(o.version=JSON.parse(n.query.version)),o},exports.parseOccurrenceId=function(e){const t=e.indexOf("@");return t<0?{recordId:e,original:null}:{recordId:e.slice(0,t),original:e.slice(t+1)}},exports.parseRRule=h,exports.recurrencePresets=function(e,t="zh"){const n=D(e),{y:r,m:o,d:i}=x(n),a=k(n),s=Math.floor((i-1)/7)+1,l=i+7>g(r,o),d="zh"===t,u=c[a],y=[{id:"none",label:d?"不重复":"Does not repeat",rrule:null},{id:"daily",label:d?"每天":"Daily",rrule:"FREQ=DAILY"},{id:"weekdays",label:d?"每个工作日(周一至周五)":"Every weekday (Monday to Friday)",rrule:"FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR"},{id:"weekly",label:d?`每周的${U[a]}`:`Weekly on ${j[a]}`,rrule:`FREQ=WEEKLY;BYDAY=${u}`},{id:"monthly_day",label:d?`每月 ${i} 日`:`Monthly on day ${i}`,rrule:`FREQ=MONTHLY;BYMONTHDAY=${i}`}];return s<=4&&y.push({id:"monthly_nth",label:d?`每月${C[s]}${U[a]}`:`Monthly on the ${B[s]} ${j[a]}`,rrule:`FREQ=MONTHLY;BYDAY=${s}${u}`}),l&&y.push({id:"monthly_last",label:d?`每月最后一个${U[a]}`:`Monthly on the last ${j[a]}`,rrule:`FREQ=MONTHLY;BYDAY=-1${u}`}),y.push({id:"yearly",label:d?`每年 ${o} 月 ${i} 日`:`Annually on ${H[o-1]} ${i}`,rrule:`FREQ=YEARLY;BYMONTH=${o};BYMONTHDAY=${i}`}),y},exports.resolveBindings=async function(e,t){const n=t.standardSchemas??je,r=t.no_ui?We():t.dialogs,o=new Map,i=[],a=async(e,s)=>{const l={reason:t.reason,no_ui:t.no_ui,node:e.id,title:e.title,decls:e.decls,given:e.given??{},parent:s,find:t.find,canCreate:e=>Boolean(e.schema_id&&n.includes(e.schema_id)),dialogs:r},d="function"==typeof e.onBind?e.onBind:Array.isArray(e.onBind)?Ge(e.onBind):Ve;let c;try{c=await d(l)}catch(h){if(h instanceof Ue)throw new Ue(h.message,h.code,h.node??e.id,h.binding);throw h}if(null===c)throw new Ue(`${e.title}: cancelled`,"CANCELLED",e.id);c=Qe(c,e.decls,e.id),o.set(e.id,c);const u=[];for(const t of e.children)u.push(await a(t,{decls:e.decls,bound:c.bindings}));const y="function"==typeof e.onInit?e.onInit:Xe,f=Array.isArray(e.onInit)?e.onInit:[],p=await y({reason:t.reason,no_ui:t.no_ui,node:e.id,title:e.title,decls:e.decls,bound:c.bindings,children:u,dialogs:r});if(!0!==p)throw new Ue(p,"NOT_READY",e.id);for(const t of f)"then"in t&&i.push({node:e.id,action:t.then.action});return{node:e.id,title:e.title,ready:!0,missing:[]}};try{return await a(e,t.parent??null),{ok:!0,results:o,then:i}}catch(s){if(s instanceof Ue)return{ok:!1,error:s};throw s}},exports.scheduleBoardOps=Be,exports.scheduleLabel=J,exports.seriesStartOf=L,exports.setValuesOps=se,exports.sortTodos=pe,exports.splitCommitOperations=l,exports.standardTableOp=ee,exports.stepsOnBind=Ge,exports.todoAddOps=he,exports.todoCompleteOps=_e,exports.todoFields=G,exports.todoItem=fe,exports.todoMoveOps=me,exports.todoUpdateOps=we,exports.viewerTimeZone=Oe,exports.weekdayOf=k,exports.ymdOf=x,exports.zonedParts=S,exports.zonedToUtc=E;
|
|
2
|
+
//# sourceMappingURL=aiws_bind-0654c24e.js.map
|