@aotui/mobile-ai-native 0.1.0-alpha.1 → 0.1.0-alpha.3
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/GUIDE.md +19 -9
- package/README.md +11 -9
- package/dist/core/action/createActionRuntime.d.ts +9 -4
- package/dist/core/action/createActionRuntime.js +47 -28
- package/dist/core/action/defineAction.d.ts +6 -3
- package/dist/core/action/defineViewTypeTool.d.ts +13 -2
- package/dist/core/action/defineViewTypeTool.js +4 -1
- package/dist/core/action/materializeToolSurface.d.ts +10 -0
- package/dist/core/action/materializeToolSurface.js +25 -0
- package/dist/core/ref/ref-index.d.ts +1 -1
- package/dist/core/snapshot/createSnapshotBundle.d.ts +3 -2
- package/dist/core/snapshot/createSnapshotBundle.js +5 -67
- package/dist/core/snapshot/createSnapshotRegistry.d.ts +1 -1
- package/dist/core/snapshot/createSnapshotRegistry.js +1 -1
- package/dist/core/state/createStore.d.ts +1 -1
- package/dist/core/tool/hardenToolSurface.d.ts +4 -0
- package/dist/core/tool/hardenToolSurface.js +85 -0
- package/dist/core/trace/createTraceStore.d.ts +1 -1
- package/dist/core/types.d.ts +19 -3
- package/dist/demo/inbox/InboxGUI.js +1 -1
- package/dist/demo/inbox/InboxTUI.d.ts +3 -3
- package/dist/demo/inbox/InboxTUI.js +32 -10
- package/dist/demo/inbox/actions.d.ts +3 -3
- package/dist/demo/inbox/actions.js +50 -11
- package/dist/demo/inbox/createInboxApp.d.ts +2 -2
- package/dist/demo/inbox/createInboxApp.js +11 -10
- package/dist/demo/inbox/effects.d.ts +2 -2
- package/dist/index.d.ts +23 -23
- package/dist/index.js +18 -18
- package/dist/projection/gui/AppProvider.d.ts +3 -2
- package/dist/projection/gui/AppProvider.js +25 -6
- package/dist/projection/gui/hooks.d.ts +3 -2
- package/dist/projection/gui/hooks.js +1 -1
- package/dist/projection/react/AppRuntimeProvider.d.ts +1 -1
- package/dist/projection/react/createReactAppRuntime.d.ts +10 -8
- package/dist/projection/react/createReactAppRuntime.js +31 -22
- package/dist/projection/react/hooks.d.ts +4 -3
- package/dist/projection/react/hooks.js +1 -1
- package/dist/projection/tui/createSnapshotAssembler.d.ts +1 -1
- package/dist/projection/tui/createSnapshotAssembler.js +4 -3
- package/dist/projection/tui/renderSnapshotDocument.d.ts +1 -1
- package/dist/projection/tui/renderTUI.d.ts +3 -2
- package/dist/projection/tui/renderTUI.js +6 -5
- package/dist/projection/tui/renderViewFragment.d.ts +1 -1
- package/dist/projection/tui/renderViewFragment.js +1 -1
- package/dist/ref/RefContext.d.ts +1 -1
- package/dist/ref/useArrayRef.js +1 -1
- package/dist/ref/useDataRef.js +1 -1
- package/dist/tool/createToolBridge.d.ts +4 -3
- package/dist/tool/createToolBridge.js +12 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
- package/LICENSE +0 -201
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { ToolDefinition } from "../../core/types";
|
|
2
|
-
import type { InboxState } from "./state";
|
|
3
|
-
export declare function createInboxSnapshotBundle(state: InboxState,
|
|
1
|
+
import type { ToolAvailability, ToolDefinition } from "../../core/types.js";
|
|
2
|
+
import type { InboxState } from "./state.js";
|
|
3
|
+
export declare function createInboxSnapshotBundle(state: InboxState, tools: readonly ToolDefinition[], toolAvailability: Readonly<Record<string, ToolAvailability>>): import("../..").SnapshotBundle;
|
|
@@ -1,13 +1,32 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
2
|
/** @jsxImportSource preact */
|
|
3
3
|
import renderToString from "preact-render-to-string";
|
|
4
|
-
import { createRefCollector } from "../../core/ref/ref-index";
|
|
5
|
-
import { createSnapshotAssembler } from "../../projection/tui/createSnapshotAssembler";
|
|
6
|
-
import { renderViewFragment } from "../../projection/tui/renderViewFragment";
|
|
7
|
-
import { RefProvider } from "../../ref/RefContext";
|
|
8
|
-
import { useDataRef } from "../../ref/useDataRef";
|
|
9
|
-
import { useArrayRef } from "../../ref/useArrayRef";
|
|
10
|
-
import { isInboxSearchActive, } from "./state";
|
|
4
|
+
import { createRefCollector } from "../../core/ref/ref-index.js";
|
|
5
|
+
import { createSnapshotAssembler } from "../../projection/tui/createSnapshotAssembler.js";
|
|
6
|
+
import { renderViewFragment } from "../../projection/tui/renderViewFragment.js";
|
|
7
|
+
import { RefProvider } from "../../ref/RefContext.js";
|
|
8
|
+
import { useDataRef } from "../../ref/useDataRef.js";
|
|
9
|
+
import { useArrayRef } from "../../ref/useArrayRef.js";
|
|
10
|
+
import { isInboxSearchActive, } from "./state.js";
|
|
11
|
+
function describeToolAvailability(availability) {
|
|
12
|
+
if (!availability) {
|
|
13
|
+
return "unknown";
|
|
14
|
+
}
|
|
15
|
+
if (availability.ok) {
|
|
16
|
+
return "available";
|
|
17
|
+
}
|
|
18
|
+
return `${availability.code}: ${availability.message}`;
|
|
19
|
+
}
|
|
20
|
+
function renderToolManifest(tools, toolAvailability) {
|
|
21
|
+
return tools
|
|
22
|
+
.map((tool) => {
|
|
23
|
+
const preconditions = tool.preconditions.length
|
|
24
|
+
? tool.preconditions.join("; ")
|
|
25
|
+
: "none";
|
|
26
|
+
return `<item>${tool.name}: ${tool.description} | exposure=${tool.exposure} | availability=${describeToolAvailability(toolAvailability[tool.name])} | preconditions=${preconditions}</item>`;
|
|
27
|
+
})
|
|
28
|
+
.join("");
|
|
29
|
+
}
|
|
11
30
|
function InboxRootContent() {
|
|
12
31
|
return (_jsxs(_Fragment, { children: [_jsx("text", { children: "App Navigation" }), _jsx("text", { children: "Semantic view graph" }), _jsx("item", { children: "Inbox: primary message list view." }), _jsx("item", { children: "Enter Inbox: mounted by default when the app opens." }), _jsx("item", { children: "Inbox actions: openMessage." }), _jsx("item", { children: "InboxSearch: focused search/results view for inbox queries." }), _jsx("item", { children: "Enter InboxSearch: use searchMessages when inbox search is relevant." }), _jsx("item", { children: "InboxSearch actions: searchMessages." }), _jsx("item", { children: "MessageDetail: opened message detail view." }), _jsx("item", { children: "Enter MessageDetail: use openMessage from Inbox." }), _jsx("item", { children: "MessageDetail actions: inspect the opened message state." })] }));
|
|
13
32
|
}
|
|
@@ -33,14 +52,16 @@ function renderFragmentMarkup(children, collector) {
|
|
|
33
52
|
markup: renderToString(_jsx(RefProvider, { registry: collector, children: children })),
|
|
34
53
|
};
|
|
35
54
|
}
|
|
36
|
-
export function createInboxSnapshotBundle(state,
|
|
55
|
+
export function createInboxSnapshotBundle(state, tools, toolAvailability) {
|
|
37
56
|
const collector = createRefCollector();
|
|
38
57
|
const rootMarkup = renderFragmentMarkup(_jsx(InboxRootContent, {}), collector);
|
|
39
58
|
const rootView = renderViewFragment({
|
|
40
59
|
id: "root",
|
|
41
60
|
type: "Root",
|
|
42
61
|
name: "Navigation",
|
|
43
|
-
markup: rootMarkup.markup
|
|
62
|
+
markup: rootMarkup.markup +
|
|
63
|
+
"<text>Tool manifest is stable; runtime validation decides whether a tool is currently executable.</text>" +
|
|
64
|
+
renderToolManifest(tools, toolAvailability),
|
|
44
65
|
});
|
|
45
66
|
const inboxMarkup = renderFragmentMarkup(_jsx(InboxListContent, { state: state }), collector);
|
|
46
67
|
const mountedViews = [
|
|
@@ -73,6 +94,7 @@ export function createInboxSnapshotBundle(state, visibleTools) {
|
|
|
73
94
|
rootView,
|
|
74
95
|
mountedViews,
|
|
75
96
|
refIndex: collector.snapshot(),
|
|
76
|
-
|
|
97
|
+
tools,
|
|
98
|
+
toolAvailability,
|
|
77
99
|
});
|
|
78
100
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import type { InboxEvent, InboxState } from "./state";
|
|
2
|
+
import type { InboxEvent, InboxState } from "./state.js";
|
|
3
3
|
declare const inboxMessageSchema: z.ZodObject<{
|
|
4
4
|
id: z.ZodString;
|
|
5
5
|
subject: z.ZodString;
|
|
6
6
|
opened: z.ZodBoolean;
|
|
7
7
|
}, z.core.$strip>;
|
|
8
8
|
export declare function createInboxActions(): {
|
|
9
|
-
openMessage: import("../..").
|
|
9
|
+
openMessage: import("../..").ActionDefinition<InboxState, InboxEvent, {
|
|
10
10
|
message: z.infer<typeof inboxMessageSchema>;
|
|
11
11
|
}>;
|
|
12
|
-
searchMessages: import("../..").
|
|
12
|
+
searchMessages: import("../..").ActionDefinition<InboxState, InboxEvent, {
|
|
13
13
|
query: string;
|
|
14
14
|
}>;
|
|
15
15
|
};
|
|
@@ -1,24 +1,55 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
import { isInboxSearchActive, isInboxSearchRelevant } from "./state";
|
|
2
|
+
import { defineAction } from "../../core/action/defineAction.js";
|
|
4
3
|
const inboxMessageSchema = z.object({
|
|
5
4
|
id: z.string(),
|
|
6
5
|
subject: z.string(),
|
|
7
6
|
opened: z.boolean(),
|
|
8
7
|
});
|
|
8
|
+
function inboxTabNotAvailable() {
|
|
9
|
+
return {
|
|
10
|
+
ok: false,
|
|
11
|
+
code: "PRECONDITION_NOT_MET",
|
|
12
|
+
message: "Inbox tools are only available when the inbox tab is active.",
|
|
13
|
+
reason: "current_tab_is_not_inbox",
|
|
14
|
+
requiredState: {
|
|
15
|
+
currentTab: "inbox",
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
9
19
|
export function createInboxActions() {
|
|
10
|
-
const openMessage =
|
|
20
|
+
const openMessage = defineAction({
|
|
11
21
|
name: "openMessage",
|
|
12
22
|
description: "Open a message from the inbox.",
|
|
13
23
|
schema: z.object({
|
|
14
24
|
message: inboxMessageSchema,
|
|
15
25
|
}),
|
|
16
|
-
viewType: "Inbox",
|
|
17
26
|
meta: {
|
|
18
27
|
supportsRefs: true,
|
|
19
28
|
},
|
|
20
|
-
|
|
21
|
-
|
|
29
|
+
exposure: "static",
|
|
30
|
+
preconditions: [
|
|
31
|
+
"Inbox tab is active",
|
|
32
|
+
"The message ref points to a message in the current inbox snapshot",
|
|
33
|
+
],
|
|
34
|
+
getAvailability(state) {
|
|
35
|
+
if (state.shell.currentTab !== "inbox") {
|
|
36
|
+
return inboxTabNotAvailable();
|
|
37
|
+
}
|
|
38
|
+
if (state.inbox.items.length === 0) {
|
|
39
|
+
return {
|
|
40
|
+
ok: false,
|
|
41
|
+
code: "PRECONDITION_NOT_MET",
|
|
42
|
+
message: "No inbox messages are available to open.",
|
|
43
|
+
reason: "no_inbox_messages",
|
|
44
|
+
requiredState: {
|
|
45
|
+
currentTab: "inbox",
|
|
46
|
+
messageCount: 1,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
ok: true,
|
|
52
|
+
};
|
|
22
53
|
},
|
|
23
54
|
handler(ctx, input) {
|
|
24
55
|
ctx.emit({ type: "MessageOpened", messageId: input.message.id });
|
|
@@ -34,16 +65,24 @@ export function createInboxActions() {
|
|
|
34
65
|
};
|
|
35
66
|
},
|
|
36
67
|
});
|
|
37
|
-
const searchMessages =
|
|
68
|
+
const searchMessages = defineAction({
|
|
38
69
|
name: "searchMessages",
|
|
39
70
|
description: "Search inbox messages.",
|
|
40
71
|
schema: z.object({
|
|
41
72
|
query: z.string().min(1),
|
|
42
73
|
}),
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
74
|
+
exposure: "static",
|
|
75
|
+
preconditions: [
|
|
76
|
+
"Inbox tab is active",
|
|
77
|
+
"The query input is a non-empty string",
|
|
78
|
+
],
|
|
79
|
+
getAvailability(state) {
|
|
80
|
+
if (state.shell.currentTab !== "inbox") {
|
|
81
|
+
return inboxTabNotAvailable();
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
ok: true,
|
|
85
|
+
};
|
|
47
86
|
},
|
|
48
87
|
async handler(ctx, input) {
|
|
49
88
|
ctx.emit({ type: "SearchStarted", query: input.query });
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { type InboxMessage } from "./state";
|
|
1
|
+
import { type InboxMessage } from "./state.js";
|
|
2
2
|
export declare function createInboxApp(config: {
|
|
3
3
|
initialMessages: InboxMessage[];
|
|
4
4
|
}): {
|
|
5
5
|
store: import("../../core/types").Store<import("./state").InboxState, import("./state").InboxEvent>;
|
|
6
6
|
bridge: {
|
|
7
|
-
listTools(): import("../..").ToolDefinition[];
|
|
7
|
+
listTools(): readonly import("../..").ToolDefinition[];
|
|
8
8
|
getSnapshotBundle(): import("../..").SnapshotBundle;
|
|
9
9
|
executeTool(name: string, input: Record<string, unknown>, snapshotId: string): Promise<import("../../core/types").ActionResult>;
|
|
10
10
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
2
|
/** @jsxImportSource preact */
|
|
3
3
|
import renderToString from "preact-render-to-string";
|
|
4
|
-
import { createActionRuntime } from "../../core/action/createActionRuntime";
|
|
5
|
-
import { createStore } from "../../core/state/createStore";
|
|
6
|
-
import { AppProvider } from "../../projection/gui/AppProvider";
|
|
7
|
-
import { createToolBridge } from "../../tool/createToolBridge";
|
|
8
|
-
import { createInboxActions } from "./actions";
|
|
9
|
-
import { createInboxEffects } from "./effects";
|
|
10
|
-
import { InboxGUI } from "./InboxGUI";
|
|
11
|
-
import { createInboxSnapshotBundle, } from "./InboxTUI";
|
|
12
|
-
import { createInitialInboxState, getInboxRelevantViewTypes, reduceInboxState, } from "./state";
|
|
4
|
+
import { createActionRuntime } from "../../core/action/createActionRuntime.js";
|
|
5
|
+
import { createStore } from "../../core/state/createStore.js";
|
|
6
|
+
import { AppProvider } from "../../projection/gui/AppProvider.js";
|
|
7
|
+
import { createToolBridge } from "../../tool/createToolBridge.js";
|
|
8
|
+
import { createInboxActions } from "./actions.js";
|
|
9
|
+
import { createInboxEffects } from "./effects.js";
|
|
10
|
+
import { InboxGUI } from "./InboxGUI.js";
|
|
11
|
+
import { createInboxSnapshotBundle, } from "./InboxTUI.js";
|
|
12
|
+
import { createInitialInboxState, getInboxRelevantViewTypes, reduceInboxState, } from "./state.js";
|
|
13
13
|
export function createInboxApp(config) {
|
|
14
14
|
const store = createStore({
|
|
15
15
|
initialState: createInitialInboxState(config.initialMessages),
|
|
@@ -25,7 +25,8 @@ export function createInboxApp(config) {
|
|
|
25
25
|
const bridge = createToolBridge({
|
|
26
26
|
actionRuntime,
|
|
27
27
|
renderCurrentSnapshot() {
|
|
28
|
-
|
|
28
|
+
const toolSurface = actionRuntime.getToolSurface();
|
|
29
|
+
return createInboxSnapshotBundle(store.getState(), toolSurface.tools, toolSurface.toolAvailability);
|
|
29
30
|
},
|
|
30
31
|
});
|
|
31
32
|
function renderGUI() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { InboxEvent, InboxMessage, InboxState } from "./state";
|
|
2
|
-
import type { EffectContext, EffectResult } from "../../core/effect/types";
|
|
1
|
+
import type { InboxEvent, InboxMessage, InboxState } from "./state.js";
|
|
2
|
+
import type { EffectContext, EffectResult } from "../../core/effect/types.js";
|
|
3
3
|
export declare function createInboxEffects(allMessages: InboxMessage[]): {
|
|
4
4
|
searchMessages(ctx: EffectContext<InboxState, InboxEvent>, input: {
|
|
5
5
|
query: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { createSnapshotBundle } from "./core/snapshot/createSnapshotBundle";
|
|
2
|
-
import { VERSION } from "./version";
|
|
1
|
+
import { createSnapshotBundle } from "./core/snapshot/createSnapshotBundle.js";
|
|
2
|
+
import { VERSION } from "./version.js";
|
|
3
3
|
export { VERSION };
|
|
4
|
-
export { createStore } from "./core/state/createStore";
|
|
4
|
+
export { createStore } from "./core/state/createStore.js";
|
|
5
5
|
export { createSnapshotBundle };
|
|
6
|
-
export type { RefIndexEntry, MountedViewDescriptor, SnapshotBundle, TraceState, ToolDefinition, StaticViewCatalogEntry, SnapshotAssemblerInput, ViewFragment, } from "./core/types";
|
|
7
|
-
export type { EffectContext, EffectFailure, EffectHandler, EffectMap, EffectResult, EffectSuccess, EffectTrace, } from "./core/effect/types";
|
|
8
|
-
export type { ActionContext, ActionDefinition, } from "./core/action/defineAction";
|
|
9
|
-
export type { ViewTypeToolActionDefinition, } from "./core/action/defineViewTypeTool";
|
|
10
|
-
export { defineAction } from "./core/action/defineAction";
|
|
11
|
-
export { defineViewTypeTool } from "./core/action/defineViewTypeTool";
|
|
12
|
-
export { createActionRuntime } from "./core/action/createActionRuntime";
|
|
13
|
-
export { createToolBridge } from "./tool/createToolBridge";
|
|
14
|
-
export { useDataRef } from "./ref/useDataRef";
|
|
15
|
-
export { useArrayRef } from "./ref/useArrayRef";
|
|
16
|
-
export { View } from "./projection/tui/View";
|
|
17
|
-
export { createSnapshotAssembler } from "./projection/tui/createSnapshotAssembler";
|
|
18
|
-
export { renderTUI } from "./projection/tui/renderTUI";
|
|
19
|
-
export { createReactAppRuntime } from "./projection/react/createReactAppRuntime";
|
|
20
|
-
export type { ReactAppDefinition, ReactAppRuntime, RuntimeTrace, } from "./projection/react/createReactAppRuntime";
|
|
21
|
-
export { AppRuntimeProvider } from "./projection/react/AppRuntimeProvider";
|
|
22
|
-
export { useAppRuntime, useRuntimeActions, useRuntimeState, useRuntimeTrace } from "./projection/react/hooks";
|
|
23
|
-
export { AppProvider } from "./projection/gui/AppProvider";
|
|
24
|
-
export { useAppState, useActions } from "./projection/gui/hooks";
|
|
25
|
-
export { createInboxApp } from "./demo/inbox/createInboxApp";
|
|
6
|
+
export type { RefIndexEntry, MountedViewDescriptor, SnapshotBundle, ToolAvailability, ToolExposure, TraceState, ToolDefinition, StaticViewCatalogEntry, SnapshotAssemblerInput, ViewFragment, } from "./core/types.js";
|
|
7
|
+
export type { EffectContext, EffectFailure, EffectHandler, EffectMap, EffectResult, EffectSuccess, EffectTrace, } from "./core/effect/types.js";
|
|
8
|
+
export type { ActionContext, ActionDefinition, } from "./core/action/defineAction.js";
|
|
9
|
+
export type { ViewTypeToolActionDefinition, } from "./core/action/defineViewTypeTool.js";
|
|
10
|
+
export { defineAction } from "./core/action/defineAction.js";
|
|
11
|
+
export { defineViewTypeTool } from "./core/action/defineViewTypeTool.js";
|
|
12
|
+
export { createActionRuntime } from "./core/action/createActionRuntime.js";
|
|
13
|
+
export { createToolBridge } from "./tool/createToolBridge.js";
|
|
14
|
+
export { useDataRef } from "./ref/useDataRef.js";
|
|
15
|
+
export { useArrayRef } from "./ref/useArrayRef.js";
|
|
16
|
+
export { View } from "./projection/tui/View.js";
|
|
17
|
+
export { createSnapshotAssembler } from "./projection/tui/createSnapshotAssembler.js";
|
|
18
|
+
export { renderTUI } from "./projection/tui/renderTUI.js";
|
|
19
|
+
export { createReactAppRuntime } from "./projection/react/createReactAppRuntime.js";
|
|
20
|
+
export type { ReactAppDefinition, ReactAppRuntime, RuntimeTrace, } from "./projection/react/createReactAppRuntime.js";
|
|
21
|
+
export { AppRuntimeProvider } from "./projection/react/AppRuntimeProvider.js";
|
|
22
|
+
export { useAppRuntime, useRuntimeActions, useRuntimeState, useRuntimeTrace } from "./projection/react/hooks.js";
|
|
23
|
+
export { AppProvider } from "./projection/gui/AppProvider.js";
|
|
24
|
+
export { useAppState, useActions } from "./projection/gui/hooks.js";
|
|
25
|
+
export { createInboxApp } from "./demo/inbox/createInboxApp.js";
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { createSnapshotBundle } from "./core/snapshot/createSnapshotBundle";
|
|
2
|
-
import { VERSION } from "./version";
|
|
1
|
+
import { createSnapshotBundle } from "./core/snapshot/createSnapshotBundle.js";
|
|
2
|
+
import { VERSION } from "./version.js";
|
|
3
3
|
export { VERSION };
|
|
4
|
-
export { createStore } from "./core/state/createStore";
|
|
4
|
+
export { createStore } from "./core/state/createStore.js";
|
|
5
5
|
export { createSnapshotBundle };
|
|
6
|
-
export { defineAction } from "./core/action/defineAction";
|
|
7
|
-
export { defineViewTypeTool } from "./core/action/defineViewTypeTool";
|
|
8
|
-
export { createActionRuntime } from "./core/action/createActionRuntime";
|
|
9
|
-
export { createToolBridge } from "./tool/createToolBridge";
|
|
10
|
-
export { useDataRef } from "./ref/useDataRef";
|
|
11
|
-
export { useArrayRef } from "./ref/useArrayRef";
|
|
12
|
-
export { View } from "./projection/tui/View";
|
|
13
|
-
export { createSnapshotAssembler } from "./projection/tui/createSnapshotAssembler";
|
|
14
|
-
export { renderTUI } from "./projection/tui/renderTUI";
|
|
15
|
-
export { createReactAppRuntime } from "./projection/react/createReactAppRuntime";
|
|
16
|
-
export { AppRuntimeProvider } from "./projection/react/AppRuntimeProvider";
|
|
17
|
-
export { useAppRuntime, useRuntimeActions, useRuntimeState, useRuntimeTrace } from "./projection/react/hooks";
|
|
18
|
-
export { AppProvider } from "./projection/gui/AppProvider";
|
|
19
|
-
export { useAppState, useActions } from "./projection/gui/hooks";
|
|
20
|
-
export { createInboxApp } from "./demo/inbox/createInboxApp";
|
|
6
|
+
export { defineAction } from "./core/action/defineAction.js";
|
|
7
|
+
export { defineViewTypeTool } from "./core/action/defineViewTypeTool.js";
|
|
8
|
+
export { createActionRuntime } from "./core/action/createActionRuntime.js";
|
|
9
|
+
export { createToolBridge } from "./tool/createToolBridge.js";
|
|
10
|
+
export { useDataRef } from "./ref/useDataRef.js";
|
|
11
|
+
export { useArrayRef } from "./ref/useArrayRef.js";
|
|
12
|
+
export { View } from "./projection/tui/View.js";
|
|
13
|
+
export { createSnapshotAssembler } from "./projection/tui/createSnapshotAssembler.js";
|
|
14
|
+
export { renderTUI } from "./projection/tui/renderTUI.js";
|
|
15
|
+
export { createReactAppRuntime } from "./projection/react/createReactAppRuntime.js";
|
|
16
|
+
export { AppRuntimeProvider } from "./projection/react/AppRuntimeProvider.js";
|
|
17
|
+
export { useAppRuntime, useRuntimeActions, useRuntimeState, useRuntimeTrace } from "./projection/react/hooks.js";
|
|
18
|
+
export { AppProvider } from "./projection/gui/AppProvider.js";
|
|
19
|
+
export { useAppState, useActions } from "./projection/gui/hooks.js";
|
|
20
|
+
export { createInboxApp } from "./demo/inbox/createInboxApp.js";
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { ComponentChildren } from "preact";
|
|
2
|
-
import type { ActionResult, Store, ToolDefinition } from "../../core/types";
|
|
2
|
+
import type { ActionResult, Store, ToolAvailability, ToolDefinition } from "../../core/types.js";
|
|
3
3
|
type LegacyAppContextValue = {
|
|
4
4
|
store: Store<unknown, unknown>;
|
|
5
5
|
actionRuntime: {
|
|
6
6
|
executeAction(name: string, input: Record<string, unknown>): Promise<ActionResult>;
|
|
7
|
-
|
|
7
|
+
listTools(): readonly ToolDefinition[];
|
|
8
|
+
getToolAvailability(): Readonly<Record<string, ToolAvailability>>;
|
|
8
9
|
};
|
|
9
10
|
};
|
|
10
11
|
export declare function AppProvider(props: {
|
|
@@ -2,13 +2,29 @@ import { jsx as _jsx } from "preact/jsx-runtime";
|
|
|
2
2
|
/** @jsxImportSource preact */
|
|
3
3
|
import { createContext } from "preact";
|
|
4
4
|
import { useContext, useMemo } from "preact/hooks";
|
|
5
|
-
import { AppRuntimeProvider } from "../react/AppRuntimeProvider";
|
|
5
|
+
import { AppRuntimeProvider } from "../react/AppRuntimeProvider.js";
|
|
6
6
|
const AppContext = createContext(null);
|
|
7
7
|
function createCompatibilityRuntime(value) {
|
|
8
8
|
let nextTraceId = 1;
|
|
9
9
|
return {
|
|
10
10
|
store: value.store,
|
|
11
|
-
actionRuntime:
|
|
11
|
+
actionRuntime: {
|
|
12
|
+
executeAction(name, input) {
|
|
13
|
+
return value.actionRuntime.executeAction(name, input);
|
|
14
|
+
},
|
|
15
|
+
listTools() {
|
|
16
|
+
return value.actionRuntime.listTools();
|
|
17
|
+
},
|
|
18
|
+
getToolAvailability() {
|
|
19
|
+
return value.actionRuntime.getToolAvailability();
|
|
20
|
+
},
|
|
21
|
+
getToolSurface() {
|
|
22
|
+
return {
|
|
23
|
+
tools: value.actionRuntime.listTools(),
|
|
24
|
+
toolAvailability: value.actionRuntime.getToolAvailability(),
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
},
|
|
12
28
|
traceStore: {
|
|
13
29
|
getState() {
|
|
14
30
|
return {
|
|
@@ -57,7 +73,7 @@ function createCompatibilityRuntime(value) {
|
|
|
57
73
|
},
|
|
58
74
|
toolBridge: {
|
|
59
75
|
listTools() {
|
|
60
|
-
return value.actionRuntime.
|
|
76
|
+
return value.actionRuntime.listTools();
|
|
61
77
|
},
|
|
62
78
|
getSnapshotBundle() {
|
|
63
79
|
throw new Error("Snapshot rendering is not available through AppProvider");
|
|
@@ -67,11 +83,14 @@ function createCompatibilityRuntime(value) {
|
|
|
67
83
|
},
|
|
68
84
|
},
|
|
69
85
|
actions: {
|
|
70
|
-
|
|
86
|
+
executeAction(name, input) {
|
|
71
87
|
return value.actionRuntime.executeAction(name, input);
|
|
72
88
|
},
|
|
73
|
-
|
|
74
|
-
return value.actionRuntime.
|
|
89
|
+
listTools() {
|
|
90
|
+
return value.actionRuntime.listTools();
|
|
91
|
+
},
|
|
92
|
+
getToolAvailability() {
|
|
93
|
+
return value.actionRuntime.getToolAvailability();
|
|
75
94
|
},
|
|
76
95
|
},
|
|
77
96
|
};
|
|
@@ -2,6 +2,7 @@ export declare function useAppState<State>(): {
|
|
|
2
2
|
state: State;
|
|
3
3
|
};
|
|
4
4
|
export declare function useActions(): {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
executeAction(name: string, input: Record<string, unknown>): Promise<import("../../core/types").ActionResult>;
|
|
6
|
+
listTools(): readonly import("../..").ToolDefinition[];
|
|
7
|
+
getToolAvailability(): Readonly<Record<string, import("../..").ToolAvailability>>;
|
|
7
8
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ComponentChildren } from "preact";
|
|
2
|
-
import type { ReactAppRuntime, RuntimeTrace } from "./createReactAppRuntime";
|
|
2
|
+
import type { ReactAppRuntime, RuntimeTrace } from "./createReactAppRuntime.js";
|
|
3
3
|
export type AppRuntime<State = unknown, Event = unknown> = ReactAppRuntime<State, Event> & {
|
|
4
4
|
trace: RuntimeTrace;
|
|
5
5
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { createActionRuntime } from "../../core/action/createActionRuntime";
|
|
2
|
-
import type { ActionDefinition } from "../../core/action/defineAction";
|
|
3
|
-
import type { EffectMap } from "../../core/effect/types";
|
|
4
|
-
import type { ActionResult, SnapshotBundle, SnapshotRegistry, StateReducer, Store, ToolDefinition, TraceRecord, TraceState, TraceStore } from "../../core/types";
|
|
5
|
-
import { createToolBridge } from "../../tool/createToolBridge";
|
|
1
|
+
import { createActionRuntime } from "../../core/action/createActionRuntime.js";
|
|
2
|
+
import type { ActionDefinition } from "../../core/action/defineAction.js";
|
|
3
|
+
import type { EffectMap } from "../../core/effect/types.js";
|
|
4
|
+
import type { ActionResult, SnapshotBundle, SnapshotRegistry, StateReducer, Store, ToolAvailability, ToolDefinition, TraceRecord, TraceState, TraceStore } from "../../core/types.js";
|
|
5
|
+
import { createToolBridge } from "../../tool/createToolBridge.js";
|
|
6
6
|
export type ReactAppDefinition<State, Event> = {
|
|
7
7
|
initialState: State;
|
|
8
8
|
reduce: StateReducer<State, Event>;
|
|
@@ -11,7 +11,8 @@ export type ReactAppDefinition<State, Event> = {
|
|
|
11
11
|
getRelevantViewTypes?: (state: State) => readonly string[];
|
|
12
12
|
renderCurrentSnapshot?: (context: {
|
|
13
13
|
state: State;
|
|
14
|
-
|
|
14
|
+
tools: readonly ToolDefinition[];
|
|
15
|
+
toolAvailability: Readonly<Record<string, ToolAvailability>>;
|
|
15
16
|
}) => SnapshotBundle;
|
|
16
17
|
};
|
|
17
18
|
export type ReactAppRuntime<State, Event> = {
|
|
@@ -22,8 +23,9 @@ export type ReactAppRuntime<State, Event> = {
|
|
|
22
23
|
snapshotRegistry: SnapshotRegistry;
|
|
23
24
|
toolBridge: ReturnType<typeof createToolBridge>;
|
|
24
25
|
actions: {
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
executeAction(name: string, input: Record<string, unknown>): Promise<ActionResult>;
|
|
27
|
+
listTools(): readonly ToolDefinition[];
|
|
28
|
+
getToolAvailability(): Readonly<Record<string, ToolAvailability>>;
|
|
27
29
|
};
|
|
28
30
|
};
|
|
29
31
|
export type RuntimeTrace = {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { createActionRuntime } from "../../core/action/createActionRuntime";
|
|
2
|
-
import { createSnapshotRegistry } from "../../core/snapshot/createSnapshotRegistry";
|
|
3
|
-
import { createStore } from "../../core/state/createStore";
|
|
4
|
-
import { createTraceStore } from "../../core/trace/createTraceStore";
|
|
5
|
-
import { createSnapshotAssembler } from "../tui/createSnapshotAssembler";
|
|
6
|
-
import { renderViewFragment } from "../tui/renderViewFragment";
|
|
7
|
-
import { createToolBridge } from "../../tool/createToolBridge";
|
|
1
|
+
import { createActionRuntime } from "../../core/action/createActionRuntime.js";
|
|
2
|
+
import { createSnapshotRegistry } from "../../core/snapshot/createSnapshotRegistry.js";
|
|
3
|
+
import { createStore } from "../../core/state/createStore.js";
|
|
4
|
+
import { createTraceStore } from "../../core/trace/createTraceStore.js";
|
|
5
|
+
import { createSnapshotAssembler } from "../tui/createSnapshotAssembler.js";
|
|
6
|
+
import { renderViewFragment } from "../tui/renderViewFragment.js";
|
|
7
|
+
import { createToolBridge } from "../../tool/createToolBridge.js";
|
|
8
8
|
export function createReactAppRuntime(app) {
|
|
9
9
|
const store = createStore({
|
|
10
10
|
initialState: app.initialState,
|
|
@@ -23,24 +23,30 @@ export function createReactAppRuntime(app) {
|
|
|
23
23
|
});
|
|
24
24
|
const snapshotRegistry = createSnapshotRegistry({ maxEntries: 2 });
|
|
25
25
|
const renderCurrentSnapshot = app.renderCurrentSnapshot ??
|
|
26
|
-
(() =>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
(() => {
|
|
27
|
+
const toolSurface = actionRuntime.getToolSurface();
|
|
28
|
+
return createSnapshotAssembler({
|
|
29
|
+
rootView: renderViewFragment({
|
|
30
|
+
id: "root",
|
|
31
|
+
type: "Root",
|
|
32
|
+
name: "Navigation",
|
|
33
|
+
children: "No custom snapshot renderer configured.",
|
|
34
|
+
}),
|
|
35
|
+
mountedViews: [],
|
|
36
|
+
refIndex: {},
|
|
37
|
+
tools: toolSurface.tools,
|
|
38
|
+
toolAvailability: toolSurface.toolAvailability,
|
|
39
|
+
});
|
|
40
|
+
});
|
|
37
41
|
const toolBridge = createToolBridge({
|
|
38
42
|
actionRuntime,
|
|
39
43
|
snapshotRegistry,
|
|
40
44
|
renderCurrentSnapshot() {
|
|
45
|
+
const toolSurface = actionRuntime.getToolSurface();
|
|
41
46
|
return renderCurrentSnapshot({
|
|
42
47
|
state: store.getState(),
|
|
43
|
-
|
|
48
|
+
tools: toolSurface.tools,
|
|
49
|
+
toolAvailability: toolSurface.toolAvailability,
|
|
44
50
|
});
|
|
45
51
|
},
|
|
46
52
|
});
|
|
@@ -65,15 +71,18 @@ export function createReactAppRuntime(app) {
|
|
|
65
71
|
snapshotRegistry,
|
|
66
72
|
toolBridge,
|
|
67
73
|
actions: {
|
|
68
|
-
async
|
|
74
|
+
async executeAction(name, input) {
|
|
69
75
|
const result = await actionRuntime.executeAction(name, input);
|
|
70
76
|
if (result.mutated) {
|
|
71
77
|
snapshotRegistry.markAllStale?.();
|
|
72
78
|
}
|
|
73
79
|
return result;
|
|
74
80
|
},
|
|
75
|
-
|
|
76
|
-
return actionRuntime.
|
|
81
|
+
listTools() {
|
|
82
|
+
return actionRuntime.listTools();
|
|
83
|
+
},
|
|
84
|
+
getToolAvailability() {
|
|
85
|
+
return actionRuntime.getToolAvailability();
|
|
77
86
|
},
|
|
78
87
|
},
|
|
79
88
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { TraceState } from "../../core/types";
|
|
1
|
+
import type { TraceState } from "../../core/types.js";
|
|
2
2
|
export declare function useAppRuntime(): import("./AppRuntimeProvider").AppRuntime<unknown, unknown>;
|
|
3
3
|
export declare function useRuntimeState<State, Selected>(selector: (state: State) => Selected): Selected;
|
|
4
4
|
export declare function useRuntimeActions(): {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
executeAction(name: string, input: Record<string, unknown>): Promise<import("../../core/types").ActionResult>;
|
|
6
|
+
listTools(): readonly import("../..").ToolDefinition[];
|
|
7
|
+
getToolAvailability(): Readonly<Record<string, import("../..").ToolAvailability>>;
|
|
7
8
|
};
|
|
8
9
|
export declare function useRuntimeTrace<Selected>(selector: (trace: TraceState) => Selected): Selected;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { SnapshotAssemblerInput, SnapshotBundle } from "../../core/types";
|
|
1
|
+
import type { SnapshotAssemblerInput, SnapshotBundle } from "../../core/types.js";
|
|
2
2
|
export declare function createSnapshotAssembler<State>(input: SnapshotAssemblerInput<State>): SnapshotBundle;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createSnapshotBundle } from "../../core/snapshot/createSnapshotBundle";
|
|
2
|
-
import { renderSnapshotDocument } from "./renderSnapshotDocument";
|
|
1
|
+
import { createSnapshotBundle } from "../../core/snapshot/createSnapshotBundle.js";
|
|
2
|
+
import { renderSnapshotDocument } from "./renderSnapshotDocument.js";
|
|
3
3
|
export function createSnapshotAssembler(input) {
|
|
4
4
|
const views = [input.rootView, ...input.mountedViews];
|
|
5
5
|
const markup = renderSnapshotDocument(views);
|
|
@@ -7,7 +7,8 @@ export function createSnapshotAssembler(input) {
|
|
|
7
7
|
markup,
|
|
8
8
|
views,
|
|
9
9
|
refIndex: input.refIndex,
|
|
10
|
-
|
|
10
|
+
tools: input.tools,
|
|
11
|
+
toolAvailability: input.toolAvailability,
|
|
11
12
|
...(input.tui === undefined ? {} : { tui: input.tui }),
|
|
12
13
|
};
|
|
13
14
|
return createSnapshotBundle(bundleInput);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { ViewFragment } from "../../core/types";
|
|
1
|
+
import type { ViewFragment } from "../../core/types.js";
|
|
2
2
|
export declare function renderSnapshotDocument(views: readonly ViewFragment[]): string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** @jsxImportSource preact */
|
|
2
2
|
import type { ComponentChild } from "preact";
|
|
3
|
-
import type { ToolDefinition } from "../../core/types";
|
|
3
|
+
import type { ToolAvailability, ToolDefinition } from "../../core/types.js";
|
|
4
4
|
export declare function renderTUI(node: ComponentChild, options: {
|
|
5
|
-
|
|
5
|
+
tools: ToolDefinition[];
|
|
6
|
+
toolAvailability?: Readonly<Record<string, ToolAvailability>>;
|
|
6
7
|
}): import("../..").SnapshotBundle;
|