buckyos 0.7.195 → 0.7.197
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/README.md +20 -0
- package/cli/core/app.ts +1 -0
- package/cli/core/argv.ts +4 -0
- package/cli/dist/cli.mjs +218 -392
- package/cli/dist/cli.mjs.map +1 -1
- package/cli/modules/aiws.ts +11 -3
- package/cli/modules/obj.ts +70 -3
- package/cli/runtime/host.ts +2 -0
- package/cli/version.ts +1 -1
- package/dist/{aiws_bind-ec6fe2d5.mjs → aiws_bind-a96cb506.mjs} +135 -31
- package/dist/aiws_bind-a96cb506.mjs.map +1 -0
- package/dist/aiws_bind-fb4caf43.js +2 -0
- package/dist/aiws_bind-fb4caf43.js.map +1 -0
- package/dist/aiws_ext.cjs +1 -1
- package/dist/aiws_ext.mjs +1 -1
- package/dist/aiws_rrule.d.ts +3 -2
- package/dist/aiws_rrule.d.ts.map +1 -1
- package/dist/aiws_schedule.d.ts +14 -2
- package/dist/aiws_schedule.d.ts.map +1 -1
- package/dist/{aiws_write-1f179e1c.js → aiws_write-189e4c0e.js} +2 -2
- package/dist/{aiws_write-1f179e1c.js.map → aiws_write-189e4c0e.js.map} +1 -1
- package/dist/{aiws_write-07562abc.mjs → aiws_write-7078045b.mjs} +2 -2
- package/dist/{aiws_write-07562abc.mjs.map → aiws_write-7078045b.mjs.map} +1 -1
- package/dist/browser.cjs +1 -1
- package/dist/browser.mjs +4 -4
- package/dist/{content_objid-7605d166.mjs → content_objid-20b82f52.mjs} +2 -2
- package/dist/{content_objid-7605d166.mjs.map → content_objid-20b82f52.mjs.map} +1 -1
- package/dist/{content_objid-17daaa69.js → content_objid-d1d089a6.js} +2 -2
- package/dist/{content_objid-17daaa69.js.map → content_objid-d1d089a6.js.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/dist/owner-extensions/object_extensions.toml +160 -0
- package/dist/owner-extensions/profiles/bindings.json +165 -0
- package/dist/owner-extensions/profiles/calendar.json +489 -0
- package/dist/owner-extensions/profiles/contacts.json +89 -0
- package/dist/owner-extensions/profiles/person.json +193 -0
- package/dist/owner-extensions/profiles/sharing.json +65 -0
- package/dist/owner-extensions/profiles/todo.json +493 -0
- package/dist/owner-extensions/scripts/bindings.mjs +9 -0
- package/dist/owner-extensions/scripts/calendar.mjs +3 -0
- package/dist/owner-extensions/scripts/contacts.mjs +9 -0
- package/dist/owner-extensions/scripts/free_busy.mjs +666 -0
- package/dist/owner-extensions/scripts/person.mjs +11 -0
- package/dist/owner-extensions/scripts/schedule.mjs +2618 -0
- package/dist/owner-extensions/scripts/sharing.mjs +8 -0
- package/dist/owner-extensions/scripts/todo.mjs +3 -0
- package/dist/owner_availability.d.ts +15 -0
- package/dist/owner_availability.d.ts.map +1 -0
- package/dist/owner_schedule.d.ts +30 -0
- package/dist/owner_schedule.d.ts.map +1 -0
- package/package.json +2 -2
- package/cli/modules/aiws_schedule.ts +0 -256
- package/dist/aiws_bind-1a26e3e6.js +0 -2
- package/dist/aiws_bind-1a26e3e6.js.map +0 -1
- package/dist/aiws_bind-ec6fe2d5.mjs.map +0 -1
package/cli/modules/aiws.ts
CHANGED
|
@@ -32,7 +32,6 @@ import { EXIT_AUTH, ToolError, UsageError } from '../core/errors.ts'
|
|
|
32
32
|
import { callService, expectObject, inputString, requiredInputString, rpcOptions } from '../core/service.ts'
|
|
33
33
|
import { getHost } from '../runtime/host.ts'
|
|
34
34
|
import { createPikgModule } from './pikg.ts'
|
|
35
|
-
import { calCommand, todoCommand } from './aiws_schedule.ts'
|
|
36
35
|
import { placeCommand } from './aiws_place.ts'
|
|
37
36
|
import { gatewayOrigin } from './share.ts'
|
|
38
37
|
|
|
@@ -1777,10 +1776,19 @@ const templateCommand: CommandDefinition = {
|
|
|
1777
1776
|
},
|
|
1778
1777
|
}
|
|
1779
1778
|
|
|
1779
|
+
const selectNameCommand: CommandDefinition = {
|
|
1780
|
+
verb: 'select-name', summary: 'Choose the workspace that keeps a conflicting personal name',
|
|
1781
|
+
positionals: [{ name: 'name', description: 'Conflicting workspace name', required: true }],
|
|
1782
|
+
options: [WORKSPACE_OPTION], inputSchema: workspaceInput({ name: { type: 'string', minLength: 1 } }, ['name']),
|
|
1783
|
+
outputSchema: OBJECT_OUTPUT, resultSchemaVersion: 1, access: WRITE_ACCESS, asyncMode: 'sync', requiresSession: true,
|
|
1784
|
+
examples: ['buckyos aiws select-name schedule --workspace ws_2611a123'],
|
|
1785
|
+
handler: (ctx, input) => aiws(ctx, 'ws.select_name', input),
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1780
1788
|
export function createAiwsModule(): CommandModule {
|
|
1781
1789
|
return {
|
|
1782
1790
|
name: 'aiws',
|
|
1783
|
-
summary: 'AI Workspace: find and read a workspace by path (ls, find, grep, stat, cat, resolve, read), its permissions (acl, acl-edit), query its tables in SQL (sql), write tables, rich text and common properties (table, text, mv, rename, set-prop),
|
|
1784
|
-
commands: [infoCommand, lsCommand, findCommand, grepCommand, statCommand, aclCommand, aclEditCommand, catCommand, resolveCommand, readCommand, sqlCommand, tableCommand, textCommand, mvCommand, renameCommand, setPropCommand,
|
|
1791
|
+
summary: 'AI Workspace: find and read a workspace by path (ls, find, grep, stat, cat, resolve, read), its permissions (acl, acl-edit), query its tables in SQL (sql), write tables, rich text and common properties (table, text, mv, rename, set-prop), resolve conflicting workspace names (select-name), Block-controls (catalogue, import, export), extension controls (build, pull, export, library, import, upgrade), Workspace templates (list, create, export), and execute wish runs as their executor (claim, heartbeat, report) or roll one back',
|
|
1792
|
+
commands: [infoCommand, selectNameCommand, lsCommand, findCommand, grepCommand, statCommand, aclCommand, aclEditCommand, catCommand, resolveCommand, readCommand, sqlCommand, tableCommand, textCommand, mvCommand, renameCommand, setPropCommand, placeCommand, controlsCommand, importCommand, exportCommand, buildCommand, pullCommand, extExportCommand, libraryCommand, extImportCommand, extUpgradeCommand, templateCommand, runGetCommand, runClaimCommand, runHeartbeatCommand, runFilesCommand, runToolCommand, runExecCommand, runProgramCommand, runReportCommand, runRollbackCommand, runStartCommand],
|
|
1785
1793
|
}
|
|
1786
1794
|
}
|
package/cli/modules/obj.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { objectUrl } from 'buckyos/node'
|
|
|
2
2
|
import type { CommandDefinition, CommandModule, JsonSchema } from '../core/command.ts'
|
|
3
3
|
import type { CommandContext } from '../core/context.ts'
|
|
4
4
|
import { EXIT_INTERNAL, ToolError, UsageError } from '../core/errors.ts'
|
|
5
|
-
import {
|
|
5
|
+
import { getHost } from '../runtime/host.ts'
|
|
6
|
+
import { callService, expectObject, requiredInputString } from '../core/service.ts'
|
|
6
7
|
|
|
7
8
|
// System URLs (buckyos doc/key url.md part one): `resolve` normalizes a reference and
|
|
8
9
|
// says where it lives, `read` follows a DID Object Card to its Profile and summary
|
|
@@ -26,7 +27,7 @@ export function createObjModule(): CommandModule {
|
|
|
26
27
|
return {
|
|
27
28
|
name: 'obj',
|
|
28
29
|
summary: 'Resolve system URLs and read DID Objects (obj://, cyfs://, file://, https://)',
|
|
29
|
-
commands: [resolveCommand(), readCommand()],
|
|
30
|
+
commands: [resolveCommand(), readCommand(), aliasCommand(), callCommand()],
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
|
|
@@ -89,7 +90,7 @@ function resolveCommand(): CommandDefinition {
|
|
|
89
90
|
|
|
90
91
|
async function getJson(ctx: CommandContext, url: string): Promise<unknown> {
|
|
91
92
|
const headers: Record<string, string> = { accept: 'application/json' }
|
|
92
|
-
if (ctx.session) headers.authorization = `Bearer ${(await ctx.session.ensureValid()).token}`
|
|
93
|
+
if (ctx.session && new URL(url).origin === new URL(ctx.connection.endpoint).origin) headers.authorization = `Bearer ${(await ctx.session.ensureValid()).token}`
|
|
93
94
|
const response = await fetch(url, { headers, signal: ctx.signal })
|
|
94
95
|
const text = await response.text()
|
|
95
96
|
if (!response.ok) {
|
|
@@ -155,3 +156,69 @@ function readCommand(): CommandDefinition {
|
|
|
155
156
|
},
|
|
156
157
|
}
|
|
157
158
|
}
|
|
159
|
+
|
|
160
|
+
function aliasCommand(): CommandDefinition {
|
|
161
|
+
const names = ['list', 'set', 'rm']
|
|
162
|
+
return {
|
|
163
|
+
verb: 'alias', summary: 'List, override or reset object aliases in your current Zone',
|
|
164
|
+
positionals: [{ name: 'action', description: 'list | set | rm', required: true }, { name: 'name', description: 'Complete alias name (set, rm)', required: false }],
|
|
165
|
+
options: [
|
|
166
|
+
{ name: 'kind', description: 'local | link | disabled', type: 'string', enum: ['local', 'link', 'disabled'] },
|
|
167
|
+
{ name: 'object', description: 'Installed object ID for a local binding', type: 'string' },
|
|
168
|
+
{ name: 'url', description: 'Fixed Object URL for a link', type: 'string' },
|
|
169
|
+
{ name: 'if-revision', property: 'if_revision', description: 'Expected override revision (0 if never configured)', type: 'integer' },
|
|
170
|
+
],
|
|
171
|
+
inputSchema: { type: 'object', properties: {
|
|
172
|
+
action: { type: 'string', enum: names }, name: { type: 'string' }, kind: { type: 'string' },
|
|
173
|
+
object: { type: 'string' }, url: { type: 'string' }, if_revision: { type: 'integer', minimum: 0 },
|
|
174
|
+
}, required: ['action'], additionalProperties: false },
|
|
175
|
+
outputSchema: OBJECT_OUTPUT, resultSchemaVersion: 1, access: { mode: 'operation', operationIdField: 'action', possibleLevels: ['read', 'write'] },
|
|
176
|
+
asyncMode: 'sync', requiresSession: true,
|
|
177
|
+
examples: ['buckyos obj alias list', 'buckyos obj alias set owner.cal --kind link --url obj://cal/calendars/alice --if-revision 0', 'buckyos obj alias rm owner.cal --if-revision 1'],
|
|
178
|
+
handler: async (ctx, input) => {
|
|
179
|
+
const { action, ...params } = input
|
|
180
|
+
if (!names.includes(String(action))) throw new UsageError('INVALID_ARGUMENT', 'expected list, set or rm')
|
|
181
|
+
if (action === 'list' && Object.keys(params).length) throw new UsageError('INVALID_ARGUMENT', 'list takes no arguments')
|
|
182
|
+
if (action !== 'list' && (!params.name || !Number.isSafeInteger(params.if_revision))) throw new UsageError('INVALID_ARGUMENT', 'name and --if-revision are required')
|
|
183
|
+
if (action === 'set' && !params.kind) throw new UsageError('INVALID_ARGUMENT', 'set requires --kind')
|
|
184
|
+
const result = expectObject(await callService(ctx, 'control-panel', 'owner.alias.' + action, params), 'owner.alias.' + action)
|
|
185
|
+
if (result.ok === false) {
|
|
186
|
+
const e = expectObject(result.error, 'alias error')
|
|
187
|
+
throw new ToolError(String(e.code), String(e.message), undefined, false, { detail: e.detail })
|
|
188
|
+
}
|
|
189
|
+
return result
|
|
190
|
+
},
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function callCommand(): CommandDefinition {
|
|
195
|
+
return {
|
|
196
|
+
verb: 'call', summary: 'Invoke xcall with your current Zone session',
|
|
197
|
+
description: 'Pass the object, action and xcall arguments verbatim. The installed agent_tool handles profiles, permissions, output and exit status.',
|
|
198
|
+
examples: ['buckyos obj call owner who', 'buckyos obj call owner.todo add title=Review'],
|
|
199
|
+
inputSchema: { type: 'object', properties: { argv: { type: 'array', items: { type: 'string' } } }, required: ['argv'] },
|
|
200
|
+
outputSchema: { type: 'object', properties: { exit_code: { type: 'integer' } }, required: ['exit_code'] }, resultSchemaVersion: 1, access: { mode: 'fixed', level: 'write' },
|
|
201
|
+
asyncMode: 'sync', requiresSession: true,
|
|
202
|
+
handler: async (ctx, input) => {
|
|
203
|
+
const host = getHost()
|
|
204
|
+
const root = host.policy.buckyosRoot
|
|
205
|
+
if (!root || host.policy.distribution !== 'system') throw new ToolError('EXTENSION_UNAVAILABLE', 'xcall requires the BuckyOS system installation')
|
|
206
|
+
if (!ctx.session) throw new ToolError('AUTH_REQUIRED', 'xcall requires a signed-in Zone session')
|
|
207
|
+
const { token } = await ctx.session.ensureValid()
|
|
208
|
+
const exe = host.path.join(root, 'bin', 'opendan', host.platform === 'win32' || host.platform === 'windows' ? 'agent_tool.exe' : 'agent_tool')
|
|
209
|
+
const env = { BUCKYOS_ROOT: root, BUCKYOS_TOOL_ENDPOINT: ctx.connection.endpoint, BUCKYOS_APPCLIENT_SESSION_TOKEN: token }
|
|
210
|
+
const child = host.spawn(exe, ['xcall', ...(input.argv as string[])], { cwd: ctx.cwd, env })
|
|
211
|
+
const cancel = () => child.kill()
|
|
212
|
+
ctx.signal.addEventListener('abort', cancel, { once: true })
|
|
213
|
+
try {
|
|
214
|
+
await child.closeInput()
|
|
215
|
+
for await (const line of child.lines()) await ctx.io.stdout(line + '\n')
|
|
216
|
+
const stderr = await child.stderr
|
|
217
|
+
if (stderr) await ctx.io.stderr(stderr)
|
|
218
|
+
return { exit_code: await child.status }
|
|
219
|
+
} finally {
|
|
220
|
+
ctx.signal.removeEventListener('abort', cancel)
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
}
|
|
224
|
+
}
|
package/cli/runtime/host.ts
CHANGED
|
@@ -257,6 +257,8 @@ export function buildDistributionPolicy(options: PolicyOptions): DistributionPol
|
|
|
257
257
|
? ['docker']
|
|
258
258
|
: parsed.module === 'aiws' && ['run-exec', 'run-program'].includes(parsed.verb ?? '') && options.runtimeExecutable
|
|
259
259
|
? [options.runtimeExecutable]
|
|
260
|
+
: options.distribution === 'system' && parsed.module === 'obj' && parsed.verb === 'call'
|
|
261
|
+
? [path.join(buckyosRoot, 'bin', 'opendan', path.sep === '\\' ? 'agent_tool.exe' : 'agent_tool')]
|
|
260
262
|
: []
|
|
261
263
|
const network = parsed.module !== undefined &&
|
|
262
264
|
!['pikg', 'command', 'completion', 'config', 'provision'].includes(parsed.module)
|
package/cli/version.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Generated by scripts/generate-cli-version.mjs. Do not edit.
|
|
2
|
-
export const PACKAGE_VERSION = '0.7.
|
|
2
|
+
export const PACKAGE_VERSION = '0.7.197'
|
|
3
3
|
export const TOOL_VERSION = PACKAGE_VERSION
|
|
4
4
|
export const SDK_VERSION = PACKAGE_VERSION
|
|
5
5
|
export const PROTOCOL_VERSION = '1'
|
|
@@ -497,7 +497,7 @@ function zonedToUtc(day, minuteOfDay, secondOfMinute, tz) {
|
|
|
497
497
|
const local = day * 864e5 + minuteOfDay * 6e4 + secondOfMinute * 1e3;
|
|
498
498
|
const first = local - offsetMs(local, tz);
|
|
499
499
|
const second = local - offsetMs(first, tz);
|
|
500
|
-
return second;
|
|
500
|
+
return second !== first && local - offsetMs(second, tz) !== second ? Math.max(first, second) : second;
|
|
501
501
|
}
|
|
502
502
|
function localDay(ms, tz) {
|
|
503
503
|
const p = zonedParts(ms, tz);
|
|
@@ -644,7 +644,7 @@ function periodsBefore(rule, startDay, day) {
|
|
|
644
644
|
return Math.max(-1, p - 1);
|
|
645
645
|
}
|
|
646
646
|
function expandSeries(rule, start, window, opts = {}) {
|
|
647
|
-
var _a;
|
|
647
|
+
var _a, _b, _c;
|
|
648
648
|
const limit = opts.limit ?? 2e3;
|
|
649
649
|
const excluded = new Set(opts.exdate ?? []);
|
|
650
650
|
const out = [];
|
|
@@ -682,7 +682,8 @@ function expandSeries(rule, start, window, opts = {}) {
|
|
|
682
682
|
const date = dateOf(day);
|
|
683
683
|
occ = { original: date, date };
|
|
684
684
|
} else {
|
|
685
|
-
const
|
|
685
|
+
const firstMs = Date.parse(start.utc);
|
|
686
|
+
const ms = day === startDay ? firstMs : zonedToUtc(day, minute, second, tz) + new Date(firstMs).getUTCMilliseconds();
|
|
686
687
|
if (untilMs !== void 0 && ms > untilMs)
|
|
687
688
|
return false;
|
|
688
689
|
occ = { original: new Date(ms).toISOString(), startMs: ms };
|
|
@@ -702,16 +703,22 @@ function expandSeries(rule, start, window, opts = {}) {
|
|
|
702
703
|
let period = rule.count === void 0 ? periodsBefore(rule, startDay, fromDay) + 1 : 0;
|
|
703
704
|
for (let guard = 0; guard < MAX_PERIODS && out.length < limit; guard++, period++) {
|
|
704
705
|
if (periodStart(rule, period, startDay) > toDay)
|
|
705
|
-
|
|
706
|
+
return out;
|
|
706
707
|
for (const day of candidates(rule, period, startDay)) {
|
|
707
708
|
if (day <= startDay)
|
|
708
709
|
continue;
|
|
709
710
|
if (day > toDay)
|
|
710
711
|
return out;
|
|
711
|
-
if (!emit(day)
|
|
712
|
+
if (!emit(day))
|
|
713
|
+
return out;
|
|
714
|
+
if (out.length >= limit) {
|
|
715
|
+
(_b = opts.onTruncated) == null ? void 0 : _b.call(opts);
|
|
712
716
|
return out;
|
|
717
|
+
}
|
|
713
718
|
}
|
|
714
719
|
}
|
|
720
|
+
if (periodStart(rule, period, startDay) <= toDay)
|
|
721
|
+
(_c = opts.onTruncated) == null ? void 0 : _c.call(opts);
|
|
715
722
|
return out;
|
|
716
723
|
}
|
|
717
724
|
function seriesStartOf(values, tz, fallbackTz = "UTC") {
|
|
@@ -1052,7 +1059,56 @@ const ru = {
|
|
|
1052
1059
|
yearly: (m, d) => `Каждый год ${d} ${RU_MONTH_GEN[m - 1]}`
|
|
1053
1060
|
}
|
|
1054
1061
|
};
|
|
1055
|
-
const
|
|
1062
|
+
const AR_DAYS = ["الاثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعة", "السبت", "الأحد"];
|
|
1063
|
+
const AR_MONTHS = ["يناير", "فبراير", "مارس", "أبريل", "مايو", "يونيو", "يوليو", "أغسطس", "سبتمبر", "أكتوبر", "نوفمبر", "ديسمبر"];
|
|
1064
|
+
const arNumber = new Intl.NumberFormat("ar");
|
|
1065
|
+
const arList = (items) => items.join(" و");
|
|
1066
|
+
const arOrdinal = (position) => {
|
|
1067
|
+
const ordinals = ["الأول", "الثاني", "الثالث", "الرابع", "الخامس"];
|
|
1068
|
+
if (position === -1)
|
|
1069
|
+
return "الأخير";
|
|
1070
|
+
const ordinal = ordinals[Math.abs(position) - 1] ?? arNumber.format(Math.abs(position));
|
|
1071
|
+
return position < 0 ? ordinal + " من النهاية" : ordinal;
|
|
1072
|
+
};
|
|
1073
|
+
const arEvery = (n, one, two, few, many) => {
|
|
1074
|
+
if (n === 1)
|
|
1075
|
+
return "كل " + one;
|
|
1076
|
+
if (n === 2)
|
|
1077
|
+
return "كل " + two;
|
|
1078
|
+
return "كل " + arNumber.format(n) + " " + (n % 100 >= 3 && n % 100 <= 10 ? few : many);
|
|
1079
|
+
};
|
|
1080
|
+
const arOn = (frequency, on) => on ? frequency + "، في " + on : frequency;
|
|
1081
|
+
const ar = {
|
|
1082
|
+
day: (wd) => AR_DAYS[wd],
|
|
1083
|
+
nth: (o, wd) => `يوم ${AR_DAYS[wd]} ${arOrdinal(o)}`,
|
|
1084
|
+
nthWorkday: (o) => `يوم العمل ${arOrdinal(o)}`,
|
|
1085
|
+
nthOf: (o, days) => days.length === 1 ? ar.nth(o, days[0]) : `اليوم ${arOrdinal(o)} من بين أيام ${arList(days.map(ar.day))}`,
|
|
1086
|
+
monthlyDays: arList,
|
|
1087
|
+
monthDay: (d) => d === -1 ? "اليوم الأخير" : d < 0 ? `اليوم ${arOrdinal(d)}` : `اليوم ${arNumber.format(d)}`,
|
|
1088
|
+
join: arList,
|
|
1089
|
+
daily: (n) => arEvery(n, "يوم", "يومين", "أيام", "يومًا"),
|
|
1090
|
+
workdays: "من الاثنين إلى الجمعة",
|
|
1091
|
+
weekly: (n, on) => [arEvery(n, "أسبوع", "أسبوعين", "أسابيع", "أسبوعًا"), on].filter(Boolean).join("، "),
|
|
1092
|
+
monthly: (n, on) => arOn(arEvery(n, "شهر", "شهرين", "أشهر", "شهرًا"), on),
|
|
1093
|
+
yearly: (n, months, mdays, days) => {
|
|
1094
|
+
const month = months ? arList(months.map((m) => AR_MONTHS[m - 1])) : "";
|
|
1095
|
+
const day = mdays ? arList(mdays.map(ar.monthDay)) : arList(days ?? []);
|
|
1096
|
+
return arOn(arEvery(n, "سنة", "سنتين", "سنوات", "سنة"), [day, month].filter(Boolean).join(" من "));
|
|
1097
|
+
},
|
|
1098
|
+
count: (n) => `، عدد المرات: ${arNumber.format(n)}`,
|
|
1099
|
+
until: (date) => `، حتى ${date}`,
|
|
1100
|
+
preset: {
|
|
1101
|
+
none: "بلا تكرار",
|
|
1102
|
+
daily: "كل يوم",
|
|
1103
|
+
weekdays: "أيام العمل (من الاثنين إلى الجمعة)",
|
|
1104
|
+
weekly: (wd) => `كل أسبوع يوم ${ar.day(wd)}`,
|
|
1105
|
+
monthlyDay: (d) => ar.monthly(1, ar.monthDay(d)),
|
|
1106
|
+
monthlyNth: (n, wd) => ar.monthly(1, ar.nth(n, wd)),
|
|
1107
|
+
monthlyLast: (wd) => ar.monthly(1, ar.nth(-1, wd)),
|
|
1108
|
+
yearly: (m, d) => `كل سنة في ${arNumber.format(d)} ${AR_MONTHS[m - 1]}`
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
const PHRASEBOOKS = { zh, "zh-TW": zhTW, en, ja, ko, fr, de, es, ru, ar };
|
|
1056
1112
|
const phrasebook = (locale) => PHRASEBOOKS[locale] ?? en;
|
|
1057
1113
|
const isWorkdays = (d) => !!d && d.length === 5 && d.every((x) => x.ordinal === void 0) && [0, 1, 2, 3, 4].every((w) => d.some((x) => x.weekday === w));
|
|
1058
1114
|
function describeRRule(rule, locale = "zh") {
|
|
@@ -1303,6 +1359,29 @@ const LABELS = {
|
|
|
1303
1359
|
workspace: "Mi agenda",
|
|
1304
1360
|
board: "Agenda"
|
|
1305
1361
|
},
|
|
1362
|
+
ar: {
|
|
1363
|
+
title: "العنوان",
|
|
1364
|
+
status: "الحالة",
|
|
1365
|
+
due: "تاريخ الاستحقاق",
|
|
1366
|
+
order: "الترتيب",
|
|
1367
|
+
done_at: "وقت الإكمال",
|
|
1368
|
+
ext: "بيانات إضافية",
|
|
1369
|
+
todo: "قيد الانتظار",
|
|
1370
|
+
doing: "قيد التنفيذ",
|
|
1371
|
+
done: "مكتملة",
|
|
1372
|
+
all_day: "طوال اليوم",
|
|
1373
|
+
start: "البداية",
|
|
1374
|
+
end: "النهاية",
|
|
1375
|
+
start_date: "تاريخ البدء",
|
|
1376
|
+
end_date: "تاريخ الانتهاء",
|
|
1377
|
+
confirmed: "مؤكد",
|
|
1378
|
+
tentative: "مبدئي",
|
|
1379
|
+
cancelled: "ملغى",
|
|
1380
|
+
todo_table: "المهام",
|
|
1381
|
+
calendar_table: "التقويم",
|
|
1382
|
+
workspace: "جدولي",
|
|
1383
|
+
board: "الجدول"
|
|
1384
|
+
},
|
|
1306
1385
|
ru: {
|
|
1307
1386
|
title: "Название",
|
|
1308
1387
|
status: "Статус",
|
|
@@ -1671,7 +1750,7 @@ function calendarOccurrences(rows, window, opts = {}) {
|
|
|
1671
1750
|
if (!start)
|
|
1672
1751
|
continue;
|
|
1673
1752
|
const exdate = originals(ext.exdate);
|
|
1674
|
-
const occs = expandSeries(rule, start, window, { exdate, viewerTz, durationMs: times.allDay ? void 0 : duration, durationDays: times.allDay ? duration : void 0, limit: opts.limit });
|
|
1753
|
+
const occs = expandSeries(rule, start, window, { exdate, viewerTz, durationMs: times.allDay ? void 0 : duration, durationDays: times.allDay ? duration : void 0, limit: opts.limit, onTruncated: opts.onTruncated });
|
|
1675
1754
|
for (const o of occs) {
|
|
1676
1755
|
const s = shift(o);
|
|
1677
1756
|
if (s)
|
|
@@ -1951,20 +2030,31 @@ const ROWS_PAGE = 1e3;
|
|
|
1951
2030
|
class ScheduleClient {
|
|
1952
2031
|
constructor(aiws, opts = {}) {
|
|
1953
2032
|
this.aiws = aiws;
|
|
2033
|
+
this.opts = opts;
|
|
1954
2034
|
this.handle = null;
|
|
1955
2035
|
this.locale = opts.locale ?? "zh";
|
|
1956
2036
|
}
|
|
1957
2037
|
/** The schedule Workspace with its two tables (created when missing; concurrent first uses converge). */
|
|
1958
2038
|
async ensure() {
|
|
1959
|
-
var _a, _b, _c;
|
|
1960
2039
|
if (this.handle)
|
|
1961
2040
|
return this.handle;
|
|
1962
2041
|
const ws = await this.aiws.call("ws.ensure", { name: SCHEDULE_WORKSPACE_NAME, title: scheduleLabel(this.locale, "workspace") });
|
|
1963
|
-
|
|
2042
|
+
return this.open(ws, true);
|
|
2043
|
+
}
|
|
2044
|
+
async open(ws, initialize = false) {
|
|
2045
|
+
var _a, _b, _c;
|
|
2046
|
+
const handle = { workspace_id: ws.workspace_id, epoch: ws.epoch, created: ws.created ?? false, todo: SCHEDULE_TODO_ID, calendar: SCHEDULE_CALENDAR_ID };
|
|
2047
|
+
if (!initialize) {
|
|
2048
|
+
this.handle = handle;
|
|
2049
|
+
return handle;
|
|
2050
|
+
}
|
|
1964
2051
|
const have = /* @__PURE__ */ new Set();
|
|
1965
2052
|
for (const id of [SCHEDULE_TODO_ID, SCHEDULE_CALENDAR_ID, SCHEDULE_SURFACE_ID]) {
|
|
1966
2053
|
try {
|
|
1967
|
-
const read = await this.aiws.call("doc.read", { workspace_id: ws.workspace_id, entity_id: id });
|
|
2054
|
+
const read = await this.aiws.call("doc.read", { workspace_id: ws.workspace_id, entity_id: id, as: "meta" });
|
|
2055
|
+
const schema = id === SCHEDULE_TODO_ID ? TODO_SCHEMA_ID : id === SCHEDULE_CALENDAR_ID ? CALENDAR_SCHEMA_ID : void 0;
|
|
2056
|
+
if (schema && read.schema_id !== schema)
|
|
2057
|
+
throw new AiwsFailure({ code: "RESOURCE_TYPE_MISMATCH", detail: id + " is not the expected schedule table", retryable: false });
|
|
1968
2058
|
if (!read.deleted)
|
|
1969
2059
|
have.add(id);
|
|
1970
2060
|
} catch (error) {
|
|
@@ -1981,20 +2071,29 @@ class ScheduleClient {
|
|
|
1981
2071
|
if (!have.has(SCHEDULE_SURFACE_ID))
|
|
1982
2072
|
ops.push(...scheduleBoardOps(this.locale));
|
|
1983
2073
|
if (ops.length) {
|
|
1984
|
-
const
|
|
2074
|
+
const initKey = `init-${this.opts.idempotencyKey ?? newRecordId("k")}`;
|
|
2075
|
+
const result = await this.commitTo(handle, ops, "create the schedule", "system", initKey);
|
|
1985
2076
|
const idConflict = (result.sub_code ?? ((_b = (_a = result.errors) == null ? void 0 : _a[0]) == null ? void 0 : _b.sub_code) ?? ((_c = result.error) == null ? void 0 : _c.sub_code)) === "ID_CONFLICT";
|
|
1986
|
-
if (result.status !== "accepted"
|
|
1987
|
-
|
|
2077
|
+
if (result.status !== "accepted") {
|
|
2078
|
+
if (!(result.status === "rejected" && idConflict))
|
|
2079
|
+
throw failureOf(result);
|
|
2080
|
+
for (const id of [SCHEDULE_TODO_ID, SCHEDULE_CALENDAR_ID, SCHEDULE_SURFACE_ID]) {
|
|
2081
|
+
const meta = await this.aiws.call("doc.read", { workspace_id: ws.workspace_id, entity_id: id, as: "meta" });
|
|
2082
|
+
if (id !== SCHEDULE_SURFACE_ID && meta.schema_id !== (id === SCHEDULE_TODO_ID ? TODO_SCHEMA_ID : CALENDAR_SCHEMA_ID))
|
|
2083
|
+
throw failureOf(result);
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
1988
2086
|
}
|
|
1989
2087
|
this.handle = handle;
|
|
1990
2088
|
return handle;
|
|
1991
2089
|
}
|
|
1992
|
-
async commitTo(handle, operations, message, origin = "agent") {
|
|
2090
|
+
async commitTo(handle, operations, message, origin = "agent", key = this.opts.idempotencyKey ?? `sched-${newRecordId("k")}`) {
|
|
1993
2091
|
var _a;
|
|
1994
|
-
const key = `sched-${newRecordId("k")}`;
|
|
1995
2092
|
const request = (epoch) => ({ protocol_version: AIWS_PROTOCOL_VERSION, workspace_id: handle.workspace_id, epoch, idempotency_key: key, origin, message, operations });
|
|
1996
2093
|
let result = await this.aiws.call("doc.commit", request(handle.epoch));
|
|
1997
2094
|
if (result.status === "rejected" && (result.code ?? ((_a = result.error) == null ? void 0 : _a.code)) === "EPOCH_MISMATCH") {
|
|
2095
|
+
if (this.opts.idempotencyKey)
|
|
2096
|
+
throw new AiwsFailure({ code: "WRITE_OUTCOME_UNKNOWN", retryable: false, detail: "original workspace epoch changed", data: { workspace_id: handle.workspace_id, idempotency_key: key } });
|
|
1998
2097
|
const info = await this.aiws.call("ws.get_info", { workspace_id: handle.workspace_id });
|
|
1999
2098
|
handle.epoch = info.epoch;
|
|
2000
2099
|
result = await this.aiws.call("doc.commit", request(handle.epoch));
|
|
@@ -2013,7 +2112,7 @@ class ScheduleClient {
|
|
|
2013
2112
|
async rows(sourceId) {
|
|
2014
2113
|
const handle = await this.ensure();
|
|
2015
2114
|
const rows = [];
|
|
2016
|
-
for (let i = 0;
|
|
2115
|
+
for (let i = 0; ; i++) {
|
|
2017
2116
|
const page = await this.aiws.call("doc.query", {
|
|
2018
2117
|
workspace_id: handle.workspace_id,
|
|
2019
2118
|
sql: 'SELECT "_record" FROM t ORDER BY "_id" LIMIT ? OFFSET ?',
|
|
@@ -2045,6 +2144,8 @@ class ScheduleClient {
|
|
|
2045
2144
|
var _a, _b, _c, _d;
|
|
2046
2145
|
const items = sortTodos((await this.rows(SCHEDULE_TODO_ID)).map(todoItem));
|
|
2047
2146
|
const at = (id) => items.find((i) => i.record_id === id);
|
|
2147
|
+
if (place.after && !at(place.after) || place.before && !at(place.before))
|
|
2148
|
+
throw new AiwsFailure({ code: "NOT_FOUND", retryable: false, detail: "placement anchor does not exist" });
|
|
2048
2149
|
let pos = { items };
|
|
2049
2150
|
if (place.after) {
|
|
2050
2151
|
const i = items.findIndex((x) => x.record_id === place.after);
|
|
@@ -2057,17 +2158,22 @@ class ScheduleClient {
|
|
|
2057
2158
|
await this.commit(ops, `add to-do: ${input.title}`);
|
|
2058
2159
|
return todoItem(await this.row(SCHEDULE_TODO_ID, record_id));
|
|
2059
2160
|
}
|
|
2161
|
+
async commitRowChange(source, row, ops, message, field = "title") {
|
|
2162
|
+
if (!ops.length && this.opts.idempotencyKey) {
|
|
2163
|
+
ops = setValuesOps(source, row, { [field]: row.values[field] ?? (field === "status" ? "todo" : row.values.title) });
|
|
2164
|
+
}
|
|
2165
|
+
if (ops.length)
|
|
2166
|
+
await this.commit(ops, message);
|
|
2167
|
+
}
|
|
2060
2168
|
async completeTodo(recordId, done = true) {
|
|
2061
2169
|
const row = await this.row(SCHEDULE_TODO_ID, recordId);
|
|
2062
2170
|
const ops = todoCompleteOps(SCHEDULE_TODO_ID, row, done);
|
|
2063
|
-
|
|
2064
|
-
await this.commit(ops, `${done ? "complete" : "reopen"} to-do ${recordId}`);
|
|
2171
|
+
await this.commitRowChange(SCHEDULE_TODO_ID, row, ops, `${done ? "complete" : "reopen"} to-do ${recordId}`, "status");
|
|
2065
2172
|
}
|
|
2066
2173
|
async updateTodo(recordId, changes) {
|
|
2067
2174
|
const row = await this.row(SCHEDULE_TODO_ID, recordId);
|
|
2068
2175
|
const ops = todoUpdateOps(SCHEDULE_TODO_ID, row, changes);
|
|
2069
|
-
|
|
2070
|
-
await this.commit(ops, `update to-do ${recordId}`);
|
|
2176
|
+
await this.commitRowChange(SCHEDULE_TODO_ID, row, ops, `update to-do ${recordId}`);
|
|
2071
2177
|
}
|
|
2072
2178
|
/** Move a to-do before / after another one, and / or into another status. */
|
|
2073
2179
|
async moveTodo(recordId, to) {
|
|
@@ -2084,8 +2190,7 @@ class ScheduleClient {
|
|
|
2084
2190
|
order = orderAt(others, to.before ? anchor : anchor + 1);
|
|
2085
2191
|
}
|
|
2086
2192
|
const ops = todoMoveOps(SCHEDULE_TODO_ID, row, { status: to.status, order });
|
|
2087
|
-
|
|
2088
|
-
await this.commit(ops, `move to-do ${recordId}`);
|
|
2193
|
+
await this.commitRowChange(SCHEDULE_TODO_ID, row, ops, `move to-do ${recordId}`, "status");
|
|
2089
2194
|
}
|
|
2090
2195
|
async removeTodos(recordIds) {
|
|
2091
2196
|
const rows = await Promise.all(recordIds.map((id) => this.row(SCHEDULE_TODO_ID, id)));
|
|
@@ -2110,9 +2215,8 @@ class ScheduleClient {
|
|
|
2110
2215
|
}
|
|
2111
2216
|
async editEvent(id, change, scope = "one") {
|
|
2112
2217
|
const { occ, rows } = await this.occurrence(id);
|
|
2113
|
-
const { ops, record_id } = eventEditOps(SCHEDULE_CALENDAR_ID, occ, change, scope, { rows });
|
|
2114
|
-
|
|
2115
|
-
await this.commit(ops, `edit event ${id} (${scope})`);
|
|
2218
|
+
const { ops, record_id } = eventEditOps(SCHEDULE_CALENDAR_ID, occ, change, scope, { rows, newRecordId: this.opts.newRecordId });
|
|
2219
|
+
await this.commitRowChange(SCHEDULE_CALENDAR_ID, occ.row, ops, `edit event ${id} (${scope})`);
|
|
2116
2220
|
return record_id;
|
|
2117
2221
|
}
|
|
2118
2222
|
async deleteEvent(id, scope = "one") {
|
|
@@ -2154,11 +2258,11 @@ function findOccurrence(rows, id) {
|
|
|
2154
2258
|
throw new AiwsFailure({ code: "INVALID_OPERATION", retryable: false, detail: `event ${recordId} has no time` });
|
|
2155
2259
|
if (override)
|
|
2156
2260
|
return occurrenceOf(override, rowTimes(override), { id, master: row, original, recurring: true, override: true });
|
|
2157
|
-
const
|
|
2158
|
-
const
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
return
|
|
2261
|
+
const fromMs = Date.parse(times.allDay ? original + "T00:00:00Z" : original);
|
|
2262
|
+
const instance = Number.isFinite(fromMs) && calendarOccurrences([row], { fromMs, toMs: fromMs + 1 }, { viewerTz: "UTC" }).find((o) => o.original === original);
|
|
2263
|
+
if (!instance)
|
|
2264
|
+
throw new AiwsFailure({ code: "NOT_FOUND", retryable: false, detail: "occurrence is outside the series or was removed" });
|
|
2265
|
+
return instance;
|
|
2162
2266
|
}
|
|
2163
2267
|
function scheduleBoardOps(locale = "zh") {
|
|
2164
2268
|
const folder = `${SCHEDULE_SURFACE_ID}-content`;
|
|
@@ -2696,4 +2800,4 @@ export {
|
|
|
2696
2800
|
ymdOf as y,
|
|
2697
2801
|
zonedParts as z
|
|
2698
2802
|
};
|
|
2699
|
-
//# sourceMappingURL=aiws_bind-
|
|
2803
|
+
//# sourceMappingURL=aiws_bind-a96cb506.mjs.map
|