@moonan_ai/sdk 0.0.4-alpha2 → 0.0.5-alpha1
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/README.md +12 -1
- package/dist/data.js +90 -0
- package/dist/data.js.map +1 -0
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/dist/model-provider.js +5 -0
- package/dist/model-provider.js.map +1 -0
- package/dist/{manifest.js → web-facet-catalog.js} +10 -10
- package/dist/web-facet-catalog.js.map +1 -0
- package/dist/web.js +4 -4
- package/dist/web.js.map +1 -1
- package/package.json +1 -1
- package/src/data.ts +184 -0
- package/src/index.ts +26 -5
- package/src/model-provider.ts +45 -0
- package/src/{manifest.ts → web-facet-catalog.ts} +9 -9
- package/src/web.ts +4 -4
- package/dist/manifest.js.map +0 -1
package/README.md
CHANGED
|
@@ -59,10 +59,21 @@ export default defineFacet((api) => {
|
|
|
59
59
|
## 约定
|
|
60
60
|
|
|
61
61
|
- 契约在两端**各写一份**:Chord 认指纹(名字、版本、成员、类型住在哪个宿主),不认模块实例。
|
|
62
|
-
- 注册表贡献(`Routes`、`Panels`)必须来自 `{ lifetime: "host" }` 的对象。
|
|
62
|
+
- 注册表贡献(`Routes`、`Panels`、`DataCodecs`、`ModelProviders`)必须来自 `{ lifetime: "host" }` 的对象。
|
|
63
|
+
- 需要统一导出/导入的数据放 `DataStore`,并注册 `DataCodecs`;需要给其他插件用模型时注册 `ModelProviders`。
|
|
63
64
|
- 服务端宿主名固定为 `"moonan"`;写别的名字,`api.serve` 会当场拒绝。
|
|
64
65
|
- 浏览器切面是**单个 ESM 文件**:浏览器没有模块 hook,重载只换入口。
|
|
65
66
|
|
|
67
|
+
## 统一数据与模型
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
import { DataCodecs, DataStore, ModelProviders } from "@moonan_ai/sdk";
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
- `DataStore` 是平台唯一的统一数据文件(local、host-lifetime);`read` 返回 `{ value, version }`,`update` 是串行读改写,`exportAll`/`importAll` 由平台 HTTP 表面调用。
|
|
74
|
+
- `DataCodecs` 是插件贡献的导出/导入 codec 注册表;没有 codec 的 namespace 不会进入统一导出。
|
|
75
|
+
- `ModelProviders` 是服务端模型提供商注册表;`list()` 是 key-free 目录,`runtime()` 是 server-only 运行时,不能给浏览器。
|
|
76
|
+
|
|
66
77
|
完整写法:<https://github.com/Pheobe-Southwood/Moonan/blob/main/docs/plugins.md> ·
|
|
67
78
|
词汇表:<https://github.com/Pheobe-Southwood/Moonan/blob/main/CONTEXT.md>
|
|
68
79
|
|
package/dist/data.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { defineRegistry, local, method } from "@earendil-works/chord";
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
/**
|
|
4
|
+
* One value in the platform's unified data store.
|
|
5
|
+
*
|
|
6
|
+
* `version` belongs to the dataset, not to the file and not to the contract. A plugin
|
|
7
|
+
* raises it when the stored shape or meaning changes and supplies a migration through its
|
|
8
|
+
* {@link DatasetCodec}; the platform never interprets the value.
|
|
9
|
+
*/
|
|
10
|
+
export const StoredDatasetSchema = Type.Object({
|
|
11
|
+
value: Type.Any(),
|
|
12
|
+
version: Type.Number(),
|
|
13
|
+
}, { additionalProperties: false });
|
|
14
|
+
/** Identity helper; keeps the codec's type while documenting intent. */
|
|
15
|
+
export function defineDataset(codec) {
|
|
16
|
+
return codec;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The registry of dataset codecs.
|
|
20
|
+
*
|
|
21
|
+
* A contribution must come from an object of `lifetime: "host"`, like every other Chord
|
|
22
|
+
* registry. The platform reads the table for the code version of the root that asks.
|
|
23
|
+
*/
|
|
24
|
+
export const DataCodecs = defineRegistry("moonan.data-codecs", {
|
|
25
|
+
conflict: "error",
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* What the data store reports about its file. This is a state member, so a plugin can read
|
|
29
|
+
* it synchronously once the store is live; the platform also exposes it over HTTP.
|
|
30
|
+
*/
|
|
31
|
+
export const DataStoreStorageInfoSchema = Type.Object({
|
|
32
|
+
file: Type.String(),
|
|
33
|
+
backup: Type.String(),
|
|
34
|
+
exists: Type.Boolean(),
|
|
35
|
+
mode: Type.Optional(Type.String()),
|
|
36
|
+
writable: Type.Boolean(),
|
|
37
|
+
revision: Type.Number(),
|
|
38
|
+
datasets: Type.Number(),
|
|
39
|
+
lastSavedAt: Type.Optional(Type.String()),
|
|
40
|
+
notice: Type.Optional(Type.String()),
|
|
41
|
+
}, { additionalProperties: false });
|
|
42
|
+
/**
|
|
43
|
+
* The wire/JSON envelope for a complete export. The file itself has a different, richer
|
|
44
|
+
* shape (it also keeps per-dataset timestamps); this is the portable subset.
|
|
45
|
+
*/
|
|
46
|
+
export const DataBundleSchema = Type.Object({
|
|
47
|
+
format: Type.Literal("moonan.data"),
|
|
48
|
+
formatVersion: Type.Literal(1),
|
|
49
|
+
createdAt: Type.String(),
|
|
50
|
+
revision: Type.Number(),
|
|
51
|
+
datasets: Type.Array(Type.Object({
|
|
52
|
+
namespace: Type.String(),
|
|
53
|
+
version: Type.Number(),
|
|
54
|
+
value: Type.Any(),
|
|
55
|
+
}, { additionalProperties: false })),
|
|
56
|
+
skipped: Type.Optional(Type.Array(Type.String())),
|
|
57
|
+
}, { additionalProperties: false });
|
|
58
|
+
export const DataImportReportSchema = Type.Object({
|
|
59
|
+
imported: Type.Array(Type.String()),
|
|
60
|
+
revision: Type.Number(),
|
|
61
|
+
skipped: Type.Optional(Type.Array(Type.String())),
|
|
62
|
+
}, { additionalProperties: false });
|
|
63
|
+
/**
|
|
64
|
+
* The platform's unified data service.
|
|
65
|
+
*
|
|
66
|
+
* It is local and host-lifetime: exactly one object exists for the server host, it owns
|
|
67
|
+
* the only data file, and every plugin reads/writes through it. It is not a remote type;
|
|
68
|
+
* browsers get data through plugin methods or the platform's export/import HTTP surface.
|
|
69
|
+
*
|
|
70
|
+
* `read` returns the raw `{ value, version }` and deliberately does not consult a codec:
|
|
71
|
+
* a plugin's `config` cell may initialize before its codec registration is published, so
|
|
72
|
+
* the plugin validates/migrates its own first value. `write` replaces a whole dataset;
|
|
73
|
+
* `update` is the read-modify-write form that runs inside the store's serial queue.
|
|
74
|
+
*/
|
|
75
|
+
export const DataStore = local("moonan.data", {
|
|
76
|
+
version: 1,
|
|
77
|
+
input: Type.Object({}),
|
|
78
|
+
members: {
|
|
79
|
+
revision: Type.Number(),
|
|
80
|
+
storage: DataStoreStorageInfoSchema,
|
|
81
|
+
read: method(Type.Object({ namespace: Type.String() }), Type.Any()),
|
|
82
|
+
write: method(Type.Object({ namespace: Type.String(), version: Type.Number(), value: Type.Any() }), StoredDatasetSchema),
|
|
83
|
+
update: method(Type.Object({ namespace: Type.String(), version: Type.Number(), update: Type.Any() }), StoredDatasetSchema),
|
|
84
|
+
remove: method(Type.Object({ namespace: Type.String() })),
|
|
85
|
+
reload: method(undefined, DataStoreStorageInfoSchema),
|
|
86
|
+
exportAll: method(Type.Object({ includeSecrets: Type.Optional(Type.Boolean()) }), DataBundleSchema),
|
|
87
|
+
importAll: method(Type.Object({ bundle: DataBundleSchema }), DataImportReportSchema),
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
//# sourceMappingURL=data.js.map
|
package/dist/data.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.js","sourceRoot":"","sources":["../src/data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAkB,MAAM,uBAAuB,CAAC;AACtF,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAC7C;IACC,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE;IACjB,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE;CACtB,EACD,EAAE,oBAAoB,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nB;QACD,MAAM,EAAE,MAAM,CACb,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,EACrF,mBAAmB,CACnB;QACD,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACzD,MAAM,EAAE,MAAM,CAAC,SAAS,EAAE,0BAA0B,CAAC;QACrD,SAAS,EAAE,MAAM,CAChB,IAAI,CAAC,MAAM,CAAC,EAAE,cAAc,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,EAC9D,gBAAgB,CAChB;QACD,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC,EAAE,sBAAsB,CAAC;KACpF;CACD,CAAC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
* `@moonan_ai/sdk` — everything a plugin needs on either side of the wire.
|
|
3
3
|
*
|
|
4
4
|
* The root entry is shared by the server facet and the browser facet: contracts,
|
|
5
|
-
* registries and the Chord primitives they
|
|
6
|
-
* `Panels` registry and the React hooks) lives
|
|
7
|
-
* React and the root entry must stay importable
|
|
5
|
+
* registries (including `DataCodecs` and `ModelProviders`) and the Chord primitives they
|
|
6
|
+
* are built from. Browser-only surface (the `Panels` registry and the React hooks) lives
|
|
7
|
+
* in `@moonan_ai/sdk/web`, because it needs React and the root entry must stay importable
|
|
8
|
+
* from a Node facet.
|
|
8
9
|
*/
|
|
9
|
-
export {
|
|
10
|
+
export { WebFacetCatalog, FacetSetSchema, WebFacetSchema, } from "./web-facet-catalog.js";
|
|
11
|
+
export { DataStore, DataCodecs, DataBundleSchema, DataImportReportSchema, DataStoreStorageInfoSchema, StoredDatasetSchema, defineDataset, } from "./data.js";
|
|
12
|
+
export { ModelProviders, } from "./model-provider.js";
|
|
10
13
|
export { Routes } from "./routes.js";
|
|
11
14
|
/** Chord primitives, re-exported so a plugin needs two dependencies instead of three. */
|
|
12
15
|
export { ChordError, defineFacet, defineRegistry, forbidden, hostFamily, hostNamed, invalid, isChordError, local, method, opaque, remote, } from "@earendil-works/chord";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACN,eAAe,EACf,cAAc,EACd,cAAc,GAGd,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,sBAAsB,EACtB,0BAA0B,EAC1B,mBAAmB,EACnB,aAAa,GAOb,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,cAAc,GAGd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAqB,MAAM,aAAa,CAAC;AAExD,yFAAyF;AACzF,OAAO,EACN,UAAU,EACV,WAAW,EACX,cAAc,EACd,SAAS,EACT,UAAU,EACV,SAAS,EACT,OAAO,EACP,YAAY,EACZ,KAAK,EACL,MAAM,EACN,MAAM,EACN,MAAM,GAiBN,MAAM,uBAAuB,CAAC;AAE/B,uFAAuF;AACvF,OAAO,EACN,kBAAkB,EAClB,gBAAgB,EAChB,OAAO,EACP,eAAe,EACf,UAAU,EACV,kBAAkB,GAElB,MAAM,+BAA+B,CAAC;AAEvC,yDAAyD;AACzD,OAAO,EAAE,IAAI,EAA6B,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-provider.js","sourceRoot":"","sources":["../src/model-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AA0CvD,MAAM,CAAC,MAAM,cAAc,GAAG,cAAc,CAAgB,wBAAwB,EAAE;IACrF,QAAQ,EAAE,OAAO;CACjB,CAAC,CAAC"}
|
|
@@ -30,20 +30,20 @@ export const FacetSetSchema = Type.Object({
|
|
|
30
30
|
error: Type.Optional(Type.String()),
|
|
31
31
|
});
|
|
32
32
|
/**
|
|
33
|
-
* The only object the platform publishes:
|
|
33
|
+
* The only object the platform publishes: the catalog of browser facets the browser host
|
|
34
|
+
* must load.
|
|
34
35
|
*
|
|
35
36
|
* This is the seam that keeps the platform free of feature state. The loader knows which
|
|
36
37
|
* modules exist; the browser cannot find that out alone (it has no filesystem and no
|
|
37
|
-
* registry to ask), so exactly one read-only object carries it across.
|
|
38
|
-
* server `Manifest` object as how browsers learn of changes (spec §6); the particular
|
|
39
|
-
* fields here are Moonan application state, not protocol fields.
|
|
38
|
+
* registry to ask), so exactly one read-only object carries it across.
|
|
40
39
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
40
|
+
* The name is deliberately about what it carries: a catalog of web facets. It is not a
|
|
41
|
+
* package manifest and it is not a general application manifest. This is a fresh contract
|
|
42
|
+
* (version 1) with no compatibility adapter: an old shell gets `upgrade_required` and
|
|
43
|
+
* reloads the page.
|
|
44
44
|
*/
|
|
45
|
-
export const
|
|
46
|
-
version:
|
|
45
|
+
export const WebFacetCatalog = remote("moonan.web-facets", {
|
|
46
|
+
version: 1,
|
|
47
47
|
input: Type.Object({}),
|
|
48
48
|
host: hostNamed("moonan"),
|
|
49
49
|
variants: {
|
|
@@ -63,4 +63,4 @@ export const Manifest = remote("moonan.manifest", {
|
|
|
63
63
|
},
|
|
64
64
|
},
|
|
65
65
|
});
|
|
66
|
-
//# sourceMappingURL=
|
|
66
|
+
//# sourceMappingURL=web-facet-catalog.js.map
|
|
@@ -0,0 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AAK,CAAC,cAAc,CAAC;gBAClC;;;;;mBAKG;gBACH,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE;aACvB;SACD;KACD;CACD,CAAC,CAAC"}
|
package/dist/web.js
CHANGED
|
@@ -3,9 +3,9 @@ import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
|
3
3
|
export { isChordError } from "@earendil-works/chord";
|
|
4
4
|
/**
|
|
5
5
|
* A `gone` error that no new reference can fix: the consumer was built against a contract the
|
|
6
|
-
* provider no longer covers. For the shell's own contracts (the platform `
|
|
6
|
+
* provider no longer covers. For the shell's own contracts (the platform `WebFacetCatalog`, or a
|
|
7
7
|
* protocol mismatch) the page needs the new build. For a plugin's contract, chord's remedy is
|
|
8
|
-
* to reload the web facets; the shell does that when the
|
|
8
|
+
* to reload the web facets; the shell does that when the WebFacetCatalog reports changed facets.
|
|
9
9
|
*/
|
|
10
10
|
export function isFatalContractError(error) {
|
|
11
11
|
return isChordError(error, "contract_mismatch") || isChordError(error, "upgrade_required");
|
|
@@ -99,7 +99,7 @@ export function useRemote(host, contract, input, options = {}) {
|
|
|
99
99
|
return;
|
|
100
100
|
// A contract that the provider no longer covers cannot be fixed by taking another
|
|
101
101
|
// reference. The shell owns the official remedy (reload the web facets when the
|
|
102
|
-
//
|
|
102
|
+
// WebFacetCatalog reports changed facets); a panel only reports it upward, and without an
|
|
103
103
|
// `onFatal` handler it says once what the developer can do.
|
|
104
104
|
if (isFatalContractError(error)) {
|
|
105
105
|
const handler = onFatal.current;
|
|
@@ -112,7 +112,7 @@ export function useRemote(host, contract, input, options = {}) {
|
|
|
112
112
|
}
|
|
113
113
|
if (!warned.current) {
|
|
114
114
|
warned.current = true;
|
|
115
|
-
console.warn("[chord] a reference is gone because its contract no longer binds. The shell reloads web facets when the
|
|
115
|
+
console.warn("[chord] a reference is gone because its contract no longer binds. The shell reloads web facets when the WebFacetCatalog reports changed facets; if this persists, the plugin's web code and contract are out of sync.", error);
|
|
116
116
|
}
|
|
117
117
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AAC,CAAC,CAAC;IAExE,eAAe,CAAC,GAAG,EAAE;QACpB,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,QAAQ,CAAC,QAAQ,CAAC,CAAC;YACnB,OAAO;QACR,CAAC;QACD,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;QACrC,MAAM,IAAI,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,IAAO,EAAE,EAAE;YAC3C,IAAI,CAAC,SAAS;gBAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,EAAE;YACX,SAAS,GAAG,IAAI,CAAC;YACjB,IAAI,EAAE,CAAC;QACR,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,OAAO,KAAK,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
package/src/data.ts
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { defineRegistry, local, method, type JsonValue } from "@earendil-works/chord";
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* One value in the platform's unified data store.
|
|
6
|
+
*
|
|
7
|
+
* `version` belongs to the dataset, not to the file and not to the contract. A plugin
|
|
8
|
+
* raises it when the stored shape or meaning changes and supplies a migration through its
|
|
9
|
+
* {@link DatasetCodec}; the platform never interprets the value.
|
|
10
|
+
*/
|
|
11
|
+
export const StoredDatasetSchema = Type.Object(
|
|
12
|
+
{
|
|
13
|
+
value: Type.Any(),
|
|
14
|
+
version: Type.Number(),
|
|
15
|
+
},
|
|
16
|
+
{ additionalProperties: false },
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export type StoredDataset = {
|
|
20
|
+
value: JsonValue;
|
|
21
|
+
version: number;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* What every plugin must contribute to make its dataset exportable and importable.
|
|
26
|
+
*
|
|
27
|
+
* The codec is a registry value, not a Chord contract: it lives in the server host, can
|
|
28
|
+
* carry functions, and never crosses a link. The platform calls it when an administrator
|
|
29
|
+
* exports or imports the unified data file.
|
|
30
|
+
*/
|
|
31
|
+
export interface DatasetCodec<T = unknown> {
|
|
32
|
+
/** Stable dataset key, conventionally `"<package>/<dataset>"`. */
|
|
33
|
+
readonly namespace: string;
|
|
34
|
+
/** Current stored shape version; see {@link StoredDataset.version}. */
|
|
35
|
+
readonly version: number;
|
|
36
|
+
/** Convert an older stored value to the current stored value. */
|
|
37
|
+
migrate(value: JsonValue, fromVersion: number): T;
|
|
38
|
+
/** Convert the current stored value to a portable export value (redact secrets here). */
|
|
39
|
+
export(value: T, options: DatasetExportOptions): JsonValue;
|
|
40
|
+
/**
|
|
41
|
+
* Convert an imported export value to the current stored value.
|
|
42
|
+
*
|
|
43
|
+
* `current` is the value already stored at this namespace, if any. A codec may use it
|
|
44
|
+
* to preserve secrets that a redacted export deliberately omitted.
|
|
45
|
+
*/
|
|
46
|
+
import(value: JsonValue, fromVersion: number, current: JsonValue | undefined): T;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface DatasetExportOptions {
|
|
50
|
+
/** False by default on the HTTP surface; a codec must redact secrets when false. */
|
|
51
|
+
readonly includeSecrets: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Identity helper; keeps the codec's type while documenting intent. */
|
|
55
|
+
export function defineDataset<T>(codec: DatasetCodec<T>): DatasetCodec<T> {
|
|
56
|
+
return codec;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The registry of dataset codecs.
|
|
61
|
+
*
|
|
62
|
+
* A contribution must come from an object of `lifetime: "host"`, like every other Chord
|
|
63
|
+
* registry. The platform reads the table for the code version of the root that asks.
|
|
64
|
+
*/
|
|
65
|
+
export const DataCodecs = defineRegistry<DatasetCodec>("moonan.data-codecs", {
|
|
66
|
+
conflict: "error",
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* What the data store reports about its file. This is a state member, so a plugin can read
|
|
71
|
+
* it synchronously once the store is live; the platform also exposes it over HTTP.
|
|
72
|
+
*/
|
|
73
|
+
export const DataStoreStorageInfoSchema = Type.Object(
|
|
74
|
+
{
|
|
75
|
+
file: Type.String(),
|
|
76
|
+
backup: Type.String(),
|
|
77
|
+
exists: Type.Boolean(),
|
|
78
|
+
mode: Type.Optional(Type.String()),
|
|
79
|
+
writable: Type.Boolean(),
|
|
80
|
+
revision: Type.Number(),
|
|
81
|
+
datasets: Type.Number(),
|
|
82
|
+
lastSavedAt: Type.Optional(Type.String()),
|
|
83
|
+
notice: Type.Optional(Type.String()),
|
|
84
|
+
},
|
|
85
|
+
{ additionalProperties: false },
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
export type DataStoreStorageInfo = {
|
|
89
|
+
file: string;
|
|
90
|
+
backup: string;
|
|
91
|
+
exists: boolean;
|
|
92
|
+
mode?: string;
|
|
93
|
+
writable: boolean;
|
|
94
|
+
revision: number;
|
|
95
|
+
datasets: number;
|
|
96
|
+
lastSavedAt?: string;
|
|
97
|
+
notice?: string;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The wire/JSON envelope for a complete export. The file itself has a different, richer
|
|
102
|
+
* shape (it also keeps per-dataset timestamps); this is the portable subset.
|
|
103
|
+
*/
|
|
104
|
+
export const DataBundleSchema = Type.Object(
|
|
105
|
+
{
|
|
106
|
+
format: Type.Literal("moonan.data"),
|
|
107
|
+
formatVersion: Type.Literal(1),
|
|
108
|
+
createdAt: Type.String(),
|
|
109
|
+
revision: Type.Number(),
|
|
110
|
+
datasets: Type.Array(
|
|
111
|
+
Type.Object(
|
|
112
|
+
{
|
|
113
|
+
namespace: Type.String(),
|
|
114
|
+
version: Type.Number(),
|
|
115
|
+
value: Type.Any(),
|
|
116
|
+
},
|
|
117
|
+
{ additionalProperties: false },
|
|
118
|
+
),
|
|
119
|
+
),
|
|
120
|
+
skipped: Type.Optional(Type.Array(Type.String())),
|
|
121
|
+
},
|
|
122
|
+
{ additionalProperties: false },
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
export type DataBundle = {
|
|
126
|
+
format: "moonan.data";
|
|
127
|
+
formatVersion: 1;
|
|
128
|
+
createdAt: string;
|
|
129
|
+
revision: number;
|
|
130
|
+
datasets: { namespace: string; version: number; value: JsonValue }[];
|
|
131
|
+
skipped?: string[];
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export const DataImportReportSchema = Type.Object(
|
|
135
|
+
{
|
|
136
|
+
imported: Type.Array(Type.String()),
|
|
137
|
+
revision: Type.Number(),
|
|
138
|
+
skipped: Type.Optional(Type.Array(Type.String())),
|
|
139
|
+
},
|
|
140
|
+
{ additionalProperties: false },
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
export type DataImportReport = {
|
|
144
|
+
imported: string[];
|
|
145
|
+
revision: number;
|
|
146
|
+
skipped?: string[];
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The platform's unified data service.
|
|
151
|
+
*
|
|
152
|
+
* It is local and host-lifetime: exactly one object exists for the server host, it owns
|
|
153
|
+
* the only data file, and every plugin reads/writes through it. It is not a remote type;
|
|
154
|
+
* browsers get data through plugin methods or the platform's export/import HTTP surface.
|
|
155
|
+
*
|
|
156
|
+
* `read` returns the raw `{ value, version }` and deliberately does not consult a codec:
|
|
157
|
+
* a plugin's `config` cell may initialize before its codec registration is published, so
|
|
158
|
+
* the plugin validates/migrates its own first value. `write` replaces a whole dataset;
|
|
159
|
+
* `update` is the read-modify-write form that runs inside the store's serial queue.
|
|
160
|
+
*/
|
|
161
|
+
export const DataStore = local("moonan.data", {
|
|
162
|
+
version: 1,
|
|
163
|
+
input: Type.Object({}),
|
|
164
|
+
members: {
|
|
165
|
+
revision: Type.Number(),
|
|
166
|
+
storage: DataStoreStorageInfoSchema,
|
|
167
|
+
read: method(Type.Object({ namespace: Type.String() }), Type.Any()),
|
|
168
|
+
write: method(
|
|
169
|
+
Type.Object({ namespace: Type.String(), version: Type.Number(), value: Type.Any() }),
|
|
170
|
+
StoredDatasetSchema,
|
|
171
|
+
),
|
|
172
|
+
update: method(
|
|
173
|
+
Type.Object({ namespace: Type.String(), version: Type.Number(), update: Type.Any() }),
|
|
174
|
+
StoredDatasetSchema,
|
|
175
|
+
),
|
|
176
|
+
remove: method(Type.Object({ namespace: Type.String() })),
|
|
177
|
+
reload: method(undefined, DataStoreStorageInfoSchema),
|
|
178
|
+
exportAll: method(
|
|
179
|
+
Type.Object({ includeSecrets: Type.Optional(Type.Boolean()) }),
|
|
180
|
+
DataBundleSchema,
|
|
181
|
+
),
|
|
182
|
+
importAll: method(Type.Object({ bundle: DataBundleSchema }), DataImportReportSchema),
|
|
183
|
+
},
|
|
184
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -2,17 +2,38 @@
|
|
|
2
2
|
* `@moonan_ai/sdk` — everything a plugin needs on either side of the wire.
|
|
3
3
|
*
|
|
4
4
|
* The root entry is shared by the server facet and the browser facet: contracts,
|
|
5
|
-
* registries and the Chord primitives they
|
|
6
|
-
* `Panels` registry and the React hooks) lives
|
|
7
|
-
* React and the root entry must stay importable
|
|
5
|
+
* registries (including `DataCodecs` and `ModelProviders`) and the Chord primitives they
|
|
6
|
+
* are built from. Browser-only surface (the `Panels` registry and the React hooks) lives
|
|
7
|
+
* in `@moonan_ai/sdk/web`, because it needs React and the root entry must stay importable
|
|
8
|
+
* from a Node facet.
|
|
8
9
|
*/
|
|
9
10
|
export {
|
|
10
|
-
|
|
11
|
+
WebFacetCatalog,
|
|
11
12
|
FacetSetSchema,
|
|
12
13
|
WebFacetSchema,
|
|
13
14
|
type FacetSetEntry,
|
|
14
15
|
type WebFacet,
|
|
15
|
-
} from "./
|
|
16
|
+
} from "./web-facet-catalog.js";
|
|
17
|
+
export {
|
|
18
|
+
DataStore,
|
|
19
|
+
DataCodecs,
|
|
20
|
+
DataBundleSchema,
|
|
21
|
+
DataImportReportSchema,
|
|
22
|
+
DataStoreStorageInfoSchema,
|
|
23
|
+
StoredDatasetSchema,
|
|
24
|
+
defineDataset,
|
|
25
|
+
type DataBundle,
|
|
26
|
+
type DataImportReport,
|
|
27
|
+
type DataStoreStorageInfo,
|
|
28
|
+
type DatasetCodec,
|
|
29
|
+
type DatasetExportOptions,
|
|
30
|
+
type StoredDataset,
|
|
31
|
+
} from "./data.js";
|
|
32
|
+
export {
|
|
33
|
+
ModelProviders,
|
|
34
|
+
type ModelInfo,
|
|
35
|
+
type ModelProvider,
|
|
36
|
+
} from "./model-provider.js";
|
|
16
37
|
export { Routes, type RouteHandler } from "./routes.js";
|
|
17
38
|
|
|
18
39
|
/** Chord primitives, re-exported so a plugin needs two dependencies instead of three. */
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { defineRegistry } from "@earendil-works/chord";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Provider-neutral metadata for one configured chat model.
|
|
5
|
+
*
|
|
6
|
+
* This is plain JSON: the registry value never crosses a link, but keeping the catalog
|
|
7
|
+
* serializable lets a plugin expose it over HTTP or in a panel without a second shape.
|
|
8
|
+
*/
|
|
9
|
+
export interface ModelInfo {
|
|
10
|
+
readonly providerId: string;
|
|
11
|
+
readonly modelId: string;
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly contextWindow?: number;
|
|
14
|
+
readonly maxTokens?: number;
|
|
15
|
+
readonly input: readonly ("text" | "image")[];
|
|
16
|
+
readonly reasoning: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A model provider contribution.
|
|
21
|
+
*
|
|
22
|
+
* `list()` is the key-free catalog. `runtime()` is a server-only handle whose concrete
|
|
23
|
+
* shape belongs to the provider package; ai-gateway returns its pi-ai `MutableModels`
|
|
24
|
+
* there. The SDK stays free of pi-ai so a generic plugin does not inherit an AI dependency.
|
|
25
|
+
*
|
|
26
|
+
* A consumer looks the provider up with the code version of its root:
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* const providers = api.registry(ModelProviders);
|
|
30
|
+
* const provider = providers.get("ai-gateway", ctx);
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* The registry value is not a Chord contract: there is no `uses` entry and no wire
|
|
34
|
+
* compatibility rule. Its table is replaced with each code version like every registry.
|
|
35
|
+
*/
|
|
36
|
+
export interface ModelProvider {
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly title: string;
|
|
39
|
+
list(): readonly ModelInfo[];
|
|
40
|
+
runtime(): unknown;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const ModelProviders = defineRegistry<ModelProvider>("moonan.model-providers", {
|
|
44
|
+
conflict: "error",
|
|
45
|
+
});
|
|
@@ -35,20 +35,20 @@ export const FacetSetSchema = Type.Object({
|
|
|
35
35
|
export type FacetSetEntry = Static<typeof FacetSetSchema>;
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
* The only object the platform publishes:
|
|
38
|
+
* The only object the platform publishes: the catalog of browser facets the browser host
|
|
39
|
+
* must load.
|
|
39
40
|
*
|
|
40
41
|
* This is the seam that keeps the platform free of feature state. The loader knows which
|
|
41
42
|
* modules exist; the browser cannot find that out alone (it has no filesystem and no
|
|
42
|
-
* registry to ask), so exactly one read-only object carries it across.
|
|
43
|
-
* server `Manifest` object as how browsers learn of changes (spec §6); the particular
|
|
44
|
-
* fields here are Moonan application state, not protocol fields.
|
|
43
|
+
* registry to ask), so exactly one read-only object carries it across.
|
|
45
44
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
45
|
+
* The name is deliberately about what it carries: a catalog of web facets. It is not a
|
|
46
|
+
* package manifest and it is not a general application manifest. This is a fresh contract
|
|
47
|
+
* (version 1) with no compatibility adapter: an old shell gets `upgrade_required` and
|
|
48
|
+
* reloads the page.
|
|
49
49
|
*/
|
|
50
|
-
export const
|
|
51
|
-
version:
|
|
50
|
+
export const WebFacetCatalog = remote("moonan.web-facets", {
|
|
51
|
+
version: 1,
|
|
52
52
|
input: Type.Object({}),
|
|
53
53
|
host: hostNamed("moonan"),
|
|
54
54
|
variants: {
|
package/src/web.ts
CHANGED
|
@@ -15,9 +15,9 @@ export { isChordError } from "@earendil-works/chord";
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* A `gone` error that no new reference can fix: the consumer was built against a contract the
|
|
18
|
-
* provider no longer covers. For the shell's own contracts (the platform `
|
|
18
|
+
* provider no longer covers. For the shell's own contracts (the platform `WebFacetCatalog`, or a
|
|
19
19
|
* protocol mismatch) the page needs the new build. For a plugin's contract, chord's remedy is
|
|
20
|
-
* to reload the web facets; the shell does that when the
|
|
20
|
+
* to reload the web facets; the shell does that when the WebFacetCatalog reports changed facets.
|
|
21
21
|
*/
|
|
22
22
|
export function isFatalContractError(error: unknown): boolean {
|
|
23
23
|
return isChordError(error, "contract_mismatch") || isChordError(error, "upgrade_required");
|
|
@@ -146,7 +146,7 @@ export function useRemote<C extends AnyContract>(
|
|
|
146
146
|
|
|
147
147
|
// A contract that the provider no longer covers cannot be fixed by taking another
|
|
148
148
|
// reference. The shell owns the official remedy (reload the web facets when the
|
|
149
|
-
//
|
|
149
|
+
// WebFacetCatalog reports changed facets); a panel only reports it upward, and without an
|
|
150
150
|
// `onFatal` handler it says once what the developer can do.
|
|
151
151
|
if (isFatalContractError(error)) {
|
|
152
152
|
const handler = onFatal.current;
|
|
@@ -160,7 +160,7 @@ export function useRemote<C extends AnyContract>(
|
|
|
160
160
|
if (!warned.current) {
|
|
161
161
|
warned.current = true;
|
|
162
162
|
console.warn(
|
|
163
|
-
"[chord] a reference is gone because its contract no longer binds. The shell reloads web facets when the
|
|
163
|
+
"[chord] a reference is gone because its contract no longer binds. The shell reloads web facets when the WebFacetCatalog reports changed facets; if this persists, the plugin's web code and contract are out of sync.",
|
|
164
164
|
error,
|
|
165
165
|
);
|
|
166
166
|
}
|
package/dist/manifest.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAe,MAAM,SAAS,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC;IACzC,6DAA6D;IAC7D,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE;IAClB,2DAA2D;IAC3D,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;CACnB,CAAC,CAAC;AAGH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC;IACzC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;IACnB,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE;IACtB,gFAAgF;IAChF,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IACxE,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC;IAClC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;CACnC,CAAC,CAAC;AAGH;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,iBAAiB,EAAE;IACjD,OAAO,EAAE,CAAC;IACV,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;IACtB,IAAI,EAAE,SAAS,CAAC,QAAQ,CAAC;IACzB,QAAQ,EAAE;QACT,EAAE,EAAE;YACH,KAAK,EAAE;gBACN,qFAAqF;g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