@aotui/mobile-ai-native 0.1.0-alpha.0 → 0.1.0-alpha.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/GUIDE.md +79 -109
- package/LICENSE +201 -0
- package/README.md +106 -40
- package/dist/core/action/createActionRuntime.d.ts +6 -6
- package/dist/core/action/createActionRuntime.js +71 -18
- package/dist/core/action/defineAction.d.ts +4 -5
- package/dist/core/action/defineViewTypeTool.d.ts +5 -0
- package/dist/core/action/defineViewTypeTool.js +3 -0
- package/dist/core/effect/types.d.ts +21 -1
- package/dist/core/snapshot/createSnapshotBundle.d.ts +7 -4
- package/dist/core/snapshot/createSnapshotBundle.js +110 -3
- package/dist/core/snapshot/createSnapshotRegistry.d.ts +4 -0
- package/dist/core/snapshot/createSnapshotRegistry.js +52 -0
- package/dist/core/trace/createTraceStore.d.ts +2 -0
- package/dist/core/trace/createTraceStore.js +38 -0
- package/dist/core/trace/types.d.ts +21 -0
- package/dist/core/trace/types.js +1 -0
- package/dist/core/types.d.ts +61 -10
- package/dist/demo/inbox/InboxGUI.js +5 -3
- package/dist/demo/inbox/InboxTUI.d.ts +3 -1
- package/dist/demo/inbox/InboxTUI.js +73 -7
- package/dist/demo/inbox/actions.d.ts +2 -2
- package/dist/demo/inbox/actions.js +15 -4
- package/dist/demo/inbox/createInboxApp.d.ts +2 -5
- package/dist/demo/inbox/createInboxApp.js +4 -4
- package/dist/demo/inbox/effects.d.ts +3 -5
- package/dist/demo/inbox/effects.js +5 -0
- package/dist/demo/inbox/state.d.ts +3 -0
- package/dist/demo/inbox/state.js +16 -0
- package/dist/index.d.ts +17 -2
- package/dist/index.js +12 -2
- package/dist/projection/gui/AppProvider.d.ts +8 -12
- package/dist/projection/gui/AppProvider.js +77 -2
- package/dist/projection/gui/hooks.d.ts +2 -5
- package/dist/projection/gui/hooks.js +3 -12
- package/dist/projection/react/AppRuntimeProvider.d.ts +10 -0
- package/dist/projection/react/AppRuntimeProvider.js +15 -0
- package/dist/projection/react/createReactAppRuntime.d.ts +35 -0
- package/dist/projection/react/createReactAppRuntime.js +80 -0
- package/dist/projection/react/hooks.d.ts +8 -0
- package/dist/projection/react/hooks.js +18 -0
- package/dist/projection/tui/View.d.ts +8 -0
- package/dist/projection/tui/View.js +5 -0
- package/dist/projection/tui/createSnapshotAssembler.d.ts +2 -0
- package/dist/projection/tui/createSnapshotAssembler.js +14 -0
- package/dist/projection/tui/renderSnapshotDocument.d.ts +2 -0
- package/dist/projection/tui/renderSnapshotDocument.js +3 -0
- package/dist/projection/tui/renderTUI.d.ts +1 -1
- package/dist/projection/tui/renderTUI.js +13 -4
- package/dist/projection/tui/renderViewFragment.d.ts +10 -0
- package/dist/projection/tui/renderViewFragment.js +15 -0
- package/dist/tool/createToolBridge.d.ts +4 -9
- package/dist/tool/createToolBridge.js +55 -11
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/package.json +8 -9
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ComponentChildren } from "preact";
|
|
2
|
+
import type { ViewFragment } from "../../core/types";
|
|
3
|
+
export type RenderViewFragmentInput = {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly type: string;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly children?: ComponentChildren;
|
|
8
|
+
readonly markup?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function renderViewFragment(input: RenderViewFragmentInput): ViewFragment;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
|
+
/** @jsxImportSource preact */
|
|
3
|
+
import renderToString from "preact-render-to-string";
|
|
4
|
+
import { View } from "./View";
|
|
5
|
+
export function renderViewFragment(input) {
|
|
6
|
+
const content = input.markup !== undefined
|
|
7
|
+
? { dangerouslySetInnerHTML: { __html: input.markup } }
|
|
8
|
+
: { children: input.children };
|
|
9
|
+
return {
|
|
10
|
+
id: input.id,
|
|
11
|
+
type: input.type,
|
|
12
|
+
name: input.name,
|
|
13
|
+
markup: renderToString(_jsx(View, { id: input.id, type: input.type, name: input.name, ...content })),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import type { SnapshotBundle, ActionResult } from "../core/types";
|
|
1
|
+
import type { SnapshotBundle, ActionResult, SnapshotRegistry, ToolDefinition } from "../core/types";
|
|
2
2
|
export declare function createToolBridge(config: {
|
|
3
3
|
actionRuntime: {
|
|
4
|
-
listVisibleTools():
|
|
5
|
-
name: string;
|
|
6
|
-
description: string;
|
|
7
|
-
}>;
|
|
4
|
+
listVisibleTools(): ToolDefinition[];
|
|
8
5
|
executeAction(name: string, input: Record<string, unknown>): Promise<ActionResult>;
|
|
9
6
|
};
|
|
10
7
|
renderCurrentSnapshot(): SnapshotBundle;
|
|
8
|
+
snapshotRegistry?: SnapshotRegistry;
|
|
11
9
|
}): {
|
|
12
|
-
listTools():
|
|
13
|
-
name: string;
|
|
14
|
-
description: string;
|
|
15
|
-
}[];
|
|
10
|
+
listTools(): ToolDefinition[];
|
|
16
11
|
getSnapshotBundle(): SnapshotBundle;
|
|
17
12
|
executeTool(name: string, input: Record<string, unknown>, snapshotId: string): Promise<ActionResult>;
|
|
18
13
|
};
|
|
@@ -1,15 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
import { createSnapshotRegistry } from "../core/snapshot/createSnapshotRegistry";
|
|
2
|
+
const DATA_REF_MARKER_PATTERN = /^\((?:[\s\S]*)\)\[[^:\]]+:(.+)\]$/;
|
|
3
|
+
const REF_ID_PATTERN = /^[A-Za-z0-9_.-]+(?:\[[^\]]+\])*$/;
|
|
4
|
+
function getExplicitRefId(value) {
|
|
5
|
+
const markerMatch = value.match(DATA_REF_MARKER_PATTERN);
|
|
6
|
+
if (markerMatch) {
|
|
7
|
+
return markerMatch[1];
|
|
8
|
+
}
|
|
9
|
+
if (REF_ID_PATTERN.test(value)) {
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
function resolveRefArgs(input, refIndex, supportsRefs) {
|
|
2
15
|
const resolved = {};
|
|
3
16
|
for (const [key, value] of Object.entries(input)) {
|
|
17
|
+
if (!supportsRefs || typeof value !== "string") {
|
|
18
|
+
resolved[key] = value;
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
4
21
|
if (typeof value === "string" && value in refIndex) {
|
|
5
22
|
resolved[key] = refIndex[value].value;
|
|
6
23
|
continue;
|
|
7
24
|
}
|
|
8
|
-
|
|
9
|
-
|
|
25
|
+
const explicitRefId = getExplicitRefId(value);
|
|
26
|
+
if (explicitRefId) {
|
|
27
|
+
if (explicitRefId in refIndex) {
|
|
28
|
+
resolved[key] = refIndex[explicitRefId].value;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
10
31
|
return {
|
|
11
32
|
success: false,
|
|
12
|
-
refId:
|
|
33
|
+
refId: explicitRefId,
|
|
13
34
|
};
|
|
14
35
|
}
|
|
15
36
|
resolved[key] = value;
|
|
@@ -20,19 +41,21 @@ function resolveRefArgs(input, refIndex) {
|
|
|
20
41
|
};
|
|
21
42
|
}
|
|
22
43
|
export function createToolBridge(config) {
|
|
23
|
-
const snapshots =
|
|
44
|
+
const snapshots = config.snapshotRegistry ??
|
|
45
|
+
createSnapshotRegistry({
|
|
46
|
+
maxEntries: 2,
|
|
47
|
+
});
|
|
24
48
|
return {
|
|
25
49
|
listTools() {
|
|
26
50
|
return config.actionRuntime.listVisibleTools();
|
|
27
51
|
},
|
|
28
52
|
getSnapshotBundle() {
|
|
29
53
|
const snapshot = config.renderCurrentSnapshot();
|
|
30
|
-
snapshots.
|
|
31
|
-
return snapshot;
|
|
54
|
+
return snapshots.create(snapshot);
|
|
32
55
|
},
|
|
33
56
|
async executeTool(name, input, snapshotId) {
|
|
34
|
-
const
|
|
35
|
-
if (!
|
|
57
|
+
const snapshotEntry = snapshots.lookup(snapshotId);
|
|
58
|
+
if (!snapshotEntry) {
|
|
36
59
|
return {
|
|
37
60
|
success: false,
|
|
38
61
|
error: {
|
|
@@ -41,7 +64,19 @@ export function createToolBridge(config) {
|
|
|
41
64
|
},
|
|
42
65
|
};
|
|
43
66
|
}
|
|
44
|
-
|
|
67
|
+
if (snapshotEntry.status === "stale") {
|
|
68
|
+
return {
|
|
69
|
+
success: false,
|
|
70
|
+
error: {
|
|
71
|
+
code: "SNAPSHOT_STALE",
|
|
72
|
+
message: `Snapshot ${snapshotId} is stale`,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const toolDefinition = snapshotEntry.snapshot.visibleTools.find((tool) => tool.name === name) ??
|
|
77
|
+
config.actionRuntime.listVisibleTools().find((tool) => tool.name === name);
|
|
78
|
+
const supportsRefs = toolDefinition?.meta?.supportsRefs === true;
|
|
79
|
+
const resolved = resolveRefArgs(input, snapshotEntry.snapshot.refIndex, supportsRefs);
|
|
45
80
|
if (!resolved.success) {
|
|
46
81
|
return {
|
|
47
82
|
success: false,
|
|
@@ -51,7 +86,16 @@ export function createToolBridge(config) {
|
|
|
51
86
|
},
|
|
52
87
|
};
|
|
53
88
|
}
|
|
54
|
-
|
|
89
|
+
const result = await config.actionRuntime.executeAction(name, resolved.data);
|
|
90
|
+
if (result.mutated) {
|
|
91
|
+
if (snapshots.markAllStale) {
|
|
92
|
+
snapshots.markAllStale();
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
snapshots.markStale(snapshotId);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
55
99
|
},
|
|
56
100
|
};
|
|
57
101
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VERSION = "0.1.0-alpha.1";
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const VERSION = "0.1.0-alpha.1";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aotui/mobile-ai-native",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
4
|
"description": "Alpha host-agnostic core for building Agent Native mobile apps with shared GUI/TUI state and snapshot-scoped tool execution.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -12,13 +12,6 @@
|
|
|
12
12
|
"types": "./dist/index.d.ts"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
|
-
"scripts": {
|
|
16
|
-
"clean": "rm -rf dist",
|
|
17
|
-
"build": "pnpm run clean && tsc -p tsconfig.json",
|
|
18
|
-
"test": "vitest",
|
|
19
|
-
"test:run": "vitest --run",
|
|
20
|
-
"prepublishOnly": "pnpm build"
|
|
21
|
-
},
|
|
22
15
|
"dependencies": {
|
|
23
16
|
"preact": "^10.28.1",
|
|
24
17
|
"preact-render-to-string": "^6.6.6",
|
|
@@ -45,5 +38,11 @@
|
|
|
45
38
|
],
|
|
46
39
|
"publishConfig": {
|
|
47
40
|
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"clean": "rm -rf dist",
|
|
44
|
+
"build": "pnpm run clean && tsc -p tsconfig.json",
|
|
45
|
+
"test": "vitest",
|
|
46
|
+
"test:run": "vitest --run"
|
|
48
47
|
}
|
|
49
|
-
}
|
|
48
|
+
}
|