@ember-marquetry/ember 0.0.0-stage → 2.0.0
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/CHANGELOG.md +39 -0
- package/LICENSE.md +21 -0
- package/NOTICE +13 -0
- package/README.md +111 -2
- package/addon-main.cjs +4 -0
- package/declarations/components/confirm.d.ts +24 -0
- package/declarations/components/confirm.d.ts.map +1 -0
- package/declarations/components/element.d.ts +53 -0
- package/declarations/components/element.d.ts.map +1 -0
- package/declarations/components/fallback.d.ts +19 -0
- package/declarations/components/fallback.d.ts.map +1 -0
- package/declarations/components/render.d.ts +113 -0
- package/declarations/components/render.d.ts.map +1 -0
- package/declarations/components/skeleton.d.ts +13 -0
- package/declarations/components/skeleton.d.ts.map +1 -0
- package/declarations/context.d.ts +33 -0
- package/declarations/context.d.ts.map +1 -0
- package/declarations/errors.d.ts +37 -0
- package/declarations/errors.d.ts.map +1 -0
- package/declarations/generation.d.ts +85 -0
- package/declarations/generation.d.ts.map +1 -0
- package/declarations/i18n.d.ts +16 -0
- package/declarations/i18n.d.ts.map +1 -0
- package/declarations/index.d.ts +11 -0
- package/declarations/index.d.ts.map +1 -0
- package/declarations/messages.d.ts +39 -0
- package/declarations/messages.d.ts.map +1 -0
- package/declarations/registry.d.ts +75 -0
- package/declarations/registry.d.ts.map +1 -0
- package/declarations/state-store.d.ts +26 -0
- package/declarations/state-store.d.ts.map +1 -0
- package/dist/index.js +969 -0
- package/dist/index.js.map +1 -0
- package/package.json +91 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @ember-marquetry/ember
|
|
2
|
+
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8c811bd: Publish through OIDC trusted publishing only, with the Ember Workbench release kit. Each version from this release on has npm provenance.
|
|
8
|
+
- Updated dependencies [8c811bd]
|
|
9
|
+
- @ember-marquetry/core@2.0.0
|
|
10
|
+
|
|
11
|
+
## 1.0.0
|
|
12
|
+
|
|
13
|
+
### Major Changes
|
|
14
|
+
|
|
15
|
+
- 8f2790b: The first release of Marquetry: generative UI for Ember.
|
|
16
|
+
|
|
17
|
+
- `core`: the spec format, the JSONL patch stream, expressions, actions, the catalog, agent events, chat threads and stream replay.
|
|
18
|
+
- `ember`: the `<Render>` component and the `Generation` state machine.
|
|
19
|
+
- `joinery`: a catalog of 69 Joinery components, with layout templates and the chart, data table and code block add-ons. The `/a2ui` subpath is the A2UI v0.9.1 basic catalog on Joinery components, for the specs of `a2ui`.
|
|
20
|
+
- `chat`: a chat thread on Joinery components, with streamed markdown, agent surfaces, tool calls, approvals and MCP Apps.
|
|
21
|
+
- `formwright`: forms with validation from a JSON Schema, field rules and named validators.
|
|
22
|
+
- `inspector`: a dev panel for `<Render>` that shows the spec, the patches with their line numbers, the state and the problems.
|
|
23
|
+
- `ai-sdk`, `ag-ui`, `a2ui` and `sse`: adapters and chat transports for the AI SDK, AG-UI 1.0, A2UI v0.9.1 and plain JSONL or SSE endpoints.
|
|
24
|
+
- `markdown`: a streamed markdown parser that makes no HTML.
|
|
25
|
+
- `mcp-apps`: a host for MCP Apps in a sandbox frame on a second origin.
|
|
26
|
+
- `eslint-plugin`, `skills`, `test-support` and the `ember-marquetry` CLI: tools for catalog authors and app developers.
|
|
27
|
+
|
|
28
|
+
Safety defaults in 1.0:
|
|
29
|
+
|
|
30
|
+
- `joinery`: a URL that the browser loads with no click (the `src` of `Image` and `Avatar`, the `image` of `Attachment`, and the `url` of the A2UI `Image`, `Video` and `AudioPlayer`) must be relative, unless `urls.mediaHosts` lists its host. `isSafeMediaUrl` is the check. `urls.hosts` applies only to links.
|
|
31
|
+
- `markdown` and `chat`: an image must pass `isSafeImageUrl` (`<Chat @isSafeImageUrl>`, `<Markdown @isSafeImageUrl>`). The default, `isRelativeUrl`, accepts only a relative URL. A block of more than 20,000 characters is plain text.
|
|
32
|
+
- `chat`: `<McpApp>` and `McpAppsConfig` have `approveDomain`. Without it, the app gets no domain that it declares in its CSP. An app cannot call a tool that needs the approval of the user (`@needsApproval`).
|
|
33
|
+
- `mcp-apps`: the proxy puts the CSP meta at offset 0 of the app HTML, and gives its own page a `frame-src` with only the approved frame domains.
|
|
34
|
+
- `ai-sdk` and `ag-ui`: a problem in one item is a `data` event named `stream-error`, and a value that the reader does not convert is a `data` event named `unconverted`. `error` is only for a failed run.
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- Updated dependencies [8f2790b]
|
|
39
|
+
- @ember-marquetry/core@1.0.0
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Joe Gaudet
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Marquetry
|
|
2
|
+
Copyright (c) 2026 Joe Gaudet. MIT licensed; see LICENSE.md.
|
|
3
|
+
|
|
4
|
+
Marquetry is an original design. Two projects gave it ideas and formats, and Marquetry copies
|
|
5
|
+
no code from them:
|
|
6
|
+
|
|
7
|
+
- json-render (Vercel, Apache 2.0): the idea of a catalog that limits a model, a flat element
|
|
8
|
+
map, and a spec that streams as JSON Lines of RFC 6902 patches.
|
|
9
|
+
- A2UI (Google, Apache 2.0): the v0.9 message format that @ember-marquetry/a2ui reads.
|
|
10
|
+
|
|
11
|
+
@ember-marquetry/ag-ui reads the event format of the AG-UI protocol, and
|
|
12
|
+
@ember-marquetry/ai-sdk reads the UI message stream format of the Vercel AI SDK. Marquetry
|
|
13
|
+
depends on neither package.
|
package/README.md
CHANGED
|
@@ -1,3 +1,112 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ember-marquetry/ember
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Marquetry renderer for Ember. It renders a spec from `@ember-marquetry/core` with the
|
|
4
|
+
Glimmer components of a registry, while the spec streams.
|
|
5
|
+
|
|
6
|
+
```gts
|
|
7
|
+
import { Generation, Render, defineRegistry } from '@ember-marquetry/ember'
|
|
8
|
+
|
|
9
|
+
const registry = defineRegistry(catalog, { Text, Stack, Button })
|
|
10
|
+
|
|
11
|
+
export default class Assistant extends Component {
|
|
12
|
+
generation = new Generation({ owner: this, catalog })
|
|
13
|
+
actions = { save: params => this.store.save(params) }
|
|
14
|
+
|
|
15
|
+
<template>
|
|
16
|
+
<Render
|
|
17
|
+
@spec={{this.generation.spec}}
|
|
18
|
+
@catalog={{catalog}}
|
|
19
|
+
@registry={{registry}}
|
|
20
|
+
@streaming={{this.generation.isStreaming}}
|
|
21
|
+
@actions={{this.actions}}
|
|
22
|
+
/>
|
|
23
|
+
</template>
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## The registry
|
|
28
|
+
|
|
29
|
+
`defineRegistry(catalog, components)` maps each component name of the catalog to a Glimmer
|
|
30
|
+
component. A name that is not there, a name that is not in the catalog, and a component with
|
|
31
|
+
other props are type errors. `mergeRegistries(a, b)` merges registries. The last one wins.
|
|
32
|
+
|
|
33
|
+
A registered component has the signature `MarquetryComponentSignature<Props>`:
|
|
34
|
+
|
|
35
|
+
| Argument | Value |
|
|
36
|
+
| ----------- | ----------------------------------------------------------------------------- |
|
|
37
|
+
| `@props` | The props after the expressions resolve and the schema validates them. |
|
|
38
|
+
| `@id` | The id of the spec element. |
|
|
39
|
+
| `@element` | The spec element as the model wrote it. |
|
|
40
|
+
| `@emit` | `(event, detail?)`: starts the actions that the spec lists under `on[event]`. |
|
|
41
|
+
| `@update` | `(prop, value)`: writes the state that the prop binds to with `$bind`. |
|
|
42
|
+
| `@bindings` | Prop name to state pointer. |
|
|
43
|
+
| `@slots` | Slot name to a component that renders the children of the slot. |
|
|
44
|
+
| `@child` | A component that renders one child by id: `<@child @id="b" />`. For tabs. |
|
|
45
|
+
| `@report` | `(message, issues?)`: reports a problem to `@onError`. The element renders. |
|
|
46
|
+
| `{{yield}}` | The children of the element. |
|
|
47
|
+
|
|
48
|
+
Put `...attributes` on the root element of the component. `<Render>` sends
|
|
49
|
+
`data-test-mq-element="<id>"` through it, and the test harness finds the element with it.
|
|
50
|
+
|
|
51
|
+
## `<Render>`
|
|
52
|
+
|
|
53
|
+
- `@spec`, `@catalog`, `@registry`: necessary.
|
|
54
|
+
- `@streaming`: true while the stream is open. An element that did not arrive yet shows a
|
|
55
|
+
skeleton. When it is false, such an element shows the fallback.
|
|
56
|
+
- State: pass `@state` and `@onStateChange(state, patches)` to control the state. Without
|
|
57
|
+
`@state`, the component keeps the state. It starts from `@defaultState`, or from `spec.state`.
|
|
58
|
+
When a later spec has a different `state`, the difference applies to the state.
|
|
59
|
+
- `@actions`: catalog action name to handler `(params, context) => result`.
|
|
60
|
+
- `@onAction(event)`: runs after each action, with `{ action, params, elementId, event, detail }`
|
|
61
|
+
and `result` or `error`.
|
|
62
|
+
- `@onError(error)`: gets a `MarquetryError` with `code`, `elementId`, `action` and `issues`.
|
|
63
|
+
- `@Fallback`, `@Skeleton`, `@Confirm`: components that replace the built-in ones.
|
|
64
|
+
- `@fallbackLabel`, `@skeletonLabel`, `@confirmTitle`, `@confirmLabel`, `@cancelLabel`: the
|
|
65
|
+
built-in strings.
|
|
66
|
+
|
|
67
|
+
### Rules
|
|
68
|
+
|
|
69
|
+
- The props resolve against the state, then the catalog repairs them. An element that stays
|
|
70
|
+
not valid shows the fallback. `@onError` runs one time for each element and cause.
|
|
71
|
+
- `visible` false renders nothing. `repeat` renders the children one time for each item.
|
|
72
|
+
- The `@props` object keeps its identity when a state change does not change the props.
|
|
73
|
+
- A cycle, or a child that does not exist when the stream is closed, shows the fallback.
|
|
74
|
+
- A spec with no root renders nothing. While the stream is open, it shows a skeleton.
|
|
75
|
+
- The renderer never renders HTML from the spec, and it compiles no template at runtime.
|
|
76
|
+
|
|
77
|
+
### Actions
|
|
78
|
+
|
|
79
|
+
The actions of an event run in order. A state action (`state.set` and the others) changes the
|
|
80
|
+
state. For a catalog action, the params resolve and the schema validates them. An action with
|
|
81
|
+
`confirm` then shows a dialog. The handler runs last.
|
|
82
|
+
|
|
83
|
+
These stop the rest of the list: params that are not valid, an action with no handler, a
|
|
84
|
+
refused confirm, and a handler that throws or rejects. The check for the handler comes before
|
|
85
|
+
the dialog, so the user does not confirm an action that cannot run.
|
|
86
|
+
|
|
87
|
+
### No error boundary
|
|
88
|
+
|
|
89
|
+
Ember has no error boundary. When a registered component throws while it renders, `<Render>`
|
|
90
|
+
cannot catch the error, and the fallback does not show. The checks above run before a component
|
|
91
|
+
renders, so a spec that is not valid does not cause this. An error in the code of a component
|
|
92
|
+
does.
|
|
93
|
+
|
|
94
|
+
## `Generation`
|
|
95
|
+
|
|
96
|
+
`new Generation({ owner, catalog, mixed, spec })` runs one generation. Its state is a Switchyard
|
|
97
|
+
machine with the states `Idle`, `Streaming`, `Done`, `Error` and `Aborted` (`GenerationState`).
|
|
98
|
+
|
|
99
|
+
- `run(source)`: `source` is an `AsyncIterable` or a `ReadableStream` of strings or bytes, or a
|
|
100
|
+
function `(signal) => source`. A second `run` aborts the first.
|
|
101
|
+
- `abort()`: aborts the signal and stops the read. `reset()`: goes back to `Idle`.
|
|
102
|
+
- Tracked: `status`, `isStreaming`, `spec`, `text` (mixed mode), `errors` (bad lines),
|
|
103
|
+
`patches` (each patch with its line number), `error` (what the source threw) and `issues`
|
|
104
|
+
(from the catalog).
|
|
105
|
+
- The destruction of `owner` aborts the run.
|
|
106
|
+
|
|
107
|
+
In tests, `settled()` waits for the end of the stream.
|
|
108
|
+
|
|
109
|
+
## Translations
|
|
110
|
+
|
|
111
|
+
Each built-in string is in `messages`. An app that registers `translator:main`, as for Joinery,
|
|
112
|
+
translates them. Without a translator, the strings are English. An argument wins over both.
|
package/addon-main.cjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
export interface ConfirmSignature {
|
|
3
|
+
Element: Element;
|
|
4
|
+
Args: {
|
|
5
|
+
title: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
confirmLabel: string;
|
|
8
|
+
cancelLabel: string;
|
|
9
|
+
/** The name of the action that waits for the answer. */
|
|
10
|
+
action: string;
|
|
11
|
+
/** The resolved params of the action. */
|
|
12
|
+
params: Record<string, unknown>;
|
|
13
|
+
onConfirm: () => void;
|
|
14
|
+
onCancel: () => void;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The built-in confirm dialog: a native modal `<dialog>`. The browser keeps the focus in it.
|
|
19
|
+
* The focus starts on the cancel button, and Escape cancels.
|
|
20
|
+
*/
|
|
21
|
+
export declare class Confirm extends Component<ConfirmSignature> {
|
|
22
|
+
cancel: (event: Event) => void;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=confirm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirm.d.ts","sourceRoot":"","sources":["../../src/components/confirm.gts"],"names":[],"mappings":"AAkEA,OAAO,SAAS,MAAM,oBAAoB,CAAA;AAK1C,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE;QACJ,KAAK,EAAE,MAAM,CAAA;QACb,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,YAAY,EAAE,MAAM,CAAA;QACpB,WAAW,EAAE,MAAM,CAAA;QACnB,wDAAwD;QACxD,MAAM,EAAE,MAAM,CAAA;QACd,yCAAyC;QACzC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAC/B,SAAS,EAAE,MAAM,IAAI,CAAA;QACrB,QAAQ,EAAE,MAAM,IAAI,CAAA;KACrB,CAAA;CACF;AAYD;;;GAGG;AACH,qBAAa,OAAQ,SAAQ,SAAS,CAAC,gBAAgB,CAAC;IACtD,MAAM,GAAI,OAAO,KAAK,UAIrB;CAoFF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import type { ComponentLike } from '@glint/template';
|
|
3
|
+
import { type Issue, type Scope, type SpecElement } from '@ember-marquetry/core';
|
|
4
|
+
import type { RenderContext, RepeatScope } from '../context.ts';
|
|
5
|
+
import { MarquetryError, type MarquetryErrorCode } from '../errors.ts';
|
|
6
|
+
import type { ChildComponent, MarquetryComponentSignature, SlotComponent } from '../registry.ts';
|
|
7
|
+
import { Stable } from '../state-store.ts';
|
|
8
|
+
type Registered = ComponentLike<MarquetryComponentSignature>;
|
|
9
|
+
/** What an element shows. All fields empty: nothing, because `visible` is false. */
|
|
10
|
+
interface Outcome {
|
|
11
|
+
error?: MarquetryError;
|
|
12
|
+
skeleton?: boolean;
|
|
13
|
+
render?: {
|
|
14
|
+
Component: Registered;
|
|
15
|
+
element: SpecElement;
|
|
16
|
+
props: Record<string, unknown>;
|
|
17
|
+
bindings: Record<string, string>;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface ElementSignature {
|
|
21
|
+
Args: {
|
|
22
|
+
id: string;
|
|
23
|
+
context: RenderContext;
|
|
24
|
+
repeat?: RepeatScope | undefined;
|
|
25
|
+
/** The ids from the root to the parent of this element. */
|
|
26
|
+
ancestors: readonly string[];
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** Renders one spec element: its registered component, a skeleton, a fallback or nothing. */
|
|
30
|
+
export declare class MarquetryElement extends Component<ElementSignature> {
|
|
31
|
+
readonly props: Stable<Record<string, unknown>>;
|
|
32
|
+
readonly bindings: Stable<Record<string, string>>;
|
|
33
|
+
readonly slotNames: Stable<string[]>;
|
|
34
|
+
readonly slotClasses: Map<string, SlotComponent>;
|
|
35
|
+
readonly child: ChildComponent;
|
|
36
|
+
get element(): SpecElement | undefined;
|
|
37
|
+
get scope(): Scope;
|
|
38
|
+
get below(): readonly string[];
|
|
39
|
+
get childIds(): readonly string[];
|
|
40
|
+
/** A component for each slot of the catalog definition and of the spec element. */
|
|
41
|
+
get slots(): Readonly<Record<string, SlotComponent>>;
|
|
42
|
+
/** One object for each list of names. `slotNames` keeps the list while the names are equal. */
|
|
43
|
+
readonly slotsByNames: WeakMap<string[], Record<string, SlotComponent>>;
|
|
44
|
+
slotsFor(names: string[]): Record<string, SlotComponent>;
|
|
45
|
+
slotClass(name: string): SlotComponent;
|
|
46
|
+
get outcome(): Outcome;
|
|
47
|
+
fail(code: MarquetryErrorCode, message: string, issues?: Issue[]): Outcome;
|
|
48
|
+
emit: (event: string, detail?: unknown) => Promise<void>;
|
|
49
|
+
report: (message: string, issues?: Issue[]) => void;
|
|
50
|
+
update: (prop: string, value: unknown) => void;
|
|
51
|
+
}
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=element.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../../src/components/element.gts"],"names":[],"mappings":"AAqUA,OAAO,SAAS,MAAM,oBAAoB,CAAA;AAE1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,EAKL,KAAK,KAAK,EACV,KAAK,KAAK,EACV,KAAK,WAAW,EACjB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC/D,OAAO,EAAE,cAAc,EAAE,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,2BAA2B,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAChG,OAAO,EAAY,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAqIpD,KAAK,UAAU,GAAG,aAAa,CAAC,2BAA2B,CAAC,CAAA;AAE5D,oFAAoF;AACpF,UAAU,OAAO;IACf,KAAK,CAAC,EAAE,cAAc,CAAA;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,MAAM,CAAC,EAAE;QACP,SAAS,EAAE,UAAU,CAAA;QACrB,OAAO,EAAE,WAAW,CAAA;QACpB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAC9B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KACjC,CAAA;CACF;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAA;QACV,OAAO,EAAE,aAAa,CAAA;QACtB,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;QAChC,2DAA2D;QAC3D,SAAS,EAAE,SAAS,MAAM,EAAE,CAAA;KAC7B,CAAA;CACF;AAED,6FAA6F;AAC7F,qBAAa,gBAAiB,SAAQ,SAAS,CAAC,gBAAgB,CAAC;IAE/D,QAAQ,CAAC,KAAK,kCAAwC;IACtD,QAAQ,CAAC,QAAQ,iCAAuC;IACxD,QAAQ,CAAC,SAAS,mBAAyB;IAC3C,QAAQ,CAAC,WAAW,6BAAmC;IACvD,QAAQ,CAAC,KAAK,iBAAuB;IAErC,IAAI,OAAO,IAAI,WAAW,GAAG,SAAS,CAIrC;IAED,IAAI,KAAK,IAAI,KAAK,CAEjB;IAED,IACI,KAAK,IAAI,SAAS,MAAM,EAAE,CAE7B;IAED,IAAI,QAAQ,IAAI,SAAS,MAAM,EAAE,CAEhC;IAED,mFAAmF;IACnF,IAAI,KAAK,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAWnD;IAED,+FAA+F;IAC/F,QAAQ,CAAC,YAAY,mDAAyD;IAE9E,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC;IASxD,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa;IAMtC,IACI,OAAO,IAAI,OAAO,CA8CrB;IAED,IAAI,CAAC,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,GAAG,OAAO;IAM1E,IAAI,GAAI,OAAO,MAAM,EAAE,SAAS,OAAO,KAAG,OAAO,CAAC,IAAI,CAAC,CACgB;IAEvE,MAAM,GAAI,SAAS,MAAM,EAAE,SAAS,KAAK,EAAE,KAAG,IAAI,CAG/C;IAEH,MAAM,GAAI,MAAM,MAAM,EAAE,OAAO,OAAO,KAAG,IAAI,CAI5C;CA+DF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { TOC } from '@ember/component/template-only';
|
|
2
|
+
import type { MarquetryError } from '../errors.ts';
|
|
3
|
+
export interface FallbackSignature {
|
|
4
|
+
Element: Element;
|
|
5
|
+
Args: {
|
|
6
|
+
/** The id of the spec element that cannot render. */
|
|
7
|
+
id: string;
|
|
8
|
+
/** Why the element cannot render. */
|
|
9
|
+
error: MarquetryError;
|
|
10
|
+
/** The text for the user. */
|
|
11
|
+
label: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Shows in the place of an element that cannot render. It is static text with the `note` role.
|
|
16
|
+
* It is not a live region: a spec can have many of them, and each one would make an announcement.
|
|
17
|
+
*/
|
|
18
|
+
export declare const Fallback: TOC<FallbackSignature>;
|
|
19
|
+
//# sourceMappingURL=fallback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fallback.d.ts","sourceRoot":"","sources":["../../src/components/fallback.gts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAA;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAElD,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE;QACJ,qDAAqD;QACrD,EAAE,EAAE,MAAM,CAAA;QACV,qCAAqC;QACrC,KAAK,EAAE,cAAc,CAAA;QACrB,6BAA6B;QAC7B,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;CACF;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,EAAE,GAAG,CAAC,iBAAiB,CAe1C,CAAA"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import type { ComponentLike } from '@glint/template';
|
|
3
|
+
import { type PatchOp, type Spec } from '@ember-marquetry/core';
|
|
4
|
+
import type { RenderCatalog, RenderContext, RepeatScope } from '../context.ts';
|
|
5
|
+
import { MarquetryError } from '../errors.ts';
|
|
6
|
+
import type { Registry } from '../registry.ts';
|
|
7
|
+
import { StateStore, type State } from '../state-store.ts';
|
|
8
|
+
import { type ConfirmSignature } from './confirm';
|
|
9
|
+
import { type FallbackSignature } from './fallback';
|
|
10
|
+
import { type SkeletonSignature } from './skeleton';
|
|
11
|
+
/** What a handler gets with the params. */
|
|
12
|
+
export interface ActionContext {
|
|
13
|
+
/** The id of the spec element that started the action. */
|
|
14
|
+
elementId: string;
|
|
15
|
+
/** The name of the event. */
|
|
16
|
+
event: string;
|
|
17
|
+
/** What the component gave to `@emit`. */
|
|
18
|
+
detail: unknown;
|
|
19
|
+
/** The state when the action started. */
|
|
20
|
+
state: State;
|
|
21
|
+
}
|
|
22
|
+
/** A handler for a catalog action. The params are the output of the schema of the action. */
|
|
23
|
+
export type ActionHandler = (params: Record<string, unknown>, context: ActionContext) => unknown | Promise<unknown>;
|
|
24
|
+
/** What `@onAction` gets after each action: `result`, or `error` when the handler failed. */
|
|
25
|
+
export interface ActionEvent {
|
|
26
|
+
action: string;
|
|
27
|
+
params: Record<string, unknown>;
|
|
28
|
+
elementId: string;
|
|
29
|
+
event: string;
|
|
30
|
+
detail: unknown;
|
|
31
|
+
result?: unknown;
|
|
32
|
+
error?: unknown;
|
|
33
|
+
}
|
|
34
|
+
export interface RenderSignature {
|
|
35
|
+
Args: {
|
|
36
|
+
spec: Spec;
|
|
37
|
+
catalog: RenderCatalog;
|
|
38
|
+
registry: Registry;
|
|
39
|
+
/** True while the stream is open. An element that did not arrive yet shows a skeleton. */
|
|
40
|
+
streaming?: boolean;
|
|
41
|
+
/** Controlled state. Pass it together with `@onStateChange`. */
|
|
42
|
+
state?: State;
|
|
43
|
+
/** Uncontrolled state: the first state. Default: the state of the spec. */
|
|
44
|
+
defaultState?: State;
|
|
45
|
+
/** Runs after each change, with the new state and the patches that made it. */
|
|
46
|
+
onStateChange?: (state: State, patches: PatchOp[]) => void;
|
|
47
|
+
/** Catalog action name to handler. */
|
|
48
|
+
actions?: Record<string, ActionHandler>;
|
|
49
|
+
onAction?: (event: ActionEvent) => void;
|
|
50
|
+
onError?: (error: MarquetryError) => void;
|
|
51
|
+
Fallback?: ComponentLike<FallbackSignature>;
|
|
52
|
+
Skeleton?: ComponentLike<SkeletonSignature>;
|
|
53
|
+
Confirm?: ComponentLike<ConfirmSignature>;
|
|
54
|
+
fallbackLabel?: string;
|
|
55
|
+
skeletonLabel?: string;
|
|
56
|
+
/** The title of the confirm dialog for an action that has no title in the catalog. */
|
|
57
|
+
confirmTitle?: string;
|
|
58
|
+
confirmLabel?: string;
|
|
59
|
+
cancelLabel?: string;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
interface PendingConfirm {
|
|
63
|
+
title: string;
|
|
64
|
+
description: string | undefined;
|
|
65
|
+
action: string;
|
|
66
|
+
params: Record<string, unknown>;
|
|
67
|
+
resolve: (agreed: boolean) => void;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Renders a spec with the components of a registry.
|
|
71
|
+
*
|
|
72
|
+
* <Render @spec={{this.generation.spec}} @catalog={{catalog}} @registry={{registry}}
|
|
73
|
+
* @streaming={{this.generation.isStreaming}} @actions={{this.actions}} />
|
|
74
|
+
*/
|
|
75
|
+
export declare class Render extends Component<RenderSignature> implements RenderContext {
|
|
76
|
+
#private;
|
|
77
|
+
version: number;
|
|
78
|
+
readonly store: StateStore;
|
|
79
|
+
pending: PendingConfirm | null;
|
|
80
|
+
get spec(): Spec;
|
|
81
|
+
get catalog(): RenderCatalog;
|
|
82
|
+
get registry(): Registry;
|
|
83
|
+
get streaming(): boolean;
|
|
84
|
+
get hasRoot(): boolean;
|
|
85
|
+
get rootId(): string;
|
|
86
|
+
get Fallback(): ComponentLike<FallbackSignature>;
|
|
87
|
+
get Skeleton(): ComponentLike<SkeletonSignature>;
|
|
88
|
+
get Confirm(): ComponentLike<ConfirmSignature>;
|
|
89
|
+
get fallbackLabel(): string;
|
|
90
|
+
get skeletonLabel(): string;
|
|
91
|
+
get confirmLabel(): string;
|
|
92
|
+
get cancelLabel(): string;
|
|
93
|
+
/** The state: `@state` when the owner controls it, else the state of this component. */
|
|
94
|
+
get state(): State;
|
|
95
|
+
/** Runs `callback` after the render. `settled()` waits for it. */
|
|
96
|
+
later(callback: () => void): void;
|
|
97
|
+
/** Applies patches from the user to the state. Throws when a patch does not fit. */
|
|
98
|
+
commit(patches: PatchOp[]): void;
|
|
99
|
+
report(error: MarquetryError): void;
|
|
100
|
+
write(id: string, path: string, value: unknown): void;
|
|
101
|
+
emit(id: string, event: string, detail: unknown, repeat: RepeatScope | undefined): Promise<void>;
|
|
102
|
+
/** Shows the confirm dialog, and resolves with the answer of the user. */
|
|
103
|
+
ask(action: string, params: Record<string, unknown>, confirm: true | {
|
|
104
|
+
title?: string;
|
|
105
|
+
description?: string;
|
|
106
|
+
}): Promise<boolean>;
|
|
107
|
+
answer(agreed: boolean): void;
|
|
108
|
+
agree: () => void;
|
|
109
|
+
refuse: () => void;
|
|
110
|
+
willDestroy(): void;
|
|
111
|
+
}
|
|
112
|
+
export {};
|
|
113
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/components/render.gts"],"names":[],"mappings":"AA0VA,OAAO,SAAS,MAAM,oBAAoB,CAAA;AAI1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,EAML,KAAK,OAAO,EAEZ,KAAK,IAAI,EACV,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAG7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAY,UAAU,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACpE,OAAO,EAAW,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAE9D,OAAO,EAAY,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AACjE,OAAO,EAAY,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CAAC,iBAAiB,CAAC,CAE/C;IAED,IAAI,OAAO,IAAI,aAAa,CAAC,gBAAgB,CAAC,CAE7C;IAED,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,wFAAwF;IACxF,IAAI,KAAK,IAAI,KAAK,CAGjB;IAED,kEAAkE;IAClE,KAAK,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;IAQjC,oFAAoF;IACpF,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI;IAYhC,MAAM,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI;IASnC,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAa/C,IAAI,CACR,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,OAAO,CAAC,IAAI,CAAC;IAyEhB,0EAA0E;IAC1E,GAAG,CACD,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,EAAE,IAAI,GAAG;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GACvD,OAAO,CAAC,OAAO,CAAC;IAenB,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI;IAM7B,KAAK,aAA0B;IAC/B,MAAM,aAA2B;IAExB,WAAW,IAAI,IAAI;CA2C7B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TOC } from '@ember/component/template-only';
|
|
2
|
+
export interface SkeletonSignature {
|
|
3
|
+
Element: Element;
|
|
4
|
+
Args: {
|
|
5
|
+
/** The id of the spec element that did not arrive yet. Empty when the spec has no root yet. */
|
|
6
|
+
id: string;
|
|
7
|
+
/** The text for the user. */
|
|
8
|
+
label: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** Shows in the place of an element that did not arrive yet, while the stream is open. */
|
|
12
|
+
export declare const Skeleton: TOC<SkeletonSignature>;
|
|
13
|
+
//# sourceMappingURL=skeleton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skeleton.d.ts","sourceRoot":"","sources":["../../src/components/skeleton.gts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAA;AAEzD,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE;QACJ,+FAA+F;QAC/F,EAAE,EAAE,MAAM,CAAA;QACV,6BAA6B;QAC7B,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;CACF;AAED,0FAA0F;AAC1F,eAAO,MAAM,QAAQ,EAAE,GAAG,CAAC,iBAAiB,CAe1C,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ComponentLike } from '@glint/template';
|
|
2
|
+
import type { Catalog, Spec } from '@ember-marquetry/core';
|
|
3
|
+
import type { FallbackSignature } from './components/fallback';
|
|
4
|
+
import type { SkeletonSignature } from './components/skeleton';
|
|
5
|
+
import type { MarquetryError } from './errors.ts';
|
|
6
|
+
import type { Registry } from './registry.ts';
|
|
7
|
+
/** The item of the nearest `repeat`. */
|
|
8
|
+
export interface RepeatScope {
|
|
9
|
+
item: unknown;
|
|
10
|
+
index: number;
|
|
11
|
+
itemPath: string;
|
|
12
|
+
}
|
|
13
|
+
/** The part of a catalog that the renderer uses. */
|
|
14
|
+
export type RenderCatalog = Pick<Catalog, 'components' | 'actions' | 'validateProps' | 'repairProps' | 'validateAction'>;
|
|
15
|
+
/** What `<Render>` gives to each element that it renders. */
|
|
16
|
+
export interface RenderContext {
|
|
17
|
+
readonly spec: Spec;
|
|
18
|
+
readonly catalog: RenderCatalog;
|
|
19
|
+
readonly registry: Registry;
|
|
20
|
+
readonly state: Record<string, unknown>;
|
|
21
|
+
readonly streaming: boolean;
|
|
22
|
+
readonly Fallback: ComponentLike<FallbackSignature>;
|
|
23
|
+
readonly Skeleton: ComponentLike<SkeletonSignature>;
|
|
24
|
+
readonly fallbackLabel: string;
|
|
25
|
+
readonly skeletonLabel: string;
|
|
26
|
+
/** Reports an error from a render: one time for each element and cause. */
|
|
27
|
+
report(error: MarquetryError): void;
|
|
28
|
+
/** Starts the actions of an event of an element. */
|
|
29
|
+
emit(id: string, event: string, detail: unknown, repeat: RepeatScope | undefined): Promise<void>;
|
|
30
|
+
/** Writes a value at a state pointer. */
|
|
31
|
+
write(id: string, path: string, value: unknown): void;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAClE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE7C,wCAAwC;AACxC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,OAAO,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,oDAAoD;AACpD,MAAM,MAAM,aAAa,GAAG,IAAI,CAC9B,OAAO,EACP,YAAY,GAAG,SAAS,GAAG,eAAe,GAAG,aAAa,GAAG,gBAAgB,CAC9E,CAAA;AAED,6DAA6D;AAC7D,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;IACnB,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAA;IAC/B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACvC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;IAC3B,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAA;IACnD,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAA;IACnD,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,2EAA2E;IAC3E,MAAM,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,CAAA;IACnC,oDAAoD;IACpD,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAChG,yCAAyC;IACzC,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAA;CACtD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Issue, IssueCode } from '@ember-marquetry/core';
|
|
2
|
+
/**
|
|
3
|
+
* The cause of an error. The codes of `core` are for a spec that is not valid. The other
|
|
4
|
+
* codes are for the registry, the state and the actions.
|
|
5
|
+
*/
|
|
6
|
+
export type MarquetryErrorCode = IssueCode
|
|
7
|
+
/** The registry has no component for the type. */
|
|
8
|
+
| 'missing-component'
|
|
9
|
+
/** `@actions` has no handler for the action. */
|
|
10
|
+
| 'missing-handler'
|
|
11
|
+
/** The params of an action do not agree with its schema. */
|
|
12
|
+
| 'invalid-params'
|
|
13
|
+
/** A handler threw an error, or its promise rejected. `cause` is the error. */
|
|
14
|
+
| 'action-failed'
|
|
15
|
+
/** A change of the state failed, for example a state action with no path. */
|
|
16
|
+
| 'state-failed'
|
|
17
|
+
/** A registered component reported a problem with `@report`. It still renders. */
|
|
18
|
+
| 'component-error';
|
|
19
|
+
export interface MarquetryErrorDetails {
|
|
20
|
+
elementId?: string;
|
|
21
|
+
action?: string;
|
|
22
|
+
issues?: Issue[];
|
|
23
|
+
cause?: unknown;
|
|
24
|
+
}
|
|
25
|
+
/** The error that `<Render>` gives to `@onError`. */
|
|
26
|
+
export declare class MarquetryError extends Error {
|
|
27
|
+
name: string;
|
|
28
|
+
readonly code: MarquetryErrorCode;
|
|
29
|
+
/** The id of the spec element. */
|
|
30
|
+
readonly elementId: string | undefined;
|
|
31
|
+
/** The name of the action, for an error from an action. */
|
|
32
|
+
readonly action: string | undefined;
|
|
33
|
+
/** The issues from the schema, for props or params that are not valid. */
|
|
34
|
+
readonly issues: Issue[];
|
|
35
|
+
constructor(code: MarquetryErrorCode, message: string, details?: MarquetryErrorDetails);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAE7D;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAC1B,SAAS;AACX,kDAAkD;GAChD,mBAAmB;AACrB,gDAAgD;GAC9C,iBAAiB;AACnB,4DAA4D;GAC1D,gBAAgB;AAClB,+EAA+E;GAC7E,eAAe;AACjB,6EAA6E;GAC3E,cAAc;AAChB,kFAAkF;GAChF,iBAAiB,CAAA;AAErB,MAAM,WAAW,qBAAqB;IACpC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,KAAK,EAAE,CAAA;IAChB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED,qDAAqD;AACrD,qBAAa,cAAe,SAAQ,KAAK;IAC9B,IAAI,SAAmB;IAChC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAA;IACjC,kCAAkC;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IACtC,2DAA2D;IAC3D,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IACnC,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,CAAA;gBAEZ,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B;CAO3F"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { type Catalog, type Issue, type PatchOp, type Spec, type StreamError } from '@ember-marquetry/core';
|
|
2
|
+
import { State } from '@switchyard-ts/core';
|
|
3
|
+
/** The states of a generation. */
|
|
4
|
+
export declare class GenerationState extends State {
|
|
5
|
+
private readonly brand;
|
|
6
|
+
/** No run started, or `reset()` ran. */
|
|
7
|
+
static Idle: GenerationState & {
|
|
8
|
+
readonly value: "idle";
|
|
9
|
+
};
|
|
10
|
+
/** The stream is open. */
|
|
11
|
+
static Streaming: GenerationState & {
|
|
12
|
+
readonly value: "streaming";
|
|
13
|
+
};
|
|
14
|
+
/** The stream ended. */
|
|
15
|
+
static Done: GenerationState & {
|
|
16
|
+
readonly value: "done";
|
|
17
|
+
};
|
|
18
|
+
/** The source threw an error. */
|
|
19
|
+
static Error: GenerationState & {
|
|
20
|
+
readonly value: "error";
|
|
21
|
+
};
|
|
22
|
+
/** `abort()` stopped the stream. */
|
|
23
|
+
static Aborted: GenerationState & {
|
|
24
|
+
readonly value: "aborted";
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
type Chunk = string | Uint8Array;
|
|
28
|
+
type Chunks = AsyncIterable<Chunk> | ReadableStream<Chunk>;
|
|
29
|
+
/** A patch of the stream, with its line number from 1. */
|
|
30
|
+
export interface GenerationPatch {
|
|
31
|
+
line: number;
|
|
32
|
+
op: PatchOp;
|
|
33
|
+
}
|
|
34
|
+
/** Where a generation reads from: the chunks, or a function that gets the abort signal. */
|
|
35
|
+
export type GenerationSource = Chunks | ((signal: AbortSignal) => Chunks | Promise<Chunks>);
|
|
36
|
+
export interface GenerationOptions {
|
|
37
|
+
/**
|
|
38
|
+
* The object that owns the generation: a component, a service or the app owner. Its
|
|
39
|
+
* destruction aborts the run.
|
|
40
|
+
*/
|
|
41
|
+
owner?: object;
|
|
42
|
+
/** With a catalog, `issues` lists what is not valid in the spec. */
|
|
43
|
+
catalog?: Pick<Catalog, 'validate'>;
|
|
44
|
+
/** In mixed mode, a line that is not a patch is text for the user. */
|
|
45
|
+
mixed?: boolean;
|
|
46
|
+
/** The spec that each run starts from. Default: an empty spec. */
|
|
47
|
+
spec?: Spec;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Runs one generation: it reads a stream of JSONL patches and builds the spec. Its state is a
|
|
51
|
+
* Switchyard machine, and each property is tracked.
|
|
52
|
+
*
|
|
53
|
+
* generation = new Generation({ owner: this, catalog })
|
|
54
|
+
* this.generation.run(signal => fetchLines('/api/generate', { signal }))
|
|
55
|
+
*
|
|
56
|
+
* <Render @spec={{this.generation.spec}} @streaming={{this.generation.isStreaming}} … />
|
|
57
|
+
*/
|
|
58
|
+
export declare class Generation {
|
|
59
|
+
#private;
|
|
60
|
+
constructor(options?: GenerationOptions);
|
|
61
|
+
/** The state of the machine. */
|
|
62
|
+
get status(): GenerationState;
|
|
63
|
+
/** True while the stream is open. */
|
|
64
|
+
get isStreaming(): boolean;
|
|
65
|
+
/** The spec after the patches so far. Each patch makes a new object. */
|
|
66
|
+
get spec(): Spec;
|
|
67
|
+
/** Mixed mode: the text that the model wrote for the user. */
|
|
68
|
+
get text(): string;
|
|
69
|
+
/** The lines of the stream that are not valid patches. */
|
|
70
|
+
get errors(): readonly StreamError[];
|
|
71
|
+
/** Each patch of the run so far, with its line number, in order. */
|
|
72
|
+
get patches(): readonly GenerationPatch[];
|
|
73
|
+
/** The error that the source threw, in the `Error` state. */
|
|
74
|
+
get error(): unknown;
|
|
75
|
+
/** What the catalog finds not valid in the spec. Empty when there is no catalog. */
|
|
76
|
+
get issues(): Issue[];
|
|
77
|
+
/** Starts a run. A run that is active aborts first. */
|
|
78
|
+
run(source: GenerationSource): void;
|
|
79
|
+
/** Aborts the signal and stops the read. The spec so far stays. No effect when no run is active. */
|
|
80
|
+
abort(): void;
|
|
81
|
+
/** Aborts a run, and goes back to the `Idle` state and the first spec. */
|
|
82
|
+
reset(): void;
|
|
83
|
+
}
|
|
84
|
+
export {};
|
|
85
|
+
//# sourceMappingURL=generation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generation.d.ts","sourceRoot":"","sources":["../src/generation.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,KAAK,IAAI,EACT,KAAK,WAAW,EAEjB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAmB,KAAK,EAAc,MAAM,qBAAqB,CAAA;AAGxE,kCAAkC;AAClC,qBAAa,eAAgB,SAAQ,KAAK;IACxC,iBAAyB,KAAK,CAAO;IACrC,wCAAwC;IACxC,MAAM,CAAC,IAAI;;MAA6B;IACxC,0BAA0B;IAC1B,MAAM,CAAC,SAAS;;MAAkC;IAClD,wBAAwB;IACxB,MAAM,CAAC,IAAI;;MAA6B;IACxC,iCAAiC;IACjC,MAAM,CAAC,KAAK;;MAA8B;IAC1C,oCAAoC;IACpC,MAAM,CAAC,OAAO;;MAAgC;CAC/C;AAED,KAAK,KAAK,GAAG,MAAM,GAA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0E;IAC1E,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Message } from './messages.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Translates the built-in strings. An app registers one as `translator:main`, the same
|
|
4
|
+
* registration that Joinery uses:
|
|
5
|
+
*
|
|
6
|
+
* owner.register('translator:main', translator, { instantiate: false })
|
|
7
|
+
*/
|
|
8
|
+
export interface Translator {
|
|
9
|
+
/** A BCP 47 locale. Make it tracked, so that a change of locale renders again. */
|
|
10
|
+
readonly locale: string;
|
|
11
|
+
/** The translated string. */
|
|
12
|
+
t(message: Message, values?: Record<string, unknown>): string;
|
|
13
|
+
}
|
|
14
|
+
/** A built-in string from the translator of the app, or in English when the app has none. */
|
|
15
|
+
export declare function translate(context: object, message: Message): string;
|
|
16
|
+
//# sourceMappingURL=i18n.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,kFAAkF;IAClF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,6BAA6B;IAC7B,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAA;CAC9D;AAED,6FAA6F;AAC7F,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAGnE"}
|