buckyos 0.7.177 → 0.7.183
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/LICENSE +202 -21
- package/NOTICE +35 -0
- package/README.md +4 -0
- package/cli/deno.json +3 -2
- package/cli/dist/cli.mjs +1725 -301
- package/cli/dist/cli.mjs.map +1 -1
- package/cli/modules/aiws.ts +761 -58
- package/cli/modules/aiws_place.ts +383 -0
- package/cli/modules/aiws_schedule.ts +256 -0
- package/cli/modules/pikg.ts +193 -51
- package/cli/runtime/fs_retry.ts +26 -0
- package/cli/runtime/host.ts +18 -0
- package/cli/runtime/host_deno.ts +51 -2
- package/cli/runtime/host_node.ts +48 -3
- package/cli/runtime/node_entry.ts +1 -0
- package/cli/system_bootstrap.ts +1 -0
- package/cli/system_launcher.ts +1 -0
- package/cli/version.ts +1 -1
- package/dist/aicc_client.d.ts +1 -1
- package/dist/aicc_client.d.ts.map +1 -1
- package/dist/aiworkspace_client.d.ts +253 -2
- package/dist/aiworkspace_client.d.ts.map +1 -1
- package/dist/aiws_bind-3b874f77.mjs +2235 -0
- package/dist/aiws_bind-3b874f77.mjs.map +1 -0
- package/dist/aiws_bind-82bace11.js +2 -0
- package/dist/aiws_bind-82bace11.js.map +1 -0
- package/dist/aiws_bind.d.ts +233 -0
- package/dist/aiws_bind.d.ts.map +1 -0
- package/dist/aiws_ext.cjs +1 -1
- package/dist/aiws_ext.cjs.map +1 -1
- package/dist/aiws_ext.d.ts +9 -5
- package/dist/aiws_ext.d.ts.map +1 -1
- package/dist/aiws_ext.mjs +146 -11
- package/dist/aiws_ext.mjs.map +1 -1
- package/dist/aiws_rrule.d.ts +121 -0
- package/dist/aiws_rrule.d.ts.map +1 -0
- package/dist/aiws_schedule.d.ts +324 -0
- package/dist/aiws_schedule.d.ts.map +1 -0
- package/dist/aiws_write-89b5cc2a.js +13 -0
- package/dist/aiws_write-89b5cc2a.js.map +1 -0
- package/dist/{executor_client-bfc8a1e1.mjs → aiws_write-c2de498e.mjs} +724 -285
- package/dist/aiws_write-c2de498e.mjs.map +1 -0
- package/dist/aiws_write.d.ts +178 -0
- package/dist/aiws_write.d.ts.map +1 -0
- package/dist/app-frame.cjs +1 -1
- package/dist/app-frame.cjs.map +1 -1
- package/dist/app-frame.d.ts +1 -0
- package/dist/app-frame.d.ts.map +1 -1
- package/dist/app-frame.mjs +6 -2
- package/dist/app-frame.mjs.map +1 -1
- package/dist/browser.cjs +1 -1
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +4 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.mjs +112 -21
- package/dist/browser.mjs.map +1 -1
- package/dist/{content_objid-9232bcaf.mjs → content_objid-a2cafba9.mjs} +2 -2
- package/dist/{content_objid-9232bcaf.mjs.map → content_objid-a2cafba9.mjs.map} +1 -1
- package/dist/content_objid-dff803ff.js +2 -0
- package/dist/{content_objid-1aff74b6.js.map → content_objid-dff803ff.js.map} +1 -1
- package/dist/{did_object_client-7fa36f90.mjs → did_object_client-cb2f9aba.mjs} +2 -2
- package/dist/{did_object_client-7fa36f90.mjs.map → did_object_client-cb2f9aba.mjs.map} +1 -1
- package/dist/executor_client.d.ts +1 -1
- package/dist/executor_client.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +113 -22
- package/dist/index.mjs.map +1 -1
- package/dist/nfsp.cjs.map +1 -1
- package/dist/nfsp.d.ts +2 -1
- package/dist/nfsp.d.ts.map +1 -1
- package/dist/nfsp.mjs.map +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.ts +5 -0
- package/dist/node.d.ts.map +1 -1
- package/dist/node.mjs +99 -6
- package/dist/node.mjs.map +1 -1
- package/dist/{object_url-f72c1704.mjs → object_url-376c5222.mjs} +4 -4
- package/dist/{object_url-f72c1704.mjs.map → object_url-376c5222.mjs.map} +1 -1
- package/dist/provision.cjs +1 -1
- package/dist/provision.cjs.map +1 -1
- package/dist/provision.mjs +48 -16
- package/dist/provision.mjs.map +1 -1
- package/dist/provision_activate.d.ts.map +1 -1
- package/dist/xllm.mjs +2 -2
- package/package.json +5 -4
- package/dist/content_objid-1aff74b6.js +0 -2
- package/dist/executor_client-7ce0ddc7.js +0 -13
- package/dist/executor_client-7ce0ddc7.js.map +0 -1
- package/dist/executor_client-bfc8a1e1.mjs.map +0 -1
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a control binds when it is placed or re-bound (buckyos notepads/aiworkspace-control-on-bind-todo.md): every
|
|
3
|
+
* control placed in one go — a composite and the first Blocks of its slots, say — runs `on_bind` from parent to child
|
|
4
|
+
* (a child sees what its parent bound), then `on_init_control` from child to parent (a parent checks its children are
|
|
5
|
+
* ready); a failure or a cancelled dialog places nothing. A control without its own `on_bind` follows the default rule
|
|
6
|
+
* of its binding declarations (`required`, `many`, `schema_id`); a composite writes its steps in component.json. The
|
|
7
|
+
* host (the Desktop, the CLI) answers the data queries, shows the dialogs — or, with `no_ui` (an Agent), fails where a
|
|
8
|
+
* person would have to choose — and turns the result into one Commit (`bindOps`). Shared by the Desktop and the CLI.
|
|
9
|
+
*/
|
|
10
|
+
import { type Json, type Op } from './aiws_schedule';
|
|
11
|
+
/** One binding a control declares (component.json `bindings`, a built-in control's contract). */
|
|
12
|
+
export interface BindingDecl {
|
|
13
|
+
accepts?: string[];
|
|
14
|
+
required?: boolean;
|
|
15
|
+
/** Takes several data: the instance binds a list. */
|
|
16
|
+
many?: boolean;
|
|
17
|
+
/** Only tables of this business schema. */
|
|
18
|
+
schema_id?: string;
|
|
19
|
+
title?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Bound data by binding name: one id, or a list for a `many` binding. An id may be a `ref` of data created here. */
|
|
23
|
+
export type Bound = Record<string, string | string[]>;
|
|
24
|
+
/** Data of the Workspace a query answers. */
|
|
25
|
+
export interface DataInfo {
|
|
26
|
+
entity_id: string;
|
|
27
|
+
type_id: string;
|
|
28
|
+
schema_id?: string | null;
|
|
29
|
+
title?: string | null;
|
|
30
|
+
name?: string | null;
|
|
31
|
+
place?: string | null;
|
|
32
|
+
}
|
|
33
|
+
/** `ids`: only these (a control's own on_bind narrowing what a dialog offers). */
|
|
34
|
+
export interface DataQuery {
|
|
35
|
+
accepts?: string[];
|
|
36
|
+
schema_id?: string;
|
|
37
|
+
ids?: string[];
|
|
38
|
+
}
|
|
39
|
+
/** Data the binding creates, in the canvas's content folder, owned by the control (`ref` names it in `bindings`). */
|
|
40
|
+
export type CreateSpec = {
|
|
41
|
+
ref: string;
|
|
42
|
+
kind: 'standard';
|
|
43
|
+
schema_id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
} | {
|
|
46
|
+
ref: string;
|
|
47
|
+
kind: 'table';
|
|
48
|
+
name: string;
|
|
49
|
+
title_field_id?: string;
|
|
50
|
+
fields: Json[];
|
|
51
|
+
} | {
|
|
52
|
+
ref: string;
|
|
53
|
+
kind: 'dir';
|
|
54
|
+
name: string;
|
|
55
|
+
};
|
|
56
|
+
/** The host's dialogs (`no_ui`: each fails with `needsUi`). */
|
|
57
|
+
export interface BindDialogs {
|
|
58
|
+
pickOne(o: {
|
|
59
|
+
title: string;
|
|
60
|
+
note?: string;
|
|
61
|
+
query: DataQuery;
|
|
62
|
+
allow_new?: boolean;
|
|
63
|
+
current?: string | null;
|
|
64
|
+
}): Promise<string | {
|
|
65
|
+
new: true;
|
|
66
|
+
} | null>;
|
|
67
|
+
/** Each chosen id, and `{ new: true }` for a new one (when `allow_new`). */
|
|
68
|
+
pickMany(o: {
|
|
69
|
+
title: string;
|
|
70
|
+
note?: string;
|
|
71
|
+
query: DataQuery;
|
|
72
|
+
preselect?: 'all' | 'none' | string[];
|
|
73
|
+
allow_new?: boolean;
|
|
74
|
+
}): Promise<(string | {
|
|
75
|
+
new: true;
|
|
76
|
+
})[] | null>;
|
|
77
|
+
confirm(o: {
|
|
78
|
+
title: string;
|
|
79
|
+
text: string;
|
|
80
|
+
}): Promise<boolean>;
|
|
81
|
+
}
|
|
82
|
+
export declare class BindFailure extends Error {
|
|
83
|
+
readonly code: 'NEEDS_UI' | 'NO_DATA' | 'NOT_READY' | 'CANCELLED' | 'INVALID';
|
|
84
|
+
readonly node?: string | undefined;
|
|
85
|
+
readonly binding?: string | undefined;
|
|
86
|
+
constructor(message: string, code: 'NEEDS_UI' | 'NO_DATA' | 'NOT_READY' | 'CANCELLED' | 'INVALID', node?: string | undefined, binding?: string | undefined);
|
|
87
|
+
}
|
|
88
|
+
export interface BindCtx {
|
|
89
|
+
reason: 'insert' | 'rebind';
|
|
90
|
+
no_ui: boolean;
|
|
91
|
+
/** The control's id in this placement and its title. */
|
|
92
|
+
node: string;
|
|
93
|
+
title: string;
|
|
94
|
+
decls: Record<string, BindingDecl>;
|
|
95
|
+
/** Bindings already given: by an Agent, chosen before inserting, or the current ones on a re-bind. */
|
|
96
|
+
given: Bound;
|
|
97
|
+
/** What the parent control declared and bound (none for the control placed at the top). */
|
|
98
|
+
parent: {
|
|
99
|
+
decls: Record<string, BindingDecl>;
|
|
100
|
+
bound: Bound;
|
|
101
|
+
} | null;
|
|
102
|
+
find(q: DataQuery): DataInfo[];
|
|
103
|
+
/** The standard schemas the host can create a table of. */
|
|
104
|
+
canCreate(decl: BindingDecl): boolean;
|
|
105
|
+
dialogs: BindDialogs;
|
|
106
|
+
}
|
|
107
|
+
export interface BindResult {
|
|
108
|
+
bindings: Bound;
|
|
109
|
+
create: CreateSpec[];
|
|
110
|
+
}
|
|
111
|
+
export type OnBind = (ctx: BindCtx) => Promise<BindResult | null>;
|
|
112
|
+
export interface ChildState {
|
|
113
|
+
node: string;
|
|
114
|
+
title: string;
|
|
115
|
+
ready: boolean;
|
|
116
|
+
missing: string[];
|
|
117
|
+
}
|
|
118
|
+
export interface InitCtx {
|
|
119
|
+
reason: 'insert' | 'rebind';
|
|
120
|
+
no_ui: boolean;
|
|
121
|
+
node: string;
|
|
122
|
+
title: string;
|
|
123
|
+
decls: Record<string, BindingDecl>;
|
|
124
|
+
bound: Bound;
|
|
125
|
+
children: ChildState[];
|
|
126
|
+
dialogs: BindDialogs;
|
|
127
|
+
}
|
|
128
|
+
/** Ready (`true`), or why not. */
|
|
129
|
+
export type OnInit = (ctx: InitCtx) => Promise<true | string>;
|
|
130
|
+
/** A composite's declared steps (component.json manifest 5). */
|
|
131
|
+
export type OnBindStep = {
|
|
132
|
+
binding: string;
|
|
133
|
+
pick: 'one' | 'many' | 'all';
|
|
134
|
+
title?: string;
|
|
135
|
+
allow_new?: boolean;
|
|
136
|
+
} | {
|
|
137
|
+
binding: string;
|
|
138
|
+
from_parent: string;
|
|
139
|
+
} | {
|
|
140
|
+
binding: string;
|
|
141
|
+
create: {
|
|
142
|
+
standard: string;
|
|
143
|
+
} | {
|
|
144
|
+
table: {
|
|
145
|
+
name: string;
|
|
146
|
+
title_field_id?: string;
|
|
147
|
+
fields: Json[];
|
|
148
|
+
};
|
|
149
|
+
} | {
|
|
150
|
+
dir: {
|
|
151
|
+
name: string;
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
when?: 'missing' | 'always';
|
|
155
|
+
};
|
|
156
|
+
export type OnInitStep = {
|
|
157
|
+
require: 'children';
|
|
158
|
+
} | {
|
|
159
|
+
then: {
|
|
160
|
+
action: string;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
/** A control of this placement, with the controls placed under it. */
|
|
164
|
+
export interface BindNode {
|
|
165
|
+
id: string;
|
|
166
|
+
title: string;
|
|
167
|
+
decls: Record<string, BindingDecl>;
|
|
168
|
+
given?: Bound;
|
|
169
|
+
onBind?: OnBind | OnBindStep[];
|
|
170
|
+
onInit?: OnInit | OnInitStep[];
|
|
171
|
+
children: BindNode[];
|
|
172
|
+
}
|
|
173
|
+
export interface BindHost {
|
|
174
|
+
reason: 'insert' | 'rebind';
|
|
175
|
+
no_ui: boolean;
|
|
176
|
+
find(q: DataQuery): DataInfo[];
|
|
177
|
+
/** Standard schemas the host creates a table of (default: the to-do and calendar tables). */
|
|
178
|
+
standardSchemas?: string[];
|
|
179
|
+
dialogs: BindDialogs;
|
|
180
|
+
/** The control the placed one goes into, when it is one already on the canvas (a Block put into a composite). */
|
|
181
|
+
parent?: {
|
|
182
|
+
decls: Record<string, BindingDecl>;
|
|
183
|
+
bound: Bound;
|
|
184
|
+
} | null;
|
|
185
|
+
}
|
|
186
|
+
export type BindOutcome = {
|
|
187
|
+
ok: true;
|
|
188
|
+
results: Map<string, BindResult>;
|
|
189
|
+
then: {
|
|
190
|
+
node: string;
|
|
191
|
+
action: string;
|
|
192
|
+
}[];
|
|
193
|
+
} | {
|
|
194
|
+
ok: false;
|
|
195
|
+
error: BindFailure;
|
|
196
|
+
};
|
|
197
|
+
export declare const STANDARD_SCHEMAS: string[];
|
|
198
|
+
/** Whether `data` is what a declaration takes. */
|
|
199
|
+
export declare function bindingAccepts(decl: BindingDecl, data: Pick<DataInfo, 'type_id' | 'schema_id'>): boolean;
|
|
200
|
+
/** The dialogs of a host without a person: every one fails, naming the binding a caller has to give. */
|
|
201
|
+
export declare function noUiDialogs(): BindDialogs;
|
|
202
|
+
/** An on_bind's result as the host takes it — also what an HTML control's script returned (TODO §2.9): every binding a
|
|
203
|
+
* declared one, a single binding one id, a `many` one at most 32; what it creates well-formed, its refs used and renamed
|
|
204
|
+
* apart from other controls' refs of the same placement. */
|
|
205
|
+
export declare function checkBindResult(value: unknown, decls: Record<string, BindingDecl>, node: string): BindResult;
|
|
206
|
+
/** The default rule of a declaration (TODO §2.4): given → the parent's matching data → the Workspace's data. */
|
|
207
|
+
export declare const defaultOnBind: OnBind;
|
|
208
|
+
/** A composite's declared steps; bindings no step settles follow the default rule. */
|
|
209
|
+
export declare function stepsOnBind(steps: OnBindStep[]): OnBind;
|
|
210
|
+
/** The default `on_init_control`: ready when this control and its children have their required bindings. */
|
|
211
|
+
export declare const defaultOnInit: OnInit;
|
|
212
|
+
/** Run both events over a placement; the `then` actions run after the host's Commit. */
|
|
213
|
+
export declare function resolveBindings(root: BindNode, host: BindHost): Promise<BindOutcome>;
|
|
214
|
+
/** The operations of what a placement creates, ids for its refs: `name(spec)` gives a free name in the folder, `orderKey()`
|
|
215
|
+
* the next key there. */
|
|
216
|
+
export declare function createOps(results: Map<string, BindResult>, opts: {
|
|
217
|
+
folderId: string;
|
|
218
|
+
newId: () => string;
|
|
219
|
+
orderKey: () => string;
|
|
220
|
+
freeName: (name: string) => string;
|
|
221
|
+
locale?: 'zh' | 'en';
|
|
222
|
+
}): {
|
|
223
|
+
ops: Op[];
|
|
224
|
+
ids: Record<string, string>;
|
|
225
|
+
};
|
|
226
|
+
/** A control's `payload.bindings` from a result: a list for a `many` binding (none bound: left out). */
|
|
227
|
+
export declare function bindingsPayload(bound: Bound, decls: Record<string, BindingDecl>, ids: Record<string, string>): Record<string, Json>;
|
|
228
|
+
/** The ids a binding names (an outline's `bindings` value, one or a list). */
|
|
229
|
+
export declare function boundIds(value: string | string[] | null | undefined): string[];
|
|
230
|
+
/** Problems of declared steps (component.json manifest 5): `on_bind` / `on_init_control`, against the bindings and
|
|
231
|
+
* actions the control declares. */
|
|
232
|
+
export declare function checkBindSteps(onBind: unknown, onInit: unknown, decls: Record<string, BindingDecl>, actions: string[]): string[];
|
|
233
|
+
//# sourceMappingURL=aiws_bind.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aiws_bind.d.ts","sourceRoot":"","sources":["../src/aiws_bind.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAuD,KAAK,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,iBAAiB,CAAA;AAEzG,iGAAiG;AACjG,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,q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strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="component.json",t="composition.json",s="aiws-manifest.json",i=".aiws-build.json",n="aiws-template/1";class o extends Error{constructor(e){super(e.filter((e=>"error"===e.severity)).map((e=>`${e.file?`${e.file}: `:""}${e.message}`)).join("; ")||"invalid control source"),this.name="AiwsSourceError",this.diagnostics=e}}const r=new TextEncoder,a=new TextDecoder;function c(e,t){return`${e.replace(/\/+$/,"")}/${t}`}function l(e){return e.replace(/[/\\\u0000-\u001f]/g," ").replace(/^\.+/,"").trim().slice(0,80)||"Workspace"}async function d(e){const t=await crypto.subtle.digest("SHA-256",e);return Array.from(new Uint8Array(t),(e=>e.toString(16).padStart(2,"0"))).join("")}async function f(e){const t=[];for(const[s,i]of e)t.push([s,await d(i)]);return t.sort(((e,t)=>e[0]<t[0]?-1:e[0]>t[0]?1:0)),`sha256:${await d(r.encode(JSON.stringify(t)))}`}function p(e){return JSON.stringify([...e].sort(((e,t)=>e.name.localeCompare(t.name))).map((e=>[e.name,e.obj_id??e.etag??""])))}const u=4194304;function m(e){let t="";for(let s=0;s<e.length;s+=32768)t+=String.fromCharCode(...e.subarray(s,s+32768));return btoa(t)}async function h(e,t,s=[]){let i=e.reduce(((e,t)=>e+t.bytes.length),0);const n=new Map;if(i>u){if(!t)throw new o([{file:"",severity:"error",message:"a control's inline files are limited to 4194304 bytes per build"}]);for(const s of[...e].sort(((e,t)=>t.bytes.length-e.bytes.length))){if(i<=u)break;n.set(s.name,await t(s.name,s.bytes)),i-=s.bytes.length}}const r=[...s];for(const o of e){const e=n.get(o.name);r.push(e?{name:o.name,obj_id:e}:{name:o.name,base64:m(o.bytes)})}return r.sort(((e,t)=>e.name<t.name?-1:e.name>t.name?1:0))}async function y(e,t,s){var i;const n=[],r=[];for(const a of t)if(null==(i=a.obj_id)?void 0:i.startsWith("cyfile:"))n.push({name:a.name,obj_id:a.obj_id});else{if(!a.node_id)throw new o([{file:a.name,severity:"error",message:"the file service did not name this file"}]);r.push({name:a.name,bytes:new Uint8Array(await(await e.readFile(a.node_id)).arrayBuffer())})}return h(r,s,n)}const g=["manifest_version","ident","kind","title","description","host_api","accepts","allow_no_source","default_size","config_schema","bindings","entry","assets","catalog","agent","deps","events"],b=["type","enum","default","required","title","description","minimum","maximum","minLength","maxLength","properties","items"],v=/^[a-z0-9][a-z0-9._-]{0,63}$/,$=/^did:[a-z0-9]+:[^/#\s]+$/,w=/^[a-z][a-z0-9_]{0,31}$/,_=/^did:[a-z0-9]+:[^/#\s]+#[a-z0-9][a-z0-9._-]{0,63}$/,k="needs manifest_version 2 (raise it in component.json)",j="needs manifest_version 3 (raise it in component.json)",x=["string","number","boolean","object","entity"],S=["text","value","metric","bar","list","badge"],O=["kind","text","label","bind","by","format","limit"],A=["open_source","activate_editor","open_definition"],N=["text","number","select","boolean","color"];function E(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function I(e){return e.length>0&&r.encode(e).length<=255&&!e.includes("\0")&&e.split("/").every((e=>e.length>0&&!e.startsWith(".")))}function z(e){const t=E(e)?e.properties:void 0;return E(t)?t:{}}function J(e,t,s,i){for(const n of e.matchAll(/\{\{([^}]*)\}\}/g)){const e=n[1].trim();e.startsWith("config.")?e.slice(7)in s||i(`${t}: {{${e}}} names no property of config_schema`):i(`${t}: only {{config.<key>}} may be used here`)}}function T(e,t,s){if(e&&"object"==typeof e&&!Array.isArray(e))for(const[i,n]of Object.entries(e))if(b.includes(i)){if("properties"===i&&n&&"object"==typeof n)for(const[e,i]of Object.entries(n))T(i,`${t}/properties/${e}`,s);"items"===i&&T(n,`${t}/items`,s)}else s.push(`${t}/${i}: keyword ${i} is outside the supported subset`);else s.push(`${t}: a schema is an object`)}function q(e,t={},s="declarative.json"){const i=[],n=(e,t)=>i.push({file:s,severity:"error",message:e,...t?{code:t}:{}}),o=e=>i.push({file:s,severity:"warning",message:e});let r;try{const t=JSON.parse(e);if(!E(t))return n("a declarative definition is a JSON object"),i;r=t}catch(f){return n(f instanceof Error?f.message:String(f)),i}const a=E(t.bindings)?t.bindings:{},c=z(t.configSchema),l=(e,t)=>{if("string"==typeof e)J(e,t,c,n);else if(Array.isArray(e))e.forEach(((e,s)=>l(e,`${t}[${s}]`)));else if(E(e))for(const[s,i]of Object.entries(e))l(i,`${t}.${s}`)},d=(e,s)=>{void 0!==e&&(Array.isArray(e)?e.forEach(((e,i)=>{const r=`${s}[${i}]`;if(E(e))if("button"!==e.kind){"string"==typeof e.kind&&S.includes(e.kind)||n(`${r}.kind ${JSON.stringify(e.kind)}: one of ${[...S,"button"].join(", ")}`);for(const t of Object.keys(e))O.includes(t)||o(`${r}: key ${t} is ignored by the interpreter`);if(void 0===e.format||["text","number","percent","currency"].includes(e.format)||n(`${r}.format ${JSON.stringify(e.format)}: text, number, percent or currency`),"string"==typeof e.bind&&e.bind.includes(".")){const t=e.bind.slice(0,e.bind.indexOf("."));"props"===t||t in a||o(`${r}.bind ${JSON.stringify(e.bind)}: ${t} is not a declared binding, so it reads the field ${JSON.stringify(e.bind)} of the main source`)}}else((e,s)=>{void 0!==t.manifestVersion&&t.manifestVersion<3&&n(`${s}: a button ${j}`);for(const t of Object.keys(e))["kind","label","emit","params"].includes(t)||o(`${s}: key ${t} is ignored by the interpreter`);"string"==typeof e.label&&e.label||n(`${s}.label: the button's text (required)`),"string"==typeof e.emit&&e.emit?t.events&&!t.events.includes(e.emit)&&n(`${s}.emit ${e.emit}: not an event of component.json`,"EVENT_UNDECLARED"):n(`${s}.emit: the event the button raises (required)`),void 0!==e.params&&(E(e.params)?l(e.params,`${s}.params`):n(`${s}.params must be an object`))})(e,r);else n(`${r} must be an object`)})):n(`${s} must be an array`))};for(const[p,u]of Object.entries(r))"layout"===p?"stack"!==u&&"row"!==u&&n("layout: stack or row"):"items"===p?d(u,"items"):"view"===p?d(E(u)?u.items:void 0,"view.items"):"accent"===p?"string"!=typeof u&&n("accent must be a colour string"):"actions"===p?(Array.isArray(u)?u:[]).forEach(((e,t)=>{const s=E(e)?e:{};"string"==typeof s.command&&A.includes(s.command)||n(`actions[${t}].command: one of ${A.join(", ")}`),"string"==typeof s.id&&"string"==typeof s.label||n(`actions[${t}] needs id and label`)})):"inspector"===p?(Array.isArray(u)?u:[]).forEach(((e,t)=>{const s=E(e)?e:{};"string"==typeof s.kind&&N.includes(s.kind)||n(`inspector[${t}].kind: one of ${N.join(", ")}`),"string"==typeof s.key&&"string"==typeof s.label||n(`inspector[${t}] needs key and label`)})):o(`key ${p} is not part of the declarative vocabulary`);return void 0===r.items&&void 0===r.view&&o("no items: the control draws nothing"),i}function C(e,s,i=t,n={}){const o=[],a=(e,t)=>o.push({file:i,severity:"error",message:e,...t?{code:t}:{}});let c;try{const t=JSON.parse(e);if(!t||"object"!=typeof t||Array.isArray(t))return a("a composition is a JSON object { layout, slots, chrome?, events? }"),o;c=t}catch(y){return a(y instanceof Error?y.message:String(y)),o}const l=z(s),d=(e,t)=>J(e,t,l,a),f=(e,t,s)=>{"number"==typeof e&&e>=0&&e<=s||("string"==typeof e&&/^\s*\{\{.*\}\}\s*$/.test(e)?d(e,t):a(`${t}: a number in [0, ${s}] or {{config.<key>}}`))};for(const t of Object.keys(c))["layout","slots","chrome","events"].includes(t)||a(`unknown key ${t} (a composition says layout, slots, chrome and events)`);const p=c.layout;let u="stack";if(p&&"object"==typeof p){"stack"===p.algorithm||"fixed"===p.algorithm||"grid"===p.algorithm?u=p.algorithm:a(`layout.algorithm ${JSON.stringify(p.algorithm)}: stack, fixed or grid (the algorithms the host ships)`);for(const[e,t]of Object.entries(p))if("algorithm"!==e)if("direction"!==e&&"spacing"!==e||"stack"===u)if("columns"!==e&&"gap"!==e||"grid"===u)if("direction"===e)"column"!==t&&"row"!==t&&a("layout.direction: column or row");else if("spacing"===e)f(t,"layout.spacing",2e3);else if("columns"===e)(!Number.isInteger(t)||t<1||t>12)&&a("layout.columns: an integer in [1, 12]");else if("gap"===e)f(t,"layout.gap",2e3);else if("padding"===e)if(t&&"object"==typeof t&&!Array.isArray(t))for(const[s,i]of Object.entries(t))["t","r","b","l"].includes(s)||a(`layout.padding.${s}: t, r, b or l`),f(i,`layout.padding.${s}`,2e3);else f(t,"layout.padding",2e3);else a(`layout: unknown key ${e}`);else a(`layout.${e} belongs to the grid layout`);else a(`layout.${e} belongs to the stack layout`);"grid"===u&&void 0===p.columns&&a("layout.columns (1…12) required: the cells of a grid row")}else a("layout { algorithm: stack | fixed | grid } required");const m=c.slots&&"object"==typeof c.slots&&!Array.isArray(c.slots)?c.slots:null;if(m){Object.keys(m).length>16&&a("at most 16 slots");for(const[e,t]of Object.entries(m)){const s=`slots.${e}`;if(w.test(e)||a(`${s}: a slot name is [a-z][a-z0-9_]{0,31}`),!t||"object"!=typeof t||Array.isArray(t)){a(`${s} must be an object`);continue}const i=t;for(const[e,t]of Object.entries(i))if("accepts"===e){if(!Array.isArray(t)||0===t.length||t.length>32){a(`${s}.accepts: 1…32 entries (cell:<ident>, a view type, container)`);continue}for(const e of t)"string"==typeof e&&e.startsWith("cell:")?(!_.test(e.slice(5))||r.encode(e.slice(5)).length>128)&&a(`${s}.accepts ${JSON.stringify(e)}: cell:<author_did>#<name>`):"container"===e||"string"==typeof e&&v.test(e)||a(`${s}.accepts ${JSON.stringify(e)}: cell:<ident>, a view type or container`)}else"min"===e?(!Number.isInteger(t)||t<0||t>64)&&a(`${s}.min: an integer in [0, 64]`):"max"===e?(!Number.isInteger(t)||t<1||t>1e3)&&a(`${s}.max: an integer in [1, 1000]`):"placement"===e?"stack"!==t&&"top"!==t&&"bottom"!==t&&"free"!==t?a(`${s}.placement: stack, top, bottom or free`):"fixed"===u&&"free"!==t?a(`${s}.placement: a fixed layout keeps every child where it is (free)`):"grid"===u&&"stack"!==t&&a(`${s}.placement: a grid fills its cells with the slots' children in slot order (stack)`):"title"===e?("string"!=typeof t||t.length>256)&&a(`${s}.title: at most 256 characters`):a(`${s}: unknown key ${e}`);Number.isInteger(i.min)&&Number.isInteger(i.max)&&i.min>i.max&&a(`${s}: min exceeds max`)}}else a("slots { <name>: { accepts?, min?, max?, placement? } } required");const h=c.chrome;if(void 0!==h)if(!h||"object"!=typeof h||Array.isArray(h))a("chrome must be an object");else for(const[t,r]of Object.entries(h)){const e=`chrome.${t}`;if("background"===t||"border"===t)"string"==typeof r&&r.length<=64?d(r,e):a(`${e}: a colour (≤ 64 characters) or {{config.<key>}}`);else if("radius"===t)f(r,e,200);else if("empty"===t)"string"==typeof r&&r.length<=1e3?d(r,e):a(`${e}: a text of at most 1000 characters`);else if("title"===t){const t=r;if(!t||"object"!=typeof t||Array.isArray(t)){a(`${e}: { text, slot? }`);continue}for(const[e,s]of Object.entries(t))"text"===e?"string"==typeof s&&s.length<=256?d(s,"chrome.title.text"):a("chrome.title.text: at most 256 characters"):"slot"===e?"string"==typeof s&&m&&s in m||a(`chrome.title.slot ${JSON.stringify(s)}: a slot of this composition`):a(`chrome.title: unknown key ${e}`);"string"!=typeof t.text&&a("chrome.title.text required")}else a(`chrome: unknown key ${t} (background, radius, border, title, empty)`)}if(void 0!==c.events)if(void 0!==n.manifestVersion&&n.manifestVersion<3&&a(`events ${j}`),E(c.events)){Object.keys(c.events).length>16&&a("events: at most 16");for(const[e,t]of Object.entries(c.events)){const s=`events.${e}`;if(w.test(e)||a(`${s}: an event name is [a-z][a-z0-9_]{0,31}`),!E(t)){a(`${s} must be an object { from: { slot, event }, title?, description? }`);continue}for(const[e,n]of Object.entries(t))"title"===e?("string"!=typeof n||n.length>256)&&a(`${s}.title: at most 256 characters`):"description"===e?("string"!=typeof n||n.length>4e3)&&a(`${s}.description: at most 4000 characters`):"from"!==e&&a(`${s}: unknown key ${e} (from, title, description)`);const i=t.from;if(!E(i)){a(`${s}.from { slot, event } required: the child event it re-raises`);continue}for(const e of Object.keys(i))"slot"!==e&&"event"!==e&&a(`${s}.from: unknown key ${e} (slot, event)`);const o="string"==typeof i.event&&w.test(i.event)?i.event:void 0;o||a(`${s}.from.event: an event name [a-z][a-z0-9_]{0,31}`);const r="string"==typeof i.slot&&m?m[i.slot]:void 0;if(!E(r)){a(`${s}.from.slot ${JSON.stringify(i.slot)}: a slot of this composition`);continue}if(!o)continue;const c=(Array.isArray(r.accepts)?r.accepts:[]).filter((e=>"string"==typeof e&&e.startsWith("cell:"))).map((e=>e.slice(5)));if(0===c.length){a(`${s}: slot ${i.slot} accepts no cell:<ident>, so no control there declares ${o}`,"EVENT_UNDECLARED");continue}c.map((e=>{var t;return null==(t=n.cellEvents)?void 0:t.call(n,e)})).every((e=>void 0!==e&&!e.includes(o)))&&a(`${s}: no control slot ${i.slot} accepts (${c.join(", ")}) declares the event ${o}`,"EVENT_UNDECLARED")}}else a("events must be an object { <name>: { from: { slot, event }, title?, description? } }");return o}function W(t,s,i,n){const o=[],a=e,c=e=>o.push({file:a,severity:"error",message:e});let l;try{const e=JSON.parse(t);if(!e||"object"!=typeof e||Array.isArray(e))return c("must be a JSON object"),o;l=e}catch(O){return c(O instanceof Error?O.message:String(O)),o}for(const e of Object.keys(l))g.includes(e)||c(`unknown key ${e}`);const d=l.manifest_version,f="number"==typeof d&&Number.isInteger(d)&&d>=1?d:0;f?f>3&&c(`manifest_version ${d} is newer than this client reads (3)`):c("manifest_version (1…3) required");const p=f>0&&f<3,u=l.ident;let m="";u&&"object"==typeof u?("string"==typeof u.author_did&&$.test(u.author_did)||c("ident.author_did must be a DID (did:<method>:<id>)"),"string"==typeof u.name&&v.test(u.name)||c("ident.name must be [a-z0-9][a-z0-9._-]{0,63}"),"string"==typeof u.author_did&&"string"==typeof u.name&&(m=`${u.author_did}#${u.name}`,r.encode(m).length>128&&c("an identity is at most 128 bytes"))):c("ident { author_did, name } required");const h="composite"===l.kind;if("declarative"===l.kind||"html"===l.kind||h||c("kind must be declarative, html or composite"),h&&1===f&&c(`kind composite ${k}`),h)for(const e of["accepts","allow_no_source"])void 0!==l[e]&&c(`${e}: a composite is a container of Blocks, not a Cell showing data`);if(("string"!=typeof l.title||!l.title||l.title.length>256)&&c("title: 1…256 characters"),void 0!==l.config_schema){const e=[];T(l.config_schema,"config_schema",e),e.forEach(c)}if(void 0!==l.bindings)if(l.bindings&&"object"==typeof l.bindings)for(const e of Object.keys(l.bindings))w.test(e)&&"props"!==e||c(`binding name ${e}: [a-z][a-z0-9_]{0,31}, not props`);else c("bindings must be an object");if(void 0!==l.deps)if(!Array.isArray(l.deps)||l.deps.length>32)c("deps: at most 32 identities <author_did>#<name>");else if(l.deps.length>0&&1===f)c(`deps ${k}`);else{const e=new Set;for(const t of l.deps)"string"==typeof t&&_.test(t)?t===m?c("deps: a control cannot depend on itself"):e.has(t)&&c(`deps lists ${t} twice`):c(`deps: ${JSON.stringify(t)} is not an identity <author_did>#<name>`),e.add(String(t))}let y=[];if(void 0!==l.events){if(h)c("events: a composite declares its events in composition.json (events.<name>.from re-raises an event of a child)");else if(p)c(`events ${j}`);else{const e=[];!function(e,t){if(E(e)){Object.keys(e).length>16&&t.push("events: at most 16");for(const[s,i]of Object.entries(e)){const e=`events.${s}`;if(w.test(s)||t.push(`${e}: an event name is [a-z][a-z0-9_]{0,31}`),E(i)){for(const[s,n]of Object.entries(i))"title"===s?("string"!=typeof n||n.length>256)&&t.push(`${e}.title: at most 256 characters`):"description"===s?("string"!=typeof n||n.length>4e3)&&t.push(`${e}.description: at most 4000 characters`):"params"!==s&&t.push(`${e}: unknown key ${s} (title, description, params)`);if(void 0!==i.params)if(E(i.params)){Object.keys(i.params).length>16&&t.push(`${e}.params: at most 16`);for(const[s,n]of Object.entries(i.params)){const i=`${e}.params.${s}`;if(w.test(s)||t.push(`${i}: a param name is [a-z][a-z0-9_]{0,31}`),E(n)){for(const[e,s]of Object.entries(n))"type"===e?"string"==typeof s&&x.includes(s)||t.push(`${i}.type: ${x.join(", ")}`):"required"===e?"boolean"!=typeof s&&t.push(`${i}.required must be a boolean`):"description"===e?("string"!=typeof s||s.length>1e3)&&t.push(`${i}.description: at most 1000 characters`):t.push(`${i}: unknown key ${e} (type, required, description)`);void 0===n.type&&t.push(`${i}.type required`)}else t.push(`${i} must be an object { type, required?, description? }`)}}else t.push(`${e}.params must be an object { <param>: { type, required?, description? } }`)}else t.push(`${e} must be an object { title?, description?, params? }`)}}else t.push("events must be an object { <name>: { title?, description?, params? } }")}(l.events,e),e.forEach(c)}!h&&E(l.events)&&(y=Object.keys(l.events))}const b=e=>"string"==typeof e&&s.includes(e),S=new Set([a]);if("html"===l.kind){const e=l.entry;if(e&&"object"==typeof e&&"string"==typeof e.html)for(const[t,s]of Object.entries(e))b(s)?S.add(String(s)):c(`entry.${t} ${JSON.stringify(s)} is not in the directory`);else c("entry must be { html, css?, js? }");void 0!==l.host_api&&2!==l.host_api&&3!==l.host_api?c("host_api: the HTML Block host speaks API 2 and 3"):3===l.host_api&&p&&c(`host_api 3 ${j}`),y.length>0&&3!==l.host_api&&o.push({file:a,severity:"warning",message:"events: an HTML control raises them with aiws.emit, which is host API 3 (set host_api to 3)"})}else if("declarative"===l.kind||h){if(b(l.entry)){S.add(String(l.entry));const e=null==i?void 0:i(String(l.entry)),t=f||void 0;void 0!==e&&h?o.push(...C(e,l.config_schema,String(l.entry),{manifestVersion:t,cellEvents:n})):void 0!==e&&o.push(...q(e,{bindings:l.bindings,events:y,configSchema:l.config_schema,manifestVersion:t},String(l.entry)))}else c(`entry ${JSON.stringify(l.entry)} is not in the directory`);h&&void 0!==l.host_api&&c("host_api: a composite runs no code of its own (its layout and chrome are the host's)"),h||void 0===l.host_api||1===l.host_api||c("host_api: the declarative interpreter is version 1")}for(const e of Array.isArray(l.assets)?l.assets:[])b(e)?S.add(String(e)):c(`asset ${JSON.stringify(e)} is not in the directory`);void 0!==l.agent&&(b(l.agent)?S.add(String(l.agent)):c(`agent ${JSON.stringify(l.agent)} is not in the directory`));for(const e of s)I(e)?S.has(e)||o.push({file:e,severity:"warning",message:"not named by component.json: kept in the source snapshot only"}):o.push({file:e,severity:"error",message:"a file of a source directory: a relative path whose parts do not start with '.'"});return o}function D(e){if(!e||"object"!=typeof e)throw new o([{file:s,severity:"error",message:"must be a JSON object"}]);const t=e,i=t.manifest_version;if("number"!=typeof i||i<1)throw new o([{file:s,severity:"error",message:"manifest_version required"}]);if(i>3)throw new o([{file:s,severity:"error",message:`manifest_version ${i} needs a newer client (this one reads 3)`}]);if("aiws"!==t.purpose)throw new o([{file:s,severity:"error",message:"purpose must be aiws"}]);if(!Array.isArray(t.controls))throw new o([{file:s,severity:"error",message:"controls must be an array"}]);return{manifest_version:i,purpose:"aiws",host_api:t.host_api??{},controls:t.controls,workspace_templates:Array.isArray(t.workspace_templates)?t.workspace_templates:[]}}const B=/^[a-z0-9][a-z0-9-]{0,63}$/;function L(e){return`templates/${e}/`}async function F(e,t){const s=L(t),i=[];for(const[n,o]of e)n.startsWith(s)&&i.push([n.slice(s.length),o]);return f(i)}function M(e,t){if(!E(e))return["a template is an object { id, title, snapshot, digest, requires, description?, params?, reset? }"];const s=[];for(const n of Object.keys(e))["id","title","description","snapshot","digest","requires","params","reset"].includes(n)||s.push(`unknown key ${n}`);"string"==typeof e.id&&B.test(e.id)?e.snapshot!==`${L(e.id)}snapshot.json`&&s.push(`snapshot must be ${L(e.id)}snapshot.json`):s.push("id: [a-z0-9][a-z0-9-]{0,63}"),("string"!=typeof e.title||!e.title||e.title.length>256)&&s.push("title: 1…256 characters"),void 0!==e.description&&("string"!=typeof e.description||e.description.length>4e3)&&s.push("description: at most 4000 characters"),"string"==typeof e.digest&&/^sha256:[0-9a-f]{64}$/.test(e.digest)||s.push("digest: sha256:<64 hex digits>");const i=e.requires;if(E(i)){for(const e of Object.keys(i))"host_api"!==e&&"controls"!==e&&s.push(`requires: unknown key ${e}`);if(void 0!==i.host_api)if(E(i.host_api))for(const[e,t]of Object.entries(i.host_api))("html"!==e&&"declarative"!==e||!Number.isInteger(t)||t<1)&&s.push(`requires.host_api.${e}: html or declarative, a positive integer`);else s.push("requires.host_api must be an object { html?, declarative? }");if(!Array.isArray(i.controls)||i.controls.length>256)s.push("requires.controls: at most 256 identities");else{const e=new Set;for(const n of i.controls)"string"==typeof n&&t.has(n)?e.has(n)&&s.push(`requires.controls lists ${n} twice`):s.push(`requires.controls: ${JSON.stringify(n)} is not a control of this manifest`),e.add(n)}}else s.push("requires { host_api?, controls } required");if(void 0!==e.params)if(!E(e.params)||Object.keys(e.params).length>32)s.push("params: an object of at most 32 { type, title?, default? }");else for(const[n,o]of Object.entries(e.params)){const e=`params.${n}`;if(w.test(n)||s.push(`${e}: a param name is [a-z][a-z0-9_]{0,31}`),E(o)){for(const[t,i]of Object.entries(o))"type"===t?"string"!==i&&"number"!==i&&"boolean"!==i&&s.push(`${e}.type: string, number or boolean`):"title"===t?("string"!=typeof i||i.length>256)&&s.push(`${e}.title: at most 256 characters`):"default"===t?["string","number","boolean"].includes(typeof i)||s.push(`${e}.default: a string, number or boolean`):s.push(`${e}: unknown key ${t} (type, title, default)`);void 0===o.type&&s.push(`${e}.type required`)}else s.push(`${e} must be an object { type, title?, default? }`)}if(void 0!==e.reset){const t=E(e.reset)?e.reset.tables:void 0;!E(e.reset)||Object.keys(e.reset).some((e=>"tables"!==e))?s.push("reset: { tables }"):void 0!==t&&(!Array.isArray(t)||t.length>64||new Set(t).size!==t.length||t.some((e=>"string"!=typeof e||!/^[a-z0-9][a-z0-9_-]{0,63}$/.test(e))))&&s.push("reset.tables: at most 64 distinct table ids")}return s}async function R(e,t,s){const i=/[*?[\]\\]/.test(s)?void 0:s;return(await e.list("string"==typeof t?t:{ref:t},{limit:i?10:1e3,...i?{filter:{name_glob:i}}:{}},["base","ident"])).entries.find((e=>e.name===s))}async function P(e,t){const s=t.split("/").filter(Boolean);if(0===s.length)throw new Error(`not a folder path: ${t}`);let i=(await e.stat(`/${s[0]}`)).ref;for(const n of s.slice(1)){const s=await R(e,i,n);if(s&&"dir"!==s.target.kind)throw new o([{file:n,severity:"error",message:`${n} in ${t} is not a folder`}]);i=s?s.target.ref:(await e.mkdir({ref:i},n)).ref}return i}async function V(e,t){const s=t.split("/").filter(Boolean);if(0===s.length)return null;let i=(await e.stat(`/${s[0]}`)).ref;for(const n of s.slice(1)){const t=await R(e,i,n);if(!t||"dir"!==t.target.kind)return null;i=t.target.ref}return i}async function U(t,s){const i=await V(t,s);return null!==i&&void 0!==await R(t,i,e)}async function G(e,t,s,i){const n="string"==typeof t?await P(e,t):t;await e.uploadFile(n,s,i,{overwrite:!0})}const H=e=>new Promise((t=>setTimeout(t,e)));async function K(e,t){const s=[],i=[],n=async(t,o,r)=>{var a,c,l;let d;do{const f=await e.list("string"==typeof t?t:{ref:t},{limit:500,...d?{cursor:d}:{}},["base","ident"]);for(const e of f.entries){if(e.name.startsWith("."))continue;const t=`${o}${e.name}`;if("dir"===e.target.kind){r>=8?i.push({file:t,severity:"error",message:"sub-folders nest at most 8 levels"}):await n(e.target.ref,`${t}/`,r+1);continue}if("file"!==e.target.kind){i.push({file:t,severity:"error",message:"only files and folders belong to a control source"});continue}const d=e.target.ref,f="object"===d.type?d.obj_id:"string"==typeof(null==(a=e.target.attrs)?void 0:a.obj_id)?e.target.attrs.obj_id:void 0;s.push({name:t,...f?{obj_id:f}:{},..."live"===d.type?{node_id:d.node_id}:{},..."string"==typeof(null==(c=e.target.attrs)?void 0:c.etag)?{etag:e.target.attrs.etag}:{},..."number"==typeof(null==(l=e.target.attrs)?void 0:l.size)?{size:e.target.attrs.size}:{}})}d=f.truncated?f.next_cursor:void 0}while(d)};if(await n(t,"",0),0===s.length&&i.push({file:"",severity:"error",message:`${t} holds no files`}),s.length>64&&i.push({file:"",severity:"error",message:"a control holds at most 64 files"}),i.some((e=>"error"===e.severity)))throw new o(i);return s.sort(((e,t)=>e.name<t.name?-1:e.name>t.name?1:0))}async function X(e,t,s,i){const n=s.lastIndexOf("/");await G(e,n<0?t:c(t,s.slice(0,n)),n<0?s:s.slice(n+1),i)}async function Y(e,t){const s=[];for(const i of t){if(!i.node_id)throw new o([{file:i.name,severity:"error",message:"the file service did not name this file"}]);s.push([i.name,new Uint8Array(await(await e.readFile(i.node_id)).arrayBuffer())])}return f(s)}async function Q(e,t){try{const s=await R(e,t,i),n="live"===(null==s?void 0:s.target.ref.type)?s.target.ref.node_id:void 0;if(!n)return null;const o=await e.readFile(n);return await o.json()}catch{return null}}async function Z(e,t,s){await G(e,t,i,r.encode(`${JSON.stringify(s,null,2)}\n`))}exports.AIWS_BUILD_STATE_FILE=i,exports.AIWS_COMPONENT_FILE=e,exports.AIWS_COMPOSITION_FILE=t,exports.AIWS_DECLARATIVE_API_VERSION=1,exports.AIWS_HTML_API_VERSION=3,exports.AIWS_MANIFEST_FILE=s,exports.AIWS_MANIFEST_VERSION=3,exports.AIWS_MAX_INLINE_BYTES=u,exports.AIWS_MAX_SOURCE_FILES=64,exports.AIWS_TEMPLATE_FORMAT=n,exports.AiwsSourceError=o,exports.aiwsContentDigest=f,exports.aiwsTemplateDigest=F,exports.buildControl=async function(e,t,s,i,n={}){const o=await K(t,i),r=await Q(t,i),a=r&&r.workspace_id===s?{def_rev:r.def_rev,dir_rev:r.dir_rev}:void 0,c=await e.extBuild(s,{files:await y(t,o,n.upload),...n.folderId?{folder_id:n.folderId}:{},...a?{expect:a}:{},...n.force?{force:!0}:{},...n.dryRun?{dry_run:!0}:{},...n.migration?{migration:n.migration}:{}});return n.dryRun||"string"!=typeof c.def_entity_id||"number"!=typeof c.def_rev||await Z(t,i,{workspace_id:s,def_entity_id:c.def_entity_id,def_rev:c.def_rev,dir_rev:Number(c.dir_rev??0),ident:String(c.ident??""),at:(new Date).toISOString()}),{...c,files:o}},exports.buildFiles=y,exports.checkComponent=W,exports.checkComposition=C,exports.checkDeclarative=q,exports.collectSources=K,exports.compatManifest=D,exports.controlSkeleton=function(s){const i=s.title??s.name;if("composite"===s.kind){const n="fixed"===s.algorithm,o=s.slots??{items:{placement:n?"free":"stack",title:"Items"}},r={layout:n?{algorithm:"fixed",padding:12}:{algorithm:"stack",direction:"column",spacing:"{{config.gap}}",padding:12},slots:o,chrome:{background:"{{config.background}}",radius:12,title:{text:"{{config.title}}"},empty:"Drop Blocks here"}},a={manifest_version:3,ident:{author_did:s.authorDid,name:s.name},kind:"composite",title:i,description:`${i}: a panel of Blocks`,default_size:{w:320,h:360},config_schema:{type:"object",properties:{title:{type:"string",title:"Title",default:i},background:{type:"string",title:"Background",default:"#f6f7fb"},gap:{type:"integer",title:"Gap (px)",default:8,minimum:0,maximum:64}}},entry:t,deps:s.deps??[],catalog:{group:"custom",description:`${i}`},agent:"AGENT.md"},c=Object.keys(o).map((e=>`\`${e}\``)).join(", ");return{[e]:`${JSON.stringify(a,null,2)}\n`,[t]:`${JSON.stringify(r,null,2)}\n`,"AGENT.md":`# ${i}\n\nA composite: an instance is a \`buckyos.container { kind: "composite", def_ref }\`; put Blocks under it with \`slot\` set to one of ${c}. Config: \`title\`, \`background\`, \`gap\`.\n`}}const n={manifest_version:3,ident:{author_did:s.authorDid,name:s.name},kind:s.kind??"declarative",title:i,description:`${i}: a control of this Workspace`,accepts:["buckyos.table-source","buckyos.record"],allow_no_source:!0,default_size:{w:260,h:140},config_schema:{type:"object",properties:{label:{type:"string",title:"Label",default:i}}},bindings:{data:{accepts:["buckyos.table-source"],title:"Data",description:"The table this control summarizes"}},catalog:{group:"custom",description:`${i}`},agent:"AGENT.md"},o=`# ${i}\n\nBind \`data\` to a table. Config: \`label\` (text).\n`;if("html"===s.kind){const t={clicked:{title:"Clicked",description:"Raised when someone clicks the button (in run mode)",params:{count:{type:"number",description:"Rows of the bound table"}}}};return{[e]:`${JSON.stringify({...n,host_api:3,events:t,entry:{html:"view.html",css:"style.css",js:"behavior.js"}},null,2)}\n`,"view.html":'<div class="card"><div class="label" id="label"></div><div class="value" id="value">—</div><button id="go" type="button">Go</button></div>\n',"style.css":".card{font:14px system-ui;padding:12px}.label{opacity:.7}.value{font-size:28px;font-weight:600}\n","behavior.js":["document.getElementById('label').textContent = (aiws.context.config || {}).label || ''","var count = 0","if (aiws.bindings.data) aiws.input('data').rows().then(function (rows) { count = rows.length; document.getElementById('value').textContent = String(count) })","// the public event of component.json: an instance binds handlers to it in its `on` (host API 3)","document.getElementById('go').addEventListener('click', function () { aiws.emit('clicked', { count: count }) })",""].join("\n"),"AGENT.md":`${o}Event: \`clicked\` (\`count\`), raised by its button; bind handlers to it in the instance's \`on\`.\n`}}return{[e]:`${JSON.stringify({...n,entry:"declarative.json"},null,2)}\n`,"declarative.json":`${JSON.stringify({layout:"stack",items:[{kind:"metric",label:i,bind:"data.count",format:"number"},{kind:"text",text:"Rows of the bound table"}]},null,2)}\n`,"AGENT.md":o}},exports.createControlSource=async function(t,s,i){const n=await P(t,s),a=await t.list({ref:n},{limit:500},["base"]).catch((()=>null));if(null==a?void 0:a.entries.some((t=>t.name===e)))throw new o([{file:e,severity:"error",message:`${s} already holds a control`}]);for(const[e,o]of Object.entries(i))await G(t,n,e,r.encode(o));return n},exports.ensureFolder=P,exports.exportBundle=async function(e,t,i,n){const o=await e.extExport(t,i,"package"),a=new Map;a.set(s,r.encode(`${JSON.stringify(o.manifest,null,2)}\n`));for(const s of o.files)a.set(s.path,void 0!==s.text?r.encode(s.text):await n(t,String(s.obj_id)));return{manifest:D(o.manifest),files:a,controls:o.controls}},exports.findFolder=V,exports.folderName=l,exports.hasControlSource=U,exports.homeControlDir=function(e,t,s){return`/home/${e}/AI Workspace/${l(t)}/controls/${s}`},exports.homeExportDir=function(e,t){return`/home/${e}/AI Workspace/exports/${t}`},exports.isSourcePath=I,exports.joinPath=c,exports.packBuildFiles=h,exports.pullControl=async function(e,t,s,i,n,o){const a=(await e.extExport(s,[i],"pull")).controls[0];await P(t,n);for(const l of a.files)await X(t,n,l.name,void 0!==l.text?r.encode(l.text):await o(s,String(l.obj_id)));const c={workspace_id:s,def_entity_id:a.entity_id,def_rev:a.def_rev,dir_rev:a.dir_rev,ident:a.ident,at:(new Date).toISOString()};return await Z(t,n,c),{files:a.files.map((e=>e.name)),state:c}},exports.readBuildState=Q,exports.slotCells=function(e){const t=new Set;for(const s of Object.values(e.slots??{}))for(const e of s.accepts??[])e.startsWith("cell:")&&t.add(e.slice(5));return[...t].sort()},exports.sourceStateKey=function(e){return`aiws:src:${e}`},exports.sourcesDigest=Y,exports.sourcesKey=p,exports.templateDir=L,exports.unbuiltChanges=async function(e,t,s,i,n){var o;if(!(await U(t,n)))return null;const r=await Y(t,await K(t,n)),a=await e.extExport(s,[i],"pull"),c=String((null==(o=a.controls[0])?void 0:o.digest)??"");return{changed:r!==c,home:r,built:c}},exports.verifyBundle=async function(t){var i,r;const c=t.get(s);if(!c)throw new o([{file:s,severity:"error",message:"missing"}]);let l;try{l=JSON.parse(a.decode(c))}catch(g){throw new o([{file:s,severity:"error",message:String(g)}])}const d=D(l),p=[],u=d.workspace_templates;u.length>0&&d.manifest_version<3&&p.push({file:s,severity:"error",message:`Workspace templates need manifest_version 3 (raise it in ${s})`}),u.length>32&&p.push({file:s,severity:"error",message:"at most 32 Workspace templates"}),0===d.controls.length&&0===u.length&&p.push({file:s,severity:"error",message:"lists no control"});const m=new Map;for(const s of d.controls){const i="string"==typeof s.dir?t.get(`${s.dir}${e}`):void 0;try{const e=i?JSON.parse(a.decode(i)):void 0;E(e)&&m.set(s.ident,E(e.events)?Object.keys(e.events):[])}catch{}}const h=new Set;for(const n of d.controls){if("string"!=typeof n.dir||!/^controls\/[a-z0-9][a-z0-9._-]{0,70}\/$/.test(n.dir)||h.has(n.dir)){p.push({file:s,severity:"error",message:`control ${n.ident}: bad or repeated dir`});continue}h.add(n.dir);const o=[...t].filter((([e])=>e.startsWith(n.dir))).map((([e,t])=>[e.slice(n.dir.length),t]));await f(o)!==n.digest&&p.push({file:n.dir,severity:"error",message:"the files do not match the manifest digest"});const c=o.find((([t])=>t===e));if(!c){p.push({file:`${n.dir}${e}`,severity:"error",message:"missing"});continue}const l=e=>{const t=o.find((([t])=>t===e));return t?a.decode(t[1]):void 0};for(const e of W(a.decode(c[1]),o.map((([e])=>e)),l,(e=>m.get(e))))p.push({...e,file:`${n.dir}${e.file}`});try{const e=JSON.parse(a.decode(c[1]));`${null==(i=e.ident)?void 0:i.author_did}#${null==(r=e.ident)?void 0:r.name}`===n.ident&&e.kind===n.kind||p.push({file:n.dir,severity:"error",message:"ident and kind must match its component.json"}),JSON.stringify([...e.deps??[]].sort())!==JSON.stringify([...n.deps??[]].sort())&&p.push({file:n.dir,severity:"error",message:"deps must match its component.json"})}catch{}}const y=new Set(d.controls.map((e=>e.ident)));for(const e of d.controls)for(const t of e.deps??[])y.has(t)||p.push({file:s,severity:"error",message:`${e.ident} depends on ${t}, which the bundle does not carry`});for(const[e,o]of u.entries()){const i=E(o)&&"string"==typeof o.id?`template ${o.id}`:`workspace_templates[${e}]`;for(const e of M(o,y))p.push({file:s,severity:"error",message:`${i}: ${e}`});if(!E(o)||"string"!=typeof o.id||!B.test(o.id))continue;const r=L(o.id);if(h.has(r)){p.push({file:s,severity:"error",message:`${i} is listed twice`});continue}h.add(r);const c=t.get(`${r}snapshot.json`);let l;try{l=c?JSON.parse(a.decode(c)).format:void 0}catch{l=void 0}c?l!==n&&p.push({file:`${r}snapshot.json`,severity:"error",message:`not a template snapshot (format ${n})`}):p.push({file:`${r}snapshot.json`,severity:"error",message:"missing"}),await F(t,o.id)!==o.digest&&p.push({file:r,severity:"error",message:"the files do not match the template digest"})}for(const e of t.keys())e===s||[...h].some((t=>e.startsWith(t)))||p.push({file:e,severity:"error",message:"belongs to no control or template of the manifest"});return{manifest:d,diagnostics:p}},exports.watchControl=async function(e,t,s,i={}){var n,o;let r,a="",c=Promise.resolve();const l=()=>{c=c.then((async()=>{let i;try{i=await K(e,t)}catch{return}const n=p(i);n!==a&&(a=n,await s(i))})).catch((()=>{}))};for(l();!(null==(n=i.signal)?void 0:n.aborted);){const s=await e.list(t,{limit:1},["base"]),n=e.watch({tokens:s.watch_token?[s.watch_token]:[],signal:i.signal});try{for await(const e of n)r&&clearTimeout(r),r=setTimeout(l,i.debounceMs??500)}catch{if(null==(o=i.signal)?void 0:o.aborted)break;await H(2e3)}finally{n.close()}}r&&clearTimeout(r),await c},exports.writeBuildState=Z,exports.writeHomeFile=G,exports.writeSourceFile=X;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./aiws_bind-82bace11.js");require("./object_url-8fb5a7bf.js"),require("./ndn_types-5b138882.js");const t="component.json",o="composition.json",s="aiws-manifest.json",i=".aiws-build.json",n="aiws-template/1";class r extends Error{constructor(e){super(e.filter((e=>"error"===e.severity)).map((e=>`${e.file?`${e.file}: `:""}${e.message}`)).join("; ")||"invalid control source"),this.name="AiwsSourceError",this.diagnostics=e}}const a=new TextEncoder,c=new TextDecoder;function l(e,t){return`${e.replace(/\/+$/,"")}/${t}`}function d(e){return e.replace(/[/\\\u0000-\u001f]/g," ").replace(/^\.+/,"").trim().slice(0,80)||"Workspace"}async function f(e){const t=await crypto.subtle.digest("SHA-256",e);return Array.from(new Uint8Array(t),(e=>e.toString(16).padStart(2,"0"))).join("")}async function p(e){const t=[];for(const[o,s]of e)t.push([o,await f(s)]);return t.sort(((e,t)=>e[0]<t[0]?-1:e[0]>t[0]?1:0)),`sha256:${await f(a.encode(JSON.stringify(t)))}`}function m(e){return JSON.stringify([...e].sort(((e,t)=>e.name.localeCompare(t.name))).map((e=>[e.name,e.obj_id??e.etag??""])))}const u=4194304;function h(e){let t="";for(let o=0;o<e.length;o+=32768)t+=String.fromCharCode(...e.subarray(o,o+32768));return btoa(t)}async function y(e,t,o=[]){let s=e.reduce(((e,t)=>e+t.bytes.length),0);const i=new Map;if(s>u){if(!t)throw new r([{file:"",severity:"error",message:"a control's inline files are limited to 4194304 bytes per build"}]);for(const o of[...e].sort(((e,t)=>t.bytes.length-e.bytes.length))){if(s<=u)break;i.set(o.name,await t(o.name,o.bytes)),s-=o.bytes.length}}const n=[...o];for(const r of e){const e=i.get(r.name);n.push(e?{name:r.name,obj_id:e}:{name:r.name,base64:h(r.bytes)})}return n.sort(((e,t)=>e.name<t.name?-1:e.name>t.name?1:0))}async function g(e,t,o){var s;const i=[],n=[];for(const a of t)if(null==(s=a.obj_id)?void 0:s.startsWith("cyfile:"))i.push({name:a.name,obj_id:a.obj_id});else{if(!a.node_id)throw new r([{file:a.name,severity:"error",message:"the file service did not name this file"}]);n.push({name:a.name,bytes:new Uint8Array(await(await e.readFile(a.node_id)).arrayBuffer())})}return y(n,o,i)}const b=["manifest_version","ident","kind","title","description","host_api","accepts","allow_no_source","default_size","config_schema","bindings","entry","assets","catalog","agent","deps","events","actions","on_bind","on_init_control"],v=["type","enum","default","required","title","description","minimum","maximum","minLength","maxLength","properties","items"],$=/^[a-z0-9][a-z0-9._-]{0,63}$/,_=/^did:[a-z0-9]+:[^/#\s]+$/,w=/^[a-z][a-z0-9_]{0,31}$/,k=/^did:[a-z0-9]+:[^/#\s]+#[a-z0-9][a-z0-9._-]{0,63}$/,j="needs manifest_version 2 (raise it in component.json)",x="needs manifest_version 3 (raise it in component.json)",S="needs manifest_version 4 (raise it in component.json)",O="needs manifest_version 5 (raise it in component.json)",A=["string","number","boolean","object","entity"],N=["text","value","metric","bar","list","badge"],E=["kind","text","label","bind","by","format","limit"],I=["open_source","activate_editor","open_definition"],z=["text","number","select","boolean","color"];function J(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function q(e){return e.length>0&&a.encode(e).length<=255&&!e.includes("\0")&&e.split("/").every((e=>e.length>0&&!e.startsWith(".")))}function T(e){const t=J(e)?e.properties:void 0;return J(t)?t:{}}function C(e,t,o,s){for(const i of e.matchAll(/\{\{([^}]*)\}\}/g)){const e=i[1].trim();e.startsWith("config.")?e.slice(7)in o||s(`${t}: {{${e}}} names no property of config_schema`):s(`${t}: only {{config.<key>}} may be used here`)}}function W(e,t,o){if(e&&"object"==typeof e&&!Array.isArray(e))for(const[s,i]of Object.entries(e))if(v.includes(s)){if("properties"===s&&i&&"object"==typeof i)for(const[e,s]of Object.entries(i))W(s,`${t}/properties/${e}`,o);"items"===s&&W(i,`${t}/items`,o)}else o.push(`${t}/${s}: keyword ${s} is outside the supported subset`);else o.push(`${t}: a schema is an object`)}function D(e,t={},o="declarative.json"){const s=[],i=(e,t)=>s.push({file:o,severity:"error",message:e,...t?{code:t}:{}}),n=e=>s.push({file:o,severity:"warning",message:e});let r;try{const t=JSON.parse(e);if(!J(t))return i("a declarative definition is a JSON object"),s;r=t}catch(f){return i(f instanceof Error?f.message:String(f)),s}const a=J(t.bindings)?t.bindings:{},c=T(t.configSchema),l=(e,t)=>{if("string"==typeof e)C(e,t,c,i);else if(Array.isArray(e))e.forEach(((e,o)=>l(e,`${t}[${o}]`)));else if(J(e))for(const[o,s]of Object.entries(e))l(s,`${t}.${o}`)},d=(e,o)=>{void 0!==e&&(Array.isArray(e)?e.forEach(((e,s)=>{const r=`${o}[${s}]`;if(J(e))if("button"!==e.kind){"string"==typeof e.kind&&N.includes(e.kind)||i(`${r}.kind ${JSON.stringify(e.kind)}: one of ${[...N,"button"].join(", ")}`);for(const t of Object.keys(e))E.includes(t)||n(`${r}: key ${t} is ignored by the interpreter`);if(void 0===e.format||["text","number","percent","currency"].includes(e.format)||i(`${r}.format ${JSON.stringify(e.format)}: text, number, percent or currency`),"string"==typeof e.bind&&e.bind.includes(".")){const t=e.bind.slice(0,e.bind.indexOf("."));"props"===t||t in a||n(`${r}.bind ${JSON.stringify(e.bind)}: ${t} is not a declared binding, so it reads the field ${JSON.stringify(e.bind)} of the main source`)}}else((e,o)=>{void 0!==t.manifestVersion&&t.manifestVersion<3&&i(`${o}: a button ${x}`);for(const t of Object.keys(e))["kind","label","emit","params"].includes(t)||n(`${o}: key ${t} is ignored by the interpreter`);"string"==typeof e.label&&e.label||i(`${o}.label: the button's text (required)`),"string"==typeof e.emit&&e.emit?t.events&&!t.events.includes(e.emit)&&i(`${o}.emit ${e.emit}: not an event of component.json`,"EVENT_UNDECLARED"):i(`${o}.emit: the event the button raises (required)`),void 0!==e.params&&(J(e.params)?l(e.params,`${o}.params`):i(`${o}.params must be an object`))})(e,r);else i(`${r} must be an object`)})):i(`${o} must be an array`))};for(const[p,m]of Object.entries(r))"layout"===p?"stack"!==m&&"row"!==m&&i("layout: stack or row"):"items"===p?d(m,"items"):"view"===p?d(J(m)?m.items:void 0,"view.items"):"accent"===p?"string"!=typeof m&&i("accent must be a colour string"):"actions"===p?(Array.isArray(m)?m:[]).forEach(((e,t)=>{const o=J(e)?e:{};"string"==typeof o.command&&I.includes(o.command)||i(`actions[${t}].command: one of ${I.join(", ")}`),"string"==typeof o.id&&"string"==typeof o.label||i(`actions[${t}] needs id and label`)})):"inspector"===p?(Array.isArray(m)?m:[]).forEach(((e,t)=>{const o=J(e)?e:{};"string"==typeof o.kind&&z.includes(o.kind)||i(`inspector[${t}].kind: one of ${z.join(", ")}`),"string"==typeof o.key&&"string"==typeof o.label||i(`inspector[${t}] needs key and label`)})):n(`key ${p} is not part of the declarative vocabulary`);return void 0===r.items&&void 0===r.view&&n("no items: the control draws nothing"),s}function B(e,t,s=o,i={}){const n=[],r=(e,t)=>n.push({file:s,severity:"error",message:e,...t?{code:t}:{}});let c;try{const t=JSON.parse(e);if(!t||"object"!=typeof t||Array.isArray(t))return r("a composition is a JSON object { layout, slots, chrome?, events? }"),n;c=t}catch(g){return r(g instanceof Error?g.message:String(g)),n}const l=T(t),d=(e,t)=>C(e,t,l,r),f=(e,t,o)=>{"number"==typeof e&&e>=0&&e<=o||("string"==typeof e&&/^\s*\{\{.*\}\}\s*$/.test(e)?d(e,t):r(`${t}: a number in [0, ${o}] or {{config.<key>}}`))},p=void 0!==i.manifestVersion&&i.manifestVersion<4;for(const o of Object.keys(c))["layout","slots","chrome","events","projections","media"].includes(o)?"projections"!==o&&"media"!==o||!p||r(`${o} ${S}`):r(`unknown key ${o} (a composition says layout, slots, chrome, events, projections and media)`);const m=c.layout;let u="stack";if(m&&"object"==typeof m){"stack"===m.algorithm||"fixed"===m.algorithm||"grid"===m.algorithm?u=m.algorithm:r(`layout.algorithm ${JSON.stringify(m.algorithm)}: stack, fixed or grid (the algorithms the host ships)`);for(const[e,t]of Object.entries(m))if("algorithm"!==e)if("direction"!==e&&"spacing"!==e||"stack"===u)if("columns"!==e&&"gap"!==e||"grid"===u)if("direction"===e)"column"!==t&&"row"!==t&&r("layout.direction: column or row");else if("spacing"===e)f(t,"layout.spacing",2e3);else if("columns"===e)(!Number.isInteger(t)||t<1||t>12)&&r("layout.columns: an integer in [1, 12]");else if("gap"===e)f(t,"layout.gap",2e3);else if("padding"===e)if(t&&"object"==typeof t&&!Array.isArray(t))for(const[o,s]of Object.entries(t))["t","r","b","l"].includes(o)||r(`layout.padding.${o}: t, r, b or l`),f(s,`layout.padding.${o}`,2e3);else f(t,"layout.padding",2e3);else r(`layout: unknown key ${e}`);else r(`layout.${e} belongs to the grid layout`);else r(`layout.${e} belongs to the stack layout`);"grid"===u&&void 0===m.columns&&r("layout.columns (1…12) required: the cells of a grid row")}else r("layout { algorithm: stack | fixed | grid } required");const h=c.slots&&"object"==typeof c.slots&&!Array.isArray(c.slots)?c.slots:null;if(h){Object.keys(h).length>16&&r("at most 16 slots");for(const[e,t]of Object.entries(h)){const o=`slots.${e}`;if(w.test(e)||r(`${o}: a slot name is [a-z][a-z0-9_]{0,31}`),!t||"object"!=typeof t||Array.isArray(t)){r(`${o} must be an object`);continue}const s=t;for(const[e,t]of Object.entries(s))if("accepts"===e){if(!Array.isArray(t)||0===t.length||t.length>32){r(`${o}.accepts: 1…32 entries (cell:<ident>, a view type, container)`);continue}for(const e of t)"string"==typeof e&&e.startsWith("cell:")?(!k.test(e.slice(5))||a.encode(e.slice(5)).length>128)&&r(`${o}.accepts ${JSON.stringify(e)}: cell:<author_did>#<name>`):"container"===e||"string"==typeof e&&$.test(e)||r(`${o}.accepts ${JSON.stringify(e)}: cell:<ident>, a view type or container`)}else if("min"===e)(!Number.isInteger(t)||t<0||t>64)&&r(`${o}.min: an integer in [0, 64]`);else if("max"===e)(!Number.isInteger(t)||t<1||t>1e3)&&r(`${o}.max: an integer in [1, 1000]`);else if("placement"===e)"stack"!==t&&"top"!==t&&"bottom"!==t&&"free"!==t?r(`${o}.placement: stack, top, bottom or free`):"fixed"===u&&"free"!==t?r(`${o}.placement: a fixed layout keeps every child where it is (free)`):"grid"===u&&"stack"!==t&&r(`${o}.placement: a grid fills its cells with the slots' children in slot order (stack)`);else if("title"===e)("string"!=typeof t||t.length>256)&&r(`${o}.title: at most 256 characters`);else if("visible"===e){if(p){r(`${o}.visible ${S}`);continue}const e=t;!J(e)||"first_open"!==e.from||Object.keys(e).some((e=>"from"!==e&&"for_ms"!==e))?r(`${o}.visible: { from: "first_open", for_ms }`):"string"==typeof e.for_ms?d(e.for_ms,`${o}.visible.for_ms`):(!Number.isInteger(e.for_ms)||e.for_ms<1||e.for_ms>316224e5)&&r(`${o}.visible.for_ms: milliseconds (≤ a year) or {{config.<key>}}`)}else r(`${o}: unknown key ${e}`);Number.isInteger(s.min)&&Number.isInteger(s.max)&&s.min>s.max&&r(`${o}: min exceeds max`)}}else r("slots { <name>: { accepts?, min?, max?, placement? } } required");const y=c.chrome;if(void 0!==y)if(!y||"object"!=typeof y||Array.isArray(y))r("chrome must be an object");else for(const[o,a]of Object.entries(y)){const e=`chrome.${o}`;if("background"===o||"border"===o)"string"==typeof a&&a.length<=64?d(a,e):r(`${e}: a colour (≤ 64 characters) or {{config.<key>}}`);else if("radius"===o)f(a,e,200);else if("empty"===o)"string"==typeof a&&a.length<=1e3?d(a,e):r(`${e}: a text of at most 1000 characters`);else if("title"===o){const t=a;if(!t||"object"!=typeof t||Array.isArray(t)){r(`${e}: { text, slot? }`);continue}for(const[e,o]of Object.entries(t))"text"===e?"string"==typeof o&&o.length<=256?d(o,"chrome.title.text"):r("chrome.title.text: at most 256 characters"):"slot"===e?"string"==typeof o&&h&&o in h||r(`chrome.title.slot ${JSON.stringify(o)}: a slot of this composition`):r(`chrome.title: unknown key ${e}`);"string"!=typeof t.text&&r("chrome.title.text required")}else r(`chrome: unknown key ${o} (background, radius, border, title, empty)`)}if(void 0!==c.events)if(void 0!==i.manifestVersion&&i.manifestVersion<3&&r(`events ${x}`),J(c.events)){Object.keys(c.events).length>16&&r("events: at most 16");for(const[e,t]of Object.entries(c.events)){const o=`events.${e}`;if(w.test(e)||r(`${o}: an event name is [a-z][a-z0-9_]{0,31}`),!J(t)){r(`${o} must be an object { from: { slot, event }, title?, description? }`);continue}for(const[e,i]of Object.entries(t))if("title"===e)("string"!=typeof i||i.length>256)&&r(`${o}.title: at most 256 characters`);else if("description"===e)("string"!=typeof i||i.length>4e3)&&r(`${o}.description: at most 4000 characters`);else if("on"===e){const e=Array.isArray(i)?i:[i];p?r(`${o}.on ${S}`):(0===e.length||e.length>4||e.some((e=>!J(e)||!["write","wish","open","notify"].includes(String(e.kind)))))&&r(`${o}.on: a handler (write, wish, open, notify) or 1…4 of them`)}else"from"!==e&&r(`${o}: unknown key ${e} (from, title, description, on)`);const s=t.from;if(!J(s)){r(`${o}.from { slot, event } required: the child event it re-raises`);continue}if(void 0!==s.projection){if(p){r(`${o}.from.projection ${S}`);continue}const e=J(c.projections)?c.projections:{};"string"==typeof s.projection&&s.projection in e||r(`${o}.from.projection ${JSON.stringify(s.projection)}: a projection of this composition`),void 0===s.role||"string"==typeof s.role&&w.test(s.role)||r(`${o}.from.role: a role name of its template`);for(const t of Object.keys(s))"projection"!==t&&"role"!==t&&r(`${o}.from: unknown key ${t} (projection, role)`);continue}for(const e of Object.keys(s))"slot"!==e&&"event"!==e&&r(`${o}.from: unknown key ${e} (slot, event)`);const n="string"==typeof s.event&&w.test(s.event)?s.event:void 0;n||r(`${o}.from.event: an event name [a-z][a-z0-9_]{0,31}`);const a="string"==typeof s.slot&&h?h[s.slot]:void 0;if(!J(a)){r(`${o}.from.slot ${JSON.stringify(s.slot)}: a slot of this composition`);continue}if(!n)continue;const l=(Array.isArray(a.accepts)?a.accepts:[]).filter((e=>"string"==typeof e&&e.startsWith("cell:"))).map((e=>e.slice(5)));if(0===l.length){r(`${o}: slot ${s.slot} accepts no cell:<ident>, so no control there declares ${n}`,"EVENT_UNDECLARED");continue}l.map((e=>{var t;return null==(t=i.cellEvents)?void 0:t.call(i,e)})).every((e=>void 0!==e&&!e.includes(n)))&&r(`${o}: no control slot ${s.slot} accepts (${l.join(", ")}) declares the event ${n}`,"EVENT_UNDECLARED")}}else r("events must be an object { <name>: { from: { slot, event }, title?, description? } }");if(void 0!==c.projections&&!p)if(!J(c.projections)||Object.keys(c.projections).length>8)r("projections: at most 8 of name → { source, template, layout }");else for(const[o,a]of Object.entries(c.projections)){const e=`projections.${o}`;if(w.test(o)||r(`${e}: a projection name is [a-z][a-z0-9_]{0,31}`),!J(a)){r(`${e} must be an object`);continue}for(const o of Object.keys(a))["source","mark","template","layout","placement","max_items"].includes(o)||r(`${e}: unknown key ${o} (source, mark, template, layout, placement, max_items)`);const t=a.source,s=J(t)?t.kind:void 0;(!J(t)||!["records","members","counts","viewer"].includes(String(s))||"viewer"!==s&&"string"!=typeof t.binding||"counts"===s&&"string"!=typeof t.field)&&r(`${e}.source: { kind: records | members | counts | viewer, binding (a binding name), field? (counts) }`);const i=J(a.template)&&Array.isArray(a.template.nodes)?a.template.nodes:null;!i||0===i.length||i.length>32?r(`${e}.template: { nodes: [1…32 of { id, view: label | shape | asset, box?, config?, when?, role? }] }`):i.forEach(((t,o)=>{J(t)&&"string"==typeof t.id&&w.test(t.id)?["label","shape","asset"].includes(String(t.view))||r(`${e}.template.nodes[${o}].view: label, shape or asset`):r(`${e}.template.nodes[${o}].id: a name [a-z][a-z0-9_]{0,31}`)}));const n=a.layout;!J(n)||"list"!==n.algorithm&&"grid"!==n.algorithm||!J(n.item)||void 0===n.item.h?r(`${e}.layout: { algorithm: list | grid, columns? (grid), gap?, item: { w?, h } }`):"grid"===n.algorithm&&void 0===n.columns&&r(`${e}.layout.columns required (grid)`),void 0===a.placement||["top","stack","bottom"].includes(String(a.placement))||r(`${e}.placement: top, stack or bottom`)}if(void 0!==c.media&&!p){const e=c.media;(!J(e)||"string"!=typeof e.slot||!h||!(e.slot in h)||"string"!=typeof e.anchor||Object.keys(l).length>0&&!(e.anchor in l))&&r("media: { slot (a slot of this composition), anchor (a config property), loop? (a config property) }")}return n}function L(o,s,i,n){const r=[],c=t,l=e=>r.push({file:c,severity:"error",message:e});let d;try{const e=JSON.parse(o);if(!e||"object"!=typeof e||Array.isArray(e))return l("must be a JSON object"),r;d=e}catch(E){return l(E instanceof Error?E.message:String(E)),r}for(const e of Object.keys(d))b.includes(e)||l(`unknown key ${e}`);const f=d.manifest_version,p="number"==typeof f&&Number.isInteger(f)&&f>=1?f:0;void 0!==d.actions&&(p>0&&p<4?l(`actions ${S}`):!Array.isArray(d.actions)||d.actions.length>16?l("actions: at most 16 of { id, title, icon?, modes?, needs?, run }"):d.actions.forEach(((e,t)=>{if(J(e)&&"string"==typeof e.id&&w.test(e.id)&&"string"==typeof e.title&&e.title){const o=Array.isArray(e.run)?e.run:[e.run];(0===o.length||o.length>4||o.some((e=>!J(e)||!["write","wish","open","notify","config","forward"].includes(String(e.kind)))))&&l(`actions[${t}].run: a handler (write, wish, open, notify, config, forward) or 1…4 of them`)}else l(`actions[${t}]: { id, title, run } (id a name [a-z][a-z0-9_]{0,31})`)}))),p?p>5&&l(`manifest_version ${f} is newer than this client reads (5)`):l("manifest_version (1…5) required");const m=p>0&&p<3,u=d.ident;let h="";u&&"object"==typeof u?("string"==typeof u.author_did&&_.test(u.author_did)||l("ident.author_did must be a DID (did:<method>:<id>)"),"string"==typeof u.name&&$.test(u.name)||l("ident.name must be [a-z0-9][a-z0-9._-]{0,63}"),"string"==typeof u.author_did&&"string"==typeof u.name&&(h=`${u.author_did}#${u.name}`,a.encode(h).length>128&&l("an identity is at most 128 bytes"))):l("ident { author_did, name } required");const y="composite"===d.kind;if("declarative"===d.kind||"html"===d.kind||y||l("kind must be declarative, html or composite"),y&&1===p&&l(`kind composite ${j}`),y)for(const e of["accepts","allow_no_source"])void 0!==d[e]&&l(`${e}: a composite is a container of Blocks, not a Cell showing data`);if(("string"!=typeof d.title||!d.title||d.title.length>256)&&l("title: 1…256 characters"),void 0!==d.config_schema){const e=[];W(d.config_schema,"config_schema",e),e.forEach(l)}if(void 0!==d.bindings)if(d.bindings&&"object"==typeof d.bindings)for(const[e,t]of Object.entries(d.bindings))if(w.test(e)&&"props"!==e||l(`binding name ${e}: [a-z][a-z0-9_]{0,31}, not props`),J(t)){for(const o of Object.keys(t))["accepts","required","many","schema_id","title","description"].includes(o)||l(`binding ${e}: unknown key ${o}`);void 0!==t.many&&"boolean"!=typeof t.many&&l(`binding ${e}.many: true or false`),void 0!==t.schema_id&&("string"!=typeof t.schema_id||!t.schema_id||t.schema_id.length>128)&&l(`binding ${e}.schema_id: a schema id such as buckyos.todo@1`)}else l(`binding ${e} must be an object`);else l("bindings must be an object");if(void 0!==d.on_bind||void 0!==d.on_init_control)if(p>0&&p<5)l(`on_bind / on_init_control ${O}`);else if("html"===d.kind){for(const[e,t]of[["on_bind","bind"],["on_init_control","init_control"]])void 0!==d[e]&&"script"!==d[e]&&l(`${e}: an HTML control writes "script" (its behavior.js handles aiws.on('${t}'))`);"number"==typeof d.host_api&&d.host_api>=5||l("on_bind / on_init_control \"script\": aiws.on('bind') / aiws.on('init_control') need host_api 5")}else if("composite"!==d.kind)l('on_bind / on_init_control: declared steps are for a composite, "script" for an HTML control');else{const t=Array.isArray(d.actions)?d.actions.filter(J).map((e=>String(e.id))):[];e.checkBindSteps(d.on_bind,d.on_init_control,J(d.bindings)?d.bindings:{},t).forEach(l)}if(void 0!==d.deps)if(!Array.isArray(d.deps)||d.deps.length>32)l("deps: at most 32 identities <author_did>#<name>");else if(d.deps.length>0&&1===p)l(`deps ${j}`);else{const e=new Set;for(const t of d.deps)"string"==typeof t&&k.test(t)?t===h?l("deps: a control cannot depend on itself"):e.has(t)&&l(`deps lists ${t} twice`):l(`deps: ${JSON.stringify(t)} is not an identity <author_did>#<name>`),e.add(String(t))}let g=[];if(void 0!==d.events){if(y)l("events: a composite declares its events in composition.json (events.<name>.from re-raises an event of a child)");else if(m)l(`events ${x}`);else{const e=[];!function(e,t){if(J(e)){Object.keys(e).length>16&&t.push("events: at most 16");for(const[o,s]of Object.entries(e)){const e=`events.${o}`;if(w.test(o)||t.push(`${e}: an event name is [a-z][a-z0-9_]{0,31}`),J(s)){for(const[o,i]of Object.entries(s))"title"===o?("string"!=typeof i||i.length>256)&&t.push(`${e}.title: at most 256 characters`):"description"===o?("string"!=typeof i||i.length>4e3)&&t.push(`${e}.description: at most 4000 characters`):"params"!==o&&t.push(`${e}: unknown key ${o} (title, description, params)`);if(void 0!==s.params)if(J(s.params)){Object.keys(s.params).length>16&&t.push(`${e}.params: at most 16`);for(const[o,i]of Object.entries(s.params)){const s=`${e}.params.${o}`;if(w.test(o)||t.push(`${s}: a param name is [a-z][a-z0-9_]{0,31}`),J(i)){for(const[e,o]of Object.entries(i))"type"===e?"string"==typeof o&&A.includes(o)||t.push(`${s}.type: ${A.join(", ")}`):"required"===e?"boolean"!=typeof o&&t.push(`${s}.required must be a boolean`):"description"===e?("string"!=typeof o||o.length>1e3)&&t.push(`${s}.description: at most 1000 characters`):t.push(`${s}: unknown key ${e} (type, required, description)`);void 0===i.type&&t.push(`${s}.type required`)}else t.push(`${s} must be an object { type, required?, description? }`)}}else t.push(`${e}.params must be an object { <param>: { type, required?, description? } }`)}else t.push(`${e} must be an object { title?, description?, params? }`)}}else t.push("events must be an object { <name>: { title?, description?, params? } }")}(d.events,e),e.forEach(l)}!y&&J(d.events)&&(g=Object.keys(d.events))}const v=e=>"string"==typeof e&&s.includes(e),N=new Set([c]);if("html"===d.kind){const e=d.entry;if(e&&"object"==typeof e&&"string"==typeof e.html)for(const[t,o]of Object.entries(e))v(o)?N.add(String(o)):l(`entry.${t} ${JSON.stringify(o)} is not in the directory`);else l("entry must be { html, css?, js? }");void 0===d.host_api||[2,3,4,5,6].includes(d.host_api)?(5===d.host_api||6===d.host_api)&&p<5?l(`host_api ${d.host_api} ${O}`):4===d.host_api&&p<4?l(`host_api 4 ${S}`):3===d.host_api&&m&&l(`host_api 3 ${x}`):l("host_api: the HTML Block host speaks API 2, 3, 4, 5 and 6"),g.length>0&&!("number"==typeof d.host_api&&d.host_api>=3)&&r.push({file:c,severity:"warning",message:"events: an HTML control raises them with aiws.emit, which is host API 3 (set host_api to 3 or later)"})}else if("declarative"===d.kind||y){if(v(d.entry)){N.add(String(d.entry));const e=null==i?void 0:i(String(d.entry)),t=p||void 0;void 0!==e&&y?r.push(...B(e,d.config_schema,String(d.entry),{manifestVersion:t,cellEvents:n})):void 0!==e&&r.push(...D(e,{bindings:d.bindings,events:g,configSchema:d.config_schema,manifestVersion:t},String(d.entry)))}else l(`entry ${JSON.stringify(d.entry)} is not in the directory`);y&&void 0!==d.host_api&&l("host_api: a composite runs no code of its own (its layout and chrome are the host's)"),y||void 0===d.host_api||1===d.host_api||l("host_api: the declarative interpreter is version 1")}for(const e of Array.isArray(d.assets)?d.assets:[])v(e)?N.add(String(e)):l(`asset ${JSON.stringify(e)} is not in the directory`);void 0!==d.agent&&(v(d.agent)?N.add(String(d.agent)):l(`agent ${JSON.stringify(d.agent)} is not in the directory`));for(const e of s)q(e)?N.has(e)||r.push({file:e,severity:"warning",message:"not named by component.json: kept in the source snapshot only"}):r.push({file:e,severity:"error",message:"a file of a source directory: a relative path whose parts do not start with '.'"});return r}function M(e){if(!e||"object"!=typeof e)throw new r([{file:s,severity:"error",message:"must be a JSON object"}]);const t=e,o=t.manifest_version;if("number"!=typeof o||o<1)throw new r([{file:s,severity:"error",message:"manifest_version required"}]);if(o>5)throw new r([{file:s,severity:"error",message:`manifest_version ${o} needs a newer client (this one reads 5)`}]);if("aiws"!==t.purpose)throw new r([{file:s,severity:"error",message:"purpose must be aiws"}]);if(!Array.isArray(t.controls))throw new r([{file:s,severity:"error",message:"controls must be an array"}]);return{manifest_version:o,purpose:"aiws",host_api:t.host_api??{},controls:t.controls,workspace_templates:Array.isArray(t.workspace_templates)?t.workspace_templates:[]}}const F=/^[a-z0-9][a-z0-9-]{0,63}$/;function V(e){return`templates/${e}/`}async function R(e,t){const o=V(t),s=[];for(const[i,n]of e)i.startsWith(o)&&s.push([i.slice(o.length),n]);return p(s)}function P(e,t){if(!J(e))return["a template is an object { id, title, snapshot, digest, requires, description?, params?, reset? }"];const o=[];for(const i of Object.keys(e))["id","title","description","snapshot","digest","requires","params","reset"].includes(i)||o.push(`unknown key ${i}`);"string"==typeof e.id&&F.test(e.id)?e.snapshot!==`${V(e.id)}snapshot.json`&&o.push(`snapshot must be ${V(e.id)}snapshot.json`):o.push("id: [a-z0-9][a-z0-9-]{0,63}"),("string"!=typeof e.title||!e.title||e.title.length>256)&&o.push("title: 1…256 characters"),void 0!==e.description&&("string"!=typeof e.description||e.description.length>4e3)&&o.push("description: at most 4000 characters"),"string"==typeof e.digest&&/^sha256:[0-9a-f]{64}$/.test(e.digest)||o.push("digest: sha256:<64 hex digits>");const s=e.requires;if(J(s)){for(const e of Object.keys(s))"host_api"!==e&&"controls"!==e&&o.push(`requires: unknown key ${e}`);if(void 0!==s.host_api)if(J(s.host_api))for(const[e,t]of Object.entries(s.host_api))("html"!==e&&"declarative"!==e||!Number.isInteger(t)||t<1)&&o.push(`requires.host_api.${e}: html or declarative, a positive integer`);else o.push("requires.host_api must be an object { html?, declarative? }");if(!Array.isArray(s.controls)||s.controls.length>256)o.push("requires.controls: at most 256 identities");else{const e=new Set;for(const i of s.controls)"string"==typeof i&&t.has(i)?e.has(i)&&o.push(`requires.controls lists ${i} twice`):o.push(`requires.controls: ${JSON.stringify(i)} is not a control of this manifest`),e.add(i)}}else o.push("requires { host_api?, controls } required");if(void 0!==e.params)if(!J(e.params)||Object.keys(e.params).length>32)o.push("params: an object of at most 32 { type, title?, default? }");else for(const[i,n]of Object.entries(e.params)){const e=`params.${i}`;if(w.test(i)||o.push(`${e}: a param name is [a-z][a-z0-9_]{0,31}`),J(n)){for(const[t,s]of Object.entries(n))"type"===t?"string"!==s&&"number"!==s&&"boolean"!==s&&o.push(`${e}.type: string, number or boolean`):"title"===t?("string"!=typeof s||s.length>256)&&o.push(`${e}.title: at most 256 characters`):"default"===t?["string","number","boolean"].includes(typeof s)||o.push(`${e}.default: a string, number or boolean`):o.push(`${e}: unknown key ${t} (type, title, default)`);void 0===n.type&&o.push(`${e}.type required`)}else o.push(`${e} must be an object { type, title?, default? }`)}if(void 0!==e.reset){const t=J(e.reset)?e.reset.tables:void 0;!J(e.reset)||Object.keys(e.reset).some((e=>"tables"!==e))?o.push("reset: { tables }"):void 0!==t&&(!Array.isArray(t)||t.length>64||new Set(t).size!==t.length||t.some((e=>"string"!=typeof e||!/^[a-z0-9][a-z0-9_-]{0,63}$/.test(e))))&&o.push("reset.tables: at most 64 distinct table ids")}return o}async function U(e,t,o){const s=/[*?[\]\\]/.test(o)?void 0:o;return(await e.list("string"==typeof t?t:{ref:t},{limit:s?10:1e3,...s?{filter:{name_glob:s}}:{}},["base","ident"])).entries.find((e=>e.name===o))}async function G(e,t){const o=t.split("/").filter(Boolean);if(0===o.length)throw new Error(`not a folder path: ${t}`);let s=(await e.stat(`/${o[0]}`)).ref;for(const i of o.slice(1)){const o=await U(e,s,i);if(o&&"dir"!==o.target.kind)throw new r([{file:i,severity:"error",message:`${i} in ${t} is not a folder`}]);s=o?o.target.ref:(await e.mkdir({ref:s},i)).ref}return s}async function H(e,t){const o=t.split("/").filter(Boolean);if(0===o.length)return null;let s=(await e.stat(`/${o[0]}`)).ref;for(const i of o.slice(1)){const t=await U(e,s,i);if(!t||"dir"!==t.target.kind)return null;s=t.target.ref}return s}async function K(e,o){const s=await H(e,o);return null!==s&&void 0!==await U(e,s,t)}async function X(e,t,o,s){const i="string"==typeof t?await G(e,t):t;await e.uploadFile(i,o,s,{overwrite:!0})}const Y=e=>new Promise((t=>setTimeout(t,e)));async function Q(e,t){const o=[],s=[],i=async(t,n,r)=>{var a,c,l;let d;do{const f=await e.list("string"==typeof t?t:{ref:t},{limit:500,...d?{cursor:d}:{}},["base","ident"]);for(const e of f.entries){if(e.name.startsWith("."))continue;const t=`${n}${e.name}`;if("dir"===e.target.kind){r>=8?s.push({file:t,severity:"error",message:"sub-folders nest at most 8 levels"}):await i(e.target.ref,`${t}/`,r+1);continue}if("file"!==e.target.kind){s.push({file:t,severity:"error",message:"only files and folders belong to a control source"});continue}const d=e.target.ref,f="object"===d.type?d.obj_id:"string"==typeof(null==(a=e.target.attrs)?void 0:a.obj_id)?e.target.attrs.obj_id:void 0;o.push({name:t,...f?{obj_id:f}:{},..."live"===d.type?{node_id:d.node_id}:{},..."string"==typeof(null==(c=e.target.attrs)?void 0:c.etag)?{etag:e.target.attrs.etag}:{},..."number"==typeof(null==(l=e.target.attrs)?void 0:l.size)?{size:e.target.attrs.size}:{}})}d=f.truncated?f.next_cursor:void 0}while(d)};if(await i(t,"",0),0===o.length&&s.push({file:"",severity:"error",message:`${t} holds no files`}),o.length>64&&s.push({file:"",severity:"error",message:"a control holds at most 64 files"}),s.some((e=>"error"===e.severity)))throw new r(s);return o.sort(((e,t)=>e.name<t.name?-1:e.name>t.name?1:0))}async function Z(e,t,o,s){const i=o.lastIndexOf("/");await X(e,i<0?t:l(t,o.slice(0,i)),i<0?o:o.slice(i+1),s)}async function ee(e,t){const o=[];for(const s of t){if(!s.node_id)throw new r([{file:s.name,severity:"error",message:"the file service did not name this file"}]);o.push([s.name,new Uint8Array(await(await e.readFile(s.node_id)).arrayBuffer())])}return p(o)}async function te(e,t){try{const o=await U(e,t,i),s="live"===(null==o?void 0:o.target.ref.type)?o.target.ref.node_id:void 0;if(!s)return null;const n=await e.readFile(s);return await n.json()}catch{return null}}async function oe(e,t,o){await X(e,t,i,a.encode(`${JSON.stringify(o,null,2)}\n`))}exports.AIWS_BUILD_STATE_FILE=i,exports.AIWS_COMPONENT_FILE=t,exports.AIWS_COMPOSITION_FILE=o,exports.AIWS_DECLARATIVE_API_VERSION=1,exports.AIWS_HTML_API_VERSION=6,exports.AIWS_MANIFEST_FILE=s,exports.AIWS_MANIFEST_VERSION=5,exports.AIWS_MAX_INLINE_BYTES=u,exports.AIWS_MAX_SOURCE_FILES=64,exports.AIWS_TEMPLATE_FORMAT=n,exports.AiwsSourceError=r,exports.aiwsContentDigest=p,exports.aiwsTemplateDigest=R,exports.buildControl=async function(e,t,o,s,i={}){const n=await Q(t,s),r=await te(t,s),a=r&&r.workspace_id===o?{def_rev:r.def_rev,dir_rev:r.dir_rev}:void 0,c=await e.extBuild(o,{files:await g(t,n,i.upload),...i.folderId?{folder_id:i.folderId}:{},...a?{expect:a}:{},...i.force?{force:!0}:{},...i.dryRun?{dry_run:!0}:{},...i.migration?{migration:i.migration}:{}});return i.dryRun||"string"!=typeof c.def_entity_id||"number"!=typeof c.def_rev||await oe(t,s,{workspace_id:o,def_entity_id:c.def_entity_id,def_rev:c.def_rev,dir_rev:Number(c.dir_rev??0),ident:String(c.ident??""),at:(new Date).toISOString()}),{...c,files:n}},exports.buildFiles=g,exports.checkComponent=L,exports.checkComposition=B,exports.checkDeclarative=D,exports.collectSources=Q,exports.compatManifest=M,exports.controlSkeleton=function(e){const s=e.title??e.name;if("composite"===e.kind){const i="fixed"===e.algorithm,n=e.slots??{items:{placement:i?"free":"stack",title:"Items"}},r={layout:i?{algorithm:"fixed",padding:12}:{algorithm:"stack",direction:"column",spacing:"{{config.gap}}",padding:12},slots:n,chrome:{background:"{{config.background}}",radius:12,title:{text:"{{config.title}}"},empty:"Drop Blocks here"}},a={manifest_version:5,ident:{author_did:e.authorDid,name:e.name},kind:"composite",title:s,description:`${s}: a panel of Blocks`,default_size:{w:320,h:360},config_schema:{type:"object",properties:{title:{type:"string",title:"Title",default:s},background:{type:"string",title:"Background",default:"#f6f7fb"},gap:{type:"integer",title:"Gap (px)",default:8,minimum:0,maximum:64}}},entry:o,deps:e.deps??[],catalog:{group:"custom",description:`${s}`},agent:"AGENT.md"},c=Object.keys(n).map((e=>`\`${e}\``)).join(", ");return{[t]:`${JSON.stringify(a,null,2)}\n`,[o]:`${JSON.stringify(r,null,2)}\n`,"AGENT.md":`# ${s}\n\nA composite: an instance is a \`buckyos.container { kind: "composite", def_ref }\`; put Blocks under it with \`slot\` set to one of ${c}. Config: \`title\`, \`background\`, \`gap\`.\n`}}const i={manifest_version:5,ident:{author_did:e.authorDid,name:e.name},kind:e.kind??"declarative",title:s,description:`${s}: a control of this Workspace`,accepts:["buckyos.table-source","buckyos.record"],allow_no_source:!0,default_size:{w:260,h:140},config_schema:{type:"object",properties:{label:{type:"string",title:"Label",default:s}}},bindings:{data:{accepts:["buckyos.table-source"],title:"Data",description:"The table this control summarizes"}},catalog:{group:"custom",description:`${s}`},agent:"AGENT.md"},n=`# ${s}\n\nBind \`data\` to a table. Config: \`label\` (text).\n`;if("html"===e.kind){const e={clicked:{title:"Clicked",description:"Raised when someone clicks the button (in run mode)",params:{count:{type:"number",description:"Rows of the bound table"}}}};return{[t]:`${JSON.stringify({...i,host_api:6,events:e,entry:{html:"view.html",css:"style.css",js:"behavior.js"}},null,2)}\n`,"view.html":'<div class="card"><div class="label" id="label"></div><div class="value" id="value">—</div><button id="go" type="button">Go</button></div>\n',"style.css":".card{font:14px system-ui;padding:12px}.label{opacity:.7}.value{font-size:28px;font-weight:600}\n","behavior.js":["document.getElementById('label').textContent = (aiws.context.config || {}).label || ''","var count = 0","if (aiws.bindings.data) aiws.input('data').rows().then(function (rows) { count = rows.length; document.getElementById('value').textContent = String(count) })","// the public event of component.json: an instance binds handlers to it in its `on` (host API 3)","document.getElementById('go').addEventListener('click', function () { aiws.emit('clicked', { count: count }) })",""].join("\n"),"AGENT.md":`${n}Event: \`clicked\` (\`count\`), raised by its button; bind handlers to it in the instance's \`on\`.\n`}}return{[t]:`${JSON.stringify({...i,entry:"declarative.json"},null,2)}\n`,"declarative.json":`${JSON.stringify({layout:"stack",items:[{kind:"metric",label:s,bind:"data.count",format:"number"},{kind:"text",text:"Rows of the bound table"}]},null,2)}\n`,"AGENT.md":n}},exports.createControlSource=async function(e,o,s){const i=await G(e,o),n=await e.list({ref:i},{limit:500},["base"]).catch((()=>null));if(null==n?void 0:n.entries.some((e=>e.name===t)))throw new r([{file:t,severity:"error",message:`${o} already holds a control`}]);for(const[t,r]of Object.entries(s))await X(e,i,t,a.encode(r));return i},exports.ensureFolder=G,exports.exportBundle=async function(e,t,o,i){const n=await e.extExport(t,o,"package"),r=new Map;r.set(s,a.encode(`${JSON.stringify(n.manifest,null,2)}\n`));for(const s of n.files)r.set(s.path,void 0!==s.text?a.encode(s.text):await i(t,String(s.obj_id)));return{manifest:M(n.manifest),files:r,controls:n.controls}},exports.findFolder=H,exports.folderName=d,exports.hasControlSource=K,exports.homeControlDir=function(e,t,o){return`/home/${e}/AI Workspace/${d(t)}/controls/${o}`},exports.homeExportDir=function(e,t){return`/home/${e}/AI Workspace/exports/${t}`},exports.isSourcePath=q,exports.joinPath=l,exports.packBuildFiles=y,exports.pullControl=async function(e,t,o,s,i,n){const r=(await e.extExport(o,[s],"pull")).controls[0];await G(t,i);for(const l of r.files)await Z(t,i,l.name,void 0!==l.text?a.encode(l.text):await n(o,String(l.obj_id)));const c={workspace_id:o,def_entity_id:r.entity_id,def_rev:r.def_rev,dir_rev:r.dir_rev,ident:r.ident,at:(new Date).toISOString()};return await oe(t,i,c),{files:r.files.map((e=>e.name)),state:c}},exports.readBuildState=te,exports.slotCells=function(e){const t=new Set;for(const o of Object.values(e.slots??{}))for(const e of o.accepts??[])e.startsWith("cell:")&&t.add(e.slice(5));return[...t].sort()},exports.sourceStateKey=function(e){return`aiws:src:${e}`},exports.sourcesDigest=ee,exports.sourcesKey=m,exports.templateDir=V,exports.unbuiltChanges=async function(e,t,o,s,i){var n;if(!(await K(t,i)))return null;const r=await ee(t,await Q(t,i)),a=await e.extExport(o,[s],"pull"),c=String((null==(n=a.controls[0])?void 0:n.digest)??"");return{changed:r!==c,home:r,built:c}},exports.verifyBundle=async function(e){var o,i;const a=e.get(s);if(!a)throw new r([{file:s,severity:"error",message:"missing"}]);let l;try{l=JSON.parse(c.decode(a))}catch(g){throw new r([{file:s,severity:"error",message:String(g)}])}const d=M(l),f=[],m=d.workspace_templates;m.length>0&&d.manifest_version<3&&f.push({file:s,severity:"error",message:`Workspace templates need manifest_version 3 (raise it in ${s})`}),m.length>32&&f.push({file:s,severity:"error",message:"at most 32 Workspace templates"}),0===d.controls.length&&0===m.length&&f.push({file:s,severity:"error",message:"lists no control"});const u=new Map;for(const s of d.controls){const o="string"==typeof s.dir?e.get(`${s.dir}${t}`):void 0;try{const e=o?JSON.parse(c.decode(o)):void 0;J(e)&&u.set(s.ident,J(e.events)?Object.keys(e.events):[])}catch{}}const h=new Set;for(const n of d.controls){if("string"!=typeof n.dir||!/^controls\/[a-z0-9][a-z0-9._-]{0,70}\/$/.test(n.dir)||h.has(n.dir)){f.push({file:s,severity:"error",message:`control ${n.ident}: bad or repeated dir`});continue}h.add(n.dir);const r=[...e].filter((([e])=>e.startsWith(n.dir))).map((([e,t])=>[e.slice(n.dir.length),t]));await p(r)!==n.digest&&f.push({file:n.dir,severity:"error",message:"the files do not match the manifest digest"});const a=r.find((([e])=>e===t));if(!a){f.push({file:`${n.dir}${t}`,severity:"error",message:"missing"});continue}const l=e=>{const t=r.find((([t])=>t===e));return t?c.decode(t[1]):void 0};for(const e of L(c.decode(a[1]),r.map((([e])=>e)),l,(e=>u.get(e))))f.push({...e,file:`${n.dir}${e.file}`});try{const e=JSON.parse(c.decode(a[1]));`${null==(o=e.ident)?void 0:o.author_did}#${null==(i=e.ident)?void 0:i.name}`===n.ident&&e.kind===n.kind||f.push({file:n.dir,severity:"error",message:"ident and kind must match its component.json"}),JSON.stringify([...e.deps??[]].sort())!==JSON.stringify([...n.deps??[]].sort())&&f.push({file:n.dir,severity:"error",message:"deps must match its component.json"})}catch{}}const y=new Set(d.controls.map((e=>e.ident)));for(const t of d.controls)for(const e of t.deps??[])y.has(e)||f.push({file:s,severity:"error",message:`${t.ident} depends on ${e}, which the bundle does not carry`});for(const[t,r]of m.entries()){const o=J(r)&&"string"==typeof r.id?`template ${r.id}`:`workspace_templates[${t}]`;for(const e of P(r,y))f.push({file:s,severity:"error",message:`${o}: ${e}`});if(!J(r)||"string"!=typeof r.id||!F.test(r.id))continue;const i=V(r.id);if(h.has(i)){f.push({file:s,severity:"error",message:`${o} is listed twice`});continue}h.add(i);const a=e.get(`${i}snapshot.json`);let l;try{l=a?JSON.parse(c.decode(a)).format:void 0}catch{l=void 0}a?l!==n&&f.push({file:`${i}snapshot.json`,severity:"error",message:`not a template snapshot (format ${n})`}):f.push({file:`${i}snapshot.json`,severity:"error",message:"missing"}),await R(e,r.id)!==r.digest&&f.push({file:i,severity:"error",message:"the files do not match the template digest"})}for(const t of e.keys())t===s||[...h].some((e=>t.startsWith(e)))||f.push({file:t,severity:"error",message:"belongs to no control or template of the manifest"});return{manifest:d,diagnostics:f}},exports.watchControl=async function(e,t,o,s={}){var i,n;let r,a="",c=Promise.resolve();const l=()=>{c=c.then((async()=>{let s;try{s=await Q(e,t)}catch{return}const i=m(s);i!==a&&(a=i,await o(s))})).catch((()=>{}))};for(l();!(null==(i=s.signal)?void 0:i.aborted);){const o=await e.list(t,{limit:1},["base"]),i=e.watch({tokens:o.watch_token?[o.watch_token]:[],signal:s.signal});try{for await(const e of i)r&&clearTimeout(r),r=setTimeout(l,s.debounceMs??500)}catch{if(null==(n=s.signal)?void 0:n.aborted)break;await Y(2e3)}finally{i.close()}}r&&clearTimeout(r),await c},exports.writeBuildState=oe,exports.writeHomeFile=X,exports.writeSourceFile=Z;
|
|
2
2
|
//# sourceMappingURL=aiws_ext.cjs.map
|