@manifesto-ai/sdk 0.1.0
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/LICENSE +21 -0
- package/README.md +182 -0
- package/dist/__tests__/bootstrap.test.d.ts +2 -0
- package/dist/__tests__/bootstrap.test.d.ts.map +1 -0
- package/dist/__tests__/bootstrap.test.js +34 -0
- package/dist/__tests__/bootstrap.test.js.map +1 -0
- package/dist/app.d.ts +51 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +170 -0
- package/dist/app.js.map +1 -0
- package/dist/create-app.d.ts +52 -0
- package/dist/create-app.d.ts.map +1 -0
- package/dist/create-app.js +94 -0
- package/dist/create-app.js.map +1 -0
- package/dist/hooks/app-ref.d.ts +71 -0
- package/dist/hooks/app-ref.d.ts.map +1 -0
- package/dist/hooks/app-ref.js +82 -0
- package/dist/hooks/app-ref.js.map +1 -0
- package/dist/hooks/context.d.ts +22 -0
- package/dist/hooks/context.d.ts.map +1 -0
- package/dist/hooks/context.js +26 -0
- package/dist/hooks/context.js.map +1 -0
- package/dist/hooks/hookable.d.ts +79 -0
- package/dist/hooks/hookable.d.ts.map +1 -0
- package/dist/hooks/hookable.js +137 -0
- package/dist/hooks/hookable.js.map +1 -0
- package/dist/hooks/index.d.ts +14 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +13 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/queue.d.ts +57 -0
- package/dist/hooks/queue.d.ts.map +1 -0
- package/dist/hooks/queue.js +141 -0
- package/dist/hooks/queue.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.d.ts +10 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +2 -0
- package/dist/manifest.js.map +1 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Manifesto AI
|
|
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,182 @@
|
|
|
1
|
+
# @manifesto-ai/sdk
|
|
2
|
+
|
|
3
|
+
> **SDK** is the public developer API layer for Manifesto applications. It presents ergonomic factory functions, lifecycle management, and hook systems while delegating all execution to the Runtime.
|
|
4
|
+
|
|
5
|
+
> **Phase 1 Notice:** During the current phase, most users should install `@manifesto-ai/app`, which re-exports all SDK APIs. See [ADR-007](../../docs/internals/adr/007-sdk-runtime-split-kickoff.md) for details.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## What is SDK?
|
|
10
|
+
|
|
11
|
+
SDK owns the public contract shape that developers interact with. It provides `createApp()`, the `App` interface, and the hook system — but delegates all orchestration to `@manifesto-ai/runtime`.
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
Application Code
|
|
15
|
+
|
|
|
16
|
+
v
|
|
17
|
+
SDK (createApp, App, Hooks) <-- you are here
|
|
18
|
+
|
|
|
19
|
+
v
|
|
20
|
+
Runtime (orchestration, execution)
|
|
21
|
+
|
|
|
22
|
+
v
|
|
23
|
+
Core / Host / World
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## What SDK Does
|
|
29
|
+
|
|
30
|
+
| Responsibility | Description |
|
|
31
|
+
|----------------|-------------|
|
|
32
|
+
| App factory | `createApp(config)` — single entry point for creating apps |
|
|
33
|
+
| App interface | `ManifestoApp` — thin facade over Runtime |
|
|
34
|
+
| Lifecycle | `ready()` / `dispose()` with status tracking |
|
|
35
|
+
| Hook system | Observable lifecycle with re-entrancy guards |
|
|
36
|
+
| AppRef | Read-only facade for safe hook access |
|
|
37
|
+
| Job queue | Deferred execution for hook-triggered actions |
|
|
38
|
+
| Test helper | `createTestApp()` — minimal app for testing |
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## What SDK Does NOT Do
|
|
43
|
+
|
|
44
|
+
| NOT Responsible For | Who Is |
|
|
45
|
+
|--------------------|--------|
|
|
46
|
+
| Execution orchestration | Runtime |
|
|
47
|
+
| Effect execution | Host (via Runtime) |
|
|
48
|
+
| Pure state computation | Core (via Runtime) |
|
|
49
|
+
| Governance and lineage | World (via Runtime) |
|
|
50
|
+
| Type/error definitions | Runtime |
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
During **Phase 1**, use `@manifesto-ai/app` as the canonical entry point:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pnpm add @manifesto-ai/app
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
For direct SDK access (preview):
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pnpm add @manifesto-ai/sdk
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Quick Example
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { createApp } from "@manifesto-ai/sdk";
|
|
74
|
+
|
|
75
|
+
const app = createApp({
|
|
76
|
+
schema: counterSchema,
|
|
77
|
+
effects: {
|
|
78
|
+
"api.save": async (params, ctx) => [
|
|
79
|
+
{ op: "set", path: "data.savedAt", value: params.timestamp },
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
await app.ready();
|
|
85
|
+
|
|
86
|
+
const handle = app.act("increment");
|
|
87
|
+
await handle.completed();
|
|
88
|
+
|
|
89
|
+
console.log(app.getState().data.count); // 1
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Core API
|
|
95
|
+
|
|
96
|
+
### Factory Functions
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
function createApp(config: AppConfig): App;
|
|
100
|
+
function createTestApp(domain: DomainSchema | string, opts?: Partial<AppConfig>): App;
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### App Interface
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
interface App {
|
|
107
|
+
// Lifecycle
|
|
108
|
+
ready(): Promise<void>;
|
|
109
|
+
dispose(opts?): Promise<void>;
|
|
110
|
+
readonly status: AppStatus;
|
|
111
|
+
readonly hooks: Hookable<AppHooks>;
|
|
112
|
+
|
|
113
|
+
// Schema
|
|
114
|
+
getDomainSchema(): DomainSchema;
|
|
115
|
+
|
|
116
|
+
// Actions
|
|
117
|
+
act(type: string, input?: unknown, opts?): ActionHandle;
|
|
118
|
+
submitProposal(proposal): Promise<ProposalResult>;
|
|
119
|
+
|
|
120
|
+
// State
|
|
121
|
+
getState<T>(): AppState<T>;
|
|
122
|
+
subscribe(selector, listener, opts?): () => void;
|
|
123
|
+
getSnapshot(): Snapshot;
|
|
124
|
+
|
|
125
|
+
// Session
|
|
126
|
+
session(actorId: string, opts?): Session;
|
|
127
|
+
|
|
128
|
+
// Branch
|
|
129
|
+
currentBranch(): Branch;
|
|
130
|
+
listBranches(): Branch[];
|
|
131
|
+
switchBranch(branchId): Promise<void>;
|
|
132
|
+
fork(opts?): Promise<Branch>;
|
|
133
|
+
|
|
134
|
+
// World Query
|
|
135
|
+
getCurrentHead(): WorldId;
|
|
136
|
+
getWorld(worldId?): World;
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
> See [sdk-SPEC-v0.1.0.md](docs/sdk-SPEC-v0.1.0.md) for the complete specification.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Relationship with Other Packages
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
App (facade) -> SDK -> Runtime -> Core / Host / World
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
| Relationship | Package | How |
|
|
151
|
+
|--------------|---------|-----|
|
|
152
|
+
| Re-exported by | `@manifesto-ai/app` | App re-exports createApp, createTestApp, hooks |
|
|
153
|
+
| Delegates to | `@manifesto-ai/runtime` | All orchestration via AppRuntime |
|
|
154
|
+
| Depends on | `@manifesto-ai/core` | Schema types |
|
|
155
|
+
| Depends on | `@manifesto-ai/world` | World types |
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## When to Use SDK Directly
|
|
160
|
+
|
|
161
|
+
**Most users should use `@manifesto-ai/app` during Phase 1.**
|
|
162
|
+
|
|
163
|
+
Use SDK directly when:
|
|
164
|
+
- Building custom integrations that need only the public API surface
|
|
165
|
+
- Creating framework-specific wrappers (React, Vue, etc.)
|
|
166
|
+
- After Phase 2 transition when SDK becomes the primary entry point
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Documentation
|
|
171
|
+
|
|
172
|
+
| Document | Purpose |
|
|
173
|
+
|----------|---------|
|
|
174
|
+
| [sdk-SPEC-v0.1.0.md](docs/sdk-SPEC-v0.1.0.md) | Complete specification |
|
|
175
|
+
| [VERSION-INDEX.md](docs/VERSION-INDEX.md) | Version history and reading guide |
|
|
176
|
+
| [ADR-007](../../docs/internals/adr/007-sdk-runtime-split-kickoff.md) | Split rationale |
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## License
|
|
181
|
+
|
|
182
|
+
[MIT](../../LICENSE)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/bootstrap.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
describe('@manifesto-ai/sdk bootstrap', () => {
|
|
3
|
+
it('SdkManifest type is importable and structurally correct', () => {
|
|
4
|
+
// Type-level verification: the manifest type constrains to expected shape
|
|
5
|
+
const manifest = {
|
|
6
|
+
name: '@manifesto-ai/sdk',
|
|
7
|
+
specVersion: '0.1.0',
|
|
8
|
+
phase: 'bootstrap',
|
|
9
|
+
};
|
|
10
|
+
expect(manifest.name).toBe('@manifesto-ai/sdk');
|
|
11
|
+
expect(manifest.specVersion).toBe('0.1.0');
|
|
12
|
+
expect(manifest.phase).toBe('bootstrap');
|
|
13
|
+
});
|
|
14
|
+
it('package entry point resolves without error', async () => {
|
|
15
|
+
const mod = await import('../index.js');
|
|
16
|
+
expect(mod).toBeDefined();
|
|
17
|
+
});
|
|
18
|
+
it('exports SDK components', async () => {
|
|
19
|
+
const mod = await import('../index.js');
|
|
20
|
+
// App Factory
|
|
21
|
+
expect(mod.createApp).toBeDefined();
|
|
22
|
+
expect(mod.createTestApp).toBeDefined();
|
|
23
|
+
// ManifestoApp
|
|
24
|
+
expect(mod.ManifestoApp).toBeDefined();
|
|
25
|
+
// Hooks
|
|
26
|
+
expect(mod.AppRefImpl).toBeDefined();
|
|
27
|
+
expect(mod.createAppRef).toBeDefined();
|
|
28
|
+
expect(mod.HookableImpl).toBeDefined();
|
|
29
|
+
expect(mod.JobQueue).toBeDefined();
|
|
30
|
+
expect(mod.HookContextImpl).toBeDefined();
|
|
31
|
+
expect(mod.createHookContext).toBeDefined();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=bootstrap.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.test.js","sourceRoot":"","sources":["../../src/__tests__/bootstrap.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAG9C,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,EAAE,CAAC,yDAAyD,EAAE,GAAG,EAAE;QACjE,0EAA0E;QAC1E,MAAM,QAAQ,GAAgB;YAC5B,IAAI,EAAE,mBAAmB;YACzB,WAAW,EAAE,OAAO;YACpB,KAAK,EAAE,WAAW;SACnB,CAAC;QAEF,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAChD,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC3C,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4CAA4C,EAAE,KAAK,IAAI,EAAE;QAC1D,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;QACxC,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wBAAwB,EAAE,KAAK,IAAI,EAAE;QACtC,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;QAExC,cAAc;QACd,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;QACpC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,WAAW,EAAE,CAAC;QAExC,eAAe;QACf,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,WAAW,EAAE,CAAC;QAEvC,QAAQ;QACR,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC;QACrC,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,WAAW,EAAE,CAAC;QACvC,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,WAAW,EAAE,CAAC;QACvC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;QACnC,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,WAAW,EAAE,CAAC;QAC1C,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,WAAW,EAAE,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/app.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manifesto App Implementation (Thin Facade)
|
|
3
|
+
*
|
|
4
|
+
* Delegates all operations to AppBootstrap (assembly) and AppRuntime (operations).
|
|
5
|
+
*
|
|
6
|
+
* @see ADR-004 Phase 4 — FACADE-1~5
|
|
7
|
+
* @see SPEC §5-6
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import type { DomainSchema, Snapshot } from "@manifesto-ai/core";
|
|
11
|
+
import type { App, ActionHandle, ActOptions, AppConfig, AppHooks, AppState, AppStatus, Branch, DisposeOptions, ForkOptions, Hookable, MemoryFacade, MigrationLink, Proposal, ProposalResult, Session, SessionOptions, SubscribeOptions, SystemFacade, Unsubscribe, World, WorldStore } from "@manifesto-ai/runtime";
|
|
12
|
+
import type { WorldId, WorldHead } from "@manifesto-ai/world";
|
|
13
|
+
/**
|
|
14
|
+
* Manifesto App — Thin Facade (FACADE-1~5)
|
|
15
|
+
*
|
|
16
|
+
* Only contains lifecycle management and delegation to AppRuntime.
|
|
17
|
+
*
|
|
18
|
+
* @see ADR-004 Phase 4
|
|
19
|
+
*/
|
|
20
|
+
export declare class ManifestoApp implements App {
|
|
21
|
+
private _lifecycleManager;
|
|
22
|
+
private _bootstrap;
|
|
23
|
+
private _runtime;
|
|
24
|
+
constructor(config: AppConfig, worldStore: WorldStore);
|
|
25
|
+
get status(): AppStatus;
|
|
26
|
+
get hooks(): Hookable<AppHooks>;
|
|
27
|
+
ready(): Promise<void>;
|
|
28
|
+
dispose(opts?: DisposeOptions): Promise<void>;
|
|
29
|
+
getDomainSchema(): DomainSchema;
|
|
30
|
+
currentBranch(): Branch;
|
|
31
|
+
listBranches(): readonly Branch[];
|
|
32
|
+
switchBranch(branchId: string): Promise<Branch>;
|
|
33
|
+
fork(opts?: ForkOptions): Promise<Branch>;
|
|
34
|
+
act(type: string, input?: unknown, opts?: ActOptions): ActionHandle;
|
|
35
|
+
getActionHandle(proposalId: string): ActionHandle;
|
|
36
|
+
session(actorId: string, opts?: SessionOptions): Session;
|
|
37
|
+
getState<T = unknown>(): AppState<T>;
|
|
38
|
+
subscribe<TSelected>(selector: (state: AppState<unknown>) => TSelected, listener: (selected: TSelected) => void, opts?: SubscribeOptions<TSelected>): Unsubscribe;
|
|
39
|
+
get system(): SystemFacade;
|
|
40
|
+
get memory(): MemoryFacade;
|
|
41
|
+
getMigrationLinks(): readonly MigrationLink[];
|
|
42
|
+
getCurrentHead(): WorldId;
|
|
43
|
+
getSnapshot<T = unknown>(): AppState<T>;
|
|
44
|
+
getSnapshot(worldId: WorldId): Promise<Snapshot>;
|
|
45
|
+
getWorld(worldId: WorldId): Promise<World>;
|
|
46
|
+
getHeads(): Promise<WorldHead[]>;
|
|
47
|
+
getLatestHead(): Promise<WorldHead | null>;
|
|
48
|
+
submitProposal(proposal: Proposal): Promise<ProposalResult>;
|
|
49
|
+
private _getRuntime;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EACV,GAAG,EACH,YAAY,EACZ,UAAU,EACV,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,MAAM,EACN,cAAc,EACd,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,aAAa,EAEb,QAAQ,EACR,cAAc,EACd,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,KAAK,EACL,UAAU,EACX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAqB9D;;;;;;GAMG;AACH,qBAAa,YAAa,YAAW,GAAG;IACtC,OAAO,CAAC,iBAAiB,CAAmB;IAC5C,OAAO,CAAC,UAAU,CAAe;IACjC,OAAO,CAAC,QAAQ,CAA2B;gBAE/B,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU;IAmCrD,IAAI,MAAM,IAAI,SAAS,CAEtB;IAED,IAAI,KAAK,IAAI,QAAQ,CAAC,QAAQ,CAAC,CAE9B;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAyBtB,OAAO,CAAC,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IA4BnD,eAAe,IAAI,YAAY;IAa/B,aAAa,IAAI,MAAM;IAIvB,YAAY,IAAI,SAAS,MAAM,EAAE;IAI3B,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
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manifesto App Implementation (Thin Facade)
|
|
3
|
+
*
|
|
4
|
+
* Delegates all operations to AppBootstrap (assembly) and AppRuntime (operations).
|
|
5
|
+
*
|
|
6
|
+
* @see ADR-004 Phase 4 — FACADE-1~5
|
|
7
|
+
* @see SPEC §5-6
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { AppDisposedError, AppBootstrap, createActionQueue, createLivenessGuard, createProposalManager, createLifecycleManager, createSchemaManager, createWorldHeadTracker, SubscriptionStore, createDefaultPolicyService, createSilentPolicyService, } from "@manifesto-ai/runtime";
|
|
11
|
+
// =============================================================================
|
|
12
|
+
// ManifestoApp Implementation (Thin Facade)
|
|
13
|
+
// =============================================================================
|
|
14
|
+
/**
|
|
15
|
+
* Manifesto App — Thin Facade (FACADE-1~5)
|
|
16
|
+
*
|
|
17
|
+
* Only contains lifecycle management and delegation to AppRuntime.
|
|
18
|
+
*
|
|
19
|
+
* @see ADR-004 Phase 4
|
|
20
|
+
*/
|
|
21
|
+
export class ManifestoApp {
|
|
22
|
+
_lifecycleManager;
|
|
23
|
+
_bootstrap;
|
|
24
|
+
_runtime = null;
|
|
25
|
+
constructor(config, worldStore) {
|
|
26
|
+
this._lifecycleManager = createLifecycleManager();
|
|
27
|
+
// PolicyService: use provided or create default
|
|
28
|
+
let policyService;
|
|
29
|
+
if (config.policyService) {
|
|
30
|
+
policyService = config.policyService;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const isTest = typeof globalThis !== "undefined" &&
|
|
34
|
+
globalThis.process?.env?.NODE_ENV === "test";
|
|
35
|
+
policyService = isTest
|
|
36
|
+
? createSilentPolicyService(config.executionKeyPolicy)
|
|
37
|
+
: createDefaultPolicyService({ executionKeyPolicy: config.executionKeyPolicy });
|
|
38
|
+
}
|
|
39
|
+
this._bootstrap = new AppBootstrap({
|
|
40
|
+
config,
|
|
41
|
+
worldStore,
|
|
42
|
+
policyService,
|
|
43
|
+
lifecycleManager: this._lifecycleManager,
|
|
44
|
+
schemaManager: createSchemaManager(config.schema),
|
|
45
|
+
proposalManager: createProposalManager(),
|
|
46
|
+
actionQueue: createActionQueue(),
|
|
47
|
+
livenessGuard: createLivenessGuard(),
|
|
48
|
+
worldHeadTracker: createWorldHeadTracker(),
|
|
49
|
+
subscriptionStore: new SubscriptionStore(),
|
|
50
|
+
effects: config.effects,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
// ===========================================================================
|
|
54
|
+
// Lifecycle
|
|
55
|
+
// ===========================================================================
|
|
56
|
+
get status() {
|
|
57
|
+
return this._lifecycleManager.status;
|
|
58
|
+
}
|
|
59
|
+
get hooks() {
|
|
60
|
+
return this._lifecycleManager.hooks;
|
|
61
|
+
}
|
|
62
|
+
async ready() {
|
|
63
|
+
if (this._lifecycleManager.status === "ready") {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (this._lifecycleManager.isDisposed()) {
|
|
67
|
+
throw new AppDisposedError("ready");
|
|
68
|
+
}
|
|
69
|
+
// Bootstrap assembles all components (steps 1-10)
|
|
70
|
+
this._runtime = await this._bootstrap.assemble(this);
|
|
71
|
+
// Initialize plugins (after _runtime is set so plugins can access app APIs)
|
|
72
|
+
await this._bootstrap.initializePlugins(this);
|
|
73
|
+
// Mark as ready
|
|
74
|
+
this._lifecycleManager.transitionTo("ready");
|
|
75
|
+
// Emit app:ready
|
|
76
|
+
await this._lifecycleManager.emitHook("app:ready", this._lifecycleManager.createHookContext());
|
|
77
|
+
}
|
|
78
|
+
async dispose(opts) {
|
|
79
|
+
if (this._lifecycleManager.status === "disposed") {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (this._lifecycleManager.status === "disposing") {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
this._lifecycleManager.transitionTo("disposing");
|
|
86
|
+
await this._lifecycleManager.emitHook("app:dispose:before", this._lifecycleManager.createHookContext());
|
|
87
|
+
this._lifecycleManager.transitionTo("disposed");
|
|
88
|
+
await this._lifecycleManager.emitHook("app:dispose", this._lifecycleManager.createHookContext());
|
|
89
|
+
}
|
|
90
|
+
// ===========================================================================
|
|
91
|
+
// Public API — all delegation to _getRuntime()
|
|
92
|
+
// ===========================================================================
|
|
93
|
+
getDomainSchema() {
|
|
94
|
+
if (this._lifecycleManager.isDisposed()) {
|
|
95
|
+
throw new AppDisposedError("getDomainSchema");
|
|
96
|
+
}
|
|
97
|
+
// Special case: getDomainSchema is accessible during plugin initialization
|
|
98
|
+
// (status is "created" but _runtime is already assembled).
|
|
99
|
+
// Original code checked schemaManager.isResolved instead of ensureReady().
|
|
100
|
+
if (this._runtime) {
|
|
101
|
+
return this._runtime.getDomainSchema();
|
|
102
|
+
}
|
|
103
|
+
return this._getRuntime("getDomainSchema").getDomainSchema();
|
|
104
|
+
}
|
|
105
|
+
currentBranch() {
|
|
106
|
+
return this._getRuntime("currentBranch").currentBranch();
|
|
107
|
+
}
|
|
108
|
+
listBranches() {
|
|
109
|
+
return this._getRuntime("listBranches").listBranches();
|
|
110
|
+
}
|
|
111
|
+
async switchBranch(branchId) {
|
|
112
|
+
return this._getRuntime("switchBranch").switchBranch(branchId);
|
|
113
|
+
}
|
|
114
|
+
async fork(opts) {
|
|
115
|
+
return this._getRuntime("fork").fork(opts);
|
|
116
|
+
}
|
|
117
|
+
act(type, input, opts) {
|
|
118
|
+
return this._getRuntime("act").act(type, input, opts);
|
|
119
|
+
}
|
|
120
|
+
getActionHandle(proposalId) {
|
|
121
|
+
return this._getRuntime("getActionHandle").getActionHandle(proposalId);
|
|
122
|
+
}
|
|
123
|
+
session(actorId, opts) {
|
|
124
|
+
return this._getRuntime("session").session(actorId, opts);
|
|
125
|
+
}
|
|
126
|
+
getState() {
|
|
127
|
+
return this._getRuntime("getState").getState();
|
|
128
|
+
}
|
|
129
|
+
subscribe(selector, listener, opts) {
|
|
130
|
+
return this._getRuntime("subscribe").subscribe(selector, listener, opts);
|
|
131
|
+
}
|
|
132
|
+
get system() {
|
|
133
|
+
return this._getRuntime("system").system;
|
|
134
|
+
}
|
|
135
|
+
get memory() {
|
|
136
|
+
return this._getRuntime("memory").memory;
|
|
137
|
+
}
|
|
138
|
+
getMigrationLinks() {
|
|
139
|
+
return this._getRuntime("getMigrationLinks").getMigrationLinks();
|
|
140
|
+
}
|
|
141
|
+
getCurrentHead() {
|
|
142
|
+
return this._getRuntime("getCurrentHead").getCurrentHead();
|
|
143
|
+
}
|
|
144
|
+
getSnapshot(worldId) {
|
|
145
|
+
if (worldId !== undefined) {
|
|
146
|
+
return this._getRuntime("getSnapshot").getSnapshot(worldId);
|
|
147
|
+
}
|
|
148
|
+
return this._getRuntime("getSnapshot").getState();
|
|
149
|
+
}
|
|
150
|
+
async getWorld(worldId) {
|
|
151
|
+
return this._getRuntime("getWorld").getWorld(worldId);
|
|
152
|
+
}
|
|
153
|
+
async getHeads() {
|
|
154
|
+
return this._getRuntime("getHeads").getHeads();
|
|
155
|
+
}
|
|
156
|
+
async getLatestHead() {
|
|
157
|
+
return this._getRuntime("getLatestHead").getLatestHead();
|
|
158
|
+
}
|
|
159
|
+
async submitProposal(proposal) {
|
|
160
|
+
return this._getRuntime("submitProposal").submitProposal(proposal);
|
|
161
|
+
}
|
|
162
|
+
// ===========================================================================
|
|
163
|
+
// Private: Runtime Guard (FACADE-5)
|
|
164
|
+
// ===========================================================================
|
|
165
|
+
_getRuntime(apiName) {
|
|
166
|
+
this._lifecycleManager.ensureReady(apiName);
|
|
167
|
+
return this._runtime;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=app.js.map
|
package/dist/app.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA8BH,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB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AK,CAAC,QAAQ,CAAC,OAAgB;QAC7B,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACxD,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,OAAO,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC,aAAa,EAAE,CAAC;IAC3D,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,QAAkB;QACrC,OAAO,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IACrE,CAAC;IAED,8EAA8E;IAC9E,oCAAoC;IACpC,8EAA8E;IAEtE,WAAW,CAAC,OAAe;QACjC,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC,QAAS,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* App Factory
|
|
3
|
+
*
|
|
4
|
+
* @see SPEC v2.3.0 §6
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import type { DomainSchema } from "@manifesto-ai/core";
|
|
8
|
+
import type { App, AppConfig, Effects, MelText } from "@manifesto-ai/runtime";
|
|
9
|
+
/**
|
|
10
|
+
* Create a new Manifesto App instance (v2.3.0).
|
|
11
|
+
*
|
|
12
|
+
* The `createApp()` function:
|
|
13
|
+
* 1. Returns synchronously with an App instance
|
|
14
|
+
* 2. Does NOT perform runtime initialization during this call
|
|
15
|
+
* 3. Creates Host internally (users provide effects, not Host)
|
|
16
|
+
* 4. Creates World internally if not provided (per ADR-003)
|
|
17
|
+
*
|
|
18
|
+
* ## v2.3.0 API (Recommended)
|
|
19
|
+
*
|
|
20
|
+
* Uses AppConfig with effects-first design. Host and World are created internally.
|
|
21
|
+
*
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const app = createApp({
|
|
24
|
+
* schema: domainSchema,
|
|
25
|
+
* effects: {
|
|
26
|
+
* 'api.fetch': async (params, ctx) => [...],
|
|
27
|
+
* 'api.save': async (params, ctx) => [...],
|
|
28
|
+
* },
|
|
29
|
+
* // world is optional (defaults to internal World with InMemoryWorldStore)
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* await app.ready();
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @see SPEC v2.3.0 §6.1
|
|
36
|
+
* @see ADR-APP-002
|
|
37
|
+
* @see ADR-003
|
|
38
|
+
*/
|
|
39
|
+
export declare function createApp(config: AppConfig): App;
|
|
40
|
+
/**
|
|
41
|
+
* Create a minimal App for testing.
|
|
42
|
+
*
|
|
43
|
+
* Uses in-memory implementations for WorldStore and empty effects.
|
|
44
|
+
* For v2.3.0, this creates an effects-first app.
|
|
45
|
+
*
|
|
46
|
+
* @param domain - Domain schema or MEL text
|
|
47
|
+
* @param opts - Additional options
|
|
48
|
+
*/
|
|
49
|
+
export declare function createTestApp(domain: MelText | DomainSchema, opts?: Partial<Omit<AppConfig, "schema" | "effects">> & {
|
|
50
|
+
effects?: Effects;
|
|
51
|
+
}): App;
|
|
52
|
+
//# sourceMappingURL=create-app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-app.d.ts","sourceRoot":"","sources":["../src/create-app.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAQ9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,GAAG,CAEhD;AA2BD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,OAAO,GAAG,YAAY,EAC9B,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAC,GAAG;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAC5E,GAAG,CAmBL"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* App Factory
|
|
3
|
+
*
|
|
4
|
+
* @see SPEC v2.3.0 §6
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { ManifestoApp } from "./app.js";
|
|
8
|
+
import { createInMemoryWorldStore, ReservedEffectTypeError, RESERVED_EFFECT_TYPE } from "@manifesto-ai/runtime";
|
|
9
|
+
// =============================================================================
|
|
10
|
+
// v2.2.0 API
|
|
11
|
+
// =============================================================================
|
|
12
|
+
/**
|
|
13
|
+
* Create a new Manifesto App instance (v2.3.0).
|
|
14
|
+
*
|
|
15
|
+
* The `createApp()` function:
|
|
16
|
+
* 1. Returns synchronously with an App instance
|
|
17
|
+
* 2. Does NOT perform runtime initialization during this call
|
|
18
|
+
* 3. Creates Host internally (users provide effects, not Host)
|
|
19
|
+
* 4. Creates World internally if not provided (per ADR-003)
|
|
20
|
+
*
|
|
21
|
+
* ## v2.3.0 API (Recommended)
|
|
22
|
+
*
|
|
23
|
+
* Uses AppConfig with effects-first design. Host and World are created internally.
|
|
24
|
+
*
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const app = createApp({
|
|
27
|
+
* schema: domainSchema,
|
|
28
|
+
* effects: {
|
|
29
|
+
* 'api.fetch': async (params, ctx) => [...],
|
|
30
|
+
* 'api.save': async (params, ctx) => [...],
|
|
31
|
+
* },
|
|
32
|
+
* // world is optional (defaults to internal World with InMemoryWorldStore)
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* await app.ready();
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @see SPEC v2.3.0 §6.1
|
|
39
|
+
* @see ADR-APP-002
|
|
40
|
+
* @see ADR-003
|
|
41
|
+
*/
|
|
42
|
+
export function createApp(config) {
|
|
43
|
+
return createAppFromConfig(config);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create App with v2.3.0 AppConfig (effects-first, World owns persistence).
|
|
47
|
+
*
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
function createAppFromConfig(config) {
|
|
51
|
+
// Extract domain from config
|
|
52
|
+
const domain = config.schema;
|
|
53
|
+
// Validate reserved effect types - users cannot override system.get
|
|
54
|
+
if (RESERVED_EFFECT_TYPE in config.effects) {
|
|
55
|
+
throw new ReservedEffectTypeError(RESERVED_EFFECT_TYPE);
|
|
56
|
+
}
|
|
57
|
+
// ADR-003: World owns persistence
|
|
58
|
+
// If world is not provided, create a default WorldStore
|
|
59
|
+
const worldStore = config.world?.store ?? createInMemoryWorldStore();
|
|
60
|
+
return new ManifestoApp(config, worldStore);
|
|
61
|
+
}
|
|
62
|
+
// =============================================================================
|
|
63
|
+
// Helper Factories
|
|
64
|
+
// =============================================================================
|
|
65
|
+
/**
|
|
66
|
+
* Create a minimal App for testing.
|
|
67
|
+
*
|
|
68
|
+
* Uses in-memory implementations for WorldStore and empty effects.
|
|
69
|
+
* For v2.3.0, this creates an effects-first app.
|
|
70
|
+
*
|
|
71
|
+
* @param domain - Domain schema or MEL text
|
|
72
|
+
* @param opts - Additional options
|
|
73
|
+
*/
|
|
74
|
+
export function createTestApp(domain, opts) {
|
|
75
|
+
return createApp({
|
|
76
|
+
schema: domain,
|
|
77
|
+
effects: opts?.effects ?? {},
|
|
78
|
+
initialData: opts?.initialData,
|
|
79
|
+
hooks: opts?.hooks,
|
|
80
|
+
actorPolicy: opts?.actorPolicy,
|
|
81
|
+
scheduler: opts?.scheduler,
|
|
82
|
+
systemActions: opts?.systemActions,
|
|
83
|
+
devtools: opts?.devtools,
|
|
84
|
+
plugins: opts?.plugins,
|
|
85
|
+
validation: opts?.validation,
|
|
86
|
+
memory: opts?.memory,
|
|
87
|
+
memoryStore: opts?.memoryStore,
|
|
88
|
+
memoryProvider: opts?.memoryProvider,
|
|
89
|
+
policyService: opts?.policyService,
|
|
90
|
+
executionKeyPolicy: opts?.executionKeyPolicy,
|
|
91
|
+
world: opts?.world,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=create-app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-app.js","sourceRoot":"","sources":["../src/create-app.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAEhH,gFAAgF;AAChF,aAAa;AACb,gFAAgF;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,MAAM,UAAU,SAAS,CAAC,MAAiB;IACzC,OAAO,mBAAmB,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC;AAED;;;;GAIG;AACH,SAAS,mBAAmB,CAAC,MAAiB;IAC5C,6BAA6B;IAC7B,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAE7B,oEAAoE;IACpE,IAAI,oBAAoB,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QAC3C,MAAM,IAAI,uBAAuB,CAAC,oBAAoB,CAAC,CAAC;IAC1D,CAAC;IAED,kCAAkC;IAClC,wDAAwD;IACxD,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,IAAI,wBAAwB,EAAE,CAAC;IAErE,OAAO,IAAI,YAAY,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAC9C,CAAC;AAED,gFAAgF;AAChF,mBAAmB;AACnB,gFAAgF;AAEhF;;;;;;;;GAQG;AACH,M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