@guuey/agent-client 0.1.0 → 0.2.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/dist/block-ui.d.ts +6 -1
- package/dist/block-ui.d.ts.map +1 -1
- package/dist/block-ui.js +21 -3
- package/dist/card-mount.d.ts +69 -0
- package/dist/card-mount.d.ts.map +1 -0
- package/dist/card-mount.js +83 -0
- package/dist/ggui-render.d.ts +161 -0
- package/dist/ggui-render.d.ts.map +1 -0
- package/dist/ggui-render.js +164 -0
- package/dist/history.d.ts +12 -0
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +17 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/dist/link-prompt.d.ts +22 -0
- package/dist/link-prompt.d.ts.map +1 -0
- package/dist/link-prompt.js +29 -0
- package/dist/sse.d.ts +19 -0
- package/dist/sse.d.ts.map +1 -1
- package/dist/sse.js +38 -0
- package/dist/types.d.ts +82 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -1
- package/dist/useAgentInvoke.d.ts.map +1 -1
- package/dist/useAgentInvoke.js +99 -12
- package/dist/web-adapters.d.ts +78 -14
- package/dist/web-adapters.d.ts.map +1 -1
- package/dist/web-adapters.js +115 -21
- package/package.json +2 -2
- package/src/block-ui.ts +19 -3
- package/src/card-mount.ts +101 -0
- package/src/ggui-render.ts +270 -0
- package/src/history.ts +17 -0
- package/src/index.ts +27 -0
- package/src/link-prompt.ts +34 -0
- package/src/sse.ts +36 -0
- package/src/types.ts +85 -3
- package/src/useAgentInvoke.ts +106 -12
- package/src/web-adapters.ts +169 -24
package/dist/block-ui.d.ts
CHANGED
|
@@ -57,7 +57,12 @@ export declare function scanProviderRawForUiResource(raw: JsonValue | undefined)
|
|
|
57
57
|
* Extract a mountable UI resource from an opaque AgBlock-shaped `JsonValue`
|
|
58
58
|
* (used for persisted card snapshot parts, which arrive untyped). Dispatches
|
|
59
59
|
* by `block.type`:
|
|
60
|
-
* - `tool-result` → its `uiData` surface channel
|
|
60
|
+
* - `tool-result` → its `uiData` surface channel, then a `ui://` resource
|
|
61
|
+
* degraded into a `provider-raw` content part — the SAME two channels
|
|
62
|
+
* the live path ({@link toolResultUiResource}) mounts. The write side
|
|
63
|
+
* (`nocode-runtime`'s `uiCardArtifactsFromMessages`, guuey#86) persists
|
|
64
|
+
* card rows for both, so the snapshot arm must mount both or
|
|
65
|
+
* provider-raw-only cards rehydrate as placeholders.
|
|
61
66
|
* - `provider-raw` → a `ui://` resource hiding in `raw`
|
|
62
67
|
* - `resource` → a first-class embedded resource (gated on `ui://`)
|
|
63
68
|
* Everything else → `undefined`.
|
package/dist/block-ui.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-ui.d.ts","sourceRoot":"","sources":["../src/block-ui.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,2EAA2E;AAC3E,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,uEAAuE;AACvE,wBAAgB,YAAY,CAAC,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,CAAC,IAAI;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAExF;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,oBAAoB,GAAG,SAAS,CAU5F;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,oBAAoB,GAAG,SAAS,CAK5F;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,SAAS,GAAG,SAAS,GACzB,oBAAoB,GAAG,SAAS,CAMlC;AAED
|
|
1
|
+
{"version":3,"file":"block-ui.d.ts","sourceRoot":"","sources":["../src/block-ui.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,2EAA2E;AAC3E,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,uEAAuE;AACvE,wBAAgB,YAAY,CAAC,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,CAAC,IAAI;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAExF;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,oBAAoB,GAAG,SAAS,CAU5F;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,oBAAoB,GAAG,SAAS,CAK5F;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,SAAS,GAAG,SAAS,GACzB,oBAAoB,GAAG,SAAS,CAMlC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,GAAG,oBAAoB,GAAG,SAAS,CAyBlF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,CAAC,OAAO,EAAE;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAC,GAC/C,oBAAoB,GAAG,SAAS,CAUlC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,YAAY,EAAE,SAAS,GAAG,oBAAoB,GAAG,SAAS,CAUxF;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,oBAAoB,GAAG,MAAM,GAAG,SAAS,CAU/E;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAK1E;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,WAAW,EAAE,CAE7E"}
|
package/dist/block-ui.js
CHANGED
|
@@ -54,7 +54,12 @@ export function scanProviderRawForUiResource(raw) {
|
|
|
54
54
|
* Extract a mountable UI resource from an opaque AgBlock-shaped `JsonValue`
|
|
55
55
|
* (used for persisted card snapshot parts, which arrive untyped). Dispatches
|
|
56
56
|
* by `block.type`:
|
|
57
|
-
* - `tool-result` → its `uiData` surface channel
|
|
57
|
+
* - `tool-result` → its `uiData` surface channel, then a `ui://` resource
|
|
58
|
+
* degraded into a `provider-raw` content part — the SAME two channels
|
|
59
|
+
* the live path ({@link toolResultUiResource}) mounts. The write side
|
|
60
|
+
* (`nocode-runtime`'s `uiCardArtifactsFromMessages`, guuey#86) persists
|
|
61
|
+
* card rows for both, so the snapshot arm must mount both or
|
|
62
|
+
* provider-raw-only cards rehydrate as placeholders.
|
|
58
63
|
* - `provider-raw` → a `ui://` resource hiding in `raw`
|
|
59
64
|
* - `resource` → a first-class embedded resource (gated on `ui://`)
|
|
60
65
|
* Everything else → `undefined`.
|
|
@@ -63,8 +68,21 @@ export function blockUiResource(block) {
|
|
|
63
68
|
if (!isJsonObject(block))
|
|
64
69
|
return undefined;
|
|
65
70
|
switch (block.type) {
|
|
66
|
-
case "tool-result":
|
|
67
|
-
|
|
71
|
+
case "tool-result": {
|
|
72
|
+
const fromUiData = asUiResource(block.uiData);
|
|
73
|
+
if (fromUiData)
|
|
74
|
+
return fromUiData;
|
|
75
|
+
if (Array.isArray(block.content)) {
|
|
76
|
+
for (const part of block.content) {
|
|
77
|
+
if (isJsonObject(part) && part.type === "provider-raw") {
|
|
78
|
+
const found = scanProviderRawForUiResource(part.raw);
|
|
79
|
+
if (found)
|
|
80
|
+
return found;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
68
86
|
case "provider-raw":
|
|
69
87
|
return scanProviderRawForUiResource(block.raw);
|
|
70
88
|
case "resource": {
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The card-mount dispatcher: ONE narrowing that answers "what, if anything,
|
|
3
|
+
* does this block mount?" across BOTH generative-UI channels a guuey pod
|
|
4
|
+
* emits.
|
|
5
|
+
*
|
|
6
|
+
* 1. **inline mcp-ui resource** — `{uri, text|blob}` on `uiData`, or a
|
|
7
|
+
* `ui://` resource degraded into a `provider-raw` content part. Handled
|
|
8
|
+
* verbatim by `block-ui.ts`; this module does not touch that path, it
|
|
9
|
+
* only tries it FIRST.
|
|
10
|
+
* 2. **ggui render** — `uiData.resourceUri` + the `_meta["ai.ggui/render"]`
|
|
11
|
+
* bootstrap, mounted through ggui's self-contained shell. See
|
|
12
|
+
* `ggui-render.ts`.
|
|
13
|
+
*
|
|
14
|
+
* Both channels land on the SAME `McpUiResourcePayload`, which is the whole
|
|
15
|
+
* point: a host that already mounts inline resources through
|
|
16
|
+
* `@mcp-ui/client`'s `AppRenderer` in a second-origin sandbox gains ggui cards
|
|
17
|
+
* without a second mount mechanism, a second iframe contract, or a second
|
|
18
|
+
* security posture to review.
|
|
19
|
+
*
|
|
20
|
+
* Precedence is inline-first and deliberate: an inline resource is the
|
|
21
|
+
* server's explicit, self-sufficient HTML. A ggui render only ever wins when
|
|
22
|
+
* there is no inline resource to prefer, so this dispatcher can never change
|
|
23
|
+
* what an existing inline card renders.
|
|
24
|
+
*
|
|
25
|
+
* ## Why the CHANNEL is returned alongside the resource
|
|
26
|
+
*
|
|
27
|
+
* The payload alone cannot say where it came from — a ggui shell is a string
|
|
28
|
+
* of HTML like any other. But a host has one decision that genuinely depends
|
|
29
|
+
* on the origin of that HTML: WHICH sandbox host page to mount it in. A ggui
|
|
30
|
+
* shell must load ggui's runtime bundle and open its WSS, so it needs a page
|
|
31
|
+
* whose CSP names the ggui origins; an inline card is arbitrary tenant HTML
|
|
32
|
+
* and must keep the self-only page it has always had. Handing back the channel
|
|
33
|
+
* keeps that one narrowing in one place — the alternative was for every host
|
|
34
|
+
* to re-run `toolResultGguiRender` beside this call and ask again.
|
|
35
|
+
*/
|
|
36
|
+
import { type McpUiResourcePayload } from "./block-ui";
|
|
37
|
+
import type { AgBlock, JsonValue } from "@silverprotocol/core";
|
|
38
|
+
/** Which generative-UI channel produced a mount. See this module's header. */
|
|
39
|
+
export type CardMountChannel = "inline" | "ggui";
|
|
40
|
+
/** A mountable card: the resource to hand the host, and where it came from. */
|
|
41
|
+
export interface CardMount {
|
|
42
|
+
/** The payload an mcp-ui host mounts, identical in shape for both channels. */
|
|
43
|
+
resource: McpUiResourcePayload;
|
|
44
|
+
/**
|
|
45
|
+
* `"inline"` — the server's own HTML, untrusted tenant content.
|
|
46
|
+
* `"ggui"` — a shell that boots the ggui runtime from a platform-pinned
|
|
47
|
+
* origin, and therefore needs a host page whose CSP allows that origin.
|
|
48
|
+
*/
|
|
49
|
+
channel: CardMountChannel;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A live `tool-result` block → the card to mount, across both channels.
|
|
53
|
+
* `undefined` when the block carries no generative UI at all (or carries a
|
|
54
|
+
* ggui render whose bootstrap did not reach us — see `ggui-render.ts`).
|
|
55
|
+
*/
|
|
56
|
+
export declare function toolResultCardMount(block: Extract<AgBlock, {
|
|
57
|
+
type: "tool-result";
|
|
58
|
+
}>): CardMount | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* A persisted `HistoryCard`'s `cardSnapshot` → the card to mount, across both
|
|
61
|
+
* channels.
|
|
62
|
+
*
|
|
63
|
+
* The ggui arm is reached only for a snapshot that stored the render's
|
|
64
|
+
* `_meta`; a bootstrap old enough to have been persisted has an expired
|
|
65
|
+
* `wsToken` anyway, so in practice a ggui history card resolves to `undefined`
|
|
66
|
+
* and the host renders its placeholder — honest, and NOT a broken mount.
|
|
67
|
+
*/
|
|
68
|
+
export declare function cardCardMount(cardSnapshot: JsonValue): CardMount | undefined;
|
|
69
|
+
//# sourceMappingURL=card-mount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card-mount.d.ts","sourceRoot":"","sources":["../src/card-mount.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,OAAO,EAAwC,KAAK,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAE7F,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAE/D,8EAA8E;AAC9E,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEjD,+EAA+E;AAC/E,MAAM,WAAW,SAAS;IACxB,+EAA+E;IAC/E,QAAQ,EAAE,oBAAoB,CAAC;IAC/B;;;;OAIG;IACH,OAAO,EAAE,gBAAgB,CAAC;CAC3B;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,CAAC,OAAO,EAAE;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAC,GAC/C,SAAS,GAAG,SAAS,CAMvB;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,YAAY,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAS5E"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The card-mount dispatcher: ONE narrowing that answers "what, if anything,
|
|
3
|
+
* does this block mount?" across BOTH generative-UI channels a guuey pod
|
|
4
|
+
* emits.
|
|
5
|
+
*
|
|
6
|
+
* 1. **inline mcp-ui resource** — `{uri, text|blob}` on `uiData`, or a
|
|
7
|
+
* `ui://` resource degraded into a `provider-raw` content part. Handled
|
|
8
|
+
* verbatim by `block-ui.ts`; this module does not touch that path, it
|
|
9
|
+
* only tries it FIRST.
|
|
10
|
+
* 2. **ggui render** — `uiData.resourceUri` + the `_meta["ai.ggui/render"]`
|
|
11
|
+
* bootstrap, mounted through ggui's self-contained shell. See
|
|
12
|
+
* `ggui-render.ts`.
|
|
13
|
+
*
|
|
14
|
+
* Both channels land on the SAME `McpUiResourcePayload`, which is the whole
|
|
15
|
+
* point: a host that already mounts inline resources through
|
|
16
|
+
* `@mcp-ui/client`'s `AppRenderer` in a second-origin sandbox gains ggui cards
|
|
17
|
+
* without a second mount mechanism, a second iframe contract, or a second
|
|
18
|
+
* security posture to review.
|
|
19
|
+
*
|
|
20
|
+
* Precedence is inline-first and deliberate: an inline resource is the
|
|
21
|
+
* server's explicit, self-sufficient HTML. A ggui render only ever wins when
|
|
22
|
+
* there is no inline resource to prefer, so this dispatcher can never change
|
|
23
|
+
* what an existing inline card renders.
|
|
24
|
+
*
|
|
25
|
+
* ## Why the CHANNEL is returned alongside the resource
|
|
26
|
+
*
|
|
27
|
+
* The payload alone cannot say where it came from — a ggui shell is a string
|
|
28
|
+
* of HTML like any other. But a host has one decision that genuinely depends
|
|
29
|
+
* on the origin of that HTML: WHICH sandbox host page to mount it in. A ggui
|
|
30
|
+
* shell must load ggui's runtime bundle and open its WSS, so it needs a page
|
|
31
|
+
* whose CSP names the ggui origins; an inline card is arbitrary tenant HTML
|
|
32
|
+
* and must keep the self-only page it has always had. Handing back the channel
|
|
33
|
+
* keeps that one narrowing in one place — the alternative was for every host
|
|
34
|
+
* to re-run `toolResultGguiRender` beside this call and ask again.
|
|
35
|
+
*/
|
|
36
|
+
import { cardUiResource, toolResultUiResource } from "./block-ui";
|
|
37
|
+
import { blockGguiRender, gguiRenderResource, toolResultGguiRender } from "./ggui-render";
|
|
38
|
+
/**
|
|
39
|
+
* A live `tool-result` block → the card to mount, across both channels.
|
|
40
|
+
* `undefined` when the block carries no generative UI at all (or carries a
|
|
41
|
+
* ggui render whose bootstrap did not reach us — see `ggui-render.ts`).
|
|
42
|
+
*/
|
|
43
|
+
export function toolResultCardMount(block) {
|
|
44
|
+
const inline = toolResultUiResource(block);
|
|
45
|
+
if (inline)
|
|
46
|
+
return { resource: inline, channel: "inline" };
|
|
47
|
+
const ggui = toolResultGguiRender(block);
|
|
48
|
+
const resource = ggui ? gguiRenderResource(ggui) : undefined;
|
|
49
|
+
return resource ? { resource, channel: "ggui" } : undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A persisted `HistoryCard`'s `cardSnapshot` → the card to mount, across both
|
|
53
|
+
* channels.
|
|
54
|
+
*
|
|
55
|
+
* The ggui arm is reached only for a snapshot that stored the render's
|
|
56
|
+
* `_meta`; a bootstrap old enough to have been persisted has an expired
|
|
57
|
+
* `wsToken` anyway, so in practice a ggui history card resolves to `undefined`
|
|
58
|
+
* and the host renders its placeholder — honest, and NOT a broken mount.
|
|
59
|
+
*/
|
|
60
|
+
export function cardCardMount(cardSnapshot) {
|
|
61
|
+
const inline = cardUiResource(cardSnapshot);
|
|
62
|
+
if (inline)
|
|
63
|
+
return { resource: inline, channel: "inline" };
|
|
64
|
+
for (const block of snapshotBlocks(cardSnapshot)) {
|
|
65
|
+
const ggui = blockGguiRender(block);
|
|
66
|
+
const resource = ggui ? gguiRenderResource(ggui) : undefined;
|
|
67
|
+
if (resource)
|
|
68
|
+
return { resource, channel: "ggui" };
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The blocks to scan inside a card snapshot: the stored `AgArtifact`'s `parts`
|
|
74
|
+
* when present, then the snapshot root itself — exactly `cardUiResource`'s own
|
|
75
|
+
* walk order, so both channels see the same candidates in the same order.
|
|
76
|
+
*/
|
|
77
|
+
function snapshotBlocks(cardSnapshot) {
|
|
78
|
+
if (typeof cardSnapshot !== "object" || cardSnapshot === null || Array.isArray(cardSnapshot)) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
const parts = cardSnapshot.parts;
|
|
82
|
+
return Array.isArray(parts) ? [...parts, cardSnapshot] : [cardSnapshot];
|
|
83
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The **ggui render** channel: narrowing + self-contained shell construction
|
|
3
|
+
* for a generative-UI card produced by the ggui MCP server (`ggui_render`).
|
|
4
|
+
*
|
|
5
|
+
* ## Why this is a second channel and not the existing one
|
|
6
|
+
*
|
|
7
|
+
* `block-ui.ts`'s original narrowing accepts exactly one shape — an mcp-ui
|
|
8
|
+
* embedded resource that carries its HTML INLINE (`{uri, text|blob}`). A ggui
|
|
9
|
+
* render carries no HTML at all. Its `tool.done` looks like this on the wire
|
|
10
|
+
* (shaped identically to the production capture the widget's fixtures
|
|
11
|
+
* replay, but with the SAME synthetic ids those redacted fixtures use —
|
|
12
|
+
* `apps/widget/src/fixtures/issue2627-render-capture.sse.txt` seq 48):
|
|
13
|
+
*
|
|
14
|
+
* ```jsonc
|
|
15
|
+
* {"type":"tool.done", "toolCallId":"toolu_0000…0005",
|
|
16
|
+
* "uiData":{"sessionId":"render_0000…0001",
|
|
17
|
+
* "resourceUri":"ui://ggui/render/render_0000…0001/c10a2055…", … },
|
|
18
|
+
* "_meta":{"ai.ggui/render":{"sessionId":"render_0000…0001","appId":"APP00000",
|
|
19
|
+
* "runtimeUrl":"https://dev.mcp.sandbox.ggui.ai/_ggui/iframe-runtime.js",
|
|
20
|
+
* "wsUrl":"wss://…/ws","wsToken":"eyJ…","expiresAt":"…",
|
|
21
|
+
* "propsJson":"{…}"},
|
|
22
|
+
* "ui":{"resourceUri":"ui://ggui/render/…"}}}
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* Two facts follow, and they shape everything below:
|
|
26
|
+
*
|
|
27
|
+
* 1. **`uiData.resourceUri` is the RECOGNITION signal.** It is the only part
|
|
28
|
+
* of the render's identity that survives `@silverprotocol/core`'s fold
|
|
29
|
+
* (the reducer copies `uiData` — and, as of `@silverprotocol/core`
|
|
30
|
+
* 0.4.1 (workspace#9), `_meta` — onto the `tool-result` block).
|
|
31
|
+
* 2. **`_meta["ai.ggui/render"]` is the MOUNT MATERIAL.** Everything needed
|
|
32
|
+
* to boot the card — which runtime bundle to load, which live-channel to
|
|
33
|
+
* open, which props to seed — lives there and nowhere else.
|
|
34
|
+
*
|
|
35
|
+
* ## How the card mounts (the ggui-documented self-contained shell)
|
|
36
|
+
*
|
|
37
|
+
* ggui's iframe runtime accepts its bootstrap from three delivery channels;
|
|
38
|
+
* the highest-priority one is the **self-contained shell**: HTML that inlines
|
|
39
|
+
* the slice envelope at `globalThis.__GGUI_META__` synchronously BEFORE the
|
|
40
|
+
* runtime bundle's `<script type="module">` evaluates, after which the runtime
|
|
41
|
+
* autostarts, creates its own mount container and renders — no postMessage
|
|
42
|
+
* round-trip, no host-side ggui code. That contract is stated verbatim by the
|
|
43
|
+
* runtime's own reader (`@ggui-ai/iframe-runtime`'s `parseMetaFromGlobal`:
|
|
44
|
+
* *"The global carries the SAME slice envelope shape as the wire `_meta`
|
|
45
|
+
* (`{ "ai.ggui/render": {...} }`) … per-render shells populate this
|
|
46
|
+
* synchronously BEFORE the runtime bundle's `<script type="module">`
|
|
47
|
+
* evaluates"*), and by its boot resolver (`runtime.js`'s autostart:
|
|
48
|
+
* `readSelfContainedMeta()` first, postMessage channels after).
|
|
49
|
+
*
|
|
50
|
+
* {@link gguiShellHtml} builds exactly that shell. Because the shell IS a
|
|
51
|
+
* string of HTML, the ggui card then rides the host's EXISTING mcp-ui mount
|
|
52
|
+
* path unchanged: it narrows to the same `McpUiResourcePayload` an inline
|
|
53
|
+
* resource does, so `@mcp-ui/client`'s `AppRenderer` posts it as `srcdoc` into
|
|
54
|
+
* the second-origin `mcp-app-sandbox.html` page — same double-iframe rule,
|
|
55
|
+
* same sandbox origin, same opaque inner frame. No second mount mechanism.
|
|
56
|
+
*
|
|
57
|
+
* The slice is inlined **verbatim**: `runtimeUrl` is honored as given (ggui's
|
|
58
|
+
* host checklist item 8 — "no fallback URL, no substitution"), and every other
|
|
59
|
+
* field is passed through untouched for the runtime's own projector to
|
|
60
|
+
* validate. This module reads exactly one field (`runtimeUrl`) and only to
|
|
61
|
+
* prove the slice is mountable at all.
|
|
62
|
+
*
|
|
63
|
+
* NOT in scope here: rehydrating a ggui card from persisted history. The
|
|
64
|
+
* bootstrap's `wsToken` expires minutes after the render (`expiresAt` in the
|
|
65
|
+
* capture above), so a stored bootstrap is dead on arrival — a history card
|
|
66
|
+
* without a live bootstrap correctly resolves to `undefined` and renders the
|
|
67
|
+
* host's placeholder rather than a broken mount.
|
|
68
|
+
*/
|
|
69
|
+
import type { AgBlock, JsonValue } from "@silverprotocol/core";
|
|
70
|
+
import { type McpUiResourcePayload } from "./block-ui";
|
|
71
|
+
/** The `_meta` key the ggui render bootstrap rides on (MCP-Apps slice convention). */
|
|
72
|
+
export declare const GGUI_RENDER_META_KEY = "ai.ggui/render";
|
|
73
|
+
/**
|
|
74
|
+
* A ggui render bootstrap: the runtime bundle URL this module reads, plus the
|
|
75
|
+
* WHOLE `ai.ggui/render` slice, verbatim, for the shell to inline.
|
|
76
|
+
*/
|
|
77
|
+
export interface GguiRenderBootstrap {
|
|
78
|
+
/** `runtimeUrl` — the ESM bundle the shell loads. Honored as given. */
|
|
79
|
+
runtimeUrl: string;
|
|
80
|
+
/**
|
|
81
|
+
* The verbatim slice. Open-ended by construction: it is ggui's wire
|
|
82
|
+
* contract, not one this package owns, and the runtime's own projector is
|
|
83
|
+
* the authority on every field. Re-declaring it here would duplicate a
|
|
84
|
+
* contract we do not own and rot at ggui's next field addition.
|
|
85
|
+
*/
|
|
86
|
+
slice: {
|
|
87
|
+
[key: string]: JsonValue;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** A ggui render recognised on a tool result: its resource uri + mount material. */
|
|
91
|
+
export interface GguiRenderDescriptor {
|
|
92
|
+
/** `uiData.resourceUri` — `ui://ggui/render/<sessionId>/<contractHash>`. */
|
|
93
|
+
resourceUri: string;
|
|
94
|
+
/** `uiData.sessionId`, when present. */
|
|
95
|
+
sessionId?: string;
|
|
96
|
+
/**
|
|
97
|
+
* The `_meta["ai.ggui/render"]` slice, when it reached us. Absent for a
|
|
98
|
+
* persisted history card and for any consumer folding without `fold.ts`'s
|
|
99
|
+
* `_meta` carriage — such a descriptor is recognised but NOT mountable.
|
|
100
|
+
*/
|
|
101
|
+
bootstrap?: GguiRenderBootstrap;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* A `_meta` container → the ggui render bootstrap, or `undefined`.
|
|
105
|
+
*
|
|
106
|
+
* Two hard requirements, both the runtime's own `validateMeta` enforces
|
|
107
|
+
* (`MALFORMED_BOOTSTRAP`): a non-empty `runtimeUrl`, AND at least one mode
|
|
108
|
+
* discriminator (see {@link hasModeDiscriminator}). A slice with `runtimeUrl`
|
|
109
|
+
* alone has a bundle to load but nothing for it to mount — the runtime would
|
|
110
|
+
* boot into a blank shell rather than a card, so this guard treats that shape
|
|
111
|
+
* as unmountable too and returns `undefined`.
|
|
112
|
+
*/
|
|
113
|
+
export declare function asGguiRenderBootstrap(meta: JsonValue | undefined): GguiRenderBootstrap | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* A tool result's `uiData` (+ its `_meta`, when carried) → a ggui render
|
|
116
|
+
* descriptor, or `undefined` for anything that is not one.
|
|
117
|
+
*
|
|
118
|
+
* The `ui://` scheme gate is deliberate: `uiData` is a general-purpose channel
|
|
119
|
+
* (every `structuredContent` of a `_meta.ui`-stamped tool lands there), so a
|
|
120
|
+
* bare `resourceUri` string is not on its own a claim of generative UI.
|
|
121
|
+
*/
|
|
122
|
+
export declare function asGguiRender(uiData: JsonValue | undefined, meta: JsonValue | undefined): GguiRenderDescriptor | undefined;
|
|
123
|
+
/** A live `tool-result` AgBlock → its ggui render descriptor, if it is one. */
|
|
124
|
+
export declare function toolResultGguiRender(block: Extract<AgBlock, {
|
|
125
|
+
type: "tool-result";
|
|
126
|
+
}>): GguiRenderDescriptor | undefined;
|
|
127
|
+
/** An untyped (persisted-snapshot) block → its ggui render descriptor, if it is one. */
|
|
128
|
+
export declare function blockGguiRender(block: JsonValue): GguiRenderDescriptor | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* The ggui **self-contained shell** for a render bootstrap — see this module's
|
|
131
|
+
* header for the contract it implements.
|
|
132
|
+
*
|
|
133
|
+
* Ordering is guaranteed twice over: the classic `<script>` runs during parse,
|
|
134
|
+
* and the runtime's `<script type="module">` is deferred by definition, so the
|
|
135
|
+
* global is always populated before the bundle evaluates.
|
|
136
|
+
*/
|
|
137
|
+
export declare function gguiShellHtml(bootstrap: GguiRenderBootstrap): string;
|
|
138
|
+
/**
|
|
139
|
+
* A ggui render descriptor → the mountable resource the host's existing
|
|
140
|
+
* mcp-ui path already knows how to mount, or `undefined` when the descriptor
|
|
141
|
+
* carries no bootstrap (history cards, and any fold that dropped `_meta`).
|
|
142
|
+
*
|
|
143
|
+
* The `uri` is the render's REAL `resourceUri` — the shell is the payload, not
|
|
144
|
+
* a renaming of the resource.
|
|
145
|
+
*
|
|
146
|
+
* **On `_meta` being required to MOUNT (but never to RECOGNISE).** Recognition
|
|
147
|
+
* — "this tool result is a ggui card" — is keyed on `uiData.resourceUri` alone
|
|
148
|
+
* and never waits for anything (see {@link asGguiRender}); nothing in this
|
|
149
|
+
* package is blocked on an upstream change. Mounting is different, and the
|
|
150
|
+
* requirement is ggui's, not ours: its runtime rejects a slice without
|
|
151
|
+
* `runtimeUrl` AND without at least one mode discriminator (`wsUrl`+`wsToken`,
|
|
152
|
+
* `codeUrl`, or `kind`) as `MALFORMED_BOOTSTRAP` and renders nothing. `uiData`
|
|
153
|
+
* carries none of those fields — it has `sessionId`, `resourceUri`, `action`,
|
|
154
|
+
* `contractHash`, `blueprintId`, `variantKey`, `cache`, `nextStep`, and that is
|
|
155
|
+
* all. So a bootstrap-less descriptor could only ever produce a blank frame;
|
|
156
|
+
* returning `undefined` and letting the host show its own placeholder is the
|
|
157
|
+
* honest answer, not a deferral. `@silverprotocol/core`'s `Reducer` is what
|
|
158
|
+
* puts `_meta` on the block for a live turn, in-repo, today.
|
|
159
|
+
*/
|
|
160
|
+
export declare function gguiRenderResource(render: GguiRenderDescriptor): McpUiResourcePayload | undefined;
|
|
161
|
+
//# sourceMappingURL=ggui-render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ggui-render.d.ts","sourceRoot":"","sources":["../src/ggui-render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAgB,KAAK,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAErE,sFAAsF;AACtF,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AAKrD;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,uEAAuE;IACvE,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,KAAK,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;CACrC;AAED,oFAAoF;AACpF,MAAM,WAAW,oBAAoB;IACnC,4EAA4E;IAC5E,WAAW,EAAE,MAAM,CAAC;IACpB,wCAAwC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,SAAS,CAAC,EAAE,mBAAmB,CAAC;CACjC;AAwBD;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,mBAAmB,GAAG,SAAS,CAQlG;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,SAAS,GAAG,SAAS,EAC7B,IAAI,EAAE,SAAS,GAAG,SAAS,GAC1B,oBAAoB,GAAG,SAAS,CAUlC;AAED,+EAA+E;AAC/E,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,CAAC,OAAO,EAAE;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAC,GAC/C,oBAAoB,GAAG,SAAS,CAElC;AAED,wFAAwF;AACxF,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,GAAG,oBAAoB,GAAG,SAAS,CAIlF;AA0BD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,mBAAmB,GAAG,MAAM,CAkBpE;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,oBAAoB,GAC3B,oBAAoB,GAAG,SAAS,CAOlC"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { isJsonObject } from "./block-ui";
|
|
2
|
+
/** The `_meta` key the ggui render bootstrap rides on (MCP-Apps slice convention). */
|
|
3
|
+
export const GGUI_RENDER_META_KEY = "ai.ggui/render";
|
|
4
|
+
/** The `ui://` scheme prefix every ggui render resource uri carries. */
|
|
5
|
+
const UI_SCHEME = "ui://";
|
|
6
|
+
/** A non-empty JSON string field. */
|
|
7
|
+
function isNonEmptyString(value) {
|
|
8
|
+
return typeof value === "string" && value.length > 0;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Does this slice carry at least one MOUNT MODE discriminator?
|
|
12
|
+
*
|
|
13
|
+
* Mirrors `@ggui-ai/iframe-runtime`'s `validateMeta` (see
|
|
14
|
+
* `node_modules/@ggui-ai/iframe-runtime/dist/meta-parse.d.ts`) and the
|
|
15
|
+
* `McpAppAiGguiRenderMeta` doc comment it implements
|
|
16
|
+
* (`@ggui-ai/protocol/integrations/mcp-apps`): the runtime needs `runtimeUrl`
|
|
17
|
+
* PLUS one of live mode (`wsUrl` + `wsToken` together), `codeUrl`, or `kind` —
|
|
18
|
+
* without one of those three the iframe has nothing to mount.
|
|
19
|
+
*/
|
|
20
|
+
function hasModeDiscriminator(slice) {
|
|
21
|
+
if (isNonEmptyString(slice.wsUrl) && isNonEmptyString(slice.wsToken))
|
|
22
|
+
return true;
|
|
23
|
+
if (isNonEmptyString(slice.codeUrl))
|
|
24
|
+
return true;
|
|
25
|
+
if (isNonEmptyString(slice.kind))
|
|
26
|
+
return true;
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A `_meta` container → the ggui render bootstrap, or `undefined`.
|
|
31
|
+
*
|
|
32
|
+
* Two hard requirements, both the runtime's own `validateMeta` enforces
|
|
33
|
+
* (`MALFORMED_BOOTSTRAP`): a non-empty `runtimeUrl`, AND at least one mode
|
|
34
|
+
* discriminator (see {@link hasModeDiscriminator}). A slice with `runtimeUrl`
|
|
35
|
+
* alone has a bundle to load but nothing for it to mount — the runtime would
|
|
36
|
+
* boot into a blank shell rather than a card, so this guard treats that shape
|
|
37
|
+
* as unmountable too and returns `undefined`.
|
|
38
|
+
*/
|
|
39
|
+
export function asGguiRenderBootstrap(meta) {
|
|
40
|
+
if (!isJsonObject(meta))
|
|
41
|
+
return undefined;
|
|
42
|
+
const slice = meta[GGUI_RENDER_META_KEY];
|
|
43
|
+
if (!isJsonObject(slice))
|
|
44
|
+
return undefined;
|
|
45
|
+
const runtimeUrl = slice.runtimeUrl;
|
|
46
|
+
if (typeof runtimeUrl !== "string" || runtimeUrl.length === 0)
|
|
47
|
+
return undefined;
|
|
48
|
+
if (!hasModeDiscriminator(slice))
|
|
49
|
+
return undefined;
|
|
50
|
+
return { runtimeUrl, slice };
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A tool result's `uiData` (+ its `_meta`, when carried) → a ggui render
|
|
54
|
+
* descriptor, or `undefined` for anything that is not one.
|
|
55
|
+
*
|
|
56
|
+
* The `ui://` scheme gate is deliberate: `uiData` is a general-purpose channel
|
|
57
|
+
* (every `structuredContent` of a `_meta.ui`-stamped tool lands there), so a
|
|
58
|
+
* bare `resourceUri` string is not on its own a claim of generative UI.
|
|
59
|
+
*/
|
|
60
|
+
export function asGguiRender(uiData, meta) {
|
|
61
|
+
if (!isJsonObject(uiData))
|
|
62
|
+
return undefined;
|
|
63
|
+
const resourceUri = uiData.resourceUri;
|
|
64
|
+
if (typeof resourceUri !== "string" || !resourceUri.startsWith(UI_SCHEME))
|
|
65
|
+
return undefined;
|
|
66
|
+
const bootstrap = asGguiRenderBootstrap(meta);
|
|
67
|
+
return {
|
|
68
|
+
resourceUri,
|
|
69
|
+
...(typeof uiData.sessionId === "string" ? { sessionId: uiData.sessionId } : {}),
|
|
70
|
+
...(bootstrap ? { bootstrap } : {}),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** A live `tool-result` AgBlock → its ggui render descriptor, if it is one. */
|
|
74
|
+
export function toolResultGguiRender(block) {
|
|
75
|
+
return asGguiRender(block.uiData, block._meta);
|
|
76
|
+
}
|
|
77
|
+
/** An untyped (persisted-snapshot) block → its ggui render descriptor, if it is one. */
|
|
78
|
+
export function blockGguiRender(block) {
|
|
79
|
+
if (!isJsonObject(block))
|
|
80
|
+
return undefined;
|
|
81
|
+
if (block.type !== "tool-result")
|
|
82
|
+
return undefined;
|
|
83
|
+
return asGguiRender(block.uiData, block._meta);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Embed a JSON value inside an inline `<script>` safely.
|
|
87
|
+
*
|
|
88
|
+
* `</script` inside a string literal terminates the element in the HTML
|
|
89
|
+
* parser regardless of JS quoting, and U+2028/U+2029 are line terminators in
|
|
90
|
+
* JS source but not in JSON — both are escaped at the `<`/codepoint level so
|
|
91
|
+
* the emitted text is still exactly the same JSON value.
|
|
92
|
+
*/
|
|
93
|
+
function inlineJson(value) {
|
|
94
|
+
return JSON.stringify(value)
|
|
95
|
+
.replace(/</g, "\\u003c")
|
|
96
|
+
.replace(/\u2028/g, "\\u2028")
|
|
97
|
+
.replace(/\u2029/g, "\\u2029");
|
|
98
|
+
}
|
|
99
|
+
/** Escape a string for use inside a double-quoted HTML attribute. */
|
|
100
|
+
function attr(value) {
|
|
101
|
+
return value
|
|
102
|
+
.replace(/&/g, "&")
|
|
103
|
+
.replace(/"/g, """)
|
|
104
|
+
.replace(/</g, "<")
|
|
105
|
+
.replace(/>/g, ">");
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The ggui **self-contained shell** for a render bootstrap — see this module's
|
|
109
|
+
* header for the contract it implements.
|
|
110
|
+
*
|
|
111
|
+
* Ordering is guaranteed twice over: the classic `<script>` runs during parse,
|
|
112
|
+
* and the runtime's `<script type="module">` is deferred by definition, so the
|
|
113
|
+
* global is always populated before the bundle evaluates.
|
|
114
|
+
*/
|
|
115
|
+
export function gguiShellHtml(bootstrap) {
|
|
116
|
+
const envelope = inlineJson({ [GGUI_RENDER_META_KEY]: bootstrap.slice });
|
|
117
|
+
return [
|
|
118
|
+
"<!doctype html>",
|
|
119
|
+
'<html lang="en">',
|
|
120
|
+
"<head>",
|
|
121
|
+
'<meta charset="utf-8">',
|
|
122
|
+
'<meta name="viewport" content="width=device-width, initial-scale=1">',
|
|
123
|
+
'<meta name="color-scheme" content="light dark">',
|
|
124
|
+
"<title>ggui card</title>",
|
|
125
|
+
"<style>html,body{margin:0;height:100%;background:transparent}</style>",
|
|
126
|
+
`<script>globalThis.__GGUI_META__=${envelope};</script>`,
|
|
127
|
+
`<script type="module" src="${attr(bootstrap.runtimeUrl)}"></script>`,
|
|
128
|
+
"</head>",
|
|
129
|
+
"<body></body>",
|
|
130
|
+
"</html>",
|
|
131
|
+
"",
|
|
132
|
+
].join("\n");
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* A ggui render descriptor → the mountable resource the host's existing
|
|
136
|
+
* mcp-ui path already knows how to mount, or `undefined` when the descriptor
|
|
137
|
+
* carries no bootstrap (history cards, and any fold that dropped `_meta`).
|
|
138
|
+
*
|
|
139
|
+
* The `uri` is the render's REAL `resourceUri` — the shell is the payload, not
|
|
140
|
+
* a renaming of the resource.
|
|
141
|
+
*
|
|
142
|
+
* **On `_meta` being required to MOUNT (but never to RECOGNISE).** Recognition
|
|
143
|
+
* — "this tool result is a ggui card" — is keyed on `uiData.resourceUri` alone
|
|
144
|
+
* and never waits for anything (see {@link asGguiRender}); nothing in this
|
|
145
|
+
* package is blocked on an upstream change. Mounting is different, and the
|
|
146
|
+
* requirement is ggui's, not ours: its runtime rejects a slice without
|
|
147
|
+
* `runtimeUrl` AND without at least one mode discriminator (`wsUrl`+`wsToken`,
|
|
148
|
+
* `codeUrl`, or `kind`) as `MALFORMED_BOOTSTRAP` and renders nothing. `uiData`
|
|
149
|
+
* carries none of those fields — it has `sessionId`, `resourceUri`, `action`,
|
|
150
|
+
* `contractHash`, `blueprintId`, `variantKey`, `cache`, `nextStep`, and that is
|
|
151
|
+
* all. So a bootstrap-less descriptor could only ever produce a blank frame;
|
|
152
|
+
* returning `undefined` and letting the host show its own placeholder is the
|
|
153
|
+
* honest answer, not a deferral. `@silverprotocol/core`'s `Reducer` is what
|
|
154
|
+
* puts `_meta` on the block for a live turn, in-repo, today.
|
|
155
|
+
*/
|
|
156
|
+
export function gguiRenderResource(render) {
|
|
157
|
+
if (!render.bootstrap)
|
|
158
|
+
return undefined;
|
|
159
|
+
return {
|
|
160
|
+
uri: render.resourceUri,
|
|
161
|
+
mimeType: "text/html",
|
|
162
|
+
text: gguiShellHtml(render.bootstrap),
|
|
163
|
+
};
|
|
164
|
+
}
|
package/dist/history.d.ts
CHANGED
|
@@ -26,6 +26,18 @@ export interface ThreadHistoryRow {
|
|
|
26
26
|
*/
|
|
27
27
|
cardSnapshot?: JsonValue | null;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Thrown when the read plane returns 401 on a transcript fetch — distinct
|
|
31
|
+
* from the generic non-OK throw below so a caller holding a token can
|
|
32
|
+
* `instanceof`-match it and retry once with a freshly-refreshed one
|
|
33
|
+
* (`createWebAdapters`'s history adapter is the concrete retry). A cached
|
|
34
|
+
* bearer that has expired since the caller last checked it is exactly the
|
|
35
|
+
* shape a refresh can fix; a 500 or a malformed request is not, and gets no
|
|
36
|
+
* such retry.
|
|
37
|
+
*/
|
|
38
|
+
export declare class HistoryUnauthorizedError extends Error {
|
|
39
|
+
constructor(message?: string);
|
|
40
|
+
}
|
|
29
41
|
/** Project raw rows to chat turns: text rows only, author → role. */
|
|
30
42
|
export declare function threadHistoryRowsToMessages(rows: ThreadHistoryRow[]): AgentMessage[];
|
|
31
43
|
/**
|
package/dist/history.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE5E,iDAAiD;AACjD,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB;;;;OAIG;IACH,YAAY,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;CACjC;
|
|
1
|
+
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE5E,iDAAiD;AACjD,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB;;;;OAIG;IACH,YAAY,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;CACjC;AAOD;;;;;;;;GAQG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,SAA6B;CAIjD;AAeD,qEAAqE;AACrE,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,gBAAgB,EAAE,GAAG,YAAY,EAAE,CAOpF;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,gBAAgB,EAAE,GAAG,WAAW,EAAE,CAOhF;AAED,MAAM,WAAW,yBAAyB;IACxC,uDAAuD;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gEAAgE;IAChE,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CAAC,EACvC,OAAO,EACP,QAAQ,EACR,WAAW,EACX,YAAoB,EACpB,SAAiB,GAClB,EAAE,yBAAyB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAuBxD"}
|
package/dist/history.js
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when the read plane returns 401 on a transcript fetch — distinct
|
|
3
|
+
* from the generic non-OK throw below so a caller holding a token can
|
|
4
|
+
* `instanceof`-match it and retry once with a freshly-refreshed one
|
|
5
|
+
* (`createWebAdapters`'s history adapter is the concrete retry). A cached
|
|
6
|
+
* bearer that has expired since the caller last checked it is exactly the
|
|
7
|
+
* shape a refresh can fix; a 500 or a malformed request is not, and gets no
|
|
8
|
+
* such retry.
|
|
9
|
+
*/
|
|
10
|
+
export class HistoryUnauthorizedError extends Error {
|
|
11
|
+
constructor(message = "history load failed: 401") {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "HistoryUnauthorizedError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
1
16
|
/** Rows requested per history page. */
|
|
2
17
|
const HISTORY_PAGE_LIMIT = 100;
|
|
3
18
|
/**
|
|
@@ -51,6 +66,8 @@ export async function fetchThreadHistory({ baseUrl, threadId, requestInit, inclu
|
|
|
51
66
|
const res = await fetchImpl(url, requestInit);
|
|
52
67
|
if (res.status === 403 || res.status === 404)
|
|
53
68
|
return { gone: true };
|
|
69
|
+
if (res.status === 401)
|
|
70
|
+
throw new HistoryUnauthorizedError();
|
|
54
71
|
if (!res.ok)
|
|
55
72
|
throw new Error(`history load failed: ${res.status}`);
|
|
56
73
|
const body = await res.json();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
export { parseSseEvents, extractAssistantText, reduceAssistantText, stringField, type ParsedSseEvent, } from "./sse";
|
|
1
|
+
export { parseSseEvents, extractAssistantText, reduceAssistantText, stringField, parseConsentRequest, parseLinkRequest, type ParsedSseEvent, } from "./sse";
|
|
2
|
+
export { dismissLinkPrompt } from "./link-prompt";
|
|
2
3
|
export { createWebAdapters, localStorageThreadStore, webGenerateId, fetchStreamTransport, AgentResponseError, type CreateWebAdaptersOptions, } from "./web-adapters";
|
|
3
|
-
export { fetchThreadHistory, threadHistoryRowsToMessages, threadHistoryRowsToCards, type ThreadHistoryRow, type ThreadHistoryFetchOptions, } from "./history";
|
|
4
|
+
export { fetchThreadHistory, threadHistoryRowsToMessages, threadHistoryRowsToCards, HistoryUnauthorizedError, type ThreadHistoryRow, type ThreadHistoryFetchOptions, } from "./history";
|
|
4
5
|
export { ingestMessageFrame } from "./blocks";
|
|
5
6
|
export { asResourcePayload, asUiResource, blockUiResource, cardUiResource, isJsonObject, resourceHtml, scanProviderRawForUiResource, sortHistoryCards, toolNameFor, toolResultUiResource, type McpUiResourcePayload, } from "./block-ui";
|
|
7
|
+
export { asGguiRender, asGguiRenderBootstrap, blockGguiRender, gguiRenderResource, gguiShellHtml, toolResultGguiRender, GGUI_RENDER_META_KEY, type GguiRenderBootstrap, type GguiRenderDescriptor, } from "./ggui-render";
|
|
8
|
+
export { cardCardMount, toolResultCardMount, type CardMount, type CardMountChannel, } from "./card-mount";
|
|
6
9
|
export type { AgEvent, AgReduceResult, AgMessage, AgBlock } from "@silverprotocol/core";
|
|
7
|
-
export type { AgentMessage, HistoryCard, ThreadIdStore, GenerateId, InvokeRequest, InvokeTransport, AgentInvokeAdapters, AgentInvokeHistoryAdapter, HistoryLoadResult, UseAgentInvokeOptions, UseAgentInvokeReturn, } from "./types";
|
|
10
|
+
export type { AgentMessage, HistoryCard, ProfileConsentRequest, ProfileLinkRequest, ThreadIdStore, GenerateId, InvokeRequest, InvokeTransport, AgentInvokeAdapters, AgentInvokeHistoryAdapter, AgentInvokeStatus, HistoryLoadResult, UseAgentInvokeOptions, UseAgentInvokeReturn, } from "./types";
|
|
8
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,WAAW,EACX,KAAK,cAAc,GACpB,MAAM,OAAO,CAAC;AACf,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,KAAK,wBAAwB,GAC9B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,kBAAkB,EAClB,2BAA2B,EAC3B,wBAAwB,EACxB,KAAK,gBAAgB,EACrB,KAAK,yBAAyB,GAC/B,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAG9C,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,4BAA4B,EAC5B,gBAAgB,EAChB,WAAW,EACX,oBAAoB,EACpB,KAAK,oBAAoB,GAC1B,MAAM,YAAY,CAAC;AAIpB,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACxF,YAAY,EACV,YAAY,EACZ,WAAW,EACX,aAAa,EACb,UAAU,EACV,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,WAAW,EACX,mBAAmB,EACnB,gBAAgB,EAChB,KAAK,cAAc,GACpB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,KAAK,wBAAwB,GAC9B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,kBAAkB,EAClB,2BAA2B,EAC3B,wBAAwB,EACxB,wBAAwB,EACxB,KAAK,gBAAgB,EACrB,KAAK,yBAAyB,GAC/B,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAG9C,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,4BAA4B,EAC5B,gBAAgB,EAChB,WAAW,EACX,oBAAoB,EACpB,KAAK,oBAAoB,GAC1B,MAAM,YAAY,CAAC;AAIpB,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,GAC1B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,KAAK,SAAS,EACd,KAAK,gBAAgB,GACtB,MAAM,cAAc,CAAC;AAItB,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACxF,YAAY,EACV,YAAY,EACZ,WAAW,EACX,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,UAAU,EACV,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
export { parseSseEvents, extractAssistantText, reduceAssistantText, stringField, } from "./sse";
|
|
1
|
+
export { parseSseEvents, extractAssistantText, reduceAssistantText, stringField, parseConsentRequest, parseLinkRequest, } from "./sse";
|
|
2
|
+
export { dismissLinkPrompt } from "./link-prompt";
|
|
2
3
|
export { createWebAdapters, localStorageThreadStore, webGenerateId, fetchStreamTransport, AgentResponseError, } from "./web-adapters";
|
|
3
|
-
export { fetchThreadHistory, threadHistoryRowsToMessages, threadHistoryRowsToCards, } from "./history";
|
|
4
|
+
export { fetchThreadHistory, threadHistoryRowsToMessages, threadHistoryRowsToCards, HistoryUnauthorizedError, } from "./history";
|
|
4
5
|
export { ingestMessageFrame } from "./blocks";
|
|
5
6
|
// Pure block-walk / resource-narrowing helpers for a block-preserving renderer
|
|
6
7
|
// (shared by Studio's `AgentBlocks` and Portal-web's agent chat). React-free.
|
|
7
8
|
export { asResourcePayload, asUiResource, blockUiResource, cardUiResource, isJsonObject, resourceHtml, scanProviderRawForUiResource, sortHistoryCards, toolNameFor, toolResultUiResource, } from "./block-ui";
|
|
9
|
+
// The ggui render channel (`uiData.resourceUri` + the `_meta["ai.ggui/render"]`
|
|
10
|
+
// bootstrap) and the dispatcher that mounts EITHER channel through the same
|
|
11
|
+
// second-origin sandbox path.
|
|
12
|
+
export { asGguiRender, asGguiRenderBootstrap, blockGguiRender, gguiRenderResource, gguiShellHtml, toolResultGguiRender, GGUI_RENDER_META_KEY, } from "./ggui-render";
|
|
13
|
+
export { cardCardMount, toolResultCardMount, } from "./card-mount";
|