@ai-matrx/applets 0.2.7
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/CHANGELOG.md +130 -0
- package/LICENSE +21 -0
- package/README.md +37 -0
- package/dist/context-Dz3PWsJd.d.cts +193 -0
- package/dist/context-Dz3PWsJd.d.ts +193 -0
- package/dist/frame.cjs +977 -0
- package/dist/frame.cjs.map +1 -0
- package/dist/frame.d.cts +42 -0
- package/dist/frame.d.ts +42 -0
- package/dist/frame.js +958 -0
- package/dist/frame.js.map +1 -0
- package/dist/host.cjs +664 -0
- package/dist/host.cjs.map +1 -0
- package/dist/host.d.cts +128 -0
- package/dist/host.d.ts +128 -0
- package/dist/host.js +641 -0
- package/dist/host.js.map +1 -0
- package/dist/index.cjs +66 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +200 -0
- package/dist/index.d.ts +200 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/platform.cjs +699 -0
- package/dist/platform.cjs.map +1 -0
- package/dist/platform.d.cts +135 -0
- package/dist/platform.d.ts +135 -0
- package/dist/platform.js +680 -0
- package/dist/platform.js.map +1 -0
- package/dist/react.cjs +880 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +178 -0
- package/dist/react.d.ts +178 -0
- package/dist/react.js +854 -0
- package/dist/react.js.map +1 -0
- package/package.json +128 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Changelog — @ai-matrx/applets
|
|
2
|
+
|
|
3
|
+
## 0.2.7
|
|
4
|
+
|
|
5
|
+
Automatic changed-only republish (docs/metadata drift since the last tag — see
|
|
6
|
+
`git diff npm/applets/vnull..npm/applets/v0.2.7 -- apps/shared/applets`).
|
|
7
|
+
No source changes intended and no consumer action required.
|
|
8
|
+
|
|
9
|
+
## 0.2.6
|
|
10
|
+
|
|
11
|
+
Automatic changed-only republish (docs/metadata drift since the last tag — see
|
|
12
|
+
`git diff npm/applets/vnull..npm/applets/v0.2.6 -- apps/shared/applets`).
|
|
13
|
+
No source changes intended and no consumer action required.
|
|
14
|
+
|
|
15
|
+
## 0.2.5
|
|
16
|
+
|
|
17
|
+
Automatic changed-only republish (docs/metadata drift since the last tag — see
|
|
18
|
+
`git diff npm/applets/vnull..npm/applets/v0.2.5 -- apps/shared/applets`).
|
|
19
|
+
No source changes intended and no consumer action required.
|
|
20
|
+
|
|
21
|
+
## 0.2.4
|
|
22
|
+
|
|
23
|
+
Automatic changed-only republish (docs/metadata drift since the last tag — see
|
|
24
|
+
`git diff npm/applets/vnull..npm/applets/v0.2.4 -- apps/shared/applets`).
|
|
25
|
+
No source changes intended and no consumer action required.
|
|
26
|
+
|
|
27
|
+
## 0.2.3
|
|
28
|
+
|
|
29
|
+
Automatic changed-only republish (docs/metadata drift since the last tag — see
|
|
30
|
+
`git diff npm/applets/vnull..npm/applets/v0.2.3 -- apps/shared/applets`).
|
|
31
|
+
No source changes intended and no consumer action required.
|
|
32
|
+
|
|
33
|
+
## 0.2.2
|
|
34
|
+
|
|
35
|
+
Automatic changed-only republish (docs/metadata drift since the last tag — see
|
|
36
|
+
`git diff npm/applets/vnull..npm/applets/v0.2.2 -- apps/shared/applets`).
|
|
37
|
+
No source changes intended and no consumer action required.
|
|
38
|
+
|
|
39
|
+
## 0.2.1 — 2026-10-06
|
|
40
|
+
|
|
41
|
+
`createPlatformHost` binds records' live updates by default: with no `records.realtime` given it uses
|
|
42
|
+
`createRecordsRealtimePort()` from `@ai-matrx/records/realtime` over the host app's mounted
|
|
43
|
+
`@ai-matrx/realtime` manager, so `rows:<alias>` fires with no per-host wiring.
|
|
44
|
+
|
|
45
|
+
Consumer action: none, unless your host passed its own realtime port only to get live rows — drop it.
|
|
46
|
+
|
|
47
|
+
## 0.2.0 — 2026-10-06
|
|
48
|
+
|
|
49
|
+
`@ai-matrx/applets/platform`: `createPlatformHost(opts)`, the real `AppletHost` over the live platform
|
|
50
|
+
(AP-0). Host-neutral — every client is injected: `{ appletId, supabase (the viewer's session), agents
|
|
51
|
+
(`@ai-matrx/agents/intelligence` port), activeOrganizationId, nav: { go, current, subscribe? },
|
|
52
|
+
reportError, surfaces?: { serverActions?, approvals?, door?, maxDepth? }, records?: { realtime?,
|
|
53
|
+
knownDoors? } }`. No framework, no store, no environment reads. Announces itself (`kind: "platform"`).
|
|
54
|
+
|
|
55
|
+
- `record()` reads `app.definition` through the viewer's client. A row with code only in
|
|
56
|
+
`component_code` is read as `files: { "App.tsx" }`, one page — a migration bridge that is deleted
|
|
57
|
+
with AP-0's record migration.
|
|
58
|
+
- `data`: table sources go through records' `createTableDataPort` (the table's own organization for
|
|
59
|
+
writes; reads span every membership); entity sources refuse `not_supported` by name until AP-3 phase B.
|
|
60
|
+
- `intelligence`: alias → key from the record, `appletId` stamped on every run; a signed-in run with
|
|
61
|
+
no active organization is refused `organization_required` (held, never picked); guests run with null.
|
|
62
|
+
- `surface`: the `applets/<id>` chain read from `ui.ui_surface*`, resolved with alchemy's
|
|
63
|
+
`resolveActionChain` and run through `runSurfaceAction`; page Actions go to the declaring Applet's
|
|
64
|
+
frame on `actions` and settle on `completeAction`; base `write_row` is answered by the data port.
|
|
65
|
+
- `kinds` read `content_ir.kind_definition` / `kind_component`; `pages` refuse `not_supported`
|
|
66
|
+
(no table-built page store exists yet).
|
|
67
|
+
- `events`: one hub for `rows:<alias>`, `run:<requestId>`, `value:<name>`, `actions`, `nav`.
|
|
68
|
+
- `child(appletId)` answers a scoped host; `dispose()` stops every producer.
|
|
69
|
+
|
|
70
|
+
### Consumer action
|
|
71
|
+
|
|
72
|
+
None for existing imports. A host replacing its hand-built web host imports `createPlatformHost` from
|
|
73
|
+
`@ai-matrx/applets/platform` and passes its own clients; until the Applet is saved through
|
|
74
|
+
`ui.save_applet_surface`, `surface.mount` refuses `surface_not_found` by name.
|
|
75
|
+
|
|
76
|
+
## 0.1.2 — 2026-10-06
|
|
77
|
+
|
|
78
|
+
Data hooks rebuilt on `@ai-matrx/records/data` (records 0.74, AP-3). One data engine: records'.
|
|
79
|
+
|
|
80
|
+
- `Column`, `Row`, `Values`, `Query`, `Page`, `DataPort`, `HostDataPort`, `RowsEvent`, `DataSource`,
|
|
81
|
+
`DataEvents` are re-exported from `@ai-matrx/records/data`; `Filter` = records' `WhereClause`,
|
|
82
|
+
`SourceInfo` = records' `DataSource`. A DataPort now answers `RecordsResult` (a `RecordsError`);
|
|
83
|
+
`fromRecordsError` turns it into the §0 `AppletError`.
|
|
84
|
+
- `useRows`, `useRow`, `useColumns`, `useSources` and create/update/archive/restore wrap
|
|
85
|
+
`useDataRows`/`useDataRow`/`useDataColumns`/`useDataSources`/`useDataMutations`; `AppletFrame`
|
|
86
|
+
mounts `DataPortProvider` (`port = host.data`, `events = host.events`, `portKey = hostId`). The
|
|
87
|
+
package's own TanStack row engine is deleted. Additive: `useRows` returns `newer` and `refresh()`,
|
|
88
|
+
`useRow` returns `refresh()`.
|
|
89
|
+
- Memory host: its data port is a records `HostDataPort` (`control.dataPort`); `spec.data` accepts a
|
|
90
|
+
real one (`createTableDataPort`) in place of `tables`. `MemoryTableSpec.refuse` returns a
|
|
91
|
+
`RecordsError` (no `retryable`); an unknown alias refuses `not_found`.
|
|
92
|
+
- `@tanstack/react-query` floor raised to `^5.104.1` (one copy shared with records).
|
|
93
|
+
|
|
94
|
+
### Consumer action
|
|
95
|
+
|
|
96
|
+
A host that implemented `AppletHost.data` itself returns `RecordsResult` with a `RecordsErrorCode`;
|
|
97
|
+
a memory-host `refuse` callback drops `retryable`; code matching optimistic ids looks for `pending-`
|
|
98
|
+
(was `optimistic:`). Applet code using §2 hooks needs no change.
|
|
99
|
+
|
|
100
|
+
## 0.1.1
|
|
101
|
+
|
|
102
|
+
Automatic changed-only republish (docs/metadata drift since the last tag — see
|
|
103
|
+
`git diff npm/applets/vnull..npm/applets/v0.1.1 -- apps/shared/applets`).
|
|
104
|
+
No source changes intended and no consumer action required.
|
|
105
|
+
|
|
106
|
+
## 0.1.0 — 2026-10-06
|
|
107
|
+
|
|
108
|
+
First release (Applets AP-0, CONTRACTS v2 §0–§4, §6, §8).
|
|
109
|
+
|
|
110
|
+
- `@ai-matrx/applets`: the types this package owns (`Result`, `AppletError`, `Status`,
|
|
111
|
+
`AppletRecord`), the `AppletHost` doorway and its ports, and the event stream names
|
|
112
|
+
(`rows:<alias>`, `run:<requestId>`, `value:<name>`, `actions`, `nav`). Types owned elsewhere
|
|
113
|
+
are re-exported from their owners: `RunRef`, `ServedInput`, `RunEvent` (`@ai-matrx/agents`),
|
|
114
|
+
`ActionDeclaration`, `ActionInfo`, `ActionContext`, `SurfacePort` (`@ai-matrx/alchemy`),
|
|
115
|
+
`ScopeSpec` (`@ai-matrx/code-runtime`), `EntityRef`, `Uuid` (`@ai-matrx/records`). `Column`,
|
|
116
|
+
`Row`, `Values`, `Query`, `Page` and `DataPort` are AP-3's and are written structurally here
|
|
117
|
+
until `@ai-matrx/records` exports them.
|
|
118
|
+
- `/host`: `createMemoryHost(spec)` — every port over in-memory data; announces itself
|
|
119
|
+
(`kind: "memory"`).
|
|
120
|
+
- `/react`: `AppletFrame`, `useRows`, `useRow`, `useColumns`, `useSources`, `useJob`, `useJobs`,
|
|
121
|
+
`useValue`, `useAction`, `defineActions`, `usePage`, `navigate`, `Link`, `Pages`, `Applet`,
|
|
122
|
+
`Kind`, `DataPage`, on TanStack Query.
|
|
123
|
+
- `/frame`: `mountApplet(record, host, scope)` / `mountAppletAsync` — compile a stored
|
|
124
|
+
multi-file record through `@ai-matrx/code-runtime` and render it in its frame.
|
|
125
|
+
|
|
126
|
+
### Consumer action
|
|
127
|
+
|
|
128
|
+
- None yet: matrx-frontend adopts this package with the in-page host (AP-0's next step).
|
|
129
|
+
|
|
130
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AI Matrix Engine
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# @ai-matrx/applets
|
|
2
|
+
|
|
3
|
+
Applets are custom interfaces an agent builds on a person's own data and the platform's
|
|
4
|
+
features. This package is the doorway between an Applet and whatever hosts it.
|
|
5
|
+
|
|
6
|
+
| Entry | What it is |
|
|
7
|
+
|---|---|
|
|
8
|
+
| `@ai-matrx/applets` | The contract types and the `AppletHost` interface. No React. |
|
|
9
|
+
| `@ai-matrx/applets/host` | `createMemoryHost(spec)` — an in-memory host for tests and development. |
|
|
10
|
+
| `@ai-matrx/applets/react` | What Applet code imports: `useRows`, `useJob`, `useValue`, `useAction`, `Pages`, … |
|
|
11
|
+
| `@ai-matrx/applets/platform` | `createPlatformHost(opts)` — the real host over the live platform; every client injected. |
|
|
12
|
+
| `@ai-matrx/applets/frame` | `mountApplet(record, host, scope)` — compile a stored Applet and render it. |
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { createMemoryHost } from "@ai-matrx/applets/host";
|
|
16
|
+
import { mountApplet } from "@ai-matrx/applets/frame";
|
|
17
|
+
|
|
18
|
+
const host = createMemoryHost({ record, tables: { posts: { columns, rows } } });
|
|
19
|
+
const mounted = mountApplet(record, host, { entries: [], shadowDangerousGlobals: true });
|
|
20
|
+
if (mounted.ok) root.render(<mounted.Component />);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Inside an Applet:
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { useRows, useJob, Pages } from "@ai-matrx/applets/react";
|
|
27
|
+
|
|
28
|
+
export default function Posts() {
|
|
29
|
+
const { rows, update, error } = useRows("posts"); // optimistic, versioned writes
|
|
30
|
+
const draft = useJob("draft"); // a declared job, by alias
|
|
31
|
+
return <ul>{rows.map((r) => <li key={r._id}>{String(r.title)}</li>)}</ul>;
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Hooks never throw: each answers a `status` and an `error` carrying the system's own sentence.
|
|
36
|
+
React and React DOM are peer dependencies. The contract this implements is
|
|
37
|
+
`common-docs/projects/applets/CONTRACTS.md` (v2).
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
3
|
+
import { Uuid as Uuid$1 } from '@ai-matrx/records';
|
|
4
|
+
import { IntelligencePort as IntelligencePort$1 } from '@ai-matrx/agents/intelligence';
|
|
5
|
+
import { SurfacePort as SurfacePort$1, ActionContext } from '@ai-matrx/alchemy/actions';
|
|
6
|
+
import { ScopeSpec } from '@ai-matrx/code-runtime';
|
|
7
|
+
import { DataPort, DataSource } from '@ai-matrx/records/data';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The Applets contract types (CONTRACTS v2 §0, §1, §3, §4, §6, §8).
|
|
11
|
+
*
|
|
12
|
+
* One owner per type. Types another package owns are RE-EXPORTED from it,
|
|
13
|
+
* never redefined; types whose owner has not exported them yet are written
|
|
14
|
+
* here structurally, each naming its owner and contract section, and are
|
|
15
|
+
* replaced by a re-export the release the owner ships them.
|
|
16
|
+
*
|
|
17
|
+
* Framework-free: no React, no runtime imports. Every import below is a type.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** `@ai-matrx/records` — a UUID string. */
|
|
21
|
+
type Uuid = Uuid$1;
|
|
22
|
+
/**
|
|
23
|
+
* The system's own sentence. Superset of `RecordsError` in the sense of the
|
|
24
|
+
* contract: `code` + the store's `message`, plus `retryable`.
|
|
25
|
+
*/
|
|
26
|
+
interface AppletError {
|
|
27
|
+
code: string;
|
|
28
|
+
message: string;
|
|
29
|
+
retryable: boolean;
|
|
30
|
+
diagnostic?: string;
|
|
31
|
+
}
|
|
32
|
+
/** Never throws: every port call and every hook write answers one of these. */
|
|
33
|
+
type Result<T> = {
|
|
34
|
+
ok: true;
|
|
35
|
+
data: T;
|
|
36
|
+
} | {
|
|
37
|
+
ok: false;
|
|
38
|
+
error: AppletError;
|
|
39
|
+
};
|
|
40
|
+
type Status = "idle" | "loading" | "ready" | "saving" | "error";
|
|
41
|
+
|
|
42
|
+
/** One source an Applet declared (CONTRACTS §2 `useSources`, §4 `sources()`) — records' `DataSource`. */
|
|
43
|
+
type SourceInfo = DataSource;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* CONTRACTS §3 `IntelligencePort` (owner `@ai-matrx/agents`, AP-1) as a host
|
|
47
|
+
* port: the agents package's port minus its in-process `events` listener —
|
|
48
|
+
* across the doorway, run events arrive on the host's `run:<requestId>`
|
|
49
|
+
* stream instead (no port takes a function).
|
|
50
|
+
*/
|
|
51
|
+
type IntelligencePort = Omit<IntelligencePort$1, "events">;
|
|
52
|
+
/** CONTRACTS §6 `SurfacePort` (owner `@ai-matrx/alchemy`, AP-2). Events: `value:<name>`. */
|
|
53
|
+
type SurfacePort = SurfacePort$1;
|
|
54
|
+
interface AppletPage {
|
|
55
|
+
path: string;
|
|
56
|
+
title: string;
|
|
57
|
+
file: string;
|
|
58
|
+
parent?: string;
|
|
59
|
+
}
|
|
60
|
+
interface AppletMandate {
|
|
61
|
+
alias: string;
|
|
62
|
+
key: string;
|
|
63
|
+
}
|
|
64
|
+
type AppletSource = {
|
|
65
|
+
alias: string;
|
|
66
|
+
table_id: Uuid;
|
|
67
|
+
organization_id: Uuid;
|
|
68
|
+
} | {
|
|
69
|
+
alias: string;
|
|
70
|
+
entity: string;
|
|
71
|
+
};
|
|
72
|
+
/** CONTRACTS §8 `AppletRecord` (owner `@ai-matrx/applets`, AP-0). */
|
|
73
|
+
interface AppletRecord {
|
|
74
|
+
id: Uuid;
|
|
75
|
+
version: number;
|
|
76
|
+
organizationId: Uuid;
|
|
77
|
+
slug: string;
|
|
78
|
+
published: boolean;
|
|
79
|
+
files: Record<string, string>;
|
|
80
|
+
entry: string;
|
|
81
|
+
scope: ScopeSpec;
|
|
82
|
+
pages: AppletPage[];
|
|
83
|
+
mandates: AppletMandate[];
|
|
84
|
+
sources: AppletSource[];
|
|
85
|
+
parentId: Uuid | null;
|
|
86
|
+
/** `applets/<id>` */
|
|
87
|
+
surfaceName: string;
|
|
88
|
+
}
|
|
89
|
+
interface Viewer {
|
|
90
|
+
userId: Uuid | null;
|
|
91
|
+
organizationIds: Uuid[];
|
|
92
|
+
activeOrganizationId: Uuid | null;
|
|
93
|
+
guest: boolean;
|
|
94
|
+
}
|
|
95
|
+
interface NavLocation {
|
|
96
|
+
path: string[];
|
|
97
|
+
params: Record<string, string>;
|
|
98
|
+
}
|
|
99
|
+
interface KindComponentSource {
|
|
100
|
+
files: Record<string, string>;
|
|
101
|
+
entry: string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* CONTRACTS §1 `AppletHost`. Every call is an async request with JSON in and
|
|
105
|
+
* JSON out (kind envelopes allowed), scoped to ONE mounted Applet.
|
|
106
|
+
*/
|
|
107
|
+
interface AppletHost {
|
|
108
|
+
viewer(): Promise<Viewer>;
|
|
109
|
+
record(): Promise<AppletRecord>;
|
|
110
|
+
child(appletId: Uuid): Promise<{
|
|
111
|
+
hostId: string;
|
|
112
|
+
}>;
|
|
113
|
+
kinds: {
|
|
114
|
+
definition(slug: string): Promise<Result<unknown>>;
|
|
115
|
+
component(slug: string, platform: string): Promise<Result<KindComponentSource | null>>;
|
|
116
|
+
};
|
|
117
|
+
pages: {
|
|
118
|
+
definition(pageId: Uuid): Promise<Result<unknown>>;
|
|
119
|
+
};
|
|
120
|
+
data: DataPort;
|
|
121
|
+
intelligence: IntelligencePort;
|
|
122
|
+
surface: SurfacePort;
|
|
123
|
+
nav: {
|
|
124
|
+
go(to: string): Promise<void>;
|
|
125
|
+
current(): Promise<NavLocation>;
|
|
126
|
+
};
|
|
127
|
+
events: {
|
|
128
|
+
on(stream: string, filter: unknown): Promise<{
|
|
129
|
+
subscriptionId: string;
|
|
130
|
+
}>;
|
|
131
|
+
off(subscriptionId: string): Promise<void>;
|
|
132
|
+
};
|
|
133
|
+
reportError(err: AppletError & {
|
|
134
|
+
where: string;
|
|
135
|
+
}): Promise<void>;
|
|
136
|
+
}
|
|
137
|
+
/** What the frame receives for each event (CONTRACTS §1). */
|
|
138
|
+
interface EventMessage {
|
|
139
|
+
subscriptionId: string;
|
|
140
|
+
payload: unknown;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* The frame's side of the doorway: the contract's `AppletHost` plus the two
|
|
144
|
+
* things §1 says the CHANNEL supplies — receiving `{ subscriptionId, payload }`
|
|
145
|
+
* messages, and addressing a child host by the `hostId` that `child()` answered.
|
|
146
|
+
* An in-page host implements these in memory; a sandbox host maps them onto a
|
|
147
|
+
* message channel. Neither is a port: nothing here crosses the doorway as data.
|
|
148
|
+
*/
|
|
149
|
+
interface AppletChannel extends AppletHost {
|
|
150
|
+
readonly hostId: string;
|
|
151
|
+
/** Subscribe to every event message for this host. Returns an unsubscribe. */
|
|
152
|
+
receive(listener: (message: EventMessage) => void): () => void;
|
|
153
|
+
/** The scoped host for a `hostId` that `child()` answered. */
|
|
154
|
+
forHost(hostId: string): AppletChannel | null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The frame: `<AppletFrame host>` and the per-frame machinery every hook reads
|
|
159
|
+
* (CONTRACTS §1–§2). One frame per mounted Applet; a nested Applet gets its own
|
|
160
|
+
* frame over the child host, sharing the parent's query cache (keys carry the
|
|
161
|
+
* hostId, so aliases never collide across nesting).
|
|
162
|
+
*
|
|
163
|
+
* The engine is TanStack Query, one QueryClient per frame tree. Rows go through
|
|
164
|
+
* ONE engine, `@ai-matrx/records/data/react`, which the frame mounts with
|
|
165
|
+
* `DataPortProvider` (port `host.data`, events `host.events`, portKey `hostId`).
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
type PageActionHandler = (input: unknown, ctx: ActionContext) => unknown | Promise<unknown>;
|
|
169
|
+
interface FrameRenderers {
|
|
170
|
+
/** Renders a kind envelope's data. The real one comes from `@ai-matrx/content-ir-react`. */
|
|
171
|
+
renderKind?: (kind: string, value: unknown) => React.ReactNode;
|
|
172
|
+
/** Renders a table-built page from its `pages.definition`. */
|
|
173
|
+
renderDataPage?: (id: string, definition: unknown) => React.ReactNode;
|
|
174
|
+
/** Renders a nested Applet over its child host (`mountApplet` supplies this). */
|
|
175
|
+
renderApplet?: (child: AppletChannel) => React.ReactNode;
|
|
176
|
+
/** The component for one of the record's page files (`mountApplet` supplies this). */
|
|
177
|
+
pageComponent?: (file: string) => React.ComponentType<Record<string, unknown>> | null;
|
|
178
|
+
}
|
|
179
|
+
declare function newQueryClient(): QueryClient;
|
|
180
|
+
interface AppletFrameProps extends FrameRenderers {
|
|
181
|
+
host: AppletChannel;
|
|
182
|
+
/** Defaults to the parent frame's client, else a new one for this frame. */
|
|
183
|
+
queryClient?: QueryClient;
|
|
184
|
+
children?: React.ReactNode;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Mounts one Applet: provides its host to every hook below, joins its surface
|
|
188
|
+
* to the runtime chain (`applets/<id>` under the parent frame's surface), and
|
|
189
|
+
* routes page-Action runs to the handlers `defineActions` registered.
|
|
190
|
+
*/
|
|
191
|
+
declare function AppletFrame({ host, queryClient, children, ...renderers }: AppletFrameProps): React.ReactElement;
|
|
192
|
+
|
|
193
|
+
export { type AppletError as A, type FrameRenderers as F, type PageActionHandler as P, type Result as R, type Status as S, type Uuid as U, type AppletRecord as a, type AppletChannel as b, type SourceInfo as c, type AppletPage as d, AppletFrame as e, type AppletFrameProps as f, newQueryClient as n };
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
3
|
+
import { Uuid as Uuid$1 } from '@ai-matrx/records';
|
|
4
|
+
import { IntelligencePort as IntelligencePort$1 } from '@ai-matrx/agents/intelligence';
|
|
5
|
+
import { SurfacePort as SurfacePort$1, ActionContext } from '@ai-matrx/alchemy/actions';
|
|
6
|
+
import { ScopeSpec } from '@ai-matrx/code-runtime';
|
|
7
|
+
import { DataPort, DataSource } from '@ai-matrx/records/data';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The Applets contract types (CONTRACTS v2 §0, §1, §3, §4, §6, §8).
|
|
11
|
+
*
|
|
12
|
+
* One owner per type. Types another package owns are RE-EXPORTED from it,
|
|
13
|
+
* never redefined; types whose owner has not exported them yet are written
|
|
14
|
+
* here structurally, each naming its owner and contract section, and are
|
|
15
|
+
* replaced by a re-export the release the owner ships them.
|
|
16
|
+
*
|
|
17
|
+
* Framework-free: no React, no runtime imports. Every import below is a type.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** `@ai-matrx/records` — a UUID string. */
|
|
21
|
+
type Uuid = Uuid$1;
|
|
22
|
+
/**
|
|
23
|
+
* The system's own sentence. Superset of `RecordsError` in the sense of the
|
|
24
|
+
* contract: `code` + the store's `message`, plus `retryable`.
|
|
25
|
+
*/
|
|
26
|
+
interface AppletError {
|
|
27
|
+
code: string;
|
|
28
|
+
message: string;
|
|
29
|
+
retryable: boolean;
|
|
30
|
+
diagnostic?: string;
|
|
31
|
+
}
|
|
32
|
+
/** Never throws: every port call and every hook write answers one of these. */
|
|
33
|
+
type Result<T> = {
|
|
34
|
+
ok: true;
|
|
35
|
+
data: T;
|
|
36
|
+
} | {
|
|
37
|
+
ok: false;
|
|
38
|
+
error: AppletError;
|
|
39
|
+
};
|
|
40
|
+
type Status = "idle" | "loading" | "ready" | "saving" | "error";
|
|
41
|
+
|
|
42
|
+
/** One source an Applet declared (CONTRACTS §2 `useSources`, §4 `sources()`) — records' `DataSource`. */
|
|
43
|
+
type SourceInfo = DataSource;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* CONTRACTS §3 `IntelligencePort` (owner `@ai-matrx/agents`, AP-1) as a host
|
|
47
|
+
* port: the agents package's port minus its in-process `events` listener —
|
|
48
|
+
* across the doorway, run events arrive on the host's `run:<requestId>`
|
|
49
|
+
* stream instead (no port takes a function).
|
|
50
|
+
*/
|
|
51
|
+
type IntelligencePort = Omit<IntelligencePort$1, "events">;
|
|
52
|
+
/** CONTRACTS §6 `SurfacePort` (owner `@ai-matrx/alchemy`, AP-2). Events: `value:<name>`. */
|
|
53
|
+
type SurfacePort = SurfacePort$1;
|
|
54
|
+
interface AppletPage {
|
|
55
|
+
path: string;
|
|
56
|
+
title: string;
|
|
57
|
+
file: string;
|
|
58
|
+
parent?: string;
|
|
59
|
+
}
|
|
60
|
+
interface AppletMandate {
|
|
61
|
+
alias: string;
|
|
62
|
+
key: string;
|
|
63
|
+
}
|
|
64
|
+
type AppletSource = {
|
|
65
|
+
alias: string;
|
|
66
|
+
table_id: Uuid;
|
|
67
|
+
organization_id: Uuid;
|
|
68
|
+
} | {
|
|
69
|
+
alias: string;
|
|
70
|
+
entity: string;
|
|
71
|
+
};
|
|
72
|
+
/** CONTRACTS §8 `AppletRecord` (owner `@ai-matrx/applets`, AP-0). */
|
|
73
|
+
interface AppletRecord {
|
|
74
|
+
id: Uuid;
|
|
75
|
+
version: number;
|
|
76
|
+
organizationId: Uuid;
|
|
77
|
+
slug: string;
|
|
78
|
+
published: boolean;
|
|
79
|
+
files: Record<string, string>;
|
|
80
|
+
entry: string;
|
|
81
|
+
scope: ScopeSpec;
|
|
82
|
+
pages: AppletPage[];
|
|
83
|
+
mandates: AppletMandate[];
|
|
84
|
+
sources: AppletSource[];
|
|
85
|
+
parentId: Uuid | null;
|
|
86
|
+
/** `applets/<id>` */
|
|
87
|
+
surfaceName: string;
|
|
88
|
+
}
|
|
89
|
+
interface Viewer {
|
|
90
|
+
userId: Uuid | null;
|
|
91
|
+
organizationIds: Uuid[];
|
|
92
|
+
activeOrganizationId: Uuid | null;
|
|
93
|
+
guest: boolean;
|
|
94
|
+
}
|
|
95
|
+
interface NavLocation {
|
|
96
|
+
path: string[];
|
|
97
|
+
params: Record<string, string>;
|
|
98
|
+
}
|
|
99
|
+
interface KindComponentSource {
|
|
100
|
+
files: Record<string, string>;
|
|
101
|
+
entry: string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* CONTRACTS §1 `AppletHost`. Every call is an async request with JSON in and
|
|
105
|
+
* JSON out (kind envelopes allowed), scoped to ONE mounted Applet.
|
|
106
|
+
*/
|
|
107
|
+
interface AppletHost {
|
|
108
|
+
viewer(): Promise<Viewer>;
|
|
109
|
+
record(): Promise<AppletRecord>;
|
|
110
|
+
child(appletId: Uuid): Promise<{
|
|
111
|
+
hostId: string;
|
|
112
|
+
}>;
|
|
113
|
+
kinds: {
|
|
114
|
+
definition(slug: string): Promise<Result<unknown>>;
|
|
115
|
+
component(slug: string, platform: string): Promise<Result<KindComponentSource | null>>;
|
|
116
|
+
};
|
|
117
|
+
pages: {
|
|
118
|
+
definition(pageId: Uuid): Promise<Result<unknown>>;
|
|
119
|
+
};
|
|
120
|
+
data: DataPort;
|
|
121
|
+
intelligence: IntelligencePort;
|
|
122
|
+
surface: SurfacePort;
|
|
123
|
+
nav: {
|
|
124
|
+
go(to: string): Promise<void>;
|
|
125
|
+
current(): Promise<NavLocation>;
|
|
126
|
+
};
|
|
127
|
+
events: {
|
|
128
|
+
on(stream: string, filter: unknown): Promise<{
|
|
129
|
+
subscriptionId: string;
|
|
130
|
+
}>;
|
|
131
|
+
off(subscriptionId: string): Promise<void>;
|
|
132
|
+
};
|
|
133
|
+
reportError(err: AppletError & {
|
|
134
|
+
where: string;
|
|
135
|
+
}): Promise<void>;
|
|
136
|
+
}
|
|
137
|
+
/** What the frame receives for each event (CONTRACTS §1). */
|
|
138
|
+
interface EventMessage {
|
|
139
|
+
subscriptionId: string;
|
|
140
|
+
payload: unknown;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* The frame's side of the doorway: the contract's `AppletHost` plus the two
|
|
144
|
+
* things §1 says the CHANNEL supplies — receiving `{ subscriptionId, payload }`
|
|
145
|
+
* messages, and addressing a child host by the `hostId` that `child()` answered.
|
|
146
|
+
* An in-page host implements these in memory; a sandbox host maps them onto a
|
|
147
|
+
* message channel. Neither is a port: nothing here crosses the doorway as data.
|
|
148
|
+
*/
|
|
149
|
+
interface AppletChannel extends AppletHost {
|
|
150
|
+
readonly hostId: string;
|
|
151
|
+
/** Subscribe to every event message for this host. Returns an unsubscribe. */
|
|
152
|
+
receive(listener: (message: EventMessage) => void): () => void;
|
|
153
|
+
/** The scoped host for a `hostId` that `child()` answered. */
|
|
154
|
+
forHost(hostId: string): AppletChannel | null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The frame: `<AppletFrame host>` and the per-frame machinery every hook reads
|
|
159
|
+
* (CONTRACTS §1–§2). One frame per mounted Applet; a nested Applet gets its own
|
|
160
|
+
* frame over the child host, sharing the parent's query cache (keys carry the
|
|
161
|
+
* hostId, so aliases never collide across nesting).
|
|
162
|
+
*
|
|
163
|
+
* The engine is TanStack Query, one QueryClient per frame tree. Rows go through
|
|
164
|
+
* ONE engine, `@ai-matrx/records/data/react`, which the frame mounts with
|
|
165
|
+
* `DataPortProvider` (port `host.data`, events `host.events`, portKey `hostId`).
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
type PageActionHandler = (input: unknown, ctx: ActionContext) => unknown | Promise<unknown>;
|
|
169
|
+
interface FrameRenderers {
|
|
170
|
+
/** Renders a kind envelope's data. The real one comes from `@ai-matrx/content-ir-react`. */
|
|
171
|
+
renderKind?: (kind: string, value: unknown) => React.ReactNode;
|
|
172
|
+
/** Renders a table-built page from its `pages.definition`. */
|
|
173
|
+
renderDataPage?: (id: string, definition: unknown) => React.ReactNode;
|
|
174
|
+
/** Renders a nested Applet over its child host (`mountApplet` supplies this). */
|
|
175
|
+
renderApplet?: (child: AppletChannel) => React.ReactNode;
|
|
176
|
+
/** The component for one of the record's page files (`mountApplet` supplies this). */
|
|
177
|
+
pageComponent?: (file: string) => React.ComponentType<Record<string, unknown>> | null;
|
|
178
|
+
}
|
|
179
|
+
declare function newQueryClient(): QueryClient;
|
|
180
|
+
interface AppletFrameProps extends FrameRenderers {
|
|
181
|
+
host: AppletChannel;
|
|
182
|
+
/** Defaults to the parent frame's client, else a new one for this frame. */
|
|
183
|
+
queryClient?: QueryClient;
|
|
184
|
+
children?: React.ReactNode;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Mounts one Applet: provides its host to every hook below, joins its surface
|
|
188
|
+
* to the runtime chain (`applets/<id>` under the parent frame's surface), and
|
|
189
|
+
* routes page-Action runs to the handlers `defineActions` registered.
|
|
190
|
+
*/
|
|
191
|
+
declare function AppletFrame({ host, queryClient, children, ...renderers }: AppletFrameProps): React.ReactElement;
|
|
192
|
+
|
|
193
|
+
export { type AppletError as A, type FrameRenderers as F, type PageActionHandler as P, type Result as R, type Status as S, type Uuid as U, type AppletRecord as a, type AppletChannel as b, type SourceInfo as c, type AppletPage as d, AppletFrame as e, type AppletFrameProps as f, newQueryClient as n };
|