@kition/kit-table-ui 0.0.0-stage → 0.1.1
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/package.json +43 -4
- package/table-ui/LICENSE +177 -0
- package/table-ui/NOTICE +223 -0
- package/table-ui/THIRD_PARTY_NOTICES.txt +11689 -0
- package/table-ui/agent/checks.json +56 -0
- package/table-ui/agent/guide.md +367 -0
- package/table-ui/assets/common-B-bp9Ip3.js +1 -0
- package/table-ui/assets/common-BMUmnQ1g.js +1 -0
- package/table-ui/assets/common-Bhm8gfvH.js +1 -0
- package/table-ui/assets/common-CeDowx6y.js +1 -0
- package/table-ui/assets/common-CrgxgxUu.js +1 -0
- package/table-ui/assets/common-DBFkHMZV.js +1 -0
- package/table-ui/assets/dev-DLKWf75z.js +1 -0
- package/table-ui/assets/index-B4NhVTGq.css +1 -0
- package/table-ui/assets/index-Cnt14ZRl.js +167 -0
- package/table-ui/assets/kit-ui-protocol-BNgs-zwK.js +1 -0
- package/table-ui/assets/kitEngine.worker-xC2uPuSX-BzMhIUM6.js +7 -0
- package/table-ui/assets/loro_wasm_bg-Gulzks_0-Gulzks_0.wasm +0 -0
- package/table-ui/assets/table--j5_5jI6.js +1 -0
- package/table-ui/assets/table-B5yY2dYW.js +1 -0
- package/table-ui/assets/table-Bpba-GrO.js +1 -0
- package/table-ui/assets/table-CpZGkC_z.js +1 -0
- package/table-ui/assets/table-CqH5qF2L.js +1 -0
- package/table-ui/assets/table-DpGGBEXD.js +1 -0
- package/table-ui/engine/kition_table_kit.js +1451 -0
- package/table-ui/engine/kition_table_kit_bg.wasm +0 -0
- package/table-ui/fonts/droid-sans-fallback/DroidSansFallbackFull.ttf +0 -0
- package/table-ui/fonts/droid-sans-fallback/LICENSE +177 -0
- package/table-ui/fonts/droid-sans-fallback/NOTICE +190 -0
- package/table-ui/fonts/inter/Inter-Variable.ttf +0 -0
- package/table-ui/fonts/inter/OFL.txt +93 -0
- package/table-ui/fonts/nanum-gothic/NanumGothic-Regular.ttf +0 -0
- package/table-ui/fonts/nanum-gothic/OFL.txt +96 -0
- package/table-ui/fonts/noto-color-emoji/Noto-COLRv1.ttf +0 -0
- package/table-ui/fonts/noto-color-emoji/OFL.txt +92 -0
- package/table-ui/index.html +14 -0
- package/table-ui/kit-ui.json +1 -0
- package/table-ui/kit.json +250 -0
- package/table-ui/model/schema.json +108 -0
- package/table-ui/templates/batch-product-designer/manifest.json +368 -0
- package/table-ui/templates/batch-product-designer/records/record-01/design-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-01/design-02.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-01/feature-image-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-01/lifestyle-shot-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-01/orthographic-views-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-01/style-board-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-02/design-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-02/design-02.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-02/feature-image-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-02/lifestyle-shot-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-02/orthographic-views-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-02/style-board-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-03/design-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-03/design-02.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-03/feature-image-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-03/lifestyle-shot-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-03/orthographic-views-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-03/style-board-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-04/design-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-04/design-02.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-04/feature-image-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-04/lifestyle-shot-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-04/orthographic-views-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-04/style-board-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-05/design-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-05/design-02.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-05/feature-image-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-05/lifestyle-shot-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-05/orthographic-views-01.webp +0 -0
- package/table-ui/templates/batch-product-designer/records/record-05/style-board-01.webp +0 -0
- package/table-ui/templates/receipt-ocr-database/cover.webp +0 -0
- package/table-ui/templates/receipt-ocr-database/manifest.json +128 -0
- package/table-ui/templates/receipt-ocr-database/records/record-01/receipt.webp +0 -0
- package/table-ui/templates/receipt-ocr-database/records/record-02/receipt.webp +0 -0
- package/table-ui/templates/receipt-ocr-database/records/record-03/receipt.webp +0 -0
- package/table-ui/templates/receipt-ocr-database/records/record-04/receipt.webp +0 -0
- package/table-ui/templates/receipt-ocr-database/records/record-05/receipt.webp +0 -0
- package/table-ui/templates/receipt-ocr-database/records/record-06/receipt.webp +0 -0
- package/table-ui/templates/receipt-ocr-database/records/record-07/receipt.webp +0 -0
- package/table-ui/templates/receipt-ocr-database/records/record-08/receipt.webp +0 -0
- package/table-ui/templates/receipt-ocr-database/records/record-09/receipt.webp +0 -0
- package/table-ui/templates/receipt-ocr-database/records/record-10/receipt.webp +0 -0
- package/table-ui/templates/table-covers/batch-product-designer.webp +0 -0
- package/table-ui/templates/table-covers/business-analytics-dashboard.webp +0 -0
- package/table-ui/templates/table-covers/leads-landing-page.webp +0 -0
- package/table-ui/templates/table-covers/lumiere-restaurant.webp +0 -0
- package/table-ui/templates/table-covers/product-launch-website.webp +0 -0
- package/table-ui/templates/table-covers/project-gantt.webp +0 -0
- package/table-ui/templates/table-covers/receipt-ocr-database.webp +0 -0
- package/table-ui/templates/table-covers/sdr-cold-call-manager.webp +0 -0
- package/table-ui/templates/table-covers/simple-client-crm.webp +0 -0
- package/table-ui/templates/table-covers/task-tracker.webp +0 -0
- package/table-ui/templates/table-covers/thumbnail-generator.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/manifest.json +308 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-01/face-photo-01.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-01/thumbnail-16x9-01.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-01/thumbnail-16x9-02.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-01/thumbnail-9x16-01.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-01/thumbnail-9x16-02.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-02/face-photo-01.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-02/thumbnail-16x9-01.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-02/thumbnail-16x9-02.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-02/thumbnail-9x16-01.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-02/thumbnail-9x16-02.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-03/face-photo-01.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-03/thumbnail-16x9-01.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-03/thumbnail-16x9-02.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-03/thumbnail-9x16-01.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-03/thumbnail-9x16-02.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-04/face-photo-01.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-04/thumbnail-16x9-01.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-04/thumbnail-16x9-02.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-04/thumbnail-9x16-01.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-04/thumbnail-9x16-02.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-05/face-photo-01.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-05/thumbnail-16x9-01.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-05/thumbnail-16x9-02.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-05/thumbnail-9x16-01.webp +0 -0
- package/table-ui/templates/youtube-tiktok-thumbnail-generator/records/record-05/thumbnail-9x16-02.webp +0 -0
- package/README.md +0 -3
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"code": "table.broken-link",
|
|
4
|
+
"severity": "error",
|
|
5
|
+
"summary": "A link field points at a table that does not exist, so its cells link to nothing.",
|
|
6
|
+
"fixture": "check-broken-link.ktable"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"code": "table.broken-lookup",
|
|
10
|
+
"severity": "error",
|
|
11
|
+
"summary": "A lookup or rollup field reads through a link field, or from a field, that does not exist, so it shows nothing.",
|
|
12
|
+
"fixture": "check-broken-lookup.ktable"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"code": "table.dashboard-missing-table",
|
|
16
|
+
"severity": "error",
|
|
17
|
+
"summary": "A dashboard reads a table that does not exist, so its widgets show nothing.",
|
|
18
|
+
"fixture": "check-dashboard-missing-table.ktable"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"code": "table.formula-error",
|
|
22
|
+
"severity": "error",
|
|
23
|
+
"summary": "A formula fails to evaluate on a record and shows an error instead of a value.",
|
|
24
|
+
"fixture": "check-formula-error.ktable"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"code": "table.formula-unknown-field",
|
|
28
|
+
"severity": "error",
|
|
29
|
+
"summary": "A formula names a field its table does not have, which it reads as empty.",
|
|
30
|
+
"fixture": "check-formula-unknown-field.ktable"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"code": "table.field-type-mismatch",
|
|
34
|
+
"severity": "error",
|
|
35
|
+
"summary": "A cell holds a value its field's type cannot show, such as text in a number field.",
|
|
36
|
+
"fixture": "check-field-type-mismatch.ktable"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"code": "table.select-option-missing",
|
|
40
|
+
"severity": "warning",
|
|
41
|
+
"summary": "A select cell holds a value that is not one of its field's options.",
|
|
42
|
+
"fixture": "check-select-option-missing.ktable"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"code": "table.required-empty",
|
|
46
|
+
"severity": "warning",
|
|
47
|
+
"summary": "A record leaves a required field empty.",
|
|
48
|
+
"fixture": "check-required-empty.ktable"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"code": "table.duplicate-primary",
|
|
52
|
+
"severity": "warning",
|
|
53
|
+
"summary": "Two records of a table have the same primary value, so links and lookups cannot tell them apart.",
|
|
54
|
+
"fixture": "check-duplicate-primary.ktable"
|
|
55
|
+
}
|
|
56
|
+
]
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
# Table kit
|
|
2
|
+
|
|
3
|
+
The Table kit opens, edits and checks table files (`.ktable`). A file holds one or more tables with
|
|
4
|
+
typed fields (text, long text, number, rating, single and multi select, date, checkbox, URL,
|
|
5
|
+
attachment, user, link, lookup, rollup, formula, AI …), their records, views (grid, kanban, gallery,
|
|
6
|
+
calendar) with filters, sorts and groups, and dashboards. An agent can add and update records,
|
|
7
|
+
fields and views, filter, sort and group views, check the file for values that don't fit their
|
|
8
|
+
fields, broken links and lookups and formula errors, and export a table to CSV or Markdown.
|
|
9
|
+
|
|
10
|
+
## Tools
|
|
11
|
+
|
|
12
|
+
The kit's prefix is `table`. Its tools are:
|
|
13
|
+
|
|
14
|
+
| Tool | Does |
|
|
15
|
+
|---|---|
|
|
16
|
+
| `table_inspect` | The file as JSON: its tables with their fields, views, record counts and first records, and its dashboards (see [Reading the file](#reading-the-file)); a preview with `preview: true` |
|
|
17
|
+
| `table_query` | Reads `records`, `fields` and `views` of the object model by id, or by following fields from the root |
|
|
18
|
+
| `table_commands` | Finds commands by keywords (`record`, `field`, `view`, `filter`, `sort`, `dashboard`), each with its parameter schema. At most 12 answers; add words when it says "showing 12" |
|
|
19
|
+
| `table_run` | Runs 1 to 50 command steps `{command, params}` in order; it stops at the first failure and saves after the last step |
|
|
20
|
+
| `table_batch` | Runs one batch of object-model operations on `records`, `fields` and `views` |
|
|
21
|
+
| `table_check` | What is wrong with the file, as diagnostics |
|
|
22
|
+
| `table_create` | Makes a new `.ktable` file holding the starter table (see [New files](#new-files)) |
|
|
23
|
+
| `table_export` | Writes the file's first table to a new CSV or Markdown file |
|
|
24
|
+
| `table_draft_ready`, `table_draft_reopen` | Asks the person to review your draft, or takes it back to edit |
|
|
25
|
+
|
|
26
|
+
Every tool takes `path`, the table file's path in the workspace. With `draft: true` your edits go
|
|
27
|
+
to your draft of the file and leave the file as it is; only the person merges or discards a
|
|
28
|
+
draft.
|
|
29
|
+
|
|
30
|
+
## Addressing and coordinates
|
|
31
|
+
|
|
32
|
+
- **Use stable object IDs.** Tables, fields, views and records expose a UUID as `tool_id` in
|
|
33
|
+
inspect and command reads. A record also exposes it as `row_key`. Commands, their nested
|
|
34
|
+
references, `on`, table/view parts, queries, batches, receipts and conflicts use the same
|
|
35
|
+
UUID. It survives rename, reorder, save and reopen. Dashboards already use their string `id`.
|
|
36
|
+
Existing integer inputs remain supported as local projection addresses, counted from 1 and
|
|
37
|
+
scoped by kind. They are declared as index addressing and hold the relevant list window;
|
|
38
|
+
structural changes can refuse them as `relocated`. They are not stable tool IDs. The short
|
|
39
|
+
numeric examples below assume a fresh read; prefer its `tool_id` in subsequent calls.
|
|
40
|
+
- **Record values are keyed by the field's `name`**, not its `title`: a field titled `Status` is
|
|
41
|
+
written as `{"status": "Done"}`. A key that names no field of the table is refused with
|
|
42
|
+
`invalid_params`, one `data.errors` entry per key at `/values/<key>` (in `transact`,
|
|
43
|
+
`/ops/<i>/records/<j>/…`), naming the field when the key is its title; the call changes nothing.
|
|
44
|
+
- **Names.** A table's or field's `name` is lowercase ASCII letters, digits and `_`, starting with a
|
|
45
|
+
letter and not ending with `_` (`^[a-z](?:[a-z0-9_]*[a-z0-9])?$`), unique among the document's
|
|
46
|
+
tables or the table's fields. Give fields explicit names when you will write their values: an
|
|
47
|
+
explicit name is kept as given, and one not in that form, or already taken (also by an earlier
|
|
48
|
+
field of the same call), is refused with `invalid_params` at `/name` or `/fields/<i>/name`.
|
|
49
|
+
Without one, the name is derived from the title: letters and digits kept and lowercased, every
|
|
50
|
+
other run of characters made one `_`, `f_` before a leading digit, `field` when nothing is left
|
|
51
|
+
(a title such as `电话`), then `_2`, `_3`, … when taken. Read derived names back from the answer.
|
|
52
|
+
- **A `link_to_record` value** is a list of the linked records' row keys or record ids
|
|
53
|
+
(`{"members": [3, 4]}`), in [`table.records.create`](/kits/table/commands/table.records.create/),
|
|
54
|
+
[`table.records.update`](/kits/table/commands/table.records.update/) and `transact`; records read
|
|
55
|
+
it back as `{row_key, display}` objects, and `null` or `[]` unlinks. A link field whose
|
|
56
|
+
`symmetric_field_id` names the target table's link field back shows the links made from either
|
|
57
|
+
side.
|
|
58
|
+
- **Filters and sorts refer to fields by `field_id`**, not by name.
|
|
59
|
+
- [`table.records.list`](/kits/table/commands/table.records.list/) pages with `offset` (the number
|
|
60
|
+
of records to skip, counted from **0**) and `limit`; it answers `total`.
|
|
61
|
+
- Leave `asOrigin` out of every call: it is for host features, not agents.
|
|
62
|
+
- **Field types** are the identifiers `text`, `long_text`, `number`, `date`, `datetime`,
|
|
63
|
+
`single_select`, `multi_select`, `checkbox`, `url`, `attachment`, `document_link`, `formula`,
|
|
64
|
+
`ai`, `rating`, `user`, `link_to_record`, `lookup`, `rollup`, `button`, `created_time`,
|
|
65
|
+
`last_modified_time`, `created_by`, `last_modified_by` and `auto_number`; view types are `grid`,
|
|
66
|
+
`kanban`, `calendar` and `gallery`. The `type` and `options` of
|
|
67
|
+
[`table.fields.create`](/kits/table/commands/table.fields.create/) and
|
|
68
|
+
[`table.tables.create`](/kits/table/commands/table.tables.create/) describe each type and the
|
|
69
|
+
options it reads (a select's `choices`, a link's `target_table_id`, …). There is no email or
|
|
70
|
+
phone type: use `text`, or `url` for a link to open. Any other `type` is refused, naming the
|
|
71
|
+
valid ones.
|
|
72
|
+
- **Answers:** every command answers `{"result": …, "change": …}`: `result` is the request's own
|
|
73
|
+
answer (for [`table.tables.list`](/kits/table/commands/table.tables.list/),
|
|
74
|
+
`{"total", "items"}`), and `change` what the call changed, or `null`. Each command's output
|
|
75
|
+
schema describes both.
|
|
76
|
+
|
|
77
|
+
## Where a step acts: `target`, `at` and `on`
|
|
78
|
+
|
|
79
|
+
Nothing a call does depends on, or leaves behind, what the person's editor shows: name tables,
|
|
80
|
+
views, records and fields by id every time, with the ids earlier answers gave you.
|
|
81
|
+
|
|
82
|
+
- A `table_run` step is `{command, params?, on?, at?}`. The run's `target` (`{"table": 2}` or
|
|
83
|
+
`{"view": 3}`) is the part every step acts in; a step's `at.part` overrides it for that step.
|
|
84
|
+
Commands still take their own `tableId` (and `viewId`): give it, matching the part.
|
|
85
|
+
- `on` names the **record** or the **field** a step acts on, by id (`[4]`). It goes into the
|
|
86
|
+
command's `recordId` (a record of the command's `tableId`: `table.records.update`, `.delete`,
|
|
87
|
+
`.history`, `table.links.*`) or `fieldId` (`table.fields.update`, `.delete`, `.duplicate`,
|
|
88
|
+
`.linkCandidates`, `table.views.patchField`), which `table_commands` with `detail` marks as the
|
|
89
|
+
command's `targets`; then do not give that parameter too. The command says whether `on` is a
|
|
90
|
+
record or a field. A command without such a parameter takes no `on`, and an id `on` gives
|
|
91
|
+
elsewhere is refused (a table file keeps no selection; an id that is both a record and a field
|
|
92
|
+
of the part's table is refused as ambiguous).
|
|
93
|
+
- No command reads what the editor shows. `table.preview.show` changes only the person's picture
|
|
94
|
+
and is put back after the call; never use it to choose what a later step acts on.
|
|
95
|
+
- Positions are not ids: `offset` in `table.records.list`, `rows` in a preview and `slide` (a
|
|
96
|
+
table's position) change when records or tables are added or moved.
|
|
97
|
+
|
|
98
|
+
## Previews of a named table or view
|
|
99
|
+
|
|
100
|
+
`table_inspect` with `"preview": true` draws `target`: `{"table": 2}` (the table as its first view
|
|
101
|
+
shows it), `{"view": 3}` (the records the view shows, filtered and in its order), a diagnostic's
|
|
102
|
+
`target` (`{"path": "tables/2/records/4/fields/5"}`: the cell outlined), and `rows: [from, to]`
|
|
103
|
+
for some records of it (positions counted from 1). Without `target` it draws the first table's
|
|
104
|
+
first view, never what the editor shows. `scale` (up to 2) and `maxSize` set its size, and
|
|
105
|
+
`preview` in the answer says what was drawn (`tableId`, `viewId`). The same call answers the same
|
|
106
|
+
picture, and drawing it changes nothing.
|
|
107
|
+
|
|
108
|
+
## What a call changed, and what others changed
|
|
109
|
+
|
|
110
|
+
- **Answers and receipts.** Every command answers `{"result", "change"}`; `change` lists, by
|
|
111
|
+
integer id, the tables, schemas and views it changed and the records upserted or deleted (with
|
|
112
|
+
their row keys). A successful `table_run` or `table_batch` also answers `changes`: `created`,
|
|
113
|
+
`changed` (each with `edits`: a field, `before` and `after`), `moved` and `deleted`, naming
|
|
114
|
+
objects by the object model's ids: a record by its `row_key` (its `cells` keyed by the fields'
|
|
115
|
+
object-model ids), a field, view or table by its object-model id. Match them with
|
|
116
|
+
`table.records.list` (each record's `row_key`) or `table_query`.
|
|
117
|
+
- **Pass the latest `revision` as `basis`.** Every answer of inspect, query, run and batch has a
|
|
118
|
+
short `revision`. Pass the last one you were given as `basis` on your next call: the answer then
|
|
119
|
+
says what others (people, other agents) changed since, in `others` (with `by`).
|
|
120
|
+
- **A `conflict`** (retryable) means others changed what the write acts on since your `basis`
|
|
121
|
+
(`deleted`, `relocated`, `changed`, or `unknown` when it cannot be told object by object). Nothing was run.
|
|
122
|
+
Read `others` and `conflicts`, look again, decide again, and send the call with the `revision`
|
|
123
|
+
the refusal gives as `basis`. Do not undo others' changes. A typed per-call premise resolves a record's integer id to its persistent
|
|
124
|
+
`row_key`, including a deleted record's tombstone, before comparing changes.
|
|
125
|
+
|
|
126
|
+
## What writes hold
|
|
127
|
+
|
|
128
|
+
Every command object parameter accepts the UUID used by receipts, conflicts and queries.
|
|
129
|
+
Reads expose it as `tool_id`; records also call it `row_key`. Use these UUIDs for `on` and
|
|
130
|
+
for table/view parts. Existing integer inputs remain local projection addresses, not stable
|
|
131
|
+
tool ids. Their declarations use index addressing and list windows: a structural change
|
|
132
|
+
before such an address can refuse it as `relocated`. UUID writes do not hold those windows.
|
|
133
|
+
|
|
134
|
+
The guard uses the facts declared for each call. Supplying a basis does not make an undeclared
|
|
135
|
+
dependency safe. Their direct tests are `places`, `outside`, and `saved`.
|
|
136
|
+
|
|
137
|
+
| Commands | Premise |
|
|
138
|
+
|---|---|
|
|
139
|
+
| `tables.update`, `fields.update`, `views.update` | Supplied stored properties; replacing `options`, `meta`, or `config` holds that whole value. Changing the primary field also holds `Table.primaryField`; the new primary field only that it is one of the table's fields. |
|
|
140
|
+
| `views.patchConfig`, `putFilterTree`, `putSorts`, `putGroups` | Effective setting, reported as derived `~rowHeight`, `~frozenColumnCount`, `~searchQuery`, `~filterTree`, `~sorts`, or `~groups`. An absent config and an absent key have the same value. |
|
|
141
|
+
| `views.patchField` | The addressed width, visibility, position or frozen value; field existence. Widths are integer pixels, rounded and clamped to 40 through 1200 on model-batch entry. Position and freezing are stored in `config.field_layout`, not SQL-only editor state. |
|
|
142
|
+
| `records.create`, `records.update`, transaction `cells.set` | Each written cell, and its field's name membership and type (a link's or select's options too: a computed field's value is dropped). Required flags and `readonly` are not held: the required check only refuses the call, and no write reads `readonly`. The table need only exist. Repeated transaction operations union their dependencies. |
|
|
143
|
+
| All named cell writes, including transaction values and combined values/order writes | Table-scoped name membership, including prior ownership after a cross-table move; a name swapped, renamed away or moved out changes the address. |
|
|
144
|
+
| Record order changes, field insertion, transaction `fields.move`, positive-position bulk copy | The destination gap, in stored list coordinates. Moves additionally hold the moving object's position. Record anchors hold their position. |
|
|
145
|
+
| Link writes, through cells or `links.replace`/`delete` | Existing membership, target record existence and ownership, the effective symmetric partner, its schema and the reverse membership the write may replace. Target display-cell changes alone are unrelated. |
|
|
146
|
+
| Formula/lookup/rollup schema and AI results | Fields a formula names, by name membership; fields and tables an option names, that they are there (the cycle check reads more, but only refuses). AI application holds the AI field's settings, the source's name, title and type, and transitive source values, linked membership and linked source cells. A whole-record concatenating rollup holds every linked field and value. Formula references are `{field_name}`; there is no separate UUID formula syntax. |
|
|
147
|
+
| `fields.duplicate` | The source field's settings and position, and the names occupying generated-name candidates. It creates an empty column; it does not copy source cells. |
|
|
148
|
+
| `tables.create`, `fields.create`, new-table `import.run` | Name membership through the first free generated suffix; unrelated names and display titles are independent, also for `tables.create {}` with no place parameter. |
|
|
149
|
+
| Field delete | Every stored property of the field, not where it is; all current cell values in that field, row membership and affected links. |
|
|
150
|
+
| Field type update | The field's `type` only. A type update changes the schema and computed projection; it does not convert stored cell values, so a cell written meanwhile stays under the new type. |
|
|
151
|
+
| `records.bulkCopy` | Stored source cells, every field's type (which are stored), and an explicit destination gap. It omits computed and link values. Bulk delete and transaction deletion hold selected records and affected links, not where the records are. |
|
|
152
|
+
| `import.run`, `csv.import` | Every field's name, title and type (a link's options) and their order, and name membership; replacement holds rows and their membership; upsert also holds key values and cells it can replace. Append does not hold unrelated existing cell values. |
|
|
153
|
+
| Dashboards and view references | The replaced dashboard (not where it is), nested table/view existence and ownership, field definitions and table-scoped field names. View settings hold only the setting replaced; a filter, sort or group holds its field's name (written beside its id) and table; a view config holds only that the fields it names are there. |
|
|
154
|
+
| Table/record/view deletion | Every stored property of the object being deleted (a record: its every cell), not where it is; table deletion also holds all its fields, views, records, object lists and link cleanup. Replacement imports hold removed records and their links. |
|
|
155
|
+
| Undo/redo | An outside reread imports only what the file adds, outside both undo histories, so the session keeps its own: undo or redo takes back or puts again only its own step and preserves the other writer's values. A file of another document, or one that lacks a change of the session, is not reconciled. |
|
|
156
|
+
| Attachments, exports and reads | Attachment upload adds a content-addressed blob, not an attachment cell. Reads and exports do not change table content. |
|
|
157
|
+
|
|
158
|
+
There is no point/region write, spatial bounds, parent transform or carried-child motion in
|
|
159
|
+
this kit. Reordering a table leaves its records' own positions unchanged; `carried` is not
|
|
160
|
+
applicable to that list operation.
|
|
161
|
+
|
|
162
|
+
For a call that declares `covers`, the kit compares numeric windows itself, alongside name
|
|
163
|
+
membership. Independent-file prefix deletion and
|
|
164
|
+
move-out tests cover insertion, a single local address and both move-destination forms.
|
|
165
|
+
Raw model batches (`table_batch`) run under the premise contracts the model declares
|
|
166
|
+
(`batchOps` in `model/schema.json`). Most operations are `direct`: they hold their object, the
|
|
167
|
+
fields they write, their references and the insertion window of an index, so `create`,
|
|
168
|
+
`list.insert` and `list.move` refuse when an outside change moved or removed what was before
|
|
169
|
+
their index. A raw cell write (`map.set` or `map.remove` of `Record.cells` under a field's id)
|
|
170
|
+
holds that one cell and, of the field, that it is there and its `type` and `options` (the
|
|
171
|
+
written value is read through them): a deleted column refuses `deleted`, a changed type or
|
|
172
|
+
option set refuses `changed`, while a rename of the field, the record's place and its other
|
|
173
|
+
cells are independent.
|
|
174
|
+
|
|
175
|
+
A call that reads a table's schema in field order holds that table's own `~fieldOrder`, a
|
|
176
|
+
small hash of its ordered field identities, so the same-server journal keeps its `before`: a
|
|
177
|
+
field another writer adds to another table leaves the call independent, while a move of the
|
|
178
|
+
table's own fields refuses. Local integer addresses are held by their windows (`within`),
|
|
179
|
+
which the guard checks itself; a record another agent adds to another table leaves a write by
|
|
180
|
+
local integers independent, and one inserted above the addressed record refuses `relocated`
|
|
181
|
+
(`list_preimages_on_same_server_local_addresses`,
|
|
182
|
+
`a_schema_read_holds_its_own_tables_field_order`).
|
|
183
|
+
Stable-ID ownership uses small per-object derived values. Destructive whole-object premises
|
|
184
|
+
can still refuse unrelated properties of their source. Layout patches compare effective
|
|
185
|
+
entries, including null-to-object transitions, so sibling layout entries are independent.
|
|
186
|
+
|
|
187
|
+
Receipts compact identical numeric shifts and identical assignments (the same value written
|
|
188
|
+
to the same field) as `footprint`, naming all affected UUIDs. Other edits beyond the default
|
|
189
|
+
receipt's bound are counted in `truncated`; request `changes: "all"` for every edit, and never
|
|
190
|
+
treat a receipt with `truncated` as complete. An edit names its `field`; `before` and `after`
|
|
191
|
+
are given when known and small. The guard's own derived facts (`~fieldOrder`, `~linkCells`,
|
|
192
|
+
`~mirrors`, `~rowIds`, `~owner`) are `premiseOnly`: receipts never report them.
|
|
193
|
+
|
|
194
|
+
Offline kit-env generation makes and replays creation tasks for every stored type (Table,
|
|
195
|
+
Field, View, Record, Dashboard). A raw `create` is given what a create gives: a Record's
|
|
196
|
+
`createdAt` (the time of the write) and `createdBy`, a Table's empty `description`, and a
|
|
197
|
+
Field's empty `formula` and `aiPrompt` (receipts leave empty strings out of a created object's
|
|
198
|
+
values). A creation receipt replayed through `table_batch` (`kition_env::ops_for`) therefore
|
|
199
|
+
makes the same object under the receipt's id
|
|
200
|
+
(`waiting_for_sdk_creation_replay_and_required_defaults`). Required JSON values
|
|
201
|
+
must remain writable and have a same-type example in the seed file. For command-level record
|
|
202
|
+
creation, inspect `required` fields and supply their values, for example
|
|
203
|
+
`{"tableId": 1, "values": {"title": "New record"}}` in the starter table.
|
|
204
|
+
|
|
205
|
+
## Reading the file
|
|
206
|
+
|
|
207
|
+
`table_inspect` answers every table with:
|
|
208
|
+
|
|
209
|
+
- `id`, `tool_id`, `name`, `label` (the title people see, which `title` params set), `recordCount`;
|
|
210
|
+
- `fields`: each field's `id`, `name` (the key of its values), `label`, `type`, `primary`, and the
|
|
211
|
+
`options` that matter for values: a select's `choices`, a link's `target_table_id`, a lookup's or
|
|
212
|
+
rollup's `link_field_id` and `target_field_id`;
|
|
213
|
+
- `views`: each view's `id`, `label`, `type`, and what it does by field name: `filter`
|
|
214
|
+
(`status neq "Done"`), `sorts` and `groups` (`title asc`), `hidden`;
|
|
215
|
+
- `records`: its first records as `{columns, rows, from, to, total, next?}`. `columns` are the field
|
|
216
|
+
names, and each row is `{id, tool_id, cells}`, one cell per column (`null` when empty). A link's cell lists
|
|
217
|
+
the linked records as `{id, display}`, by record id; text over 200 characters is cut and ends in
|
|
218
|
+
`…`.
|
|
219
|
+
|
|
220
|
+
It lists at most 20 records of a table and 100 in all. When a table's records are cut, `next` is
|
|
221
|
+
the step that lists the rest: run it as it is with `table_run`.
|
|
222
|
+
[`table.read`](/kits/table/commands/table.read/) `{"tableId": 1}` lists a table's records and
|
|
223
|
+
`{"viewId": 2}` the records a view shows (filtered and in its order), 50 at a time (`limit`, up to
|
|
224
|
+
200); each answer's `next` goes on from where it stopped (`cursor`).
|
|
225
|
+
|
|
226
|
+
```json
|
|
227
|
+
table_run {"path": "crm.ktable", "steps": [
|
|
228
|
+
{"command": "table.read", "params": {"viewId": 2, "limit": 100}}
|
|
229
|
+
]}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## New files
|
|
233
|
+
|
|
234
|
+
A new file (`table_create`, or a host's `document.open` with `create: {"format": "ktable"}`) is
|
|
235
|
+
not empty: like a new table in the editor, it holds one starter table, table 1 `Table` (name
|
|
236
|
+
`table`), with fields `title` (text, primary), `status` (single_select: `To do`, `In progress`,
|
|
237
|
+
`Done`) and `notes` (long_text), one grid view `All`, and no records.
|
|
238
|
+
|
|
239
|
+
To build your own schema, rename the starter table and change its fields, or delete it. A host
|
|
240
|
+
that makes a file for its own schema deletes it as a system write, so the person's Undo does not
|
|
241
|
+
bring it back; ids are never reused, so its first own table is table 2:
|
|
242
|
+
|
|
243
|
+
```json
|
|
244
|
+
{"command": "table.tables.delete", "params": {"tableId": 1, "asOrigin": "system:setup"}}
|
|
245
|
+
{"command": "table.tables.create", "params": {"title": "Contacts", "fields": [
|
|
246
|
+
{"title": "Name", "type": "text", "primary": true},
|
|
247
|
+
{"title": "Email", "type": "text"},
|
|
248
|
+
{"title": "Stage", "type": "single_select", "options": {"choices": ["Lead", "Customer"]}}
|
|
249
|
+
]}}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
A file with no table at all is valid and saves.
|
|
253
|
+
|
|
254
|
+
## Workflow
|
|
255
|
+
|
|
256
|
+
1. `table_inspect` to learn the ids, field names, types, views and records; `table.read` for
|
|
257
|
+
records it cut.
|
|
258
|
+
2. `table_commands` with keywords. Use the exact id it returns and follow its parameter schema;
|
|
259
|
+
never guess a command id.
|
|
260
|
+
3. `table_run` a few steps, each naming its table (`tableId`, and the run's `target` or `at.part`)
|
|
261
|
+
and its record or field (`on`, or the command's own `recordId` or `fieldId`). A failed step rolls
|
|
262
|
+
the whole run back. Pass the last `revision` as `basis`.
|
|
263
|
+
4. `table_check`, then fix what it reports. Many diagnostics carry a `fix` you can run as a step.
|
|
264
|
+
5. `table_inspect` again to confirm the result.
|
|
265
|
+
|
|
266
|
+
## Example 1: add a record and update another
|
|
267
|
+
|
|
268
|
+
```json
|
|
269
|
+
table_inspect {"path": "crm.ktable"}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
The answer lists table 1 with fields `title` (text, primary), `status` (single select:
|
|
273
|
+
`To do`, `In progress`, `Done`) and `notes` (long text), view 1 `All`, and its records. Then:
|
|
274
|
+
|
|
275
|
+
```json
|
|
276
|
+
table_run {"path": "crm.ktable", "steps": [
|
|
277
|
+
{"command": "table.records.create", "params": {"tableId": 1, "values": {"title": "Book the venue", "status": "To do"}}},
|
|
278
|
+
{"command": "table.records.update", "params": {"tableId": 1, "recordId": 1, "values": {"status": "In progress", "notes": "Draft shared on Monday"}}}
|
|
279
|
+
]}
|
|
280
|
+
table_check {"path": "crm.ktable"}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
The first step answers the new record with `"id": 3`; both steps answer `"changed": true`, and the
|
|
284
|
+
check finds nothing wrong.
|
|
285
|
+
|
|
286
|
+
## Example 2: a number field and a filtered, sorted view
|
|
287
|
+
|
|
288
|
+
```json
|
|
289
|
+
table_run {"path": "crm.ktable", "steps": [
|
|
290
|
+
{"command": "table.fields.create", "params": {"tableId": 1, "name": "priority", "title": "Priority", "type": "number"}},
|
|
291
|
+
{"command": "table.records.update", "params": {"tableId": 1, "recordId": 2, "values": {"priority": 2}}},
|
|
292
|
+
{"command": "table.views.create", "params": {"tableId": 1, "title": "Open work", "type": "grid"}}
|
|
293
|
+
]}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
The field is answered with `"id": 4`, the view with `"id": 2`. Show only what is not done, by title:
|
|
297
|
+
|
|
298
|
+
```json
|
|
299
|
+
table_run {"path": "crm.ktable", "steps": [
|
|
300
|
+
{"command": "table.views.putFilterTree", "params": {"tableId": 1, "viewId": 2,
|
|
301
|
+
"tree": {"conjunction": "and", "children": [{"condition": {"field_id": 2, "operator": "neq", "value": "Done"}}]}}},
|
|
302
|
+
{"command": "table.views.putSorts", "params": {"tableId": 1, "viewId": 2, "items": [{"field_id": 1, "direction": "asc"}]}}
|
|
303
|
+
]}
|
|
304
|
+
table_check {"path": "crm.ktable"}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
Both steps answer the stored tree and sorts, and the check finds nothing wrong.
|
|
308
|
+
|
|
309
|
+
## Example 3: edit two tables in one run
|
|
310
|
+
|
|
311
|
+
`table_inspect` lists table 1 `Notes` (fields `title`, `status`, `notes`; records 1 `Ask about
|
|
312
|
+
visas` and 2 `Find a sitter`) and table 2 `Packing` (fields 4 `item` and 5 `packed`; records 3
|
|
313
|
+
`Passport`, 4 `Charger`, 5 `Boots`). Mark two items packed and finish a note, whatever the person
|
|
314
|
+
is looking at:
|
|
315
|
+
|
|
316
|
+
```json
|
|
317
|
+
table_run {"path": "trip.ktable", "basis": "ykl0", "target": {"table": 2}, "steps": [
|
|
318
|
+
{"command": "table.records.update", "on": [3], "params": {"tableId": 2, "values": {"packed": true}}},
|
|
319
|
+
{"command": "table.records.update", "on": [4], "params": {"tableId": 2, "values": {"packed": true}}},
|
|
320
|
+
{"command": "table.records.update", "at": {"part": {"table": 1}}, "on": [2], "params": {"tableId": 1, "values": {"status": "Done"}}}
|
|
321
|
+
]}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Each step answers its record (`"id": 3`, …) and a `change` naming it; `changes` lists the three
|
|
325
|
+
records (by row key) with their cells before and after. The next call starts again from nothing:
|
|
326
|
+
name the tables and records again.
|
|
327
|
+
|
|
328
|
+
## Example 4: preview a view, then rename a field
|
|
329
|
+
|
|
330
|
+
```json
|
|
331
|
+
table_inspect {"path": "trip.ktable", "target": {"view": 2}, "preview": true}
|
|
332
|
+
table_run {"path": "trip.ktable", "basis": "ykl1", "steps": [
|
|
333
|
+
{"command": "table.fields.update", "on": [5], "params": {"tableId": 2, "title": "In the bag"}}
|
|
334
|
+
]}
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
The preview shows view 2 of table 2 (`preview.viewId` is 2), whatever the editor shows. The rename
|
|
338
|
+
answers the field with `"id": 5` and its name unchanged (`packed`: values keep their key), and
|
|
339
|
+
`changes.changed` names one `Field` with `title` `"Packed"` → `"In the bag"`.
|
|
340
|
+
|
|
341
|
+
## Pitfalls
|
|
342
|
+
|
|
343
|
+
- **Unknown keys:** a value key that names no field is refused, and nothing is written. When the
|
|
344
|
+
key is a field's title, the error says so (`the field titled "Primary channel" is named
|
|
345
|
+
primary_channel`): use that name, or read the names with
|
|
346
|
+
[`table.fields.list`](/kits/table/commands/table.fields.list/).
|
|
347
|
+
- **Select options:** a single-select value must be one of the field's `options.choices`. Writing
|
|
348
|
+
another value succeeds, and `table_check` then warns `table.select-option-missing`. Either add
|
|
349
|
+
the choice first ([`table.fields.update`](/kits/table/commands/table.fields.update/)
|
|
350
|
+
`{tableId, fieldId, options}`) or use an existing one.
|
|
351
|
+
- **Formula fields** are computed: write their `formula`, never their values.
|
|
352
|
+
- **Empty values:** a record's `values` holds only the fields that have a value; a missing key means
|
|
353
|
+
empty.
|
|
354
|
+
- **Nothing carries over between calls.** No call remembers the table, view or records of the one
|
|
355
|
+
before, or what a `table.preview.show` showed: name them by the ids earlier results gave.
|
|
356
|
+
|
|
357
|
+
## Checks
|
|
358
|
+
|
|
359
|
+
`table_check` lists what is wrong with the file. Each diagnostic has a stable `code`, a
|
|
360
|
+
`severity` (`error`, `warning` or `info`), a `message`, a `target` and, for some, a `fix`: a
|
|
361
|
+
command step to run as it is. Act on the code, not on the message. A `fix` is a suggestion: run it
|
|
362
|
+
only when it is what the person asked for. Every code the kit reports is on the
|
|
363
|
+
[checks page](/kits/table/checks/).
|
|
364
|
+
|
|
365
|
+
The check reports values that are not one of a select's options (`table.select-option-missing`,
|
|
366
|
+
whose `fix` adds the choice), empty required fields, duplicate primary values, broken links and
|
|
367
|
+
lookups, formula errors, and dashboards on missing tables.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e={actions:{cancel:`Cancelar`,close:`Fechar`,confirm:`Confirmar`,save:`Salvar`,hidePassword:`Ocultar senha`,showPassword:`Mostrar senha`},dialogs:{rightSheet:`Folha direita`}};export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e={actions:{cancel:`Annuler`,close:`Fermer`,confirm:`Confirmer`,save:`Enregistrer`,hidePassword:`Masquer le mot de passe`,showPassword:`Afficher le mot de passe`},dialogs:{rightSheet:`Volet droit`}};export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e={actions:{cancel:`Отмена`,close:`Закрыть`,confirm:`Подтвердить`,save:`Сохранить`,hidePassword:`Скрыть пароль`,showPassword:`Показать пароль`},dialogs:{rightSheet:`Правый лист`}};export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e={actions:{cancel:`取消`,close:`关闭`,confirm:`确认`,save:`保存`,hidePassword:`隐藏密码`,showPassword:`显示密码`},dialogs:{rightSheet:`右侧面板`}};export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e={actions:{cancel:`Cancelar`,close:`Cerrar`,confirm:`Confirmar`,save:`Guardar`,hidePassword:`Ocultar contraseña`,showPassword:`Mostrar contraseña`},dialogs:{rightSheet:`Hoja derecha`}};export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e={actions:{cancel:`Cancel`,close:`Close`,confirm:`Confirm`,save:`Save`,hidePassword:`Hide password`,showPassword:`Show password`},dialogs:{rightSheet:`Right sheet`}};export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{C as e,D as t,E as n,S as r,T as i,_ as a,a as o,b as s,f as c,g as l,h as u,i as d,m as f,o as p,p as m,v as h,w as g,x as _,y as v}from"./kit-ui-protocol-BNgs-zwK.js";function y(e,t){return new f(-32e3,t,{reason:e})}var b=e=>new f(-32602,e),x=e=>Object.prototype.toString.call(e)===`[object ArrayBuffer]`;function S(e){let t=e.lastIndexOf(`.`);return t>0?e.slice(t+1).toLowerCase():``}var C=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i;function w(e){let t=(e.split(/[\\/]/).pop()??``).replace(/[\u0000-\u001f\u007f<>:"|?*]/g,``).trim().replace(/^\.+/,``).replace(/[. ]+$/,``),n=t.indexOf(`.`),r=n<0?t:t.slice(0,n);if(C.test(r)&&(t=`${r}_${t.slice(r.length)}`),t.length>255){let e=S(t);t=e?`${t.slice(0,254-e.length)}.${e}`:t.slice(0,255)}return t||`Untitled`}async function T(e,t){let n=e.lastIndexOf(`.`),[r,i]=n>0?[e.slice(0,n),e.slice(n)]:[e,``];for(let n=1;n<1e4;n+=1){let a=n===1?e:`${r} ${n}${i}`;if(!await t(a))return a}throw y(`io-error`,`no unused name is left for this file`)}function E(){let e=new Uint8Array(16);return crypto.getRandomValues(e),`fh_`+Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``)}var D=e=>e.split(/[\\/]/).filter(Boolean).pop()??e,O=()=>globalThis.navigator?.userActivation?.isActive??!0,k=e=>(e??[]).map(e=>e.replace(/^\./,``).toLowerCase());function A(e,t,n){let r=[];return{append:async e=>void r.push(e),commit:async()=>{let i=new Uint8Array(r.reduce((e,t)=>e+t.byteLength,0)),a=0;for(let e of r)i.set(e,a),a+=e.byteLength;let o=await e.commit(t(),i,n());return r=[],o},abort:async()=>{r=[]}}}var j=[`files/pick`,`files/create`,`files/stat`,`files/read`,`files/list`,`files/write`,`files/release`,`files/print`];function M(e){let{storage:t}=e,n=E().slice(3),r={read:k(e.manifest?.read),create:k(e.manifest?.create),folders:e.manifest?.folders===!0,print:e.manifest?.print===!0},i=t.name??D,a=e.gesture??O,o=new Map,s=!1,c=0,l=[`files`,...e.pick?[`files-pick`]:[],...e.print?[`print`]:[]],u=e=>({handle:e.handle,name:e.name,kind:e.kind,...e.size===void 0?{}:{size:e.size},...e.mime===void 0?{}:{mime:e.mime},version:e.version,rights:[...e.rights]}),d=(t,r,a,s,c={})=>{let l={handle:E(),session:n,kit:e.kit,principal:e.principal,flow:s,rights:a,kind:r?.kind??`file`,name:c.name??i(t),ref:t,folder:c.folder??null,accept:c.accept??[],mime:c.mime??r?.mime,version:r?.version??null,size:r?.size,committed:!1,staging:null,staged:0,written:0,expected:null};o.set(l.handle,l);let{handle:u,session:d,kit:f,principal:p,kind:m,name:h}=l;return e.log?.({handle:u,session:d,kit:f,principal:p,flow:s,rights:[...a],kind:m,name:h}),l},p=(e,t,n)=>{if(s)throw y(`file-not-granted`,`the session has ended`);let r=typeof e==`string`?o.get(e):void 0;if(!r)throw y(`file-not-granted`,`this handle was not granted to this session`);if(t&&!r.rights.includes(t))throw y(`file-not-granted`,`this handle has no ${t} right`);if(n&&r.kind!==n)throw y(`file-not-granted`,`this handle is not a ${n}`);return r},m=async e=>{try{return await e()}catch(e){throw e instanceof f?e:y(`io-error`,`the host could not reach the file`)}},h=async e=>{o.delete(e.handle);let t=e.staging;e.staging=null,t&&await t.abort().catch(()=>{})},g=e=>{if(!a())throw y(`no-gesture`,`${e} needs a person's gesture in the kit`)},_=async(e,n)=>{let r=new Set([...o.values()].filter(e=>e.rights.includes(`create`)&&e.kind===`file`&&!e.committed).map(e=>e.ref)),i=await T(n,async n=>{let i=t.child(e,n);return r.has(i)||await t.stat(i)!==null});return{name:i,ref:t.child(e,i)}},v=(e,t=r.read)=>{let n=S(e);if(!r.read.includes(n)||!t.includes(n))throw y(`not-allowed`,`the kit may not read .${n||`(none)`} files`)},C=e=>{let t=S(e);if(!r.create.includes(t))throw y(`not-allowed`,`the kit may not create .${t||`(none)`} files`)},j=(e,t)=>{let n=k(e);if(n.some(e=>!t.includes(e)))throw y(`not-allowed`,`the kit asked for a file type its manifest does not declare`);return n.length?n:t},M=async n=>{if(!e.pick)throw y(`unsupported`,`this host has no picker`);if(n?.mode!==`open`&&n?.mode!==`folder`&&n?.mode!==`save`)throw b(`mode is open, folder, or save`);if(g(`files/pick`),n.mode===`folder`&&!r.folders)throw y(`not-allowed`,`the kit may not ask for folders`);let a=j(n.accept,n.mode===`save`?r.create:r.read);n.mode===`save`&&n.suggestedName!=null&&C(w(n.suggestedName));let o=await m(()=>e.pick(n)),s=[];for(let c of n.mode===`open`&&!n.multiple?o.slice(0,1):o){let o=await m(()=>t.stat(c));if(n.mode===`folder`){if(o?.kind!==`folder`)continue;let e=r.create.length?[`read`,`create`]:[`read`];s.push(u(d(c,o,e,`pick`,{accept:a})))}else if(n.mode===`open`){if(o?.kind!==`file`||!a.includes(S(i(c))))continue;s.push(u(d(c,o,[`read`],`pick`)))}else{if(!a.includes(S(i(c))))throw y(`not-allowed`,`the kit may not create this file type`);if(o?.kind===`folder`)continue;if(o&&e.readOnly)throw y(`not-allowed`,`a read-only session replaces no file`);s.push(u(d(c,o,o?[`write`]:[`create`],`pick`)));break}}return{files:s}},N=async e=>{if(typeof e?.suggestedName!=`string`)throw b(`suggestedName is a string`);let t=e.folder===void 0?null:p(e.folder,`create`,`folder`),n=w(e.suggestedName);C(n);let{name:r,ref:i}=await m(()=>_(t?.ref??null,n));return u(d(i,null,[`create`],`create`,{name:r,folder:t?.ref??null,mime:typeof e.mime==`string`?e.mime:void 0}))},P=async({handle:e,offset:n,length:r})=>{let i=p(e,`read`,`file`),a=n??0;if(!Number.isSafeInteger(a)||a<0||r!==void 0&&(!Number.isSafeInteger(r)||r<0))throw b(`offset and length are whole numbers`);let o=await m(()=>t.read(i.ref,a,r));return i.version=o.version,i.size=o.size,o},F=async({handle:e})=>{let n=p(e,`read`,`folder`),a=await m(()=>t.list(n.ref)),o=[];for(let e of a){if(!n.accept.includes(S(i(e)))||!r.read.includes(S(i(e))))continue;let a=await m(()=>t.stat(e));a?.kind===`file`&&o.push(u(d(e,a,[`read`],`list`)))}return{files:o}},I=async n=>{let r=p(n?.handle,void 0,`file`),i=r.rights.includes(`create`);if(!i&&!r.rights.includes(`write`))throw y(`file-not-granted`,`this handle has no create or write right`);if(i&&r.committed)throw y(`already-committed`,`this file was already committed`);if(!x(n.bytes))throw b(`bytes is an ArrayBuffer`);if(n.offset!==r.staged)throw b(`offset is ${r.staged}, the bytes staged so far`);let a=n.bytes.byteLength;if(e.quota?.perGrant!==void 0&&r.written+a>e.quota.perGrant||e.quota?.perSession!==void 0&&c+a>e.quota.perSession)throw y(`quota`,`this write passes the host's cap`);if(n.final&&!i){if(typeof n.expected!=`string`)throw y(`conflict`,`the final chunk carries the version it replaces`);if(await m(()=>t.unsaved?.(r.ref)??!1))throw y(`unsaved-edits`,`the file is open with unsaved edits`);r.expected=n.expected}if(!r.staging){let e=()=>i?{mode:`create`}:{mode:`replace`,expected:r.expected??``};r.staging=t.stage?t.stage(r.ref,e):A(t,()=>r.ref,e)}let o=r.staging;if(await m(()=>o.append(new Uint8Array(n.bytes.slice(0)))),r.staged+=a,r.written+=a,c+=a,!n.final)return{};let s=await L(r,o,i);return r.staging=null,r.staged=0,r.expected=null,r.version=s.version,i&&(r.committed=!0),{version:s.version}},L=async(e,n,r)=>{for(let i=0;;i+=1)try{return await m(()=>n.commit())}catch(n){let a=n instanceof f&&n.data?.reason===`conflict`;if(!r||!a||e.flow!==`create`||t.stage||i>=8)throw n;let o=await m(()=>_(e.folder,e.name));e.ref=o.ref,e.name=o.name}},R=async({handles:e})=>{for(let t of Array.isArray(e)?e:[]){let e=typeof t==`string`?o.get(t):void 0;e&&await h(e)}return{}},z=async t=>{if(!e.print)throw y(`unsupported`,`this host does not print`);if(!r.print)throw y(`not-allowed`,`the kit may not print`);g(`files/print`);let n;if(!t||typeof t!=`object`)throw b(`a print takes PDF bytes or a handle`);if(`handle`in t){let e=p(t.handle,`read`,`file`);if(S(e.name)!==`pdf`&&e.mime!==`application/pdf`)throw y(`not-allowed`,`only a PDF prints`);n=await B(e.ref)}else{if(t.mime!==`application/pdf`||!x(t.bytes))throw b(`a print takes PDF bytes or a handle`);n=new Uint8Array(t.bytes.slice(0))}let i=typeof t.title==`string`?t.title:``;return{printed:await m(()=>e.print({bytes:n,title:i}))===!0}},B=async e=>{let n=[],r=0;for(;;){let{bytes:i,size:a}=await m(()=>t.read(e,r,void 0));if(n.push(new Uint8Array(i)),r+=i.byteLength,r>=a||i.byteLength===0)break}let i=new Uint8Array(r),a=0;for(let e of n)i.set(e,a),a+=e.byteLength;return i},V={"files/pick":M,"files/create":N,"files/stat":async({handle:e})=>{let n=p(e);if(n.rights.includes(`create`)&&!n.committed&&n.kind===`file`)return u(n);let r=await m(()=>t.stat(n.ref));if(!r)throw y(`file-not-granted`,`the file is gone`);return Object.assign(n,{version:r.version,size:r.size,mime:r.mime??n.mime}),u(n)},"files/read":P,"files/list":F,"files/write":I,"files/release":R,"files/print":z};return{id:n,capabilities:l,grant:async(n,a,{flow:o,approved:c})=>{if(s)throw y(`file-not-granted`,`the session has ended`);let l=await m(()=>t.stat(n)),f=i(n);if(a.includes(`write`)){if(e.readOnly)throw y(`not-allowed`,`a read-only session replaces no file`);if(o===`agent`&&c!==!0)throw y(`not-allowed`,`an agent replaces a file only through a draft or the person's approval`);if(l?.kind!==`file`)throw y(`not-allowed`,`there is no such file to replace`);C(f)}if(a.includes(`read`)){if(!l)throw y(`not-allowed`,`there is no such file`);if(l.kind===`file`)v(f);else if(!r.folders)throw y(`not-allowed`,`the kit may not read folders`)}if(a.includes(`create`)&&(!l||l.kind===`file`)){if(l)throw y(`not-allowed`,`a create grant never names an existing file`);C(f)}return u(d(n,l,[...new Set(a)],o,l?.kind===`folder`?{accept:r.read}:{}))},revoke:async t=>{let n=[];for(let e of t){let t=o.get(e);t&&(await h(t),n.push(e))}n.length&&e.revoked?.(n)},grants:()=>[...o.values()].map(({handle:e,session:t,kit:n,principal:r,flow:i,rights:a,kind:o,name:s})=>({handle:e,session:t,kit:n,principal:r,flow:i,rights:[...a],kind:o,name:s})),serve:async(t,n)=>{if(e.trace?.(t,n),s)throw y(`file-not-granted`,`the session has ended`);return V[t](n)},end:async()=>{s=!0;for(let e of[...o.values()])await h(e)}}}function N(e){if(/^([A-Za-z]:)?[\\/]/.test(e))return null;let t=[];for(let n of e.replace(/\\/g,`/`).split(`/`))if(n&&n!==`.`){if(n===`..`){if(!t.length)return null;t.pop()}else t.push(n)}return t.length?t.join(`/`):null}function P(e,t,n){let r=N(e),i=[];for(let a of n){let n=typeof a?.path==`string`?N(a.path):null;if(!n||n===r||n.split(`/`).some(e=>e.startsWith(`.`)))continue;let o=n.split(`/`).pop(),s=o.includes(`.`)?o.slice(o.lastIndexOf(`.`)+1).toLowerCase():``;if(!t.accept.includes(s))continue;let c={path:m(e,n),name:o,version:typeof a.version==`string`?a.version:null};if(i.some(e=>e.path===c.path)||i.push(c),!t.multiple)break}return i}function F(e){throw new f(-32601,`${e} is not supported by this host`)}function I(t,m){let{handlers:y}=m,b={agent:y.openAgent,"pick-file":y.pick,replica:y.replicaRead&&y.replicaWrite,customize:y.customize,lease:y.leases,presence:y.presence},x=Object.entries(b).filter(([,e])=>e).map(([e])=>e);y.generate&&x.push(`generate`),y.open&&x.push(`open-file`),y.openUrl&&x.push(`open-url`);let S=m.document.readOnly===!0;y.pickLinks&&!S&&x.push(`links-pick`),y.fetchImage&&!S&&x.push(`fetch-image`);let C=Object.entries(y.actions??{}).filter(([,e])=>typeof e==`function`);x.push(...C.map(([e])=>`${l}${e}`));let w=Object.entries(y.services??{}).filter(([e,t])=>typeof t==`function`&&s.includes(e)&&r(e,m.document));x.push(...w.map(([e])=>`${g}${e}`)),y.comments&&x.push(`comment-anchors`),m.files&&x.push(`files`,...m.files.pick?[`files-pick`]:[],...m.files.print?[`print`]:[]);let T=m.timeoutMs??12e4,E=(t,r)=>{let o=new MessageChannel,s=new h(o.port1,`h`),l=null;s.handle(`host/read`,e=>y.read(e)),s.handle(`host/stamp`,e=>y.stamp(e)),s.handle(`host/write`,e=>y.write(e)),s.handle(`host/pick`,e=>y.pick?y.pick(e):F(`host/pick`)),s.handle(`host/openAgent`,async e=>(y.openAgent||F(`host/openAgent`),await y.openAgent(e),{}));let{replicaRead:g,replicaWrite:b}=y;s.handle(`host/replicaRead`,e=>g&&b?g(e):F(`host/replicaRead`)),s.handle(`host/replicaWrite`,async e=>((!g||!b)&&F(`host/replicaWrite`),await b(e),{})),s.handle(`host/customize`,async e=>(y.customize||F(`host/customize`),await y.customize(e),{})),s.handle(`host/leaseAcquire`,e=>y.leases?y.leases.acquire(e):F(`host/leaseAcquire`)),s.handle(`host/leaseRelease`,async e=>(y.leases||F(`host/leaseRelease`),await y.leases.release(e),{})),s.handle(`host/leases`,async()=>(y.leases||F(`host/leases`),{leases:await y.leases.list()})),s.handle(`host/generate`,e=>{if(y.generate||F(`host/generate`),!n(e?.purpose,l))throw new f(-32e3,`a kit may not generate for ${JSON.stringify(e?.purpose)}`,{reason:`not-allowed`});return y.generate(e)}),s.handle(`host/action`,e=>{let t=typeof e?.id==`string`?C.find(([t])=>t===e.id)?.[1]:void 0;if(!t)throw new f(-32e3,`this host does not serve the action ${String(e?.id)}`,{reason:`not-allowed`});return t(e.params&&typeof e.params==`object`?e.params:{})}),s.handle(`host/open`,async e=>{y.open||F(`host/open`);let t=v(e);if(!t)throw new f(-32602,`host/open needs a link with a path, a name, or a docId`);return{opened:(await y.open(t))?.opened!==!1}}),s.handle(`host/openUrl`,async t=>{if(y.openUrl||F(`host/openUrl`),!e(t?.url))throw new f(-32e3,`a host opens only https:, http:, and mailto: addresses`,{reason:`not-allowed`});return{opened:(await y.openUrl({url:t.url}))?.opened!==!1}}),s.handle(`host/fetchImage`,async e=>{if(y.fetchImage||F(`host/fetchImage`),S)throw new f(-32e3,`a read-only document fetches no pictures`,{reason:`read-only`});if(!i(e?.url))throw new f(-32e3,`a host fetches only https: and http: addresses`,{reason:`not-allowed`});let t=await y.fetchImage({url:e.url});if(!(t?.bytes instanceof ArrayBuffer)||!a.includes(t.mime))throw new f(-32e3,`${e.url} is not a picture`,{reason:`unsupported`});return{bytes:t.bytes,mime:t.mime}}),s.handle(`links/pick`,async e=>{if(y.pickLinks||F(`links/pick`),S)throw new f(-32e3,`a read-only document links no files`,{reason:`read-only`});let t=u(e);if(!t)throw new f(-32602,`links/pick needs a purpose and at least one extension without the dot`);return{links:P(m.document.path,t,await y.pickLinks(t)??[])}});let T=m.files?M({...m.files,readOnly:S,revoked:e=>s.notify(`files/revoked`,{handles:e})}):null;if(T)for(let e of j)s.handle(e,t=>T.serve(e,t));s.on(`document/conflicts`,e=>y.conflicts?.(e)),s.on(`document/schema`,e=>{let t=c(e);t&&y.schema?.(t)}),s.on(`draft/changed`,e=>y.draftChanged?.(e)),s.on(`presence/set`,e=>{let t=p(e);t&&y.presence?.(t)}),s.on(`document/changed`,e=>y.changed(e)),s.on(`replica/changed`,e=>y.replicaChanged?.(e)),s.on(`host/notify`,e=>y.notify?.(e)),s.on(`host/shortcut`,e=>y.shortcut?.(e)),s.on(`ui/action`,e=>y.action?.(e)),s.handle(`host/service`,e=>{let t=e?.service,n=w.find(([e])=>e===t)?.[1];if(!n)throw new f(-32e3,`this host does not serve ${String(t)}`,{reason:`not-allowed`});let r=_(e);if(!r)throw new f(-32602,`bad params for ${String(t)}`);return n(r.params)}),s.on(`comments/activated`,e=>{typeof e?.id==`string`&&e.id&&y.comments?.activated(e.id)}),t.postMessage({kitionKitUi:1,protocol:d,id:r},m.origin,[o.port2]);let E={...m.document,bytes:m.document.bytes?.slice(0)},D=s.request(`ui/initialize`,{protocol:d,host:m.host,document:E,theme:m.theme,locale:m.locale,shortcuts:m.shortcuts,capabilities:x,capabilitySets:m.capabilitySets??[],ui:m.ui},{transfer:!0});return D.then(e=>{l=typeof e?.kit?.id==`string`?e.kit.id:null},()=>{}),{peer:s,files:T,initialized:D}};return new Promise((e,n)=>{let r=null,i=e=>{e?.peer.close(),e?.files?.end()},a=()=>{clearTimeout(c),window.removeEventListener(`message`,l),m.signal?.removeEventListener(`abort`,s)},s=()=>{a(),i(r),n(Error(`the kit mount was abandoned`))};if(m.signal?.aborted){n(Error(`the kit mount was abandoned`));return}m.signal?.addEventListener(`abort`,s);let c=setTimeout(()=>{a(),i(r),n(Error(`the kit did not open the document in time`))},T),l=s=>{if(s.source!==t.contentWindow||!o(s.data)||s.data.ready!==`kition-kit-ui/1`||m.origin!==`*`&&s.origin!==m.origin||r?.id===s.data.id)return;i(r);let{peer:c,files:l,initialized:u}=E(s.source,s.data.id);r={peer:c,files:l,id:s.data.id},u.then(t=>{r?.peer===c&&(a(),e(L(c,t,l)))},e=>{r?.peer===c&&(a(),l?.end(),n(e instanceof Error?e:Error(String(e))))})};window.addEventListener(`message`,l),t.contentWindow?.postMessage({kitionKitUi:1,hello:d},m.origin)})}function L(e,n,r){return{kit:n.kit,capabilities:n.capabilities,state:()=>e.request(`document/state`,{}),save:()=>e.request(`document/save`,{}),fileChanged:t=>e.notify(`document/fileChanged`,{version:t}),fileHeld:t=>e.notify(`document/held`,{version:t}),setTheme:t=>e.notify(`ui/theme`,{theme:t}),setLocale:t=>e.notify(`ui/locale`,{locale:t}),focus:()=>e.notify(`ui/focus`,{}),configure:t=>e.notify(`ui/configure`,{ui:t}),leasesChanged:t=>e.notify(`lease/changed`,{leases:t}),peersChanged:t=>e.notify(`presence/peers`,{peers:t}),reveal:t=>e.notify(`document/reveal`,{view:t}),showComments:n=>{let r=n.flatMap(e=>{let n=t(e.anchor);return n&&typeof e.id==`string`?[{id:e.id,anchor:n,resolved:e.resolved===!0,count:Number.isSafeInteger(e.count)?e.count:0}]:[]});e.notify(`comments/show`,{threads:r})},locateComments:async t=>{if(!n.capabilities.includes(`comment-anchors`))return t.map(()=>!1);let{found:r}=await e.request(`comments/locate`,{anchors:t});return t.map((e,t)=>r?.[t]===!0)},onPresence:t=>e.on(`presence/set`,e=>{let n=p(e);n&&t(n)}),elements:()=>e.request(`ui/elements`,{}),check:async t=>n.capabilities.includes(`check`)?(await e.request(`document/check`,t?.draft?{draft:!0}:{})).diagnostics:[],ai:{inspect:t=>e.request(`ai/inspect`,t??{}),commands:t=>e.request(`ai/commands`,{query:t}),run:(t,n,r)=>e.request(`ai/run`,{steps:t,save:n,...r?.draft?{draft:!0}:{},...r?.origin?{origin:r.origin}:{},...r?.originLabel==null?{}:{originLabel:r.originLabel}}),preview:(t,n)=>e.request(`ai/preview`,n?.draft?{maxSize:t,draft:!0}:{maxSize:t}),version:async()=>(await e.request(`ai/version`,{})).version,premise:(t,n)=>e.request(`ai/premise`,{method:t,params:n}),changes:(t,n)=>e.request(`ai/changes`,n?{since:t,schema:n}:{since:t})},draft:{state:()=>e.request(`draft/state`,{}),ready:()=>e.request(`draft/ready`,{}),reopen:()=>e.request(`draft/reopen`,{}),compare:t=>e.request(`draft/compare`,t??{}),merge:(t,n)=>e.request(`draft/merge`,n?{origin:t,schema:n}:{origin:t}),discard:()=>e.request(`draft/discard`,{})},replica:{version:async()=>(await e.request(`replica/version`,{})).version,exportChanges:t=>e.request(`replica/export`,{since:t}),importChanges:(t,n)=>e.request(`replica/import`,{changes:t,blobs:n}),info:async()=>(await e.request(`replica/info`,{})).docId,onChanged:t=>e.on(`replica/changed`,e=>t(e.version))},model:{describe:t=>e.request(`model/describe`,t?{schema:t}:{}),batch:t=>e.request(`model/batch`,t)},files:r&&{grant:r.grant,revoke:r.revoke,grants:r.grants},close:()=>{e.close(),r?.end()}}}var R=new Set([`purpose`,`title`]),z=new Set([`mime`]),B=/^(application|audio|example|font|haptics|image|message|model|multipart|text|video)\/[a-z0-9][a-z0-9!#$&^_.+-]{0,126}(\s*;\s*[a-z0-9!#$&^_.+-]+=("[^"\\/]*"|[^\s;"\\/]+))*$/i,V=/(^|[\s"'(=])(\/(?:Users|home|root|var|tmp|private|Volumes|mnt|media|etc|opt|srv|data|workspace)\b|[A-Za-z]:[\\/]|\\\\[^\\\s]|~[\\/]|file:)/i;function H(e,t=!1){return V.test(e)?!0:!t&&(/[\\/]/.test(e)||/^\.\.?$/.test(e))}function U(e){return B.test(e)}function W(e,t,n,r,i=0){if(typeof e==`string`)(n===`mime`?!U(e)&&H(e):H(e,n===`free`))&&r.push({at:t,value:e});else if(!(typeof e!=`object`||!e||i>8||e instanceof ArrayBuffer||ArrayBuffer.isView(e))){if(Array.isArray(e))e.forEach((e,a)=>W(e,`${t}[${a}]`,n,r,i+1));else for(let[n,a]of Object.entries(e))W(a,t?`${t}.${n}`:n,R.has(n)?`free`:z.has(n)?`mime`:`name`,r,i+1)}}function G(e){let t=[];for(let{method:n,params:r}of e){if(!n.startsWith(`files/`))continue;let e=[];W(r,``,`name`,e);for(let r of e)t.push({method:n,...r})}return t}var K={pdf:`application/pdf`,png:`image/png`,jpg:`image/jpeg`,jpeg:`image/jpeg`,gif:`image/gif`,webp:`image/webp`,svg:`image/svg+xml`,txt:`text/plain`,json:`application/json`},q=e=>e.split(`/`).some(e=>e.startsWith(`.`)||e===``),J=e=>e.includes(`/`)?e.slice(0,e.lastIndexOf(`/`)):``;function Y(e,t,n=new Set){let r=t=>n.has(t)||[...e.keys()].some(e=>e.startsWith(`${t}/`));return{stat:t=>{if(q(t))return null;let n=e.get(t);if(n){let e=K[t.split(`.`).pop()?.toLowerCase()??``];return{kind:`file`,size:n.bytes.byteLength,version:String(n.version),...e?{mime:e}:{}}}return r(t)?{kind:`folder`,version:null}:null},read:async(t,n,r)=>{let i=q(t)?void 0:e.get(t);if(!i)throw y(`file-not-granted`,`the file is gone`);let a=r===void 0?i.bytes.byteLength:Math.min(i.bytes.byteLength,n+r);return{bytes:i.bytes.slice(n,a),version:String(i.version),size:i.bytes.byteLength}},list:t=>{let r=new Set;for(let i of[...e.keys(),...n]){if(!i.startsWith(`${t}/`)||q(i))continue;let e=i.slice(t.length+1);r.add(`${t}/${e.split(`/`)[0]}`)}return[...r].sort()},child:(e,n)=>{let r=e??t();return r?`${r}/${n}`:n},commit:async(t,i,a)=>{let o=e.get(t);if(a.mode===`create`&&(o||r(t)))throw y(`conflict`,`a file with this name exists`);if(a.mode===`replace`&&(!o||String(o.version)!==a.expected))throw y(`conflict`,`the file changed since it was read`);!r(J(t))&&J(t)!==``&&n.add(J(t));let s=(o?.version??0)+1;return e.set(t,{bytes:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength),version:s}),{version:String(s)}}}}var X={light:{colorScheme:`light`,tokens:{"--kit-primary":`#5645d4`,"--kit-surface":`#ffffff`,"--kit-surface-muted":`#fafaf9`,"--kit-canvas":`#f6f5f4`,"--kit-text":`#1a1a1a`,"--kit-text-muted":`#5d5b54`,"--kit-border":`#e5e3df`}},dark:{colorScheme:`dark`,tokens:{"--kit-primary":`#8b7ff0`,"--kit-surface":`#1b1e23`,"--kit-surface-muted":`#22262c`,"--kit-canvas":`#15171b`,"--kit-text":`#eceff1`,"--kit-text-muted":`#a9b0ba`,"--kit-border":`#33373e`}}};function Z(e,t){let n=t.split(`.`).pop()?.toLowerCase()??``;return!e?.length||e.some(e=>e.replace(/^\./,``).toLowerCase()===n)}function ee(e){return e!==`viewer`&&e!==`commenter`?{}:{readOnly:!0,comments:{me:`dev-${e}`,name:e===`viewer`?`Viewer`:`Commenter`,canComment:e===`commenter`,othersReadOnly:!1}}}function Q(e){let t=[];for(let n of e.split(`/`))if(n&&n!==`.`){if(n===`..`){if(!t.length)return null;t.pop()}else t.push(n)}return t.join(`/`)}function te(e,t,n){let r=t.includes(`/`)?t.slice(0,t.lastIndexOf(`/`)):``;if(e.path){let t=Q(e.path.startsWith(`/`)?e.path:`${r}/${e.path}`);return t?{path:t,exists:n.has(t)}:null}if(!e.name||e.name.includes(`/`))return null;let i=t.includes(`.`)?t.slice(t.lastIndexOf(`.`)):``,a=e=>(e.split(`/`).pop()??``).replace(/\.[^.]*$/,``).toLowerCase(),o=[...n.keys()].filter(t=>a(t)===e.name.toLowerCase()),s=o.find(e=>e.endsWith(i))??o[0];if(s)return{path:s,exists:!0};let c=Q(`${r}/${e.name}${i}`);return c?{path:c,exists:!1}:null}var $=[`menus`,`line`,`classic`,`focus`];function ne(e){let t=[];for(let n of(e??``).split(`,`).map(e=>e.trim()).filter(Boolean))$.includes(n)?t.push(n):console.warn(`kit-dev-host: ?modes= names an unknown display mode "${n}" (one of ${$.join(`, `)})`);return t.length?{allowed:t,default:t[0]}:void 0}function re(e={}){let t=new Map,n=document.getElementById(`kit`),r=document.getElementById(`status`),i=document.getElementById(`file`),a=[],o=e.entry??`./index.html`,s=e.pickable??/\.(png|jpe?g|gif|svg|webp)$/i,c=null,l=e.presence===!0||new URLSearchParams(location.search).get(`presence`)===`1`,u=[],d=[],p=[],m=new Set,h=[],g=[],_=[],v=[],y=e.generate===!0||new URLSearchParams(location.search).get(`generate`)===`1`,b=[],x=[],S=e.open===!0||new URLSearchParams(location.search).get(`open`)===`1`,C=[],w=[],T=[],E=``,D=`kit-dev-host:personal:${location.pathname}`,O=[],k=new URLSearchParams(location.search).get(`scheme`)===`dark`?`dark`:`light`,A=ne(new URLSearchParams(location.search).get(`modes`)),j=A?{modes:A}:{},M=()=>{try{return JSON.parse(localStorage.getItem(D)??`[]`)}catch{return[]}},N=()=>({...j,personal:{hide:M()}}),P=document.createElement(`details`);P.innerHTML=`<summary>UI configuration</summary><textarea rows="6" cols="60" spellcheck="false">{}</textarea><button type="button">Apply</button><select><option value="light">Light</option><option value="dark">Dark</option></select>`,r.parentElement?.append(P);let F=P.querySelector(`textarea`),L=P.querySelector(`select`);L.value=k,P.querySelector(`button`).addEventListener(`click`,()=>{try{R(JSON.parse(F.value))}catch(e){r.textContent=`configuration: ${e instanceof Error?e.message:String(e)}`}}),L.addEventListener(`change`,()=>z(L.value===`dark`?`dark`:`light`));function R(e){j={hide:e.hide,disable:e.disable,add:e.add,modes:e.modes??A},F.value=JSON.stringify(j,null,2),c?.configure(N())}function z(e){k=e,L.value=e,c?.setTheme(X[e])}async function B(i,f,b={}){c?.close(),E=i,t.set(i,{bytes:f,version:1}),r.textContent=`opening ${i}…`,n.src=`${o}?${Date.now()}`;let x=t.get(i);try{c=await I(n,{origin:location.origin,host:{name:`Development host`,version:`1`},document:{path:i,name:i.split(`/`).pop()??i,bytes:x.bytes.slice(0),version:String(x.version),lend:e.lend?{root:new URL(e.lend.root,location.href).href,folder:e.lend.folder}:void 0,...ee(new URLSearchParams(location.search).get(`role`)),...b.view?{view:b.view}:{}},theme:X[k],locale:new URLSearchParams(location.search).get(`locale`)??navigator.language,shortcuts:[`Cmd+W`,`Cmd+N`,`Cmd+O`,`Cmd+,`],ui:N(),handlers:{read:({path:e,offset:n,length:r})=>{let i=t.get(e);if(!i)throw Error(`${e} is not in the workspace`);let a=n??0;return{bytes:n!=null||r!=null?i.bytes.slice(a,r==null?void 0:a+r):i.bytes.slice(0),version:String(i.version),size:i.bytes.byteLength}},stamp:({path:e})=>({version:t.has(e)?String(t.get(e).version):null}),write:({path:e,bytes:n,mode:r})=>{let i=e;if(r!==`save`)for(let n=2;t.has(i);n+=1)i=e.replace(/(\.[^./]+)?$/,` ${n}$1`);let a=(t.get(i)?.version??0)+1;return t.set(i,{bytes:n,version:a}),{path:i,version:String(a)}},pick:({accept:e})=>({path:[...t.keys()].find(t=>s.test(t)&&Z(e,t))??null}),pickLinks:e=>{T.push(e);let n=w.shift();return(n?typeof n==`function`?n(e):n:[...t.keys()].filter(t=>t!==i&&s.test(t)&&Z(e.accept,t))).filter(e=>t.has(e)).map(e=>({path:e,version:String(t.get(e).version)}))},openAgent:()=>{r.textContent=`the editor asked for the agent`},changed:e=>{a.push(e),r.textContent=`${i}: revision ${e.revision}${e.dirty?`, unsaved`:``}`},notify:e=>{r.textContent=`${e.level}: ${e.title}`},shortcut:e=>{r.textContent=`host shortcut ${e.key}`},customize:({personal:e})=>{localStorage.setItem(D,JSON.stringify(e.hide))},action:e=>{O.push(e),r.textContent=`host button ${e.id}`},schema:e=>{d.push(e)},...l?{presence:e=>void u.push(e)}:{},...y?{generate:e=>V(e)}:{},...S?{open:e=>H(e),openUrl:e=>U(e)}:{}},...e.kitFiles?{files:{storage:Y(t,()=>E.includes(`/`)?E.slice(0,E.lastIndexOf(`/`)):``,m),kit:`dev-kit`,principal:`dev-person`,manifest:e.kitFiles,pick:async e=>{let t=h.shift();return typeof t==`function`?t(e):t??[]},print:async({bytes:e,title:t})=>(v.push({title:t,size:e.byteLength}),window.devHost.printAnswer),log:e=>void g.push(e),trace:(e,t)=>void _.push({method:e,params:t})}}:{}}),l&&p.length&&c.peersChanged(p),r.textContent=`${i} open in ${c.kit.id} ${c.kit.version}`}catch(e){r.textContent=`could not open ${i}: ${e instanceof Error?e.message:String(e)}`}}async function V(e){b.push(e),r.textContent=`the editor asked to generate for ${e.purpose}`;let t=x.shift()??{refuse:`unavailable`},n=typeof t==`function`?await t(e):t;if(`refuse`in n)throw new f(-32e3,`the development host refused: ${n.refuse}`,{reason:n.refuse});return n}async function H(e){C.push({method:`host/open`,params:e}),r.textContent=`the editor asked to open ${JSON.stringify(e.link)}`;let n=te(e.link,E,t);if(!n)throw new f(-32e3,`the link is not in the workspace`,{reason:`not-found`});if(!n.exists){if(!e.create)throw new f(-32e3,`${n.path} is not in the workspace`,{reason:`not-found`});t.set(n.path,{bytes:new ArrayBuffer(0),version:1})}return{opened:window.devHost.openAnswer}}async function U(e){return C.push({method:`host/openUrl`,params:e}),r.textContent=`the editor asked to open ${e.url}`,{opened:window.devHost.openAnswer}}function W(e){p=e,l&&c?.peersChanged(e)}window.devHost={files:t,connection:()=>c,open:B,changes:a,configure:R,actions:O,setScheme:z,presences:u,setPeers:W,schemas:d,folders:m,scriptPick:(...e)=>void h.push(...e),grants:g,fileRequests:_,prints:v,printAnswer:!0,checkNoPaths:()=>G(_),generated:b,scriptGenerate:(...e)=>void x.push(...e),opens:C,openAnswer:!0,scriptLinkPick:(...e)=>void w.push(...e),linkPicks:T},i?.addEventListener(`change`,async()=>{let e=i.files?.[0];e&&await B(e.name,await e.arrayBuffer())}),(async()=>{for(let[n,r]of Object.entries(e.files??{})){let e=await fetch(r).catch(()=>null);e?.ok&&t.set(n,{bytes:await e.arrayBuffer(),version:1})}if(!e.sample){r.textContent=`choose a file`;return}let n=await fetch(e.sample).catch(()=>null);if(!n?.ok){r.textContent=`choose a file`;return}let i=decodeURIComponent(e.sample.split(`/`).pop()??`Sample`);await B(e.lend?.folder?`${e.lend.folder}/${i}`:i,await n.arrayBuffer())})()}re({sample:`./sample/Sample.ktable`});
|