@skaile/skailify-core 0.0.0 → 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/AGENTS.md +164 -0
- package/LICENSE +202 -0
- package/README.md +126 -1
- package/dist/index.d.ts +231 -0
- package/dist/index.js +596 -0
- package/dist/index.js.map +1 -0
- package/dist/skailify.iife.js +176 -0
- package/dist/skailify.iife.js.map +1 -0
- package/package.json +52 -2
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@skaile/skailify-core`: the framework-free Skailify client. It makes an app agent-controllable inside a Skaile
|
|
3
|
+
* session, over the Skailify app channel, without a UI framework: the app creates one client with its app id (and,
|
|
4
|
+
* optionally, its navigation), and registers the views, state and actions it offers.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* const skailify = createSkailify({ appId: "deck" });
|
|
8
|
+
* skailify.registerView({ id: "slide-1", title: "Title slide" });
|
|
9
|
+
* void skailify.start();
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* The React and Angular adapters wrap this client. For a page without a bundler, `dist/skailify.iife.js` exposes
|
|
13
|
+
* the same exports as the global `Skailify`.
|
|
14
|
+
*/
|
|
15
|
+
import * as z$1 from "zod";
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
import { AppAssistantCorner, AppAssistantPresentation, AppAssistantPresentation as AppAssistantPresentation$1, AppConnectionParams, AppLogger, AppTransport, DefineAppCapabilityArgs, ReconnectOptions, SessionTokenProvider, SkaileApp } from "@skaile/workspaces/app-sdk";
|
|
18
|
+
type ConnectionStatus = {
|
|
19
|
+
state: "idle";
|
|
20
|
+
} | {
|
|
21
|
+
state: "standalone";
|
|
22
|
+
} | {
|
|
23
|
+
state: "connecting";
|
|
24
|
+
} | {
|
|
25
|
+
state: "connected";
|
|
26
|
+
sessionId: string;
|
|
27
|
+
userId?: string;
|
|
28
|
+
} | {
|
|
29
|
+
state: "reconnecting";
|
|
30
|
+
} | {
|
|
31
|
+
state: "error";
|
|
32
|
+
message: string;
|
|
33
|
+
} | {
|
|
34
|
+
state: "closed";
|
|
35
|
+
};
|
|
36
|
+
/** One line of the activity log: `in` is a call from the agent, `out` is what the app answered or a connection event. */
|
|
37
|
+
interface ActivityEntry {
|
|
38
|
+
id: number;
|
|
39
|
+
at: number;
|
|
40
|
+
direction: "in" | "out";
|
|
41
|
+
label: string;
|
|
42
|
+
detail?: string;
|
|
43
|
+
error?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* An action the agent can call. `name` is relative (`board.add_card`): the client puts `app.` in front, and the
|
|
47
|
+
* platform shows it to the agent as `app.<appId>.board.add_card`. Everything else is the app SDK's
|
|
48
|
+
* `defineAppCapability` arguments, including `requiresApproval` and `effectClass`.
|
|
49
|
+
*/
|
|
50
|
+
type AgentAction<T extends z$1.ZodTypeAny = z$1.ZodTypeAny, R extends z$1.ZodTypeAny | undefined = z$1.ZodTypeAny | undefined> = DefineAppCapabilityArgs<T, R> & {
|
|
51
|
+
/** @internal the handler waits for the view itself */
|
|
52
|
+
[SETTLES_ITSELF]?: boolean;
|
|
53
|
+
};
|
|
54
|
+
/** Types an action's handler from its input schema, for an action declared outside a component. */
|
|
55
|
+
export declare function agentAction<T extends z$1.ZodTypeAny, R extends z$1.ZodTypeAny | undefined = undefined>(action: AgentAction<T, R>): AgentAction;
|
|
56
|
+
/** What a mounted view says about itself. The last view mounted is the one on screen. */
|
|
57
|
+
interface ViewRegistration {
|
|
58
|
+
/** Stable id of the view: a route, a screen name, a record key */
|
|
59
|
+
id: string;
|
|
60
|
+
title?: string;
|
|
61
|
+
/** A small JSON-serialisable summary of what the view shows (filters, selection, counts) */
|
|
62
|
+
state?: unknown;
|
|
63
|
+
/** True while the view is still loading what it shows; the agent waits until it is false */
|
|
64
|
+
loading?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/** A capability as the agent sees it, for a panel in the app's own UI. */
|
|
67
|
+
interface CapabilityInfo {
|
|
68
|
+
/** As registered: `app.board.add_card` */
|
|
69
|
+
name: string;
|
|
70
|
+
/** As the agent calls it: `app.<appId>.board.add_card` */
|
|
71
|
+
agentName: string;
|
|
72
|
+
displayName?: string;
|
|
73
|
+
description: string;
|
|
74
|
+
kind?: "effect" | "render" | "query";
|
|
75
|
+
requiresApproval?: boolean;
|
|
76
|
+
effectClass?: string;
|
|
77
|
+
}
|
|
78
|
+
interface SkailifySnapshot {
|
|
79
|
+
status: ConnectionStatus;
|
|
80
|
+
activity: readonly ActivityEntry[];
|
|
81
|
+
capabilities: readonly CapabilityInfo[];
|
|
82
|
+
}
|
|
83
|
+
interface WindowLike {
|
|
84
|
+
readonly parent: unknown;
|
|
85
|
+
readonly location: {
|
|
86
|
+
readonly search: string;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
interface SkailifyOptions {
|
|
90
|
+
/** The app's id: the `id` of its entry in the workspace's `skaile.preview.json` */
|
|
91
|
+
appId: string;
|
|
92
|
+
/** `auto` (default): connect when embedded in Skaile; `false`: never, not even over `transport` */
|
|
93
|
+
enabled?: "auto" | false;
|
|
94
|
+
/**
|
|
95
|
+
* The app's views and how to show one, router-agnostic. With it the agent gets `list_views` and `navigate`;
|
|
96
|
+
* without it, only what the mounted components register.
|
|
97
|
+
*/
|
|
98
|
+
navigation?: Navigation;
|
|
99
|
+
logger?: AppLogger;
|
|
100
|
+
reconnect?: ReconnectOptions | false;
|
|
101
|
+
/** How long a call waits for the view to settle after an action; default 3000 ms, at most {@link MAX_WAIT_MS} */
|
|
102
|
+
settleTimeoutMs?: number;
|
|
103
|
+
/**
|
|
104
|
+
* Resolves once the framework has rendered the latest change (Angular: `ApplicationRef.whenStable()`). Settling
|
|
105
|
+
* waits for it, then for the next frame. A framework adapter sets it; without it settling waits for the next frame.
|
|
106
|
+
*/
|
|
107
|
+
rendered?: () => Promise<unknown>;
|
|
108
|
+
/**
|
|
109
|
+
* Where code runs, for a framework that tracks async work (Angular's zone.js). The connection and the settle timers
|
|
110
|
+
* run `outside`, so they never keep the app from becoming stable; the handlers run `inside`, so the app sees what
|
|
111
|
+
* they change. The Angular adapter sets it from `NgZone`; without it everything runs where it is called.
|
|
112
|
+
*/
|
|
113
|
+
zone?: {
|
|
114
|
+
inside<T>(fn: () => T): T;
|
|
115
|
+
outside<T>(fn: () => T): T;
|
|
116
|
+
};
|
|
117
|
+
/** Entries the activity log keeps; default 40 */
|
|
118
|
+
activityLimit?: number;
|
|
119
|
+
/**
|
|
120
|
+
* Connect over this transport instead of the host handshake and the WebSocket (tests, or an app that
|
|
121
|
+
* resolves its own connection). The client then connects whether or not it is embedded.
|
|
122
|
+
*/
|
|
123
|
+
transport?: AppTransport;
|
|
124
|
+
/**
|
|
125
|
+
* How Skaile shows its agent button over the app: `{ kind: "none" }` hides it, `{ kind: "floating", corner,
|
|
126
|
+
* offset, size, accent }` places it. Without it Skaile shows the button where it chooses. Change it later with
|
|
127
|
+
* {@link Skailify.setAssistant}.
|
|
128
|
+
*/
|
|
129
|
+
assistant?: AppAssistantPresentation$1;
|
|
130
|
+
/** For tests: the window, the host handshake, the transport factory and the assistant message */
|
|
131
|
+
windowRef?: WindowLike;
|
|
132
|
+
resolveParams?: (appId: string, parentOrigin: string, assistant?: AppAssistantPresentation$1) => Promise<AppConnectionParams>;
|
|
133
|
+
postAssistant?: (appId: string, parentOrigin: string, presentation: AppAssistantPresentation$1) => void;
|
|
134
|
+
createTransport?: (url: string, token: SessionTokenProvider) => AppTransport;
|
|
135
|
+
}
|
|
136
|
+
interface Skailify {
|
|
137
|
+
readonly appId: string;
|
|
138
|
+
/** The SDK peer once connecting; null when standalone or not started */
|
|
139
|
+
readonly app: SkaileApp | null;
|
|
140
|
+
/** Connects (once; later calls return the same promise). Never rejects: a failure shows in the status. */
|
|
141
|
+
start(): Promise<void>;
|
|
142
|
+
close(): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Changes how Skaile shows its agent button over the app (see {@link SkailifyOptions.assistant}). Before the
|
|
145
|
+
* connection it replaces the option; standalone it does nothing.
|
|
146
|
+
*/
|
|
147
|
+
setAssistant(presentation: AppAssistantPresentation$1): void;
|
|
148
|
+
/**
|
|
149
|
+
* Adds an action; returns the function that removes exactly this registration. Of several actions with the same
|
|
150
|
+
* name the one registered last is offered; removing it offers the one before again.
|
|
151
|
+
*/
|
|
152
|
+
registerAction<T extends z$1.ZodTypeAny, R extends z$1.ZodTypeAny | undefined = undefined>(action: AgentAction<T, R>): () => void;
|
|
153
|
+
/**
|
|
154
|
+
* Adds a view; returns the function that updates it and the one that removes it. Of several mounted views the one
|
|
155
|
+
* with the highest `order` is on screen; without one, the view added last. Pass an order from {@link viewOrder}
|
|
156
|
+
* taken while rendering, so a parent and the child it contains, mounted together, keep the child on top.
|
|
157
|
+
*/
|
|
158
|
+
registerView(view: ViewRegistration, order?: number): {
|
|
159
|
+
update(view: ViewRegistration): void;
|
|
160
|
+
remove(): void;
|
|
161
|
+
};
|
|
162
|
+
/** A new view order, increasing; take it when a view first renders */
|
|
163
|
+
viewOrder(): number;
|
|
164
|
+
/** Exposes a named piece of state to `get_view_state`; `read` is called on every read. */
|
|
165
|
+
registerState(name: string, read: () => unknown): () => void;
|
|
166
|
+
/** The view on screen: the last one mounted, else the navigation's current view */
|
|
167
|
+
currentView(): ViewRegistration | null;
|
|
168
|
+
/** Every registered state, read now */
|
|
169
|
+
readState(): Record<string, unknown>;
|
|
170
|
+
/** Whether a mounted view says it is still loading */
|
|
171
|
+
loading(): boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Waits until the app has rendered and no mounted view is loading, then tells the agent what is on screen and
|
|
174
|
+
* that it has settled. Resolves false when the timeout came first. The client calls it after every effect.
|
|
175
|
+
*/
|
|
176
|
+
settle(timeoutMs?: number): Promise<boolean>;
|
|
177
|
+
/** The full name of a relative one: `board.add_card` → `app.board.add_card` */
|
|
178
|
+
fullName(name: string): string;
|
|
179
|
+
/** The name the agent calls: `board.add_card` → `app.<appId>.board.add_card` */
|
|
180
|
+
agentName(name: string): string;
|
|
181
|
+
/** For the UI: React's `useSyncExternalStore`, Angular's signals, or a plain listener */
|
|
182
|
+
subscribe(listener: () => void): () => void;
|
|
183
|
+
getSnapshot(): SkailifySnapshot;
|
|
184
|
+
/** Adds a line to the activity log, for events of the app's own */
|
|
185
|
+
log(entry: Omit<ActivityEntry, "id" | "at">): void;
|
|
186
|
+
}
|
|
187
|
+
/** The longest a call may wait for the view to settle */
|
|
188
|
+
export declare const MAX_WAIT_MS = 10000;
|
|
189
|
+
/**
|
|
190
|
+
* The embedding host's origin, or null when the app is not embedded in Skaile. Read once at start: the app's own
|
|
191
|
+
* navigation may drop the query parameter, and every reconnect needs it.
|
|
192
|
+
*/
|
|
193
|
+
export declare function skaileParentOrigin(windowRef?: WindowLike | undefined): string | null;
|
|
194
|
+
/** Marks a capability whose handler waits for the view itself, so the wrapper does not wait a second time. */
|
|
195
|
+
declare const SETTLES_ITSELF: unique symbol;
|
|
196
|
+
export declare function createSkailify(options: SkailifyOptions): Skailify;
|
|
197
|
+
/** A view (page, screen) of the app, as the agent sees it in `list_views`. */
|
|
198
|
+
interface ViewDescriptor {
|
|
199
|
+
/** The id `navigate` takes */
|
|
200
|
+
id: string;
|
|
201
|
+
title?: string;
|
|
202
|
+
/** false for views reached only from another view; default true */
|
|
203
|
+
menu?: boolean;
|
|
204
|
+
/** Parameters the view takes in `navigate`, e.g. `{ cardId: "the card to open" }` */
|
|
205
|
+
params?: Record<string, string>;
|
|
206
|
+
}
|
|
207
|
+
/** How the agent finds and shows the app's views. Wire it to your router, or to whatever shows a view in the app. */
|
|
208
|
+
interface Navigation {
|
|
209
|
+
/** The app's views; called on every request, so it always answers the current set */
|
|
210
|
+
views: () => ViewDescriptor[];
|
|
211
|
+
/** Shows a view. May return before the view has rendered: the client waits for it to settle. */
|
|
212
|
+
navigate: (viewId: string, params: Record<string, string>) => void | Promise<void>;
|
|
213
|
+
/** The id of the view on screen, for apps whose views do not register themselves */
|
|
214
|
+
current?: () => string | undefined;
|
|
215
|
+
}
|
|
216
|
+
/** What `get_view_state` and `navigate` answer. */
|
|
217
|
+
interface ViewState {
|
|
218
|
+
view: {
|
|
219
|
+
id: string;
|
|
220
|
+
title?: string;
|
|
221
|
+
state?: unknown;
|
|
222
|
+
} | null;
|
|
223
|
+
/** What the app exposes with `registerState`, by name */
|
|
224
|
+
state: Record<string, unknown>;
|
|
225
|
+
/** The actions available now, by the name the agent calls them (`app.<appId>.<name>`) */
|
|
226
|
+
actions: string[];
|
|
227
|
+
/** false when a view was still loading when the wait timed out: read again */
|
|
228
|
+
settled: boolean;
|
|
229
|
+
}
|
|
230
|
+
export declare function viewState(client: Skailify, settled: boolean): ViewState;
|
|
231
|
+
export { type ActivityEntry, type AgentAction, type AppAssistantCorner, type AppAssistantPresentation, type CapabilityInfo, type ConnectionStatus, type Navigation, type Skailify, type SkailifyOptions, type SkailifySnapshot, type ViewDescriptor, type ViewRegistration, type ViewState, z };
|