@aiworkbench/vibe-types 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +22 -0
  2. package/src/index.ts +154 -0
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@aiworkbench/vibe-types",
3
+ "version": "0.0.1",
4
+ "publishConfig": { "access": "public" },
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "bun": "./src/index.ts",
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "build": "bun build ./src/index.ts --outdir ./dist --target=node && tsc --emitDeclarationOnly",
17
+ "dev": "tsc --watch --emitDeclarationOnly",
18
+ "type-check": "tsc --noEmit",
19
+ "clean": "rm -rf dist"
20
+ },
21
+ "files": ["dist", "src"]
22
+ }
package/src/index.ts ADDED
@@ -0,0 +1,154 @@
1
+ /**
2
+ * @aiworkbench/vibe-types
3
+ *
4
+ * Bridge interface — the contract between the Host application
5
+ * and micro-frontend mini-apps.
6
+ *
7
+ * The Host injects a bridge object into each mini-app based on
8
+ * the permissions declared in its manifest.json.
9
+ */
10
+
11
+ // ---------------------------------------------------------------------------
12
+ // Capability type
13
+ // ---------------------------------------------------------------------------
14
+
15
+ export type BridgeCapability =
16
+ | "auth"
17
+ | "api"
18
+ | "navigation"
19
+ | "theme"
20
+ | "toast"
21
+ | "storage"
22
+ | "events";
23
+
24
+ // ---------------------------------------------------------------------------
25
+ // Auth
26
+ // ---------------------------------------------------------------------------
27
+
28
+ export interface BridgeUser {
29
+ id: string;
30
+ name: string;
31
+ email?: string;
32
+ }
33
+
34
+ export interface AuthBridge {
35
+ getUser(): BridgeUser;
36
+ getToken(): Promise<string>;
37
+ }
38
+
39
+ // ---------------------------------------------------------------------------
40
+ // Navigation
41
+ // ---------------------------------------------------------------------------
42
+
43
+ export interface NavigationBridge {
44
+ navigate(path: string): void;
45
+ }
46
+
47
+ // ---------------------------------------------------------------------------
48
+ // Theme
49
+ // ---------------------------------------------------------------------------
50
+
51
+ export interface ThemeBridge {
52
+ current(): "light" | "dark";
53
+ }
54
+
55
+ // ---------------------------------------------------------------------------
56
+ // Toast
57
+ // ---------------------------------------------------------------------------
58
+
59
+ export interface ToastBridge {
60
+ show(
61
+ message: string,
62
+ options?: { type?: "info" | "success" | "error" },
63
+ ): void;
64
+ }
65
+
66
+ // ---------------------------------------------------------------------------
67
+ // API
68
+ // ---------------------------------------------------------------------------
69
+
70
+ export interface ApiBridge {
71
+ fetch(endpoint: string, options?: RequestInit): Promise<Response>;
72
+ }
73
+
74
+ // ---------------------------------------------------------------------------
75
+ // Storage — namespaced key-value persistence
76
+ // ---------------------------------------------------------------------------
77
+
78
+ export interface StorageBridge {
79
+ /** Get a value by key. Returns null if not found. */
80
+ get(key: string): Promise<string | null>;
81
+ /** Set a key-value pair. */
82
+ set(key: string, value: string): Promise<void>;
83
+ /** Remove a key. */
84
+ remove(key: string): Promise<void>;
85
+ /** List all keys in this mini-app's namespace. */
86
+ keys(): Promise<string[]>;
87
+ }
88
+
89
+ // ---------------------------------------------------------------------------
90
+ // Events — typed pub/sub between mini-app and host
91
+ // ---------------------------------------------------------------------------
92
+
93
+ export interface EventPayload {
94
+ [key: string]: unknown;
95
+ }
96
+
97
+ export interface EventsBridge {
98
+ /** Emit an event to the host. */
99
+ emit(event: string, payload?: EventPayload): void;
100
+ /** Subscribe to events from the host. Returns an unsubscribe function. */
101
+ on(event: string, handler: (payload: EventPayload) => void): () => void;
102
+ /** Subscribe once, then auto-unsubscribe. Returns an unsubscribe function. */
103
+ once(event: string, handler: (payload: EventPayload) => void): () => void;
104
+ }
105
+
106
+ // ---------------------------------------------------------------------------
107
+ // Composite Bridge
108
+ // ---------------------------------------------------------------------------
109
+
110
+ export interface Bridge {
111
+ auth: AuthBridge;
112
+ navigation: NavigationBridge;
113
+ theme: ThemeBridge;
114
+ toast: ToastBridge;
115
+ api: ApiBridge;
116
+ storage: StorageBridge;
117
+ events: EventsBridge;
118
+ }
119
+
120
+ /** Props passed to every mini-app component. */
121
+ export interface VibeProps {
122
+ bridge: Bridge;
123
+ }
124
+
125
+ /** Manifest schema for a mini-app. */
126
+ export interface VibeManifest {
127
+ id: string;
128
+ version: string;
129
+ framework: "react" | "vue" | "vanilla";
130
+ permissions: BridgeCapability[];
131
+ description: string;
132
+ entry?: string;
133
+ }
134
+
135
+ // ---------------------------------------------------------------------------
136
+ // Registry — published mini-app metadata
137
+ // ---------------------------------------------------------------------------
138
+
139
+ /** A published mini-app entry in the registry. */
140
+ export interface RegistryEntry extends VibeManifest {
141
+ /** URL to the ES module bundle on storage. */
142
+ bundleUrl: string;
143
+ /** SRI hash (sha384-…). */
144
+ integrity: string;
145
+ /** Raw bundle size in bytes. */
146
+ bundleSizeBytes?: number;
147
+ /** ISO 8601 publish timestamp. */
148
+ publishedAt: string;
149
+ /** Publisher identity (e.g. GitHub username). */
150
+ publishedBy: string;
151
+ }
152
+
153
+ /** An environment's apps.json file — an array of published entries. */
154
+ export type RegistryManifest = RegistryEntry[];