@histoire/sdk 0.0.0-stage → 1.0.0-beta.2
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/dist/adapters/types.d.ts +150 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/adapters/types.js +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/internal.d.ts +16 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +8 -0
- package/dist/mounts/channel.d.ts +20 -0
- package/dist/mounts/channel.d.ts.map +1 -0
- package/dist/mounts/channel.js +76 -0
- package/dist/mounts/events.d.ts +9 -0
- package/dist/mounts/events.d.ts.map +1 -0
- package/dist/mounts/events.js +45 -0
- package/dist/mounts/geometry.d.ts +9 -0
- package/dist/mounts/geometry.d.ts.map +1 -0
- package/dist/mounts/geometry.js +69 -0
- package/dist/mounts/handle.d.ts +5 -0
- package/dist/mounts/handle.d.ts.map +1 -0
- package/dist/mounts/handle.js +44 -0
- package/dist/mounts/iframe.d.ts +4 -0
- package/dist/mounts/iframe.d.ts.map +1 -0
- package/dist/mounts/iframe.js +143 -0
- package/dist/mounts/overlay.d.ts +11 -0
- package/dist/mounts/overlay.d.ts.map +1 -0
- package/dist/mounts/overlay.js +53 -0
- package/dist/mounts/view-snapshot.d.ts +4 -0
- package/dist/mounts/view-snapshot.d.ts.map +1 -0
- package/dist/mounts/view-snapshot.js +24 -0
- package/dist/persistence/key.d.ts +3 -0
- package/dist/persistence/key.d.ts.map +1 -0
- package/dist/persistence/key.js +4 -0
- package/dist/persistence/storage.d.ts +13 -0
- package/dist/persistence/storage.d.ts.map +1 -0
- package/dist/persistence/storage.js +37 -0
- package/dist/session/channels.d.ts +8 -0
- package/dist/session/channels.d.ts.map +1 -0
- package/dist/session/channels.js +117 -0
- package/dist/session/context.d.ts +97 -0
- package/dist/session/context.d.ts.map +1 -0
- package/dist/session/context.js +136 -0
- package/dist/session/controller.d.ts +5 -0
- package/dist/session/controller.d.ts.map +1 -0
- package/dist/session/controller.js +217 -0
- package/dist/session/debug-lease.d.ts +5 -0
- package/dist/session/debug-lease.d.ts.map +1 -0
- package/dist/session/debug-lease.js +64 -0
- package/dist/session/debug.d.ts +14 -0
- package/dist/session/debug.d.ts.map +1 -0
- package/dist/session/debug.js +242 -0
- package/dist/session/events.d.ts +7 -0
- package/dist/session/events.d.ts.map +1 -0
- package/dist/session/events.js +23 -0
- package/dist/session/inspection.d.ts +5 -0
- package/dist/session/inspection.d.ts.map +1 -0
- package/dist/session/inspection.js +88 -0
- package/dist/session/internal.d.ts +87 -0
- package/dist/session/internal.d.ts.map +1 -0
- package/dist/session/internal.js +144 -0
- package/dist/session/mounts.d.ts +6 -0
- package/dist/session/mounts.d.ts.map +1 -0
- package/dist/session/mounts.js +150 -0
- package/dist/session/notifications.d.ts +5 -0
- package/dist/session/notifications.d.ts.map +1 -0
- package/dist/session/notifications.js +143 -0
- package/dist/session/ownership.d.ts +20 -0
- package/dist/session/ownership.d.ts.map +1 -0
- package/dist/session/ownership.js +69 -0
- package/dist/session/plugin-hub.d.ts +59 -0
- package/dist/session/plugin-hub.d.ts.map +1 -0
- package/dist/session/plugin-hub.js +215 -0
- package/dist/session/plugins.d.ts +8 -0
- package/dist/session/plugins.d.ts.map +1 -0
- package/dist/session/plugins.js +78 -0
- package/dist/session/request.d.ts +8 -0
- package/dist/session/request.d.ts.map +1 -0
- package/dist/session/request.js +99 -0
- package/dist/session/runtime.d.ts +5 -0
- package/dist/session/runtime.d.ts.map +1 -0
- package/dist/session/runtime.js +25 -0
- package/dist/session/selection.d.ts +9 -0
- package/dist/session/selection.d.ts.map +1 -0
- package/dist/session/selection.js +111 -0
- package/dist/session/services.d.ts +18 -0
- package/dist/session/services.d.ts.map +1 -0
- package/dist/session/services.js +51 -0
- package/dist/session/settings.d.ts +7 -0
- package/dist/session/settings.d.ts.map +1 -0
- package/dist/session/settings.js +31 -0
- package/dist/session/snapshot.d.ts +12 -0
- package/dist/session/snapshot.d.ts.map +1 -0
- package/dist/session/snapshot.js +72 -0
- package/dist/session/state.d.ts +11 -0
- package/dist/session/state.d.ts.map +1 -0
- package/dist/session/state.js +73 -0
- package/dist/session/variant.d.ts +4 -0
- package/dist/session/variant.d.ts.map +1 -0
- package/dist/session/variant.js +11 -0
- package/dist/transport/authority.d.ts +35 -0
- package/dist/transport/authority.d.ts.map +1 -0
- package/dist/transport/authority.js +110 -0
- package/dist/transport/connection.d.ts +4 -0
- package/dist/transport/connection.d.ts.map +1 -0
- package/dist/transport/connection.js +37 -0
- package/dist/transport/handshake.d.ts +34 -0
- package/dist/transport/handshake.d.ts.map +1 -0
- package/dist/transport/handshake.js +110 -0
- package/dist/transport/inbound.d.ts +15 -0
- package/dist/transport/inbound.d.ts.map +1 -0
- package/dist/transport/inbound.js +51 -0
- package/dist/transport/port.d.ts +51 -0
- package/dist/transport/port.d.ts.map +1 -0
- package/dist/transport/port.js +288 -0
- package/dist/transport/reply.d.ts +6 -0
- package/dist/transport/reply.d.ts.map +1 -0
- package/dist/transport/reply.js +44 -0
- package/dist/transport/requests.d.ts +33 -0
- package/dist/transport/requests.d.ts.map +1 -0
- package/dist/transport/requests.js +62 -0
- package/dist/transport/session-commands.d.ts +5 -0
- package/dist/transport/session-commands.d.ts.map +1 -0
- package/dist/transport/session-commands.js +70 -0
- package/dist/transport/validated.d.ts +13 -0
- package/dist/transport/validated.d.ts.map +1 -0
- package/dist/transport/validated.js +22 -0
- package/dist/transport/validation.d.ts +8 -0
- package/dist/transport/validation.d.ts.map +1 -0
- package/dist/transport/validation.js +20 -0
- package/dist/types.d.ts +140 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +38 -3
- package/README.md +0 -3
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { createPluginChannelLimiters, getHistoireTargetKey, HistoireSdkError, isHistoirePluginId, isHistoirePluginNotice, validatePluginChannelPayload } from '@histoire/protocol';
|
|
2
|
+
import { observeOperation } from './ownership.js';
|
|
3
|
+
/** Rejects with the retirement code as soon as `signal` aborts; never waits for the transport. */
|
|
4
|
+
function untilRetired(entry, work) {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
const signal = entry.controller.signal;
|
|
7
|
+
const abort = () => reject(new HistoireSdkError(entry.retired ?? 'RUNTIME_CHANGED', 'Plugin actor retired.'));
|
|
8
|
+
if (signal.aborted)
|
|
9
|
+
return abort();
|
|
10
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
11
|
+
Promise.resolve().then(work).then(resolve, reject).finally(() => signal.removeEventListener('abort', abort));
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Host side of plugin channels shared by SDK sessions and the standalone workbench: actor
|
|
16
|
+
* registry from runtime notices, per-plugin accounting per runtime document, delivery by actor id
|
|
17
|
+
* (never by selected variant), retirement without queues or replay. Source, origin and document
|
|
18
|
+
* checks stay with each adapter before `receive`.
|
|
19
|
+
*/
|
|
20
|
+
export function createPluginChannelHub(options) {
|
|
21
|
+
const entries = new Map();
|
|
22
|
+
const documents = new Map();
|
|
23
|
+
const rejected = createPluginChannelLimiters(options.now);
|
|
24
|
+
const changes = new Set();
|
|
25
|
+
const failures = new Set();
|
|
26
|
+
const key = (pluginId, actorId) => JSON.stringify([pluginId, actorId]);
|
|
27
|
+
/** Rate windows of one runtime document, released with its last actor. */
|
|
28
|
+
function limiters(runtimeId) {
|
|
29
|
+
let value = documents.get(runtimeId);
|
|
30
|
+
if (!value)
|
|
31
|
+
documents.set(runtimeId, value = createPluginChannelLimiters(options.now));
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
/** Observers never interrupt hub bookkeeping. */
|
|
35
|
+
function notify() {
|
|
36
|
+
for (const listener of [...changes]) {
|
|
37
|
+
try {
|
|
38
|
+
listener();
|
|
39
|
+
}
|
|
40
|
+
catch { }
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Retires matching actors: pending sends reject at once with `code`, listeners are released.
|
|
45
|
+
* @returns Whether any actor retired.
|
|
46
|
+
*/
|
|
47
|
+
function retire(predicate, code) {
|
|
48
|
+
let changed = false;
|
|
49
|
+
for (const [id, entry] of entries) {
|
|
50
|
+
if (!predicate(entry.actor))
|
|
51
|
+
continue;
|
|
52
|
+
entries.delete(id);
|
|
53
|
+
entry.retired = code;
|
|
54
|
+
entry.listeners.clear();
|
|
55
|
+
entry.controller.abort();
|
|
56
|
+
changed = true;
|
|
57
|
+
}
|
|
58
|
+
for (const runtimeId of documents.keys()) {
|
|
59
|
+
if (![...entries.values()].some(entry => entry.actor.runtimeId === runtimeId))
|
|
60
|
+
documents.delete(runtimeId);
|
|
61
|
+
}
|
|
62
|
+
if (changed)
|
|
63
|
+
notify();
|
|
64
|
+
return changed;
|
|
65
|
+
}
|
|
66
|
+
/** Counts traffic a host refused before it reached an actor; notices are never charged. */
|
|
67
|
+
function reject(message) {
|
|
68
|
+
if (isHistoirePluginId(message?.pluginId) && !(typeof message.type === 'string' && isHistoirePluginNotice(message.type)))
|
|
69
|
+
rejected.get(message.pluginId).incoming.drop();
|
|
70
|
+
}
|
|
71
|
+
/** Delivers one data message to the listeners of its exact actor. */
|
|
72
|
+
function deliver(entry, payload) {
|
|
73
|
+
const rates = limiters(entry.actor.runtimeId).get(entry.actor.pluginId);
|
|
74
|
+
if (!rates.incoming.accept())
|
|
75
|
+
return;
|
|
76
|
+
const message = { pluginId: payload.pluginId, actorId: payload.actorId, type: payload.type, data: payload.data, target: { ...entry.actor.target } };
|
|
77
|
+
/** Async consumer failures stay observed but never charge a retired actor. */
|
|
78
|
+
const failed = () => {
|
|
79
|
+
if (!entry.retired)
|
|
80
|
+
rates.incoming.drop();
|
|
81
|
+
};
|
|
82
|
+
for (const { type, listener } of [...entry.listeners]) {
|
|
83
|
+
if (type !== payload.type)
|
|
84
|
+
continue;
|
|
85
|
+
try {
|
|
86
|
+
void Promise.resolve(listener(structuredClone(message.data), structuredClone(message))).catch(failed);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
failed();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
retire,
|
|
95
|
+
reject,
|
|
96
|
+
/**
|
|
97
|
+
* Admits one frame publication whose source and document the adapter already verified.
|
|
98
|
+
* @param event Attributed message or runtime notice.
|
|
99
|
+
* @param frameKey Host frame the document belongs to.
|
|
100
|
+
*/
|
|
101
|
+
receive(event, frameKey) {
|
|
102
|
+
let payload;
|
|
103
|
+
try {
|
|
104
|
+
payload = validatePluginChannelPayload(event, true);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
reject(event);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const id = key(payload.pluginId, payload.actorId);
|
|
111
|
+
if (payload.type === 'histoire:attached') {
|
|
112
|
+
// Each actor detaches with its own notice; a repeated attach is ignored.
|
|
113
|
+
if (entries.has(id))
|
|
114
|
+
return;
|
|
115
|
+
const actor = Object.freeze({ pluginId: payload.pluginId, actorId: payload.actorId, target: Object.freeze({ ...payload.target }), runtimeId: payload.runtimeId, frameKey });
|
|
116
|
+
entries.set(id, { actor, controller: new AbortController(), listeners: new Set() });
|
|
117
|
+
notify();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (payload.type === 'histoire:detached') {
|
|
121
|
+
retire(actor => actor.pluginId === payload.pluginId && actor.actorId === payload.actorId && actor.runtimeId === payload.runtimeId, 'RUNTIME_CHANGED');
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (payload.type === 'histoire:error') {
|
|
125
|
+
const data = payload.data;
|
|
126
|
+
const error = Object.assign(new Error(`frame ${data.phase} failed: ${data.message}`), { phase: data.phase, actorId: payload.actorId });
|
|
127
|
+
for (const failure of [...failures]) {
|
|
128
|
+
try {
|
|
129
|
+
if (failure.pluginId === payload.pluginId)
|
|
130
|
+
failure.listener(error);
|
|
131
|
+
}
|
|
132
|
+
catch { }
|
|
133
|
+
}
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const entry = entries.get(id);
|
|
137
|
+
if (!entry || entry.actor.runtimeId !== payload.runtimeId || entry.actor.frameKey !== frameKey || getHistoireTargetKey(entry.actor.target) !== getHistoireTargetKey(payload.target)) {
|
|
138
|
+
reject(payload);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
deliver(entry, payload);
|
|
142
|
+
},
|
|
143
|
+
/** Attached actors of one plugin, in attach order. */
|
|
144
|
+
actors(pluginId) {
|
|
145
|
+
return [...entries.values()].filter(entry => entry.actor.pluginId === pluginId).map(entry => entry.actor);
|
|
146
|
+
},
|
|
147
|
+
/**
|
|
148
|
+
* Opens a channel bound to exactly one attached actor; it never retargets.
|
|
149
|
+
* @param pluginId Plugin owning the channel.
|
|
150
|
+
* @param actorId Attached actor.
|
|
151
|
+
* @param owner Aborting it releases this channel's listeners and rejects its later posts.
|
|
152
|
+
*/
|
|
153
|
+
open(pluginId, actorId, owner) {
|
|
154
|
+
const entry = entries.get(key(pluginId, actorId));
|
|
155
|
+
if (!entry)
|
|
156
|
+
throw new HistoireSdkError('RUNTIME_CHANGED', 'Plugin actor is not attached.', { pluginId });
|
|
157
|
+
const { actor } = entry;
|
|
158
|
+
const own = new Set();
|
|
159
|
+
// Owner retirement releases this channel's listeners; actor retirement releases the hook.
|
|
160
|
+
const release = () => {
|
|
161
|
+
for (const listener of own)
|
|
162
|
+
entry.listeners.delete(listener);
|
|
163
|
+
own.clear();
|
|
164
|
+
};
|
|
165
|
+
owner?.addEventListener('abort', release, { once: true });
|
|
166
|
+
entry.controller.signal.addEventListener('abort', () => owner?.removeEventListener('abort', release), { once: true });
|
|
167
|
+
const dropped = () => Math.min(Number.MAX_SAFE_INTEGER, (documents.get(actor.runtimeId)?.droppedCount(pluginId) ?? 0) + rejected.droppedCount(pluginId));
|
|
168
|
+
return Object.freeze({
|
|
169
|
+
post: (type, data) => observeOperation(untilRetired(entry, async () => {
|
|
170
|
+
if (owner?.aborted)
|
|
171
|
+
throw new HistoireSdkError('RUNTIME_CHANGED', 'Plugin channel closed.');
|
|
172
|
+
const rates = limiters(actor.runtimeId).get(pluginId);
|
|
173
|
+
let payload;
|
|
174
|
+
try {
|
|
175
|
+
payload = validatePluginChannelPayload({ pluginId, actorId, type, data });
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
rates.outgoing.drop();
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
if (!rates.outgoing.accept())
|
|
182
|
+
throw new HistoireSdkError('RATE_LIMITED', 'Plugin channel rate limit exceeded.');
|
|
183
|
+
await options.send(actor, structuredClone(payload), entry.controller.signal);
|
|
184
|
+
})),
|
|
185
|
+
on(type, listener) {
|
|
186
|
+
if (typeof type !== 'string' || !type || isHistoirePluginNotice(type))
|
|
187
|
+
throw new HistoireSdkError('INVALID_ARGUMENT', 'Invalid plugin message type.');
|
|
188
|
+
if (typeof listener !== 'function')
|
|
189
|
+
throw new HistoireSdkError('INVALID_ARGUMENT', 'Expected plugin channel listener.');
|
|
190
|
+
if (entry.retired || owner?.aborted)
|
|
191
|
+
return () => { };
|
|
192
|
+
const subscription = { type, listener };
|
|
193
|
+
entry.listeners.add(subscription);
|
|
194
|
+
own.add(subscription);
|
|
195
|
+
return () => {
|
|
196
|
+
entry.listeners.delete(subscription);
|
|
197
|
+
own.delete(subscription);
|
|
198
|
+
};
|
|
199
|
+
},
|
|
200
|
+
getDroppedCount: dropped,
|
|
201
|
+
});
|
|
202
|
+
},
|
|
203
|
+
/** Observes attach and detach. */
|
|
204
|
+
subscribe(listener) {
|
|
205
|
+
changes.add(listener);
|
|
206
|
+
return () => changes.delete(listener);
|
|
207
|
+
},
|
|
208
|
+
/** Observes frame failures attributed to one plugin. */
|
|
209
|
+
onError(pluginId, listener) {
|
|
210
|
+
const failure = { pluginId, listener };
|
|
211
|
+
failures.add(failure);
|
|
212
|
+
return () => failures.delete(failure);
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HistoireSessionPlugins } from '../types.js';
|
|
2
|
+
import type { SessionContext } from './context.js';
|
|
3
|
+
/**
|
|
4
|
+
* Session-owned frame plugin channels. Inventory comes from the descriptor (data-only, nothing
|
|
5
|
+
* evaluated); actors come from runtime notices of the owned primary document and retire with it.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createSessionPlugins(context: SessionContext): HistoireSessionPlugins;
|
|
8
|
+
//# sourceMappingURL=plugins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../../src/session/plugins.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAuB,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAMlD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,cAAc,GAAG,sBAAsB,CAuEpF"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { HistoireSdkError } from '@histoire/protocol';
|
|
2
|
+
import { createPluginChannelHub } from './plugin-hub.js';
|
|
3
|
+
import { request } from './request.js';
|
|
4
|
+
import { primaryRuntime } from './state.js';
|
|
5
|
+
/**
|
|
6
|
+
* Session-owned frame plugin channels. Inventory comes from the descriptor (data-only, nothing
|
|
7
|
+
* evaluated); actors come from runtime notices of the owned primary document and retire with it.
|
|
8
|
+
*/
|
|
9
|
+
export function createSessionPlugins(context) {
|
|
10
|
+
const hub = createPluginChannelHub({
|
|
11
|
+
send: (actor, payload, signal) => {
|
|
12
|
+
const primary = primaryRuntime(context);
|
|
13
|
+
if (primary.runtimeId !== actor.runtimeId)
|
|
14
|
+
throw new HistoireSdkError('RUNTIME_CHANGED', 'Plugin actor belongs to a retired runtime.');
|
|
15
|
+
return request(context, primary.transport, 'plugin.post', payload, { kind: 'runtime', mountId: primary.handle.id }, signal);
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
let status = context.snapshot.status;
|
|
19
|
+
let sourceIdentity;
|
|
20
|
+
/** Owned primary document, independent of transient public readiness. */
|
|
21
|
+
function currentDocument() {
|
|
22
|
+
const primary = context.primaryId ? context.mounts.get(context.primaryId) : undefined;
|
|
23
|
+
return primary?.active ? primary.runtimeId : null;
|
|
24
|
+
}
|
|
25
|
+
/** Installed entry of `pluginId`, if the connected book advertises frame plugins. */
|
|
26
|
+
function installed(pluginId) {
|
|
27
|
+
return context.engine?.framePlugins?.available ? context.descriptor?.framePlugins?.find(plugin => plugin.id === pluginId) : undefined;
|
|
28
|
+
}
|
|
29
|
+
/** Distinct rejections: disconnected source, unavailable plugin, unsupported contract version. */
|
|
30
|
+
function assertPlugin(pluginId) {
|
|
31
|
+
context.assertConnected();
|
|
32
|
+
const plugin = installed(pluginId);
|
|
33
|
+
if (!plugin)
|
|
34
|
+
throw new HistoireSdkError('CAPABILITY_UNAVAILABLE', 'Frame plugin is not installed in this book.', { pluginId });
|
|
35
|
+
if (plugin.apiVersion !== 1)
|
|
36
|
+
throw new HistoireSdkError('PROTOCOL_MISMATCH', 'Unsupported frame plugin contract version.', { pluginId, apiVersion: plugin.apiVersion });
|
|
37
|
+
}
|
|
38
|
+
context.listeners.add((snapshot) => {
|
|
39
|
+
const nextSource = snapshot.source ? JSON.stringify([snapshot.source.sourceId, snapshot.source.epoch]) : undefined;
|
|
40
|
+
const retiredSource = (status === 'ready' && snapshot.status !== 'ready') || (sourceIdentity !== undefined && nextSource !== sourceIdentity);
|
|
41
|
+
status = snapshot.status;
|
|
42
|
+
sourceIdentity = nextSource;
|
|
43
|
+
if (retiredSource) {
|
|
44
|
+
const code = snapshot.status === 'disposed' ? 'DISPOSED' : snapshot.status === 'ready' ? 'STALE_REVISION' : 'NOT_CONNECTED';
|
|
45
|
+
hub.retire(() => true, code);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// Only physical document replacement retires actors; selection keeps them.
|
|
49
|
+
const owned = currentDocument();
|
|
50
|
+
hub.retire(actor => actor.runtimeId !== owned, 'RUNTIME_CHANGED');
|
|
51
|
+
});
|
|
52
|
+
context.deliverPlugin = (message) => {
|
|
53
|
+
const story = context.snapshot.catalog.stories.filter(entry => entry.id === message?.target?.storyId);
|
|
54
|
+
if (!installed(message?.pluginId) || message.runtimeId !== currentDocument() || message.target?.storyId !== context.snapshot.selection?.storyId
|
|
55
|
+
|| story.length !== 1 || story[0].variants.filter(variant => variant.id === message.target.variantId).length !== 1) {
|
|
56
|
+
hub.reject(message);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
hub.receive(context.copy(message), message.runtimeId);
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
frames: () => {
|
|
63
|
+
context.assertConnected();
|
|
64
|
+
return context.copy(context.engine?.framePlugins?.available ? context.descriptor?.framePlugins ?? [] : []);
|
|
65
|
+
},
|
|
66
|
+
actors: (pluginId) => {
|
|
67
|
+
assertPlugin(pluginId);
|
|
68
|
+
return hub.actors(pluginId).map(({ frameKey: _frameKey, ...actor }) => actor);
|
|
69
|
+
},
|
|
70
|
+
subscribe: listener => hub.subscribe(listener),
|
|
71
|
+
open: (pluginId, frame) => {
|
|
72
|
+
assertPlugin(pluginId);
|
|
73
|
+
if (typeof frame?.actorId !== 'string')
|
|
74
|
+
throw new HistoireSdkError('INVALID_ARGUMENT', 'Expected a frame plugin actor.');
|
|
75
|
+
return hub.open(pluginId, frame.actorId);
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HistoireSessionCommand, HistoireTransport } from '../adapters/types.js';
|
|
2
|
+
import type { SessionContext } from './context.js';
|
|
3
|
+
import type { OperationScope } from './ownership.js';
|
|
4
|
+
/** Send one captured request; stale success never mutates replacement lifetime. */
|
|
5
|
+
export declare function request<T>(context: SessionContext, transport: HistoireTransport, command: HistoireSessionCommand, payload: unknown, scope?: OperationScope, signal?: AbortSignal, explicitTarget?: import('@histoire/protocol').HistoireTarget): Promise<T>;
|
|
6
|
+
/** Await actual selected-runtime readiness, cleaning waiters on every outcome. */
|
|
7
|
+
export declare function waitForRuntime(context: SessionContext, signal: AbortSignal): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/session/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA0B,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7G,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAGpD,mFAAmF;AACnF,wBAAgB,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,iBAAiB,EAAE,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,GAAE,cAAmC,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,cAAc,CAAC,EAAE,OAAO,oBAAoB,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC,CAoD/Q;AAED,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAkC1F"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { HistoireSdkError, validateBridgeResult, validateWireValue } from '@histoire/protocol';
|
|
2
|
+
/** Send one captured request; stale success never mutates replacement lifetime. */
|
|
3
|
+
export function request(context, transport, command, payload, scope = { kind: 'source' }, signal, explicitTarget) {
|
|
4
|
+
const connection = context.assertConnected();
|
|
5
|
+
const source = context.snapshot.source;
|
|
6
|
+
const selectionVersion = context.selectionVersion;
|
|
7
|
+
const runtimeVersion = context.runtimeVersion;
|
|
8
|
+
const target = explicitTarget ?? context.snapshot.selection;
|
|
9
|
+
const identity = {
|
|
10
|
+
sessionId: context.sessionId,
|
|
11
|
+
connectionId: transport.id,
|
|
12
|
+
sourceId: source.sourceId,
|
|
13
|
+
epoch: source.epoch,
|
|
14
|
+
revision: source.revision,
|
|
15
|
+
...(scope.mountId ? { mountId: scope.mountId } : {}),
|
|
16
|
+
...((scope.kind === 'runtime' || scope.kind === 'inspection') && context.snapshot.runtime.runtimeId ? { runtimeId: context.snapshot.runtime.runtimeId } : {}),
|
|
17
|
+
...(target ? { target } : {}),
|
|
18
|
+
};
|
|
19
|
+
validateWireValue(payload, { kind: 'request', name: command });
|
|
20
|
+
const guard = () => {
|
|
21
|
+
context.assertConnected();
|
|
22
|
+
if (context.connection !== connection || context.snapshot.source?.epoch !== source.epoch || context.snapshot.source?.revision !== source.revision) {
|
|
23
|
+
throw new HistoireSdkError('STALE_REVISION', 'Source changed during operation.');
|
|
24
|
+
}
|
|
25
|
+
if (scope.mountId && !context.mounts.get(scope.mountId)?.active)
|
|
26
|
+
throw new HistoireSdkError('RUNTIME_CHANGED', 'Surface detached during operation.');
|
|
27
|
+
if ((scope.kind === 'runtime' || scope.kind === 'selection') && selectionVersion !== context.selectionVersion)
|
|
28
|
+
throw new HistoireSdkError('RUNTIME_CHANGED', 'Selected target changed during operation.');
|
|
29
|
+
if (scope.kind === 'runtime' && runtimeVersion !== context.runtimeVersion)
|
|
30
|
+
throw new HistoireSdkError('RUNTIME_CHANGED', 'Runtime document changed during operation.');
|
|
31
|
+
if (scope.kind === 'inspection' && context.mounts.get(scope.mountId)?.runtimeId !== identity.runtimeId)
|
|
32
|
+
throw new HistoireSdkError('RUNTIME_CHANGED', 'Runtime document changed during operation.');
|
|
33
|
+
};
|
|
34
|
+
return context.operations.run(scope, async (ownedSignal) => {
|
|
35
|
+
let result;
|
|
36
|
+
try {
|
|
37
|
+
result = await transport.request(command, payload, { ...identity, signal: ownedSignal });
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
guard();
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
if (result !== undefined)
|
|
44
|
+
validateWireValue(result, { kind: 'response', name: command });
|
|
45
|
+
if (!['selection.select', 'settings.update', 'events.clear'].includes(command) && !(result === undefined && ['state.patch', 'state.reset'].includes(command))) {
|
|
46
|
+
validateBridgeResult(command, result);
|
|
47
|
+
}
|
|
48
|
+
if (command === 'docs.get' || command === 'source.get') {
|
|
49
|
+
const content = result;
|
|
50
|
+
if (content.epoch !== source.epoch || content.revision !== source.revision)
|
|
51
|
+
throw new HistoireSdkError('STALE_REVISION', 'Content reply belongs to another source publication.');
|
|
52
|
+
if (content.storyId !== payload.storyId)
|
|
53
|
+
throw new HistoireSdkError('INVALID_ARGUMENT', 'Content reply does not match requested story.');
|
|
54
|
+
}
|
|
55
|
+
if (command === 'tests.collect' || command === 'tests.run') {
|
|
56
|
+
const execution = result.execution;
|
|
57
|
+
const mode = command === 'tests.collect' ? 'preview' : payload.mode;
|
|
58
|
+
if (execution && (execution.mode !== mode || execution.sourceId !== source.sourceId || execution.epoch !== source.epoch || execution.revision !== source.revision || execution.target?.storyId !== target?.storyId || execution.target?.variantId !== target?.variantId || (mode === 'preview' && execution.runtimeId !== identity.runtimeId)))
|
|
59
|
+
throw new HistoireSdkError('INVALID_ARGUMENT', 'Test result belongs to another execution owner.');
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}, guard, signal);
|
|
63
|
+
}
|
|
64
|
+
/** Await actual selected-runtime readiness, cleaning waiters on every outcome. */
|
|
65
|
+
export function waitForRuntime(context, signal) {
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
67
|
+
let timer;
|
|
68
|
+
function cleanup() {
|
|
69
|
+
context.listeners.delete(check);
|
|
70
|
+
signal.removeEventListener('abort', onAbort);
|
|
71
|
+
clearTimeout(timer);
|
|
72
|
+
}
|
|
73
|
+
function onAbort() {
|
|
74
|
+
cleanup();
|
|
75
|
+
reject(signal.reason ?? new HistoireSdkError('CANCELLED', 'Readiness cancelled.'));
|
|
76
|
+
}
|
|
77
|
+
function check() {
|
|
78
|
+
if (context.snapshot.runtime.status === 'ready' && context.snapshot.runtime.runtimeId) {
|
|
79
|
+
cleanup();
|
|
80
|
+
resolve();
|
|
81
|
+
}
|
|
82
|
+
else if (['failed', 'stale', 'absent'].includes(context.snapshot.runtime.status)) {
|
|
83
|
+
cleanup();
|
|
84
|
+
reject(new HistoireSdkError('PREVIEW_NOT_READY', 'Variant became unavailable before loading completed.'));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (signal.aborted) {
|
|
88
|
+
onAbort();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
context.listeners.add(check);
|
|
92
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
93
|
+
timer = setTimeout(() => {
|
|
94
|
+
cleanup();
|
|
95
|
+
reject(new HistoireSdkError('TIMEOUT', 'Variant loading timed out.'));
|
|
96
|
+
}, context.connection?.descriptor.config?.storyCollectTimeout ?? 30_000);
|
|
97
|
+
check();
|
|
98
|
+
});
|
|
99
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { HistoireRuntimeSnapshot } from '@histoire/protocol';
|
|
2
|
+
import type { OwnedMount, SessionContext } from './context.js';
|
|
3
|
+
/** Validate and publish a document once; retired IDs never become current again. */
|
|
4
|
+
export declare function publishRuntime(context: SessionContext, mount: OwnedMount, runtime: HistoireRuntimeSnapshot): boolean;
|
|
5
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/session/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAA;AACjE,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAG9D,oFAAoF;AACpF,wBAAgB,cAAc,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAkBpH"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { validateHistoireRuntimeSnapshot, validateWireValue } from '@histoire/protocol';
|
|
2
|
+
/** Validate and publish a document once; retired IDs never become current again. */
|
|
3
|
+
export function publishRuntime(context, mount, runtime) {
|
|
4
|
+
validateWireValue(runtime, { kind: 'event', name: 'layout.changed' });
|
|
5
|
+
validateHistoireRuntimeSnapshot(runtime);
|
|
6
|
+
if (!mount.active || runtime.mountId !== mount.handle.id || (runtime.runtimeId && mount.retiredRuntimeIds.has(runtime.runtimeId)))
|
|
7
|
+
return false;
|
|
8
|
+
const replaced = runtime.runtimeId !== null && mount.runtimeId !== null && runtime.runtimeId !== mount.runtimeId;
|
|
9
|
+
const retired = mount.runtimeId !== null && (runtime.runtimeId === null || ['stale', 'absent', 'failed'].includes(runtime.status));
|
|
10
|
+
// Retirement rejects pending work immediately, but primary slot remains
|
|
11
|
+
// reserved until mount teardown confirms cleanup. Old readiness cannot revive it.
|
|
12
|
+
if (replaced || retired)
|
|
13
|
+
mount.retiredRuntimeIds.add(mount.runtimeId);
|
|
14
|
+
if (retired)
|
|
15
|
+
mount.runtimeId = null;
|
|
16
|
+
else if (runtime.runtimeId !== null)
|
|
17
|
+
mount.runtimeId = runtime.runtimeId;
|
|
18
|
+
if (retired || replaced || (runtime.status === 'mounting' && context.snapshot.runtime.status !== 'mounting')) {
|
|
19
|
+
context.runtimeVersion++;
|
|
20
|
+
context.operations.reject('RUNTIME_CHANGED', 'Runtime document changed.', scope => scope.kind === 'runtime' || ((retired || replaced) && scope.kind === 'inspection'));
|
|
21
|
+
}
|
|
22
|
+
const projected = mount.hidden ? { ...runtime, viewports: [], viewport: null } : runtime;
|
|
23
|
+
context.publish({ runtime: context.copy(projected), ...(runtime.status === 'mounting' ? { state: null } : {}) });
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HistoireCatalog, HistoireSelectionInput, HistoireTarget } from '@histoire/protocol';
|
|
2
|
+
import type { SessionContext } from './context.js';
|
|
3
|
+
/** Validate exact IDs before changing remembered selection or runtime owner. */
|
|
4
|
+
export declare function resolveSelection(context: SessionContext, input: HistoireSelectionInput): HistoireTarget;
|
|
5
|
+
/** Publish validated intent synchronously; matching callers retain its owned ACK. */
|
|
6
|
+
export declare function select(context: SessionContext, target: HistoireTarget): Promise<void>;
|
|
7
|
+
/** Completed catalog changes cannot retain a removed/ambiguous target. */
|
|
8
|
+
export declare function reconcileSelection(context: SessionContext, catalog?: HistoireCatalog): HistoireTarget | null;
|
|
9
|
+
//# sourceMappingURL=selection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection.d.ts","sourceRoot":"","sources":["../../src/session/selection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACjG,OAAO,KAAK,EAAc,cAAc,EAAE,MAAM,cAAc,CAAA;AAM9D,gFAAgF;AAChF,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,sBAAsB,GAAG,cAAc,CAWvG;AAcD,qFAAqF;AACrF,wBAAsB,MAAM,CAAC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CA8C3F;AAED,0EAA0E;AAC1E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,GAAE,eAA0C,GAAG,cAAc,GAAG,IAAI,CAatI"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { HistoireSdkError } from '@histoire/protocol';
|
|
2
|
+
import { request, waitForRuntime } from './request.js';
|
|
3
|
+
import { publishRuntime } from './runtime.js';
|
|
4
|
+
import { assertVariant } from './variant.js';
|
|
5
|
+
/** Validate exact IDs before changing remembered selection or runtime owner. */
|
|
6
|
+
export function resolveSelection(context, input) {
|
|
7
|
+
if (!input || typeof input !== 'object')
|
|
8
|
+
throw new HistoireSdkError('INVALID_ARGUMENT', 'Selection must name a story.');
|
|
9
|
+
const story = context.story(input.storyId);
|
|
10
|
+
if (input.variantId !== undefined && input.variantId !== null && typeof input.variantId !== 'string')
|
|
11
|
+
throw new HistoireSdkError('INVALID_ARGUMENT', 'Variant ID must be a string or null.');
|
|
12
|
+
let variantId = input.variantId;
|
|
13
|
+
if (variantId === undefined) {
|
|
14
|
+
const remembered = context.remembered.get(story.id);
|
|
15
|
+
variantId = remembered && story.variants.some(variant => variant.id === remembered) ? remembered : story.variants[0]?.id ?? null;
|
|
16
|
+
}
|
|
17
|
+
if (variantId !== null)
|
|
18
|
+
assertVariant(story, variantId);
|
|
19
|
+
return { storyId: story.id, variantId };
|
|
20
|
+
}
|
|
21
|
+
/** Await actual selected document without issuing another selection execution. */
|
|
22
|
+
async function waitSelectionRuntime(context, primary) {
|
|
23
|
+
const version = context.selectionVersion;
|
|
24
|
+
const connection = context.connection;
|
|
25
|
+
const source = context.snapshot.source;
|
|
26
|
+
await context.operations.run({ kind: 'selection', mountId: primary.handle.id }, signal => waitForRuntime(context, signal), () => {
|
|
27
|
+
context.assertConnected();
|
|
28
|
+
if (connection !== context.connection || source.epoch !== context.snapshot.source?.epoch || source.revision !== context.snapshot.source.revision)
|
|
29
|
+
throw new HistoireSdkError('STALE_REVISION', 'Source changed before selection readiness.');
|
|
30
|
+
if (!primary.active || version !== context.selectionVersion)
|
|
31
|
+
throw new HistoireSdkError('RUNTIME_CHANGED', 'Selection changed before runtime readiness.');
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/** Publish validated intent synchronously; matching callers retain its owned ACK. */
|
|
35
|
+
export async function select(context, target) {
|
|
36
|
+
const previous = context.snapshot.selection;
|
|
37
|
+
const primary = context.primaryId ? context.mounts.get(context.primaryId) : undefined;
|
|
38
|
+
if (previous?.storyId === target.storyId && previous.variantId === target.variantId) {
|
|
39
|
+
if (target.variantId === null || !primary)
|
|
40
|
+
return;
|
|
41
|
+
if (!primary.active && context.snapshot.runtime.status === 'absent')
|
|
42
|
+
return;
|
|
43
|
+
if (context.snapshot.runtime.status === 'ready' && context.snapshot.runtime.runtimeId)
|
|
44
|
+
return;
|
|
45
|
+
if (!primary.active || context.snapshot.runtime.status !== 'mounting')
|
|
46
|
+
throw new HistoireSdkError('PREVIEW_NOT_READY', 'Variant is unavailable; remount it to continue.');
|
|
47
|
+
await waitSelectionRuntime(context, primary);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const connection = context.connection;
|
|
51
|
+
const source = context.snapshot.source;
|
|
52
|
+
context.selectionVersion++;
|
|
53
|
+
context.runtimeVersion++;
|
|
54
|
+
const version = context.selectionVersion;
|
|
55
|
+
/** Every publication/await stays owned by this original source and selection. */
|
|
56
|
+
function assertCurrent() {
|
|
57
|
+
context.assertConnected();
|
|
58
|
+
if (connection !== context.connection || source.epoch !== context.snapshot.source?.epoch || source.revision !== context.snapshot.source.revision)
|
|
59
|
+
throw new HistoireSdkError('STALE_REVISION', 'Source superseded during selection.');
|
|
60
|
+
if (version !== context.selectionVersion)
|
|
61
|
+
throw new HistoireSdkError('RUNTIME_CHANGED', 'Selection superseded during publication.');
|
|
62
|
+
}
|
|
63
|
+
context.operations.reject('RUNTIME_CHANGED', 'Selected target changed.', scope => scope.kind === 'runtime' || scope.kind === 'selection');
|
|
64
|
+
if (target.variantId !== null)
|
|
65
|
+
context.remembered.set(target.storyId, target.variantId);
|
|
66
|
+
context.publish({
|
|
67
|
+
selection: context.copy(target),
|
|
68
|
+
state: null,
|
|
69
|
+
events: { items: [], droppedCount: 0 },
|
|
70
|
+
runtime: primary?.active ? { ...context.snapshot.runtime, status: 'mounting', runtimeId: null, viewports: [], viewport: null } : context.snapshot.runtime,
|
|
71
|
+
});
|
|
72
|
+
// Snapshot observers may synchronously accept another target before request
|
|
73
|
+
// admission. Never capture that successor as ownership for this old intent.
|
|
74
|
+
assertCurrent();
|
|
75
|
+
if (!primary?.active)
|
|
76
|
+
return;
|
|
77
|
+
const runtime = await request(context, primary.transport, 'selection.select', target, { kind: 'selection', mountId: primary.handle.id });
|
|
78
|
+
assertCurrent();
|
|
79
|
+
// Selection adapters resolve only after the new document is ready and may
|
|
80
|
+
// return its identity. Legacy adapters publish the same identity as notification.
|
|
81
|
+
if (runtime && typeof runtime === 'object' && 'status' in runtime && 'runtimeId' in runtime) {
|
|
82
|
+
if (!publishRuntime(context, primary, runtime))
|
|
83
|
+
throw new HistoireSdkError('RUNTIME_CHANGED', 'Selection reply belongs to a retired document.');
|
|
84
|
+
}
|
|
85
|
+
assertCurrent();
|
|
86
|
+
if (target.variantId !== null && context.snapshot.runtime.status !== 'ready') {
|
|
87
|
+
await waitSelectionRuntime(context, primary);
|
|
88
|
+
assertCurrent();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** Completed catalog changes cannot retain a removed/ambiguous target. */
|
|
92
|
+
export function reconcileSelection(context, catalog = context.snapshot.catalog) {
|
|
93
|
+
const current = context.snapshot.selection;
|
|
94
|
+
if (!current)
|
|
95
|
+
return null;
|
|
96
|
+
const matches = catalog.stories.filter(story => story.id === current.storyId);
|
|
97
|
+
if (matches.length !== 1)
|
|
98
|
+
return null;
|
|
99
|
+
if (current.variantId === null)
|
|
100
|
+
return current;
|
|
101
|
+
const variants = matches[0].variants.filter(variant => variant.id === current.variantId);
|
|
102
|
+
if (variants.length === 1)
|
|
103
|
+
return current;
|
|
104
|
+
if (variants.length > 1)
|
|
105
|
+
return null;
|
|
106
|
+
context.remembered.delete(current.storyId);
|
|
107
|
+
const first = matches[0].variants[0]?.id ?? null;
|
|
108
|
+
if (first !== null && matches[0].variants.filter(variant => variant.id === first).length !== 1)
|
|
109
|
+
return null;
|
|
110
|
+
return { storyId: current.storyId, variantId: first };
|
|
111
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { HistoireDocsContent, HistoireSourceContent, HistoireTestCollectionResult, HistoireTestRunSummary } from '@histoire/protocol';
|
|
2
|
+
import type { SessionContext } from './context.js';
|
|
3
|
+
/** Metadata-only lazy docs; no preview reservation or story execution. */
|
|
4
|
+
export declare function getDocs(context: SessionContext, storyId: string): Promise<HistoireDocsContent>;
|
|
5
|
+
/** Raw source uses data bridge; dynamic source requires selected runtime. */
|
|
6
|
+
export declare function getSource(context: SessionContext, input: {
|
|
7
|
+
storyId: string;
|
|
8
|
+
variantId?: string;
|
|
9
|
+
mode: 'raw' | 'dynamic';
|
|
10
|
+
}): Promise<HistoireSourceContent>;
|
|
11
|
+
/** Collection belongs to explicit selected ready preview. */
|
|
12
|
+
export declare function collectTests(context: SessionContext): Promise<HistoireTestCollectionResult>;
|
|
13
|
+
/** One requested engine, one attributed run; assertion failure still resolves. */
|
|
14
|
+
export declare function runTests(context: SessionContext, options: {
|
|
15
|
+
mode: 'preview' | 'server';
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}): Promise<HistoireTestRunSummary>;
|
|
18
|
+
//# sourceMappingURL=services.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../../src/session/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,4BAA4B,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAC1I,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAMlD,0EAA0E;AAC1E,wBAAsB,OAAO,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAIpG;AAED,6EAA6E;AAC7E,wBAAsB,SAAS,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,KAAK,GAAG,SAAS,CAAA;CAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAYhK;AAED,6DAA6D;AAC7D,wBAAsB,YAAY,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAIjG;AAED,kFAAkF;AAClF,wBAAsB,QAAQ,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE;IAAE,IAAI,EAAE,SAAS,GAAG,QAAQ,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAYtJ"}
|