@agentshouse/mdruntime-adapter 0.1.0-c13e5bc38b145 → 0.1.0-c159093d95310

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/AGENTS.md CHANGED
@@ -59,21 +59,25 @@ media type: Save keeps the bytes in its Pending Change, offline too, and accepta
59
59
  the record the Provider's revision. Move or remove one as a Document, a pending one too,
60
60
  its bytes following; once its Pending Change has gone to the Provider, Save refuses that
61
61
  as `unknown-revision` until it is accepted. `binaryFile.read(room, path, revision?)`
62
- answers a pending record's saved bytes, or asks the Provider on every read of an accepted
63
- one or a History revision, a removed file's last included, keeping nothing. Text, a Record
64
- attachment or a conversation message may name a file by its `fileRef`; read it with
65
- `binaryFile.readReference({ fileRef, referrer })`, the `referrer` the Provider gave beside
66
- it, or `{ room, path }` of the document whose text names it. Both answer
67
- `{ kind: 'binary', blob }` or a refusal or failure.
62
+ answers a pending record's saved bytes, or an accepted one's or a History revision's, a
63
+ removed file's last included: the first read asks the Provider and the browser keeps the
64
+ bytes, and every later read of that revision, offline too, answers them from the browser.
65
+ Text, a Record attachment or a conversation message may name a file by its `fileRef`; read
66
+ it with `binaryFile.readReference({ fileRef, referrer })`, the `referrer` the Provider gave
67
+ beside it, or `{ room, path }` of the document whose text names it, kept the same way. Both
68
+ answer `{ kind: 'binary', stream, byteLength, mediaType }`, the bytes a `ReadableStream`
69
+ of parts of at most a mebibyte, or a refusal or failure; read the stream to its end, or
70
+ take it whole with `new Response(stream).blob()` where a screen needs one `Blob`.
68
71
 
69
72
  Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never touch the
70
- network; History, the binary file reads and Call go to the Provider through the Adapter.
73
+ network; History, a binary file read the browser does not keep yet and Call go to the
74
+ Provider through the Adapter.
71
75
  Call takes the Action names the Adapter declares, any other answering `undeclared`. A Call
72
76
  result whose effect the Provider places in a Room carries `at`, that Room and Room
73
77
  Version: `reached(room, roomVersion)` answers whether the Room's confirmed state has
74
78
  reached it, refreshing the Room until it has, and `reached(room, roomVersion, path)`
75
79
  whether the held copy of that document was written later. A History revision names its
76
- author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`; History of a Path no
80
+ author, `{ kind: 'user', id }` or `{ kind: 'site' | 'inbox', id, name }`; History of a Path no
77
81
  document holds answers the removed document's revisions, newest first, with `deleted:
78
82
  true`, which a link to the Path opens. Every member is asynchronous and every result a
79
83
  detached snapshot; nothing returns the authorization, performs a request the App's code
@@ -122,36 +126,38 @@ draw it as loading and observe the query to hear the complete answer. A query is
122
126
  - **Relations.** Within one Room, `hop: { field, types, where, pathPrefix }` keeps Documents
123
127
  whose reference at pointer `field`, at any depth, points to a matching Document, and
124
128
  `backlinks` with the same keys those a matching Document references, each once. A body
125
- link, or a reference declaring `cross_room`, may name another Room's
126
- `/rooms/<handle>/<path>`: `resolve(room, path, destination)` answers its `document`, the
127
- `deleted` one's last `revision`, or `unreadable` where the App does not bind it or it is
128
- locked.
129
+ link or a `cross_room` reference may name another Room's `/rooms/<handle>/<path>`:
130
+ `resolve(room, path, destination)` answers its `document`, the `deleted` one's last
131
+ `revision`, or `unreadable` where the App does not bind it or it is locked.
129
132
  - **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
130
- `preamble`, `markdown`, `backlinks`, `change` and `fileId`, where `fields` is `'all'`
133
+ `preamble`, `markdown`, `backlinks`, `change`, `fileId` and `revision`, where `fields` is `'all'`
131
134
  or a list of pointers and `sections` `'all'` or a list of names. Selected pointers
132
135
  return the frontmatter holding only them, nested as written. A backlink names the
133
136
  referring Path, MD Type and the pointer it came from as `field`. Room and Path always
134
137
  return; a Markdown Document also returns its MD Type, and at most its first 1,000
135
138
  backlinks: a query on the referring field reads the rest. A non-Markdown Document
136
- returns only Room, Path and a selected `fileId`, and a binary Path entry its
137
- `binaryFile` record too. An unselected part is absent. Select only what a screen shows:
138
- a list that selects the Markdown hears every edit of it.
139
- - **Change and file ID.** `change` is `{ author, time }` of the Document's head revision
140
- as the Provider last delivered it: `author` is `{ kind: 'user' | 'site', id, name }`, or
139
+ returns only Room, Path and a selected `fileId` and `revision`, a binary Path entry its `binaryFile`
140
+ record too, and a YAML file under `settings/` its text as a selected `markdown`, kept
141
+ out of Search. An unselected part is absent. Select only what a screen shows: a list
142
+ that selects the Markdown hears every edit of it.
143
+ - **Change, file ID and revision.** `change` is `{ author, time }` of the Document's head revision
144
+ as the Provider last delivered it: `author` is `{ kind: 'user' | 'site' | 'inbox', id, name }`, or
141
145
  `null` for a write the Provider made itself, and `time` its ISO 8601 change time, or the
142
146
  whole change `null` where it delivered no time, as at a Site. `fileId` is the Provider's
143
147
  Stable File ID of the file at the Path, or `null`. An unsent edit keeps both, an unsent
144
148
  move keeps the change and carries the file ID to the new Path, so a file ID that leaves
145
149
  one Path for another is the same file moved, and an unsent creation has neither until it
146
- is Accepted. A Room's last change is its Document with the latest `time`.
147
- - **Order and groups.** `orderBy` sorts by `room`, `path`, `type`, `folder` or `{ field }`
148
- with TanStack DB's own options; ties end with Room, then Path. `groupBy` by `room`,
149
- `type`, `folder` or `{ field }` answers `{ groups: [{ key, count }] }`, counted over every
150
- match and ordered by `count` or a key. A sort or group takes only a single-value pointer.
151
- `limit`, at most 1,000 whatever a query names, bounds the Documents or the groups, and a
152
- result it cuts short names `next`: the same query with it as `after` reads the next
153
- window, in the same order, ties included. `total: true` adds `total`, every match's
154
- count. An observed window hears rows entering, leaving or changing, and `next`, `total`.
150
+ is Accepted. `revision` is the Provider's head revision, `null` for an unsent creation or edit,
151
+ and moves with an unsent move. A Room's last change is its Document with the latest `time`.
152
+ - **Order and groups.** `orderBy` sorts by `room`, `path`, `type`, `folder` or `{ field }`: missing
153
+ and null first, last with `nulls: 'last'`, then numbers and booleans, then text by `locale` or
154
+ code point with `stringSort: 'lexical'`, then lists item by item; ties end with Room, then Path.
155
+ `groupBy` by `room`, `type`, `folder` or `{ field }` answers `{ groups: [{ key, count }] }`,
156
+ counted over every match and ordered by `count` or a key. A sort or group takes only a
157
+ single-value pointer. `limit`, at most 1,000 whatever a query names, bounds the Documents or the
158
+ groups, and a result it cuts short names `next`: the same query with it as `after` reads the next
159
+ window, in the same order, ties included. `total: true` adds `total`, every match's count. An
160
+ observed window hears rows entering, leaving or changing, and `next`, `total`.
155
161
  - **Results and errors.** A result carries no Room Version: read freshness from Rooms and
156
162
  Sync Status. `coverage` names each Room read as `{ room, generation, current }`,
157
163
  `current` false while a newer copy of that Room is being fetched, and the queued changes
@@ -161,28 +167,36 @@ draw it as loading and observe the query to hear the complete answer. A query is
161
167
  ## Local Search rules
162
168
 
163
169
  `search({ text, documents, collection, conversations, limit, after, total })` answers
164
- once, by words, from local state, with MiniSearch's defaults. There is no observed search.
170
+ once, by words, from the full-text index the browser keeps with its local state, so it
171
+ answers at once after a reload. There is no observed search.
165
172
 
166
- - **Declaration.** Only an App whose release declares Local Search searches, its first
167
- readiness waiting for its index; any other App's `search` answers the never retryable
168
- `undeclared` refusal `search-undeclared`, its `fields` naming `local_search`.
173
+ - **Declaration.** Only an App whose release declares Local Search searches; any other
174
+ App's `search` answers the never retryable `undeclared` refusal `search-undeclared`, its
175
+ `fields` naming `local_search`.
169
176
  - **What is found.** A Document by its field values, its sections' headings and text, its
170
177
  preamble and its Path, and a message by its text, never a frontmatter key, a Room Draft,
171
- a chat draft or a running turn's parts, with no phrases, word forms, typo tolerance or
172
- prefix matching.
178
+ a chat draft or a running turn's parts. Any word found ranks a hit, more found rank it
179
+ higher, and adjacent words higher still; case and the marks of Latin, Greek and
180
+ Cyrillic letters fold, English word forms stem, the last word also matches as the start
181
+ of a word unless the text ends with a space, and Chinese, Japanese, Korean and Thai text
182
+ matches by character pairs. There is no typo tolerance and no operator syntax.
173
183
  - **Narrowing.** `documents` is a Local Query filter, and `collection: true` leaves out
174
184
  what each Room's `typedSelection` roots hold; `conversations` names conversations. All
175
185
  apply before `limit`, which bounds each list, at most 1,000 whatever a search names. A
176
186
  complete answer it cuts short names `next`, which `after` takes for the next window of
177
- both lists. `total: true` adds `total`, each list's count.
187
+ both lists. `total: true` adds `total`, each list's count. A word in very many Documents
188
+ ranks among a bounded set of them, the Documents of a rarer word of the search always
189
+ among them.
178
190
  - **Results.** `{ documents, messages, coverage }`, or the same with `pending` naming each
179
- Room or conversation the search still waits for: show its hits, ask again, and never
180
- read pending as no hits. `coverage` names the Rooms and conversations searched. Each
181
- list is ranked by `score`, comparable only within it; ties come by `room`, then `path`,
182
- or by `conversation`, then `identity`. A Document hit names its `room`, `path` and
183
- `type`, a message hit its `conversation` and `identity`; `matches` maps each matched
184
- word to the parts it matched in: `fields`, `sections`, `preamble`, `path` or `text`. A
185
- hit carries no position: mark the words you show. A bad filter fails as a query does.
191
+ Room the search still waits for: show its hits, ask again, and never read pending as no
192
+ hits. `coverage` names the Rooms and conversations searched. Each list is ranked by
193
+ `score`, comparable only within it; ties come by `room`, then `path`, or by
194
+ `conversation`, then `identity`. A Document hit names its `room`, `path` and `type`, a
195
+ message hit its `conversation` and `identity`; `matches` maps each word of the search
196
+ to the parts it was found in: `fields`, `sections`, `preamble`, `path` or `text`. A hit
197
+ whose words were found carries `snippet: { part, text, at }`: the part's text around
198
+ the first word found, at most 80 characters on either side, and `at` that word's start
199
+ and end in `text`. Mark the words you show. A bad filter fails as a query does.
186
200
 
187
201
  ## Room Draft, Save, and outcome rules
188
202
 
@@ -297,8 +311,9 @@ Mix `ChatMessageList` (`components` takes your `UserMessage` and `AssistantMessa
297
311
  `ChatInput` and `ChatQuestionCard` with your own design inside a `ChatProvider`, or
298
312
  compose assistant-ui's primitives there; `useChat()` gives `send`, the conversations, the
299
313
  Agents, questions to `answer`, `options` to `choose`, `commands`, the queue to `edit` or
300
- `unqueue`, `stop`, `kill` and outcomes; never replace its messages, sending or store. It
301
- shows a conversation's latest 50 messages, and assistant-ui's `loadEarlier()` the 50
302
- before, which `ChatMessageList` calls as the reader scrolls back. A secret question is
303
- never answered here; typed answers live in the Presentation State members named `typed:…`:
304
- leave them. `Markdown` draws Markdown safely.
314
+ `unqueue`, `stop`, `kill`, `renew`, which starts a new chat with the same Agent in place
315
+ of a conversation whose session could not resume, and outcomes; never replace its
316
+ messages, sending or store. It shows a conversation's latest 50 messages, and
317
+ assistant-ui's `loadEarlier()` the 50 before, which `ChatMessageList` calls as the reader
318
+ scrolls back. A secret question is never answered here; typed answers live in the
319
+ Presentation State members named `typed:…`: leave them. `Markdown` draws Markdown safely.
package/dist/actions.d.ts CHANGED
@@ -6,10 +6,11 @@ type Operated = {
6
6
  type ConversationControl = Operated & {
7
7
  readonly conversation: string;
8
8
  };
9
- type SentFile = FileDeclaration & {
10
- readonly blob: Blob;
11
- };
12
9
  export type AppInputs = {
10
+ readonly 'conversation.attach': FileDeclaration & {
11
+ readonly room: string;
12
+ readonly blob: Blob;
13
+ };
13
14
  readonly 'conversation.answer': ConversationControl & {
14
15
  readonly answer: {
15
16
  readonly interaction_id: string;
@@ -18,6 +19,7 @@ export type AppInputs = {
18
19
  };
19
20
  readonly 'conversation.create': Operated & {
20
21
  readonly agent_id: string;
22
+ readonly replaces?: string;
21
23
  };
22
24
  readonly 'conversation.delete': ConversationControl;
23
25
  readonly 'conversation.history': ConversationHistoryRequest;
@@ -25,14 +27,16 @@ export type AppInputs = {
25
27
  readonly 'conversation.kill': ConversationControl;
26
28
  readonly 'conversation.send': ConversationControl & {
27
29
  readonly operation_id: string;
28
- readonly text?: string;
29
- readonly files?: readonly SentFile[];
30
+ readonly text: string;
30
31
  };
31
32
  readonly 'trigger.list': {
32
33
  readonly room_refs: readonly string[];
33
34
  };
34
35
  };
35
36
  export type AppAnswers = {
37
+ readonly 'conversation.attach': {
38
+ readonly path: string;
39
+ };
36
40
  readonly 'conversation.history': ConversationHistories;
37
41
  };
38
42
  export type AppAnswerAdditions = {
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,aAA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+ import { finishedUpload, houseUpload } from './upload.js';
3
4
  const HISTORY_PAGE = 100;
4
5
  const HISTORY_CONVERSATIONS = 64;
5
6
  const TRIGGER_ROOMS = 100;
@@ -23,6 +24,7 @@ function carried(door, carry, batched, room) {
23
24
  const APP_ACTS = {
24
25
  'access.read': mapped('rooms/access/read'),
25
26
  'conversation.answer': mapped('conversations/interaction/answer', answerBody),
27
+ 'conversation.attach': carried('conversations/attach', attachAction, undefined, 'room'),
26
28
  'conversation.create': carried('conversations/create', createAction),
27
29
  'conversation.delete': mapped('conversations/delete', controlBody),
28
30
  'conversation.history': carried('conversations/history', historyAction, ['conversations']),
@@ -36,6 +38,9 @@ const APP_ACTS = {
36
38
  'feature.list': mapped('apps/features/read'),
37
39
  'holder.list': mapped('apps/holders'),
38
40
  'holder.ring': mapped('apps/ring'),
41
+ 'inboxChat.assign': mapped('chats/assign'),
42
+ 'inboxChat.return': mapped('chats/return'),
43
+ 'inboxChat.takeControl': mapped('chats/take-control'),
39
44
  'member.list': mapped('rooms/members'),
40
45
  'message.send': mapped('apps/messages/send'),
41
46
  'processing.read': mapped('rooms/settings/processing/read'),
@@ -105,7 +110,12 @@ function unimplemented(name) {
105
110
  return { kind: 'rejected', code: 'action-unimplemented', fields: { name }, retryable: false };
106
111
  }
107
112
  function createBody(input) {
108
- return { agent_id: text(input, 'agent_id'), operation_id: operationId(input) };
113
+ const replaces = text(input, 'replaces');
114
+ return {
115
+ agent_id: text(input, 'agent_id'),
116
+ operation_id: operationId(input),
117
+ ...(replaces === undefined ? {} : { replaces }),
118
+ };
109
119
  }
110
120
  function controlBody(input) {
111
121
  return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };
@@ -182,106 +192,62 @@ async function recordsAction(transport, route, input, name) {
182
192
  async function carry(transport, route, name, input) {
183
193
  return actionOutcome(await transport.door(route, input), name);
184
194
  }
185
- function sendFile(entry) {
186
- const file = record(entry);
187
- const name = text(file, 'name');
188
- const bytes = file.byteLength;
189
- const sha256 = text(file, 'contentHash');
190
- if (name === undefined || typeof bytes !== 'number' || sha256 === undefined)
191
- return null;
192
- const mediaType = text(file, 'mediaType');
193
- const width = file.width;
194
- const height = file.height;
195
- return {
196
- name,
197
- media_type: mediaType !== undefined && mediaType.length > 0 ? mediaType : OCTET_STREAM,
198
- bytes,
199
- sha256,
200
- ...(typeof width === 'number' && typeof height === 'number'
201
- ? { dimensions: { width, height } }
202
- : {}),
203
- };
204
- }
205
- function sendFiles(input) {
206
- const files = record(input).files;
207
- if (files === undefined)
208
- return [];
209
- if (!Array.isArray(files))
210
- return null;
211
- const declared = [];
212
- for (const entry of files) {
213
- const file = sendFile(entry);
214
- if (file === null)
215
- return null;
216
- declared.push(file);
217
- }
218
- return declared;
219
- }
220
195
  function sendBody(input) {
221
- const files = sendFiles(input);
222
196
  const operation = text(input, 'operation_id');
223
- if (files === null || operation === undefined)
197
+ const said = text(input, 'text');
198
+ if (operation === undefined || said === undefined)
224
199
  return null;
225
- const textValue = text(input, 'text');
226
- return {
227
- conversation_id: text(input, 'conversation'),
228
- operation_id: operation,
229
- ...(textValue !== undefined && textValue.length > 0 ? { text: textValue } : {}),
230
- ...(files.length === 0 ? {} : { files }),
231
- };
200
+ return { conversation_id: text(input, 'conversation'), operation_id: operation, text: said };
232
201
  }
233
- async function fileBytes(file) {
234
- const blob = record(file).blob;
235
- if (blob === undefined || typeof blob !== 'object' || blob === null)
236
- return null;
237
- if (!('arrayBuffer' in blob) || typeof blob.arrayBuffer !== 'function')
238
- return null;
239
- return new Uint8Array(await blob.arrayBuffer());
202
+ async function sendAction(transport, route, input, name) {
203
+ const body = sendBody(input);
204
+ if (body === null)
205
+ return malformed();
206
+ const outcome = actionOutcome(await transport.door(route, body), name);
207
+ if (outcome.kind !== 'action')
208
+ return outcome;
209
+ return { ...outcome, result: withTurn(outcome.result) };
240
210
  }
241
- function uploadGrant(entry) {
242
- if (!('upload' in record(entry)))
243
- return 'absent';
244
- const upload = record(record(entry).upload);
245
- if (upload.method !== 'POST')
211
+ function attachBody(input) {
212
+ const room = text(input, 'room');
213
+ const name = text(input, 'name');
214
+ const sha256 = text(input, 'contentHash');
215
+ const bytes = record(input).byteLength;
216
+ if (room === undefined || name === undefined || sha256 === undefined)
246
217
  return null;
247
- if (typeof upload.operation !== 'string' || typeof upload.url !== 'string')
218
+ if (typeof bytes !== 'number')
248
219
  return null;
249
- return { method: 'POST', operation: upload.operation, url: upload.url };
250
- }
251
- async function uploadFiles(transport, input, result) {
252
- const sent = record(result).files;
253
- if (!Array.isArray(sent))
254
- return true;
255
- const files = Array.isArray(record(input).files) ? record(input).files : [];
256
- for (const [index, entry] of sent.entries()) {
257
- const grant = uploadGrant(entry);
258
- if (grant === 'absent')
259
- continue;
260
- const bytes = index < files.length ? await fileBytes(files[index]) : null;
261
- if (grant === null || bytes === null)
262
- return false;
263
- const answer = await transport.transfer({
264
- act: 'conversation_file_upload',
265
- url: grant.url,
266
- body: bytes,
267
- operation: grant.operation,
268
- });
269
- if (answer.status !== 200)
270
- return false;
271
- }
272
- return true;
220
+ const mediaType = text(input, 'mediaType');
221
+ return {
222
+ room_ref: room,
223
+ name,
224
+ bytes,
225
+ sha256,
226
+ media_type: mediaType !== undefined && mediaType.length > 0 ? mediaType : OCTET_STREAM,
227
+ };
273
228
  }
274
- async function sendAction(transport, route, input, name) {
275
- const body = sendBody(input);
276
- if (body === null)
229
+ async function attachAction(transport, route, input, name) {
230
+ const body = attachBody(input);
231
+ const blob = record(input).blob;
232
+ if (body === null || !(blob instanceof Blob))
277
233
  return malformed();
278
234
  const outcome = actionOutcome(await transport.door(route, body), name);
279
235
  if (outcome.kind !== 'action')
280
236
  return outcome;
281
- if (!(await uploadFiles(transport, input, outcome.result))) {
237
+ const upload = houseUpload(record(outcome.result).upload);
238
+ if (upload === null)
282
239
  return { kind: 'transport-uncertainty' };
283
- }
284
- return { ...outcome, result: withTurn(outcome.result) };
240
+ const finished = await finishedUpload(transport, upload, blob);
241
+ if (finished === null)
242
+ return { kind: 'transport-uncertainty' };
243
+ const settled = actionOutcome(finished, name);
244
+ if (settled.kind !== 'action')
245
+ return settled;
246
+ const path = text(settled.result, 'path');
247
+ if (path === undefined)
248
+ return { kind: 'transport-uncertainty' };
249
+ const result = { path };
250
+ return { kind: 'action', result };
285
251
  }
286
252
  function historyCursor(value) {
287
253
  const acceptedAt = text(value, 'accepted_at');
@@ -305,19 +271,12 @@ export function acceptedMessage(entry) {
305
271
  const cursor = historyCursor(entry);
306
272
  if (cursor === null)
307
273
  return null;
308
- const message = structuredClone(record(entry));
309
- const referrer = { message: cursor.message_id };
310
274
  return {
311
275
  identity: cursor.message_id,
312
276
  turn: text(entry, 'turn_id') ?? cursor.message_id,
313
277
  position: position(cursor),
314
278
  text: text(entry, 'text') ?? '',
315
- message: Array.isArray(message.files)
316
- ? {
317
- ...message,
318
- files: message.files.map((file) => ({ ...record(file), referrer })),
319
- }
320
- : message,
279
+ message: structuredClone(record(entry)),
321
280
  };
322
281
  }
323
282
  function historyPage(entry) {
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,OAAO,EACP,aAAa,EAmBd,MAAM,wBAAwB,CAAC;AA6ChC,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AA0BxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAyFrD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA8mBpF"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,OAAO,EACP,aAAa,EAmBd,MAAM,wBAAwB,CAAC;AAwChC,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AA2BxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AA4ErD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAknBpF"}