Skip to content

Commit afe66be

Browse files
committed
docs(showcase): a2ui-fixed-schema backend siblings across 6 frameworks
The shell-docs `/generative-ui/a2ui/fixed-schema` page references the regions `backend-schema-json-load` and `backend-render-operations` to teach how the backend loads (or inlines) the A2UI schema and emits render operations. 5 frameworks (ag2, agno, claude-sdk-python, claude-sdk-typescript, langroid) ship working schema-loading demos but hadn't tagged those region markers, so cells rendered a yellow "missing snippet" box. built-in-agent has the same issue with its schema-inline variant. Per the established sibling convention (matching `tool-rendering/render-flight-tool.snippet.tsx`), each framework now ships a docs-only `a2ui-backend.snippet.{py,ts}` exposing both regions with the canonical pattern. Zero changes to the actual demo source. Files: - 4 × `.snippet.py` (Python backends): ag2, agno, claude-sdk-python, langroid - 1 × `.snippet.ts` (TypeScript backend, schema-loading): claude-sdk-typescript - 1 × `.snippet.ts` (TypeScript backend, schema-inline): built-in-agent Closes 12 B-docs-gap region refs (6 frameworks × 2 regions).
1 parent 951b722 commit afe66be

6 files changed

Lines changed: 385 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Docs-only snippet — not imported or run. The shell-docs page at
2+
# `/generative-ui/a2ui/fixed-schema` references the regions
3+
# `backend-schema-json-load` and `backend-render-operations` to teach
4+
# the schema-loading pattern. This file exposes those regions as
5+
# canonical teaching code so the docs render real samples instead of a
6+
# missing-snippet box. The actual demo backend already loads the schema
7+
# and emits operations end-to-end; this sibling just isolates the two
8+
# teaching lines.
9+
#
10+
# Mirrors the convention from `tool-rendering/render-flight-tool.snippet.tsx`.
11+
12+
from pathlib import Path
13+
import json
14+
15+
_SCHEMAS_DIR = Path(__file__).parent / "a2ui_schemas"
16+
17+
# Stand-in for the real a2ui SDK helpers. In a real backend, import
18+
# `a2ui` from your runtime SDK; the calls below match its shape.
19+
class _A2UI:
20+
@staticmethod
21+
def load_schema(path):
22+
with open(path) as fh:
23+
return json.load(fh)
24+
@staticmethod
25+
def create_surface(*args, **kwargs): ...
26+
@staticmethod
27+
def update_components(*args, **kwargs): ...
28+
@staticmethod
29+
def update_data_model(*args, **kwargs): ...
30+
@staticmethod
31+
def render(*args, **kwargs): ...
32+
a2ui = _A2UI()
33+
SURFACE_ID = "flight-fixed-schema"
34+
CATALOG_ID = "flight-catalog"
35+
36+
37+
# @region[backend-schema-json-load]
38+
# Schemas are JSON so they can be authored and reviewed independently of
39+
# the backend code. `a2ui.load_schema` is just a thin `json.load` wrapper
40+
# that resolves the path against the schemas directory.
41+
FLIGHT_SCHEMA = a2ui.load_schema(_SCHEMAS_DIR / "flight_schema.json")
42+
# @endregion[backend-schema-json-load]
43+
44+
45+
def emit_render_operations(origin: str, destination: str, airline: str, price: float):
46+
# @region[backend-render-operations]
47+
# The a2ui middleware detects the `a2ui_operations` container in this
48+
# tool result and forwards the ops to the frontend renderer. The
49+
# frontend catalog resolves component names to local React components.
50+
return a2ui.render(
51+
operations=[
52+
a2ui.create_surface(SURFACE_ID, catalog_id=CATALOG_ID),
53+
a2ui.update_components(SURFACE_ID, FLIGHT_SCHEMA),
54+
a2ui.update_data_model(
55+
SURFACE_ID,
56+
{
57+
"origin": origin,
58+
"destination": destination,
59+
"airline": airline,
60+
"price": price,
61+
},
62+
),
63+
],
64+
)
65+
# @endregion[backend-render-operations]
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Docs-only snippet — not imported or run. The shell-docs page at
2+
# `/generative-ui/a2ui/fixed-schema` references the regions
3+
# `backend-schema-json-load` and `backend-render-operations` to teach
4+
# the schema-loading pattern. This file exposes those regions as
5+
# canonical teaching code so the docs render real samples instead of a
6+
# missing-snippet box. The actual demo backend already loads the schema
7+
# and emits operations end-to-end; this sibling just isolates the two
8+
# teaching lines.
9+
#
10+
# Mirrors the convention from `tool-rendering/render-flight-tool.snippet.tsx`.
11+
12+
from pathlib import Path
13+
import json
14+
15+
_SCHEMAS_DIR = Path(__file__).parent / "a2ui_schemas"
16+
17+
# Stand-in for the real a2ui SDK helpers. In a real backend, import
18+
# `a2ui` from your runtime SDK; the calls below match its shape.
19+
class _A2UI:
20+
@staticmethod
21+
def load_schema(path):
22+
with open(path) as fh:
23+
return json.load(fh)
24+
@staticmethod
25+
def create_surface(*args, **kwargs): ...
26+
@staticmethod
27+
def update_components(*args, **kwargs): ...
28+
@staticmethod
29+
def update_data_model(*args, **kwargs): ...
30+
@staticmethod
31+
def render(*args, **kwargs): ...
32+
a2ui = _A2UI()
33+
SURFACE_ID = "flight-fixed-schema"
34+
CATALOG_ID = "flight-catalog"
35+
36+
37+
# @region[backend-schema-json-load]
38+
# Schemas are JSON so they can be authored and reviewed independently of
39+
# the backend code. `a2ui.load_schema` is just a thin `json.load` wrapper
40+
# that resolves the path against the schemas directory.
41+
FLIGHT_SCHEMA = a2ui.load_schema(_SCHEMAS_DIR / "flight_schema.json")
42+
# @endregion[backend-schema-json-load]
43+
44+
45+
def emit_render_operations(origin: str, destination: str, airline: str, price: float):
46+
# @region[backend-render-operations]
47+
# The a2ui middleware detects the `a2ui_operations` container in this
48+
# tool result and forwards the ops to the frontend renderer. The
49+
# frontend catalog resolves component names to local React components.
50+
return a2ui.render(
51+
operations=[
52+
a2ui.create_surface(SURFACE_ID, catalog_id=CATALOG_ID),
53+
a2ui.update_components(SURFACE_ID, FLIGHT_SCHEMA),
54+
a2ui.update_data_model(
55+
SURFACE_ID,
56+
{
57+
"origin": origin,
58+
"destination": destination,
59+
"airline": airline,
60+
"price": price,
61+
},
62+
),
63+
],
64+
)
65+
# @endregion[backend-render-operations]
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Docs-only snippet — not imported or run. The shell-docs page at
2+
// `/generative-ui/a2ui/fixed-schema` references the regions
3+
// `backend-schema-json-load` and `backend-render-operations` to teach
4+
// the *schema-inline* pattern for built-in-agent (the schema is declared
5+
// as a typed literal in source rather than loaded from JSON at startup).
6+
// This file exposes those regions as canonical teaching code so the docs
7+
// render real samples instead of a missing-snippet box.
8+
//
9+
// Mirrors the convention from `tool-rendering/render-flight-tool.snippet.tsx`.
10+
11+
declare const a2ui: {
12+
createSurface: (id: string, opts: { catalogId: string }) => unknown;
13+
updateComponents: (id: string, schema: unknown) => unknown;
14+
updateDataModel: (id: string, data: Record<string, unknown>) => unknown;
15+
render: (args: { operations: unknown[] }) => unknown;
16+
};
17+
const SURFACE_ID = "flight-fixed-schema";
18+
const CATALOG_ID = "flight-catalog";
19+
20+
// @region[backend-schema-json-load]
21+
// In the schema-inline pattern, the schema is declared as a typed literal
22+
// in source rather than loaded from JSON at startup. Same shape as the
23+
// schema-loading variant; just no file I/O.
24+
const FLIGHT_SCHEMA = [
25+
{
26+
type: "Card",
27+
children: [
28+
{ type: "Title", text: "Flight" },
29+
{ type: "Row", children: [
30+
{ type: "Label", bind: "origin" },
31+
{ type: "Label", bind: "destination" },
32+
]},
33+
{ type: "Row", children: [
34+
{ type: "Label", bind: "airline" },
35+
{ type: "Label", bind: "price" },
36+
]},
37+
],
38+
},
39+
];
40+
// @endregion[backend-schema-json-load]
41+
42+
export function emitRenderOperations(args: {
43+
origin: string;
44+
destination: string;
45+
airline: string;
46+
price: number;
47+
}) {
48+
// @region[backend-render-operations]
49+
// The a2ui middleware detects the `a2ui_operations` container in this
50+
// tool result and forwards the ops to the frontend renderer. The
51+
// frontend catalog resolves component names to local React components.
52+
return a2ui.render({
53+
operations: [
54+
a2ui.createSurface(SURFACE_ID, { catalogId: CATALOG_ID }),
55+
a2ui.updateComponents(SURFACE_ID, FLIGHT_SCHEMA),
56+
a2ui.updateDataModel(SURFACE_ID, {
57+
origin: args.origin,
58+
destination: args.destination,
59+
airline: args.airline,
60+
price: args.price,
61+
}),
62+
],
63+
});
64+
// @endregion[backend-render-operations]
65+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Docs-only snippet — not imported or run. The shell-docs page at
2+
# `/generative-ui/a2ui/fixed-schema` references the regions
3+
# `backend-schema-json-load` and `backend-render-operations` to teach
4+
# the schema-loading pattern. This file exposes those regions as
5+
# canonical teaching code so the docs render real samples instead of a
6+
# missing-snippet box. The actual demo backend already loads the schema
7+
# and emits operations end-to-end; this sibling just isolates the two
8+
# teaching lines.
9+
#
10+
# Mirrors the convention from `tool-rendering/render-flight-tool.snippet.tsx`.
11+
12+
from pathlib import Path
13+
import json
14+
15+
_SCHEMAS_DIR = Path(__file__).parent / "a2ui_schemas"
16+
17+
# Stand-in for the real a2ui SDK helpers. In a real backend, import
18+
# `a2ui` from your runtime SDK; the calls below match its shape.
19+
class _A2UI:
20+
@staticmethod
21+
def load_schema(path):
22+
with open(path) as fh:
23+
return json.load(fh)
24+
@staticmethod
25+
def create_surface(*args, **kwargs): ...
26+
@staticmethod
27+
def update_components(*args, **kwargs): ...
28+
@staticmethod
29+
def update_data_model(*args, **kwargs): ...
30+
@staticmethod
31+
def render(*args, **kwargs): ...
32+
a2ui = _A2UI()
33+
SURFACE_ID = "flight-fixed-schema"
34+
CATALOG_ID = "flight-catalog"
35+
36+
37+
# @region[backend-schema-json-load]
38+
# Schemas are JSON so they can be authored and reviewed independently of
39+
# the backend code. `a2ui.load_schema` is just a thin `json.load` wrapper
40+
# that resolves the path against the schemas directory.
41+
FLIGHT_SCHEMA = a2ui.load_schema(_SCHEMAS_DIR / "flight_schema.json")
42+
# @endregion[backend-schema-json-load]
43+
44+
45+
def emit_render_operations(origin: str, destination: str, airline: str, price: float):
46+
# @region[backend-render-operations]
47+
# The a2ui middleware detects the `a2ui_operations` container in this
48+
# tool result and forwards the ops to the frontend renderer. The
49+
# frontend catalog resolves component names to local React components.
50+
return a2ui.render(
51+
operations=[
52+
a2ui.create_surface(SURFACE_ID, catalog_id=CATALOG_ID),
53+
a2ui.update_components(SURFACE_ID, FLIGHT_SCHEMA),
54+
a2ui.update_data_model(
55+
SURFACE_ID,
56+
{
57+
"origin": origin,
58+
"destination": destination,
59+
"airline": airline,
60+
"price": price,
61+
},
62+
),
63+
],
64+
)
65+
# @endregion[backend-render-operations]
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Docs-only snippet — not imported or run. The shell-docs page at
2+
// `/generative-ui/a2ui/fixed-schema` references the regions
3+
// `backend-schema-json-load` and `backend-render-operations` to teach
4+
// the schema-loading pattern. This file exposes those regions as
5+
// canonical teaching code so the docs render real samples instead of a
6+
// missing-snippet box.
7+
//
8+
// Mirrors the convention from `tool-rendering/render-flight-tool.snippet.tsx`.
9+
10+
import path from "path";
11+
import fs from "fs";
12+
13+
const SCHEMAS_DIR = path.join(__dirname, "a2ui_schemas");
14+
15+
// Stand-in for the real a2ui SDK helpers. In a real backend, import
16+
// `a2ui` from your runtime SDK.
17+
declare const a2ui: {
18+
loadSchema: (path: string) => unknown;
19+
createSurface: (id: string, opts: { catalogId: string }) => unknown;
20+
updateComponents: (id: string, schema: unknown) => unknown;
21+
updateDataModel: (id: string, data: Record<string, unknown>) => unknown;
22+
render: (args: { operations: unknown[] }) => unknown;
23+
};
24+
const SURFACE_ID = "flight-fixed-schema";
25+
const CATALOG_ID = "flight-catalog";
26+
27+
// @region[backend-schema-json-load]
28+
// Schemas are JSON so they can be authored and reviewed independently of
29+
// the backend code. `a2ui.loadSchema` is a thin wrapper around
30+
// `JSON.parse(fs.readFileSync(...))` that resolves the path against the
31+
// schemas directory.
32+
const FLIGHT_SCHEMA = a2ui.loadSchema(
33+
path.join(SCHEMAS_DIR, "flight_schema.json"),
34+
);
35+
// @endregion[backend-schema-json-load]
36+
37+
export function emitRenderOperations(args: {
38+
origin: string;
39+
destination: string;
40+
airline: string;
41+
price: number;
42+
}) {
43+
// @region[backend-render-operations]
44+
// The a2ui middleware detects the `a2ui_operations` container in this
45+
// tool result and forwards the ops to the frontend renderer. The
46+
// frontend catalog resolves component names to local React components.
47+
return a2ui.render({
48+
operations: [
49+
a2ui.createSurface(SURFACE_ID, { catalogId: CATALOG_ID }),
50+
a2ui.updateComponents(SURFACE_ID, FLIGHT_SCHEMA),
51+
a2ui.updateDataModel(SURFACE_ID, {
52+
origin: args.origin,
53+
destination: args.destination,
54+
airline: args.airline,
55+
price: args.price,
56+
}),
57+
],
58+
});
59+
// @endregion[backend-render-operations]
60+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Docs-only snippet — not imported or run. The shell-docs page at
2+
# `/generative-ui/a2ui/fixed-schema` references the regions
3+
# `backend-schema-json-load` and `backend-render-operations` to teach
4+
# the schema-loading pattern. This file exposes those regions as
5+
# canonical teaching code so the docs render real samples instead of a
6+
# missing-snippet box. The actual demo backend already loads the schema
7+
# and emits operations end-to-end; this sibling just isolates the two
8+
# teaching lines.
9+
#
10+
# Mirrors the convention from `tool-rendering/render-flight-tool.snippet.tsx`.
11+
12+
from pathlib import Path
13+
import json
14+
15+
_SCHEMAS_DIR = Path(__file__).parent / "a2ui_schemas"
16+
17+
# Stand-in for the real a2ui SDK helpers. In a real backend, import
18+
# `a2ui` from your runtime SDK; the calls below match its shape.
19+
class _A2UI:
20+
@staticmethod
21+
def load_schema(path):
22+
with open(path) as fh:
23+
return json.load(fh)
24+
@staticmethod
25+
def create_surface(*args, **kwargs): ...
26+
@staticmethod
27+
def update_components(*args, **kwargs): ...
28+
@staticmethod
29+
def update_data_model(*args, **kwargs): ...
30+
@staticmethod
31+
def render(*args, **kwargs): ...
32+
a2ui = _A2UI()
33+
SURFACE_ID = "flight-fixed-schema"
34+
CATALOG_ID = "flight-catalog"
35+
36+
37+
# @region[backend-schema-json-load]
38+
# Schemas are JSON so they can be authored and reviewed independently of
39+
# the backend code. `a2ui.load_schema` is just a thin `json.load` wrapper
40+
# that resolves the path against the schemas directory.
41+
FLIGHT_SCHEMA = a2ui.load_schema(_SCHEMAS_DIR / "flight_schema.json")
42+
# @endregion[backend-schema-json-load]
43+
44+
45+
def emit_render_operations(origin: str, destination: str, airline: str, price: float):
46+
# @region[backend-render-operations]
47+
# The a2ui middleware detects the `a2ui_operations` container in this
48+
# tool result and forwards the ops to the frontend renderer. The
49+
# frontend catalog resolves component names to local React components.
50+
return a2ui.render(
51+
operations=[
52+
a2ui.create_surface(SURFACE_ID, catalog_id=CATALOG_ID),
53+
a2ui.update_components(SURFACE_ID, FLIGHT_SCHEMA),
54+
a2ui.update_data_model(
55+
SURFACE_ID,
56+
{
57+
"origin": origin,
58+
"destination": destination,
59+
"airline": airline,
60+
"price": price,
61+
},
62+
),
63+
],
64+
)
65+
# @endregion[backend-render-operations]

0 commit comments

Comments
 (0)