@sigrix-io/gatehouse 0.4.0 → 0.5.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/README.md +13 -3
- package/package.json +3 -3
- package/src/host_blocks.js +14 -0
- package/src/run_renderer.js +19 -5
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ Each script is an IIFE that adds to one global, `window.Gatehouse`. `window.Sigr
|
|
|
53
53
|
| Constructor | Arguments |
|
|
54
54
|
| --- | --- |
|
|
55
55
|
| `PosternClient(baseUrl, options)` | `baseUrl`: where the runner (or the proxy) answers; every request goes to it under `/postern/v0`. `options.headers`: extra headers for every request. `options.fetchImpl`: a `fetch` to use instead of the page's. |
|
|
56
|
-
| `RunRenderer(container, client, options)` | `container`: the element to draw into. `client`: anything with the four verbs. `options.composition`, `options.choice`, `options.hosted`, `options.conversation`: below. |
|
|
56
|
+
| `RunRenderer(container, client, options)` | `container`: the element to draw into. `client`: anything with the four verbs. `options.composition`, `options.choice`, `options.hosted`, `options.conversation`: below. `options.titleLevel`: the heading level of the bundle's name, 1 to 6, default 1 (see [The title's level](#the-titles-level)). |
|
|
57
57
|
|
|
58
58
|
`renderer.load()` reads `describe` and `status` and draws the page. Running, stopping and retrying are the page's own buttons.
|
|
59
59
|
|
|
@@ -70,6 +70,16 @@ Each is held by a test rather than by memory (`tests/contract.test.js` and the s
|
|
|
70
70
|
- **Documents are handed in.** The composition and the choice arrive as data from whoever mounted the page, and so does everything the host blocks and the playbook block draw. Fetching them here would be reaching for a fifth verb, and Postern has four.
|
|
71
71
|
- **A link goes only to a web address.** An address a runner's author wrote becomes a link only when it is an absolute `http` or `https` one, so a `javascript:` address in `describe` is never something a click runs.
|
|
72
72
|
|
|
73
|
+
## The title's level
|
|
74
|
+
|
|
75
|
+
The run page draws the bundle's name as `<h1 class="run-title">`, which is right for a page that is nothing but the run page. A host page that already has an `<h1>` of its own passes `titleLevel: 2` (or any whole number from 1 to 6), and the name is drawn as that level instead, with the same class and the same text:
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
new Gatehouse.RunRenderer(container, client, { titleLevel: 2 });
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
A number or numeric text (`'2'`) is read as a level; anything that does not read as a whole number from 1 to 6 (absent, `0`, `7`, `2.5`, other text) is the default, 1. Pass 2 for a page that has an `<h1>` of its own; from 3 on, the heading above the examples and a result's top heading are both `<h2>` and outrank the name. Only the name's level moves: the heading above the examples stays an `<h2>`, and a result's own headings stay between `<h2>` and `<h4>`, so at `titleLevel: 2` they sit beside the name and skip no level beneath it. The renderer draws no other `<h1>`.
|
|
82
|
+
|
|
73
83
|
## The composition
|
|
74
84
|
|
|
75
85
|
`options.composition` is a seller's `ui.json`: how a runner's inputs and result are *presented*. A seller writes it, so the client re-checks everything in it rather than trusting the file it was handed.
|
|
@@ -164,7 +174,7 @@ Each carries `"v": 1`. A block refuses a document in a version it does not read,
|
|
|
164
174
|
}
|
|
165
175
|
```
|
|
166
176
|
|
|
167
|
-
**Run row.** `app_id`, `app_name`, `started_at`, `input_tokens`, `output_tokens` and `outcome` are required. `outcome` is `done`, `timed_out`, `failed` or `cancelled`; `duration_seconds`, `model`, `cost_estimate` and `detail` may be null; `currency`, an ISO 4217 code, goes beside a cost. `detail` is the host's own sentence about how the run ended, drawn as given, so it is written for the person reading. A runner's error message is not one: on a hosted run it can carry what a provider said about the operator's key (see [Hosted runs](#hosted-runs)).
|
|
177
|
+
**Run row.** `app_id`, `app_name`, `started_at`, `input_tokens`, `output_tokens` and `outcome` are required. `outcome` is `done`, `timed_out`, `failed` or `cancelled`; `duration_seconds`, `model`, `cost_estimate` and `detail` may be null; `currency`, an ISO 4217 code, goes beside a cost. `credits`, a count, is what the host's credits paid for the run, left out or null when they paid nothing for it: `RunHistory` draws a Credits column beside the tokens once any row carries one, and a dash for a row that does not. `detail` is the host's own sentence about how the run ended, drawn as given, so it is written for the person reading. A runner's error message is not one: on a hosted run it can carry what a provider said about the operator's key (see [Hosted runs](#hosted-runs)).
|
|
168
178
|
|
|
169
179
|
```json
|
|
170
180
|
{
|
|
@@ -255,7 +265,7 @@ Gatehouse is one of the open-source projects [Sigrix](https://sigrix.io) publish
|
|
|
255
265
|
- **[Postern](https://github.com/sigrix-io/postern)**, the protocol whose four verbs it calls. Its [§2.3](https://github.com/sigrix-io/postern/blob/main/SPEC.md#23-browser-clients) says what a runner owes a browser client, and why the default is to refuse.
|
|
256
266
|
- **[sigrix-runtime](https://github.com/sigrix-io/sigrix-runtime)** (`pip install sigrix-runtime`), a runner to point it at: the one inside every bundle Sigrix delivers, which can also serve an MCP server's tools as one agent. Start it with `--allow-origin` set to the page's origin.
|
|
257
267
|
- **[postern-conformance](https://pypi.org/project/postern-conformance/)** (`pip install postern-conformance`), which reports the level a runner really meets before you draw a page for it.
|
|
258
|
-
- **[Bailey](https://github.com/sigrix-io/bailey)
|
|
268
|
+
- **[Bailey](https://github.com/sigrix-io/bailey)** (`uvx bailey`), the open-source assistant, which draws a solution's apps with Gatehouse.
|
|
259
269
|
- **[Muster](https://github.com/sigrix-io/muster)**, the format a playbook's `playbook.json` is written in, which the playbook block reads. Its schema is at [sigrix.io/schemas/muster/0.1/playbook.schema.json](https://sigrix.io/schemas/muster/0.1/playbook.schema.json).
|
|
260
270
|
|
|
261
271
|
Every project Sigrix publishes, and a map of how they connect: [sigrix.io/open-source](https://sigrix.io/open-source).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sigrix-io/gatehouse",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "A browser client for Postern: draws a run page from a describe document and connects it to the four verbs. No build step and no dependencies.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Sigrix",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"test": "vitest run"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"jsdom": "
|
|
45
|
-
"vitest": "5.0
|
|
44
|
+
"jsdom": "31.0.0",
|
|
45
|
+
"vitest": "5.1.0"
|
|
46
46
|
}
|
|
47
47
|
}
|
package/src/host_blocks.js
CHANGED
|
@@ -90,6 +90,12 @@
|
|
|
90
90
|
return value;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
/* A count a document may leave out: `null` when it does. */
|
|
94
|
+
function countOrNone(doc, key) {
|
|
95
|
+
if (doc[key] === undefined || doc[key] === null) return null;
|
|
96
|
+
return countMember(doc, key);
|
|
97
|
+
}
|
|
98
|
+
|
|
93
99
|
function amountMember(doc, key, nullable) {
|
|
94
100
|
const value = doc[key];
|
|
95
101
|
if ((value === undefined || value === null) && nullable) return null;
|
|
@@ -167,6 +173,8 @@
|
|
|
167
173
|
model: textMember(row, 'model', false),
|
|
168
174
|
inputTokens: countMember(row, 'input_tokens'),
|
|
169
175
|
outputTokens: countMember(row, 'output_tokens'),
|
|
176
|
+
/* What the host's credits paid for the run, when they paid for it. */
|
|
177
|
+
credits: countOrNone(row, 'credits'),
|
|
170
178
|
costEstimate,
|
|
171
179
|
currency: costEstimate === null ? '' : currencyMember(row, 'currency'),
|
|
172
180
|
outcome: textMember(row, 'outcome', true),
|
|
@@ -511,6 +519,10 @@
|
|
|
511
519
|
if (read.refusal) refusals.push(read.refusal);
|
|
512
520
|
else runs.push(read.value);
|
|
513
521
|
});
|
|
522
|
+
/* A host whose runs no credits paid for has no such column. */
|
|
523
|
+
const showCredits = runs.some(function (run) {
|
|
524
|
+
return run.credits !== null;
|
|
525
|
+
});
|
|
514
526
|
|
|
515
527
|
if (!runs.length) {
|
|
516
528
|
if (!refusals.length) block.appendChild(el('p', 'gh-empty', options.emptyText || 'No runs yet.'));
|
|
@@ -531,6 +543,7 @@
|
|
|
531
543
|
headRow.appendChild(headCell('Duration', true));
|
|
532
544
|
headRow.appendChild(headCell('Tokens in', true));
|
|
533
545
|
headRow.appendChild(headCell('Tokens out', true));
|
|
546
|
+
if (showCredits) headRow.appendChild(headCell('Credits', true));
|
|
534
547
|
/* The column says what the figure is. A run's cost is the host's
|
|
535
548
|
* estimate from token counts and a price list, never a bill. */
|
|
536
549
|
headRow.appendChild(headCell('Cost (estimate)', true));
|
|
@@ -551,6 +564,7 @@
|
|
|
551
564
|
row.appendChild(cell(run.durationSeconds === null ? '—' : formatted.duration(run.durationSeconds), true));
|
|
552
565
|
row.appendChild(cell(formatted.count(run.inputTokens), true));
|
|
553
566
|
row.appendChild(cell(formatted.count(run.outputTokens), true));
|
|
567
|
+
if (showCredits) row.appendChild(cell(run.credits === null ? '—' : formatted.count(run.credits), true));
|
|
554
568
|
row.appendChild(cell(run.costEstimate === null ? '—' : formatted.money(run.costEstimate, run.currency), true));
|
|
555
569
|
row.appendChild(cell(run.model || '—', false));
|
|
556
570
|
body.appendChild(row);
|
package/src/run_renderer.js
CHANGED
|
@@ -36,6 +36,17 @@
|
|
|
36
36
|
return null;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/* `options.titleLevel`: which heading the bundle's name is drawn as, 1 to 6.
|
|
40
|
+
* A number, or text that reads as one ('2'), as `headingLevel` does in the
|
|
41
|
+
* host blocks. Anything that does not read as a whole number from 1 to 6
|
|
42
|
+
* (absent, 0, 7, 2.5, other text, other types) is the default, 1, so a page
|
|
43
|
+
* that asks for nothing keeps the `<h1>` it has always had. A host that
|
|
44
|
+
* already has an `<h1>` of its own passes 2. */
|
|
45
|
+
function titleLevel(option) {
|
|
46
|
+
const level = typeof option === 'number' || typeof option === 'string' ? Number(option) : NaN;
|
|
47
|
+
return Number.isInteger(level) && level >= 1 && level <= 6 ? level : 1;
|
|
48
|
+
}
|
|
49
|
+
|
|
39
50
|
function randomKey() {
|
|
40
51
|
/* An idempotency key only has to be unique to this client (SPEC 4.2). */
|
|
41
52
|
if (root.crypto && typeof root.crypto.randomUUID === 'function') return root.crypto.randomUUID();
|
|
@@ -61,8 +72,9 @@
|
|
|
61
72
|
* of the others apply (`inputChoice` in the view model has its shape): a
|
|
62
73
|
* fact the host read about this runner, handed in for the composition's
|
|
63
74
|
* reason. `options.conversation` keeps each brief and answer on the page
|
|
64
|
-
* and sends them with the next brief (`renderConversation`).
|
|
65
|
-
* is
|
|
75
|
+
* and sends them with the next brief (`renderConversation`).
|
|
76
|
+
* `options.titleLevel` (1 to 6, default 1) is the level of the heading the
|
|
77
|
+
* bundle's name is drawn as (`titleLevel`). Nothing else is read. */
|
|
66
78
|
constructor(container, client, options) {
|
|
67
79
|
const settings = options || {};
|
|
68
80
|
this.container = container;
|
|
@@ -82,6 +94,7 @@
|
|
|
82
94
|
this.lastRunId = '';
|
|
83
95
|
this.lastInputsKey = '';
|
|
84
96
|
this.idempotencyKey = '';
|
|
97
|
+
this.titleLevel = titleLevel(settings.titleLevel);
|
|
85
98
|
this.onRunStateChange = settings.onRunStateChange || function () {};
|
|
86
99
|
this.conversation = conversationSettings(settings.conversation);
|
|
87
100
|
/* Held here and nowhere else: the page forgets the conversation when it
|
|
@@ -138,7 +151,7 @@
|
|
|
138
151
|
|
|
139
152
|
renderHeader(vm) {
|
|
140
153
|
const section = el('section', 'run-header');
|
|
141
|
-
section.appendChild(el('
|
|
154
|
+
section.appendChild(el('h' + this.titleLevel, 'run-title', vm.header.name));
|
|
142
155
|
if (vm.header.summary) section.appendChild(el('p', 'run-summary', vm.header.summary));
|
|
143
156
|
const meta = el('p', 'run-meta');
|
|
144
157
|
/* Verbatim, both of them: the identifier is what the buyer types into
|
|
@@ -780,8 +793,9 @@
|
|
|
780
793
|
const target = into || this.nodes.rendered;
|
|
781
794
|
NS.viewModel.outputBlocks(value).forEach(function (block) {
|
|
782
795
|
if (block.kind === 'heading') {
|
|
783
|
-
/* Clamped to h2..h4: the page
|
|
784
|
-
*
|
|
796
|
+
/* Clamped to h2..h4: the page has an `<h1>` (the agent's name by
|
|
797
|
+
* default, or the host's own when `titleLevel` moves it), and an
|
|
798
|
+
* agent that emits `#` is describing its answer, not the page. */
|
|
785
799
|
const level = Math.min(4, Math.max(2, block.level + 1));
|
|
786
800
|
target.appendChild(el('h' + level, 'run-md-heading', block.text));
|
|
787
801
|
return;
|